@shushed/helpers 0.0.237 → 0.0.238-main-20260121134257

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.
@@ -56,6 +56,7 @@ class AirtableHelper extends runtime_1.default {
56
56
  let callIdx = 0;
57
57
  const payloadDeduplicated = payload.filter((x, idx, self) => idx === self.findIndex((t) => fieldsToMergeOn.every(field => (0, lodash_isequal_1.default)(t[field], x[field]))));
58
58
  const maxCallIdx = Math.ceil(payloadDeduplicated.length / batchSize);
59
+ let attemptNum = 0;
59
60
  while (callIdx < maxCallIdx) {
60
61
  const currentBatch = payloadDeduplicated.slice(callIdx * batchSize, (callIdx + 1) * batchSize);
61
62
  const recordsInBatch = currentBatch.map(x => {
@@ -89,8 +90,16 @@ class AirtableHelper extends runtime_1.default {
89
90
  }),
90
91
  });
91
92
  if (!response.ok && response) {
92
- const text = await response.text().catch(() => `${response?.status || 'unknown'}`);
93
- throw new Error(text);
93
+ const jsonResponse = await response.json().catch(() => `${response?.status || 'unknown'}`);
94
+ if (typeof jsonResponse === 'object' && jsonResponse.error && jsonResponse.error.type === 'RETRIABLE_ERROR' && attemptNum < 3) {
95
+ attemptNum += 1;
96
+ await new Promise(resolve => setTimeout(resolve, 100));
97
+ continue;
98
+ }
99
+ throw new Error(typeof jsonResponse === 'string' ? jsonResponse : JSON.stringify(jsonResponse));
100
+ }
101
+ else {
102
+ attemptNum = 0;
94
103
  }
95
104
  const resp = (await response.json());
96
105
  collectedResult = {
@@ -100,6 +109,7 @@ class AirtableHelper extends runtime_1.default {
100
109
  };
101
110
  }
102
111
  catch (err) {
112
+ callIdx += 1;
103
113
  const errorMessage = `Failed to update records in ${this.tableId} table (baseId: ${this.baseId}). Status: ${response?.status || 'unknown'}. Error: ${err.message}`;
104
114
  const batchErrors = currentBatch.map(() => new Error(errorMessage));
105
115
  collectedResult = {
@@ -108,9 +118,6 @@ class AirtableHelper extends runtime_1.default {
108
118
  records: collectedResult.records.concat(batchErrors)
109
119
  };
110
120
  }
111
- finally {
112
- callIdx += 1;
113
- }
114
121
  }
115
122
  const resultInOrder = [];
116
123
  for (let i = 0; i < payload.length; i++) {
@@ -399,5 +399,35 @@ class DatoHelper extends runtime_1.default {
399
399
  throw err;
400
400
  }
401
401
  }
402
+ async updateProductColour(productId, colour) {
403
+ try {
404
+ const res = await fetch(`${this.baseUrl}/items/${productId}`, {
405
+ method: "PATCH",
406
+ headers: {
407
+ Authorization: `Bearer ${this.apiToken}`,
408
+ "X-Api-Version": "3",
409
+ "X-Environment": this.environment,
410
+ "Content-Type": "application/vnd.api+json",
411
+ Accept: "application/json",
412
+ },
413
+ body: JSON.stringify({
414
+ data: {
415
+ type: "item",
416
+ id: productId,
417
+ attributes: { colour },
418
+ },
419
+ }),
420
+ });
421
+ if (!res.ok) {
422
+ const errorText = await res.text();
423
+ throw new Error(`Failed to update product colour: ${res.status} ${res.statusText} - ${errorText}`);
424
+ }
425
+ return await res.json();
426
+ }
427
+ catch (err) {
428
+ this.logging.error(`updateProductColour failed: ${err.message}`);
429
+ throw err;
430
+ }
431
+ }
402
432
  }
403
433
  exports.default = DatoHelper;
@@ -58,5 +58,6 @@ export default class DatoHelper extends Runtime {
58
58
  getProductBySku(sku: string): Promise<any>;
59
59
  createProduct(sku: string, productTypeId: string): Promise<any>;
60
60
  updateProductGallery(productId: string, gallery: any[]): Promise<any>;
61
+ updateProductColour(productId: string, colour: any): Promise<any>;
61
62
  }
62
63
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.237",
3
+ "version": "0.0.238-main-20260121134257",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",