@shushed/helpers 0.0.198-v2-20251114083458 → 0.0.198-v2-20251117105600
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.
|
@@ -42,7 +42,7 @@ class AirtableHelper extends runtime_1.default {
|
|
|
42
42
|
}
|
|
43
43
|
return existingRecord;
|
|
44
44
|
}
|
|
45
|
-
async updateMultiple(payload, callIdx = 0, collectedResult = {
|
|
45
|
+
async updateMultiple(payload, options = {}, callIdx = 0, collectedResult = {
|
|
46
46
|
updatedRecords: [],
|
|
47
47
|
createdRecords: [],
|
|
48
48
|
records: []
|
|
@@ -58,11 +58,11 @@ class AirtableHelper extends runtime_1.default {
|
|
|
58
58
|
},
|
|
59
59
|
body: JSON.stringify({
|
|
60
60
|
performUpsert: {
|
|
61
|
-
fieldsToMergeOn:
|
|
61
|
+
fieldsToMergeOn: (options.fieldsToMergeOn ?? [this.primaryKeyFieldName]).map(x => this.dictionary[x] || x),
|
|
62
62
|
},
|
|
63
63
|
returnFieldsByFieldId: true,
|
|
64
64
|
records: payload.slice(callIdx * 10, (callIdx + 1) * 10).map(x => ({
|
|
65
|
-
fields: AirtableHelper.convertToDictionary(this.dictionary, x),
|
|
65
|
+
fields: AirtableHelper.convertToDictionary(this.dictionary, this.primaryKeyWritable === false ? AirtableHelper.removePrimaryKey(x, this.primaryKeyFieldName) : x),
|
|
66
66
|
}))
|
|
67
67
|
}),
|
|
68
68
|
});
|
|
@@ -77,7 +77,7 @@ class AirtableHelper extends runtime_1.default {
|
|
|
77
77
|
records: collectedResult.records.concat(resp.records.map(x => AirtableHelper.translateFields(this.dictionary, x)))
|
|
78
78
|
};
|
|
79
79
|
if (payload.length > (callIdx + 1) * 10) {
|
|
80
|
-
return this.updateMultiple(payload, callIdx + 1, nextCollectedResult);
|
|
80
|
+
return this.updateMultiple(payload, options, callIdx + 1, nextCollectedResult);
|
|
81
81
|
}
|
|
82
82
|
return nextCollectedResult;
|
|
83
83
|
}
|
|
@@ -210,6 +210,27 @@ class AirtableHelper extends runtime_1.default {
|
|
|
210
210
|
const existingRecords = ((await responseRecords.json())?.records || []);
|
|
211
211
|
return existingRecords.map(x => AirtableHelper.translateFields(this.dictionary, x));
|
|
212
212
|
}
|
|
213
|
+
async getExistingRecordsByKeys(keys) {
|
|
214
|
+
const result = new Map();
|
|
215
|
+
if (keys.length === 0) {
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
const escapeFormulaValue = (value) => {
|
|
219
|
+
return value.replace(/"/g, '\\"');
|
|
220
|
+
};
|
|
221
|
+
const batchSize = 50;
|
|
222
|
+
for (let i = 0; i < keys.length; i += batchSize) {
|
|
223
|
+
const batch = keys.slice(i, i + batchSize);
|
|
224
|
+
const orConditions = batch.map(key => `${this.dictionary[this.primaryKeyFieldName]} = "${escapeFormulaValue(key)}"`).join(', ');
|
|
225
|
+
const formula = `OR(${orConditions})`;
|
|
226
|
+
const records = await this.getExistingRecords(formula);
|
|
227
|
+
for (const record of records) {
|
|
228
|
+
const key = record.fields[this.primaryKeyFieldName];
|
|
229
|
+
result.set(key, record);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
213
234
|
async pingWebhook(webhook) {
|
|
214
235
|
let resp;
|
|
215
236
|
try {
|
|
@@ -363,7 +363,7 @@ class EnvEngine extends runtime_1.default {
|
|
|
363
363
|
return false;
|
|
364
364
|
}
|
|
365
365
|
if (meta.aud !== expectedAudience) {
|
|
366
|
-
const receivedMoreSpecific = (expectedAudience + '-' + this.workflowId + '-' + this.triggerId) === meta.aud || (expectedAudience + '-' + this.workflowId) === meta.aud;
|
|
366
|
+
const receivedMoreSpecific = (expectedAudience + '-' + this.workflowId + '-' + this.triggerId) === meta.aud || (expectedAudience + '-' + this.workflowId) === meta.aud || (expectedAudience + '/' + this.workflowId + '/' + this.triggerId) === meta.aud || (expectedAudience + '/' + this.workflowId) === meta.aud;
|
|
367
367
|
if (!receivedMoreSpecific) {
|
|
368
368
|
this.logging.error(`Authorization header - Wrong audience, got ${meta?.aud}, expected ${expectedAudience}`);
|
|
369
369
|
return false;
|
|
@@ -656,7 +656,7 @@ class EnvEngine extends runtime_1.default {
|
|
|
656
656
|
const rawRequestBody = co_body_1.default.text(nodeReq, {
|
|
657
657
|
limit: '2mb'
|
|
658
658
|
});
|
|
659
|
-
requestBody = await (rawRequestBody.then(x => JSON.parse(x)).catch(err => {
|
|
659
|
+
requestBody = await (rawRequestBody.then(x => JSON.parse(x || 'null')).catch(err => {
|
|
660
660
|
throw new Error('Could not parse the request of the body. Body provided: ' + requestBody + '. Error message: ' + err.message);
|
|
661
661
|
}));
|
|
662
662
|
}
|
|
@@ -35,7 +35,10 @@ declare class AirtableHelper<T extends Record<string, string>, K extends keyof T
|
|
|
35
35
|
[key in keyof T]: any;
|
|
36
36
|
}> & {
|
|
37
37
|
[prumaryKeyFieldName in K]: string;
|
|
38
|
-
}>,
|
|
38
|
+
}>, options?: {
|
|
39
|
+
fieldsToMergeOn?: Array<keyof T>;
|
|
40
|
+
primaryKeyWritable?: boolean;
|
|
41
|
+
}, callIdx?: number, collectedResult?: {
|
|
39
42
|
updatedRecords: Array<string>;
|
|
40
43
|
createdRecords: Array<string>;
|
|
41
44
|
records: Array<{
|
|
@@ -106,6 +109,12 @@ declare class AirtableHelper<T extends Record<string, string>, K extends keyof T
|
|
|
106
109
|
[key in keyof T]: any;
|
|
107
110
|
};
|
|
108
111
|
}>>;
|
|
112
|
+
getExistingRecordsByKeys(keys: Array<string>): Promise<Map<string, {
|
|
113
|
+
id: string;
|
|
114
|
+
fields: {
|
|
115
|
+
[key in keyof T]: any;
|
|
116
|
+
};
|
|
117
|
+
}>>;
|
|
109
118
|
pingWebhook(webhook: {
|
|
110
119
|
webhook: {
|
|
111
120
|
id: string;
|