@shushed/helpers 0.0.215 → 0.0.217

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.
@@ -52,6 +52,14 @@
52
52
  "description": {
53
53
  "type": "string"
54
54
  },
55
+ "entry_no": {
56
+ "type": "string",
57
+ "description": "BC Entry no. Should be empty for other systems"
58
+ },
59
+ "external_entry_no": {
60
+ "type": "string",
61
+ "description": "External Entry no. Might be empty for other systems"
62
+ },
55
63
  "document_no": {
56
64
  "type": "string",
57
65
  "description": "BC Document no. Should be empty for other systems"
@@ -118,6 +126,7 @@
118
126
  "required": [
119
127
  "quantity",
120
128
  "created_at",
129
+ "entry_no",
121
130
  "document_date",
122
131
  "type"
123
132
  ]
@@ -142,6 +151,7 @@
142
151
  "colour_id",
143
152
  "size_code",
144
153
  "history",
154
+ "entry_no",
145
155
  "last_modified_at"
146
156
  ]
147
157
  }
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Stock Movement Schema", "type": "object", "additionalProperties": false, "properties": { "style_id": { "type": "string", "minLength": 1 }, "colour_id": { "type": "string", "minLength": 1 }, "size_code": { "type": "string", "minLength": 1 }, "location_code": { "type": "string", "pattern": "^\\d{3}-[A-Z]+$|^[A-Z]{2,}-?[A-Z]*$|^[A-Z]{2,}\\d{3}$" }, "source_system": { "type": "string", "enum": ["bc", "centra", "sitoo"] }, "history": { "type": "array", "items": { "type": "object", "properties": { "quantity": { "type": "integer", "minimum": 0 }, "document_no": { "type": "string" }, "external_document_no": { "type": "string" }, "type": { "type": "string", "enum": ["transfer", "negative adjustment", "positive adjustment", "purchase", "sale"] }, "unit_cost": { "oneOf": [{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Money", "type": "object", "additionalProperties": false, "properties": { "value": { "type": "integer", "minimum": 0 }, "decimal_places": { "type": "integer", "minimum": 0, "maximum": 4 }, "currency": { "title": "Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "lcy_value": { "type": "integer", "minimum": 0 }, "lcy_currency": { "title": "LCY Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "lcy_decimal_places": { "type": "integer", "minimum": 0, "maximum": 4 } }, "required": ["value", "currency", "lcy_value", "lcy_currency", "decimal_places", "lcy_decimal_places"] }, { "type": "null" }] }, "document_date": { "type": "string", "format": "date" }, "posting_date": { "type": "string", "format": "date" }, "created_at": { "type": "string", "format": "date-time" } }, "required": ["quantity", "created_at", "document_date", "type"] } }, "last_modified_at": { "type": "string", "format": "date-time" } }, "required": ["style_id", "source_system", "location_code", "colour_id", "size_code", "history", "last_modified_at"], "$id": "https://shushed.example.com/stock-move.schema.json" };
3
+ const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Stock Movement Schema", "type": "object", "additionalProperties": false, "properties": { "style_id": { "type": "string", "minLength": 1 }, "colour_id": { "type": "string", "minLength": 1 }, "size_code": { "type": "string", "minLength": 1 }, "location_code": { "type": "string", "pattern": "^\\d{3}-[A-Z]+$|^[A-Z]{2,}-?[A-Z]*$|^[A-Z]{2,}\\d{3}$" }, "source_system": { "type": "string", "enum": ["bc", "centra", "sitoo"] }, "history": { "type": "array", "items": { "type": "object", "properties": { "quantity": { "type": "integer", "minimum": 0 }, "entry_no": { "type": "string" }, "external_entry_no": { "type": "string" }, "document_no": { "type": "string" }, "external_document_no": { "type": "string" }, "type": { "type": "string", "enum": ["transfer", "negative adjustment", "positive adjustment", "purchase", "sale"] }, "unit_cost": { "oneOf": [{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Money", "type": "object", "additionalProperties": false, "properties": { "value": { "type": "integer", "minimum": 0 }, "decimal_places": { "type": "integer", "minimum": 0, "maximum": 4 }, "currency": { "title": "Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "lcy_value": { "type": "integer", "minimum": 0 }, "lcy_currency": { "title": "LCY Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "lcy_decimal_places": { "type": "integer", "minimum": 0, "maximum": 4 } }, "required": ["value", "currency", "lcy_value", "lcy_currency", "decimal_places", "lcy_decimal_places"] }, { "type": "null" }] }, "document_date": { "type": "string", "format": "date" }, "posting_date": { "type": "string", "format": "date" }, "created_at": { "type": "string", "format": "date-time" } }, "required": ["quantity", "created_at", "entry_no", "document_date", "type"] } }, "last_modified_at": { "type": "string", "format": "date-time" } }, "required": ["style_id", "source_system", "location_code", "colour_id", "size_code", "history", "entry_no", "last_modified_at"], "$id": "https://shushed.example.com/stock-move.schema.json" };
4
4
  exports.default = schema;
@@ -338,17 +338,26 @@ function onResponse(config, options, requiredFlag) {
338
338
  cacheMaxAge: 0,
339
339
  };
340
340
  }
