"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient, Pipeline } from \"@azure/core-rest-pipeline\";\nimport {\n bearerTokenAuthenticationPolicy,\n createDefaultHttpClient,\n createPipelineFromOptions,\n} from \"@azure/core-rest-pipeline\";\nimport type { KeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isTokenCredential } from \"@azure/core-auth\";\n\nimport type { ClientOptions } from \"./common.js\";\nimport { apiVersionPolicy } from \"./apiVersionPolicy.js\";\nimport { keyCredentialAuthenticationPolicy } from \"./keyCredentialAuthenticationPolicy.js\";\n\nlet cachedHttpClient: HttpClient | undefined;\n\n/**\n * Optional parameters for adding a credential policy to the pipeline.\n */\nexport interface AddCredentialPipelinePolicyOptions {\n /**\n * Options related to the client.\n */\n clientOptions?: ClientOptions;\n /**\n * The credential to use.\n */\n credential?: TokenCredential | KeyCredential;\n}\n\n/**\n * Adds a credential policy to the pipeline if a credential is provided. If none is provided, no policy is added.\n */\nexport function addCredentialPipelinePolicy(\n pipeline: Pipeline,\n endpoint: string,\n options: AddCredentialPipelinePolicyOptions = {},\n): void {\n const { credential, clientOptions } = options;\n if (!credential) {\n return;\n }\n\n if (isTokenCredential(credential)) {\n const tokenPolicy = bearerTokenAuthenticationPolicy({\n credential,\n scopes: clientOptions?.credentials?.scopes ?? `${endpoint}/.default`,\n });\n pipeline.addPolicy(tokenPolicy);\n } else if (isKeyCredential(credential)) {\n if (!clientOptions?.credentials?.apiKeyHeaderName) {\n throw new Error(`Missing API Key Header Name`);\n }\n const keyPolicy = keyCredentialAuthenticationPolicy(\n credential,\n clientOptions?.credentials?.apiKeyHeaderName,\n );\n pipeline.addPolicy(keyPolicy);\n }\n}\n\n/**\n * Creates a default rest pipeline to re-use accross Rest Level Clients\n */\nexport function createDefaultPipeline(\n endpoint: string,\n credential?: TokenCredential | KeyCredential,\n options: ClientOptions = {},\n): Pipeline {\n const pipeline = createPipelineFromOptions(options);\n\n pipeline.addPolicy(apiVersionPolicy(options));\n\n addCredentialPipelinePolicy(pipeline, endpoint, { credential, clientOptions: options });\n return pipeline;\n}\n\nfunction isKeyCredential(credential: any): credential is KeyCredential {\n return (credential as KeyCredential).key !== undefined;\n}\n\nexport function getCachedDefaultHttpsClient(): HttpClient {\n if (!cachedHttpClient) {\n cachedHttpClient = createDefaultHttpClient();\n }\n\n return cachedHttpClient;\n}\n"],
|
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gCAIO;AAEP,uBAAkC;AAGlC,8BAAiC;AACjC,+CAAkD;AAElD,IAAI;AAmBG,SAAS,4BACd,UACA,UACA,UAA8C,CAAC,GACzC;AACN,QAAM,EAAE,YAAY,cAAc,IAAI;AACtC,MAAI,CAAC,YAAY;AACf;AAAA,EACF;AAEA,UAAI,oCAAkB,UAAU,GAAG;AACjC,UAAM,kBAAc,2DAAgC;AAAA,MAClD;AAAA,MACA,QAAQ,eAAe,aAAa,UAAU,GAAG,QAAQ;AAAA,IAC3D,CAAC;AACD,aAAS,UAAU,WAAW;AAAA,EAChC,WAAW,gBAAgB,UAAU,GAAG;AACtC,QAAI,CAAC,eAAe,aAAa,kBAAkB;AACjD,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AACA,UAAM,gBAAY;AAAA,MAChB;AAAA,MACA,eAAe,aAAa;AAAA,IAC9B;AACA,aAAS,UAAU,SAAS;AAAA,EAC9B;AACF;AAKO,SAAS,sBACd,UACA,YACA,UAAyB,CAAC,GAChB;AACV,QAAM,eAAW,qDAA0B,OAAO;AAElD,WAAS,cAAU,0CAAiB,OAAO,CAAC;AAE5C,8BAA4B,UAAU,UAAU,EAAE,YAAY,eAAe,QAAQ,CAAC;AACtF,SAAO;AACT;AAEA,SAAS,gBAAgB,YAA8C;AACrE,SAAQ,WAA6B,QAAQ;AAC/C;AAEO,SAAS,8BAA0C;AACxD,MAAI,CAAC,kBAAkB;AACrB,2BAAmB,mDAAwB;AAAA,EAC7C;AAEA,SAAO;AACT;",
|