easy-airtable-api 0.0.2 → 0.0.4
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 +11 -0
- package/lib/cjs/index.js +10 -0
- package/lib/cjs/requests.js +186 -0
- package/lib/{utils.js → cjs/utils.js} +1 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/requests.js +177 -0
- package/lib/esm/types/bases.js +1 -0
- package/lib/esm/types/fields.js +1 -0
- package/lib/esm/types/records.js +1 -0
- package/lib/esm/types/tables.js +1 -0
- package/lib/esm/utils.js +26 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/requests.d.ts +46 -0
- package/lib/types/{bases.d.ts → types/bases.d.ts} +5 -4
- package/lib/types/{records.d.ts → types/records.d.ts} +8 -0
- package/package.json +22 -13
- package/tsconfig.cjs.json +23 -0
- package/tsconfig.esm.json +23 -0
- package/lib/main.d.ts +0 -31
- package/lib/main.js +0 -131
- package/lib/records.d.ts +0 -11
- package/lib/records.js +0 -46
- package/lib/requests.d.ts +0 -2
- package/lib/requests.js +0 -52
- package/lib/types/bases.js +0 -1
- package/lib/types.d.ts +0 -98
- /package/lib/{types.js → cjs/types/bases.js} +0 -0
- /package/lib/{types → cjs/types}/fields.js +0 -0
- /package/lib/{types → cjs/types}/records.js +0 -0
- /package/lib/{types → cjs/types}/tables.js +0 -0
- /package/lib/types/{fields.d.ts → types/fields.d.ts} +0 -0
- /package/lib/types/{tables.d.ts → types/tables.d.ts} +0 -0
- /package/lib/{utils.d.ts → types/utils.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -16,6 +16,17 @@ npm install easy-airtable-api
|
|
|
16
16
|
|
|
17
17
|
## Changelog
|
|
18
18
|
|
|
19
|
+
### 0.0.4
|
|
20
|
+
|
|
21
|
+
- Export all available methods
|
|
22
|
+
- Restucture lib folder to not have duplicate types.
|
|
23
|
+
|
|
24
|
+
### 0.0.3
|
|
25
|
+
|
|
26
|
+
- ESM & CJS builds.
|
|
27
|
+
- Server error handling.
|
|
28
|
+
- Generic field types.
|
|
29
|
+
|
|
19
30
|
### 0.0.2
|
|
20
31
|
|
|
21
32
|
- Basic request functions to get or update records.
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceRecords = exports.replaceRecord = exports.updateRecords = exports.updateRecord = exports.getRecords = exports.getRecord = void 0;
|
|
4
|
+
var requests_1 = require("./requests");
|
|
5
|
+
Object.defineProperty(exports, "getRecord", { enumerable: true, get: function () { return requests_1.getRecord; } });
|
|
6
|
+
Object.defineProperty(exports, "getRecords", { enumerable: true, get: function () { return requests_1.getRecords; } });
|
|
7
|
+
Object.defineProperty(exports, "updateRecord", { enumerable: true, get: function () { return requests_1.updateRecord; } });
|
|
8
|
+
Object.defineProperty(exports, "updateRecords", { enumerable: true, get: function () { return requests_1.updateRecords; } });
|
|
9
|
+
Object.defineProperty(exports, "replaceRecord", { enumerable: true, get: function () { return requests_1.replaceRecord; } });
|
|
10
|
+
Object.defineProperty(exports, "replaceRecords", { enumerable: true, get: function () { return requests_1.replaceRecords; } });
|
|
@@ -0,0 +1,186 @@
|
|
|
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.replaceRecords = exports.replaceRecord = exports.updateRecords = exports.updateRecord = exports.getRecords = exports.getRecord = void 0;
|
|
13
|
+
const https_1 = require("https");
|
|
14
|
+
const url_1 = require("url");
|
|
15
|
+
function getRecord(_a) {
|
|
16
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, recordId, }) {
|
|
17
|
+
return airtableRequest({
|
|
18
|
+
apiKey,
|
|
19
|
+
baseId,
|
|
20
|
+
tableId,
|
|
21
|
+
endpoint: `/${recordId}`,
|
|
22
|
+
method: 'GET',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.getRecord = getRecord;
|
|
27
|
+
function getRecords(_a) {
|
|
28
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, options, }) {
|
|
29
|
+
return airtableRequest({
|
|
30
|
+
apiKey,
|
|
31
|
+
baseId,
|
|
32
|
+
tableId,
|
|
33
|
+
endpoint: '/listRecords',
|
|
34
|
+
method: 'POST',
|
|
35
|
+
body: options,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.getRecords = getRecords;
|
|
40
|
+
function updateRecord(_a) {
|
|
41
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, recordId, fields, }) {
|
|
42
|
+
return airtableRequest({
|
|
43
|
+
apiKey,
|
|
44
|
+
baseId,
|
|
45
|
+
tableId,
|
|
46
|
+
endpoint: `/${recordId}`,
|
|
47
|
+
method: 'PATCH',
|
|
48
|
+
body: { fields },
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
exports.updateRecord = updateRecord;
|
|
53
|
+
function updateRecords(_a) {
|
|
54
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, records, options, }) {
|
|
55
|
+
if (!Array.isArray(records) || records.length === 0) {
|
|
56
|
+
throw new Error('The records array is empty or not provided. Please provide a non-empty array of records to update.');
|
|
57
|
+
}
|
|
58
|
+
return airtableRequest({
|
|
59
|
+
apiKey,
|
|
60
|
+
baseId,
|
|
61
|
+
tableId,
|
|
62
|
+
endpoint: '/',
|
|
63
|
+
method: 'PATCH',
|
|
64
|
+
body: Object.assign({ records }, options),
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.updateRecords = updateRecords;
|
|
69
|
+
function replaceRecord(_a) {
|
|
70
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, recordId, fields, }) {
|
|
71
|
+
return airtableRequest({
|
|
72
|
+
apiKey,
|
|
73
|
+
baseId,
|
|
74
|
+
tableId,
|
|
75
|
+
endpoint: `/${recordId}`,
|
|
76
|
+
method: 'PUT',
|
|
77
|
+
body: { fields },
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.replaceRecord = replaceRecord;
|
|
82
|
+
function replaceRecords(_a) {
|
|
83
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, records, }) {
|
|
84
|
+
if (!Array.isArray(records) || records.length === 0) {
|
|
85
|
+
throw new Error('The records array is empty or not provided. Please provide a non-empty array of records to replace.');
|
|
86
|
+
}
|
|
87
|
+
return airtableRequest({
|
|
88
|
+
apiKey,
|
|
89
|
+
baseId,
|
|
90
|
+
tableId,
|
|
91
|
+
endpoint: '/',
|
|
92
|
+
method: 'PUT',
|
|
93
|
+
body: { records },
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
exports.replaceRecords = replaceRecords;
|
|
98
|
+
function airtableRequest(request) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const { apiKey, baseId, tableId, endpoint, method, body, apiURL } = request;
|
|
101
|
+
const url = apiURL || 'https://api.airtable.com/v0';
|
|
102
|
+
if (!apiKey) {
|
|
103
|
+
throw new Error('API key is not set. Please provide a valid Airtable API key.');
|
|
104
|
+
}
|
|
105
|
+
if (!baseId) {
|
|
106
|
+
throw new Error('Base ID is not set. Please provide a valid Airtable base ID.');
|
|
107
|
+
}
|
|
108
|
+
if (!tableId) {
|
|
109
|
+
throw new Error('Table ID/Name is not set. Please provide a valid Airtable table ID or name.');
|
|
110
|
+
}
|
|
111
|
+
const response = yield apiRequest({
|
|
112
|
+
url: `${url}/${baseId}/${tableId}${endpoint}`,
|
|
113
|
+
apiKey,
|
|
114
|
+
method,
|
|
115
|
+
body,
|
|
116
|
+
});
|
|
117
|
+
validateResponse(response);
|
|
118
|
+
return response.data;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function validateResponse(response) {
|
|
122
|
+
const statusCode = response.statusCode;
|
|
123
|
+
console.log(response);
|
|
124
|
+
if (statusCode === 200)
|
|
125
|
+
return;
|
|
126
|
+
if (statusCode === 401)
|
|
127
|
+
throw new Error('Wrong API Key.');
|
|
128
|
+
else if (statusCode === 403)
|
|
129
|
+
throw new Error('NOT_AUTHORIZED');
|
|
130
|
+
else if (statusCode === 404)
|
|
131
|
+
throw new Error('NOT_FOUND');
|
|
132
|
+
else if (statusCode === 413)
|
|
133
|
+
throw new Error('Request body is too large');
|
|
134
|
+
else if (statusCode === 422)
|
|
135
|
+
throw new Error('Operation cannot be processed');
|
|
136
|
+
else if (statusCode === 429)
|
|
137
|
+
throw new Error('TOO_MANY_REQUESTS');
|
|
138
|
+
else if (statusCode === 500)
|
|
139
|
+
throw new Error('SERVER_ERROR');
|
|
140
|
+
else if (statusCode === 503)
|
|
141
|
+
throw new Error('SERVICE_UNAVAILABLE');
|
|
142
|
+
throw new Error('UNEXPECTED_ERROR');
|
|
143
|
+
}
|
|
144
|
+
function apiRequest(_a) {
|
|
145
|
+
return __awaiter(this, arguments, void 0, function* ({ url, method, apiKey, body, }) {
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
const parsedUrl = new url_1.URL(url);
|
|
148
|
+
const { hostname, pathname, search } = parsedUrl;
|
|
149
|
+
const options = {
|
|
150
|
+
method,
|
|
151
|
+
hostname,
|
|
152
|
+
path: `${pathname}${search}`,
|
|
153
|
+
timeout: 300000,
|
|
154
|
+
headers: {
|
|
155
|
+
'Content-Type': 'application/json',
|
|
156
|
+
Authorization: `Bearer ${apiKey}`,
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
const req = (0, https_1.request)(options, (res) => {
|
|
160
|
+
let data = '';
|
|
161
|
+
res.on('data', (chunk) => {
|
|
162
|
+
data += chunk;
|
|
163
|
+
});
|
|
164
|
+
res.on('end', () => {
|
|
165
|
+
try {
|
|
166
|
+
resolve({
|
|
167
|
+
data: JSON.parse(data),
|
|
168
|
+
statusCode: res.statusCode,
|
|
169
|
+
statusMessage: res.statusMessage,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
reject(new Error(`Failed to parse response as JSON: ${data}`));
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
req.on('error', (error) => {
|
|
178
|
+
reject(new Error(`airtableApi: ${error.message} (fn_${apiRequest.name})`));
|
|
179
|
+
});
|
|
180
|
+
if (body) {
|
|
181
|
+
req.write(JSON.stringify(body));
|
|
182
|
+
}
|
|
183
|
+
req.end();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
@@ -26,7 +26,7 @@ const getErrorMessage = (error) => {
|
|
|
26
26
|
return String(error);
|
|
27
27
|
};
|
|
28
28
|
exports.getErrorMessage = getErrorMessage;
|
|
29
|
-
const delay = (
|
|
29
|
+
const delay = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (ms = 0) {
|
|
30
30
|
return yield new Promise((resolve) => setTimeout(resolve, ms));
|
|
31
31
|
});
|
|
32
32
|
exports.delay = delay;
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getRecord, getRecords, updateRecord, updateRecords, replaceRecord, replaceRecords, } from './requests';
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { request } from 'https';
|
|
11
|
+
import { URL } from 'url';
|
|
12
|
+
export function getRecord(_a) {
|
|
13
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, recordId, }) {
|
|
14
|
+
return airtableRequest({
|
|
15
|
+
apiKey,
|
|
16
|
+
baseId,
|
|
17
|
+
tableId,
|
|
18
|
+
endpoint: `/${recordId}`,
|
|
19
|
+
method: 'GET',
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function getRecords(_a) {
|
|
24
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, options, }) {
|
|
25
|
+
return airtableRequest({
|
|
26
|
+
apiKey,
|
|
27
|
+
baseId,
|
|
28
|
+
tableId,
|
|
29
|
+
endpoint: '/listRecords',
|
|
30
|
+
method: 'POST',
|
|
31
|
+
body: options,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export function updateRecord(_a) {
|
|
36
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, recordId, fields, }) {
|
|
37
|
+
return airtableRequest({
|
|
38
|
+
apiKey,
|
|
39
|
+
baseId,
|
|
40
|
+
tableId,
|
|
41
|
+
endpoint: `/${recordId}`,
|
|
42
|
+
method: 'PATCH',
|
|
43
|
+
body: { fields },
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function updateRecords(_a) {
|
|
48
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, records, options, }) {
|
|
49
|
+
if (!Array.isArray(records) || records.length === 0) {
|
|
50
|
+
throw new Error('The records array is empty or not provided. Please provide a non-empty array of records to update.');
|
|
51
|
+
}
|
|
52
|
+
return airtableRequest({
|
|
53
|
+
apiKey,
|
|
54
|
+
baseId,
|
|
55
|
+
tableId,
|
|
56
|
+
endpoint: '/',
|
|
57
|
+
method: 'PATCH',
|
|
58
|
+
body: Object.assign({ records }, options),
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export function replaceRecord(_a) {
|
|
63
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, recordId, fields, }) {
|
|
64
|
+
return airtableRequest({
|
|
65
|
+
apiKey,
|
|
66
|
+
baseId,
|
|
67
|
+
tableId,
|
|
68
|
+
endpoint: `/${recordId}`,
|
|
69
|
+
method: 'PUT',
|
|
70
|
+
body: { fields },
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export function replaceRecords(_a) {
|
|
75
|
+
return __awaiter(this, arguments, void 0, function* ({ apiKey, baseId, tableId, records, }) {
|
|
76
|
+
if (!Array.isArray(records) || records.length === 0) {
|
|
77
|
+
throw new Error('The records array is empty or not provided. Please provide a non-empty array of records to replace.');
|
|
78
|
+
}
|
|
79
|
+
return airtableRequest({
|
|
80
|
+
apiKey,
|
|
81
|
+
baseId,
|
|
82
|
+
tableId,
|
|
83
|
+
endpoint: '/',
|
|
84
|
+
method: 'PUT',
|
|
85
|
+
body: { records },
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function airtableRequest(request) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const { apiKey, baseId, tableId, endpoint, method, body, apiURL } = request;
|
|
92
|
+
const url = apiURL || 'https://api.airtable.com/v0';
|
|
93
|
+
if (!apiKey) {
|
|
94
|
+
throw new Error('API key is not set. Please provide a valid Airtable API key.');
|
|
95
|
+
}
|
|
96
|
+
if (!baseId) {
|
|
97
|
+
throw new Error('Base ID is not set. Please provide a valid Airtable base ID.');
|
|
98
|
+
}
|
|
99
|
+
if (!tableId) {
|
|
100
|
+
throw new Error('Table ID/Name is not set. Please provide a valid Airtable table ID or name.');
|
|
101
|
+
}
|
|
102
|
+
const response = yield apiRequest({
|
|
103
|
+
url: `${url}/${baseId}/${tableId}${endpoint}`,
|
|
104
|
+
apiKey,
|
|
105
|
+
method,
|
|
106
|
+
body,
|
|
107
|
+
});
|
|
108
|
+
validateResponse(response);
|
|
109
|
+
return response.data;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function validateResponse(response) {
|
|
113
|
+
const statusCode = response.statusCode;
|
|
114
|
+
console.log(response);
|
|
115
|
+
if (statusCode === 200)
|
|
116
|
+
return;
|
|
117
|
+
if (statusCode === 401)
|
|
118
|
+
throw new Error('Wrong API Key.');
|
|
119
|
+
else if (statusCode === 403)
|
|
120
|
+
throw new Error('NOT_AUTHORIZED');
|
|
121
|
+
else if (statusCode === 404)
|
|
122
|
+
throw new Error('NOT_FOUND');
|
|
123
|
+
else if (statusCode === 413)
|
|
124
|
+
throw new Error('Request body is too large');
|
|
125
|
+
else if (statusCode === 422)
|
|
126
|
+
throw new Error('Operation cannot be processed');
|
|
127
|
+
else if (statusCode === 429)
|
|
128
|
+
throw new Error('TOO_MANY_REQUESTS');
|
|
129
|
+
else if (statusCode === 500)
|
|
130
|
+
throw new Error('SERVER_ERROR');
|
|
131
|
+
else if (statusCode === 503)
|
|
132
|
+
throw new Error('SERVICE_UNAVAILABLE');
|
|
133
|
+
throw new Error('UNEXPECTED_ERROR');
|
|
134
|
+
}
|
|
135
|
+
function apiRequest(_a) {
|
|
136
|
+
return __awaiter(this, arguments, void 0, function* ({ url, method, apiKey, body, }) {
|
|
137
|
+
return new Promise((resolve, reject) => {
|
|
138
|
+
const parsedUrl = new URL(url);
|
|
139
|
+
const { hostname, pathname, search } = parsedUrl;
|
|
140
|
+
const options = {
|
|
141
|
+
method,
|
|
142
|
+
hostname,
|
|
143
|
+
path: `${pathname}${search}`,
|
|
144
|
+
timeout: 300000,
|
|
145
|
+
headers: {
|
|
146
|
+
'Content-Type': 'application/json',
|
|
147
|
+
Authorization: `Bearer ${apiKey}`,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
const req = request(options, (res) => {
|
|
151
|
+
let data = '';
|
|
152
|
+
res.on('data', (chunk) => {
|
|
153
|
+
data += chunk;
|
|
154
|
+
});
|
|
155
|
+
res.on('end', () => {
|
|
156
|
+
try {
|
|
157
|
+
resolve({
|
|
158
|
+
data: JSON.parse(data),
|
|
159
|
+
statusCode: res.statusCode,
|
|
160
|
+
statusMessage: res.statusMessage,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
reject(new Error(`Failed to parse response as JSON: ${data}`));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
req.on('error', (error) => {
|
|
169
|
+
reject(new Error(`airtableApi: ${error.message} (fn_${apiRequest.name})`));
|
|
170
|
+
});
|
|
171
|
+
if (body) {
|
|
172
|
+
req.write(JSON.stringify(body));
|
|
173
|
+
}
|
|
174
|
+
req.end();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/esm/utils.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export const getArrayInChunks = (records) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
const chunks = [];
|
|
12
|
+
const chunkSize = 10;
|
|
13
|
+
for (let i = 0; i < records.length; i += chunkSize) {
|
|
14
|
+
const chunk = records.slice(i, i + chunkSize);
|
|
15
|
+
chunks.push(chunk);
|
|
16
|
+
}
|
|
17
|
+
return chunks;
|
|
18
|
+
});
|
|
19
|
+
export const getErrorMessage = (error) => {
|
|
20
|
+
if (error instanceof Error)
|
|
21
|
+
return error.message;
|
|
22
|
+
return String(error);
|
|
23
|
+
};
|
|
24
|
+
export const delay = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (ms = 0) {
|
|
25
|
+
return yield new Promise((resolve) => setTimeout(resolve, ms));
|
|
26
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getRecord, getRecords, updateRecord, updateRecords, replaceRecord, replaceRecords, } from './requests';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AirtableRecord, GetRecordsQueryParameters, UpdateRecordsRequestOptions } from './types/records';
|
|
2
|
+
export declare function getRecord<Fields>({ apiKey, baseId, tableId, recordId, }: {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
baseId: string;
|
|
5
|
+
tableId: string;
|
|
6
|
+
recordId: string;
|
|
7
|
+
}): Promise<AirtableRecord<Fields>>;
|
|
8
|
+
export declare function getRecords<Fields>({ apiKey, baseId, tableId, options, }: {
|
|
9
|
+
apiKey: string;
|
|
10
|
+
baseId: string;
|
|
11
|
+
tableId: string;
|
|
12
|
+
options: GetRecordsQueryParameters;
|
|
13
|
+
}): Promise<AirtableRecord<Fields>[]>;
|
|
14
|
+
export declare function updateRecord<Fields>({ apiKey, baseId, tableId, recordId, fields, }: {
|
|
15
|
+
apiKey: string;
|
|
16
|
+
baseId: string;
|
|
17
|
+
tableId: string;
|
|
18
|
+
recordId: string;
|
|
19
|
+
fields: object;
|
|
20
|
+
}): Promise<AirtableRecord<Fields>>;
|
|
21
|
+
export declare function updateRecords<Fields>({ apiKey, baseId, tableId, records, options, }: {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
baseId: string;
|
|
24
|
+
tableId: string;
|
|
25
|
+
records: {
|
|
26
|
+
id: string;
|
|
27
|
+
fields: object;
|
|
28
|
+
}[];
|
|
29
|
+
options?: UpdateRecordsRequestOptions;
|
|
30
|
+
}): Promise<AirtableRecord<Fields>[]>;
|
|
31
|
+
export declare function replaceRecord<Fields>({ apiKey, baseId, tableId, recordId, fields, }: {
|
|
32
|
+
apiKey: string;
|
|
33
|
+
baseId: string;
|
|
34
|
+
tableId: string;
|
|
35
|
+
recordId: string;
|
|
36
|
+
fields: object;
|
|
37
|
+
}): Promise<AirtableRecord<Fields>>;
|
|
38
|
+
export declare function replaceRecords<Fields>({ apiKey, baseId, tableId, records, }: {
|
|
39
|
+
apiKey: string;
|
|
40
|
+
baseId: string;
|
|
41
|
+
tableId: string;
|
|
42
|
+
records: {
|
|
43
|
+
id: string;
|
|
44
|
+
fields: object;
|
|
45
|
+
}[];
|
|
46
|
+
}): Promise<AirtableRecord<Fields>[]>;
|
|
@@ -3,7 +3,7 @@ type BaseList = {
|
|
|
3
3
|
name: string;
|
|
4
4
|
permissionLevel: 'none' | 'read' | 'comment' | 'edit' | 'create';
|
|
5
5
|
};
|
|
6
|
-
type ListBasesResponse = {
|
|
6
|
+
export type ListBasesResponse = {
|
|
7
7
|
bases: BaseList[];
|
|
8
8
|
offset?: string;
|
|
9
9
|
};
|
|
@@ -33,7 +33,7 @@ type Table = {
|
|
|
33
33
|
primaryFieldId: string;
|
|
34
34
|
views: TableView[];
|
|
35
35
|
};
|
|
36
|
-
type GetBaseSchemaResponse = {
|
|
36
|
+
export type GetBaseSchemaResponse = {
|
|
37
37
|
tables: Table[];
|
|
38
38
|
};
|
|
39
39
|
type TableConfigFieldOptions = {
|
|
@@ -51,12 +51,13 @@ type BasesTableConfig = {
|
|
|
51
51
|
fields: TableConfigField[];
|
|
52
52
|
name: string;
|
|
53
53
|
};
|
|
54
|
-
type CreateBaseRequestBody = {
|
|
54
|
+
export type CreateBaseRequestBody = {
|
|
55
55
|
name: string;
|
|
56
56
|
tables: BasesTableConfig[];
|
|
57
57
|
workspaceId: string;
|
|
58
58
|
};
|
|
59
|
-
type CreateBaseResponse = {
|
|
59
|
+
export type CreateBaseResponse = {
|
|
60
60
|
id: string;
|
|
61
61
|
tables: Table[];
|
|
62
62
|
};
|
|
63
|
+
export {};
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export type AirtableRecord<Fields = DefaultFieldsType> = {
|
|
2
|
+
id: string;
|
|
3
|
+
createdTime: string;
|
|
4
|
+
fields: Fields;
|
|
5
|
+
};
|
|
6
|
+
type DefaultFieldsType = {
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
};
|
|
1
9
|
type BaseId = string;
|
|
2
10
|
type TableIdOrName = string;
|
|
3
11
|
type Timezone = string;
|
package/package.json
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-airtable-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "An easy way to connect to Airtable via their API.",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
5
|
+
"main": "lib/cjs/index.js",
|
|
6
|
+
"module": "lib/esm/index.js",
|
|
7
|
+
"types": "lib/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./lib/cjs/index.js",
|
|
11
|
+
"import": "./lib/esm/index.js",
|
|
12
|
+
"types": "./lib/types/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"scripts": {
|
|
8
16
|
"watch": "tsc --watch",
|
|
9
|
-
"build": "tsc",
|
|
17
|
+
"build": "rm -r ./lib && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
|
|
18
|
+
"publish": "npm publish",
|
|
10
19
|
"lint": "eslint 'src/**/*.{ts,tsx}'",
|
|
11
20
|
"test": "vitest"
|
|
12
21
|
},
|
|
@@ -17,7 +26,7 @@
|
|
|
17
26
|
"type": "git",
|
|
18
27
|
"url": "https://github.com/marcellocurto/easy-airtable-api.git"
|
|
19
28
|
},
|
|
20
|
-
"homepage": "https://
|
|
29
|
+
"homepage": "https://marcellocurto.com/code/easy-airtable-api",
|
|
21
30
|
"author": "Marcello Curto",
|
|
22
31
|
"license": "MIT",
|
|
23
32
|
"prettier": {
|
|
@@ -40,12 +49,12 @@
|
|
|
40
49
|
"printWidth": 80
|
|
41
50
|
},
|
|
42
51
|
"devDependencies": {
|
|
43
|
-
"@types/node": "20.
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "
|
|
45
|
-
"@typescript-eslint/parser": "
|
|
46
|
-
"dotenv": "^16.
|
|
47
|
-
"eslint": "8.
|
|
48
|
-
"typescript": "5.
|
|
49
|
-
"vitest": "
|
|
52
|
+
"@types/node": "^20.11.30",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
54
|
+
"@typescript-eslint/parser": "^7.3.1",
|
|
55
|
+
"dotenv": "^16.4.5",
|
|
56
|
+
"eslint": "^8.57.0",
|
|
57
|
+
"typescript": "^5.4.3",
|
|
58
|
+
"vitest": "^1.4.0"
|
|
50
59
|
}
|
|
51
|
-
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es6",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./lib/cjs",
|
|
8
|
+
"declarationDir": "./lib/types",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"skipLibCheck": false,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"types": [
|
|
13
|
+
"node"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"src/**/*.ts"
|
|
18
|
+
],
|
|
19
|
+
"exclude": [
|
|
20
|
+
"lib",
|
|
21
|
+
"node_modules"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es6",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./lib/esm",
|
|
8
|
+
"declarationDir": "./lib/types",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"skipLibCheck": false,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"types": [
|
|
13
|
+
"node"
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"src/**/*.ts"
|
|
18
|
+
],
|
|
19
|
+
"exclude": [
|
|
20
|
+
"lib",
|
|
21
|
+
"node_modules"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/lib/main.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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.d.ts
DELETED
package/lib/requests.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
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;
|
package/lib/types/bases.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/lib/types.d.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
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[];
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|