@unchainedshop/utils 4.0.0-rc.9 → 4.0.1

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 (80) hide show
  1. package/lib/calculation.js +1 -1
  2. package/lib/calculation.js.map +1 -1
  3. package/lib/ch/addressToString.d.ts +1 -1
  4. package/lib/ch/addressToString.d.ts.map +1 -1
  5. package/lib/ch/addressToString.js +2 -0
  6. package/lib/ch/addressToString.js.map +1 -1
  7. package/lib/director/BaseDirector.d.ts +1 -1
  8. package/lib/director/BaseDirector.d.ts.map +1 -1
  9. package/lib/director/BaseDirector.js +1 -1
  10. package/lib/director/BaseDirector.js.map +1 -1
  11. package/lib/director/BaseDiscountAdapter.d.ts +3 -0
  12. package/lib/director/BaseDiscountAdapter.d.ts.map +1 -0
  13. package/lib/director/BaseDiscountAdapter.js +48 -0
  14. package/lib/director/BaseDiscountAdapter.js.map +1 -0
  15. package/lib/director/BaseDiscountDirector.d.ts +3 -0
  16. package/lib/director/BaseDiscountDirector.d.ts.map +1 -0
  17. package/lib/director/BaseDiscountDirector.js +50 -0
  18. package/lib/director/BaseDiscountDirector.js.map +1 -0
  19. package/lib/director/BasePricingAdapter.d.ts +3 -0
  20. package/lib/director/BasePricingAdapter.d.ts.map +1 -0
  21. package/lib/director/BasePricingAdapter.js +25 -0
  22. package/lib/director/BasePricingAdapter.js.map +1 -0
  23. package/lib/director/BasePricingDirector.d.ts +3 -0
  24. package/lib/director/BasePricingDirector.d.ts.map +1 -0
  25. package/lib/director/BasePricingDirector.js +61 -0
  26. package/lib/director/BasePricingDirector.js.map +1 -0
  27. package/lib/director/BasePricingSheet.d.ts +3 -0
  28. package/lib/director/BasePricingSheet.d.ts.map +1 -0
  29. package/lib/director/BasePricingSheet.js +54 -0
  30. package/lib/director/BasePricingSheet.js.map +1 -0
  31. package/lib/find-unused-slug.d.ts +2 -2
  32. package/lib/find-unused-slug.d.ts.map +1 -1
  33. package/lib/find-unused-slug.js +2 -0
  34. package/lib/find-unused-slug.js.map +1 -1
  35. package/lib/locale-helpers.d.ts +13 -4
  36. package/lib/locale-helpers.d.ts.map +1 -1
  37. package/lib/locale-helpers.js +33 -24
  38. package/lib/locale-helpers.js.map +1 -1
  39. package/lib/random-value-hex.d.ts +2 -0
  40. package/lib/random-value-hex.d.ts.map +1 -0
  41. package/lib/random-value-hex.js +8 -0
  42. package/lib/random-value-hex.js.map +1 -0
  43. package/lib/schemas/AddressSchema.d.ts +3 -0
  44. package/lib/schemas/AddressSchema.d.ts.map +1 -0
  45. package/lib/schemas/AddressSchema.js +13 -0
  46. package/lib/schemas/AddressSchema.js.map +1 -0
  47. package/lib/schemas/ContactSchema.d.ts +3 -0
  48. package/lib/schemas/ContactSchema.d.ts.map +1 -0
  49. package/lib/schemas/ContactSchema.js +6 -0
  50. package/lib/schemas/ContactSchema.js.map +1 -0
  51. package/lib/schemas/UsersSchema.d.ts +5 -0
  52. package/lib/schemas/UsersSchema.d.ts.map +1 -0
  53. package/lib/schemas/UsersSchema.js +52 -0
  54. package/lib/schemas/UsersSchema.js.map +1 -0
  55. package/lib/schemas/commonSchemaFields.d.ts +35 -0
  56. package/lib/schemas/commonSchemaFields.d.ts.map +1 -0
  57. package/lib/schemas/commonSchemaFields.js +28 -0
  58. package/lib/schemas/commonSchemaFields.js.map +1 -0
  59. package/lib/schemas/index.d.ts +43 -0
  60. package/lib/schemas/index.d.ts.map +1 -0
  61. package/lib/schemas/index.js +14 -0
  62. package/lib/schemas/index.js.map +1 -0
  63. package/lib/sha1.d.ts +1 -1
  64. package/lib/sha1.d.ts.map +1 -1
  65. package/lib/sha1.js +2 -1
  66. package/lib/sha1.js.map +1 -1
  67. package/lib/sha256.d.ts.map +1 -1
  68. package/lib/sha256.js +4 -1
  69. package/lib/sha256.js.map +1 -1
  70. package/package.json +2 -2
  71. package/src/calculation.ts +3 -3
  72. package/src/ch/addressToString.ts +4 -2
  73. package/src/director/BaseDirector.ts +2 -2
  74. package/src/director/base-director.test.ts +4 -4
  75. package/src/find-unused-slug.ts +5 -3
  76. package/src/locale-helpers.ts +52 -32
  77. package/src/sha1.ts +2 -1
  78. package/src/sha256.ts +4 -1
  79. package/src/utils-index.test.ts +1 -2
  80. package/tsconfig.json +2 -1
