(
options: ResolveManagedRemoteCapabilityOptions = {},
)
| 148 | } |
| 149 | |
| 150 | export async function resolveManagedRemoteCapability( |
| 151 | options: ResolveManagedRemoteCapabilityOptions = {}, |
| 152 | ): Promise<ManagedRemoteCapability> { |
| 153 | const activeSession = await getAuthRuntime().resolveSession({ |
| 154 | allowRefresh: true, |
| 155 | }) |
| 156 | const session = |
| 157 | activeSession.principalSource === 'managed_oauth' |
| 158 | ? activeSession |
| 159 | : (getAuthRuntime().getCurrentManagedSession() ?? activeSession) |
| 160 | const accessTokenOverride = normalizeAccessTokenOverride( |
| 161 | options.accessTokenOverride, |
| 162 | ) |
| 163 | |
| 164 | if (accessTokenOverride) { |
| 165 | const orgUUID = |
| 166 | session.identity.organizationUuid?.trim() || (await getOrganizationUUID()) |
| 167 | if (!orgUUID) { |
| 168 | throw new Error('Unable to get organization UUID') |
| 169 | } |
| 170 | |
| 171 | return { |
| 172 | accessToken: accessTokenOverride, |
| 173 | orgUUID, |
| 174 | session, |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | if (!hasUsableManagedRemotePrincipal(session) || !session.accessToken) { |
| 179 | throw new Error(MANAGED_REMOTE_AUTH_REQUIRED_MESSAGE) |
| 180 | } |
| 181 | |
| 182 | const orgUUID = |
| 183 | session.identity.organizationUuid?.trim() || (await getOrganizationUUID()) |
| 184 | if (!orgUUID) { |
| 185 | throw new Error('Unable to get organization UUID') |
| 186 | } |
| 187 | |
| 188 | return { |
| 189 | accessToken: session.accessToken, |
| 190 | orgUUID, |
| 191 | session, |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | export async function resolveManagedRemoteBootstrapCapability( |
| 196 | options: ResolveManagedRemoteCapabilityOptions = {}, |
no test coverage detected