@shushed/helpers 0.0.198-v2-20251117161322 → 0.0.198-v2-20251121121601
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/dist/cjs/dist-dereferenced/asset.js +1 -1
- package/dist/cjs/dist-dereferenced/development-colour.js +1 -1
- package/dist/cjs/src-public/airtable.js +50 -25
- package/dist/cjs/src-public/utils.js +1 -1
- package/dist/types/dist-dereferenced/asset.d.ts +17 -0
- package/dist/types/dist-dereferenced/development-colour.d.ts +17 -0
- package/dist/types/dist-types/asset.d.ts +7 -0
- package/dist/types/dist-types/development-colour.d.ts +7 -0
- package/dist/types/src-public/airtable.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Asset", "type": "object", "additionalProperties": false, "properties": { "source_url": { "type": "string" }, "last_modified_at": { "type": "string", "format": "date-time" }, "width": { "type": "integer", "minimum": 0 }, "height": { "type": "integer", "minimum": 0 }, "content_type": { "type": "string", "pattern": "^[a-z0-9-/]+$" }, "file_name": { "type": "string", "pattern": "^[a-z0-9-.]+$" } }, "required": ["source_url", "content_type", "last_modified_at"], "$id": "https://shushed.example.com/asset.json" };
|
|
3
|
+
const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Asset", "type": "object", "additionalProperties": false, "properties": { "product_id": { "type": "string" }, "dash_id": { "type": "string" }, "dash_folder_path": { "type": "string" }, "source_url": { "type": "string" }, "created_at": { "type": "string", "format": "date-time" }, "last_modified_at": { "type": "string", "format": "date-time" }, "width": { "type": "integer", "minimum": 0 }, "height": { "type": "integer", "minimum": 0 }, "meta": { "type": "object", "additionalProperties": true }, "content_type": { "type": "string", "pattern": "^[a-z0-9-/]+$" }, "file_name": { "type": "string", "pattern": "^[a-z0-9-.]+$" } }, "required": ["source_url", "content_type", "last_modified_at"], "$id": "https://shushed.example.com/asset.json" };
|
|
4
4
|
exports.default = schema;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Development Colour", "type": "object", "additionalProperties": false, "properties": { "colour_id": { "type": "string" }, "name": { "type": ["string", "null"] }, "rgb": { "anyOf": [{ "type": "null" }, { "type": "array", "items": { "type": "number" } }] }, "cmyk": { "anyOf": [{ "type": "null" }, { "type": "array", "items": { "type": "number" } }] }, "pantone": { "anyOf": [{ "type": "null" }, { "type": "object", "properties": { "name": { "type": "string" }, "system": { "type": "string", "pattern": "^[A-Z0-9-]+$" }, "id": { "type": "string", "pattern": "^[A-Z0-9-]+$" } } }] }, "display_name": { "type": ["string", "null"], "pattern": "^[ a-z-]+$" }, "family_display_name": { "type": ["string", "null"], "pattern": "^[ a-z]+$" }, "source_asset": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Asset", "type": "object", "additionalProperties": false, "properties": { "source_url": { "type": "string" }, "last_modified_at": { "type": "string", "format": "date-time" }, "width": { "type": "integer", "minimum": 0 }, "height": { "type": "integer", "minimum": 0 }, "content_type": { "type": "string", "pattern": "^[a-z0-9-/]+$" }, "file_name": { "type": "string", "pattern": "^[a-z0-9-.]+$" } }, "required": ["source_url", "content_type", "last_modified_at"] } }, "required": ["colour_id"], "$id": "https://shushed.example.com/development-colour.schema.json" };
|
|
3
|
+
const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Development Colour", "type": "object", "additionalProperties": false, "properties": { "colour_id": { "type": "string" }, "name": { "type": ["string", "null"] }, "rgb": { "anyOf": [{ "type": "null" }, { "type": "array", "items": { "type": "number" } }] }, "cmyk": { "anyOf": [{ "type": "null" }, { "type": "array", "items": { "type": "number" } }] }, "pantone": { "anyOf": [{ "type": "null" }, { "type": "object", "properties": { "name": { "type": "string" }, "system": { "type": "string", "pattern": "^[A-Z0-9-]+$" }, "id": { "type": "string", "pattern": "^[A-Z0-9-]+$" } } }] }, "display_name": { "type": ["string", "null"], "pattern": "^[ a-z-]+$" }, "family_display_name": { "type": ["string", "null"], "pattern": "^[ a-z]+$" }, "source_asset": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Asset", "type": "object", "additionalProperties": false, "properties": { "product_id": { "type": "string" }, "dash_id": { "type": "string" }, "dash_folder_path": { "type": "string" }, "source_url": { "type": "string" }, "created_at": { "type": "string", "format": "date-time" }, "last_modified_at": { "type": "string", "format": "date-time" }, "width": { "type": "integer", "minimum": 0 }, "height": { "type": "integer", "minimum": 0 }, "meta": { "type": "object", "additionalProperties": true }, "content_type": { "type": "string", "pattern": "^[a-z0-9-/]+$" }, "file_name": { "type": "string", "pattern": "^[a-z0-9-.]+$" } }, "required": ["source_url", "content_type", "last_modified_at"] } }, "required": ["colour_id"], "$id": "https://shushed.example.com/development-colour.schema.json" };
|
|
4
4
|
exports.default = schema;
|
|
@@ -62,9 +62,20 @@ class AirtableHelper extends runtime_1.default {
|
|
|
62
62
|
fieldsToMergeOn: (options.fieldsToMergeOn ?? [this.primaryKeyFieldName]).map(x => this.dictionary[x] || x),
|
|
63
63
|
},
|
|
64
64
|
returnFieldsByFieldId: true,
|
|
65
|
-
records: currentBatch.map(x =>
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
records: currentBatch.map(x => {
|
|
66
|
+
const recordId = x.$recordId;
|
|
67
|
+
const fieldsWithoutRecordId = { ...x };
|
|
68
|
+
delete fieldsWithoutRecordId.$recordId;
|
|
69
|
+
const record = {
|
|
70
|
+
fields: AirtableHelper.convertToDictionary(this.dictionary, this.primaryKeyWritable === false
|
|
71
|
+
? AirtableHelper.removePrimaryKey(fieldsWithoutRecordId, this.primaryKeyFieldName)
|
|
72
|
+
: fieldsWithoutRecordId),
|
|
73
|
+
};
|
|
74
|
+
if (recordId) {
|
|
75
|
+
record.id = recordId;
|
|
76
|
+
}
|
|
77
|
+
return record;
|
|
78
|
+
})
|
|
68
79
|
}),
|
|
69
80
|
});
|
|
70
81
|
if (!response.ok && response) {
|
|
@@ -148,7 +159,6 @@ class AirtableHelper extends runtime_1.default {
|
|
|
148
159
|
async updateRecord(recordId, payload) {
|
|
149
160
|
let response = null;
|
|
150
161
|
const tableUrl = `https://api.airtable.com/v0/${this.baseId}/${this.tableId}`;
|
|
151
|
-
console.log(recordId, AirtableHelper.removePrimaryKey(AirtableHelper.convertToDictionary(this.dictionary, payload), this.dictionary[this.primaryKeyFieldName]));
|
|
152
162
|
try {
|
|
153
163
|
response = await fetch(`${tableUrl}/${recordId}`, {
|
|
154
164
|
method: "PATCH",
|
|
@@ -199,27 +209,42 @@ class AirtableHelper extends runtime_1.default {
|
|
|
199
209
|
throw new Error(`Failed to obtain records with the id: ${id} from the ${this.tableId} table and the baseId ${this.baseId}. Status Code: ${responseRecords?.status || 'unknown'}. Error: ${err.message}`);
|
|
200
210
|
}
|
|
201
211
|
}
|
|
202
|
-
async getExistingRecords(formula) {
|
|
203
|
-
|
|
212
|
+
async getExistingRecords(formula = '') {
|
|
213
|
+
const allRecords = [];
|
|
214
|
+
let offset = undefined;
|
|
204
215
|
const tableUrl = `https://api.airtable.com/v0/${this.baseId}/${this.tableId}`;
|
|
205
|
-
|
|
206
|
-
responseRecords =
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
+
do {
|
|
217
|
+
let responseRecords = null;
|
|
218
|
+
try {
|
|
219
|
+
responseRecords = await fetch(tableUrl, {
|
|
220
|
+
method: 'POST',
|
|
221
|
+
body: JSON.stringify({
|
|
222
|
+
filterByFormula: formula,
|
|
223
|
+
offset: offset,
|
|
224
|
+
pageSize: 100,
|
|
225
|
+
returnFieldsByFieldId: true,
|
|
226
|
+
fields: Object.values(this.dictionary),
|
|
227
|
+
}),
|
|
228
|
+
headers: {
|
|
229
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
230
|
+
"Content-Type": "application/json",
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
if (!responseRecords.ok && responseRecords) {
|
|
234
|
+
const text = await responseRecords.text().catch(() => `${responseRecords?.status || 'unknown'}`);
|
|
235
|
+
throw new Error(text);
|
|
236
|
+
}
|
|
237
|
+
const data = await responseRecords.json();
|
|
238
|
+
const records = data?.records || [];
|
|
239
|
+
allRecords.push(...records);
|
|
240
|
+
offset = data?.offset;
|
|
216
241
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return
|
|
242
|
+
catch (err) {
|
|
243
|
+
const formulaMsg = formula ? `with the formula ${formula}` : 'from all records';
|
|
244
|
+
throw new Error(`Failed to obtain records ${formulaMsg} from the ${this.tableId} table and the baseId ${this.baseId}. Status Code: ${responseRecords?.status || 'unknown'}. Error: ${err.message}`);
|
|
245
|
+
}
|
|
246
|
+
} while (offset);
|
|
247
|
+
return allRecords.map(x => AirtableHelper.translateFields(this.dictionary, x));
|
|
223
248
|
}
|
|
224
249
|
async getExistingRecordsByKeys(keys) {
|
|
225
250
|
const result = new Map();
|
|
@@ -293,7 +318,7 @@ class AirtableHelper extends runtime_1.default {
|
|
|
293
318
|
url: nextUrl.toString()
|
|
294
319
|
};
|
|
295
320
|
}
|
|
296
|
-
this.logging.log(`Collected ${collectedRecords.length} records
|
|
321
|
+
this.logging.log(`Collected ${collectedRecords.length} records`);
|
|
297
322
|
if (!res.fields && res.records) {
|
|
298
323
|
collectedRecords = res.records.map((x) => AirtableHelper.translateFields(this.dictionary, x));
|
|
299
324
|
}
|
|
@@ -346,7 +371,7 @@ class AirtableHelper extends runtime_1.default {
|
|
|
346
371
|
if (!unprocessedResult) {
|
|
347
372
|
const res = (await resp.json());
|
|
348
373
|
nextCursor = res.cursor;
|
|
349
|
-
this.logging.log(`Received ${res.payloads.length} records from the table: ${this.tableId}
|
|
374
|
+
this.logging.log(`Received ${res.payloads.length} records from the table: ${this.tableId}.`);
|
|
350
375
|
for (const payload of res.payloads) {
|
|
351
376
|
const changes = payload.changedTablesById[this.tableId];
|
|
352
377
|
const airtableCreated = Object.entries(changes?.createdRecordsById || {}).map(([k, v]) => ({
|
|
@@ -311,7 +311,7 @@ function onResponse(config, options, requiredFlag) {
|
|
|
311
311
|
return Object.assign({}, x, { body: redactedResponse });
|
|
312
312
|
}
|
|
313
313
|
if (x.body instanceof Error) {
|
|
314
|
-
return Object.assign({}, x, { message: x.body.message, error: true });
|
|
314
|
+
return Object.assign({}, x, { body: { message: x.body.message, error: true } });
|
|
315
315
|
}
|
|
316
316
|
return x;
|
|
317
317
|
}
|
|
@@ -4,9 +4,22 @@ declare const schema: {
|
|
|
4
4
|
readonly type: "object";
|
|
5
5
|
readonly additionalProperties: false;
|
|
6
6
|
readonly properties: {
|
|
7
|
+
readonly product_id: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
};
|
|
10
|
+
readonly dash_id: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
};
|
|
13
|
+
readonly dash_folder_path: {
|
|
14
|
+
readonly type: "string";
|
|
15
|
+
};
|
|
7
16
|
readonly source_url: {
|
|
8
17
|
readonly type: "string";
|
|
9
18
|
};
|
|
19
|
+
readonly created_at: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
readonly format: "date-time";
|
|
22
|
+
};
|
|
10
23
|
readonly last_modified_at: {
|
|
11
24
|
readonly type: "string";
|
|
12
25
|
readonly format: "date-time";
|
|
@@ -19,6 +32,10 @@ declare const schema: {
|
|
|
19
32
|
readonly type: "integer";
|
|
20
33
|
readonly minimum: 0;
|
|
21
34
|
};
|
|
35
|
+
readonly meta: {
|
|
36
|
+
readonly type: "object";
|
|
37
|
+
readonly additionalProperties: true;
|
|
38
|
+
};
|
|
22
39
|
readonly content_type: {
|
|
23
40
|
readonly type: "string";
|
|
24
41
|
readonly pattern: "^[a-z0-9-/]+$";
|
|
@@ -64,9 +64,22 @@ declare const schema: {
|
|
|
64
64
|
readonly type: "object";
|
|
65
65
|
readonly additionalProperties: false;
|
|
66
66
|
readonly properties: {
|
|
67
|
+
readonly product_id: {
|
|
68
|
+
readonly type: "string";
|
|
69
|
+
};
|
|
70
|
+
readonly dash_id: {
|
|
71
|
+
readonly type: "string";
|
|
72
|
+
};
|
|
73
|
+
readonly dash_folder_path: {
|
|
74
|
+
readonly type: "string";
|
|
75
|
+
};
|
|
67
76
|
readonly source_url: {
|
|
68
77
|
readonly type: "string";
|
|
69
78
|
};
|
|
79
|
+
readonly created_at: {
|
|
80
|
+
readonly type: "string";
|
|
81
|
+
readonly format: "date-time";
|
|
82
|
+
};
|
|
70
83
|
readonly last_modified_at: {
|
|
71
84
|
readonly type: "string";
|
|
72
85
|
readonly format: "date-time";
|
|
@@ -79,6 +92,10 @@ declare const schema: {
|
|
|
79
92
|
readonly type: "integer";
|
|
80
93
|
readonly minimum: 0;
|
|
81
94
|
};
|
|
95
|
+
readonly meta: {
|
|
96
|
+
readonly type: "object";
|
|
97
|
+
readonly additionalProperties: true;
|
|
98
|
+
};
|
|
82
99
|
readonly content_type: {
|
|
83
100
|
readonly type: "string";
|
|
84
101
|
readonly pattern: "^[a-z0-9-/]+$";
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
export interface __MainSchema {
|
|
2
|
+
product_id?: string;
|
|
3
|
+
dash_id?: string;
|
|
4
|
+
dash_folder_path?: string;
|
|
2
5
|
source_url: string;
|
|
6
|
+
created_at?: string;
|
|
3
7
|
last_modified_at: string;
|
|
4
8
|
width?: number;
|
|
5
9
|
height?: number;
|
|
10
|
+
meta?: {
|
|
11
|
+
[k: string]: unknown;
|
|
12
|
+
};
|
|
6
13
|
content_type: string;
|
|
7
14
|
file_name?: string;
|
|
8
15
|
}
|
|
@@ -14,10 +14,17 @@ export interface __MainSchema {
|
|
|
14
14
|
source_asset?: Asset;
|
|
15
15
|
}
|
|
16
16
|
export interface Asset {
|
|
17
|
+
product_id?: string;
|
|
18
|
+
dash_id?: string;
|
|
19
|
+
dash_folder_path?: string;
|
|
17
20
|
source_url: string;
|
|
21
|
+
created_at?: string;
|
|
18
22
|
last_modified_at: string;
|
|
19
23
|
width?: number;
|
|
20
24
|
height?: number;
|
|
25
|
+
meta?: {
|
|
26
|
+
[k: string]: unknown;
|
|
27
|
+
};
|
|
21
28
|
content_type: string;
|
|
22
29
|
file_name?: string;
|
|
23
30
|
}
|
|
@@ -103,7 +103,7 @@ declare class AirtableHelper<T extends Record<string, string>, K extends keyof T
|
|
|
103
103
|
[key in keyof T]: any;
|
|
104
104
|
};
|
|
105
105
|
}>;
|
|
106
|
-
getExistingRecords(formula
|
|
106
|
+
getExistingRecords(formula?: string): Promise<Array<{
|
|
107
107
|
id: string;
|
|
108
108
|
fields: {
|
|
109
109
|
[key in keyof T]: any;
|