@labdigital/commercetools-mock 2.20.1 → 2.21.0
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/dist/index.cjs +49 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +49 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers.ts +11 -0
- package/src/repositories/abstract.ts +13 -4
- package/src/repositories/category/index.test.ts +24 -0
- package/src/repositories/category/index.ts +18 -1
- package/src/repositories/customer/index.ts +33 -2
package/dist/index.cjs
CHANGED
|
@@ -480,6 +480,15 @@ var mapHeaderType = (outgoingHttpHeaders) => {
|
|
|
480
480
|
}
|
|
481
481
|
return headersInit;
|
|
482
482
|
};
|
|
483
|
+
var generateRandomString = (length) => {
|
|
484
|
+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
485
|
+
let result = "";
|
|
486
|
+
for (let i = 0; i < length; i++) {
|
|
487
|
+
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
488
|
+
result += characters[randomIndex];
|
|
489
|
+
}
|
|
490
|
+
return result;
|
|
491
|
+
};
|
|
483
492
|
|
|
484
493
|
// src/projectAPI.ts
|
|
485
494
|
var ProjectAPI = class {
|
|
@@ -1798,7 +1807,7 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1798
1807
|
id,
|
|
1799
1808
|
params
|
|
1800
1809
|
);
|
|
1801
|
-
return resource ? this.postProcessResource(context, resource) : null;
|
|
1810
|
+
return resource ? this.postProcessResource(context, resource, params) : null;
|
|
1802
1811
|
}
|
|
1803
1812
|
get(context, id, params = {}) {
|
|
1804
1813
|
const resource = this._storage.get(
|
|
@@ -1807,7 +1816,7 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1807
1816
|
id,
|
|
1808
1817
|
params
|
|
1809
1818
|
);
|
|
1810
|
-
return resource ? this.postProcessResource(context, resource) : null;
|
|
1819
|
+
return resource ? this.postProcessResource(context, resource, params) : null;
|
|
1811
1820
|
}
|
|
1812
1821
|
getByKey(context, key, params = {}) {
|
|
1813
1822
|
const resource = this._storage.getByKey(
|
|
@@ -1816,9 +1825,9 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1816
1825
|
key,
|
|
1817
1826
|
params
|
|
1818
1827
|
);
|
|
1819
|
-
return resource ? this.postProcessResource(context, resource) : null;
|
|
1828
|
+
return resource ? this.postProcessResource(context, resource, params) : null;
|
|
1820
1829
|
}
|
|
1821
|
-
postProcessResource(context, resource) {
|
|
1830
|
+
postProcessResource(context, resource, params) {
|
|
1822
1831
|
return resource;
|
|
1823
1832
|
}
|
|
1824
1833
|
query(context, params = {}) {
|
|
@@ -1826,7 +1835,9 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1826
1835
|
...params
|
|
1827
1836
|
});
|
|
1828
1837
|
const data = result.results.map(
|
|
1829
|
-
(r) => this.postProcessResource(context, r
|
|
1838
|
+
(r) => this.postProcessResource(context, r, {
|
|
1839
|
+
expand: params.expand
|
|
1840
|
+
})
|
|
1830
1841
|
);
|
|
1831
1842
|
return {
|
|
1832
1843
|
...result,
|
|
@@ -3090,15 +3101,23 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
3090
3101
|
};
|
|
3091
3102
|
return this.saveNew(context, resource);
|
|
3092
3103
|
}
|
|
3093
|
-
postProcessResource(context, resource) {
|
|
3104
|
+
postProcessResource(context, resource, params) {
|
|
3094
3105
|
let node = resource;
|
|
3095
3106
|
const ancestors = [];
|
|
3107
|
+
const expandClauses = params?.expand?.map(parseExpandClause) ?? [];
|
|
3108
|
+
const addExpand = expandClauses?.find(
|
|
3109
|
+
(c) => c.element === "ancestors" && c.index === "*"
|
|
3110
|
+
);
|
|
3096
3111
|
while (node.parent) {
|
|
3097
3112
|
node = this._storage.getByResourceIdentifier(
|
|
3098
3113
|
context.projectKey,
|
|
3099
3114
|
node.parent
|
|
3100
3115
|
);
|
|
3101
|
-
ancestors.push({
|
|
3116
|
+
ancestors.push({
|
|
3117
|
+
typeId: "category",
|
|
3118
|
+
id: node.id,
|
|
3119
|
+
obj: addExpand ? node : void 0
|
|
3120
|
+
});
|
|
3102
3121
|
}
|
|
3103
3122
|
resource.ancestors = ancestors;
|
|
3104
3123
|
return resource;
|
|
@@ -3356,14 +3375,35 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3356
3375
|
]
|
|
3357
3376
|
});
|
|
3358
3377
|
}
|
|
3378
|
+
const addresses = draft.addresses?.map((address) => ({
|
|
3379
|
+
...address,
|
|
3380
|
+
id: generateRandomString(5)
|
|
3381
|
+
})) ?? [];
|
|
3382
|
+
const defaultBillingAddressId = addresses.length > 0 && draft.defaultBillingAddress !== void 0 ? addresses[draft.defaultBillingAddress].id : void 0;
|
|
3383
|
+
const defaultShippingAddressId = addresses.length > 0 && draft.defaultShippingAddress !== void 0 ? addresses[draft.defaultShippingAddress].id : void 0;
|
|
3359
3384
|
const resource = {
|
|
3360
3385
|
...getBaseResourceProperties(),
|
|
3386
|
+
key: draft.key,
|
|
3361
3387
|
authenticationMode: draft.authenticationMode || "Password",
|
|
3388
|
+
firstName: draft.firstName,
|
|
3389
|
+
lastName: draft.lastName,
|
|
3390
|
+
middleName: draft.middleName,
|
|
3391
|
+
title: draft.title,
|
|
3392
|
+
dateOfBirth: draft.dateOfBirth,
|
|
3393
|
+
companyName: draft.companyName,
|
|
3362
3394
|
email: draft.email.toLowerCase(),
|
|
3363
3395
|
password: draft.password ? hashPassword(draft.password) : void 0,
|
|
3364
3396
|
isEmailVerified: draft.isEmailVerified || false,
|
|
3365
|
-
addresses
|
|
3366
|
-
customerNumber: draft.customerNumber
|
|
3397
|
+
addresses,
|
|
3398
|
+
customerNumber: draft.customerNumber,
|
|
3399
|
+
externalId: draft.externalId,
|
|
3400
|
+
defaultBillingAddressId,
|
|
3401
|
+
defaultShippingAddressId,
|
|
3402
|
+
custom: createCustomFields(
|
|
3403
|
+
draft.custom,
|
|
3404
|
+
context.projectKey,
|
|
3405
|
+
this._storage
|
|
3406
|
+
)
|
|
3367
3407
|
};
|
|
3368
3408
|
return this.saveNew(context, resource);
|
|
3369
3409
|
}
|