@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.js CHANGED
@@ -944,10 +944,41 @@ var createPrice = (draft) => {
944
944
  };
945
945
  };
946
946
  var createTypedMoney = (value) => {
947
+ let fractionDigits = 2;
948
+ switch (value.currencyCode.toUpperCase()) {
949
+ case "BHD":
950
+ case "IQD":
951
+ case "JOD":
952
+ case "KWD":
953
+ case "LYD":
954
+ case "OMR":
955
+ case "TND":
956
+ fractionDigits = 3;
957
+ break;
958
+ case "CVE":
959
+ case "DJF":
960
+ case "GNF":
961
+ case "IDR":
962
+ case "JPY":
963
+ case "KMF":
964
+ case "KRW":
965
+ case "PYG":
966
+ case "RWF":
967
+ case "UGX":
968
+ case "VND":
969
+ case "VUV":
970
+ case "XAF":
971
+ case "XOF":
972
+ case "XPF":
973
+ fractionDigits = 0;
974
+ break;
975
+ default:
976
+ fractionDigits = 2;
977
+ }
947
978
  return {
948
979
  type: "centPrecision",
949
- fractionDigits: 2,
950
- ...value
980
+ ...value,
981
+ fractionDigits
951
982
  };
952
983
  };
953
984
  var resolveStoreReference = (ref, projectKey, storage) => {
@@ -1155,7 +1186,14 @@ var AbstractRepository = class {
1155
1186
  if (!(0, import_deep_equal.default)(modifiedResource, resource)) {
1156
1187
  this.save(context, modifiedResource);
1157
1188
  }
1158
- return modifiedResource;
1189
+ const result = this.postProcessResource(modifiedResource);
1190
+ if (!result) {
1191
+ throw new Error("invalid post process action");
1192
+ }
1193
+ return result;
1194
+ }
1195
+ postProcessResource(resource) {
1196
+ return resource;
1159
1197
  }
1160
1198
  };
