codebuff 1.0.142 → 1.0.143
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/README.md +1 -1
- package/dist/chat-storage.js +7 -17
- package/dist/chat-storage.js.map +1 -1
- package/dist/cli.js +7 -17
- package/dist/cli.js.map +1 -1
- package/dist/client.js +7 -17
- package/dist/client.js.map +1 -1
- package/dist/code-map/languages.js +7 -17
- package/dist/code-map/languages.js.map +1 -1
- package/dist/code-map/parse.js +7 -17
- package/dist/code-map/parse.js.map +1 -1
- package/dist/code-map/tsconfig.tsbuildinfo +1 -1
- package/dist/common/actions.d.ts +3 -3
- package/dist/common/billing/payment-guards.d.ts +11 -0
- package/dist/common/billing/payment-guards.js +136 -0
- package/dist/common/billing/payment-guards.js.map +1 -0
- package/dist/common/billing/subscription-state.d.ts +13 -0
- package/dist/common/billing/subscription-state.js +117 -0
- package/dist/common/billing/subscription-state.js.map +1 -0
- package/dist/common/billing/webhook-processor.d.ts +21 -0
- package/dist/common/billing/webhook-processor.js +315 -0
- package/dist/common/billing/webhook-processor.js.map +1 -0
- package/dist/common/constants.d.ts +1 -1
- package/dist/common/constants.js +3 -3
- package/dist/common/constants.js.map +1 -1
- package/dist/common/scripts/get-invoices.d.ts +1 -0
- package/dist/common/scripts/get-invoices.js +5 -0
- package/dist/common/scripts/get-invoices.js.map +1 -0
- package/dist/common/scripts/get-month-overage.d.ts +1 -0
- package/dist/common/scripts/get-month-overage.js +5 -0
- package/dist/common/scripts/get-month-overage.js.map +1 -0
- package/dist/common/scripts/get-upcoming-invoices.d.ts +1 -0
- package/dist/common/scripts/get-upcoming-invoices.js +5 -0
- package/dist/common/scripts/get-upcoming-invoices.js.map +1 -0
- package/dist/common/scripts/update-subscriptions.d.ts +1 -0
- package/dist/common/scripts/update-subscriptions.js +92 -0
- package/dist/common/scripts/update-subscriptions.js.map +1 -0
- package/dist/common/types/usage.d.ts +2 -2
- package/dist/common/util/credentials.d.ts +2 -2
- package/dist/common/util/get-customer-invoices.d.ts +11 -0
- package/dist/common/util/get-customer-invoices.js +117 -0
- package/dist/common/util/get-customer-invoices.js.map +1 -0
- package/dist/common/util/get-month-overage.d.ts +11 -0
- package/dist/common/util/get-month-overage.js +143 -0
- package/dist/common/util/get-month-overage.js.map +1 -0
- package/dist/common/util/get-upcoming-invoices.d.ts +11 -0
- package/dist/common/util/get-upcoming-invoices.js +141 -0
- package/dist/common/util/get-upcoming-invoices.js.map +1 -0
- package/dist/common/websockets/logger-interface.d.ts +6 -0
- package/dist/common/websockets/logger-interface.js +9 -0
- package/dist/common/websockets/logger-interface.js.map +1 -0
- package/dist/common/websockets/websocket-schema.d.ts +10 -10
- package/dist/index.js +17 -6
- package/dist/index.js.map +1 -1
- package/dist/menu.js +8 -18
- package/dist/menu.js.map +1 -1
- package/dist/project-files.js +7 -17
- package/dist/project-files.js.map +1 -1
- package/dist/utils/terminal.js +7 -17
- package/dist/utils/terminal.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook-processor.js","sourceRoot":"","sources":["../../src/billing/webhook-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6C;AAC7C,+CAAsB;AACtB,qDAAsC;AACtC,6CAA8C;AAC9C,6BAAuB;AAEvB,6DAAkF;AAClF,mDAA8C;AAC9C,qDAAgD;AAEhD,MAAM,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,OAAC,CAAC,MAAM,CAAC;QACb,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC;KAC1B,CAAC;CACH,CAAC,CAAA;AAEF,MAAa,gBAAgB;IACP;IAAiC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,gBAAE,EACA,IAAA,gBAAE,EAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAC/C,IAAA,gBAAE,EAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAChD,CACF;aACA,KAAK,CAAC,IAAA,gBAAE,EAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;aACrD,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAE1B,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAA;IAC9B,CAAC;IAEO,eAAe,CAAC,MAAc;QACpC,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,QAAQ;gBACX,OAAO,QAAQ,CAAA;YACjB,KAAK,UAAU;gBACb,OAAO,UAAU,CAAA;YACnB,KAAK,YAAY;gBACf,OAAO,YAAY,CAAA;YACrB,KAAK,UAAU;gBACb,OAAO,UAAU,CAAA;YACnB,KAAK,UAAU;gBACb,OAAO,UAAU,CAAA;YACnB,KAAK,QAAQ;gBACX,OAAO,QAAQ,CAAA;YACjB;gBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,MAAM,EAAE,CAAC,CAAA;QACvD,CAAC;IACH,CAAC;CACF;AAhVD,4CAgVC"}
|
|
@@ -28,7 +28,7 @@ export declare const UsageLimits: {
|
|
|
28
28
|
export type UsageLimits = (typeof UsageLimits)[keyof typeof UsageLimits];
|
|
29
29
|
export declare const PLAN_CONFIGS: Record<UsageLimits, PlanConfig>;
|
|
30
30
|
export declare const CREDITS_USAGE_LIMITS: Record<UsageLimits, number>;
|
|
31
|
-
export declare const costModes: readonly ["lite", "normal", "
|
|
31
|
+
export declare const costModes: readonly ["lite", "normal", "max"];
|
|
32
32
|
export type CostMode = (typeof costModes)[number];
|
|
33
33
|
export declare const getModelForMode: (costMode: CostMode, operation: "agent" | "file-requests" | "check-new-files") => "claude-3-5-sonnet-20241022" | "claude-3-5-haiku-20241022" | "gpt-4o-2024-08-06" | "gpt-4o-mini-2024-07-18";
|
|
34
34
|
export declare const claudeModels: {
|
package/dist/common/constants.js
CHANGED
|
@@ -122,7 +122,7 @@ exports.PLAN_CONFIGS = {
|
|
|
122
122
|
MOAR_PRO: {
|
|
123
123
|
limit: 27_500,
|
|
124
124
|
planName: exports.UsageLimits.MOAR_PRO,
|
|
125
|
-
displayName: 'Pro
|
|
125
|
+
displayName: 'Pro Plus',
|
|
126
126
|
monthlyPrice: 249,
|
|
127
127
|
overageRate: exports.OVERAGE_RATE_MOAR_PRO,
|
|
128
128
|
},
|
|
@@ -135,13 +135,13 @@ if (process.env.NEXT_PUBLIC_ENVIRONMENT === 'local') {
|
|
|
135
135
|
}
|
|
136
136
|
// Helper to get credits limit from a plan config
|
|
137
137
|
exports.CREDITS_USAGE_LIMITS = Object.fromEntries(Object.entries(exports.PLAN_CONFIGS).map(([key, config]) => [key, config.limit]));
|
|
138
|
-
exports.costModes = ['lite', 'normal', '
|
|
138
|
+
exports.costModes = ['lite', 'normal', 'max'];
|
|
139
139
|
const getModelForMode = (costMode, operation) => {
|
|
140
140
|
if (operation === 'agent') {
|
|
141
141
|
return costMode === 'lite' ? exports.claudeModels.haiku : exports.claudeModels.sonnet;
|
|
142
142
|
}
|
|
143
143
|
if (operation === 'file-requests') {
|
|
144
|
-
return costMode === '
|
|
144
|
+
return costMode === 'max' ? exports.claudeModels.sonnet : exports.claudeModels.haiku;
|
|
145
145
|
}
|
|
146
146
|
if (operation === 'check-new-files') {
|
|
147
147
|
return costMode === 'lite' ? exports.models.gpt4omini : exports.models.gpt4o;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,GAAG,GAAG,MAAM,CAAA;AAC1B,QAAA,iBAAiB,GAA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AAQ;QAC9B,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,GAAG,GAAG,MAAM,CAAA;AAC1B,QAAA,iBAAiB,GAAG,GAAG,GAAG,oBAAoB,CAAA;AAC9C,QAAA,kBAAkB,GAAG,GAAG,GAAG,cAAc,CAAA;AACzC,QAAA,oBAAoB,GAAG,oCAAoC,CAAA;AAE3D,QAAA,qBAAqB,GAAG;IACnC,MAAM;IACN,MAAM;IACN,QAAQ;IACR,KAAK;IACL,KAAK;IACL,SAAS;IACT,cAAc;IACd,MAAM;IACN,YAAY;IACZ,OAAO;IACP,aAAa;IACb,aAAa;IACb,aAAa;IACb,OAAO;IACP,WAAW;IACX,eAAe;IACf,aAAa;IACb,aAAa;IACb,OAAO;IACP,mBAAmB;IACnB,WAAW;CACZ,CAAA;AAEY,QAAA,yBAAyB,GAAG;IACvC,UAAU;IACV,MAAM;IACN,MAAM;IACN,SAAS;IACT,IAAI;IACJ,MAAM;IACN,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;IACL,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;IACL,OAAO;IACP,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;IACP,KAAK;IACL,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM;IACN,KAAK;IACL,KAAK;IACL,MAAM;IACN,MAAM;IACN,QAAQ;IACR,OAAO;IACP,MAAM;IACN,IAAI;IACJ,OAAO;IACP,SAAS;IACT,OAAO;CACR,CAAA;AAEY,QAAA,6BAA6B,GAAG,CAAC,CAAA;AACjC,QAAA,QAAQ,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,CAAA;AACnC,QAAA,mBAAmB,GAAG,EAAE,CAAA;AACxB,QAAA,gBAAgB,GAAG,IAAI,CAAA;AACvB,QAAA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I,SAAS,KAAK,iBAAiB,EAAE,CAAC;QACpC,OAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,cAAM,CAAC,SAAS,CAAC,CAAC,CAAC,cAAM,CAAC,KAAK,CAAA;IAC9D,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAA;AACpD,CAAC,CAAA;AAdY,QAAA,eAAe,mBAc3B;AAEY,QAAA,YAAY,GAAG;IAC1B,MAAM,EAAE,4BAA4B;IACpC,KAAK,EAAE,2BAA2B;CAC1B,CAAA;AAEG,QAAA,YAAY,GAAG;IAC1B,KAAK,EAAE,mBAAmB;IAC1B,SAAS,EAAE,wBAAwB;IACnC,EAAE,EAAE,IAAI;IACR,uBAAuB;CACf,CAAA;AAEG,QAAA,YAAY,GAAG;IAC1B,YAAY,EAAE,sBAAsB;CAC5B,CAAA;AAEG,QAAA,cAAc,GAAG;IAC5B,YAAY,EAAE,eAAe;CACrB,CAAA;AAEG,QAAA,MAAM,GAAG;IACpB,GAAG,oBAAY;IACf,GAAG,oBAAY;IACf,GAAG,oBAAY;IACf,GAAG,sBAAc;CACT,CAAA;AAEG,QAAA,YAAY,GAAG,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-invoices.js","sourceRoot":"","sources":["../../src/scripts/get-invoices.ts"],"names":[],"mappings":";;AAAA,yEAAoD;AAEpD,IAAA,4BAAI,GAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-month-overage.js","sourceRoot":"","sources":["../../src/scripts/get-month-overage.ts"],"names":[],"mappings":";;AAAA,iEAAgD;AAEhD,IAAA,wBAAI,GAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-upcoming-invoices.js","sourceRoot":"","sources":["../../src/scripts/get-upcoming-invoices.ts"],"names":[],"mappings":";;AAAA,yEAAoD;AAEpD,IAAA,4BAAI,GAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
30
|
+
const stripe_1 = require("../util/stripe");
|
|
31
|
+
const db_1 = __importDefault(require("../db"));
|
|
32
|
+
const schema = __importStar(require("../db/schema"));
|
|
33
|
+
async function main() {
|
|
34
|
+
const email = process.argv[2];
|
|
35
|
+
if (!email) {
|
|
36
|
+
console.error('Please provide an email address');
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
console.log(`Processing user ${email}...`);
|
|
40
|
+
// Find user and verify subscription
|
|
41
|
+
const user = await db_1.default.query.user.findFirst({
|
|
42
|
+
where: (0, drizzle_orm_1.eq)(schema.user.email, email),
|
|
43
|
+
});
|
|
44
|
+
if (!user?.stripe_customer_id) {
|
|
45
|
+
console.error('User not found or has no Stripe customer ID');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
console.log('Found user:', user.id);
|
|
49
|
+
// Get subscriptions for customer
|
|
50
|
+
const subscriptions = await stripe_1.stripeServer.subscriptions.list({
|
|
51
|
+
customer: user.stripe_customer_id,
|
|
52
|
+
status: 'active',
|
|
53
|
+
});
|
|
54
|
+
if (subscriptions.data.length === 0) {
|
|
55
|
+
console.error('No active subscription found');
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
const subscription = subscriptions.data[0];
|
|
59
|
+
console.log('Found subscription:', subscription.id);
|
|
60
|
+
// Update subscription items
|
|
61
|
+
console.log('Updating subscription items...');
|
|
62
|
+
await stripe_1.stripeServer.subscriptions.update(subscription.id, {
|
|
63
|
+
items: [
|
|
64
|
+
{ price: 'price_1QLxwxKrNS6SjmqWeKhJIlAD', quantity: 1 },
|
|
65
|
+
{ price: 'price_1QMlqaKrNS6SjmqWQEeaTcqk' },
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
// Calculate usage since Oct 30, 2024
|
|
69
|
+
const startDate = new Date('2024-10-30');
|
|
70
|
+
const creditsUsed = await db_1.default
|
|
71
|
+
.select({
|
|
72
|
+
total: (0, drizzle_orm_1.sql) `SUM(${schema.message.credits})`,
|
|
73
|
+
})
|
|
74
|
+
.from(schema.message)
|
|
75
|
+
.where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(schema.message.user_id, user.id), (0, drizzle_orm_1.gte)(schema.message.finished_at, startDate)))
|
|
76
|
+
.then((result) => parseInt(result[0]?.total ?? '0'));
|
|
77
|
+
console.log('Credits used since Oct 30, 2024:', creditsUsed);
|
|
78
|
+
// Report usage
|
|
79
|
+
const timestamp = Math.floor(startDate.getTime() / 1000);
|
|
80
|
+
await stripe_1.stripeServer.subscriptionItems.createUsageRecord(subscription.items.data[1].id, // Get the metered price item
|
|
81
|
+
{
|
|
82
|
+
quantity: creditsUsed,
|
|
83
|
+
timestamp,
|
|
84
|
+
action: 'set',
|
|
85
|
+
});
|
|
86
|
+
console.log('Successfully updated subscription and usage');
|
|
87
|
+
}
|
|
88
|
+
main().catch((error) => {
|
|
89
|
+
console.error('Error:', error);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=update-subscriptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-subscriptions.js","sourceRoot":"","sources":["../../src/scripts/update-subscriptions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+C;AAC/C,2CAA6C;AAC7C,+CAAsB;AACtB,qDAAsC;AAEtC,KAAK,UAAU,IAAI;IACjB,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAA;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,mBAAm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@@ -8,17 +8,17 @@ export declare const usageDataSchema: z.ZodObject<{
|
|
|
8
8
|
overageRate: z.ZodNullable<z.ZodNumber>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
10
|
creditsUsed: number;
|
|
11
|
+
overageRate: number | null;
|
|
11
12
|
totalQuota: number;
|
|
12
13
|
remainingCredits: number;
|
|
13
14
|
subscriptionActive: boolean;
|
|
14
15
|
nextQuotaReset: Date;
|
|
15
|
-
overageRate: number | null;
|
|
16
16
|
}, {
|
|
17
17
|
creditsUsed: number;
|
|
18
|
+
overageRate: number | null;
|
|
18
19
|
totalQuota: number;
|
|
19
20
|
remainingCredits: number;
|
|
20
21
|
subscriptionActive: boolean;
|
|
21
22
|
nextQuotaReset: Date;
|
|
22
|
-
overageRate: number | null;
|
|
23
23
|
}>;
|
|
24
24
|
export type UsageData = z.infer<typeof usageDataSchema>;
|
|
@@ -10,15 +10,15 @@ export declare const userSchema: z.ZodObject<{
|
|
|
10
10
|
email: string;
|
|
11
11
|
name: string | null;
|
|
12
12
|
id: string;
|
|
13
|
-
authToken: string;
|
|
14
13
|
fingerprintId: string;
|
|
14
|
+
authToken: string;
|
|
15
15
|
fingerprintHash: string;
|
|
16
16
|
}, {
|
|
17
17
|
email: string;
|
|
18
18
|
name: string | null;
|
|
19
19
|
id: string;
|
|
20
|
-
authToken: string;
|
|
21
20
|
fingerprintId: string;
|
|
21
|
+
authToken: string;
|
|
22
22
|
fingerprintHash: string;
|
|
23
23
|
}>;
|
|
24
24
|
export type User = z.infer<typeof userSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function getAllCustomersWithInvoices(): Promise<{
|
|
2
|
+
customerId: string;
|
|
3
|
+
email: string | null;
|
|
4
|
+
name: string | null;
|
|
5
|
+
lastInvoice: {
|
|
6
|
+
amount: number;
|
|
7
|
+
date: Date;
|
|
8
|
+
};
|
|
9
|
+
}[]>;
|
|
10
|
+
declare function main(): Promise<void>;
|
|
11
|
+
export { getAllCustomersWithInvoices, main };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllCustomersWithInvoices = getAllCustomersWithInvoices;
|
|
4
|
+
exports.main = main;
|
|
5
|
+
const ts_pattern_1 = require("ts-pattern");
|
|
6
|
+
const stripe_1 = require("./stripe");
|
|
7
|
+
const getCustomerId = (customer) => {
|
|
8
|
+
return (0, ts_pattern_1.match)(customer)
|
|
9
|
+
.with(
|
|
10
|
+
// string ID case
|
|
11
|
+
ts_pattern_1.P.string, (id) => id)
|
|
12
|
+
.with(
|
|
13
|
+
// Customer or DeletedCustomer case
|
|
14
|
+
{ object: 'customer' }, (customer) => customer.id)
|
|
15
|
+
.exhaustive();
|
|
16
|
+
};
|
|
17
|
+
// Track subscription status for each customer
|
|
18
|
+
const subscription_statuses = new Map();
|
|
19
|
+
async function getAllCustomersWithInvoices() {
|
|
20
|
+
const customers = [];
|
|
21
|
+
let hasMore = true;
|
|
22
|
+
let startingAfter = undefined;
|
|
23
|
+
// Iterate through all subscriptions using cursor pagination
|
|
24
|
+
while (hasMore) {
|
|
25
|
+
const result = await stripe_1.stripeServer.subscriptions.list({
|
|
26
|
+
limit: 100,
|
|
27
|
+
starting_after: startingAfter,
|
|
28
|
+
status: 'all',
|
|
29
|
+
expand: ['data.items'],
|
|
30
|
+
});
|
|
31
|
+
const { data, has_more } = result;
|
|
32
|
+
// Process each subscription
|
|
33
|
+
for (const subscription of data) {
|
|
34
|
+
// Skip if no metered items in subscription
|
|
35
|
+
const hasMeteredItem = subscription.items.data.some((item) => item.price.recurring?.usage_type === 'metered');
|
|
36
|
+
if (!hasMeteredItem) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const customerId = getCustomerId(subscription.customer);
|
|
41
|
+
const invoices = await stripe_1.stripeServer.invoices.list({
|
|
42
|
+
customer: customerId,
|
|
43
|
+
limit: 2, // Get 2 to verify they have more than one
|
|
44
|
+
status: 'paid',
|
|
45
|
+
});
|
|
46
|
+
const customer = await stripe_1.stripeServer.customers.retrieve(subscription.customer);
|
|
47
|
+
if (customer.deleted) {
|
|
48
|
+
console.log(`Customer ${customer.id} has been deleted, skipping`);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (invoices.data.length < 2) {
|
|
52
|
+
console.log(`Customer ${customer.email} has fewer than 2 paid invoices, skipping`);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const lastInvoice = invoices.data[0];
|
|
56
|
+
if (lastInvoice.amount_paid === 0) {
|
|
57
|
+
console.log(`Customer ${customer.email} paid $0 on last invoice, skipping`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
subscription_statuses.set(customer.id, {
|
|
61
|
+
cancelled: !!subscription.cancellation_details?.reason,
|
|
62
|
+
});
|
|
63
|
+
customers.push({
|
|
64
|
+
customerId: customer.id,
|
|
65
|
+
email: customer.email ?? null,
|
|
66
|
+
name: customer.name ?? null,
|
|
67
|
+
lastInvoice: {
|
|
68
|
+
amount: lastInvoice.amount_paid,
|
|
69
|
+
date: new Date(lastInvoice.created * 1000),
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.log(`Error getting invoice for subscription ${subscription.id}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
hasMore = has_more;
|
|
78
|
+
if (hasMore && data.length > 0) {
|
|
79
|
+
startingAfter = data[data.length - 1].id;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return customers;
|
|
83
|
+
}
|
|
84
|
+
// Example usage
|
|
85
|
+
async function main() {
|
|
86
|
+
try {
|
|
87
|
+
const customers = await getAllCustomersWithInvoices();
|
|
88
|
+
// Split into active and cancelled customers
|
|
89
|
+
const activeCustomers = customers.filter((c) => !subscription_statuses.get(c.customerId)?.cancelled);
|
|
90
|
+
const cancelledCustomers = customers.filter((c) => subscription_statuses.get(c.customerId)?.cancelled);
|
|
91
|
+
console.log('Active customers with past invoices:');
|
|
92
|
+
activeCustomers.forEach((customer) => {
|
|
93
|
+
console.log(`
|
|
94
|
+
Customer: ${customer.name} (${customer.email})
|
|
95
|
+
Last Invoice: ${(customer.lastInvoice.amount / 100).toFixed(2)} on ${customer.lastInvoice.date}
|
|
96
|
+
`);
|
|
97
|
+
});
|
|
98
|
+
console.log('\nCancelled customers with past invoices:');
|
|
99
|
+
cancelledCustomers.forEach((customer) => {
|
|
100
|
+
console.log(`
|
|
101
|
+
Customer: ${customer.name} (${customer.email})
|
|
102
|
+
Last Invoice: ${(customer.lastInvoice.amount / 100).toFixed(2)} on ${customer.lastInvoice.date}
|
|
103
|
+
`);
|
|
104
|
+
});
|
|
105
|
+
const total = customers.reduce((sum, customer) => sum + customer.lastInvoice.amount, 0);
|
|
106
|
+
const totalInDollars = total / 100; // Convert cents to dollars
|
|
107
|
+
const average = totalInDollars / customers.length || 0;
|
|
108
|
+
console.log(`\nTotal invoice amount (all customers): $${totalInDollars.toFixed(2)}`);
|
|
109
|
+
console.log(`Average invoice amount (all customers): $${average.toFixed(2)}`);
|
|
110
|
+
console.log(`Total active customers: ${activeCustomers.length}`);
|
|
111
|
+
console.log(`Total cancelled customers: ${cancelledCustomers.length}`);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error('Error fetching customer data:', error);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=get-customer-invoices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-customer-invoices.js","sourceRoot":"","sources":["../../src/util/get-customer-invoices.ts"],"names":[],"mappings":";;AAwKS,kEAA2B;AAAE,oBAAI;AAxK1C,2CAAqC;AAErC,qCAAuC;AAEvC,MAAM,aAAa,GAAG,CACpB,QAA2D,EAC3D,EAAE;IACF,OAAO,IAAA,kBAAK,EAAC,QAAQ,CAA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O,CAAC,CAAC,QAAQ,EAAE,EAAE;YACtC,OAAO,CAAC,GAAG,CAAC;YACN,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,KAAK;gBAC5B,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OACtD,QAAQ,CAAC,WAAW,CAAC,IACvB;CACL,CAAC,CAAA;QACE,CAAC,CAAC,CAAA;QAEF,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAC5B,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,GAAG,QAAQ,CAAC,WAAW,CAAC,MAAM,EACpD,CAAC,CACF,CAAA;QACD,MAAM,cAAc,GAAG,KAAK,GAAG,GAAG,CAAA,CAAC,2BAA2B;QAC9D,MAAM,OAAO,GAAG,cAAc,GAAG,SAAS,CAAC,MAAM,IAAI,CAAC,CAAA;QAEtD,OAAO,CAAC,GAAG,CACT,4CAA4C,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CACxE,CAAA;QACD,OAAO,CAAC,GAAG,CACT,4CAA4C,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CACjE,CAAA;QACD,OAAO,CAAC,GAAG,CAAC,2BAA2B,eAAe,CAAC,MAAM,EAAE,CAAC,CAAA;QAChE,OAAO,CAAC,GAAG,CAAC,8BAA8B,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAA;IACxE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAA;IACvD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function getAllMonthOverages(): Promise<{
|
|
2
|
+
customerId: string;
|
|
3
|
+
email: string | null;
|
|
4
|
+
name: string | null;
|
|
5
|
+
overageInvoice: {
|
|
6
|
+
amount: number;
|
|
7
|
+
date: Date;
|
|
8
|
+
};
|
|
9
|
+
}[]>;
|
|
10
|
+
declare function main(): Promise<void>;
|
|
11
|
+
export { getAllMonthOverages, main };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllMonthOverages = getAllMonthOverages;
|
|
4
|
+
exports.main = main;
|
|
5
|
+
const stripe_1 = require("./stripe");
|
|
6
|
+
const ts_pattern_1 = require("ts-pattern");
|
|
7
|
+
const getCustomerId = (customer) => {
|
|
8
|
+
return (0, ts_pattern_1.match)(customer)
|
|
9
|
+
.with(
|
|
10
|
+
// string ID case
|
|
11
|
+
ts_pattern_1.P.string, (id) => id)
|
|
12
|
+
.with(
|
|
13
|
+
// Customer or DeletedCustomer case
|
|
14
|
+
{ object: 'customer' }, (customer) => customer.id)
|
|
15
|
+
.exhaustive();
|
|
16
|
+
};
|
|
17
|
+
async function getAllMonthOverages() {
|
|
18
|
+
const customersWithOverage = [];
|
|
19
|
+
let hasMore = true;
|
|
20
|
+
let startingAfter = undefined;
|
|
21
|
+
// Iterate through all subscriptions using cursor pagination
|
|
22
|
+
while (hasMore) {
|
|
23
|
+
const result = await stripe_1.stripeServer.subscriptions.list({
|
|
24
|
+
limit: 100,
|
|
25
|
+
starting_after: startingAfter,
|
|
26
|
+
status: 'active',
|
|
27
|
+
expand: ['data.items'],
|
|
28
|
+
});
|
|
29
|
+
const { data, has_more } = result;
|
|
30
|
+
// Process each subscription
|
|
31
|
+
for (const subscription of data) {
|
|
32
|
+
// Check for metered items in subscription
|
|
33
|
+
const hasMeteredItem = subscription.items.data.some((item) => item.price.recurring?.usage_type === 'metered');
|
|
34
|
+
if (!hasMeteredItem) {
|
|
35
|
+
console.log(`Subscription ${subscription.id} has no metered items, skipping`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
console.log(`Found metered subscription: ${subscription.id}`);
|
|
39
|
+
try {
|
|
40
|
+
const customerId = getCustomerId(subscription.customer);
|
|
41
|
+
const customer = await stripe_1.stripeServer.customers.retrieve(subscription.customer);
|
|
42
|
+
if (customer.deleted) {
|
|
43
|
+
console.log(`Customer ${customer.id} has been deleted, skipping`);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
// Get upcoming invoice
|
|
47
|
+
const upcomingInvoice = await stripe_1.stripeServer.invoices.retrieveUpcoming({
|
|
48
|
+
customer: customerId,
|
|
49
|
+
subscription: subscription.id,
|
|
50
|
+
});
|
|
51
|
+
// Calculate metered items total from upcoming invoice
|
|
52
|
+
const meteredOverageItems = upcomingInvoice.lines.data
|
|
53
|
+
.filter(item => item.price?.recurring?.usage_type === 'metered');
|
|
54
|
+
console.log(`Customer ${customer.email}: Found ${meteredOverageItems.length} metered items in upcoming invoice`);
|
|
55
|
+
console.log(`Customer ${customer.email}: Metered items:`, meteredOverageItems.map(item => ({
|
|
56
|
+
amount: item.amount,
|
|
57
|
+
description: item.description,
|
|
58
|
+
period: item.period
|
|
59
|
+
})));
|
|
60
|
+
const monthlyOverageTotal = meteredOverageItems.reduce((sum, item) => sum + item.amount, 0);
|
|
61
|
+
if (monthlyOverageTotal > 0) {
|
|
62
|
+
console.log(`Customer ${customer.email}: Upcoming metered charges: $${(monthlyOverageTotal / 100).toFixed(2)}`);
|
|
63
|
+
customersWithOverage.push({
|
|
64
|
+
customerId: customer.id,
|
|
65
|
+
email: customer.email ?? null,
|
|
66
|
+
name: customer.name ?? null,
|
|
67
|
+
overageInvoice: {
|
|
68
|
+
amount: monthlyOverageTotal,
|
|
69
|
+
date: new Date(upcomingInvoice.period_end * 1000),
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// If no upcoming charges, check recent invoices
|
|
75
|
+
const oneMonthAgo = new Date();
|
|
76
|
+
oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1);
|
|
77
|
+
const recentInvoices = await stripe_1.stripeServer.invoices.list({
|
|
78
|
+
customer: customerId,
|
|
79
|
+
limit: 1,
|
|
80
|
+
status: 'paid',
|
|
81
|
+
created: {
|
|
82
|
+
gte: Math.floor(oneMonthAgo.getTime() / 1000),
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
if (recentInvoices.data.length > 0) {
|
|
86
|
+
const lastInvoice = recentInvoices.data[0];
|
|
87
|
+
const recentOverageItems = lastInvoice.lines.data
|
|
88
|
+
.filter(item => item.price?.recurring?.usage_type === 'metered');
|
|
89
|
+
console.log(`Customer ${customer.email}: Found ${recentOverageItems.length} metered items in recent invoice`);
|
|
90
|
+
console.log(`Customer ${customer.email}: Recent metered items:`, recentOverageItems.map(item => ({
|
|
91
|
+
amount: item.amount,
|
|
92
|
+
description: item.description,
|
|
93
|
+
period: item.period
|
|
94
|
+
})));
|
|
95
|
+
const recentOverageTotal = recentOverageItems.reduce((sum, item) => sum + item.amount, 0);
|
|
96
|
+
if (recentOverageTotal > 0) {
|
|
97
|
+
console.log(`Customer ${customer.email}: Recent metered charges: $${(recentOverageTotal / 100).toFixed(2)}`);
|
|
98
|
+
customersWithOverage.push({
|
|
99
|
+
customerId: customer.id,
|
|
100
|
+
email: customer.email ?? null,
|
|
101
|
+
name: customer.name ?? null,
|
|
102
|
+
overageInvoice: {
|
|
103
|
+
amount: recentOverageTotal,
|
|
104
|
+
date: new Date(lastInvoice.created * 1000),
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.log(`Error getting upcoming invoice for subscription ${subscription.id}:`, error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
hasMore = has_more;
|
|
116
|
+
if (hasMore && data.length > 0) {
|
|
117
|
+
startingAfter = data[data.length - 1].id;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return customersWithOverage;
|
|
121
|
+
}
|
|
122
|
+
async function main() {
|
|
123
|
+
try {
|
|
124
|
+
const customersWithOverage = await getAllMonthOverages();
|
|
125
|
+
console.log('Monthly overage charges:');
|
|
126
|
+
customersWithOverage.forEach((customer) => {
|
|
127
|
+
console.log(`
|
|
128
|
+
Customer: ${customer.name} (${customer.email})
|
|
129
|
+
Monthly Overage: $${(customer.overageInvoice.amount / 100).toFixed(2)} due on ${customer.overageInvoice.date}
|
|
130
|
+
`);
|
|
131
|
+
});
|
|
132
|
+
const totalOverage = customersWithOverage.reduce((sum, customer) => sum + customer.overageInvoice.amount, 0);
|
|
133
|
+
const totalOverageInDollars = totalOverage / 100;
|
|
134
|
+
const averageOverage = totalOverageInDollars / customersWithOverage.length || 0;
|
|
135
|
+
console.log(`\nTotal monthly overage: $${totalOverageInDollars.toFixed(2)}`);
|
|
136
|
+
console.log(`Average monthly overage: $${averageOverage.toFixed(2)}`);
|
|
137
|
+
console.log(`Total customers with overage charges: ${customersWithOverage.length}`);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error('Error fetching monthly overage data:', error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=get-month-overage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-month-overage.js","sourceRoot":"","sources":["../../src/util/get-month-overage.ts"],"names":[],"mappings":";;AAuLS,kDAAmB;AAAE,oBAAI;AAvLlC,qCAAuC;AAEvC,2CAAqC;AAErC,MAAM,aAAa,GAAG,CACpB,QAA2D,EAC3D,EAAE;IACF,OAAO,IAAA,kBAAK,EAAC,QAAQ,CAAC;SACnB,IAAI;IACH,iBAAiB;IACjB,cAAC,CAAC,MAAM,EACR,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CACX;SACA,IAAI;IACH,mCAAmC;IACnC,EAAE,MAAM,EAAE,UAAU,EAAE,EACtB,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAC1B;SACA,UAAU,EAAE,CAAA;AACjB,CAAC,CAAA;AAED,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AM,mBAAmB,EAAE,CAAA;QAExD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;QACvC,oBAAoB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YACxC,OAAO,CAAC,GAAG,CAAC;YACN,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,KAAK;oBACxB,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAC7D,QAAQ,CAAC,cAAc,CAAC,IAC1B;CACL,CAAC,CAAA;QACE,CAAC,CAAC,CAAA;QAEF,MAAM,YAAY,GAAG,oBAAoB,CAAC,MAAM,CAC9C,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,EACvD,CAAC,CACF,CAAA;QACD,MAAM,qBAAqB,GAAG,YAAY,GAAG,GAAG,CAAA;QAChD,MAAM,cAAc,GAAG,qBAAqB,GAAG,oBAAoB,CAAC,MAAM,IAAI,CAAC,CAAA;QAE/E,OAAO,CAAC,GAAG,CACT,6BAA6B,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAChE,CAAA;QACD,OAAO,CAAC,GAAG,CACT,6BAA6B,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CACzD,CAAA;QACD,OAAO,CAAC,GAAG,CAAC,yCAAyC,oBAAoB,CAAC,MAAM,EAAE,CAAC,CAAA;IACrF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAA;IAC9D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function getAllUpcomingInvoices(): Promise<{
|
|
2
|
+
customerId: string;
|
|
3
|
+
email: string | null;
|
|
4
|
+
name: string | null;
|
|
5
|
+
upcomingInvoice: {
|
|
6
|
+
amount: number;
|
|
7
|
+
date: Date;
|
|
8
|
+
};
|
|
9
|
+
}[]>;
|
|
10
|
+
declare function main(): Promise<void>;
|
|
11
|
+
export { getAllUpcomingInvoices, main };
|