(params: {
apiProvider: string
session: SdkAccountSessionInput
})
| 23 | > |
| 24 | |
| 25 | export function buildSdkAccountInfo(params: { |
| 26 | apiProvider: string |
| 27 | session: SdkAccountSessionInput |
| 28 | }): SdkAccountInfo | undefined { |
| 29 | if (params.apiProvider !== 'firstParty') { |
| 30 | return undefined |
| 31 | } |
| 32 | |
| 33 | const { session } = params |
| 34 | const accountInfo: SdkAccountInfo = {} |
| 35 | |
| 36 | if (session.principalSource === 'managed_oauth') { |
| 37 | accountInfo.subscription = |
| 38 | session.subscription.subscriptionName ?? 'Noumena Managed' |
| 39 | } else { |
| 40 | accountInfo.tokenSource = session.rawAuthTokenSource ?? 'none' |
| 41 | } |
| 42 | |
| 43 | if (session.hasUsableApiKey && session.rawApiKeySource) { |
| 44 | accountInfo.apiKeySource = session.rawApiKeySource |
| 45 | } |
| 46 | |
| 47 | if ( |
| 48 | session.principalSource === 'managed_oauth' && |
| 49 | session.sessionState === 'expired' |
| 50 | ) { |
| 51 | accountInfo.authTokenExpired = true |
| 52 | } |
| 53 | |
| 54 | const hasManagedAccountContext = |
| 55 | session.principalSource === 'managed_oauth' || |
| 56 | session.principalSource === 'console_api_key' |
| 57 | |
| 58 | if (hasManagedAccountContext) { |
| 59 | if (session.identity.organizationName) { |
| 60 | accountInfo.organization = session.identity.organizationName |
| 61 | } |
| 62 | if (session.identity.email) { |
| 63 | accountInfo.email = session.identity.email |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return accountInfo |
| 68 | } |
| 69 | |
| 70 | export function getCurrentSdkAccountInfo(): SdkAccountInfo | undefined { |
| 71 | return buildSdkAccountInfo({ |
no outgoing calls
no test coverage detected