@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,2 +1,6 @@
1
- export { A as AuthService, B as BusinessService, j as CartOperations, b as CatalogueQueries, l as CheckoutOperations, l as CheckoutService, a7 as CimplifyElement, a6 as CimplifyElements, ab as ELEMENT_TYPES, aa as EVENT_TYPES, af as ElementEventType, ad as ElementOptions, ae as ElementType, ac as ElementsOptions, F as FetchQuoteInput, s as FxService, G as GetProductsOptions, I as InventoryService, L as LinkService, r as LiteService, a9 as MESSAGE_TYPES, O as OrderQueries, P as PriceQuote, d as QuoteBundleSelectionInput, Q as QuoteCompositeSelectionInput, f as QuoteDynamicBuckets, e as QuoteStatus, g as QuoteUiMessage, R as RefreshQuoteInput, i as RefreshQuoteResult, q as SchedulingService, a8 as createElements, m as generateIdempotencyKey } from './index-m8zGQUda.mjs';
2
- import './payment-DnU_eLuT.mjs';
1
+ export { A as AuthService, B as BusinessService, j as CartOperations, b as CatalogueQueries, l as CheckoutOperations, l as CheckoutService, a6 as CimplifyElement, a5 as CimplifyElements, aa as ELEMENT_TYPES, a9 as EVENT_TYPES, ae as ElementEventType, ac as ElementOptions, ad as ElementType, ab as ElementsOptions, F as FetchQuoteInput, r as FxService, G as GetProductsOptions, I as InventoryService, L as LinkService, q as LiteService, a8 as MESSAGE_TYPES, O as OrderQueries, P as PriceQuote, d as QuoteBundleSelectionInput, Q as QuoteCompositeSelectionInput, f as QuoteDynamicBuckets, e as QuoteStatus, g as QuoteUiMessage, R as RefreshQuoteInput, i as RefreshQuoteResult, p as SchedulingService, a7 as createElements } from './client-CkGlXZRd.mjs';
2
+ import './payment-DA1i5hhk.mjs';
3
+
4
+ declare function generateIdempotencyKey(prefix?: string): string;
5
+
6
+ export { generateIdempotencyKey };
@@ -1,2 +1,6 @@
1
- export { A as AuthService, B as BusinessService, j as CartOperations, b as CatalogueQueries, l as CheckoutOperations, l as CheckoutService, a7 as CimplifyElement, a6 as CimplifyElements, ab as ELEMENT_TYPES, aa as EVENT_TYPES, af as ElementEventType, ad as ElementOptions, ae as ElementType, ac as ElementsOptions, F as FetchQuoteInput, s as FxService, G as GetProductsOptions, I as InventoryService, L as LinkService, r as LiteService, a9 as MESSAGE_TYPES, O as OrderQueries, P as PriceQuote, d as QuoteBundleSelectionInput, Q as QuoteCompositeSelectionInput, f as QuoteDynamicBuckets, e as QuoteStatus, g as QuoteUiMessage, R as RefreshQuoteInput, i as RefreshQuoteResult, q as SchedulingService, a8 as createElements, m as generateIdempotencyKey } from './index-BpyFcJVv.js';
2
- import './payment-DnU_eLuT.js';
1
+ export { A as AuthService, B as BusinessService, j as CartOperations, b as CatalogueQueries, l as CheckoutOperations, l as CheckoutService, a6 as CimplifyElement, a5 as CimplifyElements, aa as ELEMENT_TYPES, a9 as EVENT_TYPES, ae as ElementEventType, ac as ElementOptions, ad as ElementType, ab as ElementsOptions, F as FetchQuoteInput, r as FxService, G as GetProductsOptions, I as InventoryService, L as LinkService, q as LiteService, a8 as MESSAGE_TYPES, O as OrderQueries, P as PriceQuote, d as QuoteBundleSelectionInput, Q as QuoteCompositeSelectionInput, f as QuoteDynamicBuckets, e as QuoteStatus, g as QuoteUiMessage, R as RefreshQuoteInput, i as RefreshQuoteResult, p as SchedulingService, a7 as createElements } from './client-lvLvB1_K.js';
2
+ import './payment-DA1i5hhk.js';
3
+
4
+ declare function generateIdempotencyKey(prefix?: string): string;
5
+
6
+ export { generateIdempotencyKey };
package/dist/advanced.js CHANGED
@@ -1,83 +1,83 @@
1
1
  'use strict';
