@labdigital/commercetools-mock 1.4.0 → 1.6.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 (129) hide show
  1. package/README.md +5 -4
  2. package/dist/index.cjs +116 -18
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +30 -7
  5. package/dist/index.d.ts +30 -7
  6. package/dist/index.js +116 -18
  7. package/dist/index.js.map +1 -1
  8. package/package.json +4 -3
  9. package/src/constants.ts +2 -2
  10. package/src/ctMock.ts +176 -176
  11. package/src/exceptions.ts +10 -10
  12. package/src/helpers.ts +26 -26
  13. package/src/index.test.ts +173 -173
  14. package/src/index.ts +3 -3
  15. package/src/lib/expandParser.ts +19 -19
  16. package/src/lib/haversine.test.ts +13 -13
  17. package/src/lib/haversine.ts +14 -14
  18. package/src/lib/masking.ts +15 -15
  19. package/src/lib/parser.ts +2 -2
  20. package/src/lib/predicateParser.test.ts +204 -204
  21. package/src/lib/predicateParser.ts +398 -398
  22. package/src/lib/projectionSearchFilter.test.ts +168 -168
  23. package/src/lib/projectionSearchFilter.ts +272 -269
  24. package/src/lib/proxy.ts +8 -8
  25. package/src/oauth/errors.ts +4 -4
  26. package/src/oauth/helpers.ts +6 -6
  27. package/src/oauth/server.ts +103 -101
  28. package/src/oauth/store.ts +27 -27
  29. package/src/priceSelector.test.ts +68 -68
  30. package/src/priceSelector.ts +70 -70
  31. package/src/product-projection-search.ts +296 -296
  32. package/src/projectAPI.test.ts +3 -3
  33. package/src/projectAPI.ts +46 -46
  34. package/src/repositories/abstract.ts +190 -190
  35. package/src/repositories/associate-role.ts +10 -7
  36. package/src/repositories/attribute-group.ts +63 -8
  37. package/src/repositories/business-unit.ts +10 -7
  38. package/src/repositories/cart-discount.ts +134 -134
  39. package/src/repositories/cart.ts +517 -514
  40. package/src/repositories/category.ts +170 -167
  41. package/src/repositories/channel.ts +114 -111
  42. package/src/repositories/custom-object.ts +66 -63
  43. package/src/repositories/customer-group.ts +72 -69
  44. package/src/repositories/customer.ts +93 -79
  45. package/src/repositories/discount-code.ts +171 -168
  46. package/src/repositories/errors.ts +15 -15
  47. package/src/repositories/extension.ts +79 -76
  48. package/src/repositories/helpers.ts +180 -180
  49. package/src/repositories/index.ts +39 -39
  50. package/src/repositories/inventory-entry.ts +98 -95
  51. package/src/repositories/my-order.ts +11 -11
  52. package/src/repositories/order-edit.ts +29 -29
  53. package/src/repositories/order.test.ts +191 -191
  54. package/src/repositories/order.ts +393 -389
  55. package/src/repositories/payment.ts +155 -155
  56. package/src/repositories/product-discount.ts +149 -149
  57. package/src/repositories/product-projection.ts +116 -52
  58. package/src/repositories/product-selection.ts +31 -31
  59. package/src/repositories/product-type.ts +156 -156
  60. package/src/repositories/product.ts +600 -597
  61. package/src/repositories/project.ts +136 -135
  62. package/src/repositories/quote-request.ts +19 -19
  63. package/src/repositories/quote.ts +19 -19
  64. package/src/repositories/review.ts +24 -24
  65. package/src/repositories/shipping-method.ts +217 -217
  66. package/src/repositories/shopping-list.ts +49 -49
  67. package/src/repositories/staged-quote.ts +20 -20
  68. package/src/repositories/standalone-price.ts +72 -61
  69. package/src/repositories/state.ts +84 -84
  70. package/src/repositories/store.ts +114 -114
  71. package/src/repositories/subscription.ts +40 -40
  72. package/src/repositories/tax-category.ts +98 -98
  73. package/src/repositories/type.ts +157 -157
  74. package/src/repositories/zone.ts +71 -71
  75. package/src/server.ts +2 -2
  76. package/src/services/abstract.ts +173 -173
  77. package/src/services/attribute-group.ts +16 -0
  78. package/src/services/cart-discount.ts +8 -8
  79. package/src/services/cart.test.ts +409 -409
  80. package/src/services/cart.ts +50 -50
  81. package/src/services/category.test.ts +25 -25
  82. package/src/services/category.ts +8 -8
  83. package/src/services/channel.ts +8 -8
  84. package/src/services/custom-object.test.ts +184 -184
  85. package/src/services/custom-object.ts +48 -48
  86. package/src/services/customer-group.ts +8 -8
  87. package/src/services/customer.test.ts +151 -129
  88. package/src/services/customer.ts +27 -27
  89. package/src/services/discount-code.ts +8 -8
  90. package/src/services/extension.ts +8 -8
  91. package/src/services/index.ts +52 -44
  92. package/src/services/inventory-entry.test.ts +162 -162
  93. package/src/services/inventory-entry.ts +8 -8
  94. package/src/services/my-cart.test.ts +78 -78
  95. package/src/services/my-cart.ts +28 -28
  96. package/src/services/my-customer.test.ts +44 -44
  97. package/src/services/my-customer.ts +53 -53
  98. package/src/services/my-order.ts +20 -20
  99. package/src/services/my-payment.test.ts +65 -65
  100. package/src/services/my-payment.ts +8 -8
  101. package/src/services/order.test.ts +527 -527
  102. package/src/services/order.ts +31 -31
  103. package/src/services/payment.test.ts +65 -65
  104. package/src/services/payment.ts +8 -8
  105. package/src/services/product-discount.ts +8 -8
  106. package/src/services/product-projection.test.ts +492 -428
  107. package/src/services/product-projection.ts +32 -18
  108. package/src/services/product-type.test.ts +56 -56
  109. package/src/services/product-type.ts +8 -8
  110. package/src/services/product.test.ts +510 -510
  111. package/src/services/product.ts +8 -8
  112. package/src/services/project.ts +34 -34
  113. package/src/services/shipping-method.test.ts +81 -81
  114. package/src/services/shipping-method.ts +12 -12
  115. package/src/services/shopping-list.ts +8 -8
  116. package/src/services/standalone-price.test.ts +256 -256
  117. package/src/services/standalone-price.ts +8 -8
  118. package/src/services/state.test.ts +42 -42
  119. package/src/services/state.ts +8 -8
  120. package/src/services/store.test.ts +57 -57
  121. package/src/services/store.ts +8 -8
  122. package/src/services/subscription.ts +8 -8
  123. package/src/services/tax-category.test.ts +61 -61
  124. package/src/services/tax-category.ts +8 -8
  125. package/src/services/type.ts +8 -8
  126. package/src/services/zone.ts +8 -8
  127. package/src/storage/abstract.ts +58 -58
  128. package/src/storage/in-memory.ts +419 -419
  129. package/src/types.ts +82 -82
