@reactionary/source 0.0.38 → 0.0.40

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 (58) hide show
  1. package/core/package.json +2 -3
  2. package/core/src/index.ts +0 -2
  3. package/core/src/schemas/capabilities.schema.ts +1 -1
  4. package/core/src/schemas/models/base.model.ts +5 -5
  5. package/core/src/schemas/models/cart.model.ts +1 -1
  6. package/core/src/schemas/models/identifiers.model.ts +12 -12
  7. package/core/src/schemas/models/price.model.ts +1 -1
  8. package/core/src/schemas/models/product.model.ts +2 -2
  9. package/core/src/schemas/models/search.model.ts +3 -3
  10. package/core/src/schemas/mutations/base.mutation.ts +1 -1
  11. package/core/src/schemas/mutations/inventory.mutation.ts +0 -4
  12. package/core/src/schemas/mutations/price.mutation.ts +0 -4
  13. package/core/src/schemas/mutations/product.mutation.ts +0 -4
  14. package/core/src/schemas/mutations/search.mutation.ts +0 -4
  15. package/core/src/schemas/queries/analytics.query.ts +0 -4
  16. package/core/src/schemas/queries/base.query.ts +1 -1
  17. package/core/src/schemas/queries/cart.query.ts +0 -1
  18. package/core/src/schemas/queries/inventory.query.ts +0 -4
  19. package/examples/next/.swcrc +30 -0
  20. package/examples/next/eslint.config.mjs +21 -0
  21. package/examples/next/index.d.ts +6 -0
  22. package/examples/next/next-env.d.ts +5 -0
  23. package/examples/next/next.config.js +20 -0
  24. package/examples/next/project.json +9 -0
  25. package/examples/next/public/.gitkeep +0 -0
  26. package/examples/next/public/favicon.ico +0 -0
  27. package/examples/next/src/app/global.css +0 -0
  28. package/examples/next/src/app/layout.tsx +18 -0
  29. package/examples/next/src/app/page.module.scss +2 -0
  30. package/examples/next/src/app/page.tsx +51 -0
  31. package/examples/next/src/instrumentation.ts +9 -0
  32. package/examples/next/tsconfig.json +44 -0
  33. package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +0 -1
  34. package/examples/node/src/basic/basic-node-setup.spec.ts +0 -1
  35. package/otel/README.md +152 -172
  36. package/otel/package.json +0 -1
  37. package/otel/src/index.ts +16 -6
  38. package/otel/src/metrics.ts +3 -3
  39. package/otel/src/trace-decorator.ts +76 -97
  40. package/otel/src/tracer.ts +3 -3
  41. package/package.json +2 -2
  42. package/providers/algolia/package.json +1 -1
  43. package/providers/algolia/src/schema/configuration.schema.ts +1 -1
  44. package/providers/algolia/src/test/search.provider.spec.ts +2 -2
  45. package/providers/commercetools/package.json +1 -1
  46. package/providers/commercetools/src/schema/configuration.schema.ts +1 -1
  47. package/providers/fake/package.json +1 -1
  48. package/providers/fake/src/providers/cart.provider.ts +1 -1
  49. package/providers/fake/src/providers/search.provider.ts +11 -2
  50. package/providers/fake/src/schema/configuration.schema.ts +3 -3
  51. package/providers/fake/src/test/category.provider.spec.ts +1 -3
  52. package/providers/posthog/package.json +1 -1
  53. package/providers/posthog/src/schema/configuration.schema.ts +1 -1
  54. package/trpc/package.json +1 -2
  55. package/trpc/src/client.ts +1 -3
  56. package/tsconfig.base.json +2 -0
  57. package/core/src/decorators/trpc.decorators.ts +0 -144
  58. package/otel/src/sdk.ts +0 -57
package/core/package.json CHANGED
@@ -4,8 +4,7 @@
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "zod": "4.0.0-beta.20250430T185432",
8
- "@upstash/redis": "^1.34.9",
9
- "reflect-metadata": "0.2.2"
7
+ "zod": "4.1.9",
8
+ "@upstash/redis": "^1.34.9"
10
9
  }
