@drawbridge/drawbridge-stripe 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,23 +1,17 @@
1
1
  const lib = require( './lib' );
2
+ const stripe = require( 'stripe' )(
3
+ process.env.STRIPE_API_KEY,
4
+ {
5
+ apiVersion : '2026-01-28.preview'
6
+ }
7
+ );
2
8
 
3
- module.exports = ( apiKey ) => {
4
-
5
- const stripe = require( 'stripe' )(
6
- apiKey,
7
- {
8
- apiVersion : '2026-01-28.preview'
9
- }
10
- );
11
-
12
- return {
13
- billing : lib.billing({
14
- apiKey,
15
- stripe
16
- }),
17
- stripe,
18
- subscription : lib.subscription({
19
- stripe
20
- })
21
- }
22
-
9
+ module.exports = {
10
+ billing : lib.billing({
11
+ stripe
12
+ }),
13
+ stripe,
14
+ subscription : lib.subscription({
15
+ stripe
16
+ })
23
17
  };
package/dist/index.d.ts CHANGED
@@ -1,23 +1,17 @@
1
1
  const lib = require( './lib' );
2
+ const stripe = require( 'stripe' )(
3
+ process.env.STRIPE_API_KEY,
4
+ {
5
+ apiVersion : '2026-01-28.preview'
6
+ }
7
+ );
2
8
 
3
- module.exports = ( apiKey ) => {
4
-
5
- const stripe = require( 'stripe' )(
6
- apiKey,
7
- {
8
- apiVersion : '2026-01-28.preview'
9
- }
10
- );
11
-
12
- return {
13
- billing : lib.billing({
14
- apiKey,
15
- stripe
16
- }),
17
- stripe,
18
- subscription : lib.subscription({
19
- stripe
20
- })
21
- }
22
-
9
+ module.exports = {
10
+ billing : lib.billing({
11
+ stripe
12
+ }),
13
+ stripe,
14
+ subscription : lib.subscription({
15
+ stripe
16
+ })
23
17
  };
package/dist/index.js CHANGED
@@ -9,12 +9,11 @@ var require_billing = __commonJS({
9
9
  var axios = require("axios");
10
10
  var billing = "https://api.stripe.com/v2/billing";
11
11
  module2.exports = ({
12
- apiKey,
13
- stripe
12
+ stripe: stripe2
14
13
  }) => {
15
14
  const options = {
16
15
  headers: {
17
- "Authorization": "Bearer " + apiKey,
16
+ "Authorization": "Bearer " + process.env.STRIPE_API_KEY,
18
17
  "Content-Type": "application/json",
19
18
  "Stripe-Version": "2026-01-28.preview"
20
19
  }
@@ -22,11 +21,18 @@ var require_billing = __commonJS({
22
21
  const subscribe = async ({
23
22
  currency: currency2,
24
23
  customer,
25
- default_payment_method,
24
+ default_payment_method = null,
26
25
  metadata = {}
27
26
  }) => {
28
27
  var _a, _b, _c, _d;
29
28
  try {
29
+ const billing_profile_data = {
30
+ customer
31
+ };
32
+ if (Boolean(default_payment_method)) {
33
+ billing_profile_data["default_payment_method"] = default_payment_method;
34
+ }
35
+ ;
30
36
  const { data: intent } = await axios.post(
31
37
  billing + "/intents",
32
38
  {
@@ -40,10 +46,7 @@ var require_billing = __commonJS({
40
46
  }
41
47
  },
42
48
  payer: {
43
- billing_profile_data: {
44
- customer,
45
- default_payment_method
46
- }
49
+ billing_profile_data
47
50
  }
48
51
  },
49
52
  actions: [
@@ -77,7 +80,7 @@ var require_billing = __commonJS({
77
80
  billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/actions",
78
81
  options
79
82
  );
80
- const replenish = await stripe.billing.alerts.create({
83
+ const replenish = await stripe2.billing.alerts.create({
81
84
  alert_type: "credit_balance_threshold",
82
85
  credit_balance_threshold: {
83
86
  filters: [
@@ -104,7 +107,7 @@ var require_billing = __commonJS({
104
107
  },
105
108
  title: customer + ".credit_balance_replenish"
106
109
  });
107
- const depleted = await stripe.billing.alerts.create({
110
+ const depleted = await stripe2.billing.alerts.create({
108
111
  alert_type: "credit_balance_threshold",
109
112
  credit_balance_threshold: {
110
113
  filters: [
@@ -190,7 +193,7 @@ var require_billing = __commonJS({
190
193
  const input = Number(metadata == null ? void 0 : metadata.promptTokenCount);
191
194
  const output = parseInt(Number(metadata == null ? void 0 : metadata.totalTokenCount) - input);
192
195
  if (input) {
193
- stripe.billing.meterEvents.create({
196
+ stripe2.billing.meterEvents.create({
194
197
  event_name,
195
198
  payload: {
196
199
  model,
@@ -202,7 +205,7 @@ var require_billing = __commonJS({
202
205
  }
203
206
  ;
204
207
  if (output) {
205
- stripe.billing.meterEvents.create({
208
+ stripe2.billing.meterEvents.create({
206
209
  event_name,
207
210
  payload: {
208
211
  model,
@@ -227,14 +230,14 @@ var require_billing = __commonJS({
227
230
  var require_subscription = __commonJS({
228
231
  "lib/subscription.js"(exports2, module2) {
229
232
  module2.exports = ({
230
- stripe
233
+ stripe: stripe2
231
234
  }) => {
232
235
  const createMeter = async ({
233
236
  metadata,
234
237
  name
235
238
  }) => {
236
239
  const usage = (metadata == null ? void 0 : metadata.organization) + "_usage_" + name;
237
- const meter = await stripe.billing.meters.create({
240
+ const meter = await stripe2.billing.meters.create({
238
241
  default_aggregation: {
239
242
  formula: "sum"
240
243
  },
@@ -256,12 +259,12 @@ var require_subscription = __commonJS({
256
259
  overage
257
260
  }) => {
258
261
  const response = {};
259
- const product = await stripe.products.create({
262
+ const product = await stripe2.products.create({
260
263
  metadata,
261
264
  name
262
265
  });
263
266
  response["product"] = product == null ? void 0 : product.id;
264
- const price = await stripe.prices.create({
267
+ const price = await stripe2.prices.create({
265
268
  billing_scheme: "tiered",
266
269
  currency: currency2,
267
270
  metadata,
@@ -319,7 +322,7 @@ var require_subscription = __commonJS({
319
322
  response["price"] = price;
320
323
  response["product"] = product;
321
324
  if (subscription) {
322
- const { id } = await stripe.subscriptionItems.create({
325
+ const { id } = await stripe2.subscriptionItems.create({
323
326
  metadata,
324
327
  price,
325
328
  proration_behavior,
@@ -342,7 +345,7 @@ var require_subscription = __commonJS({
342
345
  const props = {
343
346
  metadata
344
347
  };
345
- const plan = await stripe.subscriptionItems.update(
348
+ const plan = await stripe2.subscriptionItems.update(
346
349
  (_a = items == null ? void 0 : items.plan) == null ? void 0 : _a.id,
347
350
  {
348
351
  ...props,
@@ -352,7 +355,7 @@ var require_subscription = __commonJS({
352
355
  );
353
356
  let entries = (items == null ? void 0 : items.entries) || {};
354
357
  if ((entries == null ? void 0 : entries.id) && (entries == null ? void 0 : entries.price)) {
355
- ({ id: entries["id"] } = await stripe.subscriptionItems.update(
358
+ ({ id: entries["id"] } = await stripe2.subscriptionItems.update(
356
359
  entries.id,
357
360
  {
358
361
  ...props,
@@ -372,7 +375,7 @@ var require_subscription = __commonJS({
372
375
  subscription: stripeSubscriptionId
373
376
  });
374
377
  }
375
- await stripe.subscriptions.update(
378
+ await stripe2.subscriptions.update(
376
379
  stripeSubscriptionId,
377
380
  {
378
381
  metadata
@@ -410,7 +413,7 @@ var require_subscription = __commonJS({
410
413
  overage: to.overages.entries,
411
414
  proration_behavior: "none"
412
415
  });
413
- const subscription = await stripe.subscriptions.create({
416
+ const subscription = await stripe2.subscriptions.create({
414
417
  automatic_tax: {
415
418
  enabled: true
416
419
  },
@@ -425,8 +428,8 @@ var require_subscription = __commonJS({
425
428
  ],
426
429
  metadata
427
430
  });
428
- const { product } = await stripe.prices.retrieve(to == null ? void 0 : to.stripePriceId);
429
- const plan = await stripe.subscriptionItems.create({
431
+ const { product } = await stripe2.prices.retrieve(to == null ? void 0 : to.stripePriceId);
432
+ const plan = await stripe2.subscriptionItems.create({
430
433
  subscription: subscription == null ? void 0 : subscription.id,
431
434
  price: to == null ? void 0 : to.stripePriceId,
432
435
  quantity: 1,
@@ -463,7 +466,7 @@ var require_subscription = __commonJS({
463
466
  const props = {
464
467
  metadata
465
468
  };
466
- const plan = await stripe.subscriptionItems.update(
469
+ const plan = await stripe2.subscriptionItems.update(
467
470
  (_b = (_a = current == null ? void 0 : current.items) == null ? void 0 : _a.plan) == null ? void 0 : _b.id,
468
471
  {
469
472
  ...props,
@@ -482,7 +485,7 @@ var require_subscription = __commonJS({
482
485
  name: "entries",
483
486
  overage: to.overages.entries
484
487
  });
485
- ({ id: entries["id"] } = await stripe.subscriptionItems.update(
488
+ ({ id: entries["id"] } = await stripe2.subscriptionItems.update(
486
489
  current.items.entries.id,
487
490
  {
488
491
  ...props,
@@ -503,7 +506,7 @@ var require_subscription = __commonJS({
503
506
  });
504
507
  }
505
508
  ;
506
- await stripe.subscriptions.update(
509
+ await stripe2.subscriptions.update(
507
510
  stripeSubscriptionId,
508
511
  {
509
512
  metadata
@@ -545,21 +548,18 @@ var require_lib = __commonJS({
545
548
 
546
549
  // index.js
547
550
  var lib = require_lib();
548
- module.exports = (apiKey) => {
549
- const stripe = require("stripe")(
550
- apiKey,
551
- {
552
- apiVersion: "2026-01-28.preview"
553
- }
554
- );
555
- return {
556
- billing: lib.billing({
557
- apiKey,
558
- stripe
559
- }),
560
- stripe,
561
- subscription: lib.subscription({
562
- stripe
563
- })
564
- };
551
+ var stripe = require("stripe")(
552
+ process.env.STRIPE_API_KEY,
553
+ {
554
+ apiVersion: "2026-01-28.preview"
555
+ }
556
+ );
557
+ module.exports = {
558
+ billing: lib.billing({
559
+ stripe
560
+ }),
561
+ stripe,
562
+ subscription: lib.subscription({
563
+ stripe
564
+ })
565
565
  };
package/dist/index.mjs CHANGED
@@ -15,12 +15,11 @@ var require_billing = __commonJS({
15
15
  var axios = __require("axios");
16
16
  var billing = "https://api.stripe.com/v2/billing";
17
17
  module.exports = ({
18
- apiKey,
19
18
  stripe
20
19
  }) => {
21
20
  const options = {
22
21
  headers: {
23
- "Authorization": "Bearer " + apiKey,
22
+ "Authorization": "Bearer " + process.env.STRIPE_API_KEY,
24
23
  "Content-Type": "application/json",
25
24
  "Stripe-Version": "2026-01-28.preview"
26
25
  }
@@ -28,11 +27,18 @@ var require_billing = __commonJS({
28
27
  const subscribe = async ({
29
28
  currency: currency2,
30
29
  customer,
31
- default_payment_method,
30
+ default_payment_method = null,
32
31
  metadata = {}
33
32
  }) => {
34
33
  var _a, _b, _c, _d;
35
34
  try {
35
+ const billing_profile_data = {
36
+ customer
37
+ };
38
+ if (Boolean(default_payment_method)) {
39
+ billing_profile_data["default_payment_method"] = default_payment_method;
40
+ }
41
+ ;
36
42
  const { data: intent } = await axios.post(
37
43
  billing + "/intents",
38
44
  {
@@ -46,10 +52,7 @@ var require_billing = __commonJS({
46
52
  }
47
53
  },
48
54
  payer: {
49
- billing_profile_data: {
50
- customer,
51
- default_payment_method
52
- }
55
+ billing_profile_data
53
56
  }
54
57
  },
55
58
  actions: [
@@ -553,23 +556,20 @@ var require_lib = __commonJS({
553
556
  var require_index = __commonJS({
554
557
  "index.js"(exports, module) {
555
558
  var lib = require_lib();
556
- module.exports = (apiKey) => {
557
- const stripe = __require("stripe")(
558
- apiKey,
559
- {
560
- apiVersion: "2026-01-28.preview"
561
- }
562
- );
563
- return {
564
- billing: lib.billing({
565
- apiKey,
566
- stripe
567
- }),
568
- stripe,
569
- subscription: lib.subscription({
570
- stripe
571
- })
572
- };
559
+ var stripe = __require("stripe")(
560
+ process.env.STRIPE_API_KEY,
561
+ {
562
+ apiVersion: "2026-01-28.preview"
563
+ }
564
+ );
565
+ module.exports = {
566
+ billing: lib.billing({
567
+ stripe
568
+ }),
569
+ stripe,
570
+ subscription: lib.subscription({
571
+ stripe
572
+ })
573
573
  };
574
574
  }
575
575
  });
package/package.json CHANGED
@@ -24,5 +24,5 @@
24
24
  "build": "tsup ./index.js"
25
25
  },
26
26
  "types": "dist/index.d.ts",
27
- "version": "0.0.4"
27
+ "version": "0.0.6"
28
28
  }