@@ -1,106 +1,109 @@
1
1
  import type {
2
- InventoryEntry,
3
- InventoryEntryChangeQuantityAction,
4
- InventoryEntryDraft,
5
- InventoryEntrySetCustomFieldAction,
6
- InventoryEntrySetCustomTypeAction,
7
- InventoryEntrySetExpectedDeliveryAction,
8
- InventoryEntrySetRestockableInDaysAction,
2
+ InventoryEntry,
3
+ InventoryEntryChangeQuantityAction,
4
+ InventoryEntryDraft,
5
+ InventoryEntrySetCustomFieldAction,
6
+ InventoryEntrySetCustomTypeAction,
7
+ InventoryEntrySetExpectedDeliveryAction,
8
+ InventoryEntrySetRestockableInDaysAction,
9
9
  } from '@commercetools/platform-sdk'
10
10
  import { getBaseResourceProperties } from '../helpers.js'
11
11
  import type { Writable } from '../types.js'
12
- import { AbstractResourceRepository, type RepositoryContext } from './abstract.js'
12
+ import {
13
+ AbstractResourceRepository,
14
+ type RepositoryContext,
15
+ } from './abstract.js'
13
16
  import { createCustomFields } from './helpers.js'
14
17
 
15
18
  export class InventoryEntryRepository extends AbstractResourceRepository<'inventory-entry'> {
16
- getTypeId() {
17
- return 'inventory-entry' as const
18
- }
19
+ getTypeId() {
20
+ return 'inventory-entry' as const
21
+ }
19
22
 
20
- create(
21
- context: RepositoryContext,
22
- draft: InventoryEntryDraft
23
- ): InventoryEntry {
24
- const resource: InventoryEntry = {
25
- ...getBaseResourceProperties(),
26
- sku: draft.sku,
27
- quantityOnStock: draft.quantityOnStock,
28
- availableQuantity: draft.quantityOnStock,
29
- expectedDelivery: draft.expectedDelivery,
30
- restockableInDays: draft.restockableInDays,
31
- supplyChannel: {
32
- ...draft.supplyChannel,
33
- typeId: 'channel',
34
- id: draft.supplyChannel?.id ?? '',
35
- },
36
- custom: createCustomFields(
37
- draft.custom,
38
- context.projectKey,
39
- this._storage
40
- ),
41
- }
42
- this.saveNew(context, resource)
43
- return resource
44
- }
23
+ create(
24
+ context: RepositoryContext,
25
+ draft: InventoryEntryDraft
26
+ ): InventoryEntry {
27
+ const resource: InventoryEntry = {
28
+ ...getBaseResourceProperties(),
29
+ sku: draft.sku,
30
+ quantityOnStock: draft.quantityOnStock,
31
+ availableQuantity: draft.quantityOnStock,
32
+ expectedDelivery: draft.expectedDelivery,
33
+ restockableInDays: draft.restockableInDays,
34
+ supplyChannel: {
35
+ ...draft.supplyChannel,
36
+ typeId: 'channel',
37
+ id: draft.supplyChannel?.id ?? '',
38
+ },
39
+ custom: createCustomFields(
40
+ draft.custom,
41
+ context.projectKey,
42
+ this._storage
43
+ ),
44
+ }
45
+ this.saveNew(context, resource)
46
+ return resource
47
+ }
45
48
 
46
- actions = {
47
- changeQuantity: (
48
- context: RepositoryContext,
49
- resource: Writable<InventoryEntry>,
50
- { quantity }: InventoryEntryChangeQuantityAction
51
- ) => {
52
- resource.quantityOnStock = quantity
53
- // don't know active reservations so just set to same value
54
- resource.availableQuantity = quantity
55
- },
56
- setExpectedDelivery: (
57
- context: RepositoryContext,
58
- resource: Writable<InventoryEntry>,
59
- { expectedDelivery }: InventoryEntrySetExpectedDeliveryAction
60
- ) => {
61
- resource.expectedDelivery = new Date(expectedDelivery!).toISOString()
62
- },
63
- setCustomField: (
64
- context: RepositoryContext,
65
- resource: InventoryEntry,
66
- { name, value }: InventoryEntrySetCustomFieldAction
67
- ) => {
68
- if (!resource.custom) {
69
- throw new Error('Resource has no custom field')
70
- }
71
- resource.custom.fields[name] = value
72
- },
73
- setCustomType: (
74
- context: RepositoryContext,
75
- resource: Writable<InventoryEntry>,
76
- { type, fields }: InventoryEntrySetCustomTypeAction
77
- ) => {
78
- if (!type) {
79
- resource.custom = undefined
80
- } else {
81
- const resolvedType = this._storage.getByResourceIdentifier(
82
- context.projectKey,
83
- type
84
- )
85
- if (!resolvedType) {
86
- throw new Error(`Type ${type} not found`)
87
- }
49
+ actions = {
50
+ changeQuantity: (
51
+ context: RepositoryContext,
52
+ resource: Writable<InventoryEntry>,
53
+ { quantity }: InventoryEntryChangeQuantityAction
54
+ ) => {
55
+ resource.quantityOnStock = quantity
56
+ // don't know active reservations so just set to same value
57
+ resource.availableQuantity = quantity
58
+ },
59
+ setExpectedDelivery: (
60
+ context: RepositoryContext,
61
+ resource: Writable<InventoryEntry>,
62
+ { expectedDelivery }: InventoryEntrySetExpectedDeliveryAction
63
+ ) => {
64
+ resource.expectedDelivery = new Date(expectedDelivery!).toISOString()
65
+ },
66
+ setCustomField: (
67
+ context: RepositoryContext,
68
+ resource: InventoryEntry,
69
+ { name, value }: InventoryEntrySetCustomFieldAction
70
+ ) => {
71
+ if (!resource.custom) {
72
+ throw new Error('Resource has no custom field')
73
+ }
74
+ resource.custom.fields[name] = value
75
+ },
76
+ setCustomType: (
77
+ context: RepositoryContext,
78
+ resource: Writable<InventoryEntry>,
79
+ { type, fields }: InventoryEntrySetCustomTypeAction
80
+ ) => {
81
+ if (!type) {
82
+ resource.custom = undefined
83
+ } else {
84
+ const resolvedType = this._storage.getByResourceIdentifier(
85
+ context.projectKey,
86
+ type
87
+ )
88
+ if (!resolvedType) {
89
+ throw new Error(`Type ${type} not found`)
90
+ }
88
91
 
89
- resource.custom = {
90
- type: {
91
- typeId: 'type',
92
- id: resolvedType.id,
93
- },
94
- fields: fields || {},
95
- }
96
- }
97
- },
98
- setRestockableInDays: (
99
- context: RepositoryContext,
100
- resource: Writable<InventoryEntry>,
101
- { restockableInDays }: InventoryEntrySetRestockableInDaysAction
102
- ) => {
103
- resource.restockableInDays = restockableInDays
104
- },
105
- }
92
+ resource.custom = {
93
+ type: {
94
+ typeId: 'type',
95
+ id: resolvedType.id,
96
+ },
97
+ fields: fields || {},
98
+ }
99
+ }
100
+ },
101
+ setRestockableInDays: (
102
+ context: RepositoryContext,
103
+ resource: Writable<InventoryEntry>,
104
+ { restockableInDays }: InventoryEntrySetRestockableInDaysAction
105
+ ) => {
106
+ resource.restockableInDays = restockableInDays
107
+ },
108
+ }
106
109
  }
