@cimplify/sdk 0.99.1 → 0.99.2

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/advanced.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkVEOAMBEX_js = require('./chunk-VEOAMBEX.js');
3
+ var chunk4S5EMSF5_js = require('./chunk-4S5EMSF5.js');
4
4
  require('./chunk-PTPOQVXS.js');
5
5
  require('./chunk-AETVRBKI.js');
6
6
  require('./chunk-OWW5GUSB.js');
@@ -9,77 +9,77 @@ require('./chunk-OWW5GUSB.js');
9
9
 
10
10
  Object.defineProperty(exports, "AuthService", {
11
11
  enumerable: true,
12
- get: function () { return chunkVEOAMBEX_js.AuthService; }
12
+ get: function () { return chunk4S5EMSF5_js.AuthService; }
13
13
  });
14
14
  Object.defineProperty(exports, "BusinessService", {
15
15
  enumerable: true,
16
- get: function () { return chunkVEOAMBEX_js.BusinessService; }
16
+ get: function () { return chunk4S5EMSF5_js.BusinessService; }
17
17
  });
18
18
  Object.defineProperty(exports, "CartOperations", {
19
19
  enumerable: true,
20
- get: function () { return chunkVEOAMBEX_js.CartOperations; }
20
+ get: function () { return chunk4S5EMSF5_js.CartOperations; }
21
21
  });
22
22
  Object.defineProperty(exports, "CatalogueQueries", {
23
23
  enumerable: true,
24
- get: function () { return chunkVEOAMBEX_js.CatalogueQueries; }
24
+ get: function () { return chunk4S5EMSF5_js.CatalogueQueries; }
25
25
  });
26
26
  Object.defineProperty(exports, "CheckoutOperations", {
27
27
  enumerable: true,
28
- get: function () { return chunkVEOAMBEX_js.CheckoutService; }
28
+ get: function () { return chunk4S5EMSF5_js.CheckoutService; }
29
29
  });
30
30
  Object.defineProperty(exports, "CheckoutService", {
31
31
  enumerable: true,
32
- get: function () { return chunkVEOAMBEX_js.CheckoutService; }
32
+ get: function () { return chunk4S5EMSF5_js.CheckoutService; }
33
33
  });
34
34
  Object.defineProperty(exports, "CimplifyElement", {
35
35
  enumerable: true,
36
- get: function () { return chunkVEOAMBEX_js.CimplifyElement; }
36
+ get: function () { return chunk4S5EMSF5_js.CimplifyElement; }
37
37
  });
38
38
  Object.defineProperty(exports, "CimplifyElements", {
39
39
  enumerable: true,
40
- get: function () { return chunkVEOAMBEX_js.CimplifyElements; }
40
+ get: function () { return chunk4S5EMSF5_js.CimplifyElements; }
41
41
  });
42
42
  Object.defineProperty(exports, "ELEMENT_TYPES", {
43
43
  enumerable: true,
44
- get: function () { return chunkVEOAMBEX_js.ELEMENT_TYPES; }
44
+ get: function () { return chunk4S5EMSF5_js.ELEMENT_TYPES; }
45
45
  });
46
46
  Object.defineProperty(exports, "EVENT_TYPES", {
47
47
  enumerable: true,
48
- get: function () { return chunkVEOAMBEX_js.EVENT_TYPES; }
48
+ get: function () { return chunk4S5EMSF5_js.EVENT_TYPES; }
49
49
  });
50
50
  Object.defineProperty(exports, "FxService", {
51
51
  enumerable: true,
52
- get: function () { return chunkVEOAMBEX_js.FxService; }
52
+ get: function () { return chunk4S5EMSF5_js.FxService; }
53
53
  });
54
54
  Object.defineProperty(exports, "InventoryService", {
55
55
  enumerable: true,
56
- get: function () { return chunkVEOAMBEX_js.InventoryService; }
56
+ get: function () { return chunk4S5EMSF5_js.InventoryService; }
57
57
  });
58
58
  Object.defineProperty(exports, "LinkService", {
59
59
  enumerable: true,
60
- get: function () { return chunkVEOAMBEX_js.LinkService; }
60
+ get: function () { return chunk4S5EMSF5_js.LinkService; }
61
61
  });
