@reactionary/provider-algolia 0.0.61 → 0.0.63
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/core/initialize.js +3 -8
- package/index.js +0 -1
- package/package.json +2 -2
- package/providers/index.js +0 -1
- package/providers/product-search.provider.js +13 -13
- package/schema/capabilities.schema.js +0 -1
- package/src/core/initialize.d.ts +6 -2
- package/src/index.d.ts +0 -1
- package/src/providers/index.d.ts +0 -1
- package/src/providers/product-search.provider.d.ts +7 -7
- package/src/schema/capabilities.schema.d.ts +0 -1
- package/providers/product.provider.js +0 -39
- package/src/providers/product.provider.d.ts +0 -11
package/core/initialize.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AlgoliaProductProvider } from "../providers/product.provider.js";
|
|
1
|
+
import { ProductSearchResultItemSchema } from "@reactionary/core";
|
|
3
2
|
import { AlgoliaSearchProvider } from "../providers/product-search.provider.js";
|
|
4
|
-
import { AlgoliaSearchResultSchema } from "../schema/search.schema.js";
|
|
5
3
|
function withAlgoliaCapabilities(configuration, capabilities) {
|
|
6
|
-
return (cache) => {
|
|
4
|
+
return (cache, context) => {
|
|
7
5
|
const client = {};
|
|
8
|
-
if (capabilities.product) {
|
|
9
|
-
client.product = new AlgoliaProductProvider(configuration, ProductSchema, cache);
|
|
10
|
-
}
|
|
11
6
|
if (capabilities.productSearch) {
|
|
12
|
-
client.productSearch = new AlgoliaSearchProvider(configuration, ProductSearchResultItemSchema, cache);
|
|
7
|
+
client.productSearch = new AlgoliaSearchProvider(configuration, ProductSearchResultItemSchema, cache, context);
|
|
13
8
|
}
|
|
14
9
|
return client;
|
|
15
10
|
};
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-algolia",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.63",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.0.
|
|
7
|
+
"@reactionary/core": "0.0.63",
|
|
8
8
|
"algoliasearch": "^5.23.4",
|
|
9
9
|
"zod": "4.1.9"
|
|
10
10
|
},
|
package/providers/index.js
CHANGED
|
@@ -11,11 +11,11 @@ import {
|
|
|
11
11
|
import { algoliasearch } from "algoliasearch";
|
|
12
12
|
import { AlgoliaSearchIdentifierSchema } from "../schema/search.schema.js";
|
|
13
13
|
class AlgoliaSearchProvider extends ProductSearchProvider {
|
|
14
|
-
constructor(config, schema, cache) {
|
|
15
|
-
super(schema, cache);
|
|
14
|
+
constructor(config, schema, cache, context) {
|
|
15
|
+
super(schema, cache, context);
|
|
16
16
|
this.config = config;
|
|
17
17
|
}
|
|
18
|
-
async queryByTerm(payload
|
|
18
|
+
async queryByTerm(payload) {
|
|
19
19
|
const client = algoliasearch(this.config.appId, this.config.apiKey);
|
|
20
20
|
const remote = await client.search({
|
|
21
21
|
requests: [
|
|
@@ -40,7 +40,7 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
|
|
|
40
40
|
index: input.index,
|
|
41
41
|
key: input.queryID
|
|
42
42
|
});
|
|
43
|
-
const result = this.parsePaginatedResult(input
|
|
43
|
+
const result = this.parsePaginatedResult(input);
|
|
44
44
|
result.identifier = identifier;
|
|
45
45
|
for (const selectedFacet of payload.search.facets) {
|
|
46
46
|
const facet = result.facets.find((f) => f.identifier.key === selectedFacet.facet.key);
|
|
@@ -57,15 +57,15 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
|
|
|
57
57
|
};
|
|
58
58
|
return result;
|
|
59
59
|
}
|
|
60
|
-
parseSingle(body
|
|
60
|
+
parseSingle(body) {
|
|
61
61
|
const product = this.newModel();
|
|
62
62
|
product.identifier = { key: body.objectID };
|
|
63
63
|
product.name = body.name || body.objectID;
|
|
64
64
|
product.slug = body.slug || body.objectID;
|
|
65
|
-
product.variants = [...body.variants || []].map((variant) => this.parseVariant(variant, body
|
|
65
|
+
product.variants = [...body.variants || []].map((variant) => this.parseVariant(variant, body));
|
|
66
66
|
return this.assert(product);
|
|
67
67
|
}
|
|
68
|
-
parseVariant(variant, product
|
|
68
|
+
parseVariant(variant, product) {
|
|
69
69
|
const result = ProductSearchResultItemVariantSchema.parse({
|
|
70
70
|
variant: {
|
|
71
71
|
sku: variant.variantID
|
|
@@ -77,15 +77,15 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
|
|
|
77
77
|
});
|
|
78
78
|
return result;
|
|
79
79
|
}
|
|
80
|
-
parsePaginatedResult(body
|
|
81
|
-
const items = body.hits.map((hit) => this.parseSingle(hit
|
|
80
|
+
parsePaginatedResult(body) {
|
|
81
|
+
const items = body.hits.map((hit) => this.parseSingle(hit));
|
|
82
82
|
const facets = [];
|
|
83
83
|
for (const id in body.facets) {
|
|
84
84
|
const f = body.facets[id];
|
|
85
85
|
const facetId = FacetIdentifierSchema.parse({
|
|
86
86
|
key: id
|
|
87
87
|
});
|
|
88
|
-
const facet = this.parseFacet(facetId, f
|
|
88
|
+
const facet = this.parseFacet(facetId, f);
|
|
89
89
|
facets.push(facet);
|
|
90
90
|
}
|
|
91
91
|
const result = createPaginatedResponseSchema(this.schema).parse({
|
|
@@ -102,7 +102,7 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
|
|
|
102
102
|
result.facets = facets;
|
|
103
103
|
return result;
|
|
104
104
|
}
|
|
105
|
-
parseFacet(facetIdentifier, facetValues
|
|
105
|
+
parseFacet(facetIdentifier, facetValues) {
|
|
106
106
|
const result = ProductSearchResultFacetSchema.parse({
|
|
107
107
|
identifier: facetIdentifier,
|
|
108
108
|
name: facetIdentifier.key,
|
|
@@ -114,11 +114,11 @@ class AlgoliaSearchProvider extends ProductSearchProvider {
|
|
|
114
114
|
facet: facetIdentifier,
|
|
115
115
|
key: vid
|
|
116
116
|
});
|
|
117
|
-
result.values.push(this.parseFacetValue(facetValueIdentifier, vid, fv
|
|
117
|
+
result.values.push(this.parseFacetValue(facetValueIdentifier, vid, fv));
|
|
118
118
|
}
|
|
119
119
|
return result;
|
|
120
120
|
}
|
|
121
|
-
parseFacetValue(facetValueIdentifier, label, count
|
|
121
|
+
parseFacetValue(facetValueIdentifier, label, count) {
|
|
122
122
|
return ProductSearchResultFacetValueSchema.parse({
|
|
123
123
|
identifier: facetValueIdentifier,
|
|
124
124
|
name: label,
|
package/src/core/initialize.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Cache, ProductSearchProvider, RequestContext } from "@reactionary/core";
|
|
2
2
|
import type { AlgoliaCapabilities } from "../schema/capabilities.schema.js";
|
|
3
3
|
import type { AlgoliaConfiguration } from "../schema/configuration.schema.js";
|
|
4
|
-
|
|
4
|
+
type AlgoliaClient<T extends AlgoliaCapabilities> = (T['productSearch'] extends true ? {
|
|
5
|
+
productSearch: ProductSearchProvider;
|
|
6
|
+
} : object);
|
|
7
|
+
export declare function withAlgoliaCapabilities<T extends AlgoliaCapabilities>(configuration: AlgoliaConfiguration, capabilities: T): (cache: Cache, context: RequestContext) => AlgoliaClient<T>;
|
|
8
|
+
export {};
|
package/src/index.d.ts
CHANGED
package/src/providers/index.d.ts
CHANGED
|
@@ -14,11 +14,11 @@ interface AlgoliaNativeRecord {
|
|
|
14
14
|
}
|
|
15
15
|
export declare class AlgoliaSearchProvider<T extends ProductSearchResultItem = ProductSearchResultItem> extends ProductSearchProvider<T> {
|
|
16
16
|
protected config: AlgoliaConfiguration;
|
|
17
|
-
constructor(config: AlgoliaConfiguration, schema: z.ZodType<T>, cache: Cache);
|
|
18
|
-
queryByTerm(payload: ProductSearchQueryByTerm
|
|
19
|
-
protected parseSingle(body: AlgoliaNativeRecord
|
|
20
|
-
protected parseVariant(variant: AlgoliaNativeVariant, product: AlgoliaNativeRecord
|
|
21
|
-
protected parsePaginatedResult(body: SearchResponse<AlgoliaNativeRecord
|
|
17
|
+
constructor(config: AlgoliaConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext);
|
|
18
|
+
queryByTerm(payload: ProductSearchQueryByTerm): Promise<ProductSearchResult>;
|
|
19
|
+
protected parseSingle(body: AlgoliaNativeRecord): T;
|
|
20
|
+
protected parseVariant(variant: AlgoliaNativeVariant, product: AlgoliaNativeRecord): ProductSearchResultItemVariant;
|
|
21
|
+
protected parsePaginatedResult(body: SearchResponse<AlgoliaNativeRecord>): {
|
|
22
22
|
meta: {
|
|
23
23
|
[x: string]: unknown;
|
|
24
24
|
cache: {
|
|
@@ -34,7 +34,7 @@ export declare class AlgoliaSearchProvider<T extends ProductSearchResultItem = P
|
|
|
34
34
|
totalPages: number;
|
|
35
35
|
items: T[];
|
|
36
36
|
};
|
|
37
|
-
protected parseFacet(facetIdentifier: FacetIdentifier, facetValues: Record<string, number
|
|
38
|
-
protected parseFacetValue(facetValueIdentifier: FacetValueIdentifier, label: string, count: number
|
|
37
|
+
protected parseFacet(facetIdentifier: FacetIdentifier, facetValues: Record<string, number>): ProductSearchResultFacet;
|
|
38
|
+
protected parseFacetValue(facetValueIdentifier: FacetValueIdentifier, label: string, count: number): ProductSearchResultFacetValue;
|
|
39
39
|
}
|
|
40
40
|
export {};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ProductProvider
|
|
3
|
-
} from "@reactionary/core";
|
|
4
|
-
class AlgoliaProductProvider extends ProductProvider {
|
|
5
|
-
constructor(config, schema, cache) {
|
|
6
|
-
super(schema, cache);
|
|
7
|
-
this.config = config;
|
|
8
|
-
}
|
|
9
|
-
async getById(payload, _reqCtx) {
|
|
10
|
-
const result = this.newModel();
|
|
11
|
-
result.identifier = { key: payload.id };
|
|
12
|
-
result.name = `Algolia Product ${payload.id}`;
|
|
13
|
-
result.slug = payload.id;
|
|
14
|
-
result.description = "Product from Algolia";
|
|
15
|
-
result.meta = {
|
|
16
|
-
cache: { hit: false, key: payload.id },
|
|
17
|
-
placeholder: true
|
|
18
|
-
};
|
|
19
|
-
return this.assert(result);
|
|
20
|
-
}
|
|
21
|
-
async getBySlug(payload, _reqCtx) {
|
|
22
|
-
const result = this.newModel();
|
|
23
|
-
result.identifier = { key: payload.slug };
|
|
24
|
-
result.name = `Algolia Product ${payload.slug}`;
|
|
25
|
-
result.slug = payload.slug;
|
|
26
|
-
result.description = "Product from Algolia";
|
|
27
|
-
result.meta = {
|
|
28
|
-
cache: { hit: false, key: payload.slug },
|
|
29
|
-
placeholder: true
|
|
30
|
-
};
|
|
31
|
-
return this.assert(result);
|
|
32
|
-
}
|
|
33
|
-
getBySKU(payload, reqCtx) {
|
|
34
|
-
throw new Error("Method not implemented.");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export {
|
|
38
|
-
AlgoliaProductProvider
|
|
39
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Product, ProductQueryById, ProductQueryBySlug, RequestContext, Cache, ProductQueryBySKU } from '@reactionary/core';
|
|
2
|
-
import { ProductProvider } from '@reactionary/core';
|
|
3
|
-
import type { z } from 'zod';
|
|
4
|
-
import type { AlgoliaConfiguration } from '../schema/configuration.schema.js';
|
|
5
|
-
export declare class AlgoliaProductProvider<T extends Product = Product> extends ProductProvider<T> {
|
|
6
|
-
protected config: AlgoliaConfiguration;
|
|
7
|
-
constructor(config: AlgoliaConfiguration, schema: z.ZodType<T>, cache: Cache);
|
|
8
|
-
getById(payload: ProductQueryById, _reqCtx: RequestContext): Promise<T>;
|
|
9
|
-
getBySlug(payload: ProductQueryBySlug, _reqCtx: RequestContext): Promise<T>;
|
|
10
|
-
getBySKU(payload: ProductQueryBySKU, reqCtx: RequestContext): Promise<T>;
|
|
11
|
-
}
|