Skip to content

Commit a0f559f

Browse files
committed
refactor dates
1 parent ce15444 commit a0f559f

File tree

14 files changed

+193
-43
lines changed

14 files changed

+193
-43
lines changed

apps/dashboard/app/api/integrations/vercel/callback/route.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { randomUUID } from 'node:crypto';
22
import { auth } from '@databuddy/auth';
33
import { account, and, db, eq } from '@databuddy/db';
4+
import { encryptToken } from '@databuddy/shared';
45
import { headers } from 'next/headers';
56
import { type NextRequest, NextResponse } from 'next/server';
67

@@ -97,19 +98,30 @@ export async function GET(request: NextRequest) {
9798
where: and(eq(account.userId, userId), eq(account.providerId, 'vercel')),
9899
});
99100

100-
const now = new Date().toISOString();
101+
const now = new Date();
101102
const scopeData = JSON.stringify({
102103
configurationId,
103104
teamId,
104105
installationId: tokens.installation_id,
105106
tokenType: tokens.token_type,
106107
});
107108

109+
// Encrypt the access token using Better Auth secret
110+
const betterAuthSecret = process.env.BETTER_AUTH_SECRET;
111+
if (!betterAuthSecret) {
112+
throw new Error('BETTER_AUTH_SECRET environment variable is required');
113+
}
114+
115+
const encryptedAccessToken = encryptToken(
116+
tokens.access_token,
117+
betterAuthSecret
118+
);
119+
108120
if (existingAccount) {
109121
await db
110122
.update(account)
111123
.set({
112-
accessToken: tokens.access_token,
124+
accessToken: encryptedAccessToken,
113125
scope: scopeData,
114126
updatedAt: now,
115127
})
@@ -120,7 +132,7 @@ export async function GET(request: NextRequest) {
120132
accountId: userInfo.id,
121133
providerId: 'vercel',
122134
userId,
123-
accessToken: tokens.access_token,
135+
accessToken: encryptedAccessToken,
124136
scope: scopeData,
125137
createdAt: now,
126138
updatedAt: now,

apps/dashboard/env.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import z from 'zod';
2+
3+
const envSchema = z.object({
4+
VERCEL_CLIENT_ID: z.string(),
5+
VERCEL_CLIENT_SECRET: z.string(),
6+
BETTER_AUTH_SECRET: z.string(),
7+
CLICKHOUSE_URL: z.string(),
8+
DATABASE_URL: z.string(),
9+
REDIS_URL: z.string(),
10+
AI_API_KEY: z.string(),
11+
BETTER_AUTH_URL: z.string(),
12+
AUTUMN_SECRET_KEY: z.string(),
13+
NODE_ENV: z.string().default('development'),
14+
GITHUB_CLIENT_ID: z.string(),
15+
GITHUB_CLIENT_SECRET: z.string(),
16+
GOOGLE_CLIENT_ID: z.string(),
17+
GOOGLE_CLIENT_SECRET: z.string(),
18+
RESEND_API_KEY: z.string(),
19+
NEXT_PUBLIC_API_URL: z.string(),
20+
});
21+
22+
const isDevelopment = process.env.NODE_ENV === 'development';
23+
const skipValidation = isDevelopment || process.env.SKIP_VALIDATION === 'true';
24+
25+
export const env = skipValidation ? process.env : envSchema.parse(process.env);

bun.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,6 +3406,12 @@
34063406

34073407
"ast-v8-to-istanbul/js-tokens": ["[email protected]", "", {}, "sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ=="],
34083408

3409+
"basket/@databuddy/auth": ["@databuddy/auth@file:packages/auth", { "dependencies": { "@databuddy/db": "*", "@databuddy/email": "*", "better-auth": "^1.3.8", "resend": "^4.2.0" } }],
3410+
3411+
"basket/@databuddy/redis": ["@databuddy/redis@file:packages/redis", { "dependencies": { "ioredis": "^5.4.3", "superjson": "^2.0.2", "zod": "3.25.76" }, "devDependencies": { "@types/node": "^20.11.19", "typescript": "^5.3.3" } }],
3412+
3413+
"basket/@databuddy/validation": ["@databuddy/validation@file:packages/validation", { "dependencies": { "zod": "^4.0.10" }, "devDependencies": { "typescript": "^5.3.3" } }],
3414+
34093415
"basket/autumn-js": ["[email protected]", "", { "dependencies": { "axios": "^1.10.0", "chalk": "^5.4.1", "commander": "^14.0.0", "ink": "^6.0.1", "jiti": "^2.4.2", "open": "^10.1.2", "rou3": "^0.6.1", "swr": "^2.3.3", "zod": "^3.24.1" }, "peerDependencies": { "better-auth": "^1.2.12", "better-call": "^1.0.12" }, "optionalPeers": ["better-auth", "better-call"] }, "sha512-Xmb6jvrr6EgN0UbHZZ0Er0OiLW/IbPPf02lbTNbTCuHePoSEaMQ3cxkvADpNRFf5NBo3Oos2rG2QVaDzkzIejg=="],
34103416

34113417
"basket/zod": ["[email protected]", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="],
@@ -3692,6 +3698,10 @@
36923698

36933699
"admin/react-day-picker/react": ["[email protected]", "", { "dependencies": { "loose-envify": "^1.1.0" } }, "sha512-x+VL6wbT4JRVPm7EGxXhZ8w8LTROaxPXOqhlGyVSrv0sB1jkyFGgXxJ8LVoPRLvPR6/CIZGFmfzqUa2NYeMr2A=="],
36943700

3701+
"basket/@databuddy/redis/@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-yCAeZl7a0DxgNVteXFHt9+uyFbqXGy/ShC4BlcHkoE0AfGXYv/BUiplV72DjMYXHDBXFjhvr6DD1NiRVfB4j8g=="],
3702+
3703+
"basket/@databuddy/validation/zod": ["[email protected]", "", {}, "sha512-rcUUZqlLJgBC33IT3PNMgsCq6TzLQEG/Ei/KTCU0PedSWRMAXoOUN+4t/0H+Q8bdnLPdqUYnvboJT0bn/229qg=="],
3704+
36953705
"bun-types/@types/node/undici-types": ["[email protected]", "", {}, "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag=="],
36963706

36973707
"cli-truncate/slice-ansi/is-fullwidth-code-point": ["[email protected]", "", {}, "sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ=="],

packages/rpc/src/routers/apikeys.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export const apikeysRouter = createTRPCRouter({
339339
create: protectedProcedure
340340
.input(createApiKeySchema)
341341
.mutation(async ({ ctx, input }) => {
342-
const nowIso = new Date().toISOString();
342+
const nowIso = new Date();
343343
const { secret, prefix, start } = generateKeyMaterial();
344344
const keyHash = hashSecretScrypt(secret);
345345

@@ -435,7 +435,7 @@ export const apikeysRouter = createTRPCRouter({
435435
? key.expiresAt
436436
: (input.expiresAt as string | null),
437437
metadata: input.metadata ?? key.metadata,
438-
updatedAt: new Date().toISOString(),
438+
updatedAt: new Date(),
439439
})
440440
.where(eq(apikey.id, input.id))
441441
.returning();
@@ -475,8 +475,8 @@ export const apikeysRouter = createTRPCRouter({
475475
.update(apikey)
476476
.set({
477477
enabled: false,
478-
revokedAt: new Date().toISOString(),
479-
updatedAt: new Date().toISOString(),
478+
revokedAt: new Date(),
479+
updatedAt: new Date(),
480480
})
481481
.where(eq(apikey.id, input.id));
482482
return { success: true };
@@ -519,7 +519,7 @@ export const apikeysRouter = createTRPCRouter({
519519
start,
520520
key: secret,
521521
keyHash,
522-
updatedAt: new Date().toISOString(),
522+
updatedAt: new Date(),
523523
})
524524
.where(eq(apikey.id, input.id))
525525
.returning();
@@ -562,16 +562,16 @@ export const apikeysRouter = createTRPCRouter({
562562
.delete(apikeyAccess)
563563
.where(eq(apikeyAccess.apikeyId, input.apikeyId));
564564
if (input.access.length > 0) {
565-
const nowIso = new Date().toISOString();
565+
const now = new Date();
566566
const rows: InferInsertModel<typeof apikeyAccess>[] =
567567
input.access.map((a) => ({
568568
id: nanoid(),
569569
apikeyId: input.apikeyId,
570570
resourceType: a.resourceType,
571571
resourceId: a.resourceId ?? null,
572572
scopes: a.scopes,
573-
createdAt: nowIso,
574-
updatedAt: nowIso,
573+
createdAt: now,
574+
updatedAt: now,
575575
}));
576576
await tx.insert(apikeyAccess).values(rows);
577577
}
@@ -598,7 +598,7 @@ export const apikeysRouter = createTRPCRouter({
598598
try {
599599
const key = await fetchKeyOrThrow(ctx, input.apikeyId);
600600
await assertCanManageKey(ctx, key);
601-
const nowIso = new Date().toISOString();
601+
const now = new Date();
602602
const [row] = await ctx.db
603603
.insert(apikeyAccess)
604604
.values({
@@ -607,16 +607,16 @@ export const apikeysRouter = createTRPCRouter({
607607
resourceType: input.resourceType,
608608
resourceId: input.resourceId ?? null,
609609
scopes: input.scopes,
610-
createdAt: nowIso,
611-
updatedAt: nowIso,
610+
createdAt: now,
611+
updatedAt: now,
612612
})
613613
.onConflictDoUpdate({
614614
target: [
615615
apikeyAccess.apikeyId,
616616
apikeyAccess.resourceType,
617617
apikeyAccess.resourceId,
618618
],
619-
set: { scopes: input.scopes, updatedAt: nowIso },
619+
set: { scopes: input.scopes, updatedAt: now },
620620
})
621621
.returning();
622622
return row;

packages/rpc/src/routers/assistant.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const assistantRouter = createTRPCRouter({
112112
// Update conversation timestamp
113113
await tx
114114
.update(assistantConversations)
115-
.set({ updatedAt: new Date().toISOString() })
115+
.set({ updatedAt: new Date() })
116116
.where(eq(assistantConversations.id, conversationId));
117117
});
118118

@@ -286,7 +286,7 @@ export const assistantRouter = createTRPCRouter({
286286
.update(assistantConversations)
287287
.set({
288288
title: input.title,
289-
updatedAt: new Date().toISOString(),
289+
updatedAt: new Date(),
290290
})
291291
.where(
292292
and(

packages/rpc/src/routers/db-connections.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ export const dbConnectionsRouter = createTRPCRouter({
154154
type: input.type,
155155
url: encryptConnectionUrl(input.url),
156156
organizationId: input.organizationId,
157-
createdAt: new Date().toISOString(),
158-
updatedAt: new Date().toISOString(),
157+
createdAt: new Date(),
158+
updatedAt: new Date(),
159159
})
160160
.returning({
161161
id: dbConnections.id,
@@ -179,7 +179,7 @@ export const dbConnectionsRouter = createTRPCRouter({
179179
.update(dbConnections)
180180
.set({
181181
name: input.name,
182-
updatedAt: new Date().toISOString(),
182+
updatedAt: new Date(),
183183
})
184184
.where(eq(dbConnections.id, input.id))
185185
.returning({

packages/rpc/src/routers/experiments.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ export const experimentsRouter = createTRPCRouter({
214214
id: experimentId,
215215
...experimentData,
216216
createdBy: ctx.user.id,
217-
createdAt: new Date().toISOString(),
218-
updatedAt: new Date().toISOString(),
217+
createdAt: new Date(),
218+
updatedAt: new Date(),
219219
})
220220
.returning();
221221

@@ -226,8 +226,8 @@ export const experimentsRouter = createTRPCRouter({
226226
id: crypto.randomUUID(),
227227
...variant,
228228
experimentId: experiment.id,
229-
createdAt: new Date().toISOString(),
230-
updatedAt: new Date().toISOString(),
229+
createdAt: new Date(),
230+
updatedAt: new Date(),
231231
}))
232232
);
233233
}
@@ -239,8 +239,8 @@ export const experimentsRouter = createTRPCRouter({
239239
id: crypto.randomUUID(),
240240
...goal,
241241
experimentId: experiment.id,
242-
createdAt: new Date().toISOString(),
243-
updatedAt: new Date().toISOString(),
242+
createdAt: new Date(),
243+
updatedAt: new Date(),
244244
}))
245245
);
246246
}
@@ -297,7 +297,7 @@ export const experimentsRouter = createTRPCRouter({
297297
.update(abExperiments)
298298
.set({
299299
...updateData,
300-
updatedAt: new Date().toISOString(),
300+
updatedAt: new Date(),
301301
})
302302
.where(eq(abExperiments.id, id))
303303
.returning();
@@ -361,8 +361,8 @@ export const experimentsRouter = createTRPCRouter({
361361
await ctx.db
362362
.update(abExperiments)
363363
.set({
364-
deletedAt: new Date().toISOString(),
365-
updatedAt: new Date().toISOString(),
364+
deletedAt: new Date(),
365+
updatedAt: new Date(),
366366
})
367367
.where(eq(abExperiments.id, input.id));
368368

@@ -432,8 +432,8 @@ export const experimentsRouter = createTRPCRouter({
432432
.values({
433433
id: crypto.randomUUID(),
434434
...input,
435-
createdAt: new Date().toISOString(),
436-
updatedAt: new Date().toISOString(),
435+
createdAt: new Date(),
436+
updatedAt: new Date(),
437437
})
438438
.returning();
439439

@@ -489,7 +489,7 @@ export const experimentsRouter = createTRPCRouter({
489489
.update(abVariants)
490490
.set({
491491
...updateData,
492-
updatedAt: new Date().toISOString(),
492+
updatedAt: new Date(),
493493
})
494494
.where(eq(abVariants.id, id))
495495
.returning();
@@ -594,8 +594,8 @@ export const experimentsRouter = createTRPCRouter({
594594
.values({
595595
id: crypto.randomUUID(),
596596
...input,
597-
createdAt: new Date().toISOString(),
598-
updatedAt: new Date().toISOString(),
597+
createdAt: new Date(),
598+
updatedAt: new Date(),
599599
})
600600
.returning();
601601

@@ -651,7 +651,7 @@ export const experimentsRouter = createTRPCRouter({
651651
.update(abGoals)
652652
.set({
653653
...updateData,
654-
updatedAt: new Date().toISOString(),
654+
updatedAt: new Date(),
655655
})
656656
.where(eq(abGoals.id, id))
657657
.returning();

packages/rpc/src/routers/funnels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export const funnelsRouter = createTRPCRouter({
232232
.update(funnelDefinitions)
233233
.set({
234234
...updates,
235-
updatedAt: new Date().toISOString(),
235+
updatedAt: new Date(),
236236
})
237237
.where(
238238
and(
@@ -285,7 +285,7 @@ export const funnelsRouter = createTRPCRouter({
285285
await ctx.db
286286
.update(funnelDefinitions)
287287
.set({
288-
deletedAt: new Date().toISOString(),
288+
deletedAt: new Date(),
289289
isActive: false,
290290
})
291291
.where(

packages/rpc/src/routers/goals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export const goalsRouter = createTRPCRouter({
169169
.update(goals)
170170
.set({
171171
...updates,
172-
updatedAt: new Date().toISOString(),
172+
updatedAt: new Date(),
173173
})
174174
.where(and(eq(goals.id, id), isNull(goals.deletedAt)))
175175
.returning();
@@ -199,7 +199,7 @@ export const goalsRouter = createTRPCRouter({
199199
await ctx.db
200200
.update(goals)
201201
.set({
202-
deletedAt: new Date().toISOString(),
202+
deletedAt: new Date(),
203203
isActive: false,
204204
})
205205
.where(and(eq(goals.id, input.id), isNull(goals.deletedAt)));

packages/rpc/src/routers/preferences.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const preferencesRouter = createTRPCRouter({
2929
id: nanoid(),
3030
userId: ctx.user.id,
3131
...defaultPreferences,
32-
updatedAt: new Date().toISOString(),
32+
updatedAt: new Date(),
3333
})
3434
.returning();
3535
preferences = inserted[0];
@@ -40,7 +40,7 @@ export const preferencesRouter = createTRPCRouter({
4040
updateUserPreferences: protectedProcedure
4141
.input(preferencesSchema)
4242
.mutation(async ({ ctx, input }) => {
43-
const now = new Date().toISOString();
43+
const now = new Date();
4444

4545
const result = await ctx.db
4646
.insert(userPreferences)

0 commit comments

Comments
 (0)