62
62
  Object.defineProperty(exports, "LiteService", {
63
63
  enumerable: true,
64
- get: function () { return chunkVEOAMBEX_js.LiteService; }
64
+ get: function () { return chunk4S5EMSF5_js.LiteService; }
65
65
  });
66
66
  Object.defineProperty(exports, "MESSAGE_TYPES", {
67
67
  enumerable: true,
68
- get: function () { return chunkVEOAMBEX_js.MESSAGE_TYPES; }
68
+ get: function () { return chunk4S5EMSF5_js.MESSAGE_TYPES; }
69
69
  });
70
70
  Object.defineProperty(exports, "OrderQueries", {
71
71
  enumerable: true,
72
- get: function () { return chunkVEOAMBEX_js.OrderQueries; }
72
+ get: function () { return chunk4S5EMSF5_js.OrderQueries; }
73
73
  });
74
74
  Object.defineProperty(exports, "SchedulingService", {
75
75
  enumerable: true,
76
- get: function () { return chunkVEOAMBEX_js.SchedulingService; }
76
+ get: function () { return chunk4S5EMSF5_js.SchedulingService; }
77
77
  });
78
78
  Object.defineProperty(exports, "createElements", {
79
79
  enumerable: true,
80
- get: function () { return chunkVEOAMBEX_js.createElements; }
80
+ get: function () { return chunk4S5EMSF5_js.createElements; }
81
81
  });
82
82
  Object.defineProperty(exports, "generateIdempotencyKey", {
83
83
  enumerable: true,
84
- get: function () { return chunkVEOAMBEX_js.generateIdempotencyKey; }
84
+ get: function () { return chunk4S5EMSF5_js.generateIdempotencyKey; }
85
85
  });
package/dist/advanced.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { AuthService, BusinessService, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyElement, CimplifyElements, ELEMENT_TYPES, EVENT_TYPES, FxService, InventoryService, LinkService, LiteService, MESSAGE_TYPES, OrderQueries, SchedulingService, createElements, generateIdempotencyKey } from './chunk-VUSHG3HA.mjs';
1
+ export { AuthService, BusinessService, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyElement, CimplifyElements, ELEMENT_TYPES, EVENT_TYPES, FxService, InventoryService, LinkService, LiteService, MESSAGE_TYPES, OrderQueries, SchedulingService, createElements, generateIdempotencyKey } from './chunk-ZFI2TKTO.mjs';
2
2
  import './chunk-KFLGQGMC.mjs';
3
3
  import './chunk-K5EN2W2Q.mjs';
4
4
  import './chunk-3G6RQLXK.mjs';
@@ -82,6 +82,37 @@ function generateIdempotencyKey(prefix = "idem") {
82
82
  const random = Math.random().toString(36).substring(2, 15);
83
83
  return `${prefix}_${timestamp}_${random}`;
84
84
  }
85
+ var INTENT_PREFIX = "cimplify-intent:";
86
+ function sessionStorageOrNull() {
87
+ try {
88
+ return typeof window !== "undefined" ? window.sessionStorage : null;
89
+ } catch {
90
+ return null;
91
+ }
92
+ }
93
+ function intentIdempotencyKey(scope, fingerprint, storage = sessionStorageOrNull()) {
94
+ const slot = INTENT_PREFIX + scope;
95
+ try {
96
+ const raw = storage?.getItem(slot);
97
+ if (raw) {
98
+ const stored = JSON.parse(raw);
99
+ if (stored.fingerprint === fingerprint && typeof stored.key === "string") return stored.key;
100
+ }
101
+ } catch {
102
+ }
103
+ const key = generateIdempotencyKey();
104
+ try {
105
+ storage?.setItem(slot, JSON.stringify({ key, fingerprint }));
106
+ } catch {
107
+ }
108
+ return key;
109
+ }
110
+ function clearIntentIdempotencyKey(scope, storage = sessionStorageOrNull()) {
111
+ try {
112
+ storage?.removeItem(INTENT_PREFIX + scope);
113
+ } catch {
114
+ }
115
+ }
85
116
 
86
117
  // src/internal/safe.ts
