@reactionary/source 0.0.51 → 0.2.15
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.
- package/.env-template +19 -0
- package/.github/workflows/pull-request.yml +3 -1
- package/.github/workflows/release.yml +9 -0
- package/.vscode/extensions.json +0 -2
- package/LICENSE +21 -0
- package/README.md +175 -23
- package/core/package.json +6 -2
- package/core/src/cache/cache.interface.ts +2 -1
- package/core/src/cache/index.ts +4 -0
- package/core/src/cache/memory-cache.ts +32 -4
- package/core/src/cache/noop-cache.ts +16 -2
- package/core/src/cache/redis-cache.ts +21 -1
- package/core/src/client/client-builder.ts +71 -54
- package/core/src/client/client.ts +17 -55
- package/core/src/client/index.ts +2 -0
- package/core/src/decorators/index.ts +1 -0
- package/core/src/decorators/reactionary.decorator.ts +210 -21
- package/core/src/index.ts +6 -19
- package/core/src/initialization.ts +2 -19
- package/core/src/metrics/metrics.ts +67 -0
- package/core/src/providers/analytics.provider.ts +2 -7
- package/core/src/providers/base.provider.ts +6 -70
- package/core/src/providers/cart.provider.ts +17 -57
- package/core/src/providers/category.provider.ts +9 -18
- package/core/src/providers/checkout.provider.ts +21 -19
- package/core/src/providers/identity.provider.ts +10 -12
- package/core/src/providers/index.ts +14 -13
- package/core/src/providers/inventory.provider.ts +18 -8
- package/core/src/providers/order-search.provider.ts +29 -0
- package/core/src/providers/order.provider.ts +47 -15
- package/core/src/providers/price.provider.ts +32 -38
- package/core/src/providers/product-search.provider.ts +61 -0
- package/core/src/providers/product.provider.ts +75 -16
- package/core/src/providers/profile.provider.ts +77 -17
- package/core/src/providers/store.provider.ts +6 -8
- package/core/src/schemas/capabilities.schema.ts +10 -3
- package/core/src/schemas/errors/generic.error.ts +9 -0
- package/core/src/schemas/errors/index.ts +4 -0
- package/core/src/schemas/errors/invalid-input.error.ts +9 -0
- package/core/src/schemas/errors/invalid-output.error.ts +9 -0
- package/core/src/schemas/errors/not-found.error.ts +9 -0
- package/core/src/schemas/index.ts +7 -0
- package/core/src/schemas/models/analytics.model.ts +3 -2
- package/core/src/schemas/models/base.model.ts +6 -24
- package/core/src/schemas/models/cart.model.ts +7 -16
- package/core/src/schemas/models/category.model.ts +6 -11
- package/core/src/schemas/models/checkout.model.ts +11 -14
- package/core/src/schemas/models/cost.model.ts +5 -4
- package/core/src/schemas/models/currency.model.ts +2 -1
- package/core/src/schemas/models/identifiers.model.ts +106 -62
- package/core/src/schemas/models/identity.model.ts +12 -21
- package/core/src/schemas/models/index.ts +20 -19
- package/core/src/schemas/models/inventory.model.ts +10 -7
- package/core/src/schemas/models/order-search.model.ts +28 -0
- package/core/src/schemas/models/order.model.ts +25 -32
- package/core/src/schemas/models/payment.model.ts +17 -20
- package/core/src/schemas/models/price.model.ts +14 -14
- package/core/src/schemas/models/product-search.model.ts +42 -0
- package/core/src/schemas/models/product.model.ts +64 -22
- package/core/src/schemas/models/profile.model.ts +21 -24
- package/core/src/schemas/models/shipping-method.model.ts +28 -33
- package/core/src/schemas/models/store.model.ts +10 -6
- package/core/src/schemas/mutations/analytics.mutation.ts +9 -8
- package/core/src/schemas/mutations/base.mutation.ts +2 -1
- package/core/src/schemas/mutations/cart.mutation.ts +37 -37
- package/core/src/schemas/mutations/checkout.mutation.ts +24 -31
- package/core/src/schemas/mutations/identity.mutation.ts +5 -4
- package/core/src/schemas/mutations/index.ts +10 -10
- package/core/src/schemas/mutations/profile.mutation.ts +39 -4
- package/core/src/schemas/queries/base.query.ts +2 -1
- package/core/src/schemas/queries/cart.query.ts +5 -5
- package/core/src/schemas/queries/category.query.ts +21 -21
- package/core/src/schemas/queries/checkout.query.ts +9 -11
- package/core/src/schemas/queries/identity.query.ts +3 -2
- package/core/src/schemas/queries/index.ts +14 -13
- package/core/src/schemas/queries/inventory.query.ts +6 -6
- package/core/src/schemas/queries/order-search.query.ts +10 -0
- package/core/src/schemas/queries/order.query.ts +5 -4
- package/core/src/schemas/queries/price.query.ts +11 -5
- package/core/src/schemas/queries/product-search.query.ts +16 -0
- package/core/src/schemas/queries/product.query.ts +14 -7
- package/core/src/schemas/queries/profile.query.ts +6 -3
- package/core/src/schemas/queries/store.query.ts +7 -6
- package/core/src/schemas/result.ts +107 -0
- package/core/src/schemas/session.schema.ts +6 -6
- package/core/src/test/reactionary.decorator.spec.ts +249 -0
- package/core/src/zod-utils.ts +19 -0
- package/core/tsconfig.json +3 -2
- package/core/tsconfig.spec.json +2 -26
- package/core/vitest.config.ts +14 -0
- package/documentation/1-purpose.md +114 -0
- package/documentation/2-getting-started.md +229 -0
- package/documentation/3-querying-and-changing-data.md +74 -0
- package/documentation/4-product-data.md +107 -0
- package/documentation/5-cart-and-checkout.md +211 -0
- package/documentation/6-product-search.md +143 -0
- package/documentation/7-marketing.md +3 -0
- package/eslint.config.mjs +1 -0
- package/examples/node/eslint.config.mjs +1 -4
- package/examples/node/package.json +11 -3
- package/examples/node/project.json +4 -1
- package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +22 -23
- package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +15 -11
- package/examples/node/src/basic/basic-node-setup.spec.ts +44 -28
- package/examples/node/src/basic/client-creation.spec.ts +53 -0
- package/examples/node/src/capabilities/cart.spec.ts +255 -0
- package/examples/node/src/capabilities/category.spec.ts +193 -0
- package/examples/node/src/capabilities/checkout.spec.ts +341 -0
- package/examples/node/src/capabilities/identity.spec.ts +93 -0
- package/examples/node/src/capabilities/inventory.spec.ts +66 -0
- package/examples/node/src/capabilities/order-search.spec.ts +159 -0
- package/examples/node/src/capabilities/order.spec.ts +91 -0
- package/examples/node/src/capabilities/price.spec.ts +51 -0
- package/examples/node/src/capabilities/product-search.spec.ts +293 -0
- package/examples/node/src/capabilities/product.spec.ts +122 -0
- package/examples/node/src/capabilities/profile.spec.ts +316 -0
- package/examples/node/src/capabilities/store.spec.ts +26 -0
- package/examples/node/src/utils.ts +137 -0
- package/examples/node/tsconfig.json +9 -11
- package/examples/node/tsconfig.lib.json +1 -2
- package/examples/node/tsconfig.spec.json +2 -13
- package/examples/node/vitest.config.ts +14 -0
- package/migrations.json +22 -5
- package/nx.json +8 -47
- package/package.json +24 -96
- package/providers/algolia/README.md +39 -2
- package/providers/algolia/package.json +3 -1
- package/providers/algolia/src/core/initialize.ts +9 -16
- package/providers/algolia/src/index.ts +4 -6
- package/providers/algolia/src/providers/index.ts +1 -0
- package/providers/algolia/src/providers/product-search.provider.ts +241 -0
- package/providers/algolia/src/schema/capabilities.schema.ts +2 -3
- package/providers/algolia/src/schema/index.ts +3 -0
- package/providers/algolia/src/schema/search.schema.ts +8 -8
- package/providers/algolia/tsconfig.json +2 -1
- package/providers/algolia/tsconfig.lib.json +1 -1
- package/providers/algolia/tsconfig.spec.json +2 -13
- package/providers/algolia/vitest.config.ts +14 -0
- package/providers/commercetools/README.md +30 -3
- package/providers/commercetools/package.json +3 -2
- package/providers/commercetools/src/core/client.ts +179 -100
- package/providers/commercetools/src/core/initialize.ts +131 -75
- package/providers/commercetools/src/core/token-cache.ts +45 -0
- package/providers/commercetools/src/index.ts +11 -10
- package/providers/commercetools/src/providers/cart.provider.ts +282 -356
- package/providers/commercetools/src/providers/category.provider.ts +223 -147
- package/providers/commercetools/src/providers/checkout.provider.ts +631 -449
- package/providers/commercetools/src/providers/identity.provider.ts +51 -30
- package/providers/commercetools/src/providers/index.ts +12 -12
- package/providers/commercetools/src/providers/inventory.provider.ts +77 -77
- package/providers/commercetools/src/providers/order-search.provider.ts +220 -0
- package/providers/commercetools/src/providers/order.provider.ts +97 -64
- package/providers/commercetools/src/providers/price.provider.ts +148 -118
- package/providers/commercetools/src/providers/product-search.provider.ts +528 -0
- package/providers/commercetools/src/providers/product.provider.ts +251 -81
- package/providers/commercetools/src/providers/profile.provider.ts +446 -29
- package/providers/commercetools/src/providers/store.provider.ts +56 -42
- package/providers/commercetools/src/schema/capabilities.schema.ts +3 -1
- package/providers/commercetools/src/schema/commercetools.schema.ts +17 -3
- package/providers/commercetools/src/schema/configuration.schema.ts +1 -0
- package/providers/commercetools/src/schema/session.schema.ts +7 -0
- package/providers/commercetools/src/test/caching.spec.ts +82 -0
- package/providers/commercetools/src/test/identity.spec.ts +109 -0
- package/providers/commercetools/src/test/test-utils.ts +21 -19
- package/providers/commercetools/tsconfig.json +2 -1
- package/providers/commercetools/tsconfig.lib.json +1 -1
- package/providers/commercetools/tsconfig.spec.json +2 -13
- package/providers/commercetools/vitest.config.ts +15 -0
- package/providers/fake/README.md +20 -4
- package/providers/fake/package.json +3 -2
- package/providers/fake/src/core/initialize.ts +52 -54
- package/providers/fake/src/index.ts +4 -4
- package/providers/fake/src/providers/analytics.provider.ts +6 -8
- package/providers/fake/src/providers/cart.provider.ts +165 -94
- package/providers/fake/src/providers/category.provider.ts +79 -51
- package/providers/fake/src/providers/checkout.provider.ts +254 -0
- package/providers/fake/src/providers/identity.provider.ts +58 -66
- package/providers/fake/src/providers/index.ts +13 -9
- package/providers/fake/src/providers/inventory.provider.ts +41 -37
- package/providers/fake/src/providers/order-search.provider.ts +78 -0
- package/providers/fake/src/providers/order.provider.ts +106 -0
- package/providers/fake/src/providers/price.provider.ts +94 -42
- package/providers/fake/src/providers/product-search.provider.ts +206 -0
- package/providers/fake/src/providers/product.provider.ts +57 -42
- package/providers/fake/src/providers/profile.provider.ts +147 -0
- package/providers/fake/src/providers/store.provider.ts +31 -22
- package/providers/fake/src/schema/capabilities.schema.ts +5 -1
- package/providers/fake/src/test/cart.provider.spec.ts +62 -83
- package/providers/fake/src/test/category.provider.spec.ts +147 -89
- package/providers/fake/src/test/checkout.provider.spec.ts +222 -0
- package/providers/fake/src/test/order-search.provider.spec.ts +50 -0
- package/providers/fake/src/test/order.provider.spec.ts +44 -0
- package/providers/fake/src/test/price.provider.spec.ts +52 -47
- package/providers/fake/src/test/product.provider.spec.ts +18 -10
- package/providers/fake/src/test/profile.provider.spec.ts +167 -0
- package/providers/fake/src/test/test-utils.ts +1 -1
- package/providers/fake/tsconfig.json +2 -1
- package/providers/fake/tsconfig.lib.json +1 -1
- package/providers/fake/tsconfig.spec.json +2 -14
- package/providers/fake/vitest.config.ts +14 -0
- package/providers/medusa/README.md +30 -0
- package/providers/medusa/TESTING.md +98 -0
- package/{trpc → providers/medusa}/eslint.config.mjs +1 -1
- package/providers/medusa/package.json +22 -0
- package/providers/medusa/project.json +34 -0
- package/providers/medusa/src/core/client.ts +370 -0
- package/providers/medusa/src/core/initialize.ts +78 -0
- package/providers/medusa/src/index.ts +13 -0
- package/providers/medusa/src/providers/cart.provider.ts +575 -0
- package/providers/medusa/src/providers/category.provider.ts +247 -0
- package/providers/medusa/src/providers/checkout.provider.ts +636 -0
- package/providers/medusa/src/providers/identity.provider.ts +137 -0
- package/providers/medusa/src/providers/inventory.provider.ts +173 -0
- package/providers/medusa/src/providers/order-search.provider.ts +201 -0
- package/providers/medusa/src/providers/order.provider.ts +226 -0
- package/providers/medusa/src/providers/price.provider.ts +140 -0
- package/providers/medusa/src/providers/product-search.provider.ts +243 -0
- package/providers/medusa/src/providers/product.provider.ts +261 -0
- package/providers/medusa/src/providers/profile.provider.ts +392 -0
- package/providers/medusa/src/schema/capabilities.schema.ts +18 -0
- package/providers/medusa/src/schema/configuration.schema.ts +11 -0
- package/providers/medusa/src/schema/medusa.schema.ts +31 -0
- package/providers/medusa/src/test/cart.provider.spec.ts +240 -0
- package/providers/medusa/src/test/category.provider.spec.ts +231 -0
- package/providers/medusa/src/test/checkout.spec.ts +349 -0
- package/providers/medusa/src/test/identity.provider.spec.ts +122 -0
- package/providers/medusa/src/test/inventory.provider.spec.ts +88 -0
- package/providers/medusa/src/test/large-cart.provider.spec.ts +103 -0
- package/providers/medusa/src/test/price.provider.spec.ts +104 -0
- package/providers/medusa/src/test/product.provider.spec.ts +146 -0
- package/providers/medusa/src/test/search.provider.spec.ts +203 -0
- package/providers/medusa/src/test/test-utils.ts +13 -0
- package/providers/medusa/src/utils/medusa-helpers.ts +89 -0
- package/providers/medusa/tsconfig.json +21 -0
- package/providers/medusa/tsconfig.lib.json +9 -0
- package/providers/medusa/tsconfig.spec.json +4 -0
- package/providers/medusa/vitest.config.ts +15 -0
- package/providers/meilisearch/README.md +48 -0
- package/{otel → providers/meilisearch}/eslint.config.mjs +1 -2
- package/providers/meilisearch/package.json +13 -0
- package/providers/meilisearch/project.json +34 -0
- package/providers/meilisearch/src/core/initialize.ts +16 -0
- package/providers/meilisearch/src/index.ts +5 -0
- package/providers/meilisearch/src/providers/index.ts +1 -0
- package/providers/meilisearch/src/providers/product-search.provider.ts +251 -0
- package/providers/meilisearch/src/schema/capabilities.schema.ts +9 -0
- package/providers/meilisearch/src/schema/configuration.schema.ts +10 -0
- package/providers/meilisearch/src/schema/index.ts +3 -0
- package/providers/meilisearch/src/schema/search.schema.ts +14 -0
- package/{otel → providers/meilisearch}/tsconfig.json +3 -2
- package/{trpc → providers/meilisearch}/tsconfig.lib.json +2 -2
- package/providers/meilisearch/tsconfig.spec.json +4 -0
- package/providers/meilisearch/vitest.config.ts +14 -0
- package/providers/posthog/package.json +5 -4
- package/providers/posthog/project.json +2 -2
- package/providers/posthog/src/core/initialize.ts +2 -2
- package/providers/posthog/src/index.ts +3 -3
- package/providers/posthog/tsconfig.json +2 -1
- package/tsconfig.base.json +7 -3
- package/vitest.config.ts +10 -0
- package/core/src/providers/search.provider.ts +0 -18
- package/core/src/schemas/models/search.model.ts +0 -37
- package/core/src/schemas/queries/search.query.ts +0 -9
- package/examples/next/.swcrc +0 -30
- package/examples/next/eslint.config.mjs +0 -21
- package/examples/next/index.d.ts +0 -6
- package/examples/next/next-env.d.ts +0 -5
- package/examples/next/next.config.js +0 -20
- package/examples/next/project.json +0 -9
- package/examples/next/public/.gitkeep +0 -0
- package/examples/next/public/favicon.ico +0 -0
- package/examples/next/src/app/global.css +0 -0
- package/examples/next/src/app/layout.tsx +0 -18
- package/examples/next/src/app/page.module.scss +0 -2
- package/examples/next/src/app/page.tsx +0 -48
- package/examples/next/src/instrumentation.ts +0 -9
- package/examples/next/tsconfig.json +0 -44
- package/examples/node/jest.config.ts +0 -10
- package/jest.config.ts +0 -6
- package/jest.preset.js +0 -3
- package/otel/README.md +0 -227
- package/otel/package.json +0 -11
- package/otel/pnpm-lock.yaml +0 -805
- package/otel/project.json +0 -33
- package/otel/src/index.ts +0 -22
- package/otel/src/metrics.ts +0 -76
- package/otel/src/provider-instrumentation.ts +0 -108
- package/otel/src/test/otel.spec.ts +0 -8
- package/otel/src/trace-decorator.ts +0 -226
- package/otel/src/tracer.ts +0 -83
- package/otel/src/trpc-middleware.ts +0 -128
- package/otel/tsconfig.lib.json +0 -23
- package/otel/tsconfig.spec.json +0 -28
- package/otel/vite.config.ts +0 -24
- package/providers/algolia/jest.config.ts +0 -10
- package/providers/algolia/src/providers/product.provider.ts +0 -66
- package/providers/algolia/src/providers/search.provider.ts +0 -106
- package/providers/algolia/src/test/search.provider.spec.ts +0 -91
- package/providers/commercetools/jest.config.ts +0 -10
- package/providers/commercetools/src/providers/search.provider.ts +0 -98
- package/providers/commercetools/src/test/cart.provider.spec.ts +0 -199
- package/providers/commercetools/src/test/category.provider.spec.ts +0 -168
- package/providers/commercetools/src/test/checkout.provider.spec.ts +0 -312
- package/providers/commercetools/src/test/identity.provider.spec.ts +0 -88
- package/providers/commercetools/src/test/inventory.provider.spec.ts +0 -41
- package/providers/commercetools/src/test/price.provider.spec.ts +0 -81
- package/providers/commercetools/src/test/product.provider.spec.ts +0 -80
- package/providers/commercetools/src/test/profile.provider.spec.ts +0 -49
- package/providers/commercetools/src/test/search.provider.spec.ts +0 -61
- package/providers/commercetools/src/test/store.provider.spec.ts +0 -37
- package/providers/fake/jest.config.ts +0 -10
- package/providers/fake/src/providers/search.provider.ts +0 -135
- package/trpc/README.md +0 -7
- package/trpc/__mocks__/superjson.js +0 -25
- package/trpc/jest.config.ts +0 -14
- package/trpc/package.json +0 -14
- package/trpc/project.json +0 -31
- package/trpc/src/client.ts +0 -175
- package/trpc/src/index.ts +0 -44
- package/trpc/src/integration.spec.ts +0 -223
- package/trpc/src/server.ts +0 -125
- package/trpc/src/transparent-client.spec.ts +0 -161
- package/trpc/src/types.ts +0 -144
- package/trpc/tsconfig.json +0 -16
- package/trpc/tsconfig.spec.json +0 -15
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
2
|
-
import type { RequestContext} from '@reactionary/core';
|
|
3
|
-
import { NoOpCache, ProductSchema, Session, createInitialRequestContext } from '@reactionary/core';
|
|
4
|
-
import { CommercetoolsProductProvider } from '../providers/product.provider';
|
|
5
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
6
|
-
|
|
7
|
-
const testData = {
|
|
8
|
-
product : {
|
|
9
|
-
id: '4d28f98d-c446-446e-b59a-d9f718e5b98a',
|
|
10
|
-
name: 'Sunnai Glass Bowl',
|
|
11
|
-
image: 'https://storage.googleapis.com/merchant-center-europe/sample-data/goodstore/Sunnai_Glass_Bowl-1.1.jpeg',
|
|
12
|
-
sku: 'SGB-01',
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
describe('Commercetools Product Provider', () => {
|
|
19
|
-
|
|
20
|
-
let provider: CommercetoolsProductProvider;
|
|
21
|
-
let reqCtx: RequestContext;
|
|
22
|
-
|
|
23
|
-
beforeAll( () => {
|
|
24
|
-
provider = new CommercetoolsProductProvider(getCommercetoolsTestConfiguration(), ProductSchema, new NoOpCache());
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
beforeEach( () => {
|
|
28
|
-
reqCtx = createInitialRequestContext()
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
it('should be able to get a product by id', async () => {
|
|
33
|
-
const result = await provider.getById( { id: testData.product.id }, reqCtx);
|
|
34
|
-
|
|
35
|
-
expect(result).toBeTruthy();
|
|
36
|
-
expect(result.identifier.key).toBe(testData.product.id);
|
|
37
|
-
expect(result.meta.placeholder).toBe(false);
|
|
38
|
-
expect(result.name).toBe(testData.product.name);
|
|
39
|
-
expect(result.image).toBe(testData.product.image);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should be able to get a product by slug', async () => {
|
|
43
|
-
const result = await provider.getBySlug( { slug: 'sunnai-glass-bowl' }, reqCtx);
|
|
44
|
-
|
|
45
|
-
expect(result).toBeTruthy();
|
|
46
|
-
if (result) {
|
|
47
|
-
expect(result.meta.placeholder).toBe(false);
|
|
48
|
-
expect(result.identifier.key).toBe(testData.product.id);
|
|
49
|
-
expect(result.name).toBe(testData.product.name);
|
|
50
|
-
expect(result.image).toBe(testData.product.image);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should be able to get a product by sku', async () => {
|
|
55
|
-
const result = await provider.getBySKU( { sku: { key: testData.product.sku } }, reqCtx);
|
|
56
|
-
|
|
57
|
-
expect(result).toBeTruthy();
|
|
58
|
-
if (result) {
|
|
59
|
-
expect(result.meta.placeholder).toBe(false);
|
|
60
|
-
expect(result.identifier.key).toBe(testData.product.id);
|
|
61
|
-
expect(result.name).toBe(testData.product.name);
|
|
62
|
-
expect(result.image).toBe(testData.product.image);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should return null for unknown slug', async () => {
|
|
67
|
-
const result = await provider.getBySlug( { slug: 'unknown-slug' }, reqCtx);
|
|
68
|
-
|
|
69
|
-
expect(result).toBeNull();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
it('should return a placeholder product for unknown id', async () => {
|
|
75
|
-
const result = await provider.getById( { id: 'unknown-id' }, reqCtx);
|
|
76
|
-
|
|
77
|
-
expect(result).toBeTruthy();
|
|
78
|
-
expect(result.meta.placeholder).toBe(true);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
2
|
-
import type { RequestContext } from '@reactionary/core';
|
|
3
|
-
import {
|
|
4
|
-
IdentitySchema,
|
|
5
|
-
NoOpCache,
|
|
6
|
-
ProfileSchema,
|
|
7
|
-
createInitialRequestContext,
|
|
8
|
-
} from '@reactionary/core';
|
|
9
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
10
|
-
import { CommercetoolsProfileProvider } from '../providers/profile.provider';
|
|
11
|
-
import { CommercetoolsIdentityProvider } from '../providers/identity.provider';
|
|
12
|
-
|
|
13
|
-
describe('Commercetools Profile Provider', () => {
|
|
14
|
-
let provider: CommercetoolsProfileProvider;
|
|
15
|
-
let identityProvider: CommercetoolsIdentityProvider;
|
|
16
|
-
let reqCtx: RequestContext;
|
|
17
|
-
|
|
18
|
-
beforeAll(() => {
|
|
19
|
-
provider = new CommercetoolsProfileProvider(
|
|
20
|
-
getCommercetoolsTestConfiguration(),
|
|
21
|
-
ProfileSchema,
|
|
22
|
-
new NoOpCache()
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
identityProvider = new CommercetoolsIdentityProvider(
|
|
26
|
-
getCommercetoolsTestConfiguration(),
|
|
27
|
-
IdentitySchema,
|
|
28
|
-
new NoOpCache()
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
beforeEach(async () => {
|
|
33
|
-
reqCtx = createInitialRequestContext();
|
|
34
|
-
|
|
35
|
-
const time = new Date().getTime();
|
|
36
|
-
|
|
37
|
-
await identityProvider.register({
|
|
38
|
-
username: `martin.rogne+test-${ time }@solteq.com`,
|
|
39
|
-
password: 'love2test'
|
|
40
|
-
}, reqCtx);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should be able to fetch the profile for the current user', async () => {
|
|
44
|
-
const profile = await provider.getSelf({}, reqCtx);
|
|
45
|
-
|
|
46
|
-
expect(profile).toBeDefined();
|
|
47
|
-
expect(profile.email).toContain('martin.rogne');
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
2
|
-
import type { RequestContext} from '@reactionary/core';
|
|
3
|
-
import { NoOpCache, SearchResultSchema, createInitialRequestContext } from '@reactionary/core';
|
|
4
|
-
import { CommercetoolsSearchProvider } from '../providers/search.provider';
|
|
5
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
6
|
-
|
|
7
|
-
const testData = {
|
|
8
|
-
searchTerm: 'bowl'
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
describe('Commercetools Search Provider', () => {
|
|
12
|
-
|
|
13
|
-
let provider: CommercetoolsSearchProvider;
|
|
14
|
-
let reqCtx: RequestContext;
|
|
15
|
-
|
|
16
|
-
beforeAll( () => {
|
|
17
|
-
provider = new CommercetoolsSearchProvider(getCommercetoolsTestConfiguration(), SearchResultSchema, new NoOpCache());
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
beforeEach( () => {
|
|
21
|
-
reqCtx = createInitialRequestContext()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('should be able to get a result by term', async () => {
|
|
25
|
-
const result = await provider.queryByTerm( {
|
|
26
|
-
search: {
|
|
27
|
-
term: testData.searchTerm,
|
|
28
|
-
facets: [],
|
|
29
|
-
page: 1,
|
|
30
|
-
pageSize: 10,
|
|
31
|
-
}}, reqCtx);
|
|
32
|
-
|
|
33
|
-
expect(result.products.length).toBeGreaterThan(0);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
it('should be able to get a result by term, paged', async () => {
|
|
38
|
-
const result = await provider.queryByTerm( {
|
|
39
|
-
search: {
|
|
40
|
-
term: testData.searchTerm,
|
|
41
|
-
facets: [],
|
|
42
|
-
page: 1,
|
|
43
|
-
pageSize: 1,
|
|
44
|
-
}}, reqCtx);
|
|
45
|
-
|
|
46
|
-
expect(result.products.length).toBeGreaterThan(0);
|
|
47
|
-
expect(result.pages).toBeGreaterThan(1);
|
|
48
|
-
|
|
49
|
-
const result2 = await provider.queryByTerm( {
|
|
50
|
-
search: {
|
|
51
|
-
term: testData.searchTerm,
|
|
52
|
-
facets: [],
|
|
53
|
-
page: 2,
|
|
54
|
-
pageSize: 1,
|
|
55
|
-
}}, reqCtx);
|
|
56
|
-
|
|
57
|
-
expect(result2.products.length).toBeGreaterThan(0);
|
|
58
|
-
expect(result2.pages).toBeGreaterThan(2);
|
|
59
|
-
expect(result2.products[0].identifier.key).not.toBe(result.products[0].identifier.key);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
2
|
-
import type { RequestContext } from '@reactionary/core';
|
|
3
|
-
import {
|
|
4
|
-
NoOpCache,
|
|
5
|
-
StoreSchema,
|
|
6
|
-
createInitialRequestContext,
|
|
7
|
-
} from '@reactionary/core';
|
|
8
|
-
import { getCommercetoolsTestConfiguration } from './test-utils';
|
|
9
|
-
import { CommercetoolsStoreProvider } from '../providers/store.provider';
|
|
10
|
-
|
|
11
|
-
describe('Commercetools Store Provider', () => {
|
|
12
|
-
let provider: CommercetoolsStoreProvider;
|
|
13
|
-
let reqCtx: RequestContext;
|
|
14
|
-
|
|
15
|
-
beforeAll(() => {
|
|
16
|
-
provider = new CommercetoolsStoreProvider(
|
|
17
|
-
getCommercetoolsTestConfiguration(),
|
|
18
|
-
StoreSchema,
|
|
19
|
-
new NoOpCache()
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
reqCtx = createInitialRequestContext();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should be able to query stores by longitude and latitude', async () => {
|
|
28
|
-
const stores = await provider.queryByProximity({
|
|
29
|
-
distance: 1000,
|
|
30
|
-
latitude: 15,
|
|
31
|
-
longitude: 15,
|
|
32
|
-
limit: 10
|
|
33
|
-
}, reqCtx);
|
|
34
|
-
|
|
35
|
-
expect(stores.length).toBe(2);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
displayName: 'provider-faker',
|
|
3
|
-
preset: '../../jest.preset.js',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
transform: {
|
|
6
|
-
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
|
7
|
-
},
|
|
8
|
-
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
9
|
-
coverageDirectory: '../../coverage/providers/fake',
|
|
10
|
-
};
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SearchProvider
|
|
3
|
-
} from '@reactionary/core';
|
|
4
|
-
import type {
|
|
5
|
-
SearchResult,
|
|
6
|
-
SearchResultFacet,
|
|
7
|
-
SearchResultProduct,
|
|
8
|
-
Cache as ReactionaryCache,
|
|
9
|
-
} from '@reactionary/core';
|
|
10
|
-
import type { RequestContext, SearchQueryByTerm } from '@reactionary/core';
|
|
11
|
-
import type z from 'zod';
|
|
12
|
-
import type { FakeConfiguration } from '../schema/configuration.schema';
|
|
13
|
-
import { Faker, en, base } from '@faker-js/faker';
|
|
14
|
-
import { jitter } from '../utilities/jitter';
|
|
15
|
-
import { traced } from '@reactionary/otel';
|
|
16
|
-
|
|
17
|
-
export class FakeSearchProvider<
|
|
18
|
-
T extends SearchResult = SearchResult
|
|
19
|
-
> extends SearchProvider<T> {
|
|
20
|
-
protected config: FakeConfiguration;
|
|
21
|
-
|
|
22
|
-
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: ReactionaryCache) {
|
|
23
|
-
super(schema, cache);
|
|
24
|
-
|
|
25
|
-
this.config = config;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@traced()
|
|
29
|
-
public override async queryByTerm(
|
|
30
|
-
payload: SearchQueryByTerm,
|
|
31
|
-
_reqCtx: RequestContext
|
|
32
|
-
): Promise<SearchResult> {
|
|
33
|
-
await jitter(this.config.jitter.mean, this.config.jitter.deviation);
|
|
34
|
-
|
|
35
|
-
const query = payload.search;
|
|
36
|
-
|
|
37
|
-
const querySpecificity =
|
|
38
|
-
20 - query.term.length - query.page - query.facets.length;
|
|
39
|
-
const totalProducts = 10 * querySpecificity;
|
|
40
|
-
const totalPages = Math.ceil(totalProducts / query.pageSize);
|
|
41
|
-
const productsOnPage = Math.min(totalProducts, query.pageSize);
|
|
42
|
-
|
|
43
|
-
const productGenerator = new Faker({
|
|
44
|
-
seed: querySpecificity,
|
|
45
|
-
locale: [en, base],
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const facetGenerator = new Faker({
|
|
49
|
-
seed: 100,
|
|
50
|
-
locale: [en, base],
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const products = new Array<SearchResultProduct>();
|
|
54
|
-
const facets = new Array<SearchResultFacet>();
|
|
55
|
-
|
|
56
|
-
for (let i = 0; i < productsOnPage; i++) {
|
|
57
|
-
products.push({
|
|
58
|
-
identifier: {
|
|
59
|
-
key: productGenerator.commerce.isbn(),
|
|
60
|
-
},
|
|
61
|
-
image: productGenerator.image.urlPicsumPhotos({
|
|
62
|
-
height: 300,
|
|
63
|
-
width: 300,
|
|
64
|
-
grayscale: true,
|
|
65
|
-
blur: 8,
|
|
66
|
-
}),
|
|
67
|
-
name: productGenerator.commerce.productName(),
|
|
68
|
-
slug: productGenerator.lorem.slug(),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const facetBase = ['color', 'size'];
|
|
73
|
-
|
|
74
|
-
for (const base of facetBase) {
|
|
75
|
-
const facet: SearchResultFacet = {
|
|
76
|
-
identifier: {
|
|
77
|
-
key: base,
|
|
78
|
-
},
|
|
79
|
-
name: base,
|
|
80
|
-
values: [],
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
for (let i = 0; i < 10; i++) {
|
|
84
|
-
const valueKey = i.toString();
|
|
85
|
-
const isActive =
|
|
86
|
-
query.facets.find(
|
|
87
|
-
(x) => x.facet.key === facet.identifier.key && x.key === valueKey
|
|
88
|
-
) !== undefined;
|
|
89
|
-
|
|
90
|
-
facet.values.push({
|
|
91
|
-
active: isActive,
|
|
92
|
-
count: facetGenerator.number.int({ min: 1, max: 50 }),
|
|
93
|
-
identifier: {
|
|
94
|
-
facet: {
|
|
95
|
-
key: facet.identifier.key,
|
|
96
|
-
},
|
|
97
|
-
key: valueKey,
|
|
98
|
-
},
|
|
99
|
-
name: facetGenerator.color.human(),
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
facets.push(facet);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const result = {
|
|
107
|
-
pages: totalPages,
|
|
108
|
-
identifier: {
|
|
109
|
-
term: query.term,
|
|
110
|
-
page: query.page,
|
|
111
|
-
facets: query.facets,
|
|
112
|
-
pageSize: query.pageSize,
|
|
113
|
-
},
|
|
114
|
-
facets: facets,
|
|
115
|
-
products: products,
|
|
116
|
-
meta: {
|
|
117
|
-
cache: {
|
|
118
|
-
hit: false,
|
|
119
|
-
key: '',
|
|
120
|
-
},
|
|
121
|
-
placeholder: false,
|
|
122
|
-
},
|
|
123
|
-
} satisfies SearchResult;
|
|
124
|
-
|
|
125
|
-
const foo = this.childFunction();
|
|
126
|
-
|
|
127
|
-
return this.schema.parse(result);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
@traced()
|
|
131
|
-
protected childFunction() {
|
|
132
|
-
const foo = 42;
|
|
133
|
-
return foo;
|
|
134
|
-
}
|
|
135
|
-
}
|
package/trpc/README.md
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Mock superjson for Jest testing
|
|
2
|
-
module.exports = {
|
|
3
|
-
default: {
|
|
4
|
-
stringify: JSON.stringify,
|
|
5
|
-
parse: JSON.parse,
|
|
6
|
-
serialize: (obj) => ({ json: obj, meta: undefined }),
|
|
7
|
-
deserialize: (data) => data.json,
|
|
8
|
-
output: {
|
|
9
|
-
serialize: (obj) => ({ json: obj, meta: undefined })
|
|
10
|
-
},
|
|
11
|
-
input: {
|
|
12
|
-
deserialize: (data) => data.json
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
stringify: JSON.stringify,
|
|
16
|
-
parse: JSON.parse,
|
|
17
|
-
serialize: (obj) => ({ json: obj, meta: undefined }),
|
|
18
|
-
deserialize: (data) => data.json,
|
|
19
|
-
output: {
|
|
20
|
-
serialize: (obj) => ({ json: obj, meta: undefined })
|
|
21
|
-
},
|
|
22
|
-
input: {
|
|
23
|
-
deserialize: (data) => data.json
|
|
24
|
-
}
|
|
25
|
-
};
|
package/trpc/jest.config.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
displayName: 'trpc',
|
|
3
|
-
preset: '../jest.preset.js',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
testTimeout: 15000,
|
|
6
|
-
transform: {
|
|
7
|
-
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
|
8
|
-
},
|
|
9
|
-
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
10
|
-
moduleNameMapper: {
|
|
11
|
-
'^superjson$': '<rootDir>/__mocks__/superjson.js',
|
|
12
|
-
},
|
|
13
|
-
coverageDirectory: '../coverage/trpc',
|
|
14
|
-
};
|
package/trpc/package.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@reactionary/trpc",
|
|
3
|
-
"version": "0.0.1",
|
|
4
|
-
"type": "commonjs",
|
|
5
|
-
"main": "./src/index.js",
|
|
6
|
-
"types": "./src/index.d.ts",
|
|
7
|
-
"dependencies": {
|
|
8
|
-
"@trpc/server": "^11.1.2",
|
|
9
|
-
"@reactionary/core": "0.0.1",
|
|
10
|
-
"@reactionary/otel": "0.0.1",
|
|
11
|
-
"superjson": "^2.2.2",
|
|
12
|
-
"zod": "4.1.9"
|
|
13
|
-
}
|
|
14
|
-
}
|
package/trpc/project.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "trpc",
|
|
3
|
-
"$schema": "../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "trpc/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"release": {
|
|
7
|
-
"version": {
|
|
8
|
-
"manifestRootsToUpdate": ["dist/{projectRoot}"],
|
|
9
|
-
"currentVersionResolver": "git-tag",
|
|
10
|
-
"fallbackCurrentVersionResolver": "disk"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"tags": [],
|
|
14
|
-
"targets": {
|
|
15
|
-
"build": {
|
|
16
|
-
"executor": "@nx/esbuild:esbuild",
|
|
17
|
-
"outputs": ["{options.outputPath}"],
|
|
18
|
-
"options": {
|
|
19
|
-
"outputPath": "dist/trpc",
|
|
20
|
-
"main": "trpc/src/index.ts",
|
|
21
|
-
"tsConfig": "trpc/tsconfig.lib.json",
|
|
22
|
-
"format": ["esm"]
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"nx-release-publish": {
|
|
26
|
-
"options": {
|
|
27
|
-
"packageRoot": "dist/{projectRoot}"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
package/trpc/src/client.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import type { Client, RequestContext} from '@reactionary/core';
|
|
2
|
-
import { Session } from '@reactionary/core';
|
|
3
|
-
import type { TransparentClient } from './types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Configuration options for TRPC client creation
|
|
7
|
-
*/
|
|
8
|
-
export interface TRPCClientOptions {
|
|
9
|
-
/** Default session to use if not provided in method calls */
|
|
10
|
-
defaultRequestContext?: RequestContext
|
|
11
|
-
/** Whether to automatically provide request context from defaultRequestContext\ */
|
|
12
|
-
autoRequestContext?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Create a type-safe client proxy that uses the original client's type interface
|
|
17
|
-
* while routing all calls through TRPC
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { createTRPCProxyClient } from '@trpc/client';
|
|
22
|
-
* import { createTRPCClient } from '@reactionary/trpc/client';
|
|
23
|
-
*
|
|
24
|
-
* const trpc = createTRPCProxyClient<AppRouter>({
|
|
25
|
-
* url: 'http://localhost:3000',
|
|
26
|
-
* });
|
|
27
|
-
*
|
|
28
|
-
* // Pass the original client type as the generic parameter
|
|
29
|
-
* const client = createTRPCClient<typeof serverClient>(trpc, {
|
|
30
|
-
* defaultSession: mySession,
|
|
31
|
-
* autoSession: true
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* // Fully typed using the original client interface!
|
|
35
|
-
* const product = await client.product.getById({ id: '123' }, reqCtx);
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export function createTRPCClient<TOriginalClient extends Partial<Client>>(
|
|
39
|
-
trpcClient: any,
|
|
40
|
-
options: TRPCClientOptions = {}
|
|
41
|
-
): TransparentClient<TOriginalClient> {
|
|
42
|
-
const { defaultRequestContext, autoRequestContext = false } = options;
|
|
43
|
-
|
|
44
|
-
return new Proxy({} as TransparentClient<TOriginalClient>, {
|
|
45
|
-
get(target, providerName: string | symbol) {
|
|
46
|
-
if (typeof providerName !== 'string') {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Return a typed proxy for the provider that intercepts method calls
|
|
51
|
-
return new Proxy({}, {
|
|
52
|
-
get(providerTarget, methodName: string | symbol) {
|
|
53
|
-
if (typeof methodName !== 'string') {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Only expose methods that are marked with TRPC decorators
|
|
58
|
-
// This eliminates the need to filter TRPC-specific properties
|
|
59
|
-
return async (payload: any, reqCtxArg?: RequestContext) => {
|
|
60
|
-
// Determine request context to use
|
|
61
|
-
let reqCtx = reqCtxArg;
|
|
62
|
-
if (!reqCtx && autoRequestContext && defaultRequestContext) {
|
|
63
|
-
reqCtx = defaultRequestContext;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Prepare input for TRPC call
|
|
67
|
-
const input = {
|
|
68
|
-
payload,
|
|
69
|
-
reqCtx
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// Access TRPC provider and method lazily
|
|
73
|
-
const trpcProvider = trpcClient[providerName];
|
|
74
|
-
const trpcMethod = trpcProvider[methodName];
|
|
75
|
-
|
|
76
|
-
// Use decorator metadata to determine if this is a query or mutation
|
|
77
|
-
// Note: We can't directly check the original provider here since we only have
|
|
78
|
-
// the TRPC client, so we'll fall back to the router's procedure type detection
|
|
79
|
-
if (trpcMethod?.query) {
|
|
80
|
-
return await trpcMethod.query(input);
|
|
81
|
-
} else if (trpcMethod?.mutate) {
|
|
82
|
-
return await trpcMethod.mutate(input);
|
|
83
|
-
} else {
|
|
84
|
-
throw new Error(`Method ${String(providerName)}.${String(methodName)} not found on TRPC client`);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Session provider interface for dependency injection
|
|
95
|
-
*/
|
|
96
|
-
export interface SessionProvider {
|
|
97
|
-
getRequestContext(): Promise<RequestContext> | RequestContext;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Create a TRPC client with session provider for automatic session management
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* ```typescript
|
|
105
|
-
* const sessionProvider: SessionProvider = {
|
|
106
|
-
* getSession: () => getCurrentUserSession()
|
|
107
|
-
* };
|
|
108
|
-
*
|
|
109
|
-
* const client = createTRPCClientWithSessionProvider(trpc, reqCtxProvider);
|
|
110
|
-
*
|
|
111
|
-
* // Session is automatically provided, fully typed
|
|
112
|
-
* const product = await client.product.getById({ id: '123' });
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
export function createTRPCClientWithSessionProvider<TOriginalClient extends Partial<Client>>(
|
|
116
|
-
trpcClient: any,
|
|
117
|
-
sessionProvider: SessionProvider
|
|
118
|
-
): TransparentClient<TOriginalClient> {
|
|
119
|
-
return new Proxy({} as TransparentClient<TOriginalClient>, {
|
|
120
|
-
get(target, providerName: string | symbol) {
|
|
121
|
-
if (typeof providerName !== 'string') {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return new Proxy({}, {
|
|
126
|
-
get(providerTarget, methodName: string | symbol) {
|
|
127
|
-
if (typeof methodName !== 'string') {
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return async (payload: any, reqCtxArg?: RequestContext) => {
|
|
132
|
-
// If no session provided, get from provider
|
|
133
|
-
let reqCtx = reqCtxArg;
|
|
134
|
-
if (!reqCtx) {
|
|
135
|
-
reqCtx = await sessionProvider.getRequestContext();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const input = {
|
|
139
|
-
payload,
|
|
140
|
-
reqCtx
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
// Access TRPC provider and method lazily
|
|
144
|
-
const trpcProvider = trpcClient[providerName];
|
|
145
|
-
const trpcMethod = trpcProvider[methodName];
|
|
146
|
-
|
|
147
|
-
// Use TRPC client's procedure type detection
|
|
148
|
-
if (trpcMethod?.query) {
|
|
149
|
-
return await trpcMethod.query(input);
|
|
150
|
-
} else if (trpcMethod?.mutate) {
|
|
151
|
-
return await trpcMethod.mutate(input);
|
|
152
|
-
} else {
|
|
153
|
-
throw new Error(`Method ${String(providerName)}.${String(methodName)} not found on TRPC client`);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Type alias for creating typed TRPC clients
|
|
164
|
-
* Use the original client type, not the router type
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```typescript
|
|
168
|
-
* type MyClient = typeof serverClient;
|
|
169
|
-
*
|
|
170
|
-
* function useClient(): MyClient {
|
|
171
|
-
* return createTRPCClient<MyClient>(trpcProxyClient);
|
|
172
|
-
* }
|
|
173
|
-
* ```
|
|
174
|
-
*/
|
|
175
|
-
export type TRPCClientFromRouter<TOriginalClient> = TOriginalClient;
|
package/trpc/src/index.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Re-export server utilities
|
|
2
|
-
export {
|
|
3
|
-
createTRPCServerRouter,
|
|
4
|
-
createTRPCContext,
|
|
5
|
-
router,
|
|
6
|
-
mergeRouters,
|
|
7
|
-
type TRPCRouterFromClient
|
|
8
|
-
} from './server';
|
|
9
|
-
|
|
10
|
-
// Re-export client utilities
|
|
11
|
-
export {
|
|
12
|
-
createTRPCClient,
|
|
13
|
-
createTRPCClientWithSessionProvider,
|
|
14
|
-
type TRPCClientOptions,
|
|
15
|
-
type SessionProvider,
|
|
16
|
-
type TRPCClientFromRouter
|
|
17
|
-
} from './client';
|
|
18
|
-
|
|
19
|
-
// Re-export type utilities
|
|
20
|
-
export {
|
|
21
|
-
type ClientMethodMap,
|
|
22
|
-
type MethodInfo,
|
|
23
|
-
type TRPCMethodInput,
|
|
24
|
-
type TransparentClient,
|
|
25
|
-
introspectClient,
|
|
26
|
-
isQueryMethod,
|
|
27
|
-
isMutationMethod
|
|
28
|
-
} from './types';
|
|
29
|
-
|
|
30
|
-
// Legacy exports for backward compatibility
|
|
31
|
-
import { initTRPC } from '@trpc/server';
|
|
32
|
-
import type { Client, RequestContext} from '@reactionary/core';
|
|
33
|
-
import { Session } from '@reactionary/core';
|
|
34
|
-
import { createTRPCTracing } from '@reactionary/otel';
|
|
35
|
-
|
|
36
|
-
const t = initTRPC.context<{ client: Client; reqCtx: RequestContext }>().create({});
|
|
37
|
-
|
|
38
|
-
// Always apply tracing middleware - exporters controlled via OTEL env vars
|
|
39
|
-
const basePublicProcedure = t.procedure;
|
|
40
|
-
export const publicProcedure = basePublicProcedure.use(createTRPCTracing());
|
|
41
|
-
|
|
42
|
-
// Legacy function - deprecated, use createTRPCServerRouter instead
|
|
43
|
-
import { createTRPCServerRouter } from './server';
|
|
44
|
-
export const createTRPCRouter = createTRPCServerRouter;
|