@reactionary/source 0.3.18 → 0.6.2

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 (191) hide show
  1. package/README.md +28 -14
  2. package/core/src/client/client-builder.ts +54 -6
  3. package/core/src/factories/cart.factory.ts +40 -0
  4. package/core/src/factories/category.factory.ts +40 -0
  5. package/core/src/factories/checkout.factory.ts +59 -0
  6. package/core/src/factories/identity.factory.ts +26 -0
  7. package/core/src/factories/index.ts +15 -0
  8. package/core/src/factories/inventory.factory.ts +26 -0
  9. package/core/src/factories/order-search.factory.ts +33 -0
  10. package/core/src/factories/order.factory.ts +21 -0
  11. package/core/src/factories/price.factory.ts +29 -0
  12. package/core/src/factories/product-associations.factory.ts +30 -0
  13. package/core/src/factories/product-list.factory.ts +82 -0
  14. package/core/src/factories/product-reviews.factory.ts +58 -0
  15. package/core/src/factories/product-search.factory.ts +31 -0
  16. package/core/src/factories/product.factory.ts +21 -0
  17. package/core/src/factories/profile.factory.ts +23 -0
  18. package/core/src/factories/store.factory.ts +21 -0
  19. package/core/src/index.ts +3 -1
  20. package/core/src/providers/cart.provider.ts +12 -10
  21. package/core/src/providers/category.provider.ts +9 -7
  22. package/core/src/providers/checkout.provider.ts +14 -10
  23. package/core/src/providers/identity.provider.ts +7 -7
  24. package/core/src/providers/inventory.provider.ts +4 -4
  25. package/core/src/providers/order-search.provider.ts +4 -2
  26. package/core/src/providers/order.provider.ts +4 -4
  27. package/core/src/providers/price.provider.ts +5 -5
  28. package/core/src/providers/product-associations.provider.ts +6 -4
  29. package/core/src/providers/product-list.provider.ts +13 -8
  30. package/core/src/providers/product-reviews.provider.ts +8 -4
  31. package/core/src/providers/product-search.provider.ts +15 -28
  32. package/core/src/providers/product.provider.ts +6 -6
  33. package/core/src/providers/profile.provider.ts +8 -8
  34. package/core/src/providers/store.provider.ts +2 -2
  35. package/core/src/test/client-builder.spec.ts +81 -0
  36. package/examples/node/package.json +7 -7
  37. package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +10 -4
  38. package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +8 -2
  39. package/examples/node/src/basic/basic-node-setup.spec.ts +5 -1
  40. package/examples/node/src/basic/client-creation.spec.ts +3 -3
  41. package/examples/node/src/utils.ts +41 -41
  42. package/examples/node/tsconfig.lib.json +2 -1
  43. package/package.json +1 -1
  44. package/providers/algolia/src/core/initialize.ts +76 -21
  45. package/providers/algolia/src/core/initialize.types.ts +107 -0
  46. package/providers/algolia/src/factories/index.ts +1 -0
  47. package/providers/algolia/src/factories/product-search/product-search.factory.ts +182 -0
  48. package/providers/algolia/src/index.ts +2 -2
  49. package/providers/algolia/src/providers/analytics.provider.ts +4 -4
  50. package/providers/algolia/src/providers/product-search.provider.ts +67 -184
  51. package/providers/algolia/src/schema/capabilities.schema.ts +81 -7
  52. package/providers/algolia/src/test/analytics.spec.ts +9 -1
  53. package/providers/algolia/src/test/client-builder-product-search-extension.example.ts +85 -0
  54. package/providers/commercetools/src/core/capability-descriptors.ts +324 -0
  55. package/providers/commercetools/src/core/initialize.ts +35 -151
  56. package/providers/commercetools/src/core/initialize.types.ts +174 -0
  57. package/providers/commercetools/src/factories/cart/cart.factory.ts +142 -0
  58. package/providers/commercetools/src/factories/category/category.factory.ts +77 -0
  59. package/providers/commercetools/src/factories/checkout/checkout-initializer-overrides.example.ts +94 -0
  60. package/providers/commercetools/src/factories/checkout/checkout.factory.ts +338 -0
  61. package/providers/commercetools/src/factories/identity/identity.factory.ts +26 -0
  62. package/providers/commercetools/src/factories/inventory/inventory.factory.ts +49 -0
  63. package/providers/commercetools/src/factories/order/order.factory.ts +149 -0
  64. package/providers/commercetools/src/factories/order-search/order-search.factory.ts +108 -0
  65. package/providers/commercetools/src/factories/price/price.factory.ts +76 -0
  66. package/providers/commercetools/src/factories/product/product-factory-baseline.example.ts +14 -0
  67. package/providers/commercetools/src/factories/product/product-factory-schema-and-parse-extension.example.ts +35 -0
  68. package/providers/commercetools/src/factories/product/product-factory-schema-extension.example.ts +23 -0
  69. package/providers/commercetools/src/factories/product/product-initializer-factory-extension.example.ts +41 -0
  70. package/providers/commercetools/src/factories/product/product-provider-custom-method-only.example.ts +47 -0
  71. package/providers/commercetools/src/factories/product/product-provider-schema-signature-extension.example.ts +61 -0
  72. package/providers/commercetools/src/factories/product/product.factory.ts +220 -0
  73. package/providers/commercetools/src/factories/product/utils.example.ts +9 -0
  74. package/providers/commercetools/src/factories/product-associations/product-associations.factory.ts +103 -0
  75. package/providers/commercetools/src/factories/product-list/product-list.factory.ts +122 -0
  76. package/providers/commercetools/src/factories/product-reviews/product-reviews.factory.ts +81 -0
  77. package/providers/commercetools/src/factories/product-search/product-search.factory.ts +182 -0
  78. package/providers/commercetools/src/factories/profile/profile.factory.ts +94 -0
  79. package/providers/commercetools/src/factories/store/store.factory.ts +49 -0
  80. package/providers/commercetools/src/index.ts +15 -0
  81. package/providers/commercetools/src/providers/cart.provider.ts +67 -193
  82. package/providers/commercetools/src/providers/category.provider.ts +24 -64
  83. package/providers/commercetools/src/providers/checkout.provider.ts +50 -322
  84. package/providers/commercetools/src/providers/identity.provider.ts +35 -15
  85. package/providers/commercetools/src/providers/inventory.provider.ts +13 -31
  86. package/providers/commercetools/src/providers/order-search.provider.ts +16 -110
  87. package/providers/commercetools/src/providers/order.provider.ts +13 -144
  88. package/providers/commercetools/src/providers/price.provider.ts +37 -51
  89. package/providers/commercetools/src/providers/product-associations.provider.ts +39 -104
  90. package/providers/commercetools/src/providers/product-list.provider.ts +38 -23
  91. package/providers/commercetools/src/providers/product-reviews.provider.ts +34 -14
  92. package/providers/commercetools/src/providers/product-search.provider.ts +17 -170
  93. package/providers/commercetools/src/providers/product.provider.ts +20 -199
  94. package/providers/commercetools/src/providers/profile.provider.ts +27 -73
  95. package/providers/commercetools/src/providers/store.provider.ts +13 -31
  96. package/providers/commercetools/src/schema/capabilities.schema.ts +258 -20
  97. package/providers/commercetools/src/test/caching.spec.ts +18 -2
  98. package/providers/commercetools/src/test/client-builder-merge-extensions.example.ts +125 -0
  99. package/providers/fake/src/core/initialize.ts +213 -44
  100. package/providers/fake/src/core/initialize.types.ts +164 -0
  101. package/providers/fake/src/factories/cart/cart.factory.ts +34 -0
  102. package/providers/fake/src/factories/category/category.factory.ts +40 -0
  103. package/providers/fake/src/factories/checkout/checkout.factory.ts +53 -0
  104. package/providers/fake/src/factories/identity/identity.factory.ts +25 -0
  105. package/providers/fake/src/factories/index.ts +14 -0
  106. package/providers/fake/src/factories/inventory/inventory.factory.ts +25 -0
  107. package/providers/fake/src/factories/order/order.factory.ts +22 -0
  108. package/providers/fake/src/factories/order-search/order-search.factory.ts +27 -0
  109. package/providers/fake/src/factories/price/price.factory.ts +26 -0
  110. package/providers/fake/src/factories/product/product.factory.ts +22 -0
  111. package/providers/fake/src/factories/product-associations/product-associations.factory.ts +25 -0
  112. package/providers/fake/src/factories/product-reviews/product-reviews.factory.ts +53 -0
  113. package/providers/fake/src/factories/product-search/product-search.factory.ts +27 -0
  114. package/providers/fake/src/factories/profile/profile.factory.ts +22 -0
  115. package/providers/fake/src/factories/store/store.factory.ts +22 -0
  116. package/providers/fake/src/index.ts +2 -0
  117. package/providers/fake/src/providers/cart.provider.ts +23 -14
  118. package/providers/fake/src/providers/category.provider.ts +120 -105
  119. package/providers/fake/src/providers/checkout.provider.ts +39 -20
  120. package/providers/fake/src/providers/identity.provider.ts +40 -34
  121. package/providers/fake/src/providers/inventory.provider.ts +26 -24
  122. package/providers/fake/src/providers/order-search.provider.ts +38 -30
  123. package/providers/fake/src/providers/order.provider.ts +21 -37
  124. package/providers/fake/src/providers/price.provider.ts +42 -34
  125. package/providers/fake/src/providers/product-associations.provider.ts +23 -10
  126. package/providers/fake/src/providers/product-reviews.provider.ts +71 -69
  127. package/providers/fake/src/providers/product-search.provider.ts +43 -70
  128. package/providers/fake/src/providers/product.provider.ts +34 -32
  129. package/providers/fake/src/providers/profile.provider.ts +62 -55
  130. package/providers/fake/src/providers/store.provider.ts +38 -22
  131. package/providers/fake/src/schema/capabilities.schema.ts +175 -18
  132. package/providers/fake/src/test/cart.provider.spec.ts +20 -3
  133. package/providers/fake/src/test/category.provider.spec.ts +4 -1
  134. package/providers/fake/src/test/checkout.provider.spec.ts +12 -2
  135. package/providers/fake/src/test/client-builder-product-extension.example.ts +75 -0
  136. package/providers/fake/src/test/order-search.provider.spec.ts +4 -7
  137. package/providers/fake/src/test/order.provider.spec.ts +4 -6
  138. package/providers/fake/src/test/price.provider.spec.ts +3 -1
  139. package/providers/fake/src/test/product.provider.spec.ts +8 -2
  140. package/providers/fake/src/test/profile.provider.spec.ts +4 -2
  141. package/providers/google-analytics/src/core/initialize.ts +37 -12
  142. package/providers/google-analytics/src/core/initialize.types.ts +47 -0
  143. package/providers/google-analytics/src/index.ts +1 -0
  144. package/providers/google-analytics/src/schema/capabilities.schema.ts +31 -5
  145. package/providers/medusa/src/core/initialize.ts +324 -81
  146. package/providers/medusa/src/core/initialize.types.ts +184 -0
  147. package/providers/medusa/src/factories/cart/cart.factory.ts +34 -0
  148. package/providers/medusa/src/factories/category/category.factory.ts +37 -0
  149. package/providers/medusa/src/factories/checkout/checkout.factory.ts +50 -0
  150. package/providers/medusa/src/factories/identity/identity.factory.ts +22 -0
  151. package/providers/medusa/src/factories/index.ts +12 -0
  152. package/providers/medusa/src/factories/inventory/inventory.factory.ts +25 -0
  153. package/providers/medusa/src/factories/order/order.factory.ts +22 -0
  154. package/providers/medusa/src/factories/order-search/order-search.factory.ts +27 -0
  155. package/providers/medusa/src/factories/price/price.factory.ts +26 -0
  156. package/providers/medusa/src/factories/product/product.factory.ts +22 -0
  157. package/providers/medusa/src/factories/product-associations/product-associations.factory.ts +25 -0
  158. package/providers/medusa/src/factories/product-search/product-search.factory.ts +27 -0
  159. package/providers/medusa/src/factories/profile/profile.factory.ts +22 -0
  160. package/providers/medusa/src/index.ts +2 -0
  161. package/providers/medusa/src/providers/cart.provider.ts +33 -20
  162. package/providers/medusa/src/providers/category.provider.ts +30 -12
  163. package/providers/medusa/src/providers/checkout.provider.ts +42 -17
  164. package/providers/medusa/src/providers/identity.provider.ts +1 -1
  165. package/providers/medusa/src/providers/inventory.provider.ts +21 -7
  166. package/providers/medusa/src/providers/order-search.provider.ts +16 -5
  167. package/providers/medusa/src/providers/order.provider.ts +17 -5
  168. package/providers/medusa/src/providers/price.provider.ts +26 -7
  169. package/providers/medusa/src/providers/product-associations.provider.ts +19 -8
  170. package/providers/medusa/src/providers/product-search.provider.ts +19 -31
  171. package/providers/medusa/src/providers/product.provider.ts +47 -11
  172. package/providers/medusa/src/providers/profile.provider.ts +35 -11
  173. package/providers/medusa/src/schema/capabilities.schema.ts +229 -18
  174. package/providers/medusa/src/test/cart.provider.spec.ts +18 -2
  175. package/providers/medusa/src/test/category.provider.spec.ts +4 -1
  176. package/providers/medusa/src/test/checkout.spec.ts +9 -9
  177. package/providers/medusa/src/test/inventory.provider.spec.ts +3 -1
  178. package/providers/medusa/src/test/large-cart.provider.spec.ts +8 -2
  179. package/providers/medusa/src/test/price.provider.spec.ts +8 -1
  180. package/providers/medusa/src/test/product.provider.spec.ts +3 -1
  181. package/providers/medusa/src/test/search.provider.spec.ts +16 -3
  182. package/providers/meilisearch/src/core/initialize.ts +88 -21
  183. package/providers/meilisearch/src/core/initialize.types.ts +119 -0
  184. package/providers/meilisearch/src/factories/index.ts +2 -0
  185. package/providers/meilisearch/src/factories/order-search/order-search.factory.ts +27 -0
  186. package/providers/meilisearch/src/factories/product-search/product-search.factory.ts +27 -0
  187. package/providers/meilisearch/src/index.ts +2 -0
  188. package/providers/meilisearch/src/providers/index.ts +1 -0
  189. package/providers/meilisearch/src/providers/order-search.provider.ts +21 -6
  190. package/providers/meilisearch/src/providers/product-search.provider.ts +24 -8
  191. package/providers/meilisearch/src/schema/capabilities.schema.ts +95 -8
