From 95ce00f51d7e85eee4c74837f054d97cef2d418f Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Fri, 14 Mar 2025 18:08:06 -0700 Subject: [PATCH] chore: added husky + ran format --- .husky/pre-commit | 1 + sim/app/api/auth/oauth/connections/route.ts | 14 ++++++------- sim/app/api/auth/oauth/credentials/route.ts | 10 +++++----- sim/app/components/ui/command.tsx | 6 ++++++ .../components/ui/oauth-required-modal.tsx | 2 +- sim/app/lib/auth.ts | 2 +- sim/app/stores/console/store.ts | 14 ++++++++----- .../components/credentials/credentials.tsx | 20 +++++++++---------- sim/middleware.ts | 8 ++++---- sim/tsconfig.json | 2 +- 10 files changed, 44 insertions(+), 35 deletions(-) create mode 100755 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000000..d0e28ee908 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +cd sim && npx lint-staged \ No newline at end of file diff --git a/sim/app/api/auth/oauth/connections/route.ts b/sim/app/api/auth/oauth/connections/route.ts index debf6824da..736291b17c 100644 --- a/sim/app/api/auth/oauth/connections/route.ts +++ b/sim/app/api/auth/oauth/connections/route.ts @@ -43,7 +43,7 @@ export async function GET(request: NextRequest) { .from(user) .where(eq(user.id, session.user.id)) .limit(1) - + const userEmail = userRecord.length > 0 ? userRecord[0].email : null // Process accounts to determine connections @@ -56,7 +56,7 @@ export async function GET(request: NextRequest) { if (provider && VALID_PROVIDERS.includes(provider)) { // Try multiple methods to get a user-friendly display name let displayName = '' - + // Method 1: Try to extract email from ID token (works for Google, etc.) if (acc.idToken) { try { @@ -70,17 +70,17 @@ export async function GET(request: NextRequest) { logger.warn(`[${requestId}] Error decoding ID token`, { accountId: acc.id }) } } - + // Method 2: For GitHub, the accountId might be the username if (!displayName && provider === 'github') { displayName = `${acc.accountId} (GitHub)` } - + // Method 3: Use the user's email from our database if (!displayName && userEmail) { displayName = userEmail } - + // Fallback: Use accountId with provider type as context if (!displayName) { displayName = `${acc.accountId} (${provider})` @@ -90,9 +90,7 @@ export async function GET(request: NextRequest) { const connectionKey = acc.providerId // Find existing connection for this specific provider ID - const existingConnection = connections.find( - (conn) => conn.provider === connectionKey - ) + const existingConnection = connections.find((conn) => conn.provider === connectionKey) if (existingConnection) { // Add account to existing connection diff --git a/sim/app/api/auth/oauth/credentials/route.ts b/sim/app/api/auth/oauth/credentials/route.ts index 865f461053..f82ceb9588 100644 --- a/sim/app/api/auth/oauth/credentials/route.ts +++ b/sim/app/api/auth/oauth/credentials/route.ts @@ -58,7 +58,7 @@ export async function GET(request: NextRequest) { // Try multiple methods to get a user-friendly display name let displayName = '' - + // Method 1: Try to extract email from ID token (works for Google, etc.) if (acc.idToken) { try { @@ -72,12 +72,12 @@ export async function GET(request: NextRequest) { logger.warn(`[${requestId}] Error decoding ID token`, { accountId: acc.id }) } } - + // Method 2: For GitHub, the accountId might be the username if (!displayName && baseProvider === 'github') { displayName = `${acc.accountId} (GitHub)` } - + // Method 3: Try to get the user's email from our database if (!displayName) { try { @@ -86,7 +86,7 @@ export async function GET(request: NextRequest) { .from(user) .where(eq(user.id, acc.userId)) .limit(1) - + if (userRecord.length > 0) { displayName = userRecord[0].email } @@ -94,7 +94,7 @@ export async function GET(request: NextRequest) { logger.warn(`[${requestId}] Error fetching user email`, { userId: acc.userId }) } } - + // Fallback: Use accountId with provider type as context if (!displayName) { displayName = `${acc.accountId} (${baseProvider})` diff --git a/sim/app/components/ui/command.tsx b/sim/app/components/ui/command.tsx index 764bd68eb9..885ab327dd 100644 --- a/sim/app/components/ui/command.tsx +++ b/sim/app/components/ui/command.tsx @@ -18,6 +18,12 @@ import { cn } from '@/lib/utils' // This file is not typed correctly from shadcn, so we're disabling the type checker // @ts-nocheck +// This file is not typed correctly from shadcn, so we're disabling the type checker +// @ts-nocheck + +// This file is not typed correctly from shadcn, so we're disabling the type checker +// @ts-nocheck + const Command = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { diff --git a/sim/app/components/ui/oauth-required-modal.tsx b/sim/app/components/ui/oauth-required-modal.tsx index 52aa5e4bbf..5acfe99557 100644 --- a/sim/app/components/ui/oauth-required-modal.tsx +++ b/sim/app/components/ui/oauth-required-modal.tsx @@ -132,7 +132,7 @@ export function OAuthRequiredModal({ providerId, requiredScopes, }) - + await client.oauth2.link({ providerId, callbackURL: window.location.href, diff --git a/sim/app/lib/auth.ts b/sim/app/lib/auth.ts index b50543d249..76f2e0d33c 100644 --- a/sim/app/lib/auth.ts +++ b/sim/app/lib/auth.ts @@ -31,7 +31,7 @@ export const auth = betterAuth({ accountLinking: { enabled: true, allowDifferentEmails: true, - trustedProviders: ["google", "github", "email-password"], + trustedProviders: ['google', 'github', 'email-password'], }, }, socialProviders: { diff --git a/sim/app/stores/console/store.ts b/sim/app/stores/console/store.ts index b07d7a9111..b4d7ce4eb1 100644 --- a/sim/app/stores/console/store.ts +++ b/sim/app/stores/console/store.ts @@ -20,10 +20,14 @@ const redactApiKeys = (obj: any): any => { } const result: Record = {} - + for (const [key, value] of Object.entries(obj)) { // Check if the key is 'apiKey' (case insensitive) - if (key.toLowerCase() === 'apikey' || key.toLowerCase() === 'api_key' || key.toLowerCase() === 'access_token') { + if ( + key.toLowerCase() === 'apikey' || + key.toLowerCase() === 'api_key' || + key.toLowerCase() === 'access_token' + ) { result[key] = '***REDACTED***' } else if (typeof value === 'object' && value !== null) { result[key] = redactApiKeys(value) @@ -31,7 +35,7 @@ const redactApiKeys = (obj: any): any => { result[key] = value } } - + return result } @@ -46,12 +50,12 @@ export const useConsoleStore = create()( set((state) => { // Create a new entry with redacted API keys const redactedEntry = { ...entry } - + // If the entry has output and it's an object, redact API keys if (redactedEntry.output && typeof redactedEntry.output === 'object') { redactedEntry.output = redactApiKeys(redactedEntry.output) } - + const newEntry: ConsoleEntry = { ...redactedEntry, id: crypto.randomUUID(), diff --git a/sim/app/w/components/sidebar/components/settings-modal/components/credentials/credentials.tsx b/sim/app/w/components/sidebar/components/settings-modal/components/credentials/credentials.tsx index 2d8b89b834..f40fa04c8c 100644 --- a/sim/app/w/components/sidebar/components/settings-modal/components/credentials/credentials.tsx +++ b/sim/app/w/components/sidebar/components/settings-modal/components/credentials/credentials.tsx @@ -75,8 +75,8 @@ export function Credentials({ onOpenChange }: CredentialsProps) { // Find matching connection - now we can do an exact match on providerId const connection = connections.find((conn: any) => { // Exact match on providerId is the most reliable - return conn.provider === service.providerId; - }); + return conn.provider === service.providerId + }) // If we found an exact match, use it if (connection) { @@ -92,16 +92,16 @@ export function Credentials({ onOpenChange }: CredentialsProps) { const connectionWithScopes = connections.find((conn: any) => { // Only consider connections from the same base provider if (!conn.baseProvider || !service.providerId.startsWith(conn.baseProvider)) { - return false; + return false } - + // Check if all required scopes for this service are included in the connection if (conn.scopes && service.scopes) { - return service.scopes.every(scope => conn.scopes.includes(scope)); + return service.scopes.every((scope) => conn.scopes.includes(scope)) } - - return false; - }); + + return false + }) if (connectionWithScopes) { return { @@ -112,7 +112,7 @@ export function Credentials({ onOpenChange }: CredentialsProps) { } } - return service; + return service }) setServices(updatedServices) @@ -209,7 +209,7 @@ export function Credentials({ onOpenChange }: CredentialsProps) { saveToStorage('pending_oauth_scopes', service.scopes) saveToStorage('pending_oauth_return_url', window.location.href) saveToStorage('pending_oauth_provider_id', service.providerId) - + logger.info('Connecting service:', { serviceId: service.id, providerId: service.providerId, diff --git a/sim/middleware.ts b/sim/middleware.ts index b4989e45c0..e53086be6e 100644 --- a/sim/middleware.ts +++ b/sim/middleware.ts @@ -1,9 +1,9 @@ import { NextRequest, NextResponse } from 'next/server' -import { getSessionCookie } from "better-auth/cookies" +import { getSessionCookie } from 'better-auth/cookies' export async function middleware(request: NextRequest) { - // Check if the path is exactly /w - if (request.nextUrl.pathname === '/w') { + // Check if the path is exactly /w + if (request.nextUrl.pathname === '/w') { return NextResponse.redirect(new URL('/w/1', request.url)) } @@ -25,4 +25,4 @@ export const config = { '/w', // Match exactly /w '/w/:path*', // Keep existing matcher for protected routes ], -} \ No newline at end of file +} diff --git a/sim/tsconfig.json b/sim/tsconfig.json index a0b40abecd..06d52ebbf7 100644 --- a/sim/tsconfig.json +++ b/sim/tsconfig.json @@ -29,7 +29,7 @@ "@/db": ["./app/db"], "@/db/*": ["./app/db/*"], "@/executor": ["./app/executor"], - "@/executor/*": ["./app/executor/*"], + "@/executor/*": ["./app/executor/*"] }, "allowJs": true, "noEmit": true,