@drawbridge/drawbridge-stripe 0.1.16 → 0.1.18
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 +29 -3
- package/dist/index.mjs +29 -3
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -324,10 +324,34 @@ var require_subscription = __commonJS({
|
|
|
324
324
|
};
|
|
325
325
|
const createMeter = async ({
|
|
326
326
|
idempotencyKey,
|
|
327
|
+
meter: existing,
|
|
327
328
|
metadata,
|
|
328
329
|
name
|
|
329
330
|
}) => {
|
|
330
331
|
const usage = (metadata == null ? void 0 : metadata.organization) + "_usage_" + name;
|
|
332
|
+
if (existing) {
|
|
333
|
+
const meter2 = await stripe2.billing.meters.retrieve(existing).catch(() => null);
|
|
334
|
+
if ((meter2 == null ? void 0 : meter2.status) === "active" && (meter2 == null ? void 0 : meter2.event_name) === usage) {
|
|
335
|
+
return {
|
|
336
|
+
meter: meter2.id,
|
|
337
|
+
usage
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
;
|
|
341
|
+
}
|
|
342
|
+
;
|
|
343
|
+
for await (const meter2 of stripe2.billing.meters.list({
|
|
344
|
+
status: "active"
|
|
345
|
+
})) {
|
|
346
|
+
if ((meter2 == null ? void 0 : meter2.event_name) === usage) {
|
|
347
|
+
return {
|
|
348
|
+
meter: meter2.id,
|
|
349
|
+
usage
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
;
|
|
353
|
+
}
|
|
354
|
+
;
|
|
331
355
|
const meter = await stripe2.billing.meters.create(
|
|
332
356
|
{
|
|
333
357
|
default_aggregation: {
|
|
@@ -399,6 +423,7 @@ var require_subscription = __commonJS({
|
|
|
399
423
|
idempotencyKey,
|
|
400
424
|
interval,
|
|
401
425
|
limit,
|
|
426
|
+
meter: existing,
|
|
402
427
|
metadata,
|
|
403
428
|
name,
|
|
404
429
|
overage,
|
|
@@ -408,6 +433,7 @@ var require_subscription = __commonJS({
|
|
|
408
433
|
const response = {};
|
|
409
434
|
const { meter, usage } = await createMeter({
|
|
410
435
|
idempotencyKey,
|
|
436
|
+
meter: existing,
|
|
411
437
|
metadata,
|
|
412
438
|
name
|
|
413
439
|
});
|
|
@@ -587,10 +613,10 @@ var require_subscription = __commonJS({
|
|
|
587
613
|
}
|
|
588
614
|
},
|
|
589
615
|
create: async ({
|
|
590
|
-
billingCycleAnchor,
|
|
591
616
|
customer,
|
|
592
617
|
discounts = [],
|
|
593
618
|
idempotencyKey,
|
|
619
|
+
meter,
|
|
594
620
|
metadata,
|
|
595
621
|
stripePaymentMethodId,
|
|
596
622
|
to
|
|
@@ -602,6 +628,7 @@ var require_subscription = __commonJS({
|
|
|
602
628
|
idempotencyKey,
|
|
603
629
|
interval: to.interval,
|
|
604
630
|
limit: to.limits.organization.actions,
|
|
631
|
+
meter,
|
|
605
632
|
metadata,
|
|
606
633
|
name: "actions",
|
|
607
634
|
overage: to.overages.actions,
|
|
@@ -621,8 +648,7 @@ var require_subscription = __commonJS({
|
|
|
621
648
|
price: actions.price
|
|
622
649
|
}
|
|
623
650
|
],
|
|
624
|
-
metadata
|
|
625
|
-
billing_cycle_anchor: billingCycleAnchor || "now"
|
|
651
|
+
metadata
|
|
626
652
|
},
|
|
627
653
|
idem(idempotencyKey, "subscription.create")
|
|
628
654
|
);
|
package/dist/index.mjs
CHANGED
|
@@ -330,10 +330,34 @@ var require_subscription = __commonJS({
|
|
|
330
330
|
};
|
|
331
331
|
const createMeter = async ({
|
|
332
332
|
idempotencyKey,
|
|
333
|
+
meter: existing,
|
|
333
334
|
metadata,
|
|
334
335
|
name
|
|
335
336
|
}) => {
|
|
336
337
|
const usage = (metadata == null ? void 0 : metadata.organization) + "_usage_" + name;
|
|
338
|
+
if (existing) {
|
|
339
|
+
const meter2 = await stripe.billing.meters.retrieve(existing).catch(() => null);
|
|
340
|
+
if ((meter2 == null ? void 0 : meter2.status) === "active" && (meter2 == null ? void 0 : meter2.event_name) === usage) {
|
|
341
|
+
return {
|
|
342
|
+
meter: meter2.id,
|
|
343
|
+
usage
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
;
|
|
347
|
+
}
|
|
348
|
+
;
|
|
349
|
+
for await (const meter2 of stripe.billing.meters.list({
|
|
350
|
+
status: "active"
|
|
351
|
+
})) {
|
|
352
|
+
if ((meter2 == null ? void 0 : meter2.event_name) === usage) {
|
|
353
|
+
return {
|
|
354
|
+
meter: meter2.id,
|
|
355
|
+
usage
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
;
|
|
359
|
+
}
|
|
360
|
+
;
|
|
337
361
|
const meter = await stripe.billing.meters.create(
|
|
338
362
|
{
|
|
339
363
|
default_aggregation: {
|
|
@@ -405,6 +429,7 @@ var require_subscription = __commonJS({
|
|
|
405
429
|
idempotencyKey,
|
|
406
430
|
interval,
|
|
407
431
|
limit,
|
|
432
|
+
meter: existing,
|
|
408
433
|
metadata,
|
|
409
434
|
name,
|
|
410
435
|
overage,
|
|
@@ -414,6 +439,7 @@ var require_subscription = __commonJS({
|
|
|
414
439
|
const response = {};
|
|
415
440
|
const { meter, usage } = await createMeter({
|
|
416
441
|
idempotencyKey,
|
|
442
|
+
meter: existing,
|
|
417
443
|
metadata,
|
|
418
444
|
name
|
|
419
445
|
});
|
|
@@ -593,10 +619,10 @@ var require_subscription = __commonJS({
|
|
|
593
619
|
}
|
|
594
620
|
},
|
|
595
621
|
create: async ({
|
|
596
|
-
billingCycleAnchor,
|
|
597
622
|
customer,
|
|
598
623
|
discounts = [],
|
|
599
624
|
idempotencyKey,
|
|
625
|
+
meter,
|
|
600
626
|
metadata,
|
|
601
627
|
stripePaymentMethodId,
|
|
602
628
|
to
|
|
@@ -608,6 +634,7 @@ var require_subscription = __commonJS({
|
|
|
608
634
|
idempotencyKey,
|
|
609
635
|
interval: to.interval,
|
|
610
636
|
limit: to.limits.organization.actions,
|
|
637
|
+
meter,
|
|
611
638
|
metadata,
|
|
612
639
|
name: "actions",
|
|
613
640
|
overage: to.overages.actions,
|
|
@@ -627,8 +654,7 @@ var require_subscription = __commonJS({
|
|
|
627
654
|
price: actions.price
|
|
628
655
|
}
|
|
629
656
|
],
|
|
630
|
-
metadata
|
|
631
|
-
billing_cycle_anchor: billingCycleAnchor || "now"
|
|
657
|
+
metadata
|
|
632
658
|
},
|
|
633
659
|
idem(idempotencyKey, "subscription.create")
|
|
634
660
|
);
|
package/package.json
CHANGED