2
2
 
3
- var chunk2CGA3MUW_js = require('./chunk-2CGA3MUW.js');
4
- require('./chunk-PEDLCL72.js');
3
+ var chunkHKVRUGM6_js = require('./chunk-HKVRUGM6.js');
4
+ require('./chunk-V2O5AO7I.js');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "AuthService", {
9
9
  enumerable: true,
10
- get: function () { return chunk2CGA3MUW_js.AuthService; }
10
+ get: function () { return chunkHKVRUGM6_js.AuthService; }
11
11
  });
12
12
  Object.defineProperty(exports, "BusinessService", {
13
13
  enumerable: true,
14
- get: function () { return chunk2CGA3MUW_js.BusinessService; }
14
+ get: function () { return chunkHKVRUGM6_js.BusinessService; }
15
15
  });
16
16
  Object.defineProperty(exports, "CartOperations", {
17
17
  enumerable: true,
18
- get: function () { return chunk2CGA3MUW_js.CartOperations; }
18
+ get: function () { return chunkHKVRUGM6_js.CartOperations; }
19
19
  });
20
20
  Object.defineProperty(exports, "CatalogueQueries", {
21
21
  enumerable: true,
22
- get: function () { return chunk2CGA3MUW_js.CatalogueQueries; }
22
+ get: function () { return chunkHKVRUGM6_js.CatalogueQueries; }
23
23
  });
24
24
  Object.defineProperty(exports, "CheckoutOperations", {
25
25
  enumerable: true,
26
- get: function () { return chunk2CGA3MUW_js.CheckoutService; }
26
+ get: function () { return chunkHKVRUGM6_js.CheckoutService; }
27
27
  });
28
28
  Object.defineProperty(exports, "CheckoutService", {
29
29
  enumerable: true,
30
- get: function () { return chunk2CGA3MUW_js.CheckoutService; }
30
+ get: function () { return chunkHKVRUGM6_js.CheckoutService; }
31
31
  });
32
32
  Object.defineProperty(exports, "CimplifyElement", {
33
33
  enumerable: true,
34
- get: function () { return chunk2CGA3MUW_js.CimplifyElement; }
34
+ get: function () { return chunkHKVRUGM6_js.CimplifyElement; }
35
35
  });
36
36
  Object.defineProperty(exports, "CimplifyElements", {
37
37
  enumerable: true,
38
- get: function () { return chunk2CGA3MUW_js.CimplifyElements; }
38
+ get: function () { return chunkHKVRUGM6_js.CimplifyElements; }
39
39
  });
40
40
  Object.defineProperty(exports, "ELEMENT_TYPES", {
41
41
  enumerable: true,
42
- get: function () { return chunk2CGA3MUW_js.ELEMENT_TYPES; }
42
+ get: function () { return chunkHKVRUGM6_js.ELEMENT_TYPES; }
43
43
  });
44
44
  Object.defineProperty(exports, "EVENT_TYPES", {
45
45
  enumerable: true,
46
- get: function () { return chunk2CGA3MUW_js.EVENT_TYPES; }
46
+ get: function () { return chunkHKVRUGM6_js.EVENT_TYPES; }
47
47
  });
48
48
  Object.defineProperty(exports, "FxService", {
49
49
  enumerable: true,
50
- get: function () { return chunk2CGA3MUW_js.FxService; }
50
+ get: function () { return chunkHKVRUGM6_js.FxService; }
51
51
  });
52
52
  Object.defineProperty(exports, "InventoryService", {
53
53
  enumerable: true,
54
- get: function () { return chunk2CGA3MUW_js.InventoryService; }
54
+ get: function () { return chunkHKVRUGM6_js.InventoryService; }
55
55
  });
56
56
  Object.defineProperty(exports, "LinkService", {
57
57
  enumerable: true,
58
- get: function () { return chunk2CGA3MUW_js.LinkService; }
58
+ get: function () { return chunkHKVRUGM6_js.LinkService; }
59
59
  });
