@cimplify/sdk 0.31.0 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/advanced.d.mts +6 -2
  2. package/dist/advanced.d.ts +6 -2
  3. package/dist/advanced.js +21 -21
  4. package/dist/advanced.mjs +2 -2
  5. package/dist/{chunk-46BDUSJX.mjs → chunk-2X6P5WJZ.mjs} +108 -32
  6. package/dist/{chunk-E3HC2YAE.mjs → chunk-6TVQQYQ5.mjs} +14 -1
  7. package/dist/{chunk-2CGA3MUW.js → chunk-HKVRUGM6.js} +142 -91
  8. package/dist/{chunk-3J4PPSMI.mjs → chunk-TFHKVQLL.mjs} +123 -72
  9. package/dist/{chunk-PEDLCL72.js → chunk-V2O5AO7I.js} +15 -0
  10. package/dist/{chunk-6HCBOIZ4.js → chunk-ZYACIPKO.js} +160 -84
  11. package/dist/{index-BpyFcJVv.d.ts → client-CkGlXZRd.d.mts} +121 -72
  12. package/dist/{index-m8zGQUda.d.mts → client-lvLvB1_K.d.ts} +121 -72
  13. package/dist/{index-D4oNCc37.d.mts → index-CC1JPhB2.d.mts} +2 -2
  14. package/dist/{index-BHVJgyqM.d.ts → index-CPcFayQg.d.ts} +2 -2
  15. package/dist/index.d.mts +6 -5
  16. package/dist/index.d.ts +6 -5
  17. package/dist/index.js +117 -109
  18. package/dist/index.mjs +3 -3
  19. package/dist/mock/cli.mjs +8086 -0
  20. package/dist/mock/library.d.mts +15 -0
  21. package/dist/mock/library.d.ts +15 -0
  22. package/dist/mock/library.js +7285 -0
  23. package/dist/mock/library.mjs +7278 -0
  24. package/dist/mock/msw.d.mts +14 -0
  25. package/dist/mock/msw.d.ts +14 -0
  26. package/dist/mock/msw.js +7280 -0
  27. package/dist/mock/msw.mjs +7278 -0
  28. package/dist/{payment-DnU_eLuT.d.ts → payment-DA1i5hhk.d.mts} +13 -12
  29. package/dist/{payment-DnU_eLuT.d.mts → payment-DA1i5hhk.d.ts} +13 -12
  30. package/dist/{price-DUVmRTaz.d.ts → price-Bv4G8aOO.d.ts} +1 -1
  31. package/dist/{price-D-hso3np.d.mts → price-s1XN0edJ.d.mts} +1 -1
  32. package/dist/react.d.mts +21 -4
  33. package/dist/react.d.ts +21 -4
  34. package/dist/react.js +835 -715
  35. package/dist/react.mjs +725 -605
  36. package/dist/server-B8TeE2OD.d.mts +915 -0
  37. package/dist/server-B8TeE2OD.d.ts +915 -0
  38. package/dist/styles.css +1 -1
  39. package/dist/utils.d.mts +3 -3
  40. package/dist/utils.d.ts +3 -3
  41. package/dist/utils.js +28 -28
  42. package/dist/utils.mjs +1 -1
  43. package/package.json +32 -12
  44. package/registry/cart-summary.json +1 -1
@@ -1,4 +1,4 @@
1
- import { CimplifyError, currencyCode, ErrorCode, enrichError, isPaymentStatusRequiresAction, normalizeStatusResponse, isPaymentStatusSuccess, isPaymentStatusFailure, getErrorHint } from './chunk-E3HC2YAE.mjs';
1
+ import { CimplifyError, currencyCode, ErrorCode, enrichError, isPaymentStatusRequiresAction, normalizeStatusResponse, isPaymentStatusSuccess, isPaymentStatusFailure, getErrorHint } from './chunk-6TVQQYQ5.mjs';
2
2
 
3
3
  // src/types/result.ts
