@labdigital/commercetools-mock 2.17.1 → 2.18.1

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 (180) hide show
  1. package/dist/index.cjs +4351 -4099
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +266 -413
  4. package/dist/index.d.ts +266 -413
  5. package/dist/index.js +4351 -4099
  6. package/dist/index.js.map +1 -1
  7. package/package.json +47 -47
  8. package/src/constants.ts +2 -2
  9. package/src/ctMock.test.ts +11 -11
  10. package/src/ctMock.ts +141 -127
  11. package/src/deprecation.ts +8 -0
  12. package/src/exceptions.ts +17 -15
  13. package/src/helpers.ts +32 -32
  14. package/src/index.test.ts +128 -128
  15. package/src/index.ts +3 -3
  16. package/src/lib/expandParser.ts +13 -13
  17. package/src/lib/haversine.test.ts +9 -9
  18. package/src/lib/haversine.ts +11 -11
  19. package/src/lib/masking.ts +11 -11
  20. package/src/lib/parser.ts +2 -2
  21. package/src/lib/password.ts +23 -3
  22. package/src/lib/predicateParser.test.ts +185 -183
  23. package/src/lib/predicateParser.ts +234 -234
  24. package/src/lib/projectionSearchFilter.test.ts +103 -101
  25. package/src/lib/projectionSearchFilter.ts +152 -150
  26. package/src/lib/proxy.ts +5 -5
  27. package/src/oauth/errors.ts +4 -4
  28. package/src/oauth/helpers.ts +6 -6
  29. package/src/oauth/server.test.ts +86 -86
  30. package/src/oauth/server.ts +158 -144
  31. package/src/oauth/store.ts +44 -43
  32. package/src/priceSelector.test.ts +35 -35
  33. package/src/priceSelector.ts +30 -30
  34. package/src/product-projection-search.ts +136 -134
  35. package/src/projectAPI.test.ts +7 -7
  36. package/src/projectAPI.ts +24 -22
  37. package/src/repositories/abstract.ts +168 -116
  38. package/src/repositories/associate-role.ts +90 -77
  39. package/src/repositories/attribute-group.ts +51 -40
  40. package/src/repositories/business-unit.ts +168 -148
  41. package/src/repositories/cart/actions.ts +489 -0
  42. package/src/repositories/cart/helpers.ts +30 -0
  43. package/src/repositories/cart/index.ts +180 -0
  44. package/src/repositories/cart-discount/actions.ts +148 -0
  45. package/src/repositories/cart-discount/index.ts +86 -0
  46. package/src/repositories/category/actions.ts +231 -0
  47. package/src/repositories/category/index.ts +52 -0
  48. package/src/repositories/channel.ts +88 -90
  49. package/src/repositories/custom-object.ts +46 -45
  50. package/src/repositories/customer/actions.ts +165 -0
  51. package/src/repositories/customer/index.ts +79 -0
  52. package/src/repositories/customer-group.ts +66 -55
  53. package/src/repositories/discount-code/actions.ts +149 -0
  54. package/src/repositories/discount-code/index.ts +50 -0
  55. package/src/repositories/errors.ts +10 -10
  56. package/src/repositories/extension.ts +64 -62
  57. package/src/repositories/helpers.ts +117 -118
  58. package/src/repositories/index.ts +80 -79
  59. package/src/repositories/inventory-entry/actions.ts +84 -0
  60. package/src/repositories/inventory-entry/index.ts +44 -0
  61. package/src/repositories/my-customer.ts +114 -0
  62. package/src/repositories/my-order.ts +8 -8
  63. package/src/repositories/order/actions.ts +281 -0
  64. package/src/repositories/{order.test.ts → order/index.test.ts} +77 -77
  65. package/src/repositories/order/index.ts +260 -0
  66. package/src/repositories/order-edit.ts +10 -23
  67. package/src/repositories/payment/actions.ts +305 -0
  68. package/src/repositories/payment/helpers.ts +17 -0
  69. package/src/repositories/payment/index.ts +56 -0
  70. package/src/repositories/product/actions.ts +943 -0
  71. package/src/repositories/product/helpers.ts +98 -0
  72. package/src/repositories/product/index.ts +130 -0
  73. package/src/repositories/product-discount.ts +127 -117
  74. package/src/repositories/product-projection.ts +56 -62
  75. package/src/repositories/product-selection.ts +31 -28
  76. package/src/repositories/product-type.ts +136 -134
  77. package/src/repositories/project.ts +133 -118
  78. package/src/repositories/quote-request.ts +7 -19
  79. package/src/repositories/quote.ts +7 -22
  80. package/src/repositories/review.ts +13 -26
  81. package/src/repositories/shipping-method/actions.ts +198 -0
  82. package/src/repositories/shipping-method/helpers.ts +10 -0
  83. package/src/repositories/shipping-method/index.ts +138 -0
  84. package/src/repositories/shopping-list/actions.ts +295 -0
  85. package/src/repositories/shopping-list/index.ts +122 -0
  86. package/src/repositories/staged-quote.ts +7 -20
  87. package/src/repositories/standalone-price.ts +57 -44
  88. package/src/repositories/state.ts +113 -68
  89. package/src/repositories/store.ts +106 -94
  90. package/src/repositories/subscription.ts +46 -22
  91. package/src/repositories/tax-category/actions.ts +94 -0
  92. package/src/repositories/tax-category/helpers.ts +8 -0
  93. package/src/repositories/tax-category/index.ts +25 -0
  94. package/src/repositories/type/actions.ts +162 -0
  95. package/src/repositories/type/index.ts +24 -0
  96. package/src/repositories/zone.ts +62 -58
  97. package/src/schemas/update-request.ts +12 -0
  98. package/src/server.ts +9 -9
  99. package/src/services/abstract.ts +85 -72
  100. package/src/services/associate-roles.test.ts +27 -27
  101. package/src/services/associate-roles.ts +7 -7
  102. package/src/services/attribute-group.ts +7 -7
  103. package/src/services/business-units.test.ts +28 -28
  104. package/src/services/business-units.ts +7 -7
  105. package/src/services/cart-discount.test.ts +199 -199
  106. package/src/services/cart-discount.ts +7 -7
  107. package/src/services/cart.test.ts +261 -261
  108. package/src/services/cart.ts +22 -21
  109. package/src/services/category.test.ts +121 -121
  110. package/src/services/category.ts +7 -7
  111. package/src/services/channel.ts +7 -7
  112. package/src/services/custom-object.test.ts +130 -130
  113. package/src/services/custom-object.ts +34 -31
  114. package/src/services/customer-group.ts +7 -7
  115. package/src/services/customer.test.ts +205 -205
  116. package/src/services/customer.ts +23 -36
  117. package/src/services/discount-code.ts +7 -7
  118. package/src/services/extension.ts +7 -7
  119. package/src/services/index.ts +85 -81
  120. package/src/services/inventory-entry.test.ts +106 -106
  121. package/src/services/inventory-entry.ts +7 -7
  122. package/src/services/my-cart.test.ts +56 -56
  123. package/src/services/my-cart.ts +20 -20
  124. package/src/services/my-customer.test.ts +155 -104
  125. package/src/services/my-customer.ts +66 -75
  126. package/src/services/my-order.ts +16 -16
  127. package/src/services/my-payment.test.ts +40 -40
  128. package/src/services/my-payment.ts +7 -7
  129. package/src/services/my-shopping-list.ts +7 -7
  130. package/src/services/order.test.ts +243 -243
  131. package/src/services/order.ts +23 -18
  132. package/src/services/payment.test.ts +40 -40
  133. package/src/services/payment.ts +7 -7
  134. package/src/services/product-discount.ts +7 -7
  135. package/src/services/product-projection.test.ts +190 -190
  136. package/src/services/product-projection.ts +34 -32
  137. package/src/services/product-selection.test.ts +19 -19
  138. package/src/services/product-selection.ts +7 -7
  139. package/src/services/product-type.test.ts +38 -38
  140. package/src/services/product-type.ts +7 -7
  141. package/src/services/product.test.ts +658 -656
  142. package/src/services/product.ts +7 -7
  143. package/src/services/project.test.ts +29 -24
  144. package/src/services/project.ts +22 -17
  145. package/src/services/reviews.ts +7 -7
  146. package/src/services/shipping-method.test.ts +78 -78
  147. package/src/services/shipping-method.ts +16 -16
  148. package/src/services/shopping-list.test.ts +170 -170
  149. package/src/services/shopping-list.ts +7 -7
  150. package/src/services/standalone-price.test.ts +112 -112
  151. package/src/services/standalone-price.ts +7 -7
  152. package/src/services/state.test.ts +30 -30
  153. package/src/services/state.ts +7 -7
  154. package/src/services/store.test.ts +40 -40
  155. package/src/services/store.ts +7 -7
  156. package/src/services/subscription.ts +7 -7
  157. package/src/services/tax-category.test.ts +43 -43
  158. package/src/services/tax-category.ts +7 -7
  159. package/src/services/type.ts +7 -7
  160. package/src/services/zone.ts +7 -7
  161. package/src/shippingCalculator.test.ts +43 -43
  162. package/src/shippingCalculator.ts +23 -23
  163. package/src/storage/abstract.ts +36 -34
  164. package/src/storage/in-memory.ts +237 -233
  165. package/src/storage/index.ts +2 -2
  166. package/src/types.ts +91 -91
  167. package/src/validate.ts +18 -0
  168. package/src/repositories/cart-discount.ts +0 -219
  169. package/src/repositories/cart.ts +0 -659
  170. package/src/repositories/category.ts +0 -256
  171. package/src/repositories/customer.ts +0 -228
  172. package/src/repositories/discount-code.ts +0 -181
  173. package/src/repositories/inventory-entry.ts +0 -109
  174. package/src/repositories/order.ts +0 -514
  175. package/src/repositories/payment.ts +0 -342
  176. package/src/repositories/product.ts +0 -1106
  177. package/src/repositories/shipping-method.ts +0 -312
  178. package/src/repositories/shopping-list.ts +0 -392
  179. package/src/repositories/tax-category.ts +0 -111
  180. package/src/repositories/type.ts +0 -172