60
60
  Object.defineProperty(exports, "LiteService", {
61
61
  enumerable: true,
62
- get: function () { return chunk2CGA3MUW_js.LiteService; }
62
+ get: function () { return chunkHKVRUGM6_js.LiteService; }
63
63
  });
64
64
  Object.defineProperty(exports, "MESSAGE_TYPES", {
65
65
  enumerable: true,
66
- get: function () { return chunk2CGA3MUW_js.MESSAGE_TYPES; }
66
+ get: function () { return chunkHKVRUGM6_js.MESSAGE_TYPES; }
67
67
  });
68
68
  Object.defineProperty(exports, "OrderQueries", {
69
69
  enumerable: true,
70
- get: function () { return chunk2CGA3MUW_js.OrderQueries; }
70
+ get: function () { return chunkHKVRUGM6_js.OrderQueries; }
71
71
  });
72
72
  Object.defineProperty(exports, "SchedulingService", {
73
73
  enumerable: true,
74
- get: function () { return chunk2CGA3MUW_js.SchedulingService; }
74
+ get: function () { return chunkHKVRUGM6_js.SchedulingService; }
75
75
  });
76
76
  Object.defineProperty(exports, "createElements", {
77
77
  enumerable: true,
78
- get: function () { return chunk2CGA3MUW_js.createElements; }
78
+ get: function () { return chunkHKVRUGM6_js.createElements; }
79
79
  });
80
80
  Object.defineProperty(exports, "generateIdempotencyKey", {
81
81
  enumerable: true,
82
- get: function () { return chunk2CGA3MUW_js.generateIdempotencyKey; }
82
+ get: function () { return chunkHKVRUGM6_js.generateIdempotencyKey; }
83
83
  });
