@drawbridge/drawbridge-stripe 0.1.21 → 0.1.23
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 +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +108 -15
- package/dist/index.mjs +93 -0
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { request } = require( '@drawbridge/drawbridge-utils/http' );
|
|
2
|
+
|
|
1
3
|
const lib = require( './lib' );
|
|
2
4
|
const stripe = require( 'stripe' )(
|
|
3
5
|
process.env.STRIPE_API_KEY,
|
|
@@ -10,6 +12,9 @@ module.exports = {
|
|
|
10
12
|
billing : lib.billing({
|
|
11
13
|
stripe
|
|
12
14
|
}),
|
|
15
|
+
fx : lib.fx({
|
|
16
|
+
request
|
|
17
|
+
}),
|
|
13
18
|
stripe,
|
|
14
19
|
subscription : lib.subscription({
|
|
15
20
|
stripe
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { request } = require( '@drawbridge/drawbridge-utils/http' );
|
|
2
|
+
|
|
1
3
|
const lib = require( './lib' );
|
|
2
4
|
const stripe = require( 'stripe' )(
|
|
3
5
|
process.env.STRIPE_API_KEY,
|
|
@@ -10,6 +12,9 @@ module.exports = {
|
|
|
10
12
|
billing : lib.billing({
|
|
11
13
|
stripe
|
|
12
14
|
}),
|
|
15
|
+
fx : lib.fx({
|
|
16
|
+
request
|
|
17
|
+
}),
|
|
13
18
|
stripe,
|
|
14
19
|
subscription : lib.subscription({
|
|
15
20
|
stripe
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __commonJS = (cb, mod) => function __require() {
|
|
|
6
6
|
// lib/billing.js
|
|
7
7
|
var require_billing = __commonJS({
|
|
8
8
|
"lib/billing.js"(exports2, module2) {
|
|
9
|
-
var { request } = require("@drawbridge/drawbridge-utils/http");
|
|
9
|
+
var { request: request2 } = require("@drawbridge/drawbridge-utils/http");
|
|
10
10
|
var billing = "https://api.stripe.com/v2/billing";
|
|
11
11
|
module2.exports = ({
|
|
12
12
|
stripe: stripe2
|
|
@@ -30,7 +30,7 @@ var require_billing = __commonJS({
|
|
|
30
30
|
};
|
|
31
31
|
const billableItems = async () => {
|
|
32
32
|
var _a;
|
|
33
|
-
const components = await
|
|
33
|
+
const components = await request2({
|
|
34
34
|
url: billing + "/pricing_plans/" + process.env.STRIPE_PRICING_AI_PLAN_ID + "/components",
|
|
35
35
|
headers
|
|
36
36
|
});
|
|
@@ -39,7 +39,7 @@ var require_billing = __commonJS({
|
|
|
39
39
|
return (_a2 = plan == null ? void 0 : plan.rate_card) == null ? void 0 : _a2.id;
|
|
40
40
|
}).filter(Boolean);
|
|
41
41
|
const rateResults = await Promise.all(
|
|
42
|
-
rateCardIds.map((id) =>
|
|
42
|
+
rateCardIds.map((id) => request2({
|
|
43
43
|
url: billing + "/rate_cards/" + id + "/rates",
|
|
44
44
|
headers
|
|
45
45
|
}))
|
|
@@ -76,7 +76,7 @@ var require_billing = __commonJS({
|
|
|
76
76
|
payer.billing_profile_data.default_payment_method = default_payment_method;
|
|
77
77
|
}
|
|
78
78
|
;
|
|
79
|
-
const intent = await
|
|
79
|
+
const intent = await request2({
|
|
80
80
|
method: "POST",
|
|
81
81
|
url: billing + "/intents",
|
|
82
82
|
headers: withIdem(idempotencyKey, "intent.create"),
|
|
@@ -105,19 +105,19 @@ var require_billing = __commonJS({
|
|
|
105
105
|
]
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
|
-
await
|
|
108
|
+
await request2({
|
|
109
109
|
method: "POST",
|
|
110
110
|
url: billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/reserve",
|
|
111
111
|
headers: withIdem(idempotencyKey, "intent.reserve"),
|
|
112
112
|
body: {}
|
|
113
113
|
});
|
|
114
|
-
await
|
|
114
|
+
await request2({
|
|
115
115
|
method: "POST",
|
|
116
116
|
url: billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/commit",
|
|
117
117
|
headers: withIdem(idempotencyKey, "intent.commit"),
|
|
118
118
|
body: {}
|
|
119
119
|
});
|
|
120
|
-
const actions = await
|
|
120
|
+
const actions = await request2({
|
|
121
121
|
url: billing + "/intents/" + (intent == null ? void 0 : intent.id) + "/actions",
|
|
122
122
|
headers
|
|
123
123
|
});
|
|
@@ -178,12 +178,12 @@ var require_billing = __commonJS({
|
|
|
178
178
|
;
|
|
179
179
|
let stripePricingPlanSubscriptionNextBillingDate;
|
|
180
180
|
if (!default_payment_method) {
|
|
181
|
-
const subscription = await
|
|
181
|
+
const subscription = await request2({
|
|
182
182
|
url: billing + "/pricing_plan_subscriptions/" + stripePricingPlanSubscriptionId,
|
|
183
183
|
headers
|
|
184
184
|
});
|
|
185
185
|
if (subscription == null ? void 0 : subscription.billing_cadence) {
|
|
186
|
-
const cadence = await
|
|
186
|
+
const cadence = await request2({
|
|
187
187
|
url: billing + "/cadences/" + subscription.billing_cadence,
|
|
188
188
|
headers
|
|
189
189
|
});
|
|
@@ -211,7 +211,7 @@ var require_billing = __commonJS({
|
|
|
211
211
|
id,
|
|
212
212
|
idempotencyKey
|
|
213
213
|
}) => {
|
|
214
|
-
const data = await
|
|
214
|
+
const data = await request2({
|
|
215
215
|
method: "POST",
|
|
216
216
|
url: billing + "/intents",
|
|
217
217
|
headers: withIdem(idempotencyKey, "intent.create"),
|
|
@@ -230,13 +230,13 @@ var require_billing = __commonJS({
|
|
|
230
230
|
]
|
|
231
231
|
}
|
|
232
232
|
});
|
|
233
|
-
await
|
|
233
|
+
await request2({
|
|
234
234
|
method: "POST",
|
|
235
235
|
url: billing + "/intents/" + (data == null ? void 0 : data.id) + "/reserve",
|
|
236
236
|
headers: withIdem(idempotencyKey, "intent.reserve"),
|
|
237
237
|
body: {}
|
|
238
238
|
});
|
|
239
|
-
const commit = await
|
|
239
|
+
const commit = await request2({
|
|
240
240
|
method: "POST",
|
|
241
241
|
url: billing + "/intents/" + (data == null ? void 0 : data.id) + "/commit",
|
|
242
242
|
headers: withIdem(idempotencyKey, "intent.commit"),
|
|
@@ -290,10 +290,43 @@ var require_billing = __commonJS({
|
|
|
290
290
|
}
|
|
291
291
|
});
|
|
292
292
|
|
|
293
|
+
// lib/fx.js
|
|
294
|
+
var require_fx = __commonJS({
|
|
295
|
+
"lib/fx.js"(exports2, module2) {
|
|
296
|
+
"use strict";
|
|
297
|
+
module2.exports = ({ request: request2 }) => ({
|
|
298
|
+
quote: async ({ from, to, lock = "five_minutes" }) => {
|
|
299
|
+
if (from === to) {
|
|
300
|
+
return { rate: 1, quoteId: null };
|
|
301
|
+
}
|
|
302
|
+
const auth = Buffer.from(process.env.STRIPE_API_KEY + ":").toString("base64");
|
|
303
|
+
const response = await request2({
|
|
304
|
+
body: {
|
|
305
|
+
to_currency: to,
|
|
306
|
+
"from_currencies[]": from,
|
|
307
|
+
lock_duration: lock
|
|
308
|
+
},
|
|
309
|
+
headers: {
|
|
310
|
+
"Authorization": "Basic " + auth,
|
|
311
|
+
"Stripe-Version": "2026-01-28.preview"
|
|
312
|
+
},
|
|
313
|
+
method: "POST",
|
|
314
|
+
type: "form",
|
|
315
|
+
url: "https://api.stripe.com/v1/fx_quotes"
|
|
316
|
+
});
|
|
317
|
+
return {
|
|
318
|
+
rate: response.rates[from].exchange_rate,
|
|
319
|
+
quoteId: response.id
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
293
326
|
// lib/subscription.js
|
|
294
327
|
var require_subscription = __commonJS({
|
|
295
328
|
"lib/subscription.js"(exports2, module2) {
|
|
296
|
-
var { request } = require("@drawbridge/drawbridge-utils/http");
|
|
329
|
+
var { request: request2 } = require("@drawbridge/drawbridge-utils/http");
|
|
297
330
|
var subscriptions = "https://api.stripe.com/v1/subscriptions";
|
|
298
331
|
module2.exports = ({
|
|
299
332
|
stripe: stripe2
|
|
@@ -686,7 +719,7 @@ var require_subscription = __commonJS({
|
|
|
686
719
|
idempotencyKey,
|
|
687
720
|
stripeSubscriptionId
|
|
688
721
|
}) => {
|
|
689
|
-
return await
|
|
722
|
+
return await request2({
|
|
690
723
|
method: "POST",
|
|
691
724
|
url: subscriptions + "/" + stripeSubscriptionId + "/pause",
|
|
692
725
|
type: "form",
|
|
@@ -708,7 +741,7 @@ var require_subscription = __commonJS({
|
|
|
708
741
|
idempotencyKey,
|
|
709
742
|
stripeSubscriptionId
|
|
710
743
|
}) => {
|
|
711
|
-
return await
|
|
744
|
+
return await request2({
|
|
712
745
|
method: "POST",
|
|
713
746
|
url: subscriptions + "/" + stripeSubscriptionId + "/resume",
|
|
714
747
|
type: "form",
|
|
@@ -974,6 +1007,60 @@ var require_subscription = __commonJS({
|
|
|
974
1007
|
;
|
|
975
1008
|
};
|
|
976
1009
|
return Promise.allSettled(items.map(deactivateOne));
|
|
1010
|
+
},
|
|
1011
|
+
// Pure read. Stripe-side safety-net discovery that complements the
|
|
1012
|
+
// structural deactivatableItems() pass: walks Stripe by
|
|
1013
|
+
// metadata.organization (prices/products via Search) and event_name
|
|
1014
|
+
// prefix (meters via list + client-side filter, since the Billing
|
|
1015
|
+
// Meters API has no Search endpoint and accepts no metadata). Returns
|
|
1016
|
+
// a grouped { prices, products, meters } object with id-only arrays
|
|
1017
|
+
// — caller logs the grouped object directly and flattens to feed the
|
|
1018
|
+
// existing deactivate({items}) path. Per-type try/catch keeps a
|
|
1019
|
+
// single-type Stripe outage from blocking the rest; the structured
|
|
1020
|
+
// pass already ran before this so the org-delete is never gated on
|
|
1021
|
+
// the sweep.
|
|
1022
|
+
findOrphanedItems: async ({
|
|
1023
|
+
organization
|
|
1024
|
+
}) => {
|
|
1025
|
+
var _a;
|
|
1026
|
+
const orphaned = {
|
|
1027
|
+
prices: [],
|
|
1028
|
+
products: [],
|
|
1029
|
+
meters: []
|
|
1030
|
+
};
|
|
1031
|
+
try {
|
|
1032
|
+
for await (const price of stripe2.prices.search({
|
|
1033
|
+
query: "metadata['organization']:'" + organization + "' AND active:'true'"
|
|
1034
|
+
})) {
|
|
1035
|
+
orphaned.prices.push(price.id);
|
|
1036
|
+
}
|
|
1037
|
+
;
|
|
1038
|
+
} catch {
|
|
1039
|
+
}
|
|
1040
|
+
;
|
|
1041
|
+
try {
|
|
1042
|
+
for await (const product of stripe2.products.search({
|
|
1043
|
+
query: "metadata['organization']:'" + organization + "' AND active:'true'"
|
|
1044
|
+
})) {
|
|
1045
|
+
orphaned.products.push(product.id);
|
|
1046
|
+
}
|
|
1047
|
+
;
|
|
1048
|
+
} catch {
|
|
1049
|
+
}
|
|
1050
|
+
;
|
|
1051
|
+
try {
|
|
1052
|
+
const prefix = organization + "_usage_";
|
|
1053
|
+
for await (const meter of stripe2.billing.meters.list({ status: "active" })) {
|
|
1054
|
+
if ((_a = meter == null ? void 0 : meter.event_name) == null ? void 0 : _a.startsWith(prefix)) {
|
|
1055
|
+
orphaned.meters.push(meter.id);
|
|
1056
|
+
}
|
|
1057
|
+
;
|
|
1058
|
+
}
|
|
1059
|
+
;
|
|
1060
|
+
} catch {
|
|
1061
|
+
}
|
|
1062
|
+
;
|
|
1063
|
+
return orphaned;
|
|
977
1064
|
}
|
|
978
1065
|
};
|
|
979
1066
|
};
|
|
@@ -984,15 +1071,18 @@ var require_subscription = __commonJS({
|
|
|
984
1071
|
var require_lib = __commonJS({
|
|
985
1072
|
"lib/index.js"(exports2, module2) {
|
|
986
1073
|
var billing = require_billing();
|
|
1074
|
+
var fx = require_fx();
|
|
987
1075
|
var subscription = require_subscription();
|
|
988
1076
|
module2.exports = {
|
|
989
1077
|
billing,
|
|
1078
|
+
fx,
|
|
990
1079
|
subscription
|
|
991
1080
|
};
|
|
992
1081
|
}
|
|
993
1082
|
});
|
|
994
1083
|
|
|
995
1084
|
// index.js
|
|
1085
|
+
var { request } = require("@drawbridge/drawbridge-utils/http");
|
|
996
1086
|
var lib = require_lib();
|
|
997
1087
|
var stripe = require("stripe")(
|
|
998
1088
|
process.env.STRIPE_API_KEY,
|
|
@@ -1004,6 +1094,9 @@ module.exports = {
|
|
|
1004
1094
|
billing: lib.billing({
|
|
1005
1095
|
stripe
|
|
1006
1096
|
}),
|
|
1097
|
+
fx: lib.fx({
|
|
1098
|
+
request
|
|
1099
|
+
}),
|
|
1007
1100
|
stripe,
|
|
1008
1101
|
subscription: lib.subscription({
|
|
1009
1102
|
stripe
|
package/dist/index.mjs
CHANGED
|
@@ -296,6 +296,39 @@ var require_billing = __commonJS({
|
|
|
296
296
|
}
|
|
297
297
|
});
|
|
298
298
|
|
|
299
|
+
// lib/fx.js
|
|
300
|
+
var require_fx = __commonJS({
|
|
301
|
+
"lib/fx.js"(exports, module) {
|
|
302
|
+
"use strict";
|
|
303
|
+
module.exports = ({ request }) => ({
|
|
304
|
+
quote: async ({ from, to, lock = "five_minutes" }) => {
|
|
305
|
+
if (from === to) {
|
|
306
|
+
return { rate: 1, quoteId: null };
|
|
307
|
+
}
|
|
308
|
+
const auth = Buffer.from(process.env.STRIPE_API_KEY + ":").toString("base64");
|
|
309
|
+
const response = await request({
|
|
310
|
+
body: {
|
|
311
|
+
to_currency: to,
|
|
312
|
+
"from_currencies[]": from,
|
|
313
|
+
lock_duration: lock
|
|
314
|
+
},
|
|
315
|
+
headers: {
|
|
316
|
+
"Authorization": "Basic " + auth,
|
|
317
|
+
"Stripe-Version": "2026-01-28.preview"
|
|
318
|
+
},
|
|
319
|
+
method: "POST",
|
|
320
|
+
type: "form",
|
|
321
|
+
url: "https://api.stripe.com/v1/fx_quotes"
|
|
322
|
+
});
|
|
323
|
+
return {
|
|
324
|
+
rate: response.rates[from].exchange_rate,
|
|
325
|
+
quoteId: response.id
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
299
332
|
// lib/subscription.js
|
|
300
333
|
var require_subscription = __commonJS({
|
|
301
334
|
"lib/subscription.js"(exports, module) {
|
|
@@ -980,6 +1013,60 @@ var require_subscription = __commonJS({
|
|
|
980
1013
|
;
|
|
981
1014
|
};
|
|
982
1015
|
return Promise.allSettled(items.map(deactivateOne));
|
|
1016
|
+
},
|
|
1017
|
+
// Pure read. Stripe-side safety-net discovery that complements the
|
|
1018
|
+
// structural deactivatableItems() pass: walks Stripe by
|
|
1019
|
+
// metadata.organization (prices/products via Search) and event_name
|
|
1020
|
+
// prefix (meters via list + client-side filter, since the Billing
|
|
1021
|
+
// Meters API has no Search endpoint and accepts no metadata). Returns
|
|
1022
|
+
// a grouped { prices, products, meters } object with id-only arrays
|
|
1023
|
+
// — caller logs the grouped object directly and flattens to feed the
|
|
1024
|
+
// existing deactivate({items}) path. Per-type try/catch keeps a
|
|
1025
|
+
// single-type Stripe outage from blocking the rest; the structured
|
|
1026
|
+
// pass already ran before this so the org-delete is never gated on
|
|
1027
|
+
// the sweep.
|
|
1028
|
+
findOrphanedItems: async ({
|
|
1029
|
+
organization
|
|
1030
|
+
}) => {
|
|
1031
|
+
var _a;
|
|
1032
|
+
const orphaned = {
|
|
1033
|
+
prices: [],
|
|
1034
|
+
products: [],
|
|
1035
|
+
meters: []
|
|
1036
|
+
};
|
|
1037
|
+
try {
|
|
1038
|
+
for await (const price of stripe.prices.search({
|
|
1039
|
+
query: "metadata['organization']:'" + organization + "' AND active:'true'"
|
|
1040
|
+
})) {
|
|
1041
|
+
orphaned.prices.push(price.id);
|
|
1042
|
+
}
|
|
1043
|
+
;
|
|
1044
|
+
} catch {
|
|
1045
|
+
}
|
|
1046
|
+
;
|
|
1047
|
+
try {
|
|
1048
|
+
for await (const product of stripe.products.search({
|
|
1049
|
+
query: "metadata['organization']:'" + organization + "' AND active:'true'"
|
|
1050
|
+
})) {
|
|
1051
|
+
orphaned.products.push(product.id);
|
|
1052
|
+
}
|
|
1053
|
+
;
|
|
1054
|
+
} catch {
|
|
1055
|
+
}
|
|
1056
|
+
;
|
|
1057
|
+
try {
|
|
1058
|
+
const prefix = organization + "_usage_";
|
|
1059
|
+
for await (const meter of stripe.billing.meters.list({ status: "active" })) {
|
|
1060
|
+
if ((_a = meter == null ? void 0 : meter.event_name) == null ? void 0 : _a.startsWith(prefix)) {
|
|
1061
|
+
orphaned.meters.push(meter.id);
|
|
1062
|
+
}
|
|
1063
|
+
;
|
|
1064
|
+
}
|
|
1065
|
+
;
|
|
1066
|
+
} catch {
|
|
1067
|
+
}
|
|
1068
|
+
;
|
|
1069
|
+
return orphaned;
|
|
983
1070
|
}
|
|
984
1071
|
};
|
|
985
1072
|
};
|
|
@@ -990,9 +1077,11 @@ var require_subscription = __commonJS({
|
|
|
990
1077
|
var require_lib = __commonJS({
|
|
991
1078
|
"lib/index.js"(exports, module) {
|
|
992
1079
|
var billing = require_billing();
|
|
1080
|
+
var fx = require_fx();
|
|
993
1081
|
var subscription = require_subscription();
|
|
994
1082
|
module.exports = {
|
|
995
1083
|
billing,
|
|
1084
|
+
fx,
|
|
996
1085
|
subscription
|
|
997
1086
|
};
|
|
998
1087
|
}
|
|
@@ -1001,6 +1090,7 @@ var require_lib = __commonJS({
|
|
|
1001
1090
|
// index.js
|
|
1002
1091
|
var require_index = __commonJS({
|
|
1003
1092
|
"index.js"(exports, module) {
|
|
1093
|
+
var { request } = __require("@drawbridge/drawbridge-utils/http");
|
|
1004
1094
|
var lib = require_lib();
|
|
1005
1095
|
var stripe = __require("stripe")(
|
|
1006
1096
|
process.env.STRIPE_API_KEY,
|
|
@@ -1012,6 +1102,9 @@ var require_index = __commonJS({
|
|
|
1012
1102
|
billing: lib.billing({
|
|
1013
1103
|
stripe
|
|
1014
1104
|
}),
|
|
1105
|
+
fx: lib.fx({
|
|
1106
|
+
request
|
|
1107
|
+
}),
|
|
1015
1108
|
stripe,
|
|
1016
1109
|
subscription: lib.subscription({
|
|
1017
1110
|
stripe
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@drawbridge/drawbridge-agents": "0.0.
|
|
4
|
-
"@drawbridge/drawbridge-utils": "0.0.
|
|
3
|
+
"@drawbridge/drawbridge-agents": "0.0.10",
|
|
4
|
+
"@drawbridge/drawbridge-utils": "0.0.26",
|
|
5
5
|
"stripe": "20.4.0",
|
|
6
6
|
"tsup": "8.5.1",
|
|
7
7
|
"typescript": "5.9.3"
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"build": "tsup ./index.js && npm publish"
|
|
27
27
|
},
|
|
28
28
|
"types": "dist/index.d.ts",
|
|
29
|
-
"version": "0.1.
|
|
29
|
+
"version": "0.1.23"
|
|
30
30
|
}
|