@@ -1,19 +1,19 @@
1
1
  import type {
2
- CartReference,
3
- MyOrderFromCartDraft,
4
- Order,
2
+ CartReference,
3
+ MyOrderFromCartDraft,
4
+ Order,
5
5
  } from '@commercetools/platform-sdk'
6
6
  import assert from 'assert'
7
7
  import { type RepositoryContext } from './abstract.js'
8
8
  import { OrderRepository } from './order.js'
9
9
 
10
10
  export class MyOrderRepository extends OrderRepository {
11
- create(context: RepositoryContext, draft: MyOrderFromCartDraft): Order {
12
- assert(draft.id, 'draft.id is missing')
13
- const cartIdentifier = {
14
- id: draft.id,
15
- typeId: 'cart',
16
- } as CartReference
17
- return this.createFromCart(context, cartIdentifier)
18
- }
11
+ create(context: RepositoryContext, draft: MyOrderFromCartDraft): Order {
12
+ assert(draft.id, 'draft.id is missing')
13
+ const cartIdentifier = {
14
+ id: draft.id,
15
+ typeId: 'cart',
16
+ } as CartReference
17
+ return this.createFromCart(context, cartIdentifier)
18
+ }
19
19
  }
@@ -1,39 +1,39 @@
1
1
  import type {
2
- OrderEdit,
3
- OrderEditDraft,
4
- OrderEditResult,
5
- OrderEditUpdateAction,
2
+ OrderEdit,
3
+ OrderEditDraft,
4
+ OrderEditResult,
5
+ OrderEditUpdateAction,
6
6
  } from '@commercetools/platform-sdk'
