Skip to content

Commit a11573a

Browse files
committed
improvement(credentials): simplify and clean up the review-round changes
1 parent ea714d2 commit a11573a

3 files changed

Lines changed: 20 additions & 35 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/integrations/[block]/integration-block-detail.tsx‎

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ function IntegrationBlockDetailContent({ integration, workspaceId }: Integration
175175
const [oauthOpen, setOAuthOpen] = useState(false)
176176
const [personalTokenOpen, setPersonalTokenOpen] = useState(false)
177177
const isGitLab = integration.slug === 'gitlab'
178-
const personalTokenAvailable =
179-
isGitLab && (availability?.state === 'ready' || availability?.state === 'limited')
178+
const deploymentAvailable = availability?.state === 'ready' || availability?.state === 'limited'
179+
const personalTokenAvailable = isGitLab && deploymentAvailable
180180

181181
const { data: credentials = [], isPending: credentialsLoading } = useWorkspaceCredentials({
182182
workspaceId,
@@ -211,12 +211,8 @@ function IntegrationBlockDetailContent({ integration, workspaceId }: Integration
211211
serviceName: oauthService?.serviceName,
212212
serviceIcon: oauthService?.serviceIcon,
213213
})
214-
const serviceAccountDeploymentAvailable =
215-
availability?.state === 'ready' || availability?.state === 'limited'
216214
const hasServiceAccount =
217-
serviceAccountDeploymentAvailable &&
218-
Boolean(serviceAccountTarget) &&
219-
!serviceAccountTarget?.hidden
215+
deploymentAvailable && Boolean(serviceAccountTarget) && !serviceAccountTarget?.hidden
220216
const serviceAccountConnectLabel = serviceAccountTarget?.label ?? 'Add service account'
221217
const hasHandledConnectQueryRef = useRef(false)
222218

@@ -280,6 +276,8 @@ function IntegrationBlockDetailContent({ integration, workspaceId }: Integration
280276
: []),
281277
]
282278

279+
const singleConnectOption = connectOptions.length === 1 ? connectOptions[0] : undefined
280+
283281
const handleSelectConnectOption = (value: string) => {
284282
if (value === CONNECT_MODE.oauth) setOAuthOpen(true)
285283
else if (value === CONNECT_MODE.serviceAccount) setServiceAccountOpen(true)
@@ -308,22 +306,18 @@ function IntegrationBlockDetailContent({ integration, workspaceId }: Integration
308306
onChange={handleSelectConnectOption}
309307
matchTriggerWidth={false}
310308
/>
311-
) : personalTokenAvailable ? (
312-
<Chip variant='primary' leftIcon={Plus} onClick={() => setPersonalTokenOpen(true)}>
313-
Add personal token
309+
) : singleConnectOption ? (
310+
<Chip
311+
variant='primary'
312+
leftIcon={Plus}
313+
onClick={() => handleSelectConnectOption(singleConnectOption.value)}
314+
>
315+
{singleConnectOption.value === CONNECT_MODE.oauth
316+
? 'Add to Sim'
317+
: singleConnectOption.label}
314318
</Chip>
315319
) : oauthService ? (
316-
oauthAvailable ? (
317-
<Chip variant='primary' leftIcon={Plus} onClick={() => setOAuthOpen(true)}>
318-
Add to Sim
319-
</Chip>
320-
) : hasServiceAccount ? (
321-
<Chip variant='primary' leftIcon={Plus} onClick={() => setServiceAccountOpen(true)}>
322-
{serviceAccountConnectLabel}
323-
</Chip>
324-
) : (
325-
<Chip disabled>Unavailable</Chip>
326-
)
320+
<Chip disabled>Unavailable</Chip>
327321
) : chatEnabled ? (
328322
<Chip variant='primary' leftIcon={Plus} onClick={handleAddInChat}>
329323
Add to Sim

‎apps/sim/lib/credentials/token-service-accounts/validators/gitlab.ts‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toArray, toRecord } from '@sim/utils/object'
1+
import { toRecord } from '@sim/utils/object'
22
import {
33
type SecureFetchResponse,
44
secureFetchWithValidation,
@@ -62,27 +62,17 @@ export async function validateGitLabServiceAccount(
6262
{ step: 'verify' }
6363
)
6464
}
65-
let body: unknown
66-
try {
67-
body = await response.json()
68-
} catch {
69-
throw new TokenServiceAccountValidationError('provider_unavailable', 502, {
70-
step: 'verify',
71-
reason: 'GitLab returned a malformed token lookup',
72-
})
73-
}
74-
const token = toRecord(body)
65+
const token = toRecord(await response.json().catch(() => null))
7566
if (typeof token.active !== 'boolean' || !Array.isArray(token.scopes)) {
7667
throw new TokenServiceAccountValidationError('provider_unavailable', 502, {
7768
step: 'verify',
7869
reason: 'GitLab returned an unexpected token lookup',
7970
})
8071
}
81-
const scopes = toArray(token.scopes)
8272
if (
83-
token.active !== true ||
73+
!token.active ||
8474
token.revoked === true ||
85-
!scopes.some((scope) => API_SCOPES.has(String(scope)))
75+
!token.scopes.some((scope) => API_SCOPES.has(String(scope)))
8676
) {
8777
throw new TokenServiceAccountValidationError('invalid_credentials', 400, {
8878
step: 'verify',

‎apps/sim/tools/whatsapp/whatsapp.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('WhatsApp request URL and headers', () => {
2828
'refuses a phone number ID that would leave its path segment (%s)',
2929
(phoneNumberId) => {
3030
expect(() => buildMessagesUrl(phoneNumberId)).toThrow(/phoneNumberId/)
31+
expect(() => buildMediaUploadUrl(phoneNumberId)).toThrow(/phoneNumberId/)
3132
}
3233
)
3334
})

0 commit comments

Comments
 (0)