@drawbridge/drawbridge-stripe 0.1.3 → 0.1.5

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.js CHANGED
@@ -74,11 +74,8 @@ var require_billing = __commonJS({
74
74
  currency,
75
75
  cadence_data: {
76
76
  billing_cycle: {
77
- type: "month",
78
- interval_count: 1,
79
- month: {
80
- day_of_month: 1
81
- }
77
+ type: process.env.STRIPE_SUBSCRIPTION_INTERVAL,
78
+ interval_count: 1
82
79
  },
83
80
  payer
84
81
  },
@@ -162,6 +159,12 @@ var require_billing = __commonJS({
162
159
  throw new Error("Stripe billing intent did not return a pricing plan subscription ID for customer: " + customer);
163
160
  }
164
161
  ;
162
+ let stripePricingPlanSubscriptionNextBillingDate;
163
+ if (!default_payment_method) {
164
+ const { billing_cadence: billingCadenceId } = await stripe2.v2.billing.pricingPlanSubscriptions.retrieve(stripePricingPlanSubscriptionId);
165
+ ({ next_billing_date: stripePricingPlanSubscriptionNextBillingDate } = await stripe2.v2.billing.cadences.retrieve(billingCadenceId));
166
+ }
167
+ ;
165
168
  return {
166
169
  stripeAlerts: {
167
170
  ai: {
@@ -169,7 +172,8 @@ var require_billing = __commonJS({
169
172
  replenish: replenish == null ? void 0 : replenish.id
170
173
  }
171
174
  },
172
- stripePricingPlanSubscriptionId
175
+ stripePricingPlanSubscriptionId,
176
+ stripePricingPlanSubscriptionNextBillingDate
173
177
  };
174
178
  } catch (error) {
175
179
  throw error;
@@ -384,24 +388,24 @@ var require_subscription = __commonJS({
384
388
  proration_behavior: "create_prorations"
385
389
  }
386
390
  );
387
- let entries = (items == null ? void 0 : items.entries) || {};
388
- if ((entries == null ? void 0 : entries.id) && (entries == null ? void 0 : entries.price)) {
389
- ({ id: entries["id"] } = await stripe2.subscriptionItems.update(
390
- entries.id,
391
+ let actions = (items == null ? void 0 : items.actions) || {};
392
+ if ((actions == null ? void 0 : actions.id) && (actions == null ? void 0 : actions.price)) {
393
+ ({ id: actions["id"] } = await stripe2.subscriptionItems.update(
394
+ actions.id,
391
395
  {
392
396
  ...props,
393
- price: entries.price,
397
+ price: actions.price,
394
398
  proration_behavior: "none"
395
399
  }
396
400
  ));
397
401
  } else {
398
- entries = await createItem({
402
+ actions = await createItem({
399
403
  currency: to.currency,
400
404
  interval: to.interval,
401
- limit: to.limits.organization.entries,
405
+ limit: to.limits.organization.actions,
402
406
  metadata,
403
- name: "entries",
404
- overage: to.overages.entries,
407
+ name: "actions",
408
+ overage: to.overages.actions,
405
409
  proration_behavior: "none",
406
410
  subscription: stripeSubscriptionId
407
411
  });
@@ -419,7 +423,7 @@ var require_subscription = __commonJS({
419
423
  price: (_c = plan == null ? void 0 : plan.price) == null ? void 0 : _c.id,
420
424
  product: (_d = plan == null ? void 0 : plan.price) == null ? void 0 : _d.product
421
425
  },
422
- entries
426
+ actions
423
427
  }
424
428
  };
425
429
  } catch (error) {
@@ -435,13 +439,13 @@ var require_subscription = __commonJS({
435
439
  }) => {
436
440
  var _a, _b, _c;
437
441
  try {
438
- const entries = await createItem({
442
+ const actions = await createItem({
439
443
  currency: to.currency,
440
444
  interval: to.interval,
441
- limit: to.limits.organization.entries,
445
+ limit: to.limits.organization.actions,
442
446
  metadata,
443
- name: "entries",
444
- overage: to.overages.entries,
447
+ name: "actions",
448
+ overage: to.overages.actions,
445
449
  proration_behavior: "none"
446
450
  });
447
451
  const subscription = await stripe2.subscriptions.create({
@@ -454,7 +458,7 @@ var require_subscription = __commonJS({
454
458
  discounts: (discounts == null ? void 0 : discounts.length) > 0 ? discounts : "",
455
459
  items: [
456
460
  {
457
- price: entries.price
461
+ price: actions.price
458
462
  }
459
463
  ],
460
464
  metadata
@@ -474,9 +478,9 @@ var require_subscription = __commonJS({
474
478
  price: to == null ? void 0 : to.stripePriceId,
475
479
  product
476
480
  },
477
- entries: {
481
+ actions: {
478
482
  id: (_c = (_b = (_a = subscription == null ? void 0 : subscription.items) == null ? void 0 : _a.data) == null ? void 0 : _b[0]) == null ? void 0 : _c.id,
479
- ...entries
483
+ ...actions
480
484
  }
481
485
  },
482
486
  stripeCustomerId: customer,
@@ -505,33 +509,33 @@ var require_subscription = __commonJS({
505
509
  proration_behavior: "always_invoice"
506
510
  }
507
511
  );
508
- let entries;
509
- if (((_d = (_c = current == null ? void 0 : current.items) == null ? void 0 : _c.entries) == null ? void 0 : _d.id) && ((_f = (_e = current == null ? void 0 : current.items) == null ? void 0 : _e.entries) == null ? void 0 : _f.meter)) {
510
- entries = await createTier({
512
+ let actions;
513
+ if (((_d = (_c = current == null ? void 0 : current.items) == null ? void 0 : _c.actions) == null ? void 0 : _d.id) && ((_f = (_e = current == null ? void 0 : current.items) == null ? void 0 : _e.actions) == null ? void 0 : _f.meter)) {
514
+ actions = await createTier({
511
515
  currency: to.currency,
512
516
  interval: to.interval,
513
- limit: to.limits.organization.entries,
517
+ limit: to.limits.organization.actions,
514
518
  metadata,
515
- meter: current.items.entries.meter,
516
- name: "entries",
517
- overage: to.overages.entries
519
+ meter: current.items.actions.meter,
520
+ name: "actions",
521
+ overage: to.overages.actions
518
522
  });
519
- ({ id: entries["id"] } = await stripe2.subscriptionItems.update(
520
- current.items.entries.id,
523
+ ({ id: actions["id"] } = await stripe2.subscriptionItems.update(
524
+ current.items.actions.id,
521
525
  {
522
526
  ...props,
523
- price: entries == null ? void 0 : entries.price,
527
+ price: actions == null ? void 0 : actions.price,
524
528
  proration_behavior: "none"
525
529
  }
526
530
  ));
527
531
  } else {
528
- entries = await createItem({
532
+ actions = await createItem({
529
533
  currency: to.currency,
530
534
  interval: to.interval,
531
- limit: to.limits.organization.entries,
535
+ limit: to.limits.organization.actions,
532
536
  metadata,
533
- name: "entries",
534
- overage: to.overages.entries,
537
+ name: "actions",
538
+ overage: to.overages.actions,
535
539
  proration_behavior: "none",
536
540
  subscription: stripeSubscriptionId
537
541
  });
@@ -550,9 +554,9 @@ var require_subscription = __commonJS({
550
554
  price: (_g = plan == null ? void 0 : plan.price) == null ? void 0 : _g.id,
551
555
  product: (_h = plan == null ? void 0 : plan.price) == null ? void 0 : _h.product
552
556
  },
553
- entries: {
554
- ...((_i = current == null ? void 0 : current.items) == null ? void 0 : _i.entries) || {},
555
- ...entries
557
+ actions: {
558
+ ...((_i = current == null ? void 0 : current.items) == null ? void 0 : _i.actions) || {},
559
+ ...actions
556
560
  }
557
561
  }
558
562
  };
package/dist/index.mjs CHANGED
@@ -80,11 +80,8 @@ var require_billing = __commonJS({
80
80
  currency,
81
81
  cadence_data: {
82
82
  billing_cycle: {
83
- type: "month",
84
- interval_count: 1,
85
- month: {
86
- day_of_month: 1
87
- }
83
+ type: process.env.STRIPE_SUBSCRIPTION_INTERVAL,
84
+ interval_count: 1
88
85
  },
89
86
  payer
90
87
  },
@@ -168,6 +165,12 @@ var require_billing = __commonJS({
168
165
  throw new Error("Stripe billing intent did not return a pricing plan subscription ID for customer: " + customer);
169
166
  }
170
167
  ;
168
+ let stripePricingPlanSubscriptionNextBillingDate;
169
+ if (!default_payment_method) {
170
+ const { billing_cadence: billingCadenceId } = await stripe.v2.billing.pricingPlanSubscriptions.retrieve(stripePricingPlanSubscriptionId);
171
+ ({ next_billing_date: stripePricingPlanSubscriptionNextBillingDate } = await stripe.v2.billing.cadences.retrieve(billingCadenceId));
172
+ }
173
+ ;
171
174
  return {
172
175
  stripeAlerts: {
173
176
  ai: {
@@ -175,7 +178,8 @@ var require_billing = __commonJS({
175
178
  replenish: replenish == null ? void 0 : replenish.id
176
179
  }
177
180
  },
178
- stripePricingPlanSubscriptionId
181
+ stripePricingPlanSubscriptionId,
182
+ stripePricingPlanSubscriptionNextBillingDate
179
183
  };
180
184
  } catch (error) {
181
185
  throw error;
@@ -390,24 +394,24 @@ var require_subscription = __commonJS({
390
394
  proration_behavior: "create_prorations"
391
395
  }
392
396
  );
393
- let entries = (items == null ? void 0 : items.entries) || {};
394
- if ((entries == null ? void 0 : entries.id) && (entries == null ? void 0 : entries.price)) {
395
- ({ id: entries["id"] } = await stripe.subscriptionItems.update(
396
- entries.id,
397
+ let actions = (items == null ? void 0 : items.actions) || {};
398
+ if ((actions == null ? void 0 : actions.id) && (actions == null ? void 0 : actions.price)) {
399
+ ({ id: actions["id"] } = await stripe.subscriptionItems.update(
400
+ actions.id,
397
401
  {
398
402
  ...props,
399
- price: entries.price,
403
+ price: actions.price,
400
404
  proration_behavior: "none"
401
405
  }
402
406
  ));
403
407
  } else {
404
- entries = await createItem({
408
+ actions = await createItem({
405
409
  currency: to.currency,
406
410
  interval: to.interval,
407
- limit: to.limits.organization.entries,
411
+ limit: to.limits.organization.actions,
408
412
  metadata,
409
- name: "entries",
410
- overage: to.overages.entries,
413
+ name: "actions",
414
+ overage: to.overages.actions,
411
415
  proration_behavior: "none",
412
416
  subscription: stripeSubscriptionId
413
417
  });
@@ -425,7 +429,7 @@ var require_subscription = __commonJS({
425
429
  price: (_c = plan == null ? void 0 : plan.price) == null ? void 0 : _c.id,
426
430
  product: (_d = plan == null ? void 0 : plan.price) == null ? void 0 : _d.product
427
431
  },
428
- entries
432
+ actions
429
433
  }
430
434
  };
431
435
  } catch (error) {
@@ -441,13 +445,13 @@ var require_subscription = __commonJS({
441
445
  }) => {
442
446
  var _a, _b, _c;
443
447
  try {
444
- const entries = await createItem({
448
+ const actions = await createItem({
445
449
  currency: to.currency,
446
450
  interval: to.interval,
447
- limit: to.limits.organization.entries,
451
+ limit: to.limits.organization.actions,
448
452
  metadata,
449
- name: "entries",
450
- overage: to.overages.entries,
453
+ name: "actions",
454
+ overage: to.overages.actions,
451
455
  proration_behavior: "none"
452
456
  });
453
457
  const subscription = await stripe.subscriptions.create({
@@ -460,7 +464,7 @@ var require_subscription = __commonJS({
460
464
  discounts: (discounts == null ? void 0 : discounts.length) > 0 ? discounts : "",
461
465
  items: [
462
466
  {
463
- price: entries.price
467
+ price: actions.price
464
468
  }
465
469
  ],
466
470
  metadata
@@ -480,9 +484,9 @@ var require_subscription = __commonJS({
480
484
  price: to == null ? void 0 : to.stripePriceId,
481
485
  product
482
486
  },
483
- entries: {
487
+ actions: {
484
488
  id: (_c = (_b = (_a = subscription == null ? void 0 : subscription.items) == null ? void 0 : _a.data) == null ? void 0 : _b[0]) == null ? void 0 : _c.id,
485
- ...entries
489
+ ...actions
486
490
  }
487
491
  },
488
492
  stripeCustomerId: customer,
@@ -511,33 +515,33 @@ var require_subscription = __commonJS({
511
515
  proration_behavior: "always_invoice"
512
516
  }
513
517
  );
514
- let entries;
515
- if (((_d = (_c = current == null ? void 0 : current.items) == null ? void 0 : _c.entries) == null ? void 0 : _d.id) && ((_f = (_e = current == null ? void 0 : current.items) == null ? void 0 : _e.entries) == null ? void 0 : _f.meter)) {
516
- entries = await createTier({
518
+ let actions;
519
+ if (((_d = (_c = current == null ? void 0 : current.items) == null ? void 0 : _c.actions) == null ? void 0 : _d.id) && ((_f = (_e = current == null ? void 0 : current.items) == null ? void 0 : _e.actions) == null ? void 0 : _f.meter)) {
520
+ actions = await createTier({
517
521
  currency: to.currency,
518
522
  interval: to.interval,
519
- limit: to.limits.organization.entries,
523
+ limit: to.limits.organization.actions,
520
524
  metadata,
521
- meter: current.items.entries.meter,
522
- name: "entries",
523
- overage: to.overages.entries
525
+ meter: current.items.actions.meter,
526
+ name: "actions",
527
+ overage: to.overages.actions
524
528
  });
525
- ({ id: entries["id"] } = await stripe.subscriptionItems.update(
526
- current.items.entries.id,
529
+ ({ id: actions["id"] } = await stripe.subscriptionItems.update(
530
+ current.items.actions.id,
527
531
  {
528
532
  ...props,
529
- price: entries == null ? void 0 : entries.price,
533
+ price: actions == null ? void 0 : actions.price,
530
534
  proration_behavior: "none"
531
535
  }
532
536
  ));
533
537
  } else {
534
- entries = await createItem({
538
+ actions = await createItem({
535
539
  currency: to.currency,
536
540
  interval: to.interval,
537
- limit: to.limits.organization.entries,
541
+ limit: to.limits.organization.actions,
538
542
  metadata,
539
- name: "entries",
540
- overage: to.overages.entries,
543
+ name: "actions",
544
+ overage: to.overages.actions,
541
545
  proration_behavior: "none",
542
546
  subscription: stripeSubscriptionId
543
547
  });
@@ -556,9 +560,9 @@ var require_subscription = __commonJS({
556
560
  price: (_g = plan == null ? void 0 : plan.price) == null ? void 0 : _g.id,
557
561
  product: (_h = plan == null ? void 0 : plan.price) == null ? void 0 : _h.product
558
562
  },
559
- entries: {
560
- ...((_i = current == null ? void 0 : current.items) == null ? void 0 : _i.entries) || {},
561
- ...entries
563
+ actions: {
564
+ ...((_i = current == null ? void 0 : current.items) == null ? void 0 : _i.actions) || {},
565
+ ...actions
562
566
  }
563
567
  }
564
568
  };
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.3"
27
+ "version": "0.1.5"
28
28
  }