1 | |
2 | |
3 | * Create a new key |
4 | * Create a new key of the type specified by the `type` parameter. If a name is not supplied, one will be auto generated. |
5 | */ |
6 | export async function main( |
7 | auth: RT.Mezmo, |
8 | _type: 'ingestion' | 'service' | 'all' | undefined, |
9 | body?: Body |
10 | ) { |
11 | const url = new URL(`https://api.mezmo.com/v1/config/keys`) |
12 | for (const [k, v] of [['type', _type]]) { |
13 | if (v !== undefined && v !== '') { |
14 | url.searchParams.append(k, v) |
15 | } |
16 | } |
17 | const response = await fetch(url, { |
18 | method: 'POST', |
19 | headers: { |
20 | 'Content-Type': 'application/json', |
21 | Authorization: 'Token ' + auth.apiKey |
22 | }, |
23 | body: JSON.stringify(body) |
24 | }) |
25 | if (!response.ok) { |
26 | const text = await response.text() |
27 | throw new Error(`${response.status} ${text}`) |
28 | } |
29 | return await response.json() |
30 | } |
31 |
|
32 | |
33 | |
34 | * This file was automatically generated by json-schema-to-typescript. |
35 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
36 | * and run json-schema-to-typescript to regenerate this file. |
37 | */ |
38 |
|
39 | export interface Body { |
40 | |
41 | * A user friendly name for the key |
42 | */ |
43 | name?: string |
44 | } |
45 |
|