@shushed/helpers 0.0.198-v2-20251113133839 → 0.0.198-v2-20251117103844

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: [this.dictionary[this.primaryKeyFieldName]],
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 {
@@ -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
  }
@@ -269,12 +269,12 @@ function createOnResponse(opts) {
269
269
  return (config, options) => onResponse(config, options, opts.requiredFlag);
270
270
  }
271
271
  function onResponse(config, options, requiredFlag) {
272
- options.logging.log('onResponse', config);
273
272
  const triggerOutput = options.root[options.triggerId || options.trigger?.id];
274
273
  const flags = triggerOutput?.flags;
275
274
  const numberOfInputMessages = triggerOutput?.body?.length ?? 0;
276
275
  const outputBody = config.outputs?.body;
277
276
  const outputStatus = config.outputs?.status;
277
+ requiredFlag = config.config?.requiredFlag || requiredFlag;
278
278
  let headersToSet = {};
279
279
  if (outputBody?.headersToSet) {
280
280
  headersToSet = outputBody.headersToSet;
@@ -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
- }>, callIdx?: number, collectedResult?: {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.198-v2-20251113133839",
3
+ "version": "0.0.198-v2-20251117103844",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",