@reactionary/source 0.0.48 → 0.0.52

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 (175) hide show
  1. package/core/package.json +4 -3
  2. package/core/src/cache/cache.interface.ts +1 -1
  3. package/core/src/cache/memory-cache.ts +2 -2
  4. package/core/src/cache/noop-cache.ts +1 -1
  5. package/core/src/cache/redis-cache.ts +1 -1
  6. package/core/src/client/client-builder.ts +4 -4
  7. package/core/src/client/client.ts +12 -12
  8. package/core/src/decorators/reactionary.decorator.ts +22 -2
  9. package/core/src/index.ts +14 -14
  10. package/core/src/initialization.ts +1 -1
  11. package/core/src/providers/analytics.provider.ts +2 -2
  12. package/core/src/providers/base.provider.ts +5 -5
  13. package/core/src/providers/cart.provider.ts +6 -6
  14. package/core/src/providers/category.provider.ts +4 -9
  15. package/core/src/providers/checkout.provider.ts +156 -0
  16. package/core/src/providers/identity.provider.ts +5 -5
  17. package/core/src/providers/index.ts +13 -12
  18. package/core/src/providers/inventory.provider.ts +4 -4
  19. package/core/src/providers/order.provider.ts +31 -0
  20. package/core/src/providers/price.provider.ts +5 -5
  21. package/core/src/providers/product.provider.ts +5 -5
  22. package/core/src/providers/profile.provider.ts +5 -5
  23. package/core/src/providers/search.provider.ts +4 -4
  24. package/core/src/providers/store.provider.ts +4 -4
  25. package/core/src/schemas/capabilities.schema.ts +2 -1
  26. package/core/src/schemas/models/analytics.model.ts +1 -1
  27. package/core/src/schemas/models/cart.model.ts +3 -28
  28. package/core/src/schemas/models/category.model.ts +2 -2
  29. package/core/src/schemas/models/checkout.model.ts +66 -0
  30. package/core/src/schemas/models/cost.model.ts +21 -0
  31. package/core/src/schemas/models/identifiers.model.ts +23 -2
  32. package/core/src/schemas/models/identity.model.ts +8 -5
  33. package/core/src/schemas/models/index.ts +19 -15
  34. package/core/src/schemas/models/inventory.model.ts +2 -2
  35. package/core/src/schemas/models/order.model.ts +46 -0
  36. package/core/src/schemas/models/payment.model.ts +5 -12
  37. package/core/src/schemas/models/price.model.ts +3 -3
  38. package/core/src/schemas/models/product.model.ts +6 -3
  39. package/core/src/schemas/models/profile.model.ts +2 -2
  40. package/core/src/schemas/models/search.model.ts +2 -3
  41. package/core/src/schemas/models/shipping-method.model.ts +34 -3
  42. package/core/src/schemas/models/store.model.ts +2 -2
  43. package/core/src/schemas/mutations/analytics.mutation.ts +2 -2
  44. package/core/src/schemas/mutations/cart.mutation.ts +5 -5
  45. package/core/src/schemas/mutations/checkout.mutation.ts +50 -0
  46. package/core/src/schemas/mutations/identity.mutation.ts +1 -1
  47. package/core/src/schemas/mutations/index.ts +10 -10
  48. package/core/src/schemas/mutations/profile.mutation.ts +1 -1
  49. package/core/src/schemas/queries/cart.query.ts +2 -2
  50. package/core/src/schemas/queries/category.query.ts +3 -3
  51. package/core/src/schemas/queries/checkout.query.ts +22 -0
  52. package/core/src/schemas/queries/identity.query.ts +1 -1
  53. package/core/src/schemas/queries/index.ts +13 -12
  54. package/core/src/schemas/queries/inventory.query.ts +2 -2
  55. package/core/src/schemas/queries/order.query.ts +9 -0
  56. package/core/src/schemas/queries/price.query.ts +2 -2
  57. package/core/src/schemas/queries/product.query.ts +9 -2
  58. package/core/src/schemas/queries/profile.query.ts +1 -1
  59. package/core/src/schemas/queries/search.query.ts +2 -2
  60. package/core/src/schemas/queries/store.query.ts +1 -1
  61. package/core/src/schemas/session.schema.ts +3 -3
  62. package/core/tsconfig.json +3 -2
  63. package/examples/next/next.config.js +17 -6
  64. package/examples/next/src/app/page.tsx +1 -2
  65. package/examples/node/package.json +2 -1
  66. package/examples/node/src/basic/basic-node-setup.spec.ts +1 -1
  67. package/examples/node/tsconfig.json +2 -1
  68. package/examples/node/tsconfig.spec.json +3 -2
  69. package/package.json +3 -1
  70. package/providers/algolia/package.json +2 -1
  71. package/providers/algolia/src/core/initialize.ts +5 -5
  72. package/providers/algolia/src/index.ts +5 -5
  73. package/providers/algolia/src/providers/product.provider.ts +8 -2
  74. package/providers/algolia/src/providers/search.provider.ts +1 -1
  75. package/providers/algolia/src/test/search.provider.spec.ts +1 -1
  76. package/providers/algolia/tsconfig.json +2 -1
  77. package/providers/algolia/tsconfig.spec.json +3 -2
  78. package/providers/commercetools/{jest.config.ts → jest.config.cjs} +1 -1
  79. package/providers/commercetools/package.json +3 -2
  80. package/providers/commercetools/src/core/client.ts +63 -32
  81. package/providers/commercetools/src/core/initialize.ts +20 -16
  82. package/providers/commercetools/src/index.ts +10 -10
  83. package/providers/commercetools/src/providers/cart.provider.ts +14 -19
  84. package/providers/commercetools/src/providers/category.provider.ts +3 -12
  85. package/providers/commercetools/src/providers/checkout.provider.ts +644 -0
  86. package/providers/commercetools/src/providers/identity.provider.ts +8 -8
  87. package/providers/commercetools/src/providers/index.ts +12 -9
  88. package/providers/commercetools/src/providers/inventory.provider.ts +2 -4
  89. package/providers/commercetools/src/providers/order.provider.ts +163 -0
  90. package/providers/commercetools/src/providers/price.provider.ts +3 -3
  91. package/providers/commercetools/src/providers/product.provider.ts +24 -6
  92. package/providers/commercetools/src/providers/profile.provider.ts +2 -2
  93. package/providers/commercetools/src/providers/search.provider.ts +3 -5
  94. package/providers/commercetools/src/providers/store.provider.ts +3 -3
  95. package/providers/commercetools/src/schema/capabilities.schema.ts +2 -1
  96. package/providers/commercetools/src/schema/commercetools.schema.ts +7 -5
  97. package/providers/commercetools/src/schema/configuration.schema.ts +2 -0
  98. package/providers/commercetools/src/test/cart.provider.spec.ts +24 -4
  99. package/providers/commercetools/src/test/category.provider.spec.ts +3 -3
  100. package/providers/commercetools/src/test/checkout.provider.spec.ts +312 -0
  101. package/providers/commercetools/src/test/identity.provider.spec.ts +3 -3
  102. package/providers/commercetools/src/test/inventory.provider.spec.ts +2 -2
  103. package/providers/commercetools/src/test/price.provider.spec.ts +4 -4
  104. package/providers/commercetools/src/test/product.provider.spec.ts +22 -5
  105. package/providers/commercetools/src/test/profile.provider.spec.ts +3 -3
  106. package/providers/commercetools/src/test/search.provider.spec.ts +2 -2
  107. package/providers/commercetools/src/test/store.provider.spec.ts +2 -2
  108. package/providers/commercetools/src/test/test-utils.ts +14 -0
  109. package/providers/commercetools/tsconfig.json +2 -1
  110. package/providers/commercetools/tsconfig.spec.json +4 -3
  111. package/providers/fake/{jest.config.ts → jest.config.cjs} +1 -1
  112. package/providers/fake/package.json +2 -2
  113. package/providers/fake/src/core/initialize.ts +6 -6
  114. package/providers/fake/src/index.ts +4 -4
  115. package/providers/fake/src/providers/analytics.provider.ts +1 -1
  116. package/providers/fake/src/providers/cart.provider.ts +2 -2
  117. package/providers/fake/src/providers/category.provider.ts +7 -3
  118. package/providers/fake/src/providers/identity.provider.ts +1 -1
  119. package/providers/fake/src/providers/index.ts +9 -9
  120. package/providers/fake/src/providers/inventory.provider.ts +1 -1
  121. package/providers/fake/src/providers/price.provider.ts +1 -1
  122. package/providers/fake/src/providers/product.provider.ts +10 -4
  123. package/providers/fake/src/providers/search.provider.ts +2 -5
  124. package/providers/fake/src/providers/store.provider.ts +2 -3
  125. package/providers/fake/src/test/cart.provider.spec.ts +3 -3
  126. package/providers/fake/src/test/category.provider.spec.ts +2 -2
  127. package/providers/fake/src/test/price.provider.spec.ts +2 -2
  128. package/providers/fake/src/test/product.provider.spec.ts +8 -8
  129. package/providers/fake/src/test/test-utils.ts +1 -1
  130. package/providers/fake/tsconfig.json +2 -1
  131. package/providers/fake/tsconfig.spec.json +1 -3
  132. package/providers/posthog/package.json +4 -4
  133. package/providers/posthog/project.json +2 -2
  134. package/providers/posthog/src/core/initialize.ts +2 -2
  135. package/providers/posthog/src/index.ts +3 -3
  136. package/providers/posthog/tsconfig.json +2 -1
  137. package/tsconfig.base.json +3 -4
  138. package/.claude/settings.local.json +0 -28
  139. package/core/src/providers/cart-payment.provider.ts +0 -57
  140. package/core/src/schemas/mutations/cart-payment.mutation.ts +0 -21
  141. package/core/src/schemas/queries/cart-payment.query.ts +0 -12
  142. package/otel/README.md +0 -227
  143. package/otel/eslint.config.mjs +0 -23
  144. package/otel/package.json +0 -11
  145. package/otel/pnpm-lock.yaml +0 -805
  146. package/otel/project.json +0 -33
  147. package/otel/src/index.ts +0 -22
  148. package/otel/src/metrics.ts +0 -76
  149. package/otel/src/provider-instrumentation.ts +0 -108
  150. package/otel/src/test/otel.spec.ts +0 -8
  151. package/otel/src/trace-decorator.ts +0 -226
  152. package/otel/src/tracer.ts +0 -83
  153. package/otel/src/trpc-middleware.ts +0 -128
  154. package/otel/tsconfig.json +0 -23
  155. package/otel/tsconfig.lib.json +0 -23
  156. package/otel/tsconfig.spec.json +0 -28
  157. package/otel/vite.config.ts +0 -24
  158. package/providers/commercetools/src/providers/cart-payment.provider.ts +0 -193
  159. package/providers/commercetools/src/test/cart-payment.provider.spec.ts +0 -145
  160. package/trpc/README.md +0 -7
  161. package/trpc/__mocks__/superjson.js +0 -25
  162. package/trpc/eslint.config.mjs +0 -19
  163. package/trpc/jest.config.ts +0 -14
  164. package/trpc/package.json +0 -14
  165. package/trpc/project.json +0 -31
  166. package/trpc/src/client.ts +0 -175
  167. package/trpc/src/index.ts +0 -44
  168. package/trpc/src/integration.spec.ts +0 -223
  169. package/trpc/src/server.ts +0 -125
  170. package/trpc/src/test-utils.ts +0 -31
  171. package/trpc/src/transparent-client.spec.ts +0 -162
  172. package/trpc/src/types.ts +0 -144
  173. package/trpc/tsconfig.json +0 -16
  174. package/trpc/tsconfig.lib.json +0 -10
  175. package/trpc/tsconfig.spec.json +0 -15
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { BaseQuerySchema } from './base.query';
2
+ import { BaseQuerySchema } from './base.query.js';
3
+ import { SKUIdentifierSchema } from '../models/index.js';
3
4
 
