@reactionary/source 0.3.0 → 0.3.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 (103) hide show
  1. package/core/src/client/client-builder.ts +3 -7
  2. package/core/src/client/client.ts +2 -3
  3. package/core/src/decorators/reactionary.decorator.ts +2 -2
  4. package/core/src/initialization.ts +11 -3
  5. package/core/src/providers/analytics.provider.ts +75 -0
  6. package/core/src/providers/cart.provider.ts +3 -0
  7. package/core/src/providers/category.provider.ts +1 -0
  8. package/core/src/providers/identity.provider.ts +5 -0
  9. package/core/src/schemas/errors/invalid-input.error.ts +1 -1
  10. package/core/src/schemas/errors/invalid-output.error.ts +1 -1
  11. package/core/src/schemas/models/identifiers.model.ts +3 -0
  12. package/core/src/schemas/models/order.model.ts +2 -2
  13. package/core/src/schemas/mutations/analytics/index.ts +23 -0
  14. package/core/src/schemas/mutations/analytics/product-add-to-cart.mutation.ts +25 -0
  15. package/core/src/schemas/mutations/analytics/product-details-view.mutation.ts +14 -0
  16. package/core/src/schemas/mutations/analytics/product-summary-click.mutation.ts +26 -0
  17. package/core/src/schemas/mutations/analytics/product-summary-view.mutation.ts +25 -0
  18. package/core/src/schemas/mutations/analytics/purchase.mutation.ts +14 -0
  19. package/core/src/schemas/mutations/index.ts +1 -1
  20. package/core/src/schemas/queries/order-search.query.ts +3 -0
  21. package/core/src/schemas/session.schema.ts +21 -9
  22. package/core/src/test/client-builder.spec.ts +60 -0
  23. package/core/src/zod-utils.ts +3 -1
  24. package/documentation/{1-purpose.md → docs/1-purpose.md} +4 -0
  25. package/documentation/docs/8-tracking.md +9 -0
  26. package/documentation/docs/providers/analytics.provider.md +297 -0
  27. package/documentation/docs/providers/base.provider.md +118 -0
  28. package/documentation/docs/providers/cart.provider.md +305 -0
  29. package/documentation/docs/providers/category.provider.md +244 -0
  30. package/documentation/docs/providers/checkout.provider.md +315 -0
  31. package/documentation/docs/providers/identity.provider.md +194 -0
  32. package/documentation/docs/providers/inventory.provider.md +162 -0
  33. package/documentation/docs/providers/order-search.provider.md +155 -0
  34. package/documentation/docs/providers/order.provider.md +160 -0
  35. package/documentation/docs/providers/price.provider.md +197 -0
  36. package/documentation/docs/providers/product-search.provider.md +265 -0
  37. package/documentation/docs/providers/product.provider.md +204 -0
  38. package/documentation/docs/providers/profile.provider.md +283 -0
  39. package/documentation/docs/providers/store.provider.md +146 -0
  40. package/documentation/docs/schemas/schemas.md +1862 -0
  41. package/documentation/docusaurus.config.js +33 -0
  42. package/documentation/scripts/generate.ts +52 -0
  43. package/documentation/sidebars.js +8 -0
  44. package/documentation/src/css/custom.css +3 -0
  45. package/documentation/src/pages/index.js +12 -0
  46. package/eslint.config.mjs +1 -1
  47. package/examples/node/package.json +6 -6
  48. package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +0 -2
  49. package/examples/node/src/basic/client-creation.spec.ts +2 -2
  50. package/package.json +19 -5
  51. package/providers/algolia/README.md +12 -4
  52. package/providers/algolia/project.json +1 -1
  53. package/providers/algolia/src/core/initialize.ts +7 -2
  54. package/providers/algolia/src/providers/analytics.provider.ts +114 -0
  55. package/providers/algolia/src/providers/index.ts +1 -0
  56. package/providers/algolia/src/providers/product-search.provider.ts +5 -4
  57. package/providers/algolia/src/test/analytics.spec.ts +138 -0
  58. package/providers/commercetools/project.json +1 -1
  59. package/providers/commercetools/src/providers/identity.provider.ts +8 -1
  60. package/providers/commercetools/src/providers/profile.provider.ts +1 -4
  61. package/providers/commercetools/src/test/caching.spec.ts +3 -3
  62. package/providers/commercetools/src/test/identity.spec.ts +2 -2
  63. package/providers/fake/project.json +1 -1
  64. package/providers/fake/src/providers/analytics.provider.ts +5 -0
  65. package/providers/fake/src/providers/checkout.provider.ts +5 -2
  66. package/providers/fake/src/providers/product.provider.ts +18 -8
  67. package/providers/fake/src/test/cart.provider.spec.ts +0 -2
  68. package/providers/fake/src/test/category.provider.spec.ts +3 -3
  69. package/providers/fake/src/test/checkout.provider.spec.ts +3 -7
  70. package/providers/google-analytics/README.md +11 -0
  71. package/providers/google-analytics/eslint.config.mjs +25 -0
  72. package/providers/google-analytics/package.json +12 -0
  73. package/providers/google-analytics/project.json +33 -0
  74. package/providers/google-analytics/src/core/initialize.ts +16 -0
  75. package/providers/google-analytics/src/index.ts +4 -0
  76. package/providers/google-analytics/src/providers/analytics.provider.ts +162 -0
  77. package/providers/google-analytics/src/schema/capabilities.schema.ts +10 -0
  78. package/providers/google-analytics/src/schema/configuration.schema.ts +9 -0
  79. package/providers/google-analytics/src/test/analytics.provider.spec.ts +93 -0
  80. package/providers/google-analytics/tsconfig.json +24 -0
  81. package/providers/google-analytics/tsconfig.lib.json +23 -0
  82. package/providers/google-analytics/tsconfig.spec.json +28 -0
  83. package/providers/google-analytics/vite.config.ts +26 -0
  84. package/providers/google-analytics/vitest.config.mts +21 -0
  85. package/providers/medusa/package.json +3 -10
  86. package/providers/medusa/project.json +1 -1
  87. package/providers/medusa/src/providers/identity.provider.ts +34 -10
  88. package/providers/medusa/src/providers/profile.provider.ts +5 -15
  89. package/providers/medusa/src/test/test-utils.ts +0 -1
  90. package/providers/medusa/tsconfig.json +3 -0
  91. package/providers/medusa/tsconfig.lib.json +16 -1
  92. package/providers/meilisearch/project.json +1 -1
  93. package/providers/posthog/project.json +1 -1
  94. package/tsconfig.base.json +4 -1
  95. package/.claude/settings.local.json +0 -28
  96. package/core/src/schemas/mutations/analytics.mutation.ts +0 -23
  97. package/providers/algolia/src/test/test-utils.ts +0 -31
  98. /package/documentation/{2-getting-started.md → docs/2-getting-started.md} +0 -0
  99. /package/documentation/{3-querying-and-changing-data.md → docs/3-querying-and-changing-data.md} +0 -0
  100. /package/documentation/{4-product-data.md → docs/4-product-data.md} +0 -0
  101. /package/documentation/{5-cart-and-checkout.md → docs/5-cart-and-checkout.md} +0 -0
  102. /package/documentation/{6-product-search.md → docs/6-product-search.md} +0 -0
  103. /package/documentation/{7-marketing.md → docs/7-marketing.md} +0 -0
