1 | |
2 | type TheirStack = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Get Technologies |
7 | * This endpoint lets you: |
8 | - List all the technologies we track |
9 | - Search for any given technology. Pass a `name_pattern` parameter (case-insensitive, can be a regex pattern) |
10 | - List the technologies within one or several categories. Pass a `category_pattern` parameter (case-insensitive, can be a regex pattern) |
11 |
|
12 | Calls to this endpoint don't cost you credits. |
13 | */ |
14 | export async function main( |
15 | auth: TheirStack, |
16 | name_pattern: string | undefined, |
17 | slug: string | undefined, |
18 | slugs: string | undefined, |
19 | category_pattern: string | undefined, |
20 | category_slug: string | undefined, |
21 | parent_category_slug: string | undefined, |
22 | parent_category_pattern: string | undefined, |
23 | page: string | undefined, |
24 | limit: string | undefined |
25 | ) { |
26 | const url = new URL(`https://api.theirstack.com/v0/catalog/technologies`) |
27 | for (const [k, v] of [ |
28 | ['name_pattern', name_pattern], |
29 | ['slug', slug], |
30 | ['slugs', slugs], |
31 | ['category_pattern', category_pattern], |
32 | ['category_slug', category_slug], |
33 | ['parent_category_slug', parent_category_slug], |
34 | ['parent_category_pattern', parent_category_pattern], |
35 | ['page', page], |
36 | ['limit', limit] |
37 | ]) { |
38 | if (v !== undefined && v !== '' && k !== undefined) { |
39 | url.searchParams.append(k, v) |
40 | } |
41 | } |
42 | const response = await fetch(url, { |
43 | method: 'GET', |
44 | headers: { |
45 | Authorization: 'Bearer ' + auth.apiKey |
46 | }, |
47 | body: undefined |
48 | }) |
49 | if (!response.ok) { |
50 | const text = await response.text() |
51 | throw new Error(`${response.status} ${text}`) |
52 | } |
53 | return await response.json() |
54 | } |
55 |
|