@@ -0,0 +1,3 @@
1
+ import SimpleSchema from 'simpl-schema';
2
+ export declare const ContactSchema: SimpleSchema;
3
+ //# sourceMappingURL=ContactSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContactSchema.d.ts","sourceRoot":"","sources":["../../src/schemas/ContactSchema.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,eAAO,MAAM,aAAa,cAMzB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import SimpleSchema from 'simpl-schema';
2
+ export const ContactSchema = new SimpleSchema({
3
+ telNumber: String,
4
+ emailAddress: String,
5
+ }, { requiredByDefault: false });
6
+ //# sourceMappingURL=ContactSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContactSchema.js","sourceRoot":"","sources":["../../src/schemas/ContactSchema.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,YAAY,CAC3C;IACE,SAAS,EAAE,MAAM;IACjB,YAAY,EAAE,MAAM;CACrB,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
@@ -0,0 +1,5 @@
1
+ import SimpleSchema from 'simpl-schema';
2
+ export declare const LastLoginSchema: SimpleSchema;
3
+ export declare const LastContactSchema: SimpleSchema;
4
+ export declare const UserSchema: SimpleSchema;
5
+ //# sourceMappingURL=UsersSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsersSchema.d.ts","sourceRoot":"","sources":["../../src/schemas/UsersSchema.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,cAAc,CAAC;AAexC,eAAO,MAAM,eAAe,cAU3B,CAAC;AAEF,eAAO,MAAM,iBAAiB,cAM7B,CAAC;AAEF,eAAO,MAAM,UAAU,cA+BtB,CAAC"}
@@ -0,0 +1,52 @@
1
+ import SimpleSchema from 'simpl-schema';
2
+ import { AddressSchema } from './AddressSchema.js';
3
+ import { timestampFields } from './commonSchemaFields.js';
4
+ const ProfileSchema = new SimpleSchema({
5
+ displayName: String,
6
+ birthday: Date,
7
+ phoneMobile: String,
8
+ gender: String,
9
+ address: AddressSchema,
10
+ }, { requiredByDefault: false });
11
+ export const LastLoginSchema = new SimpleSchema({
12
+ timestamp: Date,
13
+ locale: String,
14
+ countryCode: String,
15
+ remoteAddress: String,
16
+ remotePort: String,
17
+ userAgent: String,
18
+ }, { requiredByDefault: false });
19
+ export const LastContactSchema = new SimpleSchema({
20
+ telNumber: String,
21
+ emailAddress: String,
22
+ }, { requiredByDefault: false });
23
+ export const UserSchema = new SimpleSchema({
24
+ emails: Array,
25
+ 'emails.$': Object,
26
+ 'emails.$.address': String,
27
+ 'emails.$.verified': Boolean,
28
+ username: String,
29
+ lastLogin: LastLoginSchema,
30
+ profile: ProfileSchema,
31
+ lastBillingAddress: AddressSchema,
32
+ lastContact: LastContactSchema,
33
+ guest: Boolean,
34
+ initialPassword: Boolean,
35
+ tags: Array,
36
+ 'tags.$': String,
37
+ avatarId: String,
38
+ meta: {
39
+ type: Object,
40
+ optional: true,
41
+ blackbox: true,
42
+ },
43
+ services: {
44
+ type: Object,
45
+ optional: true,
46
+ blackbox: true,
47
+ },
48
+ roles: Array,
49
+ 'roles.$': String,
50
+ ...timestampFields,
51
+ }, { requiredByDefault: false });
52
+ //# sourceMappingURL=UsersSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UsersSchema.js","sourceRoot":"","sources":["../../src/schemas/UsersSchema.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,aAAa,GAAG,IAAI,YAAY,CACpC;IACE,WAAW,EAAE,MAAM;IACnB,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,MAAM;IACnB,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,aAAa;CACvB,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,YAAY,CAC7C;IACE,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,MAAM;IACd,WAAW,EAAE,MAAM;IACnB,aAAa,EAAE,MAAM;IACrB,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,MAAM;CAClB,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,YAAY,CAC/C;IACE,SAAS,EAAE,MAAM;IACjB,YAAY,EAAE,MAAM;CACrB,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,YAAY,CACxC;IACE,MAAM,EAAE,KAAK;IACb,UAAU,EAAE,MAAM;IAClB,kBAAkB,EAAE,MAAM;IAC1B,mBAAmB,EAAE,OAAO;IAC5B,QAAQ,EAAE,MAAM;IAChB,SAAS,EAAE,eAAe;IAC1B,OAAO,EAAE,aAAa;IACtB,kBAAkB,EAAE,aAAa;IACjC,WAAW,EAAE,iBAAiB;IAC9B,KAAK,EAAE,OAAO;IACd,eAAe,EAAE,OAAO;IACxB,IAAI,EAAE,KAAK;IACX,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI;KACf;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI;KACf;IACD,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,MAAM;IACjB,GAAG,eAAe;CACnB,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
@@ -0,0 +1,35 @@
1
+ export declare const contextFields: {
2
+ context: {
3
+ type: ObjectConstructor;
4
+ blackbox: boolean;
5
+ required: boolean;
6
+ };
7
+ };
8
+ export declare const logFields: {
9
+ log: ArrayConstructor;
10
+ 'log.$': {
11
+ type: ObjectConstructor;
12
+ };
13
+ 'log.$.date': {
14
+ type: DateConstructor;
15
+ };
16
+ 'log.$.status': {
17
+ type: StringConstructor;
18
+ };
19
+ 'log.$.info': {
20
+ type: StringConstructor;
21
+ };
22
+ };
23
+ export declare const timestampFields: {
24
+ created: {
25
+ type: DateConstructor;
26
+ required: boolean;
27
+ };
28
+ updated: {
29
+ type: DateConstructor;
30
+ };
31
+ deleted: {
32
+ type: DateConstructor;
33
+ };
34
+ };
35
+ //# sourceMappingURL=commonSchemaFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonSchemaFields.d.ts","sourceRoot":"","sources":["../../src/schemas/commonSchemaFields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;;;CAMzB,CAAC;AAEF,eAAO,MAAM,SAAS;;;;;;;;;;;;;;CAcrB,CAAC;AAEF,eAAO,MAAM,eAAe;;;;;;;;;;;CAI3B,CAAC"}
@@ -0,0 +1,28 @@
1
+ export const contextFields = {
2
+ context: {
3
+ type: Object,
4
+ blackbox: true,
5
+ required: false,
6
+ },
7
+ };
8
+ export const logFields = {
9
+ log: Array,
10
+ 'log.$': {
11
+ type: Object,
12
+ },
13
+ 'log.$.date': {
14
+ type: Date,
15
+ },
16
+ 'log.$.status': {
17
+ type: String,
18
+ },
19
+ 'log.$.info': {
20
+ type: String,
21
+ },
22
+ };
23
+ export const timestampFields = {
24
+ created: { type: Date, required: true },
25
+ updated: { type: Date },
26
+ deleted: { type: Date },
27
+ };
28
+ //# sourceMappingURL=commonSchemaFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonSchemaFields.js","sourceRoot":"","sources":["../../src/schemas/commonSchemaFields.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE;QACP,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,GAAG,EAAE,KAAK;IACV,OAAO,EAAE;QACP,IAAI,EAAE,MAAM;KACb;IACD,YAAY,EAAE;QACZ,IAAI,EAAE,IAAI;KACX;IACD,cAAc,EAAE;QACd,IAAI,EAAE,MAAM;KACb;IACD,YAAY,EAAE;QACZ,IAAI,EAAE,MAAM;KACb;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;IACvC,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;IACvB,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;CACxB,CAAC"}
@@ -0,0 +1,43 @@
1
+ import SimpleSchema from 'simpl-schema';
2
+ declare const Schemas: {
3
+ timestampFields: {
4
+ created: {
5
+ type: DateConstructor;
6
+ required: boolean;
7
+ };
8
+ updated: {
9
+ type: DateConstructor;
10
+ };
11
+ deleted: {
12
+ type: DateConstructor;
13
+ };
14
+ };
15
+ contextFields: {
16
+ context: {
17
+ type: ObjectConstructor;
18
+ blackbox: boolean;
19
+ required: boolean;
20
+ };
21
+ };
22
+ logFields: {
23
+ log: ArrayConstructor;
24
+ 'log.$': {
25
+ type: ObjectConstructor;
26
+ };
27
+ 'log.$.date': {
28
+ type: DateConstructor;
29
+ };
30
+ 'log.$.status': {
31
+ type: StringConstructor;
32
+ };
33
+ 'log.$.info': {
34
+ type: StringConstructor;
35
+ };
36
+ };
37
+ Address: SimpleSchema;
38
+ Contact: SimpleSchema;
39
+ User: SimpleSchema;
40
+ };
41
+ export { Schemas };
42
+ export type { SimpleSchema };
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,cAAc,CAAC;AAMxC,QAAA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAOZ,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,YAAY,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { timestampFields, contextFields, logFields } from './commonSchemaFields.js';
2
+ import { AddressSchema } from './AddressSchema.js';
3
+ import { ContactSchema } from './ContactSchema.js';
4
+ import { UserSchema } from './UsersSchema.js';
5
+ const Schemas = {
6
+ timestampFields,
7
+ contextFields,
8
+ logFields,
9
+ Address: AddressSchema,
10
+ Contact: ContactSchema,
11
+ User: UserSchema,
12
+ };
13
+ export { Schemas };
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,OAAO,GAAG;IACd,eAAe;IACf,aAAa;IACb,SAAS;IACT,OAAO,EAAE,aAAa;IACtB,OAAO,EAAE,aAAa;IACtB,IAAI,EAAE,UAAU;CACjB,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC"}
package/lib/sha1.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export default function sha1(message: any): Promise<Buffer<ArrayBuffer>>;
1
+ export default function sha1(message: any): Promise<Uint8Array<ArrayBuffer>>;
2
2
  //# sourceMappingURL=sha1.d.ts.map
