( id: string, displayName: string, providerId: string, updatedAt: Date, scope: string | null, credentialType: 'oauth' | 'service_account' = 'oauth' )
| 22 | const logger = createLogger('OAuthCredentialsAPI') |
| 23 | |
| 24 | function toCredentialResponse( |
| 25 | id: string, |
| 26 | displayName: string, |
| 27 | providerId: string, |
| 28 | updatedAt: Date, |
| 29 | scope: string | null, |
| 30 | credentialType: 'oauth' | 'service_account' = 'oauth' |
| 31 | ) { |
| 32 | const storedScope = scope?.trim() |
| 33 | // Some providers (e.g. Box) don't return scopes in their token response, |
| 34 | // so the DB column stays empty. Fall back to the configured scopes for |
| 35 | // the provider so the credential-selector doesn't show a false |
| 36 | // "Additional permissions required" banner. |
| 37 | const scopes = storedScope |
| 38 | ? storedScope.split(/[\s,]+/).filter(Boolean) |
| 39 | : getCanonicalScopesForProvider(providerId) |
| 40 | const [_, featureType = 'default'] = providerId.split('-') |
| 41 | |
| 42 | return { |
| 43 | id, |
| 44 | name: displayName, |
| 45 | provider: providerId, |
| 46 | type: credentialType, |
| 47 | lastUsed: updatedAt.toISOString(), |
| 48 | isDefault: featureType === 'default', |
| 49 | scopes, |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get credentials for a specific provider |
no test coverage detected