@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.d.cts
CHANGED
|
@@ -58,7 +58,7 @@ declare abstract class AbstractResourceRepository<T extends ResourceType> extend
|
|
|
58
58
|
delete(context: RepositoryContext, id: string, params?: GetParams$1): ResourceMap[T] | null;
|
|
59
59
|
get(context: RepositoryContext, id: string, params?: GetParams$1): ResourceMap[T] | null;
|
|
60
60
|
getByKey(context: RepositoryContext, key: string, params?: GetParams$1): ResourceMap[T] | null;
|
|
61
|
-
postProcessResource(context: RepositoryContext, resource: ResourceMap[T]): ResourceMap[T];
|
|
61
|
+
postProcessResource(context: RepositoryContext, resource: ResourceMap[T], params?: GetParams$1): ResourceMap[T];
|
|
62
62
|
query(context: RepositoryContext, params?: QueryParams$1): PagedQueryResponseMap[T] & {
|
|
63
63
|
results: ResourceMap[T][];
|
|
64
64
|
};
|
|
@@ -217,7 +217,7 @@ declare class CartDiscountRepository extends AbstractResourceRepository<"cart-di
|
|
|
217
217
|
declare class CategoryRepository extends AbstractResourceRepository<"category"> {
|
|
218
218
|
constructor(storage: AbstractStorage);
|
|
219
219
|
create(context: RepositoryContext, draft: CategoryDraft): Category;
|
|
220
|
-
postProcessResource(context: RepositoryContext, resource: Writable<Category
|
|
220
|
+
postProcessResource(context: RepositoryContext, resource: Writable<Category>, params?: GetParams$1): Category;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
declare class ChannelRepository extends AbstractResourceRepository<"channel"> {
|
package/dist/index.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ declare abstract class AbstractResourceRepository<T extends ResourceType> extend
|
|
|
58
58
|
delete(context: RepositoryContext, id: string, params?: GetParams$1): ResourceMap[T] | null;
|
|
59
59
|
get(context: RepositoryContext, id: string, params?: GetParams$1): ResourceMap[T] | null;
|
|
60
60
|
getByKey(context: RepositoryContext, key: string, params?: GetParams$1): ResourceMap[T] | null;
|
|
61
|
-
postProcessResource(context: RepositoryContext, resource: ResourceMap[T]): ResourceMap[T];
|
|
61
|
+
postProcessResource(context: RepositoryContext, resource: ResourceMap[T], params?: GetParams$1): ResourceMap[T];
|
|
62
62
|
query(context: RepositoryContext, params?: QueryParams$1): PagedQueryResponseMap[T] & {
|
|
63
63
|
results: ResourceMap[T][];
|
|
64
64
|
};
|
|
@@ -217,7 +217,7 @@ declare class CartDiscountRepository extends AbstractResourceRepository<"cart-di
|
|
|
217
217
|
declare class CategoryRepository extends AbstractResourceRepository<"category"> {
|
|
218
218
|
constructor(storage: AbstractStorage);
|
|
219
219
|
create(context: RepositoryContext, draft: CategoryDraft): Category;
|
|
220
|
-
postProcessResource(context: RepositoryContext, resource: Writable<Category
|
|
220
|
+
postProcessResource(context: RepositoryContext, resource: Writable<Category>, params?: GetParams$1): Category;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
declare class ChannelRepository extends AbstractResourceRepository<"channel"> {
|
package/dist/index.js
CHANGED
|
@@ -443,6 +443,15 @@ var mapHeaderType = (outgoingHttpHeaders) => {
|
|
|
443
443
|
}
|
|
444
444
|
return headersInit;
|
|
445
445
|
};
|
|
446
|
+
var generateRandomString = (length) => {
|
|
447
|
+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
448
|
+
let result = "";
|
|
449
|
+
for (let i = 0; i < length; i++) {
|
|
450
|
+
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
451
|
+
result += characters[randomIndex];
|
|
452
|
+
}
|
|
453
|
+
return result;
|
|
454
|
+
};
|
|
446
455
|
|
|
447
456
|
// src/projectAPI.ts
|
|
448
457
|
var ProjectAPI = class {
|
|
@@ -1761,7 +1770,7 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1761
1770
|
id,
|
|
1762
1771
|
params
|
|
1763
1772
|
);
|
|
1764
|
-
return resource ? this.postProcessResource(context, resource) : null;
|
|
1773
|
+
return resource ? this.postProcessResource(context, resource, params) : null;
|
|
1765
1774
|
}
|
|
1766
1775
|
get(context, id, params = {}) {
|
|
1767
1776
|
const resource = this._storage.get(
|
|
@@ -1770,7 +1779,7 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1770
1779
|
id,
|
|
1771
1780
|
params
|
|
1772
1781
|
);
|
|
1773
|
-
return resource ? this.postProcessResource(context, resource) : null;
|
|
1782
|
+
return resource ? this.postProcessResource(context, resource, params) : null;
|
|
1774
1783
|
}
|
|
1775
1784
|
getByKey(context, key, params = {}) {
|
|
1776
1785
|
const resource = this._storage.getByKey(
|
|
@@ -1779,9 +1788,9 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1779
1788
|
key,
|
|
1780
1789
|
params
|
|
1781
1790
|
);
|
|
1782
|
-
return resource ? this.postProcessResource(context, resource) : null;
|
|
1791
|
+
return resource ? this.postProcessResource(context, resource, params) : null;
|
|
1783
1792
|
}
|
|
1784
|
-
postProcessResource(context, resource) {
|
|
1793
|
+
postProcessResource(context, resource, params) {
|
|
1785
1794
|
return resource;
|
|
1786
1795
|
}
|
|
1787
1796
|
query(context, params = {}) {
|
|
@@ -1789,7 +1798,9 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1789
1798
|
...params
|
|
1790
1799
|
});
|
|
1791
1800
|
const data = result.results.map(
|
|
1792
|
-
(r) => this.postProcessResource(context, r
|
|
1801
|
+
(r) => this.postProcessResource(context, r, {
|
|
1802
|
+
expand: params.expand
|
|
1803
|
+
})
|
|
1793
1804
|
);
|
|
1794
1805
|
return {
|
|
1795
1806
|
...result,
|
|
@@ -3053,15 +3064,23 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
3053
3064
|
};
|
|
3054
3065
|
return this.saveNew(context, resource);
|
|
3055
3066
|
}
|
|
3056
|
-
postProcessResource(context, resource) {
|
|
3067
|
+
postProcessResource(context, resource, params) {
|
|
3057
3068
|
let node = resource;
|
|
3058
3069
|
const ancestors = [];
|
|
3070
|
+
const expandClauses = params?.expand?.map(parseExpandClause) ?? [];
|
|
3071
|
+
const addExpand = expandClauses?.find(
|
|
3072
|
+
(c) => c.element === "ancestors" && c.index === "*"
|
|
3073
|
+
);
|
|
3059
3074
|
while (node.parent) {
|
|
3060
3075
|
node = this._storage.getByResourceIdentifier(
|
|
3061
3076
|
context.projectKey,
|
|
3062
3077
|
node.parent
|
|
3063
3078
|
);
|
|
3064
|
-
ancestors.push({
|
|
3079
|
+
ancestors.push({
|
|
3080
|
+
typeId: "category",
|
|
3081
|
+
id: node.id,
|
|
3082
|
+
obj: addExpand ? node : void 0
|
|
3083
|
+
});
|
|
3065
3084
|
}
|
|
3066
3085
|
resource.ancestors = ancestors;
|
|
3067
3086
|
return resource;
|
|
@@ -3319,14 +3338,35 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3319
3338
|
]
|
|
3320
3339
|
});
|
|
3321
3340
|
}
|
|
3341
|
+
const addresses = draft.addresses?.map((address) => ({
|
|
3342
|
+
...address,
|
|
3343
|
+
id: generateRandomString(5)
|
|
3344
|
+
})) ?? [];
|
|
3345
|
+
const defaultBillingAddressId = addresses.length > 0 && draft.defaultBillingAddress !== void 0 ? addresses[draft.defaultBillingAddress].id : void 0;
|
|
3346
|
+
const defaultShippingAddressId = addresses.length > 0 && draft.defaultShippingAddress !== void 0 ? addresses[draft.defaultShippingAddress].id : void 0;
|
|
3322
3347
|
const resource = {
|
|
3323
3348
|
...getBaseResourceProperties(),
|
|
3349
|
+
key: draft.key,
|
|
3324
3350
|
authenticationMode: draft.authenticationMode || "Password",
|
|
3351
|
+
firstName: draft.firstName,
|
|
3352
|
+
lastName: draft.lastName,
|
|
3353
|
+
middleName: draft.middleName,
|
|
3354
|
+
title: draft.title,
|
|
3355
|
+
dateOfBirth: draft.dateOfBirth,
|
|
3356
|
+
companyName: draft.companyName,
|
|
3325
3357
|
email: draft.email.toLowerCase(),
|
|
3326
3358
|
password: draft.password ? hashPassword(draft.password) : void 0,
|
|
3327
3359
|
isEmailVerified: draft.isEmailVerified || false,
|
|
3328
|
-
addresses
|
|
3329
|
-
customerNumber: draft.customerNumber
|
|
3360
|
+
addresses,
|
|
3361
|
+
customerNumber: draft.customerNumber,
|
|
3362
|
+
externalId: draft.externalId,
|
|
3363
|
+
defaultBillingAddressId,
|
|
3364
|
+
defaultShippingAddressId,
|
|
3365
|
+
custom: createCustomFields(
|
|
3366
|
+
draft.custom,
|
|
3367
|
+
context.projectKey,
|
|
3368
|
+
this._storage
|
|
3369
|
+
)
|
|
3330
3370
|
};
|
|
3331
3371
|
return this.saveNew(context, resource);
|
|
3332
3372
|
}
|