@@ -1,5 +1,7 @@
1
1
  import type {
2
- Profile,
2
+ ProfileFactory,
3
+ ProfileFactoryOutput,
4
+ ProfileFactoryWithOutput,
3
5
  ProfileMutationAddShippingAddress,
4
6
  ProfileMutationMakeShippingAddressDefault,
5
7
  ProfileMutationRemoveShippingAddress,
@@ -10,8 +12,8 @@ import type {
10
12
  Result,
11
13
  NotFoundError,
12
14
  InvalidInputError,
15
+ ProfileMutationUpdateShippingAddress,
13
16
  Address,
14
- ProfileMutationUpdateShippingAddress
15
17
  } from '@reactionary/core';
16
18
  import {
17
19
  ProfileMutationUpdateSchema,
@@ -27,23 +29,29 @@ import {
27
29
  import type * as z from 'zod';
28
30
  import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
29
31
  import type { Cache } from '@reactionary/core';
30
- import type { Customer, MyCustomerUpdateAction, Address as CTAddress } from '@commercetools/platform-sdk';
32
+ import type { MyCustomerUpdateAction, Address as CTAddress } from '@commercetools/platform-sdk';
31
33
  import type { CommercetoolsAPI } from '../core/client.js';
34
+ import type { CommercetoolsProfileFactory } from '../factories/profile/profile.factory.js';
32
35
 
33
- export class CommercetoolsProfileProvider extends ProfileProvider {
36
+ export class CommercetoolsProfileProvider<
37
+ TFactory extends ProfileFactory = CommercetoolsProfileFactory,
38
+ > extends ProfileProvider<ProfileFactoryOutput<TFactory>> {
34
39
  protected config: CommercetoolsConfiguration;
35
40
  protected commercetools: CommercetoolsAPI;
41
+ protected factory: ProfileFactoryWithOutput<TFactory>;
36
42
 
37
43
  constructor(
38
44
  config: CommercetoolsConfiguration,
39
45
  cache: Cache,
40
46
  context: RequestContext,
41
- commercetools: CommercetoolsAPI
47
+ commercetools: CommercetoolsAPI,
48
+ factory: ProfileFactoryWithOutput<TFactory>,
42
49
  ) {
43
50
  super(cache, context);
44
51
 
45
52
  this.config = config;
46
53
  this.commercetools = commercetools;
54
+ this.factory = factory;
47
55
  }
48
56
 
49
57
  protected async getClient() {
@@ -51,7 +59,7 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
51
59
  return client.withProjectKey({ projectKey: this.config.projectKey });
52
60
  }
53
61
 
54
- public override async getById(payload: ProfileQuerySelf): Promise<Result<Profile, NotFoundError>> {
62
+ public override async getById(payload: ProfileQuerySelf): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
55
63
  const client = await this.getClient();
56
64
 
57
65
  const remote = await client.me().get().execute();
@@ -63,7 +71,7 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
63
71
  });
64
72
  }
65
73
 
66
- const model = this.parseSingle(remote.body);
74
+ const model = this.factory.parseProfile(this.context, remote.body);
67
75
  return success(model);
68
76
  }
69
77
 
@@ -73,7 +81,7 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
73
81
  inputSchema: ProfileMutationAddShippingAddressSchema,
74
82
  outputSchema: ProfileSchema,
75
83
  })
