@drawbridge/drawbridge-stripe 0.1.13 → 0.1.15

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 (3) hide show
  1. package/dist/index.js +140 -86
  2. package/dist/index.mjs +140 -86
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -18,28 +18,46 @@ var require_billing = __commonJS({
18
18
  "Stripe-Version": "2026-01-28.preview"
19
19
  }
20
20
  };
21
+ const withIdem = (base, suffix) => {
22
+ if (!base) return options;
23
+ return {
24
+ ...options,
25
+ headers: {
26
+ ...options.headers,
27
+ "Idempotency-Key": base + ":" + suffix
28
+ }
29
+ };
30
+ };
31
+ const idem = (base, suffix) => {
32
+ if (!base) return void 0;
33
+ return {
34
+ idempotencyKey: base + ":" + suffix
35
+ };
36
+ };
21
37
  const billableItems = async () => {
22
- var _a, _b, _c, _d, _e, _f;
38
+ var _a;
23
39
  try {
24
- const items = [];
25
40
  const { data: components } = await axios.get(
26
41
  billing + "/pricing_plans/" + process.env.STRIPE_PRICING_AI_PLAN_ID + "/components",
27
42
  options
28
43
  );
29
- for (let index = 0; index < ((_a = components == null ? void 0 : components.data) == null ? void 0 : _a.length); index++) {
30
- const plan = (_b = components == null ? void 0 : components.data) == null ? void 0 : _b[index];
31
- if ((_c = plan == null ? void 0 : plan.rate_card) == null ? void 0 : _c.id) {
32
- const { data: rates } = await axios.get(
33
- billing + "/rate_cards/" + ((_d = plan.rate_card) == null ? void 0 : _d.id) + "/rates",
34
- options
35
- );
36
- for (let i = 0; i < (rates == null ? void 0 : rates.data.length); i++) {
37
- const element = (_e = rates == null ? void 0 : rates.data) == null ? void 0 : _e[i];
38
- if ((_f = element == null ? void 0 : element.metered_item) == null ? void 0 : _f.id) {
39
- items.push({
40
- id: element.metered_item.id
41
- });
42
- }
44
+ const rateCardIds = ((components == null ? void 0 : components.data) || []).map((plan) => {
45
+ var _a2;
46
+ return (_a2 = plan == null ? void 0 : plan.rate_card) == null ? void 0 : _a2.id;
47
+ }).filter(Boolean);
48
+ const rateResults = await Promise.all(
49
+ rateCardIds.map((id) => axios.get(
50
+ billing + "/rate_cards/" + id + "/rates",
51
+ options
52
+ ))
53
+ );
54
+ const items = [];
55
+ for (const { data: rates } of rateResults) {
56
+ for (const element of (rates == null ? void 0 : rates.data) || []) {
57
+ if ((_a = element == null ? void 0 : element.metered_item) == null ? void 0 : _a.id) {
58
+ items.push({
59
+ id: element.metered_item.id
60
+ });
43
61
  }
44
62
  ;
45
63
  }
@@ -55,6 +73,7 @@ var require_billing = __commonJS({
55
73
  currency,
56
74
  customer,
57
75
  default_payment_method = null,
76
+ idempotencyKey,
58
77
  metadata = {}
59
78
  }) => {
60
79
  var _a, _b, _c, _d;
@@ -94,17 +113,17 @@ var require_billing = __commonJS({
94
113
  }
95
114
  ]
96
115
  },
97
- options
116
+ withIdem(idempotencyKey, "intent.create")
98
117
  );
99
118
  const { data: reserve } = await axios.post(
100
119
  billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/reserve",
101
120
  {},
102
- options
121
+ withIdem(idempotencyKey, "intent.reserve")
103
122
  );
104
123
  const { data: commit } = await axios.post(
105
124
  billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/commit",
106
125
  {},
107
- options
126
+ withIdem(idempotencyKey, "intent.commit")
108
127
  );
109
128
  const { data: actions } = await axios.get(
110
129
  billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/actions",
@@ -124,36 +143,42 @@ var require_billing = __commonJS({
124
143
  type: "customer"
125
144
  }
126
145
  ];
127
- const replenish = await stripe2.billing.alerts.create({
128
- alert_type: "credit_balance_threshold",
129
- credit_balance_threshold: {
130
- filters,
131
- lte: {
132
- balance_type: "monetary",
133
- monetary: {
134
- currency,
135
- value: 200
136
- // cents
146
+ const replenish = await stripe2.billing.alerts.create(
147
+ {
148
+ alert_type: "credit_balance_threshold",
149
+ credit_balance_threshold: {
150
+ filters,
151
+ lte: {
152
+ balance_type: "monetary",
153
+ monetary: {
154
+ currency,
155
+ value: 200
156
+ // cents
157
+ }
137
158
  }
138
- }
159
+ },
160
+ title: customer + ".credit_balance_replenish"
139
161
  },
140
- title: customer + ".credit_balance_replenish"
141
- });
142
- const depleted = await stripe2.billing.alerts.create({
143
- alert_type: "credit_balance_threshold",
144
- credit_balance_threshold: {
145
- filters,
146
- lte: {
147
- balance_type: "monetary",
148
- monetary: {
149
- currency,
150
- value: 1
151
- // cents
162
+ idem(idempotencyKey, "alert.replenish")
163
+ );
164
+ const depleted = await stripe2.billing.alerts.create(
165
+ {
166
+ alert_type: "credit_balance_threshold",
167
+ credit_balance_threshold: {
168
+ filters,
169
+ lte: {
170
+ balance_type: "monetary",
171
+ monetary: {
172
+ currency,
173
+ value: 1
174
+ // cents
175
+ }
152
176
  }
153
- }
177
+ },
178
+ title: customer + ".credit_balance_depleted"
154
179
  },
155
- title: customer + ".credit_balance_depleted"
156
- });
180
+ idem(idempotencyKey, "alert.depleted")
181
+ );
157
182
  const stripePricingPlanSubscriptionId = (_d = (_c = (_b = (_a = actions == null ? void 0 : actions.data) == null ? void 0 : _a[0]) == null ? void 0 : _b.subscribe) == null ? void 0 : _c.pricing_plan_subscription_details) == null ? void 0 : _d.pricing_plan_subscription;
158
183
  if (!stripePricingPlanSubscriptionId) {
159
184
  throw new Error("Stripe billing intent did not return a pricing plan subscription ID for customer: " + customer);
@@ -193,7 +218,8 @@ var require_billing = __commonJS({
193
218
  };
194
219
  const unsubscribe = async ({
195
220
  currency,
196
- id
221
+ id,
222
+ idempotencyKey
197
223
  }) => {
198
224
  try {
199
225
  const { data } = await axios.post(
@@ -212,17 +238,17 @@ var require_billing = __commonJS({
212
238
  }
213
239
  ]
214
240
  },
215
- options
241
+ withIdem(idempotencyKey, "intent.create")
216
242
  );
217
243
  await axios.post(
218
244
  billing + "/intents/" + (data == null ? void 0 : data.id) + "/reserve",
219
245
  {},
220
- options
246
+ withIdem(idempotencyKey, "intent.reserve")
221
247
  );
222
248
  const commit = await axios.post(
223
249
  billing + "/intents/" + (data == null ? void 0 : data.id) + "/commit",
224
250
  {},
225
- options
251
+ withIdem(idempotencyKey, "intent.commit")
226
252
  );
227
253
  return commit;
228
254
  } catch (error) {
@@ -238,28 +264,30 @@ var require_billing = __commonJS({
238
264
  const model = [rest == null ? void 0 : rest.provider, rest == null ? void 0 : rest.model].join("/");
239
265
  const input = Number(metadata == null ? void 0 : metadata.promptTokenCount);
240
266
  const output = parseInt(Number(metadata == null ? void 0 : metadata.totalTokenCount) - input);
241
- if (input) {
267
+ const sendMeterEvent = (token_type, value) => {
242
268
  stripe2.billing.meterEvents.create({
243
269
  event_name,
244
270
  payload: {
245
271
  model,
246
272
  stripe_customer_id: customer,
247
- token_type: "input",
248
- value: input
273
+ token_type,
274
+ value
249
275
  }
276
+ }).catch((error) => {
277
+ console.error("[billing.usage] meterEvents.create failed", {
278
+ customer,
279
+ token_type,
280
+ value,
281
+ error: error == null ? void 0 : error.message
282
+ });
250
283
  });
284
+ };
285
+ if (input) {
286
+ sendMeterEvent("input", input);
251
287
  }
252
288
  ;
253
289
  if (output) {
254
- stripe2.billing.meterEvents.create({
255
- event_name,
256
- payload: {
257
- model,
258
- stripe_customer_id: customer,
259
- token_type: "output",
260
- value: output
261
- }
262
- });
290
+ sendMeterEvent("output", output);
263
291
  }
264
292
  ;
265
293
  };
@@ -562,6 +590,7 @@ var require_subscription = __commonJS({
562
590
  billingCycleAnchor,
563
591
  customer,
564
592
  discounts = [],
593
+ idempotencyKey,
565
594
  metadata,
566
595
  stripePaymentMethodId,
567
596
  to
@@ -570,6 +599,7 @@ var require_subscription = __commonJS({
570
599
  try {
571
600
  const actions = await createItem({
572
601
  currency: to.currency,
602
+ idempotencyKey,
573
603
  interval: to.interval,
574
604
  limit: to.limits.organization.actions,
575
605
  metadata,
@@ -577,31 +607,37 @@ var require_subscription = __commonJS({
577
607
  overage: to.overages.actions,
578
608
  proration_behavior: "none"
579
609
  });
580
- const subscription = await stripe2.subscriptions.create({
581
- automatic_tax: {
582
- enabled: true
583
- },
584
- customer,
585
- description: "Organization subscription: " + metadata.organization,
586
- default_payment_method: stripePaymentMethodId,
587
- discounts: (discounts == null ? void 0 : discounts.length) > 0 ? discounts : "",
588
- items: [
589
- {
590
- price: actions.price
610
+ const subscription = await stripe2.subscriptions.create(
611
+ {
612
+ automatic_tax: {
613
+ enabled: true
614
+ },
615
+ customer,
616
+ description: "Organization subscription: " + metadata.organization,
617
+ default_payment_method: stripePaymentMethodId,
618
+ discounts: (discounts == null ? void 0 : discounts.length) > 0 ? discounts : "",
619
+ items: [
620
+ {
621
+ price: actions.price
622
+ }
623
+ ],
624
+ metadata,
625
+ ...billingCycleAnchor && {
626
+ billing_cycle_anchor: billingCycleAnchor
591
627
  }
592
- ],
593
- metadata,
594
- ...billingCycleAnchor && {
595
- billing_cycle_anchor: billingCycleAnchor
596
- }
597
- });
628
+ },
629
+ idem(idempotencyKey, "subscription.create")
630
+ );
598
631
  const { product } = await stripe2.prices.retrieve(to == null ? void 0 : to.stripePriceId);
599
- const plan = await stripe2.subscriptionItems.create({
600
- subscription: subscription == null ? void 0 : subscription.id,
601
- price: to == null ? void 0 : to.stripePriceId,
602
- quantity: 1,
603
- proration_behavior: "always_invoice"
604
- });
632
+ const plan = await stripe2.subscriptionItems.create(
633
+ {
634
+ subscription: subscription == null ? void 0 : subscription.id,
635
+ price: to == null ? void 0 : to.stripePriceId,
636
+ quantity: 1,
637
+ proration_behavior: "always_invoice"
638
+ },
639
+ idem(idempotencyKey, "plan.create")
640
+ );
605
641
  return {
606
642
  discounts,
607
643
  items: {
@@ -623,6 +659,7 @@ var require_subscription = __commonJS({
623
659
  }
624
660
  },
625
661
  pause: async ({
662
+ idempotencyKey,
626
663
  stripeSubscriptionId
627
664
  }) => {
628
665
  try {
@@ -634,7 +671,15 @@ var require_subscription = __commonJS({
634
671
  const { data } = await axios.post(
635
672
  subscriptions + "/" + stripeSubscriptionId + "/pause",
636
673
  body,
637
- options
674
+ {
675
+ ...options,
676
+ ...idempotencyKey && {
677
+ headers: {
678
+ ...options.headers,
679
+ "Idempotency-Key": idempotencyKey
680
+ }
681
+ }
682
+ }
638
683
  );
639
684
  return data;
640
685
  } catch (error) {
@@ -642,6 +687,7 @@ var require_subscription = __commonJS({
642
687
  }
643
688
  },
644
689
  resume: async ({
690
+ idempotencyKey,
645
691
  stripeSubscriptionId
646
692
  }) => {
647
693
  try {
@@ -651,7 +697,15 @@ var require_subscription = __commonJS({
651
697
  const { data } = await axios.post(
652
698
  subscriptions + "/" + stripeSubscriptionId + "/resume",
653
699
  body,
654
- options
700
+ {
701
+ ...options,
702
+ ...idempotencyKey && {
703
+ headers: {
704
+ ...options.headers,
705
+ "Idempotency-Key": idempotencyKey
706
+ }
707
+ }
708
+ }
655
709
  );
656
710
  return data;
657
711
  } catch (error) {
package/dist/index.mjs CHANGED
@@ -24,28 +24,46 @@ var require_billing = __commonJS({
24
24
  "Stripe-Version": "2026-01-28.preview"
25
25
  }
26
26
  };
27
+ const withIdem = (base, suffix) => {
28
+ if (!base) return options;
29
+ return {
30
+ ...options,
31
+ headers: {
32
+ ...options.headers,
33
+ "Idempotency-Key": base + ":" + suffix
34
+ }
35
+ };
36
+ };
37
+ const idem = (base, suffix) => {
38
+ if (!base) return void 0;
39
+ return {
40
+ idempotencyKey: base + ":" + suffix
41
+ };
42
+ };
27
43
  const billableItems = async () => {
28
- var _a, _b, _c, _d, _e, _f;
44
+ var _a;
29
45
  try {
30
- const items = [];
31
46
  const { data: components } = await axios.get(
32
47
  billing + "/pricing_plans/" + process.env.STRIPE_PRICING_AI_PLAN_ID + "/components",
33
48
  options
34
49
  );
35
- for (let index = 0; index < ((_a = components == null ? void 0 : components.data) == null ? void 0 : _a.length); index++) {
36
- const plan = (_b = components == null ? void 0 : components.data) == null ? void 0 : _b[index];
37
- if ((_c = plan == null ? void 0 : plan.rate_card) == null ? void 0 : _c.id) {
38
- const { data: rates } = await axios.get(
39
- billing + "/rate_cards/" + ((_d = plan.rate_card) == null ? void 0 : _d.id) + "/rates",
40
- options
41
- );
42
- for (let i = 0; i < (rates == null ? void 0 : rates.data.length); i++) {
43
- const element = (_e = rates == null ? void 0 : rates.data) == null ? void 0 : _e[i];
44
- if ((_f = element == null ? void 0 : element.metered_item) == null ? void 0 : _f.id) {
45
- items.push({
46
- id: element.metered_item.id
47
- });
48
- }
50
+ const rateCardIds = ((components == null ? void 0 : components.data) || []).map((plan) => {
51
+ var _a2;
52
+ return (_a2 = plan == null ? void 0 : plan.rate_card) == null ? void 0 : _a2.id;
53
+ }).filter(Boolean);
54
+ const rateResults = await Promise.all(
55
+ rateCardIds.map((id) => axios.get(
56
+ billing + "/rate_cards/" + id + "/rates",
57
+ options
58
+ ))
59
+ );
60
+ const items = [];
61
+ for (const { data: rates } of rateResults) {
62
+ for (const element of (rates == null ? void 0 : rates.data) || []) {
63
+ if ((_a = element == null ? void 0 : element.metered_item) == null ? void 0 : _a.id) {
64
+ items.push({
65
+ id: element.metered_item.id
66
+ });
49
67
  }
50
68
  ;
51
69
  }
@@ -61,6 +79,7 @@ var require_billing = __commonJS({
61
79
  currency,
62
80
  customer,
63
81
  default_payment_method = null,
82
+ idempotencyKey,
64
83
  metadata = {}
65
84
  }) => {
66
85
  var _a, _b, _c, _d;
@@ -100,17 +119,17 @@ var require_billing = __commonJS({
100
119
  }
101
120
  ]
102
121
  },
103
- options
122
+ withIdem(idempotencyKey, "intent.create")
104
123
  );
105
124
  const { data: reserve } = await axios.post(
106
125
  billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/reserve",
107
126
  {},
108
- options
127
+ withIdem(idempotencyKey, "intent.reserve")
109
128
  );
110
129
  const { data: commit } = await axios.post(
111
130
  billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/commit",
112
131
  {},
113
- options
132
+ withIdem(idempotencyKey, "intent.commit")
114
133
  );
115
134
  const { data: actions } = await axios.get(
116
135
  billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/actions",
@@ -130,36 +149,42 @@ var require_billing = __commonJS({
130
149
  type: "customer"
131
150
  }
132
151
  ];
133
- const replenish = await stripe.billing.alerts.create({
134
- alert_type: "credit_balance_threshold",
135
- credit_balance_threshold: {
136
- filters,
137
- lte: {
138
- balance_type: "monetary",
139
- monetary: {
140
- currency,
141
- value: 200
142
- // cents
152
+ const replenish = await stripe.billing.alerts.create(
153
+ {
154
+ alert_type: "credit_balance_threshold",
155
+ credit_balance_threshold: {
156
+ filters,
157
+ lte: {
158
+ balance_type: "monetary",
159
+ monetary: {
160
+ currency,
161
+ value: 200
162
+ // cents
163
+ }
143
164
  }
144
- }
165
+ },
166
+ title: customer + ".credit_balance_replenish"
145
167
  },
146
- title: customer + ".credit_balance_replenish"
147
- });
148
- const depleted = await stripe.billing.alerts.create({
149
- alert_type: "credit_balance_threshold",
150
- credit_balance_threshold: {
151
- filters,
152
- lte: {
153
- balance_type: "monetary",
154
- monetary: {
155
- currency,
156
- value: 1
157
- // cents
168
+ idem(idempotencyKey, "alert.replenish")
169
+ );
170
+ const depleted = await stripe.billing.alerts.create(
171
+ {
172
+ alert_type: "credit_balance_threshold",
173
+ credit_balance_threshold: {
174
+ filters,
175
+ lte: {
176
+ balance_type: "monetary",
177
+ monetary: {
178
+ currency,
179
+ value: 1
180
+ // cents
181
+ }
158
182
  }
159
- }
183
+ },
184
+ title: customer + ".credit_balance_depleted"
160
185
  },
161
- title: customer + ".credit_balance_depleted"
162
- });
186
+ idem(idempotencyKey, "alert.depleted")
187
+ );
163
188
  const stripePricingPlanSubscriptionId = (_d = (_c = (_b = (_a = actions == null ? void 0 : actions.data) == null ? void 0 : _a[0]) == null ? void 0 : _b.subscribe) == null ? void 0 : _c.pricing_plan_subscription_details) == null ? void 0 : _d.pricing_plan_subscription;
164
189
  if (!stripePricingPlanSubscriptionId) {
165
190
  throw new Error("Stripe billing intent did not return a pricing plan subscription ID for customer: " + customer);
@@ -199,7 +224,8 @@ var require_billing = __commonJS({
199
224
  };
200
225
  const unsubscribe = async ({
201
226
  currency,
202
- id
227
+ id,
228
+ idempotencyKey
203
229
  }) => {
204
230
  try {
205
231
  const { data } = await axios.post(
@@ -218,17 +244,17 @@ var require_billing = __commonJS({
218
244
  }
219
245
  ]
220
246
  },
221
- options
247
+ withIdem(idempotencyKey, "intent.create")
222
248
  );
223
249
  await axios.post(
224
250
  billing + "/intents/" + (data == null ? void 0 : data.id) + "/reserve",
225
251
  {},
226
- options
252
+ withIdem(idempotencyKey, "intent.reserve")
227
253
  );
228
254
  const commit = await axios.post(
229
255
  billing + "/intents/" + (data == null ? void 0 : data.id) + "/commit",
230
256
  {},
231
- options
257
+ withIdem(idempotencyKey, "intent.commit")
232
258
  );
233
259
  return commit;
234
260
  } catch (error) {
@@ -244,28 +270,30 @@ var require_billing = __commonJS({
244
270
  const model = [rest == null ? void 0 : rest.provider, rest == null ? void 0 : rest.model].join("/");
245
271
  const input = Number(metadata == null ? void 0 : metadata.promptTokenCount);
246
272
  const output = parseInt(Number(metadata == null ? void 0 : metadata.totalTokenCount) - input);
247
- if (input) {
273
+ const sendMeterEvent = (token_type, value) => {
248
274
  stripe.billing.meterEvents.create({
249
275
  event_name,
250
276
  payload: {
251
277
  model,
252
278
  stripe_customer_id: customer,
253
- token_type: "input",
254
- value: input
279
+ token_type,
280
+ value
255
281
  }
282
+ }).catch((error) => {
283
+ console.error("[billing.usage] meterEvents.create failed", {
284
+ customer,
285
+ token_type,
286
+ value,
287
+ error: error == null ? void 0 : error.message
288
+ });
256
289
  });
290
+ };
291
+ if (input) {
292
+ sendMeterEvent("input", input);
257
293
  }
258
294
  ;
259
295
  if (output) {
260
- stripe.billing.meterEvents.create({
261
- event_name,
262
- payload: {
263
- model,
264
- stripe_customer_id: customer,
265
- token_type: "output",
266
- value: output
267
- }
268
- });
296
+ sendMeterEvent("output", output);
269
297
  }
270
298
  ;
271
299
  };
@@ -568,6 +596,7 @@ var require_subscription = __commonJS({
568
596
  billingCycleAnchor,
569
597
  customer,
570
598
  discounts = [],
599
+ idempotencyKey,
571
600
  metadata,
572
601
  stripePaymentMethodId,
573
602
  to
@@ -576,6 +605,7 @@ var require_subscription = __commonJS({
576
605
  try {
577
606
  const actions = await createItem({
578
607
  currency: to.currency,
608
+ idempotencyKey,
579
609
  interval: to.interval,
580
610
  limit: to.limits.organization.actions,
581
611
  metadata,
@@ -583,31 +613,37 @@ var require_subscription = __commonJS({
583
613
  overage: to.overages.actions,
584
614
  proration_behavior: "none"
585
615
  });
586
- const subscription = await stripe.subscriptions.create({
587
- automatic_tax: {
588
- enabled: true
589
- },
590
- customer,
591
- description: "Organization subscription: " + metadata.organization,
592
- default_payment_method: stripePaymentMethodId,
593
- discounts: (discounts == null ? void 0 : discounts.length) > 0 ? discounts : "",
594
- items: [
595
- {
596
- price: actions.price
616
+ const subscription = await stripe.subscriptions.create(
617
+ {
618
+ automatic_tax: {
619
+ enabled: true
620
+ },
621
+ customer,
622
+ description: "Organization subscription: " + metadata.organization,
623
+ default_payment_method: stripePaymentMethodId,
624
+ discounts: (discounts == null ? void 0 : discounts.length) > 0 ? discounts : "",
625
+ items: [
626
+ {
627
+ price: actions.price
628
+ }
629
+ ],
630
+ metadata,
631
+ ...billingCycleAnchor && {
632
+ billing_cycle_anchor: billingCycleAnchor
597
633
  }
598
- ],
599
- metadata,
600
- ...billingCycleAnchor && {
601
- billing_cycle_anchor: billingCycleAnchor
602
- }
603
- });
634
+ },
635
+ idem(idempotencyKey, "subscription.create")
636
+ );
604
637
  const { product } = await stripe.prices.retrieve(to == null ? void 0 : to.stripePriceId);
605
- const plan = await stripe.subscriptionItems.create({
606
- subscription: subscription == null ? void 0 : subscription.id,
607
- price: to == null ? void 0 : to.stripePriceId,
608
- quantity: 1,
609
- proration_behavior: "always_invoice"
610
- });
638
+ const plan = await stripe.subscriptionItems.create(
639
+ {
640
+ subscription: subscription == null ? void 0 : subscription.id,
641
+ price: to == null ? void 0 : to.stripePriceId,
642
+ quantity: 1,
643
+ proration_behavior: "always_invoice"
644
+ },
645
+ idem(idempotencyKey, "plan.create")
646
+ );
611
647
  return {
612
648
  discounts,
613
649
  items: {
@@ -629,6 +665,7 @@ var require_subscription = __commonJS({
629
665
  }
630
666
  },
631
667
  pause: async ({
668
+ idempotencyKey,
632
669
  stripeSubscriptionId
633
670
  }) => {
634
671
  try {
@@ -640,7 +677,15 @@ var require_subscription = __commonJS({
640
677
  const { data } = await axios.post(
641
678
  subscriptions + "/" + stripeSubscriptionId + "/pause",
642
679
  body,
643
- options
680
+ {
681
+ ...options,
682
+ ...idempotencyKey && {
683
+ headers: {
684
+ ...options.headers,
685
+ "Idempotency-Key": idempotencyKey
686
+ }
687
+ }
688
+ }
644
689
  );
645
690
  return data;
646
691
  } catch (error) {
@@ -648,6 +693,7 @@ var require_subscription = __commonJS({
648
693
  }
649
694
  },
650
695
  resume: async ({
696
+ idempotencyKey,
651
697
  stripeSubscriptionId
652
698
  }) => {
653
699
  try {
@@ -657,7 +703,15 @@ var require_subscription = __commonJS({
657
703
  const { data } = await axios.post(
658
704
  subscriptions + "/" + stripeSubscriptionId + "/resume",
659
705
  body,
660
- options
706
+ {
707
+ ...options,
708
+ ...idempotencyKey && {
709
+ headers: {
710
+ ...options.headers,
711
+ "Idempotency-Key": idempotencyKey
712
+ }
713
+ }
714
+ }
661
715
  );
662
716
  return data;
663
717
  } catch (error) {
package/package.json CHANGED
@@ -24,5 +24,5 @@
24
24
  "build": "tsup ./index.js && npm publish"
25
25
  },
26
26
  "types": "dist/index.d.ts",
27
- "version": "0.1.13"
27
+ "version": "0.1.15"
28
28
  }