@labdigital/commercetools-mock 2.46.0 → 2.47.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.
Files changed (79) hide show
  1. package/dist/index.cjs +568 -241
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +782 -58
  4. package/dist/index.d.ts +782 -58
  5. package/dist/index.js +556 -229
  6. package/dist/index.js.map +1 -1
  7. package/package.json +41 -48
  8. package/src/ctMock.ts +11 -13
  9. package/src/index.test.ts +5 -5
  10. package/src/lib/predicateParser.test.ts +62 -62
  11. package/src/lib/predicateParser.ts +32 -42
  12. package/src/lib/productSearchFilter.test.ts +18 -0
  13. package/src/lib/productSearchFilter.ts +7 -0
  14. package/src/lib/projectionSearchFilter.test.ts +17 -17
  15. package/src/lib/projectionSearchFilter.ts +2 -3
  16. package/src/oauth/server.test.ts +1 -1
  17. package/src/oauth/server.ts +11 -11
  18. package/src/priceSelector.ts +1 -1
  19. package/src/product-projection-search.ts +18 -19
  20. package/src/repositories/business-unit.ts +17 -16
  21. package/src/repositories/cart/actions.ts +32 -32
  22. package/src/repositories/cart/helpers.ts +1 -1
  23. package/src/repositories/cart/index.ts +8 -8
  24. package/src/repositories/cart-discount/actions.ts +1 -4
  25. package/src/repositories/category/actions.ts +2 -6
  26. package/src/repositories/custom-object.ts +20 -21
  27. package/src/repositories/customer/actions.ts +4 -4
  28. package/src/repositories/errors.ts +1 -1
  29. package/src/repositories/extension.ts +2 -1
  30. package/src/repositories/helpers.ts +27 -27
  31. package/src/repositories/index.ts +17 -17
  32. package/src/repositories/my-customer.ts +1 -1
  33. package/src/repositories/my-order.ts +2 -2
  34. package/src/repositories/order/index.ts +1 -1
  35. package/src/repositories/product/actions.ts +1 -1
  36. package/src/repositories/quote/actions.ts +83 -0
  37. package/src/repositories/quote/index.ts +54 -0
  38. package/src/repositories/quote-request/actions.ts +84 -0
  39. package/src/repositories/quote-request/index.test.ts +167 -0
  40. package/src/repositories/quote-request/index.ts +67 -0
  41. package/src/repositories/quote-staged/actions.ts +84 -0
  42. package/src/repositories/quote-staged/index.ts +47 -0
  43. package/src/repositories/review.ts +4 -4
  44. package/src/repositories/shipping-method/actions.ts +17 -17
  45. package/src/repositories/shipping-method/index.ts +6 -6
  46. package/src/repositories/shopping-list/actions.ts +1 -1
  47. package/src/repositories/shopping-list/index.ts +9 -1
  48. package/src/repositories/subscription.ts +2 -4
  49. package/src/server.ts +3 -2
  50. package/src/services/abstract.ts +7 -7
  51. package/src/services/as-associate-order.test.ts +1 -1
  52. package/src/services/cart-discount.test.ts +1 -1
  53. package/src/services/cart.test.ts +15 -15
  54. package/src/services/category.test.ts +1 -1
  55. package/src/services/customer.test.ts +4 -4
  56. package/src/services/customer.ts +1 -1
  57. package/src/services/index.ts +20 -14
  58. package/src/services/inventory-entry.test.ts +5 -5
  59. package/src/services/my-cart.test.ts +2 -2
  60. package/src/services/my-customer.test.ts +2 -2
  61. package/src/services/order.test.ts +8 -8
  62. package/src/services/product-projection.test.ts +5 -5
  63. package/src/services/product-projection.ts +12 -14
  64. package/src/services/product.test.ts +1 -1
  65. package/src/services/quote-request.test.ts +59 -0
  66. package/src/services/quote-request.ts +16 -0
  67. package/src/services/quote-staged.ts +16 -0
  68. package/src/services/quote.ts +16 -0
  69. package/src/services/standalone-price.test.ts +4 -4
  70. package/src/services/state.test.ts +1 -1
  71. package/src/services/store.test.ts +2 -2
  72. package/src/services/tax-category.test.ts +1 -1
  73. package/src/shipping.ts +3 -3
  74. package/src/storage/in-memory.ts +55 -63
  75. package/src/testing/customer.ts +1 -1
  76. package/src/types.ts +51 -31
  77. package/src/repositories/quote-request.ts +0 -17
  78. package/src/repositories/quote.ts +0 -14
  79. package/src/repositories/staged-quote.ts +0 -17
