easy-airtable-api 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +88 -0
- package/README.md +402 -130
- package/easy-airtable-api-0.0.17.tgz +0 -0
- package/lib/bases.d.ts +18 -0
- package/lib/bases.js +40 -0
- package/lib/cli.d.ts +2 -0
- package/lib/cli.js +82 -0
- package/lib/codegen/build.d.ts +2 -0
- package/lib/codegen/build.js +25 -0
- package/lib/codegen/emit-typescript.d.ts +8 -0
- package/lib/codegen/emit-typescript.js +104 -0
- package/lib/codegen/generate.d.ts +2 -0
- package/lib/codegen/generate.js +23 -0
- package/lib/codegen/identifiers.d.ts +7 -0
- package/lib/codegen/identifiers.js +51 -0
- package/lib/codegen/index.d.ts +3 -0
- package/lib/codegen/index.js +2 -0
- package/lib/codegen/load-schema.d.ts +3 -0
- package/lib/codegen/load-schema.js +28 -0
- package/lib/codegen/map-field.d.ts +31 -0
- package/lib/codegen/map-field.js +278 -0
- package/lib/codegen/normalize-schema.d.ts +11 -0
- package/lib/codegen/normalize-schema.js +61 -0
- package/lib/codegen/types.d.ts +62 -0
- package/lib/codegen/types.js +1 -0
- package/lib/codegen/utils.d.ts +14 -0
- package/lib/codegen/utils.js +30 -0
- package/lib/codegen/write-atomic.d.ts +1 -0
- package/lib/codegen/write-atomic.js +11 -0
- package/lib/index.d.ts +8 -2
- package/lib/index.js +3 -2
- package/lib/records.d.ts +75 -9
- package/lib/records.js +110 -21
- package/lib/requests.d.ts +65 -21
- package/lib/requests.js +281 -31
- package/lib/types/bases.d.ts +8 -40
- package/lib/types/fields.d.ts +8 -8
- package/lib/types/metadata.d.ts +24 -0
- package/lib/types/metadata.js +1 -0
- package/lib/types/records.d.ts +1 -1
- package/lib/utils.d.ts +2 -2
- package/package.json +17 -9
- package/lib/generate-types.d.ts +0 -5
- package/lib/generate-types.js +0 -78
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.0.17
|
|
4
|
+
|
|
5
|
+
- Reworked Airtable type generation around the new `easy-airtable-api/codegen` workflow.
|
|
6
|
+
- Added public metadata/base helpers: `listBases`, `getBaseSchema`, and verified `createBase`.
|
|
7
|
+
- Added `airtableRequestRaw` as a public escape hatch for unsupported Airtable endpoints.
|
|
8
|
+
- Hardened the shared request layer with structured `AirtableApiError`, retries, `Retry-After`, jittered backoff, safer encoding, and configurable retry options.
|
|
9
|
+
- Added record API parity helpers including `deleteRecord`, `replaceRecord`, `replaceRecords`, `getRecord(..., options)`, `getRecordsPage`, and `iterateRecordsPages`.
|
|
10
|
+
- Expanded offline and opt-in integration test coverage for retries, batching, validation, metadata, codegen, and non-mutation guarantees.
|
|
11
|
+
|
|
12
|
+
## 0.0.16
|
|
13
|
+
|
|
14
|
+
- Improved type generation to support more Airtable field types.
|
|
15
|
+
|
|
16
|
+
## 0.0.15
|
|
17
|
+
|
|
18
|
+
- Type generation wraps type keys in quotations
|
|
19
|
+
- Fix various type generation issues
|
|
20
|
+
- added createRecords and createRecord methods
|
|
21
|
+
|
|
22
|
+
## 0.0.14
|
|
23
|
+
|
|
24
|
+
- Exported generateTypeScriptDefinitions function.
|
|
25
|
+
|
|
26
|
+
## 0.0.13
|
|
27
|
+
|
|
28
|
+
- Added generateTypeScriptDefinitions function to generate TypeScript definitions for Airtable tables.
|
|
29
|
+
|
|
30
|
+
## 0.0.12
|
|
31
|
+
|
|
32
|
+
- Reverted making apiKey, baseId, tableId default to undefined
|
|
33
|
+
- Added option to customize delay between requests via options.requestInterval
|
|
34
|
+
|
|
35
|
+
## 0.0.11
|
|
36
|
+
|
|
37
|
+
- Make apiKey, baseId, tableId default to undefined #12
|
|
38
|
+
- Missing .js in utils import #13
|
|
39
|
+
|
|
40
|
+
## 0.0.10
|
|
41
|
+
|
|
42
|
+
- Fixed deleteRecords implementation errors.
|
|
43
|
+
|
|
44
|
+
## 0.0.9
|
|
45
|
+
|
|
46
|
+
- Implemented the deleteRecords method.
|
|
47
|
+
|
|
48
|
+
## 0.0.8
|
|
49
|
+
|
|
50
|
+
- Implemented the updateRecords method.
|
|
51
|
+
- Implemented the updateRecordsUpsert method.
|
|
52
|
+
- Added a delay when executing many requests in succession.
|
|
53
|
+
- Fixed the updateRecord and updateRecords methods to return correct field types.
|
|
54
|
+
|
|
55
|
+
## 0.0.7
|
|
56
|
+
|
|
57
|
+
- Added all available options for updateRecords.
|
|
58
|
+
- Modified the getRecords function to automatically retrieve all records.
|
|
59
|
+
|
|
60
|
+
## 0.0.6
|
|
61
|
+
|
|
62
|
+
- Added all available options for updateRecord.
|
|
63
|
+
- Corrected the path to index.d.ts.
|
|
64
|
+
|
|
65
|
+
## 0.0.5
|
|
66
|
+
|
|
67
|
+
- Discontinued CJS build, supporting only ESM for now.
|
|
68
|
+
|
|
69
|
+
## 0.0.4
|
|
70
|
+
|
|
71
|
+
- Exported all available methods.
|
|
72
|
+
- Restructured the lib folder to eliminate duplicate types.
|
|
73
|
+
|
|
74
|
+
## 0.0.3
|
|
75
|
+
|
|
76
|
+
- Supported both ESM & CJS builds.
|
|
77
|
+
- Enhanced server error handling.
|
|
78
|
+
- Introduced generic field types.
|
|
79
|
+
|
|
80
|
+
## 0.0.2
|
|
81
|
+
|
|
82
|
+
- Developed basic request functions to retrieve or update records.
|
|
83
|
+
- Added type definitions for requests and fields.
|
|
84
|
+
- Conducted basic tests to verify the core functionality of the library.
|
|
85
|
+
|
|
86
|
+
## 0.0.1
|
|
87
|
+
|
|
88
|
+
- Initial project setup with no real functionality implemented.
|
package/README.md
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
# Easy Airtable API
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Easy Airtable API is a lightweight, TypeScript-first Airtable client for records, metadata/base APIs, code generation, and raw Airtable requests.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
It is built to stay practical:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- small runtime API
|
|
8
|
+
- typed CRUD helpers
|
|
9
|
+
- code generation from Airtable metadata
|
|
10
|
+
- a better fit for app code than a large SDK surface
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
The intended workflow is simple:
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
1. generate types from your Airtable base
|
|
15
|
+
2. import the generated types in your app
|
|
16
|
+
3. use the runtime helpers with those types
|
|
12
17
|
|
|
13
18
|
## Install
|
|
14
19
|
|
|
@@ -20,193 +25,460 @@ npm install easy-airtable-api
|
|
|
20
25
|
bun add easy-airtable-api
|
|
21
26
|
```
|
|
22
27
|
|
|
23
|
-
##
|
|
28
|
+
## Recommended project setup
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
A good setup is to generate Airtable types once and commit the generated file.
|
|
31
|
+
|
|
32
|
+
### Example file structure
|
|
33
|
+
|
|
34
|
+
```txt
|
|
35
|
+
.
|
|
36
|
+
├── scripts/
|
|
37
|
+
│ └── generate-airtable-types.ts
|
|
38
|
+
├── src/
|
|
39
|
+
│ ├── airtable.generated.ts
|
|
40
|
+
│ └── airtable.ts
|
|
41
|
+
├── .env
|
|
42
|
+
└── package.json
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Example environment variables
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
AIRTABLE_ACCESS_TOKEN=pat_xxx
|
|
49
|
+
AIRTABLE_BASE_ID=app_xxx
|
|
50
|
+
AIRTABLE_PROJECTS_TABLE_ID=tbl_xxx
|
|
51
|
+
AIRTABLE_WORKSPACE_ID=wsp_xxx
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Example `package.json` scripts
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"scripts": {
|
|
59
|
+
"airtable:types": "tsx scripts/generate-airtable-types.ts"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 1) Generate types into your project
|
|
65
|
+
|
|
66
|
+
Create `scripts/generate-airtable-types.ts`:
|
|
26
67
|
|
|
27
68
|
```ts
|
|
28
|
-
import {
|
|
69
|
+
import { generateAirtableTypes } from 'easy-airtable-api/codegen';
|
|
29
70
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
apiKey: 'apiKey',
|
|
38
|
-
baseId: 'baseId',
|
|
39
|
-
tableNameOrId: 'tableNameOrId',
|
|
40
|
-
recordId: 'recordId',
|
|
71
|
+
await generateAirtableTypes({
|
|
72
|
+
source: {
|
|
73
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
74
|
+
accessToken: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
75
|
+
},
|
|
76
|
+
output: './src/airtable.generated.ts',
|
|
77
|
+
enumMode: 'hybrid',
|
|
41
78
|
});
|
|
42
79
|
```
|
|
43
80
|
|
|
44
|
-
|
|
81
|
+
Then run:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npm run airtable:types
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 2) Use the generated types in your app
|
|
88
|
+
|
|
89
|
+
Create `src/airtable.ts`:
|
|
45
90
|
|
|
46
91
|
```ts
|
|
47
|
-
import { getRecords } from 'easy-airtable-api';
|
|
92
|
+
import { createRecord, getRecords, updateRecord } from 'easy-airtable-api';
|
|
93
|
+
import type {
|
|
94
|
+
ProjectsCreateFields,
|
|
95
|
+
ProjectsRecordFields,
|
|
96
|
+
} from './airtable.generated';
|
|
97
|
+
|
|
98
|
+
const apiKey = process.env.AIRTABLE_ACCESS_TOKEN!;
|
|
99
|
+
const baseId = process.env.AIRTABLE_BASE_ID!;
|
|
100
|
+
const tableId = process.env.AIRTABLE_PROJECTS_TABLE_ID!;
|
|
101
|
+
|
|
102
|
+
export async function listProjects() {
|
|
103
|
+
return getRecords<ProjectsRecordFields>({
|
|
104
|
+
apiKey,
|
|
105
|
+
baseId,
|
|
106
|
+
tableId,
|
|
107
|
+
options: {
|
|
108
|
+
maxRecords: 100,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function createProject(fields: ProjectsCreateFields) {
|
|
114
|
+
return createRecord<ProjectsCreateFields>({
|
|
115
|
+
apiKey,
|
|
116
|
+
baseId,
|
|
117
|
+
tableId,
|
|
118
|
+
fields,
|
|
119
|
+
options: {
|
|
120
|
+
typecast: true,
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export async function markProjectInProgress(recordId: string) {
|
|
126
|
+
return updateRecord<ProjectsCreateFields>({
|
|
127
|
+
apiKey,
|
|
128
|
+
baseId,
|
|
129
|
+
tableId,
|
|
130
|
+
recordId,
|
|
131
|
+
fields: {
|
|
132
|
+
Status: 'In Progress',
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
```
|
|
48
137
|
|
|
49
|
-
|
|
50
|
-
Name?: string;
|
|
51
|
-
Notes?: string;
|
|
52
|
-
Status?: string;
|
|
53
|
-
};
|
|
138
|
+
## Codegen
|
|
54
139
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
140
|
+
### `generateAirtableTypes()`
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { generateAirtableTypes } from 'easy-airtable-api/codegen';
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Supported schema sources:
|
|
147
|
+
|
|
148
|
+
- Airtable metadata API via `baseId` + `accessToken` / `apiKey`
|
|
149
|
+
- local schema file via `schemaPath`
|
|
150
|
+
- in-memory schema object via `schema`
|
|
151
|
+
|
|
152
|
+
Example using a local schema file:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
await generateAirtableTypes({
|
|
156
|
+
source: {
|
|
157
|
+
schemaPath: './airtable-schema.json',
|
|
61
158
|
},
|
|
159
|
+
output: './src/airtable.generated.ts',
|
|
62
160
|
});
|
|
63
161
|
```
|
|
64
162
|
|
|
65
|
-
###
|
|
163
|
+
### Enum typing modes
|
|
66
164
|
|
|
67
|
-
|
|
68
|
-
import { updateRecord } from 'easy-airtable-api';
|
|
165
|
+
Choice-like fields such as single select and multiple select support 3 modes:
|
|
69
166
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
167
|
+
- `literal` — exact Airtable option values only
|
|
168
|
+
- `hybrid` — exact Airtable values plus a string fallback
|
|
169
|
+
- `broad` — generic `string` / `string[]`
|
|
74
170
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
Name: 'New Name',
|
|
85
|
-
Status: 'Active',
|
|
171
|
+
`hybrid` is the default and usually the best fit for real Airtable projects because it preserves autocomplete while tolerating schema drift.
|
|
172
|
+
|
|
173
|
+
### Useful codegen options
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
await generateAirtableTypes({
|
|
177
|
+
source: {
|
|
178
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
179
|
+
accessToken: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
86
180
|
},
|
|
181
|
+
output: './src/airtable.generated.ts',
|
|
182
|
+
tableNameOrId: ['Projects', 'Tasks'],
|
|
183
|
+
enumMode: 'hybrid',
|
|
184
|
+
createRequiredMode: 'allOptional',
|
|
185
|
+
unknownFieldBehavior: 'unknown',
|
|
186
|
+
includeTableIds: true,
|
|
187
|
+
includeFieldIds: true,
|
|
188
|
+
schemaMode: 'full',
|
|
87
189
|
});
|
|
88
190
|
```
|
|
89
191
|
|
|
90
|
-
|
|
192
|
+
## Metadata/base APIs
|
|
193
|
+
|
|
194
|
+
### List accessible bases
|
|
91
195
|
|
|
92
196
|
```ts
|
|
93
|
-
import {
|
|
197
|
+
import { listBases } from 'easy-airtable-api';
|
|
94
198
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
};
|
|
199
|
+
const result = await listBases({
|
|
200
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
201
|
+
});
|
|
99
202
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
203
|
+
for (const base of result.bases) {
|
|
204
|
+
console.log(base.id, base.name, base.permissionLevel);
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Fetch a base schema directly
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import { getBaseSchema } from 'easy-airtable-api';
|
|
212
|
+
|
|
213
|
+
const schema = await getBaseSchema({
|
|
214
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
215
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
console.log(schema.tables.map((table) => table.name));
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
This is the same metadata path used by the code generator when `source` includes a `baseId` and token.
|
|
222
|
+
|
|
223
|
+
### Create a base
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
import { createBase } from 'easy-airtable-api';
|
|
227
|
+
|
|
228
|
+
const created = await createBase({
|
|
229
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
230
|
+
body: {
|
|
231
|
+
workspaceId: process.env.AIRTABLE_WORKSPACE_ID!,
|
|
232
|
+
name: 'Apartment Hunting',
|
|
233
|
+
tables: [
|
|
234
|
+
{
|
|
235
|
+
name: 'Apartments',
|
|
236
|
+
fields: [
|
|
237
|
+
{ name: 'Name', type: 'singleLineText' },
|
|
238
|
+
{
|
|
239
|
+
name: 'Visited',
|
|
240
|
+
type: 'checkbox',
|
|
241
|
+
options: { color: 'greenBright', icon: 'check' },
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
console.log(created.id);
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Per Airtable's metadata API documentation, creating a base requires a token authorized for `schema.bases:write`, and the caller must be able to create bases in the target workspace (documented as workspace creator permissions).
|
|
253
|
+
|
|
254
|
+
## Raw Airtable request escape hatch
|
|
255
|
+
|
|
256
|
+
Use `airtableRequestRaw()` when you need an Airtable endpoint that this library does not wrap yet, but still want the shared auth, retry, encoding, and structured error behavior.
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
import { airtableRequestRaw } from 'easy-airtable-api';
|
|
260
|
+
|
|
261
|
+
const schema = await airtableRequestRaw({
|
|
262
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
263
|
+
method: 'GET',
|
|
264
|
+
path: '/v0/meta/bases/app123/tables',
|
|
123
265
|
});
|
|
124
266
|
```
|
|
125
267
|
|
|
126
|
-
|
|
268
|
+
It accepts either Airtable-style `/v0/...` paths or paths relative to the API root used internally.
|
|
269
|
+
|
|
270
|
+
## Retry configuration
|
|
271
|
+
|
|
272
|
+
All runtime helpers accept an optional top-level `retry` object for tuning retry behavior without leaving the library's shared request layer.
|
|
127
273
|
|
|
128
274
|
```ts
|
|
129
|
-
import {
|
|
275
|
+
import { getRecords } from 'easy-airtable-api';
|
|
130
276
|
|
|
131
|
-
const
|
|
132
|
-
apiKey:
|
|
133
|
-
baseId:
|
|
134
|
-
|
|
277
|
+
const records = await getRecords({
|
|
278
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
279
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
280
|
+
tableId: process.env.AIRTABLE_PROJECTS_TABLE_ID!,
|
|
281
|
+
retry: {
|
|
282
|
+
maxRetries: 2,
|
|
283
|
+
baseDelayMs: 250,
|
|
284
|
+
maxDelayMs: 1000,
|
|
285
|
+
retryOn429: true,
|
|
286
|
+
retryOn5xx: true,
|
|
287
|
+
retryOnNetworkErrors: true,
|
|
288
|
+
useJitter: false,
|
|
289
|
+
},
|
|
135
290
|
});
|
|
136
291
|
```
|
|
137
292
|
|
|
138
|
-
|
|
293
|
+
The same `retry` option is supported by metadata helpers such as `listBases()` / `getBaseSchema()` and by `airtableRequestRaw()`.
|
|
139
294
|
|
|
140
|
-
|
|
295
|
+
## Runtime examples
|
|
141
296
|
|
|
142
|
-
|
|
143
|
-
- Fix various type generation issues
|
|
144
|
-
- added createRecords and createRecord methods
|
|
297
|
+
### Get a single record
|
|
145
298
|
|
|
146
|
-
|
|
299
|
+
```ts
|
|
300
|
+
import { getRecord } from 'easy-airtable-api';
|
|
301
|
+
import type { ProjectsRecordFields } from './airtable.generated';
|
|
147
302
|
|
|
148
|
-
|
|
303
|
+
const record = await getRecord<ProjectsRecordFields>({
|
|
304
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
305
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
306
|
+
tableId: process.env.AIRTABLE_PROJECTS_TABLE_ID!,
|
|
307
|
+
recordId: 'rec123',
|
|
308
|
+
options: {
|
|
309
|
+
returnFieldsByFieldId: false,
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
```
|
|
149
313
|
|
|
150
|
-
###
|
|
314
|
+
### Get one page of records
|
|
151
315
|
|
|
152
|
-
|
|
316
|
+
```ts
|
|
317
|
+
import { getRecordsPage } from 'easy-airtable-api';
|
|
318
|
+
import type { ProjectsRecordFields } from './airtable.generated';
|
|
153
319
|
|
|
154
|
-
|
|
320
|
+
const page = await getRecordsPage<ProjectsRecordFields>({
|
|
321
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
322
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
323
|
+
tableId: process.env.AIRTABLE_PROJECTS_TABLE_ID!,
|
|
324
|
+
options: {
|
|
325
|
+
pageSize: 25,
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
```
|
|
155
329
|
|
|
156
|
-
|
|
157
|
-
- Added option to customize delay between requests via options.requestInterval
|
|
330
|
+
### Iterate through record pages
|
|
158
331
|
|
|
159
|
-
|
|
332
|
+
```ts
|
|
333
|
+
import { iterateRecordsPages } from 'easy-airtable-api';
|
|
334
|
+
import type { ProjectsRecordFields } from './airtable.generated';
|
|
160
335
|
|
|
161
|
-
|
|
162
|
-
|
|
336
|
+
for await (const page of iterateRecordsPages<ProjectsRecordFields>({
|
|
337
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
338
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
339
|
+
tableId: process.env.AIRTABLE_PROJECTS_TABLE_ID!,
|
|
340
|
+
options: {
|
|
341
|
+
pageSize: 100,
|
|
342
|
+
},
|
|
343
|
+
})) {
|
|
344
|
+
console.log(page.records.length, page.offset);
|
|
345
|
+
}
|
|
346
|
+
```
|
|
163
347
|
|
|
164
|
-
###
|
|
348
|
+
### Create multiple records
|
|
165
349
|
|
|
166
|
-
|
|
350
|
+
```ts
|
|
351
|
+
import { createRecords } from 'easy-airtable-api';
|
|
352
|
+
import type { ProjectsCreateFields } from './airtable.generated';
|
|
167
353
|
|
|
168
|
-
|
|
354
|
+
const result = await createRecords<ProjectsCreateFields>({
|
|
355
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
356
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
357
|
+
tableId: process.env.AIRTABLE_PROJECTS_TABLE_ID!,
|
|
358
|
+
records: [
|
|
359
|
+
{
|
|
360
|
+
fields: {
|
|
361
|
+
Name: 'Project A',
|
|
362
|
+
Status: 'Todo',
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
fields: {
|
|
367
|
+
Name: 'Project B',
|
|
368
|
+
Status: 'In Progress',
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
],
|
|
372
|
+
options: {
|
|
373
|
+
typecast: true,
|
|
374
|
+
},
|
|
375
|
+
});
|
|
376
|
+
```
|
|
169
377
|
|
|
170
|
-
|
|
378
|
+
### Replace a single record
|
|
171
379
|
|
|
172
|
-
|
|
380
|
+
```ts
|
|
381
|
+
import { replaceRecord } from 'easy-airtable-api';
|
|
382
|
+
import type { ProjectsCreateFields } from './airtable.generated';
|
|
383
|
+
|
|
384
|
+
const result = await replaceRecord<ProjectsCreateFields>({
|
|
385
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
386
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
387
|
+
tableId: process.env.AIRTABLE_PROJECTS_TABLE_ID!,
|
|
388
|
+
recordId: 'rec123',
|
|
389
|
+
fields: {
|
|
390
|
+
Name: 'Project A',
|
|
391
|
+
Status: 'Done',
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
```
|
|
173
395
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
396
|
+
### Upsert records
|
|
397
|
+
|
|
398
|
+
```ts
|
|
399
|
+
import { updateRecordsUpsert } from 'easy-airtable-api';
|
|
400
|
+
import type { ProjectsCreateFields } from './airtable.generated';
|
|
178
401
|
|
|
179
|
-
|
|
402
|
+
const result = await updateRecordsUpsert<ProjectsCreateFields>({
|
|
403
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
404
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
405
|
+
tableId: process.env.AIRTABLE_PROJECTS_TABLE_ID!,
|
|
406
|
+
records: [
|
|
407
|
+
{
|
|
408
|
+
fields: {
|
|
409
|
+
Name: 'Project A',
|
|
410
|
+
Status: 'Done',
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
options: {
|
|
415
|
+
fieldsToMergeOn: ['Name'],
|
|
416
|
+
typecast: true,
|
|
417
|
+
},
|
|
418
|
+
});
|
|
419
|
+
```
|
|
180
420
|
|
|
181
|
-
|
|
182
|
-
- Modified the getRecords function to automatically retrieve all records.
|
|
421
|
+
### Delete a single record
|
|
183
422
|
|
|
184
|
-
|
|
423
|
+
```ts
|
|
424
|
+
import { deleteRecord } from 'easy-airtable-api';
|
|
185
425
|
|
|
186
|
-
|
|
187
|
-
|
|
426
|
+
await deleteRecord({
|
|
427
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
428
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
429
|
+
tableId: process.env.AIRTABLE_PROJECTS_TABLE_ID!,
|
|
430
|
+
recordId: 'rec123',
|
|
431
|
+
});
|
|
432
|
+
```
|
|
188
433
|
|
|
189
|
-
###
|
|
434
|
+
### Delete records
|
|
190
435
|
|
|
191
|
-
|
|
436
|
+
```ts
|
|
437
|
+
import { deleteRecords } from 'easy-airtable-api';
|
|
192
438
|
|
|
193
|
-
|
|
439
|
+
await deleteRecords({
|
|
440
|
+
apiKey: process.env.AIRTABLE_ACCESS_TOKEN!,
|
|
441
|
+
baseId: process.env.AIRTABLE_BASE_ID!,
|
|
442
|
+
tableId: process.env.AIRTABLE_PROJECTS_TABLE_ID!,
|
|
443
|
+
recordIds: ['rec123', 'rec456'],
|
|
444
|
+
});
|
|
445
|
+
```
|
|
194
446
|
|
|
195
|
-
|
|
196
|
-
- Restructured the lib folder to eliminate duplicate types.
|
|
447
|
+
## Exports
|
|
197
448
|
|
|
198
|
-
|
|
449
|
+
Runtime package:
|
|
199
450
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
451
|
+
```ts
|
|
452
|
+
import {
|
|
453
|
+
airtableRequestRaw,
|
|
454
|
+
createBase,
|
|
455
|
+
createRecord,
|
|
456
|
+
createRecords,
|
|
457
|
+
deleteRecord,
|
|
458
|
+
deleteRecords,
|
|
459
|
+
getBaseSchema,
|
|
460
|
+
getRecord,
|
|
461
|
+
getRecords,
|
|
462
|
+
getRecordsPage,
|
|
463
|
+
iterateRecordsPages,
|
|
464
|
+
listBases,
|
|
465
|
+
replaceRecord,
|
|
466
|
+
replaceRecords,
|
|
467
|
+
updateRecord,
|
|
468
|
+
updateRecords,
|
|
469
|
+
updateRecordsUpsert,
|
|
470
|
+
} from 'easy-airtable-api';
|
|
471
|
+
```
|
|
203
472
|
|
|
204
|
-
|
|
473
|
+
Codegen package:
|
|
205
474
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
475
|
+
```ts
|
|
476
|
+
import {
|
|
477
|
+
buildAirtableTypes,
|
|
478
|
+
generateAirtableTypes,
|
|
479
|
+
} from 'easy-airtable-api/codegen';
|
|
480
|
+
```
|
|
209
481
|
|
|
210
|
-
|
|
482
|
+
## Changelog
|
|
211
483
|
|
|
212
|
-
|
|
484
|
+
See [CHANGELOG.md](./CHANGELOG.md).
|
|
Binary file
|