11
10
  }
package/core/src/index.ts CHANGED
@@ -6,8 +6,6 @@ export * from './cache/noop-cache';
6
6
  export * from './client/client';
7
7
  export * from './client/client-builder';
8
8
 
9
- export * from './decorators/trpc.decorators';
10
-
11
9
  export * from './providers/analytics.provider';
12
10
  export * from './providers/base.provider';
13
11
  export * from './providers/cart.provider';
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- export const CapabilitiesSchema = z.looseInterface({
3
+ export const CapabilitiesSchema = z.looseObject({
4
4
  product: z.boolean(),
5
5
  search: z.boolean(),
6
6
  analytics: z.boolean(),
@@ -1,16 +1,16 @@
1
1
  import { z } from 'zod';
2
2
 
3
- export const CacheInformationSchema = z.looseInterface({
3
+ export const CacheInformationSchema = z.looseObject({
4
4
  hit: z.boolean().default(false),
5
5
  key: z.string().default('')
6
6
  })
7
7
 
8
- export const MetaSchema = z.looseInterface({
8
+ export const MetaSchema = z.looseObject({
9
9
  cache: CacheInformationSchema.default(() => CacheInformationSchema.parse({})),
10
10
  placeholder: z.boolean().default(false).describe('Whether or not the entity exists in a remote system, or is a default placeholder.')
11
11
  });
12
12
 
13
- export const BaseModelSchema = z.looseInterface({
13
+ export const BaseModelSchema = z.looseObject({
14
14
  meta: MetaSchema.default(() => MetaSchema.parse({}))
15
15
  });
16
16
 
@@ -19,7 +19,7 @@ export type Meta = z.infer<typeof MetaSchema>;
19
19
  export type BaseModel = z.infer<typeof BaseModelSchema>;
20
20
 
21
21
 
22
- export const PaginationOptionsSchema = z.looseInterface({
22
+ export const PaginationOptionsSchema = z.looseObject({
23
23
  pageNumber: z.number().default(1).describe('Current page number, starting from 1'),
24
24
  pageSize: z.number().default(20).describe('Number of items per page'),
25
25
  });
@@ -48,7 +48,7 @@ export function createPaginatedResponseSchema<ItemType extends z.ZodTypeAny>(
48
48
  * what we really need is the original source url, and then some metadata about the image.
49
49
  * Ie, rather than having distinct thumbnail and image fields, we just have a list of images, and the frontend will generate its own thumbnails as needed?
50
50
  */
51
- export const ImageSchema = z.looseInterface({
51
+ export const ImageSchema = z.looseObject({
52
52
  sourceUrl: z.string().default('').describe('The original source URL of the image. Pass this through your image resizing and transcoding service to get the desired size, and generate thumbnails as needed'),
53
53
  altText: z.string().default('').describe('Alternative text for the image, for accessibility purposes. Must always be set, and non-empty'),
54
54
  width: z.number().optional().describe('Width of the original image, in pixels, if known'),
@@ -22,7 +22,7 @@ export const ItemCostBreakdownSchema = z.looseObject({
22
22
 
23
23
  export type ItemCostBreakdown = z.infer<typeof ItemCostBreakdownSchema>;
24
24
 
25
- export const CartItemSchema = z.looseInterface({
25
+ export const CartItemSchema = z.looseObject({
26
26
  identifier: CartItemIdentifierSchema.default(() => CartItemIdentifierSchema.parse({})),
27
27
  product: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})),
28
28
  quantity: z.number().default(0),
@@ -1,57 +1,57 @@
1
1
  import { z } from 'zod';
2
2
 
3
- export const FacetIdentifierSchema = z.looseInterface({
3
+ export const FacetIdentifierSchema = z.looseObject({
4
4
  key: z.string().default('').nonoptional()
5
5
  });
6
6
 
7
- export const FacetValueIdentifierSchema = z.looseInterface({
7
+ export const FacetValueIdentifierSchema = z.looseObject({
8
8
  facet: FacetIdentifierSchema.default(() => FacetIdentifierSchema.parse({})),
9
9
  key: z.string().default('')
10
10
  });
11
11
 
12
- export const SKUIdentifierSchema = z.looseInterface({
12
+ export const SKUIdentifierSchema = z.looseObject({
13
13
  key: z.string().default('').nonoptional()
14
14
  });
15
15
 
16
- export const ProductIdentifierSchema = z.looseInterface({
16
+ export const ProductIdentifierSchema = z.looseObject({
17
17
  key: z.string().default(''),
18
18
  });
19
19
 
20
- export const SearchIdentifierSchema = z.looseInterface({
20
+ export const SearchIdentifierSchema = z.looseObject({
21
21
  term: z.string().default(''),
22
22
  page: z.number().default(0),
23
23
  pageSize: z.number().default(20),
24
24
  facets: z.array(FacetValueIdentifierSchema.required()).default(() => [])
25
25
  });
26
26
 
27
- export const CartIdentifierSchema = z.looseInterface({
27
+ export const CartIdentifierSchema = z.looseObject({
28
28
  key: z.string().default('')
29
29
  });
30
30
 
31
- export const CartItemIdentifierSchema = z.looseInterface({
31
+ export const CartItemIdentifierSchema = z.looseObject({
32
32
  key: z.string().default('')
33
33
  });
34
34
 
35
- export const PriceIdentifierSchema = z.looseInterface({
35
+ export const PriceIdentifierSchema = z.looseObject({
36
36
  sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
37
37
  });
38
38
 
39
- export const CategoryIdentifierSchema = z.looseInterface({
39
+ export const CategoryIdentifierSchema = z.looseObject({
40
40
  key: z.string().default('').nonoptional()
41
41
  });
42
42
 
43
43
  /**
44
44
  * The target store the user is interacting with. Can change over time, and is not necessarily the same as the default store.
45
45
  */
46
- export const WebStoreIdentifierSchema = z.looseInterface({
46
+ export const WebStoreIdentifierSchema = z.looseObject({
47
47
  key: z.string().default('').nonoptional()
48
48
  });
49
49
 
50
- export const InventoryChannelIdentifierSchema= z.looseInterface({
50
+ export const InventoryChannelIdentifierSchema= z.looseObject({
51
51
  key: z.string().default('online').nonoptional()
52
52
  });
53
53
 
54
- export const InventoryIdentifierSchema = z.looseInterface({
54
+ export const InventoryIdentifierSchema = z.looseObject({
55
55
  sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({})),
56
56
  channelId: InventoryChannelIdentifierSchema.default(() => InventoryChannelIdentifierSchema.parse({})),
57
57
  });
@@ -3,7 +3,7 @@ import { BaseModelSchema } from './base.model';
3
3
  import { PriceIdentifierSchema } from './identifiers.model';
4
4
  import { CurrencySchema } from './currency.model';
5
5
 
6
- export const MonetaryAmountSchema = z.looseInterface({
6
+ export const MonetaryAmountSchema = z.looseObject({
7
7
  value: z.number().default(0).describe('The monetary amount in decimal-precision.'),
8
8
  currency: CurrencySchema.default("XXX").describe('The currency associated with the amount, as a ISO 4217 standardized code.')
9
9
  });
@@ -2,11 +2,11 @@ import { z } from 'zod';
2
2
  import { ProductIdentifierSchema } from './identifiers.model';
3
3
  import { BaseModelSchema } from './base.model';
4
4
 
5
- export const SKUSchema = z.looseInterface({
5
+ export const SKUSchema = z.looseObject({
6
6
  identifier: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})),
7
7
  });
8
8
 
9
- export const ProductAttributeSchema = z.looseInterface({
9
+ export const ProductAttributeSchema = z.looseObject({
10
10
  id: z.string(),
11
11
  name: z.string(),
12
12
  value: z.string()
@@ -3,21 +3,21 @@ import { ProductIdentifierSchema, FacetValueIdentifierSchema, FacetIdentifierSch
3
3
  import { BaseModelSchema, createPaginatedResponseSchema } from './base.model';
4
4
  import { create } from 'domain';
5
5
 
6
- export const SearchResultProductSchema = z.looseInterface({
6
+ export const SearchResultProductSchema = z.looseObject({
7
7
  identifier: ProductIdentifierSchema.default(ProductIdentifierSchema.parse({})),
8
8
  name: z.string().default(''),
9
9
  image: z.string().url().default('https://placehold.co/400'),
10
10
  slug: z.string().default('')
11
11
  });
12
12
 
13
- export const SearchResultFacetValueSchema = z.looseInterface({
13
+ export const SearchResultFacetValueSchema = z.looseObject({
14
14
  identifier: FacetValueIdentifierSchema.default(() => FacetValueIdentifierSchema.parse({})),
15
15
  name: z.string().default(''),
16
16
  count: z.number().default(0),
17
17
  active: z.boolean().default(false)
18
18
  });
19
19
 
20
- export const SearchResultFacetSchema = z.looseInterface({
20
+ export const SearchResultFacetSchema = z.looseObject({
21
21
  identifier: FacetIdentifierSchema.default(() => FacetIdentifierSchema.parse({})),
22
22
  name: z.string().default(''),
23
23
  values: z.array(SearchResultFacetValueSchema).default(() => [])
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- export const BaseMutationSchema = z.looseInterface({
3
+ export const BaseMutationSchema = z.looseObject({
4
4
  });
5
5
 
6
6
  export type BaseMutation = z.infer<typeof BaseMutationSchema>;
@@ -1,5 +1 @@
1
1
  import { z } from 'zod';
2
-
3
- export const InventoryMutationSchema = z.union([]);
4
-
5
- export type InventoryMutation = z.infer<typeof InventoryMutationSchema>;
@@ -1,5 +1 @@
1
1
  import { z } from 'zod';
2
-
3
- export const PriceMutationSchema = z.union([]);
4
-
5
- export type PriceMutation = z.infer<typeof PriceMutationSchema>;
@@ -1,5 +1 @@
1
1
  import { z } from 'zod';
2
-
3
- export const ProductMutationSchema = z.union([]);
4
-
5
- export type ProductMutation = z.infer<typeof ProductMutationSchema>;
@@ -1,5 +1 @@
1
1
  import { z } from 'zod';
2
-
3
- export const SearchMutationSchema = z.union([]);
4
-
5
- export type SearchMutation = z.infer<typeof SearchMutationSchema>;
@@ -1,5 +1 @@
1
1
  import { z } from 'zod';
2
-
3
- export const AnalyticsQuerySchema = z.union([]);
4
-
5
- export type AnalyticsQuery = z.infer<typeof AnalyticsQuerySchema>;
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- export const BaseQuerySchema = z.looseInterface({
3
+ export const BaseQuerySchema = z.looseObject({
4
4
  });
5
5
 
6
6
  export type BaseQuery = z.infer<typeof BaseQuerySchema>;
@@ -5,6 +5,5 @@ import { CartIdentifierSchema } from '../models/identifiers.model';
5
5
  export const CartQueryByIdSchema = BaseQuerySchema.extend({
6
6
  cart: CartIdentifierSchema.required()
7
7
  });
8
- export const CartQuerySchema = z.union([CartQueryByIdSchema]);
9
8
 
10
9
  export type CartQueryById = z.infer<typeof CartQueryByIdSchema>;
@@ -7,10 +7,6 @@ export const InventoryQueryBySKUSchema = BaseQuerySchema.extend({
7
7
  sku: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})),
8
8
  });
9
9
 
10
- export const InventoryQuerySchema = z.union([InventoryQueryBySKUSchema]);
11
-
12
-
13
-
14
10
  //export type InventoryQuery = z.infer<typeof InventoryQuerySchema>;
15
11
  export type InventoryQueryBySKU = z.infer<typeof InventoryQueryBySKUSchema>;
16
12
 
@@ -0,0 +1,30 @@
1
+ {
2
+ "jsc": {
3
+ "target": "es2017",
4
+ "parser": {
5
+ "syntax": "typescript",
6
+ "decorators": true,
7
+ "dynamicImport": true
8
+ },
9
+ "transform": {
10
+ "decoratorMetadata": true,
11
+ "legacyDecorator": true
12
+ },
13
+ "keepClassNames": true,
14
+ "externalHelpers": true,
15
+ "loose": true
16
+ },
17
+ "module": {
18
+ "type": "commonjs"
19
+ },
20
+ "sourceMaps": true,
21
+ "exclude": [
22
+ "jest.config.ts",
23
+ ".*\\.spec.tsx?$",
24
+ ".*\\.test.tsx?$",
25
+ "./src/jest-setup.ts$",
26
+ "./**/jest-setup.ts$",
27
+ ".*.js$",
28
+ ".*.d.ts$"
29
+ ]
30
+ }
@@ -0,0 +1,21 @@
1
+ import { FlatCompat } from '@eslint/eslintrc';
2
+ import { dirname } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import js from '@eslint/js';
5
+ import { fixupConfigRules } from '@eslint/compat';
6
+ import nx from '@nx/eslint-plugin';
7
+ import baseConfig from '../../eslint.config.mjs';
8
+ const compat = new FlatCompat({
9
+ baseDirectory: dirname(fileURLToPath(import.meta.url)),
10
+ recommendedConfig: js.configs.recommended,
11
+ });
12
+
13
+ export default [
14
+ ...fixupConfigRules(compat.extends('next')),
15
+ ...fixupConfigRules(compat.extends('next/core-web-vitals')),
16
+ ...baseConfig,
17
+ ...nx.configs['flat/react-typescript'],
18
+ {
19
+ ignores: ['.next/**/*'],
20
+ },
21
+ ];
@@ -0,0 +1,6 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ declare module '*.svg' {
3
+ const content: any;
4
+ export const ReactComponent: any;
5
+ export default content;
6
+ }
@@ -0,0 +1,5 @@
1
+ /// <reference types="next" />
2
+ /// <reference types="next/image-types/global" />
3
+
4
+ // NOTE: This file should not be edited
5
+ // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
@@ -0,0 +1,20 @@
1
+ //@ts-check
2
+
3
+
4
+ const { composePlugins, withNx } = require('@nx/next');
5
+
6
+ /**
7
+ * @type {import('@nx/next/plugins/with-nx').WithNxOptions}
8
+ **/
9
+ const nextConfig = {
10
+ // Use this to set Nx-specific options
11
+ // See: https://nx.dev/recipes/next/next-config-setup
12
+ nx: {},
13
+ };
14
+
15
+ const plugins = [
16
+ // Add more Next.js plugins to this list if needed.
17
+ withNx,
18
+ ];
19
+
20
+ module.exports = composePlugins(...plugins)(nextConfig);
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "next",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "examples/next",
5
+ "projectType": "application",
6
+ "tags": [],
7
+ "// targets": "to see all targets run: nx show project next --web",
8
+ "targets": {}
9
+ }
File without changes
Binary file
File without changes
@@ -0,0 +1,18 @@
1
+ import './global.css';
2
+
3
+ export const metadata = {
4
+ title: 'Welcome to next',
5
+ description: 'Generated by create-nx-workspace',
6
+ };
7
+
8
+ export default function RootLayout({
9
+ children,
10
+ }: {
11
+ children: React.ReactNode;
12
+ }) {
13
+ return (
14
+ <html lang="en">
15
+ <body>{children}</body>
16
+ </html>
17
+ );
18
+ }
@@ -0,0 +1,2 @@
1
+ .page {
2
+ }
@@ -0,0 +1,51 @@
1
+ import styles from './page.module.scss';
2
+ import { ClientBuilder, NoOpCache, SessionSchema } from '@reactionary/core';
3
+ import { withFakeCapabilities } from '@reactionary/provider-fake';
4
+
5
+ export default async function Index() {
6
+ const client = new ClientBuilder()
7
+ .withCapability(
8
+ withFakeCapabilities(
9
+ {
10
+ jitter: {
11
+ mean: 0,
12
+ deviation: 0,
13
+ },
14
+ seeds: {
15
+ product: 1,
16
+ search: 1,
17
+ category: 1,
18
+ },
19
+ },
20
+ { search: true, product: false, identity: false }
21
+ )
22
+ )
23
+ .withCache(new NoOpCache())
24
+ .build();
25
+
26
+ const session = SessionSchema.parse({
27
+ id: '1234567890',
28
+ languageContext: {
29
+ countryCode: 'US',
30
+ languageCode: 'en',
31
+ currencyCode: 'USD',
32
+ },
33
+ });
34
+
35
+ const search = await client.search?.queryByTerm({
36
+ search: {
37
+ facets: [],
38
+ page: 0,
39
+ pageSize: 12,
40
+ term: 'glass',
41
+ },
42
+ }, session);
43
+
44
+ return <div className={styles.page}>
45
+ {search?.products.map((product, index) => (
46
+ <div key={index}>
47
+ { product.name }
48
+ </div>
49
+ ))}
50
+ </div>;
51
+ }
@@ -0,0 +1,9 @@
1
+ export async function register() {
2
+ if (process.env.NEXT_RUNTIME === 'nodejs') {
3
+ const { NodeSDK } = await import('@opentelemetry/sdk-node');
4
+
5
+ const sdk = new NodeSDK();
6
+
7
+ sdk.start();
8
+ }
9
+ }
@@ -0,0 +1,44 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "jsx": "preserve",
5
+ "strict": true,
6
+ "noEmit": true,
7
+ "emitDeclarationOnly": false,
8
+ "esModuleInterop": true,
9
+ "module": "esnext",
10
+ "moduleResolution": "bundler",
11
+ "resolveJsonModule": true,
12
+ "isolatedModules": true,
13
+ "lib": [
14
+ "dom",
15
+ "dom.iterable",
16
+ "esnext"
17
+ ],
18
+ "allowJs": true,
19
+ "allowSyntheticDefaultImports": true,
20
+ "forceConsistentCasingInFileNames": true,
21
+ "incremental": true,
22
+ "plugins": [
23
+ {
24
+ "name": "next"
25
+ }
26
+ ]
27
+ },
28
+ "include": [
29
+ "**/*.js",
30
+ "**/*.jsx",
31
+ "**/*.ts",
32
+ "**/*.tsx",
33
+ "../../dist/examples/next/.next/types/**/*.ts",
34
+ "../../examples/next/.next/types/**/*.ts",
35
+ "next-env.d.ts",
36
+ ".next/types/**/*.ts"
37
+ ],
38
+ "exclude": [
39
+ "node_modules",
40
+ "jest.config.ts",
41
+ "**/*.spec.ts",
42
+ "**/*.test.ts"
43
+ ]
44
+ }
@@ -68,7 +68,6 @@ describe('basic node provider extension (models)', () => {
68
68
  it('should get the enabled set of capabilities across providers', async () => {
69
69
  expect(client.product).toBeDefined();
70
70
  expect(client.search).toBeDefined();
71
- expect(client.identity).toBeUndefined();
72
71
  });
73
72
 
74
73
  it('should be able to call the regular methods and get the default value', async () => {
@@ -26,7 +26,6 @@ describe('basic node setup', () => {
26
26
  it('should only get back the enabled capabilities', async () => {
27
27
  expect(client.product).toBeDefined();
28
28
  expect(client.search).toBeDefined();
29
- expect(client.identity).toBeUndefined();
30
29
  });
31
30
 
32
31
  it('should be able to call the enabled capabilities', async () => {