@@ -0,0 +1,28 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "types": [
6
+ "vitest/globals",
7
+ "vitest/importMeta",
8
+ "vite/client",
9
+ "node",
10
+ "vitest"
11
+ ]
12
+ },
13
+ "include": [
14
+ "vite.config.ts",
15
+ "vite.config.mts",
16
+ "vitest.config.ts",
17
+ "vitest.config.mts",
18
+ "src/**/*.test.ts",
19
+ "src/**/*.spec.ts",
20
+ "src/**/*.test.tsx",
21
+ "src/**/*.spec.tsx",
22
+ "src/**/*.test.js",
23
+ "src/**/*.spec.js",
24
+ "src/**/*.test.jsx",
25
+ "src/**/*.spec.jsx",
26
+ "src/**/*.d.ts"
27
+ ]
28
+ }
@@ -0,0 +1,26 @@
1
+ /// <reference types='vitest' />
2
+ import { defineConfig } from 'vite';
3
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
4
+ import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
5
+
6
+ export default defineConfig(() => ({
7
+ root: import.meta.dirname,
8
+ cacheDir: '../../node_modules/.vite/providers/google-analytics',
9
+ plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
10
+ // Uncomment this if you are using workers.
11
+ // worker: {
12
+ // plugins: () => [ nxViteTsPaths() ],
13
+ // },
14
+ test: {
15
+ name: 'google-analytics',
16
+ watch: false,
17
+ globals: true,
18
+ environment: 'node',
19
+ include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
20
+ reporters: ['default'],
21
+ coverage: {
22
+ reportsDirectory: '../../coverage/providers/google-analytics',
23
+ provider: 'v8' as const,
24
+ },
25
+ },
26
+ }));
@@ -0,0 +1,21 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
3
+ import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
4
+
5
+ export default defineConfig(() => ({
6
+ root: __dirname,
7
+ cacheDir: '../../node_modules/.vite/providers/google-analytics',
8
+ plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
9
+ test: {
10
+ name: 'google-analytics',
11
+ watch: false,
12
+ globals: true,
13
+ environment: 'node',
14
+ include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
15
+ reporters: ['default'],
16
+ coverage: {
17
+ reportsDirectory: '../../coverage/providers/google-analytics',
18
+ provider: 'v8' as const,
19
+ },
20
+ },
21
+ }));
@@ -5,18 +5,11 @@
5
5
  "main": "index.js",
