@reactionary/source 0.0.52 → 0.2.16
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 -3
- package/core/src/cache/cache.interface.ts +1 -0
- package/core/src/cache/index.ts +4 -0
- package/core/src/cache/memory-cache.ts +30 -2
- package/core/src/cache/noop-cache.ts +15 -1
- package/core/src/cache/redis-cache.ts +20 -0
- package/core/src/client/client-builder.ts +71 -54
- package/core/src/client/client.ts +9 -47
- package/core/src/client/index.ts +2 -0
- package/core/src/decorators/index.ts +1 -0
- package/core/src/decorators/reactionary.decorator.ts +203 -34
- package/core/src/index.ts +6 -19
- package/core/src/initialization.ts +1 -18
- package/core/src/metrics/metrics.ts +67 -0
- package/core/src/providers/analytics.provider.ts +1 -6
- package/core/src/providers/base.provider.ts +5 -69
- package/core/src/providers/cart.provider.ts +15 -55
- package/core/src/providers/category.provider.ts +7 -11
- package/core/src/providers/checkout.provider.ts +17 -15
- package/core/src/providers/identity.provider.ts +6 -8
- package/core/src/providers/index.ts +2 -1
- package/core/src/providers/inventory.provider.ts +15 -5
- 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 +30 -36
- package/core/src/providers/product-search.provider.ts +61 -0
- package/core/src/providers/product.provider.ts +71 -12
- package/core/src/providers/profile.provider.ts +74 -14
- package/core/src/providers/store.provider.ts +3 -5
- 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 +2 -1
- package/core/src/schemas/models/base.model.ts +6 -24
- package/core/src/schemas/models/cart.model.ts +5 -8
- package/core/src/schemas/models/category.model.ts +4 -9
- package/core/src/schemas/models/checkout.model.ts +6 -7
- package/core/src/schemas/models/cost.model.ts +4 -3
- 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 +10 -19
- package/core/src/schemas/models/index.ts +2 -1
- package/core/src/schemas/models/inventory.model.ts +8 -5
- package/core/src/schemas/models/order-search.model.ts +28 -0
- package/core/src/schemas/models/order.model.ts +20 -26
- package/core/src/schemas/models/payment.model.ts +14 -17
- package/core/src/schemas/models/price.model.ts +11 -11
- 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 +19 -22
- package/core/src/schemas/models/shipping-method.model.ts +24 -29
- package/core/src/schemas/models/store.model.ts +9 -5
- package/core/src/schemas/mutations/analytics.mutation.ts +8 -7
- package/core/src/schemas/mutations/base.mutation.ts +2 -1
- package/core/src/schemas/mutations/cart.mutation.ts +33 -33
- package/core/src/schemas/mutations/checkout.mutation.ts +23 -30
- package/core/src/schemas/mutations/identity.mutation.ts +4 -3
- package/core/src/schemas/mutations/profile.mutation.ts +38 -3
- package/core/src/schemas/queries/base.query.ts +2 -1
- package/core/src/schemas/queries/cart.query.ts +3 -3
- package/core/src/schemas/queries/category.query.ts +18 -18
- package/core/src/schemas/queries/checkout.query.ts +7 -9
- package/core/src/schemas/queries/identity.query.ts +2 -1
- package/core/src/schemas/queries/index.ts +2 -1
- package/core/src/schemas/queries/inventory.query.ts +5 -5
- package/core/src/schemas/queries/order-search.query.ts +10 -0
- package/core/src/schemas/queries/order.query.ts +3 -2
- package/core/src/schemas/queries/price.query.ts +10 -4
- package/core/src/schemas/queries/product-search.query.ts +16 -0
- package/core/src/schemas/queries/product.query.ts +13 -6
- package/core/src/schemas/queries/profile.query.ts +5 -2
- package/core/src/schemas/queries/store.query.ts +6 -5
- package/core/src/schemas/result.ts +107 -0
- package/core/src/schemas/session.schema.ts +4 -4
- package/core/src/test/reactionary.decorator.spec.ts +249 -0
- package/core/src/zod-utils.ts +19 -0
- package/core/tsconfig.json +1 -1
- 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 +10 -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 +265 -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 +147 -0
- package/examples/node/tsconfig.json +9 -12
- package/examples/node/tsconfig.lib.json +1 -2
- package/examples/node/tsconfig.spec.json +2 -14
- 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 +2 -1
- package/providers/algolia/src/core/initialize.ts +7 -14
- package/providers/algolia/src/index.ts +2 -4
- 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 +1 -1
- package/providers/algolia/tsconfig.lib.json +1 -1
- package/providers/algolia/tsconfig.spec.json +2 -14
- package/providers/algolia/vitest.config.ts +14 -0
- package/providers/commercetools/README.md +30 -3
- package/providers/commercetools/package.json +2 -1
- package/providers/commercetools/src/core/client.ts +178 -99
- package/providers/commercetools/src/core/initialize.ts +130 -74
- package/providers/commercetools/src/core/token-cache.ts +45 -0
- package/providers/commercetools/src/index.ts +3 -2
- package/providers/commercetools/src/providers/cart.provider.ts +281 -341
- package/providers/commercetools/src/providers/category.provider.ts +223 -138
- package/providers/commercetools/src/providers/checkout.provider.ts +631 -449
- package/providers/commercetools/src/providers/identity.provider.ts +50 -29
- package/providers/commercetools/src/providers/index.ts +2 -2
- package/providers/commercetools/src/providers/inventory.provider.ts +76 -74
- package/providers/commercetools/src/providers/order-search.provider.ts +220 -0
- package/providers/commercetools/src/providers/order.provider.ts +96 -61
- package/providers/commercetools/src/providers/price.provider.ts +147 -117
- package/providers/commercetools/src/providers/product-search.provider.ts +528 -0
- package/providers/commercetools/src/providers/product.provider.ts +249 -74
- package/providers/commercetools/src/providers/profile.provider.ts +445 -28
- package/providers/commercetools/src/providers/store.provider.ts +54 -40
- 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 +1 -1
- package/providers/commercetools/tsconfig.lib.json +1 -1
- package/providers/commercetools/tsconfig.spec.json +2 -14
- package/providers/commercetools/vitest.config.ts +15 -0
- package/providers/fake/README.md +20 -4
- package/providers/fake/package.json +2 -1
- package/providers/fake/src/core/initialize.ts +47 -49
- package/providers/fake/src/providers/analytics.provider.ts +5 -7
- package/providers/fake/src/providers/cart.provider.ts +163 -92
- package/providers/fake/src/providers/category.provider.ts +78 -50
- package/providers/fake/src/providers/checkout.provider.ts +254 -0
- package/providers/fake/src/providers/identity.provider.ts +57 -65
- package/providers/fake/src/providers/index.ts +6 -2
- package/providers/fake/src/providers/inventory.provider.ts +40 -36
- 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 +93 -41
- package/providers/fake/src/providers/product-search.provider.ts +206 -0
- package/providers/fake/src/providers/product.provider.ts +56 -41
- package/providers/fake/src/providers/profile.provider.ts +147 -0
- package/providers/fake/src/providers/store.provider.ts +30 -20
- package/providers/fake/src/schema/capabilities.schema.ts +5 -1
- package/providers/fake/src/test/cart.provider.spec.ts +59 -80
- package/providers/fake/src/test/category.provider.spec.ts +145 -87
- 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 +50 -45
- package/providers/fake/src/test/product.provider.spec.ts +15 -7
- package/providers/fake/src/test/profile.provider.spec.ts +167 -0
- package/providers/fake/tsconfig.json +1 -1
- package/providers/fake/tsconfig.lib.json +1 -1
- package/providers/fake/tsconfig.spec.json +2 -12
- package/providers/fake/vitest.config.ts +14 -0
- package/providers/medusa/README.md +30 -0
- package/providers/medusa/TESTING.md +98 -0
- package/providers/medusa/eslint.config.mjs +19 -0
- 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 +202 -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/providers/meilisearch/eslint.config.mjs +22 -0
- package/providers/meilisearch/package.json +13 -0
- package/providers/meilisearch/project.json +34 -0
- package/providers/meilisearch/src/core/initialize.ts +21 -0
- package/providers/meilisearch/src/index.ts +6 -0
- package/providers/meilisearch/src/providers/index.ts +1 -0
- package/providers/meilisearch/src/providers/order-search.provider.ts +222 -0
- package/providers/meilisearch/src/providers/product-search.provider.ts +251 -0
- package/providers/meilisearch/src/schema/capabilities.schema.ts +10 -0
- package/providers/meilisearch/src/schema/configuration.schema.ts +11 -0
- package/providers/meilisearch/src/schema/index.ts +3 -0
- package/providers/meilisearch/src/schema/search.schema.ts +14 -0
- package/providers/meilisearch/tsconfig.json +24 -0
- package/providers/meilisearch/tsconfig.lib.json +10 -0
- package/providers/meilisearch/tsconfig.spec.json +4 -0
- package/providers/meilisearch/vitest.config.ts +14 -0
- package/providers/posthog/package.json +2 -1
- package/providers/posthog/tsconfig.json +1 -1
- package/tsconfig.base.json +5 -0
- package/vitest.config.ts +10 -0
- package/core/src/providers/search.provider.ts +0 -18
- package/core/src/schemas/models/search.model.ts +0 -36
- 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 -31
- 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 -47
- 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/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.cjs +0 -10
- package/providers/commercetools/src/providers/search.provider.ts +0 -96
- 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.cjs +0 -10
- package/providers/fake/src/providers/search.provider.ts +0 -132
package/migrations.json
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"migrations": [
|
|
3
3
|
{
|
|
4
|
-
"version": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
4
|
+
"version": "22.2.0-beta.1",
|
|
5
|
+
"requires": { "vitest": ">=4.0.0" },
|
|
6
|
+
"description": "Create AI Instructions to help migrate users workspaces past breaking changes for Vitest 4.",
|
|
7
|
+
"implementation": "./src/migrations/update-22-2-0/create-ai-instructions-for-vitest-4",
|
|
8
|
+
"package": "@nx/vite",
|
|
9
|
+
"name": "update-22-2-0"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"version": "22.2.0-beta.2",
|
|
13
|
+
"description": "Migrate Vitest usage from @nx/vite to @nx/vitest package.",
|
|
14
|
+
"implementation": "./src/migrations/update-22-2-0/migrate-vitest-to-vitest-package",
|
|
15
|
+
"package": "@nx/vite",
|
|
16
|
+
"name": "migrate-vitest-to-vitest-package"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"cli": "nx",
|
|
20
|
+
"version": "22.2.0-beta.1",
|
|
21
|
+
"requires": { "next": ">=16.0.0" },
|
|
22
|
+
"description": "Create AI Instructions to help migrate users workspaces to Next.js 16.",
|
|
23
|
+
"factory": "./src/migrations/update-22-2-0/create-ai-instructions-for-next-16",
|
|
24
|
+
"package": "@nx/next",
|
|
25
|
+
"name": "update-22-2-0-create-ai-instructions-for-next-16"
|
|
9
26
|
}
|
|
10
27
|
]
|
|
11
28
|
}
|
package/nx.json
CHANGED
|
@@ -9,17 +9,12 @@
|
|
|
9
9
|
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
|
|
10
10
|
"!{projectRoot}/tsconfig.spec.json",
|
|
11
11
|
"!{projectRoot}/src/test-setup.[jt]s",
|
|
12
|
-
"!{projectRoot}/
|
|
13
|
-
"!{projectRoot}/
|
|
12
|
+
"!{projectRoot}/test-setup.[jt]s",
|
|
13
|
+
"!{projectRoot}/vitest.config.ts"
|
|
14
14
|
],
|
|
15
15
|
"sharedGlobals": ["{workspaceRoot}/.github/workflows/ci.yml"]
|
|
16
16
|
},
|
|
17
17
|
"targetDefaults": {
|
|
18
|
-
"@angular-devkit/build-angular:application": {
|
|
19
|
-
"cache": true,
|
|
20
|
-
"dependsOn": ["^build"],
|
|
21
|
-
"inputs": ["production", "^production"]
|
|
22
|
-
},
|
|
23
18
|
"@nx/eslint:lint": {
|
|
24
19
|
"cache": true,
|
|
25
20
|
"inputs": [
|
|
@@ -43,28 +38,6 @@
|
|
|
43
38
|
"inputs": ["production", "^production"]
|
|
44
39
|
}
|
|
45
40
|
},
|
|
46
|
-
"generators": {
|
|
47
|
-
"@nx/angular:application": {
|
|
48
|
-
"e2eTestRunner": "none",
|
|
49
|
-
"linter": "eslint",
|
|
50
|
-
"style": "scss",
|
|
51
|
-
"unitTestRunner": "jest"
|
|
52
|
-
},
|
|
53
|
-
"@nx/next": {
|
|
54
|
-
"application": {
|
|
55
|
-
"style": "scss",
|
|
56
|
-
"linter": "eslint"
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
"@nx/angular:component": {
|
|
60
|
-
"style": "scss",
|
|
61
|
-
"displayBlock": true,
|
|
62
|
-
"skipTests": true,
|
|
63
|
-
"standalone": true,
|
|
64
|
-
"changeDetection": "OnPush",
|
|
65
|
-
"viewEncapsulation": "ShadowDom"
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
41
|
"release": {
|
|
69
42
|
"projectsRelationship": "fixed",
|
|
70
43
|
"git": {
|
|
@@ -89,34 +62,16 @@
|
|
|
89
62
|
"targetName": "lint"
|
|
90
63
|
}
|
|
91
64
|
},
|
|
92
|
-
{
|
|
93
|
-
"plugin": "@nx/jest/plugin",
|
|
94
|
-
"options": {
|
|
95
|
-
"targetName": "test"
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
65
|
{
|
|
99
66
|
"plugin": "@nx/playwright/plugin",
|
|
100
67
|
"options": {
|
|
101
68
|
"targetName": "e2e"
|
|
102
69
|
}
|
|
103
70
|
},
|
|
104
|
-
{
|
|
105
|
-
"plugin": "@nx/next/plugin",
|
|
106
|
-
"options": {
|
|
107
|
-
"startTargetName": "start",
|
|
108
|
-
"buildTargetName": "build",
|
|
109
|
-
"devTargetName": "dev",
|
|
110
|
-
"serveStaticTargetName": "serve-static",
|
|
111
|
-
"buildDepsTargetName": "build-deps",
|
|
112
|
-
"watchDepsTargetName": "watch-deps"
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
71
|
{
|
|
116
72
|
"plugin": "@nx/vite/plugin",
|
|
117
73
|
"options": {
|
|
118
74
|
"buildTargetName": "build",
|
|
119
|
-
"testTargetName": "test",
|
|
120
75
|
"serveTargetName": "serve",
|
|
121
76
|
"devTargetName": "dev",
|
|
122
77
|
"previewTargetName": "preview",
|
|
@@ -125,6 +80,12 @@
|
|
|
125
80
|
"buildDepsTargetName": "build-deps",
|
|
126
81
|
"watchDepsTargetName": "watch-deps"
|
|
127
82
|
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"plugin": "@nx/vitest",
|
|
86
|
+
"options": {
|
|
87
|
+
"testTargetName": "test"
|
|
88
|
+
}
|
|
128
89
|
}
|
|
129
90
|
],
|
|
130
91
|
"nxCloudId": "683eb2fef42fbc631b8c5f05"
|
package/package.json
CHANGED
|
@@ -1,130 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/source",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"private": false,
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@angular/common": "~19.2.0",
|
|
8
|
-
"@angular/compiler": "~19.2.0",
|
|
9
|
-
"@angular/core": "~19.2.0",
|
|
10
|
-
"@angular/forms": "~19.2.0",
|
|
11
|
-
"@angular/platform-browser": "~19.2.0",
|
|
12
|
-
"@angular/platform-browser-dynamic": "~19.2.0",
|
|
13
|
-
"@angular/router": "~19.2.0",
|
|
14
7
|
"@commercetools/platform-sdk": "^8.16.0",
|
|
15
8
|
"@commercetools/ts-client": "^4.2.1",
|
|
16
|
-
"@commercetools/ts-sdk-apm": "^4.0.0",
|
|
17
9
|
"@faker-js/faker": "^9.8.0",
|
|
10
|
+
"@medusajs/js-sdk": "^2.13.0",
|
|
18
11
|
"@opentelemetry/api": "^1.9.0",
|
|
19
12
|
"@opentelemetry/core": "^2.0.1",
|
|
20
|
-
"@opentelemetry/exporter-metrics-otlp-http": "^0.203.0",
|
|
21
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
|
|
22
|
-
"@opentelemetry/instrumentation": "^0.203.0",
|
|
23
|
-
"@opentelemetry/instrumentation-express": "^0.52.0",
|
|
24
|
-
"@opentelemetry/instrumentation-http": "^0.203.0",
|
|
25
|
-
"@opentelemetry/resources": "^2.0.1",
|
|
26
|
-
"@opentelemetry/sdk-metrics": "^2.0.1",
|
|
27
|
-
"@opentelemetry/sdk-node": "^0.203.0",
|
|
28
13
|
"@opentelemetry/sdk-trace-base": "^2.0.1",
|
|
29
14
|
"@opentelemetry/sdk-trace-node": "^2.0.1",
|
|
30
|
-
"@opentelemetry/semantic-conventions": "^1.36.0",
|
|
31
|
-
"@trpc/client": "^11.1.2",
|
|
32
|
-
"@trpc/server": "^11.1.2",
|
|
33
15
|
"@upstash/redis": "^1.34.9",
|
|
34
16
|
"algoliasearch": "^5.23.4",
|
|
35
|
-
"connect-redis": "^8.1.0",
|
|
36
|
-
"cors": "^2.8.5",
|
|
37
17
|
"debug": "^4.4.3",
|
|
38
18
|
"dotenv": "^17.2.2",
|
|
39
|
-
"
|
|
40
|
-
"express-session": "^1.18.1",
|
|
41
|
-
"ioredis": "^5.6.1",
|
|
42
|
-
"next": "~15.2.4",
|
|
19
|
+
"meilisearch": "^0.55.0",
|
|
43
20
|
"node-object-hash": "^3.1.1",
|
|
44
|
-
"posthog-node": "^
|
|
45
|
-
"react": "19.0.0",
|
|
46
|
-
"react-dom": "19.0.0",
|
|
47
|
-
"reflect-metadata": "^0.2.2",
|
|
48
|
-
"rxjs": "~7.8.0",
|
|
21
|
+
"posthog-node": "^5.24.0",
|
|
49
22
|
"search-insights": "^2.17.3",
|
|
50
|
-
"
|
|
51
|
-
"vue": "^3.5.13",
|
|
52
|
-
"zod": "4.1.9",
|
|
53
|
-
"zone.js": "~0.15.0"
|
|
23
|
+
"zod": "4.1.9"
|
|
54
24
|
},
|
|
55
25
|
"devDependencies": {
|
|
56
|
-
"@angular-devkit/build-angular": "~19.2.0",
|
|
57
|
-
"@angular-devkit/core": "~19.2.0",
|
|
58
|
-
"@angular-devkit/schematics": "~19.2.0",
|
|
59
|
-
"@angular/cli": "~19.2.0",
|
|
60
|
-
"@angular/compiler-cli": "~19.2.0",
|
|
61
|
-
"@angular/language-service": "~19.2.0",
|
|
62
26
|
"@eslint/compat": "^1.1.1",
|
|
63
27
|
"@eslint/eslintrc": "^2.1.1",
|
|
64
28
|
"@eslint/js": "^9.8.0",
|
|
65
|
-
"@
|
|
66
|
-
"@nx/
|
|
67
|
-
"@nx/
|
|
68
|
-
"@nx/
|
|
69
|
-
"@nx/eslint": "
|
|
70
|
-
"@nx/
|
|
71
|
-
"@nx/
|
|
72
|
-
"@nx/
|
|
73
|
-
"@nx/
|
|
74
|
-
"@nx/
|
|
75
|
-
"@nx/
|
|
76
|
-
"@nx/vite": "21.1.2",
|
|
77
|
-
"@nx/vue": "21.1.2",
|
|
78
|
-
"@nx/web": "21.1.2",
|
|
79
|
-
"@nx/workspace": "21.1.2",
|
|
80
|
-
"@playwright/test": "^1.36.0",
|
|
81
|
-
"@schematics/angular": "~19.2.0",
|
|
29
|
+
"@medusajs/types": "^2.11.0",
|
|
30
|
+
"@nx/devkit": "22.4.5",
|
|
31
|
+
"@nx/esbuild": "22.4.5",
|
|
32
|
+
"@nx/eslint": "22.4.5",
|
|
33
|
+
"@nx/eslint-plugin": "22.4.5",
|
|
34
|
+
"@nx/js": "22.4.5",
|
|
35
|
+
"@nx/node": "22.4.5",
|
|
36
|
+
"@nx/playwright": "22.4.5",
|
|
37
|
+
"@nx/vite": "22.4.5",
|
|
38
|
+
"@nx/vitest": "22.4.5",
|
|
39
|
+
"@nx/workspace": "22.4.5",
|
|
82
40
|
"@swc-node/register": "~1.9.1",
|
|
83
41
|
"@swc/cli": "~0.6.0",
|
|
84
42
|
"@swc/core": "~1.5.7",
|
|
85
43
|
"@swc/helpers": "~0.5.11",
|
|
86
44
|
"@types/debug": "^4.1.12",
|
|
87
|
-
"@types/
|
|
88
|
-
"@
|
|
89
|
-
"
|
|
90
|
-
"@types/react-dom": "19.0.0",
|
|
91
|
-
"@typescript-eslint/utils": "^8.19.0",
|
|
92
|
-
"@vitejs/plugin-vue": "^5.2.3",
|
|
93
|
-
"@vitest/coverage-v8": "^3.0.5",
|
|
94
|
-
"@vitest/ui": "^3.0.0",
|
|
95
|
-
"@vue/eslint-config-prettier": "7.1.0",
|
|
96
|
-
"@vue/eslint-config-typescript": "^11.0.3",
|
|
97
|
-
"@vue/test-utils": "^2.4.6",
|
|
98
|
-
"angular-eslint": "^19.2.0",
|
|
99
|
-
"esbuild": "^0.19.2",
|
|
100
|
-
"eslint": "^9.8.0",
|
|
101
|
-
"eslint-config-next": "^15.2.4",
|
|
102
|
-
"eslint-config-prettier": "^10.0.0",
|
|
103
|
-
"eslint-plugin-import": "2.31.0",
|
|
104
|
-
"eslint-plugin-jsx-a11y": "6.10.1",
|
|
105
|
-
"eslint-plugin-playwright": "^1.6.2",
|
|
106
|
-
"eslint-plugin-react": "7.35.0",
|
|
107
|
-
"eslint-plugin-react-hooks": "5.0.0",
|
|
108
|
-
"eslint-plugin-vue": "^9.16.1",
|
|
109
|
-
"jest": "^29.7.0",
|
|
110
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
111
|
-
"jest-environment-node": "^29.7.0",
|
|
112
|
-
"jest-preset-angular": "~14.4.0",
|
|
113
|
-
"jiti": "2.4.2",
|
|
114
|
-
"jsdom": "~22.1.0",
|
|
115
|
-
"jsonc-eslint-parser": "^2.1.0",
|
|
116
|
-
"nx": "21.1.2",
|
|
45
|
+
"@types/node": "^24.0.0",
|
|
46
|
+
"@typescript-eslint/utils": "^8.33.1",
|
|
47
|
+
"nx": "22.4.5",
|
|
117
48
|
"prettier": "^2.6.2",
|
|
118
|
-
"sass": "1.62.1",
|
|
119
|
-
"ts-jest": "^29.1.0",
|
|
120
49
|
"ts-node": "10.9.1",
|
|
121
50
|
"tslib": "^2.3.0",
|
|
122
|
-
"typescript": "
|
|
123
|
-
"typescript-eslint": "^8.
|
|
124
|
-
"
|
|
125
|
-
"vite": "^
|
|
126
|
-
"vitest": "^
|
|
127
|
-
"vue-tsc": "^2.2.8"
|
|
51
|
+
"typescript": "5.9.3",
|
|
52
|
+
"typescript-eslint": "^8.33.1",
|
|
53
|
+
"vite": "7.1.9",
|
|
54
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
55
|
+
"vitest": "^4.0.9"
|
|
128
56
|
},
|
|
129
57
|
"nx": {
|
|
130
58
|
"includedScripts": []
|
|
@@ -1,6 +1,43 @@
|
|
|
1
|
-
# provider
|
|
1
|
+
# Algolia provider for Reactionary
|
|
2
|
+
|
|
3
|
+
## Supports
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
| Feature | Support | Notes |
|
|
7
|
+
| ----------- | ----------- | --------- |
|
|
8
|
+
| product | Full | |
|
|
9
|
+
| productSearch | Full | |
|
|
10
|
+
| identity | N/A | |
|
|
11
|
+
| cart | N/A | |
|
|
12
|
+
| checkout | N/A | |
|
|
13
|
+
| order | N/A | Possibly later |
|
|
14
|
+
| inventory | N/A | |
|
|
15
|
+
| price | N/A | |
|
|
16
|
+
| category | N/A | Possibly later |
|
|
17
|
+
| store | N/A | Possibly later |
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Notes
|
|
21
|
+
The expected Algolia schema must contain at least these fields
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
objectID: string;
|
|
26
|
+
slug:string;
|
|
27
|
+
name: string;
|
|
28
|
+
variants: [
|
|
29
|
+
{
|
|
30
|
+
variantID: string;
|
|
31
|
+
image: string;
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
You can have more, for use with facets, and additional searchable fields, but these must be in the index, and constitutes what we are expecting to get back.
|
|
38
|
+
|
|
39
|
+
The `objectID` corrosponds to your productIdentifier, and `variantID` should match your SKU
|
|
2
40
|
|
|
3
|
-
This library was generated with [Nx](https://nx.dev).
|
|
4
41
|
|
|
5
42
|
## Building
|
|
6
43
|
|
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import { AlgoliaProductProvider } from "../providers/product.provider.js";
|
|
4
|
-
import { AlgoliaSearchProvider } from "../providers/search.provider.js";
|
|
1
|
+
import type { Cache, ClientFromCapabilities, RequestContext } from "@reactionary/core";
|
|
2
|
+
import { AlgoliaSearchProvider } from "../providers/product-search.provider.js";
|
|
5
3
|
import type { AlgoliaCapabilities } from "../schema/capabilities.schema.js";
|
|
6
4
|
import type { AlgoliaConfiguration } from "../schema/configuration.schema.js";
|
|
7
|
-
import { AlgoliaSearchResultSchema } from "../schema/search.schema.js";
|
|
8
5
|
|
|
9
|
-
export function withAlgoliaCapabilities(configuration: AlgoliaConfiguration, capabilities:
|
|
10
|
-
return (cache: Cache) => {
|
|
11
|
-
const client:
|
|
6
|
+
export function withAlgoliaCapabilities<T extends AlgoliaCapabilities>(configuration: AlgoliaConfiguration, capabilities: T) {
|
|
7
|
+
return (cache: Cache, context: RequestContext): ClientFromCapabilities<T> => {
|
|
8
|
+
const client: any = {};
|
|
12
9
|
|
|
13
|
-
if (capabilities.
|
|
14
|
-
client.
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (capabilities.search) {
|
|
18
|
-
client.search = new AlgoliaSearchProvider(configuration, AlgoliaSearchResultSchema, cache);
|
|
10
|
+
if (capabilities.productSearch) {
|
|
11
|
+
client.productSearch = new AlgoliaSearchProvider(configuration, cache, context);
|
|
19
12
|
}
|
|
20
13
|
|
|
21
14
|
return client;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export * from './core/initialize.js';
|
|
2
|
-
|
|
3
|
-
export * from './providers/product.provider.js';
|
|
4
|
-
export * from './providers/search.provider.js';
|
|
2
|
+
export * from './providers/product-search.provider.js';
|
|
5
3
|
|
|
6
4
|
export * from './schema/configuration.schema.js';
|
|
7
|
-
export * from './schema/capabilities.schema.js';
|
|
5
|
+
export * from './schema/capabilities.schema.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './product-search.provider.js';
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Cache,
|
|
3
|
+
type FacetIdentifier,
|
|
4
|
+
FacetIdentifierSchema,
|
|
5
|
+
type FacetValueIdentifier,
|
|
6
|
+
FacetValueIdentifierSchema,
|
|
7
|
+
ImageSchema,
|
|
8
|
+
ProductSearchProvider,
|
|
9
|
+
type ProductSearchQueryByTerm,
|
|
10
|
+
ProductSearchQueryByTermSchema,
|
|
11
|
+
type ProductSearchQueryCreateNavigationFilter,
|
|
12
|
+
type ProductSearchResult,
|
|
13
|
+
type ProductSearchResultFacet,
|
|
14
|
+
ProductSearchResultFacetSchema,
|
|
15
|
+
type ProductSearchResultFacetValue,
|
|
16
|
+
ProductSearchResultFacetValueSchema,
|
|
17
|
+
type ProductSearchResultItem,
|
|
18
|
+
type ProductSearchResultItemVariant,
|
|
19
|
+
ProductSearchResultItemVariantSchema,
|
|
20
|
+
ProductSearchResultSchema,
|
|
21
|
+
Reactionary,
|
|
22
|
+
type RequestContext,
|
|
23
|
+
type Result,
|
|
24
|
+
success
|
|
25
|
+
} from '@reactionary/core';
|
|
26
|
+
import { algoliasearch, type SearchResponse } from 'algoliasearch';
|
|
27
|
+
import type { AlgoliaConfiguration } from '../schema/configuration.schema.js';
|
|
28
|
+
import type { AlgoliaProductSearchResult } from '../schema/search.schema.js';
|
|
29
|
+
|
|
30
|
+
interface AlgoliaNativeVariant {
|
|
31
|
+
sku: string;
|
|
32
|
+
image: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface AlgoliaNativeRecord {
|
|
36
|
+
objectID: string;
|
|
37
|
+
slug?:string;
|
|
38
|
+
name?: string;
|
|
39
|
+
variants: Array<AlgoliaNativeVariant>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export class AlgoliaSearchProvider extends ProductSearchProvider {
|
|
44
|
+
protected config: AlgoliaConfiguration;
|
|
45
|
+
|
|
46
|
+
constructor(config: AlgoliaConfiguration, cache: Cache, context: RequestContext) {
|
|
47
|
+
super(cache, context);
|
|
48
|
+
this.config = config;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Reactionary({
|
|
52
|
+
inputSchema: ProductSearchQueryByTermSchema,
|
|
53
|
+
outputSchema: ProductSearchResultSchema
|
|
54
|
+
})
|
|
55
|
+
public override async queryByTerm(
|
|
56
|
+
payload: ProductSearchQueryByTerm
|
|
57
|
+
): Promise<Result<ProductSearchResult>> {
|
|
58
|
+
const client = algoliasearch(this.config.appId, this.config.apiKey);
|
|
59
|
+
|
|
60
|
+
const facetsThatAreNotCategory = payload.search.facets.filter(x => x.facet.key !== 'categories');
|
|
61
|
+
const categoryFacet = payload.search.facets.find(x => x.facet.key === 'categories') || payload.search.categoryFilter;
|
|
62
|
+
|
|
63
|
+
const finalFilters = [...payload.search.filters || []];
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
const finalFacetFilters = [
|
|
67
|
+
...facetsThatAreNotCategory.map(
|
|
68
|
+
(x) => `${x.facet.key}:${x.key}`
|
|
69
|
+
),
|
|
70
|
+
]
|
|
71
|
+
if (categoryFacet) {
|
|
72
|
+
finalFilters.push(`categories:"${categoryFacet.key}"`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
const remote = await client.search<AlgoliaNativeRecord>({
|
|
77
|
+
requests: [
|
|
78
|
+
{
|
|
79
|
+
indexName: this.config.indexName,
|
|
80
|
+
query: payload.search.term,
|
|
81
|
+
page: payload.search.paginationOptions.pageNumber - 1,
|
|
82
|
+
hitsPerPage: payload.search.paginationOptions.pageSize,
|
|
83
|
+
facets: ['*'],
|
|
84
|
+
analytics: true,
|
|
85
|
+
clickAnalytics: true,
|
|
86
|
+
facetFilters: finalFacetFilters,
|
|
87
|
+
filters: (finalFilters || [])
|
|
88
|
+
.join(' AND '),
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const input = remote.results[0] as SearchResponse<AlgoliaNativeRecord>;
|
|
94
|
+
const result = this.parsePaginatedResult(input, payload) as AlgoliaProductSearchResult;
|
|
95
|
+
|
|
96
|
+
// mark selected facets as active
|
|
97
|
+
for(const selectedFacet of payload.search.facets) {
|
|
98
|
+
const facet = result.facets.find((f) => f.identifier.key === selectedFacet.facet.key);
|
|
99
|
+
if(facet) {
|
|
100
|
+
const value = facet.values.find((v) => v.identifier.key === selectedFacet.key);
|
|
101
|
+
if(value) {
|
|
102
|
+
value.active = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return success(result);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public override async createCategoryNavigationFilter(payload: ProductSearchQueryCreateNavigationFilter): Promise<Result<FacetValueIdentifier>> {
|
|
111
|
+
|
|
112
|
+
const facetIdentifier = FacetIdentifierSchema.parse({
|
|
113
|
+
key: 'categories'
|
|
114
|
+
});
|
|
115
|
+
const facetValueIdentifier = FacetValueIdentifierSchema.parse({
|
|
116
|
+
facet: facetIdentifier,
|
|
117
|
+
key: payload.categoryPath.map(c => c.name).join(' > ')
|
|
118
|
+
});
|
|
119
|
+
return success(facetValueIdentifier);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
protected parseSingle(body: AlgoliaNativeRecord) {
|
|
124
|
+
const product = {
|
|
125
|
+
identifier: { key: body.objectID },
|
|
126
|
+
name: body.name || body.objectID,
|
|
127
|
+
slug: body.slug || body.objectID,
|
|
128
|
+
variants: [ ... (body.variants || []) ].map(variant => this.parseVariant(variant, body)),
|
|
129
|
+
} satisfies ProductSearchResultItem;
|
|
130
|
+
|
|
131
|
+
return product;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
protected override parseVariant(variant: AlgoliaNativeVariant, product: AlgoliaNativeRecord): ProductSearchResultItemVariant {
|
|
135
|
+
const result = ProductSearchResultItemVariantSchema.parse({
|
|
136
|
+
variant: {
|
|
137
|
+
sku: variant.sku
|
|
138
|
+
},
|
|
139
|
+
image: ImageSchema.parse({
|
|
140
|
+
sourceUrl: variant.image,
|
|
141
|
+
altText: product.name || '',
|
|
142
|
+
})
|
|
143
|
+
} satisfies Partial<ProductSearchResultItemVariant>);
|
|
144
|
+
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
protected parsePaginatedResult(body: SearchResponse<AlgoliaNativeRecord>, query: ProductSearchQueryByTerm) {
|
|
149
|
+
const items = body.hits.map((hit) => this.parseSingle(hit));
|
|
150
|
+
let facets: ProductSearchResultFacet[] = [];
|
|
151
|
+
for (const id in body.facets) {
|
|
152
|
+
const f = body.facets[id];
|
|
153
|
+
const facetId = FacetIdentifierSchema.parse({
|
|
154
|
+
key: id
|
|
155
|
+
})
|
|
156
|
+
const facet = this.parseFacet(facetId, f);
|
|
157
|
+
facets.push(facet);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
// we do something to convert the hierachy.lvl.n facet values into something more usable
|
|
162
|
+
const selectedCategoryFacet = query.search.facets.find(x => x.facet.key === 'categories') || query.search.categoryFilter;
|
|
163
|
+
let subCategoryFacet;
|
|
164
|
+
if(selectedCategoryFacet) {
|
|
165
|
+
const valueDepth = selectedCategoryFacet.key.split(' > ').length;
|
|
166
|
+
// ok, so input defined a facet value from level X, we return hierarchy.lvl.(X+1) as subcategories.
|
|
167
|
+
// hierarchy counts from 0, so length is already pointing to 'lvl.(X+1)'
|
|
168
|
+
subCategoryFacet = facets.find(f => f.identifier.key === `hierarchy.lvl${valueDepth}`);
|
|
169
|
+
} else {
|
|
170
|
+
// and remap lvl0 to 'categories'
|
|
171
|
+
subCategoryFacet = facets.find(f => f.identifier.key === 'hierarchy.lvl0');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if(subCategoryFacet) {
|
|
175
|
+
// remap to 'categories' facet
|
|
176
|
+
subCategoryFacet.identifier = FacetIdentifierSchema.parse({
|
|
177
|
+
key: 'categories'
|
|
178
|
+
});
|
|
179
|
+
subCategoryFacet.name = 'Categories';
|
|
180
|
+
for(const v of subCategoryFacet.values) {
|
|
181
|
+
const pathParts = v.identifier.key.split(' > ');
|
|
182
|
+
v.identifier.facet = subCategoryFacet.identifier;
|
|
183
|
+
v.name = pathParts[pathParts.length -1];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// remove other hierarchy facets
|
|
188
|
+
facets = facets.filter(f => !f.identifier.key.startsWith('hierarchy.lvl'));
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
const result = {
|
|
193
|
+
identifier: {
|
|
194
|
+
term: query.search.term,
|
|
195
|
+
facets: query.search.facets,
|
|
196
|
+
filters: query.search.filters,
|
|
197
|
+
paginationOptions: query.search.paginationOptions,
|
|
198
|
+
|
|
199
|
+
},
|
|
200
|
+
pageNumber: (body.page || 0) + 1,
|
|
201
|
+
pageSize: body.hitsPerPage || 0,
|
|
202
|
+
totalCount: body.nbHits || 0,
|
|
203
|
+
totalPages: body.nbPages || 0,
|
|
204
|
+
items: items,
|
|
205
|
+
facets,
|
|
206
|
+
} satisfies ProductSearchResult;
|
|
207
|
+
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
protected parseFacet(facetIdentifier: FacetIdentifier, facetValues: Record<string, number>) : ProductSearchResultFacet {
|
|
212
|
+
const result: ProductSearchResultFacet = ProductSearchResultFacetSchema.parse({
|
|
213
|
+
identifier: facetIdentifier,
|
|
214
|
+
name: facetIdentifier.key,
|
|
215
|
+
values: []
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
for (const vid in facetValues) {
|
|
219
|
+
const fv = facetValues[vid];
|
|
220
|
+
|
|
221
|
+
const facetValueIdentifier = FacetValueIdentifierSchema.parse({
|
|
222
|
+
facet: facetIdentifier,
|
|
223
|
+
key: vid
|
|
224
|
+
} satisfies Partial<FacetValueIdentifier>);
|
|
225
|
+
|
|
226
|
+
result.values.push(this.parseFacetValue(facetValueIdentifier, vid, fv));
|
|
227
|
+
}
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
protected parseFacetValue(facetValueIdentifier: FacetValueIdentifier, label: string, count: number) : ProductSearchResultFacetValue {
|
|
232
|
+
return ProductSearchResultFacetValueSchema.parse({
|
|
233
|
+
identifier: facetValueIdentifier,
|
|
234
|
+
name: label,
|
|
235
|
+
count: count,
|
|
236
|
+
active: false,
|
|
237
|
+
} satisfies Partial<ProductSearchResultFacetValue>);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
}
|
|
@@ -2,9 +2,8 @@ import { CapabilitiesSchema } from "@reactionary/core";
|
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
export const AlgoliaCapabilitiesSchema = CapabilitiesSchema.pick({
|
|
5
|
-
|
|
6
|
-
search: true,
|
|
5
|
+
productSearch: true,
|
|
7
6
|
analytics: true
|
|
8
7
|
}).partial();
|
|
9
8
|
|
|
10
|
-
export type AlgoliaCapabilities = z.infer<typeof AlgoliaCapabilitiesSchema>;
|
|
9
|
+
export type AlgoliaCapabilities = z.infer<typeof AlgoliaCapabilitiesSchema>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProductSearchIdentifierSchema, ProductSearchResultSchema } from '@reactionary/core';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
-
export const
|
|
5
|
-
key: z.string()
|
|
6
|
-
index: z.string()
|
|
4
|
+
export const AlgoliaProductSearchIdentifierSchema = ProductSearchIdentifierSchema.extend({
|
|
5
|
+
key: z.string(),
|
|
6
|
+
index: z.string(),
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
export const
|
|
10
|
-
identifier:
|
|
9
|
+
export const AlgoliaProductSearchResultSchema = ProductSearchResultSchema.extend({
|
|
10
|
+
identifier: AlgoliaProductSearchIdentifierSchema.default(() => AlgoliaProductSearchIdentifierSchema.parse({}))
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
export type
|
|
14
|
-
export type
|
|
13
|
+
export type AlgoliaProductSearchResult = z.infer<typeof AlgoliaProductSearchResultSchema>;
|
|
14
|
+
export type AlgoliaProductSearchIdentifier = z.infer<typeof AlgoliaProductSearchIdentifierSchema>;
|