1161
1199
  var AbstractResourceRepository = class extends AbstractRepository {
@@ -1164,31 +1202,36 @@ var AbstractResourceRepository = class extends AbstractRepository {
1164
1202
  this._storage.assertStorage(this.getTypeId());
1165
1203
  }
1166
1204
  query(context, params = {}) {
1167
- return this._storage.query(context.projectKey, this.getTypeId(), {
1205
+ const result = this._storage.query(context.projectKey, this.getTypeId(), {
1168
1206
  expand: params.expand,
1169
1207
  where: params.where,
1170
1208
  offset: params.offset,
1171
1209
  limit: params.limit
1172
1210
  });
1211
+ result.results = result.results.map(this.postProcessResource);
1212
+ return result;
1173
1213
  }
1174
1214
  get(context, id, params = {}) {
1175
- return this._storage.get(context.projectKey, this.getTypeId(), id, params);
1215
+ const resource = this._storage.get(context.projectKey, this.getTypeId(), id, params);
1216
+ return this.postProcessResource(resource);
1176
1217
  }
1177
1218
  getByKey(context, key, params = {}) {
1178
- return this._storage.getByKey(
1219
+ const resource = this._storage.getByKey(
1179
1220
  context.projectKey,
1180
1221
  this.getTypeId(),
1181
1222
  key,
1182
1223
  params
1183
1224
  );
1225
+ return this.postProcessResource(resource);
1184
1226
  }
1185
1227
  delete(context, id, params = {}) {
1186
- return this._storage.delete(
1228
+ const resource = this._storage.delete(
1187
1229
  context.projectKey,
1188
1230
  this.getTypeId(),
1189
1231
  id,
1190
1232
  params
1191
1233
  );
1234
+ return this.postProcessResource(resource);
1192
1235
  }
1193
1236
  save(context, resource) {
1194
1237
  const current = this.get(context, resource.id);
@@ -2472,6 +2515,25 @@ var DiscountCodeService = class extends AbstractService {
2472
2515
  }
2473
2516
  };
2474
2517
 
2518
+ // src/lib/masking.ts
2519
+ var maskSecretValue = (resource, path) => {
2520
+ const parts = path.split(".");
2521
+ const clone = JSON.parse(JSON.stringify(resource));
2522
+ let val = clone;
2523
+ const target = parts.pop();
2524
+ for (let i = 0; i < parts.length; i++) {
2525
+ const part = parts[i];
2526
+ val = val[part];
2527
+ if (val === void 0) {
2528
+ return resource;
2529
+ }
2530
+ }
2531
+ if (val && target && val[target]) {
2532
+ val[target] = "****";
2533
+ }
2534
+ return clone;
2535
+ };
2536
+
2475
2537
  // src/repositories/extension.ts
2476
2538
  var ExtensionRepository = class extends AbstractResourceRepository {
2477
2539
  constructor() {
@@ -2494,6 +2556,23 @@ var ExtensionRepository = class extends AbstractResourceRepository {
2494
2556
  getTypeId() {
2495
2557
  return "extension";
2496
2558
  }
2559
+ postProcessResource(resource) {
2560
+ var _a;
2561
+ if (resource) {
2562
+ if (resource.destination.type === "HTTP" && ((_a = resource.destination.authentication) == null ? void 0 : _a.type) === "AuthorizationHeader") {
2563
+ return maskSecretValue(
2564
+ resource,
2565
+ "destination.authentication.headerValue"
2566
+ );
2567
+ } else if (resource.destination.type == "AWSLambda") {
2568
+ return maskSecretValue(
2569
+ resource,
2570
+ "destination.accessSecret"
2571
+ );
2572
+ }
2573
+ }
2574
+ return resource;
2575
+ }
2497
2576
  create(context, draft) {
2498
2577
  const resource = {
2499
2578
  ...getBaseResourceProperties(),
@@ -3250,6 +3329,9 @@ var ProductProjectionSearch = class {
3250
3329
  lastModifiedAt: product.lastModifiedAt,
3251
3330
  version: product.version,
3252
3331
  name: obj.name,
3332
+ key: product.key,
3333
+ description: obj.description,
3334
+ metaDescription: obj.metaDescription,
3253
3335
  slug: obj.slug,
3254
3336
  categories: obj.categories,
3255
3337
  masterVariant: obj.masterVariant,
@@ -3773,25 +3855,6 @@ var ProductTypeService = class extends AbstractService {
3773
3855
  }
3774
3856
  };
3775
3857
 
3776
- // src/lib/masking.ts
3777
- var maskSecretValue = (resource, path) => {
3778
- const parts = path.split(".");
3779
- const clone = JSON.parse(JSON.stringify(resource));
3780
- let val = clone;
3781
- const target = parts.pop();
3782
- for (let i = 0; i < parts.length; i++) {
3783
- const part = parts[i];
3784
- val = val[part];
3785
- if (val === void 0) {
3786
- return resource;
3787
- }
3788
- }
3789
- if (val && target && val[target]) {
3790
- val[target] = "****";
3791
- }
3792
- return clone;
3793
- };
3794
-
3795
3858
  // src/repositories/project.ts
3796
3859
  var ProjectRepository = class extends AbstractRepository {
3797
3860
  constructor() {
@@ -3849,11 +3912,16 @@ var ProjectRepository = class extends AbstractRepository {
3849
3912
  }
3850
3913
  get(context) {
3851
3914
  const resource = this._storage.getProject(context.projectKey);
3852
- const masked = maskSecretValue(
3853
- resource,
3854
- "externalOAuth.authorizationHeader"
3855
- );
3856
- return masked;
3915
+ return this.postProcessResource(resource);
3916
+ }
3917
+ postProcessResource(resource) {
3918
+ if (resource) {
3919
+ return maskSecretValue(
3920
+ resource,
3921
+ "externalOAuth.authorizationHeader"
3922
+ );
3923
+ }
3924
+ return resource;
3857
3925
  }
3858
3926
  save(context, resource) {
3859
3927
  const current = this.get(context);
@@ -4122,6 +4190,14 @@ var StateRepository = class extends AbstractResourceRepository {
4122
4190
  },
4123
4191
  setRoles: (context, resource, { roles }) => {
4124
4192
  resource.roles = roles;
4193
+ },
4194
+ setTransitions: (context, resource, { transitions }) => {
4195
+ resource.transitions = transitions == null ? void 0 : transitions.map((resourceId) => {
4196
+ return {
4197
+ id: resourceId.id || "",
4198
+ typeId: "state"
4199
+ };
4200
+ });
4125
4201
  }
4126
4202
  };
4127
4203
  }