341
- function parsePrices(priceData, timeZone = 'UTC') {
341
+ function parsePrices(priceData, timeZone = 'UTC', options) {
342
342
  const result = [];
343
343
  const defaultStartDate = convertDateToDatetimeTZ(new Date(0).toISOString(), timeZone);
344
344
  const defaultEndDate = convertDateToDatetimeTZ(new Date('2099-01-01T00:00:00Z').toISOString(), timeZone);
345
345
  for (let i = 0; i < priceData.length; i += 1) {
346
- const priceChanges = (priceData[i].price_changes || []).map(x => ({
347
- effective_from: x.effective_from ? (!isNaN(new Date(x.effective_from).getTime()) ? convertDateToDatetimeTZ(x.effective_from, timeZone) : null) : defaultStartDate,
348
- effective_until: x.effective_until ? (!isNaN(new Date(x.effective_until).getTime()) ? convertDateToDatetimeTZ(x.effective_until, timeZone) : null) : defaultEndDate,
349
- price: x.price,
350
- price_type: x.price_type,
351
- }));
346
+ const priceChanges = (priceData[i].price_changes || []).map((priceChange) => {
347
+ let x = priceChange;
348
+ if (options?.overridePrices) {
349
+ x = options.overridePrices(priceChange);
350
+ }
351
+ if (x !== null) {
352
+ return {
353
+ effective_from: x.effective_from ? (!isNaN(new Date(x.effective_from).getTime()) ? convertDateToDatetimeTZ(x.effective_from, timeZone) : null) : defaultStartDate,
354
+ effective_until: x.effective_until ? (!isNaN(new Date(x.effective_until).getTime()) ? convertDateToDatetimeTZ(x.effective_until, timeZone) : null) : defaultEndDate,
355
+ price: x.price,
356
+ price_type: x.price_type,
357
+ };
358
+ }
359
+ return null;
360
+ }).filter((x) => x !== null);
352
361
  const rrpPriceTypes = parsePriceType(priceChanges.filter((x) => x.price_type === 'rrp'));
353
362
  const permPriceTypes = parsePriceType(priceChanges.filter((x) => x.price_type === 'perm'));
354
363
  const posPriceTypes = parsePriceType(priceChanges.filter((x) => x.price_type === 'pos'));
@@ -368,6 +377,7 @@ function parsePrices(priceData, timeZone = 'UTC') {
368
377
  }
369
378
  result.push({
370
379
  ...priceData[i],
380
+ ...(options?.overrideCurrency ? { currency: options.overrideCurrency } : {}),
371
381
  current_price: currentPrice,
372
382
  current_price_type: currentPriceType,
373
383
  rrp: rrpPriceTypes,
@@ -33,6 +33,12 @@ declare const schema: {
33
33
  readonly type: "integer";
34
34
  readonly minimum: 0;
35
35
  };
36
+ readonly entry_no: {
37
+ readonly type: "string";
38
+ };
39
+ readonly external_entry_no: {
40
+ readonly type: "string";
41
+ };
36
42
  readonly document_no: {
37
43
  readonly type: "string";
38
44
  };
@@ -99,7 +105,7 @@ declare const schema: {
99
105
  readonly format: "date-time";
100
106
  };
101
107
  };
102
- readonly required: readonly ["quantity", "created_at", "document_date", "type"];
108
+ readonly required: readonly ["quantity", "created_at", "entry_no", "document_date", "type"];
103
109
  };
104
110
  };
105
111
  readonly last_modified_at: {
@@ -107,7 +113,7 @@ declare const schema: {
107
113
  readonly format: "date-time";
108
114
  };
109
115
  };
110
- readonly required: readonly ["style_id", "source_system", "location_code", "colour_id", "size_code", "history", "last_modified_at"];
116
+ readonly required: readonly ["style_id", "source_system", "location_code", "colour_id", "size_code", "history", "entry_no", "last_modified_at"];
111
117
  readonly $id: "https://shushed.example.com/stock-move.schema.json";
112
118
  };
113
119
  export default schema;
@@ -9,6 +9,8 @@ export interface __MainSchema {
9
9
  history: {
10
10
  quantity: number;
11
11
  description?: string;
12
+ entry_no: string;
13
+ external_entry_no?: string;
12
14
  document_no?: string;
13
15
  external_document_no?: string;
14
16
  type: ("transfer" | "negative adjustment" | "positive adjustment" | "purchase" | "sale");
@@ -79,7 +79,10 @@ type NormPrice = {
79
79
  price: number;
80
80
  price_type: 'rrp' | 'perm' | 'pos';
81
81
  };
82
- export declare function parsePrices<T extends Price>(priceData: T[], timeZone?: string): (T & {
82
+ export declare function parsePrices<T extends Price>(priceData: T[], timeZone?: string, options?: {
83
+ overrideCurrency?: string;
84
+ overridePrices?: (priceData: Exclude<T['price_changes'], undefined>[number]) => Exclude<Exclude<T['price_changes'], undefined>[number], undefined> | null;
85
+ }): (T & {
83
86
  rrp: {
84
87
  current: NormPrice | undefined;
85
88
  future: NormPrice[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.215",
3
+ "version": "0.0.217",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",