package/dist/advanced.mjs CHANGED
@@ -1,2 +1,2 @@
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-3J4PPSMI.mjs';
2
- import './chunk-E3HC2YAE.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-TFHKVQLL.mjs';
2
+ import './chunk-6TVQQYQ5.mjs';
@@ -1,5 +1,5 @@
1
- import { safe, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-3J4PPSMI.mjs';
2
- import { CimplifyError, ErrorCode, enrichError } from './chunk-E3HC2YAE.mjs';
1
+ import { safe, generateIdempotencyKey, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-TFHKVQLL.mjs';
2
+ import { CimplifyError, ErrorCode, IdempotencyMismatchError, enrichError } from './chunk-6TVQQYQ5.mjs';
3
3
 
4
4
  // src/activity.ts
5
5
  var ActivityService = class {
@@ -66,12 +66,15 @@ var SubscriptionService = class {
66
66
  const encodedId = encodeURIComponent(id);
67
67
  return safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
68
68
  }
69
- async cancel(id, reason) {
69
+ async cancel(id, reason, opts) {
70
70
  const encodedId = encodeURIComponent(id);
71
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
71
72
  return safe(
72
- this.client.post(`/api/v1/subscriptions/${encodedId}/cancel`, {
73
- reason
74
- })
73
+ this.client.post(
74
+ `/api/v1/subscriptions/${encodedId}/cancel`,
75
+ { reason },
76
+ { idempotencyKey }
77
+ )
75
78
  );
76
79
  }
77
80
  async pause(id) {
@@ -86,10 +89,15 @@ var SubscriptionService = class {
86
89
  this.client.post(`/api/v1/subscriptions/${encodedId}/resume`)
87
90
  );
88
91
  }
89
- async skipNextRenewal(id) {
92
+ async skipNextRenewal(id, opts) {
90
93
  const encodedId = encodeURIComponent(id);
94
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
91
95
  return safe(
92
- this.client.post(`/api/v1/subscriptions/${encodedId}/skip`)
96
+ this.client.post(
97
+ `/api/v1/subscriptions/${encodedId}/skip`,
98
+ void 0,
99
+ { idempotencyKey }
100
+ )
93
101
  );
94
102
  }
95
103
  };
@@ -99,13 +107,18 @@ var UploadService = class {
99
107
  constructor(client) {
100
108
  this.client = client;
101
109
  }
102
- async init(filename, contentType, sizeBytes) {
110
+ async init(filename, contentType, sizeBytes, opts) {
111
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
103
112
  return safe(
104
- this.client.post("/api/v1/uploads/init", {
105
- filename,
106
- content_type: contentType,
107
- size_bytes: sizeBytes
108
- })
113
+ this.client.post(
114
+ "/api/v1/uploads/init",
115
+ {
116
+ filename,
117
+ content_type: contentType,
118
+ size_bytes: sizeBytes
119
+ },
120
+ { idempotencyKey }
121
+ )
109
122
  );
110
123
  }
111
124
  async confirm(uploadId) {
@@ -194,17 +207,23 @@ var SupportService = class {
194
207
  this.client = client;
195
208
  }
196
209
  /** Open (or resume) the customer's widget conversation. */
197
- async openConversation() {
210
+ async openConversation(opts) {
211
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
198
212
  return safe(
199
- this.client.post("/api/v1/support/conversation")
213
+ this.client.post("/api/v1/support/conversation", void 0, {
214
+ idempotencyKey
215
+ })
200
216
  );
201
217
  }
202
218
  /** Send a message in the active conversation. */
203
- async sendMessage(content) {
219
+ async sendMessage(content, opts) {
220
+ const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
204
221
  return safe(
205
- this.client.post("/api/v1/support/conversation/messages", {
206
- content
207
- })
222
+ this.client.post(
223
+ "/api/v1/support/conversation/messages",
224
+ { content },
225
+ { idempotencyKey }
226
+ )
208
227
  );
209
228
  }
210
229
  /** Poll for new messages since the given cursor. */
@@ -218,6 +237,39 @@ var SupportService = class {
218
237
  }
219
238
  };
220
239
 
240
+ // src/internal/events.ts
241
+ function createClientEvents() {
242
+ const listeners = /* @__PURE__ */ new Map();
243
+ return {
244
+ on(name, listener) {
245
+ let set = listeners.get(name);
246
+ if (!set) {
247
+ set = /* @__PURE__ */ new Set();
248
+ listeners.set(name, set);
249
+ }
250
+ set.add(listener);
251
+ return () => {
252
+ set?.delete(listener);
253
+ };
254
+ },
255
+ off(name, listener) {
256
+ listeners.get(name)?.delete(listener);
257
+ },
258
+ emit(name, payload) {
259
+ const set = listeners.get(name);
260
+ if (!set) return;
261
+ const snapshot = Array.from(set);
262
+ for (const listener of snapshot) {
263
+ try {
264
+ listener(payload);
265
+ } catch (err) {
266
+ console.error(`[Cimplify] event listener for "${name}" threw:`, err);
267
+ }
268
+ }
269
+ }
270
+ };
271
+ }
272
+
221
273
  // src/client.ts
222
274
  var ACCESS_TOKEN_STORAGE_KEY = "cimplify_access_token";
223
275
  var SESSION_TOKEN_STORAGE_KEY = "cimplify_session_token";
@@ -230,6 +282,19 @@ var DEFAULT_RETRY_DELAY_MS = 1e3;
230
282
  function sleep(ms) {
231
283
  return new Promise((resolve) => setTimeout(resolve, ms));
232
284
  }
285
+ function mergeOptionHeaders(base, opts) {
286
+ if (!opts) return base;
287
+ const merged = { ...base };
288
+ if (opts.headers) {
289
+ for (const [k, v] of Object.entries(opts.headers)) {
290
+ merged[k] = v;
291
+ }
292
+ }
293
+ if (opts.idempotencyKey) {
294
+ merged["Idempotency-Key"] = opts.idempotencyKey;
295
+ }
296
+ return merged;
297
+ }
233
298
  function isRetryable(error) {
234
299
  if (error instanceof TypeError && error.message.includes("fetch")) {
235
300
  return true;
@@ -310,6 +375,13 @@ var CimplifyClient = class {
310
375
  this.businessId = null;
311
376
  this.businessIdResolvePromise = null;
312
377
  this.inflightRequests = /* @__PURE__ */ new Map();
378
+ /**
379
+ * App-level event channel. Subscribe to surface mutation rollbacks, outbox
380
+ * activity, and dead-letter notifications to consumer code (toasts,
381
+ * Sentry, analytics, etc.). The SDK emits but never auto-consumes — the
382
+ * consumer decides how to react.
383
+ */
384
+ this.events = createClientEvents();
313
385
  this.publicKey = config.publicKey || getEnvPublicKey() || "";
314
386
  const urls = deriveUrls();
315
387
  this.baseUrl = config.baseUrl ? normalizeUrl(config.baseUrl) : urls.baseUrl;
@@ -537,7 +609,7 @@ var CimplifyClient = class {
537
609
  });
538
610
  return response;
539
611
  }
540
- if (response.status === 429 && attempt < this.maxRetries) {
612
+ if ((response.status === 429 || response.status === 503) && attempt < this.maxRetries) {
541
613
  retryCount++;
542
614
  const retryAfter = response.headers.get("Retry-After");
543
615
  const delay = retryAfter ? Math.min(parseInt(retryAfter, 10) * 1e3, 3e4) || this.retryDelay * Math.pow(2, attempt) : this.retryDelay * Math.pow(2, attempt);
@@ -545,7 +617,7 @@ var CimplifyClient = class {
545
617
  ...context,
546
618
  attempt: retryCount,
547
619
  delayMs: delay,
548
- error: new Error(`Rate limited: ${response.status}`)
620
+ error: new Error(`Retryable: ${response.status}`)
549
621
  });
550
622
  await sleep(delay);
551
623
  continue;
@@ -650,29 +722,29 @@ var CimplifyClient = class {
650
722
  return this.handleRestResponse(response);
651
723
  });
652
724
  }
653
- async post(path, body) {
725
+ async post(path, body, opts) {
654
726
  const response = await this.resilientFetch(this.buildUrl(this.baseUrl, path), {
655
727
  method: "POST",
656
728
  credentials: this.credentials,
657
- headers: this.getHeaders(),
729
+ headers: mergeOptionHeaders(this.getHeaders(), opts),
658
730
  body: body ? JSON.stringify(body) : void 0
659
731
  });
660
732
  return this.handleRestResponse(response);
661
733
  }
662
- async patch(path, body) {
734
+ async patch(path, body, opts) {
663
735
  const response = await this.resilientFetch(this.buildUrl(this.baseUrl, path), {
664
736
  method: "PATCH",
665
737
  credentials: this.credentials,
666
- headers: this.getHeaders(),
738
+ headers: mergeOptionHeaders(this.getHeaders(), opts),
667
739
  body: body ? JSON.stringify(body) : void 0
668
740
  });
669
741
  return this.handleRestResponse(response);
670
742
  }
671
- async delete(path) {
743
+ async delete(path, opts) {
672
744
  const response = await this.resilientFetch(this.buildUrl(this.baseUrl, path), {
673
745
  method: "DELETE",
674
746
  credentials: this.credentials,
675
- headers: this.getHeaders()
747
+ headers: mergeOptionHeaders(this.getHeaders(), opts)
676
748
  });
677
749
  return this.handleRestResponse(response);
678
750
  }
@@ -687,20 +759,20 @@ var CimplifyClient = class {
687
759
  return this.handleRestResponse(response);
688
760
  });
689
761
  }
690
- async linkPost(path, body) {
762
+ async linkPost(path, body, opts) {
691
763
  const response = await this.resilientFetch(`${this.linkApiUrl}${path}`, {
692
764
  method: "POST",
693
765
  credentials: this.credentials,
694
- headers: this.getHeaders(),
766
+ headers: mergeOptionHeaders(this.getHeaders(), opts),
695
767
  body: body ? JSON.stringify(body) : void 0
696
768
  });
697
769
  return this.handleRestResponse(response);
698
770
  }
699
- async linkDelete(path) {
771
+ async linkDelete(path, opts) {
700
772
  const response = await this.resilientFetch(`${this.linkApiUrl}${path}`, {
701
773
  method: "DELETE",
702
774
  credentials: this.credentials,
703
- headers: this.getHeaders()
775
+ headers: mergeOptionHeaders(this.getHeaders(), opts)
704
776
  });
705
777
  return this.handleRestResponse(response);
706
778
  }
@@ -710,6 +782,10 @@ var CimplifyClient = class {
710
782
  const errorCode = typeof json.error === "object" && json.error?.error_code || typeof json.error === "object" && json.error?.code || "API_ERROR";
711
783
  const errorMessage = typeof json.error === "object" && json.error?.error_message || typeof json.error === "object" && json.error?.message || typeof json.error === "string" && json.error || typeof json.message === "string" && json.message || "An error occurred";
712
784
  const retryable = typeof json.error === "object" && typeof json.error?.retryable === "boolean" ? json.error.retryable : false;
785
+ if (errorCode === "IDEMPOTENCY_MISMATCH") {
786
+ const originalCreatedAt = typeof json.error === "object" && json.error?.original_created_at || "";
787
+ throw new IdempotencyMismatchError(errorMessage, originalCreatedAt);
788
+ }
713
789
  const error = enrichError(
714
790
  new CimplifyError(
715
791
  errorCode,
@@ -183,13 +183,26 @@ var CimplifyError = class extends Error {
183
183
  return this.message;
184
184
  }
185
185
  };
186
+ var IdempotencyMismatchError = class extends CimplifyError {
187
+ constructor(message, originalCreatedAt) {
188
+ super("IDEMPOTENCY_MISMATCH", message, false);
189
+ this.originalCreatedAt = originalCreatedAt;
190
+ this.name = "IdempotencyMismatchError";
191
+ }
192
+ };
186
193
  function isCimplifyError(error) {
187
194
  return error instanceof CimplifyError;
188
195
  }
196
+ function isIdempotencyMismatchError(error) {
197
+ return error instanceof IdempotencyMismatchError;
198
+ }
189
199
  function getErrorHint(code) {
190
200
  return ERROR_HINTS[code];
191
201
  }
192
202
  function enrichError(error, options = {}) {
203
+ if (error instanceof IdempotencyMismatchError) {
204
+ return error;
205
+ }
193
206
  const hint = getErrorHint(error.code);
194
207
  const docsUrl = error.docs_url || hint?.docs_url || docsUrlForCode(error.code || ErrorCode.UNKNOWN_ERROR);
195
208
  const suggestion = error.suggestion || hint?.suggestion;
@@ -695,4 +708,4 @@ function detectMobileMoneyProvider(phoneNumber) {
695
708
  return null;
696
709
  }
697
710
 
698
- export { CURRENCY_SYMBOLS, CimplifyError, ERROR_HINTS, ErrorCode, MOBILE_MONEY_PROVIDERS, ZERO, categorizePaymentError, currencyCode, detectMobileMoneyProvider, enrichError, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatPriceRange, formatPriceWithTax, formatProductPrice, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getErrorHint, getMarkupPercentage, getPriceRange, getProductCurrency, getTaxAmount, getUnitPriceAtQuantity, hasTaxInfo, isCimplifyError, isOnSale, isPaymentStatusFailure, isPaymentStatusRequiresAction, isPaymentStatusSuccess, isRetryableError, isSupportedCurrency, isTaxInclusive, money, moneyFromNumber, normalizePaymentResponse, normalizeStatusResponse, parsePrice };
711
+ export { CURRENCY_SYMBOLS, CimplifyError, ERROR_HINTS, ErrorCode, IdempotencyMismatchError, MOBILE_MONEY_PROVIDERS, ZERO, categorizePaymentError, currencyCode, detectMobileMoneyProvider, enrichError, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatPriceRange, formatPriceWithTax, formatProductPrice, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getErrorHint, getMarkupPercentage, getPriceRange, getProductCurrency, getTaxAmount, getUnitPriceAtQuantity, hasTaxInfo, isCimplifyError, isIdempotencyMismatchError, isOnSale, isPaymentStatusFailure, isPaymentStatusRequiresAction, isPaymentStatusSuccess, isRetryableError, isSupportedCurrency, isTaxInclusive, money, moneyFromNumber, normalizePaymentResponse, normalizeStatusResponse, parsePrice };