4
5
  export const ProductQueryBySlugSchema = BaseQuerySchema.extend({
5
6
  slug: z.string()
@@ -9,5 +10,11 @@ export const ProductQueryByIdSchema = BaseQuerySchema.extend({
9
10
  id: z.string()
10
11
  });
11
12
 
13
+ export const ProductQueryBySKUSchema = BaseQuerySchema.extend({
14
+ sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
15
+ });
16
+
17
+
12
18
  export type ProductQueryBySlug = z.infer<typeof ProductQueryBySlugSchema>;
13
- export type ProductQueryById = z.infer<typeof ProductQueryByIdSchema>;
19
+ export type ProductQueryById = z.infer<typeof ProductQueryByIdSchema>;
20
+ export type ProductQueryBySKU = z.infer<typeof ProductQueryBySKUSchema>;
@@ -1,5 +1,5 @@
1
1
  import type { z } from 'zod';
2
- import { BaseQuerySchema } from './base.query';
2
+ import { BaseQuerySchema } from './base.query.js';
3
3
 
4
4
  export const ProfileQuerySelfSchema = BaseQuerySchema.extend({
5
5
  });
@@ -1,6 +1,6 @@
1
1
  import type { z } from 'zod';
2
- import { BaseQuerySchema } from './base.query';
3
- import { SearchIdentifierSchema } from '../models/identifiers.model';
2
+ import { BaseQuerySchema } from './base.query.js';
3
+ import { SearchIdentifierSchema } from '../models/identifiers.model.js';
4
4
 
5
5
  export const SearchQueryByTermSchema = BaseQuerySchema.extend({
6
6
  search: SearchIdentifierSchema.required()
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { BaseQuerySchema } from './base.query';
2
+ import { BaseQuerySchema } from './base.query.js';
3
3
 
4
4
  export const StoreQueryByProximitySchema = BaseQuerySchema.extend({
5
5
  longitude: z.number().default(0),
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
- import { IdentitySchema } from './models/identity.model';
3
- import { WebStoreIdentifierSchema } from './models/identifiers.model';
4
- import { CurrencySchema } from './models/currency.model';
2
+ import { IdentitySchema } from './models/identity.model.js';
3
+ import { WebStoreIdentifierSchema } from './models/identifiers.model.js';
4
+ import { CurrencySchema } from './models/currency.model.js';
5
5
 
6
6
  /**
7
7
  * The language and locale context for the current request.
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "extends": "../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "module": "commonjs",
4
+ "module": "nodenext",
5
+ "moduleResolution": "nodenext",
5
6
  "forceConsistentCasingInFileNames": true,
6
7
  "strict": true,
7
8
  "importHelpers": true,
8
9
  "noImplicitOverride": true,
9
10
  "noImplicitReturns": true,
10
11
  "noFallthroughCasesInSwitch": true,
11
- "noPropertyAccessFromIndexSignature": true
12
+ "noPropertyAccessFromIndexSignature": true,
12
13
  },
13
14
  "files": [],
14
15
  "include": [],
@@ -1,20 +1,31 @@
1
- //@ts-check
1
+ // @ts-check
2
2
 
3
-
4
3
  const { composePlugins, withNx } = require('@nx/next');
5
4
 
6
5
  /**
7
6
  * @type {import('@nx/next/plugins/with-nx').WithNxOptions}
8
7
  **/
9
8
  const nextConfig = {
10
- // Use this to set Nx-specific options
11
- // See: https://nx.dev/recipes/next/next-config-setup
9
+ // Nx-specific options
12
10
  nx: {},
11
+
12
+ webpack: (config) => {
13
+ // Ensure Next resolves .ts and .tsx files when .js imports are used
14
+ config.resolve.extensions.push('.ts', '.tsx');
15
+
16
+ // Tell Webpack: whenever you see a `.js` import, also look for a `.ts` file.
17
+ config.resolve.extensionAlias = {
18
+ '.js': ['.ts', '.js'],
19
+ '.mjs': ['.mts', '.mjs'],
20
+ };
21
+
22
+ return config;
23
+ },
13
24
  };
14
25
 
15
26
  const plugins = [
16
- // Add more Next.js plugins to this list if needed.
27
+ // Add more Next.js plugins if needed.
17
28
  withNx,
18
29
  ];
19
30
 
20
- module.exports = composePlugins(...plugins)(nextConfig);
31
+ module.exports = composePlugins(...plugins)(nextConfig);
@@ -1,7 +1,6 @@
1
1
  import styles from './page.module.scss';
2
- import { ClientBuilder, createInitialRequestContext, NoOpCache, SessionSchema } from '@reactionary/core';
2
+ import { ClientBuilder, createInitialRequestContext, NoOpCache } from '@reactionary/core';
3
3
  import { withFakeCapabilities } from '@reactionary/provider-fake';
4
- import { withCommercetoolsCapabilities } from '@reactionary/provider-commercetools';
5
4
 
6
5
  export default async function Index() {
7
6
  const client = new ClientBuilder()
@@ -2,5 +2,6 @@
2
2
  "name": "@reactionary/examples-node",
3
3
  "version": "0.0.1",
4
4
  "private": true,
5
- "dependencies": {}
5
+ "dependencies": {},
6
+ "type": "module"
6
7
  }
@@ -1,4 +1,4 @@
1
- import { buildClient, createInitialRequestContext, NoOpCache, SessionSchema } from '@reactionary/core';
1
+ import { buildClient, createInitialRequestContext, NoOpCache } from '@reactionary/core';
2
2
  import { withFakeCapabilities } from '@reactionary/provider-fake';
3
3
 
4
4
  describe('basic node setup', () => {
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "module": "commonjs",
4
+ "module": "nodenext",
5
+ "moduleResolution": "nodenext",
5
6
  "forceConsistentCasingInFileNames": true,
6
7
  "strict": true,
7
8
  "importHelpers": true,
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
3
  "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
4
  "module": "commonjs",
6
- "moduleResolution": "node10",
5
+ "moduleResolution": "node",
6
+ "verbatimModuleSyntax": false,
7
+ "outDir": "../../dist/out-tsc",
7
8
  "types": ["jest", "node"]
8
9
  },
9
10
  "include": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/source",
3
- "version": "0.0.48",
3
+ "version": "0.0.52",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "dependencies": {
@@ -34,6 +34,7 @@
34
34
  "algoliasearch": "^5.23.4",
35
35
  "connect-redis": "^8.1.0",
36
36
  "cors": "^2.8.5",
37
+ "debug": "^4.4.3",
37
38
  "dotenv": "^17.2.2",
38
39
  "express": "^5.1.0",
39
40
  "express-session": "^1.18.1",
@@ -82,6 +83,7 @@
82
83
  "@swc/cli": "~0.6.0",
83
84
  "@swc/core": "~1.5.7",
84
85
  "@swc/helpers": "~0.5.11",
86
+ "@types/debug": "^4.1.12",
85
87
  "@types/jest": "^29.5.12",
86
88
  "@types/node": "18.16.9",
87
89
  "@types/react": "19.0.0",
@@ -7,5 +7,6 @@
7
7
  "@reactionary/core": "0.0.1",
8
8
  "algoliasearch": "^5.23.4",
9
9
  "zod": "4.1.9"
10
- }
10
+ },
11
+ "type": "module"
11
12
  }
@@ -1,10 +1,10 @@
1
1
  import type { Client, Cache } from "@reactionary/core";
2
2
  import { ProductSchema } from "@reactionary/core";
3
- import { AlgoliaProductProvider } from "../providers/product.provider";
4
- import { AlgoliaSearchProvider } from "../providers/search.provider";
5
- import type { AlgoliaCapabilities } from "../schema/capabilities.schema";
6
- import type { AlgoliaConfiguration } from "../schema/configuration.schema";
7
- import { AlgoliaSearchResultSchema } from "../schema/search.schema";
3
+ import { AlgoliaProductProvider } from "../providers/product.provider.js";
4
+ import { AlgoliaSearchProvider } from "../providers/search.provider.js";
5
+ import type { AlgoliaCapabilities } from "../schema/capabilities.schema.js";
6
+ import type { AlgoliaConfiguration } from "../schema/configuration.schema.js";
7
+ import { AlgoliaSearchResultSchema } from "../schema/search.schema.js";
8
8
 
9
9
  export function withAlgoliaCapabilities(configuration: AlgoliaConfiguration, capabilities: AlgoliaCapabilities) {
10
10
  return (cache: Cache) => {
@@ -1,7 +1,7 @@
1
- export * from './core/initialize';
1
+ export * from './core/initialize.js';
2
2
 
3
- export * from './providers/product.provider';
4
- export * from './providers/search.provider';
3
+ export * from './providers/product.provider.js';
4
+ export * from './providers/search.provider.js';
5
5
 
6
- export * from './schema/configuration.schema';
7
- export * from './schema/capabilities.schema';
6
+ export * from './schema/configuration.schema.js';
7
+ export * from './schema/capabilities.schema.js';
@@ -3,13 +3,14 @@ import type {
3
3
  ProductQueryById,
4
4
  ProductQueryBySlug,
5
5
  RequestContext,
6
- Cache
6
+ Cache,
7
+ ProductQueryBySKU
7
8
  } from '@reactionary/core';
8
9
  import {
9
10
  ProductProvider
10
11
  } from '@reactionary/core';
11
12
  import type { z } from 'zod';
12
- import type { AlgoliaConfiguration } from '../schema/configuration.schema';
13
+ import type { AlgoliaConfiguration } from '../schema/configuration.schema.js';
13
14
 
14
15
  export class AlgoliaProductProvider<
15
16
  T extends Product = Product
@@ -57,4 +58,9 @@ export class AlgoliaProductProvider<
57
58
 
58
59
  return this.assert(result);
59
60
  }
61
+
62
+ public override getBySKU(payload: ProductQueryBySKU, reqCtx: RequestContext): Promise<T> {
63
+ throw new Error('Method not implemented.');
64
+ }
65
+
60
66
  }
@@ -9,7 +9,7 @@ import {
9
9
  } from '@reactionary/core';
10
10
  import { algoliasearch } from 'algoliasearch';
11
11
  import type { z } from 'zod';
12
- import type { AlgoliaConfiguration } from '../schema/configuration.schema';
12
+ import type { AlgoliaConfiguration } from '../schema/configuration.schema.js';
13
13
 
14
14
  export class AlgoliaSearchProvider<
15
15
  T extends SearchResult = SearchResult
@@ -1,6 +1,6 @@
1
1
  import 'dotenv/config';
2
2
  import { createInitialRequestContext, NoOpCache, SearchResultSchema } from '@reactionary/core';
3
- import { AlgoliaSearchProvider } from '../providers/search.provider';
3
+ import { AlgoliaSearchProvider } from '../providers/search.provider.js';
4
4
 
5
5
  describe('Algolia Search Provider', () => {
6
6
  const provider = new AlgoliaSearchProvider(
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "module": "commonjs",
4
+ "module": "nodenext",
5
+ "moduleResolution": "nodenext",
5
6
  "forceConsistentCasingInFileNames": true,
6
7
  "strict": true,
7
8
  "importHelpers": true,
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
3
  "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
4
  "module": "commonjs",
6
- "moduleResolution": "node10",
5
+ "moduleResolution": "node",
6
+ "verbatimModuleSyntax": false,
7
+ "outDir": "../../dist/out-tsc",
7
8
  "types": ["jest", "node"]
8
9
  },
9
10
  "include": [
@@ -1,4 +1,4 @@
1
- export default {
1
+ module.exports = {
2
2
  displayName: 'provider-commercetools',
3
3
  preset: '../../jest.preset.js',
4
4
  testEnvironment: 'node',
@@ -5,9 +5,10 @@
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
7
  "@reactionary/core": "0.0.1",
8
- "@reactionary/otel": "0.0.1",
8
+ "debug": "^4.4.3",
9
9
  "zod": "4.1.9",
10
10
  "@commercetools/ts-client": "^4.2.1",
11
11
  "@commercetools/platform-sdk": "^8.8.0"
12
- }
12
+ },
13
+ "type": "module"
13
14
  }
@@ -5,10 +5,20 @@ import {
5
5
  type TokenStore,
6
6
  } from '@commercetools/ts-client';
7
7
  import { createApiBuilderFromCtpClient } from '@commercetools/platform-sdk';
8
- import type { CommercetoolsConfiguration } from '../schema/configuration.schema';
8
+ import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
9
9
  import { randomUUID } from 'crypto';
10
- import { GuestIdentitySchema, IdentitySchema, type RequestContext } from '@reactionary/core';
10
+ import {
11
+ AnonymousIdentitySchema,
12
+ GuestIdentitySchema,
13
+ RegisteredIdentitySchema,
14
+ type RequestContext,
15
+ } from '@reactionary/core';
11
16
  import * as crypto from 'crypto';
17
+ import createDebug from 'debug'
18
+ const debug = createDebug('commercetools:debug')
19
+
20
+
21
+
12
22
 
13
23
  export class RequestContextTokenCache implements TokenCache {
14
24
  constructor(protected context: RequestContext) {}
@@ -18,15 +28,11 @@ export class RequestContextTokenCache implements TokenCache {
18
28
  ): Promise<TokenStore | undefined> {
19
29
  const identity = this.context.identity;
20
30
 
21
- if (identity.type !== 'Anonymous') {
22
- return {
23
- refreshToken: identity.refresh_token,
24
- token: identity.token || '',
25
- expirationTime: identity.expiry.getTime(),
26
- };
27
- }
28
-
29
- return undefined;
31
+ return {
32
+ refreshToken: identity.refresh_token,
33
+ token: identity.token || '',
34
+ expirationTime: identity.expiry.getTime(),
35
+ };
30
36
  }
31
37
 
32
38
  public async set(
@@ -41,6 +47,8 @@ export class RequestContextTokenCache implements TokenCache {
41
47
  }
42
48
  }
43
49
 
50
+
51
+
44
52
  export class CommercetoolsClient {
45
53
  protected config: CommercetoolsConfiguration;
46
54
 
@@ -57,8 +65,6 @@ export class CommercetoolsClient {
57
65
  password: string,
58
66
  reqCtx: RequestContext
59
67
  ) {
60
- const cache = new RequestContextTokenCache(reqCtx);
61
-
62
68
  const registrationBuilder =
63
69
  this.createBaseClientBuilder().withAnonymousSessionFlow({
64
70
  host: this.config.authUrl,
@@ -68,12 +74,12 @@ export class CommercetoolsClient {
68
74
  clientSecret: this.config.clientSecret,
69
75
  },
70
76
  scopes: this.config.scopes,
71
- tokenCache: cache,
72
77
  });
73
78
 
74
79
  const registrationClient = createApiBuilderFromCtpClient(
75
80
  registrationBuilder.build()
76
81
  );
82
+
77
83
  const registration = await registrationClient
78
84
  .withProjectKey({ projectKey: this.config.projectKey })
79
85
  .me()
@@ -87,6 +93,8 @@ export class CommercetoolsClient {
87
93
  .execute();
88
94
 
89
95
  const login = await this.login(username, password, reqCtx);
96
+
97
+ return login;
90
98
  }
91
99
 
92
100
  public async login(
@@ -95,7 +103,6 @@ export class CommercetoolsClient {
95
103
  reqCtx: RequestContext
96
104
  ) {
97
105
  const cache = new RequestContextTokenCache(reqCtx);
98
- const identity = reqCtx.identity;
99
106
 
100
107
  const loginBuilder = this.createBaseClientBuilder().withPasswordFlow({
101
108
  host: this.config.authUrl,
@@ -114,39 +121,52 @@ export class CommercetoolsClient {
114
121
  const login = await loginClient
115
122
  .withProjectKey({ projectKey: this.config.projectKey })
116
123
  .me()
117
- .get()
124
+ .login()
125
+ .post({
126
+ body: {
127
+ email: username,
128
+ password: password,
129
+ },
130
+ })
118
131
  .execute();
119
132
 
120
- identity.type = 'Registered';
121
- identity.logonId = username;
122
- identity.id = {
123
- userId: login.body.id
124
- };
133
+ reqCtx.identity = RegisteredIdentitySchema.parse({
134
+ ...reqCtx.identity,
135
+ type: 'Registered',
136
+ logonId: username,
137
+ id: {
138
+ userId: login.body.customer.id,
139
+ },
140
+ });
141
+
142
+ return reqCtx.identity;
125
143
  }
126
144
 
127
145
  public async logout(reqCtx: RequestContext) {
128
146
  const cache = new RequestContextTokenCache(reqCtx);
129
147
  await cache.set({ token: '', refreshToken: '', expirationTime: 0 });
130
148
 
131
- reqCtx.identity = IdentitySchema.parse({});
149
+ reqCtx.identity = AnonymousIdentitySchema.parse({});
132
150
 
133
151
  // TODO: We could do token revocation here, if we wanted to. The above simply whacks the session.
152
+
153
+ return reqCtx.identity;
134
154
  }
135
155
 
136
156
  protected createClient(reqCtx: RequestContext) {
137
157
  const cache = new RequestContextTokenCache(reqCtx);
138
-
158
+
139
159
  if (reqCtx.identity.type === 'Anonymous') {
140
160
  reqCtx.identity = GuestIdentitySchema.parse({
141
161
  id: {
142
162
  userId: crypto.randomUUID().toString(),
143
163
  },
144
- type: 'Guest'
164
+ type: 'Guest',
145
165
  });
146
166
  }
147
167
 
148
168
  const identity = reqCtx.identity;
149
- let builder = this.createBaseClientBuilder();
169
+ let builder = this.createBaseClientBuilder(reqCtx);
150
170
 
151
171
  if (!identity.token || !identity.refresh_token) {
152
172
  builder = builder.withAnonymousSessionFlow({
@@ -175,8 +195,14 @@ export class CommercetoolsClient {
175
195
  return createApiBuilderFromCtpClient(builder.build());
176
196
  }
177
197
 
178
- protected createBaseClientBuilder() {
179
- const builder = new ClientBuilder()
198
+
199
+
200
+
201
+
202
+
203
+
204
+ protected createBaseClientBuilder(reqCtx?: RequestContext) {
205
+ let builder = new ClientBuilder()
180
206
  .withProjectKey(this.config.projectKey)
181
207
  .withQueueMiddleware({
182
208
  concurrency: 20,
@@ -195,10 +221,6 @@ export class CommercetoolsClient {
195
221
  return Promise.resolve(body);
196
222
  },
197
223
  })
198
- .withCorrelationIdMiddleware({
199
- // ideally this would be pushed in as part of the session context, so we can trace it end-to-end
200
- generate: () => `REACTIONARY-${randomUUID()}`,
201
- })
202
224
  .withHttpMiddleware({
203
225
  retryConfig: {
204
226
  backoff: true,
@@ -215,8 +237,17 @@ export class CommercetoolsClient {
215
237
  httpClient: fetch,
216
238
  });
217
239
 
218
- // CT's telemetry module is currently broken and consequently not included in the above (createTelemetryMiddleware)
240
+ const correlationId = reqCtx?.correlationId || 'REACTIONARY-' + (typeof crypto !== 'undefined' && 'randomUUID' in crypto ? crypto.randomUUID() : randomUUID());
241
+ builder = builder.withCorrelationIdMiddleware({
242
+ generate: () => correlationId,
243
+ });
244
+
245
+ // Note:
219
246
 
247
+ // CT's telemetry module is currently broken and consequently not included in the above (createTelemetryMiddleware)
248
+ if (debug.enabled) {
249
+ builder = builder.withLoggerMiddleware();
250
+ }
220
251
  return builder;
221
252
  }
222
253
  }
@@ -7,7 +7,10 @@ import type {
7
7
  InventoryProvider,
8
8
  PriceProvider,
9
9
  CategoryProvider,
10
- StoreProvider} from "@reactionary/core";
10
+ StoreProvider,
11
+ CheckoutProvider,
12
+ OrderProvider
13
+ } from "@reactionary/core";
11
14
  import {
12
15
  CartSchema,
13
16
  IdentitySchema,
@@ -16,18 +19,18 @@ import {
16
19
  ProductSchema,
17
20
  SearchResultSchema,
18
21
  CategorySchema,
19
- CartPaymentInstructionSchema
22
+ CheckoutSchema
20
23
  } from "@reactionary/core";
21
- import type { CommercetoolsCapabilities } from "../schema/capabilities.schema";
22
- import { CommercetoolsSearchProvider } from "../providers/search.provider";
23
- import { CommercetoolsProductProvider } from '../providers/product.provider';
24
- import type { CommercetoolsConfiguration } from "../schema/configuration.schema";
25
- import { CommercetoolsIdentityProvider } from "../providers/identity.provider";
26
- import { CommercetoolsCartProvider } from "../providers/cart.provider";
27
- import { CommercetoolsInventoryProvider } from "../providers/inventory.provider";
28
- import { CommercetoolsPriceProvider } from "../providers/price.provider";
29
- import { CommercetoolsCategoryProvider } from "../providers/category.provider";
30
- import { CommercetoolsCartPaymentProvider } from "../providers/cart-payment.provider";
24
+ import type { CommercetoolsCapabilities } from "../schema/capabilities.schema.js";
25
+ import { CommercetoolsSearchProvider } from "../providers/search.provider.js";
26
+ import { CommercetoolsProductProvider } from '../providers/product.provider.js';
27
+ import type { CommercetoolsConfiguration } from "../schema/configuration.schema.js";
28
+ import { CommercetoolsIdentityProvider } from "../providers/identity.provider.js";
29
+ import { CommercetoolsCartProvider } from "../providers/cart.provider.js";
30
+ import { CommercetoolsInventoryProvider } from "../providers/inventory.provider.js";
31
+ import { CommercetoolsPriceProvider } from "../providers/price.provider.js";
32
+ import { CommercetoolsCategoryProvider } from "../providers/category.provider.js";
33
+ import { CommercetoolsCheckoutProvider } from "../providers/index.js";
31
34
 
32
35
  type CommercetoolsClient<T extends CommercetoolsCapabilities> =
33
36
  (T['cart'] extends true ? { cart: CartProvider } : object) &
@@ -37,8 +40,9 @@ type CommercetoolsClient<T extends CommercetoolsCapabilities> =
37
40
  (T['category'] extends true ? { category: CategoryProvider } : object) &
38
41
  (T['inventory'] extends true ? { inventory: InventoryProvider } : object) &
39
42
  (T['price'] extends true ? { price: PriceProvider } : object) &
40
- (T['store'] extends true ? { store: StoreProvider } : object);
41
-
43
+ (T['store'] extends true ? { store: StoreProvider } : object) &
44
+ (T['order'] extends true ? { order: OrderProvider } : object) &
45
+ (T['checkout'] extends true ? { checkout: CheckoutProvider } : object) ;
42
46
  export function withCommercetoolsCapabilities<T extends CommercetoolsCapabilities>(
43
47
  configuration: CommercetoolsConfiguration,
44
48
  capabilities: T
@@ -74,8 +78,8 @@ export function withCommercetoolsCapabilities<T extends CommercetoolsCapabilitie
74
78
  client.category = new CommercetoolsCategoryProvider(configuration, CategorySchema, cache);
75
79
  }
76
80
 
77
- if (capabilities.cartPayment) {
78
- client.cartPayment = new CommercetoolsCartPaymentProvider(configuration, CartPaymentInstructionSchema, cache);
81
+ if (capabilities.checkout) {
82
+ client.checkout = new CommercetoolsCheckoutProvider(configuration, CheckoutSchema, cache);
79
83
  }
80
84
 
81
85
 
@@ -1,12 +1,12 @@
1
- export * from './core/client';
2
- export * from './core/initialize';
1
+ export * from './core/client.js';
2
+ export * from './core/initialize.js';
3
3
 
4
- export * from './providers/cart.provider';
5
- export * from './providers/identity.provider';
6
- export * from './providers/inventory.provider';
7
- export * from './providers/price.provider';
8
- export * from './providers/product.provider';
9
- export * from './providers/search.provider';
4
+ export * from './providers/cart.provider.js';
5
+ export * from './providers/identity.provider.js';
6
+ export * from './providers/inventory.provider.js';
7
+ export * from './providers/price.provider.js';
8
+ export * from './providers/product.provider.js';
9
+ export * from './providers/search.provider.js';
10
10
 
11
- export * from './schema/capabilities.schema';
12
- export * from './schema/configuration.schema';
11
+ export * from './schema/capabilities.schema.js';
12
+ export * from './schema/configuration.schema.js';