@cimplify/sdk 0.7.2 → 0.7.3

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/index.js CHANGED
@@ -238,74 +238,6 @@ function combineObject(results) {
238
238
  return ok(values);
239
239
  }
240
240
 
241
- // src/query/builder.ts
242
- function escapeQueryValue(value) {
243
- return value.replace(/'/g, "\\'");
244
- }
245
- var QueryBuilder = class {
246
- constructor(entity) {
247
- this.filters = [];
248
- this.modifiers = [];
249
- this.pathSegments = [];
250
- this.entity = entity;
251
- }
252
- path(segment) {
253
- this.pathSegments.push(segment);
254
- return this;
255
- }
256
- where(field, op, value) {
257
- const v = typeof value === "string" ? `'${escapeQueryValue(value)}'` : value;
258
- if (op === "contains" || op === "startsWith") {
259
- this.filters.push(`@.${field} ${op} ${v}`);
260
- } else {
261
- this.filters.push(`@.${field}${op}${v}`);
262
- }
263
- return this;
264
- }
265
- and(field, op, value) {
266
- return this.where(field, op, value);
267
- }
268
- sort(field, order = "asc") {
269
- this.modifiers.push(`sort(${field},${order})`);
270
- return this;
271
- }
272
- limit(n) {
273
- this.modifiers.push(`limit(${n})`);
274
- return this;
275
- }
276
- offset(n) {
277
- this.modifiers.push(`offset(${n})`);
278
- return this;
279
- }
280
- count() {
281
- this.modifiers.push("count");
282
- return this;
283
- }
284
- enriched() {
285
- this.modifiers.push("enriched");
286
- return this;
287
- }
288
- build() {
289
- let query2 = this.entity;
290
- if (this.pathSegments.length > 0) {
291
- query2 += "." + this.pathSegments.join(".");
292
- }
293
- if (this.filters.length > 0) {
294
- query2 += `[?(${this.filters.join(" && ")})]`;
295
- }
296
- for (const mod of this.modifiers) {
297
- query2 += `#${mod}`;
298
- }
299
- return query2;
300
- }
301
- toString() {
302
- return this.build();
303
- }
304
- };
305
- function query(entity) {
306
- return new QueryBuilder(entity);
307
- }
308
-
309
241
  // src/catalogue.ts
310
242
  function toCimplifyError(error) {
311
243
  if (error instanceof CimplifyError) return enrichError(error);
@@ -321,14 +253,6 @@ async function safe(promise) {
321
253
  return err(toCimplifyError(error));
322
254
  }
323
255
  }
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
256
  function withQuery(path, params) {
333
257
  const query2 = new URLSearchParams();
334
258
  for (const [key, value] of Object.entries(params)) {
@@ -390,22 +314,6 @@ function normalizeCatalogueProductPayload(product) {
390
314
  }
391
315
  return normalized;
392
316
  }
393
- function findProductBySlug(products, slug) {
394
- return products.find((product) => {
395
- const value = product["slug"];
396
- return typeof value === "string" && value === slug;
397
- });
398
- }
399
- function findCategoryBySlug(categories, slug) {
400
- return categories.find((category) => {
401
- const value = category["slug"];
402
- return typeof value === "string" && value === slug;
403
- });
404
- }
405
- function hasCategorySlug(category) {
406
- const value = category["slug"];
407
- return typeof value === "string" && value.trim().length > 0;
408
- }
409
317
  function toFiniteNumber(value) {
410
318
  if (typeof value === "number" && Number.isFinite(value)) {
411
319
  return value;
@@ -493,53 +401,11 @@ var CatalogueQueries = class {
493
401
  this.client = client;
494
402
  }
495
403
  async getCatalogue() {
496
- const result = await safeWithFallback(
497
- () => this.client.get("/api/v1/catalogue"),
498
- () => this.client.query("catalogue")
499
- );
404
+ const result = await safe(this.client.get("/api/v1/catalogue"));
500
405
  if (!result.ok) return result;
501
406
  return ok(normalizeCatalogueSnapshot(result.value));
502
407
  }
503
408
  async getProducts(options) {
504
- let query2 = "products";
505
- const filters = [];
506
- if (options?.category) {
507
- filters.push(`@.category_id=='${escapeQueryValue(options.category)}'`);
508
- }
509
- if (options?.featured !== void 0) {
510
- filters.push(`@.featured==${options.featured}`);
511
- }
512
- if (options?.in_stock !== void 0) {
513
- filters.push(`@.in_stock==${options.in_stock}`);
514
- }
515
- if (options?.search) {
516
- filters.push(`@.name contains '${escapeQueryValue(options.search)}'`);
517
- }
518
- if (options?.tags?.length) {
519
- for (const tag of options.tags) {
520
- if (tag.trim().length > 0) {
521
- filters.push(`@.tags contains '${escapeQueryValue(tag)}'`);
522
- }
523
- }
524
- }
525
- if (options?.min_price !== void 0) {
526
- filters.push(`@.price>=${options.min_price}`);
527
- }
528
- if (options?.max_price !== void 0) {
529
- filters.push(`@.price<=${options.max_price}`);
530
- }
531
- if (filters.length > 0) {
532
- query2 += `[?(${filters.join(" && ")})]`;
533
- }
534
- if (options?.sort_by) {
535
- query2 += `#sort(${options.sort_by},${options.sort_order || "asc"})`;
536
- }
537
- if (options?.limit !== void 0) {
538
- query2 += `#limit(${options.limit})`;
539
- }
540
- if (options?.offset !== void 0) {
541
- query2 += `#offset(${options.offset})`;
542
- }
543
409
  const path = withQuery("/api/v1/catalogue/products", {
544
410
  category_id: options?.category,
545
411
  search: options?.search,
@@ -555,325 +421,145 @@ var CatalogueQueries = class {
555
421
  offset: options?.offset,
556
422
  cursor: options?.cursor
557
423
  });
558
- const result = await safeWithFallback(
559
- () => this.client.get(path),
560
- () => this.client.query(query2)
561
- );
424
+ const result = await safe(this.client.get(path));
562
425
  if (!result.ok) return result;
563
426
  return ok(normalizeCatalogueResult(result.value));
564
427
  }
565
428
  async getProduct(id) {
566
429
  const encodedId = encodeURIComponent(id);
567
- const result = await safeWithFallback(
568
- () => this.client.get(`/api/v1/catalogue/products/${encodedId}`),
569
- () => this.client.query(`products.${id}`)
570
- );
430
+ const result = await safe(this.client.get(`/api/v1/catalogue/products/${encodedId}`));
571
431
  if (!result.ok) return result;
572
432
  return ok(normalizeCatalogueProductPayload(result.value));
573
433
  }
574
434
  async getProductBySlug(slug) {
575
435
  const encodedSlug = encodeURIComponent(slug);
576
- const restResult = await safe(
577
- this.client.get(`/api/v1/catalogue/products/slug/${encodedSlug}`)
578
- );
579
- if (restResult.ok) {
580
- return ok(normalizeCatalogueProductPayload(restResult.value));
581
- }
582
- if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
583
- return restResult;
584
- }
585
- const filteredResult = await safe(
586
- this.client.query(
587
- `products[?(@.slug=='${escapeQueryValue(slug)}')]#limit(50)`
588
- )
589
- );
590
- if (!filteredResult.ok) return filteredResult;
591
- const exactMatch = findProductBySlug(filteredResult.value, slug);
592
- if (exactMatch) {
593
- return ok(normalizeCatalogueProductPayload(exactMatch));
594
- }
595
- if (filteredResult.value.length === 1) {
596
- return ok(normalizeCatalogueProductPayload(filteredResult.value[0]));
597
- }
598
- const unfilteredResult = await safe(
599
- this.client.query("products#limit(200)")
600
- );
601
- if (!unfilteredResult.ok) return unfilteredResult;
602
- const fallbackMatch = findProductBySlug(unfilteredResult.value, slug);
603
- if (!fallbackMatch) {
604
- return err(new CimplifyError("NOT_FOUND", `Product not found: ${slug}`, false));
605
- }
606
- return ok(normalizeCatalogueProductPayload(fallbackMatch));
436
+ const result = await safe(this.client.get(`/api/v1/catalogue/products/slug/${encodedSlug}`));
437
+ if (!result.ok) return result;
438
+ return ok(normalizeCatalogueProductPayload(result.value));
607
439
  }
608
440
  async getVariants(productId) {
609
441
  const encodedId = encodeURIComponent(productId);
610
- return safeWithFallback(
611
- () => this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`),
612
- () => this.client.query(`products.${productId}.variants`)
613
- );
442
+ return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`));
614
443
  }
615
444
  async getVariantAxes(productId) {
616
445
  const encodedId = encodeURIComponent(productId);
617
- return safeWithFallback(
618
- () => this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`),
619
- () => this.client.query(`products.${productId}.variant_axes`)
620
- );
446
+ return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`));
621
447
  }
622
- /**
623
- * Find a variant by axis selections (e.g., { "Size": "Large", "Color": "Red" })
624
- * Returns the matching variant or null if no match found.
625
- */
626
448
  async getVariantByAxisSelections(productId, selections) {
627
449
  const encodedId = encodeURIComponent(productId);
628
- return safeWithFallback(
629
- () => this.client.post(
450
+ return safe(
451
+ this.client.post(
630
452
  `/api/v1/catalogue/products/${encodedId}/variants/find`,
631
453
  {
632
454
  axis_selections: selections
633
455
  }
634
- ),
635
- () => this.client.query(`products.${productId}.variant`, {
636
- axis_selections: selections
637
- })
456
+ )
638
457
  );
639
458
  }
640
- /**
641
- * Get a specific variant by its ID
642
- */
643
459
  async getVariantById(productId, variantId) {
644
460
  const encodedProductId = encodeURIComponent(productId);
645
461
  const encodedVariantId = encodeURIComponent(variantId);
646
- return safeWithFallback(
647
- () => this.client.get(
462
+ return safe(
463
+ this.client.get(
648
464
  `/api/v1/catalogue/products/${encodedProductId}/variants/${encodedVariantId}`
649
- ),
650
- () => this.client.query(`products.${productId}.variant.${variantId}`)
465
+ )
651
466
  );
652
467
  }
653
468
  async getAddOns(productId) {
654
469
  const encodedId = encodeURIComponent(productId);
655
- return safeWithFallback(
656
- () => this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`),
657
- () => this.client.query(`products.${productId}.add_ons`)
658
- );
470
+ return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`));
659
471
  }
660
472
  async getCategories() {
661
- const result = await safeWithFallback(
662
- () => this.client.get("/api/v1/catalogue/categories"),
663
- () => this.client.query("categories")
664
- );
665
- if (!result.ok) return result;
666
- if (result.value.some(hasCategorySlug)) {
667
- return result;
668
- }
669
- const catalogueResult = await safe(
670
- this.client.query("catalogue#limit(1)")
671
- );
672
- if (!catalogueResult.ok) {
673
- return result;
674
- }
675
- const fallbackCategories = Array.isArray(catalogueResult.value.categories) ? catalogueResult.value.categories : [];
676
- return fallbackCategories.length > 0 ? ok(fallbackCategories) : result;
473
+ return safe(this.client.get("/api/v1/catalogue/categories"));
677
474
  }
678
475
  async getCategory(id) {
679
476
  const encodedId = encodeURIComponent(id);
680
- return safeWithFallback(
681
- () => this.client.get(`/api/v1/catalogue/categories/${encodedId}`),
682
- () => this.client.query(`categories.${id}`)
683
- );
477
+ return safe(this.client.get(`/api/v1/catalogue/categories/${encodedId}`));
684
478
  }
685
479
  async getCategoryBySlug(slug) {
686
480
  const encodedSlug = encodeURIComponent(slug);
687
- const restResult = await safe(this.client.get(`/api/v1/catalogue/categories/slug/${encodedSlug}`));
688
- if (restResult.ok) {
689
- return restResult;
690
- }
691
- if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
692
- return restResult;
693
- }
694
- const result = await safe(
695
- this.client.query(`categories[?(@.slug=='${escapeQueryValue(slug)}')]`)
696
- );
697
- if (!result.ok) return result;
698
- const exactMatch = findCategoryBySlug(result.value, slug);
699
- if (exactMatch) {
700
- return ok(exactMatch);
701
- }
702
- const categoriesResult = await this.getCategories();
703
- if (!categoriesResult.ok) {
704
- return categoriesResult;
705
- }
706
- const fallbackMatch = findCategoryBySlug(categoriesResult.value, slug);
707
- if (!fallbackMatch) {
708
- return err(new CimplifyError("NOT_FOUND", `Category not found: ${slug}`, false));
709
- }
710
- return ok(fallbackMatch);
481
+ return safe(this.client.get(`/api/v1/catalogue/categories/slug/${encodedSlug}`));
711
482
  }
712
483
  async getCategoryProducts(categoryId) {
713
484
  const encodedId = encodeURIComponent(categoryId);
714
- return safeWithFallback(
715
- () => this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`),
716
- () => this.client.query(
717
- `products[?(@.category_id=='${escapeQueryValue(categoryId)}')]`
718
- )
719
- );
485
+ return safe(this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`));
720
486
  }
721
487
  async getCollections() {
722
- return safeWithFallback(
723
- () => this.client.get("/api/v1/catalogue/collections"),
724
- () => this.client.query("collections")
725
- );
488
+ return safe(this.client.get("/api/v1/catalogue/collections"));
726
489
  }
727
490
  async getCollection(id) {
728
491
  const encodedId = encodeURIComponent(id);
729
- return safeWithFallback(
730
- () => this.client.get(`/api/v1/catalogue/collections/${encodedId}`),
731
- () => this.client.query(`collections.${id}`)
732
- );
492
+ return safe(this.client.get(`/api/v1/catalogue/collections/${encodedId}`));
733
493
  }
734
494
  async getCollectionBySlug(slug) {
735
495
  const encodedSlug = encodeURIComponent(slug);
736
- const restResult = await safe(
737
- this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`)
738
- );
739
- if (restResult.ok) return restResult;
740
- if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
741
- return restResult;
742
- }
743
- const result = await safe(
744
- this.client.query(`collections[?(@.slug=='${escapeQueryValue(slug)}')]`)
745
- );
746
- if (!result.ok) return result;
747
- if (!result.value.length) {
748
- return err(new CimplifyError("NOT_FOUND", `Collection not found: ${slug}`, false));
749
- }
750
- return ok(result.value[0]);
496
+ return safe(this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`));
751
497
  }
