@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.mjs CHANGED
@@ -911,10 +911,41 @@ var createPrice = (draft) => {
911
911
  };
912
912
  };
913
913
  var createTypedMoney = (value) => {
914
+ let fractionDigits = 2;
915
+ switch (value.currencyCode.toUpperCase()) {
916
+ case "BHD":
917
+ case "IQD":
918
+ case "JOD":
919
+ case "KWD":
920
+ case "LYD":
921
+ case "OMR":
922
+ case "TND":
923
+ fractionDigits = 3;
924
+ break;
925
+ case "CVE":
926
+ case "DJF":
927
+ case "GNF":
928
+ case "IDR":
929
+ case "JPY":
930
+ case "KMF":
931
+ case "KRW":
932
+ case "PYG":
933
+ case "RWF":
934
+ case "UGX":
935
+ case "VND":
936
+ case "VUV":
937
+ case "XAF":
938
+ case "XOF":
939
+ case "XPF":
940
+ fractionDigits = 0;
941
+ break;
942
+ default:
943
+ fractionDigits = 2;
944
+ }
914
945
  return {
915
946
  type: "centPrecision",
916
- fractionDigits: 2,
917
- ...value
947
+ ...value,
948
+ fractionDigits
918
949
  };
919
950
  };
920
951
  var resolveStoreReference = (ref, projectKey, storage) => {
@@ -1122,7 +1153,14 @@ var AbstractRepository = class {
1122
1153
  if (!deepEqual(modifiedResource, resource)) {
1123
1154
  this.save(context, modifiedResource);
1124
1155
  }
1125
- return modifiedResource;
1156
+ const result = this.postProcessResource(modifiedResource);
1157
+ if (!result) {
1158
+ throw new Error("invalid post process action");
1159
+ }
1160
+ return result;
1161
+ }
1162
+ postProcessResource(resource) {
1163
+ return resource;
1126
1164
  }
1127
1165
  };
