@simpleapps-com/augur-server 0.2.3 → 0.2.5
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/dist/chunk-I7EWYSPA.js +27 -0
- package/dist/chunk-I7EWYSPA.js.map +1 -0
- package/dist/index.d.ts +559 -1
- package/dist/index.js +595 -20
- package/dist/index.js.map +1 -1
- package/dist/prefetch.d.ts +78 -0
- package/dist/prefetch.js +149 -0
- package/dist/prefetch.js.map +1 -0
- package/package.json +13 -4
package/dist/index.js
CHANGED
|
@@ -2,6 +2,10 @@ import {
|
|
|
2
2
|
createQueryOptions,
|
|
3
3
|
createSuspenseQueryOptions
|
|
4
4
|
} from "./chunk-I26RJDRF.js";
|
|
5
|
+
import {
|
|
6
|
+
createServerQueryClient,
|
|
7
|
+
getServerQueryClient
|
|
8
|
+
} from "./chunk-I7EWYSPA.js";
|
|
5
9
|
|
|
6
10
|
// src/environment.ts
|
|
7
11
|
function getEnvironment() {
|
|
@@ -134,32 +138,602 @@ async function sdkCall(method, ...args) {
|
|
|
134
138
|
return method(...args);
|
|
135
139
|
}
|
|
136
140
|
|
|
137
|
-
// src/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
141
|
+
// src/cache/with-cache.ts
|
|
142
|
+
function fnv1a(str) {
|
|
143
|
+
let h = 2166136261;
|
|
144
|
+
for (let i = 0; i < str.length; i++) {
|
|
145
|
+
h ^= str.charCodeAt(i);
|
|
146
|
+
h = Math.imul(h, 16777619);
|
|
147
|
+
}
|
|
148
|
+
return (h >>> 0).toString(16).padStart(8, "0");
|
|
149
|
+
}
|
|
150
|
+
function stableStringify(value) {
|
|
151
|
+
if (value === null || value === void 0) return JSON.stringify(value);
|
|
152
|
+
if (typeof value !== "object") return JSON.stringify(value);
|
|
153
|
+
if (Array.isArray(value)) {
|
|
154
|
+
return `[${value.map(stableStringify).join(",")}]`;
|
|
155
|
+
}
|
|
156
|
+
const obj = value;
|
|
157
|
+
const keys = Object.keys(obj).sort();
|
|
158
|
+
const entries = keys.map(
|
|
159
|
+
(key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`
|
|
160
|
+
);
|
|
161
|
+
return `{${entries.join(",")}}`;
|
|
162
|
+
}
|
|
163
|
+
async function withServerCache(prefix, redisTtl, methodPath, fn, ...keyArgs) {
|
|
164
|
+
if (!redisTtl) return fn();
|
|
165
|
+
const key = `${prefix}sdk:${methodPath}:${fnv1a(stableStringify(keyArgs))}`;
|
|
166
|
+
try {
|
|
167
|
+
const cached = await cacheGet(key);
|
|
168
|
+
if (cached != null) return JSON.parse(cached);
|
|
169
|
+
} catch {
|
|
170
|
+
}
|
|
171
|
+
const result = await fn();
|
|
172
|
+
try {
|
|
173
|
+
cacheSet(key, JSON.stringify(result), redisTtl).catch(() => {
|
|
174
|
+
});
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/actions/pricing.ts
|
|
181
|
+
function resolveCustomerId(explicit, fallback) {
|
|
182
|
+
const raw = explicit ?? fallback;
|
|
183
|
+
const num = Number(raw);
|
|
184
|
+
return num > 0 ? num : 0;
|
|
185
|
+
}
|
|
186
|
+
function createPricingActions(api, config = {}) {
|
|
187
|
+
const {
|
|
188
|
+
defaultCustomerId,
|
|
189
|
+
cachePrefix = "",
|
|
190
|
+
edgeCache = 2,
|
|
191
|
+
redisTtl = 3600,
|
|
192
|
+
taxRedisTtl = 1800
|
|
193
|
+
} = config;
|
|
194
|
+
async function getItemPrice(itemId, customerId, quantity = 1) {
|
|
195
|
+
const custId = resolveCustomerId(customerId, defaultCustomerId);
|
|
196
|
+
const params = { customerId: custId, itemId, quantity, edgeCache };
|
|
197
|
+
return withServerCache(
|
|
198
|
+
cachePrefix,
|
|
199
|
+
redisTtl,
|
|
200
|
+
"pricing.priceEngine.get",
|
|
201
|
+
async () => {
|
|
202
|
+
const response = await api.pricing.priceEngine.get(params);
|
|
203
|
+
return response.data;
|
|
204
|
+
},
|
|
205
|
+
params
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
async function batchGetItemPrices(itemIds, customerId, quantity = 1) {
|
|
209
|
+
const results = await Promise.all(
|
|
210
|
+
itemIds.map((id) => getItemPrice(id, customerId, quantity).then((data) => [id, data]).catch(() => [id, null]))
|
|
211
|
+
);
|
|
212
|
+
const out = {};
|
|
213
|
+
for (const [id, data] of results) {
|
|
214
|
+
if (data) out[id] = data;
|
|
215
|
+
}
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
async function getTaxEstimate(customerId, postalCode, items) {
|
|
219
|
+
const custId = resolveCustomerId(customerId, defaultCustomerId);
|
|
220
|
+
const params = { customerId: custId, postalCode, items };
|
|
221
|
+
return withServerCache(
|
|
222
|
+
cachePrefix,
|
|
223
|
+
taxRedisTtl,
|
|
224
|
+
"pricing.taxEngine.create",
|
|
225
|
+
async () => {
|
|
226
|
+
const response = await api.pricing.taxEngine.create(params);
|
|
227
|
+
return response.data;
|
|
228
|
+
},
|
|
229
|
+
params
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
return { getItemPrice, batchGetItemPrices, getTaxEstimate };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/actions/items.ts
|
|
236
|
+
function createItemActions(api, config = {}) {
|
|
237
|
+
const {
|
|
238
|
+
cachePrefix = "",
|
|
239
|
+
edgeCache = 1,
|
|
240
|
+
longEdgeCache = 8,
|
|
241
|
+
redisTtl = 3600,
|
|
242
|
+
longRedisTtl = 28800
|
|
243
|
+
} = config;
|
|
244
|
+
async function itemCategoryLookup(path) {
|
|
245
|
+
return withServerCache(
|
|
246
|
+
cachePrefix,
|
|
247
|
+
redisTtl,
|
|
248
|
+
"items.categories.lookup.get",
|
|
249
|
+
async () => {
|
|
250
|
+
const response = await api.items.categories.lookup.get({
|
|
251
|
+
path,
|
|
252
|
+
edgeCache
|
|
253
|
+
});
|
|
254
|
+
return response.data;
|
|
255
|
+
},
|
|
256
|
+
path
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
async function getItemCategory(uid, options) {
|
|
260
|
+
return withServerCache(
|
|
261
|
+
cachePrefix,
|
|
262
|
+
redisTtl,
|
|
263
|
+
"items.categories.get",
|
|
264
|
+
async () => {
|
|
265
|
+
const response = await api.items.categories.get(uid, {
|
|
266
|
+
...options,
|
|
267
|
+
edgeCache
|
|
268
|
+
});
|
|
269
|
+
return response.data;
|
|
270
|
+
},
|
|
271
|
+
uid,
|
|
272
|
+
options
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
async function getCategoryItems(uid, filters) {
|
|
276
|
+
return withServerCache(
|
|
277
|
+
cachePrefix,
|
|
278
|
+
redisTtl,
|
|
279
|
+
"items.categories.items.list",
|
|
280
|
+
async () => {
|
|
281
|
+
const response = await api.items.categories.items.list({
|
|
282
|
+
...filters,
|
|
283
|
+
itemCategoryUid: uid,
|
|
284
|
+
edgeCache
|
|
285
|
+
});
|
|
286
|
+
return response.data;
|
|
287
|
+
},
|
|
288
|
+
uid,
|
|
289
|
+
filters
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
async function getItemAttributes(categoryUid) {
|
|
293
|
+
return withServerCache(
|
|
294
|
+
cachePrefix,
|
|
295
|
+
redisTtl,
|
|
296
|
+
"items.categories.attributes.list",
|
|
297
|
+
async () => {
|
|
298
|
+
const response = await api.items.categories.attributes.list(
|
|
299
|
+
categoryUid,
|
|
300
|
+
{ edgeCache }
|
|
301
|
+
);
|
|
302
|
+
return response.data.attributes;
|
|
303
|
+
},
|
|
304
|
+
categoryUid
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
async function getInvMast(uid) {
|
|
308
|
+
return withServerCache(
|
|
309
|
+
cachePrefix,
|
|
310
|
+
redisTtl,
|
|
311
|
+
"items.invMast.get",
|
|
312
|
+
async () => {
|
|
313
|
+
const response = await api.items.invMast.get(uid, { edgeCache: 4 });
|
|
314
|
+
return response.data;
|
|
315
|
+
},
|
|
316
|
+
uid
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
async function getInvMastDoc(params) {
|
|
320
|
+
return withServerCache(
|
|
321
|
+
cachePrefix,
|
|
322
|
+
redisTtl,
|
|
323
|
+
"items.invMast.doc.list",
|
|
324
|
+
async () => {
|
|
325
|
+
const response = await api.items.invMast.doc.list(
|
|
326
|
+
params.invMastUid ?? 0,
|
|
327
|
+
{ itemId: params.itemId, edgeCache: 4 }
|
|
328
|
+
);
|
|
329
|
+
return response.data;
|
|
330
|
+
},
|
|
331
|
+
params.invMastUid,
|
|
332
|
+
params.itemId
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
async function getStock(invMastUid) {
|
|
336
|
+
return withServerCache(
|
|
337
|
+
cachePrefix,
|
|
338
|
+
redisTtl,
|
|
339
|
+
"items.invMast.stock.list",
|
|
340
|
+
async () => {
|
|
341
|
+
const response = await api.items.invMast.stock.list(invMastUid, {
|
|
342
|
+
edgeCache
|
|
343
|
+
});
|
|
344
|
+
return response.data?.stockData;
|
|
345
|
+
},
|
|
346
|
+
invMastUid
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
async function getStockCompanySummary(invMastUid) {
|
|
350
|
+
return withServerCache(
|
|
351
|
+
cachePrefix,
|
|
352
|
+
redisTtl,
|
|
353
|
+
"items.invMast.stock.list.companySummary",
|
|
354
|
+
async () => {
|
|
355
|
+
const response = await api.items.invMast.stock.list(invMastUid, {
|
|
356
|
+
edgeCache
|
|
357
|
+
});
|
|
358
|
+
return response.data?.companySummary;
|
|
359
|
+
},
|
|
360
|
+
invMastUid
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
async function getItemFaqs(invMastUid) {
|
|
364
|
+
return withServerCache(
|
|
365
|
+
cachePrefix,
|
|
366
|
+
longRedisTtl,
|
|
367
|
+
"items.invMast.faq.list",
|
|
368
|
+
async () => {
|
|
369
|
+
const response = await api.items.invMast.faq.list(invMastUid, {
|
|
370
|
+
edgeCache: longEdgeCache
|
|
371
|
+
});
|
|
372
|
+
return response.data;
|
|
373
|
+
},
|
|
374
|
+
invMastUid
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
async function getItemSubstitutes(invMastUid) {
|
|
378
|
+
return withServerCache(
|
|
379
|
+
cachePrefix,
|
|
380
|
+
longRedisTtl,
|
|
381
|
+
"items.invMast.invSub.list",
|
|
382
|
+
async () => {
|
|
383
|
+
const response = await api.items.invMast.invSub.list(invMastUid, {
|
|
384
|
+
edgeCache: longEdgeCache
|
|
385
|
+
});
|
|
386
|
+
return response.data;
|
|
387
|
+
},
|
|
388
|
+
invMastUid
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
async function getItemAccessories(invMastUid) {
|
|
392
|
+
return withServerCache(
|
|
393
|
+
cachePrefix,
|
|
394
|
+
redisTtl,
|
|
395
|
+
"items.invMast.invAccessory.list",
|
|
396
|
+
async () => {
|
|
397
|
+
const response = await api.items.invMast.invAccessory.list(
|
|
398
|
+
invMastUid,
|
|
399
|
+
{ edgeCache }
|
|
400
|
+
);
|
|
401
|
+
return response.data;
|
|
402
|
+
},
|
|
403
|
+
invMastUid
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
async function getSimilarItems(invMastUid) {
|
|
407
|
+
return withServerCache(
|
|
408
|
+
cachePrefix,
|
|
409
|
+
longRedisTtl,
|
|
410
|
+
"items.invMast.similar.list",
|
|
411
|
+
async () => {
|
|
412
|
+
const response = await api.items.invMast.similar.list(invMastUid, {
|
|
413
|
+
edgeCache: longEdgeCache
|
|
414
|
+
});
|
|
415
|
+
return response.data;
|
|
416
|
+
},
|
|
417
|
+
invMastUid
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
async function batchGetInvMastDocs(params) {
|
|
421
|
+
const results = await Promise.all(
|
|
422
|
+
params.map(
|
|
423
|
+
(p) => getInvMastDoc(p).then((data) => [p.itemId ?? String(p.invMastUid), data]).catch(() => [p.itemId ?? String(p.invMastUid), void 0])
|
|
424
|
+
)
|
|
425
|
+
);
|
|
426
|
+
const out = {};
|
|
427
|
+
for (const [key, data] of results) {
|
|
428
|
+
if (data) out[key] = data;
|
|
429
|
+
}
|
|
430
|
+
return out;
|
|
431
|
+
}
|
|
432
|
+
async function batchGetStockData(invMastUids) {
|
|
433
|
+
const results = await Promise.all(
|
|
434
|
+
invMastUids.map(
|
|
435
|
+
(uid) => getStock(uid).then((data) => [uid, data]).catch(() => [uid, void 0])
|
|
436
|
+
)
|
|
437
|
+
);
|
|
438
|
+
const out = {};
|
|
439
|
+
for (const [uid, data] of results) {
|
|
440
|
+
if (data) out[uid] = data;
|
|
441
|
+
}
|
|
442
|
+
return out;
|
|
443
|
+
}
|
|
444
|
+
return {
|
|
445
|
+
itemCategoryLookup,
|
|
446
|
+
getItemCategory,
|
|
447
|
+
getCategoryItems,
|
|
448
|
+
getItemAttributes,
|
|
449
|
+
getInvMast,
|
|
450
|
+
getInvMastDoc,
|
|
451
|
+
getStock,
|
|
452
|
+
getStockCompanySummary,
|
|
453
|
+
getItemFaqs,
|
|
454
|
+
getItemSubstitutes,
|
|
455
|
+
getItemAccessories,
|
|
456
|
+
getSimilarItems,
|
|
457
|
+
batchGetInvMastDocs,
|
|
458
|
+
batchGetStockData
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// src/actions/commerce.ts
|
|
463
|
+
function createCommerceActions(api, config = {}) {
|
|
464
|
+
const { defaultContactId, defaultCustomerId, convertUnitOfMeasure } = config;
|
|
465
|
+
async function cartHdrLookup(params) {
|
|
466
|
+
const lookupParams = { ...params };
|
|
467
|
+
if (lookupParams.contactId == null && defaultContactId != null) {
|
|
468
|
+
lookupParams.contactId = defaultContactId;
|
|
469
|
+
}
|
|
470
|
+
if (lookupParams.customerId == null && defaultCustomerId != null) {
|
|
471
|
+
lookupParams.customerId = defaultCustomerId;
|
|
472
|
+
}
|
|
473
|
+
const response = await api.commerce.cartHdr.lookup.get(lookupParams);
|
|
474
|
+
return response.data;
|
|
475
|
+
}
|
|
476
|
+
async function getCartLines(cartHdrUid) {
|
|
477
|
+
const response = await api.commerce.cartLine.get(cartHdrUid);
|
|
478
|
+
return response.data;
|
|
479
|
+
}
|
|
480
|
+
async function addToCart(cartHdrUid, items) {
|
|
481
|
+
try {
|
|
482
|
+
const mappedItems = items.map((item) => ({
|
|
483
|
+
...item,
|
|
484
|
+
unitOfMeasure: convertUnitOfMeasure ? convertUnitOfMeasure(item.unitOfMeasure) : item.unitOfMeasure
|
|
485
|
+
}));
|
|
486
|
+
const response = await api.commerce.cartLine.add.create(
|
|
487
|
+
cartHdrUid,
|
|
488
|
+
{ items: mappedItems }
|
|
489
|
+
);
|
|
490
|
+
return response.data;
|
|
491
|
+
} catch {
|
|
492
|
+
return void 0;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
async function updateCartLines(cartHdrUid, lines) {
|
|
496
|
+
try {
|
|
497
|
+
const mappedLines = lines.map((line) => ({
|
|
498
|
+
...line,
|
|
499
|
+
unitOfMeasure: convertUnitOfMeasure ? convertUnitOfMeasure(line.unitOfMeasure) : line.unitOfMeasure
|
|
500
|
+
}));
|
|
501
|
+
const response = await api.commerce.cartLine.update.create(
|
|
502
|
+
cartHdrUid,
|
|
503
|
+
{ lines: mappedLines }
|
|
504
|
+
);
|
|
505
|
+
return response.data;
|
|
506
|
+
} catch {
|
|
507
|
+
return void 0;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
async function deleteCartItems(cartHdrUid) {
|
|
511
|
+
try {
|
|
512
|
+
await api.commerce.cartLine.delete(cartHdrUid);
|
|
513
|
+
} catch {
|
|
152
514
|
}
|
|
153
|
-
}
|
|
515
|
+
}
|
|
516
|
+
async function getCartAlsoBought(cartHdrUid) {
|
|
517
|
+
const response = await api.commerce.cartHdr.alsoBought.get(cartHdrUid);
|
|
518
|
+
return response.data;
|
|
519
|
+
}
|
|
520
|
+
async function checkoutOrder(cartHdrUid, data) {
|
|
521
|
+
try {
|
|
522
|
+
const response = await api.commerce.checkout.create({
|
|
523
|
+
...data,
|
|
524
|
+
cartHdrUid
|
|
525
|
+
});
|
|
526
|
+
return response.data;
|
|
527
|
+
} catch {
|
|
528
|
+
return void 0;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
cartHdrLookup,
|
|
533
|
+
getCartLines,
|
|
534
|
+
addToCart,
|
|
535
|
+
updateCartLines,
|
|
536
|
+
deleteCartItems,
|
|
537
|
+
getCartAlsoBought,
|
|
538
|
+
checkoutOrder
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/actions/orders.ts
|
|
543
|
+
function createOrderActions(api, config = {}) {
|
|
544
|
+
const { cachePrefix = "", edgeCache = 1, redisTtl = 3600 } = config;
|
|
545
|
+
async function getOrderDoc(orderNo, zipCode) {
|
|
546
|
+
const params = { orderNo, zipCode, edgeCache };
|
|
547
|
+
return withServerCache(
|
|
548
|
+
cachePrefix,
|
|
549
|
+
redisTtl,
|
|
550
|
+
"orders.oeHdr.doc.get",
|
|
551
|
+
async () => {
|
|
552
|
+
const response = await api.orders.oeHdr.doc.get(params);
|
|
553
|
+
return response.data;
|
|
554
|
+
},
|
|
555
|
+
params
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
return { getOrderDoc };
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// src/actions/search.ts
|
|
562
|
+
function createSearchActions(api, config = {}) {
|
|
563
|
+
const {
|
|
564
|
+
cachePrefix = "",
|
|
565
|
+
edgeCache = 1,
|
|
566
|
+
redisTtl = 3600,
|
|
567
|
+
defaultSourceFields = "display_desc"
|
|
568
|
+
} = config;
|
|
569
|
+
async function getSearchAttributes(q) {
|
|
570
|
+
const params = { q, edgeCache };
|
|
571
|
+
return withServerCache(
|
|
572
|
+
cachePrefix,
|
|
573
|
+
redisTtl,
|
|
574
|
+
"openSearch.itemSearch.attributes.list",
|
|
575
|
+
async () => {
|
|
576
|
+
const response = await api.openSearch.itemSearch.attributes.list(params);
|
|
577
|
+
return response.data.attributes;
|
|
578
|
+
},
|
|
579
|
+
q
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
async function getSearchSuggestions(q, limit, offset) {
|
|
583
|
+
const params = { q, edgeCache };
|
|
584
|
+
if (limit !== void 0) params.size = limit;
|
|
585
|
+
if (offset !== void 0) params.from = offset;
|
|
586
|
+
return withServerCache(
|
|
587
|
+
cachePrefix,
|
|
588
|
+
redisTtl,
|
|
589
|
+
"openSearch.suggestions.suggest.list",
|
|
590
|
+
async () => {
|
|
591
|
+
const response = await api.openSearch.suggestions.suggest.list(params);
|
|
592
|
+
return response.data;
|
|
593
|
+
},
|
|
594
|
+
q
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
async function itemSearch(filters, itemCategoryUid) {
|
|
598
|
+
const params = {
|
|
599
|
+
q: filters.q,
|
|
600
|
+
searchType: "query",
|
|
601
|
+
size: filters.limit,
|
|
602
|
+
from: filters.offset,
|
|
603
|
+
sortBy: filters.sortBy,
|
|
604
|
+
classId5List: itemCategoryUid ? String(itemCategoryUid) : void 0,
|
|
605
|
+
filters: filters.filters?.length ? JSON.stringify(filters.filters) : void 0,
|
|
606
|
+
sourceFieldsList: defaultSourceFields,
|
|
607
|
+
edgeCache
|
|
608
|
+
};
|
|
609
|
+
return withServerCache(
|
|
610
|
+
cachePrefix,
|
|
611
|
+
redisTtl,
|
|
612
|
+
"openSearch.itemSearch.list",
|
|
613
|
+
async () => {
|
|
614
|
+
const response = await api.openSearch.itemSearch.list(params);
|
|
615
|
+
return response.data;
|
|
616
|
+
},
|
|
617
|
+
filters,
|
|
618
|
+
itemCategoryUid
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
async function itemSearchInfinite(filters, itemCategoryUid, pageParam = 0) {
|
|
622
|
+
const params = {
|
|
623
|
+
q: filters.q,
|
|
624
|
+
searchType: "query",
|
|
625
|
+
size: filters.limit,
|
|
626
|
+
from: pageParam,
|
|
627
|
+
sortBy: filters.sortBy,
|
|
628
|
+
classId5List: itemCategoryUid ? String(itemCategoryUid) : void 0,
|
|
629
|
+
filters: filters.filters?.length ? JSON.stringify(filters.filters) : void 0,
|
|
630
|
+
sourceFieldsList: defaultSourceFields,
|
|
631
|
+
edgeCache
|
|
632
|
+
};
|
|
633
|
+
return withServerCache(
|
|
634
|
+
cachePrefix,
|
|
635
|
+
redisTtl,
|
|
636
|
+
"openSearch.itemSearch.list",
|
|
637
|
+
async () => {
|
|
638
|
+
const response = await api.openSearch.itemSearch.list(params);
|
|
639
|
+
const { items, totalResults } = response.data;
|
|
640
|
+
const nextOffset = pageParam + filters.limit;
|
|
641
|
+
return {
|
|
642
|
+
data: items,
|
|
643
|
+
total: totalResults,
|
|
644
|
+
nextCursor: nextOffset < totalResults ? nextOffset : void 0
|
|
645
|
+
};
|
|
646
|
+
},
|
|
647
|
+
filters,
|
|
648
|
+
itemCategoryUid,
|
|
649
|
+
pageParam
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
return {
|
|
653
|
+
getSearchAttributes,
|
|
654
|
+
getSearchSuggestions,
|
|
655
|
+
itemSearch,
|
|
656
|
+
itemSearchInfinite
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// src/actions/shipping.ts
|
|
661
|
+
function createShippingActions(api, config) {
|
|
662
|
+
const {
|
|
663
|
+
fromAddress,
|
|
664
|
+
defaultServiceCodes,
|
|
665
|
+
cachePrefix = "",
|
|
666
|
+
edgeCache = 1,
|
|
667
|
+
redisTtl = 3600
|
|
668
|
+
} = config;
|
|
669
|
+
async function getShippingRates(toAddress, weight, serviceCodes) {
|
|
670
|
+
const params = {
|
|
671
|
+
fromAddress,
|
|
672
|
+
toAddress: { ...toAddress, country: toAddress.country ?? "US" },
|
|
673
|
+
weight,
|
|
674
|
+
serviceCodes: serviceCodes ?? defaultServiceCodes,
|
|
675
|
+
edgeCache
|
|
676
|
+
};
|
|
677
|
+
return withServerCache(
|
|
678
|
+
cachePrefix,
|
|
679
|
+
redisTtl,
|
|
680
|
+
"ups.ratesShop.get",
|
|
681
|
+
async () => {
|
|
682
|
+
const response = await api.ups.ratesShop.get(params);
|
|
683
|
+
return response.data;
|
|
684
|
+
},
|
|
685
|
+
params
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
return { getShippingRates };
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// src/actions/joomla.ts
|
|
692
|
+
function createJoomlaActions(api, config = {}) {
|
|
693
|
+
const { cachePrefix = "", edgeCache = 1, redisTtl = 3600 } = config;
|
|
694
|
+
async function getJoomlaContent(articleId) {
|
|
695
|
+
return withServerCache(
|
|
696
|
+
cachePrefix,
|
|
697
|
+
redisTtl,
|
|
698
|
+
"joomla.content.doc.get",
|
|
699
|
+
async () => {
|
|
700
|
+
const response = await api.joomla.content.doc.get(articleId, {
|
|
701
|
+
edgeCache
|
|
702
|
+
});
|
|
703
|
+
return response.data;
|
|
704
|
+
},
|
|
705
|
+
articleId
|
|
706
|
+
);
|
|
707
|
+
}
|
|
708
|
+
async function getJoomlaContentList(params) {
|
|
709
|
+
return withServerCache(
|
|
710
|
+
cachePrefix,
|
|
711
|
+
redisTtl,
|
|
712
|
+
"joomla.content.list",
|
|
713
|
+
async () => {
|
|
714
|
+
const response = await api.joomla.content.list({
|
|
715
|
+
...params,
|
|
716
|
+
edgeCache
|
|
717
|
+
});
|
|
718
|
+
return response.data;
|
|
719
|
+
},
|
|
720
|
+
params
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
return { getJoomlaContent, getJoomlaContentList };
|
|
154
724
|
}
|
|
155
|
-
var getServerQueryClient = cache(
|
|
156
|
-
() => createServerQueryClient()
|
|
157
|
-
);
|
|
158
725
|
export {
|
|
159
726
|
cacheGet,
|
|
160
727
|
cacheSet,
|
|
728
|
+
createCommerceActions,
|
|
729
|
+
createItemActions,
|
|
730
|
+
createJoomlaActions,
|
|
731
|
+
createOrderActions,
|
|
732
|
+
createPricingActions,
|
|
161
733
|
createQueryOptions,
|
|
734
|
+
createSearchActions,
|
|
162
735
|
createServerQueryClient,
|
|
736
|
+
createShippingActions,
|
|
163
737
|
createSuspenseQueryOptions,
|
|
164
738
|
env,
|
|
165
739
|
getCircuitState,
|
|
@@ -168,6 +742,7 @@ export {
|
|
|
168
742
|
isProduction,
|
|
169
743
|
isRedisConnected,
|
|
170
744
|
isStaging,
|
|
171
|
-
sdkCall
|
|
745
|
+
sdkCall,
|
|
746
|
+
withServerCache
|
|
172
747
|
};
|
|
173
748
|
//# sourceMappingURL=index.js.map
|