76
- public override async addShippingAddress(payload: ProfileMutationAddShippingAddress): Promise<Result<Profile, NotFoundError>> {
84
+ public override async addShippingAddress(payload: ProfileMutationAddShippingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
77
85
  const client = await this.getClient();
78
86
 
79
87
  const remote = await client.me().get().execute();
@@ -101,11 +109,11 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
101
109
  })
102
110
  .execute();
103
111
  customer = updateResponse.body;
104
- const model = this.parseSingle(customer);
112
+ const model = this.factory.parseProfile(this.context, customer);
105
113
  return success(model);
106
114
  }
107
115
 
108
- public override async updateShippingAddress(payload: ProfileMutationUpdateShippingAddress): Promise<Result<Profile, NotFoundError>> {
116
+ public override async updateShippingAddress(payload: ProfileMutationUpdateShippingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
109
117
  const client = await this.getClient();
110
118
 
111
119
  const remote = await client.me().get().execute();
@@ -144,7 +152,7 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
144
152
  })
145
153
  .execute();
146
154
  customer = updateResponse.body;
147
- const model = this.parseSingle(customer);
155
+ const model = this.factory.parseProfile(this.context, customer);
148
156
  return success(model);
149
157
  }
150
158
 
@@ -152,7 +160,7 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
152
160
  inputSchema: ProfileMutationRemoveShippingAddressSchema,