6
6
  "types": "src/index.d.ts",
7
7
  "dependencies": {
8
- "zod": "4.1.9",
8
+ "@medusajs/js-sdk": "^2.13.0",
9
9
  "@reactionary/core": "0.0.1",
10
- "@medusajs/js-sdk": "^2.0.0",
11
- "debug": "^4.3.4",
10
+ "debug": "^4.4.3",
12
11
  "@medusajs/types": "^2.11.0",
13
- "dotenv": "^17.2.2"
14
- },
15
- "devDependencies": {
16
- "vitest": "*",
17
- "@vitest/ui": "*",
18
- "@vitest/coverage-v8": "*",
19
- "vite-tsconfig-paths": "*"
12
+ "zod": "4.1.9"
20
13
  },
21
14
  "sideEffects": false
22
15
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "provider-medusa",
2
+ "name": "medusa",
3
3
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
4
  "sourceRoot": "providers/medusa/src",
5
5
  "projectType": "library",
@@ -19,7 +19,6 @@ import {
19
19
  success,
20
20
  } from '@reactionary/core';
21
21
  import type { MedusaConfiguration } from '../schema/configuration.schema.js';
22
- import type z from 'zod';
23
22
  import type { MedusaAPI } from '../core/client.js';
24
23
  import createDebug from 'debug';
25
24
 
@@ -60,7 +59,10 @@ export class MedusaIdentityProvider extends IdentityProvider {
60
59
 
61
60
  if (!token) {
62
61
  debug('No active session token found, returning anonymous identity');
63
- return success(this.createAnonymousIdentity());
62
+ const identity = this.createAnonymousIdentity();
63
+ this.updateIdentityContext(identity);
64
+
65
+ return success(identity);
64
66
  }
65
67
 
66
68
  // Try to fetch customer details to verify authentication
@@ -68,18 +70,30 @@ export class MedusaIdentityProvider extends IdentityProvider {
68
70
 
69
71
  if (customerResponse.customer) {
70
72
  debug('Customer authenticated:', customerResponse.customer.email);
71
- return success({
73
+
74
+ const identity = {
72
75
  id: {
73
76
  userId: customerResponse.customer.id,
74
77
  },
75
78
  type: 'Registered',
76
- } satisfies RegisteredIdentity);
79
+ } satisfies RegisteredIdentity;
80
+
81
+ this.updateIdentityContext(identity);
82
+
83
+ return success(identity);
77
84
  }
78
85
 
79
- return success(this.createAnonymousIdentity());
86
+ const identity = this.createAnonymousIdentity();
87
+ this.updateIdentityContext(identity);
88
+
89
+ return success(identity);
80
90
  } catch (error) {
81
91
  debug('getSelf failed, returning anonymous identity:', error);
82
- return success(this.createAnonymousIdentity());
92
+
93
+ const identity = this.createAnonymousIdentity();
94
+ this.updateIdentityContext(identity);
95
+
96
+ return success(identity);
83
97
  }
84
98
  }
85
99
 
@@ -87,13 +101,17 @@ export class MedusaIdentityProvider extends IdentityProvider {
87
101
  inputSchema: IdentityMutationLoginSchema,
88
102
  outputSchema: IdentitySchema,
89
103
  })
