@shushed/helpers 0.0.306 → 0.0.307-airtable-read-fields-20260409151637

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.
@@ -14,6 +14,7 @@ class AirtableHelper extends runtime_1.default {
14
14
  primaryKeyFieldName;
15
15
  primaryKeyWritable = true;
16
16
  viewId;
17
+ readDictionary;
17
18
  constructor(opts, airtableOpts) {
18
19
  super(opts);
19
20
  this.baseId = airtableOpts.baseId;
@@ -27,6 +28,7 @@ class AirtableHelper extends runtime_1.default {
27
28
  if (typeof airtableOpts.viewId !== 'undefined') {
28
29
  this.viewId = airtableOpts.viewId;
29
30
  }
31
+ this.readDictionary = airtableOpts.readFieldIds;
30
32
  }
31
33
  static normalizeWebhookCellValues(cellValuesByFieldId) {
32
34
  const isSelectOption = (v) => v && typeof v === 'object' && !Array.isArray(v) && typeof v.id === 'string' && v.id.startsWith('sel');
@@ -492,16 +494,17 @@ class AirtableHelper extends runtime_1.default {
492
494
  const changes = this.viewId
493
495
  ? payload.changedTablesById?.[this.tableId]?.changedViewsById?.[this.viewId]
494
496
  : payload.changedTablesById?.[this.tableId];
497
+ const combinedDictionary = { ...this.dictionary, ...this.readDictionary };
495
498
  const airtableCreated = Object.entries(changes?.createdRecordsById || {}).map(([k, v]) => ({
496
499
  id: k,
497
- fields: AirtableHelper.translateFields(this.dictionary, { fields: AirtableHelper.normalizeWebhookCellValues(v.cellValuesByFieldId || {}) }).fields,
500
+ fields: AirtableHelper.translateFields(combinedDictionary, { fields: AirtableHelper.normalizeWebhookCellValues(v.cellValuesByFieldId || {}) }).fields,
498
501
  created_at: v.createdTime || payload.timestamp,
499
502
  last_modified_at: v.createdTime || payload.timestamp,
500
503
  previous_fields: null
501
504
  }));
502
505
  const airtableChanged = Object.entries(changes?.changedRecordsById || {}).map(([k, v]) => ({
503
506
  id: k,
504
- fields: AirtableHelper.translateFields(this.dictionary, {
507
+ fields: AirtableHelper.translateFields(combinedDictionary, {
505
508
  fields: AirtableHelper.normalizeWebhookCellValues(Object.assign({}, v.unchanged?.cellValuesByFieldId, v.current?.cellValuesByFieldId))
506
509
  }).fields,
507
510
  last_modified_at: payload.timestamp
@@ -650,10 +653,11 @@ class AirtableHelper extends runtime_1.default {
650
653
  async webhookHasChanged() {
651
654
  const existingWebhook = await this.getWebhook();
652
655
  const fieldIds = Object.values(this.dictionary).filter((x, idx, arr) => arr.indexOf(x) === idx);
656
+ const includeFieldIds = [...fieldIds, ...Object.values(this.readDictionary ?? {})].filter((x, idx, arr) => arr.indexOf(x) === idx);
653
657
  const expectedScope = this.viewId || this.tableId;
654
658
  if (existingWebhook?.specification.options.filters.recordChangeScope === expectedScope
655
659
  && (0, lodash_isequal_1.default)(existingWebhook?.specification.options.filters.watchDataInFieldIds, fieldIds)
656
- && (0, lodash_isequal_1.default)(existingWebhook?.specification.options.includes?.includeCellValuesInFieldIds, fieldIds)
660
+ && (0, lodash_isequal_1.default)(existingWebhook?.specification.options.includes?.includeCellValuesInFieldIds, includeFieldIds)
657
661
  && existingWebhook.specification.options.includes?.includePreviousCellValues) {
658
662
  return false;
659
663
  }
@@ -662,10 +666,11 @@ class AirtableHelper extends runtime_1.default {
662
666
  async updateOrCreateWebhook() {
663
667
  const existingWebhook = await this.getWebhook();
664
668
  const fieldIds = Object.values(this.dictionary).filter((x, idx, arr) => arr.indexOf(x) === idx);
669
+ const includeFieldIds = [...fieldIds, ...Object.values(this.readDictionary ?? {})].filter((x, idx, arr) => arr.indexOf(x) === idx);
665
670
  const recordChangeScope = this.viewId || this.tableId;
666
671
  if (existingWebhook?.specification.options.filters.recordChangeScope === recordChangeScope
667
672
  && (0, lodash_isequal_1.default)(existingWebhook?.specification.options.filters.watchDataInFieldIds, fieldIds)
668
- && (0, lodash_isequal_1.default)(existingWebhook?.specification.options.includes?.includeCellValuesInFieldIds, fieldIds)
673
+ && (0, lodash_isequal_1.default)(existingWebhook?.specification.options.includes?.includeCellValuesInFieldIds, includeFieldIds)
669
674
  && existingWebhook.specification.options.includes?.includePreviousCellValues) {
670
675
  return existingWebhook;
671
676
  }
@@ -685,7 +690,7 @@ class AirtableHelper extends runtime_1.default {
685
690
  },
686
691
  includes: {
687
692
  includePreviousCellValues: true,
688
- includeCellValuesInFieldIds: fieldIds
693
+ includeCellValuesInFieldIds: includeFieldIds
689
694
  }
690
695
  },
691
696
  }
@@ -601,12 +601,6 @@ function transformMasterOrder(payload) {
601
601
  if (code === 'TRACKED48') {
602
602
  return 'EVRI';
603
603
  }
604
- if (code === 'HSHERMES48') {
605
- return 'EVRI';
606
- }
607
- if (code === 'HSHERMES24') {
608
- return 'EVRI';
609
- }
610
604
  if (code === 'EVRID') {
611
605
  return 'EVRI';
612
606
  }
@@ -670,7 +664,7 @@ function transformMasterOrder(payload) {
670
664
  const shipDiscGross = isFirstShipment ? deliveryDiscountGrossMinor : 0;
671
665
  const shipDiscNet = isFirstShipment ? deliveryDiscountNetMinor : 0;
672
666
  const statusVal = shipmentLines.length > 0 ? "SHIPPED" : "PENDING";
673
- const result = {
667
+ return {
674
668
  erp_id: s.no || s.system_id || "",
675
669
  shipped_at: normalizeDateTime(s.shipment_date),
676
670
  status: statusVal,
@@ -687,12 +681,6 @@ function transformMasterOrder(payload) {
687
681
  discount_amount_gross: moneyFromMinor(shipDiscGross),
688
682
  discount_amount_percent: 0,
689
683
  };
690
- if (!result.courier_name && result.tracking_code) {
691
- if (result.tracking_code.startsWith('H0')) {
692
- result.courier_name = 'EVRI';
693
- }
694
- }
695
- return result;
696
684
  });
697
685
  const shipmentsBySku = new Map();
698
686
  (payload.shipments || []).forEach((s) => {
@@ -13,6 +13,7 @@ declare class AirtableHelper<T extends Record<string, string>, K extends keyof T
13
13
  primaryKeyFieldName: K;
14
14
  primaryKeyWritable: boolean;
15
15
  viewId?: string;
16
+ readDictionary?: Record<string, string>;
16
17
  constructor(opts: RuntimeOpts, airtableOpts: {
17
18
  baseId: string;
18
19
  tableId: string;
@@ -21,6 +22,7 @@ declare class AirtableHelper<T extends Record<string, string>, K extends keyof T
21
22
  primaryKeyFieldName: K;
22
23
  primaryKeyWritable?: boolean;
23
24
  viewId?: string;
25
+ readFieldIds?: Record<string, string>;
24
26
  });
25
27
  static normalizeWebhookCellValues(cellValuesByFieldId: Record<string, any>): Record<string, any>;
26
28
  static translateFields<T extends Record<string, string>, S extends {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.306",
3
+ "version": "0.0.307-airtable-read-fields-20260409151637",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",