@labdigital/commercetools-mock 0.6.0 → 0.6.3
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/commercetools-mock.cjs.development.js +423 -352
- package/dist/commercetools-mock.cjs.development.js.map +1 -1
- package/dist/commercetools-mock.cjs.production.min.js +1 -1
- package/dist/commercetools-mock.cjs.production.min.js.map +1 -1
- package/dist/commercetools-mock.esm.js +423 -352
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/repositories/abstract.d.ts +13 -9
- package/dist/repositories/cart-discount.d.ts +3 -3
- package/dist/repositories/cart.d.ts +13 -13
- package/dist/repositories/category.d.ts +11 -11
- package/dist/repositories/channel.d.ts +2 -2
- package/dist/repositories/custom-object.d.ts +3 -3
- package/dist/repositories/customer-group.d.ts +4 -4
- package/dist/repositories/customer.d.ts +4 -4
- package/dist/repositories/discount-code.d.ts +3 -3
- package/dist/repositories/extension.d.ts +3 -3
- package/dist/repositories/helpers.d.ts +3 -0
- package/dist/repositories/inventory-entry.d.ts +7 -7
- package/dist/repositories/my-order.d.ts +6 -0
- package/dist/repositories/order.d.ts +18 -17
- package/dist/repositories/payment.d.ts +8 -8
- package/dist/repositories/product-projection.d.ts +3 -3
- package/dist/repositories/product-type.d.ts +5 -5
- package/dist/repositories/product.d.ts +4 -4
- package/dist/repositories/project.d.ts +4 -4
- package/dist/repositories/shipping-method.d.ts +3 -3
- package/dist/repositories/shopping-list.d.ts +2 -2
- package/dist/repositories/state.d.ts +3 -3
- package/dist/repositories/store.d.ts +4 -4
- package/dist/repositories/subscription.d.ts +2 -2
- package/dist/repositories/tax-category.d.ts +4 -4
- package/dist/repositories/type.d.ts +3 -3
- package/dist/repositories/zone.d.ts +3 -3
- package/dist/services/my-order.d.ts +2 -2
- package/package.json +1 -1
- package/src/ctMock.ts +6 -0
- package/src/repositories/abstract.ts +37 -17
- package/src/repositories/cart-discount.ts +11 -11
- package/src/repositories/cart.ts +88 -36
- package/src/repositories/category.ts +17 -13
- package/src/repositories/channel.ts +3 -3
- package/src/repositories/custom-object.ts +16 -8
- package/src/repositories/customer-group.ts +5 -5
- package/src/repositories/customer.ts +10 -6
- package/src/repositories/discount-code.ts +14 -14
- package/src/repositories/extension.ts +12 -8
- package/src/repositories/helpers.ts +9 -0
- package/src/repositories/inventory-entry.ts +17 -10
- package/src/repositories/my-order.ts +19 -0
- package/src/repositories/order.test.ts +79 -3
- package/src/repositories/order.ts +77 -37
- package/src/repositories/payment.ts +21 -17
- package/src/repositories/product-projection.ts +5 -5
- package/src/repositories/product-type.ts +14 -10
- package/src/repositories/product.ts +5 -5
- package/src/repositories/project.ts +21 -17
- package/src/repositories/shipping-method.ts +27 -20
- package/src/repositories/shopping-list.ts +10 -6
- package/src/repositories/state.ts +13 -9
- package/src/repositories/store.ts +18 -14
- package/src/repositories/subscription.ts +3 -3
- package/src/repositories/tax-category.ts +16 -12
- package/src/repositories/type.ts +15 -11
- package/src/repositories/zone.ts +13 -9
- package/src/services/abstract.ts +21 -10
- package/src/services/cart.test.ts +48 -8
- package/src/services/cart.ts +17 -11
- package/src/services/custom-object.ts +8 -4
- package/src/services/customer.ts +5 -2
- package/src/services/my-customer.ts +7 -3
- package/src/services/my-order.ts +3 -3
- package/src/services/order.ts +3 -2
- package/src/services/product-projection.ts +2 -1
- package/src/services/product-type.ts +2 -1
- package/src/services/project.ts +4 -3
- package/src/services/store.ts +2 -1
- package/src/services/tax-category.ts +2 -1
|
@@ -950,6 +950,67 @@ const copyHeaders = headers => {
|
|
|
950
950
|
const DEFAULT_API_HOSTNAME = /^https:\/\/api\..*?\.commercetools.com:443$/;
|
|
951
951
|
const DEFAULT_AUTH_HOSTNAME = /^https:\/\/auth\..*?\.commercetools.com:443$/;
|
|
952
952
|
|
|
953
|
+
const createCustomFields = (draft, projectKey, storage) => {
|
|
954
|
+
if (!draft) return undefined;
|
|
955
|
+
if (!draft.type) return undefined;
|
|
956
|
+
if (!draft.type.typeId) return undefined;
|
|
957
|
+
if (!draft.fields) return undefined;
|
|
958
|
+
const typeResource = storage.getByResourceIdentifier(projectKey, draft.type);
|
|
959
|
+
|
|
960
|
+
if (!typeResource) {
|
|
961
|
+
throw new Error(`No type '${draft.type.typeId}' with id=${draft.type.id} or key=${draft.type.key}`);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
return {
|
|
965
|
+
type: {
|
|
966
|
+
typeId: draft.type.typeId,
|
|
967
|
+
id: typeResource.id
|
|
968
|
+
},
|
|
969
|
+
fields: draft.fields
|
|
970
|
+
};
|
|
971
|
+
};
|
|
972
|
+
const createPrice = draft => {
|
|
973
|
+
return {
|
|
974
|
+
id: v4(),
|
|
975
|
+
value: createTypedMoney(draft.value)
|
|
976
|
+
};
|
|
977
|
+
};
|
|
978
|
+
const createTypedMoney = value => {
|
|
979
|
+
return {
|
|
980
|
+
type: 'centPrecision',
|
|
981
|
+
fractionDigits: 2,
|
|
982
|
+
...value
|
|
983
|
+
};
|
|
984
|
+
};
|
|
985
|
+
const resolveStoreReference = (ref, projectKey, storage) => {
|
|
986
|
+
if (!ref) return undefined;
|
|
987
|
+
const resource = storage.getByResourceIdentifier(projectKey, ref);
|
|
988
|
+
|
|
989
|
+
if (!resource) {
|
|
990
|
+
throw new Error('No such store');
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
const store = resource;
|
|
994
|
+
return {
|
|
995
|
+
typeId: 'store',
|
|
996
|
+
key: store.key
|
|
997
|
+
};
|
|
998
|
+
};
|
|
999
|
+
const getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storage) => {
|
|
1000
|
+
const resource = storage.getByResourceIdentifier(projectKey, resourceIdentifier);
|
|
1001
|
+
if (!resource) throw new Error(`resource type ${resourceIdentifier.typeId} with id ${resourceIdentifier.id} and key ${resourceIdentifier.key} not found`);
|
|
1002
|
+
return {
|
|
1003
|
+
typeId: resourceIdentifier.typeId,
|
|
1004
|
+
id: resource == null ? void 0 : resource.id
|
|
1005
|
+
};
|
|
1006
|
+
};
|
|
1007
|
+
const getRepositoryContext = request => {
|
|
1008
|
+
return {
|
|
1009
|
+
projectKey: request.params.projectKey,
|
|
1010
|
+
storeKey: request.params.storeKey
|
|
1011
|
+
};
|
|
1012
|
+
};
|
|
1013
|
+
|
|
953
1014
|
class AbstractService {
|
|
954
1015
|
constructor(parent) {
|
|
955
1016
|
this.createStatusCode = 201;
|
|
@@ -982,7 +1043,7 @@ class AbstractService {
|
|
|
982
1043
|
|
|
983
1044
|
const offset = this._parseParam(request.query.offset);
|
|
984
1045
|
|
|
985
|
-
const result = this.repository.query(request
|
|
1046
|
+
const result = this.repository.query(getRepositoryContext(request), {
|
|
986
1047
|
expand: this._parseParam(request.query.expand),
|
|
987
1048
|
where: this._parseParam(request.query.where),
|
|
988
1049
|
limit: limit !== undefined ? Number(limit) : undefined,
|
|
@@ -1002,7 +1063,7 @@ class AbstractService {
|
|
|
1002
1063
|
}
|
|
1003
1064
|
|
|
1004
1065
|
getWithKey(request, response) {
|
|
1005
|
-
const result = this.repository.getByKey(request
|
|
1066
|
+
const result = this.repository.getByKey(getRepositoryContext(request), request.params['key'], {
|
|
1006
1067
|
expand: this._parseParam(request.query.expand)
|
|
1007
1068
|
});
|
|
1008
1069
|
if (!result) return response.status(404).send();
|
|
@@ -1010,7 +1071,7 @@ class AbstractService {
|
|
|
1010
1071
|
}
|
|
1011
1072
|
|
|
1012
1073
|
deletewithId(request, response) {
|
|
1013
|
-
const result = this.repository.delete(request
|
|
1074
|
+
const result = this.repository.delete(getRepositoryContext(request), request.params['id'], {
|
|
1014
1075
|
expand: this._parseParam(request.query.expand)
|
|
1015
1076
|
});
|
|
1016
1077
|
|
|
@@ -1027,7 +1088,7 @@ class AbstractService {
|
|
|
1027
1088
|
|
|
1028
1089
|
post(request, response) {
|
|
1029
1090
|
const draft = request.body;
|
|
1030
|
-
const resource = this.repository.create(request
|
|
1091
|
+
const resource = this.repository.create(getRepositoryContext(request), draft);
|
|
1031
1092
|
|
|
1032
1093
|
const result = this._expandWithId(request, resource.id);
|
|
1033
1094
|
|
|
@@ -1036,7 +1097,7 @@ class AbstractService {
|
|
|
1036
1097
|
|
|
1037
1098
|
postWithId(request, response) {
|
|
1038
1099
|
const updateRequest = request.body;
|
|
1039
|
-
const resource = this.repository.get(request
|
|
1100
|
+
const resource = this.repository.get(getRepositoryContext(request), request.params['id']);
|
|
1040
1101
|
|
|
1041
1102
|
if (!resource) {
|
|
1042
1103
|
return response.status(404).send('Not found');
|
|
@@ -1046,7 +1107,7 @@ class AbstractService {
|
|
|
1046
1107
|
return response.status(409).send('Concurrent modification');
|
|
1047
1108
|
}
|
|
1048
1109
|
|
|
1049
|
-
const updatedResource = this.repository.processUpdateActions(request
|
|
1110
|
+
const updatedResource = this.repository.processUpdateActions(getRepositoryContext(request), resource, updateRequest.actions);
|
|
1050
1111
|
|
|
1051
1112
|
const result = this._expandWithId(request, updatedResource.id);
|
|
1052
1113
|
|
|
@@ -1058,7 +1119,7 @@ class AbstractService {
|
|
|
1058
1119
|
}
|
|
1059
1120
|
|
|
1060
1121
|
_expandWithId(request, resourceId) {
|
|
1061
|
-
const result = this.repository.get(request
|
|
1122
|
+
const result = this.repository.get(getRepositoryContext(request), resourceId, {
|
|
1062
1123
|
expand: this._parseParam(request.query.expand)
|
|
1063
1124
|
});
|
|
1064
1125
|
return result;
|
|
@@ -1094,7 +1155,7 @@ class AbstractRepository {
|
|
|
1094
1155
|
this._storage = storage;
|
|
1095
1156
|
}
|
|
1096
1157
|
|
|
1097
|
-
processUpdateActions(
|
|
1158
|
+
processUpdateActions(context, resource, actions) {
|
|
1098
1159
|
// Deep-copy
|
|
1099
1160
|
const modifiedResource = JSON.parse(JSON.stringify(resource));
|
|
1100
1161
|
actions.forEach(action => {
|
|
@@ -1105,11 +1166,11 @@ class AbstractRepository {
|
|
|
1105
1166
|
return;
|
|
1106
1167
|
}
|
|
1107
1168
|
|
|
1108
|
-
updateFunc(
|
|
1169
|
+
updateFunc(context, modifiedResource, action);
|
|
1109
1170
|
});
|
|
1110
1171
|
|
|
1111
1172
|
if (!deepEqual(modifiedResource, resource)) {
|
|
1112
|
-
this.save(
|
|
1173
|
+
this.save(context, modifiedResource);
|
|
1113
1174
|
}
|
|
1114
1175
|
|
|
1115
1176
|
return modifiedResource;
|
|
@@ -1123,8 +1184,8 @@ class AbstractResourceRepository extends AbstractRepository {
|
|
|
1123
1184
|
this._storage.assertStorage(this.getTypeId());
|
|
1124
1185
|
}
|
|
1125
1186
|
|
|
1126
|
-
query(
|
|
1127
|
-
return this._storage.query(projectKey, this.getTypeId(), {
|
|
1187
|
+
query(context, params = {}) {
|
|
1188
|
+
return this._storage.query(context.projectKey, this.getTypeId(), {
|
|
1128
1189
|
expand: params.expand,
|
|
1129
1190
|
where: params.where,
|
|
1130
1191
|
offset: params.offset,
|
|
@@ -1132,20 +1193,20 @@ class AbstractResourceRepository extends AbstractRepository {
|
|
|
1132
1193
|
});
|
|
1133
1194
|
}
|
|
1134
1195
|
|
|
1135
|
-
get(
|
|
1136
|
-
return this._storage.get(projectKey, this.getTypeId(), id, params);
|
|
1196
|
+
get(context, id, params = {}) {
|
|
1197
|
+
return this._storage.get(context.projectKey, this.getTypeId(), id, params);
|
|
1137
1198
|
}
|
|
1138
1199
|
|
|
1139
|
-
getByKey(
|
|
1140
|
-
return this._storage.getByKey(projectKey, this.getTypeId(), key, params);
|
|
1200
|
+
getByKey(context, key, params = {}) {
|
|
1201
|
+
return this._storage.getByKey(context.projectKey, this.getTypeId(), key, params);
|
|
1141
1202
|
}
|
|
1142
1203
|
|
|
1143
|
-
delete(
|
|
1144
|
-
return this._storage.delete(projectKey, this.getTypeId(), id, params);
|
|
1204
|
+
delete(context, id, params = {}) {
|
|
1205
|
+
return this._storage.delete(context.projectKey, this.getTypeId(), id, params);
|
|
1145
1206
|
}
|
|
1146
1207
|
|
|
1147
|
-
save(
|
|
1148
|
-
const current = this.get(
|
|
1208
|
+
save(context, resource) {
|
|
1209
|
+
const current = this.get(context, resource.id);
|
|
1149
1210
|
|
|
1150
1211
|
if (current) {
|
|
1151
1212
|
checkConcurrentModification(current, resource.version);
|
|
@@ -1161,103 +1222,48 @@ class AbstractResourceRepository extends AbstractRepository {
|
|
|
1161
1222
|
|
|
1162
1223
|
resource.version += 1;
|
|
1163
1224
|
|
|
1164
|
-
this._storage.add(projectKey, this.getTypeId(), resource);
|
|
1225
|
+
this._storage.add(context.projectKey, this.getTypeId(), resource);
|
|
1165
1226
|
}
|
|
1166
1227
|
|
|
1167
1228
|
}
|
|
1168
1229
|
|
|
1169
|
-
const createCustomFields = (draft, projectKey, storage) => {
|
|
1170
|
-
if (!draft) return undefined;
|
|
1171
|
-
if (!draft.type) return undefined;
|
|
1172
|
-
if (!draft.type.typeId) return undefined;
|
|
1173
|
-
if (!draft.fields) return undefined;
|
|
1174
|
-
const typeResource = storage.getByResourceIdentifier(projectKey, draft.type);
|
|
1175
|
-
|
|
1176
|
-
if (!typeResource) {
|
|
1177
|
-
throw new Error(`No type '${draft.type.typeId}' with id=${draft.type.id} or key=${draft.type.key}`);
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
return {
|
|
1181
|
-
type: {
|
|
1182
|
-
typeId: draft.type.typeId,
|
|
1183
|
-
id: typeResource.id
|
|
1184
|
-
},
|
|
1185
|
-
fields: draft.fields
|
|
1186
|
-
};
|
|
1187
|
-
};
|
|
1188
|
-
const createPrice = draft => {
|
|
1189
|
-
return {
|
|
1190
|
-
id: v4(),
|
|
1191
|
-
value: createTypedMoney(draft.value)
|
|
1192
|
-
};
|
|
1193
|
-
};
|
|
1194
|
-
const createTypedMoney = value => {
|
|
1195
|
-
return {
|
|
1196
|
-
type: 'centPrecision',
|
|
1197
|
-
fractionDigits: 2,
|
|
1198
|
-
...value
|
|
1199
|
-
};
|
|
1200
|
-
};
|
|
1201
|
-
const resolveStoreReference = (ref, projectKey, storage) => {
|
|
1202
|
-
if (!ref) return undefined;
|
|
1203
|
-
const resource = storage.getByResourceIdentifier(projectKey, ref);
|
|
1204
|
-
|
|
1205
|
-
if (!resource) {
|
|
1206
|
-
throw new Error('No such store');
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
const store = resource;
|
|
1210
|
-
return {
|
|
1211
|
-
typeId: 'store',
|
|
1212
|
-
key: store.key
|
|
1213
|
-
};
|
|
1214
|
-
};
|
|
1215
|
-
const getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storage) => {
|
|
1216
|
-
const resource = storage.getByResourceIdentifier(projectKey, resourceIdentifier);
|
|
1217
|
-
if (!resource) throw new Error(`resource type ${resourceIdentifier.typeId} with id ${resourceIdentifier.id} and key ${resourceIdentifier.key} not found`);
|
|
1218
|
-
return {
|
|
1219
|
-
typeId: resourceIdentifier.typeId,
|
|
1220
|
-
id: resource == null ? void 0 : resource.id
|
|
1221
|
-
};
|
|
1222
|
-
};
|
|
1223
|
-
|
|
1224
1230
|
class CartDiscountRepository extends AbstractResourceRepository {
|
|
1225
1231
|
constructor() {
|
|
1226
1232
|
super(...arguments);
|
|
1227
1233
|
this.actions = {
|
|
1228
|
-
setKey: (
|
|
1234
|
+
setKey: (context, resource, {
|
|
1229
1235
|
key
|
|
1230
1236
|
}) => {
|
|
1231
1237
|
resource.key = key;
|
|
1232
1238
|
},
|
|
1233
|
-
setDescription: (
|
|
1239
|
+
setDescription: (context, resource, {
|
|
1234
1240
|
description
|
|
1235
1241
|
}) => {
|
|
1236
1242
|
resource.description = description;
|
|
1237
1243
|
},
|
|
1238
|
-
setValidFrom: (
|
|
1244
|
+
setValidFrom: (context, resource, {
|
|
1239
1245
|
validFrom
|
|
1240
1246
|
}) => {
|
|
1241
1247
|
resource.validFrom = validFrom;
|
|
1242
1248
|
},
|
|
1243
|
-
setValidUntil: (
|
|
1249
|
+
setValidUntil: (context, resource, {
|
|
1244
1250
|
validUntil
|
|
1245
1251
|
}) => {
|
|
1246
1252
|
resource.validUntil = validUntil;
|
|
1247
1253
|
},
|
|
1248
|
-
setValidFromAndUntil: (
|
|
1254
|
+
setValidFromAndUntil: (context, resource, {
|
|
1249
1255
|
validFrom,
|
|
1250
1256
|
validUntil
|
|
1251
1257
|
}) => {
|
|
1252
1258
|
resource.validFrom = validFrom;
|
|
1253
1259
|
resource.validUntil = validUntil;
|
|
1254
1260
|
},
|
|
1255
|
-
changeSortOrder: (
|
|
1261
|
+
changeSortOrder: (context, resource, {
|
|
1256
1262
|
sortOrder
|
|
1257
1263
|
}) => {
|
|
1258
1264
|
resource.sortOrder = sortOrder;
|
|
1259
1265
|
},
|
|
1260
|
-
changeIsActive: (
|
|
1266
|
+
changeIsActive: (context, resource, {
|
|
1261
1267
|
isActive
|
|
1262
1268
|
}) => {
|
|
1263
1269
|
resource.isActive = isActive;
|
|
@@ -1269,7 +1275,7 @@ class CartDiscountRepository extends AbstractResourceRepository {
|
|
|
1269
1275
|
return 'cart-discount';
|
|
1270
1276
|
}
|
|
1271
1277
|
|
|
1272
|
-
create(
|
|
1278
|
+
create(context, draft) {
|
|
1273
1279
|
const resource = { ...getBaseResourceProperties(),
|
|
1274
1280
|
key: draft.key,
|
|
1275
1281
|
description: draft.description,
|
|
@@ -1285,7 +1291,7 @@ class CartDiscountRepository extends AbstractResourceRepository {
|
|
|
1285
1291
|
validUntil: draft.validUntil,
|
|
1286
1292
|
value: this.transformValueDraft(draft.value)
|
|
1287
1293
|
};
|
|
1288
|
-
this.save(
|
|
1294
|
+
this.save(context, resource);
|
|
1289
1295
|
return resource;
|
|
1290
1296
|
}
|
|
1291
1297
|
|
|
@@ -1341,7 +1347,7 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1341
1347
|
constructor() {
|
|
1342
1348
|
super(...arguments);
|
|
1343
1349
|
this.actions = {
|
|
1344
|
-
addLineItem: (
|
|
1350
|
+
addLineItem: (context, resource, {
|
|
1345
1351
|
productId,
|
|
1346
1352
|
variantId,
|
|
1347
1353
|
sku,
|
|
@@ -1352,10 +1358,10 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1352
1358
|
|
|
1353
1359
|
if (productId && variantId) {
|
|
1354
1360
|
// Fetch product and variant by ID
|
|
1355
|
-
product = this._storage.get(projectKey, 'product', productId, {});
|
|
1361
|
+
product = this._storage.get(context.projectKey, 'product', productId, {});
|
|
1356
1362
|
} else if (sku) {
|
|
1357
1363
|
// Fetch product and variant by SKU
|
|
1358
|
-
const items = this._storage.query(projectKey, 'product', {
|
|
1364
|
+
const items = this._storage.query(context.projectKey, 'product', {
|
|
1359
1365
|
where: [`masterData(current(masterVariant(sku="${sku}"))) or masterData(current(variants(sku="${sku}")))`]
|
|
1360
1366
|
});
|
|
1361
1367
|
|
|
@@ -1416,7 +1422,17 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1416
1422
|
});
|
|
1417
1423
|
}
|
|
1418
1424
|
|
|
1419
|
-
const
|
|
1425
|
+
const currency = resource.totalPrice.currencyCode;
|
|
1426
|
+
const price = selectPrice({
|
|
1427
|
+
prices: variant.prices,
|
|
1428
|
+
currency,
|
|
1429
|
+
country: resource.country
|
|
1430
|
+
});
|
|
1431
|
+
|
|
1432
|
+
if (!price) {
|
|
1433
|
+
throw new Error(`No valid price found for ${productId} for country ${resource.country} and currency ${currency}`);
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1420
1436
|
resource.lineItems.push({
|
|
1421
1437
|
id: v4(),
|
|
1422
1438
|
productId: product.id,
|
|
@@ -1440,7 +1456,7 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1440
1456
|
|
|
1441
1457
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1442
1458
|
},
|
|
1443
|
-
removeLineItem: (
|
|
1459
|
+
removeLineItem: (context, resource, {
|
|
1444
1460
|
lineItemId,
|
|
1445
1461
|
quantity
|
|
1446
1462
|
}) => {
|
|
@@ -1474,15 +1490,15 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1474
1490
|
|
|
1475
1491
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1476
1492
|
},
|
|
1477
|
-
setBillingAddress: (
|
|
1493
|
+
setBillingAddress: (context, resource, {
|
|
1478
1494
|
address
|
|
1479
1495
|
}) => {
|
|
1480
1496
|
resource.billingAddress = address;
|
|
1481
1497
|
},
|
|
1482
|
-
setShippingMethod: (
|
|
1498
|
+
setShippingMethod: (context, resource, {
|
|
1483
1499
|
shippingMethod
|
|
1484
1500
|
}) => {
|
|
1485
|
-
const resolvedType = this._storage.getByResourceIdentifier(projectKey, //@ts-ignore
|
|
1501
|
+
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, //@ts-ignore
|
|
1486
1502
|
shippingMethod);
|
|
1487
1503
|
|
|
1488
1504
|
if (!resolvedType) {
|
|
@@ -1497,17 +1513,17 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1497
1513
|
}
|
|
1498
1514
|
};
|
|
1499
1515
|
},
|
|
1500
|
-
setCountry: (
|
|
1516
|
+
setCountry: (context, resource, {
|
|
1501
1517
|
country
|
|
1502
1518
|
}) => {
|
|
1503
1519
|
resource.country = country;
|
|
1504
1520
|
},
|
|
1505
|
-
setCustomerEmail: (
|
|
1521
|
+
setCustomerEmail: (context, resource, {
|
|
1506
1522
|
email
|
|
1507
1523
|
}) => {
|
|
1508
1524
|
resource.customerEmail = email;
|
|
1509
1525
|
},
|
|
1510
|
-
setCustomField: (
|
|
1526
|
+
setCustomField: (context, resource, {
|
|
1511
1527
|
name,
|
|
1512
1528
|
value
|
|
1513
1529
|
}) => {
|
|
@@ -1517,14 +1533,14 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1517
1533
|
|
|
1518
1534
|
resource.custom.fields[name] = value;
|
|
1519
1535
|
},
|
|
1520
|
-
setCustomType: (
|
|
1536
|
+
setCustomType: (context, resource, {
|
|
1521
1537
|
type,
|
|
1522
1538
|
fields
|
|
1523
1539
|
}) => {
|
|
1524
1540
|
if (!type) {
|
|
1525
1541
|
resource.custom = undefined;
|
|
1526
1542
|
} else {
|
|
1527
|
-
const resolvedType = this._storage.getByResourceIdentifier(projectKey, type);
|
|
1543
|
+
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, type);
|
|
1528
1544
|
|
|
1529
1545
|
if (!resolvedType) {
|
|
1530
1546
|
throw new Error(`Type ${type} not found`);
|
|
@@ -1539,29 +1555,25 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1539
1555
|
};
|
|
1540
1556
|
}
|
|
1541
1557
|
},
|
|
1542
|
-
setLocale: (
|
|
1558
|
+
setLocale: (context, resource, {
|
|
1543
1559
|
locale
|
|
1544
1560
|
}) => {
|
|
1545
1561
|
resource.locale = locale;
|
|
1546
1562
|
},
|
|
1547
|
-
setShippingAddress: (
|
|
1563
|
+
setShippingAddress: (context, resource, {
|
|
1548
1564
|
address
|
|
1549
1565
|
}) => {
|
|
1550
1566
|
resource.shippingAddress = address;
|
|
1551
1567
|
}
|
|
1552
1568
|
};
|
|
1553
1569
|
|
|
1554
|
-
this.draftLineItemtoLineItem = (projectKey, draftLineItem) => {
|
|
1555
|
-
var _variant$prices2;
|
|
1556
|
-
|
|
1570
|
+
this.draftLineItemtoLineItem = (projectKey, draftLineItem, currency, country) => {
|
|
1557
1571
|
const {
|
|
1558
1572
|
productId,
|
|
1559
|
-
quantity
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
let sku = draftLineItem.variant.sku;
|
|
1573
|
+
quantity,
|
|
1574
|
+
variantId,
|
|
1575
|
+
sku
|
|
1576
|
+
} = draftLineItem;
|
|
1565
1577
|
let product = null;
|
|
1566
1578
|
let variant;
|
|
1567
1579
|
|
|
@@ -1599,11 +1611,15 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1599
1611
|
throw new Error(sku ? `A variant with SKU '${sku}' for product '${product.id}' not found.` : `A variant with ID '${variantId}' for product '${product.id}' not found.`);
|
|
1600
1612
|
}
|
|
1601
1613
|
|
|
1602
|
-
const price = (_variant$prices2 = variant.prices) == null ? void 0 : _variant$prices2[0];
|
|
1603
1614
|
const quant = quantity != null ? quantity : 1;
|
|
1615
|
+
const price = selectPrice({
|
|
1616
|
+
prices: variant.prices,
|
|
1617
|
+
currency,
|
|
1618
|
+
country
|
|
1619
|
+
});
|
|
1604
1620
|
|
|
1605
1621
|
if (!price) {
|
|
1606
|
-
throw new Error(`
|
|
1622
|
+
throw new Error(`No valid price found for ${productId} for country ${country} and currency ${currency}`);
|
|
1607
1623
|
}
|
|
1608
1624
|
|
|
1609
1625
|
return {
|
|
@@ -1631,13 +1647,13 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1631
1647
|
return 'cart';
|
|
1632
1648
|
}
|
|
1633
1649
|
|
|
1634
|
-
create(
|
|
1635
|
-
var _draft$lineItems;
|
|
1650
|
+
create(context, draft) {
|
|
1651
|
+
var _draft$lineItems$map, _draft$lineItems, _draft$taxMode, _draft$taxRoundingMod, _draft$taxCalculation, _draft$origin;
|
|
1636
1652
|
|
|
1637
|
-
const lineItems = (_draft$lineItems = draft.lineItems) == null ? void 0 : _draft$lineItems.map(draftLineItem => this.draftLineItemtoLineItem(projectKey, draftLineItem));
|
|
1653
|
+
const lineItems = (_draft$lineItems$map = (_draft$lineItems = draft.lineItems) == null ? void 0 : _draft$lineItems.map(draftLineItem => this.draftLineItemtoLineItem(context.projectKey, draftLineItem, draft.currency, draft.country))) != null ? _draft$lineItems$map : [];
|
|
1638
1654
|
const resource = { ...getBaseResourceProperties(),
|
|
1639
1655
|
cartState: 'Active',
|
|
1640
|
-
lineItems
|
|
1656
|
+
lineItems,
|
|
1641
1657
|
customLineItems: [],
|
|
1642
1658
|
totalPrice: {
|
|
1643
1659
|
type: 'centPrecision',
|
|
@@ -1645,16 +1661,18 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1645
1661
|
currencyCode: draft.currency,
|
|
1646
1662
|
fractionDigits: 0
|
|
1647
1663
|
},
|
|
1648
|
-
taxMode: 'Platform',
|
|
1649
|
-
taxRoundingMode: 'HalfEven',
|
|
1650
|
-
taxCalculationMode: 'LineItemLevel',
|
|
1664
|
+
taxMode: (_draft$taxMode = draft.taxMode) != null ? _draft$taxMode : 'Platform',
|
|
1665
|
+
taxRoundingMode: (_draft$taxRoundingMod = draft.taxRoundingMode) != null ? _draft$taxRoundingMod : 'HalfEven',
|
|
1666
|
+
taxCalculationMode: (_draft$taxCalculation = draft.taxCalculationMode) != null ? _draft$taxCalculation : 'LineItemLevel',
|
|
1651
1667
|
refusedGifts: [],
|
|
1652
|
-
|
|
1653
|
-
|
|
1668
|
+
locale: draft.locale,
|
|
1669
|
+
country: draft.country,
|
|
1670
|
+
origin: (_draft$origin = draft.origin) != null ? _draft$origin : 'Customer',
|
|
1671
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
1654
1672
|
}; // @ts-ignore
|
|
1655
1673
|
|
|
1656
1674
|
resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
|
|
1657
|
-
this.save(
|
|
1675
|
+
this.save(context, resource);
|
|
1658
1676
|
return resource;
|
|
1659
1677
|
}
|
|
1660
1678
|
|
|
@@ -1673,6 +1691,25 @@ class CartRepository extends AbstractResourceRepository {
|
|
|
1673
1691
|
|
|
1674
1692
|
}
|
|
1675
1693
|
|
|
1694
|
+
const selectPrice = ({
|
|
1695
|
+
prices,
|
|
1696
|
+
currency,
|
|
1697
|
+
country
|
|
1698
|
+
}) => {
|
|
1699
|
+
if (!prices) {
|
|
1700
|
+
return undefined;
|
|
1701
|
+
} // Quick-and-dirty way of selecting price based on the given currency and country.
|
|
1702
|
+
// Can be improved later to give more priority to exact matches over
|
|
1703
|
+
// 'all country' matches, and include customer groups in the mix as well
|
|
1704
|
+
|
|
1705
|
+
|
|
1706
|
+
return prices.find(price => {
|
|
1707
|
+
const countryMatch = !price.country || price.country === country;
|
|
1708
|
+
const currencyMatch = price.value.currencyCode === currency;
|
|
1709
|
+
return countryMatch && currencyMatch;
|
|
1710
|
+
});
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1676
1713
|
const calculateLineItemTotalPrice = lineItem => lineItem.price.value.centAmount * lineItem.quantity;
|
|
1677
1714
|
|
|
1678
1715
|
const calculateCartTotalPrice = cart => cart.lineItems.reduce((cur, item) => cur + item.totalPrice.centAmount, 0);
|
|
@@ -1681,10 +1718,10 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1681
1718
|
constructor() {
|
|
1682
1719
|
super(...arguments);
|
|
1683
1720
|
this.actions = {
|
|
1684
|
-
addPayment: (
|
|
1721
|
+
addPayment: (context, resource, {
|
|
1685
1722
|
payment
|
|
1686
1723
|
}) => {
|
|
1687
|
-
const resolvedPayment = this._storage.getByResourceIdentifier(projectKey, payment);
|
|
1724
|
+
const resolvedPayment = this._storage.getByResourceIdentifier(context.projectKey, payment);
|
|
1688
1725
|
|
|
1689
1726
|
if (!resolvedPayment) {
|
|
1690
1727
|
throw new Error(`Payment ${payment.id} not found`);
|
|
@@ -1701,20 +1738,20 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1701
1738
|
id: payment.id
|
|
1702
1739
|
});
|
|
1703
1740
|
},
|
|
1704
|
-
changeOrderState: (
|
|
1741
|
+
changeOrderState: (context, resource, {
|
|
1705
1742
|
orderState
|
|
1706
1743
|
}) => {
|
|
1707
1744
|
resource.orderState = orderState;
|
|
1708
1745
|
},
|
|
1709
|
-
changePaymentState: (
|
|
1746
|
+
changePaymentState: (context, resource, {
|
|
1710
1747
|
paymentState
|
|
1711
1748
|
}) => {
|
|
1712
1749
|
resource.paymentState = paymentState;
|
|
1713
1750
|
},
|
|
1714
|
-
transitionState: (
|
|
1751
|
+
transitionState: (context, resource, {
|
|
1715
1752
|
state
|
|
1716
1753
|
}) => {
|
|
1717
|
-
const resolvedType = this._storage.getByResourceIdentifier(projectKey, state);
|
|
1754
|
+
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, state);
|
|
1718
1755
|
|
|
1719
1756
|
if (!resolvedType) {
|
|
1720
1757
|
throw new Error(`No state found with key=${state.key} or id=${state.key}`);
|
|
@@ -1725,17 +1762,17 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1725
1762
|
id: resolvedType.id
|
|
1726
1763
|
};
|
|
1727
1764
|
},
|
|
1728
|
-
setBillingAddress: (
|
|
1765
|
+
setBillingAddress: (context, resource, {
|
|
1729
1766
|
address
|
|
1730
1767
|
}) => {
|
|
1731
1768
|
resource.billingAddress = address;
|
|
1732
1769
|
},
|
|
1733
|
-
setCustomerEmail: (
|
|
1770
|
+
setCustomerEmail: (context, resource, {
|
|
1734
1771
|
email
|
|
1735
1772
|
}) => {
|
|
1736
1773
|
resource.customerEmail = email;
|
|
1737
1774
|
},
|
|
1738
|
-
setCustomField: (
|
|
1775
|
+
setCustomField: (context, resource, {
|
|
1739
1776
|
name,
|
|
1740
1777
|
value
|
|
1741
1778
|
}) => {
|
|
@@ -1745,14 +1782,14 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1745
1782
|
|
|
1746
1783
|
resource.custom.fields[name] = value;
|
|
1747
1784
|
},
|
|
1748
|
-
setCustomType: (
|
|
1785
|
+
setCustomType: (context, resource, {
|
|
1749
1786
|
type,
|
|
1750
1787
|
fields
|
|
1751
1788
|
}) => {
|
|
1752
1789
|
if (!type) {
|
|
1753
1790
|
resource.custom = undefined;
|
|
1754
1791
|
} else {
|
|
1755
|
-
const resolvedType = this._storage.getByResourceIdentifier(projectKey, type);
|
|
1792
|
+
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, type);
|
|
1756
1793
|
|
|
1757
1794
|
if (!resolvedType) {
|
|
1758
1795
|
throw new Error(`Type ${type} not found`);
|
|
@@ -1767,27 +1804,27 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1767
1804
|
};
|
|
1768
1805
|
}
|
|
1769
1806
|
},
|
|
1770
|
-
setLocale: (
|
|
1807
|
+
setLocale: (context, resource, {
|
|
1771
1808
|
locale
|
|
1772
1809
|
}) => {
|
|
1773
1810
|
resource.locale = locale;
|
|
1774
1811
|
},
|
|
1775
|
-
setOrderNumber: (
|
|
1812
|
+
setOrderNumber: (context, resource, {
|
|
1776
1813
|
orderNumber
|
|
1777
1814
|
}) => {
|
|
1778
1815
|
resource.orderNumber = orderNumber;
|
|
1779
1816
|
},
|
|
1780
|
-
setShippingAddress: (
|
|
1817
|
+
setShippingAddress: (context, resource, {
|
|
1781
1818
|
address
|
|
1782
1819
|
}) => {
|
|
1783
1820
|
resource.shippingAddress = address;
|
|
1784
1821
|
},
|
|
1785
|
-
setStore: (
|
|
1822
|
+
setStore: (context, resource, {
|
|
1786
1823
|
store
|
|
1787
1824
|
}) => {
|
|
1788
1825
|
if (!store) return;
|
|
1789
1826
|
|
|
1790
|
-
const resolvedType = this._storage.getByResourceIdentifier(projectKey, store);
|
|
1827
|
+
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, store);
|
|
1791
1828
|
|
|
1792
1829
|
if (!resolvedType) {
|
|
1793
1830
|
throw new Error(`No store found with key=${store.key}`);
|
|
@@ -1806,17 +1843,24 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1806
1843
|
return 'order';
|
|
1807
1844
|
}
|
|
1808
1845
|
|
|
1809
|
-
create(
|
|
1846
|
+
create(context, draft) {
|
|
1810
1847
|
assert(draft.cart, 'draft.cart is missing');
|
|
1848
|
+
return this.createFromCart(context, {
|
|
1849
|
+
id: draft.cart.id,
|
|
1850
|
+
typeId: 'cart'
|
|
1851
|
+
}, draft.orderNumber);
|
|
1852
|
+
}
|
|
1811
1853
|
|
|
1812
|
-
|
|
1854
|
+
createFromCart(context, cartReference, orderNumber) {
|
|
1855
|
+
const cart = this._storage.getByResourceIdentifier(context.projectKey, cartReference);
|
|
1813
1856
|
|
|
1814
1857
|
if (!cart) {
|
|
1815
1858
|
throw new Error('Cannot find cart');
|
|
1816
1859
|
}
|
|
1817
1860
|
|
|
1818
1861
|
const resource = { ...getBaseResourceProperties(),
|
|
1819
|
-
orderNumber
|
|
1862
|
+
orderNumber,
|
|
1863
|
+
cart: cartReference,
|
|
1820
1864
|
orderState: 'Open',
|
|
1821
1865
|
lineItems: [],
|
|
1822
1866
|
customLineItems: [],
|
|
@@ -1824,13 +1868,17 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1824
1868
|
refusedGifts: [],
|
|
1825
1869
|
origin: 'Customer',
|
|
1826
1870
|
syncInfo: [],
|
|
1871
|
+
store: context.storeKey ? {
|
|
1872
|
+
key: context.storeKey,
|
|
1873
|
+
typeId: 'store'
|
|
1874
|
+
} : undefined,
|
|
1827
1875
|
lastMessageSequenceNumber: 0
|
|
1828
1876
|
};
|
|
1829
|
-
this.save(
|
|
1877
|
+
this.save(context, resource);
|
|
1830
1878
|
return resource;
|
|
1831
1879
|
}
|
|
1832
1880
|
|
|
1833
|
-
import(
|
|
1881
|
+
import(context, draft) {
|
|
1834
1882
|
var _draft$lineItems, _draft$customLineItem;
|
|
1835
1883
|
|
|
1836
1884
|
// TODO: Check if order with given orderNumber already exists
|
|
@@ -1838,7 +1886,7 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1838
1886
|
const resource = { ...getBaseResourceProperties(),
|
|
1839
1887
|
billingAddress: draft.billingAddress,
|
|
1840
1888
|
shippingAddress: draft.shippingAddress,
|
|
1841
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage),
|
|
1889
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
1842
1890
|
customerEmail: draft.customerEmail,
|
|
1843
1891
|
lastMessageSequenceNumber: 0,
|
|
1844
1892
|
orderNumber: draft.orderNumber,
|
|
@@ -1846,21 +1894,21 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1846
1894
|
origin: draft.origin || 'Customer',
|
|
1847
1895
|
paymentState: draft.paymentState,
|
|
1848
1896
|
refusedGifts: [],
|
|
1849
|
-
store: resolveStoreReference(draft.store, projectKey, this._storage),
|
|
1897
|
+
store: resolveStoreReference(draft.store, context.projectKey, this._storage),
|
|
1850
1898
|
syncInfo: [],
|
|
1851
|
-
lineItems: ((_draft$lineItems = draft.lineItems) == null ? void 0 : _draft$lineItems.map(item => this.lineItemFromImportDraft.bind(this)(
|
|
1852
|
-
customLineItems: ((_draft$customLineItem = draft.customLineItems) == null ? void 0 : _draft$customLineItem.map(item => this.customLineItemFromImportDraft.bind(this)(
|
|
1899
|
+
lineItems: ((_draft$lineItems = draft.lineItems) == null ? void 0 : _draft$lineItems.map(item => this.lineItemFromImportDraft.bind(this)(context, item))) || [],
|
|
1900
|
+
customLineItems: ((_draft$customLineItem = draft.customLineItems) == null ? void 0 : _draft$customLineItem.map(item => this.customLineItemFromImportDraft.bind(this)(context, item))) || [],
|
|
1853
1901
|
totalPrice: {
|
|
1854
1902
|
type: 'centPrecision',
|
|
1855
1903
|
...draft.totalPrice,
|
|
1856
1904
|
fractionDigits: 2
|
|
1857
1905
|
}
|
|
1858
1906
|
};
|
|
1859
|
-
this.save(
|
|
1907
|
+
this.save(context, resource);
|
|
1860
1908
|
return resource;
|
|
1861
1909
|
}
|
|
1862
1910
|
|
|
1863
|
-
lineItemFromImportDraft(
|
|
1911
|
+
lineItemFromImportDraft(context, draft) {
|
|
1864
1912
|
let product;
|
|
1865
1913
|
let variant;
|
|
1866
1914
|
|
|
@@ -1870,7 +1918,7 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1870
1918
|
sku: draft.variant.sku
|
|
1871
1919
|
};
|
|
1872
1920
|
|
|
1873
|
-
var items = this._storage.query(projectKey, 'product', {
|
|
1921
|
+
var items = this._storage.query(context.projectKey, 'product', {
|
|
1874
1922
|
where: [`masterData(current(masterVariant(sku="${draft.variant.sku}"))) or masterData(current(variants(sku="${draft.variant.sku}")))`]
|
|
1875
1923
|
});
|
|
1876
1924
|
|
|
@@ -1897,7 +1945,7 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1897
1945
|
}
|
|
1898
1946
|
|
|
1899
1947
|
const lineItem = { ...getBaseResourceProperties(),
|
|
1900
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage),
|
|
1948
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
1901
1949
|
discountedPricePerQuantity: [],
|
|
1902
1950
|
lineItemMode: 'Standard',
|
|
1903
1951
|
name: draft.name,
|
|
@@ -1918,9 +1966,9 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1918
1966
|
return lineItem;
|
|
1919
1967
|
}
|
|
1920
1968
|
|
|
1921
|
-
customLineItemFromImportDraft(
|
|
1969
|
+
customLineItemFromImportDraft(context, draft) {
|
|
1922
1970
|
const lineItem = { ...getBaseResourceProperties(),
|
|
1923
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage),
|
|
1971
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
1924
1972
|
discountedPricePerQuantity: [],
|
|
1925
1973
|
money: createTypedMoney(draft.money),
|
|
1926
1974
|
name: draft.name,
|
|
@@ -1932,8 +1980,8 @@ class OrderRepository extends AbstractResourceRepository {
|
|
|
1932
1980
|
return lineItem;
|
|
1933
1981
|
}
|
|
1934
1982
|
|
|
1935
|
-
getWithOrderNumber(
|
|
1936
|
-
const result = this._storage.query(projectKey, this.getTypeId(), { ...params,
|
|
1983
|
+
getWithOrderNumber(context, orderNumber, params = {}) {
|
|
1984
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), { ...params,
|
|
1937
1985
|
where: [`orderNumber="${orderNumber}"`]
|
|
1938
1986
|
});
|
|
1939
1987
|
|
|
@@ -1964,17 +2012,25 @@ class CartService extends AbstractService {
|
|
|
1964
2012
|
|
|
1965
2013
|
extraRoutes(parent) {
|
|
1966
2014
|
parent.post('/replicate', (request, response) => {
|
|
1967
|
-
// @ts-ignore
|
|
1968
|
-
|
|
2015
|
+
const context = getRepositoryContext(request); // @ts-ignore
|
|
2016
|
+
|
|
2017
|
+
const cartOrOrder = request.body.reference.typeId === 'order' ? this.orderRepository.get(context, request.body.reference.id) : this.repository.get(context, request.body.reference.id);
|
|
1969
2018
|
|
|
1970
2019
|
if (!cartOrOrder) {
|
|
1971
2020
|
return response.status(400).send();
|
|
1972
2021
|
}
|
|
1973
2022
|
|
|
1974
|
-
const
|
|
2023
|
+
const cartDraft = { ...cartOrOrder,
|
|
1975
2024
|
currency: cartOrOrder.totalPrice.currencyCode,
|
|
1976
|
-
discountCodes: []
|
|
1977
|
-
|
|
2025
|
+
discountCodes: [],
|
|
2026
|
+
lineItems: cartOrOrder.lineItems.map(lineItem => {
|
|
2027
|
+
return { ...lineItem,
|
|
2028
|
+
variantId: lineItem.variant.id,
|
|
2029
|
+
sku: lineItem.variant.sku
|
|
2030
|
+
};
|
|
2031
|
+
})
|
|
2032
|
+
};
|
|
2033
|
+
const newCart = this.repository.create(context, cartDraft);
|
|
1978
2034
|
return response.status(200).send(newCart);
|
|
1979
2035
|
});
|
|
1980
2036
|
}
|
|
@@ -1985,7 +2041,7 @@ class CategoryRepository extends AbstractResourceRepository {
|
|
|
1985
2041
|
constructor() {
|
|
1986
2042
|
super(...arguments);
|
|
1987
2043
|
this.actions = {
|
|
1988
|
-
changeAssetName: (
|
|
2044
|
+
changeAssetName: (context, resource, {
|
|
1989
2045
|
assetId,
|
|
1990
2046
|
assetKey,
|
|
1991
2047
|
name
|
|
@@ -2002,17 +2058,17 @@ class CategoryRepository extends AbstractResourceRepository {
|
|
|
2002
2058
|
}
|
|
2003
2059
|
});
|
|
2004
2060
|
},
|
|
2005
|
-
changeSlug: (
|
|
2061
|
+
changeSlug: (context, resource, {
|
|
2006
2062
|
slug
|
|
2007
2063
|
}) => {
|
|
2008
2064
|
resource.slug = slug;
|
|
2009
2065
|
},
|
|
2010
|
-
setKey: (
|
|
2066
|
+
setKey: (context, resource, {
|
|
2011
2067
|
key
|
|
2012
2068
|
}) => {
|
|
2013
2069
|
resource.key = key;
|
|
2014
2070
|
},
|
|
2015
|
-
setAssetDescription: (
|
|
2071
|
+
setAssetDescription: (context, resource, {
|
|
2016
2072
|
assetId,
|
|
2017
2073
|
assetKey,
|
|
2018
2074
|
description
|
|
@@ -2029,7 +2085,7 @@ class CategoryRepository extends AbstractResourceRepository {
|
|
|
2029
2085
|
}
|
|
2030
2086
|
});
|
|
2031
2087
|
},
|
|
2032
|
-
setAssetSources: (
|
|
2088
|
+
setAssetSources: (context, resource, {
|
|
2033
2089
|
assetId,
|
|
2034
2090
|
assetKey,
|
|
2035
2091
|
sources
|
|
@@ -2046,22 +2102,22 @@ class CategoryRepository extends AbstractResourceRepository {
|
|
|
2046
2102
|
}
|
|
2047
2103
|
});
|
|
2048
2104
|
},
|
|
2049
|
-
setDescription: (
|
|
2105
|
+
setDescription: (context, resource, {
|
|
2050
2106
|
description
|
|
2051
2107
|
}) => {
|
|
2052
2108
|
resource.description = description;
|
|
2053
2109
|
},
|
|
2054
|
-
setMetaDescription: (
|
|
2110
|
+
setMetaDescription: (context, resource, {
|
|
2055
2111
|
metaDescription
|
|
2056
2112
|
}) => {
|
|
2057
2113
|
resource.metaDescription = metaDescription;
|
|
2058
2114
|
},
|
|
2059
|
-
setMetaKeywords: (
|
|
2115
|
+
setMetaKeywords: (context, resource, {
|
|
2060
2116
|
metaKeywords
|
|
2061
2117
|
}) => {
|
|
2062
2118
|
resource.metaKeywords = metaKeywords;
|
|
2063
2119
|
},
|
|
2064
|
-
setMetaTitle: (
|
|
2120
|
+
setMetaTitle: (context, resource, {
|
|
2065
2121
|
metaTitle
|
|
2066
2122
|
}) => {
|
|
2067
2123
|
resource.metaTitle = metaTitle;
|
|
@@ -2073,7 +2129,7 @@ class CategoryRepository extends AbstractResourceRepository {
|
|
|
2073
2129
|
return 'category';
|
|
2074
2130
|
}
|
|
2075
2131
|
|
|
2076
|
-
create(
|
|
2132
|
+
create(context, draft) {
|
|
2077
2133
|
var _draft$assets;
|
|
2078
2134
|
|
|
2079
2135
|
const resource = { ...getBaseResourceProperties(),
|
|
@@ -2095,11 +2151,11 @@ class CategoryRepository extends AbstractResourceRepository {
|
|
|
2095
2151
|
sources: d.sources,
|
|
2096
2152
|
tags: d.tags,
|
|
2097
2153
|
key: d.key,
|
|
2098
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage)
|
|
2154
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
2099
2155
|
};
|
|
2100
2156
|
})) || []
|
|
2101
2157
|
};
|
|
2102
|
-
this.save(
|
|
2158
|
+
this.save(context, resource);
|
|
2103
2159
|
return resource;
|
|
2104
2160
|
}
|
|
2105
2161
|
|
|
@@ -2122,12 +2178,12 @@ class ChannelRepository extends AbstractResourceRepository {
|
|
|
2122
2178
|
return 'channel';
|
|
2123
2179
|
}
|
|
2124
2180
|
|
|
2125
|
-
create(
|
|
2181
|
+
create(context, draft) {
|
|
2126
2182
|
const resource = { ...getBaseResourceProperties(),
|
|
2127
2183
|
key: draft.key,
|
|
2128
2184
|
roles: draft.roles || []
|
|
2129
2185
|
};
|
|
2130
|
-
this.save(
|
|
2186
|
+
this.save(context, resource);
|
|
2131
2187
|
return resource;
|
|
2132
2188
|
}
|
|
2133
2189
|
|
|
@@ -2149,12 +2205,12 @@ class CustomerGroupRepository extends AbstractResourceRepository {
|
|
|
2149
2205
|
constructor() {
|
|
2150
2206
|
super(...arguments);
|
|
2151
2207
|
this.actions = {
|
|
2152
|
-
setKey: (
|
|
2208
|
+
setKey: (context, resource, {
|
|
2153
2209
|
key
|
|
2154
2210
|
}) => {
|
|
2155
2211
|
resource.key = key;
|
|
2156
2212
|
},
|
|
2157
|
-
changeName: (
|
|
2213
|
+
changeName: (context, resource, {
|
|
2158
2214
|
name
|
|
2159
2215
|
}) => {
|
|
2160
2216
|
resource.name = name;
|
|
@@ -2166,12 +2222,12 @@ class CustomerGroupRepository extends AbstractResourceRepository {
|
|
|
2166
2222
|
return 'customer';
|
|
2167
2223
|
}
|
|
2168
2224
|
|
|
2169
|
-
create(
|
|
2225
|
+
create(context, draft) {
|
|
2170
2226
|
const resource = { ...getBaseResourceProperties(),
|
|
2171
2227
|
key: draft.key,
|
|
2172
2228
|
name: draft.groupName
|
|
2173
2229
|
};
|
|
2174
|
-
this.save(
|
|
2230
|
+
this.save(context, resource);
|
|
2175
2231
|
return resource;
|
|
2176
2232
|
}
|
|
2177
2233
|
|
|
@@ -2193,7 +2249,7 @@ class CustomerRepository extends AbstractResourceRepository {
|
|
|
2193
2249
|
constructor() {
|
|
2194
2250
|
super(...arguments);
|
|
2195
2251
|
this.actions = {
|
|
2196
|
-
changeEmail: (
|
|
2252
|
+
changeEmail: (_context, resource, {
|
|
2197
2253
|
email
|
|
2198
2254
|
}) => {
|
|
2199
2255
|
resource.email = email;
|
|
@@ -2205,19 +2261,19 @@ class CustomerRepository extends AbstractResourceRepository {
|
|
|
2205
2261
|
return 'customer';
|
|
2206
2262
|
}
|
|
2207
2263
|
|
|
2208
|
-
create(
|
|
2264
|
+
create(context, draft) {
|
|
2209
2265
|
const resource = { ...getBaseResourceProperties(),
|
|
2210
2266
|
email: draft.email,
|
|
2211
2267
|
password: draft.password ? Buffer.from(draft.password).toString('base64') : undefined,
|
|
2212
2268
|
isEmailVerified: draft.isEmailVerified || false,
|
|
2213
2269
|
addresses: []
|
|
2214
2270
|
};
|
|
2215
|
-
this.save(
|
|
2271
|
+
this.save(context, resource);
|
|
2216
2272
|
return resource;
|
|
2217
2273
|
}
|
|
2218
2274
|
|
|
2219
|
-
getMe(
|
|
2220
|
-
const results = this._storage.query(projectKey, this.getTypeId(), {}); // grab the first customer you can find
|
|
2275
|
+
getMe(context) {
|
|
2276
|
+
const results = this._storage.query(context.projectKey, this.getTypeId(), {}); // grab the first customer you can find
|
|
2221
2277
|
|
|
2222
2278
|
|
|
2223
2279
|
if (results.count > 0) {
|
|
@@ -2241,10 +2297,12 @@ class CustomerService extends AbstractService {
|
|
|
2241
2297
|
|
|
2242
2298
|
extraRoutes(parent) {
|
|
2243
2299
|
parent.post('/password-token', (request, response) => {
|
|
2244
|
-
const customer = this.repository.query(request
|
|
2300
|
+
const customer = this.repository.query(getRepositoryContext(request), {
|
|
2245
2301
|
where: [`email="${request.body.email}"`]
|
|
2246
|
-
});
|
|
2247
|
-
|
|
2302
|
+
}); // @ts-ignore
|
|
2303
|
+
|
|
2304
|
+
const ttlMinutes = request.params.ttlMinutes ? // @ts-ignore
|
|
2305
|
+
+request.params.ttlMinutes : 34560;
|
|
2248
2306
|
const {
|
|
2249
2307
|
version,
|
|
2250
2308
|
...rest
|
|
@@ -2264,8 +2322,8 @@ class CustomObjectRepository extends AbstractResourceRepository {
|
|
|
2264
2322
|
return 'key-value-document';
|
|
2265
2323
|
}
|
|
2266
2324
|
|
|
2267
|
-
create(
|
|
2268
|
-
const current = this.getWithContainerAndKey(
|
|
2325
|
+
create(context, draft) {
|
|
2326
|
+
const current = this.getWithContainerAndKey(context, draft.container, draft.key);
|
|
2269
2327
|
const baseProperties = getBaseResourceProperties();
|
|
2270
2328
|
|
|
2271
2329
|
if (current) {
|
|
@@ -2293,12 +2351,12 @@ class CustomObjectRepository extends AbstractResourceRepository {
|
|
|
2293
2351
|
key: draft.key,
|
|
2294
2352
|
value: draft.value
|
|
2295
2353
|
};
|
|
2296
|
-
this.save(
|
|
2354
|
+
this.save(context, resource);
|
|
2297
2355
|
return resource;
|
|
2298
2356
|
}
|
|
2299
2357
|
|
|
2300
|
-
getWithContainerAndKey(
|
|
2301
|
-
const items = this._storage.all(projectKey, this.getTypeId());
|
|
2358
|
+
getWithContainerAndKey(context, container, key) {
|
|
2359
|
+
const items = this._storage.all(context.projectKey, this.getTypeId());
|
|
2302
2360
|
|
|
2303
2361
|
return items.find(item => item.container === container && item.key === key);
|
|
2304
2362
|
}
|
|
@@ -2322,7 +2380,7 @@ class CustomObjectService extends AbstractService {
|
|
|
2322
2380
|
}
|
|
2323
2381
|
|
|
2324
2382
|
getWithContainerAndKey(request, response) {
|
|
2325
|
-
const result = this.repository.getWithContainerAndKey(request
|
|
2383
|
+
const result = this.repository.getWithContainerAndKey(getRepositoryContext(request), request.params.container, request.params.key);
|
|
2326
2384
|
|
|
2327
2385
|
if (!result) {
|
|
2328
2386
|
return response.status(404).send('Not Found');
|
|
@@ -2336,18 +2394,18 @@ class CustomObjectService extends AbstractService {
|
|
|
2336
2394
|
key: request.params.key,
|
|
2337
2395
|
container: request.params.container
|
|
2338
2396
|
};
|
|
2339
|
-
const result = this.repository.create(request
|
|
2397
|
+
const result = this.repository.create(getRepositoryContext(request), draft);
|
|
2340
2398
|
return response.status(200).send(result);
|
|
2341
2399
|
}
|
|
2342
2400
|
|
|
2343
2401
|
deleteWithContainerAndKey(request, response) {
|
|
2344
|
-
const current = this.repository.getWithContainerAndKey(request
|
|
2402
|
+
const current = this.repository.getWithContainerAndKey(getRepositoryContext(request), request.params.container, request.params.key);
|
|
2345
2403
|
|
|
2346
2404
|
if (!current) {
|
|
2347
2405
|
return response.status(404).send('Not Found');
|
|
2348
2406
|
}
|
|
2349
2407
|
|
|
2350
|
-
const result = this.repository.delete(request
|
|
2408
|
+
const result = this.repository.delete(getRepositoryContext(request), current.id);
|
|
2351
2409
|
return response.status(200).send(result);
|
|
2352
2410
|
}
|
|
2353
2411
|
|
|
@@ -2357,12 +2415,12 @@ class DiscountCodeRepository extends AbstractResourceRepository {
|
|
|
2357
2415
|
constructor() {
|
|
2358
2416
|
super(...arguments);
|
|
2359
2417
|
this.actions = {
|
|
2360
|
-
changeIsActive: (
|
|
2418
|
+
changeIsActive: (context, resource, {
|
|
2361
2419
|
isActive
|
|
2362
2420
|
}) => {
|
|
2363
2421
|
resource.isActive = isActive;
|
|
2364
2422
|
},
|
|
2365
|
-
changeCartDiscounts: (
|
|
2423
|
+
changeCartDiscounts: (context, resource, {
|
|
2366
2424
|
cartDiscounts
|
|
2367
2425
|
}) => {
|
|
2368
2426
|
resource.cartDiscounts = cartDiscounts.map(obj => ({
|
|
@@ -2370,42 +2428,42 @@ class DiscountCodeRepository extends AbstractResourceRepository {
|
|
|
2370
2428
|
id: obj.id
|
|
2371
2429
|
}));
|
|
2372
2430
|
},
|
|
2373
|
-
setDescription: (
|
|
2431
|
+
setDescription: (context, resource, {
|
|
2374
2432
|
description
|
|
2375
2433
|
}) => {
|
|
2376
2434
|
resource.description = description;
|
|
2377
2435
|
},
|
|
2378
|
-
setCartPredicate: (
|
|
2436
|
+
setCartPredicate: (context, resource, {
|
|
2379
2437
|
cartPredicate
|
|
2380
2438
|
}) => {
|
|
2381
2439
|
resource.cartPredicate = cartPredicate;
|
|
2382
2440
|
},
|
|
2383
|
-
setName: (
|
|
2441
|
+
setName: (context, resource, {
|
|
2384
2442
|
name
|
|
2385
2443
|
}) => {
|
|
2386
2444
|
resource.name = name;
|
|
2387
2445
|
},
|
|
2388
|
-
setMaxApplications: (
|
|
2446
|
+
setMaxApplications: (context, resource, {
|
|
2389
2447
|
maxApplications
|
|
2390
2448
|
}) => {
|
|
2391
2449
|
resource.maxApplications = maxApplications;
|
|
2392
2450
|
},
|
|
2393
|
-
setMaxApplicationsPerCustomer: (
|
|
2451
|
+
setMaxApplicationsPerCustomer: (context, resource, {
|
|
2394
2452
|
maxApplicationsPerCustomer
|
|
2395
2453
|
}) => {
|
|
2396
2454
|
resource.maxApplicationsPerCustomer = maxApplicationsPerCustomer;
|
|
2397
2455
|
},
|
|
2398
|
-
setValidFrom: (
|
|
2456
|
+
setValidFrom: (context, resource, {
|
|
2399
2457
|
validFrom
|
|
2400
2458
|
}) => {
|
|
2401
2459
|
resource.validFrom = validFrom;
|
|
2402
2460
|
},
|
|
2403
|
-
setValidUntil: (
|
|
2461
|
+
setValidUntil: (context, resource, {
|
|
2404
2462
|
validUntil
|
|
2405
2463
|
}) => {
|
|
2406
2464
|
resource.validUntil = validUntil;
|
|
2407
2465
|
},
|
|
2408
|
-
setValidFromAndUntil: (
|
|
2466
|
+
setValidFromAndUntil: (context, resource, {
|
|
2409
2467
|
validFrom,
|
|
2410
2468
|
validUntil
|
|
2411
2469
|
}) => {
|
|
@@ -2419,7 +2477,7 @@ class DiscountCodeRepository extends AbstractResourceRepository {
|
|
|
2419
2477
|
return 'cart-discount';
|
|
2420
2478
|
}
|
|
2421
2479
|
|
|
2422
|
-
create(
|
|
2480
|
+
create(context, draft) {
|
|
2423
2481
|
const resource = { ...getBaseResourceProperties(),
|
|
2424
2482
|
applicationVersion: 1,
|
|
2425
2483
|
cartDiscounts: draft.cartDiscounts.map(obj => ({
|
|
@@ -2438,7 +2496,7 @@ class DiscountCodeRepository extends AbstractResourceRepository {
|
|
|
2438
2496
|
maxApplications: draft.maxApplications,
|
|
2439
2497
|
maxApplicationsPerCustomer: draft.maxApplicationsPerCustomer
|
|
2440
2498
|
};
|
|
2441
|
-
this.save(
|
|
2499
|
+
this.save(context, resource);
|
|
2442
2500
|
return resource;
|
|
2443
2501
|
}
|
|
2444
2502
|
|
|
@@ -2460,22 +2518,22 @@ class ExtensionRepository extends AbstractResourceRepository {
|
|
|
2460
2518
|
constructor() {
|
|
2461
2519
|
super(...arguments);
|
|
2462
2520
|
this.actions = {
|
|
2463
|
-
setKey: (
|
|
2521
|
+
setKey: (context, resource, {
|
|
2464
2522
|
key
|
|
2465
2523
|
}) => {
|
|
2466
2524
|
resource.key = key;
|
|
2467
2525
|
},
|
|
2468
|
-
setTimeoutInMs: (
|
|
2526
|
+
setTimeoutInMs: (context, resource, {
|
|
2469
2527
|
timeoutInMs
|
|
2470
2528
|
}) => {
|
|
2471
2529
|
resource.timeoutInMs = timeoutInMs;
|
|
2472
2530
|
},
|
|
2473
|
-
changeTriggers: (
|
|
2531
|
+
changeTriggers: (context, resource, {
|
|
2474
2532
|
triggers
|
|
2475
2533
|
}) => {
|
|
2476
2534
|
resource.triggers = triggers;
|
|
2477
2535
|
},
|
|
2478
|
-
changeDestination: (
|
|
2536
|
+
changeDestination: (context, resource, {
|
|
2479
2537
|
destination
|
|
2480
2538
|
}) => {
|
|
2481
2539
|
resource.destination = destination;
|
|
@@ -2487,14 +2545,14 @@ class ExtensionRepository extends AbstractResourceRepository {
|
|
|
2487
2545
|
return 'extension';
|
|
2488
2546
|
}
|
|
2489
2547
|
|
|
2490
|
-
create(
|
|
2548
|
+
create(context, draft) {
|
|
2491
2549
|
const resource = { ...getBaseResourceProperties(),
|
|
2492
2550
|
key: draft.key,
|
|
2493
2551
|
timeoutInMs: draft.timeoutInMs,
|
|
2494
2552
|
destination: draft.destination,
|
|
2495
2553
|
triggers: draft.triggers
|
|
2496
2554
|
};
|
|
2497
|
-
this.save(
|
|
2555
|
+
this.save(context, resource);
|
|
2498
2556
|
return resource;
|
|
2499
2557
|
}
|
|
2500
2558
|
|
|
@@ -2516,19 +2574,19 @@ class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
2516
2574
|
constructor() {
|
|
2517
2575
|
super(...arguments);
|
|
2518
2576
|
this.actions = {
|
|
2519
|
-
changeQuantity: (
|
|
2577
|
+
changeQuantity: (context, resource, {
|
|
2520
2578
|
quantity
|
|
2521
2579
|
}) => {
|
|
2522
2580
|
resource.quantityOnStock = quantity; // don't know active reservations so just set to same value
|
|
2523
2581
|
|
|
2524
2582
|
resource.availableQuantity = quantity;
|
|
2525
2583
|
},
|
|
2526
|
-
setExpectedDelivery: (
|
|
2584
|
+
setExpectedDelivery: (context, resource, {
|
|
2527
2585
|
expectedDelivery
|
|
2528
2586
|
}) => {
|
|
2529
2587
|
resource.expectedDelivery = new Date(expectedDelivery).toISOString();
|
|
2530
2588
|
},
|
|
2531
|
-
setCustomField: (
|
|
2589
|
+
setCustomField: (context, resource, {
|
|
2532
2590
|
name,
|
|
2533
2591
|
value
|
|
2534
2592
|
}) => {
|
|
@@ -2538,14 +2596,14 @@ class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
2538
2596
|
|
|
2539
2597
|
resource.custom.fields[name] = value;
|
|
2540
2598
|
},
|
|
2541
|
-
setCustomType: (
|
|
2599
|
+
setCustomType: (context, resource, {
|
|
2542
2600
|
type,
|
|
2543
2601
|
fields
|
|
2544
2602
|
}) => {
|
|
2545
2603
|
if (!type) {
|
|
2546
2604
|
resource.custom = undefined;
|
|
2547
2605
|
} else {
|
|
2548
|
-
const resolvedType = this._storage.getByResourceIdentifier(projectKey, type);
|
|
2606
|
+
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, type);
|
|
2549
2607
|
|
|
2550
2608
|
if (!resolvedType) {
|
|
2551
2609
|
throw new Error(`Type ${type} not found`);
|
|
@@ -2560,7 +2618,7 @@ class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
2560
2618
|
};
|
|
2561
2619
|
}
|
|
2562
2620
|
},
|
|
2563
|
-
setRestockableInDays: (
|
|
2621
|
+
setRestockableInDays: (context, resource, {
|
|
2564
2622
|
restockableInDays
|
|
2565
2623
|
}) => {
|
|
2566
2624
|
resource.restockableInDays = restockableInDays;
|
|
@@ -2572,7 +2630,7 @@ class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
2572
2630
|
return 'inventory-entry';
|
|
2573
2631
|
}
|
|
2574
2632
|
|
|
2575
|
-
create(
|
|
2633
|
+
create(context, draft) {
|
|
2576
2634
|
var _draft$supplyChannel$, _draft$supplyChannel;
|
|
2577
2635
|
|
|
2578
2636
|
const resource = { ...getBaseResourceProperties(),
|
|
@@ -2585,9 +2643,9 @@ class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
2585
2643
|
typeId: 'channel',
|
|
2586
2644
|
id: (_draft$supplyChannel$ = (_draft$supplyChannel = draft.supplyChannel) == null ? void 0 : _draft$supplyChannel.id) != null ? _draft$supplyChannel$ : ''
|
|
2587
2645
|
},
|
|
2588
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage)
|
|
2646
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
2589
2647
|
};
|
|
2590
|
-
this.save(
|
|
2648
|
+
this.save(context, resource);
|
|
2591
2649
|
return resource;
|
|
2592
2650
|
}
|
|
2593
2651
|
|
|
@@ -2647,14 +2705,14 @@ class PaymentRepository extends AbstractResourceRepository {
|
|
|
2647
2705
|
constructor() {
|
|
2648
2706
|
super(...arguments);
|
|
2649
2707
|
|
|
2650
|
-
this.transactionFromTransactionDraft = (draft,
|
|
2708
|
+
this.transactionFromTransactionDraft = (draft, context) => ({ ...draft,
|
|
2651
2709
|
id: v4(),
|
|
2652
2710
|
amount: createTypedMoney(draft.amount),
|
|
2653
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage)
|
|
2711
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
2654
2712
|
});
|
|
2655
2713
|
|
|
2656
2714
|
this.actions = {
|
|
2657
|
-
setCustomField: (
|
|
2715
|
+
setCustomField: (context, resource, {
|
|
2658
2716
|
name,
|
|
2659
2717
|
value
|
|
2660
2718
|
}) => {
|
|
@@ -2664,14 +2722,14 @@ class PaymentRepository extends AbstractResourceRepository {
|
|
|
2664
2722
|
|
|
2665
2723
|
resource.custom.fields[name] = value;
|
|
2666
2724
|
},
|
|
2667
|
-
setCustomType: (
|
|
2725
|
+
setCustomType: (context, resource, {
|
|
2668
2726
|
type,
|
|
2669
2727
|
fields
|
|
2670
2728
|
}) => {
|
|
2671
2729
|
if (!type) {
|
|
2672
2730
|
resource.custom = undefined;
|
|
2673
2731
|
} else {
|
|
2674
|
-
const resolvedType = this._storage.getByResourceIdentifier(projectKey, type);
|
|
2732
|
+
const resolvedType = this._storage.getByResourceIdentifier(context.projectKey, type);
|
|
2675
2733
|
|
|
2676
2734
|
if (!resolvedType) {
|
|
2677
2735
|
throw new Error(`Type ${type} not found`);
|
|
@@ -2686,12 +2744,12 @@ class PaymentRepository extends AbstractResourceRepository {
|
|
|
2686
2744
|
};
|
|
2687
2745
|
}
|
|
2688
2746
|
},
|
|
2689
|
-
addTransaction: (
|
|
2747
|
+
addTransaction: (context, resource, {
|
|
2690
2748
|
transaction
|
|
2691
2749
|
}) => {
|
|
2692
|
-
resource.transactions = [...resource.transactions, this.transactionFromTransactionDraft(transaction,
|
|
2750
|
+
resource.transactions = [...resource.transactions, this.transactionFromTransactionDraft(transaction, context)];
|
|
2693
2751
|
},
|
|
2694
|
-
changeTransactionState: (
|
|
2752
|
+
changeTransactionState: (_context, resource, {
|
|
2695
2753
|
transactionId,
|
|
2696
2754
|
state
|
|
2697
2755
|
}) => {
|
|
@@ -2701,10 +2759,10 @@ class PaymentRepository extends AbstractResourceRepository {
|
|
|
2701
2759
|
};
|
|
2702
2760
|
resource.transactions[index] = updatedTransaction;
|
|
2703
2761
|
},
|
|
2704
|
-
transitionState: (
|
|
2762
|
+
transitionState: (context, resource, {
|
|
2705
2763
|
state
|
|
2706
2764
|
}) => {
|
|
2707
|
-
const stateObj = this._storage.getByResourceIdentifier(projectKey, state);
|
|
2765
|
+
const stateObj = this._storage.getByResourceIdentifier(context.projectKey, state);
|
|
2708
2766
|
|
|
2709
2767
|
if (!stateObj) {
|
|
2710
2768
|
throw new Error(`State ${state} not found`);
|
|
@@ -2723,18 +2781,18 @@ class PaymentRepository extends AbstractResourceRepository {
|
|
|
2723
2781
|
return 'payment';
|
|
2724
2782
|
}
|
|
2725
2783
|
|
|
2726
|
-
create(
|
|
2784
|
+
create(context, draft) {
|
|
2727
2785
|
const resource = { ...getBaseResourceProperties(),
|
|
2728
2786
|
amountPlanned: createTypedMoney(draft.amountPlanned),
|
|
2729
2787
|
paymentMethodInfo: draft.paymentMethodInfo,
|
|
2730
2788
|
paymentStatus: draft.paymentStatus ? { ...draft.paymentStatus,
|
|
2731
|
-
state: draft.paymentStatus.state ? getReferenceFromResourceIdentifier(draft.paymentStatus.state, projectKey, this._storage) : undefined
|
|
2789
|
+
state: draft.paymentStatus.state ? getReferenceFromResourceIdentifier(draft.paymentStatus.state, context.projectKey, this._storage) : undefined
|
|
2732
2790
|
} : {},
|
|
2733
|
-
transactions: (draft.transactions || []).map(t => this.transactionFromTransactionDraft(t,
|
|
2734
|
-
interfaceInteractions: (draft.interfaceInteractions || []).map(interaction => createCustomFields(interaction, projectKey, this._storage)),
|
|
2735
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage)
|
|
2791
|
+
transactions: (draft.transactions || []).map(t => this.transactionFromTransactionDraft(t, context)),
|
|
2792
|
+
interfaceInteractions: (draft.interfaceInteractions || []).map(interaction => createCustomFields(interaction, context.projectKey, this._storage)),
|
|
2793
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
2736
2794
|
};
|
|
2737
|
-
this.save(
|
|
2795
|
+
this.save(context, resource);
|
|
2738
2796
|
return resource;
|
|
2739
2797
|
}
|
|
2740
2798
|
|
|
@@ -2769,12 +2827,12 @@ class OrderService extends AbstractService {
|
|
|
2769
2827
|
|
|
2770
2828
|
import(request, response) {
|
|
2771
2829
|
const importDraft = request.body;
|
|
2772
|
-
const resource = this.repository.import(request
|
|
2830
|
+
const resource = this.repository.import(getRepositoryContext(request), importDraft);
|
|
2773
2831
|
return response.status(200).send(resource);
|
|
2774
2832
|
}
|
|
2775
2833
|
|
|
2776
2834
|
getWithOrderNumber(request, response) {
|
|
2777
|
-
const resource = this.repository.getWithOrderNumber(request
|
|
2835
|
+
const resource = this.repository.getWithOrderNumber(getRepositoryContext(request), request.params.orderNumber, request.query);
|
|
2778
2836
|
|
|
2779
2837
|
if (resource) {
|
|
2780
2838
|
return response.status(200).send(resource);
|
|
@@ -2826,7 +2884,7 @@ class ProductProjectionRepository extends AbstractResourceRepository {
|
|
|
2826
2884
|
return 'product-projection';
|
|
2827
2885
|
}
|
|
2828
2886
|
|
|
2829
|
-
create(
|
|
2887
|
+
create(context, draft) {
|
|
2830
2888
|
var _draft$variants$map, _draft$variants;
|
|
2831
2889
|
|
|
2832
2890
|
if (!draft.masterVariant) {
|
|
@@ -2851,17 +2909,17 @@ class ProductProjectionRepository extends AbstractResourceRepository {
|
|
|
2851
2909
|
// @ts-ignore
|
|
2852
2910
|
searchKeywords: draft.searchKeywords
|
|
2853
2911
|
};
|
|
2854
|
-
this.save(
|
|
2912
|
+
this.save(context, resource);
|
|
2855
2913
|
return resource;
|
|
2856
2914
|
}
|
|
2857
2915
|
|
|
2858
|
-
search(
|
|
2916
|
+
search(context, query) {
|
|
2859
2917
|
var _query$filterQuery;
|
|
2860
2918
|
|
|
2861
2919
|
const filter = (_query$filterQuery = query['filter.query']) != null ? _query$filterQuery : query.filter;
|
|
2862
2920
|
const wherePredicate = filter ? parseFilterExpression(filter) : undefined;
|
|
2863
2921
|
|
|
2864
|
-
const results = this._storage.query(projectKey, this.getTypeId(), {
|
|
2922
|
+
const results = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
2865
2923
|
where: wherePredicate,
|
|
2866
2924
|
offset: query.offset ? Number(query.offset) : undefined,
|
|
2867
2925
|
limit: query.limit ? Number(query.limit) : undefined
|
|
@@ -2896,7 +2954,7 @@ class ProductProjectionService extends AbstractService {
|
|
|
2896
2954
|
}
|
|
2897
2955
|
|
|
2898
2956
|
search(request, response) {
|
|
2899
|
-
const resource = this.repository.search(request
|
|
2957
|
+
const resource = this.repository.search(getRepositoryContext(request), request.query);
|
|
2900
2958
|
return response.status(200).send(resource);
|
|
2901
2959
|
}
|
|
2902
2960
|
|
|
@@ -2906,7 +2964,7 @@ class ProductRepository extends AbstractResourceRepository {
|
|
|
2906
2964
|
constructor() {
|
|
2907
2965
|
super(...arguments);
|
|
2908
2966
|
this.actions = {
|
|
2909
|
-
publish: (
|
|
2967
|
+
publish: (context, resource, {
|
|
2910
2968
|
scope
|
|
2911
2969
|
}) => {
|
|
2912
2970
|
if (resource.masterData.staged) {
|
|
@@ -2918,7 +2976,7 @@ class ProductRepository extends AbstractResourceRepository {
|
|
|
2918
2976
|
resource.masterData.hasStagedChanges = false;
|
|
2919
2977
|
resource.masterData.published = true;
|
|
2920
2978
|
},
|
|
2921
|
-
setAttribute: (
|
|
2979
|
+
setAttribute: (context, resource, {
|
|
2922
2980
|
variantId,
|
|
2923
2981
|
sku,
|
|
2924
2982
|
name,
|
|
@@ -2979,7 +3037,7 @@ class ProductRepository extends AbstractResourceRepository {
|
|
|
2979
3037
|
return 'product';
|
|
2980
3038
|
}
|
|
2981
3039
|
|
|
2982
|
-
create(
|
|
3040
|
+
create(context, draft) {
|
|
2983
3041
|
var _draft$publish, _draft$publish2;
|
|
2984
3042
|
|
|
2985
3043
|
const productData = {
|
|
@@ -3003,7 +3061,7 @@ class ProductRepository extends AbstractResourceRepository {
|
|
|
3003
3061
|
published: (_draft$publish2 = draft.publish) != null ? _draft$publish2 : false
|
|
3004
3062
|
}
|
|
3005
3063
|
};
|
|
3006
|
-
this.save(
|
|
3064
|
+
this.save(context, resource);
|
|
3007
3065
|
return resource;
|
|
3008
3066
|
}
|
|
3009
3067
|
|
|
@@ -3063,7 +3121,7 @@ class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
3063
3121
|
constructor() {
|
|
3064
3122
|
super(...arguments);
|
|
3065
3123
|
|
|
3066
|
-
this.attributeDefinitionFromAttributeDefinitionDraft = (
|
|
3124
|
+
this.attributeDefinitionFromAttributeDefinitionDraft = (_context, draft) => {
|
|
3067
3125
|
var _draft$attributeConst, _draft$inputHint, _draft$isSearchable;
|
|
3068
3126
|
|
|
3069
3127
|
return { ...draft,
|
|
@@ -3074,7 +3132,7 @@ class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
3074
3132
|
};
|
|
3075
3133
|
|
|
3076
3134
|
this.actions = {
|
|
3077
|
-
changeLocalizedEnumValueLabel: (
|
|
3135
|
+
changeLocalizedEnumValueLabel: (context, resource, {
|
|
3078
3136
|
attributeName,
|
|
3079
3137
|
newValue
|
|
3080
3138
|
}) => {
|
|
@@ -3102,7 +3160,7 @@ class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
3102
3160
|
}
|
|
3103
3161
|
});
|
|
3104
3162
|
},
|
|
3105
|
-
changeLabel: (
|
|
3163
|
+
changeLabel: (context, resource, {
|
|
3106
3164
|
attributeName,
|
|
3107
3165
|
label
|
|
3108
3166
|
}) => {
|
|
@@ -3121,21 +3179,21 @@ class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
3121
3179
|
return 'product-type';
|
|
3122
3180
|
}
|
|
3123
3181
|
|
|
3124
|
-
create(
|
|
3182
|
+
create(context, draft) {
|
|
3125
3183
|
var _draft$attributes;
|
|
3126
3184
|
|
|
3127
3185
|
const resource = { ...getBaseResourceProperties(),
|
|
3128
3186
|
key: draft.key,
|
|
3129
3187
|
name: draft.name,
|
|
3130
3188
|
description: draft.description,
|
|
3131
|
-
attributes: ((_draft$attributes = draft.attributes) != null ? _draft$attributes : []).map(a => this.attributeDefinitionFromAttributeDefinitionDraft(
|
|
3189
|
+
attributes: ((_draft$attributes = draft.attributes) != null ? _draft$attributes : []).map(a => this.attributeDefinitionFromAttributeDefinitionDraft(context, a))
|
|
3132
3190
|
};
|
|
3133
|
-
this.save(
|
|
3191
|
+
this.save(context, resource);
|
|
3134
3192
|
return resource;
|
|
3135
3193
|
}
|
|
3136
3194
|
|
|
3137
|
-
getWithKey(
|
|
3138
|
-
const result = this._storage.query(projectKey, this.getTypeId(), {
|
|
3195
|
+
getWithKey(context, key) {
|
|
3196
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3139
3197
|
where: [`key="${key}"`]
|
|
3140
3198
|
});
|
|
3141
3199
|
|
|
@@ -3168,7 +3226,7 @@ class ProductTypeService extends AbstractService {
|
|
|
3168
3226
|
}
|
|
3169
3227
|
|
|
3170
3228
|
getWithKey(request, response) {
|
|
3171
|
-
const resource = this.repository.getWithKey(request
|
|
3229
|
+
const resource = this.repository.getWithKey(getRepositoryContext(request), request.params.key);
|
|
3172
3230
|
|
|
3173
3231
|
if (resource) {
|
|
3174
3232
|
return response.status(200).send(resource);
|
|
@@ -3205,32 +3263,32 @@ class ProjectRepository extends AbstractRepository {
|
|
|
3205
3263
|
constructor() {
|
|
3206
3264
|
super(...arguments);
|
|
3207
3265
|
this.actions = {
|
|
3208
|
-
changeName: (
|
|
3266
|
+
changeName: (context, resource, {
|
|
3209
3267
|
name
|
|
3210
3268
|
}) => {
|
|
3211
3269
|
resource.name = name;
|
|
3212
3270
|
},
|
|
3213
|
-
changeCurrencies: (
|
|
3271
|
+
changeCurrencies: (context, resource, {
|
|
3214
3272
|
currencies
|
|
3215
3273
|
}) => {
|
|
3216
3274
|
resource.currencies = currencies;
|
|
3217
3275
|
},
|
|
3218
|
-
changeCountries: (
|
|
3276
|
+
changeCountries: (context, resource, {
|
|
3219
3277
|
countries
|
|
3220
3278
|
}) => {
|
|
3221
3279
|
resource.countries = countries;
|
|
3222
3280
|
},
|
|
3223
|
-
changeLanguages: (
|
|
3281
|
+
changeLanguages: (context, resource, {
|
|
3224
3282
|
languages
|
|
3225
3283
|
}) => {
|
|
3226
3284
|
resource.languages = languages;
|
|
3227
3285
|
},
|
|
3228
|
-
changeMessagesEnabled: (
|
|
3286
|
+
changeMessagesEnabled: (context, resource, {
|
|
3229
3287
|
messagesEnabled
|
|
3230
3288
|
}) => {
|
|
3231
3289
|
resource.messages.enabled = messagesEnabled;
|
|
3232
3290
|
},
|
|
3233
|
-
changeProductSearchIndexingEnabled: (
|
|
3291
|
+
changeProductSearchIndexingEnabled: (context, resource, {
|
|
3234
3292
|
enabled
|
|
3235
3293
|
}) => {
|
|
3236
3294
|
var _resource$searchIndex;
|
|
@@ -3242,7 +3300,7 @@ class ProjectRepository extends AbstractRepository {
|
|
|
3242
3300
|
resource.searchIndexing.products.status = enabled ? 'Activated' : 'Deactivated';
|
|
3243
3301
|
resource.searchIndexing.products.lastModifiedAt = new Date().toISOString();
|
|
3244
3302
|
},
|
|
3245
|
-
changeOrderSearchStatus: (
|
|
3303
|
+
changeOrderSearchStatus: (context, resource, {
|
|
3246
3304
|
status
|
|
3247
3305
|
}) => {
|
|
3248
3306
|
var _resource$searchIndex2;
|
|
@@ -3254,22 +3312,22 @@ class ProjectRepository extends AbstractRepository {
|
|
|
3254
3312
|
resource.searchIndexing.orders.status = status;
|
|
3255
3313
|
resource.searchIndexing.orders.lastModifiedAt = new Date().toISOString();
|
|
3256
3314
|
},
|
|
3257
|
-
setShippingRateInputType: (
|
|
3315
|
+
setShippingRateInputType: (context, resource, {
|
|
3258
3316
|
shippingRateInputType
|
|
3259
3317
|
}) => {
|
|
3260
3318
|
resource.shippingRateInputType = shippingRateInputType;
|
|
3261
3319
|
},
|
|
3262
|
-
setExternalOAuth: (
|
|
3320
|
+
setExternalOAuth: (context, resource, {
|
|
3263
3321
|
externalOAuth
|
|
3264
3322
|
}) => {
|
|
3265
3323
|
resource.externalOAuth = externalOAuth;
|
|
3266
3324
|
},
|
|
3267
|
-
changeCountryTaxRateFallbackEnabled: (
|
|
3325
|
+
changeCountryTaxRateFallbackEnabled: (context, resource, {
|
|
3268
3326
|
countryTaxRateFallbackEnabled
|
|
3269
3327
|
}) => {
|
|
3270
3328
|
resource.carts.countryTaxRateFallbackEnabled = countryTaxRateFallbackEnabled;
|
|
3271
3329
|
},
|
|
3272
|
-
changeCartsConfiguration: (
|
|
3330
|
+
changeCartsConfiguration: (context, resource, {
|
|
3273
3331
|
cartsConfiguration
|
|
3274
3332
|
}) => {
|
|
3275
3333
|
resource.carts = cartsConfiguration || {
|
|
@@ -3280,15 +3338,15 @@ class ProjectRepository extends AbstractRepository {
|
|
|
3280
3338
|
};
|
|
3281
3339
|
}
|
|
3282
3340
|
|
|
3283
|
-
get(
|
|
3284
|
-
const resource = this._storage.getProject(projectKey);
|
|
3341
|
+
get(context) {
|
|
3342
|
+
const resource = this._storage.getProject(context.projectKey);
|
|
3285
3343
|
|
|
3286
3344
|
const masked = maskSecretValue(resource, 'externalOAuth.authorizationHeader');
|
|
3287
3345
|
return masked;
|
|
3288
3346
|
}
|
|
3289
3347
|
|
|
3290
|
-
save(
|
|
3291
|
-
const current = this.get(
|
|
3348
|
+
save(context, resource) {
|
|
3349
|
+
const current = this.get(context);
|
|
3292
3350
|
|
|
3293
3351
|
if (current) {
|
|
3294
3352
|
checkConcurrentModification(current, resource.version);
|
|
@@ -3321,20 +3379,19 @@ class ProjectService {
|
|
|
3321
3379
|
}
|
|
3322
3380
|
|
|
3323
3381
|
get(request, response) {
|
|
3324
|
-
const
|
|
3325
|
-
const project = this.repository.get(projectKey);
|
|
3382
|
+
const project = this.repository.get(getRepositoryContext(request));
|
|
3326
3383
|
return response.status(200).send(project);
|
|
3327
3384
|
}
|
|
3328
3385
|
|
|
3329
3386
|
post(request, response) {
|
|
3330
3387
|
const updateRequest = request.body;
|
|
3331
|
-
const project = this.repository.get(request
|
|
3388
|
+
const project = this.repository.get(getRepositoryContext(request));
|
|
3332
3389
|
|
|
3333
3390
|
if (!project) {
|
|
3334
3391
|
return response.status(404).send({});
|
|
3335
3392
|
}
|
|
3336
3393
|
|
|
3337
|
-
this.repository.processUpdateActions(request
|
|
3394
|
+
this.repository.processUpdateActions(getRepositoryContext(request), project, updateRequest.actions);
|
|
3338
3395
|
return response.status(200).send({});
|
|
3339
3396
|
}
|
|
3340
3397
|
|
|
@@ -3344,11 +3401,11 @@ class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
3344
3401
|
constructor() {
|
|
3345
3402
|
super(...arguments);
|
|
3346
3403
|
|
|
3347
|
-
this._transformZoneRateDraft = (
|
|
3404
|
+
this._transformZoneRateDraft = (context, draft) => {
|
|
3348
3405
|
var _draft$shippingRates;
|
|
3349
3406
|
|
|
3350
3407
|
return { ...draft,
|
|
3351
|
-
zone: getReferenceFromResourceIdentifier(draft.zone, projectKey, this._storage),
|
|
3408
|
+
zone: getReferenceFromResourceIdentifier(draft.zone, context.projectKey, this._storage),
|
|
3352
3409
|
shippingRates: (_draft$shippingRates = draft.shippingRates) == null ? void 0 : _draft$shippingRates.map(this._transformShippingRate)
|
|
3353
3410
|
};
|
|
3354
3411
|
};
|
|
@@ -3362,7 +3419,7 @@ class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
3362
3419
|
};
|
|
3363
3420
|
|
|
3364
3421
|
this.actions = {
|
|
3365
|
-
addShippingRate: (
|
|
3422
|
+
addShippingRate: (_context, resource, {
|
|
3366
3423
|
shippingRate,
|
|
3367
3424
|
zone
|
|
3368
3425
|
}) => {
|
|
@@ -3382,7 +3439,7 @@ class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
3382
3439
|
shippingRates: [rate]
|
|
3383
3440
|
});
|
|
3384
3441
|
},
|
|
3385
|
-
removeShippingRate: (
|
|
3442
|
+
removeShippingRate: (_context, resource, {
|
|
3386
3443
|
shippingRate,
|
|
3387
3444
|
zone
|
|
3388
3445
|
}) => {
|
|
@@ -3396,10 +3453,10 @@ class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
3396
3453
|
}
|
|
3397
3454
|
});
|
|
3398
3455
|
},
|
|
3399
|
-
addZone: (
|
|
3456
|
+
addZone: (context, resource, {
|
|
3400
3457
|
zone
|
|
3401
3458
|
}) => {
|
|
3402
|
-
const zoneReference = getReferenceFromResourceIdentifier(zone, projectKey, this._storage);
|
|
3459
|
+
const zoneReference = getReferenceFromResourceIdentifier(zone, context.projectKey, this._storage);
|
|
3403
3460
|
|
|
3404
3461
|
if (resource.zoneRates === undefined) {
|
|
3405
3462
|
resource.zoneRates = [];
|
|
@@ -3410,39 +3467,39 @@ class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
3410
3467
|
shippingRates: []
|
|
3411
3468
|
});
|
|
3412
3469
|
},
|
|
3413
|
-
removeZone: (
|
|
3470
|
+
removeZone: (_context, resource, {
|
|
3414
3471
|
zone
|
|
3415
3472
|
}) => {
|
|
3416
3473
|
resource.zoneRates = resource.zoneRates.filter(zoneRate => {
|
|
3417
3474
|
return zoneRate.zone.id !== zone.id;
|
|
3418
3475
|
});
|
|
3419
3476
|
},
|
|
3420
|
-
setKey: (
|
|
3477
|
+
setKey: (_context, resource, {
|
|
3421
3478
|
key
|
|
3422
3479
|
}) => {
|
|
3423
3480
|
resource.key = key;
|
|
3424
3481
|
},
|
|
3425
|
-
setDescription: (
|
|
3482
|
+
setDescription: (_context, resource, {
|
|
3426
3483
|
description
|
|
3427
3484
|
}) => {
|
|
3428
3485
|
resource.description = description;
|
|
3429
3486
|
},
|
|
3430
|
-
setLocalizedDescription: (
|
|
3487
|
+
setLocalizedDescription: (_context, resource, {
|
|
3431
3488
|
localizedDescription
|
|
3432
3489
|
}) => {
|
|
3433
3490
|
resource.localizedDescription = localizedDescription;
|
|
3434
3491
|
},
|
|
3435
|
-
setPredicate: (
|
|
3492
|
+
setPredicate: (_context, resource, {
|
|
3436
3493
|
predicate
|
|
3437
3494
|
}) => {
|
|
3438
3495
|
resource.predicate = predicate;
|
|
3439
3496
|
},
|
|
3440
|
-
changeIsDefault: (
|
|
3497
|
+
changeIsDefault: (_context, resource, {
|
|
3441
3498
|
isDefault
|
|
3442
3499
|
}) => {
|
|
3443
3500
|
resource.isDefault = isDefault;
|
|
3444
3501
|
},
|
|
3445
|
-
changeName: (
|
|
3502
|
+
changeName: (_context, resource, {
|
|
3446
3503
|
name
|
|
3447
3504
|
}) => {
|
|
3448
3505
|
resource.name = name;
|
|
@@ -3454,16 +3511,16 @@ class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
3454
3511
|
return 'shipping-method';
|
|
3455
3512
|
}
|
|
3456
3513
|
|
|
3457
|
-
create(
|
|
3514
|
+
create(context, draft) {
|
|
3458
3515
|
var _draft$zoneRates;
|
|
3459
3516
|
|
|
3460
3517
|
const resource = { ...getBaseResourceProperties(),
|
|
3461
3518
|
...draft,
|
|
3462
|
-
taxCategory: getReferenceFromResourceIdentifier(draft.taxCategory, projectKey, this._storage),
|
|
3463
|
-
zoneRates: (_draft$zoneRates = draft.zoneRates) == null ? void 0 : _draft$zoneRates.map(z => this._transformZoneRateDraft(
|
|
3464
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage)
|
|
3519
|
+
taxCategory: getReferenceFromResourceIdentifier(draft.taxCategory, context.projectKey, this._storage),
|
|
3520
|
+
zoneRates: (_draft$zoneRates = draft.zoneRates) == null ? void 0 : _draft$zoneRates.map(z => this._transformZoneRateDraft(context, z)),
|
|
3521
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
3465
3522
|
};
|
|
3466
|
-
this.save(
|
|
3523
|
+
this.save(context, resource);
|
|
3467
3524
|
return resource;
|
|
3468
3525
|
}
|
|
3469
3526
|
|
|
@@ -3491,13 +3548,13 @@ class ShoppingListRepository extends AbstractResourceRepository {
|
|
|
3491
3548
|
return 'shopping-list';
|
|
3492
3549
|
}
|
|
3493
3550
|
|
|
3494
|
-
create(
|
|
3551
|
+
create(context, draft) {
|
|
3495
3552
|
var _draft$lineItems, _draft$store;
|
|
3496
3553
|
|
|
3497
3554
|
// const product =
|
|
3498
3555
|
const resource = { ...getBaseResourceProperties(),
|
|
3499
3556
|
...draft,
|
|
3500
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage),
|
|
3557
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
3501
3558
|
textLineItems: [],
|
|
3502
3559
|
lineItems: (_draft$lineItems = draft.lineItems) == null ? void 0 : _draft$lineItems.map(e => {
|
|
3503
3560
|
var _e$addedAt, _e$productId, _e$quantity;
|
|
@@ -3512,16 +3569,16 @@ class ShoppingListRepository extends AbstractResourceRepository {
|
|
|
3512
3569
|
typeId: 'product-type',
|
|
3513
3570
|
id: ''
|
|
3514
3571
|
},
|
|
3515
|
-
custom: createCustomFields(e.custom, projectKey, this._storage)
|
|
3572
|
+
custom: createCustomFields(e.custom, context.projectKey, this._storage)
|
|
3516
3573
|
};
|
|
3517
3574
|
}),
|
|
3518
|
-
customer: draft.customer ? getReferenceFromResourceIdentifier(draft.customer, projectKey, this._storage) : undefined,
|
|
3575
|
+
customer: draft.customer ? getReferenceFromResourceIdentifier(draft.customer, context.projectKey, this._storage) : undefined,
|
|
3519
3576
|
store: (_draft$store = draft.store) != null && _draft$store.key ? {
|
|
3520
3577
|
typeId: 'store',
|
|
3521
3578
|
key: draft.store.key
|
|
3522
3579
|
} : undefined
|
|
3523
3580
|
};
|
|
3524
|
-
this.save(
|
|
3581
|
+
this.save(context, resource);
|
|
3525
3582
|
return resource;
|
|
3526
3583
|
}
|
|
3527
3584
|
|
|
@@ -3543,22 +3600,22 @@ class StateRepository extends AbstractResourceRepository {
|
|
|
3543
3600
|
constructor() {
|
|
3544
3601
|
super(...arguments);
|
|
3545
3602
|
this.actions = {
|
|
3546
|
-
changeKey: (
|
|
3603
|
+
changeKey: (context, resource, {
|
|
3547
3604
|
key
|
|
3548
3605
|
}) => {
|
|
3549
3606
|
resource.key = key;
|
|
3550
3607
|
},
|
|
3551
|
-
setDescription: (
|
|
3608
|
+
setDescription: (context, resource, {
|
|
3552
3609
|
description
|
|
3553
3610
|
}) => {
|
|
3554
3611
|
resource.description = description;
|
|
3555
3612
|
},
|
|
3556
|
-
setName: (
|
|
3613
|
+
setName: (context, resource, {
|
|
3557
3614
|
name
|
|
3558
3615
|
}) => {
|
|
3559
3616
|
resource.name = name;
|
|
3560
3617
|
},
|
|
3561
|
-
setRoles: (
|
|
3618
|
+
setRoles: (context, resource, {
|
|
3562
3619
|
roles
|
|
3563
3620
|
}) => {
|
|
3564
3621
|
resource.roles = roles;
|
|
@@ -3570,14 +3627,14 @@ class StateRepository extends AbstractResourceRepository {
|
|
|
3570
3627
|
return 'state';
|
|
3571
3628
|
}
|
|
3572
3629
|
|
|
3573
|
-
create(
|
|
3630
|
+
create(context, draft) {
|
|
3574
3631
|
const resource = { ...getBaseResourceProperties(),
|
|
3575
3632
|
...draft,
|
|
3576
3633
|
builtIn: false,
|
|
3577
3634
|
initial: draft.initial || false,
|
|
3578
|
-
transitions: (draft.transitions || []).map(t => getReferenceFromResourceIdentifier(t, projectKey, this._storage))
|
|
3635
|
+
transitions: (draft.transitions || []).map(t => getReferenceFromResourceIdentifier(t, context.projectKey, this._storage))
|
|
3579
3636
|
};
|
|
3580
|
-
this.save(
|
|
3637
|
+
this.save(context, resource);
|
|
3581
3638
|
return resource;
|
|
3582
3639
|
}
|
|
3583
3640
|
|
|
@@ -3599,17 +3656,17 @@ class StoreRepository extends AbstractResourceRepository {
|
|
|
3599
3656
|
constructor() {
|
|
3600
3657
|
super(...arguments);
|
|
3601
3658
|
this.actions = {
|
|
3602
|
-
setName: (
|
|
3659
|
+
setName: (context, resource, {
|
|
3603
3660
|
name
|
|
3604
3661
|
}) => {
|
|
3605
3662
|
resource.name = name;
|
|
3606
3663
|
},
|
|
3607
|
-
setDistributionChannels: (
|
|
3664
|
+
setDistributionChannels: (context, resource, {
|
|
3608
3665
|
distributionChannels
|
|
3609
3666
|
}) => {
|
|
3610
|
-
resource.distributionChannels = this.transformChannels(
|
|
3667
|
+
resource.distributionChannels = this.transformChannels(context, distributionChannels);
|
|
3611
3668
|
},
|
|
3612
|
-
setLanguages: (
|
|
3669
|
+
setLanguages: (context, resource, {
|
|
3613
3670
|
languages
|
|
3614
3671
|
}) => {
|
|
3615
3672
|
resource.languages = languages;
|
|
@@ -3621,25 +3678,25 @@ class StoreRepository extends AbstractResourceRepository {
|
|
|
3621
3678
|
return 'store';
|
|
3622
3679
|
}
|
|
3623
3680
|
|
|
3624
|
-
create(
|
|
3681
|
+
create(context, draft) {
|
|
3625
3682
|
const resource = { ...getBaseResourceProperties(),
|
|
3626
3683
|
key: draft.key,
|
|
3627
3684
|
name: draft.name,
|
|
3628
3685
|
languages: draft.languages,
|
|
3629
|
-
distributionChannels: this.transformChannels(
|
|
3630
|
-
supplyChannels: this.transformChannels(
|
|
3686
|
+
distributionChannels: this.transformChannels(context, draft.distributionChannels),
|
|
3687
|
+
supplyChannels: this.transformChannels(context, draft.supplyChannels)
|
|
3631
3688
|
};
|
|
3632
|
-
this.save(
|
|
3689
|
+
this.save(context, resource);
|
|
3633
3690
|
return resource;
|
|
3634
3691
|
}
|
|
3635
3692
|
|
|
3636
|
-
transformChannels(
|
|
3693
|
+
transformChannels(context, channels) {
|
|
3637
3694
|
if (!channels) return [];
|
|
3638
|
-
return channels.map(ref => getReferenceFromResourceIdentifier(ref, projectKey, this._storage));
|
|
3695
|
+
return channels.map(ref => getReferenceFromResourceIdentifier(ref, context.projectKey, this._storage));
|
|
3639
3696
|
}
|
|
3640
3697
|
|
|
3641
|
-
getWithKey(
|
|
3642
|
-
const result = this._storage.query(projectKey, this.getTypeId(), {
|
|
3698
|
+
getWithKey(context, key) {
|
|
3699
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3643
3700
|
where: [`key="${key}"`]
|
|
3644
3701
|
});
|
|
3645
3702
|
|
|
@@ -3671,7 +3728,7 @@ class StoreService extends AbstractService {
|
|
|
3671
3728
|
}
|
|
3672
3729
|
|
|
3673
3730
|
getWithKey(request, response) {
|
|
3674
|
-
const resource = this.repository.getWithKey(request
|
|
3731
|
+
const resource = this.repository.getWithKey(getRepositoryContext(request), request.params.key);
|
|
3675
3732
|
|
|
3676
3733
|
if (resource) {
|
|
3677
3734
|
return response.status(200).send(resource);
|
|
@@ -3687,7 +3744,7 @@ class SubscriptionRepository extends AbstractResourceRepository {
|
|
|
3687
3744
|
return 'subscription';
|
|
3688
3745
|
}
|
|
3689
3746
|
|
|
3690
|
-
create(
|
|
3747
|
+
create(context, draft) {
|
|
3691
3748
|
// TODO: We could actually test this here by using the aws sdk. For now
|
|
3692
3749
|
// hardcode a failed check when account id is 0000000000
|
|
3693
3750
|
if (draft.destination.type === 'SQS') {
|
|
@@ -3713,7 +3770,7 @@ class SubscriptionRepository extends AbstractResourceRepository {
|
|
|
3713
3770
|
messages: draft.messages || [],
|
|
3714
3771
|
status: 'Healthy'
|
|
3715
3772
|
};
|
|
3716
|
-
this.save(
|
|
3773
|
+
this.save(context, resource);
|
|
3717
3774
|
return resource;
|
|
3718
3775
|
}
|
|
3719
3776
|
|
|
@@ -3741,7 +3798,7 @@ class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
3741
3798
|
});
|
|
3742
3799
|
|
|
3743
3800
|
this.actions = {
|
|
3744
|
-
addTaxRate: (
|
|
3801
|
+
addTaxRate: (context, resource, {
|
|
3745
3802
|
taxRate
|
|
3746
3803
|
}) => {
|
|
3747
3804
|
if (resource.rates === undefined) {
|
|
@@ -3750,7 +3807,7 @@ class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
3750
3807
|
|
|
3751
3808
|
resource.rates.push(this.taxRateFromTaxRateDraft(taxRate));
|
|
3752
3809
|
},
|
|
3753
|
-
removeTaxRate: (
|
|
3810
|
+
removeTaxRate: (context, resource, {
|
|
3754
3811
|
taxRateId
|
|
3755
3812
|
}) => {
|
|
3756
3813
|
if (resource.rates === undefined) {
|
|
@@ -3761,7 +3818,7 @@ class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
3761
3818
|
return taxRate.id !== taxRateId;
|
|
3762
3819
|
});
|
|
3763
3820
|
},
|
|
3764
|
-
replaceTaxRate: (
|
|
3821
|
+
replaceTaxRate: (context, resource, {
|
|
3765
3822
|
taxRateId,
|
|
3766
3823
|
taxRate
|
|
3767
3824
|
}) => {
|
|
@@ -3779,17 +3836,17 @@ class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
3779
3836
|
}
|
|
3780
3837
|
}
|
|
3781
3838
|
},
|
|
3782
|
-
setDescription: (
|
|
3839
|
+
setDescription: (context, resource, {
|
|
3783
3840
|
description
|
|
3784
3841
|
}) => {
|
|
3785
3842
|
resource.description = description;
|
|
3786
3843
|
},
|
|
3787
|
-
setKey: (
|
|
3844
|
+
setKey: (context, resource, {
|
|
3788
3845
|
key
|
|
3789
3846
|
}) => {
|
|
3790
3847
|
resource.key = key;
|
|
3791
3848
|
},
|
|
3792
|
-
changeName: (
|
|
3849
|
+
changeName: (context, resource, {
|
|
3793
3850
|
name
|
|
3794
3851
|
}) => {
|
|
3795
3852
|
resource.name = name;
|
|
@@ -3801,19 +3858,19 @@ class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
3801
3858
|
return 'tax-category';
|
|
3802
3859
|
}
|
|
3803
3860
|
|
|
3804
|
-
create(
|
|
3861
|
+
create(context, draft) {
|
|
3805
3862
|
var _draft$rates;
|
|
3806
3863
|
|
|
3807
3864
|
const resource = { ...getBaseResourceProperties(),
|
|
3808
3865
|
...draft,
|
|
3809
3866
|
rates: ((_draft$rates = draft.rates) == null ? void 0 : _draft$rates.map(this.taxRateFromTaxRateDraft)) || []
|
|
3810
3867
|
};
|
|
3811
|
-
this.save(
|
|
3868
|
+
this.save(context, resource);
|
|
3812
3869
|
return resource;
|
|
3813
3870
|
}
|
|
3814
3871
|
|
|
3815
|
-
getWithKey(
|
|
3816
|
-
const result = this._storage.query(projectKey, this.getTypeId(), {
|
|
3872
|
+
getWithKey(context, key) {
|
|
3873
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3817
3874
|
where: [`key="${key}"`]
|
|
3818
3875
|
});
|
|
3819
3876
|
|
|
@@ -3846,7 +3903,7 @@ class TaxCategoryService extends AbstractService {
|
|
|
3846
3903
|
}
|
|
3847
3904
|
|
|
3848
3905
|
getWithKey(request, response) {
|
|
3849
|
-
const resource = this.repository.getWithKey(request
|
|
3906
|
+
const resource = this.repository.getWithKey(getRepositoryContext(request), request.params.key);
|
|
3850
3907
|
|
|
3851
3908
|
if (resource) {
|
|
3852
3909
|
return response.status(200).send(resource);
|
|
@@ -3861,29 +3918,29 @@ class TypeRepository extends AbstractResourceRepository {
|
|
|
3861
3918
|
constructor() {
|
|
3862
3919
|
super(...arguments);
|
|
3863
3920
|
this.actions = {
|
|
3864
|
-
addFieldDefinition: (
|
|
3921
|
+
addFieldDefinition: (context, resource, {
|
|
3865
3922
|
fieldDefinition
|
|
3866
3923
|
}) => {
|
|
3867
3924
|
resource.fieldDefinitions.push(fieldDefinition);
|
|
3868
3925
|
},
|
|
3869
|
-
removeFieldDefinition: (
|
|
3926
|
+
removeFieldDefinition: (context, resource, {
|
|
3870
3927
|
fieldName
|
|
3871
3928
|
}) => {
|
|
3872
3929
|
resource.fieldDefinitions = resource.fieldDefinitions.filter(f => {
|
|
3873
3930
|
return f.name !== fieldName;
|
|
3874
3931
|
});
|
|
3875
3932
|
},
|
|
3876
|
-
setDescription: (
|
|
3933
|
+
setDescription: (context, resource, {
|
|
3877
3934
|
description
|
|
3878
3935
|
}) => {
|
|
3879
3936
|
resource.description = description;
|
|
3880
3937
|
},
|
|
3881
|
-
changeName: (
|
|
3938
|
+
changeName: (context, resource, {
|
|
3882
3939
|
name
|
|
3883
3940
|
}) => {
|
|
3884
3941
|
resource.name = name;
|
|
3885
3942
|
},
|
|
3886
|
-
changeFieldDefinitionOrder: (
|
|
3943
|
+
changeFieldDefinitionOrder: (context, resource, {
|
|
3887
3944
|
fieldNames
|
|
3888
3945
|
}) => {
|
|
3889
3946
|
const fields = new Map(resource.fieldDefinitions.map(item => [item.name, item]));
|
|
@@ -3907,7 +3964,7 @@ class TypeRepository extends AbstractResourceRepository {
|
|
|
3907
3964
|
|
|
3908
3965
|
resource.fieldDefinitions.push(...current);
|
|
3909
3966
|
},
|
|
3910
|
-
addEnumValue: (
|
|
3967
|
+
addEnumValue: (context, resource, {
|
|
3911
3968
|
fieldName,
|
|
3912
3969
|
value
|
|
3913
3970
|
}) => {
|
|
@@ -3924,7 +3981,7 @@ class TypeRepository extends AbstractResourceRepository {
|
|
|
3924
3981
|
}
|
|
3925
3982
|
});
|
|
3926
3983
|
},
|
|
3927
|
-
changeEnumValueLabel: (
|
|
3984
|
+
changeEnumValueLabel: (context, resource, {
|
|
3928
3985
|
fieldName,
|
|
3929
3986
|
value
|
|
3930
3987
|
}) => {
|
|
@@ -3956,7 +4013,7 @@ class TypeRepository extends AbstractResourceRepository {
|
|
|
3956
4013
|
return 'type';
|
|
3957
4014
|
}
|
|
3958
4015
|
|
|
3959
|
-
create(
|
|
4016
|
+
create(context, draft) {
|
|
3960
4017
|
const resource = { ...getBaseResourceProperties(),
|
|
3961
4018
|
key: draft.key,
|
|
3962
4019
|
name: draft.name,
|
|
@@ -3964,7 +4021,7 @@ class TypeRepository extends AbstractResourceRepository {
|
|
|
3964
4021
|
fieldDefinitions: draft.fieldDefinitions || [],
|
|
3965
4022
|
description: draft.description
|
|
3966
4023
|
};
|
|
3967
|
-
this.save(
|
|
4024
|
+
this.save(context, resource);
|
|
3968
4025
|
return resource;
|
|
3969
4026
|
}
|
|
3970
4027
|
|
|
@@ -3986,29 +4043,29 @@ class ZoneRepository extends AbstractResourceRepository {
|
|
|
3986
4043
|
constructor() {
|
|
3987
4044
|
super(...arguments);
|
|
3988
4045
|
this.actions = {
|
|
3989
|
-
addLocation: (
|
|
4046
|
+
addLocation: (context, resource, {
|
|
3990
4047
|
location
|
|
3991
4048
|
}) => {
|
|
3992
4049
|
resource.locations.push(location);
|
|
3993
4050
|
},
|
|
3994
|
-
removeLocation: (
|
|
4051
|
+
removeLocation: (context, resource, {
|
|
3995
4052
|
location
|
|
3996
4053
|
}) => {
|
|
3997
4054
|
resource.locations = resource.locations.filter(loc => {
|
|
3998
4055
|
return !(loc.country === location.country && loc.state === location.state);
|
|
3999
4056
|
});
|
|
4000
4057
|
},
|
|
4001
|
-
changeName: (
|
|
4058
|
+
changeName: (context, resource, {
|
|
4002
4059
|
name
|
|
4003
4060
|
}) => {
|
|
4004
4061
|
resource.name = name;
|
|
4005
4062
|
},
|
|
4006
|
-
setDescription: (
|
|
4063
|
+
setDescription: (context, resource, {
|
|
4007
4064
|
description
|
|
4008
4065
|
}) => {
|
|
4009
4066
|
resource.description = description;
|
|
4010
4067
|
},
|
|
4011
|
-
setKey: (
|
|
4068
|
+
setKey: (context, resource, {
|
|
4012
4069
|
key
|
|
4013
4070
|
}) => {
|
|
4014
4071
|
resource.key = key;
|
|
@@ -4020,14 +4077,14 @@ class ZoneRepository extends AbstractResourceRepository {
|
|
|
4020
4077
|
return 'zone';
|
|
4021
4078
|
}
|
|
4022
4079
|
|
|
4023
|
-
create(
|
|
4080
|
+
create(context, draft) {
|
|
4024
4081
|
const resource = { ...getBaseResourceProperties(),
|
|
4025
4082
|
key: draft.key,
|
|
4026
4083
|
locations: draft.locations || [],
|
|
4027
4084
|
name: draft.name,
|
|
4028
4085
|
description: draft.description
|
|
4029
4086
|
};
|
|
4030
|
-
this.save(
|
|
4087
|
+
this.save(context, resource);
|
|
4031
4088
|
return resource;
|
|
4032
4089
|
}
|
|
4033
4090
|
|
|
@@ -4069,7 +4126,7 @@ class MyCustomerService extends AbstractService {
|
|
|
4069
4126
|
}
|
|
4070
4127
|
|
|
4071
4128
|
getMe(request, response) {
|
|
4072
|
-
const resource = this.repository.getMe(request
|
|
4129
|
+
const resource = this.repository.getMe(getRepositoryContext(request));
|
|
4073
4130
|
|
|
4074
4131
|
if (!resource) {
|
|
4075
4132
|
return response.status(404).send('Not found');
|
|
@@ -4080,7 +4137,7 @@ class MyCustomerService extends AbstractService {
|
|
|
4080
4137
|
|
|
4081
4138
|
signUp(request, response) {
|
|
4082
4139
|
const draft = request.body;
|
|
4083
|
-
const resource = this.repository.create(request
|
|
4140
|
+
const resource = this.repository.create(getRepositoryContext(request), draft);
|
|
4084
4141
|
|
|
4085
4142
|
const result = this._expandWithId(request, resource.id);
|
|
4086
4143
|
|
|
@@ -4095,7 +4152,7 @@ class MyCustomerService extends AbstractService {
|
|
|
4095
4152
|
password
|
|
4096
4153
|
} = request.body;
|
|
4097
4154
|
const encodedPassword = Buffer.from(password).toString('base64');
|
|
4098
|
-
const result = this.repository.query(request
|
|
4155
|
+
const result = this.repository.query(getRepositoryContext(request), {
|
|
4099
4156
|
where: [`email = "${email}"`, `password = "${encodedPassword}"`]
|
|
4100
4157
|
});
|
|
4101
4158
|
|
|
@@ -4116,10 +4173,22 @@ class MyCustomerService extends AbstractService {
|
|
|
4116
4173
|
|
|
4117
4174
|
}
|
|
4118
4175
|
|
|
4176
|
+
class MyOrderRepository extends OrderRepository {
|
|
4177
|
+
create(context, draft) {
|
|
4178
|
+
assert(draft.id, 'draft.id is missing');
|
|
4179
|
+
const cartIdentifier = {
|
|
4180
|
+
id: draft.id,
|
|
4181
|
+
typeId: 'cart'
|
|
4182
|
+
};
|
|
4183
|
+
return this.createFromCart(context, cartIdentifier);
|
|
4184
|
+
}
|
|
4185
|
+
|
|
4186
|
+
}
|
|
4187
|
+
|
|
4119
4188
|
class MyOrderService extends AbstractService {
|
|
4120
4189
|
constructor(parent, storage) {
|
|
4121
4190
|
super(parent);
|
|
4122
|
-
this.repository = new
|
|
4191
|
+
this.repository = new MyOrderRepository(storage);
|
|
4123
4192
|
}
|
|
4124
4193
|
|
|
4125
4194
|
getBasePath() {
|
|
@@ -4222,8 +4291,10 @@ class CommercetoolsMock {
|
|
|
4222
4291
|
|
|
4223
4292
|
if (this.options.enableAuthentication) {
|
|
4224
4293
|
app.use('/:projectKey', this._oauth2.createMiddleware(), projectRouter);
|
|
4294
|
+
app.use('/:projectKey/in-store/key=:storeKey', this._oauth2.createMiddleware(), projectRouter);
|
|
4225
4295
|
} else {
|
|
4226
4296
|
app.use('/:projectKey', projectRouter);
|
|
4297
|
+
app.use('/:projectKey/in-store/key=:storeKey', projectRouter);
|
|
4227
4298
|
}
|
|
4228
4299
|
|
|
4229
4300
|
this._projectService = new ProjectService(projectRouter, this._storage);
|