90
- public override async login(payload: IdentityMutationLogin): Promise<Result<Identity>> {
104
+ public override async login(
105
+ payload: IdentityMutationLogin
106
+ ): Promise<Result<Identity>> {
91
107
  debug('Attempting login for user:', payload.username);
92
- const identity = await this.medusaApi.login(
108
+ const identity = (await this.medusaApi.login(
93
109
  payload.username,
94
110
  payload.password,
95
111
  this.context
96
- ) satisfies Identity;
112
+ )) satisfies Identity;
113
+
114
+ this.updateIdentityContext(identity);
97
115
 
98
116
  return success(identity);
99
117
  }
@@ -102,10 +120,14 @@ export class MedusaIdentityProvider extends IdentityProvider {
102
120
  inputSchema: IdentityMutationLogoutSchema,
103
121
  outputSchema: IdentitySchema,
104
122
  })
105
- public override async logout(_payload: IdentityMutationLogout): Promise<Result<Identity>> {
123
+ public override async logout(
124
+ _payload: IdentityMutationLogout
125
+ ): Promise<Result<Identity>> {
106
126
  debug('Logging out user');
107
127
  const identity = await this.medusaApi.logout(this.context);
108
128
 
129
+ this.updateIdentityContext(identity);
130
+
109
131
  return success(identity);
110
132
  }
111
133
 
@@ -132,6 +154,8 @@ export class MedusaIdentityProvider extends IdentityProvider {
132
154
  this.context
133
155
  );
134
156
 
157
+ this.updateIdentityContext(identity);
158
+
135
159
  return success(identity);
136
160
  }
137
161
  }
@@ -129,9 +129,7 @@ export class MedusaProfileProvider extends ProfileProvider {
129
129
  if (existingAddress) {
130
130
  return error<InvalidInputError>({
131
131
  type: 'InvalidInput',
132
- error: {
133
- message: 'Address with the same nickname already exists',
134
- }
132
+ error: 'Address with the same nickname already exists'
135
133
  });
136
134
  }
137
135
 
@@ -139,9 +137,7 @@ export class MedusaProfileProvider extends ProfileProvider {
139
137
  if (!response.customer) {
140
138
  return error<InvalidInputError>({
141
139
  type: 'InvalidInput',
142
- error: {
143
- message: 'Failed to add shipping address',
144
- }
140
+ error: 'Failed to add shipping address'
145
141
  });
146
142
  }
147
143
 
@@ -180,9 +176,7 @@ export class MedusaProfileProvider extends ProfileProvider {
180
176
  if (!response.customer) {
181
177
  return error<InvalidInputError>({
182
178
  type: 'InvalidInput',
183
- error: {
184
- message: 'Failed to add shipping address',
185
- }
179
+ error: 'Failed to add shipping address'
186
180
  })
187
181
  }
188
182
 
@@ -221,9 +215,7 @@ export class MedusaProfileProvider extends ProfileProvider {
221
215
  if (!response.deleted) {
222
216
  return error<InvalidInputError>({
223
217
  type: 'InvalidInput',
224
- error: {
225
- message: 'Failed to delete shipping address',
226
- }
218
+ error: 'Failed to delete shipping address'
227
219
  });
228
220
  }
229
221
 
@@ -292,9 +284,7 @@ export class MedusaProfileProvider extends ProfileProvider {
292
284
  if (existingAddressWithNickname && !existingAddressWithNickname.is_default_billing) {
293
285
  return error<InvalidInputError>({
294
286
  type: 'InvalidInput',
295
- error: {
296
- message: 'Another address with the same nickname already exists',
297
- }
287
+ error: 'Another address with the same nickname already exists'
298
288
  });
299
289
  }
300
290
 
@@ -1,4 +1,3 @@
1
- import 'dotenv/config';
2
1
 
3
2
  import { MedusaConfigurationSchema, type MedusaConfiguration } from '../schema/configuration.schema.js';
4
3
 
@@ -16,6 +16,9 @@
16
16
  "references": [
17
17
  {
18
18
  "path": "./tsconfig.lib.json"
19
+ },
20
+ {
21
+ "path": "./tsconfig.spec.json"
19
22
  }
20
23
  ]
21
24
  }
@@ -5,5 +5,20 @@
5
5
  "declaration": true,
6
6
  "types": ["node"]
7
7
  },
8
- "include": ["src/**/*.ts"]
8
+ "include": ["src/**/*.ts"],
9
+ "exclude": [
10
+ "vite.config.ts",
11
+ "vite.config.mts",
12
+ "vitest.config.ts",
13
+ "vitest.config.mts",
14
+ "src/**/*.test.ts",
15
+ "src/**/*.spec.ts",
16
+ "src/**/*.test.tsx",
17
+ "src/**/*.spec.tsx",
18
+ "src/**/*.test.js",
19
+ "src/**/*.spec.js",
20
+ "src/**/*.test.jsx",
21
+ "src/**/*.spec.jsx",
22
+ "src/test/**/*.ts"
23
+ ]
9
24
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "provider-meilisearch",
2
+ "name": "meilisearch",
3
3
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
4
  "sourceRoot": "providers/meilisearch/src",
5
5
  "projectType": "library",
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "provider-posthog",
2
+ "name": "posthog",
3
3
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
4
  "sourceRoot": "providers/posthog/src",
5
5
  "projectType": "library",
@@ -27,7 +27,10 @@
27
27
  "providers/commercetools/src/index.ts"
28
28
  ],
29
29
  "@reactionary/provider-fake": ["providers/fake/src/index.ts"],
30
- "@reactionary/provider-posthog": ["providers/posthog/src/index.ts"]
30
+ "@reactionary/provider-posthog": ["providers/posthog/src/index.ts"],
31
+ "@reactionary/google-analytics": [
32
+ "providers/google-analytics/src/index.ts"
33
+ ]
31
34
  },
32
35
  "verbatimModuleSyntax": true
33
36
  },
