@labdigital/commercetools-mock 2.17.0 → 2.18.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 (178) hide show
  1. package/dist/index.cjs +4219 -3989
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +268 -415
  4. package/dist/index.d.ts +268 -415
  5. package/dist/index.js +4219 -3989
  6. package/dist/index.js.map +1 -1
  7. package/package.json +44 -46
  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 +110 -67
  30. package/src/oauth/server.ts +161 -141
  31. package/src/oauth/store.ts +49 -44
  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/server.ts +9 -9
  98. package/src/services/abstract.ts +75 -72
  99. package/src/services/associate-roles.test.ts +27 -27
  100. package/src/services/associate-roles.ts +7 -7
  101. package/src/services/attribute-group.ts +7 -7
  102. package/src/services/business-units.test.ts +28 -28
  103. package/src/services/business-units.ts +7 -7
  104. package/src/services/cart-discount.test.ts +199 -199
  105. package/src/services/cart-discount.ts +7 -7
  106. package/src/services/cart.test.ts +261 -261
  107. package/src/services/cart.ts +22 -21
  108. package/src/services/category.test.ts +121 -121
  109. package/src/services/category.ts +7 -7
  110. package/src/services/channel.ts +7 -7
  111. package/src/services/custom-object.test.ts +130 -130
  112. package/src/services/custom-object.ts +34 -31
  113. package/src/services/customer-group.ts +7 -7
  114. package/src/services/customer.test.ts +205 -205
  115. package/src/services/customer.ts +31 -29
  116. package/src/services/discount-code.ts +7 -7
  117. package/src/services/extension.ts +7 -7
  118. package/src/services/index.ts +85 -81
  119. package/src/services/inventory-entry.test.ts +106 -106
  120. package/src/services/inventory-entry.ts +7 -7
  121. package/src/services/my-cart.test.ts +56 -56
  122. package/src/services/my-cart.ts +20 -20
  123. package/src/services/my-customer.test.ts +155 -104
  124. package/src/services/my-customer.ts +61 -75
  125. package/src/services/my-order.ts +16 -16
  126. package/src/services/my-payment.test.ts +40 -40
  127. package/src/services/my-payment.ts +7 -7
  128. package/src/services/my-shopping-list.ts +7 -7
  129. package/src/services/order.test.ts +243 -243
  130. package/src/services/order.ts +23 -18
  131. package/src/services/payment.test.ts +40 -40
  132. package/src/services/payment.ts +7 -7
  133. package/src/services/product-discount.ts +7 -7
  134. package/src/services/product-projection.test.ts +190 -190
  135. package/src/services/product-projection.ts +34 -32
  136. package/src/services/product-selection.test.ts +19 -19
  137. package/src/services/product-selection.ts +7 -7
  138. package/src/services/product-type.test.ts +38 -38
  139. package/src/services/product-type.ts +7 -7
  140. package/src/services/product.test.ts +658 -656
  141. package/src/services/product.ts +7 -7
  142. package/src/services/project.test.ts +24 -24
  143. package/src/services/project.ts +17 -17
  144. package/src/services/reviews.ts +7 -7
  145. package/src/services/shipping-method.test.ts +78 -78
  146. package/src/services/shipping-method.ts +16 -16
  147. package/src/services/shopping-list.test.ts +170 -170
  148. package/src/services/shopping-list.ts +7 -7
  149. package/src/services/standalone-price.test.ts +112 -112
  150. package/src/services/standalone-price.ts +7 -7
  151. package/src/services/state.test.ts +30 -30
  152. package/src/services/state.ts +7 -7
  153. package/src/services/store.test.ts +40 -40
  154. package/src/services/store.ts +7 -7
  155. package/src/services/subscription.ts +7 -7
  156. package/src/services/tax-category.test.ts +43 -43
  157. package/src/services/tax-category.ts +7 -7
  158. package/src/services/type.ts +7 -7
  159. package/src/services/zone.ts +7 -7
  160. package/src/shippingCalculator.test.ts +43 -43
  161. package/src/shippingCalculator.ts +23 -23
  162. package/src/storage/abstract.ts +36 -34
  163. package/src/storage/in-memory.ts +237 -233
  164. package/src/storage/index.ts +2 -2
  165. package/src/types.ts +91 -91
  166. package/src/repositories/cart-discount.ts +0 -219
  167. package/src/repositories/cart.ts +0 -659
  168. package/src/repositories/category.ts +0 -256
  169. package/src/repositories/customer.ts +0 -228
  170. package/src/repositories/discount-code.ts +0 -181
  171. package/src/repositories/inventory-entry.ts +0 -109
  172. package/src/repositories/order.ts +0 -514
  173. package/src/repositories/payment.ts +0 -342
  174. package/src/repositories/product.ts +0 -1106
  175. package/src/repositories/shipping-method.ts +0 -312
  176. package/src/repositories/shopping-list.ts +0 -392
  177. package/src/repositories/tax-category.ts +0 -111
  178. package/src/repositories/type.ts +0 -172
