@labdigital/commercetools-mock 0.6.2 → 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 +86 -81
- 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 +61 -56
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/services/abstract.ts +1 -1
- package/src/services/cart.ts +1 -1
- package/src/services/custom-object.ts +1 -1
- package/src/services/customer.ts +1 -1
- package/src/services/my-customer.ts +1 -1
- package/src/services/order.ts +1 -1
- package/src/services/product-projection.ts +1 -1
- package/src/services/product-type.ts +1 -1
- package/src/services/project.ts +1 -1
- package/src/services/store.ts +1 -1
- package/src/services/tax-category.ts +1 -1
|
@@ -16,7 +16,6 @@ var auth = _interopDefault(require('basic-auth'));
|
|
|
16
16
|
var bodyParser = _interopDefault(require('body-parser'));
|
|
17
17
|
var crypto = require('crypto');
|
|
18
18
|
var uuid = require('uuid');
|
|
19
|
-
var helpers = require('repositories/helpers');
|
|
20
19
|
var deepEqual = _interopDefault(require('deep-equal'));
|
|
21
20
|
|
|
22
21
|
const parseExpandClause = clause => {
|
|
@@ -958,6 +957,67 @@ const copyHeaders = headers => {
|
|
|
958
957
|
const DEFAULT_API_HOSTNAME = /^https:\/\/api\..*?\.commercetools.com:443$/;
|
|
959
958
|
const DEFAULT_AUTH_HOSTNAME = /^https:\/\/auth\..*?\.commercetools.com:443$/;
|
|
960
959
|
|
|
960
|
+
const createCustomFields = (draft, projectKey, storage) => {
|
|
961
|
+
if (!draft) return undefined;
|
|
962
|
+
if (!draft.type) return undefined;
|
|
963
|
+
if (!draft.type.typeId) return undefined;
|
|
964
|
+
if (!draft.fields) return undefined;
|
|
965
|
+
const typeResource = storage.getByResourceIdentifier(projectKey, draft.type);
|
|
966
|
+
|
|
967
|
+
if (!typeResource) {
|
|
968
|
+
throw new Error(`No type '${draft.type.typeId}' with id=${draft.type.id} or key=${draft.type.key}`);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
return {
|
|
972
|
+
type: {
|
|
973
|
+
typeId: draft.type.typeId,
|
|
974
|
+
id: typeResource.id
|
|
975
|
+
},
|
|
976
|
+
fields: draft.fields
|
|
977
|
+
};
|
|
978
|
+
};
|
|
979
|
+
const createPrice = draft => {
|
|
980
|
+
return {
|
|
981
|
+
id: uuid.v4(),
|
|
982
|
+
value: createTypedMoney(draft.value)
|
|
983
|
+
};
|
|
984
|
+
};
|
|
985
|
+
const createTypedMoney = value => {
|
|
986
|
+
return {
|
|
987
|
+
type: 'centPrecision',
|
|
988
|
+
fractionDigits: 2,
|
|
989
|
+
...value
|
|
990
|
+
};
|
|
991
|
+
};
|
|
992
|
+
const resolveStoreReference = (ref, projectKey, storage) => {
|
|
993
|
+
if (!ref) return undefined;
|
|
994
|
+
const resource = storage.getByResourceIdentifier(projectKey, ref);
|
|
995
|
+
|
|
996
|
+
if (!resource) {
|
|
997
|
+
throw new Error('No such store');
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
const store = resource;
|
|
1001
|
+
return {
|
|
1002
|
+
typeId: 'store',
|
|
1003
|
+
key: store.key
|
|
1004
|
+
};
|
|
1005
|
+
};
|
|
1006
|
+
const getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storage) => {
|
|
1007
|
+
const resource = storage.getByResourceIdentifier(projectKey, resourceIdentifier);
|
|
1008
|
+
if (!resource) throw new Error(`resource type ${resourceIdentifier.typeId} with id ${resourceIdentifier.id} and key ${resourceIdentifier.key} not found`);
|
|
1009
|
+
return {
|
|
1010
|
+
typeId: resourceIdentifier.typeId,
|
|
1011
|
+
id: resource == null ? void 0 : resource.id
|
|
1012
|
+
};
|
|
1013
|
+
};
|
|
1014
|
+
const getRepositoryContext = request => {
|
|
1015
|
+
return {
|
|
1016
|
+
projectKey: request.params.projectKey,
|
|
1017
|
+
storeKey: request.params.storeKey
|
|
1018
|
+
};
|
|
1019
|
+
};
|
|
1020
|
+
|
|
961
1021
|
class AbstractService {
|
|
962
1022
|
constructor(parent) {
|
|
963
1023
|
this.createStatusCode = 201;
|
|
@@ -990,7 +1050,7 @@ class AbstractService {
|
|
|
990
1050
|
|
|
991
1051
|
const offset = this._parseParam(request.query.offset);
|
|
992
1052
|
|
|
993
|
-
const result = this.repository.query(
|
|
1053
|
+
const result = this.repository.query(getRepositoryContext(request), {
|
|
994
1054
|
expand: this._parseParam(request.query.expand),
|
|
995
1055
|
where: this._parseParam(request.query.where),
|
|
996
1056
|
limit: limit !== undefined ? Number(limit) : undefined,
|
|
@@ -1010,7 +1070,7 @@ class AbstractService {
|
|
|
1010
1070
|
}
|
|
1011
1071
|
|
|
1012
1072
|
getWithKey(request, response) {
|
|
1013
|
-
const result = this.repository.getByKey(
|
|
1073
|
+
const result = this.repository.getByKey(getRepositoryContext(request), request.params['key'], {
|
|
1014
1074
|
expand: this._parseParam(request.query.expand)
|
|
1015
1075
|
});
|
|
1016
1076
|
if (!result) return response.status(404).send();
|
|
@@ -1018,7 +1078,7 @@ class AbstractService {
|
|
|
1018
1078
|
}
|
|
1019
1079
|
|
|
1020
1080
|
deletewithId(request, response) {
|
|
1021
|
-
const result = this.repository.delete(
|
|
1081
|
+
const result = this.repository.delete(getRepositoryContext(request), request.params['id'], {
|
|
1022
1082
|
expand: this._parseParam(request.query.expand)
|
|
1023
1083
|
});
|
|
1024
1084
|
|
|
@@ -1035,7 +1095,7 @@ class AbstractService {
|
|
|
1035
1095
|
|
|
1036
1096
|
post(request, response) {
|
|
1037
1097
|
const draft = request.body;
|
|
1038
|
-
const resource = this.repository.create(
|
|
1098
|
+
const resource = this.repository.create(getRepositoryContext(request), draft);
|
|
1039
1099
|
|
|
1040
1100
|
const result = this._expandWithId(request, resource.id);
|
|
1041
1101
|
|
|
@@ -1044,7 +1104,7 @@ class AbstractService {
|
|
|
1044
1104
|
|
|
1045
1105
|
postWithId(request, response) {
|
|
1046
1106
|
const updateRequest = request.body;
|
|
1047
|
-
const resource = this.repository.get(
|
|
1107
|
+
const resource = this.repository.get(getRepositoryContext(request), request.params['id']);
|
|
1048
1108
|
|
|
1049
1109
|
if (!resource) {
|
|
1050
1110
|
return response.status(404).send('Not found');
|
|
@@ -1054,7 +1114,7 @@ class AbstractService {
|
|
|
1054
1114
|
return response.status(409).send('Concurrent modification');
|
|
1055
1115
|
}
|
|
1056
1116
|
|
|
1057
|
-
const updatedResource = this.repository.processUpdateActions(
|
|
1117
|
+
const updatedResource = this.repository.processUpdateActions(getRepositoryContext(request), resource, updateRequest.actions);
|
|
1058
1118
|
|
|
1059
1119
|
const result = this._expandWithId(request, updatedResource.id);
|
|
1060
1120
|
|
|
@@ -1066,7 +1126,7 @@ class AbstractService {
|
|
|
1066
1126
|
}
|
|
1067
1127
|
|
|
1068
1128
|
_expandWithId(request, resourceId) {
|
|
1069
|
-
const result = this.repository.get(
|
|
1129
|
+
const result = this.repository.get(getRepositoryContext(request), resourceId, {
|
|
1070
1130
|
expand: this._parseParam(request.query.expand)
|
|
1071
1131
|
});
|
|
1072
1132
|
return result;
|
|
@@ -1174,61 +1234,6 @@ class AbstractResourceRepository extends AbstractRepository {
|
|
|
1174
1234
|
|
|
1175
1235
|
}
|
|
1176
1236
|
|
|
1177
|
-
const createCustomFields = (draft, projectKey, storage) => {
|
|
1178
|
-
if (!draft) return undefined;
|
|
1179
|
-
if (!draft.type) return undefined;
|
|
1180
|
-
if (!draft.type.typeId) return undefined;
|
|
1181
|
-
if (!draft.fields) return undefined;
|
|
1182
|
-
const typeResource = storage.getByResourceIdentifier(projectKey, draft.type);
|
|
1183
|
-
|
|
1184
|
-
if (!typeResource) {
|
|
1185
|
-
throw new Error(`No type '${draft.type.typeId}' with id=${draft.type.id} or key=${draft.type.key}`);
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
return {
|
|
1189
|
-
type: {
|
|
1190
|
-
typeId: draft.type.typeId,
|
|
1191
|
-
id: typeResource.id
|
|
1192
|
-
},
|
|
1193
|
-
fields: draft.fields
|
|
1194
|
-
};
|
|
1195
|
-
};
|
|
1196
|
-
const createPrice = draft => {
|
|
1197
|
-
return {
|
|
1198
|
-
id: uuid.v4(),
|
|
1199
|
-
value: createTypedMoney(draft.value)
|
|
1200
|
-
};
|
|
1201
|
-
};
|
|
1202
|
-
const createTypedMoney = value => {
|
|
1203
|
-
return {
|
|
1204
|
-
type: 'centPrecision',
|
|
1205
|
-
fractionDigits: 2,
|
|
1206
|
-
...value
|
|
1207
|
-
};
|
|
1208
|
-
};
|
|
1209
|
-
const resolveStoreReference = (ref, projectKey, storage) => {
|
|
1210
|
-
if (!ref) return undefined;
|
|
1211
|
-
const resource = storage.getByResourceIdentifier(projectKey, ref);
|
|
1212
|
-
|
|
1213
|
-
if (!resource) {
|
|
1214
|
-
throw new Error('No such store');
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
const store = resource;
|
|
1218
|
-
return {
|
|
1219
|
-
typeId: 'store',
|
|
1220
|
-
key: store.key
|
|
1221
|
-
};
|
|
1222
|
-
};
|
|
1223
|
-
const getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storage) => {
|
|
1224
|
-
const resource = storage.getByResourceIdentifier(projectKey, resourceIdentifier);
|
|
1225
|
-
if (!resource) throw new Error(`resource type ${resourceIdentifier.typeId} with id ${resourceIdentifier.id} and key ${resourceIdentifier.key} not found`);
|
|
1226
|
-
return {
|
|
1227
|
-
typeId: resourceIdentifier.typeId,
|
|
1228
|
-
id: resource == null ? void 0 : resource.id
|
|
1229
|
-
};
|
|
1230
|
-
};
|
|
1231
|
-
|
|
1232
1237
|
class CartDiscountRepository extends AbstractResourceRepository {
|
|
1233
1238
|
constructor() {
|
|
1234
1239
|
super(...arguments);
|
|
@@ -2014,7 +2019,7 @@ class CartService extends AbstractService {
|
|
|
2014
2019
|
|
|
2015
2020
|
extraRoutes(parent) {
|
|
2016
2021
|
parent.post('/replicate', (request, response) => {
|
|
2017
|
-
const context =
|
|
2022
|
+
const context = getRepositoryContext(request); // @ts-ignore
|
|
2018
2023
|
|
|
2019
2024
|
const cartOrOrder = request.body.reference.typeId === 'order' ? this.orderRepository.get(context, request.body.reference.id) : this.repository.get(context, request.body.reference.id);
|
|
2020
2025
|
|
|
@@ -2299,7 +2304,7 @@ class CustomerService extends AbstractService {
|
|
|
2299
2304
|
|
|
2300
2305
|
extraRoutes(parent) {
|
|
2301
2306
|
parent.post('/password-token', (request, response) => {
|
|
2302
|
-
const customer = this.repository.query(
|
|
2307
|
+
const customer = this.repository.query(getRepositoryContext(request), {
|
|
2303
2308
|
where: [`email="${request.body.email}"`]
|
|
2304
2309
|
}); // @ts-ignore
|
|
2305
2310
|
|
|
@@ -2382,7 +2387,7 @@ class CustomObjectService extends AbstractService {
|
|
|
2382
2387
|
}
|
|
2383
2388
|
|
|
2384
2389
|
getWithContainerAndKey(request, response) {
|
|
2385
|
-
const result = this.repository.getWithContainerAndKey(
|
|
2390
|
+
const result = this.repository.getWithContainerAndKey(getRepositoryContext(request), request.params.container, request.params.key);
|
|
2386
2391
|
|
|
2387
2392
|
if (!result) {
|
|
2388
2393
|
return response.status(404).send('Not Found');
|
|
@@ -2396,18 +2401,18 @@ class CustomObjectService extends AbstractService {
|
|
|
2396
2401
|
key: request.params.key,
|
|
2397
2402
|
container: request.params.container
|
|
2398
2403
|
};
|
|
2399
|
-
const result = this.repository.create(
|
|
2404
|
+
const result = this.repository.create(getRepositoryContext(request), draft);
|
|
2400
2405
|
return response.status(200).send(result);
|
|
2401
2406
|
}
|
|
2402
2407
|
|
|
2403
2408
|
deleteWithContainerAndKey(request, response) {
|
|
2404
|
-
const current = this.repository.getWithContainerAndKey(
|
|
2409
|
+
const current = this.repository.getWithContainerAndKey(getRepositoryContext(request), request.params.container, request.params.key);
|
|
2405
2410
|
|
|
2406
2411
|
if (!current) {
|
|
2407
2412
|
return response.status(404).send('Not Found');
|
|
2408
2413
|
}
|
|
2409
2414
|
|
|
2410
|
-
const result = this.repository.delete(
|
|
2415
|
+
const result = this.repository.delete(getRepositoryContext(request), current.id);
|
|
2411
2416
|
return response.status(200).send(result);
|
|
2412
2417
|
}
|
|
2413
2418
|
|
|
@@ -2829,12 +2834,12 @@ class OrderService extends AbstractService {
|
|
|
2829
2834
|
|
|
2830
2835
|
import(request, response) {
|
|
2831
2836
|
const importDraft = request.body;
|
|
2832
|
-
const resource = this.repository.import(
|
|
2837
|
+
const resource = this.repository.import(getRepositoryContext(request), importDraft);
|
|
2833
2838
|
return response.status(200).send(resource);
|
|
2834
2839
|
}
|
|
2835
2840
|
|
|
2836
2841
|
getWithOrderNumber(request, response) {
|
|
2837
|
-
const resource = this.repository.getWithOrderNumber(
|
|
2842
|
+
const resource = this.repository.getWithOrderNumber(getRepositoryContext(request), request.params.orderNumber, request.query);
|
|
2838
2843
|
|
|
2839
2844
|
if (resource) {
|
|
2840
2845
|
return response.status(200).send(resource);
|
|
@@ -2956,7 +2961,7 @@ class ProductProjectionService extends AbstractService {
|
|
|
2956
2961
|
}
|
|
2957
2962
|
|
|
2958
2963
|
search(request, response) {
|
|
2959
|
-
const resource = this.repository.search(
|
|
2964
|
+
const resource = this.repository.search(getRepositoryContext(request), request.query);
|
|
2960
2965
|
return response.status(200).send(resource);
|
|
2961
2966
|
}
|
|
2962
2967
|
|
|
@@ -3228,7 +3233,7 @@ class ProductTypeService extends AbstractService {
|
|
|
3228
3233
|
}
|
|
3229
3234
|
|
|
3230
3235
|
getWithKey(request, response) {
|
|
3231
|
-
const resource = this.repository.getWithKey(
|
|
3236
|
+
const resource = this.repository.getWithKey(getRepositoryContext(request), request.params.key);
|
|
3232
3237
|
|
|
3233
3238
|
if (resource) {
|
|
3234
3239
|
return response.status(200).send(resource);
|
|
@@ -3381,19 +3386,19 @@ class ProjectService {
|
|
|
3381
3386
|
}
|
|
3382
3387
|
|
|
3383
3388
|
get(request, response) {
|
|
3384
|
-
const project = this.repository.get(
|
|
3389
|
+
const project = this.repository.get(getRepositoryContext(request));
|
|
3385
3390
|
return response.status(200).send(project);
|
|
3386
3391
|
}
|
|
3387
3392
|
|
|
3388
3393
|
post(request, response) {
|
|
3389
3394
|
const updateRequest = request.body;
|
|
3390
|
-
const project = this.repository.get(
|
|
3395
|
+
const project = this.repository.get(getRepositoryContext(request));
|
|
3391
3396
|
|
|
3392
3397
|
if (!project) {
|
|
3393
3398
|
return response.status(404).send({});
|
|
3394
3399
|
}
|
|
3395
3400
|
|
|
3396
|
-
this.repository.processUpdateActions(
|
|
3401
|
+
this.repository.processUpdateActions(getRepositoryContext(request), project, updateRequest.actions);
|
|
3397
3402
|
return response.status(200).send({});
|
|
3398
3403
|
}
|
|
3399
3404
|
|
|
@@ -3730,7 +3735,7 @@ class StoreService extends AbstractService {
|
|
|
3730
3735
|
}
|
|
3731
3736
|
|
|
3732
3737
|
getWithKey(request, response) {
|
|
3733
|
-
const resource = this.repository.getWithKey(
|
|
3738
|
+
const resource = this.repository.getWithKey(getRepositoryContext(request), request.params.key);
|
|
3734
3739
|
|
|
3735
3740
|
if (resource) {
|
|
3736
3741
|
return response.status(200).send(resource);
|
|
@@ -3905,7 +3910,7 @@ class TaxCategoryService extends AbstractService {
|
|
|
3905
3910
|
}
|
|
3906
3911
|
|
|
3907
3912
|
getWithKey(request, response) {
|
|
3908
|
-
const resource = this.repository.getWithKey(
|
|
3913
|
+
const resource = this.repository.getWithKey(getRepositoryContext(request), request.params.key);
|
|
3909
3914
|
|
|
3910
3915
|
if (resource) {
|
|
3911
3916
|
return response.status(200).send(resource);
|
|
@@ -4128,7 +4133,7 @@ class MyCustomerService extends AbstractService {
|
|
|
4128
4133
|
}
|
|
4129
4134
|
|
|
4130
4135
|
getMe(request, response) {
|
|
4131
|
-
const resource = this.repository.getMe(
|
|
4136
|
+
const resource = this.repository.getMe(getRepositoryContext(request));
|
|
4132
4137
|
|
|
4133
4138
|
if (!resource) {
|
|
4134
4139
|
return response.status(404).send('Not found');
|
|
@@ -4139,7 +4144,7 @@ class MyCustomerService extends AbstractService {
|
|
|
4139
4144
|
|
|
4140
4145
|
signUp(request, response) {
|
|
4141
4146
|
const draft = request.body;
|
|
4142
|
-
const resource = this.repository.create(
|
|
4147
|
+
const resource = this.repository.create(getRepositoryContext(request), draft);
|
|
4143
4148
|
|
|
4144
4149
|
const result = this._expandWithId(request, resource.id);
|
|
4145
4150
|
|
|
@@ -4154,7 +4159,7 @@ class MyCustomerService extends AbstractService {
|
|
|
4154
4159
|
password
|
|
4155
4160
|
} = request.body;
|
|
4156
4161
|
const encodedPassword = Buffer.from(password).toString('base64');
|
|
4157
|
-
const result = this.repository.query(
|
|
4162
|
+
const result = this.repository.query(getRepositoryContext(request), {
|
|
4158
4163
|
where: [`email = "${email}"`, `password = "${encodedPassword}"`]
|
|
4159
4164
|
});
|
|
4160
4165
|
|