@azure/core-client 1.9.3-alpha.20240701.3 → 1.9.3-alpha.20240705.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/browser/serviceClient.d.ts +0 -1
  2. package/dist/browser/serviceClient.d.ts.map +1 -1
  3. package/dist/browser/serviceClient.js +0 -1
  4. package/dist/browser/serviceClient.js.map +1 -1
  5. package/dist/commonjs/authorizeRequestOnClaimChallenge.js +2 -3
  6. package/dist/commonjs/authorizeRequestOnClaimChallenge.js.map +1 -1
  7. package/dist/commonjs/base64.js +4 -5
  8. package/dist/commonjs/base64.js.map +1 -1
  9. package/dist/commonjs/deserializationPolicy.js +2 -2
  10. package/dist/commonjs/deserializationPolicy.js.map +1 -1
  11. package/dist/commonjs/httpClientCache.js +1 -2
  12. package/dist/commonjs/httpClientCache.js.map +1 -1
  13. package/dist/commonjs/interfaceHelpers.js +2 -3
  14. package/dist/commonjs/interfaceHelpers.js.map +1 -1
  15. package/dist/commonjs/operationHelpers.js +2 -3
  16. package/dist/commonjs/operationHelpers.js.map +1 -1
  17. package/dist/commonjs/pipeline.js +1 -2
  18. package/dist/commonjs/pipeline.js.map +1 -1
  19. package/dist/commonjs/serializationPolicy.js +4 -4
  20. package/dist/commonjs/serializationPolicy.js.map +1 -1
  21. package/dist/commonjs/serializer.js +2 -2
  22. package/dist/commonjs/serializer.js.map +1 -1
  23. package/dist/commonjs/serviceClient.d.ts +0 -1
  24. package/dist/commonjs/serviceClient.d.ts.map +1 -1
  25. package/dist/commonjs/serviceClient.js +0 -1
  26. package/dist/commonjs/serviceClient.js.map +1 -1
  27. package/dist/commonjs/urlHelpers.js +2 -3
  28. package/dist/commonjs/urlHelpers.js.map +1 -1
  29. package/dist/commonjs/utils.js +4 -5
  30. package/dist/commonjs/utils.js.map +1 -1
  31. package/dist/core-client.d.ts +0 -1
  32. package/dist/esm/serviceClient.d.ts +0 -1
  33. package/dist/esm/serviceClient.d.ts.map +1 -1
  34. package/dist/esm/serviceClient.js +0 -1
  35. package/dist/esm/serviceClient.js.map +1 -1
  36. package/dist/esm/state.d.ts.map +1 -1
  37. package/dist/react-native/serviceClient.d.ts +0 -1
  38. package/dist/react-native/serviceClient.d.ts.map +1 -1
  39. package/dist/react-native/serviceClient.js +0 -1
  40. package/dist/react-native/serviceClient.js.map +1 -1
  41. package/dist/react-native/state.d.ts.map +1 -1
  42. package/package.json +5 -4
