Skip to content

Commit 095d74d

Browse files
committed
move stripe.ts from common to internal
1 parent cfcf577 commit 095d74d

File tree

16 files changed

+156
-156
lines changed

16 files changed

+156
-156
lines changed

backend/src/llm-apis/message-cost-tracker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
TEST_USER_ID,
99
} from '@codebuff/common/old-constants'
1010
import { withRetry } from '@codebuff/common/util/promise'
11-
import { stripeServer } from '@codebuff/common/util/stripe'
1211
import { logSyncFailure } from '@codebuff/common/util/sync-failure'
12+
import { stripeServer } from '@codebuff/internal/util/stripe'
1313
import { eq } from 'drizzle-orm'
1414
import Stripe from 'stripe'
1515
import { WebSocket } from 'ws'

packages/billing/src/auto-topup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as schema from '@codebuff/common/db/schema'
55
import { CREDIT_PRICING } from '@codebuff/common/old-constants'
66
import { convertCreditsToUsdCents } from '@codebuff/common/util/currency'
77
import { getNextQuotaReset } from '@codebuff/common/util/dates'
8-
import { stripeServer } from '@codebuff/common/util/stripe'
8+
import { stripeServer } from '@codebuff/internal/util/stripe'
99
import { eq } from 'drizzle-orm'
1010

1111
import { calculateUsageAndBalance } from './balance-calculator'

packages/billing/src/org-billing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import db from '@codebuff/common/db'
33
import * as schema from '@codebuff/common/db/schema'
44
import { withSerializableTransaction } from '@codebuff/common/db/transaction'
55
import { GrantTypeValues } from '@codebuff/common/types/grant'
6-
import { stripeServer } from '@codebuff/common/util/stripe'
6+
import { stripeServer } from '@codebuff/internal/util/stripe'
77
import { env } from '@codebuff/internal/env'
88
import { and, asc, gt, isNull, or, eq } from 'drizzle-orm'
99

scripts/calculate-average-spend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { stripeServer } from '@codebuff/common/util/stripe'
1+
import { stripeServer } from '@codebuff/internal/util/stripe'
22

33
import type Stripe from 'stripe'
44

scripts/calculate-mrr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { stripeServer } from '@codebuff/common/util/stripe'
1+
import { stripeServer } from '@codebuff/internal/util/stripe'
22

33
import type Stripe from 'stripe'
44

scripts/update-stripe-subscriptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { db } from '@codebuff/common/db'
44
import { eq } from 'drizzle-orm'
55

66
import * as schema from '../common/src/db/schema'
7-
import { stripeServer } from '../common/src/util/stripe'
7+
import { stripeServer } from '@codebuff/internal/util/stripe'
88

99
import type Stripe from 'stripe'
1010

web/src/app/api/auth/[...nextauth]/auth-options.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import * as schema from '@codebuff/common/db/schema'
77
import { DEFAULT_FREE_CREDITS_GRANT } from '@codebuff/common/old-constants'
88
import { getNextQuotaReset } from '@codebuff/common/util/dates'
99
import { generateCompactId } from '@codebuff/common/util/string'
10-
import { stripeServer } from '@codebuff/common/util/stripe'
1110
import { logSyncFailure } from '@codebuff/common/util/sync-failure'
1211
import { loops, env } from '@codebuff/internal'
12+
import { stripeServer } from '@codebuff/internal/util/stripe'
1313
import { eq } from 'drizzle-orm'
1414
import GitHubProvider from 'next-auth/providers/github'
1515

