@shushed/helpers 0.0.226 → 0.0.227-main-20260107085003
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/contracts/index.js +1 -5
- package/dist/cjs/contracts/product-draft.schema.json +5 -159
- package/dist/cjs/dist-dereferenced/index.js +1 -5
- package/dist/cjs/dist-dereferenced/messages/product-draft.js +1 -1
- package/dist/cjs/dist-dereferenced/product-draft.js +1 -1
- package/dist/cjs/src-public/airtable.js +59 -96
- package/dist/cjs/src-public/bcOrder.js +77 -60
- package/dist/cjs/src-public/centra.js +5 -56
- package/dist/cjs/src-public/env.js +1 -1
- package/dist/cjs/src-public/index.js +1 -3
- package/dist/cjs/src-public/pubsub.js +10 -35
- package/dist/cjs/src-public/runtime.js +9 -48
- package/dist/cjs/src-public/utils.js +0 -3
- package/dist/package.json +2 -3
- package/dist/types/contracts/index.d.ts +0 -2
- package/dist/types/dist-dereferenced/index.d.ts +0 -2
- package/dist/types/dist-dereferenced/messages/product-draft.d.ts +1 -148
- package/dist/types/dist-dereferenced/product-draft.d.ts +1 -148
- package/dist/types/dist-types/index.d.ts +0 -2
- package/dist/types/dist-types/messages/product-draft.d.ts +4 -23
- package/dist/types/dist-types/product-draft.d.ts +4 -23
- package/dist/types/src-public/airtable.d.ts +9 -0
- package/dist/types/src-public/centra.d.ts +0 -3
- package/dist/types/src-public/env.d.ts +1 -1
- package/dist/types/src-public/index.d.ts +0 -1
- package/dist/types/src-public/pubsub.d.ts +1 -4
- package/dist/types/src-public/runtime.d.ts +4 -17
- package/dist/types/src-public/types.d.ts +0 -6
- package/dist/types/src-public/utils.d.ts +1 -1
- package/package.json +3 -4
- package/dist/cjs/contracts/purchase-orderline.schema.json +0 -135
- package/dist/cjs/contracts/stock-movement.schema.json +0 -144
- package/dist/cjs/dist-dereferenced/purchase-orderline.js +0 -4
- package/dist/cjs/dist-dereferenced/stock-movement.js +0 -4
- package/dist/cjs/dist-types/purchase-orderline.js +0 -2
- package/dist/cjs/dist-types/stock-movement.js +0 -2
- package/dist/cjs/src-public/sitoo.js +0 -349
- package/dist/types/dist-dereferenced/purchase-orderline.d.ts +0 -114
- package/dist/types/dist-dereferenced/stock-movement.d.ts +0 -110
- package/dist/types/dist-types/purchase-orderline.d.ts +0 -31
- package/dist/types/dist-types/stock-movement.d.ts +0 -30
- package/dist/types/src-public/sitoo.d.ts +0 -254
|
@@ -169,30 +169,33 @@ function transformMasterOrder(payload) {
|
|
|
169
169
|
if (desc)
|
|
170
170
|
skuByDescription[desc] = sku;
|
|
171
171
|
});
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
|
|
172
|
+
const isShippableItem = (line) => {
|
|
173
|
+
const itemNo = String(line?.item_no || line?.no || '');
|
|
174
|
+
const variantCode = String(line?.variant_code || '');
|
|
175
|
+
const amount = Number(line?.amount || line?.amount_excl_vat || 0);
|
|
176
|
+
const amountGross = Number(line?.amount_including_vat || line?.amount_incl_vat || 0);
|
|
177
|
+
const quantity = Number(line?.quantity || 0);
|
|
178
|
+
const hasStyleAndColour = itemNo.includes('-');
|
|
179
|
+
const hasSize = variantCode.trim().length > 0;
|
|
180
|
+
const hasValue = amount > 0 || amountGross > 0 || quantity > 0;
|
|
181
|
+
const hasQuantity = quantity > 0;
|
|
182
|
+
return Boolean(hasStyleAndColour && hasSize && hasValue && hasQuantity);
|
|
175
183
|
};
|
|
176
184
|
const returnedQtyBySku = {};
|
|
177
185
|
(payload.credit_memos || []).forEach((cm) => {
|
|
178
186
|
(cm.credit_memo_lines || []).forEach((l) => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
187
|
+
if (!isShippableItem(l)) {
|
|
188
|
+
const desc = String(l?.description || '');
|
|
189
|
+
if (desc && skuByDescription[desc]) {
|
|
190
|
+
const sku = skuByDescription[desc];
|
|
191
|
+
returnedQtyBySku[sku] = (returnedQtyBySku[sku] || 0) + (l.quantity || 0);
|
|
192
|
+
}
|
|
184
193
|
return;
|
|
185
|
-
const typeStr = String(l?.type || '').toLowerCase();
|
|
186
|
-
const isTypeItem = typeStr.includes('item');
|
|
187
|
-
if (isTypeItem) {
|
|
188
|
-
const variant = String(l?.variant_code || '');
|
|
189
|
-
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
190
|
-
returnedQtyBySku[sku] = (returnedQtyBySku[sku] || 0) + (l.quantity || 0);
|
|
191
|
-
}
|
|
192
|
-
else if (desc && skuByDescription[desc]) {
|
|
193
|
-
const sku = skuByDescription[desc];
|
|
194
|
-
returnedQtyBySku[sku] = (returnedQtyBySku[sku] || 0) + (l.quantity || 0);
|
|
195
194
|
}
|
|
195
|
+
const itemNo = String(l?.item_no || l?.no || '');
|
|
196
|
+
const variant = String(l?.variant_code || '');
|
|
197
|
+
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
198
|
+
returnedQtyBySku[sku] = (returnedQtyBySku[sku] || 0) + (l.quantity || 0);
|
|
196
199
|
});
|
|
197
200
|
});
|
|
198
201
|
(payload.sales || []).forEach((sale) => {
|
|
@@ -200,14 +203,9 @@ function transformMasterOrder(payload) {
|
|
|
200
203
|
if (!docTypeRaw.toLowerCase().includes('return'))
|
|
201
204
|
return;
|
|
202
205
|
(sale.sale_lines || []).forEach((l) => {
|
|
203
|
-
|
|
204
|
-
const desc = String(l?.description || '');
|
|
205
|
-
if (itemNo.toUpperCase() === 'X DELCHR' || itemNo.toUpperCase() === 'REFUND')
|
|
206
|
-
return;
|
|
207
|
-
if ((l?.quantity || 0) <= 0)
|
|
208
|
-
return;
|
|
209
|
-
if (!isItemish(l?.type, itemNo, desc))
|
|
206
|
+
if (!isShippableItem(l))
|
|
210
207
|
return;
|
|
208
|
+
const itemNo = String(l?.item_no || l?.no || '');
|
|
211
209
|
const variant = String(l?.variant_code || '');
|
|
212
210
|
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
213
211
|
returnedQtyBySku[sku] = (returnedQtyBySku[sku] || 0) + (l.quantity || 0);
|
|
@@ -237,18 +235,12 @@ function transformMasterOrder(payload) {
|
|
|
237
235
|
const shippedQtyBySku = {};
|
|
238
236
|
(payload.shipments || []).forEach((s) => {
|
|
239
237
|
(s.shipment_lines || []).forEach((l) => {
|
|
240
|
-
|
|
241
|
-
if (itemNo.toUpperCase() === 'X DELCHR')
|
|
242
|
-
return;
|
|
243
|
-
const desc = String(l?.description || '');
|
|
244
|
-
const looksProduct = itemNo.includes('-') || desc.includes(' - ');
|
|
245
|
-
const qty = Number(l?.quantity || 0);
|
|
246
|
-
if (!looksProduct)
|
|
247
|
-
return;
|
|
248
|
-
if (qty <= 0)
|
|
238
|
+
if (!isShippableItem(l))
|
|
249
239
|
return;
|
|
240
|
+
const itemNo = String(l?.item_no || l?.no || "");
|
|
250
241
|
const variant = String(l?.variant_code || "");
|
|
251
242
|
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
243
|
+
const qty = Number(l?.quantity || 0);
|
|
252
244
|
shippedQtyBySku[sku] = (shippedQtyBySku[sku] || 0) + qty;
|
|
253
245
|
});
|
|
254
246
|
});
|
|
@@ -519,19 +511,30 @@ function transformMasterOrder(payload) {
|
|
|
519
511
|
const d = new Date(source.includes("T") ? source : `${source}T00:00:00Z`);
|
|
520
512
|
return isNaN(d.getTime()) ? new Date().toISOString() : d.toISOString();
|
|
521
513
|
};
|
|
514
|
+
const mapCourierName = (shippingAgentCode) => {
|
|
515
|
+
if (!shippingAgentCode || typeof shippingAgentCode !== 'string')
|
|
516
|
+
return null;
|
|
517
|
+
const code = shippingAgentCode.toUpperCase().trim();
|
|
518
|
+
if (code === 'GLOBALE' || code === 'ROYALMAIL' || code === 'EVRI' || code === 'WAITROSE') {
|
|
519
|
+
return code;
|
|
520
|
+
}
|
|
521
|
+
return null;
|
|
522
|
+
};
|
|
523
|
+
const mapClassName = (serviceCode) => {
|
|
524
|
+
if (!serviceCode || typeof serviceCode !== 'string')
|
|
525
|
+
return 'STANDARD';
|
|
526
|
+
const code = serviceCode.toUpperCase().trim();
|
|
527
|
+
if (code.includes('24') || code.includes('EXPRESS') || code.includes('PRIORITY')) {
|
|
528
|
+
return 'PRIORITY';
|
|
529
|
+
}
|
|
530
|
+
return 'STANDARD';
|
|
531
|
+
};
|
|
522
532
|
const mappedShipments = (payload.shipments || []).map((s) => {
|
|
523
533
|
const rawLines = (s.shipment_lines || [])
|
|
524
|
-
.filter((l) => (l
|
|
525
|
-
.filter((l) => String(l?.item_no || '').toUpperCase() !== 'X DELCHR')
|
|
526
|
-
.filter((l) => {
|
|
527
|
-
const itemNo = String(l?.item_no || '');
|
|
528
|
-
const desc = String(l?.description || '');
|
|
529
|
-
const looksProduct = itemNo.includes('-') || desc.includes(' - ');
|
|
530
|
-
return looksProduct;
|
|
531
|
-
});
|
|
534
|
+
.filter((l) => isShippableItem(l));
|
|
532
535
|
const qtyBySku = new Map();
|
|
533
536
|
rawLines.forEach((l) => {
|
|
534
|
-
const itemNo = String(l?.item_no || '');
|
|
537
|
+
const itemNo = String(l?.item_no || l?.no || '');
|
|
535
538
|
const variant = String(l?.variant_code || '');
|
|
536
539
|
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
537
540
|
const q = Number(l?.quantity || 0);
|
|
@@ -550,6 +553,9 @@ function transformMasterOrder(payload) {
|
|
|
550
553
|
status: statusVal,
|
|
551
554
|
type: statusVal === "SHIPPED" ? "SHIPPED-OUTBOUND" : undefined,
|
|
552
555
|
shipped_by: "TORQUE",
|
|
556
|
+
courier_name: mapCourierName(s.shipping_agent_code),
|
|
557
|
+
tracking_code: (s.torque_tracking_id && typeof s.torque_tracking_id === 'string') ? s.torque_tracking_id : null,
|
|
558
|
+
class_name: mapClassName(s.shipping_agent_service_code),
|
|
553
559
|
items: shipmentLines,
|
|
554
560
|
amount_net: money(0),
|
|
555
561
|
amount_gross: money(0),
|
|
@@ -558,28 +564,27 @@ function transformMasterOrder(payload) {
|
|
|
558
564
|
discount_amount_percent: 0,
|
|
559
565
|
};
|
|
560
566
|
});
|
|
567
|
+
const shipmentsBySku = new Map();
|
|
568
|
+
(payload.shipments || []).forEach((s) => {
|
|
569
|
+
(s.shipment_lines || []).forEach((sl) => {
|
|
570
|
+
if (!isShippableItem(sl))
|
|
571
|
+
return;
|
|
572
|
+
const itemNo = String(sl?.item_no || sl?.no || '');
|
|
573
|
+
const variant = String(sl?.variant_code || '');
|
|
574
|
+
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
575
|
+
if (!shipmentsBySku.has(sku)) {
|
|
576
|
+
shipmentsBySku.set(sku, s);
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
});
|
|
561
580
|
const returnShipments = (payload.credit_memos || [])
|
|
562
581
|
.filter((cm) => {
|
|
563
582
|
const lines = cm?.credit_memo_lines || [];
|
|
564
|
-
return lines.some((l) =>
|
|
565
|
-
const itemNo = String(l?.item_no || l?.no || "");
|
|
566
|
-
const upper = itemNo.toUpperCase();
|
|
567
|
-
if (upper === 'X DELCHR' || upper === 'REFUND')
|
|
568
|
-
return false;
|
|
569
|
-
const looksProduct = itemNo.includes('-');
|
|
570
|
-
return (l?.quantity || 0) > 0 && looksProduct;
|
|
571
|
-
});
|
|
583
|
+
return lines.some((l) => isShippableItem(l));
|
|
572
584
|
})
|
|
573
585
|
.map((cm, idx) => {
|
|
574
586
|
const rawLines = (cm.credit_memo_lines || [])
|
|
575
|
-
.filter((l) => (l
|
|
576
|
-
.filter((l) => {
|
|
577
|
-
const itemNo = String(l?.item_no || l?.no || '');
|
|
578
|
-
const upper = itemNo.toUpperCase();
|
|
579
|
-
if (upper === 'X DELCHR' || upper === 'REFUND')
|
|
580
|
-
return false;
|
|
581
|
-
return itemNo.includes('-');
|
|
582
|
-
});
|
|
587
|
+
.filter((l) => isShippableItem(l));
|
|
583
588
|
const qtyBySku = new Map();
|
|
584
589
|
rawLines.forEach((l) => {
|
|
585
590
|
const itemNo = String(l?.item_no || l?.no || '');
|
|
@@ -589,6 +594,7 @@ function transformMasterOrder(payload) {
|
|
|
589
594
|
qtyBySku.set(sku, (qtyBySku.get(sku) || 0) + q);
|
|
590
595
|
});
|
|
591
596
|
const skus = Array.from(qtyBySku.keys()).sort();
|
|
597
|
+
const matchingShipment = skus.length > 0 ? shipmentsBySku.get(skus[0]) : null;
|
|
592
598
|
const lines = skus.map((sku, i) => ({
|
|
593
599
|
lineNumber: i + 1,
|
|
594
600
|
sku,
|
|
@@ -602,6 +608,17 @@ function transformMasterOrder(payload) {
|
|
|
602
608
|
status: "RECEIVED",
|
|
603
609
|
type: "SHIPPED-RETURN",
|
|
604
610
|
shipped_by: "CUSTOMER",
|
|
611
|
+
courier_name: mapCourierName(matchingShipment?.shipping_agent_code || cm.shipping_agent_code),
|
|
612
|
+
tracking_code: (() => {
|
|
613
|
+
if (matchingShipment?.torque_tracking_id && typeof matchingShipment.torque_tracking_id === 'string') {
|
|
614
|
+
return matchingShipment.torque_tracking_id;
|
|
615
|
+
}
|
|
616
|
+
if (cm.torque_tracking_id && typeof cm.torque_tracking_id === 'string') {
|
|
617
|
+
return cm.torque_tracking_id;
|
|
618
|
+
}
|
|
619
|
+
return null;
|
|
620
|
+
})(),
|
|
621
|
+
class_name: mapClassName(matchingShipment?.shipping_agent_service_code || cm.shipping_agent_service_code),
|
|
605
622
|
items: lines,
|
|
606
623
|
amount_net: money(0),
|
|
607
624
|
amount_gross: money(0),
|
|
@@ -766,7 +783,7 @@ function transformMasterOrder(payload) {
|
|
|
766
783
|
return acc + (s.amount_incl_vat || 0);
|
|
767
784
|
}
|
|
768
785
|
const lineAmounts = (s.shipment_lines || []).reduce((lineAcc, l) => {
|
|
769
|
-
if (
|
|
786
|
+
if (!isShippableItem(l))
|
|
770
787
|
return lineAcc;
|
|
771
788
|
const orderLineNo = Number(l?.order_line_no || -1);
|
|
772
789
|
let sourceLine = orderLineNo > 0 ? sourceLineMap.get(orderLineNo) : null;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const crypto_1 = __importDefault(require("crypto"));
|
|
7
7
|
const env_1 = __importDefault(require("./env"));
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
|
-
const CACHE_EXPIRATION_MS = 1000 * 60 *
|
|
9
|
+
const CACHE_EXPIRATION_MS = 1000 * 60 * 60 * 3;
|
|
10
10
|
class CentraHelper extends env_1.default {
|
|
11
11
|
opts;
|
|
12
12
|
shaToken;
|
|
@@ -99,12 +99,6 @@ class CentraHelper extends env_1.default {
|
|
|
99
99
|
getCacheKeyForMarket(marketExternalId) {
|
|
100
100
|
return `${this.getCacheKeyForMarkets()}_${marketExternalId}`;
|
|
101
101
|
}
|
|
102
|
-
getCacheKeyForCampaigns() {
|
|
103
|
-
return `centra_${this.shaToken}_campaign_name`;
|
|
104
|
-
}
|
|
105
|
-
getCacheKeyForCampaign(campaignName) {
|
|
106
|
-
return `${this.getCacheKeyForCampaigns()}_${campaignName}`;
|
|
107
|
-
}
|
|
108
102
|
getCacheKeyForSizeCharts() {
|
|
109
103
|
return `centra_${this.shaToken}_size_chart_external_id`;
|
|
110
104
|
}
|
|
@@ -136,7 +130,7 @@ class CentraHelper extends env_1.default {
|
|
|
136
130
|
return `${this.getCacheKeyForCentraWarehouses()}_${warehouseExternalId}`;
|
|
137
131
|
}
|
|
138
132
|
getCacheKeyForCentraPricelists() {
|
|
139
|
-
return `centra_${this.shaToken}
|
|
133
|
+
return `centra_${this.shaToken}_pricelist_external_id`;
|
|
140
134
|
}
|
|
141
135
|
getCacheKeyForCentraPricelist(pricelistExternalId) {
|
|
142
136
|
return `${this.getCacheKeyForCentraPricelists()}_${pricelistExternalId}`;
|
|
@@ -224,7 +218,7 @@ class CentraHelper extends env_1.default {
|
|
|
224
218
|
return result;
|
|
225
219
|
}
|
|
226
220
|
async fetchCentraCampaigns(names) {
|
|
227
|
-
const limit =
|
|
221
|
+
const limit = (names?.length || 0) > 200 ? 200 : (names?.length || 0);
|
|
228
222
|
let nextCursor = null;
|
|
229
223
|
const result = {};
|
|
230
224
|
do {
|
|
@@ -276,7 +270,7 @@ class CentraHelper extends env_1.default {
|
|
|
276
270
|
nextCursor = null;
|
|
277
271
|
}
|
|
278
272
|
if (campaignConnection && campaignConnection.edges?.length) {
|
|
279
|
-
for (let i =
|
|
273
|
+
for (let i = campaignConnection.edges.length; i < (names?.length || 0); i++) {
|
|
280
274
|
const { node } = campaignConnection.edges[i];
|
|
281
275
|
result[node.name] = node;
|
|
282
276
|
}
|
|
@@ -727,9 +721,7 @@ class CentraHelper extends env_1.default {
|
|
|
727
721
|
}
|
|
728
722
|
else {
|
|
729
723
|
for (const warehouse of warehouses) {
|
|
730
|
-
|
|
731
|
-
warehouseToSet[warehouse.externalId] = warehouse;
|
|
732
|
-
}
|
|
724
|
+
warehouseToSet[warehouse.externalId] = warehouse;
|
|
733
725
|
}
|
|
734
726
|
await this.set(Object.entries(warehouseToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForCentraWarehouse(key), value: JSON.stringify(value) })), 'env', {
|
|
735
727
|
ephemeralMs: CACHE_EXPIRATION_MS,
|
|
@@ -805,49 +797,6 @@ class CentraHelper extends env_1.default {
|
|
|
805
797
|
}
|
|
806
798
|
return Object.assign({}, pricelistInCache, pricelistToSet);
|
|
807
799
|
}
|
|
808
|
-
async getCentraCampaigns(alwaysFetch = false) {
|
|
809
|
-
let campaignInCache = {};
|
|
810
|
-
let dedupedCampaignNamesInCache = [];
|
|
811
|
-
let campaignsToFetch = null;
|
|
812
|
-
if (!alwaysFetch) {
|
|
813
|
-
const campaignNamesInCache = await (this.get(this.getCacheKeyForCampaigns(), 'env', {
|
|
814
|
-
isEphemeral: true,
|
|
815
|
-
encrypted: false,
|
|
816
|
-
}).then(x => x ? JSON.parse(x) : null));
|
|
817
|
-
if (campaignNamesInCache) {
|
|
818
|
-
dedupedCampaignNamesInCache = campaignNamesInCache.filter((x, index, self) => self.indexOf(x) === index);
|
|
819
|
-
campaignInCache = Object.fromEntries(Object.entries(await this.get(dedupedCampaignNamesInCache.map((x) => this.getCacheKeyForCampaign(x)), 'env', {
|
|
820
|
-
isEphemeral: true,
|
|
821
|
-
encrypted: false,
|
|
822
|
-
})).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]).filter(([_, value]) => value));
|
|
823
|
-
campaignsToFetch = dedupedCampaignNamesInCache.filter(x => !campaignInCache[x]);
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
const campaignToSet = {};
|
|
827
|
-
if (!campaignsToFetch || campaignsToFetch.length) {
|
|
828
|
-
const campaigns = await this.fetchCentraCampaigns();
|
|
829
|
-
if (CentraHelper.isCentraErrors(campaigns)) {
|
|
830
|
-
return new Error(`Failed to fetch campaigns: ${campaigns.errors.map((x) => x.message).join(', ')}`);
|
|
831
|
-
}
|
|
832
|
-
else {
|
|
833
|
-
for (const campaign of Object.values(campaigns)) {
|
|
834
|
-
campaignToSet[campaign.name] = campaign;
|
|
835
|
-
}
|
|
836
|
-
await this.set(Object.entries(campaignToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForCampaign(key), value: JSON.stringify(value) })), 'env', {
|
|
837
|
-
ephemeralMs: CACHE_EXPIRATION_MS,
|
|
838
|
-
encrypted: false,
|
|
839
|
-
});
|
|
840
|
-
await this.set([{
|
|
841
|
-
name: this.getCacheKeyForCampaigns(),
|
|
842
|
-
value: JSON.stringify(Object.keys(campaignToSet)),
|
|
843
|
-
}], 'env', {
|
|
844
|
-
ephemeralMs: CACHE_EXPIRATION_MS,
|
|
845
|
-
encrypted: false,
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
return Object.assign({}, campaignInCache, campaignToSet);
|
|
850
|
-
}
|
|
851
800
|
async getCentraMarkets(alwaysFetch = false) {
|
|
852
801
|
let marketInCache = {};
|
|
853
802
|
let dedupedMarketNamesInCache = [];
|
|
@@ -567,7 +567,7 @@ class EnvEngine extends runtime_1.default {
|
|
|
567
567
|
batchSize: 1,
|
|
568
568
|
subscriptionFilter: null,
|
|
569
569
|
batchWindowSeconds: 10,
|
|
570
|
-
}, Object.fromEntries(Object.entries(rnPartialConfig).filter(
|
|
570
|
+
}, Object.fromEntries(Object.entries(rnPartialConfig).filter(x => !(x === null || x === undefined))));
|
|
571
571
|
return rnConfig;
|
|
572
572
|
}
|
|
573
573
|
createOrUpdateRespectfulNudge(subscriptionName, rnPartialConfig) {
|
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.RedisConnectionError = exports.RateLimit = exports.setHeaders = exports.BCOrderHelper = exports.DatoHelper = exports.AirtableHelper = exports.CentraHelper = exports.BigQueryHelper = exports.JWKSHelper = exports.CloudTasksHelper = exports.Secrets = exports.SchedulerHelper = exports.Logging = exports.Runtime = exports.PubSubHelper = exports.EnvEngine = exports.validate = void 0;
|
|
21
21
|
var validate_1 = require("./validate");
|
|
22
22
|
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return __importDefault(validate_1).default; } });
|
|
23
23
|
__exportStar(require("./sanitize"), exports);
|
|
@@ -52,5 +52,3 @@ Object.defineProperty(exports, "setHeaders", { enumerable: true, get: function (
|
|
|
52
52
|
var rateLimit_1 = require("./rateLimit");
|
|
53
53
|
Object.defineProperty(exports, "RateLimit", { enumerable: true, get: function () { return __importDefault(rateLimit_1).default; } });
|
|
54
54
|
Object.defineProperty(exports, "RedisConnectionError", { enumerable: true, get: function () { return rateLimit_1.RedisConnectionError; } });
|
|
55
|
-
var sitoo_1 = require("./sitoo");
|
|
56
|
-
Object.defineProperty(exports, "SitooHelper", { enumerable: true, get: function () { return __importDefault(sitoo_1).default; } });
|
|
@@ -79,44 +79,19 @@ class PubSubHelper extends runtime_1.default {
|
|
|
79
79
|
}
|
|
80
80
|
const topic = pubSubPublishTopics[options.topicName];
|
|
81
81
|
const batches = payloads.length > 5 ? (0, lodash_chunk_1.default)(payloads, 10) : [payloads];
|
|
82
|
-
|
|
82
|
+
const attributes = {
|
|
83
|
+
...options.extraAttributes,
|
|
84
|
+
source_system: options.sourceSystem,
|
|
85
|
+
target_system: options.targetSystem,
|
|
86
|
+
buildship_id: this.systemEnvName + '-' + this.workflowId + '-' + this.triggerId,
|
|
87
|
+
};
|
|
83
88
|
const messageIds = [];
|
|
84
89
|
for (let i = 0; i < batches.length; i++) {
|
|
85
90
|
const batch = batches[i];
|
|
86
|
-
const results = await Promise.allSettled(batch.map((x) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (typeof options.extraAttributes === 'function') {
|
|
91
|
-
nextAttributes = Object.fromEntries(Object.entries(options.extraAttributes ? Object.assign({}, nextAttributes, options.extraAttributes(x)) : nextAttributes).filter(([_, v]) => v !== undefined && v !== null).map(([k, v]) => [k, typeof v === 'boolean' ? (v ? 'yes' : 'no') : `${v}`]));
|
|
92
|
-
}
|
|
93
|
-
else if (typeof options.extraAttributes === 'object') {
|
|
94
|
-
for (const key in options.extraAttributes) {
|
|
95
|
-
let resultForKey;
|
|
96
|
-
if (typeof options.extraAttributes[key] === 'function') {
|
|
97
|
-
resultForKey = options.extraAttributes[key](x);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
resultForKey = options.extraAttributes[key];
|
|
101
|
-
}
|
|
102
|
-
if (typeof resultForKey === 'boolean') {
|
|
103
|
-
nextAttributes[key] = resultForKey ? 'yes' : 'no';
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
nextAttributes[key] = `${resultForKey}`;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
nextAttributes = Object.assign(nextAttributes, {
|
|
110
|
-
source_system: options.sourceSystem,
|
|
111
|
-
target_system: options.targetSystem,
|
|
112
|
-
buildship_id: this.systemEnvName + '-' + this.workflowId + '-' + this.triggerId,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return topic.publishMessage({
|
|
116
|
-
data: Buffer.from(JSON.stringify(x)),
|
|
117
|
-
attributes: nextAttributes
|
|
118
|
-
});
|
|
119
|
-
}));
|
|
91
|
+
const results = await Promise.allSettled(batch.map((x) => topic.publishMessage({
|
|
92
|
+
data: Buffer.from(JSON.stringify(x)),
|
|
93
|
+
attributes: Object.fromEntries(Object.entries(options.attributesGenerator ? Object.assign({}, attributes, options.attributesGenerator(x)) : attributes).filter(([_, v]) => v !== undefined && v !== null).map(([k, v]) => [k, `${v}`]))
|
|
94
|
+
})));
|
|
120
95
|
for (const result of results) {
|
|
121
96
|
if (result.status === 'fulfilled') {
|
|
122
97
|
messageIds.push(result.value);
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.Logging = void 0;
|
|
7
|
-
const lodash_pick_1 = __importDefault(require("lodash.pick"));
|
|
8
4
|
const DEFAULT_BRANCH = 'migratedprod';
|
|
9
5
|
const getCircularReplacer = () => {
|
|
10
6
|
const seen = new WeakSet();
|
|
@@ -63,50 +59,34 @@ exports.Logging = Logging;
|
|
|
63
59
|
class Runtime {
|
|
64
60
|
workflowId;
|
|
65
61
|
triggerId;
|
|
66
|
-
triggerName;
|
|
67
|
-
triggerVersion;
|
|
68
62
|
envName;
|
|
69
63
|
pubSubPrefix;
|
|
70
64
|
systemEnvName;
|
|
71
65
|
runtimeUrl;
|
|
72
66
|
logging;
|
|
73
|
-
|
|
74
|
-
triggerConfigProperties = undefined;
|
|
75
|
-
triggerConfig = undefined;
|
|
76
|
-
workflowRoot;
|
|
67
|
+
workflowRoot = null;
|
|
77
68
|
constructor(opts) {
|
|
78
69
|
if (opts instanceof Runtime) {
|
|
79
70
|
this.workflowRoot = opts.workflowRoot;
|
|
80
71
|
this.workflowId = opts.workflowId;
|
|
81
72
|
this.triggerId = opts.triggerId;
|
|
82
|
-
this.triggerName = opts.triggerName;
|
|
83
|
-
this.triggerVersion = opts.triggerVersion;
|
|
84
73
|
this.systemEnvName = opts.systemEnvName;
|
|
85
74
|
this.runtimeUrl = opts.runtimeUrl;
|
|
86
75
|
this.pubSubPrefix = opts.pubSubPrefix;
|
|
87
76
|
this.envName = opts.envName;
|
|
88
77
|
this.logging = opts.logging || new Logging(this.workflowId, this.triggerId, this.systemEnvName);
|
|
89
|
-
this.triggerName = opts.triggerName;
|
|
90
|
-
this.triggerVersion = opts.triggerVersion;
|
|
91
|
-
this.triggerDataProperties = opts.triggerDataProperties;
|
|
92
|
-
this.triggerConfigProperties = opts.triggerConfigProperties;
|
|
93
|
-
this.triggerConfig = opts.triggerConfig;
|
|
94
78
|
}
|
|
95
79
|
else {
|
|
96
|
-
|
|
80
|
+
if (opts.root) {
|
|
81
|
+
this.workflowRoot = opts.root;
|
|
82
|
+
}
|
|
97
83
|
this.workflowId = opts.workflowId || opts.workflow?.id || '';
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.
|
|
101
|
-
this.triggerVersion = buildSemver((opts.trigger.label.split(/\sv\d/)[1]?.trim() || 'v0').replace(/^v/, ''));
|
|
102
|
-
this.triggerDataProperties = opts.trigger.data?.properties;
|
|
103
|
-
this.triggerConfigProperties = opts.trigger.config?.properties;
|
|
84
|
+
this.triggerId = opts.triggerId || opts.trigger?.id || '';
|
|
85
|
+
if (!this.triggerId && opts.session) {
|
|
86
|
+
this.triggerId = Object.values(opts.session?.executedNodes || {}).find(e => e.nodeType === 'trigger')?.nodeId ?? 'unknown';
|
|
104
87
|
}
|
|
105
|
-
else {
|
|
106
|
-
this.triggerId =
|
|
107
|
-
this.triggerName = this.workflowRoot[this.triggerId]?.triggerName || this.workflowId;
|
|
108
|
-
this.triggerVersion = this.workflowRoot[this.triggerId]?.triggerVersion || '0.0.0';
|
|
109
|
-
this.triggerConfig = this.workflowRoot[this.triggerId]?.triggerConfig;
|
|
88
|
+
else if (!this.triggerId) {
|
|
89
|
+
this.triggerId = 'unknown';
|
|
110
90
|
}
|
|
111
91
|
this.systemEnvName = this.getSystemEnvName(opts);
|
|
112
92
|
this.envName = this.systemEnvName === DEFAULT_BRANCH ? 'prod' : this.systemEnvName;
|
|
@@ -115,18 +95,6 @@ class Runtime {
|
|
|
115
95
|
this.logging = opts.logging || new Logging(this.workflowId, this.triggerId, this.systemEnvName);
|
|
116
96
|
}
|
|
117
97
|
}
|
|
118
|
-
enhanceWorkflowReturn(triggerReturn, triggerConfig) {
|
|
119
|
-
const keys = Object.keys(this.triggerDataProperties || {});
|
|
120
|
-
return Object.assign((0, lodash_pick_1.default)({
|
|
121
|
-
workflowId: this.workflowId,
|
|
122
|
-
triggerId: this.triggerId,
|
|
123
|
-
triggerName: this.triggerName,
|
|
124
|
-
triggerVersion: this.triggerVersion,
|
|
125
|
-
systemEnvName: this.systemEnvName,
|
|
126
|
-
envName: this.envName,
|
|
127
|
-
triggerConfig: (0, lodash_pick_1.default)(triggerConfig, Object.entries(this.triggerConfigProperties || {}).filter(([_, value]) => !value.buildship?.sensitive).map(([key]) => key))
|
|
128
|
-
}, keys), triggerReturn);
|
|
129
|
-
}
|
|
130
98
|
getRuntimeUrl(options) {
|
|
131
99
|
if (options.runtimeUrl && this.isDeployment) {
|
|
132
100
|
return options.runtimeUrl;
|
|
@@ -175,10 +143,3 @@ class Runtime {
|
|
|
175
143
|
}
|
|
176
144
|
exports.default = Runtime;
|
|
177
145
|
;
|
|
178
|
-
function buildSemver(version) {
|
|
179
|
-
const parts = version.split(/\./).map(x => parseInt(x, 10));
|
|
180
|
-
for (let i = parts.length; i < 3; i++) {
|
|
181
|
-
parts.push(0);
|
|
182
|
-
}
|
|
183
|
-
return parts.join('.');
|
|
184
|
-
}
|
|
@@ -264,9 +264,6 @@ function setRetryAfterVariable(value, options) {
|
|
|
264
264
|
global.functionsCache = global.functionsCache || {};
|
|
265
265
|
exports.FUNCTION_EXPR_ERROR = Symbol('function');
|
|
266
266
|
function createFunction(expression) {
|
|
267
|
-
if (typeof expression === 'function') {
|
|
268
|
-
return expression;
|
|
269
|
-
}
|
|
270
267
|
if (!global.functionsCache[expression]) {
|
|
271
268
|
global.functionsCache[expression] = new Function('symbol', 'payload', 'try { return ' + expression + ' } catch (err) { return symbol; }');
|
|
272
269
|
}
|
package/dist/package.json
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@google-cloud/firestore": "^7.11.1",
|
|
9
8
|
"@hackylabs/deep-redact": "^2.2.1",
|
|
10
9
|
"ajv": "^8.17.1",
|
|
11
10
|
"ajv-formats": "^3.0.1",
|
|
@@ -13,15 +12,15 @@
|
|
|
13
12
|
"jose": "^6.0.11",
|
|
14
13
|
"lodash.chunk": "^4.2.0",
|
|
15
14
|
"lodash.clonedeep": "^4.5.0",
|
|
16
|
-
"lodash.groupby": "^4.6.0",
|
|
17
15
|
"lodash.isequal": "^4.5.0",
|
|
18
16
|
"lodash.omit": "^4.5.0",
|
|
19
17
|
"lodash.pick": "^4.4.0",
|
|
20
18
|
"mime-types": "^3.0.1",
|
|
21
19
|
"p-limit": "^7.1.1",
|
|
22
20
|
"rate-limiter-flexible": "^7.2.0",
|
|
21
|
+
"uuid": "^11.1.0",
|
|
23
22
|
"redis": "^5.6.0",
|
|
24
|
-
"
|
|
23
|
+
"@google-cloud/firestore": "^7.11.1"
|
|
25
24
|
},
|
|
26
25
|
"files": [
|
|
27
26
|
"dist"
|
|
@@ -10,8 +10,6 @@ export { default as DevelopmentColour } from './development-colour.schema.json';
|
|
|
10
10
|
export { default as Asset } from './asset.schema.json';
|
|
11
11
|
export { default as CustomerSegment } from './customer-segment.schema.json';
|
|
12
12
|
export { default as MarketingPref } from './marketing-preferences.schema.json';
|
|
13
|
-
export { default as StockMovement } from './stock-movement.schema.json';
|
|
14
|
-
export { default as PurchaseOrderline } from './purchase-orderline.schema.json';
|
|
15
13
|
export * from './order';
|
|
16
14
|
export { default as Order } from './order.schema.json';
|
|
17
15
|
export * from './messages';
|
|
@@ -10,8 +10,6 @@ export { default as Price } from './price';
|
|
|
10
10
|
export { default as ProductCategory } from './product-category';
|
|
11
11
|
export { default as ProductDraft } from './product-draft';
|
|
12
12
|
export { default as Product } from './product';
|
|
13
|
-
export { default as PurchaseOrderline } from './purchase-orderline';
|
|
14
|
-
export { default as StockMovement } from './stock-movement';
|
|
15
13
|
export { default as Stock } from './stock';
|
|
16
14
|
export { default as Total } from './total';
|
|
17
15
|
export * as Messages from './messages';
|