@drawbridge/drawbridge-stripe 0.1.14 → 0.1.15
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 +32 -28
- package/dist/index.mjs +32 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35,27 +35,29 @@ var require_billing = __commonJS({
|
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
const billableItems = async () => {
|
|
38
|
-
var _a
|
|
38
|
+
var _a;
|
|
39
39
|
try {
|
|
40
|
-
const items = [];
|
|
41
40
|
const { data: components } = await axios.get(
|
|
42
41
|
billing + "/pricing_plans/" + process.env.STRIPE_PRICING_AI_PLAN_ID + "/components",
|
|
43
42
|
options
|
|
44
43
|
);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
const rateCardIds = ((components == null ? void 0 : components.data) || []).map((plan) => {
|
|
45
|
+
var _a2;
|
|
46
|
+
return (_a2 = plan == null ? void 0 : plan.rate_card) == null ? void 0 : _a2.id;
|
|
47
|
+
}).filter(Boolean);
|
|
48
|
+
const rateResults = await Promise.all(
|
|
49
|
+
rateCardIds.map((id) => axios.get(
|
|
50
|
+
billing + "/rate_cards/" + id + "/rates",
|
|
51
|
+
options
|
|
52
|
+
))
|
|
53
|
+
);
|
|
54
|
+
const items = [];
|
|
55
|
+
for (const { data: rates } of rateResults) {
|
|
56
|
+
for (const element of (rates == null ? void 0 : rates.data) || []) {
|
|
57
|
+
if ((_a = element == null ? void 0 : element.metered_item) == null ? void 0 : _a.id) {
|
|
58
|
+
items.push({
|
|
59
|
+
id: element.metered_item.id
|
|
60
|
+
});
|
|
59
61
|
}
|
|
60
62
|
;
|
|
61
63
|
}
|
|
@@ -262,28 +264,30 @@ var require_billing = __commonJS({
|
|
|
262
264
|
const model = [rest == null ? void 0 : rest.provider, rest == null ? void 0 : rest.model].join("/");
|
|
263
265
|
const input = Number(metadata == null ? void 0 : metadata.promptTokenCount);
|
|
264
266
|
const output = parseInt(Number(metadata == null ? void 0 : metadata.totalTokenCount) - input);
|
|
265
|
-
|
|
267
|
+
const sendMeterEvent = (token_type, value) => {
|
|
266
268
|
stripe2.billing.meterEvents.create({
|
|
267
269
|
event_name,
|
|
268
270
|
payload: {
|
|
269
271
|
model,
|
|
270
272
|
stripe_customer_id: customer,
|
|
271
|
-
token_type
|
|
272
|
-
value
|
|
273
|
+
token_type,
|
|
274
|
+
value
|
|
273
275
|
}
|
|
276
|
+
}).catch((error) => {
|
|
277
|
+
console.error("[billing.usage] meterEvents.create failed", {
|
|
278
|
+
customer,
|
|
279
|
+
token_type,
|
|
280
|
+
value,
|
|
281
|
+
error: error == null ? void 0 : error.message
|
|
282
|
+
});
|
|
274
283
|
});
|
|
284
|
+
};
|
|
285
|
+
if (input) {
|
|
286
|
+
sendMeterEvent("input", input);
|
|
275
287
|
}
|
|
276
288
|
;
|
|
277
289
|
if (output) {
|
|
278
|
-
|
|
279
|
-
event_name,
|
|
280
|
-
payload: {
|
|
281
|
-
model,
|
|
282
|
-
stripe_customer_id: customer,
|
|
283
|
-
token_type: "output",
|
|
284
|
-
value: output
|
|
285
|
-
}
|
|
286
|
-
});
|
|
290
|
+
sendMeterEvent("output", output);
|
|
287
291
|
}
|
|
288
292
|
;
|
|
289
293
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -41,27 +41,29 @@ var require_billing = __commonJS({
|
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
43
|
const billableItems = async () => {
|
|
44
|
-
var _a
|
|
44
|
+
var _a;
|
|
45
45
|
try {
|
|
46
|
-
const items = [];
|
|
47
46
|
const { data: components } = await axios.get(
|
|
48
47
|
billing + "/pricing_plans/" + process.env.STRIPE_PRICING_AI_PLAN_ID + "/components",
|
|
49
48
|
options
|
|
50
49
|
);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
50
|
+
const rateCardIds = ((components == null ? void 0 : components.data) || []).map((plan) => {
|
|
51
|
+
var _a2;
|
|
52
|
+
return (_a2 = plan == null ? void 0 : plan.rate_card) == null ? void 0 : _a2.id;
|
|
53
|
+
}).filter(Boolean);
|
|
54
|
+
const rateResults = await Promise.all(
|
|
55
|
+
rateCardIds.map((id) => axios.get(
|
|
56
|
+
billing + "/rate_cards/" + id + "/rates",
|
|
57
|
+
options
|
|
58
|
+
))
|
|
59
|
+
);
|
|
60
|
+
const items = [];
|
|
61
|
+
for (const { data: rates } of rateResults) {
|
|
62
|
+
for (const element of (rates == null ? void 0 : rates.data) || []) {
|
|
63
|
+
if ((_a = element == null ? void 0 : element.metered_item) == null ? void 0 : _a.id) {
|
|
64
|
+
items.push({
|
|
65
|
+
id: element.metered_item.id
|
|
66
|
+
});
|
|
65
67
|
}
|
|
66
68
|
;
|
|
67
69
|
}
|
|
@@ -268,28 +270,30 @@ var require_billing = __commonJS({
|
|
|
268
270
|
const model = [rest == null ? void 0 : rest.provider, rest == null ? void 0 : rest.model].join("/");
|
|
269
271
|
const input = Number(metadata == null ? void 0 : metadata.promptTokenCount);
|
|
270
272
|
const output = parseInt(Number(metadata == null ? void 0 : metadata.totalTokenCount) - input);
|
|
271
|
-
|
|
273
|
+
const sendMeterEvent = (token_type, value) => {
|
|
272
274
|
stripe.billing.meterEvents.create({
|
|
273
275
|
event_name,
|
|
274
276
|
payload: {
|
|
275
277
|
model,
|
|
276
278
|
stripe_customer_id: customer,
|
|
277
|
-
token_type
|
|
278
|
-
value
|
|
279
|
+
token_type,
|
|
280
|
+
value
|
|
279
281
|
}
|
|
282
|
+
}).catch((error) => {
|
|
283
|
+
console.error("[billing.usage] meterEvents.create failed", {
|
|
284
|
+
customer,
|
|
285
|
+
token_type,
|
|
286
|
+
value,
|
|
287
|
+
error: error == null ? void 0 : error.message
|
|
288
|
+
});
|
|
280
289
|
});
|
|
290
|
+
};
|
|
291
|
+
if (input) {
|
|
292
|
+
sendMeterEvent("input", input);
|
|
281
293
|
}
|
|
282
294
|
;
|
|
283
295
|
if (output) {
|
|
284
|
-
|
|
285
|
-
event_name,
|
|
286
|
-
payload: {
|
|
287
|
-
model,
|
|
288
|
-
stripe_customer_id: customer,
|
|
289
|
-
token_type: "output",
|
|
290
|
-
value: output
|
|
291
|
-
}
|
|
292
|
-
});
|
|
296
|
+
sendMeterEvent("output", output);
|
|
293
297
|
}
|
|
294
298
|
;
|
|
295
299
|
};
|
package/package.json
CHANGED