153
161
  outputSchema: ProfileSchema,
154
162
  })
155
- public override async removeShippingAddress(payload: ProfileMutationRemoveShippingAddress): Promise<Result<Profile, NotFoundError>> {
163
+ public override async removeShippingAddress(payload: ProfileMutationRemoveShippingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
156
164
  const client = await this.getClient();
157
165
 
158
166
  const remote = await client.me().get().execute();
@@ -207,13 +215,13 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
207
215
  .execute();
208
216
  customer = updateResponse.body;
209
217
 
210
- const model = this.parseSingle(customer);
218
+ const model = this.factory.parseProfile(this.context, customer);
211
219
  return success(model);
212
220
  }
213
221
 
214
222
 
215
223
 
216
- public override async makeShippingAddressDefault(payload: ProfileMutationMakeShippingAddressDefault): Promise<Result<Profile, NotFoundError>> {
224
+ public override async makeShippingAddressDefault(payload: ProfileMutationMakeShippingAddressDefault): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
217
225
  const client = await this.getClient();
218
226
 
219
227
  const remote = await client.me().get().execute();
@@ -257,7 +265,7 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
257
265
  })
258
266
  .execute();
259
267
  customer = updateResponse.body;
260
- const model = this.parseSingle(customer);
268
+ const model = this.factory.parseProfile(this.context, customer);
261
269
  return success(model);
262
270
  }
263
271
 
@@ -266,7 +274,7 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
266
274
  inputSchema: ProfileMutationSetBillingAddressSchema,
267
275
  outputSchema: ProfileSchema,
268
276
  })
269
- public override async setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<Profile, NotFoundError>> {
277
+ public override async setBillingAddress(payload: ProfileMutationSetBillingAddress): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
270
278
  const client = await this.getClient();
271
279
 
272
280
  const remote = await client.me().get().execute();
@@ -311,7 +319,7 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
311
319
  .execute();
312
320
  customer = updateResponse.body;
313
321
  }
314
- const model = this.parseSingle(customer);
322
+ const model = this.factory.parseProfile(this.context, customer);
315
323
  return success(model);
316
324
  }
317
325
 
@@ -319,7 +327,7 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
319
327
  inputSchema: ProfileMutationUpdateSchema,