4
4
  function ok(value) {
@@ -70,6 +70,16 @@ function combineObject(results) {
70
70
  return ok(values);
71
71
  }
72
72
 
73
+ // src/internal/idempotency.ts
74
+ function generateIdempotencyKey(prefix = "idem") {
75
+ if (typeof crypto !== "undefined" && crypto.randomUUID) {
76
+ return `${prefix}_${crypto.randomUUID()}`;
77
+ }
78
+ const timestamp = Date.now().toString(36);
79
+ const random = Math.random().toString(36).substring(2, 15);
80
+ return `${prefix}_${timestamp}_${random}`;
81
+ }
82
+
73
83
  // src/internal/safe.ts
74
84
  function toCimplifyError(error) {
75
85
  if (error instanceof CimplifyError) return enrichError(error);
@@ -398,8 +408,11 @@ var CatalogueQueries = class {
398
408
  )
399
409
  );
400
410
  }
401
- async fetchQuote(input) {
402
- return safe(this.client.post("/api/v1/catalogue/quotes", input));
411
+ async fetchQuote(input, opts) {
412
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
413
+ return safe(
414
+ this.client.post("/api/v1/catalogue/quotes", input, { idempotencyKey })
415
+ );
403
416
  }
404
417
  async getQuote(quoteId) {
405
418
  const encodedQuoteId = encodeURIComponent(quoteId);
@@ -592,22 +605,11 @@ function lineItemToCartInput(item) {
592
605
  }
593
606
  return input;
594
607
  }
595
- function isUICartResponse(value) {
596
- return "cart" in value;
597
- }
598
- function unwrapEnrichedCart(value) {
599
- return isUICartResponse(value) ? value.cart : value;
600
- }
601
608
  var CartOperations = class {
602
609
  constructor(client) {
603
610
  this.client = client;
604
611
  }
605
612
  async get() {
606
- const result = await safe(this.client.get("/api/v1/cart"));
607
- if (!result.ok) return result;
608
- return ok(unwrapEnrichedCart(result.value));
609
- }
610
- async getRaw() {
611
613
  return safe(this.client.get("/api/v1/cart"));
612
614
  }
613
615
  async getItems() {
@@ -633,15 +635,23 @@ var CartOperations = class {
633
635
  currency: cart.pricing.currency
634
636
  });
635
637
  }
636
- async addItem(input) {
637
- return safe(this.client.post("/api/v1/cart/items", input));
638
+ async addItem(input, opts) {
639
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
640
+ return safe(
641
+ this.client.post("/api/v1/cart/items", input, { idempotencyKey })
642
+ );
638
643
  }
639
644
  async updateItem(cartItemId, updates) {
640
- if (typeof updates.quantity === "number") {
641
- return this.updateQuantity(cartItemId, updates.quantity);
645
+ if (typeof updates.quantity !== "number") {
646
+ return {
647
+ ok: false,
648
+ error: new CimplifyError(
649
+ "VALIDATION_ERROR",
650
+ "updateItem requires a quantity; richer mid-cart edits are not supported"
651
+ )
652
+ };
642
653
  }
643
- const encodedId = encodeURIComponent(cartItemId);
644
- return safe(this.client.patch(`/api/v1/cart/items/${encodedId}`, updates));
654
+ return this.updateQuantity(cartItemId, updates.quantity);
645
655
  }
646
656
  async updateQuantity(cartItemId, quantity) {
647
657
  const encodedId = encodeURIComponent(cartItemId);
@@ -658,11 +668,14 @@ var CartOperations = class {
658
668
  async clear() {
659
669
  return safe(this.client.delete("/api/v1/cart"));
660
670
  }
661
- async applyCoupon(code) {
671
+ async applyCoupon(code, opts) {
672
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
662
673
  return safe(
663
- this.client.post("/api/v1/cart/coupons", {
664
- coupon_code: code
665
- })
674
+ this.client.post(
675
+ "/api/v1/cart/coupons",
676
+ { coupon_code: code },
677
+ { idempotencyKey }
678
+ )
666
679
  );
667
680
  }
668
681
  async removeCoupon() {
@@ -1525,14 +1538,6 @@ function toTerminalFailure(code, message, recoverable) {
1525
1538
  }
1526
1539
  };
1527
1540
  }
1528
- function generateIdempotencyKey() {
1529
- if (typeof crypto !== "undefined" && crypto.randomUUID) {
1530
- return `idem_${crypto.randomUUID()}`;
1531
- }
1532
- const timestamp = Date.now().toString(36);
1533
- const random = Math.random().toString(36).substring(2, 15);
1534
- return `idem_${timestamp}_${random}`;
1535
- }
1536
1541
  var CheckoutService = class {
1537
1542
  constructor(client) {
1538
1543
  this.client = client;
@@ -1713,13 +1718,16 @@ var OrderQueries = class {
1713
1718
  async getByStatus(status) {
1714
1719
  return this.list({ status });
1715
1720
  }
1716
- async cancel(orderId, reason) {
1721
+ async cancel(orderId, reason, opts) {
1717
1722
  const encodedId = encodeURIComponent(orderId);
1718
1723
  const tokenParam = this.orderTokenParam(orderId);
1724
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
1719
1725
  return safe(
1720
- this.client.post(`/api/v1/orders/${encodedId}/cancel${tokenParam}`, {
1721
- reason
1722
- })
1726
+ this.client.post(
1727
+ `/api/v1/orders/${encodedId}/cancel${tokenParam}`,
1728
+ { reason },
1729
+ { idempotencyKey }
1730
+ )
1723
1731
  );
1724
1732
  }
1725
1733
  };
@@ -1764,12 +1772,16 @@ var LinkService = class {
1764
1772
  async getProfile() {
1765
1773
  return safe(this.client.linkGet("/v1/link/profile"));
1766
1774
  }
1767
- async requestOtp(input) {
1768
- return safe(this.client.linkPost("/v1/link/auth/request-otp", input));
1775
+ async requestOtp(input, opts) {
1776
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
1777
+ return safe(
1778
+ this.client.linkPost("/v1/link/auth/request-otp", input, { idempotencyKey })
1779
+ );
1769
1780
  }
1770
- async verifyOtp(input) {
1781
+ async verifyOtp(input, opts) {
1782
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
1771
1783
  const result = await safe(
1772
- this.client.linkPost("/v1/link/auth/verify-otp", input)
1784
+ this.client.linkPost("/v1/link/auth/verify-otp", input, { idempotencyKey })
1773
1785
  );
1774
1786
  if (result.ok && result.value.session_token) {
1775
1787
  this.client.setAccessToken(result.value.session_token);
@@ -1798,20 +1810,33 @@ var LinkService = class {
1798
1810
  async getPreferences() {
1799
1811
  return safe(this.client.linkGet("/v1/link/preferences"));
1800
1812
  }
1801
- async enroll(data) {
1802
- return safe(this.client.linkPost("/v1/link/enroll", data));
1813
+ async enroll(data, opts) {
1814
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
1815
+ return safe(
1816
+ this.client.linkPost("/v1/link/enroll", data, { idempotencyKey })
1817
+ );
1803
1818
  }
1804
- async enrollAndLinkOrder(data) {
1819
+ async enrollAndLinkOrder(data, opts) {
1820
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
1805
1821
  return safe(
1806
- this.client.linkPost("/v1/link/enroll-and-link-order", data)
1822
+ this.client.linkPost(
1823
+ "/v1/link/enroll-and-link-order",
1824
+ data,
1825
+ { idempotencyKey }
1826
+ )
1807
1827
  );
1808
1828
  }
1809
1829
  async updatePreferences(preferences) {
1810
1830
  return safe(this.client.linkPost("/v1/link/preferences", preferences));
1811
1831
  }
1812
- async createAddress(input) {
1832
+ async createAddress(input, opts) {
1833
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
1813
1834
  return safe(
1814
- this.client.linkPost("/v1/link/addresses", toCreateAddressPayload(input))
1835
+ this.client.linkPost(
1836
+ "/v1/link/addresses",
1837
+ toCreateAddressPayload(input),
1838
+ { idempotencyKey }
1839
+ )
1815
1840
  );
1816
1841
  }
1817
1842
  async updateAddress(input) {
@@ -1841,11 +1866,13 @@ var LinkService = class {
1841
1866
  )
1842
1867
  );
1843
1868
  }
1844
- async createMobileMoney(input) {
1869
+ async createMobileMoney(input, opts) {
1870
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
1845
1871
  return safe(
1846
1872
  this.client.linkPost(
1847
1873
  "/v1/link/mobile-money",
1848
- toCreateMobileMoneyPayload(input)
1874
+ toCreateMobileMoneyPayload(input),
1875
+ { idempotencyKey }
1849
1876
  )
1850
1877
  );
1851
1878
  }
@@ -1870,10 +1897,13 @@ var LinkService = class {
1870
1897
  )
1871
1898
  );
1872
1899
  }
1873
- async verifyMobileMoney(mobileMoneyId) {
1900
+ async verifyMobileMoney(mobileMoneyId, opts) {
1901
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
1874
1902
  return safe(
1875
1903
  this.client.linkPost(
1876
- `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/verify`
1904
+ `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/verify`,
1905
+ void 0,
1906
+ { idempotencyKey }
1877
1907
  )
1878
1908
  );
1879
1909
  }
@@ -1906,24 +1936,34 @@ var AuthService = class {
1906
1936
  if (!result.ok) return result;
1907
1937
  return ok(result.value.is_authenticated);
1908
1938
  }
1909
- async requestOtp(contact, contactType) {
1939
+ async requestOtp(contact, contactType, opts) {
1940
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
1910
1941
  return safe(
1911
- this.client.post("/api/v1/auth/request-otp", {
1912
- contact,
1913
- contact_type: contactType
1914
- })
1942
+ this.client.post(
1943
+ "/api/v1/auth/request-otp",
1944
+ { contact, contact_type: contactType },
1945
+ { idempotencyKey }
1946
+ )
1915
1947
  );
1916
1948
  }
1917
- async verifyOtp(code, contact) {
1918
- return safe(
1919
- this.client.post("/api/v1/auth/verify-otp", {
1920
- otp_code: code,
1921
- contact
1922
- })
1949
+ async verifyOtp(code, contact, opts) {
1950
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
1951
+ const result = await safe(
1952
+ this.client.post(
1953
+ "/api/v1/auth/verify-otp",
1954
+ { otp_code: code, contact },
1955
+ { idempotencyKey }
1956
+ )
1923
1957
  );
1958
+ if (result.ok && result.value.session_token) {
1959
+ this.client.setAccessToken(result.value.session_token);
1960
+ }
1961
+ return result;
1924
1962
  }
1925
1963
  async logout() {
1926
- return safe(this.client.post("/api/v1/auth/logout"));
1964
+ const result = await safe(this.client.post("/api/v1/auth/logout"));
1965
+ this.client.clearSession();
1966
+ return result;
1927
1967
  }
1928
1968
  async updateProfile(input) {
1929
1969
  return safe(this.client.post("/api/v1/auth/profile", input));
@@ -2118,17 +2158,25 @@ var SchedulingService = class {
2118
2158
  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));
2119
2159
  return ok(past);
2120
2160
  }
2121
- async cancelBooking(input) {
2161
+ async cancelBooking(input, opts) {
2122
2162
  const encodedId = encodeURIComponent(input.booking_id);
2163
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
2123
2164
  return safe(
2124
- this.client.post(`/api/v1/scheduling/bookings/${encodedId}/cancel`, {
2125
- reason: input.reason
2126
- })
2165
+ this.client.post(
2166
+ `/api/v1/scheduling/bookings/${encodedId}/cancel`,
2167
+ { reason: input.reason },
2168
+ { idempotencyKey }
2169
+ )
2127
2170
  );
2128
2171
  }
2129
- async rescheduleBooking(input) {
2172
+ async rescheduleBooking(input, opts) {
2173
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
2130
2174
  return safe(
2131
- this.client.post("/api/v1/scheduling/bookings/reschedule", input)
2175
+ this.client.post(
2176
+ "/api/v1/scheduling/bookings/reschedule",
2177
+ input,
2178
+ { idempotencyKey }
2179
+ )
2132
2180
  );
2133
2181
  }
2134
2182
  async getNextAvailableSlot(serviceId, fromDate) {
@@ -2138,7 +2186,7 @@ var SchedulingService = class {
2138
2186
  date
2139
2187
  });
2140
2188
  if (!result.ok) return result;
2141
- return ok(result.value.find((slot) => slot.is_available) || null);
2189
+ return ok(result.value[0] ?? null);
2142
2190
  }
2143
2191
  async hasAvailabilityOn(serviceId, date) {
2144
2192
  const result = await this.getAvailableSlots({
@@ -2146,7 +2194,7 @@ var SchedulingService = class {
2146
2194
  date
2147
2195
  });
2148
2196
  if (!result.ok) return result;
2149
- return ok(result.value.some((slot) => slot.is_available));
2197
+ return ok(result.value.length > 0);
2150
2198
  }
2151
2199
  };
2152
2200
 
@@ -2180,8 +2228,11 @@ var FxService = class {
2180
2228
  const path = `/api/v1/fx/rate?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
2181
2229
  return safe(this.client.get(path));
2182
2230
  }
2183
- async lockQuote(request) {
2184
- return safe(this.client.post("/api/v1/fx/quotes", request));
2231
+ async lockQuote(request, opts) {
2232
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
2233
+ return safe(
2234
+ this.client.post("/api/v1/fx/quotes", request, { idempotencyKey })
2235
+ );
2185
2236
  }
2186
2237
  };
2187
2238
 
@@ -185,13 +185,26 @@ var CimplifyError = class extends Error {
185
185
  return this.message;
186
186
  }
187
187
  };
188
+ var IdempotencyMismatchError = class extends CimplifyError {
189
+ constructor(message, originalCreatedAt) {
190
+ super("IDEMPOTENCY_MISMATCH", message, false);
191
+ this.originalCreatedAt = originalCreatedAt;
192
+ this.name = "IdempotencyMismatchError";
193
+ }
194
+ };
188
195
  function isCimplifyError(error) {
189
196
  return error instanceof CimplifyError;
190
197
  }
198
+ function isIdempotencyMismatchError(error) {
199
+ return error instanceof IdempotencyMismatchError;
200
+ }
191
201
  function getErrorHint(code) {
192
202
  return ERROR_HINTS[code];
193
203
  }
194
204
  function enrichError(error, options = {}) {
205
+ if (error instanceof IdempotencyMismatchError) {
206
+ return error;
207
+ }
195
208
  const hint = getErrorHint(error.code);
196
209
  const docsUrl = error.docs_url || hint?.docs_url || docsUrlForCode(error.code || ErrorCode.UNKNOWN_ERROR);
197
210
  const suggestion = error.suggestion || hint?.suggestion;
@@ -701,6 +714,7 @@ exports.CURRENCY_SYMBOLS = CURRENCY_SYMBOLS;
701
714
  exports.CimplifyError = CimplifyError;
702
715
  exports.ERROR_HINTS = ERROR_HINTS;
703
716
  exports.ErrorCode = ErrorCode;
717
+ exports.IdempotencyMismatchError = IdempotencyMismatchError;
704
718
  exports.MOBILE_MONEY_PROVIDERS = MOBILE_MONEY_PROVIDERS;
705
719
  exports.ZERO = ZERO;
706
720
  exports.categorizePaymentError = categorizePaymentError;
@@ -727,6 +741,7 @@ exports.getTaxAmount = getTaxAmount;
727
741
  exports.getUnitPriceAtQuantity = getUnitPriceAtQuantity;
728
742
  exports.hasTaxInfo = hasTaxInfo;
729
743
  exports.isCimplifyError = isCimplifyError;
744
+ exports.isIdempotencyMismatchError = isIdempotencyMismatchError;
730
745
  exports.isOnSale = isOnSale;
731
746
  exports.isPaymentStatusFailure = isPaymentStatusFailure;
732
747
  exports.isPaymentStatusRequiresAction = isPaymentStatusRequiresAction;