(apiKey: string | undefined)
| 44 | } |
| 45 | |
| 46 | async function resolveApiClient(apiKey: string | undefined): Promise<ManagementApiClient> { |
| 47 | if (apiKey) { |
| 48 | return createManagementApiClient({ baseUrl: getManagementApiUrl(), token: apiKey }) |
| 49 | } |
| 50 | |
| 51 | const tokenStorage = new FileTokenStorage() |
| 52 | const tokens = await tokenStorage.getTokens() |
| 53 | |
| 54 | if (!tokens) { |
| 55 | console.log(`Opening browser to authenticate on ${dim('console.prisma.io')}...`) |
| 56 | await login({ utmMedium: 'command-postgres-link' }) |
| 57 | } |
| 58 | |
| 59 | return createAuthenticatedManagementAPI().client |
| 60 | } |
| 61 | |
| 62 | function isExpiredSessionError(err: unknown): boolean { |
| 63 | return err instanceof AuthError && err.refreshTokenInvalid |
no test coverage detected