@drawbridge/drawbridge-stripe 0.1.1 → 0.1.3
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 +54 -26
- package/dist/index.mjs +54 -26
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -18,6 +18,39 @@ var require_billing = __commonJS({
|
|
|
18
18
|
"Stripe-Version": "2026-01-28.preview"
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
+
const billableItems = async () => {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f;
|
|
23
|
+
try {
|
|
24
|
+
const items = [];
|
|
25
|
+
const { data: components } = await axios.get(
|
|
26
|
+
billing + "/pricing_plans/" + process.env.STRIPE_PRICING_AI_PLAN_ID + "/components",
|
|
27
|
+
options
|
|
28
|
+
);
|
|
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
|
+
}
|
|
43
|
+
}
|
|
44
|
+
;
|
|
45
|
+
}
|
|
46
|
+
;
|
|
47
|
+
}
|
|
48
|
+
;
|
|
49
|
+
return items;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
21
54
|
const subscribe = async ({
|
|
22
55
|
currency,
|
|
23
56
|
customer,
|
|
@@ -80,22 +113,24 @@ var require_billing = __commonJS({
|
|
|
80
113
|
billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/actions",
|
|
81
114
|
options
|
|
82
115
|
);
|
|
116
|
+
const billable_items = await billableItems();
|
|
117
|
+
const filters = [
|
|
118
|
+
{
|
|
119
|
+
credit_grants: {
|
|
120
|
+
applicability_config: {
|
|
121
|
+
scope: {
|
|
122
|
+
billable_items
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
customer,
|
|
127
|
+
type: "customer"
|
|
128
|
+
}
|
|
129
|
+
];
|
|
83
130
|
const replenish = await stripe2.billing.alerts.create({
|
|
84
131
|
alert_type: "credit_balance_threshold",
|
|
85
132
|
credit_balance_threshold: {
|
|
86
|
-
filters
|
|
87
|
-
{
|
|
88
|
-
credit_grants: {
|
|
89
|
-
applicability_config: {
|
|
90
|
-
scope: {
|
|
91
|
-
price_type: "metered"
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
customer,
|
|
96
|
-
type: "customer"
|
|
97
|
-
}
|
|
98
|
-
],
|
|
133
|
+
filters,
|
|
99
134
|
lte: {
|
|
100
135
|
balance_type: "monetary",
|
|
101
136
|
monetary: {
|
|
@@ -110,19 +145,7 @@ var require_billing = __commonJS({
|
|
|
110
145
|
const depleted = await stripe2.billing.alerts.create({
|
|
111
146
|
alert_type: "credit_balance_threshold",
|
|
112
147
|
credit_balance_threshold: {
|
|
113
|
-
filters
|
|
114
|
-
{
|
|
115
|
-
credit_grants: {
|
|
116
|
-
applicability_config: {
|
|
117
|
-
scope: {
|
|
118
|
-
price_type: "metered"
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
customer,
|
|
123
|
-
type: "customer"
|
|
124
|
-
}
|
|
125
|
-
],
|
|
148
|
+
filters,
|
|
126
149
|
lte: {
|
|
127
150
|
balance_type: "monetary",
|
|
128
151
|
monetary: {
|
|
@@ -135,6 +158,10 @@ var require_billing = __commonJS({
|
|
|
135
158
|
title: customer + ".credit_balance_depleted"
|
|
136
159
|
});
|
|
137
160
|
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;
|
|
161
|
+
if (!stripePricingPlanSubscriptionId) {
|
|
162
|
+
throw new Error("Stripe billing intent did not return a pricing plan subscription ID for customer: " + customer);
|
|
163
|
+
}
|
|
164
|
+
;
|
|
138
165
|
return {
|
|
139
166
|
stripeAlerts: {
|
|
140
167
|
ai: {
|
|
@@ -221,6 +248,7 @@ var require_billing = __commonJS({
|
|
|
221
248
|
;
|
|
222
249
|
};
|
|
223
250
|
return {
|
|
251
|
+
billableItems,
|
|
224
252
|
subscribe,
|
|
225
253
|
unsubscribe,
|
|
226
254
|
usage
|
package/dist/index.mjs
CHANGED
|
@@ -24,6 +24,39 @@ var require_billing = __commonJS({
|
|
|
24
24
|
"Stripe-Version": "2026-01-28.preview"
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
+
const billableItems = async () => {
|
|
28
|
+
var _a, _b, _c, _d, _e, _f;
|
|
29
|
+
try {
|
|
30
|
+
const items = [];
|
|
31
|
+
const { data: components } = await axios.get(
|
|
32
|
+
billing + "/pricing_plans/" + process.env.STRIPE_PRICING_AI_PLAN_ID + "/components",
|
|
33
|
+
options
|
|
34
|
+
);
|
|
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
|
+
}
|
|
49
|
+
}
|
|
50
|
+
;
|
|
51
|
+
}
|
|
52
|
+
;
|
|
53
|
+
}
|
|
54
|
+
;
|
|
55
|
+
return items;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
27
60
|
const subscribe = async ({
|
|
28
61
|
currency,
|
|
29
62
|
customer,
|
|
@@ -86,22 +119,24 @@ var require_billing = __commonJS({
|
|
|
86
119
|
billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/actions",
|
|
87
120
|
options
|
|
88
121
|
);
|
|
122
|
+
const billable_items = await billableItems();
|
|
123
|
+
const filters = [
|
|
124
|
+
{
|
|
125
|
+
credit_grants: {
|
|
126
|
+
applicability_config: {
|
|
127
|
+
scope: {
|
|
128
|
+
billable_items
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
customer,
|
|
133
|
+
type: "customer"
|
|
134
|
+
}
|
|
135
|
+
];
|
|
89
136
|
const replenish = await stripe.billing.alerts.create({
|
|
90
137
|
alert_type: "credit_balance_threshold",
|
|
91
138
|
credit_balance_threshold: {
|
|
92
|
-
filters
|
|
93
|
-
{
|
|
94
|
-
credit_grants: {
|
|
95
|
-
applicability_config: {
|
|
96
|
-
scope: {
|
|
97
|
-
price_type: "metered"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
customer,
|
|
102
|
-
type: "customer"
|
|
103
|
-
}
|
|
104
|
-
],
|
|
139
|
+
filters,
|
|
105
140
|
lte: {
|
|
106
141
|
balance_type: "monetary",
|
|
107
142
|
monetary: {
|
|
@@ -116,19 +151,7 @@ var require_billing = __commonJS({
|
|
|
116
151
|
const depleted = await stripe.billing.alerts.create({
|
|
117
152
|
alert_type: "credit_balance_threshold",
|
|
118
153
|
credit_balance_threshold: {
|
|
119
|
-
filters
|
|
120
|
-
{
|
|
121
|
-
credit_grants: {
|
|
122
|
-
applicability_config: {
|
|
123
|
-
scope: {
|
|
124
|
-
price_type: "metered"
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
customer,
|
|
129
|
-
type: "customer"
|
|
130
|
-
}
|
|
131
|
-
],
|
|
154
|
+
filters,
|
|
132
155
|
lte: {
|
|
133
156
|
balance_type: "monetary",
|
|
134
157
|
monetary: {
|
|
@@ -141,6 +164,10 @@ var require_billing = __commonJS({
|
|
|
141
164
|
title: customer + ".credit_balance_depleted"
|
|
142
165
|
});
|
|
143
166
|
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;
|
|
167
|
+
if (!stripePricingPlanSubscriptionId) {
|
|
168
|
+
throw new Error("Stripe billing intent did not return a pricing plan subscription ID for customer: " + customer);
|
|
169
|
+
}
|
|
170
|
+
;
|
|
144
171
|
return {
|
|
145
172
|
stripeAlerts: {
|
|
146
173
|
ai: {
|
|
@@ -227,6 +254,7 @@ var require_billing = __commonJS({
|
|
|
227
254
|
;
|
|
228
255
|
};
|
|
229
256
|
return {
|
|
257
|
+
billableItems,
|
|
230
258
|
subscribe,
|
|
231
259
|
unsubscribe,
|
|
232
260
|
usage
|