@unchainedshop/utils 3.0.0-alpha7 → 3.0.0-rc.11

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.
Files changed (74) hide show
  1. package/lib/calculation.d.ts +0 -5
  2. package/lib/calculation.d.ts.map +1 -1
  3. package/lib/calculation.js +0 -20
  4. package/lib/calculation.js.map +1 -1
  5. package/lib/ch/addressToString.d.ts +12 -0
  6. package/lib/ch/addressToString.d.ts.map +1 -0
  7. package/lib/ch/addressToString.js +14 -0
  8. package/lib/ch/addressToString.js.map +1 -0
  9. package/lib/ch/index.d.ts +3 -0
  10. package/lib/ch/index.d.ts.map +1 -0
  11. package/lib/ch/index.js +4 -0
  12. package/lib/ch/index.js.map +1 -0
  13. package/lib/ch/priceToString.d.ts +6 -0
  14. package/lib/ch/priceToString.d.ts.map +1 -0
  15. package/lib/ch/priceToString.js +6 -0
  16. package/lib/ch/priceToString.js.map +1 -0
  17. package/lib/director/BaseDirector.js +1 -1
  18. package/lib/director/BaseDirector.js.map +1 -1
  19. package/lib/sha1.d.ts +2 -0
  20. package/lib/sha1.d.ts.map +1 -0
  21. package/lib/sha1.js +6 -0
  22. package/lib/sha1.js.map +1 -0
  23. package/lib/sha256.d.ts +2 -0
  24. package/lib/sha256.d.ts.map +1 -0
  25. package/lib/sha256.js +6 -0
  26. package/lib/sha256.js.map +1 -0
  27. package/lib/utils-index.d.ts +17 -7
  28. package/lib/utils-index.d.ts.map +1 -1
  29. package/lib/utils-index.js +3 -13
  30. package/lib/utils-index.js.map +1 -1
  31. package/package.json +8 -11
  32. package/src/calculation.test.ts +0 -43
  33. package/src/calculation.ts +0 -26
  34. package/src/ch/addressToString.ts +23 -0
  35. package/src/ch/index.ts +3 -0
  36. package/src/ch/priceToString.ts +6 -0
  37. package/src/director/BaseDirector.ts +1 -1
  38. package/src/sha1.ts +5 -0
  39. package/src/sha256.ts +5 -0
  40. package/src/utils-index.test.ts +1 -1
  41. package/src/utils-index.ts +19 -17
  42. package/tsconfig.json +4 -4
  43. package/lib/director/BaseDiscountAdapter.d.ts +0 -38
  44. package/lib/director/BaseDiscountAdapter.d.ts.map +0 -1
  45. package/lib/director/BaseDiscountAdapter.js +0 -48
  46. package/lib/director/BaseDiscountAdapter.js.map +0 -1
  47. package/lib/director/BaseDiscountDirector.d.ts +0 -13
  48. package/lib/director/BaseDiscountDirector.d.ts.map +0 -1
  49. package/lib/director/BaseDiscountDirector.js +0 -50
  50. package/lib/director/BaseDiscountDirector.js.map +0 -1
  51. package/lib/director/BasePricingAdapter.d.ts +0 -46
  52. package/lib/director/BasePricingAdapter.d.ts.map +0 -1
  53. package/lib/director/BasePricingAdapter.js +0 -25
  54. package/lib/director/BasePricingAdapter.js.map +0 -1
  55. package/lib/director/BasePricingDirector.d.ts +0 -16
  56. package/lib/director/BasePricingDirector.d.ts.map +0 -1
  57. package/lib/director/BasePricingDirector.js +0 -61
  58. package/lib/director/BasePricingDirector.js.map +0 -1
  59. package/lib/director/BasePricingSheet.d.ts +0 -47
  60. package/lib/director/BasePricingSheet.d.ts.map +0 -1
  61. package/lib/director/BasePricingSheet.js +0 -54
  62. package/lib/director/BasePricingSheet.js.map +0 -1
  63. package/lib/random-value-hex.d.ts +0 -2
  64. package/lib/random-value-hex.d.ts.map +0 -1
  65. package/lib/random-value-hex.js +0 -8
  66. package/lib/random-value-hex.js.map +0 -1
  67. package/src/director/BaseDiscountAdapter.ts +0 -89
  68. package/src/director/BaseDiscountDirector.ts +0 -77
  69. package/src/director/BasePricingAdapter.ts +0 -89
  70. package/src/director/BasePricingDirector.ts +0 -133
  71. package/src/director/BasePricingSheet.ts +0 -121
  72. package/src/director/base-discount-adapter.test.ts +0 -49
  73. package/src/director/base-price-sheet.test.ts +0 -100
  74. package/src/random-value-hex.ts +0 -8
