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