@@ -63,7 +63,6 @@ export declare class ServiceClient {
63
63
  readonly pipeline: Pipeline;
64
64
  /**
65
65
  * The ServiceClient constructor
66
- * @param credential - The credentials used for authentication with the service.
67
66
  * @param options - The service client options that govern the behavior of the client.
68
67
  */
69
68
  constructor(options?: ServiceClientOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"serviceClient.d.ts","sourceRoot":"","sources":["../../src/serviceClient.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAElB,aAAa,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,QAAQ,EACR,eAAe,EACf,gBAAgB,EAEjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AASnD;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACrC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,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OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;IAEpC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAS;IAE9C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAU;IAEpD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;IAEzC;;OAEG;IACH,SAAgB,QAAQ,EAAE,QAAQ,CAAC;IAEnC;;;OAGG;gBACS,OAAO,GAAE,oBAAyB;IAwB9C;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAItE;;;;;OAKG;IACG,oBAAoB,CAAC,CAAC,EAC1B,kBAAkB,EAAE,kBAAkB,EACtC,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,CAAC,CAAC;CA8Fd"}
@@ -14,7 +14,6 @@ import { logger } from "./log.js";
14
14
  export class ServiceClient {
15
15
  /**
16
16
  * The ServiceClient constructor
17
- * @param credential - The credentials used for authentication with the service.
18
17
  * @param options - The service client options that govern the behavior of the client.
19
18
  */
20
19
  constructor(options = {}) {
@@ -1 +1 @@
1
- {"version":3,"file":"serviceClient.js","sourceRoot":"","sources":["../../src/serviceClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OAAO,EAKL,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,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I,KAAK,CACb,2JAA2J,CAC5J,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n CommonClientOptions,\n OperationArguments,\n OperationRequest,\n OperationSpec,\n} from \"./interfaces.js\";\nimport {\n HttpClient,\n Pipeline,\n PipelineRequest,\n PipelineResponse,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { createClientPipeline } from \"./pipeline.js\";\nimport { flattenResponse } from \"./utils.js\";\nimport { getCachedDefaultHttpClient } from \"./httpClientCache.js\";\nimport { getOperationRequestInfo } from \"./operationHelpers.js\";\nimport { getRequestUrl } from \"./urlHelpers.js\";\nimport { getStreamingResponseStatusCodes } from \"./interfaceHelpers.js\";\nimport { logger } from \"./log.js\";\n\n/**\n * Options to be provided while creating the client.\n */\nexport interface ServiceClientOptions extends CommonClientOptions {\n /**\n * If specified, this is the base URI that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n * @deprecated This property is deprecated and will be removed soon, please use endpoint instead\n */\n baseUri?: string;\n /**\n * If specified, this is the endpoint that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n * to encourage customer to use endpoint, we mark the baseUri as deprecated.\n */\n endpoint?: string;\n /**\n * If specified, will be used to build the BearerTokenAuthenticationPolicy.\n */\n credentialScopes?: string | string[];\n /**\n * The default request content type for the service.\n * Used if no requestContentType is present on an OperationSpec.\n */\n requestContentType?: string;\n /**\n * Credential used to authenticate the request.\n */\n credential?: TokenCredential;\n /**\n * A customized pipeline to use, otherwise a default one will be created.\n */\n pipeline?: Pipeline;\n}\n\n/**\n * Initializes a new instance of the ServiceClient.\n */\nexport class ServiceClient {\n /**\n * If specified, this is the base URI that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n */\n private readonly _endpoint?: string;\n\n /**\n * The default request content type for the service.\n * Used if no requestContentType is present on an OperationSpec.\n */\n private readonly _requestContentType?: string;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n private readonly _allowInsecureConnection?: boolean;\n\n /**\n * The HTTP client that will be used to send requests.\n */\n private readonly _httpClient: HttpClient;\n\n /**\n * The pipeline used by this client to make requests\n */\n public readonly pipeline: Pipeline;\n\n /**\n * The ServiceClient constructor\n * @param credential - The credentials used for authentication with the service.\n * @param options - The service client options that govern the behavior of the client.\n */\n constructor(options: ServiceClientOptions = {}) {\n this._requestContentType = options.requestContentType;\n this._endpoint = options.endpoint ?? options.baseUri;\n if (options.baseUri) {\n logger.warning(\n \"The baseUri option for SDK Clients has been deprecated, please use endpoint instead.\",\n );\n }\n this._allowInsecureConnection = options.allowInsecureConnection;\n this._httpClient = options.httpClient || getCachedDefaultHttpClient();\n\n this.pipeline = options.pipeline || createDefaultPipeline(options);\n if (options.additionalPolicies?.length) {\n for (const { policy, position } of options.additionalPolicies) {\n // Sign happens after Retry and is commonly needed to occur\n // before policies that intercept post-retry.\n const afterPhase = position === \"perRetry\" ? \"Sign\" : undefined;\n this.pipeline.addPolicy(policy, {\n afterPhase,\n });\n }\n }\n }\n\n /**\n * Send the provided httpRequest.\n */\n async sendRequest(request: PipelineRequest): Promise<PipelineResponse> {\n return this.pipeline.sendRequest(this._httpClient, request);\n }\n\n /**\n * Send an HTTP request that is populated using the provided OperationSpec.\n * @typeParam T - The typed result of the request, based on the OperationSpec.\n * @param operationArguments - The arguments that the HTTP request's templated values will be populated from.\n * @param operationSpec - The OperationSpec to use to populate the httpRequest.\n */\n async sendOperationRequest<T>(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<T> {\n const endpoint: string | undefined = operationSpec.baseUrl || this._endpoint;\n if (!endpoint) {\n throw new Error(\n \"If operationSpec.baseUrl is not specified, then the ServiceClient must have a endpoint string property that contains the base URL to use.\",\n );\n }\n\n // Templatized URLs sometimes reference properties on the ServiceClient child class,\n // so we have to pass `this` below in order to search these properties if they're\n // not part of OperationArguments\n const url = getRequestUrl(endpoint, operationSpec, operationArguments, this);\n\n const request: OperationRequest = createPipelineRequest({\n url,\n });\n request.method = operationSpec.httpMethod;\n const operationInfo = getOperationRequestInfo(request);\n operationInfo.operationSpec = operationSpec;\n operationInfo.operationArguments = operationArguments;\n\n const contentType = operationSpec.contentType || this._requestContentType;\n if (contentType && operationSpec.requestBody) {\n request.headers.set(\"Content-Type\", contentType);\n }\n\n const options = operationArguments.options;\n if (options) {\n const requestOptions = options.requestOptions;\n\n if (requestOptions) {\n if (requestOptions.timeout) {\n request.timeout = requestOptions.timeout;\n }\n\n if (requestOptions.onUploadProgress) {\n request.onUploadProgress = requestOptions.onUploadProgress;\n }\n\n if (requestOptions.onDownloadProgress) {\n request.onDownloadProgress = requestOptions.onDownloadProgress;\n }\n\n if (requestOptions.shouldDeserialize !== undefined) {\n operationInfo.shouldDeserialize = requestOptions.shouldDeserialize;\n }\n\n if (requestOptions.allowInsecureConnection) {\n request.allowInsecureConnection = true;\n }\n }\n\n if (options.abortSignal) {\n request.abortSignal = options.abortSignal;\n }\n\n if (options.tracingOptions) {\n request.tracingOptions = options.tracingOptions;\n }\n }\n\n if (this._allowInsecureConnection) {\n request.allowInsecureConnection = true;\n }\n\n if (request.streamResponseStatusCodes === undefined) {\n request.streamResponseStatusCodes = getStreamingResponseStatusCodes(operationSpec);\n }\n\n try {\n const rawResponse = await this.sendRequest(request);\n const flatResponse = flattenResponse(\n rawResponse,\n operationSpec.responses[rawResponse.status],\n ) as T;\n if (options?.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n return flatResponse;\n } catch (error: any) {\n if (typeof error === \"object\" && error?.response) {\n const rawResponse = error.response;\n const flatResponse = flattenResponse(\n rawResponse,\n operationSpec.responses[error.statusCode] || operationSpec.responses[\"default\"],\n );\n error.details = flatResponse;\n if (options?.onResponse) {\n options.onResponse(rawResponse, flatResponse, error);\n }\n }\n throw error;\n }\n }\n}\n\nfunction createDefaultPipeline(options: ServiceClientOptions): Pipeline {\n const credentialScopes = getCredentialScopes(options);\n const credentialOptions =\n options.credential && credentialScopes\n ? { credentialScopes, credential: options.credential }\n : undefined;\n\n return createClientPipeline({\n ...options,\n credentialOptions,\n });\n}\n\nfunction getCredentialScopes(options: ServiceClientOptions): string | string[] | undefined {\n if (options.credentialScopes) {\n return options.credentialScopes;\n }\n\n if (options.endpoint) {\n return `${options.endpoint}/.default`;\n }\n\n if (options.baseUri) {\n return `${options.baseUri}/.default`;\n }\n\n if (options.credential && !options.credentialScopes) {\n throw new Error(\n `When using credentials, the ServiceClientOptions must contain either a endpoint or a credentialScopes. Unable to create a bearerTokenAuthenticationPolicy`,\n );\n }\n\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"serviceClient.js","sourceRoot":"","sources":["../../src/serviceClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OAAO,EAKL,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAqClC;;GAEG;AACH,MAAM,OAAO,aAAa;IA4BxB;;;OAGG;IACH,YAAY,UAAgC,EAAE;;QAC5C,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACtD,IAAI,CAAC,SAAS,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,OAAO,CAAC,OAAO,CAAC;QAC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OAAO,GAAG,YAAY,CAAC;gBAC7B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,EAAE,CAAC;oBACxB,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;gBACvD,CAAC;YACH,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAED,SAAS,qBAAqB,CAAC,OAA6B;IAC1D,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,iBAAiB,GACrB,OAAO,CAAC,UAAU,IAAI,gBAAgB;QACpC,CAAC,CAAC,EAAE,gBAAgB,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE;QACtD,CAAC,CAAC,SAAS,CAAC;IAEhB,OAAO,oBAAoB,iCACtB,OAAO,KACV,iBAAiB,IACjB,CAAC;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,OAA6B;IACxD,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC,gBAAgB,CAAC;IAClC,CAAC;IAED,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,OAAO,GAAG,OAAO,CAAC,QAAQ,WAAW,CAAC;IACxC,CAAC;IAED,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,GAAG,OAAO,CAAC,OAAO,WAAW,CAAC;IACvC,CAAC;IAED,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,2JAA2J,CAC5J,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n CommonClientOptions,\n OperationArguments,\n OperationRequest,\n OperationSpec,\n} from \"./interfaces.js\";\nimport {\n HttpClient,\n Pipeline,\n PipelineRequest,\n PipelineResponse,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { createClientPipeline } from \"./pipeline.js\";\nimport { flattenResponse } from \"./utils.js\";\nimport { getCachedDefaultHttpClient } from \"./httpClientCache.js\";\nimport { getOperationRequestInfo } from \"./operationHelpers.js\";\nimport { getRequestUrl } from \"./urlHelpers.js\";\nimport { getStreamingResponseStatusCodes } from \"./interfaceHelpers.js\";\nimport { logger } from \"./log.js\";\n\n/**\n * Options to be provided while creating the client.\n */\nexport interface ServiceClientOptions extends CommonClientOptions {\n /**\n * If specified, this is the base URI that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n * @deprecated This property is deprecated and will be removed soon, please use endpoint instead\n */\n baseUri?: string;\n /**\n * If specified, this is the endpoint that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n * to encourage customer to use endpoint, we mark the baseUri as deprecated.\n */\n endpoint?: string;\n /**\n * If specified, will be used to build the BearerTokenAuthenticationPolicy.\n */\n credentialScopes?: string | string[];\n /**\n * The default request content type for the service.\n * Used if no requestContentType is present on an OperationSpec.\n */\n requestContentType?: string;\n /**\n * Credential used to authenticate the request.\n */\n credential?: TokenCredential;\n /**\n * A customized pipeline to use, otherwise a default one will be created.\n */\n pipeline?: Pipeline;\n}\n\n/**\n * Initializes a new instance of the ServiceClient.\n */\nexport class ServiceClient {\n /**\n * If specified, this is the base URI that requests will be made against for this ServiceClient.\n * If it is not specified, then all OperationSpecs must contain a baseUrl property.\n */\n private readonly _endpoint?: string;\n\n /**\n * The default request content type for the service.\n * Used if no requestContentType is present on an OperationSpec.\n */\n private readonly _requestContentType?: string;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n private readonly _allowInsecureConnection?: boolean;\n\n /**\n * The HTTP client that will be used to send requests.\n */\n private readonly _httpClient: HttpClient;\n\n /**\n * The pipeline used by this client to make requests\n */\n public readonly pipeline: Pipeline;\n\n /**\n * The ServiceClient constructor\n * @param options - The service client options that govern the behavior of the client.\n */\n constructor(options: ServiceClientOptions = {}) {\n this._requestContentType = options.requestContentType;\n this._endpoint = options.endpoint ?? options.baseUri;\n if (options.baseUri) {\n logger.warning(\n \"The baseUri option for SDK Clients has been deprecated, please use endpoint instead.\",\n );\n }\n this._allowInsecureConnection = options.allowInsecureConnection;\n this._httpClient = options.httpClient || getCachedDefaultHttpClient();\n\n this.pipeline = options.pipeline || createDefaultPipeline(options);\n if (options.additionalPolicies?.length) {\n for (const { policy, position } of options.additionalPolicies) {\n // Sign happens after Retry and is commonly needed to occur\n // before policies that intercept post-retry.\n const afterPhase = position === \"perRetry\" ? \"Sign\" : undefined;\n this.pipeline.addPolicy(policy, {\n afterPhase,\n });\n }\n }\n }\n\n /**\n * Send the provided httpRequest.\n */\n async sendRequest(request: PipelineRequest): Promise<PipelineResponse> {\n return this.pipeline.sendRequest(this._httpClient, request);\n }\n\n /**\n * Send an HTTP request that is populated using the provided OperationSpec.\n * @typeParam T - The typed result of the request, based on the OperationSpec.\n * @param operationArguments - The arguments that the HTTP request's templated values will be populated from.\n * @param operationSpec - The OperationSpec to use to populate the httpRequest.\n */\n async sendOperationRequest<T>(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<T> {\n const endpoint: string | undefined = operationSpec.baseUrl || this._endpoint;\n if (!endpoint) {\n throw new Error(\n \"If operationSpec.baseUrl is not specified, then the ServiceClient must have a endpoint string property that contains the base URL to use.\",\n );\n }\n\n // Templatized URLs sometimes reference properties on the ServiceClient child class,\n // so we have to pass `this` below in order to search these properties if they're\n // not part of OperationArguments\n const url = getRequestUrl(endpoint, operationSpec, operationArguments, this);\n\n const request: OperationRequest = createPipelineRequest({\n url,\n });\n request.method = operationSpec.httpMethod;\n const operationInfo = getOperationRequestInfo(request);\n operationInfo.operationSpec = operationSpec;\n operationInfo.operationArguments = operationArguments;\n\n const contentType = operationSpec.contentType || this._requestContentType;\n if (contentType && operationSpec.requestBody) {\n request.headers.set(\"Content-Type\", contentType);\n }\n\n const options = operationArguments.options;\n if (options) {\n const requestOptions = options.requestOptions;\n\n if (requestOptions) {\n if (requestOptions.timeout) {\n request.timeout = requestOptions.timeout;\n }\n\n if (requestOptions.onUploadProgress) {\n request.onUploadProgress = requestOptions.onUploadProgress;\n }\n\n if (requestOptions.onDownloadProgress) {\n request.onDownloadProgress = requestOptions.onDownloadProgress;\n }\n\n if (requestOptions.shouldDeserialize !== undefined) {\n operationInfo.shouldDeserialize = requestOptions.shouldDeserialize;\n }\n\n if (requestOptions.allowInsecureConnection) {\n request.allowInsecureConnection = true;\n }\n }\n\n if (options.abortSignal) {\n request.abortSignal = options.abortSignal;\n }\n\n if (options.tracingOptions) {\n request.tracingOptions = options.tracingOptions;\n }\n }\n\n if (this._allowInsecureConnection) {\n request.allowInsecureConnection = true;\n }\n\n if (request.streamResponseStatusCodes === undefined) {\n request.streamResponseStatusCodes = getStreamingResponseStatusCodes(operationSpec);\n }\n\n try {\n const rawResponse = await this.sendRequest(request);\n const flatResponse = flattenResponse(\n rawResponse,\n operationSpec.responses[rawResponse.status],\n ) as T;\n if (options?.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n return flatResponse;\n } catch (error: any) {\n if (typeof error === \"object\" && error?.response) {\n const rawResponse = error.response;\n const flatResponse = flattenResponse(\n rawResponse,\n operationSpec.responses[error.statusCode] || operationSpec.responses[\"default\"],\n );\n error.details = flatResponse;\n if (options?.onResponse) {\n options.onResponse(rawResponse, flatResponse, error);\n }\n }\n throw error;\n }\n }\n}\n\nfunction createDefaultPipeline(options: ServiceClientOptions): Pipeline {\n const credentialScopes = getCredentialScopes(options);\n const credentialOptions =\n options.credential && credentialScopes\n ? { credentialScopes, credential: options.credential }\n : undefined;\n\n return createClientPipeline({\n ...options,\n credentialOptions,\n });\n}\n\nfunction getCredentialScopes(options: ServiceClientOptions): string | string[] | undefined {\n if (options.credentialScopes) {\n return options.credentialScopes;\n }\n\n if (options.endpoint) {\n return `${options.endpoint}/.default`;\n }\n\n if (options.baseUri) {\n return `${options.baseUri}/.default`;\n }\n\n if (options.credential && !options.credentialScopes) {\n throw new Error(\n `When using credentials, the ServiceClientOptions must contain either a endpoint or a credentialScopes. Unable to create a bearerTokenAuthenticationPolicy`,\n );\n }\n\n return undefined;\n}\n"]}
@@ -2,7 +2,8 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT license.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.authorizeRequestOnClaimChallenge = exports.parseCAEChallenge = void 0;
5
+ exports.parseCAEChallenge = parseCAEChallenge;
6
+ exports.authorizeRequestOnClaimChallenge = authorizeRequestOnClaimChallenge;
6
7
  const log_js_1 = require("./log.js");
7
8
  const base64_js_1 = require("./base64.js");
8
9
  /**
@@ -20,7 +21,6 @@ function parseCAEChallenge(challenges) {
20
21
  return keyValuePairs.reduce((a, b) => (Object.assign(Object.assign({}, a), b)), {});
21
22
  });
22
23
  }
23
- exports.parseCAEChallenge = parseCAEChallenge;
24
24
  /**
25
25
  * This function can be used as a callback for the `bearerTokenAuthenticationPolicy` of `@azure/core-rest-pipeline`, to support CAE challenges:
26
26
  * [Continuous Access Evaluation](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation).
@@ -70,5 +70,4 @@ async function authorizeRequestOnClaimChallenge(onChallengeOptions) {
70
70
  onChallengeOptions.request.headers.set("Authorization", `Bearer ${accessToken.token}`);
71
71
  return true;
72
72
  }
73
- exports.authorizeRequestOnClaimChallenge = authorizeRequestOnClaimChallenge;
74
73
  //# sourceMappingURL=authorizeRequestOnClaimChallenge.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"authorizeRequestOnClaimChallenge.js","sourceRoot":"","sources":["../../src/authorizeRequestOnClaimChallenge.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,qCAAsD;AACtD,2CAAmD;AAEnD;;;;;GA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,CAAC,IAAI,CACT,kHAAkH,CACnH,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,UAAU,GAAmB,iBAAiB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAEtE,MAAM,eAAe,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACzD,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CACT,iIAAiI,CAClI,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,kBAAkB,CAAC,cAAc,CACzD,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EACxD;QACE,MAAM,EAAE,IAAA,gCAAoB,EAAC,eAAe,CAAC,MAAM,CAAC;KACrD,CACF,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;IACvF,OAAO,IAAI,CAAC;AACd,CAAC;AApCD,4EAoCC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AuthorizeRequestOnChallengeOptions } from \"@azure/core-rest-pipeline\";\nimport { logger as coreClientLogger } from \"./log.js\";\nimport { decodeStringToString } from \"./base64.js\";\n\n/**\n * Converts: `Bearer a=\"b\", c=\"d\", Bearer d=\"e\", f=\"g\"`.\n * Into: `[ { a: 'b', c: 'd' }, { d: 'e', f: 'g' } ]`.\n *\n * @internal\n */\nexport function parseCAEChallenge(challenges: string): any[] {\n const bearerChallenges = `, ${challenges.trim()}`.split(\", Bearer \").filter((x) => x);\n return bearerChallenges.map((challenge) => {\n const challengeParts = `${challenge.trim()}, `.split('\", ').filter((x) => x);\n const keyValuePairs = challengeParts.map((keyValue) =>\n (([key, value]) => ({ [key]: value }))(keyValue.trim().split('=\"')),\n );\n // Key-value pairs to plain object:\n return keyValuePairs.reduce((a, b) => ({ ...a, ...b }), {});\n });\n}\n\n/**\n * CAE Challenge structure\n */\nexport interface CAEChallenge {\n scope: string;\n claims: string;\n}\n\n/**\n * This function can be used as a callback for the `bearerTokenAuthenticationPolicy` of `@azure/core-rest-pipeline`, to support CAE challenges:\n * [Continuous Access Evaluation](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation).\n *\n * Call the `bearerTokenAuthenticationPolicy` with the following options:\n *\n * ```ts\n * import { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\n * import { authorizeRequestOnClaimChallenge } from \"@azure/core-client\";\n *\n * const bearerTokenAuthenticationPolicy = bearerTokenAuthenticationPolicy({\n * authorizeRequestOnChallenge: authorizeRequestOnClaimChallenge\n * });\n * ```\n *\n * Once provided, the `bearerTokenAuthenticationPolicy` policy will internally handle Continuous Access Evaluation (CAE) challenges.\n * When it can't complete a challenge it will return the 401 (unauthorized) response from ARM.\n *\n * Example challenge with claims:\n *\n * ```\n * Bearer authorization_uri=\"https://login.windows-ppe.net/\", error=\"invalid_token\",\n * error_description=\"User session has been revoked\",\n * claims=\"eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTYwMzc0MjgwMCJ9fX0=\"\n * ```\n */\nexport async function authorizeRequestOnClaimChallenge(\n onChallengeOptions: AuthorizeRequestOnChallengeOptions,\n): Promise<boolean> {\n const { scopes, response } = onChallengeOptions;\n const logger = onChallengeOptions.logger || coreClientLogger;\n\n const challenge = response.headers.get(\"WWW-Authenticate\");\n if (!challenge) {\n logger.info(\n `The WWW-Authenticate header was missing. Failed to perform the Continuous Access Evaluation authentication flow.`,\n );\n return false;\n }\n const challenges: CAEChallenge[] = parseCAEChallenge(challenge) || [];\n\n const parsedChallenge = challenges.find((x) => x.claims);\n if (!parsedChallenge) {\n logger.info(\n `The WWW-Authenticate header was missing the necessary \"claims\" to perform the Continuous Access Evaluation authentication flow.`,\n );\n return false;\n }\n\n const accessToken = await onChallengeOptions.getAccessToken(\n parsedChallenge.scope ? [parsedChallenge.scope] : scopes,\n {\n claims: decodeStringToString(parsedChallenge.claims),\n },\n );\n\n if (!accessToken) {\n return false;\n }\n\n onChallengeOptions.request.headers.set(\"Authorization\", `Bearer ${accessToken.token}`);\n return true;\n}\n"]}
1
+ {"version":3,"file":"authorizeRequestOnClaimChallenge.js","sourceRoot":"","sources":["../../src/authorizeRequestOnClaimChallenge.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAYlC,8CAUC;AAoCD,4EAoCC;AA3FD,qCAAsD;AACtD,2CAAmD;AAEnD;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,UAAkB;IAClD,MAAM,gBAAgB,GAAG,KAAK,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACtF,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QACxC,MAAM,cAAc,GAAG,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7E,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CACpD,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI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CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;IACvF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AuthorizeRequestOnChallengeOptions } from \"@azure/core-rest-pipeline\";\nimport { logger as coreClientLogger } from \"./log.js\";\nimport { decodeStringToString } from \"./base64.js\";\n\n/**\n * Converts: `Bearer a=\"b\", c=\"d\", Bearer d=\"e\", f=\"g\"`.\n * Into: `[ { a: 'b', c: 'd' }, { d: 'e', f: 'g' } ]`.\n *\n * @internal\n */\nexport function parseCAEChallenge(challenges: string): any[] {\n const bearerChallenges = `, ${challenges.trim()}`.split(\", Bearer \").filter((x) => x);\n return bearerChallenges.map((challenge) => {\n const challengeParts = `${challenge.trim()}, `.split('\", ').filter((x) => x);\n const keyValuePairs = challengeParts.map((keyValue) =>\n (([key, value]) => ({ [key]: value }))(keyValue.trim().split('=\"')),\n );\n // Key-value pairs to plain object:\n return keyValuePairs.reduce((a, b) => ({ ...a, ...b }), {});\n });\n}\n\n/**\n * CAE Challenge structure\n */\nexport interface CAEChallenge {\n scope: string;\n claims: string;\n}\n\n/**\n * This function can be used as a callback for the `bearerTokenAuthenticationPolicy` of `@azure/core-rest-pipeline`, to support CAE challenges:\n * [Continuous Access Evaluation](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation).\n *\n * Call the `bearerTokenAuthenticationPolicy` with the following options:\n *\n * ```ts\n * import { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\n * import { authorizeRequestOnClaimChallenge } from \"@azure/core-client\";\n *\n * const bearerTokenAuthenticationPolicy = bearerTokenAuthenticationPolicy({\n * authorizeRequestOnChallenge: authorizeRequestOnClaimChallenge\n * });\n * ```\n *\n * Once provided, the `bearerTokenAuthenticationPolicy` policy will internally handle Continuous Access Evaluation (CAE) challenges.\n * When it can't complete a challenge it will return the 401 (unauthorized) response from ARM.\n *\n * Example challenge with claims:\n *\n * ```\n * Bearer authorization_uri=\"https://login.windows-ppe.net/\", error=\"invalid_token\",\n * error_description=\"User session has been revoked\",\n * claims=\"eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTYwMzc0MjgwMCJ9fX0=\"\n * ```\n */\nexport async function authorizeRequestOnClaimChallenge(\n onChallengeOptions: AuthorizeRequestOnChallengeOptions,\n): Promise<boolean> {\n const { scopes, response } = onChallengeOptions;\n const logger = onChallengeOptions.logger || coreClientLogger;\n\n const challenge = response.headers.get(\"WWW-Authenticate\");\n if (!challenge) {\n logger.info(\n `The WWW-Authenticate header was missing. Failed to perform the Continuous Access Evaluation authentication flow.`,\n );\n return false;\n }\n const challenges: CAEChallenge[] = parseCAEChallenge(challenge) || [];\n\n const parsedChallenge = challenges.find((x) => x.claims);\n if (!parsedChallenge) {\n logger.info(\n `The WWW-Authenticate header was missing the necessary \"claims\" to perform the Continuous Access Evaluation authentication flow.`,\n );\n return false;\n }\n\n const accessToken = await onChallengeOptions.getAccessToken(\n parsedChallenge.scope ? [parsedChallenge.scope] : scopes,\n {\n claims: decodeStringToString(parsedChallenge.claims),\n },\n );\n\n if (!accessToken) {\n return false;\n }\n\n onChallengeOptions.request.headers.set(\"Authorization\", `Bearer ${accessToken.token}`);\n return true;\n}\n"]}
@@ -2,7 +2,10 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT license.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.decodeStringToString = exports.decodeString = exports.encodeByteArray = exports.encodeString = void 0;
5
+ exports.encodeString = encodeString;
6
+ exports.encodeByteArray = encodeByteArray;
7
+ exports.decodeString = decodeString;
8
+ exports.decodeStringToString = decodeStringToString;
6
9
  /**
7
10
  * Encodes a string in base64 format.
8
11
  * @param value - the string to encode
@@ -11,7 +14,6 @@ exports.decodeStringToString = exports.decodeString = exports.encodeByteArray =
11
14
  function encodeString(value) {
12
15
  return Buffer.from(value).toString("base64");
13
16
  }
14
- exports.encodeString = encodeString;
15
17
  /**
16
18
  * Encodes a byte array in base64 format.
17
19
  * @param value - the Uint8Aray to encode
@@ -21,7 +23,6 @@ function encodeByteArray(value) {
21
23
  const bufferValue = value instanceof Buffer ? value : Buffer.from(value.buffer);
22
24
  return bufferValue.toString("base64");
23
25
  }
24
- exports.encodeByteArray = encodeByteArray;
25
26
  /**
26
27
  * Decodes a base64 string into a byte array.
27
28
  * @param value - the base64 string to decode
@@ -30,7 +31,6 @@ exports.encodeByteArray = encodeByteArray;
30
31
  function decodeString(value) {
31
32
  return Buffer.from(value, "base64");
32
33
  }
33
- exports.decodeString = decodeString;
34
34
  /**
35
35
  * Decodes a base64 string into a string.
36
36
  * @param value - the base64 string to decode
@@ -39,5 +39,4 @@ exports.decodeString = decodeString;
39
39
  function decodeStringToString(value) {
40
40
  return Buffer.from(value, "base64").toString();
41
41
  }
42
- exports.decodeStringToString = decodeStringToString;
43
42
  //# sourceMappingURL=base64.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC;;;;GAIG;AACH,SAAgB,YAAY,CAAC,KAAa;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAFD,oCAEC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,KAAiB;IAC/C,MAAM,WAAW,GAAG,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAqB,CAAC,CAAC;IAC/F,OAAO,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC;AAHD,0CAGC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,KAAa;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AAFD,oCAEC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,KAAa;IAChD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;AACjD,CAAC;AAFD,oDAEC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Encodes a string in base64 format.\n * @param value - the string to encode\n * @internal\n */\nexport function encodeString(value: string): string {\n return Buffer.from(value).toString(\"base64\");\n}\n\n/**\n * Encodes a byte array in base64 format.\n * @param value - the Uint8Aray to encode\n * @internal\n */\nexport function encodeByteArray(value: Uint8Array): string {\n const bufferValue = value instanceof Buffer ? value : Buffer.from(value.buffer as ArrayBuffer);\n return bufferValue.toString(\"base64\");\n}\n\n/**\n * Decodes a base64 string into a byte array.\n * @param value - the base64 string to decode\n * @internal\n */\nexport function decodeString(value: string): Uint8Array {\n return Buffer.from(value, \"base64\");\n}\n\n/**\n * Decodes a base64 string into a string.\n * @param value - the base64 string to decode\n * @internal\n */\nexport function decodeStringToString(value: string): string {\n return Buffer.from(value, \"base64\").toString();\n}\n"]}
1
+ {"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAOlC,oCAEC;AAOD,0CAGC;AAOD,oCAEC;AAOD,oDAEC;AAnCD;;;;GAIG;AACH,SAAgB,YAAY,CAAC,KAAa;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,KAAiB;IAC/C,MAAM,WAAW,GAAG,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAqB,CAAC,CAAC;IAC/F,OAAO,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,KAAa;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,KAAa;IAChD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;AACjD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Encodes a string in base64 format.\n * @param value - the string to encode\n * @internal\n */\nexport function encodeString(value: string): string {\n return Buffer.from(value).toString(\"base64\");\n}\n\n/**\n * Encodes a byte array in base64 format.\n * @param value - the Uint8Aray to encode\n * @internal\n */\nexport function encodeByteArray(value: Uint8Array): string {\n const bufferValue = value instanceof Buffer ? value : Buffer.from(value.buffer as ArrayBuffer);\n return bufferValue.toString(\"base64\");\n}\n\n/**\n * Decodes a base64 string into a byte array.\n * @param value - the base64 string to decode\n * @internal\n */\nexport function decodeString(value: string): Uint8Array {\n return Buffer.from(value, \"base64\");\n}\n\n/**\n * Decodes a base64 string into a string.\n * @param value - the base64 string to decode\n * @internal\n */\nexport function decodeStringToString(value: string): string {\n return Buffer.from(value, \"base64\").toString();\n}\n"]}
@@ -2,7 +2,8 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT license.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.deserializationPolicy = exports.deserializationPolicyName = void 0;
5
+ exports.deserializationPolicyName = void 0;
6
+ exports.deserializationPolicy = deserializationPolicy;
6
7
  const interfaces_js_1 = require("./interfaces.js");
7
8
  const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
8
9
  const serializer_js_1 = require("./serializer.js");
@@ -37,7 +38,6 @@ function deserializationPolicy(options = {}) {
37
38
  },
38
39
  };
39
40
  }