@@ -1,4 +1,9 @@
1
1
  import {
2
+ BusinessUnitChangeAssociateModeAction,
3
+ BusinessUnitChangeStatusAction,
4
+ BusinessUnitUpdateAction,
5
+ CompanyDraft,
6
+ DivisionDraft,
2
7
  type Associate,
3
8
  type BusinessUnit,
4
9
  type BusinessUnitAddAddressAction,
@@ -13,35 +18,28 @@ import {
13
18
  type BusinessUnitSetStoreModeAction,
14
19
  type Company,
15
20
  type Division,
16
- BusinessUnitChangeStatusAction,
17
- CompanyDraft,
18
- DivisionDraft,
19
- } from '@commercetools/platform-sdk'
21
+ } from "@commercetools/platform-sdk";
22
+ import { getBaseResourceProperties } from "../helpers";
23
+ import { AbstractStorage } from "../storage/abstract";
24
+ import { Writable } from "../types";
20
25
  import {
21
26
  AbstractResourceRepository,
27
+ AbstractUpdateHandler,
28
+ UpdateHandlerInterface,
22
29
  type RepositoryContext,
23
- } from './abstract.js'
24
- import { getBaseResourceProperties } from '../helpers.js'
30
+ } from "./abstract";
25
31
  import {
26
32
  createAddress,
27
33
  createAssociate,
28
34
  createCustomFields,
29
35
  getBusinessUnitKeyReference,
30
36
  getStoreKeyReference,
31
- } from './helpers.js'
32
- import { Writable } from '../types.js'
33
-
34
- export class BusinessUnitRepository extends AbstractResourceRepository<'business-unit'> {
35
- getTypeId() {
36
- return 'business-unit' as const
37
- }
37
+ } from "./helpers";
38
38
 
39
- private _isCompanyDraft(draft: BusinessUnitDraft): draft is CompanyDraft {
40
- return draft.unitType === 'Company'
41
- }
42
-
43
- private _isDivisionDraft(draft: BusinessUnitDraft): draft is DivisionDraft {
44
- return draft.unitType === 'Division'
39
+ export class BusinessUnitRepository extends AbstractResourceRepository<"business-unit"> {
40
+ constructor(storage: AbstractStorage) {
41
+ super("business-unit", storage);
42
+ this.actions = new BusinessUnitUpdateHandler(this._storage);
45
43
  }
46
44
 
47
45
  create(context: RepositoryContext, draft: BusinessUnitDraft): BusinessUnit {
@@ -50,27 +48,27 @@ export class BusinessUnitRepository extends AbstractResourceRepository<'business
50
48
  key: draft.key,
51
49
  status: draft.status,
52
50
  stores: draft.stores?.map((s) =>
53
- getStoreKeyReference(s, context.projectKey, this._storage)
51
+ getStoreKeyReference(s, context.projectKey, this._storage),
54
52
  ),
55
53
  storeMode: draft.storeMode,
56
54
  name: draft.name,
57
55
  contactEmail: draft.contactEmail,
58
56
  addresses: draft.addresses?.map((a) =>
59
- createAddress(a, context.projectKey, this._storage)
57
+ createAddress(a, context.projectKey, this._storage),
60
58
  ),
61
59
  custom: createCustomFields(
62
60
  draft.custom,
63
61
  context.projectKey,
64
- this._storage
62
+ this._storage,
65
63
  ),
66
64
  shippingAddressIds: draft.shippingAddresses,
67
65
  defaultShippingAddressId: draft.defaultShippingAddress,
68
66
  billingAddressIds: draft.billingAddresses,
69
67
  associateMode: draft.associateMode,
70
68
  associates: draft.associates?.map((a) =>
71
- createAssociate(a, context.projectKey, this._storage)
69
+ createAssociate(a, context.projectKey, this._storage),
72
70
  ),
73
- }
71
+ };
74
72
 
75
73
  if (this._isDivisionDraft(draft)) {
76
74
  const division = {
@@ -78,138 +76,160 @@ export class BusinessUnitRepository extends AbstractResourceRepository<'business
78
76
  parentUnit: getBusinessUnitKeyReference(
79
77
  draft.parentUnit,
80
78
  context.projectKey,
81
- this._storage
79
+ this._storage,
82
80
  ),
83
- } as Division
81
+ } as Division;
84
82
 
85
- this.saveNew(context, division)
86
- return division
83
+ this.saveNew(context, division);
84
+ return division;
87
85
  } else if (this._isCompanyDraft(draft)) {
88
- const company = resource as Company
86
+ const company = resource as Company;
89
87
 
90
- this.saveNew(context, company)
91
- return company
88
+ this.saveNew(context, company);
89
+ return company;
92
90
  }
