MCPcopy Index your code
hub / github.com/simstudioai/sim / getAccessibleOAuthCredentials

Function getAccessibleOAuthCredentials

apps/sim/lib/credentials/environment.ts:487–555  ·  view source on GitHub ↗
(
  workspaceId: string,
  userId: string,
  options?: { isWorkspaceAdmin?: boolean }
)

Source from the content-addressed store, hash-verified

485}
486
487export async function getAccessibleOAuthCredentials(
488 workspaceId: string,
489 userId: string,
490 options?: { isWorkspaceAdmin?: boolean }
491): Promise<AccessibleOAuthCredential[]> {
492 const isWorkspaceAdmin =
493 options?.isWorkspaceAdmin ?? (await hasWorkspaceAdminAccess(userId, workspaceId))
494
495 if (isWorkspaceAdmin) {
496 const rows = await db
497 .select({
498 id: credential.id,
499 providerId: credential.providerId,
500 displayName: credential.displayName,
501 updatedAt: credential.updatedAt,
502 })
503 .from(credential)
504 .where(
505 and(
506 eq(credential.workspaceId, workspaceId),
507 inArray(credential.type, ['oauth', 'service_account'])
508 )
509 )
510
511 return rows
512 .filter((row): row is typeof row & { providerId: string } => Boolean(row.providerId))
513 .map((row) => ({
514 id: row.id,
515 providerId: row.providerId,
516 displayName: row.displayName,
517 role: 'admin' as const,
518 updatedAt: row.updatedAt,
519 }))
520 }
521
522 const rows = await db
523 .select({
524 id: credential.id,
525 providerId: credential.providerId,
526 displayName: credential.displayName,
527 role: credentialMember.role,
528 updatedAt: credential.updatedAt,
529 })
530 .from(credential)
531 .innerJoin(
532 credentialMember,
533 and(
534 eq(credentialMember.credentialId, credential.id),
535 eq(credentialMember.userId, userId),
536 eq(credentialMember.status, 'active')
537 )
538 )
539 .where(
540 and(
541 eq(credential.workspaceId, workspaceId),
542 inArray(credential.type, ['oauth', 'service_account'])
543 )
544 )

Callers 3

executeFunction · 0.90
buildWorkspaceMdDataFunction · 0.90

Calls 2

hasWorkspaceAdminAccessFunction · 0.90
eqFunction · 0.50

Tested by

no test coverage detected