7
7
  import { getBaseResourceProperties } from '../helpers.js'
8
8
  import type { Writable } from '../types.js'
9
9
  import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
10
10
 
11
11
  export class OrderEditRepository extends AbstractResourceRepository<'order-edit'> {
12
- getTypeId() {
13
- return 'order-edit' as const
14
- }
12
+ getTypeId() {
13
+ return 'order-edit' as const
14
+ }
15
15
 
16
- create(context: RepositoryContext, draft: OrderEditDraft): OrderEdit {
17
- const resource: OrderEdit = {
18
- ...getBaseResourceProperties(),
19
- stagedActions: draft.stagedActions ?? [],
20
- resource: draft.resource,
21
- result: {
22
- type: 'NotProcessed',
23
- } as OrderEditResult,
24
- }
25
- this.saveNew(context, resource)
26
- return resource
27
- }
16
+ create(context: RepositoryContext, draft: OrderEditDraft): OrderEdit {
17
+ const resource: OrderEdit = {
18
+ ...getBaseResourceProperties(),
19
+ stagedActions: draft.stagedActions ?? [],
20
+ resource: draft.resource,
21
+ result: {
22
+ type: 'NotProcessed',
23
+ } as OrderEditResult,
24
+ }
25
+ this.saveNew(context, resource)
26
+ return resource
27
+ }
28
28
 
29
- actions: Partial<
30
- Record<
31
- OrderEditUpdateAction['action'],
32
- (
33
- context: RepositoryContext,
34
- resource: Writable<OrderEdit>,
35
- action: any
36
- ) => void
37
- >
38
- > = {}
29
+ actions: Partial<
30
+ Record<
31
+ OrderEditUpdateAction['action'],
32
+ (
33
+ context: RepositoryContext,
34
+ resource: Writable<OrderEdit>,
35
+ action: any
36
+ ) => void
37
+ >
38
+ > = {}
39
39
  }