40
- exports.deserializationPolicy = deserializationPolicy;
41
41
  function getOperationResponseMap(parsedResponse) {
42
42
  let result;
43
43
  const request = parsedResponse.request;
@@ -1 +1 @@
1
- {"version":3,"file":"deserializationPolicy.js","sourceRoot":"","sources":["../../src/deserializationPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,mDASyB;AACzB,kEAMmC;AACnC,mDAAkD;AAClD,+DAAgE;AAEhE,MAAM,uBAAuB,GAAG,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAAC;AAClE,MAAM,sBAAsB,GAAG,CAAC,iBAAiB,EAAE,sBAAsB,CAAC,CAAC;AAE3E;;GAEG;AACU,QAAA,yBAAyB,GAAG,uBAAuB,CAAC;AAyCjE;;GAEG;AACH,SAAgB,qBAAqB,CAAC,UAAwC,EAAE;;IAC9E,MAAM,gBAAgB,GAAG,MAAA,MAAA,OAAO,CAAC,oBAAoB,0CAAE,IAAI,mCAAI,uBAAuB,CAAC;IACvF,MAAM,eAAe,GAAG,MAAA,MAAA,OAAO,CAAC,oBAAoB,0CAAE,GAAG,mCAAI,sBAAsB,CAAC;IACpF,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IACpD,MAAM,cAAc,GAA8B;QAChD,GAAG,EAAE;YACH,QAAQ,EAAE,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,GAAG,CAAC,QAAQ,mCAAI,EAAE;YAC/C,WAAW,EAAE,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,GAAG,CAAC,WAAW,mCAAI,KAAK;YACxD,UAAU,EAAE,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,GAAG,CAAC,U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QACV,CAAC;IACH,CAAC;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n FullOperationResponse,\n OperationRequest,\n OperationResponseMap,\n OperationSpec,\n RequiredSerializerOptions,\n SerializerOptions,\n XML_CHARKEY,\n XmlOptions,\n} from \"./interfaces.js\";\nimport {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n RestError,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { MapperTypeNames } from \"./serializer.js\";\nimport { getOperationRequestInfo } from \"./operationHelpers.js\";\n\nconst defaultJsonContentTypes = [\"application/json\", \"text/json\"];\nconst defaultXmlContentTypes = [\"application/xml\", \"application/atom+xml\"];\n\n/**\n * The programmatic identifier of the deserializationPolicy.\n */\nexport const deserializationPolicyName = \"deserializationPolicy\";\n\n/**\n * Options to configure API response deserialization.\n */\nexport interface DeserializationPolicyOptions {\n /**\n * Configures the expected content types for the deserialization of\n * JSON and XML response bodies.\n */\n expectedContentTypes?: DeserializationContentTypes;\n\n /**\n * A function that is able to parse XML. Required for XML support.\n */\n parseXML?: (str: string, opts?: XmlOptions) => Promise<any>;\n\n /**\n * Configures behavior of xml parser and builder.\n */\n serializerOptions?: SerializerOptions;\n}\n\n/**\n * The content-types that will indicate that an operation response should be deserialized in a\n * particular way.\n */\nexport interface DeserializationContentTypes {\n /**\n * The content-types that indicate that an operation response should be deserialized as JSON.\n * Defaults to [ \"application/json\", \"text/json\" ].\n */\n json?: string[];\n\n /**\n * The content-types that indicate that an operation response should be deserialized as XML.\n * Defaults to [ \"application/xml\", \"application/atom+xml\" ].\n */\n xml?: string[];\n}\n\n/**\n * This policy handles parsing out responses according to OperationSpecs on the request.\n */\nexport function deserializationPolicy(options: DeserializationPolicyOptions = {}): PipelinePolicy {\n const jsonContentTypes = options.expectedContentTypes?.json ?? defaultJsonContentTypes;\n const xmlContentTypes = options.expectedContentTypes?.xml ?? defaultXmlContentTypes;\n const parseXML = options.parseXML;\n const serializerOptions = options.serializerOptions;\n const updatedOptions: RequiredSerializerOptions = {\n xml: {\n rootName: serializerOptions?.xml.rootName ?? \"\",\n includeRoot: serializerOptions?.xml.includeRoot ?? false,\n xmlCharKey: serializerOptions?.xml.xmlCharKey ?? XML_CHARKEY,\n },\n };\n\n return {\n name: deserializationPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n const response = await next(request);\n return deserializeResponseBody(\n jsonContentTypes,\n xmlContentTypes,\n response,\n updatedOptions,\n parseXML,\n );\n },\n };\n}\n\nfunction getOperationResponseMap(\n parsedResponse: PipelineResponse,\n): undefined | OperationResponseMap {\n let result: OperationResponseMap | undefined;\n const request: OperationRequest = parsedResponse.request;\n const operationInfo = getOperationRequestInfo(request);\n const operationSpec = operationInfo?.operationSpec;\n if (operationSpec) {\n if (!operationInfo?.operationResponseGetter) {\n result = operationSpec.responses[parsedResponse.status];\n } else {\n result = operationInfo?.operationResponseGetter(operationSpec, parsedResponse);\n }\n }\n return result;\n}\n\nfunction shouldDeserializeResponse(parsedResponse: PipelineResponse): boolean {\n const request: OperationRequest = parsedResponse.request;\n const operationInfo = getOperationRequestInfo(request);\n const shouldDeserialize = operationInfo?.shouldDeserialize;\n let result: boolean;\n if (shouldDeserialize === undefined) {\n result = true;\n } else if (typeof shouldDeserialize === \"boolean\") {\n result = shouldDeserialize;\n } else {\n result = shouldDeserialize(parsedResponse);\n }\n return result;\n}\n\nasync function deserializeResponseBody(\n jsonContentTypes: string[],\n xmlContentTypes: string[],\n response: PipelineResponse,\n options: RequiredSerializerOptions,\n parseXML?: (str: string, opts?: XmlOptions) => Promise<any>,\n): Promise<PipelineResponse> {\n const parsedResponse = await parse(\n jsonContentTypes,\n xmlContentTypes,\n response,\n options,\n parseXML,\n );\n if (!shouldDeserializeResponse(parsedResponse)) {\n return parsedResponse;\n }\n\n const operationInfo = getOperationRequestInfo(parsedResponse.request);\n const operationSpec = operationInfo?.operationSpec;\n if (!operationSpec || !operationSpec.responses) {\n return parsedResponse;\n }\n\n const responseSpec = getOperationResponseMap(parsedResponse);\n const { error, shouldReturnResponse } = handleErrorResponse(\n parsedResponse,\n operationSpec,\n responseSpec,\n options,\n );\n if (error) {\n throw error;\n } else if (shouldReturnResponse) {\n return parsedResponse;\n }\n\n // An operation response spec does exist for current status code, so\n // use it to deserialize the response.\n if (responseSpec) {\n if (responseSpec.bodyMapper) {\n let valueToDeserialize: any = parsedResponse.parsedBody;\n if (operationSpec.isXML && responseSpec.bodyMapper.type.name === MapperTypeNames.Sequence) {\n valueToDeserialize =\n typeof valueToDeserialize === \"object\"\n ? valueToDeserialize[responseSpec.bodyMapper.xmlElementName!]\n : [];\n }\n try {\n parsedResponse.parsedBody = operationSpec.serializer.deserialize(\n responseSpec.bodyMapper,\n valueToDeserialize,\n \"operationRes.parsedBody\",\n options,\n );\n } catch (deserializeError: any) {\n const restError = new RestError(\n `Error ${deserializeError} occurred in deserializing the responseBody - ${parsedResponse.bodyAsText}`,\n {\n statusCode: parsedResponse.status,\n request: parsedResponse.request,\n response: parsedResponse,\n },\n );\n throw restError;\n }\n } else if (operationSpec.httpMethod === \"HEAD\") {\n // head methods never have a body, but we return a boolean to indicate presence/absence of the resource\n parsedResponse.parsedBody = response.status >= 200 && response.status < 300;\n }\n\n if (responseSpec.headersMapper) {\n parsedResponse.parsedHeaders = operationSpec.serializer.deserialize(\n responseSpec.headersMapper,\n parsedResponse.headers.toJSON(),\n \"operationRes.parsedHeaders\",\n { xml: {}, ignoreUnknownProperties: true },\n );\n }\n }\n\n return parsedResponse;\n}\n\nfunction isOperationSpecEmpty(operationSpec: OperationSpec): boolean {\n const expectedStatusCodes = Object.keys(operationSpec.responses);\n return (\n expectedStatusCodes.length === 0 ||\n (expectedStatusCodes.length === 1 && expectedStatusCodes[0] === \"default\")\n );\n}\n\nfunction handleErrorResponse(\n parsedResponse: FullOperationResponse,\n operationSpec: OperationSpec,\n responseSpec: OperationResponseMap | undefined,\n options: RequiredSerializerOptions,\n): { error: RestError | null; shouldReturnResponse: boolean } {\n const isSuccessByStatus = 200 <= parsedResponse.status && parsedResponse.status < 300;\n const isExpectedStatusCode: boolean = isOperationSpecEmpty(operationSpec)\n ? isSuccessByStatus\n : !!responseSpec;\n\n if (isExpectedStatusCode) {\n if (responseSpec) {\n if (!responseSpec.isError) {\n return { error: null, shouldReturnResponse: false };\n }\n } else {\n return { error: null, shouldReturnResponse: false };\n }\n }\n\n const errorResponseSpec = responseSpec ?? operationSpec.responses.default;\n\n const initialErrorMessage = parsedResponse.request.streamResponseStatusCodes?.has(\n parsedResponse.status,\n )\n ? `Unexpected status code: ${parsedResponse.status}`\n : (parsedResponse.bodyAsText as string);\n\n const error = new RestError(initialErrorMessage, {\n statusCode: parsedResponse.status,\n request: parsedResponse.request,\n response: parsedResponse,\n });\n\n // If the item failed but there's no error spec or default spec to deserialize the error,\n // we should fail so we just throw the parsed response\n if (!errorResponseSpec) {\n throw error;\n }\n\n const defaultBodyMapper = errorResponseSpec.bodyMapper;\n const defaultHeadersMapper = errorResponseSpec.headersMapper;\n\n try {\n // If error response has a body, try to deserialize it using default body mapper.\n // Then try to extract error code & message from it\n if (parsedResponse.parsedBody) {\n const parsedBody = parsedResponse.parsedBody;\n let deserializedError;\n\n if (defaultBodyMapper) {\n let valueToDeserialize: any = parsedBody;\n if (operationSpec.isXML && defaultBodyMapper.type.name === MapperTypeNames.Sequence) {\n valueToDeserialize = [];\n const elementName = defaultBodyMapper.xmlElementName;\n if (typeof parsedBody === \"object\" && elementName) {\n valueToDeserialize = parsedBody[elementName];\n }\n }\n deserializedError = operationSpec.serializer.deserialize(\n defaultBodyMapper,\n valueToDeserialize,\n \"error.response.parsedBody\",\n options,\n );\n }\n\n const internalError: any = parsedBody.error || deserializedError || parsedBody;\n error.code = internalError.code;\n if (internalError.message) {\n error.message = internalError.message;\n }\n\n if (defaultBodyMapper) {\n (error.response! as FullOperationResponse).parsedBody = deserializedError;\n }\n }\n\n // If error response has headers, try to deserialize it using default header mapper\n if (parsedResponse.headers && defaultHeadersMapper) {\n (error.response! as FullOperationResponse).parsedHeaders =\n operationSpec.serializer.deserialize(\n defaultHeadersMapper,\n parsedResponse.headers.toJSON(),\n \"operationRes.parsedHeaders\",\n );\n }\n } catch (defaultError: any) {\n error.message = `Error \"${defaultError.message}\" occurred in deserializing the responseBody - \"${parsedResponse.bodyAsText}\" for the default response.`;\n }\n\n return { error, shouldReturnResponse: false };\n}\n\nasync function parse(\n jsonContentTypes: string[],\n xmlContentTypes: string[],\n operationResponse: FullOperationResponse,\n opts: RequiredSerializerOptions,\n parseXML?: (str: string, opts?: XmlOptions) => Promise<any>,\n): Promise<FullOperationResponse> {\n if (\n !operationResponse.request.streamResponseStatusCodes?.has(operationResponse.status) &&\n operationResponse.bodyAsText\n ) {\n const text = operationResponse.bodyAsText;\n const contentType: string = operationResponse.headers.get(\"Content-Type\") || \"\";\n const contentComponents: string[] = !contentType\n ? []\n : contentType.split(\";\").map((component) => component.toLowerCase());\n\n try {\n if (\n contentComponents.length === 0 ||\n contentComponents.some((component) => jsonContentTypes.indexOf(component) !== -1)\n ) {\n operationResponse.parsedBody = JSON.parse(text);\n return operationResponse;\n } else if (contentComponents.some((component) => xmlContentTypes.indexOf(component) !== -1)) {\n if (!parseXML) {\n throw new Error(\"Parsing XML not supported.\");\n }\n const body = await parseXML(text, opts.xml);\n operationResponse.parsedBody = body;\n return operationResponse;\n }\n } catch (err: any) {\n const msg = `Error \"${err}\" occurred while parsing the response body - ${operationResponse.bodyAsText}.`;\n const errCode = err.code || RestError.PARSE_ERROR;\n const e = new RestError(msg, {\n code: errCode,\n statusCode: operationResponse.status,\n request: operationResponse.request,\n response: operationResponse,\n });\n throw e;\n }\n }\n\n return operationResponse;\n}\n"]}
1
+ {"version":3,"file":"deserializationPolicy.js","sourceRoot":"","sources":["../../src/deserializationPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAwElC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,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAChD,OAAO,iBAAiB,CAAC;YAC3B,CAAC;iBAAM,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5F,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACd,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;gBAChD,CAAC;gBACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;gBAC5C,iBAAiB,CAAC,UAAU,GAAG,IAAI,CAAC;gBACpC,OAAO,iBAAiB,CAAC;YAC3B,CAAC;QACH,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,UAAU,GAAG,gDAAgD,iBAAiB,CAAC,UAAU,GAAG,CAAC;YACzG,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,8BAAS,CAAC,WAAW,CAAC;YAClD,MAAM,CAAC,GAAG,IAAI,8BAAS,CAAC,GAAG,EAAE;gBAC3B,IAAI,EAAE,OAAO;gBACb,UAAU,EAAE,iBAAiB,CAAC,MAAM;gBACpC,OAAO,EAAE,iBAAiB,CAAC,OAAO;gBAClC,QAAQ,EAAE,iBAAiB;aAC5B,CAAC,CAAC;YACH,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n FullOperationResponse,\n OperationRequest,\n OperationResponseMap,\n OperationSpec,\n RequiredSerializerOptions,\n SerializerOptions,\n XML_CHARKEY,\n XmlOptions,\n} from \"./interfaces.js\";\nimport {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n RestError,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { MapperTypeNames } from \"./serializer.js\";\nimport { getOperationRequestInfo } from \"./operationHelpers.js\";\n\nconst defaultJsonContentTypes = [\"application/json\", \"text/json\"];\nconst defaultXmlContentTypes = [\"application/xml\", \"application/atom+xml\"];\n\n/**\n * The programmatic identifier of the deserializationPolicy.\n */\nexport const deserializationPolicyName = \"deserializationPolicy\";\n\n/**\n * Options to configure API response deserialization.\n */\nexport interface DeserializationPolicyOptions {\n /**\n * Configures the expected content types for the deserialization of\n * JSON and XML response bodies.\n */\n expectedContentTypes?: DeserializationContentTypes;\n\n /**\n * A function that is able to parse XML. Required for XML support.\n */\n parseXML?: (str: string, opts?: XmlOptions) => Promise<any>;\n\n /**\n * Configures behavior of xml parser and builder.\n */\n serializerOptions?: SerializerOptions;\n}\n\n/**\n * The content-types that will indicate that an operation response should be deserialized in a\n * particular way.\n */\nexport interface DeserializationContentTypes {\n /**\n * The content-types that indicate that an operation response should be deserialized as JSON.\n * Defaults to [ \"application/json\", \"text/json\" ].\n */\n json?: string[];\n\n /**\n * The content-types that indicate that an operation response should be deserialized as XML.\n * Defaults to [ \"application/xml\", \"application/atom+xml\" ].\n */\n xml?: string[];\n}\n\n/**\n * This policy handles parsing out responses according to OperationSpecs on the request.\n */\nexport function deserializationPolicy(options: DeserializationPolicyOptions = {}): PipelinePolicy {\n const jsonContentTypes = options.expectedContentTypes?.json ?? defaultJsonContentTypes;\n const xmlContentTypes = options.expectedContentTypes?.xml ?? defaultXmlContentTypes;\n const parseXML = options.parseXML;\n const serializerOptions = options.serializerOptions;\n const updatedOptions: RequiredSerializerOptions = {\n xml: {\n rootName: serializerOptions?.xml.rootName ?? \"\",\n includeRoot: serializerOptions?.xml.includeRoot ?? false,\n xmlCharKey: serializerOptions?.xml.xmlCharKey ?? XML_CHARKEY,\n },\n };\n\n return {\n name: deserializationPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n const response = await next(request);\n return deserializeResponseBody(\n jsonContentTypes,\n xmlContentTypes,\n response,\n updatedOptions,\n parseXML,\n );\n },\n };\n}\n\nfunction getOperationResponseMap(\n parsedResponse: PipelineResponse,\n): undefined | OperationResponseMap {\n let result: OperationResponseMap | undefined;\n const request: OperationRequest = parsedResponse.request;\n const operationInfo = getOperationRequestInfo(request);\n const operationSpec = operationInfo?.operationSpec;\n if (operationSpec) {\n if (!operationInfo?.operationResponseGetter) {\n result = operationSpec.responses[parsedResponse.status];\n } else {\n result = operationInfo?.operationResponseGetter(operationSpec, parsedResponse);\n }\n }\n return result;\n}\n\nfunction shouldDeserializeResponse(parsedResponse: PipelineResponse): boolean {\n const request: OperationRequest = parsedResponse.request;\n const operationInfo = getOperationRequestInfo(request);\n const shouldDeserialize = operationInfo?.shouldDeserialize;\n let result: boolean;\n if (shouldDeserialize === undefined) {\n result = true;\n } else if (typeof shouldDeserialize === \"boolean\") {\n result = shouldDeserialize;\n } else {\n result = shouldDeserialize(parsedResponse);\n }\n return result;\n}\n\nasync function deserializeResponseBody(\n jsonContentTypes: string[],\n xmlContentTypes: string[],\n response: PipelineResponse,\n options: RequiredSerializerOptions,\n parseXML?: (str: string, opts?: XmlOptions) => Promise<any>,\n): Promise<PipelineResponse> {\n const parsedResponse = await parse(\n jsonContentTypes,\n xmlContentTypes,\n response,\n options,\n parseXML,\n );\n if (!shouldDeserializeResponse(parsedResponse)) {\n return parsedResponse;\n }\n\n const operationInfo = getOperationRequestInfo(parsedResponse.request);\n const operationSpec = operationInfo?.operationSpec;\n if (!operationSpec || !operationSpec.responses) {\n return parsedResponse;\n }\n\n const responseSpec = getOperationResponseMap(parsedResponse);\n const { error, shouldReturnResponse } = handleErrorResponse(\n parsedResponse,\n operationSpec,\n responseSpec,\n options,\n );\n if (error) {\n throw error;\n } else if (shouldReturnResponse) {\n return parsedResponse;\n }\n\n // An operation response spec does exist for current status code, so\n // use it to deserialize the response.\n if (responseSpec) {\n if (responseSpec.bodyMapper) {\n let valueToDeserialize: any = parsedResponse.parsedBody;\n if (operationSpec.isXML && responseSpec.bodyMapper.type.name === MapperTypeNames.Sequence) {\n valueToDeserialize =\n typeof valueToDeserialize === \"object\"\n ? valueToDeserialize[responseSpec.bodyMapper.xmlElementName!]\n : [];\n }\n try {\n parsedResponse.parsedBody = operationSpec.serializer.deserialize(\n responseSpec.bodyMapper,\n valueToDeserialize,\n \"operationRes.parsedBody\",\n options,\n );\n } catch (deserializeError: any) {\n const restError = new RestError(\n `Error ${deserializeError} occurred in deserializing the responseBody - ${parsedResponse.bodyAsText}`,\n {\n statusCode: parsedResponse.status,\n request: parsedResponse.request,\n response: parsedResponse,\n },\n );\n throw restError;\n }\n } else if (operationSpec.httpMethod === \"HEAD\") {\n // head methods never have a body, but we return a boolean to indicate presence/absence of the resource\n parsedResponse.parsedBody = response.status >= 200 && response.status < 300;\n }\n\n if (responseSpec.headersMapper) {\n parsedResponse.parsedHeaders = operationSpec.serializer.deserialize(\n responseSpec.headersMapper,\n parsedResponse.headers.toJSON(),\n \"operationRes.parsedHeaders\",\n { xml: {}, ignoreUnknownProperties: true },\n );\n }\n }\n\n return parsedResponse;\n}\n\nfunction isOperationSpecEmpty(operationSpec: OperationSpec): boolean {\n const expectedStatusCodes = Object.keys(operationSpec.responses);\n return (\n expectedStatusCodes.length === 0 ||\n (expectedStatusCodes.length === 1 && expectedStatusCodes[0] === \"default\")\n );\n}\n\nfunction handleErrorResponse(\n parsedResponse: FullOperationResponse,\n operationSpec: OperationSpec,\n responseSpec: OperationResponseMap | undefined,\n options: RequiredSerializerOptions,\n): { error: RestError | null; shouldReturnResponse: boolean } {\n const isSuccessByStatus = 200 <= parsedResponse.status && parsedResponse.status < 300;\n const isExpectedStatusCode: boolean = isOperationSpecEmpty(operationSpec)\n ? isSuccessByStatus\n : !!responseSpec;\n\n if (isExpectedStatusCode) {\n if (responseSpec) {\n if (!responseSpec.isError) {\n return { error: null, shouldReturnResponse: false };\n }\n } else {\n return { error: null, shouldReturnResponse: false };\n }\n }\n\n const errorResponseSpec = responseSpec ?? operationSpec.responses.default;\n\n const initialErrorMessage = parsedResponse.request.streamResponseStatusCodes?.has(\n parsedResponse.status,\n )\n ? `Unexpected status code: ${parsedResponse.status}`\n : (parsedResponse.bodyAsText as string);\n\n const error = new RestError(initialErrorMessage, {\n statusCode: parsedResponse.status,\n request: parsedResponse.request,\n response: parsedResponse,\n });\n\n // If the item failed but there's no error spec or default spec to deserialize the error,\n // we should fail so we just throw the parsed response\n if (!errorResponseSpec) {\n throw error;\n }\n\n const defaultBodyMapper = errorResponseSpec.bodyMapper;\n const defaultHeadersMapper = errorResponseSpec.headersMapper;\n\n try {\n // If error response has a body, try to deserialize it using default body mapper.\n // Then try to extract error code & message from it\n if (parsedResponse.parsedBody) {\n const parsedBody = parsedResponse.parsedBody;\n let deserializedError;\n\n if (defaultBodyMapper) {\n let valueToDeserialize: any = parsedBody;\n if (operationSpec.isXML && defaultBodyMapper.type.name === MapperTypeNames.Sequence) {\n valueToDeserialize = [];\n const elementName = defaultBodyMapper.xmlElementName;\n if (typeof parsedBody === \"object\" && elementName) {\n valueToDeserialize = parsedBody[elementName];\n }\n }\n deserializedError = operationSpec.serializer.deserialize(\n defaultBodyMapper,\n valueToDeserialize,\n \"error.response.parsedBody\",\n options,\n );\n }\n\n const internalError: any = parsedBody.error || deserializedError || parsedBody;\n error.code = internalError.code;\n if (internalError.message) {\n error.message = internalError.message;\n }\n\n if (defaultBodyMapper) {\n (error.response! as FullOperationResponse).parsedBody = deserializedError;\n }\n }\n\n // If error response has headers, try to deserialize it using default header mapper\n if (parsedResponse.headers && defaultHeadersMapper) {\n (error.response! as FullOperationResponse).parsedHeaders =\n operationSpec.serializer.deserialize(\n defaultHeadersMapper,\n parsedResponse.headers.toJSON(),\n \"operationRes.parsedHeaders\",\n );\n }\n } catch (defaultError: any) {\n error.message = `Error \"${defaultError.message}\" occurred in deserializing the responseBody - \"${parsedResponse.bodyAsText}\" for the default response.`;\n }\n\n return { error, shouldReturnResponse: false };\n}\n\nasync function parse(\n jsonContentTypes: string[],\n xmlContentTypes: string[],\n operationResponse: FullOperationResponse,\n opts: RequiredSerializerOptions,\n parseXML?: (str: string, opts?: XmlOptions) => Promise<any>,\n): Promise<FullOperationResponse> {\n if (\n !operationResponse.request.streamResponseStatusCodes?.has(operationResponse.status) &&\n operationResponse.bodyAsText\n ) {\n const text = operationResponse.bodyAsText;\n const contentType: string = operationResponse.headers.get(\"Content-Type\") || \"\";\n const contentComponents: string[] = !contentType\n ? []\n : contentType.split(\";\").map((component) => component.toLowerCase());\n\n try {\n if (\n contentComponents.length === 0 ||\n contentComponents.some((component) => jsonContentTypes.indexOf(component) !== -1)\n ) {\n operationResponse.parsedBody = JSON.parse(text);\n return operationResponse;\n } else if (contentComponents.some((component) => xmlContentTypes.indexOf(component) !== -1)) {\n if (!parseXML) {\n throw new Error(\"Parsing XML not supported.\");\n }\n const body = await parseXML(text, opts.xml);\n operationResponse.parsedBody = body;\n return operationResponse;\n }\n } catch (err: any) {\n const msg = `Error \"${err}\" occurred while parsing the response body - ${operationResponse.bodyAsText}.`;\n const errCode = err.code || RestError.PARSE_ERROR;\n const e = new RestError(msg, {\n code: errCode,\n statusCode: operationResponse.status,\n request: operationResponse.request,\n response: operationResponse,\n });\n throw e;\n }\n }\n\n return operationResponse;\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT license.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.getCachedDefaultHttpClient = void 0;
5
+ exports.getCachedDefaultHttpClient = getCachedDefaultHttpClient;
6
6
  const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
7
7
  let cachedHttpClient;
8
8
  function getCachedDefaultHttpClient() {
@@ -11,5 +11,4 @@ function getCachedDefaultHttpClient() {
11
11
  }
12
12
  return cachedHttpClient;
13
13
  }
14
- exports.getCachedDefaultHttpClient = getCachedDefaultHttpClient;
15
14
  //# sourceMappingURL=httpClientCache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpClientCache.js","sourceRoot":"","sources":["../../src/httpClientCache.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,kEAAgF;AAEhF,IAAI,gBAAwC,CAAC;AAE7C,SAAgB,0BAA0B;IACxC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,gBAAgB,GAAG,IAAA,4CAAuB,GAAE,CAAC;IAC/C,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAND,gEAMC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { HttpClient, createDefaultHttpClient } from \"@azure/core-rest-pipeline\";\n\nlet cachedHttpClient: HttpClient | undefined;\n\nexport function getCachedDefaultHttpClient(): HttpClient {\n if (!cachedHttpClient) {\n cachedHttpClient = createDefaultHttpClient();\n }\n\n return cachedHttpClient;\n}\n"]}
1
+ {"version":3,"file":"httpClientCache.js","sourceRoot":"","sources":["../../src/httpClientCache.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAMlC,gEAMC;AAVD,kEAAgF;AAEhF,IAAI,gBAAwC,CAAC;AAE7C,SAAgB,0BAA0B;IACxC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,gBAAgB,GAAG,IAAA,4CAAuB,GAAE,CAAC;IAC/C,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { HttpClient, createDefaultHttpClient } from \"@azure/core-rest-pipeline\";\n\nlet cachedHttpClient: HttpClient | undefined;\n\nexport function getCachedDefaultHttpClient(): HttpClient {\n if (!cachedHttpClient) {\n cachedHttpClient = createDefaultHttpClient();\n }\n\n return cachedHttpClient;\n}\n"]}
@@ -2,7 +2,8 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT license.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.getPathStringFromParameter = exports.getStreamingResponseStatusCodes = void 0;
5
+ exports.getStreamingResponseStatusCodes = getStreamingResponseStatusCodes;
6
+ exports.getPathStringFromParameter = getPathStringFromParameter;
6
7
  const serializer_js_1 = require("./serializer.js");
7
8
  /**
8
9
  * Gets the list of status codes for streaming responses.
@@ -19,7 +20,6 @@ function getStreamingResponseStatusCodes(operationSpec) {
19
20
  }
20
21
  return result;
21
22
  }
22
- exports.getStreamingResponseStatusCodes = getStreamingResponseStatusCodes;
23
23
  /**
24
24
  * Get the path to this parameter's value as a dotted string (a.b.c).
25
25
  * @param parameter - The parameter to get the path string for.
@@ -40,5 +40,4 @@ function getPathStringFromParameter(parameter) {
40
40
  }
41
41
  return result;
42
42
  }
43
- exports.getPathStringFromParameter = getPathStringFromParameter;
44
43
  //# sourceMappingURL=interfaceHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaceHelpers.js","sourceRoot":"","sources":["../../src/interfaceHelpers.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,mDAAkD;AAElD;;;GAGG;AACH,SAAgB,+BAA+B,CAAC,aAA4B;IAC1E,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,KAAK,MAAM,UAAU,IAAI,aAAa,CAAC,SAAS,EAAE,CAAC;QACjD,MAAM,iBAAiB,GAAG,aAAa,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC9D,IACE,iBAAiB,CAAC,UAAU;YAC5B,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,+BAAe,CAAC,MAAM,EACjE,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAZD,0EAYC;AAED;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,SAA6B;IACtE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC5C,IAAI,MAAc,CAAC;IACnB,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;QACtC,MAAM,GAAG,aAAa,CAAC;IACzB,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QACxC,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,MAAM,CAAC,cAAe,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAXD,gEAWC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { OperationParameter, OperationSpec } from \"./interfaces.js\";\nimport { MapperTypeNames } from \"./serializer.js\";\n\n/**\n * Gets the list of status codes for streaming responses.\n * @internal\n */\nexport function getStreamingResponseStatusCodes(operationSpec: OperationSpec): Set<number> {\n const result = new Set<number>();\n for (const statusCode in operationSpec.responses) {\n const operationResponse = operationSpec.responses[statusCode];\n if (\n operationResponse.bodyMapper &&\n operationResponse.bodyMapper.type.name === MapperTypeNames.Stream\n ) {\n result.add(Number(statusCode));\n }\n }\n return result;\n}\n\n/**\n * Get the path to this parameter's value as a dotted string (a.b.c).\n * @param parameter - The parameter to get the path string for.\n * @returns The path to this parameter's value as a dotted string.\n * @internal\n */\nexport function getPathStringFromParameter(parameter: OperationParameter): string {\n const { parameterPath, mapper } = parameter;\n let result: string;\n if (typeof parameterPath === \"string\") {\n result = parameterPath;\n } else if (Array.isArray(parameterPath)) {\n result = parameterPath.join(\".\");\n } else {\n result = mapper.serializedName!;\n }\n return result;\n}\n"]}
1
+ {"version":3,"file":"interfaceHelpers.js","sourceRoot":"","sources":["../../src/interfaceHelpers.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AASlC,0EAYC;AAQD,gEAWC;AArCD,mDAAkD;AAElD;;;GAGG;AACH,SAAgB,+BAA+B,CAAC,aAA4B;IAC1E,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,KAAK,MAAM,UAAU,IAAI,aAAa,CAAC,SAAS,EAAE,CAAC;QACjD,MAAM,iBAAiB,GAAG,aAAa,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC9D,IACE,iBAAiB,CAAC,UAAU;YAC5B,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,+BAAe,CAAC,MAAM,EACjE,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,SAA6B;IACtE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC5C,IAAI,MAAc,CAAC;IACnB,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;QACtC,MAAM,GAAG,aAAa,CAAC;IACzB,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QACxC,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,MAAM,CAAC,cAAe,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { OperationParameter, OperationSpec } from \"./interfaces.js\";\nimport { MapperTypeNames } from \"./serializer.js\";\n\n/**\n * Gets the list of status codes for streaming responses.\n * @internal\n */\nexport function getStreamingResponseStatusCodes(operationSpec: OperationSpec): Set<number> {\n const result = new Set<number>();\n for (const statusCode in operationSpec.responses) {\n const operationResponse = operationSpec.responses[statusCode];\n if (\n operationResponse.bodyMapper &&\n operationResponse.bodyMapper.type.name === MapperTypeNames.Stream\n ) {\n result.add(Number(statusCode));\n }\n }\n return result;\n}\n\n/**\n * Get the path to this parameter's value as a dotted string (a.b.c).\n * @param parameter - The parameter to get the path string for.\n * @returns The path to this parameter's value as a dotted string.\n * @internal\n */\nexport function getPathStringFromParameter(parameter: OperationParameter): string {\n const { parameterPath, mapper } = parameter;\n let result: string;\n if (typeof parameterPath === \"string\") {\n result = parameterPath;\n } else if (Array.isArray(parameterPath)) {\n result = parameterPath.join(\".\");\n } else {\n result = mapper.serializedName!;\n }\n return result;\n}\n"]}
@@ -2,7 +2,8 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT license.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.getOperationRequestInfo = exports.getOperationArgumentValueFromParameter = void 0;
5
+ exports.getOperationArgumentValueFromParameter = getOperationArgumentValueFromParameter;
6
+ exports.getOperationRequestInfo = getOperationRequestInfo;
6
7
  const state_js_1 = require("./state.js");
7
8
  /**
8
9
  * @internal
@@ -60,7 +61,6 @@ function getOperationArgumentValueFromParameter(operationArguments, parameter, f
60
61
  }
61
62
  return value;
62
63
  }
63
- exports.getOperationArgumentValueFromParameter = getOperationArgumentValueFromParameter;
64
64
  function getPropertyFromParameterPath(parent, parameterPath) {
65
65
  const result = { propertyFound: false };
66
66
  let i = 0;
@@ -95,5 +95,4 @@ function getOperationRequestInfo(request) {
95
95
  }
96
96
  return info;
97
97
  }
98
- exports.getOperationRequestInfo = getOperationRequestInfo;
99
98
  //# sourceMappingURL=operationHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"operationHelpers.js","sourceRoot":"","sources":["../../src/operationHelpers.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAYlC,yCAAmC;AAEnC;;;;;;;GAOG;AACH,SAAgB,sCAAsC,CACpD,kBAAsC,EACtC,SAA6B,EAC7B,cAAiD;IAEjD,IAAI,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;IAC5C,MAAM,eAA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CAAC,OAAyB;IAC/D,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,OAAO,uBAAuB,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,IAAI,GAAG,gBAAK,CAAC,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAElD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,GAAG,EAAE,CAAC;QACV,gBAAK,CAAC,mBAAmB,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,0DAWC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n CompositeMapper,\n Mapper,\n OperationArguments,\n OperationParameter,\n OperationRequest,\n OperationRequestInfo,\n ParameterPath,\n} from \"./interfaces.js\";\n\nimport { state } from \"./state.js\";\n\n/**\n * @internal\n * Retrieves the value to use for a given operation argument\n * @param operationArguments - The arguments passed from the generated client\n * @param parameter - The parameter description\n * @param fallbackObject - If something isn't found in the arguments bag, look here.\n * Generally used to look at the service client properties.\n */\nexport function getOperationArgumentValueFromParameter(\n operationArguments: OperationArguments,\n parameter: OperationParameter,\n fallbackObject?: { [parameterName: string]: any },\n): any {\n let parameterPath = parameter.parameterPath;\n const parameterMapper = parameter.mapper;\n let value: any;\n if (typeof parameterPath === \"string\") {\n parameterPath = [parameterPath];\n }\n if (Array.isArray(parameterPath)) {\n if (parameterPath.length > 0) {\n if (parameterMapper.isConstant) {\n value = parameterMapper.defaultValue;\n } else {\n let propertySearchResult = getPropertyFromParameterPath(operationArguments, parameterPath);\n\n if (!propertySearchResult.propertyFound && fallbackObject) {\n propertySearchResult = getPropertyFromParameterPath(fallbackObject, parameterPath);\n }\n\n let useDefaultValue = false;\n if (!propertySearchResult.propertyFound) {\n useDefaultValue =\n parameterMapper.required ||\n (parameterPath[0] === \"options\" && parameterPath.length === 2);\n }\n value = useDefaultValue ? parameterMapper.defaultValue : propertySearchResult.propertyValue;\n }\n }\n } else {\n if (parameterMapper.required) {\n value = {};\n }\n\n for (const propertyName in parameterPath) {\n const propertyMapper: Mapper = (parameterMapper as CompositeMapper).type.modelProperties![\n propertyName\n ];\n const propertyPath: ParameterPath = parameterPath[propertyName];\n const propertyValue: any = getOperationArgumentValueFromParameter(\n operationArguments,\n {\n parameterPath: propertyPath,\n mapper: propertyMapper,\n },\n fallbackObject,\n );\n if (propertyValue !== undefined) {\n if (!value) {\n value = {};\n }\n value[propertyName] = propertyValue;\n }\n }\n }\n return value;\n}\n\ninterface PropertySearchResult {\n propertyValue?: any;\n propertyFound: boolean;\n}\n\nfunction getPropertyFromParameterPath(\n parent: { [parameterName: string]: any },\n parameterPath: string[],\n): PropertySearchResult {\n const result: PropertySearchResult = { propertyFound: false };\n let i = 0;\n for (; i < parameterPath.length; ++i) {\n const parameterPathPart: string = parameterPath[i];\n // Make sure to check inherited properties too, so don't use hasOwnProperty().\n if (parent && parameterPathPart in parent) {\n parent = parent[parameterPathPart];\n } else {\n break;\n }\n }\n if (i === parameterPath.length) {\n result.propertyValue = parent;\n result.propertyFound = true;\n }\n return result;\n}\n\nconst originalRequestSymbol = Symbol.for(\"@azure/core-client original request\");\n\nfunction hasOriginalRequest(\n request: OperationRequest,\n): request is OperationRequest & { [originalRequestSymbol]: OperationRequest } {\n return originalRequestSymbol in request;\n}\n\nexport function getOperationRequestInfo(request: OperationRequest): OperationRequestInfo {\n if (hasOriginalRequest(request)) {\n return getOperationRequestInfo(request[originalRequestSymbol]);\n }\n let info = state.operationRequestMap.get(request);\n\n if (!info) {\n info = {};\n state.operationRequestMap.set(request, info);\n }\n return info;\n}\n"]}
1
+ {"version":3,"file":"operationHelpers.js","sourceRoot":"","sources":["../../src/operationHelpers.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAsBlC,wFA0DC;AAqCD,0DAWC;AApHD,yCAAmC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CAAC,qCAAqC,CAAC,CAAC;AAEhF,SAAS,kBAAkB,CACzB,OAAyB;IAEzB,OAAO,qBAAqB,IAAI,OAAO,CAAC;AAC1C,CAAC;AAED,SAAgB,uBAAuB,CAAC,OAAyB;IAC/D,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,OAAO,uBAAuB,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,IAAI,GAAG,gBAAK,CAAC,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAElD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,GAAG,EAAE,CAAC;QACV,gBAAK,CAAC,mBAAmB,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n CompositeMapper,\n Mapper,\n OperationArguments,\n OperationParameter,\n OperationRequest,\n OperationRequestInfo,\n ParameterPath,\n} from \"./interfaces.js\";\n\nimport { state } from \"./state.js\";\n\n/**\n * @internal\n * Retrieves the value to use for a given operation argument\n * @param operationArguments - The arguments passed from the generated client\n * @param parameter - The parameter description\n * @param fallbackObject - If something isn't found in the arguments bag, look here.\n * Generally used to look at the service client properties.\n */\nexport function getOperationArgumentValueFromParameter(\n operationArguments: OperationArguments,\n parameter: OperationParameter,\n fallbackObject?: { [parameterName: string]: any },\n): any {\n let parameterPath = parameter.parameterPath;\n const parameterMapper = parameter.mapper;\n let value: any;\n if (typeof parameterPath === \"string\") {\n parameterPath = [parameterPath];\n }\n if (Array.isArray(parameterPath)) {\n if (parameterPath.length > 0) {\n if (parameterMapper.isConstant) {\n value = parameterMapper.defaultValue;\n } else {\n let propertySearchResult = getPropertyFromParameterPath(operationArguments, parameterPath);\n\n if (!propertySearchResult.propertyFound && fallbackObject) {\n propertySearchResult = getPropertyFromParameterPath(fallbackObject, parameterPath);\n }\n\n let useDefaultValue = false;\n if (!propertySearchResult.propertyFound) {\n useDefaultValue =\n parameterMapper.required ||\n (parameterPath[0] === \"options\" && parameterPath.length === 2);\n }\n value = useDefaultValue ? parameterMapper.defaultValue : propertySearchResult.propertyValue;\n }\n }\n } else {\n if (parameterMapper.required) {\n value = {};\n }\n\n for (const propertyName in parameterPath) {\n const propertyMapper: Mapper = (parameterMapper as CompositeMapper).type.modelProperties![\n propertyName\n ];\n const propertyPath: ParameterPath = parameterPath[propertyName];\n const propertyValue: any = getOperationArgumentValueFromParameter(\n operationArguments,\n {\n parameterPath: propertyPath,\n mapper: propertyMapper,\n },\n fallbackObject,\n );\n if (propertyValue !== undefined) {\n if (!value) {\n value = {};\n }\n value[propertyName] = propertyValue;\n }\n }\n }\n return value;\n}\n\ninterface PropertySearchResult {\n propertyValue?: any;\n propertyFound: boolean;\n}\n\nfunction getPropertyFromParameterPath(\n parent: { [parameterName: string]: any },\n parameterPath: string[],\n): PropertySearchResult {\n const result: PropertySearchResult = { propertyFound: false };\n let i = 0;\n for (; i < parameterPath.length; ++i) {\n const parameterPathPart: string = parameterPath[i];\n // Make sure to check inherited properties too, so don't use hasOwnProperty().\n if (parent && parameterPathPart in parent) {\n parent = parent[parameterPathPart];\n } else {\n break;\n }\n }\n if (i === parameterPath.length) {\n result.propertyValue = parent;\n result.propertyFound = true;\n }\n return result;\n}\n\nconst originalRequestSymbol = Symbol.for(\"@azure/core-client original request\");\n\nfunction hasOriginalRequest(\n request: OperationRequest,\n): request is OperationRequest & { [originalRequestSymbol]: OperationRequest } {\n return originalRequestSymbol in request;\n}\n\nexport function getOperationRequestInfo(request: OperationRequest): OperationRequestInfo {\n if (hasOriginalRequest(request)) {\n return getOperationRequestInfo(request[originalRequestSymbol]);\n }\n let info = state.operationRequestMap.get(request);\n\n if (!info) {\n info = {};\n state.operationRequestMap.set(request, info);\n }\n return info;\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT license.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.createClientPipeline = void 0;
5
+ exports.createClientPipeline = createClientPipeline;
6
6
  const deserializationPolicy_js_1 = require("./deserializationPolicy.js");
7
7
  const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
8
8
  const serializationPolicy_js_1 = require("./serializationPolicy.js");
@@ -26,5 +26,4 @@ function createClientPipeline(options = {}) {
26
26
  });
27
27
  return pipeline;
28
28
  }
29
- exports.createClientPipeline = createClientPipeline;
30
29
  //# sourceMappingURL=pipeline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/pipeline.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,yEAAiG;AACjG,kEAKmC;AACnC,qEAA2F;AAuB3F;;;;;GAKG;AACH,SAAgB,oBAAoB,CAAC,UAAyC,EAAE;IAC9E,MAAM,QAAQ,GAAG,IAAA,8CAAyB,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,CAAC;IAC1D,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;QAC9B,QAAQ,CAAC,SAAS,CAChB,IAAA,oDAA+B,EAAC;YAC9B,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,UAAU;YAChD,MAAM,EAAE,OAAO,CAAC,iBAAiB,CAAC,gBAAgB;SACnD,CAAC,CACH,CAAC;IACJ,CAAC;IAED,QAAQ,CAAC,SAAS,CAAC,IAAA,4CAAmB,EAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;IAC9F,QAAQ,CAAC,SAAS,CAAC,IAAA,gDAAqB,EAAC,OAAO,CAAC,sBAAsB,CAAC,EAAE;QACxE,KAAK,EAAE,aAAa;KACrB,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAjBD,oDAiBC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { DeserializationPolicyOptions, deserializationPolicy } from \"./deserializationPolicy.js\";\nimport {\n InternalPipelineOptions,\n Pipeline,\n bearerTokenAuthenticationPolicy,\n createPipelineFromOptions,\n} from \"@azure/core-rest-pipeline\";\nimport { SerializationPolicyOptions, serializationPolicy } from \"./serializationPolicy.js\";\nimport { TokenCredential } from \"@azure/core-auth\";\n\n/**\n * Options for creating a Pipeline to use with ServiceClient.\n * Mostly for customizing the auth policy (if using token auth) or\n * the deserialization options when using XML.\n */\nexport interface InternalClientPipelineOptions extends InternalPipelineOptions {\n /**\n * Options to customize bearerTokenAuthenticationPolicy.\n */\n credentialOptions?: { credentialScopes: string | string[]; credential: TokenCredential };\n /**\n * Options to customize deserializationPolicy.\n */\n deserializationOptions?: DeserializationPolicyOptions;\n /**\n * Options to customize serializationPolicy.\n */\n serializationOptions?: SerializationPolicyOptions;\n}\n\n/**\n * Creates a new Pipeline for use with a Service Client.\n * Adds in deserializationPolicy by default.\n * Also adds in bearerTokenAuthenticationPolicy if passed a TokenCredential.\n * @param options - Options to customize the created pipeline.\n */\nexport function createClientPipeline(options: InternalClientPipelineOptions = {}): Pipeline {\n const pipeline = createPipelineFromOptions(options ?? {});\n if (options.credentialOptions) {\n pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential: options.credentialOptions.credential,\n scopes: options.credentialOptions.credentialScopes,\n }),\n );\n }\n\n pipeline.addPolicy(serializationPolicy(options.serializationOptions), { phase: \"Serialize\" });\n pipeline.addPolicy(deserializationPolicy(options.deserializationOptions), {\n phase: \"Deserialize\",\n });\n\n return pipeline;\n}\n"]}
1
+ {"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../src/pipeline.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAsClC,oDAiBC;AArDD,yEAAiG;AACjG,kEAKmC;AACnC,qEAA2F;AAuB3F;;;;;GAKG;AACH,SAAgB,oBAAoB,CAAC,UAAyC,EAAE;IAC9E,MAAM,QAAQ,GAAG,IAAA,8CAAyB,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,CAAC;IAC1D,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;QAC9B,QAAQ,CAAC,SAAS,CAChB,IAAA,oDAA+B,EAAC;YAC9B,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,UAAU;YAChD,MAAM,EAAE,OAAO,CAAC,iBAAiB,CAAC,gBAAgB;SACnD,CAAC,CACH,CAAC;IACJ,CAAC;IAED,QAAQ,CAAC,SAAS,CAAC,IAAA,4CAAmB,EAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;IAC9F,QAAQ,CAAC,SAAS,CAAC,IAAA,gDAAqB,EAAC,OAAO,CAAC,sBAAsB,CAAC,EAAE;QACxE,KAAK,EAAE,aAAa;KACrB,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { DeserializationPolicyOptions, deserializationPolicy } from \"./deserializationPolicy.js\";\nimport {\n InternalPipelineOptions,\n Pipeline,\n bearerTokenAuthenticationPolicy,\n createPipelineFromOptions,\n} from \"@azure/core-rest-pipeline\";\nimport { SerializationPolicyOptions, serializationPolicy } from \"./serializationPolicy.js\";\nimport { TokenCredential } from \"@azure/core-auth\";\n\n/**\n * Options for creating a Pipeline to use with ServiceClient.\n * Mostly for customizing the auth policy (if using token auth) or\n * the deserialization options when using XML.\n */\nexport interface InternalClientPipelineOptions extends InternalPipelineOptions {\n /**\n * Options to customize bearerTokenAuthenticationPolicy.\n */\n credentialOptions?: { credentialScopes: string | string[]; credential: TokenCredential };\n /**\n * Options to customize deserializationPolicy.\n */\n deserializationOptions?: DeserializationPolicyOptions;\n /**\n * Options to customize serializationPolicy.\n */\n serializationOptions?: SerializationPolicyOptions;\n}\n\n/**\n * Creates a new Pipeline for use with a Service Client.\n * Adds in deserializationPolicy by default.\n * Also adds in bearerTokenAuthenticationPolicy if passed a TokenCredential.\n * @param options - Options to customize the created pipeline.\n */\nexport function createClientPipeline(options: InternalClientPipelineOptions = {}): Pipeline {\n const pipeline = createPipelineFromOptions(options ?? {});\n if (options.credentialOptions) {\n pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential: options.credentialOptions.credential,\n scopes: options.credentialOptions.credentialScopes,\n }),\n );\n }\n\n pipeline.addPolicy(serializationPolicy(options.serializationOptions), { phase: \"Serialize\" });\n pipeline.addPolicy(deserializationPolicy(options.deserializationOptions), {\n phase: \"Deserialize\",\n });\n\n return pipeline;\n}\n"]}
@@ -2,7 +2,10 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT license.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.serializeRequestBody = exports.serializeHeaders = exports.serializationPolicy = exports.serializationPolicyName = void 0;
5
+ exports.serializationPolicyName = void 0;
6
+ exports.serializationPolicy = serializationPolicy;
7
+ exports.serializeHeaders = serializeHeaders;
8
+ exports.serializeRequestBody = serializeRequestBody;
6
9
  const interfaces_js_1 = require("./interfaces.js");
7
10
  const operationHelpers_js_1 = require("./operationHelpers.js");
8
11
  const serializer_js_1 = require("./serializer.js");
@@ -31,7 +34,6 @@ function serializationPolicy(options = {}) {
31
34
  },
32
35
  };
33
36
  }
