@reactionary/provider-algolia 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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # provider-algolia
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build provider-algolia` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test provider-algolia` to execute the unit tests via [Jest](https://jestjs.io).
package/index.js ADDED
@@ -0,0 +1,649 @@
1
+ // core/src/cache/redis-cache.ts
2
+ import { Redis } from "@upstash/redis";
3
+
4
+ // core/src/providers/base.provider.ts
5
+ var BaseProvider = class {
6
+ constructor(schema, querySchema, mutationSchema) {
7
+ this.schema = schema;
8
+ this.querySchema = querySchema;
9
+ this.mutationSchema = mutationSchema;
10
+ }
11
+ /**
12
+ * Validates that the final domain model constructed by the provider
13
+ * fulfills the schema as defined. This will throw an exception.
14
+ */
15
+ assert(value) {
16
+ return this.schema.parse(value);
17
+ }
18
+ /**
19
+ * Creates a new model entity based on the schema defaults.
20
+ */
21
+ newModel() {
22
+ return this.schema.parse({});
23
+ }
24
+ /**
25
+ * Retrieves a set of entities matching the list of queries. The size of
26
+ * the resulting list WILL always match the size of the query list. The
27
+ * result list will never contain nulls or undefined. The order
28
+ * of the results will match the order of the queries.
29
+ */
30
+ async query(queries, session) {
31
+ const results = await this.fetch(queries, session);
32
+ for (const result of results) {
33
+ this.assert(result);
34
+ }
35
+ return results;
36
+ }
37
+ /**
38
+ * Executes the listed mutations in order and returns the final state
39
+ * resulting from that set of operations.
40
+ */
41
+ async mutate(mutations, session) {
42
+ const result = await this.process(mutations, session);
43
+ this.assert(result);
44
+ return result;
45
+ }
46
+ };
47
+
48
+ // core/src/providers/product.provider.ts
49
+ var ProductProvider = class extends BaseProvider {
50
+ };
51
+
52
+ // core/src/providers/search.provider.ts
53
+ var SearchProvider = class extends BaseProvider {
54
+ };
55
+
56
+ // core/src/schemas/capabilities.schema.ts
57
+ import { z } from "zod";
58
+ var CapabilitiesSchema = z.looseInterface({
59
+ product: z.boolean(),
60
+ search: z.boolean(),
61
+ analytics: z.boolean(),
62
+ identity: z.boolean(),
63
+ cart: z.boolean(),
64
+ inventory: z.boolean(),
65
+ price: z.boolean()
66
+ });
67
+
68
+ // core/src/schemas/session.schema.ts
69
+ import { z as z4 } from "zod";
70
+
71
+ // core/src/schemas/models/identity.model.ts
72
+ import { z as z3 } from "zod";
73
+
74
+ // core/src/schemas/models/base.model.ts
75
+ import { z as z2 } from "zod";
76
+ var CacheInformationSchema = z2.looseInterface({
77
+ hit: z2.boolean().default(false),
78
+ key: z2.string().default("")
79
+ });
80
+ var MetaSchema = z2.looseInterface({
81
+ cache: CacheInformationSchema.default(() => CacheInformationSchema.parse({})),
82
+ placeholder: z2.boolean().default(false).describe("Whether or not the entity exists in a remote system, or is a default placeholder.")
83
+ });
84
+ var BaseModelSchema = z2.looseInterface({
85
+ meta: MetaSchema.default(() => MetaSchema.parse({}))
86
+ });
87
+
88
+ // core/src/schemas/models/identity.model.ts
89
+ var IdentityTypeSchema = z3.enum(["Anonymous", "Guest", "Registered"]);
90
+ var IdentitySchema = BaseModelSchema.extend({
91
+ id: z3.string().default(""),
92
+ type: IdentityTypeSchema.default("Anonymous"),
93
+ token: z3.string().optional(),
94
+ issued: z3.coerce.date().default(/* @__PURE__ */ new Date()),
95
+ expiry: z3.coerce.date().default(/* @__PURE__ */ new Date())
96
+ });
97
+
98
+ // core/src/schemas/session.schema.ts
99
+ var SessionSchema = z4.looseObject({
100
+ id: z4.string(),
101
+ identity: IdentitySchema.default(() => IdentitySchema.parse({}))
102
+ });
103
+
104
+ // core/src/schemas/models/cart.model.ts
105
+ import { z as z6 } from "zod";
106
+
107
+ // core/src/schemas/models/identifiers.model.ts
108
+ import { z as z5 } from "zod";
109
+ var FacetIdentifierSchema = z5.looseInterface({
110
+ key: z5.string().default("").nonoptional()
111
+ });
112
+ var FacetValueIdentifierSchema = z5.looseInterface({
113
+ facet: FacetIdentifierSchema.default(() => FacetIdentifierSchema.parse({})),
114
+ key: z5.string().default("")
115
+ });
116
+ var SKUIdentifierSchema = z5.looseInterface({
117
+ key: z5.string().default("").nonoptional()
118
+ });
119
+ var ProductIdentifierSchema = z5.looseInterface({
120
+ key: z5.string().default("")
121
+ });
122
+ var SearchIdentifierSchema = z5.looseInterface({
123
+ term: z5.string().default(""),
124
+ page: z5.number().default(0),
125
+ pageSize: z5.number().default(20),
126
+ facets: z5.array(FacetValueIdentifierSchema.required()).default(() => [])
127
+ });
128
+ var CartIdentifierSchema = z5.looseInterface({
129
+ key: z5.string().default("")
130
+ });
131
+ var CartItemIdentifierSchema = z5.looseInterface({
132
+ key: z5.string().default("")
133
+ });
134
+ var PriceIdentifierSchema = z5.looseInterface({
135
+ sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({}))
136
+ });
137
+
138
+ // core/src/schemas/models/cart.model.ts
139
+ var CartItemSchema = z6.looseInterface({
140
+ identifier: CartItemIdentifierSchema.default(() => CartItemIdentifierSchema.parse({})),
141
+ product: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})),
142
+ quantity: z6.number().default(0)
143
+ });
144
+ var CartSchema = BaseModelSchema.extend({
145
+ identifier: CartIdentifierSchema.default(() => CartIdentifierSchema.parse({})),
146
+ items: z6.array(CartItemSchema).default(() => [])
147
+ });
148
+
149
+ // core/src/schemas/models/currency.model.ts
150
+ import { z as z7 } from "zod";
151
+ var CurrencySchema = z7.enum([
152
+ "AED",
153
+ "AFN",
154
+ "ALL",
155
+ "AMD",
156
+ "ANG",
157
+ "AOA",
158
+ "ARS",
159
+ "AUD",
160
+ "AWG",
161
+ "AZN",
162
+ "BAM",
163
+ "BBD",
164
+ "BDT",
165
+ "BGN",
166
+ "BHD",
167
+ "BIF",
168
+ "BMD",
169
+ "BND",
170
+ "BOB",
171
+ "BOV",
172
+ "BRL",
173
+ "BSD",
174
+ "BTN",
175
+ "BWP",
176
+ "BYN",
177
+ "BZD",
178
+ "CAD",
179
+ "CDF",
180
+ "CHE",
181
+ "CHF",
182
+ "CHW",
183
+ "CLF",
184
+ "CLP",
185
+ "CNY",
186
+ "COP",
187
+ "COU",
188
+ "CRC",
189
+ "CUC",
190
+ "CUP",
191
+ "CVE",
192
+ "CZK",
193
+ "DJF",
194
+ "DKK",
195
+ "DOP",
196
+ "DZD",
197
+ "EGP",
198
+ "ERN",
199
+ "ETB",
200
+ "EUR",
201
+ "FJD",
202
+ "FKP",
203
+ "GBP",
204
+ "GEL",
205
+ "GHS",
206
+ "GIP",
207
+ "GMD",
208
+ "GNF",
209
+ "GTQ",
210
+ "GYD",
211
+ "HKD",
212
+ "HNL",
213
+ "HRK",
214
+ "HTG",
215
+ "HUF",
216
+ "IDR",
217
+ "ILS",
218
+ "INR",
219
+ "IQD",
220
+ "IRR",
221
+ "ISK",
222
+ "JMD",
223
+ "JOD",
224
+ "JPY",
225
+ "KES",
226
+ "KGS",
227
+ "KHR",
228
+ "KMF",
229
+ "KPW",
230
+ "KRW",
231
+ "KWD",
232
+ "KYD",
233
+ "KZT",
234
+ "LAK",
235
+ "LBP",
236
+ "LKR",
237
+ "LRD",
238
+ "LSL",
239
+ "LYD",
240
+ "MAD",
241
+ "MDL",
242
+ "MGA",
243
+ "MKD",
244
+ "MMK",
245
+ "MNT",
246
+ "MOP",
247
+ "MRU",
248
+ "MUR",
249
+ "MVR",
250
+ "MWK",
251
+ "MXN",
252
+ "MXV",
253
+ "MYR",
254
+ "MZN",
255
+ "NAD",
256
+ "NGN",
257
+ "NIO",
258
+ "NOK",
259
+ "NPR",
260
+ "NZD",
261
+ "OMR",
262
+ "PAB",
263
+ "PEN",
264
+ "PGK",
265
+ "PHP",
266
+ "PKR",
267
+ "PLN",
268
+ "PYG",
269
+ "QAR",
270
+ "RON",
271
+ "RSD",
272
+ "RUB",
273
+ "RWF",
274
+ "SAR",
275
+ "SBD",
276
+ "SCR",
277
+ "SDG",
278
+ "SEK",
279
+ "SGD",
280
+ "SHP",
281
+ "SLE",
282
+ "SLL",
283
+ "SOS",
284
+ "SRD",
285
+ "SSP",
286
+ "STN",
287
+ "SYP",
288
+ "SZL",
289
+ "THB",
290
+ "TJS",
291
+ "TMT",
292
+ "TND",
293
+ "TOP",
294
+ "TRY",
295
+ "TTD",
296
+ "TVD",
297
+ "TWD",
298
+ "TZS",
299
+ "UAH",
300
+ "UGX",
301
+ "USD",
302
+ "USN",
303
+ "UYI",
304
+ "UYU",
305
+ "UYW",
306
+ "UZS",
307
+ "VED",
308
+ "VES",
309
+ "VND",
310
+ "VUV",
311
+ "WST",
312
+ "XAF",
313
+ "XAG",
314
+ "XAU",
315
+ "XBA",
316
+ "XBB",
317
+ "XBC",
318
+ "XBD",
319
+ "XCD",
320
+ "XDR",
321
+ "XOF",
322
+ "XPD",
323
+ "XPF",
324
+ "XPT",
325
+ "XSU",
326
+ "XTS",
327
+ "XUA",
328
+ "XXX",
329
+ "YER",
330
+ "ZAR",
331
+ "ZMW",
332
+ "ZWL"
333
+ ]);
334
+
335
+ // core/src/schemas/models/inventory.model.ts
336
+ import { z as z8 } from "zod";
337
+ var InventorySchema = BaseModelSchema.extend({
338
+ quantity: z8.number().default(0)
339
+ });
340
+
341
+ // core/src/schemas/models/price.model.ts
342
+ import { z as z9 } from "zod";
343
+ var MonetaryAmountSchema = z9.looseInterface({
344
+ cents: z9.number().default(0).describe("The monetary amount in cent-precision."),
345
+ currency: CurrencySchema.default("XXX").describe("The currency associated with the amount, as a ISO 4217 standardized code.")
346
+ });
347
+ var PriceSchema = BaseModelSchema.extend({
348
+ identifier: PriceIdentifierSchema.default(() => PriceIdentifierSchema.parse({})),
349
+ value: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({}))
350
+ });
351
+
352
+ // core/src/schemas/models/product.model.ts
353
+ import { z as z10 } from "zod";
354
+ var SKUSchema = z10.looseInterface({
355
+ identifier: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({}))
356
+ });
357
+ var ProductAttributeSchema = z10.looseInterface({
358
+ id: z10.string(),
359
+ name: z10.string(),
360
+ value: z10.string()
361
+ });
362
+ var ProductSchema = BaseModelSchema.extend({
363
+ identifier: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})),
364
+ name: z10.string().default(""),
365
+ slug: z10.string().default(""),
366
+ description: z10.string().default(""),
367
+ image: z10.string().url().default("https://placehold.co/400"),
368
+ images: z10.string().url().array().default(() => []),
369
+ attributes: z10.array(ProductAttributeSchema).default(() => []),
370
+ skus: z10.array(SKUSchema).default(() => [])
371
+ });
372
+
373
+ // core/src/schemas/models/search.model.ts
374
+ import { z as z11 } from "zod";
375
+ var SearchResultProductSchema = z11.looseInterface({
376
+ identifier: ProductIdentifierSchema.default(ProductIdentifierSchema.parse({})),
377
+ name: z11.string().default(""),
378
+ image: z11.string().url().default("https://placehold.co/400"),
379
+ slug: z11.string().default("")
380
+ });
381
+ var SearchResultFacetValueSchema = z11.looseInterface({
382
+ identifier: FacetValueIdentifierSchema.default(() => FacetValueIdentifierSchema.parse({})),
383
+ name: z11.string().default(""),
384
+ count: z11.number().default(0),
385
+ active: z11.boolean().default(false)
386
+ });
387
+ var SearchResultFacetSchema = z11.looseInterface({
388
+ identifier: FacetIdentifierSchema.default(() => FacetIdentifierSchema.parse({})),
389
+ name: z11.string().default(""),
390
+ values: z11.array(SearchResultFacetValueSchema).default(() => [])
391
+ });
392
+ var SearchResultSchema = BaseModelSchema.extend({
393
+ identifier: SearchIdentifierSchema.default(() => SearchIdentifierSchema.parse({})),
394
+ products: z11.array(SearchResultProductSchema).default(() => []),
395
+ pages: z11.number().default(0),
396
+ facets: z11.array(SearchResultFacetSchema).default(() => [])
397
+ });
398
+
399
+ // core/src/schemas/mutations/base.mutation.ts
400
+ import { z as z12 } from "zod";
401
+ var BaseMutationSchema = z12.looseInterface({
402
+ mutation: z12.ZodLiteral
403
+ });
404
+
405
+ // core/src/schemas/mutations/cart.mutation.ts
406
+ import { z as z13 } from "zod";
407
+ var CartMutationItemAddSchema = BaseMutationSchema.extend({
408
+ mutation: z13.literal("add"),
409
+ cart: CartIdentifierSchema.required(),
410
+ product: ProductIdentifierSchema.required(),
411
+ quantity: z13.number()
412
+ });
413
+ var CartMutationItemRemoveSchema = BaseMutationSchema.extend({
414
+ mutation: z13.literal("remove"),
415
+ cart: CartIdentifierSchema.required(),
416
+ item: CartItemIdentifierSchema.required()
417
+ });
418
+ var CartMutationItemQuantityChangeSchema = BaseMutationSchema.extend({
419
+ mutation: z13.literal("adjustQuantity"),
420
+ cart: CartIdentifierSchema.required(),
421
+ item: CartItemIdentifierSchema.required(),
422
+ quantity: z13.number()
423
+ });
424
+ var CartMutationSchema = z13.union([CartMutationItemAddSchema, CartMutationItemRemoveSchema, CartMutationItemQuantityChangeSchema]);
425
+
426
+ // core/src/schemas/mutations/identity.mutation.ts
427
+ import { z as z14 } from "zod";
428
+ var IdentityMutationLoginSchema = BaseMutationSchema.extend({
429
+ mutation: z14.literal("login"),
430
+ username: z14.string(),
431
+ password: z14.string()
432
+ });
433
+ var IdentityMutationLogoutSchema = BaseMutationSchema.extend({
434
+ mutation: z14.literal("logout")
435
+ });
436
+ var IdentityMutationSchema = z14.union([IdentityMutationLoginSchema, IdentityMutationLogoutSchema]);
437
+
438
+ // core/src/schemas/mutations/inventory.mutation.ts
439
+ import { z as z15 } from "zod";
440
+ var InventoryMutationSchema = z15.union([]);
441
+
442
+ // core/src/schemas/mutations/price.mutation.ts
443
+ import { z as z16 } from "zod";
444
+ var PriceMutationSchema = z16.union([]);
445
+
446
+ // core/src/schemas/mutations/product.mutation.ts
447
+ import { z as z17 } from "zod";
448
+ var ProductMutationSchema = z17.union([]);
449
+
450
+ // core/src/schemas/mutations/search.mutation.ts
451
+ import { z as z18 } from "zod";
452
+ var SearchMutationSchema = z18.union([]);
453
+
454
+ // core/src/schemas/queries/base.query.ts
455
+ import { z as z19 } from "zod";
456
+ var BaseQuerySchema = z19.looseInterface({
457
+ query: z19.ZodLiteral
458
+ });
459
+
460
+ // core/src/schemas/queries/cart.query.ts
461
+ import { z as z20 } from "zod";
462
+ var CartQueryByIdSchema = BaseQuerySchema.extend({
463
+ query: z20.literal("id"),
464
+ cart: CartIdentifierSchema.required()
465
+ });
466
+ var CartQuerySchema = z20.union([CartQueryByIdSchema]);
467
+
468
+ // core/src/schemas/queries/identity.query.ts
469
+ import { z as z21 } from "zod";
470
+ var IdentityQuerySelfSchema = BaseQuerySchema.extend({
471
+ query: z21.literal("self")
472
+ });
473
+ var IdentityQuerySchema = z21.union([IdentityQuerySelfSchema]);
474
+
475
+ // core/src/schemas/queries/inventory.query.ts
476
+ import { z as z22 } from "zod";
477
+ var InventoryQuerySchema = BaseQuerySchema.extend({
478
+ query: z22.literal("sku"),
479
+ sku: z22.string()
480
+ });
481
+
482
+ // core/src/schemas/queries/price.query.ts
483
+ import { z as z23 } from "zod";
484
+ var PriceQueryBySkuSchema = BaseQuerySchema.extend({
485
+ query: z23.literal("sku"),
486
+ sku: SKUIdentifierSchema.required()
487
+ });
488
+ var PriceQuerySchema = z23.union([PriceQueryBySkuSchema]);
489
+
490
+ // core/src/schemas/queries/product.query.ts
491
+ import { z as z24 } from "zod";
492
+ var ProductQueryBySlugSchema = BaseQuerySchema.extend({
493
+ query: z24.literal("slug"),
494
+ slug: z24.string()
495
+ });
496
+ var ProductQueryByIdSchema = BaseQuerySchema.extend({
497
+ query: z24.literal("id"),
498
+ id: z24.string()
499
+ });
500
+ var ProductQuerySchema = z24.union([ProductQueryBySlugSchema, ProductQueryByIdSchema]);
501
+
502
+ // core/src/schemas/queries/search.query.ts
503
+ import { z as z25 } from "zod";
504
+ var SearchQueryByTermSchema = BaseQuerySchema.extend({
505
+ query: z25.literal("term"),
506
+ search: SearchIdentifierSchema.required()
507
+ });
508
+ var SearchQuerySchema = z25.union([SearchQueryByTermSchema]);
509
+
510
+ // providers/algolia/src/providers/product.provider.ts
511
+ var AlgoliaProductProvider = class extends ProductProvider {
512
+ constructor(config, schema, querySchema, mutationSchema) {
513
+ super(schema, querySchema, mutationSchema);
514
+ this.config = config;
515
+ }
516
+ async fetch(queries, session) {
517
+ return [];
518
+ }
519
+ process(mutation, session) {
520
+ throw new Error("Method not implemented.");
521
+ }
522
+ };
523
+
524
+ // providers/algolia/src/providers/search.provider.ts
525
+ import { algoliasearch } from "algoliasearch";
526
+ var AlgoliaSearchProvider = class extends SearchProvider {
527
+ constructor(config, schema, querySchema, mutationSchema) {
528
+ super(schema, querySchema, mutationSchema);
529
+ this.config = config;
530
+ }
531
+ async fetch(queries, session) {
532
+ const results = [];
533
+ for (const query of queries) {
534
+ const result = await this.get(query.search);
535
+ results.push(result);
536
+ }
537
+ return results;
538
+ }
539
+ process(mutations, session) {
540
+ throw new Error("Method not implemented.");
541
+ }
542
+ async get(identifier) {
543
+ const client = algoliasearch(this.config.appId, this.config.apiKey);
544
+ const remote = await client.search({
545
+ requests: [
546
+ {
547
+ indexName: this.config.indexName,
548
+ query: identifier.term,
549
+ page: identifier.page,
550
+ hitsPerPage: identifier.pageSize,
551
+ facets: ["*"],
552
+ analytics: true,
553
+ clickAnalytics: true,
554
+ facetFilters: identifier.facets.map(
555
+ (x) => `${encodeURIComponent(x.facet.key)}:${x.key}`
556
+ )
557
+ }
558
+ ]
559
+ });
560
+ const parsed = this.parse(remote, identifier);
561
+ return parsed;
562
+ }
563
+ parse(remote, query) {
564
+ const result = this.newModel();
565
+ const remoteProducts = remote.results[0];
566
+ for (const id in remoteProducts.facets) {
567
+ const f = remoteProducts.facets[id];
568
+ const facet = SearchResultFacetSchema.parse({});
569
+ facet.identifier.key = id;
570
+ facet.name = id;
571
+ for (const vid in f) {
572
+ const fv = f[vid];
573
+ const facetValue = SearchResultFacetValueSchema.parse({});
574
+ facetValue.count = fv;
575
+ facetValue.name = vid;
576
+ facetValue.identifier.key = vid;
577
+ facetValue.identifier.facet = facet.identifier;
578
+ if (query.facets.find(
579
+ (x) => x.facet.key == facetValue.identifier.facet.key && x.key == facetValue.identifier.key
580
+ )) {
581
+ facetValue.active = true;
582
+ }
583
+ facet.values.push(facetValue);
584
+ }
585
+ result.facets.push(facet);
586
+ }
587
+ for (const p of remoteProducts.hits) {
588
+ result.products.push({
589
+ identifier: {
590
+ key: p.objectID
591
+ },
592
+ slug: p.slug,
593
+ name: p.name,
594
+ image: p.image
595
+ });
596
+ }
597
+ result.identifier = {
598
+ ...query,
599
+ index: remoteProducts.index,
600
+ key: remoteProducts.queryID
601
+ };
602
+ result.pages = remoteProducts.nbPages;
603
+ return result;
604
+ }
605
+ };
606
+
607
+ // providers/algolia/src/schema/search.schema.ts
608
+ import { z as z26 } from "zod";
609
+ var AlgoliaSearchIdentifierSchema = SearchIdentifierSchema.extend({
610
+ key: z26.string().default(""),
611
+ index: z26.string().default("")
612
+ });
613
+ var AlgoliaSearchResultSchema = SearchResultSchema.extend({
614
+ identifier: AlgoliaSearchIdentifierSchema.default(() => AlgoliaSearchIdentifierSchema.parse({}))
615
+ });
616
+
617
+ // providers/algolia/src/core/initialize.ts
618
+ function withAlgoliaCapabilities(configuration, capabilities) {
619
+ const client = {};
620
+ if (capabilities.product) {
621
+ client.product = new AlgoliaProductProvider(configuration, ProductSchema, ProductQuerySchema, ProductMutationSchema);
622
+ }
623
+ if (capabilities.search) {
624
+ client.search = new AlgoliaSearchProvider(configuration, AlgoliaSearchResultSchema, SearchQuerySchema, SearchMutationSchema);
625
+ }
626
+ return client;
627
+ }
628
+
629
+ // providers/algolia/src/schema/configuration.schema.ts
630
+ import { z as z27 } from "zod";
631
+ var AlgoliaConfigurationSchema = z27.looseInterface({
632
+ appId: z27.string(),
633
+ apiKey: z27.string(),
634
+ indexName: z27.string()
635
+ });
636
+
637
+ // providers/algolia/src/schema/capabilities.schema.ts
638
+ var AlgoliaCapabilitiesSchema = CapabilitiesSchema.pick({
639
+ product: true,
640
+ search: true,
641
+ analytics: true
642
+ }).partial();
643
+ export {
644
+ AlgoliaCapabilitiesSchema,
645
+ AlgoliaConfigurationSchema,
646
+ AlgoliaProductProvider,
647
+ AlgoliaSearchProvider,
648
+ withAlgoliaCapabilities
649
+ };
package/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@reactionary/provider-algolia",
3
+ "version": "0.0.27",
4
+ "dependencies": {
5
+ "@reactionary/core": "0.0.27",
6
+ "algoliasearch": "^5.23.4",
7
+ "zod": "4.0.0-beta.20250430T185432"
8
+ }
9
+ }
@@ -0,0 +1,4 @@
1
+ import { Client } from "@reactionary/core";
2
+ import { AlgoliaCapabilities } from "../schema/capabilities.schema";
3
+ import { AlgoliaConfiguration } from "../schema/configuration.schema";
4
+ export declare function withAlgoliaCapabilities(configuration: AlgoliaConfiguration, capabilities: AlgoliaCapabilities): Partial<Client>;
package/src/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './core/initialize';
2
+ export * from './providers/product.provider';
3
+ export * from './providers/search.provider';
4
+ export * from './schema/configuration.schema';
5
+ export * from './schema/capabilities.schema';
@@ -0,0 +1,9 @@
1
+ import { BaseMutation, Product, ProductMutation, ProductProvider, ProductQuery, Session } from '@reactionary/core';
2
+ import { z } from 'zod';
3
+ import { AlgoliaConfiguration } from '../schema/configuration.schema';
4
+ export declare class AlgoliaProductProvider<T extends Product = Product, Q extends ProductQuery = ProductQuery, M extends ProductMutation = ProductMutation> extends ProductProvider<T, Q, M> {
5
+ protected config: AlgoliaConfiguration;
6
+ constructor(config: AlgoliaConfiguration, schema: z.ZodType<T>, querySchema: z.ZodType<Q, Q>, mutationSchema: z.ZodType<M, M>);
7
+ protected fetch(queries: Q[], session: Session): Promise<T[]>;
8
+ protected process(mutation: BaseMutation[], session: Session): Promise<T>;
9
+ }
@@ -0,0 +1,11 @@
1
+ import { SearchIdentifier, SearchMutation, SearchProvider, SearchQuery, SearchResult, Session } from '@reactionary/core';
2
+ import { z } from 'zod';
3
+ import { AlgoliaConfiguration } from '../schema/configuration.schema';
4
+ export declare class AlgoliaSearchProvider<T extends SearchResult = SearchResult, Q extends SearchQuery = SearchQuery, M extends SearchMutation = SearchMutation> extends SearchProvider<T, Q, M> {
5
+ protected config: AlgoliaConfiguration;
6
+ constructor(config: AlgoliaConfiguration, schema: z.ZodType<T>, querySchema: z.ZodType<Q, Q>, mutationSchema: z.ZodType<M, M>);
7
+ protected fetch(queries: Q[], session: Session): Promise<T[]>;
8
+ protected process(mutations: M[], session: Session): Promise<T>;
9
+ protected get(identifier: SearchIdentifier): Promise<T>;
10
+ protected parse(remote: any, query: SearchIdentifier): T;
11
+ }
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ export declare const AlgoliaCapabilitiesSchema: z.ZodInterface<{
3
+ search: z.ZodOptional<z.ZodBoolean>;
4
+ product: z.ZodOptional<z.ZodBoolean>;
5
+ analytics: z.ZodOptional<z.ZodBoolean>;
6
+ }, {
7
+ optional: "search" | "product" | "analytics";
8
+ defaulted: never;
9
+ extra: Record<string, unknown>;
10
+ }>;
11
+ export type AlgoliaCapabilities = z.infer<typeof AlgoliaCapabilitiesSchema>;
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ export declare const AlgoliaConfigurationSchema: z.ZodInterface<{
3
+ appId: z.ZodString;
4
+ apiKey: z.ZodString;
5
+ indexName: z.ZodString;
6
+ }, {
7
+ optional: never;
8
+ defaulted: never;
9
+ extra: Record<string, unknown>;
10
+ }>;
11
+ export type AlgoliaConfiguration = z.infer<typeof AlgoliaConfigurationSchema>;
@@ -0,0 +1,171 @@
1
+ import { z } from 'zod';
2
+ export declare const AlgoliaSearchIdentifierSchema: z.MergeInterfaces<z.ZodInterface<{
3
+ term: z.ZodDefault<z.ZodString>;
4
+ page: z.ZodDefault<z.ZodNumber>;
5
+ pageSize: z.ZodDefault<z.ZodNumber>;
6
+ facets: z.ZodDefault<z.ZodArray<z.ZodInterface<{
7
+ key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
8
+ facet: z.ZodNonOptional<z.ZodDefault<z.ZodInterface<{
9
+ key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
10
+ }, {
11
+ optional: never;
12
+ defaulted: never;
13
+ extra: Record<string, unknown>;
14
+ }>>>;
15
+ }, {
16
+ optional: never;
17
+ defaulted: never;
18
+ extra: Record<string, unknown>;
19
+ }>>>;
20
+ }, {
21
+ optional: never;
22
+ defaulted: never;
23
+ extra: Record<string, unknown>;
24
+ }>, z.ZodInterface<{
25
+ key: z.ZodDefault<z.ZodString>;
26
+ index: z.ZodDefault<z.ZodString>;
27
+ }, {
28
+ optional: never;
29
+ defaulted: never;
30
+ extra: {};
31
+ }>>;
32
+ export declare const AlgoliaSearchResultSchema: z.MergeInterfaces<z.MergeInterfaces<z.ZodInterface<{
33
+ meta: z.ZodDefault<z.ZodInterface<{
34
+ cache: z.ZodDefault<z.ZodInterface<{
35
+ hit: z.ZodDefault<z.ZodBoolean>;
36
+ key: z.ZodDefault<z.ZodString>;
37
+ }, {
38
+ optional: never;
39
+ defaulted: never;
40
+ extra: Record<string, unknown>;
41
+ }>>;
42
+ placeholder: z.ZodDefault<z.ZodBoolean>;
43
+ }, {
44
+ optional: never;
45
+ defaulted: never;
46
+ extra: Record<string, unknown>;
47
+ }>>;
48
+ }, {
49
+ optional: never;
50
+ defaulted: never;
51
+ extra: Record<string, unknown>;
52
+ }>, z.ZodInterface<{
53
+ identifier: z.ZodDefault<z.ZodInterface<{
54
+ term: z.ZodDefault<z.ZodString>;
55
+ page: z.ZodDefault<z.ZodNumber>;
56
+ pageSize: z.ZodDefault<z.ZodNumber>;
57
+ facets: z.ZodDefault<z.ZodArray<z.ZodInterface<{
58
+ key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
59
+ facet: z.ZodNonOptional<z.ZodDefault<z.ZodInterface<{
60
+ key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
61
+ }, {
62
+ optional: never;
63
+ defaulted: never;
64
+ extra: Record<string, unknown>;
65
+ }>>>;
66
+ }, {
67
+ optional: never;
68
+ defaulted: never;
69
+ extra: Record<string, unknown>;
70
+ }>>>;
71
+ }, {
72
+ optional: never;
73
+ defaulted: never;
74
+ extra: Record<string, unknown>;
75
+ }>>;
76
+ products: z.ZodDefault<z.ZodArray<z.ZodInterface<{
77
+ identifier: z.ZodDefault<z.ZodInterface<{
78
+ key: z.ZodDefault<z.ZodString>;
79
+ }, {
80
+ optional: never;
81
+ defaulted: never;
82
+ extra: Record<string, unknown>;
83
+ }>>;
84
+ name: z.ZodDefault<z.ZodString>;
85
+ image: z.ZodDefault<z.ZodString>;
86
+ slug: z.ZodDefault<z.ZodString>;
87
+ }, {
88
+ optional: never;
89
+ defaulted: never;
90
+ extra: Record<string, unknown>;
91
+ }>>>;
92
+ pages: z.ZodDefault<z.ZodNumber>;
93
+ facets: z.ZodDefault<z.ZodArray<z.ZodInterface<{
94
+ identifier: z.ZodDefault<z.ZodInterface<{
95
+ key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
96
+ }, {
97
+ optional: never;
98
+ defaulted: never;
99
+ extra: Record<string, unknown>;
100
+ }>>;
101
+ name: z.ZodDefault<z.ZodString>;
102
+ values: z.ZodDefault<z.ZodArray<z.ZodInterface<{
103
+ identifier: z.ZodDefault<z.ZodInterface<{
104
+ facet: z.ZodDefault<z.ZodInterface<{
105
+ key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
106
+ }, {
107
+ optional: never;
108
+ defaulted: never;
109
+ extra: Record<string, unknown>;
110
+ }>>;
111
+ key: z.ZodDefault<z.ZodString>;
112
+ }, {
113
+ optional: never;
114
+ defaulted: never;
115
+ extra: Record<string, unknown>;
116
+ }>>;
117
+ name: z.ZodDefault<z.ZodString>;
118
+ count: z.ZodDefault<z.ZodNumber>;
119
+ active: z.ZodDefault<z.ZodBoolean>;
120
+ }, {
121
+ optional: never;
122
+ defaulted: never;
123
+ extra: Record<string, unknown>;
124
+ }>>>;
125
+ }, {
126
+ optional: never;
127
+ defaulted: never;
128
+ extra: Record<string, unknown>;
129
+ }>>>;
130
+ }, {
131
+ optional: never;
132
+ defaulted: never;
133
+ extra: {};
134
+ }>>, z.ZodInterface<{
135
+ identifier: z.ZodDefault<z.MergeInterfaces<z.ZodInterface<{
136
+ term: z.ZodDefault<z.ZodString>;
137
+ page: z.ZodDefault<z.ZodNumber>;
138
+ pageSize: z.ZodDefault<z.ZodNumber>;
139
+ facets: z.ZodDefault<z.ZodArray<z.ZodInterface<{
140
+ key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
141
+ facet: z.ZodNonOptional<z.ZodDefault<z.ZodInterface<{
142
+ key: z.ZodNonOptional<z.ZodDefault<z.ZodString>>;
143
+ }, {
144
+ optional: never;
145
+ defaulted: never;
146
+ extra: Record<string, unknown>;
147
+ }>>>;
148
+ }, {
149
+ optional: never;
150
+ defaulted: never;
151
+ extra: Record<string, unknown>;
152
+ }>>>;
153
+ }, {
154
+ optional: never;
155
+ defaulted: never;
156
+ extra: Record<string, unknown>;
157
+ }>, z.ZodInterface<{
158
+ key: z.ZodDefault<z.ZodString>;
159
+ index: z.ZodDefault<z.ZodString>;
160
+ }, {
161
+ optional: never;
162
+ defaulted: never;
163
+ extra: {};
164
+ }>>>;
165
+ }, {
166
+ optional: never;
167
+ defaulted: never;
168
+ extra: {};
169
+ }>>;
170
+ export type AlgoliaSearchResult = z.infer<typeof AlgoliaSearchResultSchema>;
171
+ export type AlgoliaSearchIdentifier = z.infer<typeof AlgoliaSearchIdentifierSchema>;