@@ -1,5 +1,5 @@
1
+ import assert from "node:assert";
1
2
  import type { Order, Payment, State } from "@commercetools/platform-sdk";
2
- import assert from "assert";
3
3
  import supertest from "supertest";
4
4
  import { afterEach, beforeEach, describe, expect, test } from "vitest";
5
5
  import { generateRandomString } from "~src/helpers";
@@ -46,7 +46,7 @@ describe("Order Query", () => {
46
46
  test("no filter", async () => {
47
47
  assert(order, "order not created");
48
48
 
49
- const response = await supertest(ctMock.app).get(`/dummy/orders`);
49
+ const response = await supertest(ctMock.app).get("/dummy/orders");
50
50
  expect(response.status).toBe(200);
51
51
  expect(response.body.count).toBe(1);
52
52
  expect(response.body.total).toBe(1);
@@ -59,14 +59,14 @@ describe("Order Query", () => {
59
59
 
60
60
  {
61
61
  const response = await supertest(ctMock.app)
62
- .get(`/dummy/orders`)
62
+ .get("/dummy/orders")
63
63
  .query({ where: 'orderNumber="nomatch"' });
64
64
  expect(response.status).toBe(200);
65
65
  expect(response.body.count).toBe(0);
66
66
  }
67
67
  {
68
68
  const response = await supertest(ctMock.app)
69
- .get(`/dummy/orders`)
69
+ .get("/dummy/orders")
70
70
  .query({ where: 'orderNumber="foobar"' });
71
71
  expect(response.status).toBe(200);
72
72
  expect(response.body.count).toBe(1);
@@ -171,7 +171,7 @@ describe("Order payment tests", () => {
171
171
  ctMock.project().add("order", order);
172
172
 
173
173
  const response = await supertest(ctMock.app)
174
- .get(`/dummy/orders`)
174
+ .get("/dummy/orders")
175
175
  .query({ where: `paymentInfo(payments(id="${payment.id}"))` });
176
176
 
177
177
  expect(response.status).toBe(200);
@@ -179,8 +179,8 @@ describe("Order payment tests", () => {
179
179
 
180
180
  {
181
181
  const response = await supertest(ctMock.app)
182
- .get(`/dummy/orders`)
183
- .query({ where: `paymentInfo(payments(id is defined))` });
182
+ .get("/dummy/orders")
183
+ .query({ where: "paymentInfo(payments(id is defined))" });
184
184
 
185
185
  expect(response.status).toBe(200);
186
186
  expect(response.body.results[0].id).toBe(order.id);
@@ -800,7 +800,7 @@ describe("Order Import", () => {
800
800
 
801
801
  test("Import", async () => {
802
802
  const response = await supertest(ctMock.app)
803
- .post(`/dummy/orders/import`)
803
+ .post("/dummy/orders/import")
804
804
  .send({
805
805
  orderNumber: "100000001",
806
806
  totalPrice: {
@@ -181,7 +181,7 @@ beforeEach(async () => {
181
181
  ],
182
182
  assets: [],
183
183
  images: [],
184
- attributes: productDraft.variants![0].attributes,
184
+ attributes: productDraft.variants?.[0].attributes,
185
185
  },
186
186
  ],
187
187
  name: productDraft.name,
@@ -236,8 +236,8 @@ describe("Product Projection Query - Generic", () => {
236
236
  const response = await supertest(ctMock.app)
237
237
  .get("/dummy/product-projections")
238
238
  .query({
239
- "limit": 50,
240
- "where": ["slug(nl-NL=:slug)"],
239
+ limit: 50,
240
+ where: ["slug(nl-NL=:slug)"],
241
241
  "var.slug": "test-product",
242
242
  });
243
243
 
@@ -257,8 +257,8 @@ describe("Product Projection Query - Generic", () => {
257
257
  const response = await supertest(ctMock.app)
258
258
  .get("/dummy/product-projections")
259
259
  .query({
260
- "limit": 50,
261
- "where": ["slug(nl-NL=:slug)"],
260
+ limit: 50,
261
+ where: ["slug(nl-NL=:slug)"],
262
262
  "var.slug": "missing-product",
263
263
  });
264
264
 
@@ -40,21 +40,19 @@ export class ProductProjectionService extends AbstractService {
40
40
  search(request: Request, response: Response) {
41
41
  const query = request.query;
42
42
  const searchParams: ProductProjectionQueryParams = {
43
- "filter": queryParamsArray(query.filter),
43
+ filter: queryParamsArray(query.filter),
44
44
  "filter.query": queryParamsArray(query["filter.query"]),
45
- "facet": queryParamsArray(query.facet),
46
- "expand": queryParamsArray(query.expand),
47
- "staged": queryParamsValue(query.staged) === "true",
48
- "localeProjection": queryParamsValue(query.localeProjection),
49
- "storeProjection": queryParamsValue(query.storeProjection),
50
- "priceChannel": queryParamsValue(query.priceChannel),
51
- "priceCountry": queryParamsValue(query.priceCountry),
52
- "priceCurrency": queryParamsValue(query.priceCurrency),
53
- "priceCustomerGroup": queryParamsValue(query.priceCustomerGroup),
54
- "offset": query.offset
55
- ? Number(queryParamsValue(query.offset))
56
- : undefined,
57
- "limit": query.limit ? Number(queryParamsValue(query.limit)) : undefined,
45
+ facet: queryParamsArray(query.facet),
46
+ expand: queryParamsArray(query.expand),
47
+ staged: queryParamsValue(query.staged) === "true",
48
+ localeProjection: queryParamsValue(query.localeProjection),
49
+ storeProjection: queryParamsValue(query.storeProjection),
50
+ priceChannel: queryParamsValue(query.priceChannel),
51
+ priceCountry: queryParamsValue(query.priceCountry),
52
+ priceCurrency: queryParamsValue(query.priceCurrency),
53
+ priceCustomerGroup: queryParamsValue(query.priceCustomerGroup),
54
+ offset: query.offset ? Number(queryParamsValue(query.offset)) : undefined,
55
+ limit: query.limit ? Number(queryParamsValue(query.limit)) : undefined,
58
56
  };
59
57
  const resource = this.repository.search(
60
58
  getRepositoryContext(request),
@@ -1,3 +1,4 @@
1
+ import assert from "node:assert";
1
2
  import type {
2
3
  Category,
3
4
  CategoryDraft,
@@ -19,7 +20,6 @@ import type {
19
20
  Type,
20
21
  TypeDraft,
21
22
  } from "@commercetools/platform-sdk";
22
- import assert from "assert";
23
23
  import supertest from "supertest";
24
24
  import {
25
25
  afterAll,
@@ -0,0 +1,59 @@
1
+ import supertest from "supertest";
2
+ import { afterEach, describe, expect, it } from "vitest";
3
+ import { customerDraftFactory } from "~src/testing/customer";
4
+ import { CommercetoolsMock } from "../index";
5
+
6
+ describe("Quote Request Create", () => {
7
+ const ctMock = new CommercetoolsMock();
8
+
9
+ afterEach(() => {
10
+ ctMock.clear();
11
+ });
12
+
13
+ it("should create a quote request", async () => {
14
+ const customer = await customerDraftFactory(ctMock).create();
15
+ let response = await supertest(ctMock.app)
16
+ .post("/dummy/carts")
17
+ .send({
18
+ currency: "EUR",
19
+ customerId: customer.id,
20
+ custom: {
21
+ type: {
22
+ key: "my-cart",
23
+ },
24
+ fields: {
25
+ description: "example description",
26
+ },
27
+ },
28
+ });
29
+ expect(response.status).toBe(201);
30
+ const cart = response.body;
31
+
32
+ response = await supertest(ctMock.app)
33
+ .post("/dummy/quote-requests")
34
+ .send({
35
+ cart: {
36
+ typeId: "cart",
37
+ id: cart.id,
38
+ },
39
+ cartVersion: cart.version,
40
+ });
41
+ expect(response.status).toBe(201);
42
+ const quote = response.body;
43
+
44
+ expect(quote.cart).toEqual({
45
+ typeId: "cart",
46
+ id: cart.id,
47
+ });
48
+
49
+ response = await supertest(ctMock.app)
50
+ .get(`/dummy/quote-requests/${quote.id}`)
51
+ .send();
52
+
53
+ const quoteResult = response.body;
54
+ expect(quoteResult.cart).toEqual({
55
+ typeId: "cart",
56
+ id: cart.id,
57
+ });
58
+ });
59
+ });
@@ -0,0 +1,16 @@
1
+ import type { Router } from "express";
2
+ import type { QuoteRequestRepository } from "~src/repositories/quote-request";
3
+ import AbstractService from "./abstract";
4
+
5
+ export class QuoteRequestService extends AbstractService {
6
+ public repository: QuoteRequestRepository;
7
+
8
+ constructor(parent: Router, repository: QuoteRequestRepository) {
9
+ super(parent);
10
+ this.repository = repository;
11
+ }
12
+
13
+ getBasePath() {
14
+ return "quote-requests";
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ import type { Router } from "express";
2
+ import type { StagedQuoteRepository } from "~src/repositories/quote-staged";
3
+ import AbstractService from "./abstract";
4
+
5
+ export class StagedQuoteService extends AbstractService {
6
+ public repository: StagedQuoteRepository;
7
+
8
+ constructor(parent: Router, repository: StagedQuoteRepository) {
9
+ super(parent);
10
+ this.repository = repository;
11
+ }
12
+
13
+ getBasePath() {
14
+ return "staged-quotes";
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ import type { Router } from "express";
2
+ import type { QuoteRepository } from "~src/repositories/quote";
3
+ import AbstractService from "./abstract";
4
+
5
+ export class QuoteService extends AbstractService {
6
+ public repository: QuoteRepository;
7
+
8
+ constructor(parent: Router, repository: QuoteRepository) {
9
+ super(parent);
10
+ this.repository = repository;
11
+ }
12
+
13
+ getBasePath() {
14
+ return "quotes";
15
+ }
16
+ }
@@ -120,7 +120,7 @@ describe("Standalone price Actions", () => {
120
120
 
121
121
  test("changeValue", async () => {
122
122
  const response = await supertest(ctMock.app)
123
- .post("/dummy/standalone-prices/" + id)
123
+ .post(`/dummy/standalone-prices/${id}`)
124
124
  .send({
125
125
  version: 1,
126
126
  actions: [
@@ -159,7 +159,7 @@ describe("Standalone price Actions", () => {
159
159
 
160
160
  test("setActive", async () => {
161
161
  const response = await supertest(ctMock.app)
162
- .post("/dummy/standalone-prices/" + id)
162
+ .post(`/dummy/standalone-prices/${id}`)
163
163
  .send({
164
164
  version: 1,
165
165
  actions: [
@@ -195,7 +195,7 @@ describe("Standalone price Actions", () => {
195
195
 
196
196
  test("setDiscounted", async () => {
197
197
  const response = await supertest(ctMock.app)
198
- .post("/dummy/standalone-prices/" + id)
198
+ .post(`/dummy/standalone-prices/${id}`)
199
199
  .send({
200
200
  version: 1,
201
201
  actions: [
@@ -250,7 +250,7 @@ describe("Standalone price Actions", () => {
250
250
  });
251
251
 
252
252
  const response2 = await supertest(ctMock.app)
253
- .post("/dummy/standalone-prices/" + id)
253
+ .post(`/dummy/standalone-prices/${id}`)
254
254
  .send({
255
255
  version: 2,
256
256
  actions: [
@@ -1,4 +1,4 @@
1
- import { type StateDraft } from "@commercetools/platform-sdk";
1
+ import type { StateDraft } from "@commercetools/platform-sdk";
2
2
  import supertest from "supertest";
3
3
  import { describe, expect, test } from "vitest";
4
4
  import { CommercetoolsMock } from "../index";
@@ -21,7 +21,7 @@ describe("Store", () => {
21
21
  });
22
22
 
23
23
  const response = await supertest(ctMock.app).get(
24
- `/dummy/stores/key=STOREKEY`,
24
+ "/dummy/stores/key=STOREKEY",
25
25
  );
26
26
 
27
27
  expect(response.status).toBe(200);
@@ -54,7 +54,7 @@ describe("Store", () => {
54
54
  });
55
55
 
56
56
  const response = await supertest(ctMock.app).get(
57
- `/dummy/stores/key=DOESNOTEXIST`,
57
+ "/dummy/stores/key=DOESNOTEXIST",
58
58
  );
59
59
 
60
60
  expect(response.status).toBe(404);
@@ -65,7 +65,7 @@ describe("Tax Category", () => {
65
65
  expect(createResponse.status).toBe(201);
66
66
 
67
67
  const response = await supertest(ctMock.app)
68
- .get(`/dummy/tax-categories/`)
68
+ .get("/dummy/tax-categories/")
69
69
  .query({ where: `key="${createResponse.body.key}"` });
70
70
 
71
71
  expect(response.status).toBe(200);
package/src/shipping.ts CHANGED
@@ -106,12 +106,12 @@ export const getShippingMethodsMatchingCart = (
106
106
  context.projectKey,
107
107
  "shipping-method",
108
108
  {
109
- "where": [
110
- `zoneRates(zone(id in (:zoneIds)))`,
109
+ where: [
110
+ "zoneRates(zone(id in (:zoneIds)))",
111
111
  `zoneRates(shippingRates(price(currencyCode="${cart.totalPrice.currencyCode}")))`,
112
112
  ],
113
113
  "var.zoneIds": zoneIds,
114
- "expand": params.expand,
114
+ expand: params.expand,
115
115
  },
116
116
  );
117
117
 
@@ -1,47 +1,47 @@
1
+ import assert from "node:assert";
1
2
  import type {
2
3
  InvalidJsonInputError,
3
4
  ReferencedResourceNotFoundError,
4
5
  ShoppingListLineItem,
5
6
  } from "@commercetools/platform-sdk";
6
- import {
7
- type AssociateRole,
8
- type AttributeGroup,
9
- type BusinessUnit,
10
- type Cart,
11
- type CartDiscount,
12
- type Category,
13
- type Channel,
14
- type CustomObject,
15
- type Customer,
16
- type CustomerGroup,
17
- type DiscountCode,
18
- type Extension,
19
- type InvalidInputError,
20
- type InventoryEntry,
21
- type Order,
22
- type PagedQueryResponse,
23
- type Payment,
24
- type Product,
25
- type ProductDiscount,
26
- type ProductProjection,
27
- type ProductTailoring,
28
- type ProductType,
29
- type Project,
30
- type Quote,
31
- type QuoteRequest,
32
- type Reference,
33
- type ResourceIdentifier,
34
- type ShippingMethod,
35
- type ShoppingList,
36
- type StagedQuote,
37
- type State,
38
- type Store,
39
- type Subscription,
40
- type TaxCategory,
41
- type Type,
42
- type Zone,
7
+ import type {
8
+ AssociateRole,
9
+ AttributeGroup,
10
+ BusinessUnit,
11
+ Cart,
12
+ CartDiscount,
13
+ Category,
14
+ Channel,
15
+ CustomObject,
16
+ Customer,
17
+ CustomerGroup,
18
+ DiscountCode,
19
+ Extension,
20
+ InvalidInputError,
21
+ InventoryEntry,
22
+ Order,
23
+ PagedQueryResponse,
24
+ Payment,
25
+ Product,
26
+ ProductDiscount,
27
+ ProductProjection,
28
+ ProductTailoring,
29
+ ProductType,
30
+ Project,
31
+ Quote,
32
+ QuoteRequest,
33
+ Reference,
34
+ ResourceIdentifier,
35
+ ShippingMethod,
36
+ ShoppingList,
37
+ StagedQuote,
38
+ State,
39
+ Store,
40
+ Subscription,
41
+ TaxCategory,
42
+ Type,
43
+ Zone,
43
44
  } from "@commercetools/platform-sdk";
44
- import assert from "assert";
45
45
  import { CommercetoolsError } from "~src/exceptions";
46
46
  import { cloneObject } from "../helpers";
47
47
  import { parseExpandClause } from "../lib/expandParser";
@@ -174,38 +174,38 @@ export class InMemoryStorage extends AbstractStorage {
174
174
  "associate-role": new Map<string, AssociateRole>(),
175
175
  "attribute-group": new Map<string, AttributeGroup>(),
176
176
  "business-unit": new Map<string, BusinessUnit>(),
177
- "cart": new Map<string, Cart>(),
177
+ cart: new Map<string, Cart>(),
178
178
  "cart-discount": new Map<string, CartDiscount>(),
179
- "category": new Map<string, Category>(),
180
- "channel": new Map<string, Channel>(),
181
- "customer": new Map<string, Customer>(),
179
+ category: new Map<string, Category>(),
180
+ channel: new Map<string, Channel>(),
181
+ customer: new Map<string, Customer>(),
182
182
  "customer-group": new Map<string, CustomerGroup>(),
183
183
  "discount-code": new Map<string, DiscountCode>(),
184
- "extension": new Map<string, Extension>(),
184
+ extension: new Map<string, Extension>(),
185
185
  "inventory-entry": new Map<string, InventoryEntry>(),
186
186
  "key-value-document": new Map<string, CustomObject>(),
187
- "order": new Map<string, Order>(),
187
+ order: new Map<string, Order>(),
188
188
  "order-edit": new Map<string, any>(),
189
- "payment": new Map<string, Payment>(),
190
- "product": new Map<string, Product>(),
191
- "quote": new Map<string, Quote>(),
189
+ payment: new Map<string, Payment>(),
190
+ product: new Map<string, Product>(),
191
+ quote: new Map<string, Quote>(),
192
192
  "quote-request": new Map<string, QuoteRequest>(),
193
193
  "product-discount": new Map<string, ProductDiscount>(),
194
194
  "product-selection": new Map<string, any>(),
195
195
  "product-type": new Map<string, ProductType>(),
196
196
  "product-projection": new Map<string, ProductProjection>(),
197
197
  "product-tailoring": new Map<string, ProductTailoring>(),
198
- "review": new Map<string, any>(),
198
+ review: new Map<string, any>(),
199
199
  "shipping-method": new Map<string, ShippingMethod>(),
200
200
  "staged-quote": new Map<string, StagedQuote>(),
201
- "state": new Map<string, State>(),
202
- "store": new Map<string, Store>(),
201
+ state: new Map<string, State>(),
202
+ store: new Map<string, Store>(),
203
203
  "shopping-list": new Map<string, ShoppingList>(),
204
204
  "standalone-price": new Map<string, any>(),
205
- "subscription": new Map<string, Subscription>(),
205
+ subscription: new Map<string, Subscription>(),
206
206
  "tax-category": new Map<string, TaxCategory>(),
207
- "type": new Map<string, Type>(),
208
- "zone": new Map<string, Zone>(),
207
+ type: new Map<string, Type>(),
208
+ zone: new Map<string, Zone>(),
209
209
  };
210
210
  }
211
211
  return projectStorage;
@@ -416,11 +416,7 @@ export class InMemoryStorage extends AbstractStorage {
416
416
 
417
417
  throw new CommercetoolsError<ReferencedResourceNotFoundError>({
418
418
  code: "ReferencedResourceNotFound",
419
- message:
420
- `The referenced object of type '${identifier.typeId}' with id ` +
421
- `'${identifier.id}' was not found. It either doesn't exist, or it ` +
422
- `can't be accessed from this endpoint (e.g., if the endpoint ` +
423
- `filters by store or customer account).`,
419
+ message: `The referenced object of type '${identifier.typeId}' with id '${identifier.id}' was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
424
420
  typeId: identifier.typeId,
425
421
  id: identifier.id,
426
422
  });
@@ -438,11 +434,7 @@ export class InMemoryStorage extends AbstractStorage {
438
434
 
439
435
  throw new CommercetoolsError<ReferencedResourceNotFoundError>({
440
436
  code: "ReferencedResourceNotFound",
441
- message:
442
- `The referenced object of type '${identifier.typeId}' with key ` +
443
- `'${identifier.key}' was not found. It either doesn't exist, or it ` +
444
- `can't be accessed from this endpoint (e.g., if the endpoint ` +
445
- `filters by store or customer account).`,
437
+ message: `The referenced object of type '${identifier.typeId}' with key '${identifier.key}' was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
446
438
  typeId: identifier.typeId,
447
439
  key: identifier.key,
448
440
  });
@@ -7,7 +7,7 @@ export const customerDraftFactory = (m: CommercetoolsMock) =>
7
7
  Factory.define<CustomerDraft, CustomerDraft, Customer>(({ onCreate }) => {
8
8
  onCreate(async (draft) => {
9
9
  const response = await supertest(m.app)
10
- .post(`/dummy/customers`)
10
+ .post("/dummy/customers")
11
11
  .send(draft);
12
12
 
13
13
  return response.body.customer;
package/src/types.ts CHANGED
@@ -3,7 +3,27 @@ import type { RepositoryMap } from "./repositories";
3
3
 
4
4
  export const isType = <T>(x: T) => x;
5
5
 
6
- export type Writable<T> = { -readonly [P in keyof T]: Writable<T[P]> };
6
+ type Builtin =
7
+ | string
8
+ | number
9
+ | boolean
10
+ | undefined
11
+ | null
12
+ | symbol
13
+ | bigint
14
+ | Date
15
+ | RegExp;
16
+
17
+ export type Writable<T> = T extends Builtin
18
+ ? T
19
+ : T extends ReadonlyArray<infer U>
20
+ ? WritableArray<U>
21
+ : T extends object
22
+ ? { -readonly [P in keyof T]: Writable<T[P]> }
23
+ : T;
24
+
25
+ export interface WritableArray<T> extends Array<Writable<T>> {}
26
+
7
27
  export type ShallowWritable<T> = { -readonly [P in keyof T]: T[P] };
8
28
 
9
29
  export type ServiceTypes =
@@ -23,40 +43,40 @@ export type ResourceMap = {
23
43
  "associate-role": ctp.AssociateRole;
24
44
  "business-unit": ctp.BusinessUnit;
25
45
  "cart-discount": ctp.CartDiscount;
26
- "cart": ctp.Cart;
27
- "category": ctp.Category;
28
- "channel": ctp.Channel;
46
+ cart: ctp.Cart;
47
+ category: ctp.Category;
48
+ channel: ctp.Channel;
29
49
  "customer-email-token": never;
30
50
  "customer-group": ctp.CustomerGroup;
31
51
  "customer-password-token": never;
32
- "customer": ctp.Customer;
52
+ customer: ctp.Customer;
33
53
  "discount-code": ctp.DiscountCode;
34
- "extension": ctp.Extension;
54
+ extension: ctp.Extension;
35
55
  "inventory-entry": ctp.InventoryEntry;
36
56
  "key-value-document": ctp.CustomObject;
37
57
  "order-edit": ctp.OrderEdit;
38
- "order": ctp.Order;
39
- "payment": ctp.Payment;
58
+ order: ctp.Order;
59
+ payment: ctp.Payment;
40
60
  "product-discount": ctp.ProductDiscount;
41
61
  "product-price": ctp.StandalonePrice;
42
62
  "product-projection": ctp.ProductProjection;
43
63
  "product-selection": ctp.ProductSelection;
44
64
  "product-tailoring": ctp.ProductTailoring;
45
65
  "product-type": ctp.ProductType;
46
- "product": ctp.Product;
66
+ product: ctp.Product;
47
67
  "quote-request": ctp.QuoteRequest;
48
- "quote": ctp.Quote;
49
- "review": ctp.Review;
68
+ quote: ctp.Quote;
69
+ review: ctp.Review;
50
70
  "shipping-method": ctp.ShippingMethod;
51
71
  "shopping-list": ctp.ShoppingList;
52
72
  "staged-quote": ctp.StagedQuote;
53
73
  "standalone-price": ctp.StandalonePrice;
54
- "state": ctp.State;
55
- "store": ctp.Store;
56
- "subscription": ctp.Subscription;
74
+ state: ctp.State;
75
+ store: ctp.Store;
76
+ subscription: ctp.Subscription;
57
77
  "tax-category": ctp.TaxCategory;
58
- "type": ctp.Type;
59
- "zone": ctp.Zone;
78
+ type: ctp.Type;
79
+ zone: ctp.Zone;
60
80
  };
61
81
 
62
82
  export type PagedQueryResponseMap = {
@@ -64,38 +84,38 @@ export type PagedQueryResponseMap = {
64
84
  "associate-role": ctp.AssociateRolePagedQueryResponse;
65
85
  "business-unit": ctp.BusinessUnitPagedQueryResponse;
66
86
  "cart-discount": ctp.CartDiscountPagedQueryResponse;
67
- "cart": ctp.CartPagedQueryResponse;
68
- "category": ctp.CategoryPagedQueryResponse;
69
- "channel": ctp.ChannelPagedQueryResponse;
87
+ cart: ctp.CartPagedQueryResponse;
88
+ category: ctp.CategoryPagedQueryResponse;
89
+ channel: ctp.ChannelPagedQueryResponse;
70
90
  "customer-email-token": never;
71
91
  "customer-group": ctp.CustomerGroupPagedQueryResponse;
72
92
  "customer-password-token": never;
73
- "customer": ctp.CustomerPagedQueryResponse;
93
+ customer: ctp.CustomerPagedQueryResponse;
74
94
  "discount-code": ctp.DiscountCodePagedQueryResponse;
75
- "extension": ctp.ExtensionPagedQueryResponse;
95
+ extension: ctp.ExtensionPagedQueryResponse;
76
96
  "inventory-entry": ctp.InventoryPagedQueryResponse;
77
97
  "key-value-document": ctp.CustomObjectPagedQueryResponse;
78
98
  "order-edit": ctp.OrderEditPagedQueryResponse;
79
- "order": ctp.OrderPagedQueryResponse;
80
- "payment": ctp.PaymentPagedQueryResponse;
99
+ order: ctp.OrderPagedQueryResponse;
100
+ payment: ctp.PaymentPagedQueryResponse;
81
101
  "product-discount": ctp.ProductDiscountPagedQueryResponse;
82
102
  "product-price": ctp.StandalonePricePagedQueryResponse;
83
103
  "product-projection": ctp.ProductProjectionPagedQueryResponse;
84
104
  "product-selection": ctp.ProductSelectionPagedQueryResponse;
85
105
  "product-tailoring": ctp.ProductTailoringPagedQueryResponse;
86
106
  "product-type": ctp.ProductTypePagedQueryResponse;
87
- "product": ctp.ProductPagedQueryResponse;
107
+ product: ctp.ProductPagedQueryResponse;
88
108
  "quote-request": ctp.QuoteRequestPagedQueryResponse;
89
- "quote": ctp.QuotePagedQueryResponse;
90
- "review": ctp.ReviewPagedQueryResponse;
109
+ quote: ctp.QuotePagedQueryResponse;
110
+ review: ctp.ReviewPagedQueryResponse;
91
111
  "shipping-method": ctp.ShippingMethodPagedQueryResponse;
92
112
  "shopping-list": ctp.ShoppingListPagedQueryResponse;
93
113
  "staged-quote": ctp.StagedQuotePagedQueryResponse;
94
114
  "standalone-price": ctp.StandalonePricePagedQueryResponse;
95
- "state": ctp.StatePagedQueryResponse;
96
- "store": ctp.StorePagedQueryResponse;
97
- "subscription": ctp.SubscriptionPagedQueryResponse;
115
+ state: ctp.StatePagedQueryResponse;
116
+ store: ctp.StorePagedQueryResponse;
117
+ subscription: ctp.SubscriptionPagedQueryResponse;
98
118
  "tax-category": ctp.TaxCategoryPagedQueryResponse;
99
- "type": ctp.TypePagedQueryResponse;
100
- "zone": ctp.ZonePagedQueryResponse;
119
+ type: ctp.TypePagedQueryResponse;
120
+ zone: ctp.ZonePagedQueryResponse;
101
121
  };