752
498
  async getCollectionProducts(collectionId) {
753
499
  const encodedId = encodeURIComponent(collectionId);
754
- return safeWithFallback(
755
- () => this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`),
756
- () => this.client.query(`collections.${collectionId}.products`)
757
- );
500
+ return safe(this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`));
758
501
  }
759
502
  async searchCollections(query2, limit = 20) {
760
503
  const path = withQuery("/api/v1/catalogue/collections", { search: query2, limit });
761
- return safeWithFallback(
762
- () => this.client.get(path),
763
- () => this.client.query(
764
- `collections[?(@.name contains '${escapeQueryValue(query2)}')]#limit(${limit})`
765
- )
766
- );
504
+ return safe(this.client.get(path));
767
505
  }
768
506
  async getBundles() {
769
- return safeWithFallback(
770
- () => this.client.get("/api/v1/catalogue/bundles"),
771
- () => this.client.query("bundles")
772
- );
507
+ return safe(this.client.get("/api/v1/catalogue/bundles"));
773
508
  }
774
509
  async getBundle(id) {
775
510
  const encodedId = encodeURIComponent(id);
776
- return safeWithFallback(
777
- () => this.client.get(`/api/v1/catalogue/bundles/${encodedId}`),
778
- () => this.client.query(`bundles.${id}`)
779
- );
511
+ return safe(this.client.get(`/api/v1/catalogue/bundles/${encodedId}`));
780
512
  }
781
513
  async getBundleBySlug(slug) {
782
514
  const encodedSlug = encodeURIComponent(slug);
783
- const restResult = await safe(
784
- this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`)
785
- );
786
- if (restResult.ok) return restResult;
787
- if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
788
- return restResult;
789
- }
790
- const result = await safe(
791
- this.client.query(
792
- `bundles[?(@.slug=='${escapeQueryValue(slug)}')]`
793
- )
794
- );
795
- if (!result.ok) return result;
796
- if (!result.value.length) {
797
- return err(new CimplifyError("NOT_FOUND", `Bundle not found: ${slug}`, false));
798
- }
799
- return ok(result.value[0]);
515
+ return safe(this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`));
800
516
  }
801
517
  async searchBundles(query2, limit = 20) {
802
518
  const path = withQuery("/api/v1/catalogue/bundles", { search: query2, limit });
803
- return safeWithFallback(
804
- () => this.client.get(path),
805
- () => this.client.query(
806
- `bundles[?(@.name contains '${escapeQueryValue(query2)}')]#limit(${limit})`
807
- )
808
- );
519
+ return safe(this.client.get(path));
809
520
  }
810
521
  async getComposites(options) {
811
- let query2 = "composites";
812
- if (options?.limit) {
813
- query2 += `#limit(${options.limit})`;
814
- }
815
522
  const path = withQuery("/api/v1/catalogue/composites", { limit: options?.limit });
816
- return safeWithFallback(
817
- () => this.client.get(path),
818
- () => this.client.query(query2)
819
- );
523
+ return safe(this.client.get(path));
820
524
  }
821
525
  async getComposite(id) {
822
526
  const encodedId = encodeURIComponent(id);
823
- return safeWithFallback(
824
- () => this.client.get(`/api/v1/catalogue/composites/${encodedId}`),
825
- () => this.client.query(`composites.${id}`)
826
- );
527
+ return safe(this.client.get(`/api/v1/catalogue/composites/${encodedId}`));
827
528
  }
828
529
  async getCompositeByProductId(productId) {
829
530
  const encodedId = encodeURIComponent(productId);
830
- return safeWithFallback(
831
- () => this.client.get(
531
+ return safe(
532
+ this.client.get(
832
533
  `/api/v1/catalogue/composites/by-product/${encodedId}`
833
- ),
834
- () => this.client.query(`composites.by_product.${productId}`)
534
+ )
835
535
  );
836
536
  }
837
537
  async calculateCompositePrice(compositeId, selections, locationId) {
838
538
  const encodedId = encodeURIComponent(compositeId);
839
- return safeWithFallback(
840
- () => this.client.post(
539
+ return safe(
540
+ this.client.post(
841
541
  `/api/v1/catalogue/composites/${encodedId}/calculate-price`,
842
542
  {
843
543
  selections,
844
544
  location_id: locationId
845
545
  }
846
- ),
847
- () => this.client.call("composite.calculatePrice", {
848
- composite_id: compositeId,
849
- selections,
850
- location_id: locationId
851
- })
546
+ )
852
547
  );
853
548
  }
854
549
  async fetchQuote(input) {
855
- return safeWithFallback(
856
- () => this.client.post("/api/v1/catalogue/quotes", input),
857
- () => this.client.call("catalogue.createQuote", input)
858
- );
550
+ return safe(this.client.post("/api/v1/catalogue/quotes", input));
859
551
  }
860
552
  async getQuote(quoteId) {
861
553
  const encodedQuoteId = encodeURIComponent(quoteId);
862
- return safeWithFallback(
863
- () => this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`),
864
- () => this.client.call("catalogue.getQuote", {
865
- quote_id: quoteId
866
- })
867
- );
554
+ return safe(this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`));
868
555
  }
869
556
  async refreshQuote(input) {
870
557
  const encodedQuoteId = encodeURIComponent(input.quote_id);
871
- return safeWithFallback(
872
- () => this.client.post(
558
+ return safe(
559
+ this.client.post(
873
560
  `/api/v1/catalogue/quotes/${encodedQuoteId}/refresh`,
874
561
  input
875
- ),
876
- () => this.client.call("catalogue.refreshQuote", input)
562
+ )
877
563
  );
878
564
  }
879
565
  async search(query2, options) {
@@ -889,35 +575,19 @@ var CatalogueQueries = class {
889
575
  return this.search(query2, options);
890
576
  }
891
577
  async getMenu(options) {
892
- let query2 = "menu";
893
- if (options?.category) {
894
- query2 = `menu[?(@.category=='${escapeQueryValue(options.category)}')]`;
895
- }
896
- if (options?.limit) {
897
- query2 += `#limit(${options.limit})`;
898
- }
899
578
  const path = withQuery("/api/v1/catalogue/menu", {
900
579
  category_id: options?.category,
901
580
  limit: options?.limit
902
581
  });
903
- return safeWithFallback(
904
- () => this.client.get(path),
905
- () => this.client.query(query2)
906
- );
582
+ return safe(this.client.get(path));
907
583
  }
908
584
  async getMenuCategory(categoryId) {
909
585
  const encodedId = encodeURIComponent(categoryId);
910
- return safeWithFallback(
911
- () => this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`),
912
- () => this.client.query(`menu.category.${categoryId}`)
913
- );
586
+ return safe(this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`));
914
587
  }
915
588
  async getMenuItem(itemId) {
916
589
  const encodedId = encodeURIComponent(itemId);
917
- return safeWithFallback(
918
- () => this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`),
919
- () => this.client.query(`menu.${itemId}`)
920
- );
590
+ return safe(this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`));
921
591
  }
922
592
  };
