easy-airtable-api 0.0.1 → 0.0.2
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/README.md +25 -1
- package/lib/main.d.ts +31 -0
- package/lib/main.js +130 -0
- package/lib/records.d.ts +11 -0
- package/lib/records.js +46 -0
- package/lib/requests.d.ts +2 -0
- package/lib/requests.js +52 -0
- package/lib/types/bases.d.ts +62 -0
- package/lib/types/bases.js +1 -0
- package/lib/types/fields.d.ts +328 -0
- package/lib/types/fields.js +2 -0
- package/lib/types/records.d.ts +123 -0
- package/lib/types/records.js +2 -0
- package/lib/types/tables.d.ts +99 -0
- package/lib/types/tables.js +2 -0
- package/lib/types.d.ts +98 -0
- package/lib/types.js +2 -0
- package/lib/utils.d.ts +4 -0
- package/lib/utils.js +32 -0
- package/package.json +34 -3
- package/src/main.ts +0 -0
- package/tsconfig.json +0 -15
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
1
|
# Easy Airtable API
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is meant as an easier/better-to-use alternative to the official Airtable node app.
|
|
4
|
+
|
|
5
|
+
My focus is on delivering a better experience using types and making it easier to get and modify records with some helper functions.
|
|
6
|
+
|
|
7
|
+
Currently, this project is super early and still needs a lot of work. However, most methods have been implemented to at least get and update records.
|
|
8
|
+
|
|
9
|
+
More to come soon.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm install easy-airtable-api
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Changelog
|
|
18
|
+
|
|
19
|
+
### 0.0.2
|
|
20
|
+
|
|
21
|
+
- Basic request functions to get or update records.
|
|
22
|
+
- Added type definitions for requests and fields.
|
|
23
|
+
- Basic tests to check the core functionality of the library.
|
|
24
|
+
|
|
25
|
+
### 0.0.1
|
|
26
|
+
|
|
27
|
+
- Basic project setup - no real functionality.
|
package/lib/main.d.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { GetRecordsQueryParameters, UpdateRecordsRequestOptions } from './types/records';
|
|
2
|
+
type AirtableRecord = {
|
|
3
|
+
id: string;
|
|
4
|
+
fields: {
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export default class Airtable {
|
|
9
|
+
private apiKey;
|
|
10
|
+
private baseId;
|
|
11
|
+
private tableId;
|
|
12
|
+
private apiURL;
|
|
13
|
+
url(url: string): this;
|
|
14
|
+
auth(key: string): this;
|
|
15
|
+
base(baseId: string): this;
|
|
16
|
+
table(tableId: string): this;
|
|
17
|
+
private request;
|
|
18
|
+
getRecord(recordId: string): Promise<AirtableRecord>;
|
|
19
|
+
getRecords(options: GetRecordsQueryParameters): Promise<AirtableRecord[]>;
|
|
20
|
+
updateRecord(recordId: string, fields: object): Promise<AirtableRecord>;
|
|
21
|
+
updateRecords(records: {
|
|
22
|
+
id: string;
|
|
23
|
+
fields: object;
|
|
24
|
+
}[], options?: UpdateRecordsRequestOptions): Promise<AirtableRecord[]>;
|
|
25
|
+
replaceRecord(recordId: string, fields: object): Promise<AirtableRecord>;
|
|
26
|
+
replaceMultipleRecords(records: {
|
|
27
|
+
id: string;
|
|
28
|
+
fields: object;
|
|
29
|
+
}[]): Promise<AirtableRecord[]>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
package/lib/main.js
CHANGED
|
@@ -1 +1,131 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const requests_1 = require("./requests");
|
|
13
|
+
class Airtable {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.apiKey = undefined;
|
|
16
|
+
this.baseId = undefined;
|
|
17
|
+
this.tableId = undefined;
|
|
18
|
+
this.apiURL = 'https://api.airtable.com/v0';
|
|
19
|
+
}
|
|
20
|
+
url(url) {
|
|
21
|
+
if (typeof url === 'string') {
|
|
22
|
+
this.apiURL = url;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw new Error('API URL must be a string');
|
|
26
|
+
}
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
auth(key) {
|
|
30
|
+
if (typeof key === 'string') {
|
|
31
|
+
this.apiKey = key;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw new Error('API Key must be a string');
|
|
35
|
+
}
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
base(baseId) {
|
|
39
|
+
if (typeof baseId === 'string') {
|
|
40
|
+
this.baseId = baseId;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error('baseId must be a string');
|
|
44
|
+
}
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
table(tableId) {
|
|
48
|
+
if (typeof tableId === 'string') {
|
|
49
|
+
this.tableId = tableId;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error('tableId/tableName must be a string');
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
request({ endpoint, method, body, }) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
if (!this.apiKey) {
|
|
59
|
+
throw new Error('API Key must be set before making requests.');
|
|
60
|
+
}
|
|
61
|
+
if (!this.baseId) {
|
|
62
|
+
throw new Error('Base ID must be set before making requests.');
|
|
63
|
+
}
|
|
64
|
+
if (!this.tableId) {
|
|
65
|
+
throw new Error('Table ID/Name must be set before making requests.');
|
|
66
|
+
}
|
|
67
|
+
return yield (0, requests_1.apiRequest)({
|
|
68
|
+
url: `${this.apiURL}/${this.baseId}/${this.tableId}${endpoint}`,
|
|
69
|
+
apiKey: this.apiKey,
|
|
70
|
+
method: method,
|
|
71
|
+
body,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
getRecord(recordId) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
return this.request({
|
|
78
|
+
endpoint: `/${recordId}`,
|
|
79
|
+
method: 'GET',
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
getRecords(options) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
return this.request({
|
|
86
|
+
endpoint: '/listRecords',
|
|
87
|
+
method: 'POST',
|
|
88
|
+
body: options,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
updateRecord(recordId, fields) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
return this.request({
|
|
95
|
+
endpoint: `/${recordId}`,
|
|
96
|
+
method: 'PATCH',
|
|
97
|
+
body: { fields },
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
updateRecords(records, options) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
if (!Array.isArray(records)) {
|
|
104
|
+
throw new Error('records to update must be an array.');
|
|
105
|
+
}
|
|
106
|
+
if (records.length === 0) {
|
|
107
|
+
throw new Error('records to update array must have at least one item.');
|
|
108
|
+
}
|
|
109
|
+
return this.request({
|
|
110
|
+
endpoint: '/',
|
|
111
|
+
method: 'PATCH',
|
|
112
|
+
body: Object.assign({ records }, options),
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
replaceRecord(recordId, fields) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
return this.request({
|
|
119
|
+
endpoint: `/${recordId}`,
|
|
120
|
+
method: 'PUT',
|
|
121
|
+
body: { fields },
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
replaceMultipleRecords(records) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
return this.request({ endpoint: '/', method: 'PUT', body: { records } });
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.default = Airtable;
|
package/lib/records.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const getAirtableRecords: ({ recordId, baseId, tableName, options, }: {
|
|
2
|
+
recordId?: string | string[] | undefined;
|
|
3
|
+
baseId: string;
|
|
4
|
+
tableName: string;
|
|
5
|
+
options?: string | undefined;
|
|
6
|
+
}) => Promise<any>;
|
|
7
|
+
export declare const getAllAirtableRecords: ({ baseId, tableName, options, }: {
|
|
8
|
+
baseId: string;
|
|
9
|
+
tableName: string;
|
|
10
|
+
options: string;
|
|
11
|
+
}) => Promise<unknown[]>;
|
package/lib/records.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getAllAirtableRecords = exports.getAirtableRecords = void 0;
|
|
13
|
+
const getAirtableRecords = ({ recordId, baseId, tableName, options, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const url = `https://api.airtable.com/v0/${baseId}/${tableName}/${recordId ? recordId : ''}?cellFormat=json${options ? options : ''}`;
|
|
15
|
+
try {
|
|
16
|
+
return yield getRequest({ url });
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.log(error);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
exports.getAirtableRecords = getAirtableRecords;
|
|
23
|
+
const getAllAirtableRecords = ({ baseId, tableName, options, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
let records = [];
|
|
26
|
+
const request = yield (0, exports.getAirtableRecords)({ baseId, tableName, options });
|
|
27
|
+
if ((_a = request === null || request === void 0 ? void 0 : request.error) === null || _a === void 0 ? void 0 : _a.message)
|
|
28
|
+
throw new Error((_b = request === null || request === void 0 ? void 0 : request.error) === null || _b === void 0 ? void 0 : _b.message);
|
|
29
|
+
const requestRecords = request.records;
|
|
30
|
+
records = [...records, ...requestRecords];
|
|
31
|
+
let paginationToken = request === null || request === void 0 ? void 0 : request.offset;
|
|
32
|
+
if (paginationToken) {
|
|
33
|
+
do {
|
|
34
|
+
const request = yield (0, exports.getAirtableRecords)({
|
|
35
|
+
baseId,
|
|
36
|
+
tableName,
|
|
37
|
+
options: `${options}&offset=${paginationToken}`,
|
|
38
|
+
});
|
|
39
|
+
const requestRecords = request === null || request === void 0 ? void 0 : request.records;
|
|
40
|
+
records = [...records, ...requestRecords];
|
|
41
|
+
paginationToken = request === null || request === void 0 ? void 0 : request.offset;
|
|
42
|
+
} while (paginationToken);
|
|
43
|
+
}
|
|
44
|
+
return records;
|
|
45
|
+
});
|
|
46
|
+
exports.getAllAirtableRecords = getAllAirtableRecords;
|
package/lib/requests.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.apiRequest = void 0;
|
|
13
|
+
const https_1 = require("https");
|
|
14
|
+
const url_1 = require("url");
|
|
15
|
+
const apiRequest = ({ url, method, apiKey, body, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const parsedUrl = new url_1.URL(url);
|
|
18
|
+
const { hostname, pathname, search } = parsedUrl;
|
|
19
|
+
const options = {
|
|
20
|
+
method,
|
|
21
|
+
hostname,
|
|
22
|
+
path: `${pathname}${search}`,
|
|
23
|
+
timeout: 300000,
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'application/json',
|
|
26
|
+
Authorization: `Bearer ${apiKey}`,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const req = (0, https_1.request)(options, (res) => {
|
|
30
|
+
let data = '';
|
|
31
|
+
res.on('data', (chunk) => {
|
|
32
|
+
data += chunk;
|
|
33
|
+
});
|
|
34
|
+
res.on('end', () => {
|
|
35
|
+
try {
|
|
36
|
+
resolve(JSON.parse(data));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
reject(new Error(`Failed to parse response as JSON: ${data}`));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
req.on('error', (error) => {
|
|
44
|
+
reject(new Error(`airtableApi: ${error.message} (fn_${exports.apiRequest.name})`));
|
|
45
|
+
});
|
|
46
|
+
if (body) {
|
|
47
|
+
req.write(JSON.stringify(body));
|
|
48
|
+
}
|
|
49
|
+
req.end();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
exports.apiRequest = apiRequest;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
type BaseList = {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
permissionLevel: 'none' | 'read' | 'comment' | 'edit' | 'create';
|
|
5
|
+
};
|
|
6
|
+
type ListBasesResponse = {
|
|
7
|
+
bases: BaseList[];
|
|
8
|
+
offset?: string;
|
|
9
|
+
};
|
|
10
|
+
type BasesFieldOptions = {
|
|
11
|
+
inverseLinkFieldId?: string;
|
|
12
|
+
isReversed?: boolean;
|
|
13
|
+
linkedTableId?: string;
|
|
14
|
+
prefersSingleRecordLink?: boolean;
|
|
15
|
+
};
|
|
16
|
+
type Field = {
|
|
17
|
+
description?: string;
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
options?: BasesFieldOptions;
|
|
22
|
+
};
|
|
23
|
+
type TableView = {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
type: string;
|
|
27
|
+
};
|
|
28
|
+
type Table = {
|
|
29
|
+
description?: string;
|
|
30
|
+
fields: Field[];
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
primaryFieldId: string;
|
|
34
|
+
views: TableView[];
|
|
35
|
+
};
|
|
36
|
+
type GetBaseSchemaResponse = {
|
|
37
|
+
tables: Table[];
|
|
38
|
+
};
|
|
39
|
+
type TableConfigFieldOptions = {
|
|
40
|
+
color?: string;
|
|
41
|
+
icon?: string;
|
|
42
|
+
};
|
|
43
|
+
type TableConfigField = {
|
|
44
|
+
description?: string;
|
|
45
|
+
name: string;
|
|
46
|
+
type: string;
|
|
47
|
+
options?: TableConfigFieldOptions;
|
|
48
|
+
};
|
|
49
|
+
type BasesTableConfig = {
|
|
50
|
+
description?: string;
|
|
51
|
+
fields: TableConfigField[];
|
|
52
|
+
name: string;
|
|
53
|
+
};
|
|
54
|
+
type CreateBaseRequestBody = {
|
|
55
|
+
name: string;
|
|
56
|
+
tables: BasesTableConfig[];
|
|
57
|
+
workspaceId: string;
|
|
58
|
+
};
|
|
59
|
+
type CreateBaseResponse = {
|
|
60
|
+
id: string;
|
|
61
|
+
tables: Table[];
|
|
62
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
type AIState = 'empty' | 'loading' | 'generated' | 'error';
|
|
2
|
+
export interface AICell {
|
|
3
|
+
state: AIState;
|
|
4
|
+
isStale: boolean;
|
|
5
|
+
value: string | null;
|
|
6
|
+
errorType?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AIFieldTypeAndOptions {
|
|
9
|
+
type: 'aiText';
|
|
10
|
+
options: {
|
|
11
|
+
prompt?: (string | {
|
|
12
|
+
field: {
|
|
13
|
+
fieldId: string;
|
|
14
|
+
referencedFieldIds?: string[];
|
|
15
|
+
};
|
|
16
|
+
})[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface AttachmentWrite {
|
|
20
|
+
url: string;
|
|
21
|
+
filename?: string;
|
|
22
|
+
id?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface AttachmentFieldTypeAndOptions {
|
|
25
|
+
type: 'multipleAttachments';
|
|
26
|
+
options: {
|
|
27
|
+
isReversed: boolean;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export type AutoNumberCell = number;
|
|
31
|
+
export interface AutoNumberFieldTypeAndOptions {
|
|
32
|
+
type: 'autoNumber';
|
|
33
|
+
}
|
|
34
|
+
export interface BarcodeCell {
|
|
35
|
+
type?: string;
|
|
36
|
+
text: string;
|
|
37
|
+
}
|
|
38
|
+
export interface BarcodeFieldTypeAndOptions {
|
|
39
|
+
type: 'barcode';
|
|
40
|
+
}
|
|
41
|
+
export interface ButtonCell {
|
|
42
|
+
label: string;
|
|
43
|
+
url: string | null;
|
|
44
|
+
}
|
|
45
|
+
export interface ButtonFieldTypeAndOptions {
|
|
46
|
+
type: 'button';
|
|
47
|
+
}
|
|
48
|
+
export type CheckboxCellV1 = true | 'empty';
|
|
49
|
+
export type CheckboxCellV2 = true | null;
|
|
50
|
+
export interface CheckboxFieldTypeAndOptions {
|
|
51
|
+
type: 'checkbox';
|
|
52
|
+
options: {
|
|
53
|
+
color: 'yellowBright' | 'orangeBright' | 'redBright' | 'pinkBright' | 'purpleBright' | 'blueBright' | 'cyanBright' | 'tealBright' | 'greenBright' | 'grayBright';
|
|
54
|
+
icon: 'check' | 'xCheckbox' | 'star' | 'heart' | 'thumbsUp' | 'flag' | 'dot';
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface CollaboratorCell {
|
|
58
|
+
id: string;
|
|
59
|
+
email?: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
profilePicUrl?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface SingleCollaboratorFieldTypeAndOptions {
|
|
64
|
+
type: 'singleCollaborator';
|
|
65
|
+
options: {};
|
|
66
|
+
}
|
|
67
|
+
export type CountCell = number;
|
|
68
|
+
export interface CountFieldTypeAndOptions {
|
|
69
|
+
type: 'count';
|
|
70
|
+
options: {
|
|
71
|
+
isValid: boolean;
|
|
72
|
+
recordLinkFieldId?: string | null;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export type CreatedByCell = CollaboratorCell;
|
|
76
|
+
export interface CreatedByFieldTypeAndOptions {
|
|
77
|
+
type: 'createdBy';
|
|
78
|
+
}
|
|
79
|
+
export type CreatedTimeCell = string;
|
|
80
|
+
export interface CreatedTimeFieldTypeAndOptions {
|
|
81
|
+
type: 'createdTime';
|
|
82
|
+
options: {
|
|
83
|
+
result?: any;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export type CurrencyCell = number;
|
|
87
|
+
export interface CurrencyFieldTypeAndOptions {
|
|
88
|
+
type: 'currency';
|
|
89
|
+
options: {
|
|
90
|
+
precision: number;
|
|
91
|
+
symbol: string;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export type DateCell = string;
|
|
95
|
+
export interface DateFormatOptions {
|
|
96
|
+
format: 'l' | 'LL' | 'M/D/YYYY' | 'D/M/YYYY' | 'YYYY-MM-DD';
|
|
97
|
+
name: 'local' | 'friendly' | 'us' | 'european' | 'iso';
|
|
98
|
+
}
|
|
99
|
+
export interface DateFieldTypeAndOptions {
|
|
100
|
+
type: 'date';
|
|
101
|
+
options: {
|
|
102
|
+
dateFormat: DateFormatOptions;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export type DateTimeCell = string;
|
|
106
|
+
export interface TimeFormatOptions {
|
|
107
|
+
format: 'h:mma' | 'HH:mm' | undefined;
|
|
108
|
+
name: '12hour' | '24hour';
|
|
109
|
+
}
|
|
110
|
+
export interface DateTimeFieldTypeAndOptions {
|
|
111
|
+
type: 'dateTime';
|
|
112
|
+
options: {
|
|
113
|
+
timeZone: string;
|
|
114
|
+
dateFormat: DateFormatOptions;
|
|
115
|
+
timeFormat: TimeFormatOptions;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export type DurationCell = number;
|
|
119
|
+
export interface DurationFieldTypeAndOptions {
|
|
120
|
+
type: 'duration';
|
|
121
|
+
options: {
|
|
122
|
+
durationFormat: 'h:mm' | 'h:mm:ss' | 'h:mm:ss.S' | 'h:mm:ss.SS' | 'h:mm:ss.SSS';
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export type EmailCell = string;
|
|
126
|
+
export interface EmailFieldTypeAndOptions {
|
|
127
|
+
type: 'email';
|
|
128
|
+
}
|
|
129
|
+
export type FormulaCell = string | number;
|
|
130
|
+
export interface FormulaFieldTypeAndOptions {
|
|
131
|
+
type: 'formula';
|
|
132
|
+
options: {
|
|
133
|
+
formula: string;
|
|
134
|
+
isValid: boolean;
|
|
135
|
+
referencedFieldIds: string[] | null;
|
|
136
|
+
result: any;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export type LastModifiedByCell = {
|
|
140
|
+
id: string;
|
|
141
|
+
email?: string;
|
|
142
|
+
name?: string;
|
|
143
|
+
profilePicUrl?: string;
|
|
144
|
+
};
|
|
145
|
+
export interface LastModifiedByFieldTypeAndOptions {
|
|
146
|
+
type: 'lastModifiedBy';
|
|
147
|
+
}
|
|
148
|
+
export type LastModifiedTimeCell = string;
|
|
149
|
+
export interface LastModifiedTimeFieldTypeAndOptions {
|
|
150
|
+
type: 'lastModifiedTime';
|
|
151
|
+
options: {
|
|
152
|
+
isValid: boolean;
|
|
153
|
+
referencedFieldIds: string[] | null;
|
|
154
|
+
result: any;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export type LinkToAnotherRecordCellV1 = string[];
|
|
158
|
+
export type LinkToAnotherRecordCellV2 = {
|
|
159
|
+
id: string;
|
|
160
|
+
name: string;
|
|
161
|
+
}[];
|
|
162
|
+
export interface LinkToAnotherRecordFieldTypeAndOptions {
|
|
163
|
+
type: 'multipleRecordLinks';
|
|
164
|
+
options: {
|
|
165
|
+
isReversed: boolean;
|
|
166
|
+
linkedTableId: string;
|
|
167
|
+
prefersSingleRecordLink: boolean;
|
|
168
|
+
inverseLinkFieldId?: string;
|
|
169
|
+
viewIdForRecordSelection?: string;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export type LongTextCell = string;
|
|
173
|
+
export interface LongTextFieldTypeAndOptions {
|
|
174
|
+
type: 'multilineText';
|
|
175
|
+
}
|
|
176
|
+
export type LookupCellV1 = (number | string | boolean | any)[];
|
|
177
|
+
export type LookupCellV2 = {
|
|
178
|
+
valuesByLinkedRecordId: {
|
|
179
|
+
[key: string]: any[];
|
|
180
|
+
};
|
|
181
|
+
linkedRecordIds: string[];
|
|
182
|
+
};
|
|
183
|
+
export interface LookupFieldTypeAndOptions {
|
|
184
|
+
type: 'lookup';
|
|
185
|
+
options: {
|
|
186
|
+
fieldIdInLinkedTable: string | null;
|
|
187
|
+
isValid: boolean;
|
|
188
|
+
recordLinkFieldId: string | null;
|
|
189
|
+
result: any;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
export type Collaborator = {
|
|
193
|
+
id: string;
|
|
194
|
+
email?: string;
|
|
195
|
+
name?: string;
|
|
196
|
+
profilePicUrl?: string;
|
|
197
|
+
};
|
|
198
|
+
export type Collaborators = Collaborator[];
|
|
199
|
+
export type ChoiceColor = 'blueLight2' | 'cyanLight2' | 'tealLight2' | 'greenLight2' | 'yellowLight2' | 'orangeLight2' | 'redLight2' | 'pinkLight2' | 'purpleLight2' | 'grayLight2' | 'blueLight1' | 'cyanLight1' | 'tealLight1' | 'greenLight1' | 'yellowLight1' | 'orangeLight1' | 'redLight1' | 'pinkLight1' | 'purpleLight1' | 'grayLight1' | 'blueBright' | 'cyanBright' | 'tealBright' | 'greenBright' | 'yellowBright' | 'orangeBright' | 'redBright' | 'pinkBright' | 'purpleBright' | 'grayBright' | 'blueDark1' | 'cyanDark1' | 'tealDark1' | 'greenDark1' | 'yellowDark1' | 'orangeDark1' | 'redDark1' | 'pinkDark1' | 'purpleDark1' | 'grayDark1';
|
|
200
|
+
export type Choice = {
|
|
201
|
+
id: string;
|
|
202
|
+
color?: ChoiceColor;
|
|
203
|
+
name: string;
|
|
204
|
+
};
|
|
205
|
+
export type SelectOptions = {
|
|
206
|
+
choices: Choice[];
|
|
207
|
+
};
|
|
208
|
+
export type RatingColor = 'yellowBright' | 'orangeBright' | 'redBright' | 'pinkBright' | 'purpleBright' | 'blueBright' | 'cyanBright' | 'tealBright' | 'greenBright' | 'grayBright';
|
|
209
|
+
export type RatingIcon = 'star' | 'heart' | 'thumbsUp' | 'flag' | 'dot';
|
|
210
|
+
export type RatingOptions = {
|
|
211
|
+
color: RatingColor;
|
|
212
|
+
icon: RatingIcon;
|
|
213
|
+
max: number;
|
|
214
|
+
};
|
|
215
|
+
export type RollupOptions = {
|
|
216
|
+
fieldIdInLinkedTable?: string;
|
|
217
|
+
recordLinkFieldId?: string;
|
|
218
|
+
result?: any;
|
|
219
|
+
isValid?: boolean;
|
|
220
|
+
referencedFieldIds?: string[];
|
|
221
|
+
};
|
|
222
|
+
export type ExternalSyncChoice = {
|
|
223
|
+
id: string;
|
|
224
|
+
color?: ChoiceColor;
|
|
225
|
+
name: string;
|
|
226
|
+
};
|
|
227
|
+
export type ExternalSyncOptions = {
|
|
228
|
+
choices: ExternalSyncChoice[];
|
|
229
|
+
};
|
|
230
|
+
export type SingleLineText = string | null;
|
|
231
|
+
export type MultilineText = string | null;
|
|
232
|
+
export type RichText = string;
|
|
233
|
+
export type SingleSelect = string;
|
|
234
|
+
export type MultipleSelects = string[];
|
|
235
|
+
export type MultipleLookupValues = string[];
|
|
236
|
+
export type Checkbox = boolean;
|
|
237
|
+
export type AirtableUrl = string | null;
|
|
238
|
+
export type AirtableEmail = string;
|
|
239
|
+
export type AirtableInteger = number | null;
|
|
240
|
+
export type Count = number;
|
|
241
|
+
export type Duration = number;
|
|
242
|
+
export type Formula = string | string[] | number;
|
|
243
|
+
export type MultipleRecordLinks = string[];
|
|
244
|
+
export type MultipleAttachments = Attachment[];
|
|
245
|
+
export type FormulaSingleReturn = string | number;
|
|
246
|
+
export type Rollup = string | number;
|
|
247
|
+
export type AutoNumber = number;
|
|
248
|
+
export type AirtableButton = {
|
|
249
|
+
label: string;
|
|
250
|
+
url: string;
|
|
251
|
+
};
|
|
252
|
+
export type LastModifiedTime = string;
|
|
253
|
+
export type CreatedTime = string;
|
|
254
|
+
export type DateTime = string;
|
|
255
|
+
export type PhoneNumber = string;
|
|
256
|
+
export type Currency = number;
|
|
257
|
+
export type Percent = number;
|
|
258
|
+
export interface Attachment {
|
|
259
|
+
id: string;
|
|
260
|
+
url: string;
|
|
261
|
+
filename: string;
|
|
262
|
+
size: number;
|
|
263
|
+
type: string;
|
|
264
|
+
thumbnails?: {
|
|
265
|
+
small?: Thumbnail;
|
|
266
|
+
large?: Thumbnail;
|
|
267
|
+
full?: Thumbnail;
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
export interface Thumbnail {
|
|
271
|
+
url: string;
|
|
272
|
+
width: number;
|
|
273
|
+
height: number;
|
|
274
|
+
}
|
|
275
|
+
export type UpserptRecords = {
|
|
276
|
+
records: {
|
|
277
|
+
id: string;
|
|
278
|
+
createdTime: string;
|
|
279
|
+
fields: unknown;
|
|
280
|
+
}[];
|
|
281
|
+
updatedRecords: string[];
|
|
282
|
+
createdRecords: string[];
|
|
283
|
+
};
|
|
284
|
+
export interface UpdateRecordsBody {
|
|
285
|
+
typecast: boolean;
|
|
286
|
+
records: UpdateRecords;
|
|
287
|
+
}
|
|
288
|
+
export interface UpdateRecordsBodyUpsert extends UpdateRecordsBody {
|
|
289
|
+
performUpsert: {
|
|
290
|
+
fieldsToMergeOn: FieldsToMergeOn;
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
export type BaseId = string;
|
|
294
|
+
export type TableId = string;
|
|
295
|
+
export type FieldsToMergeOn = string[];
|
|
296
|
+
export type ApiRequest = {
|
|
297
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
298
|
+
url: string;
|
|
299
|
+
apiKey: string;
|
|
300
|
+
body?: RequestBody;
|
|
301
|
+
};
|
|
302
|
+
export type RequestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
303
|
+
export interface RequestMethodProps {
|
|
304
|
+
url: string;
|
|
305
|
+
apiKey: string;
|
|
306
|
+
body?: RequestBody;
|
|
307
|
+
}
|
|
308
|
+
export type RequestBody = unknown;
|
|
309
|
+
export interface AirtableRecordRequest {
|
|
310
|
+
baseId: string;
|
|
311
|
+
tableId: string;
|
|
312
|
+
atId?: string;
|
|
313
|
+
body: RequestBody;
|
|
314
|
+
}
|
|
315
|
+
export interface UpdateAirtableRecordRequest {
|
|
316
|
+
atId?: string;
|
|
317
|
+
baseId: string;
|
|
318
|
+
tableId: string;
|
|
319
|
+
body?: RequestBody;
|
|
320
|
+
}
|
|
321
|
+
export interface RequestBodyWebsiteInfos {
|
|
322
|
+
fields: unknown;
|
|
323
|
+
}
|
|
324
|
+
export type UpdateRecord = {
|
|
325
|
+
fields: unknown;
|
|
326
|
+
};
|
|
327
|
+
export type UpdateRecords = UpdateRecord[];
|
|
328
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
type BaseId = string;
|
|
2
|
+
type TableIdOrName = string;
|
|
3
|
+
type Timezone = string;
|
|
4
|
+
type SortDirection = 'asc' | 'desc';
|
|
5
|
+
type CellFormat = 'json' | 'string';
|
|
6
|
+
type RecordMetadataOptions = 'commentCount';
|
|
7
|
+
interface SortObject {
|
|
8
|
+
field: string;
|
|
9
|
+
direction?: SortDirection;
|
|
10
|
+
}
|
|
11
|
+
export interface GetRecordsQueryParameters {
|
|
12
|
+
timeZone?: Timezone;
|
|
13
|
+
userLocale?: string;
|
|
14
|
+
pageSize?: number;
|
|
15
|
+
maxRecords?: number;
|
|
16
|
+
offset?: string;
|
|
17
|
+
view?: string;
|
|
18
|
+
sort?: SortObject[];
|
|
19
|
+
filterByFormula?: string;
|
|
20
|
+
cellFormat?: CellFormat;
|
|
21
|
+
fields?: string[];
|
|
22
|
+
returnFieldsByFieldId?: boolean;
|
|
23
|
+
recordMetadata?: RecordMetadataOptions[];
|
|
24
|
+
}
|
|
25
|
+
type RecordField = {
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
};
|
|
28
|
+
export interface AirtableBaseRecord {
|
|
29
|
+
id: string;
|
|
30
|
+
createdTime: string;
|
|
31
|
+
fields: RecordField;
|
|
32
|
+
}
|
|
33
|
+
export interface ListRecordsResponse {
|
|
34
|
+
offset?: string;
|
|
35
|
+
records: AirtableBaseRecord[];
|
|
36
|
+
}
|
|
37
|
+
export interface GetRecordQueryParameters {
|
|
38
|
+
cellFormat?: CellFormat;
|
|
39
|
+
returnFieldsByFieldId?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface GetRecordPathParameters {
|
|
42
|
+
baseId: BaseId;
|
|
43
|
+
tableIdOrName: TableIdOrName;
|
|
44
|
+
recordId: string;
|
|
45
|
+
}
|
|
46
|
+
export interface UpdatePathParameters {
|
|
47
|
+
baseId: BaseId;
|
|
48
|
+
tableIdOrName: TableIdOrName;
|
|
49
|
+
}
|
|
50
|
+
export interface PerformUpsert {
|
|
51
|
+
fieldsToMergeOn: string[];
|
|
52
|
+
}
|
|
53
|
+
export interface UpdateRecordsRequestBody {
|
|
54
|
+
performUpsert?: PerformUpsert;
|
|
55
|
+
returnFieldsByFieldId?: boolean;
|
|
56
|
+
typecast?: boolean;
|
|
57
|
+
records: AirtableBaseRecord[];
|
|
58
|
+
}
|
|
59
|
+
export interface UpsertResponse {
|
|
60
|
+
createdRecords: string[];
|
|
61
|
+
updatedRecords: string[];
|
|
62
|
+
records: AirtableBaseRecord[];
|
|
63
|
+
}
|
|
64
|
+
export interface UpdateRecordPathParameters {
|
|
65
|
+
baseId: BaseId;
|
|
66
|
+
tableIdOrName: TableIdOrName;
|
|
67
|
+
recordId: string;
|
|
68
|
+
}
|
|
69
|
+
export interface UpdateRecordRequestBody {
|
|
70
|
+
typecast?: boolean;
|
|
71
|
+
fields: RecordField;
|
|
72
|
+
}
|
|
73
|
+
export interface UpdateRecordResponse {
|
|
74
|
+
id: string;
|
|
75
|
+
createdTime: string;
|
|
76
|
+
fields: RecordField;
|
|
77
|
+
}
|
|
78
|
+
export interface CreateRecordsPathParameters {
|
|
79
|
+
baseId: BaseId;
|
|
80
|
+
tableIdOrName: TableIdOrName;
|
|
81
|
+
}
|
|
82
|
+
export interface CreateRecordsRequestBody {
|
|
83
|
+
fields?: RecordField;
|
|
84
|
+
records?: AirtableBaseRecord[];
|
|
85
|
+
returnFieldsByFieldId?: boolean;
|
|
86
|
+
typecast?: boolean;
|
|
87
|
+
}
|
|
88
|
+
export type UpdateRecordsRequestOptions = {
|
|
89
|
+
typecast?: boolean;
|
|
90
|
+
returnFieldsByFieldId?: boolean;
|
|
91
|
+
};
|
|
92
|
+
export interface CreateRecordResponse {
|
|
93
|
+
id: string;
|
|
94
|
+
createdTime: string;
|
|
95
|
+
fields: RecordField;
|
|
96
|
+
}
|
|
97
|
+
export interface CreateRecordsResponse {
|
|
98
|
+
records: CreateRecordResponse[];
|
|
99
|
+
}
|
|
100
|
+
export interface DeleteRecordsPathParameters {
|
|
101
|
+
baseId: BaseId;
|
|
102
|
+
tableIdOrName: TableIdOrName;
|
|
103
|
+
}
|
|
104
|
+
export interface DeleteRecordsQueryParameters {
|
|
105
|
+
records: string[];
|
|
106
|
+
}
|
|
107
|
+
export interface DeleteRecordResponse {
|
|
108
|
+
id: string;
|
|
109
|
+
deleted: true;
|
|
110
|
+
}
|
|
111
|
+
export interface DeleteRecordsResponse {
|
|
112
|
+
records: DeleteRecordResponse[];
|
|
113
|
+
}
|
|
114
|
+
export interface DeleteRecordPathParameters {
|
|
115
|
+
baseId: BaseId;
|
|
116
|
+
tableIdOrName: TableIdOrName;
|
|
117
|
+
recordId: string;
|
|
118
|
+
}
|
|
119
|
+
export interface SingleDeleteRecordResponse {
|
|
120
|
+
id: string;
|
|
121
|
+
deleted: true;
|
|
122
|
+
}
|
|
123
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export type UpserptRecords = {
|
|
2
|
+
records: {
|
|
3
|
+
id: string;
|
|
4
|
+
createdTime: string;
|
|
5
|
+
fields: unknown;
|
|
6
|
+
}[];
|
|
7
|
+
updatedRecords: string[];
|
|
8
|
+
createdRecords: string[];
|
|
9
|
+
};
|
|
10
|
+
export interface UpdateRecordsBody<Fields> {
|
|
11
|
+
typecast: boolean;
|
|
12
|
+
records: UpdateRecords<Fields>;
|
|
13
|
+
}
|
|
14
|
+
export interface UpdateRecordsBodyUpsert<Fields> extends UpdateRecordsBody<Fields> {
|
|
15
|
+
performUpsert: {
|
|
16
|
+
fieldsToMergeOn: FieldsToMergeOn;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export type BaseId = string;
|
|
20
|
+
export type TableId = string;
|
|
21
|
+
export type FieldsToMergeOn = string[];
|
|
22
|
+
export type ApiRequest = {
|
|
23
|
+
url: string;
|
|
24
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
25
|
+
apiKey: string;
|
|
26
|
+
body?: RequestBody;
|
|
27
|
+
};
|
|
28
|
+
export type RequestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
29
|
+
export interface RequestMethodProps {
|
|
30
|
+
url: string;
|
|
31
|
+
apiKey: string;
|
|
32
|
+
body?: RequestBody;
|
|
33
|
+
}
|
|
34
|
+
export type RequestBody = unknown;
|
|
35
|
+
export interface AirtableRecordRequest {
|
|
36
|
+
baseId: string;
|
|
37
|
+
tableId: string;
|
|
38
|
+
atId?: string;
|
|
39
|
+
body: RequestBody;
|
|
40
|
+
}
|
|
41
|
+
export interface UpdateAirtableRecordRequest {
|
|
42
|
+
atId?: string;
|
|
43
|
+
baseId: string;
|
|
44
|
+
tableId: string;
|
|
45
|
+
body?: RequestBody;
|
|
46
|
+
}
|
|
47
|
+
export interface RequestBodyWebsiteInfos {
|
|
48
|
+
fields: unknown;
|
|
49
|
+
}
|
|
50
|
+
export type UpdateRecord<Fields> = {
|
|
51
|
+
fields: Fields;
|
|
52
|
+
};
|
|
53
|
+
export type UpdateRecords<Fields> = UpdateRecord<Fields>[];
|
|
54
|
+
type FieldType = 'singleLineText' | 'checkbox';
|
|
55
|
+
type TableFieldOptions = {
|
|
56
|
+
color?: string;
|
|
57
|
+
icon?: string;
|
|
58
|
+
};
|
|
59
|
+
type FieldConfig = {
|
|
60
|
+
id?: string;
|
|
61
|
+
name: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
type: FieldType;
|
|
64
|
+
options?: TableFieldOptions;
|
|
65
|
+
};
|
|
66
|
+
export type BaseTableDetails = {
|
|
67
|
+
name: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
};
|
|
70
|
+
export type TableConfig = {
|
|
71
|
+
name: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
fields: FieldConfig[];
|
|
74
|
+
};
|
|
75
|
+
type ViewType = 'grid' | 'form' | 'calendar' | 'gallery' | 'kanban' | 'timeline' | 'block';
|
|
76
|
+
export type View = {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
type: ViewType;
|
|
80
|
+
visibleFieldIds?: string[];
|
|
81
|
+
};
|
|
82
|
+
export type TableModel = {
|
|
83
|
+
id: string;
|
|
84
|
+
primaryFieldId: string;
|
|
85
|
+
name: string;
|
|
86
|
+
description?: string;
|
|
87
|
+
fields: FieldConfig[];
|
|
88
|
+
views: View[];
|
|
89
|
+
};
|
|
90
|
+
export type UpdateTableRequestBody = {
|
|
91
|
+
name?: string;
|
|
92
|
+
description?: string;
|
|
93
|
+
};
|
|
94
|
+
export type CreateTableRequestBody = {
|
|
95
|
+
name: string;
|
|
96
|
+
description?: string;
|
|
97
|
+
fields: FieldConfig[];
|
|
98
|
+
};
|
|
99
|
+
export {};
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export type SingleLineText = string | null;
|
|
2
|
+
export type MultilineText = string | null;
|
|
3
|
+
export type RichText = string;
|
|
4
|
+
export type SingleSelect = string;
|
|
5
|
+
export type MultipleSelects = string[];
|
|
6
|
+
export type MultipleLookupValues = string[];
|
|
7
|
+
export type Checkbox = boolean;
|
|
8
|
+
export type AirtableUrl = string | null;
|
|
9
|
+
export type AirtableEmail = string;
|
|
10
|
+
export type AirtableInteger = number | null;
|
|
11
|
+
export type Count = number;
|
|
12
|
+
export type Duration = number;
|
|
13
|
+
export type Formula = string | string[] | number;
|
|
14
|
+
export type MultipleRecordLinks = string[];
|
|
15
|
+
export type MultipleAttachments = Attachment[];
|
|
16
|
+
export type FormulaSingleReturn = string | number;
|
|
17
|
+
export type Rollup = string | number;
|
|
18
|
+
export type AutoNumber = number;
|
|
19
|
+
export type AirtableButton = {
|
|
20
|
+
label: string;
|
|
21
|
+
url: string;
|
|
22
|
+
};
|
|
23
|
+
export type LastModifiedTime = string;
|
|
24
|
+
export type CreatedTime = string;
|
|
25
|
+
export type DateTime = string;
|
|
26
|
+
export type PhoneNumber = string;
|
|
27
|
+
export type Currency = number;
|
|
28
|
+
export type Percent = number;
|
|
29
|
+
export interface Attachment {
|
|
30
|
+
id: string;
|
|
31
|
+
url: string;
|
|
32
|
+
filename: string;
|
|
33
|
+
size: number;
|
|
34
|
+
type: string;
|
|
35
|
+
thumbnails?: {
|
|
36
|
+
small: Thumbnail;
|
|
37
|
+
large: Thumbnail;
|
|
38
|
+
full: Thumbnail;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface Thumbnail {
|
|
42
|
+
url: string;
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
}
|
|
46
|
+
export type UpserptRecords = {
|
|
47
|
+
records: {
|
|
48
|
+
id: string;
|
|
49
|
+
createdTime: string;
|
|
50
|
+
fields: unknown;
|
|
51
|
+
}[];
|
|
52
|
+
updatedRecords: string[];
|
|
53
|
+
createdRecords: string[];
|
|
54
|
+
};
|
|
55
|
+
export interface UpdateRecordsBody {
|
|
56
|
+
typecast: boolean;
|
|
57
|
+
records: UpdateRecords;
|
|
58
|
+
}
|
|
59
|
+
export interface UpdateRecordsBodyUpsert extends UpdateRecordsBody {
|
|
60
|
+
performUpsert: {
|
|
61
|
+
fieldsToMergeOn: FieldsToMergeOn;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export type BaseId = string;
|
|
65
|
+
export type TableId = string;
|
|
66
|
+
export type FieldsToMergeOn = string[];
|
|
67
|
+
export type ApiRequest = {
|
|
68
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
69
|
+
url: string;
|
|
70
|
+
apiKey: string;
|
|
71
|
+
body?: RequestBody;
|
|
72
|
+
};
|
|
73
|
+
export type RequestMethods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
74
|
+
export interface RequestMethodProps {
|
|
75
|
+
url: string;
|
|
76
|
+
apiKey: string;
|
|
77
|
+
body?: RequestBody;
|
|
78
|
+
}
|
|
79
|
+
export type RequestBody = unknown;
|
|
80
|
+
export interface AirtableRecordRequest {
|
|
81
|
+
baseId: string;
|
|
82
|
+
tableId: string;
|
|
83
|
+
atId?: string;
|
|
84
|
+
body: RequestBody;
|
|
85
|
+
}
|
|
86
|
+
export interface UpdateAirtableRecordRequest {
|
|
87
|
+
atId?: string;
|
|
88
|
+
baseId: string;
|
|
89
|
+
tableId: string;
|
|
90
|
+
body?: RequestBody;
|
|
91
|
+
}
|
|
92
|
+
export interface RequestBodyWebsiteInfos {
|
|
93
|
+
fields: unknown;
|
|
94
|
+
}
|
|
95
|
+
export type UpdateRecord = {
|
|
96
|
+
fields: unknown;
|
|
97
|
+
};
|
|
98
|
+
export type UpdateRecords = UpdateRecord[];
|
package/lib/types.js
ADDED
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UpdateRecords } from './types/fields';
|
|
2
|
+
export declare const getArrayInChunks: (records: UpdateRecords) => Promise<import("./types/fields").UpdateRecord[][]>;
|
|
3
|
+
export declare const getErrorMessage: (error: Error | unknown) => string;
|
|
4
|
+
export declare const delay: (ms?: number) => Promise<unknown>;
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.delay = exports.getErrorMessage = exports.getArrayInChunks = void 0;
|
|
13
|
+
const getArrayInChunks = (records) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const chunks = [];
|
|
15
|
+
const chunkSize = 10;
|
|
16
|
+
for (let i = 0; i < records.length; i += chunkSize) {
|
|
17
|
+
const chunk = records.slice(i, i + chunkSize);
|
|
18
|
+
chunks.push(chunk);
|
|
19
|
+
}
|
|
20
|
+
return chunks;
|
|
21
|
+
});
|
|
22
|
+
exports.getArrayInChunks = getArrayInChunks;
|
|
23
|
+
const getErrorMessage = (error) => {
|
|
24
|
+
if (error instanceof Error)
|
|
25
|
+
return error.message;
|
|
26
|
+
return String(error);
|
|
27
|
+
};
|
|
28
|
+
exports.getErrorMessage = getErrorMessage;
|
|
29
|
+
const delay = (ms = 0) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
return yield new Promise((resolve) => setTimeout(resolve, ms));
|
|
31
|
+
});
|
|
32
|
+
exports.delay = delay;
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-airtable-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "An easy way to connect to Airtable via their API.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
8
|
+
"watch": "tsc --watch",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
11
|
+
"test": "vitest"
|
|
9
12
|
},
|
|
10
13
|
"keywords": [
|
|
11
14
|
"airtable"
|
|
@@ -16,5 +19,33 @@
|
|
|
16
19
|
},
|
|
17
20
|
"homepage": "https://github.com/marcellocurto/easy-airtable-api",
|
|
18
21
|
"author": "Marcello Curto",
|
|
19
|
-
"license": "MIT"
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"prettier": {
|
|
24
|
+
"trailingComma": "es5",
|
|
25
|
+
"tabWidth": 2,
|
|
26
|
+
"useTabs": false,
|
|
27
|
+
"semi": true,
|
|
28
|
+
"singleQuote": true,
|
|
29
|
+
"proseWrap": "preserve",
|
|
30
|
+
"quoteProps": "as-needed",
|
|
31
|
+
"arrowParens": "always",
|
|
32
|
+
"bracketSpacing": true,
|
|
33
|
+
"endOfLine": "lf",
|
|
34
|
+
"htmlWhitespaceSensitivity": "css",
|
|
35
|
+
"insertPragma": false,
|
|
36
|
+
"singleAttributePerLine": false,
|
|
37
|
+
"bracketSameLine": false,
|
|
38
|
+
"jsxBracketSameLine": false,
|
|
39
|
+
"jsxSingleQuote": true,
|
|
40
|
+
"printWidth": 80
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "20.5.9",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "6.8.0",
|
|
45
|
+
"@typescript-eslint/parser": "6.8.0",
|
|
46
|
+
"dotenv": "^16.3.1",
|
|
47
|
+
"eslint": "8.51.0",
|
|
48
|
+
"typescript": "5.2.2",
|
|
49
|
+
"vitest": "0.34.4"
|
|
50
|
+
}
|
|
20
51
|
}
|
package/src/main.ts
DELETED
|
File without changes
|