93
91
 
94
- throw new Error('Invalid business unit type')
92
+ throw new Error("Invalid business unit type");
95
93
  }
96
94
 
97
- actions = {
98
- addAddress: (
99
- context: RepositoryContext,
100
- resource: Writable<BusinessUnit>,
101
- { address }: BusinessUnitAddAddressAction
102
- ) => {
103
- const newAddress = createAddress(
104
- address,
105
- context.projectKey,
106
- this._storage
107
- )
108
- if (newAddress) {
109
- resource.addresses.push(newAddress)
110
- }
111
- },
112
- addAssociate: (
113
- context: RepositoryContext,
114
- resource: Writable<BusinessUnit>,
115
- { associate }: BusinessUnitAddAssociateAction
116
- ) => {
117
- const newAssociate = createAssociate(
118
- associate,
119
- context.projectKey,
120
- this._storage
121
- )
122
- if (newAssociate) {
123
- resource.associates.push(newAssociate)
124
- }
125
- },
126
- setAssociates: (
127
- context: RepositoryContext,
128
- resource: Writable<BusinessUnit>,
129
- { associates }: BusinessUnitSetAssociatesAction
130
- ) => {
131
- const newAssociates = associates
132
- .map((a) => createAssociate(a, context.projectKey, this._storage))
133
- .filter((a): a is Writable<Associate> => a !== undefined)
134
- resource.associates = newAssociates || undefined
135
- },
136
- setContactEmail: (
137
- context: RepositoryContext,
138
- resource: Writable<BusinessUnit>,
139
- { contactEmail }: BusinessUnitSetContactEmailAction
140
- ) => {
141
- resource.contactEmail = contactEmail
142
- },
143
- setStoreMode: (
144
- context: RepositoryContext,
145
- resource: Writable<BusinessUnit>,
146
- { storeMode }: BusinessUnitSetStoreModeAction
147
- ) => {
148
- resource.storeMode = storeMode
149
- },
150
- changeAssociateMode: (
151
- context: RepositoryContext,
152
- resource: Writable<BusinessUnit>,
153
- { storeMode }: BusinessUnitSetStoreModeAction
154
- ) => {
155
- resource.associateMode = storeMode
156
- },
157
- changeName: (
158
- context: RepositoryContext,
159
- resource: Writable<BusinessUnit>,
160
- { name }: BusinessUnitChangeNameAction
161
- ) => {
162
- resource.name = name
163
- },
164
- changeAddress: (
165
- context: RepositoryContext,
166
- resource: Writable<BusinessUnit>,
167
- { address }: BusinessUnitChangeAddressAction
168
- ) => {
169
- const newAddress = createAddress(
170
- address,
171
- context.projectKey,
172
- this._storage
173
- )
174
- if (newAddress) {
175
- resource.addresses.push(newAddress)
176
- }
177
- },
178
- addStore: (
179
- context: RepositoryContext,
180
- resource: Writable<BusinessUnit>,
181
- { store }: BusinessUnitAddStoreAction
182
- ) => {
183
- const newStore = getStoreKeyReference(
184
- store,
185
- context.projectKey,
186
- this._storage
187
- )
188
- if (newStore) {
189
- if (!resource.stores) {
190
- resource.stores = []
191
- }
192
-
193
- resource.stores.push(newStore)
95
+ private _isCompanyDraft(draft: BusinessUnitDraft): draft is CompanyDraft {
96
+ return draft.unitType === "Company";
97
+ }
98
+
99
+ private _isDivisionDraft(draft: BusinessUnitDraft): draft is DivisionDraft {
100
+ return draft.unitType === "Division";
101
+ }
102
+ }
103
+
104
+ class BusinessUnitUpdateHandler
105
+ extends AbstractUpdateHandler
106
+ implements
107
+ Partial<UpdateHandlerInterface<BusinessUnit, BusinessUnitUpdateAction>>
108
+ {
109
+ addAddress(
110
+ context: RepositoryContext,
111
+ resource: Writable<BusinessUnit>,
112
+ { address }: BusinessUnitAddAddressAction,
113
+ ) {
114
+ const newAddress = createAddress(
115
+ address,
116
+ context.projectKey,
117
+ this._storage,
118
+ );
119
+ if (newAddress) {
120
+ resource.addresses.push(newAddress);
121
+ }
122
+ }
123
+
124
+ addAssociate(
125
+ context: RepositoryContext,
126
+ resource: Writable<BusinessUnit>,
127
+ { associate }: BusinessUnitAddAssociateAction,
128
+ ) {
129
+ const newAssociate = createAssociate(
130
+ associate,
131
+ context.projectKey,
132
+ this._storage,
133
+ );
134
+ if (newAssociate) {
135
+ resource.associates.push(newAssociate);
136
+ }
137
+ }
138
+
139
+ addStore(
140
+ context: RepositoryContext,
141
+ resource: Writable<BusinessUnit>,
142
+ { store }: BusinessUnitAddStoreAction,
143
+ ) {
144
+ const newStore = getStoreKeyReference(
145
+ store,
146
+ context.projectKey,
147
+ this._storage,
148
+ );
149
+ if (newStore) {
150
+ if (!resource.stores) {
151
+ resource.stores = [];
194
152
  }
195
- },
196
- changeParentUnit: (
197
- context: RepositoryContext,
198
- resource: Writable<BusinessUnit>,
199
- { parentUnit }: BusinessUnitChangeParentUnitAction
200
- ) => {
201
- resource.parentUnit = getBusinessUnitKeyReference(
202
- parentUnit,
203
- context.projectKey,
204
- this._storage
205
- )
206
- },
207
- changeStatus: (
208
- context: RepositoryContext,
209
- resource: Writable<BusinessUnit>,
210
- { status }: BusinessUnitChangeStatusAction
211
- ) => {
212
- resource.status = status
213
- },
153
+
154
+ resource.stores.push(newStore);
155
+ }
156
+ }
157
+
158
+ changeAddress(
159
+ context: RepositoryContext,
160
+ resource: Writable<BusinessUnit>,
161
+ { address }: BusinessUnitChangeAddressAction,
162
+ ) {
163
+ const newAddress = createAddress(
164
+ address,
165
+ context.projectKey,
166
+ this._storage,
167
+ );
168
+ if (newAddress) {
169
+ resource.addresses.push(newAddress);
170
+ }
171
+ }
172
+
173
+ changeAssociateMode(
174
+ context: RepositoryContext,
175
+ resource: Writable<BusinessUnit>,
176
+ { associateMode }: BusinessUnitChangeAssociateModeAction,
177
+ ) {
178
+ resource.associateMode = associateMode;
179
+ }
180
+
181
+ changeName(
182
+ context: RepositoryContext,
183
+ resource: Writable<BusinessUnit>,
184
+ { name }: BusinessUnitChangeNameAction,
185
+ ) {
186
+ resource.name = name;
187
+ }
188
+
189
+ changeParentUnit(
190
+ context: RepositoryContext,
191
+ resource: Writable<BusinessUnit>,
192
+ { parentUnit }: BusinessUnitChangeParentUnitAction,
193
+ ) {
194
+ resource.parentUnit = getBusinessUnitKeyReference(
195
+ parentUnit,
196
+ context.projectKey,
197
+ this._storage,
198
+ );
199
+ }
200
+
201
+ changeStatus(
202
+ context: RepositoryContext,
203
+ resource: Writable<BusinessUnit>,
204
+ { status }: BusinessUnitChangeStatusAction,
205
+ ) {
206
+ resource.status = status;
207
+ }
208
+
209
+ setAssociates(
210
+ context: RepositoryContext,
211
+ resource: Writable<BusinessUnit>,
212
+ { associates }: BusinessUnitSetAssociatesAction,
213
+ ) {
214
+ const newAssociates = associates
215
+ .map((a) => createAssociate(a, context.projectKey, this._storage))
216
+ .filter((a): a is Writable<Associate> => a !== undefined);
217
+ resource.associates = newAssociates || undefined;
218
+ }
219
+
220
+ setContactEmail(
221
+ context: RepositoryContext,
222
+ resource: Writable<BusinessUnit>,
223
+ { contactEmail }: BusinessUnitSetContactEmailAction,
224
+ ) {
225
+ resource.contactEmail = contactEmail;
226
+ }
227
+
228
+ setStoreMode(
229
+ context: RepositoryContext,
230
+ resource: Writable<BusinessUnit>,
231
+ { storeMode }: BusinessUnitSetStoreModeAction,
232
+ ) {
233
+ resource.storeMode = storeMode;
214
234
  }
215
235
  }