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