Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/sim/app/api/auth/shopify/authorize/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { env } from '@/lib/core/config/env'
import { getBaseUrl } from '@/lib/core/utils/urls'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('ShopifyAuthorize')

Expand Down Expand Up @@ -161,7 +162,7 @@ export async function GET(request: NextRequest) {
const baseUrl = getBaseUrl()
const redirectUri = `${baseUrl}/api/auth/oauth2/callback/shopify`

const state = crypto.randomUUID()
const state = generateId()

const oauthUrl =
`https://${cleanShop}/admin/oauth/authorize?` +
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/app/api/copilot/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '@/lib/copilot/request-helpers'
import { env } from '@/lib/core/config/env'
import { resolveWorkflowIdForUser } from '@/lib/workflows/utils'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('CopilotChatAPI')

Expand Down Expand Up @@ -188,7 +189,7 @@ export async function POST(req: NextRequest) {
const workflowId = resolved.workflowId

// Ensure we have a consistent user message ID for this request
const userMessageIdToUse = userMessageId || crypto.randomUUID()
const userMessageIdToUse = userMessageId || generateId()
try {
logger.info(`[${tracker.requestId}] Received chat POST`, {
hasContexts: Array.isArray(normalizedContexts),
Expand Down Expand Up @@ -474,7 +475,7 @@ export async function POST(req: NextRequest) {
}

const assistantMessage = {
id: crypto.randomUUID(),
id: generateId(),
role: 'assistant',
content: responseData.content,
timestamp: new Date().toISOString(),
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/app/api/credential-sets/[id]/invite/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getSession } from '@/lib/auth'
import { hasCredentialSetsAccess } from '@/lib/billing'
import { getBaseUrl } from '@/lib/core/utils/urls'
import { sendEmail } from '@/lib/messaging/email/mailer'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('CredentialSetInvite')

Expand Down Expand Up @@ -105,12 +106,12 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
const body = await req.json()
const { email } = createInviteSchema.parse(body)

const token = crypto.randomUUID()
const token = generateId()
const expiresAt = new Date()
expiresAt.setDate(expiresAt.getDate() + 7)

const invitation = {
id: crypto.randomUUID(),
id: generateId(),
credentialSetId: id,
email: email || null,
token,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/credential-sets/[id]/members/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
import { getSession } from '@/lib/auth'
import { hasCredentialSetsAccess } from '@/lib/billing'
import { syncAllWebhooksForCredentialSet } from '@/lib/webhooks/utils.server'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('CredentialSetMembers')

Expand Down Expand Up @@ -167,7 +168,7 @@ export async function DELETE(req: NextRequest, { params }: { params: Promise<{ i
return NextResponse.json({ error: 'Member not found' }, { status: 404 })
}

const requestId = crypto.randomUUID().slice(0, 8)
const requestId = generateId().slice(0, 8)

// Use transaction to ensure member deletion + webhook sync are atomic
await db.transaction(async (tx) => {
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/app/api/credential-sets/invite/[token]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
import { getSession } from '@/lib/auth'
import { syncAllWebhooksForCredentialSet } from '@/lib/webhooks/utils.server'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('CredentialSetInviteToken')

Expand Down Expand Up @@ -125,11 +126,11 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ tok
}

const now = new Date()
const requestId = crypto.randomUUID().slice(0, 8)
const requestId = generateId().slice(0, 8)

await db.transaction(async (tx) => {
await tx.insert(credentialSetMember).values({
id: crypto.randomUUID(),
id: generateId(),
credentialSetId: invitation.credentialSetId,
userId: session.user.id,
status: 'active',
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/credential-sets/memberships/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
import { getSession } from '@/lib/auth'
import { syncAllWebhooksForCredentialSet } from '@/lib/webhooks/utils.server'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('CredentialSetMemberships')

Expand Down Expand Up @@ -60,7 +61,7 @@ export async function DELETE(req: NextRequest) {
}

try {
const requestId = crypto.randomUUID().slice(0, 8)
const requestId = generateId().slice(0, 8)

// Use transaction to ensure revocation + webhook sync are atomic
await db.transaction(async (tx) => {
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/credential-sets/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { z } from 'zod'
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
import { getSession } from '@/lib/auth'
import { hasCredentialSetsAccess } from '@/lib/billing'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('CredentialSets')

Expand Down Expand Up @@ -148,7 +149,7 @@ export async function POST(req: Request) {

const now = new Date()
const newCredentialSet = {
id: crypto.randomUUID(),
id: generateId(),
organizationId,
name,
description: description || null,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/credentials/[id]/members/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { getSession } from '@/lib/auth'
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('CredentialMembersAPI')

Expand Down Expand Up @@ -133,7 +134,7 @@ export async function POST(request: NextRequest, context: RouteContext) {
}

await db.insert(credentialMember).values({
id: crypto.randomUUID(),
id: generateId(),
credentialId,
userId,
role,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/credentials/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { z } from 'zod'
import { getSession } from '@/lib/auth'
import { getCredentialActorContext } from '@/lib/credentials/access'
import {
import { generateId } from '@/lib/core/utils/id'
syncPersonalEnvCredentialsForUser,
syncWorkspaceEnvCredentials,
} from '@/lib/credentials/environment'
Expand Down Expand Up @@ -222,7 +223,7 @@ export async function DELETE(
await db
.insert(workspaceEnvironment)
.values({
id: workspaceRow?.id || crypto.randomUUID(),
id: workspaceRow?.id || generateId(),
workspaceId: access.credential.workspaceId,
variables: current,
createdAt: workspaceRow?.createdAt || new Date(),
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/credentials/draft/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NextResponse } from 'next/server'
import { z } from 'zod'
import { getSession } from '@/lib/auth'
import { checkWorkspaceAccess } from '@/lib/workspaces/permissions/utils'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('CredentialDraftAPI')

Expand Down Expand Up @@ -75,7 +76,7 @@ export async function POST(request: Request) {
await db
.insert(pendingCredentialDraft)
.values({
id: crypto.randomUUID(),
id: generateId(),
userId,
workspaceId,
providerId,
Expand Down
7 changes: 4 additions & 3 deletions apps/sim/app/api/credentials/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { syncWorkspaceOAuthCredentialsForUser } from '@/lib/credentials/oauth'
import { getServiceConfigByProviderId } from '@/lib/oauth'
import { checkWorkspaceAccess } from '@/lib/workspaces/permissions/utils'
import { isValidEnvVarName } from '@/executor/constants'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('CredentialsAPI')

Expand Down Expand Up @@ -423,7 +424,7 @@ export async function POST(request: NextRequest) {
}

const now = new Date()
const credentialId = crypto.randomUUID()
const credentialId = generateId()
const [workspaceRow] = await db
.select({ ownerId: workspace.ownerId })
.from(workspace)
Expand Down Expand Up @@ -451,7 +452,7 @@ export async function POST(request: NextRequest) {
if (workspaceUserIds.length > 0) {
for (const memberUserId of workspaceUserIds) {
await tx.insert(credentialMember).values({
id: crypto.randomUUID(),
id: generateId(),
credentialId,
userId: memberUserId,
role:
Expand All @@ -468,7 +469,7 @@ export async function POST(request: NextRequest) {
}
} else {
await tx.insert(credentialMember).values({
id: crypto.randomUUID(),
id: generateId(),
credentialId,
userId: session.user.id,
role: 'admin',
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/environment/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { decryptSecret, encryptSecret } from '@/lib/core/security/encryption'
import { generateRequestId } from '@/lib/core/utils/request'
import { syncPersonalEnvCredentialsForUser } from '@/lib/credentials/environment'
import type { EnvironmentVariable } from '@/stores/settings/environment'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('EnvironmentAPI')

Expand Down Expand Up @@ -42,7 +43,7 @@ export async function POST(req: NextRequest) {
await db
.insert(environment)
.values({
id: crypto.randomUUID(),
id: generateId(),
userId: session.user.id,
variables: encryptedVariables,
updatedAt: new Date(),
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/app/api/folders/[id]/duplicate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getSession } from '@/lib/auth'
import { generateRequestId } from '@/lib/core/utils/request'
import { duplicateWorkflow } from '@/lib/workflows/persistence/duplicate'
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('FolderDuplicateAPI')

Expand Down Expand Up @@ -60,7 +61,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
const targetWorkspaceId = workspaceId || sourceFolder.workspaceId

const { newFolderId, folderMapping } = await db.transaction(async (tx) => {
const newFolderId = crypto.randomUUID()
const newFolderId = generateId()
const now = new Date()
const targetParentId = parentId ?? sourceFolder.parentId

Expand Down Expand Up @@ -220,7 +221,7 @@ async function duplicateFolderStructure(
)

for (const childFolder of childFolders) {
const newChildFolderId = crypto.randomUUID()
const newChildFolderId = generateId()
folderMapping.set(childFolder.id, newChildFolderId)

await tx.insert(workflowFolder).values({
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/folders/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
import { getSession } from '@/lib/auth'
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('FoldersAPI')

Expand Down Expand Up @@ -80,7 +81,7 @@ export async function POST(request: NextRequest) {
}

// Generate a new ID
const id = crypto.randomUUID()
const id = generateId()

const newFolder = await db.transaction(async (tx) => {
let sortOrder: number
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/mcp/servers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { McpDomainNotAllowedError, validateMcpDomain } from '@/lib/mcp/domain-ch
import { getParsedBody, withMcpAuth } from '@/lib/mcp/middleware'
import { mcpService } from '@/lib/mcp/service'
import {
import { generateId } from '@/lib/core/utils/id'
createMcpErrorResponse,
createMcpSuccessResponse,
generateMcpServerId,
Expand Down Expand Up @@ -83,7 +84,7 @@ export const POST = withMcpAuth('write')(
throw e
}

const serverId = body.url ? generateMcpServerId(workspaceId, body.url) : crypto.randomUUID()
const serverId = body.url ? generateMcpServerId(workspaceId, body.url) : generateId()

const [existingServer] = await db
.select({ id: mcpServers.id, deletedAt: mcpServers.deletedAt })
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/mcp/workflow-servers/[id]/tools/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/util
import { generateParameterSchemaForWorkflow } from '@/lib/mcp/workflow-mcp-sync'
import { sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
import { hasValidStartBlock } from '@/lib/workflows/triggers/trigger-utils.server'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('WorkflowMcpToolsAPI')

Expand Down Expand Up @@ -181,7 +182,7 @@ export const POST = withMcpAuth<RouteParams>('write')(
? body.parameterSchema
: await generateParameterSchemaForWorkflow(body.workflowId)

const toolId = crypto.randomUUID()
const toolId = generateId()
const [tool] = await db
.insert(workflowMcpTool)
.values({
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/app/api/mcp/workflow-servers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createMcpErrorResponse, createMcpSuccessResponse } from '@/lib/mcp/util
import { generateParameterSchemaForWorkflow } from '@/lib/mcp/workflow-mcp-sync'
import { sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
import { hasValidStartBlock } from '@/lib/workflows/triggers/trigger-utils.server'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('WorkflowMcpServersAPI')

Expand Down Expand Up @@ -104,7 +105,7 @@ export const POST = withMcpAuth('write')(
)
}

const serverId = crypto.randomUUID()
const serverId = generateId()

const [server] = await db
.insert(workflowMcpServer)
Expand Down Expand Up @@ -160,7 +161,7 @@ export const POST = withMcpAuth('write')(

const parameterSchema = await generateParameterSchemaForWorkflow(workflowRecord.id)

const toolId = crypto.randomUUID()
const toolId = generateId()
await db.insert(workflowMcpTool).values({
id: toolId,
serverId,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/memory/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { checkInternalAuth } from '@/lib/auth/hybrid'
import { generateRequestId } from '@/lib/core/utils/request'
import { checkWorkspaceAccess } from '@/lib/workspaces/permissions/utils'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('MemoryAPI')

Expand Down Expand Up @@ -163,7 +164,7 @@ export async function POST(request: NextRequest) {

const initialData = Array.isArray(data) ? data : [data]
const now = new Date()
const id = `mem_${crypto.randomUUID().replace(/-/g, '')}`
const id = `mem_${generateId().replace(/-/g, '')}`

const { sql } = await import('drizzle-orm')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { getSession } from '@/lib/auth'
import { hasAccessControlAccess } from '@/lib/billing'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('PermissionGroupBulkMembers')

Expand Down Expand Up @@ -129,7 +130,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
}

const newMembers = usersToAdd.map((userId) => ({
id: crypto.randomUUID(),
id: generateId(),
permissionGroupId: id,
userId,
assignedBy: session.user.id,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/app/api/permission-groups/[id]/members/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { z } from 'zod'
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
import { getSession } from '@/lib/auth'
import { hasAccessControlAccess } from '@/lib/billing'
import { generateId } from '@/lib/core/utils/id'

const logger = createLogger('PermissionGroupMembers')

Expand Down Expand Up @@ -137,7 +138,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
}

const memberData = {
id: crypto.randomUUID(),
id: generateId(),
permissionGroupId: id,
userId,
assignedBy: session.user.id,
Expand Down
Loading