Edits history of script submission #20929 for ' Generate an authentication link (terra)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Generate an authentication link
     * Creates a login link that allows end users to connect their fitness tracking account
     */
    export async function main(
    	auth: RT.Terra,
    	resource: string | undefined,
    	dev_id: string,
    	body?: Body
    ) {
    	const url = new URL(`https://api.tryterra.co/v2/auth/authenticateUser`)
    	for (const [k, v] of [['resource', resource]]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'dev-id': dev_id,
    			'dev-id': auth.devId,
    			'Content-Type': 'application/json',
    			'X-api-key': auth.apiKey
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    
    /* eslint-disable */
    /**
     * This file was automatically generated by json-schema-to-typescript.
     * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
     * and run json-schema-to-typescript to regenerate this file.
     */
    
    export interface Body {
    	language?: string
    	reference_id?: string
    	auth_success_redirect_url?: string
    	auth_failure_redirect_url?: string
    	[k: string]: unknown
    }
    

    Submitted by hugo697 235 days ago