@@ -29,7 +29,7 @@ async function createAndLinkStripeCustomer(params: {
2929
if (!email || !name) {
3030
logger.warn(
3131
{ userId },
32-
'User email or name missing, cannot create Stripe customer.'
32+
'User email or name missing, cannot create Stripe customer.',
3333
)
3434
return null
3535
}
@@ -58,7 +58,7 @@ async function createAndLinkStripeCustomer(params: {
5858

5959
logger.info(
6060
{ userId, customerId: customer.id },
61-
'Stripe customer created with usage subscription and linked to user.'
61+
'Stripe customer created with usage subscription and linked to user.',
6262
)
6363
return customer.id
6464
} catch (error) {
@@ -68,7 +68,7 @@ async function createAndLinkStripeCustomer(params: {
6868
: 'Unknown error creating Stripe customer'
6969
logger.error(
7070
{ userId, error },
71-
'Failed to create Stripe customer or update user record.'
71+
'Failed to create Stripe customer or update user record.',
7272
)
7373
await logSyncFailure({
7474
id: userId,
@@ -107,7 +107,7 @@ async function createInitialCreditGrant(params: {
107107
creditsGranted: DEFAULT_FREE_CREDITS_GRANT,
108108
expiresAt: nextQuotaReset,
109109
},
110-
'Initial free credit grant created.'
110+
'Initial free credit grant created.',
111111
)
112112
} catch (grantError) {
113113
const errorMessage =
@@ -116,7 +116,7 @@ async function createInitialCreditGrant(params: {
116116
: 'Unknown error creating initial credit grant'
117117
logger.error(
118118
{ userId, error: grantError },
119-
'Failed to create initial credit grant.'
119+
'Failed to create initial credit grant.',
120120
)
121121
await logSyncFailure({
122122
id: userId,
@@ -167,7 +167,7 @@ export const authOptions: NextAuthOptions = {
167167
authCode: !!authCode,
168168
referralCode,
169169
allParams: Object.fromEntries(
170-
potentialRedirectUrl.searchParams.entries()
170+
potentialRedirectUrl.searchParams.entries(),
171171
),
172172
})
173173

@@ -179,30 +179,30 @@ export const authOptions: NextAuthOptions = {
179179
console.log('🟡 NextAuth CLI flow redirect to:', onboardUrl.toString())
180180
logger.info(
181181
{ url, authCode, redirectTarget: onboardUrl.toString() },
182-
'Redirecting CLI flow to /onboard'
182+
'Redirecting CLI flow to /onboard',
183183
)
184184
return onboardUrl.toString()
185185
}
186186

187187
if (url.startsWith('/') || potentialRedirectUrl.origin === baseUrl) {
188188
console.log(
189189
'🟡 NextAuth web flow redirect to:',
190-
potentialRedirectUrl.toString()
190+
potentialRedirectUrl.toString(),
191191
)
192192
logger.info(
193193
{ url, redirectTarget: potentialRedirectUrl.toString() },
194-
'Redirecting web flow to callbackUrl'
194+
'Redirecting web flow to callbackUrl',
195195
)
196196
return potentialRedirectUrl.toString()
197197
}
198198

199199
console.log(
200200
'🟡 NextAuth external/invalid URL, redirect to baseUrl:',
201-
baseUrl
201+
baseUrl,
202202
)
203203
logger.info(
204204
{ url, baseUrl, redirectTarget: baseUrl },
205-
'Callback URL is external or invalid, redirecting to baseUrl'
205+
'Callback URL is external or invalid, redirecting to baseUrl',
206206
)
207207
return baseUrl
208208
},
@@ -211,7 +211,7 @@ export const authOptions: NextAuthOptions = {
211211
createUser: async ({ user }) => {
212212
logger.info(
213213
{ userId: user.id, email: user.email },
214-
'createUser event triggered'
214+
'createUser event triggered',
215215
)
216216

217217
// Get all user data we need upfront

web/src/app/api/orgs/[orgId]/billing/setup/route.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import db from '@codebuff/common/db'
22
import * as schema from '@codebuff/common/db/schema'
33
import { pluralize } from '@codebuff/common/util/string'
4-
import { stripeServer } from '@codebuff/common/util/stripe'
54
import { env } from '@codebuff/internal'
5+
import { stripeServer } from '@codebuff/internal/util/stripe'
66
import { eq, and, sql } from 'drizzle-orm'
77
import { NextResponse } from 'next/server'
88
import { getServerSession } from 'next-auth'
@@ -38,15 +38,15 @@ export async function GET(req: NextRequest, { params }: RouteParams) {
3838
.where(
3939
and(
4040
eq(schema.orgMember.org_id, orgId),
41-
eq(schema.orgMember.user_id, session.user.id)
42-
)
41+
eq(schema.orgMember.user_id, session.user.id),
42+
),
4343
)
4444
.limit(1)
4545

4646
if (membership.length === 0) {
4747
return NextResponse.json(
4848
{ error: 'Organization not found' },
49-
{ status: 404 }
49+
{ status: 404 },
5050
)
5151
}
5252

@@ -56,7 +56,7 @@ export async function GET(req: NextRequest, { params }: RouteParams) {
5656
if (role !== 'owner' && role !== 'admin') {
5757
return NextResponse.json(
5858
{ error: 'Insufficient permissions' },
59-
{ status: 403 }
59+
{ status: 403 },
6060
)
6161
}
6262

@@ -80,7 +80,7 @@ export async function GET(req: NextRequest, { params }: RouteParams) {
8080
} catch (error) {
8181
logger.warn(
8282
{ orgId, error },
83-
'Failed to check existing payment methods'
83+
'Failed to check existing payment methods',
8484
)
8585
}
8686
}
@@ -95,11 +95,11 @@ export async function GET(req: NextRequest, { params }: RouteParams) {
9595
} catch (error: any) {
9696
logger.error(
9797
{ error: error.message, orgId },
98-
'Failed to get billing setup status'
98+
'Failed to get billing setup status',
9999
)
100100
return NextResponse.json(
101101
{ error: 'Internal server error' },
102-
{ status: 500 }
102+
{ status: 500 },
103103
)
104104
}
105105
}
@@ -124,15 +124,15 @@ export async function POST(req: NextRequest, { params }: RouteParams) {
124124
.where(
125125
and(
126126
eq(schema.orgMember.org_id, orgId),
127-
eq(schema.orgMember.user_id, session.user.id)
128-
)
127+
eq(schema.orgMember.user_id, session.user.id),
128+
),
129129
)
130130
.limit(1)
131131

132132
if (membership.length === 0) {
133133
return NextResponse.json(
134134
{ error: 'Organization not found' },
135-
{ status: 404 }
135+
{ status: 404 },
136136
)
137137
}
138138

@@ -142,7 +142,7 @@ export async function POST(req: NextRequest, { params }: RouteParams) {
142142
if (role !== 'owner' && role !== 'admin') {
143143
return NextResponse.json(
144144
{ error: 'Insufficient permissions' },
145-
{ status: 403 }
145+
{ status: 403 },
146146
)
147147
}
148148

@@ -180,7 +180,7 @@ export async function POST(req: NextRequest, { params }: RouteParams) {
180180

181181
logger.info(
182182
{ orgId, stripeCustomerId },
183-
'Created Stripe customer for organization'
183+
'Created Stripe customer for organization',
184184
)
185185
}
186186

@@ -218,24 +218,24 @@ export async function POST(req: NextRequest, { params }: RouteParams) {
218218
logger.error({ orgId }, 'Stripe checkout session created without a URL')
219219
return NextResponse.json(
220220
{ error: 'Could not create Stripe checkout session' },
221-
{ status: 500 }
221+
{ status: 500 },
222222
)
223223
}
224224

225225
logger.info(
226226
{ orgId, sessionId: checkoutSession.id, seatCount },
227-
'Created Stripe checkout session for billing setup with seat-based pricing'
227+
'Created Stripe checkout session for billing setup with seat-based pricing',
228228
)
229229

230230
return NextResponse.json({ sessionId: checkoutSession.id })
231231
} catch (error: any) {
232232
logger.error(
233233
{ error: error.message, orgId },
234-
'Failed to create billing setup session'
234+
'Failed to create billing setup session',
235235
)
236236
return NextResponse.json(
237237
{ error: 'Internal server error' },
238-
{ status: 500 }
238+
{ status: 500 },
239239
)
240240
}
241241
}

web/src/app/api/orgs/[orgId]/billing/status/route.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import db from '@codebuff/common/db'
22
import * as schema from '@codebuff/common/db/schema'
3-
import { stripeServer } from '@codebuff/common/util/stripe'
43
import { env } from '@codebuff/internal/env'
4+
import { stripeServer } from '@codebuff/internal/util/stripe'
55
import { eq, and, sql } from 'drizzle-orm'
66
import { NextResponse } from 'next/server'
77
import { getServerSession } from 'next-auth'
@@ -37,15 +37,15 @@ export async function GET(req: NextRequest, { params }: RouteParams) {
3737
.where(
3838
and(
3939
eq(schema.orgMember.org_id, orgId),
40-
eq(schema.orgMember.user_id, session.user.id)
41-
)
40+
eq(schema.orgMember.user_id, session.user.id),
41+
),
4242
)
4343
.limit(1)
4444

4545
if (membership.length === 0) {
4646
return NextResponse.json(
4747
{ error: 'Organization not found' },
48-
{ status: 404 }
48+
{ status: 404 },
4949
)
5050
}
5151

@@ -55,7 +55,7 @@ export async function GET(req: NextRequest, { params }: RouteParams) {
5555
if (role !== 'owner' && role !== 'admin') {
5656
return NextResponse.json(
5757
{ error: 'Insufficient permissions' },
58-
{ status: 403 }
58+
{ status: 403 },
5959
)
6060
}
6161

@@ -83,7 +83,7 @@ export async function GET(req: NextRequest, { params }: RouteParams) {
8383
// Get subscription details if subscription exists
8484
if (organization.stripe_subscription_id) {
8585
const subscription = await stripeServer.subscriptions.retrieve(
86-
organization.stripe_subscription_id
86+
organization.stripe_subscription_id,
8787
)
8888

8989
subscriptionDetails = {
@@ -117,11 +117,11 @@ export async function GET(req: NextRequest, { params }: RouteParams) {
117117
} catch (error: any) {
118118
logger.error(
119119
{ error: error.message, orgId },
120-
'Failed to get billing status'
120+
'Failed to get billing status',
121121
)
122122
return NextResponse.json(
123123
{ error: 'Internal server error' },
124-
{ status: 500 }
124+
{ status: 500 },
125125
)
126126
}
127127
}

0 commit comments

Comments
 (0)