@reactionary/source 0.0.27
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/.editorconfig +13 -0
- package/.github/workflows/pull-request.yml +37 -0
- package/.github/workflows/release.yml +49 -0
- package/.nvmrc +1 -0
- package/.prettierignore +6 -0
- package/.prettierrc +3 -0
- package/.verdaccio/config.yml +28 -0
- package/.vscode/extensions.json +9 -0
- package/README.md +39 -0
- package/core/README.md +11 -0
- package/core/eslint.config.mjs +23 -0
- package/core/package.json +8 -0
- package/core/project.json +33 -0
- package/core/src/cache/caching-strategy.ts +25 -0
- package/core/src/cache/redis-cache.ts +41 -0
- package/core/src/client/client.ts +39 -0
- package/core/src/index.ts +42 -0
- package/core/src/providers/analytics.provider.ts +10 -0
- package/core/src/providers/base.provider.ts +75 -0
- package/core/src/providers/cart.provider.ts +10 -0
- package/core/src/providers/identity.provider.ts +10 -0
- package/core/src/providers/inventory.provider.ts +11 -0
- package/core/src/providers/price.provider.ts +10 -0
- package/core/src/providers/product.provider.ts +11 -0
- package/core/src/providers/search.provider.ts +12 -0
- package/core/src/schemas/capabilities.schema.ts +13 -0
- package/core/src/schemas/models/analytics.model.ts +7 -0
- package/core/src/schemas/models/base.model.ts +19 -0
- package/core/src/schemas/models/cart.model.ts +17 -0
- package/core/src/schemas/models/currency.model.ts +187 -0
- package/core/src/schemas/models/identifiers.model.ts +45 -0
- package/core/src/schemas/models/identity.model.ts +15 -0
- package/core/src/schemas/models/inventory.model.ts +8 -0
- package/core/src/schemas/models/price.model.ts +17 -0
- package/core/src/schemas/models/product.model.ts +28 -0
- package/core/src/schemas/models/search.model.ts +35 -0
- package/core/src/schemas/mutations/analytics.mutation.ts +22 -0
- package/core/src/schemas/mutations/base.mutation.ts +7 -0
- package/core/src/schemas/mutations/cart.mutation.ts +30 -0
- package/core/src/schemas/mutations/identity.mutation.ts +18 -0
- package/core/src/schemas/mutations/inventory.mutation.ts +5 -0
- package/core/src/schemas/mutations/price.mutation.ts +5 -0
- package/core/src/schemas/mutations/product.mutation.ts +6 -0
- package/core/src/schemas/mutations/search.mutation.ts +5 -0
- package/core/src/schemas/queries/analytics.query.ts +5 -0
- package/core/src/schemas/queries/base.query.ts +7 -0
- package/core/src/schemas/queries/cart.query.ts +12 -0
- package/core/src/schemas/queries/identity.query.ts +10 -0
- package/core/src/schemas/queries/inventory.query.ts +9 -0
- package/core/src/schemas/queries/price.query.ts +12 -0
- package/core/src/schemas/queries/product.query.ts +18 -0
- package/core/src/schemas/queries/search.query.ts +12 -0
- package/core/src/schemas/session.schema.ts +9 -0
- package/core/tsconfig.json +23 -0
- package/core/tsconfig.lib.json +23 -0
- package/core/tsconfig.spec.json +28 -0
- package/eslint.config.mjs +46 -0
- package/examples/angular/e2e/example.spec.ts +9 -0
- package/examples/angular/eslint.config.mjs +41 -0
- package/examples/angular/playwright.config.ts +38 -0
- package/examples/angular/project.json +86 -0
- package/examples/angular/public/favicon.ico +0 -0
- package/examples/angular/src/app/app.component.html +6 -0
- package/examples/angular/src/app/app.component.scss +22 -0
- package/examples/angular/src/app/app.component.ts +14 -0
- package/examples/angular/src/app/app.config.ts +16 -0
- package/examples/angular/src/app/app.routes.ts +25 -0
- package/examples/angular/src/app/cart/cart.component.html +4 -0
- package/examples/angular/src/app/cart/cart.component.scss +14 -0
- package/examples/angular/src/app/cart/cart.component.ts +73 -0
- package/examples/angular/src/app/identity/identity.component.html +6 -0
- package/examples/angular/src/app/identity/identity.component.scss +18 -0
- package/examples/angular/src/app/identity/identity.component.ts +49 -0
- package/examples/angular/src/app/product/product.component.html +14 -0
- package/examples/angular/src/app/product/product.component.scss +11 -0
- package/examples/angular/src/app/product/product.component.ts +42 -0
- package/examples/angular/src/app/search/search.component.html +35 -0
- package/examples/angular/src/app/search/search.component.scss +129 -0
- package/examples/angular/src/app/search/search.component.ts +50 -0
- package/examples/angular/src/app/services/product.service.ts +35 -0
- package/examples/angular/src/app/services/search.service.ts +48 -0
- package/examples/angular/src/app/services/trpc.client.ts +27 -0
- package/examples/angular/src/index.html +13 -0
- package/examples/angular/src/main.ts +7 -0
- package/examples/angular/src/styles.scss +17 -0
- package/examples/angular/src/test-setup.ts +6 -0
- package/examples/angular/tsconfig.app.json +10 -0
- package/examples/angular/tsconfig.editor.json +6 -0
- package/examples/angular/tsconfig.json +32 -0
- package/examples/node/README.md +11 -0
- package/examples/node/eslint.config.mjs +22 -0
- package/examples/node/jest.config.ts +10 -0
- package/examples/node/package.json +10 -0
- package/examples/node/project.json +20 -0
- package/examples/node/src/index.ts +2 -0
- package/examples/node/src/initialize-algolia.spec.ts +29 -0
- package/examples/node/src/initialize-commercetools.spec.ts +31 -0
- package/examples/node/src/initialize-extended-providers.spec.ts +38 -0
- package/examples/node/src/initialize-mixed-providers.spec.ts +36 -0
- package/examples/node/src/providers/custom-algolia-product.provider.ts +18 -0
- package/examples/node/src/schemas/custom-product.schema.ts +8 -0
- package/examples/node/tsconfig.json +23 -0
- package/examples/node/tsconfig.lib.json +10 -0
- package/examples/node/tsconfig.spec.json +15 -0
- package/examples/trpc-node/eslint.config.mjs +3 -0
- package/examples/trpc-node/project.json +61 -0
- package/examples/trpc-node/src/assets/.gitkeep +0 -0
- package/examples/trpc-node/src/main.ts +55 -0
- package/examples/trpc-node/src/router-instance.ts +52 -0
- package/examples/trpc-node/tsconfig.app.json +9 -0
- package/examples/trpc-node/tsconfig.json +13 -0
- package/examples/vue/eslint.config.mjs +24 -0
- package/examples/vue/index.html +13 -0
- package/examples/vue/project.json +8 -0
- package/examples/vue/src/app/App.vue +275 -0
- package/examples/vue/src/main.ts +6 -0
- package/examples/vue/src/styles.scss +9 -0
- package/examples/vue/src/vue-shims.d.ts +5 -0
- package/examples/vue/tsconfig.app.json +14 -0
- package/examples/vue/tsconfig.json +20 -0
- package/examples/vue/vite.config.ts +31 -0
- package/jest.config.ts +6 -0
- package/jest.preset.js +3 -0
- package/migrations.json +11 -0
- package/nx.json +130 -0
- package/package.json +118 -0
- package/project.json +14 -0
- package/providers/algolia/README.md +11 -0
- package/providers/algolia/eslint.config.mjs +22 -0
- package/providers/algolia/jest.config.ts +10 -0
- package/providers/algolia/package.json +9 -0
- package/providers/algolia/project.json +33 -0
- package/providers/algolia/src/core/initialize.ts +20 -0
- package/providers/algolia/src/index.ts +7 -0
- package/providers/algolia/src/providers/product.provider.ts +25 -0
- package/providers/algolia/src/providers/search.provider.ts +125 -0
- package/providers/algolia/src/schema/capabilities.schema.ts +10 -0
- package/providers/algolia/src/schema/configuration.schema.ts +9 -0
- package/providers/algolia/src/schema/search.schema.ts +14 -0
- package/providers/algolia/src/test/product.provider.spec.ts +18 -0
- package/providers/algolia/src/test/search.provider.spec.ts +82 -0
- package/providers/algolia/tsconfig.json +23 -0
- package/providers/algolia/tsconfig.lib.json +10 -0
- package/providers/algolia/tsconfig.spec.json +15 -0
- package/providers/commercetools/README.md +11 -0
- package/providers/commercetools/eslint.config.mjs +22 -0
- package/providers/commercetools/jest.config.ts +10 -0
- package/providers/commercetools/package.json +10 -0
- package/providers/commercetools/project.json +33 -0
- package/providers/commercetools/src/core/client.ts +152 -0
- package/providers/commercetools/src/core/initialize.ts +40 -0
- package/providers/commercetools/src/index.ts +12 -0
- package/providers/commercetools/src/providers/cart.provider.ts +223 -0
- package/providers/commercetools/src/providers/identity.provider.ts +130 -0
- package/providers/commercetools/src/providers/inventory.provider.ts +82 -0
- package/providers/commercetools/src/providers/price.provider.ts +66 -0
- package/providers/commercetools/src/providers/product.provider.ts +90 -0
- package/providers/commercetools/src/providers/search.provider.ts +86 -0
- package/providers/commercetools/src/schema/capabilities.schema.ts +13 -0
- package/providers/commercetools/src/schema/configuration.schema.ts +11 -0
- package/providers/commercetools/src/test/product.provider.spec.ts +20 -0
- package/providers/commercetools/src/test/search.provider.spec.ts +18 -0
- package/providers/commercetools/tsconfig.json +23 -0
- package/providers/commercetools/tsconfig.lib.json +10 -0
- package/providers/commercetools/tsconfig.spec.json +15 -0
- package/providers/fake/README.md +7 -0
- package/providers/fake/eslint.config.mjs +22 -0
- package/providers/fake/package.json +9 -0
- package/providers/fake/project.json +33 -0
- package/providers/fake/src/core/initialize.ts +24 -0
- package/providers/fake/src/index.ts +8 -0
- package/providers/fake/src/providers/identity.provider.ts +91 -0
- package/providers/fake/src/providers/product.provider.ts +73 -0
- package/providers/fake/src/providers/search.provider.ts +142 -0
- package/providers/fake/src/schema/capabilities.schema.ts +10 -0
- package/providers/fake/src/schema/configuration.schema.ts +15 -0
- package/providers/fake/src/utilities/jitter.ts +14 -0
- package/providers/fake/tsconfig.json +20 -0
- package/providers/fake/tsconfig.lib.json +9 -0
- package/providers/posthog/README.md +7 -0
- package/providers/posthog/eslint.config.mjs +22 -0
- package/providers/posthog/package.json +11 -0
- package/providers/posthog/project.json +33 -0
- package/providers/posthog/src/core/initialize.ts +9 -0
- package/providers/posthog/src/index.ts +4 -0
- package/providers/posthog/src/schema/capabilities.schema.ts +8 -0
- package/providers/posthog/src/schema/configuration.schema.ts +8 -0
- package/providers/posthog/tsconfig.json +20 -0
- package/providers/posthog/tsconfig.lib.json +9 -0
- package/trpc/README.md +7 -0
- package/trpc/eslint.config.mjs +19 -0
- package/trpc/package.json +13 -0
- package/trpc/project.json +31 -0
- package/trpc/src/index.ts +64 -0
- package/trpc/tsconfig.json +13 -0
- package/trpc/tsconfig.lib.json +9 -0
- package/tsconfig.base.json +30 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Identity,
|
|
3
|
+
IdentityMutation,
|
|
4
|
+
IdentityMutationLogin,
|
|
5
|
+
IdentityProvider,
|
|
6
|
+
IdentityQuery,
|
|
7
|
+
Session,
|
|
8
|
+
} from '@reactionary/core';
|
|
9
|
+
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
10
|
+
import z from 'zod';
|
|
11
|
+
import { faker } from '@faker-js/faker';
|
|
12
|
+
|
|
13
|
+
export class FakeIdentityProvider<
|
|
14
|
+
T extends Identity = Identity,
|
|
15
|
+
Q extends IdentityQuery = IdentityQuery,
|
|
16
|
+
M extends IdentityMutation = IdentityMutation
|
|
17
|
+
> extends IdentityProvider<T, Q, M> {
|
|
18
|
+
protected config: FakeConfiguration;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
config: FakeConfiguration,
|
|
22
|
+
schema: z.ZodType<T>,
|
|
23
|
+
querySchema: z.ZodType<Q, Q>,
|
|
24
|
+
mutationSchema: z.ZodType<M, M>
|
|
25
|
+
) {
|
|
26
|
+
super(schema, querySchema, mutationSchema);
|
|
27
|
+
|
|
28
|
+
this.config = config;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected override async fetch(queries: Q[], session: Session): Promise<T[]> {
|
|
32
|
+
const results = [];
|
|
33
|
+
|
|
34
|
+
for (const query of queries) {
|
|
35
|
+
const result = await this.get(session);
|
|
36
|
+
|
|
37
|
+
results.push(result);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return results;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
protected override async process(
|
|
44
|
+
mutations: M[],
|
|
45
|
+
session: Session
|
|
46
|
+
): Promise<T> {
|
|
47
|
+
let result = this.newModel();
|
|
48
|
+
|
|
49
|
+
for (const mutation of mutations) {
|
|
50
|
+
switch (mutation.mutation) {
|
|
51
|
+
case 'login':
|
|
52
|
+
result = await this.login(mutation, session);
|
|
53
|
+
break;
|
|
54
|
+
case 'logout':
|
|
55
|
+
result = await this.logout(session);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected async login(
|
|
64
|
+
payload: IdentityMutationLogin,
|
|
65
|
+
session: Session
|
|
66
|
+
): Promise<T> {
|
|
67
|
+
const base = this.newModel();
|
|
68
|
+
|
|
69
|
+
base.id = faker.string.uuid();
|
|
70
|
+
base.token = faker.string.uuid();
|
|
71
|
+
base.issued = faker.date.recent();
|
|
72
|
+
base.issued = faker.date.soon();
|
|
73
|
+
base.type = 'Registered';
|
|
74
|
+
|
|
75
|
+
return base;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected async get(session: Session): Promise<T> {
|
|
79
|
+
const base = this.schema.parse(session.identity);
|
|
80
|
+
|
|
81
|
+
return base;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected async logout(session: Session): Promise<T> {
|
|
85
|
+
const base = this.newModel();
|
|
86
|
+
|
|
87
|
+
session.identity = base;
|
|
88
|
+
|
|
89
|
+
return base;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseMutation,
|
|
3
|
+
Product,
|
|
4
|
+
ProductMutation,
|
|
5
|
+
ProductProvider,
|
|
6
|
+
ProductQuery,
|
|
7
|
+
Session,
|
|
8
|
+
} from '@reactionary/core';
|
|
9
|
+
import z from 'zod';
|
|
10
|
+
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
11
|
+
import { base, en, Faker } from '@faker-js/faker';
|
|
12
|
+
|
|
13
|
+
export class FakeProductProvider<
|
|
14
|
+
T extends Product = Product,
|
|
15
|
+
Q extends ProductQuery = ProductQuery,
|
|
16
|
+
M extends ProductMutation = ProductMutation
|
|
17
|
+
> extends ProductProvider<T, Q, M> {
|
|
18
|
+
protected config: FakeConfiguration;
|
|
19
|
+
|
|
20
|
+
constructor(config: FakeConfiguration, schema: z.ZodType<T>, querySchema: z.ZodType<Q, Q>, mutationSchema: z.ZodType<M, M>) {
|
|
21
|
+
super(schema, querySchema, mutationSchema);
|
|
22
|
+
|
|
23
|
+
this.config = config;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected override async fetch(queries: Q[], session: Session): Promise<T[]> {
|
|
27
|
+
const results = new Array<T>();
|
|
28
|
+
|
|
29
|
+
for (const query of queries) {
|
|
30
|
+
const generator = new Faker({
|
|
31
|
+
seed: 42,
|
|
32
|
+
locale: [en, base],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const key = (query.id as string) || generator.commerce.isbn();
|
|
36
|
+
const slug = (query.slug as string) || generator.lorem.slug();
|
|
37
|
+
|
|
38
|
+
const product: Product = {
|
|
39
|
+
identifier: {
|
|
40
|
+
key: key,
|
|
41
|
+
},
|
|
42
|
+
name: generator.commerce.productName(),
|
|
43
|
+
slug: slug,
|
|
44
|
+
attributes: [],
|
|
45
|
+
description: generator.commerce.productDescription(),
|
|
46
|
+
image: generator.image.urlPicsumPhotos({
|
|
47
|
+
width: 600,
|
|
48
|
+
height: 600,
|
|
49
|
+
}),
|
|
50
|
+
images: [],
|
|
51
|
+
meta: {
|
|
52
|
+
cache: {
|
|
53
|
+
hit: false,
|
|
54
|
+
key: key,
|
|
55
|
+
},
|
|
56
|
+
placeholder: false
|
|
57
|
+
},
|
|
58
|
+
skus: [],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
results.push(product as T);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return results;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected override process(
|
|
68
|
+
mutation: BaseMutation[],
|
|
69
|
+
session: Session
|
|
70
|
+
): Promise<T> {
|
|
71
|
+
throw new Error('Method not implemented.');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SearchIdentifier,
|
|
3
|
+
SearchMutation,
|
|
4
|
+
SearchProvider,
|
|
5
|
+
SearchQuery,
|
|
6
|
+
SearchResult,
|
|
7
|
+
SearchResultFacet,
|
|
8
|
+
SearchResultProduct,
|
|
9
|
+
Session,
|
|
10
|
+
} from '@reactionary/core';
|
|
11
|
+
import z from 'zod';
|
|
12
|
+
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
13
|
+
import { Faker, en, base } from '@faker-js/faker';
|
|
14
|
+
import { jitter } from '../utilities/jitter';
|
|
15
|
+
|
|
16
|
+
export class FakeSearchProvider<
|
|
17
|
+
T extends SearchResult = SearchResult,
|
|
18
|
+
Q extends SearchQuery = SearchQuery,
|
|
19
|
+
M extends SearchMutation = SearchMutation
|
|
20
|
+
> extends SearchProvider<T, Q, M> {
|
|
21
|
+
protected config: FakeConfiguration;
|
|
22
|
+
|
|
23
|
+
constructor(config: FakeConfiguration, schema: z.ZodType<T>, querySchema: z.ZodType<Q, Q>, mutationSchema: z.ZodType<M, M>) {
|
|
24
|
+
super(schema, querySchema, mutationSchema);
|
|
25
|
+
|
|
26
|
+
this.config = config;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected override async fetch(queries: Q[], session: Session): Promise<T[]> {
|
|
30
|
+
const results = [];
|
|
31
|
+
|
|
32
|
+
for (const query of queries) {
|
|
33
|
+
const result = await this.get(query.search);
|
|
34
|
+
|
|
35
|
+
results.push(result);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return results;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected override process(mutations: M[], session: Session): Promise<T> {
|
|
42
|
+
throw new Error('Method not implemented.');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public async get(identifier: SearchIdentifier): Promise<T> {
|
|
46
|
+
await jitter(this.config.jitter.mean, this.config.jitter.deviation);
|
|
47
|
+
|
|
48
|
+
return this.parse({}, identifier);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public parse(data: unknown, query: SearchIdentifier): T {
|
|
52
|
+
const querySpecificity =
|
|
53
|
+
20 - query.term.length - query.page - query.facets.length;
|
|
54
|
+
const totalProducts = 10 * querySpecificity;
|
|
55
|
+
const totalPages = Math.ceil(totalProducts / query.pageSize);
|
|
56
|
+
const productsOnPage = Math.min(totalProducts, query.pageSize);
|
|
57
|
+
|
|
58
|
+
const productGenerator = new Faker({
|
|
59
|
+
seed: querySpecificity,
|
|
60
|
+
locale: [en, base],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const facetGenerator = new Faker({
|
|
64
|
+
seed: 100,
|
|
65
|
+
locale: [en, base],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const products = new Array<SearchResultProduct>();
|
|
69
|
+
const facets = new Array<SearchResultFacet>();
|
|
70
|
+
|
|
71
|
+
for (let i = 0; i < productsOnPage; i++) {
|
|
72
|
+
products.push({
|
|
73
|
+
identifier: {
|
|
74
|
+
key: productGenerator.commerce.isbn(),
|
|
75
|
+
},
|
|
76
|
+
image: productGenerator.image.urlPicsumPhotos({
|
|
77
|
+
height: 300,
|
|
78
|
+
width: 300,
|
|
79
|
+
grayscale: true,
|
|
80
|
+
blur: 8
|
|
81
|
+
}),
|
|
82
|
+
name: productGenerator.commerce.productName(),
|
|
83
|
+
slug: productGenerator.lorem.slug(),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const facetBase = ['color', 'size'];
|
|
88
|
+
|
|
89
|
+
for (const base of facetBase) {
|
|
90
|
+
const facet: SearchResultFacet = {
|
|
91
|
+
identifier: {
|
|
92
|
+
key: base,
|
|
93
|
+
},
|
|
94
|
+
name: base,
|
|
95
|
+
values: [],
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
for (let i = 0; i < 10; i++) {
|
|
99
|
+
const valueKey = i.toString();
|
|
100
|
+
const isActive =
|
|
101
|
+
query.facets.find(
|
|
102
|
+
(x) => x.facet.key === facet.identifier.key && x.key === valueKey
|
|
103
|
+
) !== undefined;
|
|
104
|
+
|
|
105
|
+
facet.values.push({
|
|
106
|
+
active: isActive,
|
|
107
|
+
count: facetGenerator.number.int({ min: 1, max: 50 }),
|
|
108
|
+
identifier: {
|
|
109
|
+
facet: {
|
|
110
|
+
key: facet.identifier.key,
|
|
111
|
+
},
|
|
112
|
+
key: valueKey,
|
|
113
|
+
},
|
|
114
|
+
name: facetGenerator.color.human(),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
facets.push(facet);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const result = {
|
|
122
|
+
pages: totalPages,
|
|
123
|
+
identifier: {
|
|
124
|
+
term: query.term,
|
|
125
|
+
page: query.page,
|
|
126
|
+
facets: query.facets,
|
|
127
|
+
pageSize: query.pageSize,
|
|
128
|
+
},
|
|
129
|
+
facets: facets,
|
|
130
|
+
products: products,
|
|
131
|
+
meta: {
|
|
132
|
+
cache: {
|
|
133
|
+
hit: false,
|
|
134
|
+
key: ''
|
|
135
|
+
},
|
|
136
|
+
placeholder: false
|
|
137
|
+
}
|
|
138
|
+
} satisfies SearchResult;
|
|
139
|
+
|
|
140
|
+
return this.schema.parse(result);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CapabilitiesSchema } from "@reactionary/core";
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const FakeCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
5
|
+
product: true,
|
|
6
|
+
search: true,
|
|
7
|
+
identity: true
|
|
8
|
+
}).partial();
|
|
9
|
+
|
|
10
|
+
export type FakeCapabilities = z.infer<typeof FakeCapabilitiesSchema>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const FakeConfigurationSchema = z.looseInterface({
|
|
4
|
+
jitter: z
|
|
5
|
+
.looseInterface({
|
|
6
|
+
mean: z.number().min(0).max(10000),
|
|
7
|
+
deviation: z.number().min(0).max(5000),
|
|
8
|
+
})
|
|
9
|
+
.default({
|
|
10
|
+
mean: 0,
|
|
11
|
+
deviation: 0,
|
|
12
|
+
}),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export type FakeConfiguration = z.infer<typeof FakeConfigurationSchema>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export async function jitter(duration: number, deviation: number) {
|
|
2
|
+
const j = gaussianRandom(duration, deviation);
|
|
3
|
+
|
|
4
|
+
return new Promise(resolve => setTimeout(resolve, j));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function gaussianRandom(mean: number, deviation: number) {
|
|
9
|
+
const u = 1 - Math.random();
|
|
10
|
+
const v = Math.random();
|
|
11
|
+
const z = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
|
|
12
|
+
|
|
13
|
+
return z * deviation + mean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"forceConsistentCasingInFileNames": true,
|
|
6
|
+
"strict": true,
|
|
7
|
+
"importHelpers": true,
|
|
8
|
+
"noImplicitOverride": true,
|
|
9
|
+
"noImplicitReturns": true,
|
|
10
|
+
"noFallthroughCasesInSwitch": true,
|
|
11
|
+
"noPropertyAccessFromIndexSignature": true
|
|
12
|
+
},
|
|
13
|
+
"files": [],
|
|
14
|
+
"include": [],
|
|
15
|
+
"references": [
|
|
16
|
+
{
|
|
17
|
+
"path": "./tsconfig.lib.json"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import baseConfig from '../../eslint.config.mjs';
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
...baseConfig,
|
|
5
|
+
{
|
|
6
|
+
files: ['**/*.json'],
|
|
7
|
+
rules: {
|
|
8
|
+
'@nx/dependency-checks': [
|
|
9
|
+
'error',
|
|
10
|
+
{
|
|
11
|
+
ignoredFiles: [
|
|
12
|
+
'{projectRoot}/eslint.config.{js,cjs,mjs}',
|
|
13
|
+
'{projectRoot}/esbuild.config.{js,ts,mjs,mts}',
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
languageOptions: {
|
|
19
|
+
parser: await import('jsonc-eslint-parser'),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "provider-posthog",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "providers/posthog/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/providers/posthog",
|
|
20
|
+
"main": "providers/posthog/src/index.ts",
|
|
21
|
+
"tsConfig": "providers/posthog/tsconfig.lib.json",
|
|
22
|
+
"assets": ["providers/posthog/*.md"],
|
|
23
|
+
"format": ["cjs"],
|
|
24
|
+
"generatePackageJson": true
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"nx-release-publish": {
|
|
28
|
+
"options": {
|
|
29
|
+
"packageRoot": "dist/{projectRoot}"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Client } from "@reactionary/core";
|
|
2
|
+
import { PosthogConfiguration } from "../schema/configuration.schema";
|
|
3
|
+
import { PosthogCapabilities } from "../schema/capabilities.schema";
|
|
4
|
+
|
|
5
|
+
export function withPosthogCapabilities(configuration: PosthogConfiguration, capabilities: PosthogCapabilities) {
|
|
6
|
+
const client: Partial<Client> = {};
|
|
7
|
+
|
|
8
|
+
return client;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CapabilitiesSchema } from "@reactionary/core";
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const PosthogCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
5
|
+
analytics: true
|
|
6
|
+
}).partial();
|
|
7
|
+
|
|
8
|
+
export type PosthogCapabilities = z.infer<typeof PosthogCapabilitiesSchema>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"forceConsistentCasingInFileNames": true,
|
|
6
|
+
"strict": true,
|
|
7
|
+
"importHelpers": true,
|
|
8
|
+
"noImplicitOverride": true,
|
|
9
|
+
"noImplicitReturns": true,
|
|
10
|
+
"noFallthroughCasesInSwitch": true,
|
|
11
|
+
"noPropertyAccessFromIndexSignature": true
|
|
12
|
+
},
|
|
13
|
+
"files": [],
|
|
14
|
+
"include": [],
|
|
15
|
+
"references": [
|
|
16
|
+
{
|
|
17
|
+
"path": "./tsconfig.lib.json"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
package/trpc/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import baseConfig from '../eslint.config.mjs';
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
...baseConfig,
|
|
5
|
+
{
|
|
6
|
+
files: ['**/*.json'],
|
|
7
|
+
rules: {
|
|
8
|
+
'@nx/dependency-checks': [
|
|
9
|
+
'error',
|
|
10
|
+
{
|
|
11
|
+
ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'],
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
languageOptions: {
|
|
16
|
+
parser: await import('jsonc-eslint-parser'),
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
"superjson": "^2.2.2",
|
|
11
|
+
"zod": "4.0.0-beta.20250430T185432"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { initTRPC } from '@trpc/server';
|
|
2
|
+
import {
|
|
3
|
+
Client,
|
|
4
|
+
Session,
|
|
5
|
+
} from '@reactionary/core';
|
|
6
|
+
import superjson from 'superjson';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { BaseProvider } from '@reactionary/core';
|
|
9
|
+
import { TRPCQueryProcedure, TRPCMutationProcedure } from '@trpc/server';
|
|
10
|
+
|
|
11
|
+
const t = initTRPC.context<{ client: Client; session: Session }>().create({
|
|
12
|
+
transformer: superjson,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const router = t.router;
|
|
16
|
+
export const mergeRouters = t.mergeRouters;
|
|
17
|
+
export const publicProcedure = t.procedure;
|
|
18
|
+
|
|
19
|
+
export function createTRPCRouter<T extends Client = Client>(client: T) {
|
|
20
|
+
type BaseProviderKeys<T> = {
|
|
21
|
+
[K in keyof T]: T[K] extends BaseProvider ? K : never;
|
|
22
|
+
}[keyof T];
|
|
23
|
+
|
|
24
|
+
type ReactionaryRouter = {
|
|
25
|
+
[Property in BaseProviderKeys<Client>]: TRPCQueryProcedure<{
|
|
26
|
+
input: Array<z.infer<T[Property]['querySchema']>>;
|
|
27
|
+
output: Array<z.infer<Awaited<T[Property]['schema']>>>;
|
|
28
|
+
meta: any;
|
|
29
|
+
}>;
|
|
30
|
+
} & {
|
|
31
|
+
[Property in BaseProviderKeys<Client> as `${Property}Mutation`]: TRPCMutationProcedure<{
|
|
32
|
+
input: Array<z.infer<T[Property]['mutationSchema']>>;
|
|
33
|
+
output: z.infer<Awaited<T[Property]['schema']>>;
|
|
34
|
+
meta: any;
|
|
35
|
+
}>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const routes: Record<string, any> = {};
|
|
39
|
+
|
|
40
|
+
for (const key in client) {
|
|
41
|
+
const provider = client[key];
|
|
42
|
+
|
|
43
|
+
if (provider instanceof BaseProvider) {
|
|
44
|
+
const queryKey = key as keyof ReactionaryRouter;
|
|
45
|
+
const mutationKey = key + 'Mutation' as keyof ReactionaryRouter;
|
|
46
|
+
|
|
47
|
+
routes[queryKey] = publicProcedure
|
|
48
|
+
.input(provider.querySchema.array())
|
|
49
|
+
.output(provider.schema.array())
|
|
50
|
+
.query(async (opts) => {
|
|
51
|
+
return provider.query(opts.input, opts.ctx.session);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
routes[mutationKey] = publicProcedure
|
|
55
|
+
.input(provider.mutationSchema.array())
|
|
56
|
+
.output(provider.schema)
|
|
57
|
+
.mutation(async (opts) => {
|
|
58
|
+
return provider.mutate(opts.input, opts.ctx.session);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return router<ReactionaryRouter>(routes as ReactionaryRouter);
|
|
64
|
+
}
|