@cimplify/sdk 0.6.10 → 0.6.12
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/ads-t3FBTU8p.d.mts +20 -0
- package/dist/ads-t3FBTU8p.d.ts +20 -0
- package/dist/advanced.d.mts +25 -0
- package/dist/advanced.d.ts +25 -0
- package/dist/advanced.js +534 -102
- package/dist/advanced.mjs +534 -102
- package/dist/client-2Rmdqutj.d.ts +2373 -0
- package/dist/client-BIbWQK7v.d.mts +2373 -0
- package/dist/index-DAztg_LQ.d.ts +326 -0
- package/dist/index-Dqaywky7.d.mts +326 -0
- package/dist/index.d.mts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +590 -105
- package/dist/index.mjs +587 -106
- package/dist/payment-CLIWNMaP.d.mts +1133 -0
- package/dist/payment-CLIWNMaP.d.ts +1133 -0
- package/dist/react.d.mts +375 -0
- package/dist/react.d.ts +375 -0
- package/dist/react.js +562 -105
- package/dist/react.mjs +562 -105
- package/dist/utils.d.mts +2 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +27 -0
- package/dist/utils.mjs +24 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,6 +33,11 @@ var ErrorCode = {
|
|
|
33
33
|
CHECKOUT_VALIDATION_FAILED: "CHECKOUT_VALIDATION_FAILED",
|
|
34
34
|
DELIVERY_ADDRESS_REQUIRED: "DELIVERY_ADDRESS_REQUIRED",
|
|
35
35
|
CUSTOMER_INFO_REQUIRED: "CUSTOMER_INFO_REQUIRED",
|
|
36
|
+
// Quote
|
|
37
|
+
QUOTE_NOT_FOUND: "QUOTE_NOT_FOUND",
|
|
38
|
+
QUOTE_EXPIRED: "QUOTE_EXPIRED",
|
|
39
|
+
QUOTE_CONSUMED: "QUOTE_CONSUMED",
|
|
40
|
+
QUOTE_STORAGE_UNAVAILABLE: "QUOTE_STORAGE_UNAVAILABLE",
|
|
36
41
|
// Payment
|
|
37
42
|
PAYMENT_FAILED: "PAYMENT_FAILED",
|
|
38
43
|
PAYMENT_CANCELLED: "PAYMENT_CANCELLED",
|
|
@@ -73,6 +78,10 @@ var ERROR_SUGGESTIONS = {
|
|
|
73
78
|
CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
|
|
74
79
|
DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
|
|
75
80
|
CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
|
|
81
|
+
QUOTE_NOT_FOUND: "Quote could not be found. Refresh pricing and create a new quote before checkout.",
|
|
82
|
+
QUOTE_EXPIRED: "Quote has expired. Re-fetch pricing to generate a new quote with a valid expiry window.",
|
|
83
|
+
QUOTE_CONSUMED: "Quote has already been used. Request a fresh quote to prevent duplicate checkout attempts.",
|
|
84
|
+
QUOTE_STORAGE_UNAVAILABLE: "Quote storage is temporarily unavailable. Retry shortly and avoid charging until quote fetch succeeds.",
|
|
76
85
|
PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
|
|
77
86
|
PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
|
|
78
87
|
INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
|
|
@@ -312,6 +321,23 @@ async function safe(promise) {
|
|
|
312
321
|
return err(toCimplifyError(error));
|
|
313
322
|
}
|
|
314
323
|
}
|
|
324
|
+
async function safeWithFallback(primary, fallback) {
|
|
325
|
+
const primaryResult = await safe(primary());
|
|
326
|
+
if (primaryResult.ok) return primaryResult;
|
|
327
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
328
|
+
return primaryResult;
|
|
329
|
+
}
|
|
330
|
+
return safe(fallback());
|
|
331
|
+
}
|
|
332
|
+
function withQuery(path, params) {
|
|
333
|
+
const query2 = new URLSearchParams();
|
|
334
|
+
for (const [key, value] of Object.entries(params)) {
|
|
335
|
+
if (value === void 0) continue;
|
|
336
|
+
query2.set(key, String(value));
|
|
337
|
+
}
|
|
338
|
+
const queryString = query2.toString();
|
|
339
|
+
return queryString ? `${path}?${queryString}` : path;
|
|
340
|
+
}
|
|
315
341
|
function isRecord(value) {
|
|
316
342
|
return typeof value === "object" && value !== null;
|
|
317
343
|
}
|
|
@@ -369,11 +395,79 @@ function findProductBySlug(products, slug) {
|
|
|
369
395
|
return typeof value === "string" && value === slug;
|
|
370
396
|
});
|
|
371
397
|
}
|
|
398
|
+
function findCategoryBySlug(categories, slug) {
|
|
399
|
+
return categories.find((category) => {
|
|
400
|
+
const value = category["slug"];
|
|
401
|
+
return typeof value === "string" && value === slug;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function hasCategorySlug(category) {
|
|
405
|
+
const value = category["slug"];
|
|
406
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
407
|
+
}
|
|
408
|
+
function toFiniteNumber(value) {
|
|
409
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
410
|
+
return value;
|
|
411
|
+
}
|
|
412
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
413
|
+
const parsed = Number(value);
|
|
414
|
+
if (Number.isFinite(parsed)) {
|
|
415
|
+
return parsed;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return void 0;
|
|
419
|
+
}
|
|
420
|
+
function normalizePagination(value) {
|
|
421
|
+
if (!isRecord(value)) {
|
|
422
|
+
return void 0;
|
|
423
|
+
}
|
|
424
|
+
const totalCount = toFiniteNumber(value.total_count);
|
|
425
|
+
const currentPage = toFiniteNumber(value.current_page);
|
|
426
|
+
const pageSize = toFiniteNumber(value.page_size);
|
|
427
|
+
const totalPages = toFiniteNumber(value.total_pages);
|
|
428
|
+
if (totalCount === void 0 || currentPage === void 0 || pageSize === void 0 || totalPages === void 0) {
|
|
429
|
+
return void 0;
|
|
430
|
+
}
|
|
431
|
+
return {
|
|
432
|
+
total_count: totalCount,
|
|
433
|
+
current_page: currentPage,
|
|
434
|
+
page_size: pageSize,
|
|
435
|
+
total_pages: totalPages,
|
|
436
|
+
has_more: value.has_more === true,
|
|
437
|
+
next_cursor: typeof value.next_cursor === "string" ? value.next_cursor : void 0
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function normalizeCatalogueResult(payload) {
|
|
441
|
+
if (Array.isArray(payload)) {
|
|
442
|
+
return {
|
|
443
|
+
items: payload.map((product) => normalizeCatalogueProductPayload(product)),
|
|
444
|
+
is_complete: true
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
if (!isRecord(payload)) {
|
|
448
|
+
return {
|
|
449
|
+
items: [],
|
|
450
|
+
is_complete: true
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
const rawItems = Array.isArray(payload.products) ? payload.products : Array.isArray(payload.items) ? payload.items : [];
|
|
454
|
+
return {
|
|
455
|
+
items: rawItems.map((product) => normalizeCatalogueProductPayload(product)),
|
|
456
|
+
is_complete: typeof payload.is_complete === "boolean" ? payload.is_complete : true,
|
|
457
|
+
total_available: toFiniteNumber(payload.total_available),
|
|
458
|
+
pagination: normalizePagination(payload.pagination)
|
|
459
|
+
};
|
|
460
|
+
}
|
|
372
461
|
var CatalogueQueries = class {
|
|
373
462
|
constructor(client) {
|
|
374
463
|
this.client = client;
|
|
375
464
|
}
|
|
376
465
|
async getProducts(options) {
|
|
466
|
+
const result = await this.getProductsWithMeta(options);
|
|
467
|
+
if (!result.ok) return result;
|
|
468
|
+
return ok(result.value.items);
|
|
469
|
+
}
|
|
470
|
+
async getProductsWithMeta(options) {
|
|
377
471
|
let query2 = "products";
|
|
378
472
|
const filters = [];
|
|
379
473
|
if (options?.category) {
|
|
@@ -388,6 +482,13 @@ var CatalogueQueries = class {
|
|
|
388
482
|
if (options?.search) {
|
|
389
483
|
filters.push(`@.name contains '${escapeQueryValue(options.search)}'`);
|
|
390
484
|
}
|
|
485
|
+
if (options?.tags?.length) {
|
|
486
|
+
for (const tag of options.tags) {
|
|
487
|
+
if (tag.trim().length > 0) {
|
|
488
|
+
filters.push(`@.tags contains '${escapeQueryValue(tag)}'`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
391
492
|
if (options?.min_price !== void 0) {
|
|
392
493
|
filters.push(`@.price>=${options.min_price}`);
|
|
393
494
|
}
|
|
@@ -400,25 +501,57 @@ var CatalogueQueries = class {
|
|
|
400
501
|
if (options?.sort_by) {
|
|
401
502
|
query2 += `#sort(${options.sort_by},${options.sort_order || "asc"})`;
|
|
402
503
|
}
|
|
403
|
-
if (options?.limit) {
|
|
504
|
+
if (options?.limit !== void 0) {
|
|
404
505
|
query2 += `#limit(${options.limit})`;
|
|
405
506
|
}
|
|
406
|
-
if (options?.offset) {
|
|
507
|
+
if (options?.offset !== void 0) {
|
|
407
508
|
query2 += `#offset(${options.offset})`;
|
|
408
509
|
}
|
|
409
|
-
const
|
|
510
|
+
const path = withQuery("/api/v1/catalogue/products", {
|
|
511
|
+
category_id: options?.category,
|
|
512
|
+
search: options?.search,
|
|
513
|
+
page: options?.page,
|
|
514
|
+
tags: options?.tags?.join(","),
|
|
515
|
+
featured: options?.featured,
|
|
516
|
+
in_stock: options?.in_stock,
|
|
517
|
+
min_price: options?.min_price,
|
|
518
|
+
max_price: options?.max_price,
|
|
519
|
+
sort_by: options?.sort_by,
|
|
520
|
+
sort_order: options?.sort_order,
|
|
521
|
+
limit: options?.limit,
|
|
522
|
+
offset: options?.offset,
|
|
523
|
+
cursor: options?.cursor
|
|
524
|
+
});
|
|
525
|
+
const result = await safeWithFallback(
|
|
526
|
+
() => this.client.get(path),
|
|
527
|
+
() => this.client.query(query2)
|
|
528
|
+
);
|
|
410
529
|
if (!result.ok) return result;
|
|
411
|
-
return ok(result.value
|
|
530
|
+
return ok(normalizeCatalogueResult(result.value));
|
|
412
531
|
}
|
|
413
532
|
async getProduct(id) {
|
|
414
|
-
const
|
|
533
|
+
const encodedId = encodeURIComponent(id);
|
|
534
|
+
const result = await safeWithFallback(
|
|
535
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}`),
|
|
536
|
+
() => this.client.query(`products.${id}`)
|
|
537
|
+
);
|
|
415
538
|
if (!result.ok) return result;
|
|
416
539
|
return ok(normalizeCatalogueProductPayload(result.value));
|
|
417
540
|
}
|
|
418
541
|
async getProductBySlug(slug) {
|
|
542
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
543
|
+
const restResult = await safe(
|
|
544
|
+
this.client.get(`/api/v1/catalogue/products/slug/${encodedSlug}`)
|
|
545
|
+
);
|
|
546
|
+
if (restResult.ok) {
|
|
547
|
+
return ok(normalizeCatalogueProductPayload(restResult.value));
|
|
548
|
+
}
|
|
549
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
550
|
+
return restResult;
|
|
551
|
+
}
|
|
419
552
|
const filteredResult = await safe(
|
|
420
553
|
this.client.query(
|
|
421
|
-
`products[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
554
|
+
`products[?(@.slug=='${escapeQueryValue(slug)}')]#limit(50)`
|
|
422
555
|
)
|
|
423
556
|
);
|
|
424
557
|
if (!filteredResult.ok) return filteredResult;
|
|
@@ -429,7 +562,9 @@ var CatalogueQueries = class {
|
|
|
429
562
|
if (filteredResult.value.length === 1) {
|
|
430
563
|
return ok(normalizeCatalogueProductPayload(filteredResult.value[0]));
|
|
431
564
|
}
|
|
432
|
-
const unfilteredResult = await safe(
|
|
565
|
+
const unfilteredResult = await safe(
|
|
566
|
+
this.client.query("products#limit(200)")
|
|
567
|
+
);
|
|
433
568
|
if (!unfilteredResult.ok) return unfilteredResult;
|
|
434
569
|
const fallbackMatch = findProductBySlug(unfilteredResult.value, slug);
|
|
435
570
|
if (!fallbackMatch) {
|
|
@@ -438,18 +573,33 @@ var CatalogueQueries = class {
|
|
|
438
573
|
return ok(normalizeCatalogueProductPayload(fallbackMatch));
|
|
439
574
|
}
|
|
440
575
|
async getVariants(productId) {
|
|
441
|
-
|
|
576
|
+
const encodedId = encodeURIComponent(productId);
|
|
577
|
+
return safeWithFallback(
|
|
578
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`),
|
|
579
|
+
() => this.client.query(`products.${productId}.variants`)
|
|
580
|
+
);
|
|
442
581
|
}
|
|
443
582
|
async getVariantAxes(productId) {
|
|
444
|
-
|
|
583
|
+
const encodedId = encodeURIComponent(productId);
|
|
584
|
+
return safeWithFallback(
|
|
585
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`),
|
|
586
|
+
() => this.client.query(`products.${productId}.variant_axes`)
|
|
587
|
+
);
|
|
445
588
|
}
|
|
446
589
|
/**
|
|
447
590
|
* Find a variant by axis selections (e.g., { "Size": "Large", "Color": "Red" })
|
|
448
591
|
* Returns the matching variant or null if no match found.
|
|
449
592
|
*/
|
|
450
593
|
async getVariantByAxisSelections(productId, selections) {
|
|
451
|
-
|
|
452
|
-
|
|
594
|
+
const encodedId = encodeURIComponent(productId);
|
|
595
|
+
return safeWithFallback(
|
|
596
|
+
() => this.client.post(
|
|
597
|
+
`/api/v1/catalogue/products/${encodedId}/variants/find`,
|
|
598
|
+
{
|
|
599
|
+
axis_selections: selections
|
|
600
|
+
}
|
|
601
|
+
),
|
|
602
|
+
() => this.client.query(`products.${productId}.variant`, {
|
|
453
603
|
axis_selections: selections
|
|
454
604
|
})
|
|
455
605
|
);
|
|
@@ -458,45 +608,107 @@ var CatalogueQueries = class {
|
|
|
458
608
|
* Get a specific variant by its ID
|
|
459
609
|
*/
|
|
460
610
|
async getVariantById(productId, variantId) {
|
|
461
|
-
|
|
611
|
+
const encodedProductId = encodeURIComponent(productId);
|
|
612
|
+
const encodedVariantId = encodeURIComponent(variantId);
|
|
613
|
+
return safeWithFallback(
|
|
614
|
+
() => this.client.get(
|
|
615
|
+
`/api/v1/catalogue/products/${encodedProductId}/variants/${encodedVariantId}`
|
|
616
|
+
),
|
|
617
|
+
() => this.client.query(`products.${productId}.variant.${variantId}`)
|
|
618
|
+
);
|
|
462
619
|
}
|
|
463
620
|
async getAddOns(productId) {
|
|
464
|
-
|
|
621
|
+
const encodedId = encodeURIComponent(productId);
|
|
622
|
+
return safeWithFallback(
|
|
623
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`),
|
|
624
|
+
() => this.client.query(`products.${productId}.add_ons`)
|
|
625
|
+
);
|
|
465
626
|
}
|
|
466
627
|
async getCategories() {
|
|
467
|
-
|
|
628
|
+
const result = await safeWithFallback(
|
|
629
|
+
() => this.client.get("/api/v1/catalogue/categories"),
|
|
630
|
+
() => this.client.query("categories")
|
|
631
|
+
);
|
|
632
|
+
if (!result.ok) return result;
|
|
633
|
+
if (result.value.some(hasCategorySlug)) {
|
|
634
|
+
return result;
|
|
635
|
+
}
|
|
636
|
+
const catalogueResult = await safe(
|
|
637
|
+
this.client.query("catalogue#limit(1)")
|
|
638
|
+
);
|
|
639
|
+
if (!catalogueResult.ok) {
|
|
640
|
+
return result;
|
|
641
|
+
}
|
|
642
|
+
const fallbackCategories = Array.isArray(catalogueResult.value.categories) ? catalogueResult.value.categories : [];
|
|
643
|
+
return fallbackCategories.length > 0 ? ok(fallbackCategories) : result;
|
|
468
644
|
}
|
|
469
645
|
async getCategory(id) {
|
|
470
|
-
|
|
646
|
+
const encodedId = encodeURIComponent(id);
|
|
647
|
+
return safeWithFallback(
|
|
648
|
+
() => this.client.get(`/api/v1/catalogue/categories/${encodedId}`),
|
|
649
|
+
() => this.client.query(`categories.${id}`)
|
|
650
|
+
);
|
|
471
651
|
}
|
|
472
652
|
async getCategoryBySlug(slug) {
|
|
653
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
654
|
+
const restResult = await safe(this.client.get(`/api/v1/catalogue/categories/slug/${encodedSlug}`));
|
|
655
|
+
if (restResult.ok) {
|
|
656
|
+
return restResult;
|
|
657
|
+
}
|
|
658
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
659
|
+
return restResult;
|
|
660
|
+
}
|
|
473
661
|
const result = await safe(
|
|
474
662
|
this.client.query(`categories[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
475
663
|
);
|
|
476
664
|
if (!result.ok) return result;
|
|
477
|
-
|
|
665
|
+
const exactMatch = findCategoryBySlug(result.value, slug);
|
|
666
|
+
if (exactMatch) {
|
|
667
|
+
return ok(exactMatch);
|
|
668
|
+
}
|
|
669
|
+
const categoriesResult = await this.getCategories();
|
|
670
|
+
if (!categoriesResult.ok) {
|
|
671
|
+
return categoriesResult;
|
|
672
|
+
}
|
|
673
|
+
const fallbackMatch = findCategoryBySlug(categoriesResult.value, slug);
|
|
674
|
+
if (!fallbackMatch) {
|
|
478
675
|
return err(new CimplifyError("NOT_FOUND", `Category not found: ${slug}`, false));
|
|
479
676
|
}
|
|
480
|
-
return ok(
|
|
677
|
+
return ok(fallbackMatch);
|
|
481
678
|
}
|
|
482
679
|
async getCategoryProducts(categoryId) {
|
|
483
|
-
|
|
484
|
-
|
|
680
|
+
const encodedId = encodeURIComponent(categoryId);
|
|
681
|
+
return safeWithFallback(
|
|
682
|
+
() => this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`),
|
|
683
|
+
() => this.client.query(
|
|
485
684
|
`products[?(@.category_id=='${escapeQueryValue(categoryId)}')]`
|
|
486
685
|
)
|
|
487
686
|
);
|
|
488
687
|
}
|
|
489
688
|
async getCollections() {
|
|
490
|
-
return
|
|
689
|
+
return safeWithFallback(
|
|
690
|
+
() => this.client.get("/api/v1/catalogue/collections"),
|
|
691
|
+
() => this.client.query("collections")
|
|
692
|
+
);
|
|
491
693
|
}
|
|
492
694
|
async getCollection(id) {
|
|
493
|
-
|
|
695
|
+
const encodedId = encodeURIComponent(id);
|
|
696
|
+
return safeWithFallback(
|
|
697
|
+
() => this.client.get(`/api/v1/catalogue/collections/${encodedId}`),
|
|
698
|
+
() => this.client.query(`collections.${id}`)
|
|
699
|
+
);
|
|
494
700
|
}
|
|
495
701
|
async getCollectionBySlug(slug) {
|
|
702
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
703
|
+
const restResult = await safe(
|
|
704
|
+
this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`)
|
|
705
|
+
);
|
|
706
|
+
if (restResult.ok) return restResult;
|
|
707
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
708
|
+
return restResult;
|
|
709
|
+
}
|
|
496
710
|
const result = await safe(
|
|
497
|
-
this.client.query(
|
|
498
|
-
`collections[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
499
|
-
)
|
|
711
|
+
this.client.query(`collections[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
500
712
|
);
|
|
501
713
|
if (!result.ok) return result;
|
|
502
714
|
if (!result.value.length) {
|
|
@@ -505,22 +717,43 @@ var CatalogueQueries = class {
|
|
|
505
717
|
return ok(result.value[0]);
|
|
506
718
|
}
|
|
507
719
|
async getCollectionProducts(collectionId) {
|
|
508
|
-
|
|
720
|
+
const encodedId = encodeURIComponent(collectionId);
|
|
721
|
+
return safeWithFallback(
|
|
722
|
+
() => this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`),
|
|
723
|
+
() => this.client.query(`collections.${collectionId}.products`)
|
|
724
|
+
);
|
|
509
725
|
}
|
|
510
726
|
async searchCollections(query2, limit = 20) {
|
|
511
|
-
|
|
512
|
-
|
|
727
|
+
const path = withQuery("/api/v1/catalogue/collections", { search: query2, limit });
|
|
728
|
+
return safeWithFallback(
|
|
729
|
+
() => this.client.get(path),
|
|
730
|
+
() => this.client.query(
|
|
513
731
|
`collections[?(@.name contains '${escapeQueryValue(query2)}')]#limit(${limit})`
|
|
514
732
|
)
|
|
515
733
|
);
|
|
516
734
|
}
|
|
517
735
|
async getBundles() {
|
|
518
|
-
return
|
|
736
|
+
return safeWithFallback(
|
|
737
|
+
() => this.client.get("/api/v1/catalogue/bundles"),
|
|
738
|
+
() => this.client.query("bundles")
|
|
739
|
+
);
|
|
519
740
|
}
|
|
520
741
|
async getBundle(id) {
|
|
521
|
-
|
|
742
|
+
const encodedId = encodeURIComponent(id);
|
|
743
|
+
return safeWithFallback(
|
|
744
|
+
() => this.client.get(`/api/v1/catalogue/bundles/${encodedId}`),
|
|
745
|
+
() => this.client.query(`bundles.${id}`)
|
|
746
|
+
);
|
|
522
747
|
}
|
|
523
748
|
async getBundleBySlug(slug) {
|
|
749
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
750
|
+
const restResult = await safe(
|
|
751
|
+
this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`)
|
|
752
|
+
);
|
|
753
|
+
if (restResult.ok) return restResult;
|
|
754
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
755
|
+
return restResult;
|
|
756
|
+
}
|
|
524
757
|
const result = await safe(
|
|
525
758
|
this.client.query(
|
|
526
759
|
`bundles[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
@@ -533,8 +766,10 @@ var CatalogueQueries = class {
|
|
|
533
766
|
return ok(result.value[0]);
|
|
534
767
|
}
|
|
535
768
|
async searchBundles(query2, limit = 20) {
|
|
536
|
-
|
|
537
|
-
|
|
769
|
+
const path = withQuery("/api/v1/catalogue/bundles", { search: query2, limit });
|
|
770
|
+
return safeWithFallback(
|
|
771
|
+
() => this.client.get(path),
|
|
772
|
+
() => this.client.query(
|
|
538
773
|
`bundles[?(@.name contains '${escapeQueryValue(query2)}')]#limit(${limit})`
|
|
539
774
|
)
|
|
540
775
|
);
|
|
@@ -544,17 +779,39 @@ var CatalogueQueries = class {
|
|
|
544
779
|
if (options?.limit) {
|
|
545
780
|
query2 += `#limit(${options.limit})`;
|
|
546
781
|
}
|
|
547
|
-
|
|
782
|
+
const path = withQuery("/api/v1/catalogue/composites", { limit: options?.limit });
|
|
783
|
+
return safeWithFallback(
|
|
784
|
+
() => this.client.get(path),
|
|
785
|
+
() => this.client.query(query2)
|
|
786
|
+
);
|
|
548
787
|
}
|
|
549
788
|
async getComposite(id) {
|
|
550
|
-
|
|
789
|
+
const encodedId = encodeURIComponent(id);
|
|
790
|
+
return safeWithFallback(
|
|
791
|
+
() => this.client.get(`/api/v1/catalogue/composites/${encodedId}`),
|
|
792
|
+
() => this.client.query(`composites.${id}`)
|
|
793
|
+
);
|
|
551
794
|
}
|
|
552
795
|
async getCompositeByProductId(productId) {
|
|
553
|
-
|
|
796
|
+
const encodedId = encodeURIComponent(productId);
|
|
797
|
+
return safeWithFallback(
|
|
798
|
+
() => this.client.get(
|
|
799
|
+
`/api/v1/catalogue/composites/by-product/${encodedId}`
|
|
800
|
+
),
|
|
801
|
+
() => this.client.query(`composites.by_product.${productId}`)
|
|
802
|
+
);
|
|
554
803
|
}
|
|
555
804
|
async calculateCompositePrice(compositeId, selections, locationId) {
|
|
556
|
-
|
|
557
|
-
|
|
805
|
+
const encodedId = encodeURIComponent(compositeId);
|
|
806
|
+
return safeWithFallback(
|
|
807
|
+
() => this.client.post(
|
|
808
|
+
`/api/v1/catalogue/composites/${encodedId}/calculate-price`,
|
|
809
|
+
{
|
|
810
|
+
selections,
|
|
811
|
+
location_id: locationId
|
|
812
|
+
}
|
|
813
|
+
),
|
|
814
|
+
() => this.client.call("composite.calculatePrice", {
|
|
558
815
|
composite_id: compositeId,
|
|
559
816
|
selections,
|
|
560
817
|
location_id: locationId
|
|
@@ -562,35 +819,41 @@ var CatalogueQueries = class {
|
|
|
562
819
|
);
|
|
563
820
|
}
|
|
564
821
|
async fetchQuote(input) {
|
|
565
|
-
return
|
|
822
|
+
return safeWithFallback(
|
|
823
|
+
() => this.client.post("/api/v1/catalogue/quotes", input),
|
|
824
|
+
() => this.client.call("catalogue.createQuote", input)
|
|
825
|
+
);
|
|
566
826
|
}
|
|
567
827
|
async getQuote(quoteId) {
|
|
568
|
-
|
|
569
|
-
|
|
828
|
+
const encodedQuoteId = encodeURIComponent(quoteId);
|
|
829
|
+
return safeWithFallback(
|
|
830
|
+
() => this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`),
|
|
831
|
+
() => this.client.call("catalogue.getQuote", {
|
|
570
832
|
quote_id: quoteId
|
|
571
833
|
})
|
|
572
834
|
);
|
|
573
835
|
}
|
|
574
836
|
async refreshQuote(input) {
|
|
575
|
-
|
|
837
|
+
const encodedQuoteId = encodeURIComponent(input.quote_id);
|
|
838
|
+
return safeWithFallback(
|
|
839
|
+
() => this.client.post(
|
|
840
|
+
`/api/v1/catalogue/quotes/${encodedQuoteId}/refresh`,
|
|
841
|
+
input
|
|
842
|
+
),
|
|
843
|
+
() => this.client.call("catalogue.refreshQuote", input)
|
|
844
|
+
);
|
|
576
845
|
}
|
|
577
846
|
async search(query2, options) {
|
|
578
|
-
const
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
return
|
|
847
|
+
const result = await this.getProducts({
|
|
848
|
+
search: query2,
|
|
849
|
+
category: options?.category,
|
|
850
|
+
limit: options?.limit ?? 20
|
|
851
|
+
});
|
|
852
|
+
if (!result.ok) return result;
|
|
853
|
+
return ok(result.value);
|
|
585
854
|
}
|
|
586
855
|
async searchProducts(query2, options) {
|
|
587
|
-
return
|
|
588
|
-
this.client.call("catalogue.search", {
|
|
589
|
-
query: query2,
|
|
590
|
-
limit: options?.limit ?? 20,
|
|
591
|
-
category: options?.category
|
|
592
|
-
})
|
|
593
|
-
);
|
|
856
|
+
return this.search(query2, options);
|
|
594
857
|
}
|
|
595
858
|
async getMenu(options) {
|
|
596
859
|
let query2 = "menu";
|
|
@@ -600,13 +863,28 @@ var CatalogueQueries = class {
|
|
|
600
863
|
if (options?.limit) {
|
|
601
864
|
query2 += `#limit(${options.limit})`;
|
|
602
865
|
}
|
|
603
|
-
|
|
866
|
+
const path = withQuery("/api/v1/catalogue/menu", {
|
|
867
|
+
category_id: options?.category,
|
|
868
|
+
limit: options?.limit
|
|
869
|
+
});
|
|
870
|
+
return safeWithFallback(
|
|
871
|
+
() => this.client.get(path),
|
|
872
|
+
() => this.client.query(query2)
|
|
873
|
+
);
|
|
604
874
|
}
|
|
605
875
|
async getMenuCategory(categoryId) {
|
|
606
|
-
|
|
876
|
+
const encodedId = encodeURIComponent(categoryId);
|
|
877
|
+
return safeWithFallback(
|
|
878
|
+
() => this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`),
|
|
879
|
+
() => this.client.query(`menu.category.${categoryId}`)
|
|
880
|
+
);
|
|
607
881
|
}
|
|
608
882
|
async getMenuItem(itemId) {
|
|
609
|
-
|
|
883
|
+
const encodedId = encodeURIComponent(itemId);
|
|
884
|
+
return safeWithFallback(
|
|
885
|
+
() => this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`),
|
|
886
|
+
() => this.client.query(`menu.${itemId}`)
|
|
887
|
+
);
|
|
610
888
|
}
|
|
611
889
|
};
|
|
612
890
|
|
|
@@ -625,6 +903,14 @@ async function safe2(promise) {
|
|
|
625
903
|
return err(toCimplifyError2(error));
|
|
626
904
|
}
|
|
627
905
|
}
|
|
906
|
+
async function safeWithFallback2(primary, fallback) {
|
|
907
|
+
const primaryResult = await safe2(primary());
|
|
908
|
+
if (primaryResult.ok) return primaryResult;
|
|
909
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
910
|
+
return primaryResult;
|
|
911
|
+
}
|
|
912
|
+
return safe2(fallback());
|
|
913
|
+
}
|
|
628
914
|
function isUICartResponse(value) {
|
|
629
915
|
return "cart" in value;
|
|
630
916
|
}
|
|
@@ -636,21 +922,36 @@ var CartOperations = class {
|
|
|
636
922
|
this.client = client;
|
|
637
923
|
}
|
|
638
924
|
async get() {
|
|
639
|
-
const result = await
|
|
925
|
+
const result = await safeWithFallback2(
|
|
926
|
+
() => this.client.get("/api/v1/cart"),
|
|
927
|
+
() => this.client.query("cart#enriched")
|
|
928
|
+
);
|
|
640
929
|
if (!result.ok) return result;
|
|
641
930
|
return ok(unwrapEnrichedCart(result.value));
|
|
642
931
|
}
|
|
643
932
|
async getRaw() {
|
|
644
|
-
return
|
|
933
|
+
return safeWithFallback2(
|
|
934
|
+
() => this.client.get("/api/v1/cart"),
|
|
935
|
+
() => this.client.query("cart")
|
|
936
|
+
);
|
|
645
937
|
}
|
|
646
938
|
async getItems() {
|
|
647
|
-
return
|
|
939
|
+
return safeWithFallback2(
|
|
940
|
+
() => this.client.get("/api/v1/cart/items"),
|
|
941
|
+
() => this.client.query("cart_items")
|
|
942
|
+
);
|
|
648
943
|
}
|
|
649
944
|
async getCount() {
|
|
650
|
-
return
|
|
945
|
+
return safeWithFallback2(
|
|
946
|
+
() => this.client.get("/api/v1/cart/count"),
|
|
947
|
+
() => this.client.query("cart#count")
|
|
948
|
+
);
|
|
651
949
|
}
|
|
652
950
|
async getTotal() {
|
|
653
|
-
return
|
|
951
|
+
return safeWithFallback2(
|
|
952
|
+
() => this.client.get("/api/v1/cart/total"),
|
|
953
|
+
() => this.client.query("cart#total")
|
|
954
|
+
);
|
|
654
955
|
}
|
|
655
956
|
async getSummary() {
|
|
656
957
|
const cartResult = await this.get();
|
|
@@ -667,43 +968,66 @@ var CartOperations = class {
|
|
|
667
968
|
});
|
|
668
969
|
}
|
|
669
970
|
async addItem(input) {
|
|
670
|
-
return
|
|
971
|
+
return safeWithFallback2(
|
|
972
|
+
() => this.client.post("/api/v1/cart/items", input),
|
|
973
|
+
() => this.client.call("cart.addItem", input)
|
|
974
|
+
);
|
|
671
975
|
}
|
|
672
976
|
async updateItem(cartItemId, updates) {
|
|
673
|
-
|
|
674
|
-
this.
|
|
977
|
+
if (typeof updates.quantity === "number") {
|
|
978
|
+
return this.updateQuantity(cartItemId, updates.quantity);
|
|
979
|
+
}
|
|
980
|
+
const encodedId = encodeURIComponent(cartItemId);
|
|
981
|
+
return safeWithFallback2(
|
|
982
|
+
() => this.client.patch(`/api/v1/cart/items/${encodedId}`, updates),
|
|
983
|
+
() => this.client.call("cart.updateItem", {
|
|
675
984
|
cart_item_id: cartItemId,
|
|
676
985
|
...updates
|
|
677
986
|
})
|
|
678
987
|
);
|
|
679
988
|
}
|
|
680
989
|
async updateQuantity(cartItemId, quantity) {
|
|
681
|
-
|
|
682
|
-
|
|
990
|
+
const encodedId = encodeURIComponent(cartItemId);
|
|
991
|
+
return safeWithFallback2(
|
|
992
|
+
() => this.client.patch(`/api/v1/cart/items/${encodedId}`, {
|
|
993
|
+
quantity
|
|
994
|
+
}),
|
|
995
|
+
() => this.client.call("cart.updateItemQuantity", {
|
|
683
996
|
cart_item_id: cartItemId,
|
|
684
997
|
quantity
|
|
685
998
|
})
|
|
686
999
|
);
|
|
687
1000
|
}
|
|
688
1001
|
async removeItem(cartItemId) {
|
|
689
|
-
|
|
690
|
-
|
|
1002
|
+
const encodedId = encodeURIComponent(cartItemId);
|
|
1003
|
+
return safeWithFallback2(
|
|
1004
|
+
() => this.client.delete(`/api/v1/cart/items/${encodedId}`),
|
|
1005
|
+
() => this.client.call("cart.removeItem", {
|
|
691
1006
|
cart_item_id: cartItemId
|
|
692
1007
|
})
|
|
693
1008
|
);
|
|
694
1009
|
}
|
|
695
1010
|
async clear() {
|
|
696
|
-
return
|
|
1011
|
+
return safeWithFallback2(
|
|
1012
|
+
() => this.client.delete("/api/v1/cart"),
|
|
1013
|
+
() => this.client.call("cart.clearCart")
|
|
1014
|
+
);
|
|
697
1015
|
}
|
|
698
1016
|
async applyCoupon(code) {
|
|
699
|
-
return
|
|
700
|
-
this.client.
|
|
1017
|
+
return safeWithFallback2(
|
|
1018
|
+
() => this.client.post("/api/v1/cart/coupons", {
|
|
1019
|
+
coupon_code: code
|
|
1020
|
+
}),
|
|
1021
|
+
() => this.client.call("cart.applyCoupon", {
|
|
701
1022
|
coupon_code: code
|
|
702
1023
|
})
|
|
703
1024
|
);
|
|
704
1025
|
}
|
|
705
1026
|
async removeCoupon() {
|
|
706
|
-
return
|
|
1027
|
+
return safeWithFallback2(
|
|
1028
|
+
() => this.client.delete("/api/v1/cart/coupons/current"),
|
|
1029
|
+
() => this.client.call("cart.removeCoupon")
|
|
1030
|
+
);
|
|
707
1031
|
}
|
|
708
1032
|
async isEmpty() {
|
|
709
1033
|
const countResult = await this.getCount();
|
|
@@ -984,6 +1308,25 @@ function parsePrice(value) {
|
|
|
984
1308
|
const parsed = parseFloat(cleaned);
|
|
985
1309
|
return isNaN(parsed) ? 0 : parsed;
|
|
986
1310
|
}
|
|
1311
|
+
function hasTaxInfo(priceInfo) {
|
|
1312
|
+
return priceInfo.tax_info !== void 0 && priceInfo.tax_info !== null;
|
|
1313
|
+
}
|
|
1314
|
+
function getTaxAmount(priceInfo) {
|
|
1315
|
+
return parsePrice(priceInfo.tax_info?.tax_amount);
|
|
1316
|
+
}
|
|
1317
|
+
function isTaxInclusive(priceInfo) {
|
|
1318
|
+
return priceInfo.tax_info?.is_inclusive === true;
|
|
1319
|
+
}
|
|
1320
|
+
function formatPriceWithTax(priceInfo, currency = "GHS") {
|
|
1321
|
+
const finalPrice = formatPrice(priceInfo.final_price, currency);
|
|
1322
|
+
if (!hasTaxInfo(priceInfo)) {
|
|
1323
|
+
return finalPrice;
|
|
1324
|
+
}
|
|
1325
|
+
if (isTaxInclusive(priceInfo)) {
|
|
1326
|
+
return `${finalPrice} (incl. tax)`;
|
|
1327
|
+
}
|
|
1328
|
+
return `${finalPrice} + ${formatPrice(getTaxAmount(priceInfo), currency)} tax`;
|
|
1329
|
+
}
|
|
987
1330
|
function getDisplayPrice(product) {
|
|
988
1331
|
if (product.price_info) {
|
|
989
1332
|
return parsePrice(product.price_info.final_price);
|
|
@@ -1846,6 +2189,14 @@ async function safe3(promise) {
|
|
|
1846
2189
|
return err(toCimplifyError3(error));
|
|
1847
2190
|
}
|
|
1848
2191
|
}
|
|
2192
|
+
async function safeWithFallback3(primary, fallback) {
|
|
2193
|
+
const primaryResult = await safe3(primary());
|
|
2194
|
+
if (primaryResult.ok) return primaryResult;
|
|
2195
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2196
|
+
return primaryResult;
|
|
2197
|
+
}
|
|
2198
|
+
return safe3(fallback());
|
|
2199
|
+
}
|
|
1849
2200
|
function toTerminalFailure(code, message, recoverable) {
|
|
1850
2201
|
return {
|
|
1851
2202
|
success: false,
|
|
@@ -1873,8 +2224,11 @@ var CheckoutService = class {
|
|
|
1873
2224
|
...data,
|
|
1874
2225
|
idempotency_key: data.idempotency_key || generateIdempotencyKey()
|
|
1875
2226
|
};
|
|
1876
|
-
return
|
|
1877
|
-
this.client.
|
|
2227
|
+
return safeWithFallback3(
|
|
2228
|
+
() => this.client.post("/api/v1/checkout", {
|
|
2229
|
+
checkout_data: checkoutData
|
|
2230
|
+
}),
|
|
2231
|
+
() => this.client.call(CHECKOUT_MUTATION.PROCESS, {
|
|
1878
2232
|
checkout_data: checkoutData
|
|
1879
2233
|
})
|
|
1880
2234
|
);
|
|
@@ -1888,18 +2242,23 @@ var CheckoutService = class {
|
|
|
1888
2242
|
);
|
|
1889
2243
|
}
|
|
1890
2244
|
async submitAuthorization(input) {
|
|
1891
|
-
return
|
|
1892
|
-
this.client.
|
|
2245
|
+
return safeWithFallback3(
|
|
2246
|
+
() => this.client.post("/api/v1/payments/authorization", input),
|
|
2247
|
+
() => this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
|
|
1893
2248
|
);
|
|
1894
2249
|
}
|
|
1895
2250
|
async pollPaymentStatus(orderId) {
|
|
1896
|
-
|
|
1897
|
-
|
|
2251
|
+
const encodedId = encodeURIComponent(orderId);
|
|
2252
|
+
return safeWithFallback3(
|
|
2253
|
+
() => this.client.get(`/api/v1/orders/${encodedId}/payment-status`),
|
|
2254
|
+
() => this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
|
|
1898
2255
|
);
|
|
1899
2256
|
}
|
|
1900
2257
|
async updateOrderCustomer(orderId, customer) {
|
|
1901
|
-
|
|
1902
|
-
|
|
2258
|
+
const encodedId = encodeURIComponent(orderId);
|
|
2259
|
+
return safeWithFallback3(
|
|
2260
|
+
() => this.client.post(`/api/v1/orders/${encodedId}/customer`, customer),
|
|
2261
|
+
() => this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
|
|
1903
2262
|
order_id: orderId,
|
|
1904
2263
|
...customer
|
|
1905
2264
|
})
|
|
@@ -2029,6 +2388,14 @@ async function safe4(promise) {
|
|
|
2029
2388
|
return err(toCimplifyError4(error));
|
|
2030
2389
|
}
|
|
2031
2390
|
}
|
|
2391
|
+
async function safeWithFallback4(primary, fallback) {
|
|
2392
|
+
const primaryResult = await safe4(primary());
|
|
2393
|
+
if (primaryResult.ok) return primaryResult;
|
|
2394
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2395
|
+
return primaryResult;
|
|
2396
|
+
}
|
|
2397
|
+
return safe4(fallback());
|
|
2398
|
+
}
|
|
2032
2399
|
var OrderQueries = class {
|
|
2033
2400
|
constructor(client) {
|
|
2034
2401
|
this.client = client;
|
|
@@ -2045,20 +2412,36 @@ var OrderQueries = class {
|
|
|
2045
2412
|
if (options?.offset) {
|
|
2046
2413
|
query2 += `#offset(${options.offset})`;
|
|
2047
2414
|
}
|
|
2048
|
-
|
|
2415
|
+
const params = new URLSearchParams();
|
|
2416
|
+
if (options?.status) params.set("status", options.status);
|
|
2417
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
2418
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
2419
|
+
const path = params.toString() ? `/api/v1/orders?${params.toString()}` : "/api/v1/orders";
|
|
2420
|
+
return safeWithFallback4(
|
|
2421
|
+
() => this.client.get(path),
|
|
2422
|
+
() => this.client.query(query2)
|
|
2423
|
+
);
|
|
2049
2424
|
}
|
|
2050
2425
|
async get(orderId) {
|
|
2051
|
-
|
|
2426
|
+
const encodedId = encodeURIComponent(orderId);
|
|
2427
|
+
return safeWithFallback4(
|
|
2428
|
+
() => this.client.get(`/api/v1/orders/${encodedId}`),
|
|
2429
|
+
() => this.client.query(`orders.${orderId}`)
|
|
2430
|
+
);
|
|
2052
2431
|
}
|
|
2053
2432
|
async getRecent(limit = 5) {
|
|
2054
2433
|
return safe4(this.client.query(`orders#sort(created_at,desc)#limit(${limit})`));
|
|
2055
2434
|
}
|
|
2056
2435
|
async getByStatus(status) {
|
|
2057
|
-
return
|
|
2436
|
+
return this.list({ status });
|
|
2058
2437
|
}
|
|
2059
2438
|
async cancel(orderId, reason) {
|
|
2060
|
-
|
|
2061
|
-
|
|
2439
|
+
const encodedId = encodeURIComponent(orderId);
|
|
2440
|
+
return safeWithFallback4(
|
|
2441
|
+
() => this.client.post(`/api/v1/orders/${encodedId}/cancel`, {
|
|
2442
|
+
reason
|
|
2443
|
+
}),
|
|
2444
|
+
() => this.client.call("order.cancelOrder", {
|
|
2062
2445
|
order_id: orderId,
|
|
2063
2446
|
reason
|
|
2064
2447
|
})
|
|
@@ -2233,12 +2616,23 @@ async function safe6(promise) {
|
|
|
2233
2616
|
return err(toCimplifyError6(error));
|
|
2234
2617
|
}
|
|
2235
2618
|
}
|
|
2619
|
+
async function safeWithFallback5(primary, fallback) {
|
|
2620
|
+
const primaryResult = await safe6(primary());
|
|
2621
|
+
if (primaryResult.ok) return primaryResult;
|
|
2622
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2623
|
+
return primaryResult;
|
|
2624
|
+
}
|
|
2625
|
+
return safe6(fallback());
|
|
2626
|
+
}
|
|
2236
2627
|
var AuthService = class {
|
|
2237
2628
|
constructor(client) {
|
|
2238
2629
|
this.client = client;
|
|
2239
2630
|
}
|
|
2240
2631
|
async getStatus() {
|
|
2241
|
-
return
|
|
2632
|
+
return safeWithFallback5(
|
|
2633
|
+
() => this.client.get("/api/v1/auth/status"),
|
|
2634
|
+
() => this.client.query("auth")
|
|
2635
|
+
);
|
|
2242
2636
|
}
|
|
2243
2637
|
async getCurrentUser() {
|
|
2244
2638
|
const result = await this.getStatus();
|
|
@@ -2251,23 +2645,34 @@ var AuthService = class {
|
|
|
2251
2645
|
return ok(result.value.is_authenticated);
|
|
2252
2646
|
}
|
|
2253
2647
|
async requestOtp(contact, contactType) {
|
|
2254
|
-
return
|
|
2255
|
-
this.client.
|
|
2648
|
+
return safeWithFallback5(
|
|
2649
|
+
() => this.client.post("/api/v1/auth/request-otp", {
|
|
2650
|
+
contact,
|
|
2651
|
+
contact_type: contactType
|
|
2652
|
+
}),
|
|
2653
|
+
() => this.client.call(AUTH_MUTATION.REQUEST_OTP, {
|
|
2256
2654
|
contact,
|
|
2257
2655
|
contact_type: contactType
|
|
2258
2656
|
})
|
|
2259
2657
|
);
|
|
2260
2658
|
}
|
|
2261
2659
|
async verifyOtp(code, contact) {
|
|
2262
|
-
return
|
|
2263
|
-
this.client.
|
|
2660
|
+
return safeWithFallback5(
|
|
2661
|
+
() => this.client.post("/api/v1/auth/verify-otp", {
|
|
2662
|
+
otp_code: code,
|
|
2663
|
+
contact
|
|
2664
|
+
}),
|
|
2665
|
+
() => this.client.call(AUTH_MUTATION.VERIFY_OTP, {
|
|
2264
2666
|
otp_code: code,
|
|
2265
2667
|
contact
|
|
2266
2668
|
})
|
|
2267
2669
|
);
|
|
2268
2670
|
}
|
|
2269
2671
|
async logout() {
|
|
2270
|
-
return
|
|
2672
|
+
return safeWithFallback5(
|
|
2673
|
+
() => this.client.post("/api/v1/auth/logout"),
|
|
2674
|
+
() => this.client.call("auth.logout")
|
|
2675
|
+
);
|
|
2271
2676
|
}
|
|
2272
2677
|
async updateProfile(input) {
|
|
2273
2678
|
return safe6(this.client.call("auth.update_profile", input));
|
|
@@ -2295,12 +2700,23 @@ async function safe7(promise) {
|
|
|
2295
2700
|
return err(toCimplifyError7(error));
|
|
2296
2701
|
}
|
|
2297
2702
|
}
|
|
2703
|
+
async function safeWithFallback6(primary, fallback) {
|
|
2704
|
+
const primaryResult = await safe7(primary());
|
|
2705
|
+
if (primaryResult.ok) return primaryResult;
|
|
2706
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2707
|
+
return primaryResult;
|
|
2708
|
+
}
|
|
2709
|
+
return safe7(fallback());
|
|
2710
|
+
}
|
|
2298
2711
|
var BusinessService = class {
|
|
2299
2712
|
constructor(client) {
|
|
2300
2713
|
this.client = client;
|
|
2301
2714
|
}
|
|
2302
2715
|
async getInfo() {
|
|
2303
|
-
return
|
|
2716
|
+
return safeWithFallback6(
|
|
2717
|
+
() => this.client.get("/api/v1/business"),
|
|
2718
|
+
() => this.client.query("business.info")
|
|
2719
|
+
);
|
|
2304
2720
|
}
|
|
2305
2721
|
async getByHandle(handle) {
|
|
2306
2722
|
return safe7(this.client.query(`business.handle.${handle}`));
|
|
@@ -2309,24 +2725,48 @@ var BusinessService = class {
|
|
|
2309
2725
|
return safe7(this.client.query("business.domain", { domain }));
|
|
2310
2726
|
}
|
|
2311
2727
|
async getSettings() {
|
|
2312
|
-
return
|
|
2728
|
+
return safeWithFallback6(
|
|
2729
|
+
() => this.client.get("/api/v1/business/settings"),
|
|
2730
|
+
() => this.client.query("business.settings")
|
|
2731
|
+
);
|
|
2313
2732
|
}
|
|
2314
2733
|
async getTheme() {
|
|
2315
|
-
return
|
|
2734
|
+
return safeWithFallback6(
|
|
2735
|
+
() => this.client.get("/api/v1/business/theme"),
|
|
2736
|
+
() => this.client.query("business.theme")
|
|
2737
|
+
);
|
|
2316
2738
|
}
|
|
2317
2739
|
async getLocations() {
|
|
2318
|
-
return
|
|
2740
|
+
return safeWithFallback6(
|
|
2741
|
+
() => this.client.get("/api/v1/business/locations"),
|
|
2742
|
+
() => this.client.query("business.locations")
|
|
2743
|
+
);
|
|
2319
2744
|
}
|
|
2320
2745
|
async getLocation(locationId) {
|
|
2321
|
-
|
|
2746
|
+
const result = await this.getLocations();
|
|
2747
|
+
if (!result.ok) return err(result.error);
|
|
2748
|
+
const location = result.value.find((item) => item.id === locationId);
|
|
2749
|
+
if (!location) {
|
|
2750
|
+
return err(new CimplifyError(ErrorCode.NOT_FOUND, `Location not found: ${locationId}`, false));
|
|
2751
|
+
}
|
|
2752
|
+
return ok(location);
|
|
2322
2753
|
}
|
|
2323
2754
|
async getHours() {
|
|
2324
|
-
return
|
|
2755
|
+
return safeWithFallback6(
|
|
2756
|
+
() => this.client.get("/api/v1/business/hours"),
|
|
2757
|
+
() => this.client.query("business.hours")
|
|
2758
|
+
);
|
|
2325
2759
|
}
|
|
2326
2760
|
async getLocationHours(locationId) {
|
|
2327
|
-
|
|
2761
|
+
const result = await this.getHours();
|
|
2762
|
+
if (!result.ok) return result;
|
|
2763
|
+
return ok(result.value.filter((hour) => hour.location_id === locationId));
|
|
2328
2764
|
}
|
|
2329
2765
|
async getBootstrap() {
|
|
2766
|
+
const restBootstrap = await safe7(this.client.get("/api/v1/bootstrap"));
|
|
2767
|
+
if (restBootstrap.ok) {
|
|
2768
|
+
return restBootstrap;
|
|
2769
|
+
}
|
|
2330
2770
|
const [businessResult, locationsResult, categoriesResult] = await Promise.all([
|
|
2331
2771
|
this.getInfo(),
|
|
2332
2772
|
this.getLocations(),
|
|
@@ -2619,15 +3059,30 @@ async function safe11(promise) {
|
|
|
2619
3059
|
return err(toCimplifyError11(error));
|
|
2620
3060
|
}
|
|
2621
3061
|
}
|
|
3062
|
+
async function safeWithFallback7(primary, fallback) {
|
|
3063
|
+
const primaryResult = await safe11(primary());
|
|
3064
|
+
if (primaryResult.ok) return primaryResult;
|
|
3065
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
3066
|
+
return primaryResult;
|
|
3067
|
+
}
|
|
3068
|
+
return safe11(fallback());
|
|
3069
|
+
}
|
|
2622
3070
|
var FxService = class {
|
|
2623
3071
|
constructor(client) {
|
|
2624
3072
|
this.client = client;
|
|
2625
3073
|
}
|
|
2626
3074
|
async getRate(from, to) {
|
|
2627
|
-
|
|
3075
|
+
const path = `/api/v1/fx/rate?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
|
|
3076
|
+
return safeWithFallback7(
|
|
3077
|
+
() => this.client.get(path),
|
|
3078
|
+
() => this.client.call("fx.getRate", { from, to })
|
|
3079
|
+
);
|
|
2628
3080
|
}
|
|
2629
3081
|
async lockQuote(request) {
|
|
2630
|
-
return
|
|
3082
|
+
return safeWithFallback7(
|
|
3083
|
+
() => this.client.post("/api/v1/fx/quotes", request),
|
|
3084
|
+
() => this.client.call("fx.lockQuote", request)
|
|
3085
|
+
);
|
|
2631
3086
|
}
|
|
2632
3087
|
};
|
|
2633
3088
|
|
|
@@ -3635,6 +4090,15 @@ var CimplifyClient = class {
|
|
|
3635
4090
|
});
|
|
3636
4091
|
return this.handleRestResponse(response);
|
|
3637
4092
|
}
|
|
4093
|
+
async patch(path, body) {
|
|
4094
|
+
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
4095
|
+
method: "PATCH",
|
|
4096
|
+
credentials: this.credentials,
|
|
4097
|
+
headers: this.getHeaders(),
|
|
4098
|
+
body: body ? JSON.stringify(body) : void 0
|
|
4099
|
+
});
|
|
4100
|
+
return this.handleRestResponse(response);
|
|
4101
|
+
}
|
|
3638
4102
|
async delete(path) {
|
|
3639
4103
|
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
3640
4104
|
method: "DELETE",
|
|
@@ -3674,11 +4138,14 @@ var CimplifyClient = class {
|
|
|
3674
4138
|
async handleRestResponse(response) {
|
|
3675
4139
|
const json = await response.json();
|
|
3676
4140
|
if (!response.ok) {
|
|
4141
|
+
const errorCode = typeof json.error === "object" && json.error?.error_code || typeof json.error === "object" && json.error?.code || "API_ERROR";
|
|
4142
|
+
const errorMessage = typeof json.error === "object" && json.error?.error_message || typeof json.error === "object" && json.error?.message || typeof json.error === "string" && json.error || typeof json.message === "string" && json.message || "An error occurred";
|
|
4143
|
+
const retryable = typeof json.error === "object" && typeof json.error?.retryable === "boolean" ? json.error.retryable : false;
|
|
3677
4144
|
const error = enrichError(
|
|
3678
4145
|
new CimplifyError(
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
4146
|
+
errorCode,
|
|
4147
|
+
errorMessage,
|
|
4148
|
+
retryable
|
|
3682
4149
|
),
|
|
3683
4150
|
{ isTestMode: this.isTestMode() }
|
|
3684
4151
|
);
|
|
@@ -3689,7 +4156,21 @@ var CimplifyClient = class {
|
|
|
3689
4156
|
}
|
|
3690
4157
|
throw error;
|
|
3691
4158
|
}
|
|
3692
|
-
|
|
4159
|
+
if (json?.success === false || json?.error?.code || json?.error?.message) {
|
|
4160
|
+
const error = enrichError(
|
|
4161
|
+
new CimplifyError(
|
|
4162
|
+
json.error?.code || "API_ERROR",
|
|
4163
|
+
json.error?.message || "An error occurred",
|
|
4164
|
+
json.error?.retryable || false
|
|
4165
|
+
),
|
|
4166
|
+
{ isTestMode: this.isTestMode() }
|
|
4167
|
+
);
|
|
4168
|
+
throw error;
|
|
4169
|
+
}
|
|
4170
|
+
if (json?.data !== void 0) {
|
|
4171
|
+
return json.data;
|
|
4172
|
+
}
|
|
4173
|
+
return json;
|
|
3693
4174
|
}
|
|
3694
4175
|
async handleResponse(response) {
|
|
3695
4176
|
const json = await response.json();
|
|
@@ -3860,6 +4341,7 @@ exports.formatNumberCompact = formatNumberCompact;
|
|
|
3860
4341
|
exports.formatPrice = formatPrice;
|
|
3861
4342
|
exports.formatPriceAdjustment = formatPriceAdjustment;
|
|
3862
4343
|
exports.formatPriceCompact = formatPriceCompact;
|
|
4344
|
+
exports.formatPriceWithTax = formatPriceWithTax;
|
|
3863
4345
|
exports.formatProductPrice = formatProductPrice;
|
|
3864
4346
|
exports.fromPromise = fromPromise;
|
|
3865
4347
|
exports.generateIdempotencyKey = generateIdempotencyKey;
|
|
@@ -3871,6 +4353,8 @@ exports.getErrorHint = getErrorHint;
|
|
|
3871
4353
|
exports.getMarkupPercentage = getMarkupPercentage;
|
|
3872
4354
|
exports.getOrElse = getOrElse;
|
|
3873
4355
|
exports.getProductCurrency = getProductCurrency;
|
|
4356
|
+
exports.getTaxAmount = getTaxAmount;
|
|
4357
|
+
exports.hasTaxInfo = hasTaxInfo;
|
|
3874
4358
|
exports.isCimplifyError = isCimplifyError;
|
|
3875
4359
|
exports.isErr = isErr;
|
|
3876
4360
|
exports.isOk = isOk;
|
|
@@ -3879,6 +4363,7 @@ exports.isPaymentStatusFailure = isPaymentStatusFailure;
|
|
|
3879
4363
|
exports.isPaymentStatusRequiresAction = isPaymentStatusRequiresAction;
|
|
3880
4364
|
exports.isPaymentStatusSuccess = isPaymentStatusSuccess;
|
|
3881
4365
|
exports.isRetryableError = isRetryableError;
|
|
4366
|
+
exports.isTaxInclusive = isTaxInclusive;
|
|
3882
4367
|
exports.mapError = mapError;
|
|
3883
4368
|
exports.mapResult = mapResult;
|
|
3884
4369
|
exports.money = money;
|