@shushed/helpers 0.0.204-main-20251209142954 → 0.0.205-fix-erp-729-20251209153116
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.
|
@@ -62,7 +62,6 @@ class AirtableHelper extends runtime_1.default {
|
|
|
62
62
|
fieldsToMergeOn: (options.fieldsToMergeOn ?? [this.primaryKeyFieldName]).map(x => this.dictionary[x] || x),
|
|
63
63
|
},
|
|
64
64
|
returnFieldsByFieldId: true,
|
|
65
|
-
typecast: options.typecast || false,
|
|
66
65
|
records: currentBatch.map(x => {
|
|
67
66
|
const recordId = x.$recordId;
|
|
68
67
|
const fieldsWithoutRecordId = { ...x };
|
|
@@ -400,18 +400,15 @@ function transformMasterOrder(payload) {
|
|
|
400
400
|
const desc = String(line?.description || '').trim().toLowerCase();
|
|
401
401
|
return desc === 'delivery';
|
|
402
402
|
};
|
|
403
|
-
let invoicesNetMinor = 0;
|
|
404
403
|
let invoicesGrossMinor = 0;
|
|
405
404
|
(payload.invoices || []).forEach((inv) => {
|
|
406
405
|
(inv.invoice_lines || []).forEach((line) => {
|
|
407
406
|
if (!isDeliveryItem(line)) {
|
|
408
|
-
invoicesNetMinor += toMinorUnits(Number(line?.amount || line?.amount_excl_vat || 0));
|
|
409
407
|
invoicesGrossMinor += toMinorUnits(Number(line?.amount_including_vat || line?.amount_incl_vat || 0));
|
|
410
408
|
}
|
|
411
409
|
});
|
|
412
410
|
});
|
|
413
411
|
if (invoicesGrossMinor === 0 && (payload.invoices || []).length > 0) {
|
|
414
|
-
invoicesNetMinor = toMinorUnits((payload.invoices || []).reduce((acc, inv) => acc + (inv.amount_excl_vat || 0), 0));
|
|
415
412
|
invoicesGrossMinor = toMinorUnits((payload.invoices || []).reduce((acc, inv) => acc + (inv.amount_incl_vat || 0), 0));
|
|
416
413
|
}
|
|
417
414
|
if (invoicesGrossMinor === 0 && invoicedLineNos.size > 0 && sale0?.sale_lines) {
|
|
@@ -423,10 +420,8 @@ function transformMasterOrder(payload) {
|
|
|
423
420
|
const lineNo = Number(l?.line_no || -1);
|
|
424
421
|
return invoicedLineNos.has(lineNo);
|
|
425
422
|
});
|
|
426
|
-
invoicesNetMinor = toMinorUnits(invoicedSaleLines.reduce((acc, l) => acc + (Number(l?.amount || 0)), 0));
|
|
427
423
|
invoicesGrossMinor = toMinorUnits(invoicedSaleLines.reduce((acc, l) => acc + (Number(l?.amount_including_vat || 0)), 0));
|
|
428
424
|
}
|
|
429
|
-
let nonInvSalesNetMinor = 0;
|
|
430
425
|
let nonInvSalesGrossMinor = 0;
|
|
431
426
|
if (sale0?.sale_lines && sale0.sale_lines.length > 0) {
|
|
432
427
|
const allSaleLines = (sale0.sale_lines || []).filter((l) => {
|
|
@@ -436,26 +431,20 @@ function transformMasterOrder(payload) {
|
|
|
436
431
|
return false;
|
|
437
432
|
return true;
|
|
438
433
|
});
|
|
439
|
-
const totalSaleNetMinor = toMinorUnits(allSaleLines.reduce((acc, l) => acc + (Number(l?.amount || 0)), 0));
|
|
440
434
|
const totalSaleGrossMinor = toMinorUnits(allSaleLines.reduce((acc, l) => acc + (Number(l?.amount_including_vat || 0)), 0));
|
|
441
435
|
if (invoicesGrossMinor > 0) {
|
|
442
|
-
nonInvSalesNetMinor = Math.max(0, totalSaleNetMinor - invoicesNetMinor);
|
|
443
436
|
nonInvSalesGrossMinor = Math.max(0, totalSaleGrossMinor - invoicesGrossMinor);
|
|
444
437
|
}
|
|
445
438
|
else {
|
|
446
|
-
nonInvSalesNetMinor = totalSaleNetMinor;
|
|
447
439
|
nonInvSalesGrossMinor = totalSaleGrossMinor;
|
|
448
440
|
}
|
|
449
441
|
}
|
|
450
442
|
else if (sale0 && (sale0.amount_excl_vat || sale0.amount_incl_vat)) {
|
|
451
|
-
const saleNetMinor = toMinorUnits(sale0.amount_excl_vat || 0);
|
|
452
443
|
const saleGrossMinor = toMinorUnits(sale0.amount_incl_vat || 0);
|
|
453
444
|
if (invoicesGrossMinor > 0) {
|
|
454
|
-
nonInvSalesNetMinor = Math.max(0, saleNetMinor - invoicesNetMinor);
|
|
455
445
|
nonInvSalesGrossMinor = Math.max(0, saleGrossMinor - invoicesGrossMinor);
|
|
456
446
|
}
|
|
457
447
|
else {
|
|
458
|
-
nonInvSalesNetMinor = saleNetMinor;
|
|
459
448
|
nonInvSalesGrossMinor = saleGrossMinor;
|
|
460
449
|
}
|
|
461
450
|
}
|
|
@@ -468,32 +457,30 @@ function transformMasterOrder(payload) {
|
|
|
468
457
|
const lineNo = Number(l?.line_no || -1);
|
|
469
458
|
return !invoicedLineNos.has(lineNo);
|
|
470
459
|
});
|
|
471
|
-
nonInvSalesNetMinor = toMinorUnits(nonInvoicedSales.reduce((acc, l) => acc + (Number(l?.amount || 0)), 0));
|
|
472
460
|
nonInvSalesGrossMinor = toMinorUnits(nonInvoicedSales.reduce((acc, l) => acc + (Number(l?.amount_including_vat || 0)), 0));
|
|
473
461
|
}
|
|
474
|
-
const returnsNetMinor = toMinorUnits((payload.credit_memos || []).reduce((acc, cm) => acc + (cm.amount_excl_vat || 0), 0));
|
|
475
|
-
const returnsGrossMinor = toMinorUnits((payload.credit_memos || []).reduce((acc, cm) => acc + (cm.amount_incl_vat || 0), 0));
|
|
476
|
-
const totalNetMinor = invoicesNetMinor + nonInvSalesNetMinor;
|
|
477
462
|
const totalGrossMinor = invoicesGrossMinor + nonInvSalesGrossMinor;
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
amount_gross: moneyFromMinor(returnsGrossMinor),
|
|
489
|
-
discount_amount_net: money(0),
|
|
490
|
-
discount_amount_gross: money(0),
|
|
491
|
-
discount_amount_percent: 0,
|
|
463
|
+
const invoicesNetMinorWithDelivery = toMinorUnits((payload.invoices || []).reduce((acc, inv) => acc + (inv.amount_excl_vat || 0), 0));
|
|
464
|
+
const invoicesGrossMinorWithDelivery = toMinorUnits((payload.invoices || []).reduce((acc, inv) => acc + (inv.amount_incl_vat || 0), 0));
|
|
465
|
+
let nonInvSalesNetMinorWithDelivery = 0;
|
|
466
|
+
let nonInvSalesGrossMinorWithDelivery = 0;
|
|
467
|
+
if (sale0 && (sale0.amount_excl_vat || sale0.amount_incl_vat)) {
|
|
468
|
+
const saleNetMinor = toMinorUnits(sale0.amount_excl_vat || 0);
|
|
469
|
+
const saleGrossMinor = toMinorUnits(sale0.amount_incl_vat || 0);
|
|
470
|
+
if (invoicesGrossMinorWithDelivery > 0) {
|
|
471
|
+
nonInvSalesNetMinorWithDelivery = Math.max(0, saleNetMinor - invoicesNetMinorWithDelivery);
|
|
472
|
+
nonInvSalesGrossMinorWithDelivery = Math.max(0, saleGrossMinor - invoicesGrossMinorWithDelivery);
|
|
492
473
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
474
|
+
else {
|
|
475
|
+
nonInvSalesNetMinorWithDelivery = saleNetMinor;
|
|
476
|
+
nonInvSalesGrossMinorWithDelivery = saleGrossMinor;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
const totalNetMinorWithDelivery = invoicesNetMinorWithDelivery + nonInvSalesNetMinorWithDelivery;
|
|
480
|
+
const totalGrossMinorWithDelivery = invoicesGrossMinorWithDelivery + nonInvSalesGrossMinorWithDelivery;
|
|
481
|
+
const total = {
|
|
482
|
+
amount_net: moneyFromMinor(totalNetMinorWithDelivery),
|
|
483
|
+
amount_gross: moneyFromMinor(totalGrossMinorWithDelivery),
|
|
497
484
|
discount_amount_net: money(0),
|
|
498
485
|
discount_amount_gross: money(0),
|
|
499
486
|
discount_amount_percent: 0,
|
|
@@ -603,7 +590,7 @@ function transformMasterOrder(payload) {
|
|
|
603
590
|
const merchReturnGrossFromCreditMemos = (payload.credit_memos || []).reduce((acc, cm) => {
|
|
604
591
|
const lines = cm?.credit_memo_lines || [];
|
|
605
592
|
let hasQualifying = false;
|
|
606
|
-
const
|
|
593
|
+
const sumGross = lines.reduce((s, l) => {
|
|
607
594
|
const itemNo = String(l?.item_no || l?.no || "");
|
|
608
595
|
const desc = String(l?.description || "");
|
|
609
596
|
const looksProduct = itemNo.includes('-') || desc.includes(' - ');
|
|
@@ -616,24 +603,36 @@ function transformMasterOrder(payload) {
|
|
|
616
603
|
}
|
|
617
604
|
return s;
|
|
618
605
|
}, 0);
|
|
606
|
+
const sumNet = lines.reduce((s, l) => {
|
|
607
|
+
const itemNo = String(l?.item_no || l?.no || "");
|
|
608
|
+
const desc = String(l?.description || "");
|
|
609
|
+
const looksProduct = itemNo.includes('-') || desc.includes(' - ');
|
|
610
|
+
const typeStr = String(l?.type || "").toLowerCase();
|
|
611
|
+
const isItemish = typeStr.includes('item') || looksProduct;
|
|
612
|
+
const isRefund = itemNo.toUpperCase() === 'REFUND';
|
|
613
|
+
if ((l?.quantity || 0) > 0 && isItemish && !isRefund && !isDeliveryItem(l)) {
|
|
614
|
+
return s + (l?.amount || l?.amount_excl_vat || 0);
|
|
615
|
+
}
|
|
616
|
+
return s;
|
|
617
|
+
}, 0);
|
|
619
618
|
if (!hasQualifying)
|
|
620
619
|
return acc;
|
|
621
620
|
if (cm?.amount_incl_vat != null && cm.amount_incl_vat > 0) {
|
|
622
|
-
return acc + cm.amount_incl_vat;
|
|
621
|
+
return { gross: acc.gross + cm.amount_incl_vat, net: acc.net + (cm.amount_excl_vat || 0) };
|
|
623
622
|
}
|
|
624
|
-
return acc +
|
|
625
|
-
}, 0);
|
|
623
|
+
return { gross: acc.gross + sumGross, net: acc.net + sumNet };
|
|
624
|
+
}, { gross: 0, net: 0 });
|
|
626
625
|
const merchReturnGrossFromReturnSales = (payload.sales || []).reduce((acc, sale) => {
|
|
627
626
|
const docTypeRaw = String(sale?.document_type || sale?.documentType || "");
|
|
628
627
|
const isReturnOrder = docTypeRaw.toLowerCase().includes('return');
|
|
629
628
|
if (!isReturnOrder)
|
|
630
629
|
return acc;
|
|
631
630
|
if (sale?.amount_incl_vat != null && sale.amount_incl_vat > 0) {
|
|
632
|
-
return acc + sale.amount_incl_vat;
|
|
631
|
+
return { gross: acc.gross + sale.amount_incl_vat, net: acc.net + (sale.amount_excl_vat || sale.amount || 0) };
|
|
633
632
|
}
|
|
634
633
|
const lines = sale?.sale_lines || [];
|
|
635
634
|
let hasQualifying = false;
|
|
636
|
-
const
|
|
635
|
+
const sumGross = lines.reduce((s, l) => {
|
|
637
636
|
const itemNo = String(l?.item_no || l?.no || "");
|
|
638
637
|
const desc = String(l?.description || "");
|
|
639
638
|
const looksProduct = itemNo.includes('-') || desc.includes(' - ');
|
|
@@ -646,10 +645,46 @@ function transformMasterOrder(payload) {
|
|
|
646
645
|
}
|
|
647
646
|
return s;
|
|
648
647
|
}, 0);
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
648
|
+
const sumNet = lines.reduce((s, l) => {
|
|
649
|
+
const itemNo = String(l?.item_no || l?.no || "");
|
|
650
|
+
const desc = String(l?.description || "");
|
|
651
|
+
const looksProduct = itemNo.includes('-') || desc.includes(' - ');
|
|
652
|
+
const typeStr = String(l?.type || "").toLowerCase();
|
|
653
|
+
const isItemish = typeStr.includes('item') || looksProduct;
|
|
654
|
+
const isRefund = itemNo.toUpperCase() === 'REFUND';
|
|
655
|
+
if ((l?.quantity || 0) > 0 && isItemish && !isRefund && !isDeliveryItem(l)) {
|
|
656
|
+
return s + (l?.amount || l?.amount_excl_vat || 0);
|
|
657
|
+
}
|
|
658
|
+
return s;
|
|
659
|
+
}, 0);
|
|
660
|
+
if (sumGross > 0) {
|
|
661
|
+
return { gross: acc.gross + sumGross, net: acc.net + sumNet };
|
|
662
|
+
}
|
|
663
|
+
if (hasQualifying) {
|
|
664
|
+
return { gross: acc.gross + (sale?.amount_incl_vat || sale?.amount_including_vat || 0), net: acc.net + (sale?.amount_excl_vat || sale?.amount || 0) };
|
|
665
|
+
}
|
|
666
|
+
return acc;
|
|
667
|
+
}, { gross: 0, net: 0 });
|
|
668
|
+
const merchReturnGross = merchReturnGrossFromCreditMemos.gross + merchReturnGrossFromReturnSales.gross;
|
|
652
669
|
const hasMerchReturn = merchReturnGross > 0;
|
|
670
|
+
const returnsNetMinor = toMinorUnits((payload.credit_memos || []).reduce((acc, cm) => acc + (cm.amount_excl_vat || 0), 0));
|
|
671
|
+
const returnsGrossMinor = toMinorUnits((payload.credit_memos || []).reduce((acc, cm) => acc + (cm.amount_incl_vat || 0), 0));
|
|
672
|
+
const return_total = (returnsGrossMinor > 0)
|
|
673
|
+
? {
|
|
674
|
+
amount_net: moneyFromMinor(returnsNetMinor),
|
|
675
|
+
amount_gross: moneyFromMinor(returnsGrossMinor),
|
|
676
|
+
discount_amount_net: money(0),
|
|
677
|
+
discount_amount_gross: money(0),
|
|
678
|
+
discount_amount_percent: 0,
|
|
679
|
+
}
|
|
680
|
+
: undefined;
|
|
681
|
+
const net_total = {
|
|
682
|
+
amount_net: moneyFromMinor(Math.max(0, totalNetMinorWithDelivery - returnsNetMinor)),
|
|
683
|
+
amount_gross: moneyFromMinor(Math.max(0, totalGrossMinorWithDelivery - returnsGrossMinor)),
|
|
684
|
+
discount_amount_net: money(0),
|
|
685
|
+
discount_amount_gross: money(0),
|
|
686
|
+
discount_amount_percent: 0,
|
|
687
|
+
};
|
|
653
688
|
const totalOrderGrossMinor = totalGrossMinor;
|
|
654
689
|
const sourceLineMap = new Map();
|
|
655
690
|
sourceLines.forEach((line) => {
|
|
@@ -73,14 +73,6 @@ class CentraHelper extends env_1.default {
|
|
|
73
73
|
errors.push(...userErrors.map((x) => ({ message: x.message, path: x.path })));
|
|
74
74
|
return { errors, limitExceeded: response.status === 429 };
|
|
75
75
|
}
|
|
76
|
-
if (resp.data && typeof resp.data === 'object') {
|
|
77
|
-
for (const key in resp.data) {
|
|
78
|
-
if (resp.data[key] && typeof resp.data[key] === 'object' && 'userErrors' in resp.data[key] && Array.isArray(resp.data[key].userErrors) && resp.data[key].userErrors.length > 0) {
|
|
79
|
-
errors.push(...resp.data[key].userErrors.map((x) => ({ message: x.message, path: x.path })));
|
|
80
|
-
return { errors, limitExceeded: response.status === 429 };
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
76
|
}
|
|
85
77
|
if (response.status === 429) {
|
|
86
78
|
resp.limitExceeded = true;
|
|
@@ -331,7 +323,7 @@ class CentraHelper extends env_1.default {
|
|
|
331
323
|
} while (hasNextPage);
|
|
332
324
|
return result;
|
|
333
325
|
}
|
|
334
|
-
async fetchCentraMarkets() {
|
|
326
|
+
async fetchCentraMarkets(externalIds) {
|
|
335
327
|
const result = [];
|
|
336
328
|
const limit = 200;
|
|
337
329
|
let page = 0;
|
|
@@ -341,15 +333,15 @@ class CentraHelper extends env_1.default {
|
|
|
341
333
|
method: 'POST',
|
|
342
334
|
body: JSON.stringify({
|
|
343
335
|
query: `
|
|
344
|
-
query GetMarkets($limit: Int, $page: Int) {
|
|
345
|
-
markets(limit: $limit, page: $page) {
|
|
336
|
+
query GetMarkets($limit: Int, $page: Int${externalIds ? `, $externalIds: MarketsFilter` : ''}) {
|
|
337
|
+
markets(${externalIds ? `where: $externalIds, ` : ''}limit: $limit, page: $page) {
|
|
346
338
|
id
|
|
347
339
|
externalId
|
|
348
340
|
name
|
|
349
341
|
}
|
|
350
342
|
}
|
|
351
343
|
`,
|
|
352
|
-
variables: { page: page, limit: limit }
|
|
344
|
+
variables: { page: page, limit: limit, externalIds: { externalId: externalIds } }
|
|
353
345
|
})
|
|
354
346
|
});
|
|
355
347
|
if (CentraHelper.isCentraErrors(data)) {
|
|
@@ -479,7 +471,7 @@ class CentraHelper extends env_1.default {
|
|
|
479
471
|
nextCursor = null;
|
|
480
472
|
}
|
|
481
473
|
if (data && data.data?.productConnection?.edges?.length) {
|
|
482
|
-
for (let i =
|
|
474
|
+
for (let i = data.data.productConnection.edges.length; i < styleIds.length; i++) {
|
|
483
475
|
const { node } = data.data.productConnection.edges[i];
|
|
484
476
|
result[node.externalId] = node;
|
|
485
477
|
}
|
|
@@ -505,15 +497,16 @@ class CentraHelper extends env_1.default {
|
|
|
505
497
|
edges {
|
|
506
498
|
node {
|
|
507
499
|
id
|
|
500
|
+
externalId
|
|
508
501
|
status
|
|
509
|
-
|
|
502
|
+
url
|
|
510
503
|
metaTitle
|
|
511
504
|
metaDescription
|
|
512
505
|
name
|
|
513
506
|
categories {
|
|
514
507
|
id
|
|
515
508
|
name
|
|
516
|
-
|
|
509
|
+
url
|
|
517
510
|
isTopCategory
|
|
518
511
|
}
|
|
519
512
|
markets {
|
|
@@ -525,7 +518,7 @@ class CentraHelper extends env_1.default {
|
|
|
525
518
|
externalId
|
|
526
519
|
status
|
|
527
520
|
}
|
|
528
|
-
|
|
521
|
+
productVariant {
|
|
529
522
|
id
|
|
530
523
|
externalId
|
|
531
524
|
status
|
|
@@ -572,8 +565,8 @@ class CentraHelper extends env_1.default {
|
|
|
572
565
|
for (let i = 0; i < edges.length; i++) {
|
|
573
566
|
const { node } = edges[i];
|
|
574
567
|
if (inputIdType === 'variant') {
|
|
575
|
-
result[+node.
|
|
576
|
-
result[+node.
|
|
568
|
+
result[+node.productVariant[0].id] = [];
|
|
569
|
+
result[+node.productVariant[0].id].push(node);
|
|
577
570
|
}
|
|
578
571
|
else {
|
|
579
572
|
result[+node.product.id] = [];
|
|
@@ -797,45 +790,59 @@ class CentraHelper extends env_1.default {
|
|
|
797
790
|
}
|
|
798
791
|
return Object.assign({}, pricelistInCache, pricelistToSet);
|
|
799
792
|
}
|
|
800
|
-
async getCentraMarkets(alwaysFetch = false) {
|
|
793
|
+
async getCentraMarkets(externalIds, alwaysFetch = false) {
|
|
794
|
+
if (externalIds && !externalIds.length) {
|
|
795
|
+
return {};
|
|
796
|
+
}
|
|
801
797
|
let marketInCache = {};
|
|
802
|
-
let
|
|
798
|
+
let dedupedExternalIds = [];
|
|
803
799
|
let marketsToFetch = null;
|
|
804
800
|
if (!alwaysFetch) {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
801
|
+
if (!externalIds) {
|
|
802
|
+
externalIds = (await this.get(this.getCacheKeyForMarkets(), 'env', {
|
|
803
|
+
isEphemeral: true,
|
|
804
|
+
encrypted: false,
|
|
805
|
+
}).then(x => x ? JSON.parse(x) : null));
|
|
806
|
+
}
|
|
807
|
+
if (externalIds) {
|
|
808
|
+
dedupedExternalIds = externalIds.filter((x, index, self) => self.indexOf(x) === index);
|
|
809
|
+
marketInCache = Object.fromEntries(Object.entries(await this.get(dedupedExternalIds.map(x => this.getCacheKeyForMarket(x)), 'env', {
|
|
812
810
|
isEphemeral: true,
|
|
813
811
|
encrypted: false,
|
|
814
812
|
})).map(([key, value]) => [key, value ? JSON.parse(value || 'null') : undefined]).filter(([_, value]) => value));
|
|
815
|
-
marketsToFetch =
|
|
813
|
+
marketsToFetch = dedupedExternalIds.filter(x => !marketInCache[x]);
|
|
816
814
|
}
|
|
817
815
|
}
|
|
818
816
|
const marketToSet = {};
|
|
819
817
|
if (!marketsToFetch || marketsToFetch.length) {
|
|
820
|
-
const markets = await this.fetchCentraMarkets();
|
|
818
|
+
const markets = await this.fetchCentraMarkets(marketsToFetch);
|
|
821
819
|
if (CentraHelper.isCentraErrors(markets)) {
|
|
822
|
-
|
|
820
|
+
if (marketsToFetch) {
|
|
821
|
+
for (const marketExternalId of marketsToFetch) {
|
|
822
|
+
marketToSet[marketExternalId] = new Error(`Failed to fetch market ${marketExternalId}: ${markets.errors.map((x) => x.message).join(', ')}`);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
return new Error(`Failed to fetch markets: ${markets.errors.map((x) => x.message).join(', ')}`);
|
|
827
|
+
}
|
|
823
828
|
}
|
|
824
829
|
else {
|
|
825
830
|
for (const market of markets) {
|
|
826
|
-
marketToSet[market.
|
|
831
|
+
marketToSet[market.externalId] = market;
|
|
827
832
|
}
|
|
828
833
|
await this.set(Object.entries(marketToSet).filter(([_, value]) => !(value instanceof Error)).map(([key, value]) => ({ name: this.getCacheKeyForMarket(key), value: JSON.stringify(value) })), 'env', {
|
|
829
834
|
ephemeralMs: CACHE_EXPIRATION_MS,
|
|
830
835
|
encrypted: false,
|
|
831
836
|
});
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
837
|
+
if (!marketsToFetch) {
|
|
838
|
+
await this.set([{
|
|
839
|
+
name: this.getCacheKeyForMarkets(),
|
|
840
|
+
value: JSON.stringify(Object.keys(marketToSet)),
|
|
841
|
+
}], 'env', {
|
|
842
|
+
ephemeralMs: CACHE_EXPIRATION_MS,
|
|
843
|
+
encrypted: false,
|
|
844
|
+
});
|
|
845
|
+
}
|
|
839
846
|
}
|
|
840
847
|
}
|
|
841
848
|
return Object.assign({}, marketInCache, marketToSet);
|
|
@@ -44,7 +44,6 @@ declare class AirtableHelper<T extends Record<string, string>, K extends keyof T
|
|
|
44
44
|
}>, options?: {
|
|
45
45
|
fieldsToMergeOn?: Array<keyof T>;
|
|
46
46
|
primaryKeyWritable?: boolean;
|
|
47
|
-
typecast?: boolean;
|
|
48
47
|
}, callIdx?: number, collectedResult?: {
|
|
49
48
|
updatedRecords: Array<string>;
|
|
50
49
|
createdRecords: Array<string>;
|
|
@@ -19,18 +19,19 @@ export type BasicCentraProduct = {
|
|
|
19
19
|
export type BasicCentraDisplay = {
|
|
20
20
|
id: number;
|
|
21
21
|
name: string;
|
|
22
|
+
externalId: string;
|
|
22
23
|
status: string;
|
|
23
|
-
|
|
24
|
+
url: string;
|
|
24
25
|
metaTitle: string;
|
|
25
26
|
metaDescription: string;
|
|
26
27
|
categories: {
|
|
27
28
|
id: number;
|
|
28
29
|
name: string;
|
|
29
|
-
|
|
30
|
+
url: string;
|
|
30
31
|
isTopCategory: boolean;
|
|
31
32
|
}[];
|
|
32
33
|
markets: BasicCentraMarket[];
|
|
33
|
-
|
|
34
|
+
productVariant: Array<{
|
|
34
35
|
id: number;
|
|
35
36
|
externalId: string;
|
|
36
37
|
status: string;
|
|
@@ -76,6 +77,7 @@ export type BasicCentraCountry = {
|
|
|
76
77
|
export type BasicCentraMarket = {
|
|
77
78
|
id: number;
|
|
78
79
|
name: string;
|
|
80
|
+
externalId: string;
|
|
79
81
|
};
|
|
80
82
|
export type BasicCentraVariant = {
|
|
81
83
|
id: number;
|
|
@@ -156,14 +158,14 @@ export default class CentraHelper extends EnvEngine {
|
|
|
156
158
|
fetchCentraWarehouses(externalIds?: string[] | undefined | null): Promise<CentraErrors | Array<BasicCentraWarehouse>>;
|
|
157
159
|
fetchCentraCampaigns(names?: string[] | undefined | null): Promise<CentraErrors | Record<string, BasicCentraCampaign | Error>>;
|
|
158
160
|
fetchPricelists(names?: string[] | undefined | null): Promise<CentraErrors | Array<BasicPricelist>>;
|
|
159
|
-
fetchCentraMarkets(): Promise<CentraErrors | Array<BasicCentraMarket>>;
|
|
161
|
+
fetchCentraMarkets(externalIds?: string[] | undefined | null): Promise<CentraErrors | Array<BasicCentraMarket>>;
|
|
160
162
|
fetchCentraSizeCharts(externalIds?: string[] | undefined | null): Promise<CentraErrors | Array<BasicCentraSizeChart>>;
|
|
161
163
|
private fetchCentraProducts;
|
|
162
164
|
private fetchCentraDisplays;
|
|
163
165
|
private fetchCentraVariants;
|
|
164
166
|
getCentraWarehouses(externalIds?: string[] | null | undefined, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraWarehouse>>;
|
|
165
167
|
getCentraPricelists(names?: string[] | null | undefined, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicPricelist>>;
|
|
166
|
-
getCentraMarkets(alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraMarket>>;
|
|
168
|
+
getCentraMarkets(externalIds?: string[] | null | undefined, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraMarket>>;
|
|
167
169
|
getCentraCountries(iso2Codes?: string[] | null | undefined, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraCountry>>;
|
|
168
170
|
getCentraSizeCharts(externalIds?: string[] | null | undefined, alwaysFetch?: boolean): Promise<Error | Record<string, Error | BasicCentraSizeChart>>;
|
|
169
171
|
getCentraProducts(styleIds: string[]): Promise<Error | Record<string, Error | BasicCentraProduct>>;
|