This repository has been archived by the owner on May 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.ts
66 lines (58 loc) · 1.86 KB
/
run.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import axios from "axios";
import env from "./env";
const run = async () => {
const bases = await getAirtableBases();
// Intentionally an async loop. This would usually be bad for performance but
// in this case it helps us avoid getting rate limited by the Airtable API
for (const base of bases) {
const schema = await getAirtableBaseSchema(base.id);
// TODO: verification here
// Currently blocked on Airtable not giving us the base description,
// which is needed to figure out the ownership chain
}
}
/* https://airtable.com/developers/web/api/list-bases#response-bases */
type Bases = {
id: string,
name: string,
permissionLevel: "none" | "read" | "comment" | "edit" | "create",
}[];
const getAirtableBases = async (): Promise<Bases> => {
const res = await axios<{ bases: Bases }>({
url: `https://api.airtable.com/v0/meta/bases`,
headers: {
Authorization: `Bearer ${env.AIRTABLE_PERSONAL_ACCESS_TOKEN}`,
},
});
return res.data.bases;
};
/* https://airtable.com/developers/web/api/get-base-schema#response-tables */
type BaseSchema = {
id: string,
primaryFieldId: string,
name: string;
description: string | undefined;
fields: {
id: string,
type: string,
name: string,
description: string | undefined,
options: unknown,
}[];
views: {
id: string,
type: string,
name: string,
visibleFieldIds: string[] | undefined;
}
}[];
const getAirtableBaseSchema = async (baseId: string): Promise<BaseSchema> => {
const res = await axios<{ tables: BaseSchema }>({
url: `https://api.airtable.com/v0/meta/bases/${baseId}/tables`,
headers: {
Authorization: `Bearer ${env.AIRTABLE_PERSONAL_ACCESS_TOKEN}`,
},
});
return res.data.tables;
};
export default run;