1 | |
2 | |
3 | * Generate an authentication link |
4 | * Creates a login link that allows end users to connect their fitness tracking account |
5 | */ |
6 | export async function main( |
7 | auth: RT.Terra, |
8 | resource: string | undefined, |
9 | dev_id: string, |
10 | body?: Body |
11 | ) { |
12 | const url = new URL(`https://api.tryterra.co/v2/auth/authenticateUser`) |
13 | for (const [k, v] of [['resource', resource]]) { |
14 | if (v !== undefined && v !== '') { |
15 | url.searchParams.append(k, v) |
16 | } |
17 | } |
18 | const response = await fetch(url, { |
19 | method: 'POST', |
20 | headers: { |
21 | 'dev-id': dev_id, |
22 | 'dev-id': auth.devId, |
23 | 'Content-Type': 'application/json', |
24 | 'X-api-key': auth.apiKey |
25 | }, |
26 | body: JSON.stringify(body) |
27 | }) |
28 | if (!response.ok) { |
29 | const text = await response.text() |
30 | throw new Error(`${response.status} ${text}`) |
31 | } |
32 | return await response.json() |
33 | } |
34 |
|
35 | |
36 | |
37 | * This file was automatically generated by json-schema-to-typescript. |
38 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
39 | * and run json-schema-to-typescript to regenerate this file. |
40 | */ |
41 |
|
42 | export interface Body { |
43 | language?: string |
44 | reference_id?: string |
45 | auth_success_redirect_url?: string |
46 | auth_failure_redirect_url?: string |
47 | [k: string]: unknown |
48 | } |
49 |
|