Skip to content

Commit 2c2c32c

Browse files
waleedlatif1Sg312
andauthored
improvement(hygiene): refactored routes to be more restful, reduced code surface area and removed redundant code (#1217)
* improvement(invitations): consolidate invite-error and invite pages, made API endpoints more restful and reduced code surface area for invitations by 50% * refactored logs API routes * refactor rate limit api route, consolidate usage check api endpoint * refactored chat page and invitations page * consolidate ollama and openrouter stores to just providers store * removed unused route * removed legacy envvar methods * remove dead, legacy routes for invitations PUT and workflow SYNC * improvement(copilot): improve context inputs and fix some bugs (#1216) * Add logs v1 * Update * Updates * Updates * Fixes * Fix current workflow in context * Fix mentions * Error handling * Fix chat loading * Hide current workflow from context * Run workflow fix * Lint * updated invitation log * styling for invitation pages --------- Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com>
1 parent 65e8618 commit 2c2c32c

File tree

86 files changed

+7958
-2551
lines changed

Some content is hidden

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

86 files changed

+7958
-2551
lines changed

apps/sim/app/api/environment/route.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type { EnvironmentVariable } from '@/stores/settings/environment/types'
1010

1111
const logger = createLogger('EnvironmentAPI')
1212

13-
// Schema for environment variable updates
1413
const EnvVarSchema = z.object({
1514
variables: z.record(z.string()),
1615
})
@@ -30,15 +29,13 @@ export async function POST(req: NextRequest) {
3029
try {
3130
const { variables } = EnvVarSchema.parse(body)
3231

33-
// Encrypt all variables
3432
const encryptedVariables = await Promise.all(
3533
Object.entries(variables).map(async ([key, value]) => {
3634
const { encrypted } = await encryptSecret(value)
3735
return [key, encrypted] as const
3836
})
3937
).then((entries) => Object.fromEntries(entries))
4038

41-
// Replace all environment variables for user
4239
await db
4340
.insert(environment)
4441
.values({
@@ -78,7 +75,6 @@ export async function GET(request: Request) {
7875
const requestId = crypto.randomUUID().slice(0, 8)
7976

8077
try {
81-
// Get the session directly in the API route
8278
const session = await getSession()
8379
if (!session?.user?.id) {
8480
logger.warn(`[${requestId}] Unauthorized environment variables access attempt`)
@@ -97,18 +93,15 @@ export async function GET(request: Request) {
9793
return NextResponse.json({ data: {} }, { status: 200 })
9894
}
9995

100-
// Decrypt the variables for client-side use
10196
const encryptedVariables = result[0].variables as Record<string, string>
10297
const decryptedVariables: Record<string, EnvironmentVariable> = {}
10398

104-
// Decrypt each variable
10599
for (const [key, encryptedValue] of Object.entries(encryptedVariables)) {
106100
try {
107101
const { decrypted } = await decryptSecret(encryptedValue)
108102
decryptedVariables[key] = { key, value: decrypted }
109103
} catch (error) {
110104
logger.error(`[${requestId}] Error decrypting variable ${key}`, error)
111-
// If decryption fails, provide a placeholder
112105
decryptedVariables[key] = { key, value: '' }
113106
}
114107
}

apps/sim/app/api/environment/variables/route.ts

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

apps/sim/app/api/files/presigned/route.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { NextRequest } from 'next/server'
2-
import { beforeEach, describe, expect, test, vi } from 'vitest'
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
33
import { setupFileApiMocks } from '@/app/api/__test-utils__/utils'
44

5+
/**
6+
* Tests for file presigned API route
7+
*
8+
* @vitest-environment node
9+
*/
10+
511
describe('/api/files/presigned', () => {
612
beforeEach(() => {
713
vi.clearAllMocks()
@@ -19,7 +25,7 @@ describe('/api/files/presigned', () => {
1925
})
2026

2127
describe('POST', () => {
22-
test('should return error when cloud storage is not enabled', async () => {
28+
it('should return error when cloud storage is not enabled', async () => {
2329
setupFileApiMocks({
2430
cloudEnabled: false,
2531
storageProvider: 's3',
@@ -39,7 +45,7 @@ describe('/api/files/presigned', () => {
3945
const response = await POST(request)
4046
const data = await response.json()
4147

42-
expect(response.status).toBe(500) // Changed from 400 to 500 (StorageConfigError)
48+
expect(response.status).toBe(500)
4349
expect(data.error).toBe('Direct uploads are only available when cloud storage is enabled')
4450
expect(data.code).toBe('STORAGE_CONFIG_ERROR')
4551
expect(data.directUploadSupported).toBe(false)

apps/sim/app/api/logs/[executionId]/frozen-canvas/route.ts renamed to apps/sim/app/api/logs/execution/[executionId]/route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createLogger } from '@/lib/logs/console/logger'
44
import { db } from '@/db'
55
import { workflowExecutionLogs, workflowExecutionSnapshots } from '@/db/schema'
66

7-
const logger = createLogger('FrozenCanvasAPI')
7+
const logger = createLogger('LogsByExecutionIdAPI')
88

99
export async function GET(
1010
_request: NextRequest,
@@ -13,7 +13,7 @@ export async function GET(
1313
try {
1414
const { executionId } = await params
1515

16-
logger.debug(`Fetching frozen canvas data for execution: ${executionId}`)
16+
logger.debug(`Fetching execution data for: ${executionId}`)
1717

1818
// Get the workflow execution log to find the snapshot
1919
const [workflowLog] = await db
@@ -50,14 +50,14 @@ export async function GET(
5050
},
5151
}
5252

53-
logger.debug(`Successfully fetched frozen canvas data for execution: ${executionId}`)
53+
logger.debug(`Successfully fetched execution data for: ${executionId}`)
5454
logger.debug(
5555
`Workflow state contains ${Object.keys((snapshot.stateData as any)?.blocks || {}).length} blocks`
5656
)
5757

5858
return NextResponse.json(response)
5959
} catch (error) {
60-
logger.error('Error fetching frozen canvas data:', error)
61-
return NextResponse.json({ error: 'Failed to fetch frozen canvas data' }, { status: 500 })
60+
logger.error('Error fetching execution data:', error)
61+
return NextResponse.json({ error: 'Failed to fetch execution data' }, { status: 500 })
6262
}
6363
}

0 commit comments

Comments
 (0)