@labdigital/commercetools-mock 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +353 -188
- package/dist/index.global.js +1007 -876
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +348 -217
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +348 -217
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/ctMock.ts +15 -9
- package/src/helpers.ts +1 -1
- package/src/lib/projectionSearchFilter.ts +3 -2
- package/src/priceSelector.test.ts +1 -3
- package/src/product-projection-search.ts +1 -3
- package/src/projectAPI.test.ts +7 -0
- package/src/projectAPI.ts +17 -22
- package/src/repositories/abstract.ts +31 -24
- package/src/repositories/cart-discount.ts +3 -4
- package/src/repositories/cart.ts +20 -15
- package/src/repositories/category.ts +6 -7
- package/src/repositories/channel.ts +4 -5
- package/src/repositories/custom-object.ts +9 -13
- package/src/repositories/customer-group.ts +3 -4
- package/src/repositories/customer.ts +4 -5
- package/src/repositories/discount-code.ts +4 -5
- package/src/repositories/errors.ts +1 -3
- package/src/repositories/extension.ts +7 -8
- package/src/repositories/helpers.ts +2 -2
- package/src/repositories/index.ts +19 -3
- package/src/repositories/inventory-entry.ts +4 -5
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/order-edit.ts +39 -0
- package/src/repositories/order.test.ts +16 -11
- package/src/repositories/order.ts +15 -8
- package/src/repositories/payment.ts +6 -7
- package/src/repositories/product-discount.ts +4 -24
- package/src/repositories/product-projection.ts +11 -5
- package/src/repositories/product-selection.ts +40 -0
- package/src/repositories/product-type.ts +11 -28
- package/src/repositories/product.ts +117 -10
- package/src/repositories/project.ts +9 -8
- package/src/repositories/quote-request.ts +28 -0
- package/src/repositories/quote.ts +28 -0
- package/src/repositories/review.ts +34 -0
- package/src/repositories/shipping-method.ts +10 -11
- package/src/repositories/shopping-list.ts +4 -4
- package/src/repositories/staged-quote.ts +29 -0
- package/src/repositories/standalone-price.ts +36 -0
- package/src/repositories/state.ts +15 -8
- package/src/repositories/store.ts +11 -27
- package/src/repositories/subscription.ts +3 -4
- package/src/repositories/tax-category.ts +5 -22
- package/src/repositories/type.ts +12 -13
- package/src/repositories/zone.ts +4 -5
- package/src/server.ts +4 -4
- package/src/services/abstract.ts +3 -5
- package/src/services/cart-discount.ts +1 -1
- package/src/services/cart.test.ts +1 -1
- package/src/services/cart.ts +40 -33
- package/src/services/category.ts +1 -1
- package/src/services/channel.ts +1 -1
- package/src/services/custom-object.test.ts +1 -1
- package/src/services/custom-object.ts +2 -2
- package/src/services/customer-group.ts +1 -1
- package/src/services/customer.test.ts +1 -1
- package/src/services/customer.ts +3 -3
- package/src/services/discount-code.ts +1 -1
- package/src/services/extension.ts +1 -1
- package/src/services/inventory-entry.test.ts +1 -1
- package/src/services/inventory-entry.ts +1 -1
- package/src/services/my-cart.test.ts +2 -0
- package/src/services/my-cart.ts +1 -1
- package/src/services/my-customer.ts +1 -1
- package/src/services/my-order.ts +1 -1
- package/src/services/my-payment.ts +1 -1
- package/src/services/order.test.ts +24 -20
- package/src/services/order.ts +2 -2
- package/src/services/payment.ts +1 -1
- package/src/services/product-discount.ts +1 -17
- package/src/services/product-projection.test.ts +1 -1
- package/src/services/product-projection.ts +2 -2
- package/src/services/product-type.ts +1 -17
- package/src/services/product.test.ts +63 -2
- package/src/services/product.ts +1 -1
- package/src/services/project.ts +4 -5
- package/src/services/shipping-method.ts +1 -1
- package/src/services/shopping-list.ts +1 -1
- package/src/services/state.ts +1 -1
- package/src/services/store.ts +2 -18
- package/src/services/subscription.ts +1 -1
- package/src/services/tax-category.ts +1 -17
- package/src/services/type.ts +1 -1
- package/src/services/zone.ts +1 -1
- package/src/storage/abstract.ts +82 -0
- package/src/{storage.ts → storage/in-memory.ts} +57 -118
- package/src/storage/index.ts +2 -0
- package/src/types.ts +48 -119
package/dist/index.mjs
CHANGED
|
@@ -4,9 +4,56 @@ import express2 from "express";
|
|
|
4
4
|
import supertest from "supertest";
|
|
5
5
|
import morgan from "morgan";
|
|
6
6
|
|
|
7
|
-
// src/storage.ts
|
|
7
|
+
// src/storage/abstract.ts
|
|
8
|
+
var AbstractStorage = class {
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/storage/in-memory.ts
|
|
8
12
|
import assert from "assert";
|
|
9
13
|
|
|
14
|
+
// src/exceptions.ts
|
|
15
|
+
var CommercetoolsError = class extends Error {
|
|
16
|
+
constructor(info, statusCode = 400) {
|
|
17
|
+
super(info.message);
|
|
18
|
+
this.info = info;
|
|
19
|
+
this.statusCode = statusCode || 500;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/helpers.ts
|
|
24
|
+
import { v4 as uuidv4 } from "uuid";
|
|
25
|
+
var getBaseResourceProperties = () => ({
|
|
26
|
+
id: uuidv4(),
|
|
27
|
+
createdAt: new Date().toISOString(),
|
|
28
|
+
lastModifiedAt: new Date().toISOString(),
|
|
29
|
+
version: 0
|
|
30
|
+
});
|
|
31
|
+
var nestedLookup = (obj, path) => {
|
|
32
|
+
if (!path || path === "") {
|
|
33
|
+
return obj;
|
|
34
|
+
}
|
|
35
|
+
const parts = path.split(".");
|
|
36
|
+
let val = obj;
|
|
37
|
+
for (let i = 0; i < parts.length; i++) {
|
|
38
|
+
const part = parts[i];
|
|
39
|
+
if (val == void 0) {
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
val = val[part];
|
|
43
|
+
}
|
|
44
|
+
return val;
|
|
45
|
+
};
|
|
46
|
+
var QueryParamsAsArray = (input) => {
|
|
47
|
+
if (input == void 0) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(input)) {
|
|
51
|
+
return input;
|
|
52
|
+
}
|
|
53
|
+
return [input];
|
|
54
|
+
};
|
|
55
|
+
var cloneObject = (o) => JSON.parse(JSON.stringify(o));
|
|
56
|
+
|
|
10
57
|
// src/lib/expandParser.ts
|
|
11
58
|
var parseExpandClause = (clause) => {
|
|
12
59
|
const result = {
|
|
@@ -324,52 +371,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
324
371
|
return result;
|
|
325
372
|
};
|
|
326
373
|
|
|
327
|
-
// src/
|
|
328
|
-
var CommercetoolsError = class extends Error {
|
|
329
|
-
constructor(info, statusCode = 400) {
|
|
330
|
-
super(info.message);
|
|
331
|
-
this.info = info;
|
|
332
|
-
this.statusCode = statusCode || 500;
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
// src/helpers.ts
|
|
337
|
-
import { v4 as uuidv4 } from "uuid";
|
|
338
|
-
var getBaseResourceProperties = () => ({
|
|
339
|
-
id: uuidv4(),
|
|
340
|
-
createdAt: new Date().toISOString(),
|
|
341
|
-
lastModifiedAt: new Date().toISOString(),
|
|
342
|
-
version: 0
|
|
343
|
-
});
|
|
344
|
-
var nestedLookup = (obj, path) => {
|
|
345
|
-
if (!path || path === "") {
|
|
346
|
-
return obj;
|
|
347
|
-
}
|
|
348
|
-
const parts = path.split(".");
|
|
349
|
-
let val = obj;
|
|
350
|
-
for (let i = 0; i < parts.length; i++) {
|
|
351
|
-
const part = parts[i];
|
|
352
|
-
if (val == void 0) {
|
|
353
|
-
return void 0;
|
|
354
|
-
}
|
|
355
|
-
val = val[part];
|
|
356
|
-
}
|
|
357
|
-
return val;
|
|
358
|
-
};
|
|
359
|
-
var QueryParamsAsArray = (input) => {
|
|
360
|
-
if (input == void 0) {
|
|
361
|
-
return [];
|
|
362
|
-
}
|
|
363
|
-
if (Array.isArray(input)) {
|
|
364
|
-
return input;
|
|
365
|
-
}
|
|
366
|
-
return [input];
|
|
367
|
-
};
|
|
368
|
-
var cloneObject = (o) => JSON.parse(JSON.stringify(o));
|
|
369
|
-
|
|
370
|
-
// src/storage.ts
|
|
371
|
-
var AbstractStorage = class {
|
|
372
|
-
};
|
|
374
|
+
// src/storage/in-memory.ts
|
|
373
375
|
var InMemoryStorage = class extends AbstractStorage {
|
|
374
376
|
constructor() {
|
|
375
377
|
super(...arguments);
|
|
@@ -465,13 +467,15 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
465
467
|
"order-edit": /* @__PURE__ */ new Map(),
|
|
466
468
|
payment: /* @__PURE__ */ new Map(),
|
|
467
469
|
product: /* @__PURE__ */ new Map(),
|
|
470
|
+
quote: /* @__PURE__ */ new Map(),
|
|
471
|
+
"quote-request": /* @__PURE__ */ new Map(),
|
|
468
472
|
"product-discount": /* @__PURE__ */ new Map(),
|
|
469
|
-
"product-price": /* @__PURE__ */ new Map(),
|
|
470
473
|
"product-selection": /* @__PURE__ */ new Map(),
|
|
471
474
|
"product-type": /* @__PURE__ */ new Map(),
|
|
472
475
|
"product-projection": /* @__PURE__ */ new Map(),
|
|
473
476
|
review: /* @__PURE__ */ new Map(),
|
|
474
477
|
"shipping-method": /* @__PURE__ */ new Map(),
|
|
478
|
+
"staged-quote": /* @__PURE__ */ new Map(),
|
|
475
479
|
state: /* @__PURE__ */ new Map(),
|
|
476
480
|
store: /* @__PURE__ */ new Map(),
|
|
477
481
|
"shopping-list": /* @__PURE__ */ new Map(),
|
|
@@ -543,7 +547,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
543
547
|
if (!store) {
|
|
544
548
|
throw new Error("No type");
|
|
545
549
|
}
|
|
546
|
-
let resources =
|
|
550
|
+
let resources = this.all(projectKey, typeId);
|
|
547
551
|
if (params.where) {
|
|
548
552
|
try {
|
|
549
553
|
const filterFunc = parseQueryExpression(params.where);
|
|
@@ -617,7 +621,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
617
621
|
console.error(
|
|
618
622
|
`No resource found with typeId=${identifier.typeId}, id=${identifier.id}`
|
|
619
623
|
);
|
|
620
|
-
return
|
|
624
|
+
return null;
|
|
621
625
|
}
|
|
622
626
|
if (identifier.key) {
|
|
623
627
|
const store = this.forProjectKey(projectKey)[identifier.typeId];
|
|
@@ -634,7 +638,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
634
638
|
);
|
|
635
639
|
}
|
|
636
640
|
}
|
|
637
|
-
return
|
|
641
|
+
return null;
|
|
638
642
|
}
|
|
639
643
|
_resolveReference(projectKey, reference, expand) {
|
|
640
644
|
if (reference === void 0)
|
|
@@ -801,14 +805,14 @@ var OAuth2Server = class {
|
|
|
801
805
|
|
|
802
806
|
// src/projectAPI.ts
|
|
803
807
|
var ProjectAPI = class {
|
|
804
|
-
constructor(projectKey,
|
|
808
|
+
constructor(projectKey, repositories, storage) {
|
|
805
809
|
this.projectKey = projectKey;
|
|
806
810
|
this._storage = storage;
|
|
807
|
-
this.
|
|
811
|
+
this._repositories = repositories;
|
|
808
812
|
}
|
|
809
813
|
add(typeId, resource) {
|
|
810
|
-
const
|
|
811
|
-
if (
|
|
814
|
+
const repository = this._repositories[typeId];
|
|
815
|
+
if (repository) {
|
|
812
816
|
this._storage.add(this.projectKey, typeId, {
|
|
813
817
|
...getBaseResourceProperties(),
|
|
814
818
|
...resource
|
|
@@ -826,9 +830,9 @@ var ProjectAPI = class {
|
|
|
826
830
|
);
|
|
827
831
|
}
|
|
828
832
|
getRepository(typeId) {
|
|
829
|
-
const
|
|
830
|
-
if (
|
|
831
|
-
return
|
|
833
|
+
const repository = this._repositories[typeId];
|
|
834
|
+
if (repository !== void 0) {
|
|
835
|
+
return repository;
|
|
832
836
|
}
|
|
833
837
|
throw new Error("No such repository");
|
|
834
838
|
}
|
|
@@ -998,13 +1002,13 @@ var ProjectService = class {
|
|
|
998
1002
|
if (!project) {
|
|
999
1003
|
return response.status(404).send({});
|
|
1000
1004
|
}
|
|
1001
|
-
this.repository.processUpdateActions(
|
|
1005
|
+
const updatedResource = this.repository.processUpdateActions(
|
|
1002
1006
|
getRepositoryContext(request),
|
|
1003
1007
|
project,
|
|
1004
1008
|
updateRequest.version,
|
|
1005
1009
|
updateRequest.actions
|
|
1006
1010
|
);
|
|
1007
|
-
return response.status(200).send(
|
|
1011
|
+
return response.status(200).send(updatedResource);
|
|
1008
1012
|
}
|
|
1009
1013
|
};
|
|
1010
1014
|
|
|
@@ -1064,14 +1068,14 @@ var AbstractRepository = class {
|
|
|
1064
1068
|
}
|
|
1065
1069
|
return result;
|
|
1066
1070
|
}
|
|
1067
|
-
postProcessResource(resource) {
|
|
1068
|
-
return resource;
|
|
1069
|
-
}
|
|
1070
1071
|
};
|
|
1071
1072
|
var AbstractResourceRepository = class extends AbstractRepository {
|
|
1072
1073
|
constructor(storage) {
|
|
1073
1074
|
super(storage);
|
|
1074
1075
|
}
|
|
1076
|
+
postProcessResource(resource) {
|
|
1077
|
+
return resource;
|
|
1078
|
+
}
|
|
1075
1079
|
query(context, params = {}) {
|
|
1076
1080
|
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
1077
1081
|
expand: params.expand,
|
|
@@ -1218,11 +1222,13 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1218
1222
|
id: uuidv43(),
|
|
1219
1223
|
productId: product.id,
|
|
1220
1224
|
productKey: product.key,
|
|
1221
|
-
name: product.masterData.current.name,
|
|
1222
1225
|
productSlug: product.masterData.current.slug,
|
|
1223
1226
|
productType: product.productType,
|
|
1227
|
+
name: product.masterData.current.name,
|
|
1224
1228
|
variant,
|
|
1225
1229
|
price,
|
|
1230
|
+
taxedPricePortions: [],
|
|
1231
|
+
perMethodTaxRate: [],
|
|
1226
1232
|
totalPrice: {
|
|
1227
1233
|
...price.value,
|
|
1228
1234
|
centAmount: price.value.centAmount * quantity
|
|
@@ -1369,15 +1375,17 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1369
1375
|
id: uuidv43(),
|
|
1370
1376
|
productId: product.id,
|
|
1371
1377
|
productKey: product.key,
|
|
1372
|
-
name: product.masterData.current.name,
|
|
1373
1378
|
productSlug: product.masterData.current.slug,
|
|
1374
1379
|
productType: product.productType,
|
|
1380
|
+
name: product.masterData.current.name,
|
|
1375
1381
|
variant,
|
|
1376
1382
|
price,
|
|
1377
1383
|
totalPrice: {
|
|
1378
1384
|
...price.value,
|
|
1379
1385
|
centAmount: price.value.centAmount * quant
|
|
1380
1386
|
},
|
|
1387
|
+
taxedPricePortions: [],
|
|
1388
|
+
perMethodTaxRate: [],
|
|
1381
1389
|
quantity: quant,
|
|
1382
1390
|
discountedPricePerQuantity: [],
|
|
1383
1391
|
lineItemMode: "Standard",
|
|
@@ -1402,21 +1410,23 @@ var CartRepository = class extends AbstractResourceRepository {
|
|
|
1402
1410
|
const resource = {
|
|
1403
1411
|
...getBaseResourceProperties(),
|
|
1404
1412
|
cartState: "Active",
|
|
1405
|
-
|
|
1413
|
+
country: draft.country,
|
|
1406
1414
|
customLineItems: [],
|
|
1415
|
+
lineItems,
|
|
1416
|
+
locale: draft.locale,
|
|
1417
|
+
taxCalculationMode: draft.taxCalculationMode ?? "LineItemLevel",
|
|
1418
|
+
taxMode: draft.taxMode ?? "Platform",
|
|
1419
|
+
taxRoundingMode: draft.taxRoundingMode ?? "HalfEven",
|
|
1407
1420
|
totalPrice: {
|
|
1408
1421
|
type: "centPrecision",
|
|
1409
1422
|
centAmount: 0,
|
|
1410
1423
|
currencyCode: draft.currency,
|
|
1411
1424
|
fractionDigits: 0
|
|
1412
1425
|
},
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
taxCalculationMode: draft.taxCalculationMode ?? "LineItemLevel",
|
|
1416
|
-
refusedGifts: [],
|
|
1417
|
-
locale: draft.locale,
|
|
1418
|
-
country: draft.country,
|
|
1426
|
+
shippingMode: "Single",
|
|
1427
|
+
shipping: [],
|
|
1419
1428
|
origin: draft.origin ?? "Customer",
|
|
1429
|
+
refusedGifts: [],
|
|
1420
1430
|
custom: createCustomFields(
|
|
1421
1431
|
draft.custom,
|
|
1422
1432
|
context.projectKey,
|
|
@@ -1770,10 +1780,7 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
1770
1780
|
}
|
|
1771
1781
|
}
|
|
1772
1782
|
getWithContainerAndKey(context, container, key) {
|
|
1773
|
-
const items = this._storage.all(
|
|
1774
|
-
context.projectKey,
|
|
1775
|
-
this.getTypeId()
|
|
1776
|
-
);
|
|
1783
|
+
const items = this._storage.all(context.projectKey, this.getTypeId());
|
|
1777
1784
|
return items.find(
|
|
1778
1785
|
(item) => item.container === container && item.key === key
|
|
1779
1786
|
);
|
|
@@ -1880,7 +1887,7 @@ var CustomerGroupRepository = class extends AbstractResourceRepository {
|
|
|
1880
1887
|
};
|
|
1881
1888
|
}
|
|
1882
1889
|
getTypeId() {
|
|
1883
|
-
return "customer";
|
|
1890
|
+
return "customer-group";
|
|
1884
1891
|
}
|
|
1885
1892
|
create(context, draft) {
|
|
1886
1893
|
const resource = {
|
|
@@ -1965,7 +1972,7 @@ var DiscountCodeRepository = class extends AbstractResourceRepository {
|
|
|
1965
1972
|
};
|
|
1966
1973
|
}
|
|
1967
1974
|
getTypeId() {
|
|
1968
|
-
return "
|
|
1975
|
+
return "discount-code";
|
|
1969
1976
|
}
|
|
1970
1977
|
create(context, draft) {
|
|
1971
1978
|
const resource = {
|
|
@@ -2276,6 +2283,8 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2276
2283
|
refusedGifts: [],
|
|
2277
2284
|
origin: "Customer",
|
|
2278
2285
|
syncInfo: [],
|
|
2286
|
+
shippingMode: cart.shippingMode,
|
|
2287
|
+
shipping: cart.shipping,
|
|
2279
2288
|
store: context.storeKey ? {
|
|
2280
2289
|
key: context.storeKey,
|
|
2281
2290
|
typeId: "store"
|
|
@@ -2304,6 +2313,8 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2304
2313
|
origin: draft.origin || "Customer",
|
|
2305
2314
|
paymentState: draft.paymentState,
|
|
2306
2315
|
refusedGifts: [],
|
|
2316
|
+
shippingMode: "Single",
|
|
2317
|
+
shipping: [],
|
|
2307
2318
|
store: resolveStoreReference(
|
|
2308
2319
|
draft.store,
|
|
2309
2320
|
context.projectKey,
|
|
@@ -2375,6 +2386,8 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2375
2386
|
quantity: draft.quantity,
|
|
2376
2387
|
state: draft.state || [],
|
|
2377
2388
|
taxRate: draft.taxRate,
|
|
2389
|
+
taxedPricePortions: [],
|
|
2390
|
+
perMethodTaxRate: [],
|
|
2378
2391
|
totalPrice: createTypedMoney(draft.price.value),
|
|
2379
2392
|
variant: {
|
|
2380
2393
|
id: variant.id,
|
|
@@ -2396,6 +2409,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
2396
2409
|
money: createTypedMoney(draft.money),
|
|
2397
2410
|
name: draft.name,
|
|
2398
2411
|
quantity: draft.quantity,
|
|
2412
|
+
priceMode: draft.priceMode,
|
|
2399
2413
|
slug: draft.slug,
|
|
2400
2414
|
state: [],
|
|
2401
2415
|
totalPrice: createTypedMoney(draft.money)
|
|
@@ -2429,6 +2443,29 @@ var MyOrderRepository = class extends OrderRepository {
|
|
|
2429
2443
|
}
|
|
2430
2444
|
};
|
|
2431
2445
|
|
|
2446
|
+
// src/repositories/order-edit.ts
|
|
2447
|
+
var OrderEditRepository = class extends AbstractResourceRepository {
|
|
2448
|
+
constructor() {
|
|
2449
|
+
super(...arguments);
|
|
2450
|
+
this.actions = {};
|
|
2451
|
+
}
|
|
2452
|
+
getTypeId() {
|
|
2453
|
+
return "order-edit";
|
|
2454
|
+
}
|
|
2455
|
+
create(context, draft) {
|
|
2456
|
+
const resource = {
|
|
2457
|
+
...getBaseResourceProperties(),
|
|
2458
|
+
stagedActions: draft.stagedActions ?? [],
|
|
2459
|
+
resource: draft.resource,
|
|
2460
|
+
result: {
|
|
2461
|
+
type: "NotProcessed"
|
|
2462
|
+
}
|
|
2463
|
+
};
|
|
2464
|
+
this.saveNew(context, resource);
|
|
2465
|
+
return resource;
|
|
2466
|
+
}
|
|
2467
|
+
};
|
|
2468
|
+
|
|
2432
2469
|
// src/repositories/payment.ts
|
|
2433
2470
|
import { v4 as uuidv45 } from "uuid";
|
|
2434
2471
|
var PaymentRepository = class extends AbstractResourceRepository {
|
|
@@ -2588,7 +2625,7 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2588
2625
|
checkForStagedChanges(resource);
|
|
2589
2626
|
return resource;
|
|
2590
2627
|
},
|
|
2591
|
-
|
|
2628
|
+
setDescription: (context, resource, { description, staged }) => {
|
|
2592
2629
|
const onlyStaged = staged !== void 0 ? staged : true;
|
|
2593
2630
|
resource.masterData.staged.description = description;
|
|
2594
2631
|
if (!onlyStaged) {
|
|
@@ -2597,9 +2634,80 @@ var ProductRepository = class extends AbstractResourceRepository {
|
|
|
2597
2634
|
checkForStagedChanges(resource);
|
|
2598
2635
|
return resource;
|
|
2599
2636
|
},
|
|
2600
|
-
|
|
2637
|
+
setKey: (context, resource, { key }) => {
|
|
2601
2638
|
resource.key = key;
|
|
2602
2639
|
return resource;
|
|
2640
|
+
},
|
|
2641
|
+
addExternalImage: (context, resource, { variantId, sku, image, staged }) => {
|
|
2642
|
+
const addImg = (data) => {
|
|
2643
|
+
const { variant, isMasterVariant, variantIndex } = getVariant(
|
|
2644
|
+
data,
|
|
2645
|
+
variantId,
|
|
2646
|
+
sku
|
|
2647
|
+
);
|
|
2648
|
+
if (!variant) {
|
|
2649
|
+
throw new Error(
|
|
2650
|
+
`Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2653
|
+
if (!variant.images) {
|
|
2654
|
+
variant.images = [];
|
|
2655
|
+
} else {
|
|
2656
|
+
const existingImage = variant.images.find((x) => x.url === image.url);
|
|
2657
|
+
if (existingImage) {
|
|
2658
|
+
throw new Error(
|
|
2659
|
+
`Cannot add image '${image.url}' because product '${resource.id}' already has that image.`
|
|
2660
|
+
);
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
variant.images.push(image);
|
|
2664
|
+
if (isMasterVariant) {
|
|
2665
|
+
data.masterVariant = variant;
|
|
2666
|
+
} else {
|
|
2667
|
+
data.variants[variantIndex] = variant;
|
|
2668
|
+
}
|
|
2669
|
+
};
|
|
2670
|
+
const onlyStaged = staged !== void 0 ? staged : true;
|
|
2671
|
+
addImg(resource.masterData.staged);
|
|
2672
|
+
if (!onlyStaged) {
|
|
2673
|
+
addImg(resource.masterData.current);
|
|
2674
|
+
}
|
|
2675
|
+
checkForStagedChanges(resource);
|
|
2676
|
+
return resource;
|
|
2677
|
+
},
|
|
2678
|
+
removeImage: (context, resource, { variantId, sku, imageUrl, staged }) => {
|
|
2679
|
+
const removeImg = (data) => {
|
|
2680
|
+
const { variant, isMasterVariant, variantIndex } = getVariant(
|
|
2681
|
+
data,
|
|
2682
|
+
variantId,
|
|
2683
|
+
sku
|
|
2684
|
+
);
|
|
2685
|
+
if (!variant) {
|
|
2686
|
+
throw new Error(
|
|
2687
|
+
`Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
|
|
2688
|
+
);
|
|
2689
|
+
}
|
|
2690
|
+
const variantImages = variant.images ?? [];
|
|
2691
|
+
const existingImage = variantImages.find((x) => x.url === imageUrl);
|
|
2692
|
+
if (!existingImage) {
|
|
2693
|
+
throw new Error(
|
|
2694
|
+
`Cannot remove image '${imageUrl}' because product '${resource.id}' does not have that image.`
|
|
2695
|
+
);
|
|
2696
|
+
}
|
|
2697
|
+
variant.images = variantImages.filter((image) => image.url !== imageUrl);
|
|
2698
|
+
if (isMasterVariant) {
|
|
2699
|
+
data.masterVariant = variant;
|
|
2700
|
+
} else {
|
|
2701
|
+
data.variants[variantIndex] = variant;
|
|
2702
|
+
}
|
|
2703
|
+
};
|
|
2704
|
+
const onlyStaged = staged !== void 0 ? staged : true;
|
|
2705
|
+
removeImg(resource.masterData.staged);
|
|
2706
|
+
if (!onlyStaged) {
|
|
2707
|
+
removeImg(resource.masterData.current);
|
|
2708
|
+
}
|
|
2709
|
+
checkForStagedChanges(resource);
|
|
2710
|
+
return resource;
|
|
2603
2711
|
}
|
|
2604
2712
|
};
|
|
2605
2713
|
}
|
|
@@ -2783,18 +2891,6 @@ var ProductDiscountRepository = class extends AbstractResourceRepository {
|
|
|
2783
2891
|
}
|
|
2784
2892
|
}
|
|
2785
2893
|
}
|
|
2786
|
-
getWithKey(context, key) {
|
|
2787
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
2788
|
-
where: [`key="${key}"`]
|
|
2789
|
-
});
|
|
2790
|
-
if (result.count === 1) {
|
|
2791
|
-
return result.results[0];
|
|
2792
|
-
}
|
|
2793
|
-
if (result.count > 1) {
|
|
2794
|
-
throw new Error("Duplicate product discount key");
|
|
2795
|
-
}
|
|
2796
|
-
return;
|
|
2797
|
-
}
|
|
2798
2894
|
};
|
|
2799
2895
|
|
|
2800
2896
|
// src/lib/projectionSearchFilter.ts
|
|
@@ -3042,7 +3138,7 @@ var ProductProjectionSearch = class {
|
|
|
3042
3138
|
this._storage = storage;
|
|
3043
3139
|
}
|
|
3044
3140
|
search(projectKey, params) {
|
|
3045
|
-
let resources = this._storage.all(projectKey, "product").map((r) => this.transform(r, params.staged ?? false)).filter((p) =>
|
|
3141
|
+
let resources = this._storage.all(projectKey, "product").map((r) => this.transform(r, params.staged ?? false)).filter((p) => {
|
|
3046
3142
|
if (!params.staged) {
|
|
3047
3143
|
return p.published;
|
|
3048
3144
|
}
|
|
@@ -3109,8 +3205,6 @@ var ProductProjectionSearch = class {
|
|
|
3109
3205
|
}
|
|
3110
3206
|
transform(product, staged) {
|
|
3111
3207
|
const obj = !staged ? product.masterData.current : product.masterData.staged;
|
|
3112
|
-
if (!obj)
|
|
3113
|
-
return null;
|
|
3114
3208
|
return {
|
|
3115
3209
|
id: product.id,
|
|
3116
3210
|
createdAt: product.createdAt,
|
|
@@ -3282,12 +3376,18 @@ var ProductProjectionRepository = class extends AbstractResourceRepository {
|
|
|
3282
3376
|
throw new Error("No valid action");
|
|
3283
3377
|
}
|
|
3284
3378
|
query(context, params = {}) {
|
|
3285
|
-
|
|
3379
|
+
const response = this._storage.query(context.projectKey, "product", {
|
|
3286
3380
|
expand: params.expand,
|
|
3287
3381
|
where: params.where,
|
|
3288
3382
|
offset: params.offset,
|
|
3289
3383
|
limit: params.limit
|
|
3290
3384
|
});
|
|
3385
|
+
return {
|
|
3386
|
+
...response,
|
|
3387
|
+
results: response.results.map(
|
|
3388
|
+
(r) => this._searchService.transform(r, false)
|
|
3389
|
+
)
|
|
3390
|
+
};
|
|
3291
3391
|
}
|
|
3292
3392
|
search(context, query) {
|
|
3293
3393
|
const results = this._searchService.search(context.projectKey, {
|
|
@@ -3303,6 +3403,27 @@ var ProductProjectionRepository = class extends AbstractResourceRepository {
|
|
|
3303
3403
|
}
|
|
3304
3404
|
};
|
|
3305
3405
|
|
|
3406
|
+
// src/repositories/product-selection.ts
|
|
3407
|
+
var ProductSelectionRepository = class extends AbstractResourceRepository {
|
|
3408
|
+
constructor() {
|
|
3409
|
+
super(...arguments);
|
|
3410
|
+
this.actions = {};
|
|
3411
|
+
}
|
|
3412
|
+
getTypeId() {
|
|
3413
|
+
return "product-selection";
|
|
3414
|
+
}
|
|
3415
|
+
create(context, draft) {
|
|
3416
|
+
const resource = {
|
|
3417
|
+
...getBaseResourceProperties(),
|
|
3418
|
+
productCount: 0,
|
|
3419
|
+
name: draft.name,
|
|
3420
|
+
type: "individual"
|
|
3421
|
+
};
|
|
3422
|
+
this.saveNew(context, resource);
|
|
3423
|
+
return resource;
|
|
3424
|
+
}
|
|
3425
|
+
};
|
|
3426
|
+
|
|
3306
3427
|
// src/repositories/product-type.ts
|
|
3307
3428
|
var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
3308
3429
|
constructor() {
|
|
@@ -3354,20 +3475,20 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3354
3475
|
this.attributeDefinitionFromAttributeDefinitionDraft(context, attribute)
|
|
3355
3476
|
);
|
|
3356
3477
|
},
|
|
3357
|
-
|
|
3478
|
+
changeAttributeOrderByName: (context, resource, { attributeNames }) => {
|
|
3358
3479
|
var _a;
|
|
3359
3480
|
const attrs = new Map(
|
|
3360
3481
|
(_a = resource.attributes) == null ? void 0 : _a.map((item) => [item.name, item])
|
|
3361
3482
|
);
|
|
3362
3483
|
const result = [];
|
|
3363
3484
|
let current = resource.attributes;
|
|
3364
|
-
|
|
3365
|
-
const attr = attrs.get(
|
|
3485
|
+
attributeNames.forEach((attrName) => {
|
|
3486
|
+
const attr = attrs.get(attrName);
|
|
3366
3487
|
if (attr === void 0) {
|
|
3367
3488
|
throw new Error("New attr");
|
|
3368
3489
|
}
|
|
3369
3490
|
result.push(attr);
|
|
3370
|
-
current = current == null ? void 0 : current.filter((f) => f.name !==
|
|
3491
|
+
current = current == null ? void 0 : current.filter((f) => f.name !== attrName);
|
|
3371
3492
|
});
|
|
3372
3493
|
resource.attributes = result;
|
|
3373
3494
|
if (current) {
|
|
@@ -3415,18 +3536,6 @@ var ProductTypeRepository = class extends AbstractResourceRepository {
|
|
|
3415
3536
|
this.saveNew(context, resource);
|
|
3416
3537
|
return resource;
|
|
3417
3538
|
}
|
|
3418
|
-
getWithKey(context, key) {
|
|
3419
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3420
|
-
where: [`key="${key}"`]
|
|
3421
|
-
});
|
|
3422
|
-
if (result.count === 1) {
|
|
3423
|
-
return result.results[0];
|
|
3424
|
-
}
|
|
3425
|
-
if (result.count > 1) {
|
|
3426
|
-
throw new Error("Duplicate product type key");
|
|
3427
|
-
}
|
|
3428
|
-
return;
|
|
3429
|
-
}
|
|
3430
3539
|
};
|
|
3431
3540
|
|
|
3432
3541
|
// src/repositories/project.ts
|
|
@@ -3446,8 +3555,9 @@ var ProjectRepository = class extends AbstractRepository {
|
|
|
3446
3555
|
changeLanguages: (context, resource, { languages }) => {
|
|
3447
3556
|
resource.languages = languages;
|
|
3448
3557
|
},
|
|
3449
|
-
|
|
3450
|
-
resource.messages.enabled =
|
|
3558
|
+
changeMessagesConfiguration: (context, resource, { messagesConfiguration }) => {
|
|
3559
|
+
resource.messages.enabled = messagesConfiguration.enabled;
|
|
3560
|
+
resource.messages.deleteDaysAfterCreation = messagesConfiguration.deleteDaysAfterCreation;
|
|
3451
3561
|
},
|
|
3452
3562
|
changeProductSearchIndexingEnabled: (context, resource, { enabled }) => {
|
|
3453
3563
|
var _a;
|
|
@@ -3503,6 +3613,53 @@ var ProjectRepository = class extends AbstractRepository {
|
|
|
3503
3613
|
}
|
|
3504
3614
|
};
|
|
3505
3615
|
|
|
3616
|
+
// src/repositories/quote.ts
|
|
3617
|
+
var QuoteRepository = class extends AbstractResourceRepository {
|
|
3618
|
+
constructor() {
|
|
3619
|
+
super(...arguments);
|
|
3620
|
+
this.actions = {};
|
|
3621
|
+
}
|
|
3622
|
+
getTypeId() {
|
|
3623
|
+
return "quote";
|
|
3624
|
+
}
|
|
3625
|
+
create(context, draft) {
|
|
3626
|
+
throw new Error("not implemented");
|
|
3627
|
+
}
|
|
3628
|
+
};
|
|
3629
|
+
|
|
3630
|
+
// src/repositories/quote-request.ts
|
|
3631
|
+
var QuoteRequestRepository = class extends AbstractResourceRepository {
|
|
3632
|
+
constructor() {
|
|
3633
|
+
super(...arguments);
|
|
3634
|
+
this.actions = {};
|
|
3635
|
+
}
|
|
3636
|
+
getTypeId() {
|
|
3637
|
+
return "quote-request";
|
|
3638
|
+
}
|
|
3639
|
+
create(context, draft) {
|
|
3640
|
+
throw new Error("not implemented");
|
|
3641
|
+
}
|
|
3642
|
+
};
|
|
3643
|
+
|
|
3644
|
+
// src/repositories/review.ts
|
|
3645
|
+
var ReviewRepository = class extends AbstractResourceRepository {
|
|
3646
|
+
constructor() {
|
|
3647
|
+
super(...arguments);
|
|
3648
|
+
this.actions = {};
|
|
3649
|
+
}
|
|
3650
|
+
getTypeId() {
|
|
3651
|
+
return "review";
|
|
3652
|
+
}
|
|
3653
|
+
create(context, draft) {
|
|
3654
|
+
const resource = {
|
|
3655
|
+
...getBaseResourceProperties(),
|
|
3656
|
+
includedInStatistics: false
|
|
3657
|
+
};
|
|
3658
|
+
this.saveNew(context, resource);
|
|
3659
|
+
return resource;
|
|
3660
|
+
}
|
|
3661
|
+
};
|
|
3662
|
+
|
|
3506
3663
|
// src/repositories/shipping-method.ts
|
|
3507
3664
|
import deepEqual3 from "deep-equal";
|
|
3508
3665
|
var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
@@ -3677,6 +3834,41 @@ var ShoppingListRepository = class extends AbstractResourceRepository {
|
|
|
3677
3834
|
}
|
|
3678
3835
|
};
|
|
3679
3836
|
|
|
3837
|
+
// src/repositories/staged-quote.ts
|
|
3838
|
+
var StagedQuoteRepository = class extends AbstractResourceRepository {
|
|
3839
|
+
constructor() {
|
|
3840
|
+
super(...arguments);
|
|
3841
|
+
this.actions = {};
|
|
3842
|
+
}
|
|
3843
|
+
getTypeId() {
|
|
3844
|
+
return "staged-quote";
|
|
3845
|
+
}
|
|
3846
|
+
create(context, draft) {
|
|
3847
|
+
throw new Error("not implemented");
|
|
3848
|
+
}
|
|
3849
|
+
};
|
|
3850
|
+
|
|
3851
|
+
// src/repositories/standalone-price.ts
|
|
3852
|
+
var StandAlonePriceRepository = class extends AbstractResourceRepository {
|
|
3853
|
+
constructor() {
|
|
3854
|
+
super(...arguments);
|
|
3855
|
+
this.actions = {};
|
|
3856
|
+
}
|
|
3857
|
+
getTypeId() {
|
|
3858
|
+
return "standalone-price";
|
|
3859
|
+
}
|
|
3860
|
+
create(context, draft) {
|
|
3861
|
+
const resource = {
|
|
3862
|
+
...getBaseResourceProperties(),
|
|
3863
|
+
active: draft.active,
|
|
3864
|
+
sku: draft.sku,
|
|
3865
|
+
value: draft.value
|
|
3866
|
+
};
|
|
3867
|
+
this.saveNew(context, resource);
|
|
3868
|
+
return resource;
|
|
3869
|
+
}
|
|
3870
|
+
};
|
|
3871
|
+
|
|
3680
3872
|
// src/repositories/state.ts
|
|
3681
3873
|
var StateRepository = class extends AbstractResourceRepository {
|
|
3682
3874
|
constructor() {
|
|
@@ -3685,6 +3877,9 @@ var StateRepository = class extends AbstractResourceRepository {
|
|
|
3685
3877
|
changeKey: (context, resource, { key }) => {
|
|
3686
3878
|
resource.key = key;
|
|
3687
3879
|
},
|
|
3880
|
+
changeInitial: (context, resource, { initial }) => {
|
|
3881
|
+
resource.initial = initial;
|
|
3882
|
+
},
|
|
3688
3883
|
setDescription: (context, resource, { description }) => {
|
|
3689
3884
|
resource.description = description;
|
|
3690
3885
|
},
|
|
@@ -3797,18 +3992,6 @@ var StoreRepository = class extends AbstractResourceRepository {
|
|
|
3797
3992
|
)
|
|
3798
3993
|
);
|
|
3799
3994
|
}
|
|
3800
|
-
getWithKey(context, key) {
|
|
3801
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3802
|
-
where: [`key="${key}"`]
|
|
3803
|
-
});
|
|
3804
|
-
if (result.count === 1) {
|
|
3805
|
-
return result.results[0];
|
|
3806
|
-
}
|
|
3807
|
-
if (result.count > 1) {
|
|
3808
|
-
throw new Error("Duplicate store key");
|
|
3809
|
-
}
|
|
3810
|
-
return;
|
|
3811
|
-
}
|
|
3812
3995
|
};
|
|
3813
3996
|
|
|
3814
3997
|
// src/repositories/subscription.ts
|
|
@@ -3908,18 +4091,6 @@ var TaxCategoryRepository = class extends AbstractResourceRepository {
|
|
|
3908
4091
|
this.saveNew(context, resource);
|
|
3909
4092
|
return resource;
|
|
3910
4093
|
}
|
|
3911
|
-
getWithKey(context, key) {
|
|
3912
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3913
|
-
where: [`key="${key}"`]
|
|
3914
|
-
});
|
|
3915
|
-
if (result.count === 1) {
|
|
3916
|
-
return result.results[0];
|
|
3917
|
-
}
|
|
3918
|
-
if (result.count > 1) {
|
|
3919
|
-
throw new Error("Duplicate tax category key");
|
|
3920
|
-
}
|
|
3921
|
-
return;
|
|
3922
|
-
}
|
|
3923
4094
|
};
|
|
3924
4095
|
|
|
3925
4096
|
// src/repositories/type.ts
|
|
@@ -4078,18 +4249,25 @@ var createRepositories = (storage) => ({
|
|
|
4078
4249
|
"inventory-entry": new InventoryEntryRepository(storage),
|
|
4079
4250
|
"key-value-document": new CustomObjectRepository(storage),
|
|
4080
4251
|
order: new OrderRepository(storage),
|
|
4252
|
+
"order-edit": new OrderEditRepository(storage),
|
|
4081
4253
|
payment: new PaymentRepository(storage),
|
|
4082
4254
|
"my-cart": new CartRepository(storage),
|
|
4083
4255
|
"my-order": new MyOrderRepository(storage),
|
|
4084
4256
|
"my-customer": new CustomerRepository(storage),
|
|
4085
4257
|
"my-payment": new PaymentRepository(storage),
|
|
4086
|
-
"shipping-method": new ShippingMethodRepository(storage),
|
|
4087
|
-
"product-type": new ProductTypeRepository(storage),
|
|
4088
4258
|
product: new ProductRepository(storage),
|
|
4089
|
-
|
|
4259
|
+
"product-type": new ProductTypeRepository(storage),
|
|
4090
4260
|
"product-discount": new ProductDiscountRepository(storage),
|
|
4091
4261
|
"product-projection": new ProductProjectionRepository(storage),
|
|
4262
|
+
"product-selection": new ProductSelectionRepository(storage),
|
|
4263
|
+
project: new ProjectRepository(storage),
|
|
4264
|
+
review: new ReviewRepository(storage),
|
|
4265
|
+
quote: new QuoteRepository(storage),
|
|
4266
|
+
"quote-request": new QuoteRequestRepository(storage),
|
|
4267
|
+
"shipping-method": new ShippingMethodRepository(storage),
|
|
4092
4268
|
"shopping-list": new ShoppingListRepository(storage),
|
|
4269
|
+
"staged-quote": new StagedQuoteRepository(storage),
|
|
4270
|
+
"standalone-price": new StandAlonePriceRepository(storage),
|
|
4093
4271
|
state: new StateRepository(storage),
|
|
4094
4272
|
store: new StoreRepository(storage),
|
|
4095
4273
|
subscription: new SubscriptionRepository(storage),
|
|
@@ -4258,25 +4436,27 @@ var CartService = class extends AbstractService {
|
|
|
4258
4436
|
return "carts";
|
|
4259
4437
|
}
|
|
4260
4438
|
extraRoutes(parent) {
|
|
4261
|
-
parent.post("/replicate", (
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
}
|
|
4439
|
+
parent.post("/replicate", this.replicate.bind(this));
|
|
4440
|
+
}
|
|
4441
|
+
replicate(request, response) {
|
|
4442
|
+
const context = getRepositoryContext(request);
|
|
4443
|
+
const cartOrOrder = request.body.reference.typeId === "order" ? this.orderRepository.get(context, request.body.reference.id) : this.repository.get(context, request.body.reference.id);
|
|
4444
|
+
if (!cartOrOrder) {
|
|
4445
|
+
return response.status(400).send();
|
|
4446
|
+
}
|
|
4447
|
+
const cartDraft = {
|
|
4448
|
+
...cartOrOrder,
|
|
4449
|
+
currency: cartOrOrder.totalPrice.currencyCode,
|
|
4450
|
+
discountCodes: [],
|
|
4451
|
+
shipping: [],
|
|
4452
|
+
lineItems: cartOrOrder.lineItems.map((lineItem) => ({
|
|
4453
|
+
...lineItem,
|
|
4454
|
+
variantId: lineItem.variant.id,
|
|
4455
|
+
sku: lineItem.variant.sku
|
|
4456
|
+
}))
|
|
4457
|
+
};
|
|
4458
|
+
const newCart = this.repository.create(context, cartDraft);
|
|
4459
|
+
return response.status(200).send(newCart);
|
|
4280
4460
|
}
|
|
4281
4461
|
};
|
|
4282
4462
|
|
|
@@ -4621,19 +4801,6 @@ var ProductDiscountService = class extends AbstractService {
|
|
|
4621
4801
|
getBasePath() {
|
|
4622
4802
|
return "product-discounts";
|
|
4623
4803
|
}
|
|
4624
|
-
extraRoutes(router) {
|
|
4625
|
-
router.get("/key=:key", this.getWithKey.bind(this));
|
|
4626
|
-
}
|
|
4627
|
-
getWithKey(request, response) {
|
|
4628
|
-
const resource = this.repository.getWithKey(
|
|
4629
|
-
getRepositoryContext(request),
|
|
4630
|
-
request.params.key
|
|
4631
|
-
);
|
|
4632
|
-
if (resource) {
|
|
4633
|
-
return response.status(200).send(resource);
|
|
4634
|
-
}
|
|
4635
|
-
return response.status(404).send("Not found");
|
|
4636
|
-
}
|
|
4637
4804
|
};
|
|
4638
4805
|
|
|
4639
4806
|
// src/services/product-projection.ts
|
|
@@ -4666,19 +4833,6 @@ var ProductTypeService = class extends AbstractService {
|
|
|
4666
4833
|
getBasePath() {
|
|
4667
4834
|
return "product-types";
|
|
4668
4835
|
}
|
|
4669
|
-
extraRoutes(router) {
|
|
4670
|
-
router.get("/key=:key", this.getWithKey.bind(this));
|
|
4671
|
-
}
|
|
4672
|
-
getWithKey(request, response) {
|
|
4673
|
-
const resource = this.repository.getWithKey(
|
|
4674
|
-
getRepositoryContext(request),
|
|
4675
|
-
request.params.key
|
|
4676
|
-
);
|
|
4677
|
-
if (resource) {
|
|
4678
|
-
return response.status(200).send(resource);
|
|
4679
|
-
}
|
|
4680
|
-
return response.status(404).send("Not found");
|
|
4681
|
-
}
|
|
4682
4836
|
};
|
|
4683
4837
|
|
|
4684
4838
|
// src/services/shipping-method.ts
|
|
@@ -4727,19 +4881,6 @@ var StoreService = class extends AbstractService {
|
|
|
4727
4881
|
getBasePath() {
|
|
4728
4882
|
return "stores";
|
|
4729
4883
|
}
|
|
4730
|
-
extraRoutes(router) {
|
|
4731
|
-
router.get("/key=:key", this.getWithKey.bind(this));
|
|
4732
|
-
}
|
|
4733
|
-
getWithKey(request, response) {
|
|
4734
|
-
const resource = this.repository.getWithKey(
|
|
4735
|
-
getRepositoryContext(request),
|
|
4736
|
-
request.params.key
|
|
4737
|
-
);
|
|
4738
|
-
if (resource) {
|
|
4739
|
-
return response.status(200).send(resource);
|
|
4740
|
-
}
|
|
4741
|
-
return response.status(404).send("Not found");
|
|
4742
|
-
}
|
|
4743
4884
|
};
|
|
4744
4885
|
|
|
4745
4886
|
// src/services/subscription.ts
|
|
@@ -4762,19 +4903,6 @@ var TaxCategoryService = class extends AbstractService {
|
|
|
4762
4903
|
getBasePath() {
|
|
4763
4904
|
return "tax-categories";
|
|
4764
4905
|
}
|
|
4765
|
-
extraRoutes(router) {
|
|
4766
|
-
router.get("/key=:key", this.getWithKey.bind(this));
|
|
4767
|
-
}
|
|
4768
|
-
getWithKey(request, response) {
|
|
4769
|
-
const resource = this.repository.getWithKey(
|
|
4770
|
-
getRepositoryContext(request),
|
|
4771
|
-
request.params.key
|
|
4772
|
-
);
|
|
4773
|
-
if (resource) {
|
|
4774
|
-
return response.status(200).send(resource);
|
|
4775
|
-
}
|
|
4776
|
-
return response.status(404).send("Not found");
|
|
4777
|
-
}
|
|
4778
4906
|
};
|
|
4779
4907
|
|
|
4780
4908
|
// src/services/type.ts
|
|
@@ -4859,8 +4987,8 @@ var CommercetoolsMock = class {
|
|
|
4859
4987
|
constructor(options = {}) {
|
|
4860
4988
|
this._nockScopes = { auth: void 0, api: void 0 };
|
|
4861
4989
|
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
4862
|
-
this._services =
|
|
4863
|
-
this._repositories =
|
|
4990
|
+
this._services = null;
|
|
4991
|
+
this._repositories = null;
|
|
4864
4992
|
this._projectService = void 0;
|
|
4865
4993
|
this._storage = new InMemoryStorage();
|
|
4866
4994
|
this._oauth2 = new OAuth2Server({
|
|
@@ -4887,9 +5015,12 @@ var CommercetoolsMock = class {
|
|
|
4887
5015
|
if (!projectKey && !this.options.defaultProjectKey) {
|
|
4888
5016
|
throw new Error("No projectKey passed and no default set");
|
|
4889
5017
|
}
|
|
5018
|
+
if (this._repositories === null) {
|
|
5019
|
+
throw new Error("repositories not initialized yet");
|
|
5020
|
+
}
|
|
4890
5021
|
return new ProjectAPI(
|
|
4891
5022
|
projectKey || this.options.defaultProjectKey,
|
|
4892
|
-
this.
|
|
5023
|
+
this._repositories,
|
|
4893
5024
|
this._storage
|
|
4894
5025
|
);
|
|
4895
5026
|
}
|
|
@@ -4900,6 +5031,7 @@ var CommercetoolsMock = class {
|
|
|
4900
5031
|
server.keepAliveTimeout = 60 * 1e3;
|
|
4901
5032
|
}
|
|
4902
5033
|
createApp(options) {
|
|
5034
|
+
this._repositories = createRepositories(this._storage);
|
|
4903
5035
|
const app = express2();
|
|
4904
5036
|
const projectRouter = express2.Router({ mergeParams: true });
|
|
4905
5037
|
projectRouter.use(express2.json());
|
|
@@ -4918,12 +5050,11 @@ var CommercetoolsMock = class {
|
|
|
4918
5050
|
app.use("/:projectKey", projectRouter);
|
|
4919
5051
|
app.use("/:projectKey/in-store/key=:storeKey", projectRouter);
|
|
4920
5052
|
}
|
|
4921
|
-
this.
|
|
5053
|
+
this._services = createServices(projectRouter, this._repositories);
|
|
4922
5054
|
this._projectService = new ProjectService(
|
|
4923
5055
|
projectRouter,
|
|
4924
5056
|
this._repositories.project
|
|
4925
5057
|
);
|
|
4926
|
-
this._services = createServices(projectRouter, this._repositories);
|
|
4927
5058
|
app.use((err, req, resp, next) => {
|
|
4928
5059
|
if (err instanceof CommercetoolsError) {
|
|
4929
5060
|
return resp.status(err.statusCode).send({
|