320
328
  outputSchema: ProfileSchema,
321
329
  })
322
- public override async update(payload: ProfileMutationUpdate): Promise<Result<Profile, NotFoundError>> {
330
+ public override async update(payload: ProfileMutationUpdate): Promise<Result<ProfileFactoryOutput<TFactory>, NotFoundError>> {
323
331
  const client = await this.getClient();
324
332
 
325
333
  const remote = await client.me().get().execute();
@@ -381,65 +389,11 @@ export class CommercetoolsProfileProvider extends ProfileProvider {
381
389
  .execute();
382
390
  customer = updateResponse.body;
383
391
  }
384
- const model = this.parseSingle(customer);
392
+ const model = this.factory.parseProfile(this.context, customer);
385
393
  return success(model);
386
394
 
387
395
  }
388
396
 
389
- protected parseAddress(address: CTAddress): Address {
390
- const result = {
391
- identifier: {
392
- nickName: address.key || '',
393
- },
394
- firstName: address.firstName || '',
395
- lastName: address.lastName || '',
396
- streetAddress: address.streetName || '',
397
- streetNumber: address.streetNumber || '',
398
- city: address.city || '',
399
- region: address.region || '',
400
- postalCode: address.postalCode || '',
401
- countryCode: address.country,
402
- } satisfies Address;
403
-
404
- return result;
405
- }
406
-
407
- protected parseSingle(body: Customer): Profile {
408
- const email = body.email;
409
- const emailVerified = body.isEmailVerified;
410
- let defaultCTBillingAddress = body.addresses.find(addr => addr.id === body.defaultBillingAddressId);
411
- const phone = defaultCTBillingAddress?.phone ?? '';
412
-
413
-
414
- // if we only have the phone number on the billing address, we dont really have a billing address, so we ignore it
415
- if (this.isIncompleteAddress(defaultCTBillingAddress)) {
416
- defaultCTBillingAddress = undefined;
417
- }
418
-
419
- const defaultCTShippingAddress = body.addresses.find(addr => addr.id === body.defaultShippingAddressId);
420
-
421
- const alternateShippingAddresses = body.addresses.filter(x => x.id !== body.defaultBillingAddressId && x.id !== body.defaultShippingAddressId).map(addr => this.parseAddress(addr));
422
- const billingAddress = defaultCTBillingAddress ? this.parseAddress(defaultCTBillingAddress) : undefined;
423
- const shippingAddress = defaultCTShippingAddress ? this.parseAddress(defaultCTShippingAddress) : undefined;
424
-
425
- const result = {
426
- identifier: {
427
- userId: body.id
428
- },
429
- email,
430
- emailVerified,
431
- alternateShippingAddresses,
432
- billingAddress: billingAddress,
433
- shippingAddress: shippingAddress,
434
- createdAt: body.createdAt,
435
- phone,
436
- phoneVerified: false,
437
- updatedAt: body.lastModifiedAt
438
- } satisfies Profile;
439
-
440
- return result;
441
- }
442
-
443
397
  protected createCTAddressDraft( address: Address): CTAddress {
444
398
  return {
445
399
  key: address.identifier.nickName,
@@ -1,32 +1,37 @@
1
1
  import type {
2
2
  RequestContext,
3
3
  Cache,
4
+ StoreFactory,
5
+ StoreFactoryOutput,
6
+ StoreFactoryWithOutput,
4
7
  StoreQueryByProximity,
5
- Store,
6
- StoreIdentifier,
7
- FulfillmentCenterIdentifier,
8
8
  Result,
9
9
  } from '@reactionary/core';
10
10
  import { Reactionary, StoreProvider, StoreQueryByProximitySchema, StoreSchema, success, error } from '@reactionary/core';
11
11
  import * as z from 'zod';
12
12
  import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
13
- import type { Channel } from '@commercetools/platform-sdk';
14
13
  import type { CommercetoolsAPI } from '../core/client.js';
14
+ import type { CommercetoolsStoreFactory } from '../factories/store/store.factory.js';
15
15
 
16
- export class CommercetoolsStoreProvider extends StoreProvider {
16
+ export class CommercetoolsStoreProvider<
17
+ TFactory extends StoreFactory = CommercetoolsStoreFactory,
18
+ > extends StoreProvider<StoreFactoryOutput<TFactory>> {
17
19
  protected config: CommercetoolsConfiguration;
18
20
  protected commercetools: CommercetoolsAPI;
21
+ protected factory: StoreFactoryWithOutput<TFactory>;
19
22
 
20
23
  constructor(
21
24
  config: CommercetoolsConfiguration,
22
25
  cache: Cache,
23
26
  context: RequestContext,
24
- commercetools: CommercetoolsAPI
27
+ commercetools: CommercetoolsAPI,
28
+ factory: StoreFactoryWithOutput<TFactory>,
25
29
  ) {
26
30
  super(cache, context);
27
31
 
28
32
  this.config = config;
29
33
  this.commercetools = commercetools;
34
+ this.factory = factory;
30
35
  }
31
36
 
32
37
  protected async getClient() {
@@ -40,7 +45,7 @@ export class CommercetoolsStoreProvider extends StoreProvider {
40
45
  })
41
46
  public override async queryByProximity(
42
47
  payload: StoreQueryByProximity
43
- ): Promise<Result<Array<Store>>> {
48
+ ): Promise<Result<Array<StoreFactoryOutput<TFactory>>>> {
44
49
  const client = await this.getClient();
45
50
 
46
51
  const remote = await client
@@ -60,33 +65,10 @@ export class CommercetoolsStoreProvider extends StoreProvider {
60
65
  const results = [];
61
66
 
62
67
  for (const r of remote.body.results) {
63
- results.push(this.parseSingle(r));
68
+ results.push(this.factory.parseStore(this.context, r));
64
69
  }
65
70
 
66
71
  return success(results);
67
72
  }
68
73
 
69
- protected parseSingle(body: Channel): Store {
70
-
71
- let name = '';
72
- if (body.name && body.name['la']) {
73
- name = body.name['la'];
74
- }
75
-
76
- const identifier = {
77
- key: body.key,
78
- } satisfies StoreIdentifier;
79
-
80
- const fulfillmentCenter = {
81
- key: body.key,
82
- } satisfies FulfillmentCenterIdentifier;
83
-
84
- const result = {
85
- identifier,
86
- fulfillmentCenter,
87
- name,
88
- } satisfies Store;
89
-
90
- return result;
91
- }
92
74
  }
@@ -1,22 +1,260 @@
1
- import { CapabilitiesSchema } from "@reactionary/core";
2
- import type * as z from 'zod';
1
+ import type {
2
+ Cache,
3
+ CartFactory,
4
+ CartFactoryWithOutput,
5
+ CartProvider,
6
+ CategoryFactory,
7
+ CategoryFactoryWithOutput,
8
+ CategoryProvider,
9
+ CheckoutFactory,
10
+ CheckoutFactoryWithOutput,
11
+ CheckoutProvider,
12
+ IdentityFactory,
13
+ IdentityFactoryWithOutput,
14
+ IdentityProvider,
15
+ InventoryFactory,
16
+ InventoryFactoryWithOutput,
17
+ InventoryProvider,
18
+ OrderFactory,
19
+ OrderFactoryWithOutput,
20
+ OrderProvider,
21
+ OrderSearchFactory,
22
+ OrderSearchFactoryWithOutput,
23
+ OrderSearchProvider,
24
+ PriceFactory,
25
+ PriceFactoryWithOutput,
26
+ PriceProvider,
27
+ ProductAssociationsFactory,
28
+ ProductAssociationsFactoryWithOutput,
29
+ ProductAssociationsProvider,
30
+ ProductFactory,
31
+ ProductFactoryWithOutput,
32
+ ProductListFactory,
33
+ ProductListFactoryWithOutput,
34
+ ProductListProvider,
35
+ ProductProvider,
36
+ ProductReviewsFactory,
37
+ ProductReviewsFactoryWithOutput,
38
+ ProductReviewsProvider,
39
+ ProductSearchFactory,
40
+ ProductSearchFactoryWithOutput,
41
+ ProductSearchProvider,
42
+ ProfileFactory,
43
+ ProfileFactoryWithOutput,
44
+ ProfileProvider,
45
+ RequestContext,
46
+ StoreFactory,
47
+ StoreFactoryWithOutput,
48
+ StoreProvider,
49
+ } from '@reactionary/core';
50
+ import { CapabilitiesSchema } from '@reactionary/core';
51
+ import type { CommercetoolsAPI } from '../core/client.js';
52
+ import type { CommercetoolsConfiguration } from './configuration.schema.js';
53
+ import * as z from 'zod';
54
+
55
+ const EnabledCapabilitySchema = z.looseObject({
56
+ enabled: z.boolean(),
57
+ });
58
+
59
+ const OverridableCapabilitySchema = z.looseObject({
60
+ enabled: z.boolean(),
61
+ factory: z.unknown().optional(),
62
+ provider: z.unknown().optional(),
63
+ });
3
64
 
4
65
  export const CommercetoolsCapabilitiesSchema = CapabilitiesSchema.pick({
5
- product: true,
6
- productSearch: true,
7
- productAssociations: true,
8
- productReviews: true,
9
- productList: true,
10
- identity: true,
11
- cart: true,
12
- checkout: true,
13
- order: true,
14
- orderSearch: true,
15
- inventory: true,
16
- price: true,
17
- category: true,
18
- store: true,
19
- profile: true
20
- }).partial();
21
-
22
- export type CommercetoolsCapabilities = z.infer<typeof CommercetoolsCapabilitiesSchema>;
66
+ product: true,
67
+ productSearch: true,
68
+ productAssociations: true,
69
+ productReviews: true,
70
+ productList: true,
71
+ identity: true,
72
+ cart: true,
73
+ checkout: true,
74
+ order: true,
75
+ orderSearch: true,
76
+ inventory: true,
77
+ price: true,
78
+ category: true,
79
+ store: true,
80
+ profile: true,
81
+ })
82
+ .extend({
83
+ productSearch: EnabledCapabilitySchema.optional(),
84
+ productAssociations: EnabledCapabilitySchema.optional(),
85
+ productReviews: EnabledCapabilitySchema.optional(),
86
+ productList: EnabledCapabilitySchema.optional(),
87
+ identity: EnabledCapabilitySchema.optional(),
88
+ cart: EnabledCapabilitySchema.optional(),
89
+ order: EnabledCapabilitySchema.optional(),
90
+ orderSearch: EnabledCapabilitySchema.optional(),
91
+ inventory: EnabledCapabilitySchema.optional(),
92
+ price: EnabledCapabilitySchema.optional(),
93
+ category: EnabledCapabilitySchema.optional(),
94
+ store: EnabledCapabilitySchema.optional(),
95
+ profile: EnabledCapabilitySchema.optional(),
96
+ product: OverridableCapabilitySchema.optional(),
97
+ checkout: OverridableCapabilitySchema.optional(),
98
+ })
99
+ .partial();
100
+
101
+ export interface CommercetoolsCapabilityProviderFactoryArgs<TFactory> {
102
+ cache: Cache;
103
+ context: RequestContext;
104
+ config: CommercetoolsConfiguration;
105
+ commercetoolsApi: CommercetoolsAPI;
106
+ factory: TFactory;
107
+ }
108
+
109
+ export interface CommercetoolsCapabilityConfig<TFactory, TProvider> {
110
+ factory?: TFactory;
111
+ provider?: (args: CommercetoolsCapabilityProviderFactoryArgs<TFactory>) => TProvider;
112
+ }
113
+
114
+ type EnabledCapabilityConfig<TFactory, TProvider> = {
115
+ enabled: boolean;
116
+ } & CommercetoolsCapabilityConfig<TFactory, TProvider>;
117
+
118
+ export type CommercetoolsProductCapabilityConfig<
119
+ TFactory extends ProductFactory = ProductFactory,
120
+ TProvider extends ProductProvider = ProductProvider,
121
+ > = CommercetoolsCapabilityConfig<ProductFactoryWithOutput<TFactory>, TProvider>;
122
+
123
+ export type CommercetoolsCheckoutCapabilityConfig<
124
+ TFactory extends CheckoutFactory = CheckoutFactory,
125
+ TProvider extends CheckoutProvider = CheckoutProvider,
126
+ > = CommercetoolsCapabilityConfig<CheckoutFactoryWithOutput<TFactory>, TProvider>;
127
+
128
+ export type CommercetoolsProductSearchCapabilityConfig = CommercetoolsCapabilityConfig<
129
+ ProductSearchFactoryWithOutput<ProductSearchFactory>,
130
+ ProductSearchProvider
131
+ >;
132
+ export type CommercetoolsProductAssociationsCapabilityConfig = CommercetoolsCapabilityConfig<
133
+ ProductAssociationsFactoryWithOutput<ProductAssociationsFactory>,
134
+ ProductAssociationsProvider
135
+ >;
136
+ export type CommercetoolsProductReviewsCapabilityConfig = CommercetoolsCapabilityConfig<
137
+ ProductReviewsFactoryWithOutput<ProductReviewsFactory>,
138
+ ProductReviewsProvider
139
+ >;
140
+ export type CommercetoolsProductListCapabilityConfig = CommercetoolsCapabilityConfig<
141
+ ProductListFactoryWithOutput<ProductListFactory>,
142
+ ProductListProvider
143
+ >;
144
+ export type CommercetoolsIdentityCapabilityConfig = CommercetoolsCapabilityConfig<
145
+ IdentityFactoryWithOutput<IdentityFactory>,
146
+ IdentityProvider
147
+ >;
148
+ export type CommercetoolsCartCapabilityConfig = CommercetoolsCapabilityConfig<
149
+ CartFactoryWithOutput<CartFactory>,
150
+ CartProvider
151
+ >;
152
+ export type CommercetoolsInventoryCapabilityConfig = CommercetoolsCapabilityConfig<
153
+ InventoryFactoryWithOutput<InventoryFactory>,
154
+ InventoryProvider
155
+ >;
156
+ export type CommercetoolsPriceCapabilityConfig = CommercetoolsCapabilityConfig<
157
+ PriceFactoryWithOutput<PriceFactory>,
158
+ PriceProvider
159
+ >;
160
+ export type CommercetoolsCategoryCapabilityConfig = CommercetoolsCapabilityConfig<
161
+ CategoryFactoryWithOutput<CategoryFactory>,
162
+ CategoryProvider
163
+ >;
164
+ export type CommercetoolsStoreCapabilityConfig = CommercetoolsCapabilityConfig<
165
+ StoreFactoryWithOutput<StoreFactory>,
166
+ StoreProvider
167
+ >;
168
+ export type CommercetoolsProfileCapabilityConfig = CommercetoolsCapabilityConfig<
169
+ ProfileFactoryWithOutput<ProfileFactory>,
170
+ ProfileProvider
171
+ >;
172
+ export type CommercetoolsOrderCapabilityConfig = CommercetoolsCapabilityConfig<
173
+ OrderFactoryWithOutput<OrderFactory>,
174
+ OrderProvider
175
+ >;
176
+ export type CommercetoolsOrderSearchCapabilityConfig = CommercetoolsCapabilityConfig<
177
+ OrderSearchFactoryWithOutput<OrderSearchFactory>,
178
+ OrderSearchProvider
179
+ >;
180
+
181
+ export type CommercetoolsCapabilityConfigMap<
182
+ TProductFactory extends ProductFactory = ProductFactory,
183
+ TProductProvider extends ProductProvider = ProductProvider,
184
+ TCheckoutFactory extends CheckoutFactory = CheckoutFactory,
185
+ TCheckoutProvider extends CheckoutProvider = CheckoutProvider,
186
+ > = {
187
+ product: EnabledCapabilityConfig<
188
+ ProductFactoryWithOutput<TProductFactory>,
189
+ TProductProvider
190
+ >;
191
+ checkout: EnabledCapabilityConfig<
192
+ CheckoutFactoryWithOutput<TCheckoutFactory>,
193
+ TCheckoutProvider
194
+ >;
195
+ productSearch: EnabledCapabilityConfig<
196
+ ProductSearchFactoryWithOutput<ProductSearchFactory>,
197
+ ProductSearchProvider
198
+ >;
199
+ productAssociations: EnabledCapabilityConfig<
200
+ ProductAssociationsFactoryWithOutput<ProductAssociationsFactory>,
201
+ ProductAssociationsProvider
202
+ >;
203
+ productReviews: EnabledCapabilityConfig<
204
+ ProductReviewsFactoryWithOutput<ProductReviewsFactory>,
205
+ ProductReviewsProvider
206
+ >;
207
+ productList: EnabledCapabilityConfig<
208
+ ProductListFactoryWithOutput<ProductListFactory>,
209
+ ProductListProvider
210
+ >;
211
+ identity: EnabledCapabilityConfig<
212
+ IdentityFactoryWithOutput<IdentityFactory>,
213
+ IdentityProvider
214
+ >;
215
+ cart: EnabledCapabilityConfig<CartFactoryWithOutput<CartFactory>, CartProvider>;
216
+ inventory: EnabledCapabilityConfig<
217
+ InventoryFactoryWithOutput<InventoryFactory>,
218
+ InventoryProvider
219
+ >;
220
+ price: EnabledCapabilityConfig<PriceFactoryWithOutput<PriceFactory>, PriceProvider>;
221
+ category: EnabledCapabilityConfig<
222
+ CategoryFactoryWithOutput<CategoryFactory>,
223
+ CategoryProvider
224
+ >;
225
+ store: EnabledCapabilityConfig<StoreFactoryWithOutput<StoreFactory>, StoreProvider>;
226
+ profile: EnabledCapabilityConfig<
227
+ ProfileFactoryWithOutput<ProfileFactory>,
228
+ ProfileProvider
229
+ >;
230
+ order: EnabledCapabilityConfig<OrderFactoryWithOutput<OrderFactory>, OrderProvider>;
231
+ orderSearch: EnabledCapabilityConfig<
232
+ OrderSearchFactoryWithOutput<OrderSearchFactory>,
233
+ OrderSearchProvider
234
+ >;
235
+ };
236
+
237
+ type CommercetoolsCapabilitiesBase = z.infer<typeof CommercetoolsCapabilitiesSchema>;
238
+
239
+ export type CommercetoolsCapabilities<
240
+ TProductFactory extends ProductFactory = ProductFactory,
241
+ TProductProvider extends ProductProvider = ProductProvider,
242
+ TCheckoutFactory extends CheckoutFactory = CheckoutFactory,
243
+ TCheckoutProvider extends CheckoutProvider = CheckoutProvider,
244
+ > = Omit<
245
+ CommercetoolsCapabilitiesBase,
246
+ keyof CommercetoolsCapabilityConfigMap<
247
+ TProductFactory,
248
+ TProductProvider,
249
+ TCheckoutFactory,
250
+ TCheckoutProvider
251
+ >
252
+ > &
253
+ Partial<
254
+ CommercetoolsCapabilityConfigMap<
255
+ TProductFactory,
256
+ TProductProvider,
257
+ TCheckoutFactory,
258
+ TCheckoutProvider
259
+ >
260
+ >;
@@ -4,12 +4,16 @@ import { getCommercetoolsTestConfiguration } from './test-utils.js';
4
4
  import {
5
5
  createInitialRequestContext,
6
6
  MemoryCache,
7
+ ProductSchema,
8
+ ProductSearchResultSchema,
7
9
  type ProductIdentifier,
8
10
  type ProductSearchQueryByTerm,
9
11
  } from '@reactionary/core';
10
12
  import { CommercetoolsProductProvider } from '../providers/product.provider.js';
11
13
  import { CommercetoolsAPI } from '../core/client.js';
12
14
  import { CommercetoolsSearchProvider } from '../providers/product-search.provider.js';
15
+ import { CommercetoolsProductFactory } from '../factories/product/product.factory.js';
16
+ import { CommercetoolsProductSearchFactory } from '../factories/product-search/product-search.factory.js';
13
17
 
14
18
  describe('Caching', () => {
15
19
  it('should cache repeat look-ups for products', async () => {
@@ -17,7 +21,13 @@ describe('Caching', () => {
17
21
  const context = createInitialRequestContext();
18
22
  const cache = new MemoryCache();
19
23
  const client = new CommercetoolsAPI(config, context);
20
- const provider = new CommercetoolsProductProvider(config, cache, context, client);
24
+ const provider = new CommercetoolsProductProvider(
25
+ cache,
26
+ context,
27
+ config,
28
+ client,
29
+ new CommercetoolsProductFactory(ProductSchema)
30
+ );
21
31
 
22
32
  const identifier = {
23
33
  key: 'product_10959528'
@@ -49,7 +59,13 @@ describe('Caching', () => {
49
59
  const context = createInitialRequestContext();
50
60
  const cache = new MemoryCache();
51
61
  const client = new CommercetoolsAPI(config, context);
52
- const provider = new CommercetoolsSearchProvider(config, cache, context, client);
62
+ const provider = new CommercetoolsSearchProvider(
63
+ config,
64
+ cache,
65
+ context,
66
+ client,
67
+ new CommercetoolsProductSearchFactory(ProductSearchResultSchema),
68
+ );
53
69
 
54
70
  const query = {
55
71
  search: {