@drawbridge/drawbridge-stripe 0.1.8 → 0.1.10

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
@@ -404,6 +404,8 @@ var require_subscription = __commonJS({
404
404
  return ((_b2 = (_a2 = item == null ? void 0 : item.price) == null ? void 0 : _a2.recurring) == null ? void 0 : _b2.usage_type) === "metered";
405
405
  }
406
406
  );
407
+ const currentPeriodStart = currentPlanItem == null ? void 0 : currentPlanItem.current_period_start;
408
+ const currentPeriodEnd = currentPlanItem == null ? void 0 : currentPlanItem.current_period_end;
407
409
  const phases = [
408
410
  {
409
411
  items: [
@@ -415,8 +417,8 @@ var require_subscription = __commonJS({
415
417
  price: (_b = currentActionsItem == null ? void 0 : currentActionsItem.price) == null ? void 0 : _b.id
416
418
  }
417
419
  ],
418
- start_date: live.current_period_start,
419
- end_date: live.current_period_end,
420
+ start_date: currentPeriodStart,
421
+ end_date: currentPeriodEnd,
420
422
  proration_behavior: "none"
421
423
  },
422
424
  {
@@ -436,18 +438,25 @@ var require_subscription = __commonJS({
436
438
  const schedule = await stripe2.subscriptionSchedules.create({
437
439
  from_subscription: stripeSubscriptionId
438
440
  });
439
- await stripe2.subscriptionSchedules.update(
440
- schedule.id,
441
- {
442
- end_behavior: "release",
443
- phases
444
- }
445
- );
441
+ try {
442
+ await stripe2.subscriptionSchedules.update(
443
+ schedule.id,
444
+ {
445
+ end_behavior: "release",
446
+ phases
447
+ }
448
+ );
449
+ } catch (error) {
450
+ await stripe2.subscriptionSchedules.release(schedule.id).catch(() => {
451
+ });
452
+ throw error;
453
+ }
454
+ ;
446
455
  return {
447
456
  items,
448
457
  pending: {
449
458
  scheduleId: schedule.id,
450
- effectiveAt: new Date(live.current_period_end * 1e3)
459
+ effectiveAt: new Date(currentPeriodEnd * 1e3)
451
460
  }
452
461
  };
453
462
  }
@@ -610,6 +619,14 @@ var require_subscription = __commonJS({
610
619
  }
611
620
  ;
612
621
  const product = await stripe2.prices.retrieve(to == null ? void 0 : to.stripePriceId);
622
+ const livePlanItem = live.items.data.find(
623
+ (item) => {
624
+ var _a2, _b2;
625
+ return ((_b2 = (_a2 = item == null ? void 0 : item.price) == null ? void 0 : _a2.recurring) == null ? void 0 : _b2.usage_type) !== "metered";
626
+ }
627
+ );
628
+ const currentPeriodStart = livePlanItem == null ? void 0 : livePlanItem.current_period_start;
629
+ const currentPeriodEnd = livePlanItem == null ? void 0 : livePlanItem.current_period_end;
613
630
  const phases = [
614
631
  {
615
632
  items: [
@@ -621,8 +638,8 @@ var require_subscription = __commonJS({
621
638
  price: (_f = (_e = current == null ? void 0 : current.items) == null ? void 0 : _e.actions) == null ? void 0 : _f.price
622
639
  }
623
640
  ],
624
- start_date: live.current_period_start,
625
- end_date: live.current_period_end,
641
+ start_date: currentPeriodStart,
642
+ end_date: currentPeriodEnd,
626
643
  proration_behavior: "none"
627
644
  },
628
645
  {
@@ -642,13 +659,20 @@ var require_subscription = __commonJS({
642
659
  const schedule = await stripe2.subscriptionSchedules.create({
643
660
  from_subscription: stripeSubscriptionId
644
661
  });
645
- await stripe2.subscriptionSchedules.update(
646
- schedule.id,
647
- {
648
- end_behavior: "release",
649
- phases
650
- }
651
- );
662
+ try {
663
+ await stripe2.subscriptionSchedules.update(
664
+ schedule.id,
665
+ {
666
+ end_behavior: "release",
667
+ phases
668
+ }
669
+ );
670
+ } catch (error) {
671
+ await stripe2.subscriptionSchedules.release(schedule.id).catch(() => {
672
+ });
673
+ throw error;
674
+ }
675
+ ;
652
676
  return {
653
677
  items: {
654
678
  plan: {
@@ -659,7 +683,7 @@ var require_subscription = __commonJS({
659
683
  },
660
684
  pending: {
661
685
  scheduleId: schedule.id,
662
- effectiveAt: new Date(live.current_period_end * 1e3)
686
+ effectiveAt: new Date(currentPeriodEnd * 1e3)
663
687
  }
664
688
  };
665
689
  }
package/dist/index.mjs CHANGED
@@ -410,6 +410,8 @@ var require_subscription = __commonJS({
410
410
  return ((_b2 = (_a2 = item == null ? void 0 : item.price) == null ? void 0 : _a2.recurring) == null ? void 0 : _b2.usage_type) === "metered";
411
411
  }
412
412
  );
413
+ const currentPeriodStart = currentPlanItem == null ? void 0 : currentPlanItem.current_period_start;
414
+ const currentPeriodEnd = currentPlanItem == null ? void 0 : currentPlanItem.current_period_end;
413
415
  const phases = [
414
416
  {
415
417
  items: [
@@ -421,8 +423,8 @@ var require_subscription = __commonJS({
421
423
  price: (_b = currentActionsItem == null ? void 0 : currentActionsItem.price) == null ? void 0 : _b.id
422
424
  }
423
425
  ],
424
- start_date: live.current_period_start,
425
- end_date: live.current_period_end,
426
+ start_date: currentPeriodStart,
427
+ end_date: currentPeriodEnd,
426
428
  proration_behavior: "none"
427
429
  },
428
430
  {
@@ -442,18 +444,25 @@ var require_subscription = __commonJS({
442
444
  const schedule = await stripe.subscriptionSchedules.create({
443
445
  from_subscription: stripeSubscriptionId
444
446
  });
445
- await stripe.subscriptionSchedules.update(
446
- schedule.id,
447
- {
448
- end_behavior: "release",
449
- phases
450
- }
451
- );
447
+ try {
448
+ await stripe.subscriptionSchedules.update(
449
+ schedule.id,
450
+ {
451
+ end_behavior: "release",
452
+ phases
453
+ }
454
+ );
455
+ } catch (error) {
456
+ await stripe.subscriptionSchedules.release(schedule.id).catch(() => {
457
+ });
458
+ throw error;
459
+ }
460
+ ;
452
461
  return {
453
462
  items,
454
463
  pending: {
455
464
  scheduleId: schedule.id,
456
- effectiveAt: new Date(live.current_period_end * 1e3)
465
+ effectiveAt: new Date(currentPeriodEnd * 1e3)
457
466
  }
458
467
  };
459
468
  }
@@ -616,6 +625,14 @@ var require_subscription = __commonJS({
616
625
  }
617
626
  ;
618
627
  const product = await stripe.prices.retrieve(to == null ? void 0 : to.stripePriceId);
628
+ const livePlanItem = live.items.data.find(
629
+ (item) => {
630
+ var _a2, _b2;
631
+ return ((_b2 = (_a2 = item == null ? void 0 : item.price) == null ? void 0 : _a2.recurring) == null ? void 0 : _b2.usage_type) !== "metered";
632
+ }
633
+ );
634
+ const currentPeriodStart = livePlanItem == null ? void 0 : livePlanItem.current_period_start;
635
+ const currentPeriodEnd = livePlanItem == null ? void 0 : livePlanItem.current_period_end;
619
636
  const phases = [
620
637
  {
621
638
  items: [
@@ -627,8 +644,8 @@ var require_subscription = __commonJS({
627
644
  price: (_f = (_e = current == null ? void 0 : current.items) == null ? void 0 : _e.actions) == null ? void 0 : _f.price
628
645
  }
629
646
  ],
630
- start_date: live.current_period_start,
631
- end_date: live.current_period_end,
647
+ start_date: currentPeriodStart,
648
+ end_date: currentPeriodEnd,
632
649
  proration_behavior: "none"
633
650
  },
634
651
  {
@@ -648,13 +665,20 @@ var require_subscription = __commonJS({
648
665
  const schedule = await stripe.subscriptionSchedules.create({
649
666
  from_subscription: stripeSubscriptionId
650
667
  });
651
- await stripe.subscriptionSchedules.update(
652
- schedule.id,
653
- {
654
- end_behavior: "release",
655
- phases
656
- }
657
- );
668
+ try {
669
+ await stripe.subscriptionSchedules.update(
670
+ schedule.id,
671
+ {
672
+ end_behavior: "release",
673
+ phases
674
+ }
675
+ );
676
+ } catch (error) {
677
+ await stripe.subscriptionSchedules.release(schedule.id).catch(() => {
678
+ });
679
+ throw error;
680
+ }
681
+ ;
658
682
  return {
659
683
  items: {
660
684
  plan: {
@@ -665,7 +689,7 @@ var require_subscription = __commonJS({
665
689
  },
666
690
  pending: {
667
691
  scheduleId: schedule.id,
668
- effectiveAt: new Date(live.current_period_end * 1e3)
692
+ effectiveAt: new Date(currentPeriodEnd * 1e3)
669
693
  }
670
694
  };
671
695
  }
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.8"
27
+ "version": "0.1.10"
28
28
  }