34
- exports.serializationPolicy = serializationPolicy;
35
37
  /**
36
38
  * @internal
37
39
  */
@@ -62,7 +64,6 @@ function serializeHeaders(request, operationArguments, operationSpec) {
62
64
  }
63
65
  }
64
66
  }
65
- exports.serializeHeaders = serializeHeaders;
66
67
  /**
67
68
  * @internal
68
69
  */
@@ -130,7 +131,6 @@ function serializeRequestBody(request, operationArguments, operationSpec, string
130
131
  }
131
132
  }
132
133
  }
133
- exports.serializeRequestBody = serializeRequestBody;
134
134
  /**
135
135
  * Adds an xml namespace to the xml serialized object if needed, otherwise it just returns the value itself
136
136
  */
@@ -1 +1 @@
1
- {"version":3,"file":"serializationPolicy.js","sourceRoot":"","sources":["../../src/serializationPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,mDAUyB;AAEzB,+DAG+B;AAC/B,mDAAkD;AAClD,+DAAmE;AAEnE;;GAEG;AACU,QAAA,uBAAuB,GAAG,qBAAqB,CAAC;AAiB7D;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,UAAsC,EAAE;IAC1E,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAE1C,OAAO;QACL,IAAI,EAAE,+BAAuB;QAC7B,KAAK,CAAC,WAAW,CAAC,OAAyB,EAAE,IAAiB;YAC5D,MAAM,aAAa,GAAG,IAAA,6CAAuB,EAAC,OAAO,CAAC,CAAC;YACvD,MAAM,aAAa,GAAG,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,aAAa,CAAC;YACnD,MAAM,kBAAkB,GAAG,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,kBAAkB,CAAC;YAC7D,IAAI,aAAa,IAAI,kBAAkB,EAAE,CAAC;gBACxC,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,EAAE,aAAa,CAAC,CAAC;gBAC7D,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;YACjF,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAhBD,kDAgBC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAC9B,OAAyB,EACzB,kBAAsC,EACtC,aAA4B;;IAE5B,IAAI,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACnC,KAAK,MAAM,eAAe,IAAI,aAAa,CAAC,gBAAgB,EAAE,CAAC;YAC7D,IAAI,WAAW,GAAG,IAAA,4DAAsC,EAAC,kB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,CAAC,EAAE,CAAC;QAChF,MAAM,MAAM,GAAQ,EAAE,CAAC;QACvB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC;QACjD,MAAM,CAAC,2BAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;QACnD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,SAAS,kBAAkB,CACzB,GAAQ,EACR,WAAmB,EACnB,eAAwB,EACxB,YAAqB;IAErB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACd,CAAC;IACD,IAAI,CAAC,eAAe,IAAI,CAAC,YAAY,EAAE,CAAC;QACtC,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;IAChC,CAAC;IAED,MAAM,MAAM,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;IACtC,MAAM,CAAC,2BAAW,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n DictionaryMapper,\n OperationArguments,\n OperationRequest,\n OperationSpec,\n RequiredSerializerOptions,\n SerializerOptions,\n XML_ATTRKEY,\n XML_CHARKEY,\n XmlOptions,\n} from \"./interfaces.js\";\nimport { PipelinePolicy, PipelineResponse, SendRequest } from \"@azure/core-rest-pipeline\";\nimport {\n getOperationArgumentValueFromParameter,\n getOperationRequestInfo,\n} from \"./operationHelpers.js\";\nimport { MapperTypeNames } from \"./serializer.js\";\nimport { getPathStringFromParameter } from \"./interfaceHelpers.js\";\n\n/**\n * The programmatic identifier of the serializationPolicy.\n */\nexport const serializationPolicyName = \"serializationPolicy\";\n\n/**\n * Options to configure API request serialization.\n */\nexport interface SerializationPolicyOptions {\n /**\n * A function that is able to write XML. Required for XML support.\n */\n stringifyXML?: (obj: any, opts?: XmlOptions) => string;\n\n /**\n * Configures behavior of xml parser and builder.\n */\n serializerOptions?: SerializerOptions;\n}\n\n/**\n * This policy handles assembling the request body and headers using\n * an OperationSpec and OperationArguments on the request.\n */\nexport function serializationPolicy(options: SerializationPolicyOptions = {}): PipelinePolicy {\n const stringifyXML = options.stringifyXML;\n\n return {\n name: serializationPolicyName,\n async sendRequest(request: OperationRequest, next: SendRequest): Promise<PipelineResponse> {\n const operationInfo = getOperationRequestInfo(request);\n const operationSpec = operationInfo?.operationSpec;\n const operationArguments = operationInfo?.operationArguments;\n if (operationSpec && operationArguments) {\n serializeHeaders(request, operationArguments, operationSpec);\n serializeRequestBody(request, operationArguments, operationSpec, stringifyXML);\n }\n return next(request);\n },\n };\n}\n\n/**\n * @internal\n */\nexport function serializeHeaders(\n request: OperationRequest,\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n): void {\n if (operationSpec.headerParameters) {\n for (const headerParameter of operationSpec.headerParameters) {\n let headerValue = getOperationArgumentValueFromParameter(operationArguments, headerParameter);\n if ((headerValue !== null && headerValue !== undefined) || headerParameter.mapper.required) {\n headerValue = operationSpec.serializer.serialize(\n headerParameter.mapper,\n headerValue,\n getPathStringFromParameter(headerParameter),\n );\n const headerCollectionPrefix = (headerParameter.mapper as DictionaryMapper)\n .headerCollectionPrefix;\n if (headerCollectionPrefix) {\n for (const key of Object.keys(headerValue)) {\n request.headers.set(headerCollectionPrefix + key, headerValue[key]);\n }\n } else {\n request.headers.set(\n headerParameter.mapper.serializedName || getPathStringFromParameter(headerParameter),\n headerValue,\n );\n }\n }\n }\n }\n const customHeaders = operationArguments.options?.requestOptions?.customHeaders;\n if (customHeaders) {\n for (const customHeaderName of Object.keys(customHeaders)) {\n request.headers.set(customHeaderName, customHeaders[customHeaderName]);\n }\n }\n}\n\n/**\n * @internal\n */\nexport function serializeRequestBody(\n request: OperationRequest,\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n stringifyXML: (obj: any, opts?: XmlOptions) => string = function () {\n throw new Error(\"XML serialization unsupported!\");\n },\n): void {\n const serializerOptions = operationArguments.options?.serializerOptions;\n const updatedOptions: RequiredSerializerOptions = {\n xml: {\n rootName: serializerOptions?.xml.rootName ?? \"\",\n includeRoot: serializerOptions?.xml.includeRoot ?? false,\n xmlCharKey: serializerOptions?.xml.xmlCharKey ?? XML_CHARKEY,\n },\n };\n\n const xmlCharKey = updatedOptions.xml.xmlCharKey;\n if (operationSpec.requestBody && operationSpec.requestBody.mapper) {\n request.body = getOperationArgumentValueFromParameter(\n operationArguments,\n operationSpec.requestBody,\n );\n\n const bodyMapper = operationSpec.requestBody.mapper;\n const {\n required,\n serializedName,\n xmlName,\n xmlElementName,\n xmlNamespace,\n xmlNamespacePrefix,\n nullable,\n } = bodyMapper;\n const typeName = bodyMapper.type.name;\n\n try {\n if (\n (request.body !== undefined && request.body !== null) ||\n (nullable && request.body === null) ||\n required\n ) {\n const requestBodyParameterPathString: string = getPathStringFromParameter(\n operationSpec.requestBody,\n );\n request.body = operationSpec.serializer.serialize(\n bodyMapper,\n request.body,\n requestBodyParameterPathString,\n updatedOptions,\n );\n\n const isStream = typeName === MapperTypeNames.Stream;\n\n if (operationSpec.isXML) {\n const xmlnsKey = xmlNamespacePrefix ? `xmlns:${xmlNamespacePrefix}` : \"xmlns\";\n const value = getXmlValueWithNamespace(\n xmlNamespace,\n xmlnsKey,\n typeName,\n request.body,\n updatedOptions,\n );\n\n if (typeName === MapperTypeNames.Sequence) {\n request.body = stringifyXML(\n prepareXMLRootList(\n value,\n xmlElementName || xmlName || serializedName!,\n xmlnsKey,\n xmlNamespace,\n ),\n { rootName: xmlName || serializedName, xmlCharKey },\n );\n } else if (!isStream) {\n request.body = stringifyXML(value, {\n rootName: xmlName || serializedName,\n xmlCharKey,\n });\n }\n } else if (\n typeName === MapperTypeNames.String &&\n (operationSpec.contentType?.match(\"text/plain\") || operationSpec.mediaType === \"text\")\n ) {\n // the String serializer has validated that request body is a string\n // so just send the string.\n return;\n } else if (!isStream) {\n request.body = JSON.stringify(request.body);\n }\n }\n } catch (error: any) {\n throw new Error(\n `Error \"${error.message}\" occurred in serializing the payload - ${JSON.stringify(\n serializedName,\n undefined,\n \" \",\n )}.`,\n );\n }\n } else if (operationSpec.formDataParameters && operationSpec.formDataParameters.length > 0) {\n request.formData = {};\n for (const formDataParameter of operationSpec.formDataParameters) {\n const formDataParameterValue = getOperationArgumentValueFromParameter(\n operationArguments,\n formDataParameter,\n );\n if (formDataParameterValue !== undefined && formDataParameterValue !== null) {\n const formDataParameterPropertyName: string =\n formDataParameter.mapper.serializedName || getPathStringFromParameter(formDataParameter);\n request.formData[formDataParameterPropertyName] = operationSpec.serializer.serialize(\n formDataParameter.mapper,\n formDataParameterValue,\n getPathStringFromParameter(formDataParameter),\n updatedOptions,\n );\n }\n }\n }\n}\n\n/**\n * Adds an xml namespace to the xml serialized object if needed, otherwise it just returns the value itself\n */\nfunction getXmlValueWithNamespace(\n xmlNamespace: string | undefined,\n xmlnsKey: string,\n typeName: string,\n serializedValue: any,\n options: RequiredSerializerOptions,\n): any {\n // Composite and Sequence schemas already got their root namespace set during serialization\n // We just need to add xmlns to the other schema types\n if (xmlNamespace && ![\"Composite\", \"Sequence\", \"Dictionary\"].includes(typeName)) {\n const result: any = {};\n result[options.xml.xmlCharKey] = serializedValue;\n result[XML_ATTRKEY] = { [xmlnsKey]: xmlNamespace };\n return result;\n }\n\n return serializedValue;\n}\n\nfunction prepareXMLRootList(\n obj: any,\n elementName: string,\n xmlNamespaceKey?: string,\n xmlNamespace?: string,\n): { [key: string]: any[] } {\n if (!Array.isArray(obj)) {\n obj = [obj];\n }\n if (!xmlNamespaceKey || !xmlNamespace) {\n return { [elementName]: obj };\n }\n\n const result = { [elementName]: obj };\n result[XML_ATTRKEY] = { [xmlNamespaceKey]: xmlNamespace };\n return result;\n}\n"]}
1
+ {"version":3,"file":"serializationPolicy.js","sourceRoot":"","sources":["../../src/serializationPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AA6ClC,kDAgBC;AAKD,4CAmCC;AAKD,oDAuHC;AA/ND,mDAUyB;AAEzB,+DAG+B;AAC/B,mDAAkD;AAClD,+DAAmE;AAEnE;;GAEG;AACU,QAAA,uBAAuB,GAAG,qBAAqB,CAAC;AAiB7D;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,UAAsC,EAAE;IAC1E,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAE1C,OAAO;QACL,IAAI,EAAE,+BAAuB;QAC7B,KAAK,CAAC,WAAW,CAAC,OAAyB,EAAE,IAAiB;YAC5D,MAAM,aAAa,GAAG,IAAA,6CAAuB,EAAC,OAAO,CAAC,CAAC;YACvD,MAAM,aAAa,GAAG,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,aAAa,CAAC;YACnD,MAAM,kBAAkB,GAAG,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,kBAAkB,CAAC;YAC7D,IAAI,aAAa,IAAI,kBAAkB,EAAE,CAAC;gBACxC,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,EAAE,aAAa,CAAC,CAAC;gBAC7D,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;YACjF,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAC9B,OAAyB,EACzB,kBAAsC,EACtC,aAA4B;;IAE5B,IAAI,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACnC,KAAK,MAAM,eAAe,IAAI,aAAa,CAAC,gBAAgB,EAAE,CAAC;YAC7D,IAAI,WAAW,GAAG,IAAA,4DAAsC,EAAC,kBAAkB,EAAE,eA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AAE,CAAC;QACvB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC;QACjD,MAAM,CAAC,2BAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;QACnD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,SAAS,kBAAkB,CACzB,GAAQ,EACR,WAAmB,EACnB,eAAwB,EACxB,YAAqB;IAErB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACd,CAAC;IACD,IAAI,CAAC,eAAe,IAAI,CAAC,YAAY,EAAE,CAAC;QACtC,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;IAChC,CAAC;IAED,MAAM,MAAM,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;IACtC,MAAM,CAAC,2BAAW,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n DictionaryMapper,\n OperationArguments,\n OperationRequest,\n OperationSpec,\n RequiredSerializerOptions,\n SerializerOptions,\n XML_ATTRKEY,\n XML_CHARKEY,\n XmlOptions,\n} from \"./interfaces.js\";\nimport { PipelinePolicy, PipelineResponse, SendRequest } from \"@azure/core-rest-pipeline\";\nimport {\n getOperationArgumentValueFromParameter,\n getOperationRequestInfo,\n} from \"./operationHelpers.js\";\nimport { MapperTypeNames } from \"./serializer.js\";\nimport { getPathStringFromParameter } from \"./interfaceHelpers.js\";\n\n/**\n * The programmatic identifier of the serializationPolicy.\n */\nexport const serializationPolicyName = \"serializationPolicy\";\n\n/**\n * Options to configure API request serialization.\n */\nexport interface SerializationPolicyOptions {\n /**\n * A function that is able to write XML. Required for XML support.\n */\n stringifyXML?: (obj: any, opts?: XmlOptions) => string;\n\n /**\n * Configures behavior of xml parser and builder.\n */\n serializerOptions?: SerializerOptions;\n}\n\n/**\n * This policy handles assembling the request body and headers using\n * an OperationSpec and OperationArguments on the request.\n */\nexport function serializationPolicy(options: SerializationPolicyOptions = {}): PipelinePolicy {\n const stringifyXML = options.stringifyXML;\n\n return {\n name: serializationPolicyName,\n async sendRequest(request: OperationRequest, next: SendRequest): Promise<PipelineResponse> {\n const operationInfo = getOperationRequestInfo(request);\n const operationSpec = operationInfo?.operationSpec;\n const operationArguments = operationInfo?.operationArguments;\n if (operationSpec && operationArguments) {\n serializeHeaders(request, operationArguments, operationSpec);\n serializeRequestBody(request, operationArguments, operationSpec, stringifyXML);\n }\n return next(request);\n },\n };\n}\n\n/**\n * @internal\n */\nexport function serializeHeaders(\n request: OperationRequest,\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n): void {\n if (operationSpec.headerParameters) {\n for (const headerParameter of operationSpec.headerParameters) {\n let headerValue = getOperationArgumentValueFromParameter(operationArguments, headerParameter);\n if ((headerValue !== null && headerValue !== undefined) || headerParameter.mapper.required) {\n headerValue = operationSpec.serializer.serialize(\n headerParameter.mapper,\n headerValue,\n getPathStringFromParameter(headerParameter),\n );\n const headerCollectionPrefix = (headerParameter.mapper as DictionaryMapper)\n .headerCollectionPrefix;\n if (headerCollectionPrefix) {\n for (const key of Object.keys(headerValue)) {\n request.headers.set(headerCollectionPrefix + key, headerValue[key]);\n }\n } else {\n request.headers.set(\n headerParameter.mapper.serializedName || getPathStringFromParameter(headerParameter),\n headerValue,\n );\n }\n }\n }\n }\n const customHeaders = operationArguments.options?.requestOptions?.customHeaders;\n if (customHeaders) {\n for (const customHeaderName of Object.keys(customHeaders)) {\n request.headers.set(customHeaderName, customHeaders[customHeaderName]);\n }\n }\n}\n\n/**\n * @internal\n */\nexport function serializeRequestBody(\n request: OperationRequest,\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n stringifyXML: (obj: any, opts?: XmlOptions) => string = function () {\n throw new Error(\"XML serialization unsupported!\");\n },\n): void {\n const serializerOptions = operationArguments.options?.serializerOptions;\n const updatedOptions: RequiredSerializerOptions = {\n xml: {\n rootName: serializerOptions?.xml.rootName ?? \"\",\n includeRoot: serializerOptions?.xml.includeRoot ?? false,\n xmlCharKey: serializerOptions?.xml.xmlCharKey ?? XML_CHARKEY,\n },\n };\n\n const xmlCharKey = updatedOptions.xml.xmlCharKey;\n if (operationSpec.requestBody && operationSpec.requestBody.mapper) {\n request.body = getOperationArgumentValueFromParameter(\n operationArguments,\n operationSpec.requestBody,\n );\n\n const bodyMapper = operationSpec.requestBody.mapper;\n const {\n required,\n serializedName,\n xmlName,\n xmlElementName,\n xmlNamespace,\n xmlNamespacePrefix,\n nullable,\n } = bodyMapper;\n const typeName = bodyMapper.type.name;\n\n try {\n if (\n (request.body !== undefined && request.body !== null) ||\n (nullable && request.body === null) ||\n required\n ) {\n const requestBodyParameterPathString: string = getPathStringFromParameter(\n operationSpec.requestBody,\n );\n request.body = operationSpec.serializer.serialize(\n bodyMapper,\n request.body,\n requestBodyParameterPathString,\n updatedOptions,\n );\n\n const isStream = typeName === MapperTypeNames.Stream;\n\n if (operationSpec.isXML) {\n const xmlnsKey = xmlNamespacePrefix ? `xmlns:${xmlNamespacePrefix}` : \"xmlns\";\n const value = getXmlValueWithNamespace(\n xmlNamespace,\n xmlnsKey,\n typeName,\n request.body,\n updatedOptions,\n );\n\n if (typeName === MapperTypeNames.Sequence) {\n request.body = stringifyXML(\n prepareXMLRootList(\n value,\n xmlElementName || xmlName || serializedName!,\n xmlnsKey,\n xmlNamespace,\n ),\n { rootName: xmlName || serializedName, xmlCharKey },\n );\n } else if (!isStream) {\n request.body = stringifyXML(value, {\n rootName: xmlName || serializedName,\n xmlCharKey,\n });\n }\n } else if (\n typeName === MapperTypeNames.String &&\n (operationSpec.contentType?.match(\"text/plain\") || operationSpec.mediaType === \"text\")\n ) {\n // the String serializer has validated that request body is a string\n // so just send the string.\n return;\n } else if (!isStream) {\n request.body = JSON.stringify(request.body);\n }\n }\n } catch (error: any) {\n throw new Error(\n `Error \"${error.message}\" occurred in serializing the payload - ${JSON.stringify(\n serializedName,\n undefined,\n \" \",\n )}.`,\n );\n }\n } else if (operationSpec.formDataParameters && operationSpec.formDataParameters.length > 0) {\n request.formData = {};\n for (const formDataParameter of operationSpec.formDataParameters) {\n const formDataParameterValue = getOperationArgumentValueFromParameter(\n operationArguments,\n formDataParameter,\n );\n if (formDataParameterValue !== undefined && formDataParameterValue !== null) {\n const formDataParameterPropertyName: string =\n formDataParameter.mapper.serializedName || getPathStringFromParameter(formDataParameter);\n request.formData[formDataParameterPropertyName] = operationSpec.serializer.serialize(\n formDataParameter.mapper,\n formDataParameterValue,\n getPathStringFromParameter(formDataParameter),\n updatedOptions,\n );\n }\n }\n }\n}\n\n/**\n * Adds an xml namespace to the xml serialized object if needed, otherwise it just returns the value itself\n */\nfunction getXmlValueWithNamespace(\n xmlNamespace: string | undefined,\n xmlnsKey: string,\n typeName: string,\n serializedValue: any,\n options: RequiredSerializerOptions,\n): any {\n // Composite and Sequence schemas already got their root namespace set during serialization\n // We just need to add xmlns to the other schema types\n if (xmlNamespace && ![\"Composite\", \"Sequence\", \"Dictionary\"].includes(typeName)) {\n const result: any = {};\n result[options.xml.xmlCharKey] = serializedValue;\n result[XML_ATTRKEY] = { [xmlnsKey]: xmlNamespace };\n return result;\n }\n\n return serializedValue;\n}\n\nfunction prepareXMLRootList(\n obj: any,\n elementName: string,\n xmlNamespaceKey?: string,\n xmlNamespace?: string,\n): { [key: string]: any[] } {\n if (!Array.isArray(obj)) {\n obj = [obj];\n }\n if (!xmlNamespaceKey || !xmlNamespace) {\n return { [elementName]: obj };\n }\n\n const result = { [elementName]: obj };\n result[XML_ATTRKEY] = { [xmlNamespaceKey]: xmlNamespace };\n return result;\n}\n"]}