@@ -1,342 +0,0 @@
1
- import type {
2
- CustomerReference,
3
- Payment,
4
- PaymentAddInterfaceInteractionAction,
5
- PaymentAddTransactionAction,
6
- PaymentChangeAmountPlannedAction,
7
- PaymentChangeTransactionInteractionIdAction,
8
- PaymentChangeTransactionStateAction,
9
- PaymentChangeTransactionTimestampAction,
10
- PaymentDraft,
11
- PaymentSetAnonymousIdAction,
12
- PaymentSetCustomFieldAction,
13
- PaymentSetCustomTypeAction,
14
- PaymentSetCustomerAction,
15
- PaymentSetInterfaceIdAction,
16
- PaymentSetKeyAction,
17
- PaymentSetMethodInfoInterfaceAction,
18
- PaymentSetMethodInfoMethodAction,
19
- PaymentSetMethodInfoNameAction,
20
- PaymentSetStatusInterfaceCodeAction,
21
- PaymentSetStatusInterfaceTextAction,
22
- PaymentSetTransactionCustomFieldAction,
23
- PaymentSetTransactionCustomTypeAction,
24
- PaymentTransitionStateAction,
25
- PaymentUpdateAction,
26
- State,
27
- StateReference,
28
- Transaction,
29
- TransactionDraft,
30
- } from '@commercetools/platform-sdk'
31
- import { v4 as uuidv4 } from 'uuid'
32
- import { getBaseResourceProperties } from '../helpers.js'
33
- import type { Writable } from '../types.js'
34
- import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
35
- import {
36
- createCentPrecisionMoney,
37
- createCustomFields,
38
- getReferenceFromResourceIdentifier,
39
- } from './helpers.js'
40
-
41
- export class PaymentRepository extends AbstractResourceRepository<'payment'> {
42
- getTypeId() {
43
- return 'payment' as const
44
- }
45
-
46
- create(context: RepositoryContext, draft: PaymentDraft): Payment {
47
- const resource: Payment = {
48
- ...getBaseResourceProperties(),
49
- amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
50
- paymentMethodInfo: draft.paymentMethodInfo!,
51
- paymentStatus: draft.paymentStatus
52
- ? {
53
- ...draft.paymentStatus,
54
- state: draft.paymentStatus.state
55
- ? getReferenceFromResourceIdentifier<StateReference>(
56
- draft.paymentStatus.state,
57
- context.projectKey,
58
- this._storage
59
- )
60
- : undefined,
61
- }
62
- : {},
63
- transactions: (draft.transactions || []).map((t) =>
64
- this.transactionFromTransactionDraft(t, context)
65
- ),
66
- interfaceInteractions: (draft.interfaceInteractions || []).map(
67
- (interaction) =>
68
- createCustomFields(interaction, context.projectKey, this._storage)!
69
- ),
70
- custom: createCustomFields(
71
- draft.custom,
72
- context.projectKey,
73
- this._storage
74
- ),
75
- }
76
-
77
- this.saveNew(context, resource)
78
- return resource
79
- }
80
-
81
- transactionFromTransactionDraft = (
82
- draft: TransactionDraft,
83
- context: RepositoryContext
84
- ): Transaction => ({
85
- ...draft,
86
- id: uuidv4(),
87
- amount: createCentPrecisionMoney(draft.amount),
88
- custom: createCustomFields(draft.custom, context.projectKey, this._storage),
89
- state: draft.state ?? 'Initial', // Documented as default
90
- })
91
-
92
- actions: Record<
93
- PaymentUpdateAction['action'],
94
- (
95
- context: RepositoryContext,
96
- resource: Writable<Payment>,
97
- action: any
98
- ) => void
99
- > = {
100
- addInterfaceInteraction: (
101
- context: RepositoryContext,
102
- resource: Writable<Payment>,
103
- { type, fields }: PaymentAddInterfaceInteractionAction
104
- ) => {
105
- resource.interfaceInteractions.push(
106
- createCustomFields({ type, fields }, context.projectKey, this._storage)!
107
- )
108
- },
109
- addTransaction: (
110
- context: RepositoryContext,
111
- resource: Writable<Payment>,
112
- { transaction }: PaymentAddTransactionAction
113
- ) => {
114
- resource.transactions = [
115
- ...resource.transactions,
116
- this.transactionFromTransactionDraft(transaction, context),
117
- ]
118
- },
119
- changeAmountPlanned: (
120
- _context: RepositoryContext,
121
- resource: Writable<Payment>,
122
- { amount }: PaymentChangeAmountPlannedAction
123
- ) => {
124
- resource.amountPlanned = createCentPrecisionMoney(amount)
125
- },
126
- changeTransactionInteractionId: (
127
- _context: RepositoryContext,
128
- resource: Writable<Payment>,
129
- {
130
- transactionId,
131
- interactionId,
132
- }: PaymentChangeTransactionInteractionIdAction
133
- ) => {
134
- const transaction = resource.transactions.find(
135
- (e: Transaction) => e.id === transactionId
136
- )
137
- if (transaction) {
138
- transaction.interactionId = interactionId
139
- }
140
- },
141
- changeTransactionState: (
142
- _context: RepositoryContext,
143
- resource: Writable<Payment>,
144
- { transactionId, state }: PaymentChangeTransactionStateAction
145
- ) => {
146
- const index = resource.transactions.findIndex(
147
- (e: Transaction) => e.id === transactionId
148
- )
149
- const updatedTransaction: Transaction = {
150
- ...resource.transactions[index],
151
- state,
152
- }
153
- resource.transactions[index] = updatedTransaction
154
- },
155
- changeTransactionTimestamp: (
156
- _context: RepositoryContext,
157
- resource: Writable<Payment>,
158
- { transactionId, timestamp }: PaymentChangeTransactionTimestampAction
159
- ) => {
160
- const transaction = resource.transactions.find(
161
- (e: Transaction) => e.id === transactionId
162
- )
163
- if (transaction) {
164
- transaction.timestamp = timestamp
165
- }
166
- },
167
- transitionState: (
168
- context: RepositoryContext,
169
- resource: Writable<Payment>,
170
- { state }: PaymentTransitionStateAction
171
- ) => {
172
- const stateObj = this._storage.getByResourceIdentifier(
173
- context.projectKey,
174
- state
175
- ) as State | null
176
-
177
- if (!stateObj) {
178
- throw new Error(`State ${state} not found`)
179
- }
180
-
181
- resource.paymentStatus.state = {
182
- typeId: 'state',
183
- id: stateObj.id,
184
- obj: stateObj,
185
- }
186
- },
187
- setAnonymousId: (
188
- _context: RepositoryContext,
189
- resource: Writable<Payment>,
190
- { anonymousId }: PaymentSetAnonymousIdAction
191
- ) => {
192
- resource.anonymousId = anonymousId
193
- resource.customer = undefined
194
- },
195
- setCustomer: (
196
- _context: RepositoryContext,
197
- resource: Writable<Payment>,
198
- { customer }: PaymentSetCustomerAction
199
- ) => {
200
- if (customer) {
201
- const c = getReferenceFromResourceIdentifier<CustomerReference>(
202
- customer,
203
- _context.projectKey,
204
- this._storage
205
- )
206
- resource.customer = c
207
- resource.anonymousId = undefined
208
- }
209
- },
210
- setCustomField: (
211
- context: RepositoryContext,
212
- resource: Payment,
213
- { name, value }: PaymentSetCustomFieldAction
214
- ) => {
215
- if (!resource.custom) {
216
- throw new Error('Resource has no custom field')
217
- }
218
-
219
- resource.custom.fields[name] = value
220
- },
221
- setCustomType: (
222
- context: RepositoryContext,
223
- resource: Writable<Payment>,
224
- { type, fields }: PaymentSetCustomTypeAction
225
- ) => {
226
- if (!type) {
227
- resource.custom = undefined
228
- } else {
229
- const resolvedType = this._storage.getByResourceIdentifier(
230
- context.projectKey,
231
- type
232
- )
233
- if (!resolvedType) {
234
- throw new Error(`Type ${type} not found`)
235
- }
236
-
237
- resource.custom = {
238
- type: {
239
- typeId: 'type',
240
- id: resolvedType.id,
241
- },
242
- fields: fields ?? {},
243
- }
244
- }
245
- },
246
- setInterfaceId: (
247
- _context: RepositoryContext,
248
- resource: Writable<Payment>,
249
- { interfaceId }: PaymentSetInterfaceIdAction
250
- ) => {
251
- resource.interfaceId = interfaceId
252
- },
253
- setKey: (
254
- _context: RepositoryContext,
255
- resource: Writable<Payment>,
256
- { key }: PaymentSetKeyAction
257
- ) => {
258
- resource.key = key
259
- },
260
- setMethodInfoMethod: (
261
- _context: RepositoryContext,
262
- resource: Writable<Payment>,
263
- { method }: PaymentSetMethodInfoMethodAction
264
- ) => {
265
- resource.paymentMethodInfo.method = method
266
- },
267
- setMethodInfoName: (
268
- _context: RepositoryContext,
269
- resource: Writable<Payment>,
270
- { name }: PaymentSetMethodInfoNameAction
271
- ) => {
272
- resource.paymentMethodInfo.name = name
273
- },
274
- setMethodInfoInterface: (
275
- _context: RepositoryContext,
276
- resource: Writable<Payment>,
277
- args: PaymentSetMethodInfoInterfaceAction
278
- ) => {
279
- resource.paymentMethodInfo.paymentInterface = args.interface
280
- },
281
- setStatusInterfaceCode: (
282
- _context: RepositoryContext,
283
- resource: Writable<Payment>,
284
- { interfaceCode }: PaymentSetStatusInterfaceCodeAction
285
- ) => {
286
- resource.paymentStatus.interfaceCode = interfaceCode
287
- },
288
- setStatusInterfaceText: (
289
- _context: RepositoryContext,
290
- resource: Writable<Payment>,
291
- { interfaceText }: PaymentSetStatusInterfaceTextAction
292
- ) => {
293
- resource.paymentStatus.interfaceText = interfaceText
294
- },
295
- setTransactionCustomField: (
296
- _context: RepositoryContext,
297
- resource: Writable<Payment>,
298
- { transactionId, name, value }: PaymentSetTransactionCustomFieldAction
299
- ) => {
300
- const transaction = resource.transactions.find(
301
- (e: Transaction) => e.id === transactionId
302
- )
303
- if (transaction) {
304
- if (!transaction.custom) {
305
- throw new Error('Transaction has no custom field')
306
- }
307
-
308
- transaction.custom.fields[name] = value
309
- }
310
- },
311
- setTransactionCustomType: (
312
- context: RepositoryContext,
313
- resource: Writable<Payment>,
314
- { transactionId, type, fields }: PaymentSetTransactionCustomTypeAction
315
- ) => {
316
- const transaction = resource.transactions.find(
317
- (e: Transaction) => e.id === transactionId
318
- )
319
- if (transaction) {
320
- if (!type) {
321
- transaction.custom = undefined
322
- } else {
323
- const resolvedType = this._storage.getByResourceIdentifier(
324
- context.projectKey,
325
- type
326
- )
327
- if (!resolvedType) {
328
- throw new Error(`Type ${type} not found`)
329
- }
330
-
331
- transaction.custom = {
332
- type: {
333
- typeId: 'type',
334
- id: resolvedType.id,
335
- },
336
- fields: fields ?? {},
337
- }
338
- }
339
- }
340
- },
341
- }
342
- }