Skip to content

Commit 8a9bc4e

Browse files
waleedlatif1icecrasher321aadamgoughAdam GoughAdam Gough
authored
fix(permissions): make permissions check case insensitive, resolve hydration issues by consolidating environment checking function (#678)
* fix(permissions): make permissions check case insensitive * consolidated use of helpers to fetch environment * use import aliases * fix(voice): added voice functionality back to chat client (#676) * fix(voice): added voice functioanlity back to chat clinet * add logic to support deployed chat in staging * fix(api-timeout): increase timeout for API block to 2 min (#677) * feat(wealthbox): added wealthbox crm (#669) * feat: wealthbox * feat: added tools * feat: tested and finished tools * feat: tested and finished tools * feat: added refresh token * fix: added docs * bun lint * feat: removed files #669 * fix: greptile comments * fix: stringified messages #669 * add visibilty to params --------- Co-authored-by: Adam Gough <[email protected]> Co-authored-by: Adam Gough <[email protected]> Co-authored-by: Vikhyath Mondreti <[email protected]> --------- Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: Adam Gough <[email protected]> Co-authored-by: Adam Gough <[email protected]> Co-authored-by: Adam Gough <[email protected]> Co-authored-by: Vikhyath Mondreti <[email protected]>
1 parent d65bdaf commit 8a9bc4e

File tree

47 files changed

+145
-181
lines changed

Some content is hidden

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

47 files changed

+145
-181
lines changed

apps/sim/app/api/chat/edit/[id]/route.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { and, eq } from 'drizzle-orm'
22
import type { NextRequest } from 'next/server'
33
import { z } from 'zod'
44
import { getSession } from '@/lib/auth'
5-
import { env } from '@/lib/env'
5+
import { isDev } from '@/lib/environment'
66
import { createLogger } from '@/lib/logs/console-logger'
77
import { getBaseDomain } from '@/lib/urls/utils'
88
import { encryptSecret } from '@/lib/utils'
@@ -71,9 +71,7 @@ export async function GET(_request: NextRequest, { params }: { params: Promise<{
7171
// Create a new result object without the password
7272
const { password, ...safeData } = chatInstance[0]
7373

74-
const isDevelopment = env.NODE_ENV === 'development'
75-
76-
const chatUrl = isDevelopment
74+
const chatUrl = isDev
7775
? `http://${chatInstance[0].subdomain}.${getBaseDomain()}`
7876
: `https://${chatInstance[0].subdomain}.simstudio.ai`
7977

@@ -221,9 +219,7 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise<
221219

222220
const updatedSubdomain = subdomain || existingChat[0].subdomain
223221

224-
const isDevelopment = env.NODE_ENV === 'development'
225-
226-
const chatUrl = isDevelopment
222+
const chatUrl = isDev
227223
? `http://${updatedSubdomain}.${getBaseDomain()}`
228224
: `https://${updatedSubdomain}.simstudio.ai`
229225

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { v4 as uuidv4 } from 'uuid'
44
import { z } from 'zod'
55
import { getSession } from '@/lib/auth'
66
import { env } from '@/lib/env'
7+
import { isDev } from '@/lib/environment'
78
import { createLogger } from '@/lib/logs/console-logger'
89
import { encryptSecret } from '@/lib/utils'
910
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
@@ -169,11 +170,10 @@ export async function POST(request: NextRequest) {
169170

170171
// Return successful response with chat URL
171172
// Check if we're in development or production
172-
const isDevelopment = env.NODE_ENV === 'development'
173173
const baseUrl = env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'
174174

175175
let chatUrl: string
176-
if (isDevelopment) {
176+
if (isDev) {
177177
try {
178178
const url = new URL(baseUrl)
179179
chatUrl = `${url.protocol}//${subdomain}.${url.host}`

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { eq, sql } from 'drizzle-orm'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { v4 as uuidv4 } from 'uuid'
4-
import { env } from '@/lib/env'
4+
import { isDev } from '@/lib/environment'
55
import { createLogger } from '@/lib/logs/console-logger'
66
import { EnhancedLoggingSession } from '@/lib/logs/enhanced-logging-session'
77
import { buildTraceSpans } from '@/lib/logs/trace-spans'
@@ -20,7 +20,6 @@ declare global {
2020
}
2121

2222
const logger = createLogger('ChatAuthUtils')
23-
const isDevelopment = env.NODE_ENV === 'development'
2423

2524
export const encryptAuthToken = (subdomainId: string, type: string): string => {
2625
return Buffer.from(`${subdomainId}:${type}:${Date.now()}`).toString('base64')
@@ -63,11 +62,11 @@ export const setChatAuthCookie = (
6362
name: `chat_auth_${subdomainId}`,
6463
value: token,
6564
httpOnly: true,
66-
secure: !isDevelopment,
65+
secure: !isDev,
6766
sameSite: 'lax',
6867
path: '/',
6968
// Using subdomain for the domain in production
70-
domain: isDevelopment ? undefined : '.simstudio.ai',
69+
domain: isDev ? undefined : '.simstudio.ai',
7170
maxAge: 60 * 60 * 24, // 24 hours
7271
})
7372
}
@@ -78,7 +77,7 @@ export function addCorsHeaders(response: NextResponse, request: NextRequest) {
7877
const origin = request.headers.get('origin') || ''
7978

8079
// In development, allow any localhost subdomain
81-
if (isDevelopment && origin.includes('localhost')) {
80+
if (isDev && origin.includes('localhost')) {
8281
response.headers.set('Access-Control-Allow-Origin', origin)
8382
response.headers.set('Access-Control-Allow-Credentials', 'true')
8483
response.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')

apps/sim/app/api/files/delete/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
isBlobPath,
1919
isCloudPath,
2020
isS3Path,
21-
} from '../utils'
21+
} from '@/app/api/files/utils'
2222

2323
export const dynamic = 'force-dynamic'
2424

apps/sim/app/api/files/parse/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ async function handleCsvBuffer(
447447
logger.info(`Parsing CSV in memory: ${filename}`)
448448

449449
// Use the parseBuffer function from our library
450-
const { parseBuffer } = await import('../../../../lib/file-parsers')
450+
const { parseBuffer } = await import('@/lib/file-parsers')
451451
const result = await parseBuffer(fileBuffer, 'csv')
452452

453453
return {
@@ -492,7 +492,7 @@ async function handleGenericTextBuffer(
492492

493493
// Try to use a specialized parser if available
494494
try {
495-
const { parseBuffer, isSupportedFileType } = await import('../../../../lib/file-parsers')
495+
const { parseBuffer, isSupportedFileType } = await import('@/lib/file-parsers')
496496

497497
if (isSupportedFileType(extension)) {
498498
const result = await parseBuffer(fileBuffer, extension)
@@ -578,7 +578,7 @@ async function parseBufferAsPdf(buffer: Buffer) {
578578
// Import parsers dynamically to avoid initialization issues in tests
579579
// First try to use the main PDF parser
580580
try {
581-
const { PdfParser } = await import('../../../../lib/file-parsers/pdf-parser')
581+
const { PdfParser } = await import('@/lib/file-parsers/pdf-parser')
582582
const parser = new PdfParser()
583583
logger.info('Using main PDF parser for buffer')
584584

@@ -589,7 +589,7 @@ async function parseBufferAsPdf(buffer: Buffer) {
589589
} catch (error) {
590590
// Fallback to raw PDF parser
591591
logger.warn('Main PDF parser failed, using raw parser for buffer:', error)
592-
const { RawPdfParser } = await import('../../../../lib/file-parsers/raw-pdf-parser')
592+
const { RawPdfParser } = await import('@/lib/file-parsers/raw-pdf-parser')
593593
const rawParser = new RawPdfParser()
594594

595595
return await rawParser.parseBuffer(buffer)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getStorageProvider, isUsingCloudStorage } from '@/lib/uploads'
77
import { getBlobServiceClient } from '@/lib/uploads/blob/blob-client'
88
import { getS3Client, sanitizeFilenameForMetadata } from '@/lib/uploads/s3/s3-client'
99
import { BLOB_CONFIG, BLOB_KB_CONFIG, S3_CONFIG, S3_KB_CONFIG } from '@/lib/uploads/setup'
10-
import { createErrorResponse, createOptionsResponse } from '../utils'
10+
import { createErrorResponse, createOptionsResponse } from '@/app/api/files/utils'
1111

1212
const logger = createLogger('PresignedUploadAPI')
1313

apps/sim/app/api/files/serve/[...path]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
FileNotFoundError,
1212
findLocalFile,
1313
getContentType,
14-
} from '../../utils'
14+
} from '@/app/api/files/utils'
1515

1616
export const dynamic = 'force-dynamic'
1717

apps/sim/app/api/organizations/[id]/invitations/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@/lib/billing/validation/seat-management'
1414
import { sendEmail } from '@/lib/email/mailer'
1515
import { validateAndNormalizeEmail } from '@/lib/email/utils'
16+
import { env } from '@/lib/env'
1617
import { createLogger } from '@/lib/logs/console-logger'
1718
import { hasWorkspaceAdminAccess } from '@/lib/permissions/utils'
1819
import { db } from '@/db'
@@ -344,7 +345,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
344345
organizationEntry[0]?.name || 'organization',
345346
role,
346347
workspaceInvitationsWithNames,
347-
`${process.env.NEXT_PUBLIC_BASE_URL}/api/organizations/invitations/accept?id=${orgInvitation.id}`
348+
`${env.NEXT_PUBLIC_APP_URL}/api/organizations/invitations/accept?id=${orgInvitation.id}`
348349
)
349350

350351
emailResult = await sendEmail({
@@ -357,7 +358,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
357358
const emailHtml = await renderInvitationEmail(
358359
inviter[0]?.name || 'Someone',
359360
organizationEntry[0]?.name || 'organization',
360-
`${process.env.NEXT_PUBLIC_BASE_URL}/api/organizations/invitations/accept?id=${orgInvitation.id}`,
361+
`${env.NEXT_PUBLIC_APP_URL}/api/organizations/invitations/accept?id=${orgInvitation.id}`,
361362
email
362363
)
363364

apps/sim/app/api/organizations/[id]/members/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getSession } from '@/lib/auth'
66
import { validateSeatAvailability } from '@/lib/billing/validation/seat-management'
77
import { sendEmail } from '@/lib/email/mailer'
88
import { validateAndNormalizeEmail } from '@/lib/email/utils'
9+
import { env } from '@/lib/env'
910
import { createLogger } from '@/lib/logs/console-logger'
1011
import { db } from '@/db'
1112
import { invitation, member, organization, user, userStats } from '@/db/schema'
@@ -246,7 +247,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
246247
const emailHtml = await renderInvitationEmail(
247248
inviter[0]?.name || 'Someone',
248249
organizationEntry[0]?.name || 'organization',
249-
`${process.env.NEXT_PUBLIC_BASE_URL}/api/organizations/invitations/accept?id=${invitationId}`,
250+
`${env.NEXT_PUBLIC_APP_URL}/api/organizations/invitations/accept?id=${invitationId}`,
250251
normalizedEmail
251252
)
252253

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { NextResponse } from 'next/server'
2+
import { isDev } from '@/lib/environment'
23
import { createLogger } from '@/lib/logs/console-logger'
34
import { executeTool } from '@/tools'
45
import { getTool, validateToolRequest } from '@/tools/utils'
@@ -51,14 +52,14 @@ const createErrorResponse = (error: any, status = 500, additionalData = {}) => {
5152
logger.error('Creating error response', {
5253
errorMessage,
5354
status,
54-
stack: process.env.NODE_ENV === 'development' ? errorStack : undefined,
55+
stack: isDev ? errorStack : undefined,
5556
})
5657

5758
return formatResponse(
5859
{
5960
success: false,
6061
error: errorMessage,
61-
stack: process.env.NODE_ENV === 'development' ? errorStack : undefined,
62+
stack: isDev ? errorStack : undefined,
6263
...additionalData,
6364
},
6465
status

0 commit comments

Comments
 (0)