{"version":3,"sources":["jsdelivr-header.js","/npm/@azure-tools/test-credential@1.3.1/src/noOpCredential.ts","/npm/@azure-tools/test-credential@1.3.1/src/browserRelayCredential.ts","/npm/@azure-tools/test-credential@1.3.1/src/index.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,iOCMa,eACX,QAAA,GACE,OAAO,QAAQ,QAAQ,CACrB,MAAO,oBACP,mBAAoB,KAAK,MAAQ,O,ECPjC,MAAO,iCAAiC,MAC5C,WAAA,CACE,EACO,GAEP,MAAM,GAFC,KAAK,MAAL,EAGP,KAAK,KAAO,0B,EAShB,eAAe,iBACb,EACA,EAAiD,IAEjD,MAAM,QAAiB,MAAM,GAAG,eAA0B,CACxD,OAAQ,MACR,KAAM,KAAK,UAAU,GACrB,QAAS,CAAE,eAAgB,sBAG7B,IAAK,EAAS,GAAI,CAChB,GAAwB,MAApB,EAAS,OAEX,MAAM,IAAI,yBACR,2CACQ,EAAS,QAA+B,OAIpD,MAAM,IAAI,yBACR,qDAAqD,EAAS,S,CAIlE,aAAe,EAAS,QAA2B,EACrD,CAUA,eAAe,kBACb,EACA,EACA,EACA,EAA2B,IAE3B,MAAM,EAAS,IAAI,gBAAgB,CACjC,SACA,QAAS,KAAK,UAAU,KAGpB,QAAiB,MAAM,GAAG,eAAyB,WAAsB,KAE/E,IAAK,EAAS,GAAI,CAChB,GAAwB,MAApB,EAAS,OAEX,MAAM,IAAI,yBACR,uCACQ,EAAS,QAA+B,OAIpD,MAAM,IAAI,yBACR,yDAAyD,EAAS,S,CAItE,aAAc,EAAS,MACzB,CASgB,SAAA,6BACd,EAAuC,IAEvC,IAAI,EAEJ,MAAM,sBAAE,EAAwB,0BAA4C,EAAf,EAAe,aAAA,EAAtE,2BAEN,MAAO,CACL,SAAc,MAAC,EAAQ,KAChB,IACH,QAAqB,iBAAiB,EAAuB,UAGlD,kBAAkB,EAAuB,EAAc,EAAQ,IAGlF,CC7DgB,SAAA,qBACd,EAAsD,IAEtD,GAAI,8BACF,OAAO,IAAI,eACN,GAAI,mBACT,OAAO,6BAA6B,GAC/B,CACL,MAAqC,EAAe,aAAA,EAA9C,2BACA,EAAoB,QAAQ,IAAI,mBAEtC,GAAI,EAAmB,CACrB,MAAM,EAAsB,QAAQ,IAAI,wCAClC,EAAW,QAAQ,IAAI,4BACvB,EAAW,QAAQ,IAAI,4BAC7B,GAAI,GAAuB,GAAY,EACrC,OAAO,IAAI,kCACT,EACA,EACA,EACA,EACA,GAGJ,MAAM,IAAI,MAAM,yGACS,gBAAkC,gBAAuB,I,CAEpF,OAAO,IAAI,gCACT,IAAI,mCAA0B,GAC9B,IAAI,4BAAmB,GACvB,IAAI,qCAA4B,GAIhC,IAAI,+BAAsB,G,CAGhC,C","file":"/npm/@azure-tools/test-credential@1.3.1/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.19.2.\n * Original file: /npm/@azure-tools/test-credential@1.3.1/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken, TokenCredential } from \"@azure/core-auth\";\n\n/**\n * `TokenCredential` implementation for playback.\n * If your regular AAD credentials don't take the recorder httpClient option, the AAD traffic won't be recorded.\n * In this case, you'll need to bypass the AAD requests with no-op.\n *\n * Using this NoOpCredential as your credential in playback mode would help you bypass the AAD traffic.\n */\nexport class NoOpCredential implements TokenCredential {\n  getToken(): Promise<AccessToken> {\n    return Promise.resolve({\n      token: \"SecretPlaceholder\",\n      expiresOnTimestamp: Date.now() + 86400 * 1000,\n    });\n  }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { CreateTestCredentialOptions, DefaultAzureCredentialCombinedOptions } from \".\";\n\n/**\n * Authentication error thrown when the relay server could not authenticate.\n */\nexport class RelayAuthenticationError extends Error {\n  constructor(\n    message: string,\n    public cause?: unknown,\n  ) {\n    super(message);\n    this.name = \"RelayAuthenticationError\";\n  }\n}\n\n/**\n * Ask the relay server to create a credential\n * @param relayServer Relay server URL\n * @returns id of the created credential, to be passed back to the relay when calling getToken\n */\nasync function createCredential(\n  relayServer: string,\n  options: DefaultAzureCredentialCombinedOptions = {},\n): Promise<string> {\n  const response = await fetch(`${relayServer}credential/`, {\n    method: \"PUT\",\n    body: JSON.stringify(options),\n    headers: { \"Content-Type\": \"application/json\" },\n  });\n\n  if (!response.ok) {\n    if (response.status === 400) {\n      // Throw the error that the relay received\n      throw new RelayAuthenticationError(\n        \"Relay could not create credential\",\n        ((await response.json()) as { error: unknown }).error,\n      );\n    }\n\n    throw new RelayAuthenticationError(\n      `Relay could not create credential: got error code ${response.status}`,\n    );\n  }\n\n  return ((await response.json()) as { id: string }).id;\n}\n\n/**\n * Get a token from the relay\n * @param relayServer Relay server URL\n * @param credentialId ID of the credential (created using createCredential) to get the token with\n * @param scopes Scopes\n * @param options Credential options to be passed to getToken\n * @returns Access token from the relay\n */\nasync function getTokenFromRelay(\n  relayServer: string,\n  credentialId: string,\n  scopes: string | string[],\n  options: GetTokenOptions = {},\n): Promise<AccessToken> {\n  const params = new URLSearchParams({\n    scopes,\n    options: JSON.stringify(options),\n  });\n\n  const response = await fetch(`${relayServer}credential/${credentialId}/token?${params}`);\n\n  if (!response.ok) {\n    if (response.status === 400) {\n      // Throw the error that the relay received\n      throw new RelayAuthenticationError(\n        \"Relay was unable to get token\",\n        ((await response.json()) as { error: unknown }).error,\n      );\n    }\n\n    throw new RelayAuthenticationError(\n      `Could not get token from relay server: got error code ${response.status}`,\n    );\n  }\n\n  return (await response.json()) as AccessToken;\n}\n\n/**\n * Create a credential that can be used in the browser to get tokens from a relay server.\n * This credential should be used in conjunction with the relay server provided by the dev-tool package.\n *\n * @param options options for creating the credential.\n * @returns a credential which will use the relay endpoint to get access tokens.\n */\nexport function createBrowserRelayCredential(\n  options: CreateTestCredentialOptions = {},\n): TokenCredential {\n  let credentialId: string | undefined = undefined;\n\n  const { browserRelayServerUrl = \"http://localhost:4895/\", ...dacOptions } = options;\n\n  return {\n    async getToken(scopes, getTokenOptions) {\n      if (!credentialId) {\n        credentialId = await createCredential(browserRelayServerUrl, dacOptions);\n      }\n\n      return await getTokenFromRelay(browserRelayServerUrl, credentialId, scopes, getTokenOptions);\n    },\n  };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n  AzureCliCredential,\n  AzureDeveloperCliCredential,\n  AzurePipelinesCredential,\n  AzurePowerShellCredential,\n  ChainedTokenCredential,\n  DefaultAzureCredentialClientIdOptions,\n  DefaultAzureCredentialOptions,\n  DefaultAzureCredentialResourceIdOptions,\n  EnvironmentCredential,\n} from \"@azure/identity\";\nimport { isPlaybackMode } from \"@azure-tools/test-recorder\";\nimport { NoOpCredential } from \"./noOpCredential\";\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { isBrowser } from \"@azure/core-util\";\nimport { createBrowserRelayCredential } from \"./browserRelayCredential\";\n\n/**\n * Alias of the different possible options shapes for the DefaultAzureCredential constructor.\n */\nexport type DefaultAzureCredentialCombinedOptions =\n  | DefaultAzureCredentialClientIdOptions\n  | DefaultAzureCredentialResourceIdOptions\n  | DefaultAzureCredentialOptions;\n\n/**\n * Options to be passed to createTestCredential.\n * These options are the same as DefaultAzureCredential, with the addition of an option for the relay server\n * URL used in browser tests.\n */\nexport type CreateTestCredentialOptions = DefaultAzureCredentialCombinedOptions & {\n  /**\n   * URL of the relay server for the browser relay credential used in browser tests.\n   */\n  browserRelayServerUrl?: string;\n};\n\n/**\n * ## Credential to be used in the tests.\n *\n * ### In playback mode\n *  - returns the NoOpCredential (helps bypass the AAD traffic)\n *\n * ### In record/live modes\n *  - returns the DefaultAzureCredential in Node (expects that you used [`User Auth` or `Auth via development tools`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#authenticate-users) credentials)\n *  - Returns browser relay credential in browser. Requires the dev-tool browser relay server to be running (dev-tool run start-browser-relay, or is automatically started when using the dev-tool browser test command)\n *  - AAD traffic won't be recorded if this credential is used.\n */\nexport function createTestCredential(\n  tokenCredentialOptions: CreateTestCredentialOptions = {},\n): TokenCredential {\n  if (isPlaybackMode()) {\n    return new NoOpCredential();\n  } else if (isBrowser) {\n    return createBrowserRelayCredential(tokenCredentialOptions);\n  } else {\n    const { browserRelayServerUrl: _, ...dacOptions } = tokenCredentialOptions;\n    const systemAccessToken = process.env.SYSTEM_ACCESSTOKEN;\n    // If we have a system access token, we are in Azure Pipelines\n    if (systemAccessToken) {\n      const serviceConnectionID = process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID;\n      const clientID = process.env.AZURESUBSCRIPTION_CLIENT_ID;\n      const tenantID = process.env.AZURESUBSCRIPTION_TENANT_ID;\n      if (serviceConnectionID && clientID && tenantID) {\n        return new AzurePipelinesCredential(\n          tenantID,\n          clientID,\n          serviceConnectionID,\n          systemAccessToken,\n          dacOptions,\n        );\n      }\n      throw new Error(`Running in Azure Pipelines environment. Missing environment variables: \n        serviceConnectionID: ${serviceConnectionID}, tenantID: ${tenantID}, clientID: ${clientID}`);\n    }\n    return new ChainedTokenCredential(\n      new AzurePowerShellCredential(dacOptions),\n      new AzureCliCredential(dacOptions),\n      new AzureDeveloperCliCredential(dacOptions),\n      // Keep Environment Credential for packages that have not migrated to Federated Authentication\n      // See the migration guide for more information\n      // https://dev.azure.com/azure-sdk/internal/_wiki/wikis/internal.wiki/1080/Secret-auth-migration\n      new EnvironmentCredential(dacOptions),\n    );\n  }\n}\n\nexport { NoOpCredential };\n"]}