923
593
 
@@ -936,14 +606,6 @@ async function safe2(promise) {
936
606
  return err(toCimplifyError2(error));
937
607
  }
938
608
  }
939
- async function safeWithFallback2(primary, fallback) {
940
- const primaryResult = await safe2(primary());
941
- if (primaryResult.ok) return primaryResult;
942
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
943
- return primaryResult;
944
- }
945
- return safe2(fallback());
946
- }
947
609
  function isUICartResponse(value) {
948
610
  return "cart" in value;
949
611
  }
@@ -955,36 +617,21 @@ var CartOperations = class {
955
617
  this.client = client;
956
618
  }
957
619
  async get() {
958
- const result = await safeWithFallback2(
959
- () => this.client.get("/api/v1/cart"),
960
- () => this.client.query("cart#enriched")
961
- );
620
+ const result = await safe2(this.client.get("/api/v1/cart"));
962
621
  if (!result.ok) return result;
963
622
  return ok(unwrapEnrichedCart(result.value));
964
623
  }
965
624
  async getRaw() {
966
- return safeWithFallback2(
967
- () => this.client.get("/api/v1/cart"),
968
- () => this.client.query("cart")
969
- );
625
+ return safe2(this.client.get("/api/v1/cart"));
970
626
  }
971
627
  async getItems() {
972
- return safeWithFallback2(
973
- () => this.client.get("/api/v1/cart/items"),
974
- () => this.client.query("cart_items")
975
- );
628
+ return safe2(this.client.get("/api/v1/cart/items"));
976
629
  }
977
630
  async getCount() {
978
- return safeWithFallback2(
979
- () => this.client.get("/api/v1/cart/count"),
980
- () => this.client.query("cart#count")
981
- );
631
+ return safe2(this.client.get("/api/v1/cart/count"));
982
632
  }
983
633
  async getTotal() {
984
- return safeWithFallback2(
985
- () => this.client.get("/api/v1/cart/total"),
986
- () => this.client.query("cart#total")
987
- );
634
+ return safe2(this.client.get("/api/v1/cart/total"));
988
635
  }
989
636
  async getSummary() {
990
637
  const cartResult = await this.get();
@@ -1001,66 +648,39 @@ var CartOperations = class {
1001
648
  });
1002
649
  }
1003
650
  async addItem(input) {
1004
- return safeWithFallback2(
1005
- () => this.client.post("/api/v1/cart/items", input),
1006
- () => this.client.call("cart.addItem", input)
1007
- );
651
+ return safe2(this.client.post("/api/v1/cart/items", input));
1008
652
  }
1009
653
  async updateItem(cartItemId, updates) {
1010
654
  if (typeof updates.quantity === "number") {
1011
655
  return this.updateQuantity(cartItemId, updates.quantity);
1012
656
  }
1013
657
  const encodedId = encodeURIComponent(cartItemId);
1014
- return safeWithFallback2(
1015
- () => this.client.patch(`/api/v1/cart/items/${encodedId}`, updates),
1016
- () => this.client.call("cart.updateItem", {
1017
- cart_item_id: cartItemId,
1018
- ...updates
1019
- })
1020
- );
658
+ return safe2(this.client.patch(`/api/v1/cart/items/${encodedId}`, updates));
1021
659
  }
