@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.
- package/lib/calculation.js +1 -1
- package/lib/calculation.js.map +1 -1
- package/lib/ch/addressToString.d.ts +1 -1
- package/lib/ch/addressToString.d.ts.map +1 -1
- package/lib/ch/addressToString.js +2 -0
- package/lib/ch/addressToString.js.map +1 -1
- package/lib/director/BaseDirector.d.ts +1 -1
- package/lib/director/BaseDirector.d.ts.map +1 -1
- package/lib/director/BaseDirector.js +1 -1
- package/lib/director/BaseDirector.js.map +1 -1
- package/lib/director/BaseDiscountAdapter.d.ts +3 -0
- package/lib/director/BaseDiscountAdapter.d.ts.map +1 -0
- package/lib/director/BaseDiscountAdapter.js +48 -0
- package/lib/director/BaseDiscountAdapter.js.map +1 -0
- package/lib/director/BaseDiscountDirector.d.ts +3 -0
- package/lib/director/BaseDiscountDirector.d.ts.map +1 -0
- package/lib/director/BaseDiscountDirector.js +50 -0
- package/lib/director/BaseDiscountDirector.js.map +1 -0
- package/lib/director/BasePricingAdapter.d.ts +3 -0
- package/lib/director/BasePricingAdapter.d.ts.map +1 -0
- package/lib/director/BasePricingAdapter.js +25 -0
- package/lib/director/BasePricingAdapter.js.map +1 -0
- package/lib/director/BasePricingDirector.d.ts +3 -0
- package/lib/director/BasePricingDirector.d.ts.map +1 -0
- package/lib/director/BasePricingDirector.js +61 -0
- package/lib/director/BasePricingDirector.js.map +1 -0
- package/lib/director/BasePricingSheet.d.ts +3 -0
- package/lib/director/BasePricingSheet.d.ts.map +1 -0
- package/lib/director/BasePricingSheet.js +54 -0
- package/lib/director/BasePricingSheet.js.map +1 -0
- package/lib/find-unused-slug.d.ts +2 -2
- package/lib/find-unused-slug.d.ts.map +1 -1
- package/lib/find-unused-slug.js +2 -0
- package/lib/find-unused-slug.js.map +1 -1
- package/lib/locale-helpers.d.ts +13 -4
- package/lib/locale-helpers.d.ts.map +1 -1
- package/lib/locale-helpers.js +33 -24
- package/lib/locale-helpers.js.map +1 -1
- package/lib/random-value-hex.d.ts +2 -0
- package/lib/random-value-hex.d.ts.map +1 -0
- package/lib/random-value-hex.js +8 -0
- package/lib/random-value-hex.js.map +1 -0
- package/lib/schemas/AddressSchema.d.ts +3 -0
- package/lib/schemas/AddressSchema.d.ts.map +1 -0
- package/lib/schemas/AddressSchema.js +13 -0
- package/lib/schemas/AddressSchema.js.map +1 -0
- package/lib/schemas/ContactSchema.d.ts +3 -0
- package/lib/schemas/ContactSchema.d.ts.map +1 -0
- package/lib/schemas/ContactSchema.js +6 -0
- package/lib/schemas/ContactSchema.js.map +1 -0
- package/lib/schemas/UsersSchema.d.ts +5 -0
- package/lib/schemas/UsersSchema.d.ts.map +1 -0
- package/lib/schemas/UsersSchema.js +52 -0
- package/lib/schemas/UsersSchema.js.map +1 -0
- package/lib/schemas/commonSchemaFields.d.ts +35 -0
- package/lib/schemas/commonSchemaFields.d.ts.map +1 -0
- package/lib/schemas/commonSchemaFields.js +28 -0
- package/lib/schemas/commonSchemaFields.js.map +1 -0
- package/lib/schemas/index.d.ts +43 -0
- package/lib/schemas/index.d.ts.map +1 -0
- package/lib/schemas/index.js +14 -0
- package/lib/schemas/index.js.map +1 -0
- package/lib/sha1.d.ts +1 -1
- package/lib/sha1.d.ts.map +1 -1
- package/lib/sha1.js +2 -1
- package/lib/sha1.js.map +1 -1
- package/lib/sha256.d.ts.map +1 -1
- package/lib/sha256.js +4 -1
- package/lib/sha256.js.map +1 -1
- package/package.json +2 -2
- package/src/calculation.ts +3 -3
- package/src/ch/addressToString.ts +4 -2
- package/src/director/BaseDirector.ts +2 -2
- package/src/director/base-director.test.ts +4 -4
- package/src/find-unused-slug.ts +5 -3
- package/src/locale-helpers.ts +52 -32
- package/src/sha1.ts +2 -1
- package/src/sha256.ts +4 -1
- package/src/utils-index.test.ts +1 -2
- package/tsconfig.json +2 -1
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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<
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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"}
|
package/lib/sha256.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA,wBAA8B,MAAM,CAAC,OAAO,KAAA,
|
|
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
|
-
|
|
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,
|
|
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.
|
|
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
|
|
30
|
+
"@unchainedshop/logger": "^4.0.0",
|
|
31
31
|
"hashids": "^2.3.0",
|
|
32
32
|
"resolve-accept-language": "^3.1.11"
|
|
33
33
|
},
|
package/src/calculation.ts
CHANGED
|
@@ -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),
|
|
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'),
|
|
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"', () => {
|
package/src/find-unused-slug.ts
CHANGED
|
@@ -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
|
|
17
|
-
): ((params: { title?: string; existingSlug
|
|
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
|
|
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
|
}
|
package/src/locale-helpers.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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 = (
|
|
46
|
-
if (
|
|
47
|
-
const resolvedCurrency = currencies.find(
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/utils-index.test.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { describe, it } from 'node:test';
|
|
2
2
|
import assert from 'node:assert';
|
|
3
|
-
import {
|
|
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
|
|