@@ -1,9 +1,4 @@
1
- import { IBasePricingSheet, PricingCalculation } from './director/BasePricingSheet.js';
2
1
  export declare const roundToNext: (value: number, precision: number) => number;
3
- export declare const resolveRatioAndTaxDivisorForPricingSheet: (pricing: IBasePricingSheet<PricingCalculation>, total: number) => {
4
- ratio: number;
5
- taxDivisor: number;
6
- };
7
2
  export declare const calculateAmountToSplit: (configuration: {
8
3
  rate?: number;
9
4
  fixedRate?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"calculation.d.ts","sourceRoot":"","sources":["../src/calculation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEvF,eAAO,MAAM,WAAW,UAAW,MAAM,aAAa,MAAM,WAClB,CAAC;AAE3C,eAAO,MAAM,wCAAwC,YAC1C,iBAAiB,CAAC,kBAAkB,CAAC,SACvC,MAAM;;;CAoBd,CAAC;AAEF,eAAO,MAAM,sBAAsB,kBAClB;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,UAC5C,MAAM,WAQf,CAAC;AAEF,eAAO,MAAM,SAAS,kBAAmB;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,wBAG7E,CAAC;AAEF,eAAO,MAAM,YAAY,UAAW,MAAM,QAAQ,MAAM,cAAc,OAAO,WAE5E,CAAC;AAEF,eAAO,MAAM,mBAAmB,0BACP;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,UACtD,MAAM,aAMf,CAAC;AAEF,eAAO,MAAM,6BAA6B,mCAQzC,CAAC"}
1
+ {"version":3,"file":"calculation.d.ts","sourceRoot":"","sources":["../src/calculation.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,UAAW,MAAM,aAAa,MAAM,WAClB,CAAC;AAE3C,eAAO,MAAM,sBAAsB,kBAClB;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,UAC5C,MAAM,WAQf,CAAC;AAEF,eAAO,MAAM,SAAS,kBAAmB;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,wBAG7E,CAAC;AAEF,eAAO,MAAM,YAAY,UAAW,MAAM,QAAQ,MAAM,cAAc,OAAO,WAE5E,CAAC;AAEF,eAAO,MAAM,mBAAmB,0BACP;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,UACtD,MAAM,aAMf,CAAC;AAEF,eAAO,MAAM,6BAA6B,mCAQzC,CAAC"}
@@ -1,24 +1,4 @@
1
1
  export const roundToNext = (value, precision) => Math.ceil(value / precision) * precision;
2
- export const resolveRatioAndTaxDivisorForPricingSheet = (pricing, total) => {
3
- if (total === 0 || !pricing) {
4
- return {
5
- ratio: 1,
6
- taxDivisor: 1,
7
- };
8
- }
9
- const tax = pricing.taxSum();
10
- const gross = pricing.gross();
11
- if (gross - tax === 0) {
12
- return {
13
- ratio: 0,
14
- taxDivisor: 0,
15
- };
16
- }
17
- return {
18
- ratio: gross / total,
19
- taxDivisor: gross / (gross - tax),
20
- };
21
- };
22
2
  export const calculateAmountToSplit = (configuration, amount) => {
23
3
  const deductionAmount = configuration.rate
24
4
  ? amount * configuration.rate
@@ -1 +1 @@
1
- {"version":3,"file":"calculation.js","sourceRoot":"","sources":["../src/calculation.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,SAAiB,EAAE,EAAE,CAC9D,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;AAE3C,MAAM,CAAC,MAAM,wCAAwC,GAAG,CACtD,OAA8C,EAC9C,KAAa,EACb,EAAE;IACF,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO;YACL,KAAK,EAAE,CAAC;YACR,UAAU,EAA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AC/F,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;IAC9D,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,EAAE,KAAK,EAAE,EAAE;QACnD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACzE,OAAO,CAAC,qBAAqB,GAAG,WAAW,EAAE,gBAAgB,GAAG,cAAc,CAAC,CAAC;IAClF,CAAC,EACD,CAAC,CAAC,EAAE,CAAC,CAAC,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare const addressToString: (address: {
2
+ addressLine?: string;
3
+ addressLine2?: string;
4
+ city?: string;
5
+ company?: string;
6
+ countryCode?: string;
7
+ firstName?: string;
8
+ lastName?: string;
9
+ postalCode?: string;
10
+ regionCode?: string;
11
+ }) => string;
12
+ //# sourceMappingURL=addressToString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addressToString.d.ts","sourceRoot":"","sources":["../../src/ch/addressToString.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,YAAa;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,WAYA,CAAC"}
@@ -0,0 +1,14 @@
1
+ export const addressToString = (address) => {
2
+ return [
3
+ [address.firstName, address.lastName].filter(Boolean).join(' '),
4
+ address.company,
5
+ address.addressLine,
6
+ address.addressLine2,
7
+ [address.postalCode, address.city].filter(Boolean).join(' '),
8
+ address.regionCode,
9
+ [address.countryCode].filter(Boolean).join(''),
10
+ ]
11
+ .filter(Boolean)
12
+ .join('\n');
13
+ };
14
+ //# sourceMappingURL=addressToString.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addressToString.js","sourceRoot":"","sources":["../../src/ch/addressToString.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAU/B,EAAE,EAAE;IACH,OAAO;QACL,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC/D,OAAO,CAAC,OAAO;QACf,OAAO,CAAC,WAAW;QACnB,OAAO,CAAC,YAAY;QACpB,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC5D,OAAO,CAAC,UAAU;QAClB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;KAC/C;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './addressToString.js';
2
+ export * from './priceToString.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ch/index.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,4 @@
1
+ // This file contains helpers specifically for Swiss projects. It is not intended to be used in other projects.
2
+ export * from './addressToString.js';
3
+ export * from './priceToString.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ch/index.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const priceToString: ({ amount, currency }: {
2
+ amount: number;
3
+ currency: string;
4
+ }) => string;
5
+ export default priceToString;
6
+ //# sourceMappingURL=priceToString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priceToString.d.ts","sourceRoot":"","sources":["../../src/ch/priceToString.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,yBAA0B;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,WAGvF,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ export const priceToString = ({ amount, currency }) => {
2
+ const fixedPrice = amount / 100;
3
+ return `${currency} ${fixedPrice}`;
4
+ };
5
+ export default priceToString;
6
+ //# sourceMappingURL=priceToString.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priceToString.js","sourceRoot":"","sources":["../../src/ch/priceToString.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAwC,EAAE,EAAE;IAC1F,MAAM,UAAU,GAAG,MAAM,GAAG,GAAG,CAAC;IAChC,OAAO,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACrC,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -9,7 +9,7 @@ export const BaseDirector = (directorName, options) => {
9
9
  getAdapters: ({ adapterFilter } = {}) => {
10
10
  const sortKey = options?.adapterSortKey || keyField;
11
11
  return Array.from(Adapters.values())
12
- .sort((left, right) => left[sortKey] - right[sortKey])
12
+ .toSorted((left, right) => left[sortKey] - right[sortKey])
13
13
  .filter(adapterFilter || (() => true));
14
14
  },
15
15
  registerAdapter: (Adapter) => {
@@ -1 +1 @@
1
- {"version":3,"file":"BaseDirector.js","sourceRoot":"","sources":["../../src/director/BaseDirector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAU5C,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,YAAoB,EACpB,OAGC,EAC2B,EAAE;IAC9B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAChD,MAAM,QAAQ,GAAG,OAAO,EAAE,eAAe,IAAI,KAAK,CAAC;IAEnD,OAAO;QACL,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;YAClB,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QAED,WAAW,EAAE,CAAC,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,EAAE;YACtC,MAAM,OAAO,GAAG,OAAO,EAAE,cAAc,IAAI,QAAQ,CAAC;YACpD,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;iBACjC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;iBACrD,MAAM,CAAC,aAAa,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3C,CAAC;QAED,eAAe,EAAE,CAAC,OAAO,EAAE,EAAE;YAC3B,GAAG,CACD,GAAG,YAAY,kBAAkB,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAC/E,OAAO,CAAC,GACV,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,KAAK,GAAG,CACzC,CAAC;YACF,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,QAA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CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAC/E,OAAO,CAAC,GACV,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,KAAK,GAAG,CACzC,CAAC;YACF,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;QAED,iBAAiB,EAAE,CAAC,GAAG,EAAE,EAAE;YACzB,GAAG,CAAC,GAAG,YAAY,oBAAoB,GAAG,EAAE,CAAC,CAAC;YAC9C,OAAO,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
package/lib/sha1.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export default function sha1(message: any): Promise<Buffer<ArrayBufferLike>>;
2
+ //# sourceMappingURL=sha1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha1.d.ts","sourceRoot":"","sources":["../src/sha1.ts"],"names":[],"mappings":"AAAA,wBAA8B,IAAI,CAAC,OAAO,KAAA,oCAIzC"}
package/lib/sha1.js ADDED
@@ -0,0 +1,6 @@
1
+ export default async function sha1(message) {
2
+ const bytes = new TextEncoder().encode(message);
3
+ const hashBuffer = await crypto.subtle.digest('SHA-1', bytes);
4
+ return Buffer.from(hashBuffer);
5
+ }
6
+ //# sourceMappingURL=sha1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha1.js","sourceRoot":"","sources":["../src/sha1.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,IAAI,CAAC,OAAO;IACxC,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC9D,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function sha256(message: any): Promise<string>;
2
+ //# sourceMappingURL=sha256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA,wBAA8B,MAAM,CAAC,OAAO,KAAA,mBAI3C"}
package/lib/sha256.js ADDED
@@ -0,0 +1,6 @@
1
+ export default async function sha256(message) {
2
+ const bytes = new TextEncoder().encode(message);
3
+ const hashBuffer = await crypto.subtle.digest('SHA-256', bytes);
4
+ return Buffer.from(hashBuffer).toString('hex');
5
+ }
6
+ //# sourceMappingURL=sha256.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.js","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,MAAM,CAAC,OAAO;IAC1C,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAChE,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC"}
@@ -1,12 +1,13 @@
1
1
  export * as calculation from './calculation.js';
2
+ export * as ch from './ch/index.js';
2
3
  export * from './locale-helpers.js';
3
4
  export { default as objectInvert } from './object-invert.js';
4
5
  export { default as findUnusedSlug } from './find-unused-slug.js';
5
6
  export { default as slugify } from './slugify.js';
6
- export { default as pipePromises } from './pipe-promises.js';
7
7
  export { default as generateRandomHash } from './generate-random-hash.js';
8
- export { default as randomValueHex } from './random-value-hex.js';
9
8
  export { default as buildObfuscatedFieldsFilter } from './build-obfuscated-fields-filter.js';
9
+ export { default as sha256 } from './sha256.js';
10
+ export { default as sha1 } from './sha1.js';
10
11
  export declare enum SortDirection {
11
12
  ASC = "ASC",
12
13
  DESC = "DESC"
@@ -15,13 +16,22 @@ export type SortOption = {
15
16
  key: string;
16
17
  value: SortDirection;
17
18
  };
19
+ export type Price = {
20
+ amount: number;
21
+ currency: string;
22
+ };
23
+ export interface PricingCalculation {
24
+ category: string;
25
+ amount: number;
26
+ baseCategory?: string;
27
+ meta?: any;
28
+ }
18
29
  export type NodeOrTree<T> = string | Tree<T>;
19
30
  export type Tree<T> = Array<NodeOrTree<T>>;
31
+ export interface DateFilterInput {
32
+ start?: string;
33
+ end?: string;
34
+ }
20
35
  export * from './director/BaseAdapter.js';
21
36
  export * from './director/BaseDirector.js';
22
- export * from './director/BasePricingAdapter.js';
23
- export * from './director/BasePricingDirector.js';
24
- export * from './director/BasePricingSheet.js';
25
- export * from './director/BaseDiscountAdapter.js';
26
- export * from './director/BaseDiscountDirector.js';
27
37
  //# sourceMappingURL=utils-index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils-index.d.ts","sourceRoot":"","sources":["../src/utils-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAEhD,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAM7F,oBAAY,aAAa;IACvB,GAAG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,MAAM,CAAC;IACZ,KAAK,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3C,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC"}
@@ -1,28 +1,18 @@
1
1
  export * as calculation from './calculation.js';
2
+ export * as ch from './ch/index.js';
2
3
  export * from './locale-helpers.js';
3
4
  export { default as objectInvert } from './object-invert.js';
4
5
  export { default as findUnusedSlug } from './find-unused-slug.js';
5
6
  export { default as slugify } from './slugify.js';
6
- export { default as pipePromises } from './pipe-promises.js';
7
7
  export { default as generateRandomHash } from './generate-random-hash.js';
8
- export { default as randomValueHex } from './random-value-hex.js';
9
8
  export { default as buildObfuscatedFieldsFilter } from './build-obfuscated-fields-filter.js';
10
- /*
11
- * Schemas
12
- */
9
+ export { default as sha256 } from './sha256.js';
10
+ export { default as sha1 } from './sha1.js';
13
11
  export var SortDirection;
14
12
  (function (SortDirection) {
15
13
  SortDirection["ASC"] = "ASC";
16
14
  SortDirection["DESC"] = "DESC";
17
15
  })(SortDirection || (SortDirection = {}));
18
- /*
19
- * Director
20
- */
21
16
  export * from './director/BaseAdapter.js';
22
17
  export * from './director/BaseDirector.js';
23
- export * from './director/BasePricingAdapter.js';
24
- export * from './director/BasePricingDirector.js';
25
- export * from './director/BasePricingSheet.js';
26
- export * from './director/BaseDiscountAdapter.js';
27
- export * from './director/BaseDiscountDirector.js';
28
18
  //# sourceMappingURL=utils-index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils-index.js","sourceRoot":"","sources":["../src/utils-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAEhD,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAE7F;;GAEG;AAEH,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,4BAAW,CAAA;IACX,8BAAa,CAAA;AACf,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB;AASD;;GAEG;AAEH,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAE3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAE/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC"}
1
+ {"version":3,"file":"utils-index.js","sourceRoot":"","sources":["../src/utils-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,eAAe,CAAC;AAEpC,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAC7F,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,4BAAW,CAAA;IACX,8BAAa,CAAA;AACf,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB;AAyBD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC"}
package/package.json CHANGED
@@ -1,16 +1,13 @@
1
1
  {
2
2
  "name": "@unchainedshop/utils",
3
- "version": "3.0.0-alpha7",
3
+ "version": "3.0.0-rc.11",
4
4
  "main": "lib/utils-index.js",
5
- "exports": {
6
- ".": "./lib/utils-index.js",
7
- "./*": "./lib/*"
8
- },
9
5
  "types": "lib/utils-index.d.ts",
10
6
  "type": "module",
11
7
  "scripts": {
12
- "clean": "rm -rf lib",
13
- "prepublishOnly": "npm run clean && tsc",
8
+ "clean": "tsc -b --clean",
9
+ "build": "tsc -b",
10
+ "prepublishOnly": "npm run clean && npm run build",
14
11
  "watch": "tsc -w",
15
12
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
16
13
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
@@ -30,13 +27,13 @@
30
27
  },
31
28
  "homepage": "https://github.com/unchainedshop/unchained#readme",
32
29
  "dependencies": {
33
- "@unchainedshop/logger": "^3.0.0-alpha4",
30
+ "@unchainedshop/logger": "^3.0.0-rc.11",
34
31
  "hashids": "^2.3.0",
35
- "resolve-accept-language": "^3.1.8"
32
+ "resolve-accept-language": "^3.1.10"
36
33
  },
37
34
  "devDependencies": {
38
- "@types/node": "^22.8.1",
35
+ "@types/node": "^22.10.2",
39
36
  "jest": "^29.7.0",
40
- "typescript": "^5.6.3"
37
+ "typescript": "^5.7.2"
41
38
  }
42
39
  }
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  applyRate,
3
- resolveRatioAndTaxDivisorForPricingSheet,
4
3
  roundToNext,
5
4
  resolveAmountAndTax,
6
5
  applyDiscountToMultipleShares,
@@ -29,48 +28,6 @@ describe('roundToNext', () => {
29
28
  });
30
29
  });
31
30
 
32
- describe('resolveRatioAndTaxDivisorForPricingSheet', () => {
33
- it('total is 0 and pricing is provided', () => {
34
- const pricing: any = {
35
- taxSum: () => 10,
36
- gross: () => 20,
37
- net: () => 10,
38
- };
39
- const result = resolveRatioAndTaxDivisorForPricingSheet(pricing, 0);
40
- expect(result).toEqual({ ratio: 1, taxDivisor: 1 });
41
- });
42
-
43
- it('gross - tax is 0', () => {
44
- const pricing: any = {
45
- taxSum: () => 10,
46
- gross: () => 10,
47
- net: () => 0,
48
- };
49
- const result = resolveRatioAndTaxDivisorForPricingSheet(pricing, 20);
50
- expect(result).toEqual({ ratio: 0, taxDivisor: 0 });
51
- });
52
-
53
- it('gross - tax is not 0', () => {
54
- const pricing: any = {
55
- taxSum: () => 10,
56
- gross: () => 20,
57
- net: () => 10,
58
- };
59
- const result = resolveRatioAndTaxDivisorForPricingSheet(pricing, 20);
60
- expect(result).toEqual({ ratio: 1, taxDivisor: 2 });
61
- });
62
-
63
- it('taxSum is 0', () => {
64
- const pricing: any = {
65
- taxSum: () => 0,
66
- gross: () => 20,
67
- net: () => 20,
68
- };
69
- const result = resolveRatioAndTaxDivisorForPricingSheet(pricing, 20);
70
- expect(result).toEqual({ ratio: 1, taxDivisor: 1 });
71
- });
72
- });
73
-
74
31
  describe('resolveAmountAndTax', () => {
75
32
  it('ratio is 0 and taxDivisor is 0', () => {
76
33
  const result = resolveAmountAndTax({ ratio: 0, taxDivisor: 0 }, 100);
@@ -1,32 +1,6 @@
1
- import { IBasePricingSheet, PricingCalculation } from './director/BasePricingSheet.js';
2
-
3
1
  export const roundToNext = (value: number, precision: number) =>
4
2
  Math.ceil(value / precision) * precision;
5
3
 
6
- export const resolveRatioAndTaxDivisorForPricingSheet = (
7
- pricing: IBasePricingSheet<PricingCalculation>,
8
- total: number,
9
- ) => {
10
- if (total === 0 || !pricing) {
11
- return {
12
- ratio: 1,
13
- taxDivisor: 1,
14
- };
15
- }
16
- const tax = pricing.taxSum();
17
- const gross = pricing.gross();
18
- if (gross - tax === 0) {
19
- return {
20
- ratio: 0,
21
- taxDivisor: 0,
22
- };
23
- }
24
- return {
25
- ratio: gross / total,
26
- taxDivisor: gross / (gross - tax),
27
- };
28
- };
29
-
30
4
  export const calculateAmountToSplit = (
31
5
  configuration: { rate?: number; fixedRate?: number },
32
6
  amount: number,
@@ -0,0 +1,23 @@
1
+ export const addressToString = (address: {
2
+ addressLine?: string;
3
+ addressLine2?: string;
4
+ city?: string;
5
+ company?: string;
6
+ countryCode?: string;
7
+ firstName?: string;
8
+ lastName?: string;
9
+ postalCode?: string;
10
+ regionCode?: string;
11
+ }) => {
12
+ return [
13
+ [address.firstName, address.lastName].filter(Boolean).join(' '),
14
+ address.company,
15
+ address.addressLine,
16
+ address.addressLine2,
17
+ [address.postalCode, address.city].filter(Boolean).join(' '),
18
+ address.regionCode,
19
+ [address.countryCode].filter(Boolean).join(''),
20
+ ]
21
+ .filter(Boolean)
22
+ .join('\n');
23
+ };
@@ -0,0 +1,3 @@
1
+ // This file contains helpers specifically for Swiss projects. It is not intended to be used in other projects.
2
+ export * from './addressToString.js';
3
+ export * from './priceToString.js';
@@ -0,0 +1,6 @@
1
+ export const priceToString = ({ amount, currency }: { amount: number; currency: string }) => {
2
+ const fixedPrice = amount / 100;
3
+ return `${currency} ${fixedPrice}`;
4
+ };
5
+
6
+ export default priceToString;
@@ -26,7 +26,7 @@ export const BaseDirector = <AdapterType extends IBaseAdapter>(
26
26
  getAdapters: ({ adapterFilter } = {}) => {
27
27
  const sortKey = options?.adapterSortKey || keyField;
28
28
  return Array.from(Adapters.values())
29
- .sort((left, right) => left[sortKey] - right[sortKey])
29
+ .toSorted((left, right) => left[sortKey] - right[sortKey])
30
30
  .filter(adapterFilter || (() => true));
31
31
  },
32
32
 
package/src/sha1.ts ADDED
@@ -0,0 +1,5 @@
1
+ export default async function sha1(message) {
2
+ const bytes = new TextEncoder().encode(message);
3
+ const hashBuffer = await crypto.subtle.digest('SHA-1', bytes);
4
+ return Buffer.from(hashBuffer);
5
+ }
package/src/sha256.ts ADDED
@@ -0,0 +1,5 @@
1
+ export default async function sha256(message) {
2
+ const bytes = new TextEncoder().encode(message);
3
+ const hashBuffer = await crypto.subtle.digest('SHA-256', bytes);
4
+ return Buffer.from(hashBuffer).toString('hex');
5
+ }
@@ -1,4 +1,4 @@
1
- import { resolveBestCountry, resolveBestSupported, slugify, systemLocale } from '@unchainedshop/utils';
1
+ import { resolveBestCountry, resolveBestSupported, slugify, systemLocale } from './utils-index.js';
2
2
  import generateHashId from './generate-random-hash.js';
3
3
 
4
4
  describe('Utils', () => {
@@ -1,17 +1,14 @@
1
1
  export * as calculation from './calculation.js';
2
+ export * as ch from './ch/index.js';
2
3
 
3
4
  export * from './locale-helpers.js';
4
5
  export { default as objectInvert } from './object-invert.js';
5
6
  export { default as findUnusedSlug } from './find-unused-slug.js';
6
7
  export { default as slugify } from './slugify.js';
7
- export { default as pipePromises } from './pipe-promises.js';
8
8
  export { default as generateRandomHash } from './generate-random-hash.js';
9
- export { default as randomValueHex } from './random-value-hex.js';
10
9
  export { default as buildObfuscatedFieldsFilter } from './build-obfuscated-fields-filter.js';
11
-
12
- /*
13
- * Schemas
14
- */
10
+ export { default as sha256 } from './sha256.js';
11
+ export { default as sha1 } from './sha1.js';
15
12
 
16
13
  export enum SortDirection {
17
14
  ASC = 'ASC',
@@ -23,18 +20,23 @@ export type SortOption = {
23
20
  value: SortDirection;
24
21
  };
25
22
 
26
- export type NodeOrTree<T> = string | Tree<T>; // eslint-disable-line
23
+ export type Price = { amount: number; currency: string };
24
+
25
+ export interface PricingCalculation {
26
+ category: string;
27
+ amount: number;
28
+ baseCategory?: string;
29
+ meta?: any;
30
+ }
31
+
32
+ export type NodeOrTree<T> = string | Tree<T>;
33
+
27
34
  export type Tree<T> = Array<NodeOrTree<T>>;
28
- /*
29
- * Director
30
- */
35
+
36
+ export interface DateFilterInput {
37
+ start?: string;
38
+ end?: string;
39
+ }
31
40
 
32
41
  export * from './director/BaseAdapter.js';
33
42
  export * from './director/BaseDirector.js';
34
-
35
- export * from './director/BasePricingAdapter.js';
36
- export * from './director/BasePricingDirector.js';
37
- export * from './director/BasePricingSheet.js';
38
-
39
- export * from './director/BaseDiscountAdapter.js';
40
- export * from './director/BaseDiscountDirector.js';
package/tsconfig.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "extends": "../shared/base.tsconfig.json",
3
3
  "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "lib"
4
+ "declarationDir": "./lib",
5
+ "rootDir": "./src",
6
+ "outDir": "./lib"
6
7
  },
7
- "exclude": ["**/*.test.ts", "**/*.test.js", "tests"],
8
- "include": ["./src"]
8
+ "exclude": ["**/*.test.ts", "**/*.test.js", "tests", "lib"]
9
9
  }
@@ -1,38 +0,0 @@
1
- import { UnchainedCore } from '@unchainedshop/core';
2
- import { IBaseAdapter } from './BaseAdapter.js';
3
- import { IPricingSheet, PricingCalculation } from './BasePricingSheet.js';
4
- export interface DiscountContext {
5
- code?: string;
6
- orderDiscount?: {
7
- _id?: string;
8
- orderId: string;
9
- };
10
- order?: {
11
- _id?: string;
12
- userId: string;
13
- };
14
- }
15
- export type IDiscountAdapter<DiscountConfiguration> = IBaseAdapter & {
16
- orderIndex: number;
17
- isManualAdditionAllowed: (code: string) => Promise<boolean>;
18
- isManualRemovalAllowed: () => Promise<boolean>;
19
- actions: (params: {
20
- context: DiscountContext & UnchainedCore;
21
- }) => Promise<DiscountAdapterActions<DiscountConfiguration>>;
22
- };
23
- export interface DiscountAdapterActions<DiscountConfiguration> {
24
- isValidForSystemTriggering: () => Promise<boolean>;
25
- isValidForCodeTriggering: (params: {
26
- code: string;
27
- }) => Promise<boolean>;
28
- discountForPricingAdapterKey: (params: {
29
- pricingAdapterKey: string;
30
- calculationSheet: IPricingSheet<PricingCalculation>;
31
- }) => DiscountConfiguration;
32
- reserve: (params: {
33
- code: string;
34
- }) => Promise<any>;
35
- release: () => Promise<void>;
36
- }
37
- export declare const BaseDiscountAdapter: Omit<IDiscountAdapter<unknown>, 'key' | 'label' | 'version'>;
38
- //# sourceMappingURL=BaseDiscountAdapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BaseDiscountAdapter.d.ts","sourceRoot":"","sources":["../../src/director/BaseDiscountAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE1E,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAClD,KAAK,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C;AAED,MAAM,MAAM,gBAAgB,CAAC,qB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