@labdigital/commercetools-mock 2.19.0 → 2.20.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/dist/index.cjs +32 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.js +32 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
- package/src/repositories/abstract.ts +16 -9
- package/src/repositories/category/index.test.ts +82 -0
- package/src/repositories/category/index.ts +26 -2
- package/src/repositories/extension.ts +4 -1
- package/src/repositories/order/actions.ts +9 -0
- package/src/repositories/project.ts +2 -2
- package/src/services/category.test.ts +2 -0
- package/src/services/order.test.ts +35 -0
package/dist/index.cjs
CHANGED
|
@@ -1775,7 +1775,7 @@ var AbstractRepository = class {
|
|
|
1775
1775
|
if (resource.version != updatedResource.version) {
|
|
1776
1776
|
this.saveUpdate(context, version, updatedResource);
|
|
1777
1777
|
}
|
|
1778
|
-
const result = this.postProcessResource(updatedResource);
|
|
1778
|
+
const result = this.postProcessResource(context, updatedResource);
|
|
1779
1779
|
if (!result) {
|
|
1780
1780
|
throw new Error("invalid post process action");
|
|
1781
1781
|
}
|
|
@@ -1798,7 +1798,7 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1798
1798
|
id,
|
|
1799
1799
|
params
|
|
1800
1800
|
);
|
|
1801
|
-
return resource ? this.postProcessResource(resource) : null;
|
|
1801
|
+
return resource ? this.postProcessResource(context, resource) : null;
|
|
1802
1802
|
}
|
|
1803
1803
|
get(context, id, params = {}) {
|
|
1804
1804
|
const resource = this._storage.get(
|
|
@@ -1807,7 +1807,7 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1807
1807
|
id,
|
|
1808
1808
|
params
|
|
1809
1809
|
);
|
|
1810
|
-
return resource ? this.postProcessResource(resource) : null;
|
|
1810
|
+
return resource ? this.postProcessResource(context, resource) : null;
|
|
1811
1811
|
}
|
|
1812
1812
|
getByKey(context, key, params = {}) {
|
|
1813
1813
|
const resource = this._storage.getByKey(
|
|
@@ -1816,17 +1816,22 @@ var AbstractResourceRepository = class extends AbstractRepository {
|
|
|
1816
1816
|
key,
|
|
1817
1817
|
params
|
|
1818
1818
|
);
|
|
1819
|
-
return resource ? this.postProcessResource(resource) : null;
|
|
1819
|
+
return resource ? this.postProcessResource(context, resource) : null;
|
|
1820
1820
|
}
|
|
1821
|
-
postProcessResource(resource) {
|
|
1821
|
+
postProcessResource(context, resource) {
|
|
1822
1822
|
return resource;
|
|
1823
1823
|
}
|
|
1824
1824
|
query(context, params = {}) {
|
|
1825
1825
|
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
1826
1826
|
...params
|
|
1827
1827
|
});
|
|
1828
|
-
|
|
1829
|
-
|
|
1828
|
+
const data = result.results.map(
|
|
1829
|
+
(r) => this.postProcessResource(context, r)
|
|
1830
|
+
);
|
|
1831
|
+
return {
|
|
1832
|
+
...result,
|
|
1833
|
+
results: data
|
|
1834
|
+
};
|
|
1830
1835
|
}
|
|
1831
1836
|
saveNew(context, resource) {
|
|
1832
1837
|
resource.version = 1;
|
|
@@ -3063,7 +3068,7 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
3063
3068
|
externalId: draft.externalId || "",
|
|
3064
3069
|
parent: draft.parent ? { typeId: "category", id: draft.parent.id } : void 0,
|
|
3065
3070
|
ancestors: [],
|
|
3066
|
-
//
|
|
3071
|
+
// Resolved at runtime
|
|
3067
3072
|
assets: draft.assets?.map((d) => ({
|
|
3068
3073
|
id: (0, import_uuid8.v4)(),
|
|
3069
3074
|
name: d.name,
|
|
@@ -3085,6 +3090,19 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
3085
3090
|
};
|
|
3086
3091
|
return this.saveNew(context, resource);
|
|
3087
3092
|
}
|
|
3093
|
+
postProcessResource(context, resource) {
|
|
3094
|
+
let node = resource;
|
|
3095
|
+
const ancestors = [];
|
|
3096
|
+
while (node.parent) {
|
|
3097
|
+
node = this._storage.getByResourceIdentifier(
|
|
3098
|
+
context.projectKey,
|
|
3099
|
+
node.parent
|
|
3100
|
+
);
|
|
3101
|
+
ancestors.push({ typeId: "category", id: node.id });
|
|
3102
|
+
}
|
|
3103
|
+
resource.ancestors = ancestors;
|
|
3104
|
+
return resource;
|
|
3105
|
+
}
|
|
3088
3106
|
};
|
|
3089
3107
|
|
|
3090
3108
|
// src/repositories/channel.ts
|
|
@@ -3557,7 +3575,7 @@ var ExtensionRepository = class extends AbstractResourceRepository {
|
|
|
3557
3575
|
};
|
|
3558
3576
|
return this.saveNew(context, resource);
|
|
3559
3577
|
}
|
|
3560
|
-
postProcessResource(resource) {
|
|
3578
|
+
postProcessResource(context, resource) {
|
|
3561
3579
|
if (resource) {
|
|
3562
3580
|
const extension = resource;
|
|
3563
3581
|
if (extension.destination.type === "HTTP" && extension.destination.authentication?.type === "AuthorizationHeader") {
|
|
@@ -3804,6 +3822,9 @@ var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3804
3822
|
setCustomerEmail(context, resource, { email }) {
|
|
3805
3823
|
resource.customerEmail = email;
|
|
3806
3824
|
}
|
|
3825
|
+
setCustomerId(context, resource, { customerId }) {
|
|
3826
|
+
resource.customerId = customerId;
|
|
3827
|
+
}
|
|
3807
3828
|
setCustomField(context, resource, { name, value }) {
|
|
3808
3829
|
if (!resource.custom) {
|
|
3809
3830
|
throw new Error("Resource has no custom field");
|
|
@@ -5881,9 +5902,9 @@ var ProjectRepository = class extends AbstractRepository {
|
|
|
5881
5902
|
}
|
|
5882
5903
|
get(context) {
|
|
5883
5904
|
const resource = this._storage.getProject(context.projectKey);
|
|
5884
|
-
return this.postProcessResource(resource);
|
|
5905
|
+
return this.postProcessResource(context, resource);
|
|
5885
5906
|
}
|
|
5886
|
-
postProcessResource(resource) {
|
|
5907
|
+
postProcessResource(context, resource) {
|
|
5887
5908
|
if (resource) {
|
|
5888
5909
|
return maskSecretValue(resource, "externalOAuth.authorizationHeader");
|
|
5889
5910
|
}
|