@labdigital/commercetools-mock 2.20.0 → 2.20.2
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 +37 -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 +37 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
- package/src/repositories/abstract.ts +23 -9
- package/src/repositories/category/index.test.ts +92 -0
- package/src/repositories/category/index.ts +43 -2
- package/src/repositories/extension.ts +4 -1
- package/src/repositories/project.ts +2 -2
- package/src/services/category.test.ts +2 -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, params) : 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, params) : 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, params) : null;
|
|
1820
1820
|
}
|
|
1821
|
-
postProcessResource(resource) {
|
|
1821
|
+
postProcessResource(context, resource, params) {
|
|
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,27 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
3085
3090
|
};
|
|
3086
3091
|
return this.saveNew(context, resource);
|
|
3087
3092
|
}
|
|
3093
|
+
postProcessResource(context, resource, params) {
|
|
3094
|
+
let node = resource;
|
|
3095
|
+
const ancestors = [];
|
|
3096
|
+
const expandClauses = params?.expand?.map(parseExpandClause) ?? [];
|
|
3097
|
+
const addExpand = expandClauses?.find(
|
|
3098
|
+
(c) => c.element === "ancestors" && c.index === "*"
|
|
3099
|
+
);
|
|
3100
|
+
while (node.parent) {
|
|
3101
|
+
node = this._storage.getByResourceIdentifier(
|
|
3102
|
+
context.projectKey,
|
|
3103
|
+
node.parent
|
|
3104
|
+
);
|
|
3105
|
+
ancestors.push({
|
|
3106
|
+
typeId: "category",
|
|
3107
|
+
id: node.id,
|
|
3108
|
+
obj: addExpand ? node : void 0
|
|
3109
|
+
});
|
|
3110
|
+
}
|
|
3111
|
+
resource.ancestors = ancestors;
|
|
3112
|
+
return resource;
|
|
3113
|
+
}
|
|
3088
3114
|
};
|
|
3089
3115
|
|
|
3090
3116
|
// src/repositories/channel.ts
|
|
@@ -3557,7 +3583,7 @@ var ExtensionRepository = class extends AbstractResourceRepository {
|
|
|
3557
3583
|
};
|
|
3558
3584
|
return this.saveNew(context, resource);
|
|
3559
3585
|
}
|
|
3560
|
-
postProcessResource(resource) {
|
|
3586
|
+
postProcessResource(context, resource) {
|
|
3561
3587
|
if (resource) {
|
|
3562
3588
|
const extension = resource;
|
|
3563
3589
|
if (extension.destination.type === "HTTP" && extension.destination.authentication?.type === "AuthorizationHeader") {
|
|
@@ -5884,9 +5910,9 @@ var ProjectRepository = class extends AbstractRepository {
|
|
|
5884
5910
|
}
|
|
5885
5911
|
get(context) {
|
|
5886
5912
|
const resource = this._storage.getProject(context.projectKey);
|
|
5887
|
-
return this.postProcessResource(resource);
|
|
5913
|
+
return this.postProcessResource(context, resource);
|
|
5888
5914
|
}
|
|
5889
|
-
postProcessResource(resource) {
|
|
5915
|
+
postProcessResource(context, resource) {
|
|
5890
5916
|
if (resource) {
|
|
5891
5917
|
return maskSecretValue(resource, "externalOAuth.authorizationHeader");
|
|
5892
5918
|
}
|