1128
1166
  var AbstractResourceRepository = class extends AbstractRepository {
@@ -1131,31 +1169,36 @@ var AbstractResourceRepository = class extends AbstractRepository {
1131
1169
  this._storage.assertStorage(this.getTypeId());
1132
1170
  }
1133
1171
  query(context, params = {}) {
1134
- return this._storage.query(context.projectKey, this.getTypeId(), {
1172
+ const result = this._storage.query(context.projectKey, this.getTypeId(), {
1135
1173
  expand: params.expand,
1136
1174
  where: params.where,
1137
1175
  offset: params.offset,
1138
1176
  limit: params.limit
1139
1177
  });
1178
+ result.results = result.results.map(this.postProcessResource);
1179
+ return result;
1140
1180
  }
1141
1181
  get(context, id, params = {}) {
1142
- return this._storage.get(context.projectKey, this.getTypeId(), id, params);
1182
+ const resource = this._storage.get(context.projectKey, this.getTypeId(), id, params);
1183
+ return this.postProcessResource(resource);
1143
1184
  }
1144
1185
  getByKey(context, key, params = {}) {
1145
- return this._storage.getByKey(
1186
+ const resource = this._storage.getByKey(
1146
1187
  context.projectKey,
1147
1188
  this.getTypeId(),
1148
1189
  key,
1149
1190
  params
1150
1191
  );
1192
+ return this.postProcessResource(resource);
1151
1193
  }
1152
1194
  delete(context, id, params = {}) {
1153
- return this._storage.delete(
1195
+ const resource = this._storage.delete(
1154
1196
  context.projectKey,
1155
1197
  this.getTypeId(),
1156
1198
  id,
1157
1199
  params
1158
1200
  );
1201
+ return this.postProcessResource(resource);
1159
1202
  }
1160
1203
  save(context, resource) {
1161
1204
  const current = this.get(context, resource.id);
@@ -2439,6 +2482,25 @@ var DiscountCodeService = class extends AbstractService {
2439
2482
  }
2440
2483
  };
2441
2484
 
2485
+ // src/lib/masking.ts
2486
+ var maskSecretValue = (resource, path) => {
2487
+ const parts = path.split(".");
2488
+ const clone = JSON.parse(JSON.stringify(resource));
2489
+ let val = clone;
2490
+ const target = parts.pop();
2491
+ for (let i = 0; i < parts.length; i++) {
2492
+ const part = parts[i];
2493
+ val = val[part];
2494
+ if (val === void 0) {
2495
+ return resource;
2496
+ }
2497
+ }
2498
+ if (val && target && val[target]) {
2499
+ val[target] = "****";
2500
+ }
2501
+ return clone;
2502
+ };
2503
+
2442
2504
  // src/repositories/extension.ts
2443
2505
  var ExtensionRepository = class extends AbstractResourceRepository {
2444
2506
  constructor() {
@@ -2461,6 +2523,23 @@ var ExtensionRepository = class extends AbstractResourceRepository {
2461
2523
  getTypeId() {
2462
2524
  return "extension";
2463
2525
  }
2526
+ postProcessResource(resource) {
2527
+ var _a;
2528
+ if (resource) {
2529
+ if (resource.destination.type === "HTTP" && ((_a = resource.destination.authentication) == null ? void 0 : _a.type) === "AuthorizationHeader") {
2530
+ return maskSecretValue(
2531
+ resource,
2532
+ "destination.authentication.headerValue"
2533
+ );
2534
+ } else if (resource.destination.type == "AWSLambda") {
2535
+ return maskSecretValue(
2536
+ resource,
2537
+ "destination.accessSecret"
2538
+ );
2539
+ }
2540
+ }
2541
+ return resource;
2542
+ }
2464
2543
  create(context, draft) {
2465
2544
  const resource = {
2466
2545
  ...getBaseResourceProperties(),
@@ -3217,6 +3296,9 @@ var ProductProjectionSearch = class {
3217
3296
  lastModifiedAt: product.lastModifiedAt,
3218
3297
  version: product.version,
3219
3298
  name: obj.name,
3299
+ key: product.key,
3300
+ description: obj.description,
3301
+ metaDescription: obj.metaDescription,
3220
3302
  slug: obj.slug,
3221
3303
  categories: obj.categories,
3222
3304
  masterVariant: obj.masterVariant,
@@ -3740,25 +3822,6 @@ var ProductTypeService = class extends AbstractService {
3740
3822
  }
3741
3823
  };
3742
3824
 
3743
- // src/lib/masking.ts
3744
- var maskSecretValue = (resource, path) => {
3745
- const parts = path.split(".");
3746
- const clone = JSON.parse(JSON.stringify(resource));
3747
- let val = clone;
3748
- const target = parts.pop();
3749
- for (let i = 0; i < parts.length; i++) {
3750
- const part = parts[i];
3751
- val = val[part];
3752
- if (val === void 0) {
3753
- return resource;
3754
- }
3755
- }
3756
- if (val && target && val[target]) {
3757
- val[target] = "****";
3758
- }
3759
- return clone;
3760
- };
3761
-
3762
3825
  // src/repositories/project.ts
3763
3826
  var ProjectRepository = class extends AbstractRepository {
3764
3827
  constructor() {
@@ -3816,11 +3879,16 @@ var ProjectRepository = class extends AbstractRepository {
3816
3879
  }
3817
3880
  get(context) {
3818
3881
  const resource = this._storage.getProject(context.projectKey);
3819
- const masked = maskSecretValue(
3820
- resource,
3821
- "externalOAuth.authorizationHeader"
3822
- );
3823
- return masked;
3882
+ return this.postProcessResource(resource);
3883
+ }
3884
+ postProcessResource(resource) {
3885
+ if (resource) {
3886
+ return maskSecretValue(
3887
+ resource,
3888
+ "externalOAuth.authorizationHeader"
3889
+ );
3890
+ }
3891
+ return resource;
3824
3892
  }
3825
3893
  save(context, resource) {
3826
3894
  const current = this.get(context);
@@ -4089,6 +4157,14 @@ var StateRepository = class extends AbstractResourceRepository {
4089
4157
  },
4090
4158
  setRoles: (context, resource, { roles }) => {
4091
4159
  resource.roles = roles;
4160
+ },
4161
+ setTransitions: (context, resource, { transitions }) => {
4162
+ resource.transitions = transitions == null ? void 0 : transitions.map((resourceId) => {
4163
+ return {
4164
+ id: resourceId.id || "",
4165
+ typeId: "state"
4166
+ };
4167
+ });
4092
4168
  }
4093
4169
  };
4094
4170
  }