@labdigital/commercetools-mock 0.8.0 → 0.9.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.d.ts +1 -0
- package/dist/index.global.js +107 -31
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +107 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -4
- package/src/product-projection-search.ts +4 -0
- package/src/repositories/abstract.ts +23 -5
- package/src/repositories/extension.ts +18 -1
- package/src/repositories/helpers.ts +37 -3
- package/src/repositories/project.ts +10 -5
- package/src/repositories/state.ts +14 -0
- package/src/validate.js +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -347,6 +347,7 @@ declare abstract class AbstractRepository {
|
|
|
347
347
|
constructor(storage: AbstractStorage);
|
|
348
348
|
abstract save({ projectKey }: RepositoryContext, resource: BaseResource | Project): void;
|
|
349
349
|
processUpdateActions(context: RepositoryContext, resource: BaseResource | Project, actions: UpdateAction[]): BaseResource;
|
|
350
|
+
postProcessResource(resource: BaseResource | null): BaseResource | null;
|
|
350
351
|
}
|
|
351
352
|
declare abstract class AbstractResourceRepository extends AbstractRepository {
|
|
352
353
|
abstract create(context: RepositoryContext, draft: any): BaseResource;
|
package/dist/index.global.js
CHANGED
|
@@ -45859,10 +45859,41 @@ ${this.pendingMocks().join("\n")}`
|
|
|
45859
45859
|
};
|
|
45860
45860
|
};
|
|
45861
45861
|
var createTypedMoney = (value) => {
|
|
45862
|
+
let fractionDigits = 2;
|
|
45863
|
+
switch (value.currencyCode.toUpperCase()) {
|
|
45864
|
+
case "BHD":
|
|
45865
|
+
case "IQD":
|
|
45866
|
+
case "JOD":
|
|
45867
|
+
case "KWD":
|
|
45868
|
+
case "LYD":
|
|
45869
|
+
case "OMR":
|
|
45870
|
+
case "TND":
|
|
45871
|
+
fractionDigits = 3;
|
|
45872
|
+
break;
|
|
45873
|
+
case "CVE":
|
|
45874
|
+
case "DJF":
|
|
45875
|
+
case "GNF":
|
|
45876
|
+
case "IDR":
|
|
45877
|
+
case "JPY":
|
|
45878
|
+
case "KMF":
|
|
45879
|
+
case "KRW":
|
|
45880
|
+
case "PYG":
|
|
45881
|
+
case "RWF":
|
|
45882
|
+
case "UGX":
|
|
45883
|
+
case "VND":
|
|
45884
|
+
case "VUV":
|
|
45885
|
+
case "XAF":
|
|
45886
|
+
case "XOF":
|
|
45887
|
+
case "XPF":
|
|
45888
|
+
fractionDigits = 0;
|
|
45889
|
+
break;
|
|
45890
|
+
default:
|
|
45891
|
+
fractionDigits = 2;
|
|
45892
|
+
}
|
|
45862
45893
|
return {
|
|
45863
45894
|
type: "centPrecision",
|
|
45864
|
-
|
|
45865
|
-
|
|
45895
|
+
...value,
|
|
45896
|
+
fractionDigits
|
|
45866
45897
|
};
|
|
45867
45898
|
};
|
|
45868
45899
|
var resolveStoreReference = (ref, projectKey, storage) => {
|
|
@@ -46070,7 +46101,14 @@ ${this.pendingMocks().join("\n")}`
|
|
|
46070
46101
|
if (!(0, import_deep_equal.default)(modifiedResource, resource)) {
|
|
46071
46102
|
this.save(context, modifiedResource);
|
|
46072
46103
|
}
|
|
46073
|
-
|
|
46104
|
+
const result = this.postProcessResource(modifiedResource);
|
|
46105
|
+
if (!result) {
|
|
46106
|
+
throw new Error("invalid post process action");
|
|
46107
|
+
}
|
|
46108
|
+
return result;
|
|
46109
|
+
}
|
|
46110
|
+
postProcessResource(resource) {
|
|
46111
|
+
return resource;
|
|
46074
46112
|
}
|
|
46075
46113
|
};
|
|
46076
46114
|
var AbstractResourceRepository = class extends AbstractRepository {
|
|
@@ -46079,31 +46117,36 @@ ${this.pendingMocks().join("\n")}`
|
|
|
46079
46117
|
this._storage.assertStorage(this.getTypeId());
|
|
46080
46118
|
}
|
|
46081
46119
|
query(context, params = {}) {
|
|
46082
|
-
|
|
46120
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
46083
46121
|
expand: params.expand,
|
|
46084
46122
|
where: params.where,
|
|
46085
46123
|
offset: params.offset,
|
|
46086
46124
|
limit: params.limit
|
|
46087
46125
|
});
|
|
46126
|
+
result.results = result.results.map(this.postProcessResource);
|
|
46127
|
+
return result;
|
|
46088
46128
|
}
|
|
46089
46129
|
get(context, id, params = {}) {
|
|
46090
|
-
|
|
46130
|
+
const resource = this._storage.get(context.projectKey, this.getTypeId(), id, params);
|
|
46131
|
+
return this.postProcessResource(resource);
|
|
46091
46132
|
}
|
|
46092
46133
|
getByKey(context, key, params = {}) {
|
|
46093
|
-
|
|
46134
|
+
const resource = this._storage.getByKey(
|
|
46094
46135
|
context.projectKey,
|
|
46095
46136
|
this.getTypeId(),
|
|
46096
46137
|
key,
|
|
46097
46138
|
params
|
|
46098
46139
|
);
|
|
46140
|
+
return this.postProcessResource(resource);
|
|
46099
46141
|
}
|
|
46100
46142
|
delete(context, id, params = {}) {
|
|
46101
|
-
|
|
46143
|
+
const resource = this._storage.delete(
|
|
46102
46144
|
context.projectKey,
|
|
46103
46145
|
this.getTypeId(),
|
|
46104
46146
|
id,
|
|
46105
46147
|
params
|
|
46106
46148
|
);
|
|
46149
|
+
return this.postProcessResource(resource);
|
|
46107
46150
|
}
|
|
46108
46151
|
save(context, resource) {
|
|
46109
46152
|
const current = this.get(context, resource.id);
|
|
@@ -47384,6 +47427,25 @@ ${this.pendingMocks().join("\n")}`
|
|
|
47384
47427
|
}
|
|
47385
47428
|
};
|
|
47386
47429
|
|
|
47430
|
+
// src/lib/masking.ts
|
|
47431
|
+
var maskSecretValue = (resource, path) => {
|
|
47432
|
+
const parts = path.split(".");
|
|
47433
|
+
const clone = JSON.parse(JSON.stringify(resource));
|
|
47434
|
+
let val = clone;
|
|
47435
|
+
const target = parts.pop();
|
|
47436
|
+
for (let i = 0; i < parts.length; i++) {
|
|
47437
|
+
const part = parts[i];
|
|
47438
|
+
val = val[part];
|
|
47439
|
+
if (val === void 0) {
|
|
47440
|
+
return resource;
|
|
47441
|
+
}
|
|
47442
|
+
}
|
|
47443
|
+
if (val && target && val[target]) {
|
|
47444
|
+
val[target] = "****";
|
|
47445
|
+
}
|
|
47446
|
+
return clone;
|
|
47447
|
+
};
|
|
47448
|
+
|
|
47387
47449
|
// src/repositories/extension.ts
|
|
47388
47450
|
var ExtensionRepository = class extends AbstractResourceRepository {
|
|
47389
47451
|
constructor() {
|
|
@@ -47406,6 +47468,23 @@ ${this.pendingMocks().join("\n")}`
|
|
|
47406
47468
|
getTypeId() {
|
|
47407
47469
|
return "extension";
|
|
47408
47470
|
}
|
|
47471
|
+
postProcessResource(resource) {
|
|
47472
|
+
var _a;
|
|
47473
|
+
if (resource) {
|
|
47474
|
+
if (resource.destination.type === "HTTP" && ((_a = resource.destination.authentication) == null ? void 0 : _a.type) === "AuthorizationHeader") {
|
|
47475
|
+
return maskSecretValue(
|
|
47476
|
+
resource,
|
|
47477
|
+
"destination.authentication.headerValue"
|
|
47478
|
+
);
|
|
47479
|
+
} else if (resource.destination.type == "AWSLambda") {
|
|
47480
|
+
return maskSecretValue(
|
|
47481
|
+
resource,
|
|
47482
|
+
"destination.accessSecret"
|
|
47483
|
+
);
|
|
47484
|
+
}
|
|
47485
|
+
}
|
|
47486
|
+
return resource;
|
|
47487
|
+
}
|
|
47409
47488
|
create(context, draft) {
|
|
47410
47489
|
const resource = {
|
|
47411
47490
|
...getBaseResourceProperties(),
|
|
@@ -48161,6 +48240,9 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48161
48240
|
lastModifiedAt: product.lastModifiedAt,
|
|
48162
48241
|
version: product.version,
|
|
48163
48242
|
name: obj.name,
|
|
48243
|
+
key: product.key,
|
|
48244
|
+
description: obj.description,
|
|
48245
|
+
metaDescription: obj.metaDescription,
|
|
48164
48246
|
slug: obj.slug,
|
|
48165
48247
|
categories: obj.categories,
|
|
48166
48248
|
masterVariant: obj.masterVariant,
|
|
@@ -48683,25 +48765,6 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48683
48765
|
}
|
|
48684
48766
|
};
|
|
48685
48767
|
|
|
48686
|
-
// src/lib/masking.ts
|
|
48687
|
-
var maskSecretValue = (resource, path) => {
|
|
48688
|
-
const parts = path.split(".");
|
|
48689
|
-
const clone = JSON.parse(JSON.stringify(resource));
|
|
48690
|
-
let val = clone;
|
|
48691
|
-
const target = parts.pop();
|
|
48692
|
-
for (let i = 0; i < parts.length; i++) {
|
|
48693
|
-
const part = parts[i];
|
|
48694
|
-
val = val[part];
|
|
48695
|
-
if (val === void 0) {
|
|
48696
|
-
return resource;
|
|
48697
|
-
}
|
|
48698
|
-
}
|
|
48699
|
-
if (val && target && val[target]) {
|
|
48700
|
-
val[target] = "****";
|
|
48701
|
-
}
|
|
48702
|
-
return clone;
|
|
48703
|
-
};
|
|
48704
|
-
|
|
48705
48768
|
// src/repositories/project.ts
|
|
48706
48769
|
var ProjectRepository = class extends AbstractRepository {
|
|
48707
48770
|
constructor() {
|
|
@@ -48759,11 +48822,16 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48759
48822
|
}
|
|
48760
48823
|
get(context) {
|
|
48761
48824
|
const resource = this._storage.getProject(context.projectKey);
|
|
48762
|
-
|
|
48763
|
-
|
|
48764
|
-
|
|
48765
|
-
)
|
|
48766
|
-
|
|
48825
|
+
return this.postProcessResource(resource);
|
|
48826
|
+
}
|
|
48827
|
+
postProcessResource(resource) {
|
|
48828
|
+
if (resource) {
|
|
48829
|
+
return maskSecretValue(
|
|
48830
|
+
resource,
|
|
48831
|
+
"externalOAuth.authorizationHeader"
|
|
48832
|
+
);
|
|
48833
|
+
}
|
|
48834
|
+
return resource;
|
|
48767
48835
|
}
|
|
48768
48836
|
save(context, resource) {
|
|
48769
48837
|
const current = this.get(context);
|
|
@@ -49032,6 +49100,14 @@ ${this.pendingMocks().join("\n")}`
|
|
|
49032
49100
|
},
|
|
49033
49101
|
setRoles: (context, resource, { roles }) => {
|
|
49034
49102
|
resource.roles = roles;
|
|
49103
|
+
},
|
|
49104
|
+
setTransitions: (context, resource, { transitions }) => {
|
|
49105
|
+
resource.transitions = transitions == null ? void 0 : transitions.map((resourceId) => {
|
|
49106
|
+
return {
|
|
49107
|
+
id: resourceId.id || "",
|
|
49108
|
+
typeId: "state"
|
|
49109
|
+
};
|
|
49110
|
+
});
|
|
49035
49111
|
}
|
|
49036
49112
|
};
|
|
49037
49113
|
}
|