Skip to content

Commit 00f9d40

Browse files
committed
remove unused files with knip
1 parent 123d39a commit 00f9d40

File tree

68 files changed

+560
-5936
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+560
-5936
lines changed

apps/sim/app/(auth)/components/status-page-loading.tsx

Lines changed: 0 additions & 60 deletions
This file was deleted.

apps/sim/app/(landing)/studio/head.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.

apps/sim/app/api/chat/[identifier]/otp/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import type { NextRequest } from 'next/server'
77
import { z } from 'zod'
88
import { renderOTPEmail } from '@/components/emails'
99
import { getRedisClient } from '@/lib/core/config/redis'
10+
import { addCorsHeaders } from '@/lib/core/security/deployment'
1011
import { getStorageMethod } from '@/lib/core/storage'
1112
import { generateRequestId } from '@/lib/core/utils/request'
1213
import { sendEmail } from '@/lib/messaging/email/mailer'
13-
import { addCorsHeaders, setChatAuthCookie } from '@/app/api/chat/utils'
14+
import { setChatAuthCookie } from '@/app/api/chat/utils'
1415
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
1516

1617
const logger = createLogger('ChatOtpAPI')

apps/sim/app/api/chat/[identifier]/route.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import { createLogger } from '@sim/logger'
55
import { eq } from 'drizzle-orm'
66
import { type NextRequest, NextResponse } from 'next/server'
77
import { z } from 'zod'
8+
import { addCorsHeaders, validateAuthToken } from '@/lib/core/security/deployment'
89
import { generateRequestId } from '@/lib/core/utils/request'
910
import { preprocessExecution } from '@/lib/execution/preprocessing'
1011
import { LoggingSession } from '@/lib/logs/execution/logging-session'
1112
import { ChatFiles } from '@/lib/uploads'
12-
import {
13-
addCorsHeaders,
14-
setChatAuthCookie,
15-
validateAuthToken,
16-
validateChatAuth,
17-
} from '@/app/api/chat/utils'
13+
import { setChatAuthCookie, validateChatAuth } from '@/app/api/chat/utils'
1814
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
1915

2016
const logger = createLogger('ChatIdentifierAPI')

apps/sim/app/api/chat/utils.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { NextResponse } from 'next/server'
55
* @vitest-environment node
66
*/
77
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
8-
import { env } from '@/lib/core/config/env'
98