87
118
  function toCimplifyError(error) {
@@ -1590,13 +1621,26 @@ var CheckoutService = class {
1590
1621
  if (invalid) {
1591
1622
  return err(invalid);
1592
1623
  }
1624
+ const intentScope = `checkout:${data.cart_id}`;
1625
+ const intentFingerprint = JSON.stringify([
1626
+ data.payment_method,
1627
+ data.mobile_money_details,
1628
+ data.pay_currency,
1629
+ data.voucher_code,
1630
+ data.pay_deposit
1631
+ ]);
1593
1632
  const checkoutData = {
1594
1633
  ...data,
1595
- idempotency_key: data.idempotency_key || generateIdempotencyKey()
1634
+ idempotency_key: data.idempotency_key || intentIdempotencyKey(intentScope, intentFingerprint)
1596
1635
  };
1597
1636
  const result = await safe(this.client.post("/api/v1/checkout", checkoutData));
1598
- if (result.ok && result.value.bill_token) {
1599
- this.client.setOrderToken(result.value.order_id, result.value.bill_token);
1637
+ if (result.ok) {
1638
+ clearIntentIdempotencyKey(intentScope);
1639
+ if (result.value.bill_token) {
1640
+ this.client.setOrderToken(result.value.order_id, result.value.bill_token);
1641
+ }
1642
+ } else if (result.error.code !== chunkAETVRBKI_js.ErrorCode.NETWORK_ERROR && result.error.code !== chunkAETVRBKI_js.ErrorCode.TIMEOUT) {
1643
+ clearIntentIdempotencyKey(intentScope);
1600
1644
  }
1601
1645
  return result;
1602
1646
  }
@@ -1670,7 +1714,7 @@ var CheckoutService = class {
1670
1714
  special_instructions: data.special_instructions,
1671
1715
  link_address_id: data.link_address_id,
1672
1716
  link_payment_method_id: data.link_payment_method_id,
1673
- idempotency_key: data.idempotency_key || generateIdempotencyKey(),
1717
+ idempotency_key: data.idempotency_key,
1674
1718
  metadata: data.metadata,
1675
1719
  pay_currency: data.pay_currency,
1676
1720
  fx_quote_id: data.fx_quote_id,
@@ -1,4 +1,4 @@
1
- import { safe, generateIdempotencyKey, err, ok, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-VUSHG3HA.mjs';
1
+ import { safe, generateIdempotencyKey, err, ok, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-ZFI2TKTO.mjs';
2
2
  import { CimplifyError, ErrorCode, IdempotencyMismatchError, enrichError } from './chunk-K5EN2W2Q.mjs';
3
3
 
4
4
  // src/store-credit.ts
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkFECGCIVV_js = require('./chunk-FECGCIVV.js');
4
- var chunkW5PH7SPK_js = require('./chunk-W5PH7SPK.js');
4
+ var chunkR7FAU2ZF_js = require('./chunk-R7FAU2ZF.js');
5
5
  var zod = require('zod');
6
6
 
7
7
  var cimplifyRegistry = zod.z.registry();
@@ -619,7 +619,7 @@ function createTestClient(options = {}) {
619
619
  if (echoed) sessionToken = echoed;
620
620
  return res;
621
621
  };
622
- const client = chunkW5PH7SPK_js.createCimplifyClient({
622
+ const client = chunkR7FAU2ZF_js.createCimplifyClient({
623
623
  baseUrl: TEST_BASE_URL,
624
624
  // Link mock lives at /v1/link on the same Hono app, so point the SDK's
625
625
  // separate Link transport at the same TEST_BASE_URL.
@@ -1,5 +1,5 @@
1
1
  import { createMockApp } from './chunk-7TEMLVDT.mjs';
2
- import { createCimplifyClient } from './chunk-XMDLF5Y6.mjs';
2
+ import { createCimplifyClient } from './chunk-DOEGVGTM.mjs';
3
3
  import { z } from 'zod';
4
4
 
5
5
  var cimplifyRegistry = z.registry();
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkVEOAMBEX_js = require('./chunk-VEOAMBEX.js');
3
+ var chunk4S5EMSF5_js = require('./chunk-4S5EMSF5.js');
4
4
  var chunkAETVRBKI_js = require('./chunk-AETVRBKI.js');
5
5
 
6
6
  // src/store-credit.ts
@@ -13,7 +13,7 @@ var StoreCreditQueries = class {
13
13
  * currency. Requires a signed-in customer; returns an error otherwise.
14
14
  */
15
15
  async balance() {
16
- return chunkVEOAMBEX_js.safe(this.client.get("/api/v1/store-credit/balance"));
16
+ return chunk4S5EMSF5_js.safe(this.client.get("/api/v1/store-credit/balance"));
17
17
  }
18
18
  };
19
19
 
@@ -105,7 +105,7 @@ var ActivityService = class {
105
105
  this.sendEvents([event]);
106
106
  }
107
107
  async getState() {
108
- return chunkVEOAMBEX_js.safe(this.client.get("/api/v1/activity/state"));
108
+ return chunk4S5EMSF5_js.safe(this.client.get("/api/v1/activity/state"));
109
109
  }
110
110
  async getRecommendations(options) {
111
111
  const params = new URLSearchParams();
@@ -113,10 +113,10 @@ var ActivityService = class {
113
113
  if (options?.limit) params.set("limit", String(options.limit));
114
114
  const query = params.toString();
115
115
  const path = query ? `/api/v1/activity/recommendations?${query}` : "/api/v1/activity/recommendations";
116
- return chunkVEOAMBEX_js.safe(this.client.get(path));
116
+ return chunk4S5EMSF5_js.safe(this.client.get(path));
117
117
  }
118
118
  async dismissMessage(code) {
119
- return chunkVEOAMBEX_js.safe(
119
+ return chunk4S5EMSF5_js.safe(
120
120
  this.client.post("/api/v1/activity/messages/dismiss", { code })
121
121
  );
122
122
  }
@@ -189,16 +189,16 @@ var SubscriptionService = class {
189
189
  this.client = client;
190
190
  }
191
191
  async list() {
192
- return chunkVEOAMBEX_js.safe(this.client.get("/api/v1/subscriptions"));
192
+ return chunk4S5EMSF5_js.safe(this.client.get("/api/v1/subscriptions"));
193
193
  }
194
194
  async get(id) {
195
195
  const encodedId = encodeURIComponent(id);
196
- return chunkVEOAMBEX_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
196
+ return chunk4S5EMSF5_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
197
197
  }
198
198
  async cancel(id, reason, opts) {
199
199
  const encodedId = encodeURIComponent(id);
200
- const idempotencyKey = opts?.idempotencyKey ?? chunkVEOAMBEX_js.generateIdempotencyKey();
201
- return chunkVEOAMBEX_js.safe(
200
+ const idempotencyKey = opts?.idempotencyKey ?? chunk4S5EMSF5_js.generateIdempotencyKey();
201
+ return chunk4S5EMSF5_js.safe(
202
202
  this.client.post(
203
203
  `/api/v1/subscriptions/${encodedId}/cancel`,
204
204
  { reason },
@@ -208,20 +208,20 @@ var SubscriptionService = class {
208
208
  }
209
209
  async pause(id) {
210
210
  const encodedId = encodeURIComponent(id);
211
- return chunkVEOAMBEX_js.safe(
211
+ return chunk4S5EMSF5_js.safe(
212
212
  this.client.post(`/api/v1/subscriptions/${encodedId}/pause`)
213
213
  );
214
214
  }
215
215
  async resume(id) {
216
216
  const encodedId = encodeURIComponent(id);
217
- return chunkVEOAMBEX_js.safe(
217
+ return chunk4S5EMSF5_js.safe(
218
218
  this.client.post(`/api/v1/subscriptions/${encodedId}/resume`)
219
219
  );
220
220
  }
221
221
  async skipNextRenewal(id, opts) {
222
222
  const encodedId = encodeURIComponent(id);
223
- const idempotencyKey = opts?.idempotencyKey ?? chunkVEOAMBEX_js.generateIdempotencyKey();
224
- return chunkVEOAMBEX_js.safe(
223
+ const idempotencyKey = opts?.idempotencyKey ?? chunk4S5EMSF5_js.generateIdempotencyKey();
224
+ return chunk4S5EMSF5_js.safe(
225
225
  this.client.post(
226
226
  `/api/v1/subscriptions/${encodedId}/skip`,
227
227
  void 0,
@@ -237,8 +237,8 @@ var UploadService = class {
237
237
  this.client = client;
238
238
  }
239
239
  async init(filename, contentType, sizeBytes, opts) {
240
- const idempotencyKey = opts?.idempotencyKey ?? chunkVEOAMBEX_js.generateIdempotencyKey();
241
- return chunkVEOAMBEX_js.safe(
240
+ const idempotencyKey = opts?.idempotencyKey ?? chunk4S5EMSF5_js.generateIdempotencyKey();
241
+ return chunk4S5EMSF5_js.safe(
242
242
  this.client.post(
243
243
  "/api/v1/uploads/init",
244
244
  {
@@ -251,7 +251,7 @@ var UploadService = class {
251
251
  );
252
252
  }
253
253
  async confirm(uploadId) {
254
- return chunkVEOAMBEX_js.safe(
254
+ return chunk4S5EMSF5_js.safe(
255
255
  this.client.post("/api/v1/uploads/confirm", {
256
256
  upload_id: uploadId
257
257
  })
@@ -297,7 +297,7 @@ var PlacesService = class {
297
297
  this.client = client;
298
298
  }
299
299
  async autocomplete(input, sessionToken) {
300
- return chunkVEOAMBEX_js.safe(
300
+ return chunk4S5EMSF5_js.safe(
301
301
  this.client.post("/api/v1/places/autocomplete", {
302
302
  input,
303
303
  sessionToken
@@ -305,7 +305,7 @@ var PlacesService = class {
305
305
  );
306
306
  }
307
307
  async details(placeId, sessionToken) {
308
- return chunkVEOAMBEX_js.safe(
308
+ return chunk4S5EMSF5_js.safe(
309
309
  this.client.post("/api/v1/places/details", {
310
310
  place_id: placeId,
311
311
  sessionToken
@@ -324,7 +324,7 @@ var DeliveryService = class {
324
324
  params.set("dropoff_lat", String(dropoffLat));
325
325
  params.set("dropoff_lng", String(dropoffLng));
326
326
  if (country) params.set("country", country);
327
- return chunkVEOAMBEX_js.safe(
327
+ return chunk4S5EMSF5_js.safe(
328
328
  this.client.get(`/api/v1/delivery/fee?${params.toString()}`)
329
329
  );
330
330
  }
@@ -336,7 +336,7 @@ var DeliveryService = class {
336
336
  params.set("dropoff_lng", String(dropoffLng));
337
337
  if (opts?.country) params.set("country", opts.country);
338
338
  if (opts?.orderValue != null) params.set("order_value", String(opts.orderValue));
339
- return chunkVEOAMBEX_js.safe(
339
+ return chunk4S5EMSF5_js.safe(
340
340
  this.client.get(`/api/v1/delivery/options?${params.toString()}`)
341
341
  );
342
342
  }
@@ -413,7 +413,7 @@ var SupportService = class {
413
413
  async claimConversation() {
414
414
  const accessToken = this.client.getAccessToken();
415
415
  if (!accessToken) {
416
- return chunkVEOAMBEX_js.err(new chunkAETVRBKI_js.CimplifyError("not_authenticated", "No access token to claim with"));
416
+ return chunk4S5EMSF5_js.err(new chunkAETVRBKI_js.CimplifyError("not_authenticated", "No access token to claim with"));
417
417
  }
418
418
  if (this.claimInFlight) {
419
419
  if (this.claimInFlightToken === accessToken) return this.claimInFlight;
@@ -421,12 +421,12 @@ var SupportService = class {
421
421
  return this.claimConversation();
422
422
  }
423
423
  if (this.lastClaimedAccessToken === accessToken) {
424
- return chunkVEOAMBEX_js.err(new chunkAETVRBKI_js.CimplifyError("already_claimed", "Session already claimed for this token"));
424
+ return chunk4S5EMSF5_js.err(new chunkAETVRBKI_js.CimplifyError("already_claimed", "Session already claimed for this token"));
425
425
  }
426
426
  const epoch = this.client.getSessionEpoch();
427
427
  this.claimInFlightToken = accessToken;
428
428
  this.claimInFlight = (async () => {
429
- const result = await chunkVEOAMBEX_js.safe(
429
+ const result = await chunk4S5EMSF5_js.safe(
430
430
  this.client.post(
431
431
  "/api/v1/support/conversation/claim",
432
432
  { access_token: accessToken },
@@ -435,7 +435,7 @@ var SupportService = class {
435
435
  );
436
436
  if (result.ok) {
437
437
  if (this.client.getSessionEpoch() !== epoch) {
438
- return chunkVEOAMBEX_js.err(
438
+ return chunk4S5EMSF5_js.err(
439
439
  new chunkAETVRBKI_js.CimplifyError("session_cleared", "Session was cleared during the claim")
440
440
  );
441
441
  }
@@ -464,20 +464,20 @@ var SupportService = class {
464
464
  * the inbox with empty threads.
465
465
  */
466
466
  async peekConversation() {
467
- const result = await chunkVEOAMBEX_js.safe(
467
+ const result = await chunk4S5EMSF5_js.safe(
468
468
  this.client.get("/api/v1/support/conversation")
469
469
  );
470
470
  if (!result.ok) return result;
471
- if (!result.value.conversation) return chunkVEOAMBEX_js.ok(null);
472
- return chunkVEOAMBEX_js.ok({
471
+ if (!result.value.conversation) return chunk4S5EMSF5_js.ok(null);
472
+ return chunk4S5EMSF5_js.ok({
473
473
  conversation: result.value.conversation,
474
474
  messages: result.value.messages
475
475
  });
476
476
  }
477
477
  /** Open (or resume) the customer's widget conversation. */
478
478
  async openConversation(opts) {
479
- const idempotencyKey = opts?.idempotencyKey ?? chunkVEOAMBEX_js.generateIdempotencyKey();
480
- return chunkVEOAMBEX_js.safe(
479
+ const idempotencyKey = opts?.idempotencyKey ?? chunk4S5EMSF5_js.generateIdempotencyKey();
480
+ return chunk4S5EMSF5_js.safe(
481
481
  this.client.post("/api/v1/support/conversation", void 0, {
482
482
  idempotencyKey
483
483
  })
@@ -492,8 +492,8 @@ var SupportService = class {
492
492
  * server resolves it thread-scoped and echoes the quote as `reply_to`.
493
493
  */
494
494
  async sendMessage(content, opts) {
495
- const idempotencyKey = opts?.idempotencyKey ?? chunkVEOAMBEX_js.generateIdempotencyKey();
496
- return chunkVEOAMBEX_js.safe(
495
+ const idempotencyKey = opts?.idempotencyKey ?? chunk4S5EMSF5_js.generateIdempotencyKey();
496
+ return chunk4S5EMSF5_js.safe(
497
497
  this.client.post(
498
498
  "/api/v1/support/conversation/messages",
499
499
  {
@@ -517,11 +517,11 @@ var SupportService = class {
517
517
  if (options.limit) params.set("limit", String(options.limit));
518
518
  const query = params.toString();
519
519
  const path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages";
520
- return chunkVEOAMBEX_js.safe(this.client.get(path));
520
+ return chunk4S5EMSF5_js.safe(this.client.get(path));
521
521
  }
522
522
  /** React to a message in the active conversation by its `ChatMessage.id`. */
523
523
  async reactToMessage(messageId, emoji) {
524
- return chunkVEOAMBEX_js.safe(
524
+ return chunk4S5EMSF5_js.safe(
525
525
  this.client.post(
526
526
  `/api/v1/support/conversation/messages/${messageId}/reactions`,
527
527
  { emoji }
@@ -530,8 +530,8 @@ var SupportService = class {
530
530
  }
531
531
  /** Ask for a person: flags the thread for the merchant's inbox. */
532
532
  async requestHuman(opts) {
533
- const idempotencyKey = opts?.idempotencyKey ?? chunkVEOAMBEX_js.generateIdempotencyKey();
534
- return chunkVEOAMBEX_js.safe(
533
+ const idempotencyKey = opts?.idempotencyKey ?? chunk4S5EMSF5_js.generateIdempotencyKey();
534
+ return chunk4S5EMSF5_js.safe(
535
535
  this.client.post(
536
536
  "/api/v1/support/conversation/handoff",
537
537
  void 0,
@@ -1250,25 +1250,25 @@ var CimplifyClient = class {
1250
1250
  }
1251
1251
  get catalogue() {
1252
1252
  if (!this._catalogue) {
1253
- this._catalogue = new chunkVEOAMBEX_js.CatalogueQueries(this);
1253
+ this._catalogue = new chunk4S5EMSF5_js.CatalogueQueries(this);
1254
1254
  }
1255
1255
  return this._catalogue;
1256
1256
  }
1257
1257
  get cart() {
1258
1258
  if (!this._cart) {
1259
- this._cart = new chunkVEOAMBEX_js.CartOperations(this);
1259
+ this._cart = new chunk4S5EMSF5_js.CartOperations(this);
1260
1260
  }
1261
1261
  return this._cart;
1262
1262
  }
1263
1263
  get checkout() {
1264
1264
  if (!this._checkout) {
1265
- this._checkout = new chunkVEOAMBEX_js.CheckoutService(this);
1265
+ this._checkout = new chunk4S5EMSF5_js.CheckoutService(this);
1266
1266
  }
1267
1267
  return this._checkout;
1268
1268
  }
1269
1269
  get orders() {
1270
1270
  if (!this._orders) {
1271
- this._orders = new chunkVEOAMBEX_js.OrderQueries(this);
1271
+ this._orders = new chunk4S5EMSF5_js.OrderQueries(this);
1272
1272
  }
1273
1273
  return this._orders;
1274
1274
  }
@@ -1298,43 +1298,43 @@ var CimplifyClient = class {
1298
1298
  }
1299
1299
  get link() {
1300
1300
  if (!this._link) {
1301
- this._link = new chunkVEOAMBEX_js.LinkService(this);
1301
+ this._link = new chunk4S5EMSF5_js.LinkService(this);
1302
1302
  }
1303
1303
  return this._link;
1304
1304
  }
1305
1305
  get auth() {
1306
1306
  if (!this._auth) {
1307
- this._auth = new chunkVEOAMBEX_js.AuthService(this);
1307
+ this._auth = new chunk4S5EMSF5_js.AuthService(this);
1308
1308
  }
1309
1309
  return this._auth;
1310
1310
  }
1311
1311
  get business() {
1312
1312
  if (!this._business) {
1313
- this._business = new chunkVEOAMBEX_js.BusinessService(this);
1313
+ this._business = new chunk4S5EMSF5_js.BusinessService(this);
1314
1314
  }
1315
1315
  return this._business;
1316
1316
  }
1317
1317
  get inventory() {
1318
1318
  if (!this._inventory) {
1319
- this._inventory = new chunkVEOAMBEX_js.InventoryService(this);
1319
+ this._inventory = new chunk4S5EMSF5_js.InventoryService(this);
1320
1320
  }
1321
1321
  return this._inventory;
1322
1322
  }
1323
1323
  get scheduling() {
1324
1324
  if (!this._scheduling) {
1325
- this._scheduling = new chunkVEOAMBEX_js.SchedulingService(this);
1325
+ this._scheduling = new chunk4S5EMSF5_js.SchedulingService(this);
1326
1326
  }
1327
1327
  return this._scheduling;
1328
1328
  }
1329
1329
  get lite() {
1330
1330
  if (!this._lite) {
1331
- this._lite = new chunkVEOAMBEX_js.LiteService(this);
1331
+ this._lite = new chunk4S5EMSF5_js.LiteService(this);
1332
1332
  }
1333
1333
  return this._lite;
1334
1334
  }
1335
1335
  get fx() {
1336
1336
  if (!this._fx) {
1337
- this._fx = new chunkVEOAMBEX_js.FxService(this);
1337
+ this._fx = new chunk4S5EMSF5_js.FxService(this);
1338
1338
  }
1339
1339
  return this._fx;
1340
1340
  }
@@ -1369,7 +1369,7 @@ var CimplifyClient = class {
1369
1369
  if (businessId) {
1370
1370
  this.setBusinessId(businessId);
1371
1371
  }
1372
- return chunkVEOAMBEX_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
1372
+ return chunk4S5EMSF5_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
1373
1373
  }
1374
1374
  };
1375
1375
  function createCimplifyClient(config = {}) {
@@ -1,5 +1,5 @@
1
1
  import { isPaymentStatusRequiresAction, normalizeStatusResponse, isPaymentStatusSuccess, isPaymentStatusFailure } from './chunk-KFLGQGMC.mjs';
2
- import { CimplifyError, currencyCode, ErrorCode, enrichError, getErrorHint } from './chunk-K5EN2W2Q.mjs';
2
+ import { CimplifyError, ErrorCode, currencyCode, enrichError, getErrorHint } from './chunk-K5EN2W2Q.mjs';
3
3
 
4
4
  // src/types/result.ts
5
5
  function ok(value) {
@@ -80,6 +80,37 @@ function generateIdempotencyKey(prefix = "idem") {
80
80
  const random = Math.random().toString(36).substring(2, 15);
81
81
  return `${prefix}_${timestamp}_${random}`;
82
82
  }
83
+ var INTENT_PREFIX = "cimplify-intent:";
84
+ function sessionStorageOrNull() {
85
+ try {
86
+ return typeof window !== "undefined" ? window.sessionStorage : null;
87
+ } catch {
88
+ return null;
89
+ }
90
+ }
91
+ function intentIdempotencyKey(scope, fingerprint, storage = sessionStorageOrNull()) {
92
+ const slot = INTENT_PREFIX + scope;
93
+ try {
94
+ const raw = storage?.getItem(slot);
95
+ if (raw) {
96
+ const stored = JSON.parse(raw);
97
+ if (stored.fingerprint === fingerprint && typeof stored.key === "string") return stored.key;
98
+ }
99
+ } catch {
100
+ }
101
+ const key = generateIdempotencyKey();
102
+ try {
103
+ storage?.setItem(slot, JSON.stringify({ key, fingerprint }));
104
+ } catch {
105
+ }
106
+ return key;
107
+ }
108
+ function clearIntentIdempotencyKey(scope, storage = sessionStorageOrNull()) {
109
+ try {
110
+ storage?.removeItem(INTENT_PREFIX + scope);
111
+ } catch {
112
+ }
113
+ }
83
114
 
84
115
  // src/internal/safe.ts
85
116
  function toCimplifyError(error) {
@@ -1588,13 +1619,26 @@ var CheckoutService = class {
1588
1619
  if (invalid) {
1589
1620
  return err(invalid);
1590
1621
  }
1622
+ const intentScope = `checkout:${data.cart_id}`;
1623
+ const intentFingerprint = JSON.stringify([
1624
+ data.payment_method,
1625
+ data.mobile_money_details,
1626
+ data.pay_currency,
1627
+ data.voucher_code,
1628
+ data.pay_deposit
1629
+ ]);
1591
1630
  const checkoutData = {
1592
1631
  ...data,
1593
- idempotency_key: data.idempotency_key || generateIdempotencyKey()
1632
+ idempotency_key: data.idempotency_key || intentIdempotencyKey(intentScope, intentFingerprint)
1594
1633
  };
1595
1634
  const result = await safe(this.client.post("/api/v1/checkout", checkoutData));
1596
- if (result.ok && result.value.bill_token) {
1597
- this.client.setOrderToken(result.value.order_id, result.value.bill_token);
1635
+ if (result.ok) {
1636
+ clearIntentIdempotencyKey(intentScope);
1637
+ if (result.value.bill_token) {
1638
+ this.client.setOrderToken(result.value.order_id, result.value.bill_token);
1639
+ }
1640
+ } else if (result.error.code !== ErrorCode.NETWORK_ERROR && result.error.code !== ErrorCode.TIMEOUT) {
1641
+ clearIntentIdempotencyKey(intentScope);
1598
1642
  }
1599
1643
  return result;
1600
1644
  }
@@ -1668,7 +1712,7 @@ var CheckoutService = class {
1668
1712
  special_instructions: data.special_instructions,
1669
1713
  link_address_id: data.link_address_id,
1670
1714
  link_payment_method_id: data.link_payment_method_id,
1671
- idempotency_key: data.idempotency_key || generateIdempotencyKey(),
1715
+ idempotency_key: data.idempotency_key,
1672
1716
  metadata: data.metadata,
1673
1717
  pay_currency: data.pay_currency,
1674
1718
  fx_quote_id: data.fx_quote_id,