1022
660
  async updateQuantity(cartItemId, quantity) {
1023
661
  const encodedId = encodeURIComponent(cartItemId);
1024
- return safeWithFallback2(
1025
- () => this.client.patch(`/api/v1/cart/items/${encodedId}`, {
1026
- quantity
1027
- }),
1028
- () => this.client.call("cart.updateItemQuantity", {
1029
- cart_item_id: cartItemId,
662
+ return safe2(
663
+ this.client.patch(`/api/v1/cart/items/${encodedId}`, {
1030
664
  quantity
1031
665
  })
1032
666
  );
1033
667
  }
1034
668
  async removeItem(cartItemId) {
1035
669
  const encodedId = encodeURIComponent(cartItemId);
1036
- return safeWithFallback2(
1037
- () => this.client.delete(`/api/v1/cart/items/${encodedId}`),
1038
- () => this.client.call("cart.removeItem", {
1039
- cart_item_id: cartItemId
1040
- })
1041
- );
670
+ return safe2(this.client.delete(`/api/v1/cart/items/${encodedId}`));
1042
671
  }
1043
672
  async clear() {
1044
- return safeWithFallback2(
1045
- () => this.client.delete("/api/v1/cart"),
1046
- () => this.client.call("cart.clearCart")
1047
- );
673
+ return safe2(this.client.delete("/api/v1/cart"));
1048
674
  }
1049
675
  async applyCoupon(code) {
1050
- return safeWithFallback2(
1051
- () => this.client.post("/api/v1/cart/coupons", {
1052
- coupon_code: code
1053
- }),
1054
- () => this.client.call("cart.applyCoupon", {
676
+ return safe2(
677
+ this.client.post("/api/v1/cart/coupons", {
1055
678
  coupon_code: code
1056
679
  })
1057
680
  );
1058
681
  }
1059
682
  async removeCoupon() {
1060
- return safeWithFallback2(
1061
- () => this.client.delete("/api/v1/cart/coupons/current"),
1062
- () => this.client.call("cart.removeCoupon")
1063
- );
683
+ return safe2(this.client.delete("/api/v1/cart/coupons/current"));
1064
684
  }
1065
685
  async isEmpty() {
1066
686
  const countResult = await this.getCount();
@@ -1097,105 +717,6 @@ var CartOperations = class {
1097
717
  }
1098
718
  };
1099
719
 
1100
- // src/constants.ts
1101
- var CHECKOUT_MODE = {
1102
- LINK: "link",
1103
- GUEST: "guest"
1104
- };
1105
- var ORDER_TYPE = {
1106
- DELIVERY: "delivery",
1107
- PICKUP: "pickup",
1108
- DINE_IN: "dine-in",
1109
- WALK_IN: "walk-in"
1110
- };
1111
- var PAYMENT_METHOD = {
1112
- MOBILE_MONEY: "mobile_money",
1113
- CARD: "card"
1114
- };
1115
- var CHECKOUT_STEP = {
1116
- AUTHENTICATION: "authentication",
1117
- ORDER_DETAILS: "order_details",
1118
- PAYMENT_METHOD: "payment_method",
1119
- PAYMENT: "payment",
1120
- CONFIRMATION: "confirmation"
1121
- };
1122
- var PAYMENT_STATE = {
1123
- INITIAL: "initial",
1124
- PREPARING: "preparing",
1125
- PROCESSING: "processing",
1126
- VERIFYING: "verifying",
1127
- AWAITING_AUTHORIZATION: "awaiting_authorization",
1128
- SUCCESS: "success",
1129
- ERROR: "error",
1130
- TIMEOUT: "timeout"
1131
- };
1132
- var PICKUP_TIME_TYPE = {
1133
- ASAP: "asap",
1134
- SCHEDULED: "scheduled"
1135
- };
1136
- var MOBILE_MONEY_PROVIDER = {
1137
- MTN: "mtn",
1138
- VODAFONE: "vodafone",
1139
- AIRTEL: "airtel"
1140
- };
1141
- var AUTHORIZATION_TYPE = {
1142
- OTP: "otp",
1143
- PIN: "pin",
1144
- PHONE: "phone",
1145
- BIRTHDAY: "birthday",
1146
- ADDRESS: "address"
1147
- };
1148
- var DEVICE_TYPE = {
1149
- MOBILE: "mobile",
1150
- DESKTOP: "desktop",
1151
- TABLET: "tablet"
1152
- };
1153
- var CONTACT_TYPE = {
1154
- PHONE: "phone",
1155
- EMAIL: "email"
1156
- };
1157
- var LINK_QUERY = {
1158
- DATA: "link.data",
1159
- ADDRESSES: "link.addresses",
1160
- MOBILE_MONEY: "link.mobile_money",
1161
- PREFERENCES: "link.preferences",
1162
- SESSIONS: "link.sessions"
1163
- };
1164
- var LINK_MUTATION = {
1165
- CHECK_STATUS: "link.check_status",
1166
- ENROLL: "link.enroll",
1167
- ENROLL_AND_LINK_ORDER: "link.enroll_and_link_order",
1168
- UPDATE_PREFERENCES: "link.update_preferences",
1169
- CREATE_ADDRESS: "link.create_address",
1170
- UPDATE_ADDRESS: "link.update_address",
1171
- DELETE_ADDRESS: "link.delete_address",
1172
- SET_DEFAULT_ADDRESS: "link.set_default_address",
1173
- TRACK_ADDRESS_USAGE: "link.track_address_usage",
1174
- CREATE_MOBILE_MONEY: "link.create_mobile_money",
1175
- DELETE_MOBILE_MONEY: "link.delete_mobile_money",
1176
- SET_DEFAULT_MOBILE_MONEY: "link.set_default_mobile_money",
1177
- TRACK_MOBILE_MONEY_USAGE: "link.track_mobile_money_usage",
1178
- VERIFY_MOBILE_MONEY: "link.verify_mobile_money",
1179
- REVOKE_SESSION: "link.revoke_session",
1180
- REVOKE_ALL_SESSIONS: "link.revoke_all_sessions"
1181
- };
1182
- var AUTH_MUTATION = {
1183
- REQUEST_OTP: "auth.request_otp",
1184
- VERIFY_OTP: "auth.verify_otp"
1185
- };
1186
- var CHECKOUT_MUTATION = {
1187
- PROCESS: "checkout.process"
1188
- };
1189
- var PAYMENT_MUTATION = {
1190
- SUBMIT_AUTHORIZATION: "payment.submit_authorization",
1191
- CHECK_STATUS: "order.poll_payment_status"
1192
- };
1193
- var ORDER_MUTATION = {
1194
- UPDATE_CUSTOMER: "order.update_order_customer"
1195
- };
1196
- var DEFAULT_CURRENCY = "GHS";
1197
- var DEFAULT_COUNTRY = "GHA";
1198
-
1199
720
  // src/utils/price.ts
1200
721
  var CURRENCY_SYMBOLS = {
1201
722
  // Major world currencies
@@ -2222,14 +1743,6 @@ async function safe3(promise) {
2222
1743
  return err(toCimplifyError3(error));
2223
1744
  }
2224
1745
  }
2225
- async function safeWithFallback3(primary, fallback) {
2226
- const primaryResult = await safe3(primary());
2227
- if (primaryResult.ok) return primaryResult;
2228
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2229
- return primaryResult;
2230
- }
2231
- return safe3(fallback());
2232
- }
2233
1746
  function toTerminalFailure(code, message, recoverable) {
2234
1747
  return {
2235
1748
  success: false,
@@ -2261,11 +1774,8 @@ var CheckoutService = class {
2261
1774
  ...data,
2262
1775
  idempotency_key: data.idempotency_key || generateIdempotencyKey()
2263
1776
  };
2264
- const result = await safeWithFallback3(
2265
- () => this.client.post("/api/v1/checkout", {
2266
- checkout_data: checkoutData
2267
- }),
2268
- () => this.client.call(CHECKOUT_MUTATION.PROCESS, {
1777
+ const result = await safe3(
1778
+ this.client.post("/api/v1/checkout", {
2269
1779
  checkout_data: checkoutData
2270
1780
  })
2271
1781
  );
@@ -2274,45 +1784,32 @@ var CheckoutService = class {
2274
1784
  }
2275
1785
  return result;
2276
1786
  }
2277
- async initializePayment(orderId, method) {
2278
- return safe3(
2279
- this.client.call("order.initializePayment", {
2280
- order_id: orderId,
2281
- payment_method: method
2282
- })
1787
+ async initializePayment(_orderId, _method) {
1788
+ return err(
1789
+ new CimplifyError(
1790
+ "NOT_IMPLEMENTED",
1791
+ "initializePayment is not available in REST mode.",
1792
+ false
1793
+ )
2283
1794
  );
2284
1795
  }
2285
1796
  async submitAuthorization(input) {
2286
- return safeWithFallback3(
2287
- () => this.client.post("/api/v1/payments/authorization", input),
2288
- () => this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
2289
- );
1797
+ return safe3(this.client.post("/api/v1/payments/authorization", input));
2290
1798
  }
2291
1799
  async pollPaymentStatus(orderId) {
2292
1800
  const encodedId = encodeURIComponent(orderId);
2293
1801
  const tokenParam = this.orderTokenParam(orderId);
2294
- return safeWithFallback3(
2295
- () => this.client.get(`/api/v1/orders/${encodedId}/payment-status${tokenParam}`),
2296
- () => this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
2297
- );
1802
+ return safe3(this.client.get(`/api/v1/orders/${encodedId}/payment-status${tokenParam}`));
2298
1803
  }
2299
1804
  async updateOrderCustomer(orderId, customer) {
2300
1805
  const encodedId = encodeURIComponent(orderId);
2301
1806
  const tokenParam = this.orderTokenParam(orderId);
2302
- return safeWithFallback3(
2303
- () => this.client.post(`/api/v1/orders/${encodedId}/customer${tokenParam}`, customer),
2304
- () => this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
2305
- order_id: orderId,
2306
- ...customer
2307
- })
2308
- );
1807
+ return safe3(this.client.post(`/api/v1/orders/${encodedId}/customer${tokenParam}`, customer));
2309
1808
  }
2310
1809
  async verifyPayment(orderId) {
2311
- return safe3(
2312
- this.client.call("order.verifyPayment", {
2313
- order_id: orderId
2314
- })
2315
- );
1810
+ const encodedId = encodeURIComponent(orderId);
1811
+ const tokenParam = this.orderTokenParam(orderId);
1812
+ return safe3(this.client.post(`/api/v1/orders/${encodedId}/verify-payment${tokenParam}`));
2316
1813
  }
2317
1814
  async processAndResolve(data) {
2318
1815
  data.on_status_change?.("preparing", {});
@@ -2431,14 +1928,6 @@ async function safe4(promise) {
2431
1928
  return err(toCimplifyError4(error));
2432
1929
  }
2433
1930
  }
2434
- async function safeWithFallback4(primary, fallback) {
2435
- const primaryResult = await safe4(primary());
2436
- if (primaryResult.ok) return primaryResult;
2437
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2438
- return primaryResult;
2439
- }
2440
- return safe4(fallback());
2441
- }
2442
1931
  var OrderQueries = class {
2443
1932
  constructor(client) {
2444
1933
  this.client = client;
@@ -2448,37 +1937,20 @@ var OrderQueries = class {
2448
1937
  return token ? `?token=${encodeURIComponent(token)}` : "";
2449
1938
  }
2450
1939
  async list(options) {
2451
- let query2 = "orders";
2452
- if (options?.status) {
2453
- query2 += `[?(@.status=='${options.status}')]`;
2454
- }
2455
- query2 += "#sort(created_at,desc)";
2456
- if (options?.limit) {
2457
- query2 += `#limit(${options.limit})`;
2458
- }
2459
- if (options?.offset) {
2460
- query2 += `#offset(${options.offset})`;
2461
- }
2462
1940
  const params = new URLSearchParams();
2463
1941
  if (options?.status) params.set("status", options.status);
2464
1942
  if (options?.limit) params.set("limit", String(options.limit));
2465
1943
  if (options?.offset) params.set("offset", String(options.offset));
2466
1944
  const path = params.toString() ? `/api/v1/orders?${params.toString()}` : "/api/v1/orders";
2467
- return safeWithFallback4(
2468
- () => this.client.get(path),
2469
- () => this.client.query(query2)
2470
- );
1945
+ return safe4(this.client.get(path));
2471
1946
  }
2472
1947
  async get(orderId) {
2473
1948
  const encodedId = encodeURIComponent(orderId);
2474
1949
  const tokenParam = this.orderTokenParam(orderId);
2475
- return safeWithFallback4(
2476
- () => this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`),
2477
- () => this.client.query(`orders.${orderId}`)
2478
- );
1950
+ return safe4(this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`));
2479
1951
  }
2480
1952
  async getRecent(limit = 5) {
2481
- return safe4(this.client.query(`orders#sort(created_at,desc)#limit(${limit})`));
1953
+ return this.list({ limit });
2482
1954
  }
2483
1955
  async getByStatus(status) {
2484
1956
  return this.list({ status });
@@ -2486,12 +1958,8 @@ var OrderQueries = class {
2486
1958
  async cancel(orderId, reason) {
2487
1959
  const encodedId = encodeURIComponent(orderId);
2488
1960
  const tokenParam = this.orderTokenParam(orderId);
2489
- return safeWithFallback4(
2490
- () => this.client.post(`/api/v1/orders/${encodedId}/cancel${tokenParam}`, {
2491
- reason
2492
- }),
2493
- () => this.client.call("order.cancelOrder", {
2494
- order_id: orderId,
1961
+ return safe4(
1962
+ this.client.post(`/api/v1/orders/${encodedId}/cancel${tokenParam}`, {
2495
1963
  reason
2496
1964
  })
2497
1965
  );
@@ -2513,6 +1981,38 @@ async function safe5(promise) {
2513
1981
  return err(toCimplifyError5(error));
2514
1982
  }
2515
1983
  }
1984
+ function encodePathSegment(value) {
1985
+ return encodeURIComponent(value);
1986
+ }
1987
+ function toCreateAddressPayload(input) {
1988
+ return {
1989
+ label: input.label,
1990
+ street_address: input.address_line1,
1991
+ apartment: input.address_line2,
1992
+ city: input.city,
1993
+ region: input.state ?? "",
1994
+ postal_code: input.postal_code,
1995
+ country: input.country
1996
+ };
1997
+ }
1998
+ function toUpdateAddressPayload(input) {
1999
+ return {
2000
+ label: input.label,
2001
+ street_address: input.address_line1,
2002
+ apartment: input.address_line2,
2003
+ city: input.city,
2004
+ region: input.state,
2005
+ postal_code: input.postal_code,
2006
+ country: input.country
2007
+ };
2008
+ }
2009
+ function toCreateMobileMoneyPayload(input) {
2010
+ return {
2011
+ phone_number: input.phone_number,
2012
+ provider: input.provider,
2013
+ label: input.account_name
2014
+ };
2015
+ }
2516
2016
  var LinkService = class {
2517
2017
  constructor(client) {
2518
2018
  this.client = client;
@@ -2540,11 +2040,7 @@ var LinkService = class {
2540
2040
  return result;
2541
2041
  }
2542
2042
  async checkStatus(contact) {
2543
- return safe5(
2544
- this.client.call(LINK_MUTATION.CHECK_STATUS, {
2545
- contact
2546
- })
2547
- );
2043
+ return safe5(this.client.linkPost("/v1/link/check-status", { contact }));
2548
2044
  }
2549
2045
  async getLinkData() {
2550
2046
  return safe5(this.client.linkGet("/v1/link/data"));
@@ -2556,61 +2052,85 @@ var LinkService = class {
2556
2052
  return safe5(this.client.linkGet("/v1/link/mobile-money"));
2557
2053
  }
2558
2054
  async getPreferences() {
2559
- return safe5(this.client.query(LINK_QUERY.PREFERENCES));
2055
+ return safe5(this.client.linkGet("/v1/link/preferences"));
2560
2056
  }
2561
2057
  async enroll(data) {
2562
- return safe5(this.client.call(LINK_MUTATION.ENROLL, data));
2058
+ return safe5(this.client.linkPost("/v1/link/enroll", data));
2563
2059
  }
2564
2060
  async enrollAndLinkOrder(data) {
2565
2061
  return safe5(
2566
- this.client.call(LINK_MUTATION.ENROLL_AND_LINK_ORDER, data)
2062
+ this.client.linkPost("/v1/link/enroll-and-link-order", data)
2567
2063
  );
2568
2064
  }
2569
2065
  async updatePreferences(preferences) {
2570
- return safe5(this.client.call(LINK_MUTATION.UPDATE_PREFERENCES, preferences));
2066
+ return safe5(this.client.linkPost("/v1/link/preferences", preferences));
2571
2067
  }
2572
2068
  async createAddress(input) {
2573
- return safe5(this.client.call(LINK_MUTATION.CREATE_ADDRESS, input));
2069
+ return safe5(
2070
+ this.client.linkPost("/v1/link/addresses", toCreateAddressPayload(input))
2071
+ );
2574
2072
  }
2575
2073
  async updateAddress(input) {
2576
- return safe5(this.client.call(LINK_MUTATION.UPDATE_ADDRESS, input));
2074
+ return safe5(
2075
+ this.client.linkPost(
2076
+ `/v1/link/addresses/${encodePathSegment(input.address_id)}`,
2077
+ toUpdateAddressPayload(input)
2078
+ )
2079
+ );
2577
2080
  }
2578
2081
  async deleteAddress(addressId) {
2579
- return safe5(this.client.linkDelete(`/v1/link/addresses/${addressId}`));
2082
+ return safe5(
2083
+ this.client.linkDelete(`/v1/link/addresses/${encodePathSegment(addressId)}`)
2084
+ );
2580
2085
  }
2581
2086
  async setDefaultAddress(addressId) {
2582
- return safe5(this.client.linkPost(`/v1/link/addresses/${addressId}/default`));
2087
+ return safe5(
2088
+ this.client.linkPost(
2089
+ `/v1/link/addresses/${encodePathSegment(addressId)}/default`
2090
+ )
2091
+ );
2583
2092
  }
2584
2093
  async trackAddressUsage(addressId) {
2585
2094
  return safe5(
2586
- this.client.call(LINK_MUTATION.TRACK_ADDRESS_USAGE, {
2587
- address_id: addressId
2588
- })
2095
+ this.client.linkPost(
2096
+ `/v1/link/addresses/${encodePathSegment(addressId)}/track-usage`
2097
+ )
2589
2098
  );
2590
2099
  }
2591
2100
  async createMobileMoney(input) {
2592
- return safe5(this.client.call(LINK_MUTATION.CREATE_MOBILE_MONEY, input));
2101
+ return safe5(
2102
+ this.client.linkPost(
2103
+ "/v1/link/mobile-money",
2104
+ toCreateMobileMoneyPayload(input)
2105
+ )
2106
+ );
2593
2107
  }
2594
2108
  async deleteMobileMoney(mobileMoneyId) {
2595
2109
  return safe5(
2596
- this.client.linkDelete(`/v1/link/mobile-money/${mobileMoneyId}`)
2110
+ this.client.linkDelete(
2111
+ `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}`
2112
+ )
2597
2113
  );
2598
2114
  }
2599
2115
  async setDefaultMobileMoney(mobileMoneyId) {
2600
2116
  return safe5(
2601
- this.client.linkPost(`/v1/link/mobile-money/${mobileMoneyId}/default`)
2117
+ this.client.linkPost(
2118
+ `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/default`
2119
+ )
2602
2120
  );
2603
2121
  }
2604
2122
  async trackMobileMoneyUsage(mobileMoneyId) {
2605
2123
  return safe5(
2606
- this.client.call(LINK_MUTATION.TRACK_MOBILE_MONEY_USAGE, {
2607
- mobile_money_id: mobileMoneyId
2608
- })
2124
+ this.client.linkPost(
2125
+ `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/track-usage`
2126
+ )
2609
2127
  );
2610
2128
  }
2611
2129
  async verifyMobileMoney(mobileMoneyId) {
2612
2130
  return safe5(
2613
- this.client.call(LINK_MUTATION.VERIFY_MOBILE_MONEY, mobileMoneyId)
2131
+ this.client.linkPost(
2132
+ `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/verify`
2133
+ )
2614
2134
  );
2615
2135
  }
2616
2136
  async getSessions() {
@@ -2623,30 +2143,28 @@ var LinkService = class {
2623
2143
  return safe5(this.client.linkDelete("/v1/link/sessions"));
2624
2144
  }
2625
2145
  async getAddressesRest() {
2626
- return safe5(this.client.linkGet("/v1/link/addresses"));
2146
+ return this.getAddresses();
2627
2147
  }
2628
2148
  async createAddressRest(input) {
2629
- return safe5(this.client.linkPost("/v1/link/addresses", input));
2149
+ return this.createAddress(input);
2630
2150
  }
2631
2151
  async deleteAddressRest(addressId) {
2632
- return safe5(this.client.linkDelete(`/v1/link/addresses/${addressId}`));
2152
+ return this.deleteAddress(addressId);
2633
2153
  }
2634
2154
  async setDefaultAddressRest(addressId) {
2635
- return safe5(this.client.linkPost(`/v1/link/addresses/${addressId}/default`));
2155
+ return this.setDefaultAddress(addressId);
2636
2156
  }
2637
2157
  async getMobileMoneyRest() {
2638
- return safe5(this.client.linkGet("/v1/link/mobile-money"));
2158
+ return this.getMobileMoney();
2639
2159
  }
2640
2160
  async createMobileMoneyRest(input) {
2641
- return safe5(this.client.linkPost("/v1/link/mobile-money", input));
2161
+ return this.createMobileMoney(input);
2642
2162
  }
2643
2163
  async deleteMobileMoneyRest(mobileMoneyId) {
2644
- return safe5(this.client.linkDelete(`/v1/link/mobile-money/${mobileMoneyId}`));
2164
+ return this.deleteMobileMoney(mobileMoneyId);
2645
2165
  }
2646
2166
  async setDefaultMobileMoneyRest(mobileMoneyId) {
2647
- return safe5(
2648
- this.client.linkPost(`/v1/link/mobile-money/${mobileMoneyId}/default`)
2649
- );
2167
+ return this.setDefaultMobileMoney(mobileMoneyId);
2650
2168
  }
2651
2169
  };
2652
2170
 
@@ -2665,23 +2183,12 @@ async function safe6(promise) {
2665
2183
  return err(toCimplifyError6(error));
2666
2184
  }
2667
2185
  }
2668
- async function safeWithFallback5(primary, fallback) {
2669
- const primaryResult = await safe6(primary());
2670
- if (primaryResult.ok) return primaryResult;
2671
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2672
- return primaryResult;
2673
- }
2674
- return safe6(fallback());
2675
- }
2676
2186
  var AuthService = class {
2677
2187
  constructor(client) {
2678
2188
  this.client = client;
2679
2189
  }
2680
2190
  async getStatus() {
2681
- return safeWithFallback5(
2682
- () => this.client.get("/api/v1/auth/status"),
2683
- () => this.client.query("auth")
2684
- );
2191
+ return safe6(this.client.get("/api/v1/auth/status"));
2685
2192
  }
2686
2193
  async getCurrentUser() {
2687
2194
  const result = await this.getStatus();
@@ -2694,43 +2201,26 @@ var AuthService = class {
2694
2201
  return ok(result.value.is_authenticated);
2695
2202
  }
2696
2203
  async requestOtp(contact, contactType) {
2697
- return safeWithFallback5(
2698
- () => this.client.post("/api/v1/auth/request-otp", {
2699
- contact,
2700
- contact_type: contactType
2701
- }),
2702
- () => this.client.call(AUTH_MUTATION.REQUEST_OTP, {
2204
+ return safe6(
2205
+ this.client.post("/api/v1/auth/request-otp", {
2703
2206
  contact,
2704
2207
  contact_type: contactType
2705
2208
  })
2706
2209
  );
2707
2210
  }
2708
2211
  async verifyOtp(code, contact) {
2709
- return safeWithFallback5(
2710
- () => this.client.post("/api/v1/auth/verify-otp", {
2711
- otp_code: code,
2712
- contact
2713
- }),
2714
- () => this.client.call(AUTH_MUTATION.VERIFY_OTP, {
2212
+ return safe6(
2213
+ this.client.post("/api/v1/auth/verify-otp", {
2715
2214
  otp_code: code,
2716
2215
  contact
2717
2216
  })
2718
2217
  );
2719
2218
  }
2720
2219
  async logout() {
2721
- return safeWithFallback5(
2722
- () => this.client.post("/api/v1/auth/logout"),
2723
- () => this.client.call("auth.logout")
2724
- );
2220
+ return safe6(this.client.post("/api/v1/auth/logout"));
2725
2221
  }
2726
2222
  async updateProfile(input) {
2727
- return safe6(this.client.call("auth.update_profile", input));
2728
- }
2729
- async changePassword(input) {
2730
- return safe6(this.client.call("auth.change_password", input));
2731
- }
2732
- async resetPassword(email) {
2733
- return safe6(this.client.call("auth.reset_password", { email }));
2223
+ return safe6(this.client.post("/api/v1/auth/profile", input));
2734
2224
  }
2735
2225
  };
2736
2226
 
@@ -2749,47 +2239,29 @@ async function safe7(promise) {
2749
2239
  return err(toCimplifyError7(error));
2750
2240
  }
2751
2241
  }
2752
- async function safeWithFallback6(primary, fallback) {
2753
- const primaryResult = await safe7(primary());
2754
- if (primaryResult.ok) return primaryResult;
2755
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2756
- return primaryResult;
2757
- }
2758
- return safe7(fallback());
2759
- }
2760
2242
  var BusinessService = class {
2761
2243
  constructor(client) {
2762
2244
  this.client = client;
2763
2245
  }
2764
2246
  async getInfo() {
2765
- return safeWithFallback6(
2766
- () => this.client.get("/api/v1/business"),
2767
- () => this.client.query("business.info")
2768
- );
2247
+ return safe7(this.client.get("/api/v1/business"));
2769
2248
  }
2770
2249
  async getByHandle(handle) {
2771
- return safe7(this.client.query(`business.handle.${handle}`));
2250
+ const encodedHandle = encodeURIComponent(handle);
2251
+ return safe7(this.client.get(`/api/v1/business/by-handle/${encodedHandle}`));
2772
2252
  }
2773
2253
  async getByDomain(domain) {
2774
- return safe7(this.client.query("business.domain", { domain }));
2254
+ const encodedDomain = encodeURIComponent(domain);
2255
+ return safe7(this.client.get(`/api/v1/business/by-domain?domain=${encodedDomain}`));
2775
2256
  }
2776
2257
  async getSettings() {
2777
- return safeWithFallback6(
2778
- () => this.client.get("/api/v1/business/settings"),
2779
- () => this.client.query("business.settings")
2780
- );
2258
+ return safe7(this.client.get("/api/v1/business/settings"));
2781
2259
  }
2782
2260
  async getTheme() {
2783
- return safeWithFallback6(
2784
- () => this.client.get("/api/v1/business/theme"),
2785
- () => this.client.query("business.theme")
2786
- );
2261
+ return safe7(this.client.get("/api/v1/business/theme"));
2787
2262
  }
2788
2263
  async getLocations() {
2789
- return safeWithFallback6(
2790
- () => this.client.get("/api/v1/business/locations"),
2791
- () => this.client.query("business.locations")
2792
- );
2264
+ return safe7(this.client.get("/api/v1/business/locations"));
2793
2265
  }
2794
2266
  async getLocation(locationId) {
2795
2267
  const result = await this.getLocations();
@@ -2801,10 +2273,7 @@ var BusinessService = class {
2801
2273
  return ok(location);
2802
2274
  }
2803
2275
  async getHours() {
2804
- return safeWithFallback6(
2805
- () => this.client.get("/api/v1/business/hours"),
2806
- () => this.client.query("business.hours")
2807
- );
2276
+ return safe7(this.client.get("/api/v1/business/hours"));
2808
2277
  }
2809
2278
  async getLocationHours(locationId) {
2810
2279
  const result = await this.getHours();
@@ -2812,31 +2281,7 @@ var BusinessService = class {
2812
2281
  return ok(result.value.filter((hour) => hour.location_id === locationId));
2813
2282
  }
2814
2283
  async getBootstrap() {
2815
- const restBootstrap = await safe7(this.client.get("/api/v1/bootstrap"));
2816
- if (restBootstrap.ok) {
2817
- return restBootstrap;
2818
- }
2819
- const [businessResult, locationsResult, categoriesResult] = await Promise.all([
2820
- this.getInfo(),
2821
- this.getLocations(),
2822
- safe7(this.client.query("categories#select(id,name,slug)"))
2823
- ]);
2824
- if (!businessResult.ok) return businessResult;
2825
- if (!locationsResult.ok) return locationsResult;
2826
- if (!categoriesResult.ok) return categoriesResult;
2827
- const business = businessResult.value;
2828
- const locations = locationsResult.value;
2829
- const categories = categoriesResult.value;
2830
- const defaultLocation = locations[0];
2831
- return ok({
2832
- business,
2833
- location: defaultLocation,
2834
- locations,
2835
- categories,
2836
- currency: business.default_currency,
2837
- is_open: defaultLocation?.accepts_online_orders ?? false,
2838
- accepts_orders: defaultLocation?.accepts_online_orders ?? false
2839
- });
2284
+ return safe7(this.client.get("/api/v1/bootstrap"));
2840
2285
  }
2841
2286
  };
2842
2287
 
@@ -2859,49 +2304,47 @@ var InventoryService = class {
2859
2304
  constructor(client) {
2860
2305
  this.client = client;
2861
2306
  }
2307
+ withQuery(path, params) {
2308
+ const searchParams = new URLSearchParams();
2309
+ for (const [key, value] of Object.entries(params)) {
2310
+ if (value === void 0) continue;
2311
+ searchParams.set(key, String(value));
2312
+ }
2313
+ const query2 = searchParams.toString();
2314
+ return query2 ? `${path}?${query2}` : path;
2315
+ }
2862
2316
  async getStockLevels() {
2863
- return safe8(this.client.query("inventory.stock_levels"));
2317
+ return safe8(this.client.get("/api/v1/inventory/stock-levels"));
2864
2318
  }
2865
2319
  async getProductStock(productId, locationId) {
2866
- if (locationId) {
2867
- return safe8(
2868
- this.client.query("inventory.product", {
2869
- product_id: productId,
2870
- location_id: locationId
2871
- })
2872
- );
2873
- }
2874
- return safe8(
2875
- this.client.query("inventory.product", {
2876
- product_id: productId
2877
- })
2878
- );
2320
+ const encodedId = encodeURIComponent(productId);
2321
+ const path = this.withQuery(`/api/v1/inventory/products/${encodedId}/stock`, {
2322
+ location_id: locationId
2323
+ });
2324
+ return safe8(this.client.get(path));
2879
2325
  }
2880
2326
  async getVariantStock(variantId, locationId) {
2881
- return safe8(
2882
- this.client.query("inventory.variant", {
2883
- variant_id: variantId,
2884
- location_id: locationId
2885
- })
2886
- );
2327
+ const encodedId = encodeURIComponent(variantId);
2328
+ const path = this.withQuery(`/api/v1/inventory/variants/${encodedId}/stock`, {
2329
+ location_id: locationId
2330
+ });
2331
+ return safe8(this.client.get(path));
2887
2332
  }
2888
2333
  async checkProductAvailability(productId, quantity, locationId) {
2889
- return safe8(
2890
- this.client.query("inventory.check_availability", {
2891
- product_id: productId,
2892
- quantity,
2893
- location_id: locationId
2894
- })
2895
- );
2334
+ const encodedId = encodeURIComponent(productId);
2335
+ const path = this.withQuery(`/api/v1/inventory/products/${encodedId}/availability`, {
2336
+ quantity,
2337
+ location_id: locationId
2338
+ });
2339
+ return safe8(this.client.get(path));
2896
2340
  }
2897
2341
  async checkVariantAvailability(variantId, quantity, locationId) {
2898
- return safe8(
2899
- this.client.query("inventory.check_availability", {
2900
- variant_id: variantId,
2901
- quantity,
2902
- location_id: locationId
2903
- })
2904
- );
2342
+ const encodedId = encodeURIComponent(variantId);
2343
+ const path = this.withQuery(`/api/v1/inventory/variants/${encodedId}/availability`, {
2344
+ quantity,
2345
+ location_id: locationId
2346
+ });
2347
+ return safe8(this.client.get(path));
2905
2348
  }
2906
2349
  async checkMultipleAvailability(items, locationId) {
2907
2350
  const results = await Promise.all(
@@ -2915,7 +2358,7 @@ var InventoryService = class {
2915
2358
  return ok(results.map((r) => r.value));
2916
2359
  }
2917
2360
  async getSummary() {
2918
- return safe8(this.client.query("inventory.summary"));
2361
+ return safe8(this.client.get("/api/v1/inventory/summary"));
2919
2362
  }
2920
2363
  async isInStock(productId, locationId) {
2921
2364
  const result = await this.checkProductAvailability(productId, 1, locationId);
@@ -2930,9 +2373,6 @@ var InventoryService = class {
2930
2373
  };
2931
2374
 
2932
2375
  // src/scheduling.ts
2933
- function toVariables(input) {
2934
- return Object.fromEntries(Object.entries(input));
2935
- }
2936
2376
  function toCimplifyError9(error) {
2937
2377
  if (error instanceof CimplifyError) return error;
2938
2378
  if (error instanceof Error) {
@@ -2947,68 +2387,110 @@ async function safe9(promise) {
2947
2387
  return err(toCimplifyError9(error));
2948
2388
  }
2949
2389
  }
2390
+ function withQuery2(path, params) {
2391
+ const searchParams = new URLSearchParams();
2392
+ for (const [key, value] of Object.entries(params)) {
2393
+ if (value === void 0) continue;
2394
+ searchParams.set(key, String(value));
2395
+ }
2396
+ const query2 = searchParams.toString();
2397
+ return query2 ? `${path}?${query2}` : path;
2398
+ }
2399
+ function normalizeServiceAvailability(result) {
2400
+ if (Array.isArray(result.days) && result.days.length > 0) {
2401
+ return result;
2402
+ }
2403
+ const days = Array.isArray(result.availability) ? result.availability.map((day) => ({
2404
+ ...day,
2405
+ is_fully_booked: day.is_fully_booked ?? (typeof day.has_availability === "boolean" ? !day.has_availability : void 0)
2406
+ })) : [];
2407
+ return { ...result, days };
2408
+ }
2409
+ function firstScheduledTime(booking) {
2410
+ return booking.service_items.find((item) => typeof item.scheduled_start === "string")?.scheduled_start || booking.created_at;
2411
+ }
2950
2412
  var SchedulingService = class {
2951
2413
  constructor(client) {
2952
2414
  this.client = client;
2953
2415
  }
2954
2416
  async getServices() {
2955
- return safe9(this.client.query("scheduling.services"));
2417
+ return safe9(this.client.get("/api/v1/scheduling/services"));
2956
2418
  }
2957
2419
  /**
2958
- * Get a specific service by ID
2959
- * Note: Filters from all services client-side (no single-service endpoint)
2420
+ * Get a specific service by ID.
2960
2421
  */
2961
2422
  async getService(serviceId) {
2962
2423
  const result = await this.getServices();
2963
2424
  if (!result.ok) return result;
2964
- return ok(result.value.find((s) => s.id === serviceId) || null);
2425
+ return ok(result.value.find((service) => service.id === serviceId) || null);
2965
2426
  }
2966
2427
  async getAvailableSlots(input) {
2967
- return safe9(
2968
- this.client.query("scheduling.slots", toVariables(input))
2969
- );
2428
+ const path = withQuery2("/api/v1/scheduling/slots", {
2429
+ service_id: input.service_id,
2430
+ date: input.date,
2431
+ participant_count: input.participant_count,
2432
+ duration_minutes: input.duration_minutes
2433
+ });
2434
+ return safe9(this.client.get(path));
2970
2435
  }
2971
2436
  async checkSlotAvailability(input) {
2972
- return safe9(
2973
- this.client.query(
2974
- "scheduling.check_availability",
2975
- toVariables(input)
2976
- )
2977
- );
2437
+ const path = withQuery2("/api/v1/scheduling/slots/check", {
2438
+ service_id: input.service_id,
2439
+ slot_time: input.slot_time,
2440
+ duration_minutes: input.duration_minutes,
2441
+ participant_count: input.participant_count
2442
+ });
2443
+ return safe9(this.client.get(path));
2978
2444
  }
2979
2445
  async getServiceAvailability(params) {
2446
+ const path = withQuery2("/api/v1/scheduling/availability", {
2447
+ service_id: params.service_id,
2448
+ start_date: params.start_date,
2449
+ end_date: params.end_date,
2450
+ location_id: params.location_id,
2451
+ participant_count: params.participant_count
2452
+ });
2980
2453
  return safe9(
2981
- this.client.query(
2982
- "scheduling.availability",
2983
- toVariables(params)
2984
- )
2454
+ this.client.get(path).then((result) => normalizeServiceAvailability(result))
2985
2455
  );
2986
2456
  }
2987
2457
  async getBooking(bookingId) {
2988
- return safe9(this.client.query(`scheduling.${bookingId}`));
2458
+ const encodedId = encodeURIComponent(bookingId);
2459
+ return safe9(this.client.get(`/api/v1/scheduling/bookings/${encodedId}`));
2989
2460
  }
2990
- async getCustomerBookings() {
2991
- return safe9(this.client.query("scheduling"));
2461
+ async getCustomerBookings(customerId) {
2462
+ const path = withQuery2("/api/v1/scheduling/bookings", {
2463
+ customer_id: customerId
2464
+ });
2465
+ return safe9(this.client.get(path));
2992
2466
  }
2993
2467
  async getUpcomingBookings() {
2994
- return safe9(
2995
- this.client.query(
2996
- "scheduling[?(@.status!='completed' && @.status!='cancelled')]#sort(start_time,asc)"
2997
- )
2998
- );
2468
+ const result = await this.getCustomerBookings();
2469
+ if (!result.ok) return result;
2470
+ const upcoming = result.value.filter((booking) => {
2471
+ const status = String(booking.status).toLowerCase();
2472
+ return status !== "completed" && status !== "cancelled";
2473
+ }).sort((a, b) => firstScheduledTime(a).localeCompare(firstScheduledTime(b)));
2474
+ return ok(upcoming);
2999
2475
  }
3000
2476
  async getPastBookings(limit = 10) {
3001
- return safe9(
3002
- this.client.query(
3003
- `scheduling[?(@.status=='completed')]#sort(start_time,desc)#limit(${limit})`
3004
- )
3005
- );
2477
+ const result = await this.getCustomerBookings();
2478
+ if (!result.ok) return result;
2479
+ const past = result.value.filter((booking) => String(booking.status).toLowerCase() === "completed").sort((a, b) => firstScheduledTime(b).localeCompare(firstScheduledTime(a))).slice(0, Math.max(0, limit));
2480
+ return ok(past);
3006
2481
  }
3007
2482
  async cancelBooking(input) {
3008
- return safe9(this.client.call("scheduling.cancel_booking", input));
2483
+ const encodedId = encodeURIComponent(input.booking_id);
2484
+ return safe9(
2485
+ this.client.post(`/api/v1/scheduling/bookings/${encodedId}/cancel`, {
2486
+ reason: input.reason
2487
+ })
2488
+ );
3009
2489
  }
3010
2490
  async rescheduleBooking(input) {
3011
- return safe9(this.client.call("scheduling.reschedule_booking", input));
2491
+ return safe9(
2492
+ this.client.post("/api/v1/scheduling/bookings/reschedule", input)
2493
+ );
3012
2494
  }
3013
2495
  async getNextAvailableSlot(serviceId, fromDate) {
3014
2496
  const date = fromDate || (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
@@ -3027,6 +2509,12 @@ var SchedulingService = class {
3027
2509
  if (!result.ok) return result;
3028
2510
  return ok(result.value.some((slot) => slot.is_available));
3029
2511
  }
2512
+ // Compatibility alias for callers typed against the older Booking shape.
2513
+ async getBookingLegacy(bookingId) {
2514
+ const result = await this.getBooking(bookingId);
2515
+ if (!result.ok) return result;
2516
+ return ok(result.value);
2517
+ }
3030
2518
  };
3031
2519
 
3032
2520
  // src/lite.ts
@@ -3049,47 +2537,18 @@ var LiteService = class {
3049
2537
  this.client = client;
3050
2538
  }
3051
2539
  async getBootstrap() {
3052
- return safe10(this.client.query("lite.bootstrap"));
2540
+ return safe10(this.client.get("/api/v1/lite/bootstrap"));
3053
2541
  }
3054
2542
  async getTable(tableId) {
3055
- return safe10(this.client.query(`lite.table.${tableId}`));
3056
- }
3057
- async getTableByNumber(tableNumber, locationId) {
3058
- return safe10(
3059
- this.client.query("lite.table_by_number", {
3060
- table_number: tableNumber,
3061
- location_id: locationId
3062
- })
3063
- );
3064
- }
3065
- async sendToKitchen(tableId, items) {
3066
- return safe10(
3067
- this.client.call("lite.send_to_kitchen", {
3068
- table_id: tableId,
3069
- items
3070
- })
3071
- );
3072
- }
3073
- async callWaiter(tableId, reason) {
3074
- return safe10(
3075
- this.client.call("lite.call_waiter", {
3076
- table_id: tableId,
3077
- reason
3078
- })
3079
- );
3080
- }
3081
- async requestBill(tableId) {
3082
- return safe10(
3083
- this.client.call("lite.request_bill", {
3084
- table_id: tableId
3085
- })
3086
- );
2543
+ const encodedId = encodeURIComponent(tableId);
2544
+ return safe10(this.client.get(`/api/v1/lite/tables/${encodedId}`));
3087
2545
  }
3088
2546
  async getMenu() {
3089
- return safe10(this.client.query("lite.menu"));
2547
+ return safe10(this.client.get("/api/v1/lite/menu"));
3090
2548
  }
3091
2549
  async getMenuByCategory(categoryId) {
3092
- return safe10(this.client.query(`lite.menu.category.${categoryId}`));
2550
+ const encodedId = encodeURIComponent(categoryId);
2551
+ return safe10(this.client.get(`/api/v1/lite/menu/categories/${encodedId}`));
3093
2552
  }
3094
2553
  };
3095
2554
 
@@ -3108,30 +2567,16 @@ async function safe11(promise) {
3108
2567
  return err(toCimplifyError11(error));
3109
2568
  }
3110
2569
  }
3111
- async function safeWithFallback7(primary, fallback) {
3112
- const primaryResult = await safe11(primary());
3113
- if (primaryResult.ok) return primaryResult;
3114
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
3115
- return primaryResult;
3116
- }
3117
- return safe11(fallback());
3118
- }
3119
2570
  var FxService = class {
3120
2571
  constructor(client) {
3121
2572
  this.client = client;
3122
2573
  }
3123
2574
  async getRate(from, to) {
3124
2575
  const path = `/api/v1/fx/rate?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
3125
- return safeWithFallback7(
3126
- () => this.client.get(path),
3127
- () => this.client.call("fx.getRate", { from, to })
3128
- );
2576
+ return safe11(this.client.get(path));
3129
2577
  }
3130
2578
  async lockQuote(request) {
3131
- return safeWithFallback7(
3132
- () => this.client.post("/api/v1/fx/quotes", request),
3133
- () => this.client.call("fx.lockQuote", request)
3134
- );
2579
+ return safe11(this.client.post("/api/v1/fx/quotes", request));
3135
2580
  }
3136
2581
  };
3137
2582
 
@@ -4107,41 +3552,6 @@ var CimplifyClient = class {
4107
3552
  this.inflightRequests.set(key, request);
4108
3553
  return request;
4109
3554
  }
4110
- async query(query2, variables) {
4111
- const body = { query: query2 };
4112
- if (variables) {
4113
- body.variables = variables;
4114
- }
4115
- if (Object.keys(this.context).length > 0) {
4116
- body.context = this.context;
4117
- }
4118
- const key = this.getDedupeKey("query", body);
4119
- return this.deduplicatedRequest(key, async () => {
4120
- const response = await this.resilientFetch(`${this.baseUrl}/api/q`, {
4121
- method: "POST",
4122
- credentials: this.credentials,
4123
- headers: this.getHeaders(),
4124
- body: JSON.stringify(body)
4125
- });
4126
- return this.handleResponse(response);
4127
- });
4128
- }
4129
- async call(method, args) {
4130
- const body = {
4131
- method,
4132
- args: args !== void 0 ? [args] : []
4133
- };
4134
- if (Object.keys(this.context).length > 0) {
4135
- body.context = this.context;
4136
- }
4137
- const response = await this.resilientFetch(`${this.baseUrl}/api/m`, {
4138
- method: "POST",
4139
- credentials: this.credentials,
4140
- headers: this.getHeaders(),
4141
- body: JSON.stringify(body)
4142
- });
4143
- return this.handleResponse(response);
4144
- }
4145
3555
  async get(path) {
4146
3556
  const key = this.getDedupeKey("get", path);
4147
3557
  return this.deduplicatedRequest(key, async () => {
@@ -4244,26 +3654,6 @@ var CimplifyClient = class {
4244
3654
  }
4245
3655
  return json;
4246
3656
  }
4247
- async handleResponse(response) {
4248
- const json = await response.json();
4249
- if (!json.success || json.error) {
4250
- const error = enrichError(
4251
- new CimplifyError(
4252
- json.error?.code || "UNKNOWN_ERROR",
4253
- json.error?.message || "An unknown error occurred",
4254
- json.error?.retryable || false
4255
- ),
4256
- { isTestMode: this.isTestMode() }
4257
- );
4258
- if (response.status === 401 || error.code === ErrorCode.UNAUTHORIZED) {
4259
- console.warn(
4260
- "[Cimplify] Received 401 Unauthorized. Access token may be missing/expired. Refresh authentication and retry the request."
4261
- );
4262
- }
4263
- throw error;
4264
- }
4265
- return json.data;
4266
- }
4267
3657
  get catalogue() {
4268
3658
  if (!this._catalogue) {
4269
3659
  this._catalogue = new CatalogueQueries(this);
@@ -4355,6 +3745,173 @@ function createCimplifyClient(config = {}) {
4355
3745
  return new CimplifyClient(config);
4356
3746
  }
4357
3747
 
3748
+ // src/query/builder.ts
3749
+ function escapeQueryValue(value) {
3750
+ return value.replace(/'/g, "\\'");
3751
+ }
3752
+ var QueryBuilder = class {
3753
+ constructor(entity) {
3754
+ this.filters = [];
3755
+ this.modifiers = [];
3756
+ this.pathSegments = [];
3757
+ this.entity = entity;
3758
+ }
3759
+ path(segment) {
3760
+ this.pathSegments.push(segment);
3761
+ return this;
3762
+ }
3763
+ where(field, op, value) {
3764
+ const v = typeof value === "string" ? `'${escapeQueryValue(value)}'` : value;
3765
+ if (op === "contains" || op === "startsWith") {
3766
+ this.filters.push(`@.${field} ${op} ${v}`);
3767
+ } else {
3768
+ this.filters.push(`@.${field}${op}${v}`);
3769
+ }
3770
+ return this;
3771
+ }
3772
+ and(field, op, value) {
3773
+ return this.where(field, op, value);
3774
+ }
3775
+ sort(field, order = "asc") {
3776
+ this.modifiers.push(`sort(${field},${order})`);
3777
+ return this;
3778
+ }
3779
+ limit(n) {
3780
+ this.modifiers.push(`limit(${n})`);
3781
+ return this;
3782
+ }
3783
+ offset(n) {
3784
+ this.modifiers.push(`offset(${n})`);
3785
+ return this;
3786
+ }
3787
+ count() {
3788
+ this.modifiers.push("count");
3789
+ return this;
3790
+ }
3791
+ enriched() {
3792
+ this.modifiers.push("enriched");
3793
+ return this;
3794
+ }
3795
+ build() {
3796
+ let query2 = this.entity;
3797
+ if (this.pathSegments.length > 0) {
3798
+ query2 += "." + this.pathSegments.join(".");
3799
+ }
3800
+ if (this.filters.length > 0) {
3801
+ query2 += `[?(${this.filters.join(" && ")})]`;
3802
+ }
3803
+ for (const mod of this.modifiers) {
3804
+ query2 += `#${mod}`;
3805
+ }
3806
+ return query2;
3807
+ }
3808
+ toString() {
3809
+ return this.build();
3810
+ }
3811
+ };
3812
+ function query(entity) {
3813
+ return new QueryBuilder(entity);
3814
+ }
3815
+
3816
+ // src/constants.ts
3817
+ var CHECKOUT_MODE = {
3818
+ LINK: "link",
3819
+ GUEST: "guest"
3820
+ };
3821
+ var ORDER_TYPE = {
3822
+ DELIVERY: "delivery",
3823
+ PICKUP: "pickup",
3824
+ DINE_IN: "dine-in",
3825
+ WALK_IN: "walk-in"
3826
+ };
3827
+ var PAYMENT_METHOD = {
3828
+ MOBILE_MONEY: "mobile_money",
3829
+ CARD: "card"
3830
+ };
3831
+ var CHECKOUT_STEP = {
3832
+ AUTHENTICATION: "authentication",
3833
+ ORDER_DETAILS: "order_details",
3834
+ PAYMENT_METHOD: "payment_method",
3835
+ PAYMENT: "payment",
3836
+ CONFIRMATION: "confirmation"
3837
+ };
3838
+ var PAYMENT_STATE = {
3839
+ INITIAL: "initial",
3840
+ PREPARING: "preparing",
3841
+ PROCESSING: "processing",
3842
+ VERIFYING: "verifying",
3843
+ AWAITING_AUTHORIZATION: "awaiting_authorization",
3844
+ SUCCESS: "success",
3845
+ ERROR: "error",
3846
+ TIMEOUT: "timeout"
3847
+ };
3848
+ var PICKUP_TIME_TYPE = {
3849
+ ASAP: "asap",
3850
+ SCHEDULED: "scheduled"
3851
+ };
3852
+ var MOBILE_MONEY_PROVIDER = {
3853
+ MTN: "mtn",
3854
+ VODAFONE: "vodafone",
3855
+ AIRTEL: "airtel"
3856
+ };
3857
+ var AUTHORIZATION_TYPE = {
3858
+ OTP: "otp",
3859
+ PIN: "pin",
3860
+ PHONE: "phone",
3861
+ BIRTHDAY: "birthday",
3862
+ ADDRESS: "address"
3863
+ };
3864
+ var DEVICE_TYPE = {
3865
+ MOBILE: "mobile",
3866
+ DESKTOP: "desktop",
3867
+ TABLET: "tablet"
3868
+ };
3869
+ var CONTACT_TYPE = {
3870
+ PHONE: "phone",
3871
+ EMAIL: "email"
3872
+ };
3873
+ var LINK_QUERY = {
3874
+ DATA: "link.data",
3875
+ ADDRESSES: "link.addresses",
3876
+ MOBILE_MONEY: "link.mobile_money",
3877
+ PREFERENCES: "link.preferences",
3878
+ SESSIONS: "link.sessions"
3879
+ };
3880
+ var LINK_MUTATION = {
3881
+ CHECK_STATUS: "link.check_status",
3882
+ ENROLL: "link.enroll",
3883
+ ENROLL_AND_LINK_ORDER: "link.enroll_and_link_order",
3884
+ UPDATE_PREFERENCES: "link.update_preferences",
3885
+ CREATE_ADDRESS: "link.create_address",
3886
+ UPDATE_ADDRESS: "link.update_address",
3887
+ DELETE_ADDRESS: "link.delete_address",
3888
+ SET_DEFAULT_ADDRESS: "link.set_default_address",
3889
+ TRACK_ADDRESS_USAGE: "link.track_address_usage",
3890
+ CREATE_MOBILE_MONEY: "link.create_mobile_money",
3891
+ DELETE_MOBILE_MONEY: "link.delete_mobile_money",
3892
+ SET_DEFAULT_MOBILE_MONEY: "link.set_default_mobile_money",
3893
+ TRACK_MOBILE_MONEY_USAGE: "link.track_mobile_money_usage",
3894
+ VERIFY_MOBILE_MONEY: "link.verify_mobile_money",
3895
+ REVOKE_SESSION: "link.revoke_session",
3896
+ REVOKE_ALL_SESSIONS: "link.revoke_all_sessions"
3897
+ };
3898
+ var AUTH_MUTATION = {
3899
+ REQUEST_OTP: "auth.request_otp",
3900
+ VERIFY_OTP: "auth.verify_otp"
3901
+ };
3902
+ var CHECKOUT_MUTATION = {
3903
+ PROCESS: "checkout.process"
3904
+ };
3905
+ var PAYMENT_MUTATION = {
3906
+ SUBMIT_AUTHORIZATION: "payment.submit_authorization",
3907
+ CHECK_STATUS: "order.poll_payment_status"
3908
+ };
3909
+ var ORDER_MUTATION = {
3910
+ UPDATE_CUSTOMER: "order.update_order_customer"
3911
+ };
3912
+ var DEFAULT_CURRENCY = "GHS";
3913
+ var DEFAULT_COUNTRY = "GHA";
3914
+
4358
3915
  exports.AUTHORIZATION_TYPE = AUTHORIZATION_TYPE;
4359
3916
  exports.AUTH_MUTATION = AUTH_MUTATION;
4360
3917
  exports.AuthService = AuthService;