109
vi.mock('@sim/db', () => ({
1110
db: {
@@ -64,7 +63,7 @@ describe('Chat API Utils', () => {
6463
vi.stubGlobal('process', {
6564
...process,
6665
env: {
67-
...env,
66+
...process.env,
6867
NODE_ENV: 'development',
6968
},
7069
})
@@ -75,8 +74,8 @@ describe('Chat API Utils', () => {
7574
})
7675

7776
describe('Auth token utils', () => {
78-
it('should validate auth tokens', async () => {
79-
const { validateAuthToken } = await import('@/app/api/chat/utils')
77+
it.concurrent('should validate auth tokens', async () => {
78+
const { validateAuthToken } = await import('@/lib/core/security/deployment')
8079

8180
const chatId = 'test-chat-id'
8281
const type = 'password'
@@ -92,8 +91,8 @@ describe('Chat API Utils', () => {
9291
expect(isInvalidChat).toBe(false)
9392
})
9493

95-
it('should reject expired tokens', async () => {
96-
const { validateAuthToken } = await import('@/app/api/chat/utils')
94+
it.concurrent('should reject expired tokens', async () => {
95+
const { validateAuthToken } = await import('@/lib/core/security/deployment')
9796

9897
const chatId = 'test-chat-id'
9998
const expiredToken = Buffer.from(
@@ -136,7 +135,7 @@ describe('Chat API Utils', () => {
136135

137136
describe('CORS handling', () => {
138137
it('should add CORS headers for localhost in development', async () => {
139-
const { addCorsHeaders } = await import('@/app/api/chat/utils')
138+
const { addCorsHeaders } = await import('@/lib/core/security/deployment')
140139

141140
const mockRequest = {
142141
headers: {
@@ -343,7 +342,7 @@ describe('Chat API Utils', () => {
343342
})
344343

345344
describe('Execution Result Processing', () => {
346-
it('should process logs regardless of overall success status', () => {
345+
it.concurrent('should process logs regardless of overall success status', () => {
347346
const executionResult = {
348347
success: false,
349348
output: {},
@@ -381,7 +380,7 @@ describe('Chat API Utils', () => {
381380
expect(executionResult.logs[1].error).toBe('Agent 2 failed')
382381
})
383382

384-
it('should handle ExecutionResult vs StreamingExecution types correctly', () => {
383+
it.concurrent('should handle ExecutionResult vs StreamingExecution types correctly', () => {
385384
const executionResult = {
386385
success: true,
387386
output: { content: 'test' },

apps/sim/app/api/chat/utils.ts

Lines changed: 15 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
import { createHash } from 'crypto'
21
import { db } from '@sim/db'
32
import { chat, workflow } from '@sim/db/schema'
43
import { createLogger } from '@sim/logger'
54
import { eq } from 'drizzle-orm'
65
import type { NextRequest, NextResponse } from 'next/server'
7-
import { isDev } from '@/lib/core/config/feature-flags'
6+
import {
7+
isEmailAllowed,
8+
setDeploymentAuthCookie,
9+
validateAuthToken,
10+
} from '@/lib/core/security/deployment'
811
import { decryptSecret } from '@/lib/core/security/encryption'
912
import { hasAdminPermission } from '@/lib/workspaces/permissions/utils'
1013

1114
const logger = createLogger('ChatAuthUtils')
1215

13-
function hashPassword(encryptedPassword: string): string {
14-
return createHash('sha256').update(encryptedPassword).digest('hex').substring(0, 8)
16+
export function setChatAuthCookie(
17+
response: NextResponse,
18+
chatId: string,
19+
type: string,
20+
encryptedPassword?: string | null
21+
): void {
22+
setDeploymentAuthCookie(response, 'chat', chatId, type, encryptedPassword)
1523
}
1624

1725
/**
@@ -82,77 +90,6 @@ export async function checkChatAccess(
8290
return { hasAccess: false }
8391
}
8492

85-
function encryptAuthToken(chatId: string, type: string, encryptedPassword?: string | null): string {
86-
const pwHash = encryptedPassword ? hashPassword(encryptedPassword) : ''
87-
return Buffer.from(`${chatId}:${type}:${Date.now()}:${pwHash}`).toString('base64')
88-
}
89-
90-
export function validateAuthToken(
91-
token: string,
92-
chatId: string,
93-
encryptedPassword?: string | null
94-
): boolean {
95-
try {
96-
const decoded = Buffer.from(token, 'base64').toString()
97-
const parts = decoded.split(':')
98-
const [storedId, _type, timestamp, storedPwHash] = parts
99-
100-
if (storedId !== chatId) {
101-
return false
102-
}
103-
104-
const createdAt = Number.parseInt(timestamp)
105-
const now = Date.now()
106-
const expireTime = 24 * 60 * 60 * 1000
107-
108-
if (now - createdAt > expireTime) {
109-
return false
110-
}
111-
112-
if (encryptedPassword) {
113-
const currentPwHash = hashPassword(encryptedPassword)
114-
if (storedPwHash !== currentPwHash) {
115-
return false
116-
}
117-
}
118-
119-
return true
120-
} catch (_e) {
121-
return false
122-
}
123-
}
124-
125-
export function setChatAuthCookie(
126-
response: NextResponse,
127-
chatId: string,
128-
type: string,
129-
encryptedPassword?: string | null
130-
): void {
131-
const token = encryptAuthToken(chatId, type, encryptedPassword)
132-
response.cookies.set({
133-
name: `chat_auth_${chatId}`,
134-
value: token,
135-
httpOnly: true,
136-
secure: !isDev,
137-
sameSite: 'lax',
138-
path: '/',
139-
maxAge: 60 * 60 * 24,
140-
})
141-
}
142-
143-
export function addCorsHeaders(response: NextResponse, request: NextRequest) {
144-
const origin = request.headers.get('origin') || ''
145-
146-
if (isDev && origin.includes('localhost')) {
147-
response.headers.set('Access-Control-Allow-Origin', origin)
148-
response.headers.set('Access-Control-Allow-Credentials', 'true')
149-
response.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
150-
response.headers.set('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With')
151-
}
152-
153-
return response
154-
}
155-
15693
export async function validateChatAuth(
15794
requestId: string,
15895
deployment: any,
@@ -231,12 +168,7 @@ export async function validateChatAuth(
231168

232169
const allowedEmails = deployment.allowedEmails || []
233170

234-
if (allowedEmails.includes(email)) {
235-
return { authorized: false, error: 'otp_required' }
236-
}
237-
238-
const domain = email.split('@')[1]
239-
if (domain && allowedEmails.some((allowed: string) => allowed === `@${domain}`)) {
171+
if (isEmailAllowed(email, allowedEmails)) {
240172
return { authorized: false, error: 'otp_required' }
241173
}
242174

@@ -270,12 +202,7 @@ export async function validateChatAuth(
270202

271203
const allowedEmails = deployment.allowedEmails || []
272204

273-
if (allowedEmails.includes(email)) {
274-
return { authorized: true }
275-
}
276-
277-
const domain = email.split('@')[1]
278-
if (domain && allowedEmails.some((allowed: string) => allowed === `@${domain}`)) {
205+
if (isEmailAllowed(email, allowedEmails)) {
279206
return { authorized: true }
280207
}
281208

@@ -296,12 +223,7 @@ export async function validateChatAuth(
296223

297224
const allowedEmails = deployment.allowedEmails || []
298225

299-
if (allowedEmails.includes(userEmail)) {
300-
return { authorized: true }
301-
}
302-
303-
const domain = userEmail.split('@')[1]
304-
if (domain && allowedEmails.some((allowed: string) => allowed === `@${domain}`)) {
226+
if (isEmailAllowed(userEmail, allowedEmails)) {
305227
return { authorized: true }
306228
}
307229

apps/sim/app/api/form/[identifier]/route.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import { createLogger } from '@sim/logger'
55
import { eq } from 'drizzle-orm'
66
import { type NextRequest, NextResponse } from 'next/server'
77
import { z } from 'zod'
8+
import { addCorsHeaders, validateAuthToken } from '@/lib/core/security/deployment'
89
import { generateRequestId } from '@/lib/core/utils/request'
910
import { preprocessExecution } from '@/lib/execution/preprocessing'
1011
import { LoggingSession } from '@/lib/logs/execution/logging-session'
1112
import { createStreamingResponse } from '@/lib/workflows/streaming/streaming'
12-
import {
13-
addCorsHeaders,
14-
setFormAuthCookie,
15-
validateAuthToken,
16-
validateFormAuth,
17-
} from '@/app/api/form/utils'
13+
import { setFormAuthCookie, validateFormAuth } from '@/app/api/form/utils'
1814
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
1915

2016
const logger = createLogger('FormIdentifierAPI')

0 commit comments

Comments
 (0)