Skip to content

Commit 1ced54a

Browse files
authored
fix(settings): restore paste-to-destructure for workspace secrets, cleanup hooks and design tokens (#4231)
* fix(settings): restore paste-to-destructure for workspace secrets, cleanup hooks and design tokens Restores the env-var paste feature (KEY=VALUE → split rows, multi-line → multi rows) for workspace secrets that was lost when the unified Credentials tab was split into Secrets and Integrations. Adds `parseEnvVarLine`, `parseValidEnvVars`, and `handleWorkspacePaste` with full support for export prefix, quoted values, inline comments, and base64 false-positive guards. Also adds consistent value masking (show on focus / mask on blur) to new workspace input rows. Cleans up ~20 unnecessary `useCallback` wrappers, fixes a direct state mutation in `handleSingleValuePaste`, moves `e.preventDefault()` inside the `parsedVars.length > 0` guard, replaces all hardcoded hex colors with CSS variable tokens, converts template-literal classNames to `cn()`, and replaces raw `<button>` with emcn `Button`. * fix(settings): fix handlePaste silent swallow, quote-strip bug, and credential sync efficiency - Move e.preventDefault() inside parsedVars guard in handlePaste so KEY= lines don't silently discard input (mirrors handleWorkspacePaste fix from same PR) - Add value.length >= 2 guard before quote-stripping to prevent single-char values like KEY=\" from being stripped to empty and silently dropped - Introduce createWorkspaceEnvCredentials and deleteWorkspaceEnvCredentials for delta-aware credential sync (O(k) instead of O(n*m) for env var mutations) - Fix createWorkspaceEnvCredentials early-return bug that skipped credential record creation when workspace had zero members - Update credentials/[id] DELETE to use deleteWorkspaceEnvCredentials instead of full syncWorkspaceEnvCredentials - Optimize syncWorkspaceEnvCredentials to fetch workspace+member IDs in parallel once instead of once per credential * fix(settings): normalize Windows line endings in paste handlers * fix(settings): eliminate double-parse in handlePaste by inlining handleKeyValuePaste
1 parent 951fbd4 commit 1ced54a

File tree

5 files changed

+475
-361
lines changed

5 files changed

+475
-361
lines changed

apps/sim/app/api/credentials/[id]/route.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { getSession } from '@/lib/auth'
1010
import { encryptSecret } from '@/lib/core/security/encryption'
1111
import { getCredentialActorContext } from '@/lib/credentials/access'
1212
import {
13+
deleteWorkspaceEnvCredentials,
1314
syncPersonalEnvCredentialsForUser,
14-
syncWorkspaceEnvCredentials,
1515
} from '@/lib/credentials/environment'
1616
import { captureServerEvent } from '@/lib/posthog/server'
1717

@@ -317,10 +317,9 @@ export async function DELETE(
317317
set: { variables: current, updatedAt: new Date() },
318318
})
319319

320-
await syncWorkspaceEnvCredentials({
320+
await deleteWorkspaceEnvCredentials({
321321
workspaceId: access.credential.workspaceId,
322-
envKeys: Object.keys(current),
323-
actingUserId: session.user.id,
322+
removedKeys: [access.credential.envKey],
324323
})
325324

326325
captureServerEvent(

apps/sim/app/api/workspaces/[id]/environment/route.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
99
import { getSession } from '@/lib/auth'
1010
import { encryptSecret } from '@/lib/core/security/encryption'
1111
import { generateRequestId } from '@/lib/core/utils/request'
12-
import { syncWorkspaceEnvCredentials } from '@/lib/credentials/environment'
12+
import {
13+
createWorkspaceEnvCredentials,
14+
deleteWorkspaceEnvCredentials,
15+
} from '@/lib/credentials/environment'
1316
import { getPersonalAndWorkspaceEnv } from '@/lib/environment/utils'
1417
import { getUserEntityPermissions, getWorkspaceById } from '@/lib/workspaces/permissions/utils'
1518

@@ -126,11 +129,8 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
126129
set: { variables: merged, updatedAt: new Date() },
127130
})
128131

129-
await syncWorkspaceEnvCredentials({
130-
workspaceId,
131-
envKeys: Object.keys(merged),
132-
actingUserId: userId,
133-
})
132+
const newKeys = Object.keys(variables).filter((k) => !(k in existingEncrypted))
133+
await createWorkspaceEnvCredentials({ workspaceId, newKeys, actingUserId: userId })
134134

135135
recordAudit({
136136
workspaceId,
@@ -215,11 +215,7 @@ export async function DELETE(
215215
set: { variables: current, updatedAt: new Date() },
216216
})
217217

218-
await syncWorkspaceEnvCredentials({
219-
workspaceId,
220-
envKeys: Object.keys(current),
221-
actingUserId: userId,
222-
})
218+
await deleteWorkspaceEnvCredentials({ workspaceId, removedKeys: keys })
223219

224220
recordAudit({
225221
workspaceId,

0 commit comments

Comments
 (0)