@shushed/helpers 0.0.293 → 0.0.295

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.
@@ -114,15 +114,19 @@ function transformMasterOrder(payload) {
114
114
  if (value === null || value === undefined)
115
115
  return null;
116
116
  if (typeof value === "number") {
117
- return Number.isInteger(value) ? value : null;
117
+ if (!Number.isInteger(value) || value === 0)
118
+ return null;
119
+ return value;
118
120
  }
119
121
  if (typeof value === "string") {
120
122
  const s = value.trim();
121
- if (!s)
123
+ if (!s || s === "0")
122
124
  return null;
123
125
  if (/^-?\d+$/.test(s)) {
124
126
  const parsed = Number(s);
125
- return Number.isInteger(parsed) ? parsed : null;
127
+ if (!Number.isInteger(parsed) || parsed === 0)
128
+ return null;
129
+ return parsed;
126
130
  }
127
131
  }
128
132
  return null;
@@ -273,7 +277,16 @@ function transformMasterOrder(payload) {
273
277
  const returnedRemainingBySku = { ...returnedTotalBySkuCapped };
274
278
  const itemsList = [];
275
279
  sourceLines
276
- .filter((line) => line.type === "Item")
280
+ .filter((line) => {
281
+ if (line.type !== "Item")
282
+ return false;
283
+ const itemNo = String(line?.item_no || line?.no || '');
284
+ const variantCode = String(line?.variant_code || '');
285
+ const upper = itemNo.toUpperCase().replace(/\s+/g, '');
286
+ if (upper.includes('DELCHR') || upper.startsWith('GFT') || upper.startsWith('VCH'))
287
+ return false;
288
+ return itemNo.includes('-') && variantCode.trim().length > 0;
289
+ })
277
290
  .forEach((line) => {
278
291
  const itemNo = line.no || "";
279
292
  const variant = line.variant_code || "";
@@ -409,7 +422,10 @@ function transformMasterOrder(payload) {
409
422
  const invoicedLineNos = new Set((payload.invoices || []).flatMap((inv) => (inv?.invoice_lines || []).map((l) => Number(l?.order_line_no || -1))));
410
423
  const isDeliveryItem = (line) => {
411
424
  const desc = String(line?.description || '').trim().toLowerCase();
412
- return desc === 'delivery';
425
+ if (desc === 'delivery')
426
+ return true;
427
+ const itemNo = String(line?.item_no || line?.no || '').toUpperCase().replace(/\s+/g, '');
428
+ return itemNo.includes('DELCHR');
413
429
  };
414
430
  let invoicesGrossMinor = 0;
415
431
  (payload.invoices || []).forEach((inv) => {
@@ -862,9 +878,17 @@ function transformMasterOrder(payload) {
862
878
  else if (shippedGrossMinor > 0 && totalOrderGrossMinor > 0) {
863
879
  status = shippedGrossMinor >= totalOrderGrossMinor ? "SHIPPED" : "PARTIALLY-SHIPPED";
864
880
  }
865
- const sfcc_order_id = (sale0?.created_by === "STOREFRONT")
866
- ? (sale0?.no || null)
867
- : ((invoice0?.created_by === "STOREFRONT") ? (invoice0?.order_no || null) : null);
881
+ const sfcc_order_id = (() => {
882
+ const raw = (sale0?.created_by === "STOREFRONT")
883
+ ? (sale0?.no ?? null)
884
+ : ((invoice0?.created_by === "STOREFRONT") ? (invoice0?.order_no ?? null) : null);
885
+ if (raw === null || raw === undefined)
886
+ return null;
887
+ const s = String(raw).trim();
888
+ if (!s || s === "0")
889
+ return null;
890
+ return s;
891
+ })();
868
892
  const billing_from = invoice0 || sale0 || null;
869
893
  const shipping_from = invoice0 || sale0 || null;
870
894
  const mapPaymentMethod = (code, card) => {
@@ -1258,7 +1282,9 @@ function transformMasterOrder(payload) {
1258
1282
  if (v === null || v === undefined)
1259
1283
  return null;
1260
1284
  const s = String(v).trim();
1261
- return s.length > 0 ? s : null;
1285
+ if (!s || s === "0")
1286
+ return null;
1287
+ return s;
1262
1288
  })(),
1263
1289
  system_created_by,
1264
1290
  ordered_at,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.293",
3
+ "version": "0.0.295",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",