@@ -1,28 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npx nx build:*)",
5
- "Bash(npx tsc:*)",
6
- "Bash(npx nx lint:*)",
7
- "Bash(npx nx test:*)",
8
- "Bash(npx nx run:*)",
9
- "Bash(npx ts-node:*)",
10
- "Bash(npx tsx:*)",
11
- "Bash(grep:*)",
12
- "Bash(pnpm list:*)",
13
- "Bash(npx nx affected:build:*)",
14
- "Bash(npx nx affected:lint:*)",
15
- "Bash(cat:*)",
16
- "Bash(npx nx show projects:*)",
17
- "Bash(npx nx g:*)",
18
- "Bash(pnpm add:*)",
19
- "Bash(npx nx show project:*)",
20
- "Bash(npx nx reset:*)",
21
- "WebSearch",
22
- "Bash(node:*)",
23
- "Bash(npm view:*)"
24
- ],
25
- "deny": [],
26
- "ask": []
27
- }
28
- }
@@ -1,23 +0,0 @@
1
- import { z } from 'zod';
2
- import { BaseMutationSchema } from './base.mutation.js';
3
- import { ProductIdentifierSchema, ProductSearchIdentifierSchema } from '../models/identifiers.model.js';
4
- import type { InferType } from '../../zod-utils.js';
5
-
6
- export const AnalyticsMutationSearchEventSchema = BaseMutationSchema.extend({
7
- mutation: z.literal('search'),
8
- search: ProductSearchIdentifierSchema,
9
- products: z.array(ProductIdentifierSchema),
10
- });
11
-
12
- export const AnalyticsMutationSearchProductClickEventSchema = BaseMutationSchema.extend({
13
- mutation: z.literal('product-search-click'),
14
- search: ProductSearchIdentifierSchema,
15
- product: ProductIdentifierSchema,
16
- position: z.number().min(0)
17
- });
18
-
19
- export const AnalyticsMutationSchema = z.union([AnalyticsMutationSearchEventSchema, AnalyticsMutationSearchProductClickEventSchema]);
20
-
21
- export type AnalyticsMutation = InferType<typeof AnalyticsMutationSchema>;
22
- export type AnalyticsMutationSearchEvent = InferType<typeof AnalyticsMutationSearchEventSchema>;
23
- export type AnalyticsMutationSearchProductClickEvent = InferType<typeof AnalyticsMutationSearchProductClickEventSchema>;
@@ -1,31 +0,0 @@
1
- import type { Session } from "@reactionary/core";
2
-
3
- export function createAnonymousTestSession(): Session {
4
- return {
5
- id: 'test-session-id',
6
- identity: {
7
- type: 'Anonymous',
8
- meta: {
9
- cache: { hit: false, key: '' },
10
- placeholder: false,
11
- },
12
- id: { userId: 'anonymous' },
13
- token: undefined,
14
- issued: new Date(),
15
- expiry: new Date(new Date().getTime() + 3600 * 1000),
16
- logonId: "",
17
- createdAt: "",
18
- updatedAt: "",
19
- keyring: [],
20
- currentService: undefined
21
- },
22
- languageContext: {
23
- locale: 'en-US',
24
- currencyCode: 'USD',
25
- countryCode: 'US',
26
- },
27
- storeIdentifier: {
28
- key: 'the-good-store',
29
- },
30
- };
31
- }