@cimplify/sdk 0.6.11 → 0.7.0
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 +8 -3
- package/dist/advanced.d.mts +2 -2
- package/dist/advanced.d.ts +2 -2
- package/dist/advanced.js +529 -102
- package/dist/advanced.mjs +529 -102
- package/dist/{client-DM3-ZG29.d.ts → client-CyBNao15.d.ts} +15 -927
- package/dist/{client-BngAGN0v.d.mts → client-hccS_JMl.d.mts} +15 -927
- package/dist/{index-DaKJxoEh.d.mts → index-B_JHO-ER.d.ts} +29 -35
- package/dist/{index-pztT_bcJ.d.ts → index-mrKi_VbR.d.mts} +29 -35
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +585 -105
- package/dist/index.mjs +582 -106
- package/dist/payment-CLIWNMaP.d.mts +1133 -0
- package/dist/payment-CLIWNMaP.d.ts +1133 -0
- package/dist/react.d.mts +5 -2
- package/dist/react.d.ts +5 -2
- package/dist/react.js +582 -108
- package/dist/react.mjs +582 -108
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +27 -0
- package/dist/utils.mjs +24 -1
- package/package.json +1 -1
- package/dist/payment-Cu75tmUc.d.mts +0 -196
- package/dist/payment-Cu75tmUc.d.ts +0 -196
package/dist/advanced.mjs
CHANGED
|
@@ -18,7 +18,8 @@ function currencyCode(value) {
|
|
|
18
18
|
}
|
|
19
19
|
var ErrorCode = {
|
|
20
20
|
// General
|
|
21
|
-
UNKNOWN_ERROR: "UNKNOWN_ERROR"
|
|
21
|
+
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
22
|
+
NOT_FOUND: "NOT_FOUND"};
|
|
22
23
|
var DOCS_ERROR_BASE_URL = "https://docs.cimplify.io/reference/error-codes";
|
|
23
24
|
function docsUrlForCode(code) {
|
|
24
25
|
return `${DOCS_ERROR_BASE_URL}#${code.toLowerCase().replace(/_/g, "-")}`;
|
|
@@ -42,6 +43,10 @@ var ERROR_SUGGESTIONS = {
|
|
|
42
43
|
CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
|
|
43
44
|
DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
|
|
44
45
|
CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
|
|
46
|
+
QUOTE_NOT_FOUND: "Quote could not be found. Refresh pricing and create a new quote before checkout.",
|
|
47
|
+
QUOTE_EXPIRED: "Quote has expired. Re-fetch pricing to generate a new quote with a valid expiry window.",
|
|
48
|
+
QUOTE_CONSUMED: "Quote has already been used. Request a fresh quote to prevent duplicate checkout attempts.",
|
|
49
|
+
QUOTE_STORAGE_UNAVAILABLE: "Quote storage is temporarily unavailable. Retry shortly and avoid charging until quote fetch succeeds.",
|
|
45
50
|
PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
|
|
46
51
|
PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
|
|
47
52
|
INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
|
|
@@ -198,6 +203,23 @@ async function safe(promise) {
|
|
|
198
203
|
return err(toCimplifyError(error));
|
|
199
204
|
}
|
|
200
205
|
}
|
|
206
|
+
async function safeWithFallback(primary, fallback) {
|
|
207
|
+
const primaryResult = await safe(primary());
|
|
208
|
+
if (primaryResult.ok) return primaryResult;
|
|
209
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
210
|
+
return primaryResult;
|
|
211
|
+
}
|
|
212
|
+
return safe(fallback());
|
|
213
|
+
}
|
|
214
|
+
function withQuery(path, params) {
|
|
215
|
+
const query2 = new URLSearchParams();
|
|
216
|
+
for (const [key, value] of Object.entries(params)) {
|
|
217
|
+
if (value === void 0) continue;
|
|
218
|
+
query2.set(key, String(value));
|
|
219
|
+
}
|
|
220
|
+
const queryString = query2.toString();
|
|
221
|
+
return queryString ? `${path}?${queryString}` : path;
|
|
222
|
+
}
|
|
201
223
|
function isRecord(value) {
|
|
202
224
|
return typeof value === "object" && value !== null;
|
|
203
225
|
}
|
|
@@ -255,6 +277,69 @@ function findProductBySlug(products, slug) {
|
|
|
255
277
|
return typeof value === "string" && value === slug;
|
|
256
278
|
});
|
|
257
279
|
}
|
|
280
|
+
function findCategoryBySlug(categories, slug) {
|
|
281
|
+
return categories.find((category) => {
|
|
282
|
+
const value = category["slug"];
|
|
283
|
+
return typeof value === "string" && value === slug;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function hasCategorySlug(category) {
|
|
287
|
+
const value = category["slug"];
|
|
288
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
289
|
+
}
|
|
290
|
+
function toFiniteNumber(value) {
|
|
291
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
292
|
+
return value;
|
|
293
|
+
}
|
|
294
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
295
|
+
const parsed = Number(value);
|
|
296
|
+
if (Number.isFinite(parsed)) {
|
|
297
|
+
return parsed;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return void 0;
|
|
301
|
+
}
|
|
302
|
+
function normalizePagination(value) {
|
|
303
|
+
if (!isRecord(value)) {
|
|
304
|
+
return void 0;
|
|
305
|
+
}
|
|
306
|
+
const totalCount = toFiniteNumber(value.total_count);
|
|
307
|
+
const currentPage = toFiniteNumber(value.current_page);
|
|
308
|
+
const pageSize = toFiniteNumber(value.page_size);
|
|
309
|
+
const totalPages = toFiniteNumber(value.total_pages);
|
|
310
|
+
if (totalCount === void 0 || currentPage === void 0 || pageSize === void 0 || totalPages === void 0) {
|
|
311
|
+
return void 0;
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
total_count: totalCount,
|
|
315
|
+
current_page: currentPage,
|
|
316
|
+
page_size: pageSize,
|
|
317
|
+
total_pages: totalPages,
|
|
318
|
+
has_more: value.has_more === true,
|
|
319
|
+
next_cursor: typeof value.next_cursor === "string" ? value.next_cursor : void 0
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function normalizeCatalogueResult(payload) {
|
|
323
|
+
if (Array.isArray(payload)) {
|
|
324
|
+
return {
|
|
325
|
+
items: payload.map((product) => normalizeCatalogueProductPayload(product)),
|
|
326
|
+
is_complete: true
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
if (!isRecord(payload)) {
|
|
330
|
+
return {
|
|
331
|
+
items: [],
|
|
332
|
+
is_complete: true
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
const rawItems = Array.isArray(payload.products) ? payload.products : Array.isArray(payload.items) ? payload.items : [];
|
|
336
|
+
return {
|
|
337
|
+
items: rawItems.map((product) => normalizeCatalogueProductPayload(product)),
|
|
338
|
+
is_complete: typeof payload.is_complete === "boolean" ? payload.is_complete : true,
|
|
339
|
+
total_available: toFiniteNumber(payload.total_available),
|
|
340
|
+
pagination: normalizePagination(payload.pagination)
|
|
341
|
+
};
|
|
342
|
+
}
|
|
258
343
|
var CatalogueQueries = class {
|
|
259
344
|
constructor(client) {
|
|
260
345
|
this.client = client;
|
|
@@ -274,6 +359,13 @@ var CatalogueQueries = class {
|
|
|
274
359
|
if (options?.search) {
|
|
275
360
|
filters.push(`@.name contains '${escapeQueryValue(options.search)}'`);
|
|
276
361
|
}
|
|
362
|
+
if (options?.tags?.length) {
|
|
363
|
+
for (const tag of options.tags) {
|
|
364
|
+
if (tag.trim().length > 0) {
|
|
365
|
+
filters.push(`@.tags contains '${escapeQueryValue(tag)}'`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
277
369
|
if (options?.min_price !== void 0) {
|
|
278
370
|
filters.push(`@.price>=${options.min_price}`);
|
|
279
371
|
}
|
|
@@ -286,25 +378,57 @@ var CatalogueQueries = class {
|
|
|
286
378
|
if (options?.sort_by) {
|
|
287
379
|
query2 += `#sort(${options.sort_by},${options.sort_order || "asc"})`;
|
|
288
380
|
}
|
|
289
|
-
if (options?.limit) {
|
|
381
|
+
if (options?.limit !== void 0) {
|
|
290
382
|
query2 += `#limit(${options.limit})`;
|
|
291
383
|
}
|
|
292
|
-
if (options?.offset) {
|
|
384
|
+
if (options?.offset !== void 0) {
|
|
293
385
|
query2 += `#offset(${options.offset})`;
|
|
294
386
|
}
|
|
295
|
-
const
|
|
387
|
+
const path = withQuery("/api/v1/catalogue/products", {
|
|
388
|
+
category_id: options?.category,
|
|
389
|
+
search: options?.search,
|
|
390
|
+
page: options?.page,
|
|
391
|
+
tags: options?.tags?.join(","),
|
|
392
|
+
featured: options?.featured,
|
|
393
|
+
in_stock: options?.in_stock,
|
|
394
|
+
min_price: options?.min_price,
|
|
395
|
+
max_price: options?.max_price,
|
|
396
|
+
sort_by: options?.sort_by,
|
|
397
|
+
sort_order: options?.sort_order,
|
|
398
|
+
limit: options?.limit,
|
|
399
|
+
offset: options?.offset,
|
|
400
|
+
cursor: options?.cursor
|
|
401
|
+
});
|
|
402
|
+
const result = await safeWithFallback(
|
|
403
|
+
() => this.client.get(path),
|
|
404
|
+
() => this.client.query(query2)
|
|
405
|
+
);
|
|
296
406
|
if (!result.ok) return result;
|
|
297
|
-
return ok(result.value
|
|
407
|
+
return ok(normalizeCatalogueResult(result.value));
|
|
298
408
|
}
|
|
299
409
|
async getProduct(id) {
|
|
300
|
-
const
|
|
410
|
+
const encodedId = encodeURIComponent(id);
|
|
411
|
+
const result = await safeWithFallback(
|
|
412
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}`),
|
|
413
|
+
() => this.client.query(`products.${id}`)
|
|
414
|
+
);
|
|
301
415
|
if (!result.ok) return result;
|
|
302
416
|
return ok(normalizeCatalogueProductPayload(result.value));
|
|
303
417
|
}
|
|
304
418
|
async getProductBySlug(slug) {
|
|
419
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
420
|
+
const restResult = await safe(
|
|
421
|
+
this.client.get(`/api/v1/catalogue/products/slug/${encodedSlug}`)
|
|
422
|
+
);
|
|
423
|
+
if (restResult.ok) {
|
|
424
|
+
return ok(normalizeCatalogueProductPayload(restResult.value));
|
|
425
|
+
}
|
|
426
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
427
|
+
return restResult;
|
|
428
|
+
}
|
|
305
429
|
const filteredResult = await safe(
|
|
306
430
|
this.client.query(
|
|
307
|
-
`products[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
431
|
+
`products[?(@.slug=='${escapeQueryValue(slug)}')]#limit(50)`
|
|
308
432
|
)
|
|
309
433
|
);
|
|
310
434
|
if (!filteredResult.ok) return filteredResult;
|
|
@@ -315,7 +439,9 @@ var CatalogueQueries = class {
|
|
|
315
439
|
if (filteredResult.value.length === 1) {
|
|
316
440
|
return ok(normalizeCatalogueProductPayload(filteredResult.value[0]));
|
|
317
441
|
}
|
|
318
|
-
const unfilteredResult = await safe(
|
|
442
|
+
const unfilteredResult = await safe(
|
|
443
|
+
this.client.query("products#limit(200)")
|
|
444
|
+
);
|
|
319
445
|
if (!unfilteredResult.ok) return unfilteredResult;
|
|
320
446
|
const fallbackMatch = findProductBySlug(unfilteredResult.value, slug);
|
|
321
447
|
if (!fallbackMatch) {
|
|
@@ -324,18 +450,33 @@ var CatalogueQueries = class {
|
|
|
324
450
|
return ok(normalizeCatalogueProductPayload(fallbackMatch));
|
|
325
451
|
}
|
|
326
452
|
async getVariants(productId) {
|
|
327
|
-
|
|
453
|
+
const encodedId = encodeURIComponent(productId);
|
|
454
|
+
return safeWithFallback(
|
|
455
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`),
|
|
456
|
+
() => this.client.query(`products.${productId}.variants`)
|
|
457
|
+
);
|
|
328
458
|
}
|
|
329
459
|
async getVariantAxes(productId) {
|
|
330
|
-
|
|
460
|
+
const encodedId = encodeURIComponent(productId);
|
|
461
|
+
return safeWithFallback(
|
|
462
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`),
|
|
463
|
+
() => this.client.query(`products.${productId}.variant_axes`)
|
|
464
|
+
);
|
|
331
465
|
}
|
|
332
466
|
/**
|
|
333
467
|
* Find a variant by axis selections (e.g., { "Size": "Large", "Color": "Red" })
|
|
334
468
|
* Returns the matching variant or null if no match found.
|
|
335
469
|
*/
|
|
336
470
|
async getVariantByAxisSelections(productId, selections) {
|
|
337
|
-
|
|
338
|
-
|
|
471
|
+
const encodedId = encodeURIComponent(productId);
|
|
472
|
+
return safeWithFallback(
|
|
473
|
+
() => this.client.post(
|
|
474
|
+
`/api/v1/catalogue/products/${encodedId}/variants/find`,
|
|
475
|
+
{
|
|
476
|
+
axis_selections: selections
|
|
477
|
+
}
|
|
478
|
+
),
|
|
479
|
+
() => this.client.query(`products.${productId}.variant`, {
|
|
339
480
|
axis_selections: selections
|
|
340
481
|
})
|
|
341
482
|
);
|
|
@@ -344,45 +485,107 @@ var CatalogueQueries = class {
|
|
|
344
485
|
* Get a specific variant by its ID
|
|
345
486
|
*/
|
|
346
487
|
async getVariantById(productId, variantId) {
|
|
347
|
-
|
|
488
|
+
const encodedProductId = encodeURIComponent(productId);
|
|
489
|
+
const encodedVariantId = encodeURIComponent(variantId);
|
|
490
|
+
return safeWithFallback(
|
|
491
|
+
() => this.client.get(
|
|
492
|
+
`/api/v1/catalogue/products/${encodedProductId}/variants/${encodedVariantId}`
|
|
493
|
+
),
|
|
494
|
+
() => this.client.query(`products.${productId}.variant.${variantId}`)
|
|
495
|
+
);
|
|
348
496
|
}
|
|
349
497
|
async getAddOns(productId) {
|
|
350
|
-
|
|
498
|
+
const encodedId = encodeURIComponent(productId);
|
|
499
|
+
return safeWithFallback(
|
|
500
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`),
|
|
501
|
+
() => this.client.query(`products.${productId}.add_ons`)
|
|
502
|
+
);
|
|
351
503
|
}
|
|
352
504
|
async getCategories() {
|
|
353
|
-
|
|
505
|
+
const result = await safeWithFallback(
|
|
506
|
+
() => this.client.get("/api/v1/catalogue/categories"),
|
|
507
|
+
() => this.client.query("categories")
|
|
508
|
+
);
|
|
509
|
+
if (!result.ok) return result;
|
|
510
|
+
if (result.value.some(hasCategorySlug)) {
|
|
511
|
+
return result;
|
|
512
|
+
}
|
|
513
|
+
const catalogueResult = await safe(
|
|
514
|
+
this.client.query("catalogue#limit(1)")
|
|
515
|
+
);
|
|
516
|
+
if (!catalogueResult.ok) {
|
|
517
|
+
return result;
|
|
518
|
+
}
|
|
519
|
+
const fallbackCategories = Array.isArray(catalogueResult.value.categories) ? catalogueResult.value.categories : [];
|
|
520
|
+
return fallbackCategories.length > 0 ? ok(fallbackCategories) : result;
|
|
354
521
|
}
|
|
355
522
|
async getCategory(id) {
|
|
356
|
-
|
|
523
|
+
const encodedId = encodeURIComponent(id);
|
|
524
|
+
return safeWithFallback(
|
|
525
|
+
() => this.client.get(`/api/v1/catalogue/categories/${encodedId}`),
|
|
526
|
+
() => this.client.query(`categories.${id}`)
|
|
527
|
+
);
|
|
357
528
|
}
|
|
358
529
|
async getCategoryBySlug(slug) {
|
|
530
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
531
|
+
const restResult = await safe(this.client.get(`/api/v1/catalogue/categories/slug/${encodedSlug}`));
|
|
532
|
+
if (restResult.ok) {
|
|
533
|
+
return restResult;
|
|
534
|
+
}
|
|
535
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
536
|
+
return restResult;
|
|
537
|
+
}
|
|
359
538
|
const result = await safe(
|
|
360
539
|
this.client.query(`categories[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
361
540
|
);
|
|
362
541
|
if (!result.ok) return result;
|
|
363
|
-
|
|
542
|
+
const exactMatch = findCategoryBySlug(result.value, slug);
|
|
543
|
+
if (exactMatch) {
|
|
544
|
+
return ok(exactMatch);
|
|
545
|
+
}
|
|
546
|
+
const categoriesResult = await this.getCategories();
|
|
547
|
+
if (!categoriesResult.ok) {
|
|
548
|
+
return categoriesResult;
|
|
549
|
+
}
|
|
550
|
+
const fallbackMatch = findCategoryBySlug(categoriesResult.value, slug);
|
|
551
|
+
if (!fallbackMatch) {
|
|
364
552
|
return err(new CimplifyError("NOT_FOUND", `Category not found: ${slug}`, false));
|
|
365
553
|
}
|
|
366
|
-
return ok(
|
|
554
|
+
return ok(fallbackMatch);
|
|
367
555
|
}
|
|
368
556
|
async getCategoryProducts(categoryId) {
|
|
369
|
-
|
|
370
|
-
|
|
557
|
+
const encodedId = encodeURIComponent(categoryId);
|
|
558
|
+
return safeWithFallback(
|
|
559
|
+
() => this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`),
|
|
560
|
+
() => this.client.query(
|
|
371
561
|
`products[?(@.category_id=='${escapeQueryValue(categoryId)}')]`
|
|
372
562
|
)
|
|
373
563
|
);
|
|
374
564
|
}
|
|
375
565
|
async getCollections() {
|
|
376
|
-
return
|
|
566
|
+
return safeWithFallback(
|
|
567
|
+
() => this.client.get("/api/v1/catalogue/collections"),
|
|
568
|
+
() => this.client.query("collections")
|
|
569
|
+
);
|
|
377
570
|
}
|
|
378
571
|
async getCollection(id) {
|
|
379
|
-
|
|
572
|
+
const encodedId = encodeURIComponent(id);
|
|
573
|
+
return safeWithFallback(
|
|
574
|
+
() => this.client.get(`/api/v1/catalogue/collections/${encodedId}`),
|
|
575
|
+
() => this.client.query(`collections.${id}`)
|
|
576
|
+
);
|
|
380
577
|
}
|
|
381
578
|
async getCollectionBySlug(slug) {
|
|
579
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
580
|
+
const restResult = await safe(
|
|
581
|
+
this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`)
|
|
582
|
+
);
|
|
583
|
+
if (restResult.ok) return restResult;
|
|
584
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
585
|
+
return restResult;
|
|
586
|
+
}
|
|
382
587
|
const result = await safe(
|
|
383
|
-
this.client.query(
|
|
384
|
-
`collections[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
385
|
-
)
|
|
588
|
+
this.client.query(`collections[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
386
589
|
);
|
|
387
590
|
if (!result.ok) return result;
|
|
388
591
|
if (!result.value.length) {
|
|
@@ -391,22 +594,43 @@ var CatalogueQueries = class {
|
|
|
391
594
|
return ok(result.value[0]);
|
|
392
595
|
}
|
|
393
596
|
async getCollectionProducts(collectionId) {
|
|
394
|
-
|
|
597
|
+
const encodedId = encodeURIComponent(collectionId);
|
|
598
|
+
return safeWithFallback(
|
|
599
|
+
() => this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`),
|
|
600
|
+
() => this.client.query(`collections.${collectionId}.products`)
|
|
601
|
+
);
|
|
395
602
|
}
|
|
396
603
|
async searchCollections(query2, limit = 20) {
|
|
397
|
-
|
|
398
|
-
|
|
604
|
+
const path = withQuery("/api/v1/catalogue/collections", { search: query2, limit });
|
|
605
|
+
return safeWithFallback(
|
|
606
|
+
() => this.client.get(path),
|
|
607
|
+
() => this.client.query(
|
|
399
608
|
`collections[?(@.name contains '${escapeQueryValue(query2)}')]#limit(${limit})`
|
|
400
609
|
)
|
|
401
610
|
);
|
|
402
611
|
}
|
|
403
612
|
async getBundles() {
|
|
404
|
-
return
|
|
613
|
+
return safeWithFallback(
|
|
614
|
+
() => this.client.get("/api/v1/catalogue/bundles"),
|
|
615
|
+
() => this.client.query("bundles")
|
|
616
|
+
);
|
|
405
617
|
}
|
|
406
618
|
async getBundle(id) {
|
|
407
|
-
|
|
619
|
+
const encodedId = encodeURIComponent(id);
|
|
620
|
+
return safeWithFallback(
|
|
621
|
+
() => this.client.get(`/api/v1/catalogue/bundles/${encodedId}`),
|
|
622
|
+
() => this.client.query(`bundles.${id}`)
|
|
623
|
+
);
|
|
408
624
|
}
|
|
409
625
|
async getBundleBySlug(slug) {
|
|
626
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
627
|
+
const restResult = await safe(
|
|
628
|
+
this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`)
|
|
629
|
+
);
|
|
630
|
+
if (restResult.ok) return restResult;
|
|
631
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
632
|
+
return restResult;
|
|
633
|
+
}
|
|
410
634
|
const result = await safe(
|
|
411
635
|
this.client.query(
|
|
412
636
|
`bundles[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
@@ -419,8 +643,10 @@ var CatalogueQueries = class {
|
|
|
419
643
|
return ok(result.value[0]);
|
|
420
644
|
}
|
|
421
645
|
async searchBundles(query2, limit = 20) {
|
|
422
|
-
|
|
423
|
-
|
|
646
|
+
const path = withQuery("/api/v1/catalogue/bundles", { search: query2, limit });
|
|
647
|
+
return safeWithFallback(
|
|
648
|
+
() => this.client.get(path),
|
|
649
|
+
() => this.client.query(
|
|
424
650
|
`bundles[?(@.name contains '${escapeQueryValue(query2)}')]#limit(${limit})`
|
|
425
651
|
)
|
|
426
652
|
);
|
|
@@ -430,17 +656,39 @@ var CatalogueQueries = class {
|
|
|
430
656
|
if (options?.limit) {
|
|
431
657
|
query2 += `#limit(${options.limit})`;
|
|
432
658
|
}
|
|
433
|
-
|
|
659
|
+
const path = withQuery("/api/v1/catalogue/composites", { limit: options?.limit });
|
|
660
|
+
return safeWithFallback(
|
|
661
|
+
() => this.client.get(path),
|
|
662
|
+
() => this.client.query(query2)
|
|
663
|
+
);
|
|
434
664
|
}
|
|
435
665
|
async getComposite(id) {
|
|
436
|
-
|
|
666
|
+
const encodedId = encodeURIComponent(id);
|
|
667
|
+
return safeWithFallback(
|
|
668
|
+
() => this.client.get(`/api/v1/catalogue/composites/${encodedId}`),
|
|
669
|
+
() => this.client.query(`composites.${id}`)
|
|
670
|
+
);
|
|
437
671
|
}
|
|
438
672
|
async getCompositeByProductId(productId) {
|
|
439
|
-
|
|
673
|
+
const encodedId = encodeURIComponent(productId);
|
|
674
|
+
return safeWithFallback(
|
|
675
|
+
() => this.client.get(
|
|
676
|
+
`/api/v1/catalogue/composites/by-product/${encodedId}`
|
|
677
|
+
),
|
|
678
|
+
() => this.client.query(`composites.by_product.${productId}`)
|
|
679
|
+
);
|
|
440
680
|
}
|
|
441
681
|
async calculateCompositePrice(compositeId, selections, locationId) {
|
|
442
|
-
|
|
443
|
-
|
|
682
|
+
const encodedId = encodeURIComponent(compositeId);
|
|
683
|
+
return safeWithFallback(
|
|
684
|
+
() => this.client.post(
|
|
685
|
+
`/api/v1/catalogue/composites/${encodedId}/calculate-price`,
|
|
686
|
+
{
|
|
687
|
+
selections,
|
|
688
|
+
location_id: locationId
|
|
689
|
+
}
|
|
690
|
+
),
|
|
691
|
+
() => this.client.call("composite.calculatePrice", {
|
|
444
692
|
composite_id: compositeId,
|
|
445
693
|
selections,
|
|
446
694
|
location_id: locationId
|
|
@@ -448,35 +696,41 @@ var CatalogueQueries = class {
|
|
|
448
696
|
);
|
|
449
697
|
}
|
|
450
698
|
async fetchQuote(input) {
|
|
451
|
-
return
|
|
699
|
+
return safeWithFallback(
|
|
700
|
+
() => this.client.post("/api/v1/catalogue/quotes", input),
|
|
701
|
+
() => this.client.call("catalogue.createQuote", input)
|
|
702
|
+
);
|
|
452
703
|
}
|
|
453
704
|
async getQuote(quoteId) {
|
|
454
|
-
|
|
455
|
-
|
|
705
|
+
const encodedQuoteId = encodeURIComponent(quoteId);
|
|
706
|
+
return safeWithFallback(
|
|
707
|
+
() => this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`),
|
|
708
|
+
() => this.client.call("catalogue.getQuote", {
|
|
456
709
|
quote_id: quoteId
|
|
457
710
|
})
|
|
458
711
|
);
|
|
459
712
|
}
|
|
460
713
|
async refreshQuote(input) {
|
|
461
|
-
|
|
714
|
+
const encodedQuoteId = encodeURIComponent(input.quote_id);
|
|
715
|
+
return safeWithFallback(
|
|
716
|
+
() => this.client.post(
|
|
717
|
+
`/api/v1/catalogue/quotes/${encodedQuoteId}/refresh`,
|
|
718
|
+
input
|
|
719
|
+
),
|
|
720
|
+
() => this.client.call("catalogue.refreshQuote", input)
|
|
721
|
+
);
|
|
462
722
|
}
|
|
463
723
|
async search(query2, options) {
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return
|
|
724
|
+
const result = await this.getProducts({
|
|
725
|
+
search: query2,
|
|
726
|
+
category: options?.category,
|
|
727
|
+
limit: options?.limit ?? 20
|
|
728
|
+
});
|
|
729
|
+
if (!result.ok) return result;
|
|
730
|
+
return ok(result.value.items);
|
|
471
731
|
}
|
|
472
732
|
async searchProducts(query2, options) {
|
|
473
|
-
return
|
|
474
|
-
this.client.call("catalogue.search", {
|
|
475
|
-
query: query2,
|
|
476
|
-
limit: options?.limit ?? 20,
|
|
477
|
-
category: options?.category
|
|
478
|
-
})
|
|
479
|
-
);
|
|
733
|
+
return this.search(query2, options);
|
|
480
734
|
}
|
|
481
735
|
async getMenu(options) {
|
|
482
736
|
let query2 = "menu";
|
|
@@ -486,13 +740,28 @@ var CatalogueQueries = class {
|
|
|
486
740
|
if (options?.limit) {
|
|
487
741
|
query2 += `#limit(${options.limit})`;
|
|
488
742
|
}
|
|
489
|
-
|
|
743
|
+
const path = withQuery("/api/v1/catalogue/menu", {
|
|
744
|
+
category_id: options?.category,
|
|
745
|
+
limit: options?.limit
|
|
746
|
+
});
|
|
747
|
+
return safeWithFallback(
|
|
748
|
+
() => this.client.get(path),
|
|
749
|
+
() => this.client.query(query2)
|
|
750
|
+
);
|
|
490
751
|
}
|
|
491
752
|
async getMenuCategory(categoryId) {
|
|
492
|
-
|
|
753
|
+
const encodedId = encodeURIComponent(categoryId);
|
|
754
|
+
return safeWithFallback(
|
|
755
|
+
() => this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`),
|
|
756
|
+
() => this.client.query(`menu.category.${categoryId}`)
|
|
757
|
+
);
|
|
493
758
|
}
|
|
494
759
|
async getMenuItem(itemId) {
|
|
495
|
-
|
|
760
|
+
const encodedId = encodeURIComponent(itemId);
|
|
761
|
+
return safeWithFallback(
|
|
762
|
+
() => this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`),
|
|
763
|
+
() => this.client.query(`menu.${itemId}`)
|
|
764
|
+
);
|
|
496
765
|
}
|
|
497
766
|
};
|
|
498
767
|
|
|
@@ -511,6 +780,14 @@ async function safe2(promise) {
|
|
|
511
780
|
return err(toCimplifyError2(error));
|
|
512
781
|
}
|
|
513
782
|
}
|
|
783
|
+
async function safeWithFallback2(primary, fallback) {
|
|
784
|
+
const primaryResult = await safe2(primary());
|
|
785
|
+
if (primaryResult.ok) return primaryResult;
|
|
786
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
787
|
+
return primaryResult;
|
|
788
|
+
}
|
|
789
|
+
return safe2(fallback());
|
|
790
|
+
}
|
|
514
791
|
function isUICartResponse(value) {
|
|
515
792
|
return "cart" in value;
|
|
516
793
|
}
|
|
@@ -522,21 +799,36 @@ var CartOperations = class {
|
|
|
522
799
|
this.client = client;
|
|
523
800
|
}
|
|
524
801
|
async get() {
|
|
525
|
-
const result = await
|
|
802
|
+
const result = await safeWithFallback2(
|
|
803
|
+
() => this.client.get("/api/v1/cart"),
|
|
804
|
+
() => this.client.query("cart#enriched")
|
|
805
|
+
);
|
|
526
806
|
if (!result.ok) return result;
|
|
527
807
|
return ok(unwrapEnrichedCart(result.value));
|
|
528
808
|
}
|
|
529
809
|
async getRaw() {
|
|
530
|
-
return
|
|
810
|
+
return safeWithFallback2(
|
|
811
|
+
() => this.client.get("/api/v1/cart"),
|
|
812
|
+
() => this.client.query("cart")
|
|
813
|
+
);
|
|
531
814
|
}
|
|
532
815
|
async getItems() {
|
|
533
|
-
return
|
|
816
|
+
return safeWithFallback2(
|
|
817
|
+
() => this.client.get("/api/v1/cart/items"),
|
|
818
|
+
() => this.client.query("cart_items")
|
|
819
|
+
);
|
|
534
820
|
}
|
|
535
821
|
async getCount() {
|
|
536
|
-
return
|
|
822
|
+
return safeWithFallback2(
|
|
823
|
+
() => this.client.get("/api/v1/cart/count"),
|
|
824
|
+
() => this.client.query("cart#count")
|
|
825
|
+
);
|
|
537
826
|
}
|
|
538
827
|
async getTotal() {
|
|
539
|
-
return
|
|
828
|
+
return safeWithFallback2(
|
|
829
|
+
() => this.client.get("/api/v1/cart/total"),
|
|
830
|
+
() => this.client.query("cart#total")
|
|
831
|
+
);
|
|
540
832
|
}
|
|
541
833
|
async getSummary() {
|
|
542
834
|
const cartResult = await this.get();
|
|
@@ -553,43 +845,66 @@ var CartOperations = class {
|
|
|
553
845
|
});
|
|
554
846
|
}
|
|
555
847
|
async addItem(input) {
|
|
556
|
-
return
|
|
848
|
+
return safeWithFallback2(
|
|
849
|
+
() => this.client.post("/api/v1/cart/items", input),
|
|
850
|
+
() => this.client.call("cart.addItem", input)
|
|
851
|
+
);
|
|
557
852
|
}
|
|
558
853
|
async updateItem(cartItemId, updates) {
|
|
559
|
-
|
|
560
|
-
this.
|
|
854
|
+
if (typeof updates.quantity === "number") {
|
|
855
|
+
return this.updateQuantity(cartItemId, updates.quantity);
|
|
856
|
+
}
|
|
857
|
+
const encodedId = encodeURIComponent(cartItemId);
|
|
858
|
+
return safeWithFallback2(
|
|
859
|
+
() => this.client.patch(`/api/v1/cart/items/${encodedId}`, updates),
|
|
860
|
+
() => this.client.call("cart.updateItem", {
|
|
561
861
|
cart_item_id: cartItemId,
|
|
562
862
|
...updates
|
|
563
863
|
})
|
|
564
864
|
);
|
|
565
865
|
}
|
|
566
866
|
async updateQuantity(cartItemId, quantity) {
|
|
567
|
-
|
|
568
|
-
|
|
867
|
+
const encodedId = encodeURIComponent(cartItemId);
|
|
868
|
+
return safeWithFallback2(
|
|
869
|
+
() => this.client.patch(`/api/v1/cart/items/${encodedId}`, {
|
|
870
|
+
quantity
|
|
871
|
+
}),
|
|
872
|
+
() => this.client.call("cart.updateItemQuantity", {
|
|
569
873
|
cart_item_id: cartItemId,
|
|
570
874
|
quantity
|
|
571
875
|
})
|
|
572
876
|
);
|
|
573
877
|
}
|
|
574
878
|
async removeItem(cartItemId) {
|
|
575
|
-
|
|
576
|
-
|
|
879
|
+
const encodedId = encodeURIComponent(cartItemId);
|
|
880
|
+
return safeWithFallback2(
|
|
881
|
+
() => this.client.delete(`/api/v1/cart/items/${encodedId}`),
|
|
882
|
+
() => this.client.call("cart.removeItem", {
|
|
577
883
|
cart_item_id: cartItemId
|
|
578
884
|
})
|
|
579
885
|
);
|
|
580
886
|
}
|
|
581
887
|
async clear() {
|
|
582
|
-
return
|
|
888
|
+
return safeWithFallback2(
|
|
889
|
+
() => this.client.delete("/api/v1/cart"),
|
|
890
|
+
() => this.client.call("cart.clearCart")
|
|
891
|
+
);
|
|
583
892
|
}
|
|
584
893
|
async applyCoupon(code) {
|
|
585
|
-
return
|
|
586
|
-
this.client.
|
|
894
|
+
return safeWithFallback2(
|
|
895
|
+
() => this.client.post("/api/v1/cart/coupons", {
|
|
896
|
+
coupon_code: code
|
|
897
|
+
}),
|
|
898
|
+
() => this.client.call("cart.applyCoupon", {
|
|
587
899
|
coupon_code: code
|
|
588
900
|
})
|
|
589
901
|
);
|
|
590
902
|
}
|
|
591
903
|
async removeCoupon() {
|
|
592
|
-
return
|
|
904
|
+
return safeWithFallback2(
|
|
905
|
+
() => this.client.delete("/api/v1/cart/coupons/current"),
|
|
906
|
+
() => this.client.call("cart.removeCoupon")
|
|
907
|
+
);
|
|
593
908
|
}
|
|
594
909
|
async isEmpty() {
|
|
595
910
|
const countResult = await this.getCount();
|
|
@@ -1349,6 +1664,14 @@ async function safe3(promise) {
|
|
|
1349
1664
|
return err(toCimplifyError3(error));
|
|
1350
1665
|
}
|
|
1351
1666
|
}
|
|
1667
|
+
async function safeWithFallback3(primary, fallback) {
|
|
1668
|
+
const primaryResult = await safe3(primary());
|
|
1669
|
+
if (primaryResult.ok) return primaryResult;
|
|
1670
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
1671
|
+
return primaryResult;
|
|
1672
|
+
}
|
|
1673
|
+
return safe3(fallback());
|
|
1674
|
+
}
|
|
1352
1675
|
function toTerminalFailure(code, message, recoverable) {
|
|
1353
1676
|
return {
|
|
1354
1677
|
success: false,
|
|
@@ -1376,8 +1699,11 @@ var CheckoutService = class {
|
|
|
1376
1699
|
...data,
|
|
1377
1700
|
idempotency_key: data.idempotency_key || generateIdempotencyKey()
|
|
1378
1701
|
};
|
|
1379
|
-
return
|
|
1380
|
-
this.client.
|
|
1702
|
+
return safeWithFallback3(
|
|
1703
|
+
() => this.client.post("/api/v1/checkout", {
|
|
1704
|
+
checkout_data: checkoutData
|
|
1705
|
+
}),
|
|
1706
|
+
() => this.client.call(CHECKOUT_MUTATION.PROCESS, {
|
|
1381
1707
|
checkout_data: checkoutData
|
|
1382
1708
|
})
|
|
1383
1709
|
);
|
|
@@ -1391,18 +1717,23 @@ var CheckoutService = class {
|
|
|
1391
1717
|
);
|
|
1392
1718
|
}
|
|
1393
1719
|
async submitAuthorization(input) {
|
|
1394
|
-
return
|
|
1395
|
-
this.client.
|
|
1720
|
+
return safeWithFallback3(
|
|
1721
|
+
() => this.client.post("/api/v1/payments/authorization", input),
|
|
1722
|
+
() => this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
|
|
1396
1723
|
);
|
|
1397
1724
|
}
|
|
1398
1725
|
async pollPaymentStatus(orderId) {
|
|
1399
|
-
|
|
1400
|
-
|
|
1726
|
+
const encodedId = encodeURIComponent(orderId);
|
|
1727
|
+
return safeWithFallback3(
|
|
1728
|
+
() => this.client.get(`/api/v1/orders/${encodedId}/payment-status`),
|
|
1729
|
+
() => this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
|
|
1401
1730
|
);
|
|
1402
1731
|
}
|
|
1403
1732
|
async updateOrderCustomer(orderId, customer) {
|
|
1404
|
-
|
|
1405
|
-
|
|
1733
|
+
const encodedId = encodeURIComponent(orderId);
|
|
1734
|
+
return safeWithFallback3(
|
|
1735
|
+
() => this.client.post(`/api/v1/orders/${encodedId}/customer`, customer),
|
|
1736
|
+
() => this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
|
|
1406
1737
|
order_id: orderId,
|
|
1407
1738
|
...customer
|
|
1408
1739
|
})
|
|
@@ -1532,6 +1863,14 @@ async function safe4(promise) {
|
|
|
1532
1863
|
return err(toCimplifyError4(error));
|
|
1533
1864
|
}
|
|
1534
1865
|
}
|
|
1866
|
+
async function safeWithFallback4(primary, fallback) {
|
|
1867
|
+
const primaryResult = await safe4(primary());
|
|
1868
|
+
if (primaryResult.ok) return primaryResult;
|
|
1869
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
1870
|
+
return primaryResult;
|
|
1871
|
+
}
|
|
1872
|
+
return safe4(fallback());
|
|
1873
|
+
}
|
|
1535
1874
|
var OrderQueries = class {
|
|
1536
1875
|
constructor(client) {
|
|
1537
1876
|
this.client = client;
|
|
@@ -1548,20 +1887,36 @@ var OrderQueries = class {
|
|
|
1548
1887
|
if (options?.offset) {
|
|
1549
1888
|
query2 += `#offset(${options.offset})`;
|
|
1550
1889
|
}
|
|
1551
|
-
|
|
1890
|
+
const params = new URLSearchParams();
|
|
1891
|
+
if (options?.status) params.set("status", options.status);
|
|
1892
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
1893
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
1894
|
+
const path = params.toString() ? `/api/v1/orders?${params.toString()}` : "/api/v1/orders";
|
|
1895
|
+
return safeWithFallback4(
|
|
1896
|
+
() => this.client.get(path),
|
|
1897
|
+
() => this.client.query(query2)
|
|
1898
|
+
);
|
|
1552
1899
|
}
|
|
1553
1900
|
async get(orderId) {
|
|
1554
|
-
|
|
1901
|
+
const encodedId = encodeURIComponent(orderId);
|
|
1902
|
+
return safeWithFallback4(
|
|
1903
|
+
() => this.client.get(`/api/v1/orders/${encodedId}`),
|
|
1904
|
+
() => this.client.query(`orders.${orderId}`)
|
|
1905
|
+
);
|
|
1555
1906
|
}
|
|
1556
1907
|
async getRecent(limit = 5) {
|
|
1557
1908
|
return safe4(this.client.query(`orders#sort(created_at,desc)#limit(${limit})`));
|
|
1558
1909
|
}
|
|
1559
1910
|
async getByStatus(status) {
|
|
1560
|
-
return
|
|
1911
|
+
return this.list({ status });
|
|
1561
1912
|
}
|
|
1562
1913
|
async cancel(orderId, reason) {
|
|
1563
|
-
|
|
1564
|
-
|
|
1914
|
+
const encodedId = encodeURIComponent(orderId);
|
|
1915
|
+
return safeWithFallback4(
|
|
1916
|
+
() => this.client.post(`/api/v1/orders/${encodedId}/cancel`, {
|
|
1917
|
+
reason
|
|
1918
|
+
}),
|
|
1919
|
+
() => this.client.call("order.cancelOrder", {
|
|
1565
1920
|
order_id: orderId,
|
|
1566
1921
|
reason
|
|
1567
1922
|
})
|
|
@@ -1736,12 +2091,23 @@ async function safe6(promise) {
|
|
|
1736
2091
|
return err(toCimplifyError6(error));
|
|
1737
2092
|
}
|
|
1738
2093
|
}
|
|
2094
|
+
async function safeWithFallback5(primary, fallback) {
|
|
2095
|
+
const primaryResult = await safe6(primary());
|
|
2096
|
+
if (primaryResult.ok) return primaryResult;
|
|
2097
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2098
|
+
return primaryResult;
|
|
2099
|
+
}
|
|
2100
|
+
return safe6(fallback());
|
|
2101
|
+
}
|
|
1739
2102
|
var AuthService = class {
|
|
1740
2103
|
constructor(client) {
|
|
1741
2104
|
this.client = client;
|
|
1742
2105
|
}
|
|
1743
2106
|
async getStatus() {
|
|
1744
|
-
return
|
|
2107
|
+
return safeWithFallback5(
|
|
2108
|
+
() => this.client.get("/api/v1/auth/status"),
|
|
2109
|
+
() => this.client.query("auth")
|
|
2110
|
+
);
|
|
1745
2111
|
}
|
|
1746
2112
|
async getCurrentUser() {
|
|
1747
2113
|
const result = await this.getStatus();
|
|
@@ -1754,23 +2120,34 @@ var AuthService = class {
|
|
|
1754
2120
|
return ok(result.value.is_authenticated);
|
|
1755
2121
|
}
|
|
1756
2122
|
async requestOtp(contact, contactType) {
|
|
1757
|
-
return
|
|
1758
|
-
this.client.
|
|
2123
|
+
return safeWithFallback5(
|
|
2124
|
+
() => this.client.post("/api/v1/auth/request-otp", {
|
|
2125
|
+
contact,
|
|
2126
|
+
contact_type: contactType
|
|
2127
|
+
}),
|
|
2128
|
+
() => this.client.call(AUTH_MUTATION.REQUEST_OTP, {
|
|
1759
2129
|
contact,
|
|
1760
2130
|
contact_type: contactType
|
|
1761
2131
|
})
|
|
1762
2132
|
);
|
|
1763
2133
|
}
|
|
1764
2134
|
async verifyOtp(code, contact) {
|
|
1765
|
-
return
|
|
1766
|
-
this.client.
|
|
2135
|
+
return safeWithFallback5(
|
|
2136
|
+
() => this.client.post("/api/v1/auth/verify-otp", {
|
|
2137
|
+
otp_code: code,
|
|
2138
|
+
contact
|
|
2139
|
+
}),
|
|
2140
|
+
() => this.client.call(AUTH_MUTATION.VERIFY_OTP, {
|
|
1767
2141
|
otp_code: code,
|
|
1768
2142
|
contact
|
|
1769
2143
|
})
|
|
1770
2144
|
);
|
|
1771
2145
|
}
|
|
1772
2146
|
async logout() {
|
|
1773
|
-
return
|
|
2147
|
+
return safeWithFallback5(
|
|
2148
|
+
() => this.client.post("/api/v1/auth/logout"),
|
|
2149
|
+
() => this.client.call("auth.logout")
|
|
2150
|
+
);
|
|
1774
2151
|
}
|
|
1775
2152
|
async updateProfile(input) {
|
|
1776
2153
|
return safe6(this.client.call("auth.update_profile", input));
|
|
@@ -1798,12 +2175,23 @@ async function safe7(promise) {
|
|
|
1798
2175
|
return err(toCimplifyError7(error));
|
|
1799
2176
|
}
|
|
1800
2177
|
}
|
|
2178
|
+
async function safeWithFallback6(primary, fallback) {
|
|
2179
|
+
const primaryResult = await safe7(primary());
|
|
2180
|
+
if (primaryResult.ok) return primaryResult;
|
|
2181
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2182
|
+
return primaryResult;
|
|
2183
|
+
}
|
|
2184
|
+
return safe7(fallback());
|
|
2185
|
+
}
|
|
1801
2186
|
var BusinessService = class {
|
|
1802
2187
|
constructor(client) {
|
|
1803
2188
|
this.client = client;
|
|
1804
2189
|
}
|
|
1805
2190
|
async getInfo() {
|
|
1806
|
-
return
|
|
2191
|
+
return safeWithFallback6(
|
|
2192
|
+
() => this.client.get("/api/v1/business"),
|
|
2193
|
+
() => this.client.query("business.info")
|
|
2194
|
+
);
|
|
1807
2195
|
}
|
|
1808
2196
|
async getByHandle(handle) {
|
|
1809
2197
|
return safe7(this.client.query(`business.handle.${handle}`));
|
|
@@ -1812,24 +2200,48 @@ var BusinessService = class {
|
|
|
1812
2200
|
return safe7(this.client.query("business.domain", { domain }));
|
|
1813
2201
|
}
|
|
1814
2202
|
async getSettings() {
|
|
1815
|
-
return
|
|
2203
|
+
return safeWithFallback6(
|
|
2204
|
+
() => this.client.get("/api/v1/business/settings"),
|
|
2205
|
+
() => this.client.query("business.settings")
|
|
2206
|
+
);
|
|
1816
2207
|
}
|
|
1817
2208
|
async getTheme() {
|
|
1818
|
-
return
|
|
2209
|
+
return safeWithFallback6(
|
|
2210
|
+
() => this.client.get("/api/v1/business/theme"),
|
|
2211
|
+
() => this.client.query("business.theme")
|
|
2212
|
+
);
|
|
1819
2213
|
}
|
|
1820
2214
|
async getLocations() {
|
|
1821
|
-
return
|
|
2215
|
+
return safeWithFallback6(
|
|
2216
|
+
() => this.client.get("/api/v1/business/locations"),
|
|
2217
|
+
() => this.client.query("business.locations")
|
|
2218
|
+
);
|
|
1822
2219
|
}
|
|
1823
2220
|
async getLocation(locationId) {
|
|
1824
|
-
|
|
2221
|
+
const result = await this.getLocations();
|
|
2222
|
+
if (!result.ok) return err(result.error);
|
|
2223
|
+
const location = result.value.find((item) => item.id === locationId);
|
|
2224
|
+
if (!location) {
|
|
2225
|
+
return err(new CimplifyError(ErrorCode.NOT_FOUND, `Location not found: ${locationId}`, false));
|
|
2226
|
+
}
|
|
2227
|
+
return ok(location);
|
|
1825
2228
|
}
|
|
1826
2229
|
async getHours() {
|
|
1827
|
-
return
|
|
2230
|
+
return safeWithFallback6(
|
|
2231
|
+
() => this.client.get("/api/v1/business/hours"),
|
|
2232
|
+
() => this.client.query("business.hours")
|
|
2233
|
+
);
|
|
1828
2234
|
}
|
|
1829
2235
|
async getLocationHours(locationId) {
|
|
1830
|
-
|
|
2236
|
+
const result = await this.getHours();
|
|
2237
|
+
if (!result.ok) return result;
|
|
2238
|
+
return ok(result.value.filter((hour) => hour.location_id === locationId));
|
|
1831
2239
|
}
|
|
1832
2240
|
async getBootstrap() {
|
|
2241
|
+
const restBootstrap = await safe7(this.client.get("/api/v1/bootstrap"));
|
|
2242
|
+
if (restBootstrap.ok) {
|
|
2243
|
+
return restBootstrap;
|
|
2244
|
+
}
|
|
1833
2245
|
const [businessResult, locationsResult, categoriesResult] = await Promise.all([
|
|
1834
2246
|
this.getInfo(),
|
|
1835
2247
|
this.getLocations(),
|
|
@@ -2122,15 +2534,30 @@ async function safe11(promise) {
|
|
|
2122
2534
|
return err(toCimplifyError11(error));
|
|
2123
2535
|
}
|
|
2124
2536
|
}
|
|
2537
|
+
async function safeWithFallback7(primary, fallback) {
|
|
2538
|
+
const primaryResult = await safe11(primary());
|
|
2539
|
+
if (primaryResult.ok) return primaryResult;
|
|
2540
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2541
|
+
return primaryResult;
|
|
2542
|
+
}
|
|
2543
|
+
return safe11(fallback());
|
|
2544
|
+
}
|
|
2125
2545
|
var FxService = class {
|
|
2126
2546
|
constructor(client) {
|
|
2127
2547
|
this.client = client;
|
|
2128
2548
|
}
|
|
2129
2549
|
async getRate(from, to) {
|
|
2130
|
-
|
|
2550
|
+
const path = `/api/v1/fx/rate?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
|
|
2551
|
+
return safeWithFallback7(
|
|
2552
|
+
() => this.client.get(path),
|
|
2553
|
+
() => this.client.call("fx.getRate", { from, to })
|
|
2554
|
+
);
|
|
2131
2555
|
}
|
|
2132
2556
|
async lockQuote(request) {
|
|
2133
|
-
return
|
|
2557
|
+
return safeWithFallback7(
|
|
2558
|
+
() => this.client.post("/api/v1/fx/quotes", request),
|
|
2559
|
+
() => this.client.call("fx.lockQuote", request)
|
|
2560
|
+
);
|
|
2134
2561
|
}
|
|
2135
2562
|
};
|
|
2136
2563
|
|