package/lib/sha1.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sha1.d.ts","sourceRoot":"","sources":["../src/sha1.ts"],"names":[],"mappings":"AAAA,wBAA8B,IAAI,CAAC,OAAO,KAAA,gCAIzC"}
1
+ {"version":3,"file":"sha1.d.ts","sourceRoot":"","sources":["../src/sha1.ts"],"names":[],"mappings":"AAAA,wBAA8B,IAAI,CAAC,OAAO,KAAA,oCAKzC"}
package/lib/sha1.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export default async function sha1(message) {
2
2
  const bytes = new TextEncoder().encode(message);
3
3
  const hashBuffer = await crypto.subtle.digest('SHA-1', bytes);
4
- return Buffer.from(hashBuffer);
4
+ // Return Uint8Array instead of Buffer
5
+ return new Uint8Array(hashBuffer);
5
6
  }
6
7
  //# sourceMappingURL=sha1.js.map
package/lib/sha1.js.map CHANGED
@@ -1 +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"}
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,sCAAsC;IACtC,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA,wBAA8B,MAAM,CAAC,OAAO,KAAA,mBAI3C"}
1
+ {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA,wBAA8B,MAAM,CAAC,OAAO,KAAA,mBAO3C"}
package/lib/sha256.js CHANGED
@@ -1,6 +1,9 @@
1
1
  export default async function sha256(message) {
2
2
  const bytes = new TextEncoder().encode(message);
3
3
  const hashBuffer = await crypto.subtle.digest('SHA-256', bytes);
4
- return Buffer.from(hashBuffer).toString('hex');
4
+ // Convert ArrayBuffer to hex string without using Buffer
5
+ return Array.from(new Uint8Array(hashBuffer))
6
+ .map((b) => b.toString(16).padStart(2, '0'))
7
+ .join('');
5
8
  }
6
9
  //# sourceMappingURL=sha256.js.map
package/lib/sha256.js.map CHANGED
@@ -1 +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
+ {"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,yDAAyD;IACzD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;SAC1C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/utils",
3
- "version": "4.0.0-rc.9",
3
+ "version": "4.0.1",
4
4
  "main": "lib/utils-index.js",
5
5
  "types": "lib/utils-index.d.ts",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/unchainedshop/unchained#readme",
29
29
  "dependencies": {
30
- "@unchainedshop/logger": "^4.0.0-rc.4",
30
+ "@unchainedshop/logger": "^4.0.0",
31
31
  "hashids": "^2.3.0",
32
32
  "resolve-accept-language": "^3.1.11"
33
33
  },
@@ -7,7 +7,7 @@ export const calculateAmountToSplit = (
7
7
  ) => {
8
8
  const deductionAmount = configuration.rate
9
9
  ? amount * configuration.rate
10
- : Math.min(configuration.fixedRate, amount);
10
+ : Math.min(configuration.fixedRate || 0, amount);
11
11
 
12
12
  const leftInDiscount = Math.max(0, deductionAmount);
13
13
  return leftInDiscount;
@@ -26,9 +26,9 @@ export const resolveAmountAndTax = (
26
26
  { ratio, taxDivisor }: { ratio?: number; taxDivisor?: number },
27
27
  amount: number,
28
28
  ) => {
29
- const shareAmount = Number.isFinite(ratio) ? amount * ratio : 0;
29
+ const shareAmount = Number.isFinite(ratio) ? amount * ratio! : 0;
30
30
  const shareTaxAmount =
31
- Number.isFinite(taxDivisor) && taxDivisor !== 0 ? shareAmount - shareAmount / taxDivisor : 0;
31
+ Number.isFinite(taxDivisor) && taxDivisor !== 0 ? shareAmount - shareAmount / taxDivisor! : 0;
32
32
  return [shareAmount, shareTaxAmount];
33
33
  };
34
34
 
@@ -1,4 +1,4 @@
1
- export const addressToString = (address: {
1
+ export const addressToString = (address?: {
2
2
  addressLine?: string;
3
3
  addressLine2?: string;
4
4
  city?: string;
@@ -8,7 +8,9 @@ export const addressToString = (address: {
8
8
  lastName?: string;
9
9
  postalCode?: string;
10
10
  regionCode?: string;
11
- }) => {
11
+ }): string => {
12
+ if (!address) return '';
13
+
12
14
  return [
13
15
  [address.firstName, address.lastName].filter(Boolean).join(' '),
14
16
  address.company,
@@ -2,7 +2,7 @@ import { IBaseAdapter } from './BaseAdapter.js';
2
2
 
3
3
  export interface IBaseDirector<Adapter extends IBaseAdapter> {
4
4
  getAdapters: (options?: { adapterFilter?: (adapter: Adapter) => boolean }) => Adapter[];
5
- getAdapter: (key: string) => Adapter;
5
+ getAdapter: (key: string) => Adapter | null;
6
6
  registerAdapter: (A: Adapter) => void;
7
7
  unregisterAdapter: (key: string) => boolean;
8
8
  }
@@ -19,7 +19,7 @@ export const BaseDirector = <AdapterType extends IBaseAdapter>(
19
19
 
20
20
  return {
21
21
  getAdapter: (key) => {
22
- return Adapters.get(key);
22
+ return Adapters.get(key) || null;
23
23
  },
24
24
 
25
25
  getAdapters: ({ adapterFilter } = {}) => {
@@ -1,6 +1,6 @@
1
1
  import { describe, it, beforeEach } from 'node:test';
2
2
  import assert from 'node:assert';
3
- import { BaseDirector } from './BaseDirector.js';
3
+ import { BaseDirector, IBaseDirector } from './BaseDirector.js';
4
4
 
5
5
  const adapter1 = {
6
6
  key: 'adapter1',
@@ -24,7 +24,7 @@ const adapter3 = {
24
24
  };
25
25
 
26
26
  describe('BaseDirector', () => {
27
- let director;
27
+ let director: IBaseDirector<any>;
28
28
 
29
29
  beforeEach(() => {
30
30
  director = BaseDirector('TestDirector');
@@ -69,7 +69,7 @@ describe('BaseDirector', () => {
69
69
  const directorName = 'TestDirector';
70
70
  const adapterKeyField = 'key';
71
71
  director = BaseDirector(directorName, { adapterKeyField });
72
- assert.strictEqual(director.getAdapter(adapter1.key), undefined);
72
+ assert.strictEqual(director.getAdapter(adapter1.key), null);
73
73
  });
74
74
  });
75
75
 
@@ -79,7 +79,7 @@ describe('BaseDirector', () => {
79
79
  });
80
80
 
81
81
  it('should return undefined if no Adapter is registered with the given key', () => {
82
- assert.strictEqual(director.getAdapter('invalid-key'), undefined);
82
+ assert.strictEqual(director.getAdapter('invalid-key'), null);
83
83
  });
84
84
 
85
85
  it('should return the correct Adapter object when the keyField is set to a property other than "key"', () => {
@@ -13,14 +13,14 @@ const incrementSuffixedSlug = (slugIncludingSuffix, delimiter = DELIMITER) => {
13
13
 
14
14
  export default (
15
15
  checkSlugIsUniqueFn: (slug: string) => Promise<boolean>,
16
- { slugify }: { slugify?: (text: string) => string },
17
- ): ((params: { title?: string; existingSlug: string; newSlug?: string }) => Promise<string>) => {
16
+ { slugify }: { slugify: (text: string) => string },
17
+ ): ((params: { title?: string; existingSlug?: string; newSlug?: string }) => Promise<string>) => {
18
18
  const findUnusedSlug = async ({
19
19
  title,
20
20
  existingSlug,
21
21
  newSlug,
22
22
  }: {
23
- title?: string;
23
+ title: string;
24
24
  existingSlug?: string;
25
25
  newSlug?: string;
26
26
  }) => {
@@ -28,6 +28,8 @@ export default (
28
28
  if (!(await checkSlugIsUniqueFn(slug))) {
29
29
  const isSlugAlreadySuffixed = !!newSlug;
30
30
  return findUnusedSlug({
31
+ title,
32
+ existingSlug,
31
33
  newSlug: isSlugAlreadySuffixed ? incrementSuffixedSlug(slug) : addSuffixToSlug(slug),
32
34
  });
33
35
  }
@@ -4,56 +4,76 @@ const { UNCHAINED_LANG = 'de', UNCHAINED_COUNTRY = 'CH', UNCHAINED_CURRENCY = 'C
4
4
 
5
5
  export const systemLocale = new Intl.Locale(`${UNCHAINED_LANG}-${UNCHAINED_COUNTRY}`);
6
6
 
7
+ export const determineFallbackLocale = (
8
+ countries: { isoCode: string }[],
9
+ languages: { isoCode: string }[],
10
+ ): Intl.Locale => {
11
+ try {
12
+ const country =
13
+ countries.find((country) => country.isoCode === systemLocale.region)?.isoCode ||
14
+ countries[0]?.isoCode;
15
+ const language =
16
+ languages.find((language) => language.isoCode === systemLocale.language)?.isoCode ||
17
+ languages[0]?.isoCode;
18
+ return new Intl.Locale(`${language}-${country}`);
19
+ } catch {
20
+ return systemLocale;
21
+ }
22
+ };
23
+
7
24
  export const resolveBestSupported = (
8
25
  acceptLanguage: string,
9
- supportedLocales: string[],
26
+ acceptCountry: string,
27
+ {
28
+ countries = [],
29
+ languages = [],
30
+ }: {
31
+ countries: { isoCode: string }[];
32
+ languages: { isoCode: string }[];
33
+ },
10
34
  ): Intl.Locale => {
35
+ const supportedLocales: string[] = languages.reduce<string[]>((accumulator, language) => {
36
+ const added = countries
37
+ .filter((country) => {
38
+ if (acceptCountry) {
39
+ return country.isoCode === acceptCountry;
40
+ }
41
+ return true;
42
+ })
43
+ .map((country) => {
44
+ return `${language.isoCode}-${country.isoCode}`;
45
+ });
46
+ return accumulator.concat(added);
47
+ }, []);
48
+
49
+ const fallbackLocale = determineFallbackLocale(countries, languages);
50
+
11
51
  try {
12
52
  const { match } = resolveAcceptLanguage(
13
53
  acceptLanguage || '',
14
54
  supportedLocales,
15
- systemLocale.baseName,
55
+ fallbackLocale.baseName,
16
56
  {
17
57
  returnMatchType: true,
18
58
  },
19
59
  );
20
60
  return new Intl.Locale(match);
21
61
  } catch {
22
- return systemLocale;
23
- }
24
- };
25
-
26
- export const resolveBestCountry = (
27
- localeCountry: string,
28
- shopCountry: string,
29
- countries: { isoCode: string }[],
30
- ) => {
31
- if (shopCountry) {
32
- const resolvedCountry = countries.reduce<string>((lastResolved, country) => {
33
- if (shopCountry === country.isoCode) {
34
- return country.isoCode;
35
- }
36
- return lastResolved;
37
- }, null);
38
- if (resolvedCountry) {
39
- return resolvedCountry;
40
- }
62
+ return fallbackLocale;
41
63
  }
42
- return localeCountry || systemLocale.region;
43
64
  };
44
65
 
45
- export const resolveBestCurrency = (localeCurrency: string, currencies: { isoCode: string }[]) => {
46
- if (localeCurrency) {
47
- const resolvedCurrency = currencies.find((currency) => currency.isoCode === localeCurrency);
66
+ export const resolveBestCurrency = (currencyCode: string | null, currencies: { isoCode: string }[]) => {
67
+ if (currencyCode) {
68
+ const resolvedCurrency = currencies.find(
69
+ (currency) => currency.isoCode.toUpperCase() === currencyCode.toUpperCase(),
70
+ );
48
71
  if (resolvedCurrency) {
49
72
  return resolvedCurrency.isoCode;
50
73
  }
51
74
  }
52
-
53
- const fallbackCurrency = currencies.find((currency) => currency.isoCode === UNCHAINED_CURRENCY);
54
- if (fallbackCurrency) {
55
- return fallbackCurrency.isoCode;
56
- }
57
-
58
- return currencies?.[0]?.isoCode || UNCHAINED_CURRENCY;
75
+ return (
76
+ currencies.find((currency) => currency.isoCode === UNCHAINED_CURRENCY)?.isoCode ||
77
+ currencies[0]?.isoCode
78
+ );
59
79
  };
package/src/sha1.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export default async function sha1(message) {
2
2
  const bytes = new TextEncoder().encode(message);
3
3
  const hashBuffer = await crypto.subtle.digest('SHA-1', bytes);
4
- return Buffer.from(hashBuffer);
4
+ // Return Uint8Array instead of Buffer
5
+ return new Uint8Array(hashBuffer);
5
6
  }
package/src/sha256.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  export default async function sha256(message) {
2
2
  const bytes = new TextEncoder().encode(message);
3
3
  const hashBuffer = await crypto.subtle.digest('SHA-256', bytes);
4
- return Buffer.from(hashBuffer).toString('hex');
4
+ // Convert ArrayBuffer to hex string without using Buffer
5
+ return Array.from(new Uint8Array(hashBuffer))
6
+ .map((b) => b.toString(16).padStart(2, '0'))
7
+ .join('');
5
8
  }
@@ -1,12 +1,11 @@
1
1
  import { describe, it } from 'node:test';
2
2
  import assert from 'node:assert';
3
- import { resolveBestCountry, resolveBestSupported, slugify, systemLocale } from './utils-index.js';
3
+ import { resolveBestSupported, slugify, systemLocale } from './utils-index.js';
4
4
  import generateHashId from './generate-random-hash.js';
5
5
 
6
6
  describe('Utils', () => {
7
7
  it('Locale', () => {
8
8
  assert.ok(systemLocale);
9
- assert.equal(typeof resolveBestCountry, 'function');
10
9
  assert.equal(typeof resolveBestSupported, 'function');
11
10
  });
12
11
 
package/tsconfig.json CHANGED
@@ -3,7 +3,8 @@
3
3
  "compilerOptions": {
4
4
  "declarationDir": "./lib",
5
5
  "rootDir": "./src",
6
- "outDir": "./lib"
6
+ "outDir": "./lib",
7
+
7
8
  },
8
9
  "exclude": ["**/*.test.ts", "**/*.test.js", "tests", "lib"]
9
10
  }