@azure/core-client 1.10.2-alpha.20260311.2 → 1.10.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 (105) hide show
  1. package/dist/browser/authorizeRequestOnTenantChallenge.js +1 -2
  2. package/dist/browser/authorizeRequestOnTenantChallenge.js.map +1 -1
  3. package/dist/browser/base64.d.ts +1 -5
  4. package/dist/browser/base64.js +6 -14
  5. package/dist/browser/base64.js.map +1 -1
  6. package/dist/browser/interfaceHelpers.js +1 -2
  7. package/dist/browser/interfaceHelpers.js.map +1 -1
  8. package/dist/browser/operationHelpers.js +8 -4
  9. package/dist/browser/operationHelpers.js.map +1 -1
  10. package/dist/browser/serializationPolicy.js +1 -1
  11. package/dist/browser/serializationPolicy.js.map +1 -1
  12. package/dist/browser/serializer.js +32 -11
  13. package/dist/browser/serializer.js.map +1 -1
  14. package/dist/browser/serviceClient.js +2 -2
  15. package/dist/browser/serviceClient.js.map +1 -1
  16. package/dist/browser/{state.d.ts → state-web.d.mts} +1 -1
  17. package/dist/browser/{state.js → state-web.mjs} +1 -1
  18. package/dist/browser/state-web.mjs.map +1 -0
  19. package/dist/browser/urlHelpers.js +2 -1
  20. package/dist/browser/urlHelpers.js.map +1 -1
  21. package/dist/commonjs/authorizeRequestOnTenantChallenge.js +1 -2
  22. package/dist/commonjs/authorizeRequestOnTenantChallenge.js.map +1 -1
  23. package/dist/commonjs/base64.d.ts +1 -1
  24. package/dist/commonjs/base64.js +6 -6
  25. package/dist/commonjs/base64.js.map +1 -1
  26. package/dist/commonjs/interfaceHelpers.js +1 -2
  27. package/dist/commonjs/interfaceHelpers.js.map +1 -1
  28. package/dist/commonjs/operationHelpers.js +10 -6
  29. package/dist/commonjs/operationHelpers.js.map +1 -1
  30. package/dist/commonjs/serializationPolicy.js +1 -1
  31. package/dist/commonjs/serializationPolicy.js.map +1 -1
  32. package/dist/commonjs/serializer.js +32 -11
  33. package/dist/commonjs/serializer.js.map +1 -1
  34. package/dist/commonjs/serviceClient.js +2 -2
  35. package/dist/commonjs/serviceClient.js.map +1 -1
  36. package/dist/commonjs/{state.d.ts → state-cjs.d.ts} +1 -1
  37. package/dist/commonjs/{state.js → state-cjs.js} +1 -1
  38. package/dist/commonjs/state-cjs.js.map +1 -0
  39. package/dist/commonjs/tsdoc-metadata.json +1 -1
  40. package/dist/commonjs/urlHelpers.js +2 -1
  41. package/dist/commonjs/urlHelpers.js.map +1 -1
  42. package/dist/esm/authorizeRequestOnClaimChallenge.js +67 -44
  43. package/dist/esm/authorizeRequestOnClaimChallenge.js.map +1 -7
  44. package/dist/esm/authorizeRequestOnTenantChallenge.js +97 -72
  45. package/dist/esm/authorizeRequestOnTenantChallenge.js.map +1 -7
  46. package/dist/esm/base64.d.ts +1 -1
  47. package/dist/esm/base64.js +32 -15
  48. package/dist/esm/base64.js.map +1 -7
  49. package/dist/esm/deserializationPolicy.js +202 -205
  50. package/dist/esm/deserializationPolicy.js.map +1 -7
  51. package/dist/esm/httpClientCache.js +8 -8
  52. package/dist/esm/httpClientCache.js.map +1 -7
  53. package/dist/esm/index.js +11 -31
  54. package/dist/esm/index.js.map +1 -7
  55. package/dist/esm/interfaceHelpers.js +34 -23
  56. package/dist/esm/interfaceHelpers.js.map +1 -7
  57. package/dist/esm/interfaces.js +11 -6
  58. package/dist/esm/interfaces.js.map +1 -7
  59. package/dist/esm/log.js +4 -4
  60. package/dist/esm/log.js.map +1 -7
  61. package/dist/esm/operationHelpers.js +86 -73
  62. package/dist/esm/operationHelpers.js.map +1 -7
  63. package/dist/esm/pipeline.js +23 -22
  64. package/dist/esm/pipeline.js.map +1 -7
  65. package/dist/esm/serializationPolicy.js +134 -163
  66. package/dist/esm/serializationPolicy.js.map +1 -7
  67. package/dist/esm/serializer.js +877 -812
  68. package/dist/esm/serializer.js.map +1 -7
  69. package/dist/esm/serviceClient.js +150 -151
  70. package/dist/esm/serviceClient.js.map +1 -7
  71. package/dist/esm/state-cjs.d.ts +8 -0
  72. package/dist/esm/state-cjs.js +9 -0
  73. package/dist/esm/state-cjs.js.map +1 -0
  74. package/dist/esm/state.js +10 -5
  75. package/dist/esm/state.js.map +1 -7
  76. package/dist/esm/urlHelpers.js +207 -199
  77. package/dist/esm/urlHelpers.js.map +1 -7
  78. package/dist/esm/utils.js +118 -64
  79. package/dist/esm/utils.js.map +1 -7
  80. package/dist/react-native/authorizeRequestOnTenantChallenge.js +1 -2
  81. package/dist/react-native/authorizeRequestOnTenantChallenge.js.map +1 -1
  82. package/dist/react-native/base64.d.ts +1 -1
  83. package/dist/react-native/base64.js +6 -6
  84. package/dist/react-native/base64.js.map +1 -1
  85. package/dist/react-native/interfaceHelpers.js +1 -2
  86. package/dist/react-native/interfaceHelpers.js.map +1 -1
  87. package/dist/react-native/operationHelpers.js +8 -4
  88. package/dist/react-native/operationHelpers.js.map +1 -1
  89. package/dist/react-native/serializationPolicy.js +1 -1
  90. package/dist/react-native/serializationPolicy.js.map +1 -1
  91. package/dist/react-native/serializer.js +32 -11
  92. package/dist/react-native/serializer.js.map +1 -1
  93. package/dist/react-native/serviceClient.js +2 -2
  94. package/dist/react-native/serviceClient.js.map +1 -1
  95. package/dist/react-native/state-web.d.mts +8 -0
  96. package/dist/react-native/state-web.mjs +9 -0
  97. package/dist/react-native/state-web.mjs.map +1 -0
  98. package/dist/react-native/urlHelpers.js +2 -1
  99. package/dist/react-native/urlHelpers.js.map +1 -1
  100. package/package.json +31 -17
  101. package/dist/browser/state.js.map +0 -1
  102. package/dist/commonjs/state.js.map +0 -1
  103. package/dist/react-native/state.d.ts +0 -8
  104. package/dist/react-native/state.js +0 -10
  105. package/dist/react-native/state.js.map +0 -1
@@ -1,3 +1,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
1
3
  import { createPipelineRequest } from "@azure/core-rest-pipeline";
2
4
  import { createClientPipeline } from "./pipeline.js";
3
5
  import { flattenResponse } from "./utils.js";
@@ -6,168 +8,165 @@ import { getOperationRequestInfo } from "./operationHelpers.js";
6
8
  import { getRequestUrl } from "./urlHelpers.js";
7
9
  import { getStreamingResponseStatusCodes } from "./interfaceHelpers.js";
8
10
  import { logger } from "./log.js";
9
- class ServiceClient {
10
- /**
11
- * If specified, this is the base URI that requests will be made against for this ServiceClient.
12
- * If it is not specified, then all OperationSpecs must contain a baseUrl property.
13
- */
14
- _endpoint;
15
- /**
16
- * The default request content type for the service.
17
- * Used if no requestContentType is present on an OperationSpec.
18
- */
19
- _requestContentType;
20
- /**
21
- * Set to true if the request is sent over HTTP instead of HTTPS
22
- */
23
- _allowInsecureConnection;
24
- /**
25
- * The HTTP client that will be used to send requests.
26
- */
27
- _httpClient;
28
- /**
29
- * The pipeline used by this client to make requests
30
- */
31
- pipeline;
32
- /**
33
- * The ServiceClient constructor
34
- * @param options - The service client options that govern the behavior of the client.
35
- */
36
- constructor(options = {}) {
37
- this._requestContentType = options.requestContentType;
38
- this._endpoint = options.endpoint ?? options.baseUri;
39
- if (options.baseUri) {
40
- logger.warning(
41
- "The baseUri option for SDK Clients has been deprecated, please use endpoint instead."
42
- );
43
- }
44
- this._allowInsecureConnection = options.allowInsecureConnection;
45
- this._httpClient = options.httpClient || getCachedDefaultHttpClient();
46
- this.pipeline = options.pipeline || createDefaultPipeline(options);
47
- if (options.additionalPolicies?.length) {
48
- for (const { policy, position } of options.additionalPolicies) {
49
- const afterPhase = position === "perRetry" ? "Sign" : void 0;
50
- this.pipeline.addPolicy(policy, {
51
- afterPhase
52
- });
53
- }
54
- }
55
- }
56
- /**
57
- * Send the provided httpRequest.
58
- */
59
- async sendRequest(request) {
60
- return this.pipeline.sendRequest(this._httpClient, request);
61
- }
62
- /**
63
- * Send an HTTP request that is populated using the provided OperationSpec.
64
- * @typeParam T - The typed result of the request, based on the OperationSpec.
65
- * @param operationArguments - The arguments that the HTTP request's templated values will be populated from.
66
- * @param operationSpec - The OperationSpec to use to populate the httpRequest.
67
- */
68
- async sendOperationRequest(operationArguments, operationSpec) {
69
- const endpoint = operationSpec.baseUrl || this._endpoint;
70
- if (!endpoint) {
71
- throw new Error(
72
- "If operationSpec.baseUrl is not specified, then the ServiceClient must have a endpoint string property that contains the base URL to use."
73
- );
11
+ /**
12
+ * Initializes a new instance of the ServiceClient.
13
+ */
14
+ export class ServiceClient {
15
+ /**
16
+ * If specified, this is the base URI that requests will be made against for this ServiceClient.
17
+ * If it is not specified, then all OperationSpecs must contain a baseUrl property.
18
+ */
19
+ _endpoint;
20
+ /**
21
+ * The default request content type for the service.
22
+ * Used if no requestContentType is present on an OperationSpec.
23
+ */
24
+ _requestContentType;
25
+ /**
26
+ * Set to true if the request is sent over HTTP instead of HTTPS
27
+ */
28
+ _allowInsecureConnection;
29
+ /**
30
+ * The HTTP client that will be used to send requests.
31
+ */
32
+ _httpClient;
33
+ /**
34
+ * The pipeline used by this client to make requests
35
+ */
36
+ pipeline;
37
+ /**
38
+ * The ServiceClient constructor
39
+ * @param options - The service client options that govern the behavior of the client.
40
+ */
41
+ constructor(options = {}) {
42
+ this._requestContentType = options.requestContentType;
43
+ this._endpoint = options.endpoint ?? options.baseUri;
44
+ if (options.baseUri) {
45
+ logger.warning("The baseUri option for SDK Clients has been deprecated, please use endpoint instead.");
46
+ }
47
+ this._allowInsecureConnection = options.allowInsecureConnection;
48
+ this._httpClient = options.httpClient || getCachedDefaultHttpClient();
49
+ this.pipeline = options.pipeline || createDefaultPipeline(options);
50
+ if (options.additionalPolicies?.length) {
51
+ for (const { policy, position } of options.additionalPolicies) {
52
+ // Sign happens after Retry and is commonly needed to occur
53
+ // before policies that intercept post-retry.
54
+ const afterPhase = position === "perRetry" ? "Sign" : undefined;
55
+ this.pipeline.addPolicy(policy, {
56
+ afterPhase,
57
+ });
58
+ }
59
+ }
74
60
  }
75
- const url = getRequestUrl(endpoint, operationSpec, operationArguments, this);
76
- const request = createPipelineRequest({
77
- url
78
- });
79
- request.method = operationSpec.httpMethod;
80
- const operationInfo = getOperationRequestInfo(request);
81
- operationInfo.operationSpec = operationSpec;
82
- operationInfo.operationArguments = operationArguments;
83
- const contentType = operationSpec.contentType || this._requestContentType;
84
- if (contentType && operationSpec.requestBody) {
85
- request.headers.set("Content-Type", contentType);
61
+ /**
62
+ * Send the provided httpRequest.
63
+ */
64
+ sendRequest(request) {
65
+ return this.pipeline.sendRequest(this._httpClient, request);
86
66
  }
87
- const options = operationArguments.options;
88
- if (options) {
89
- const requestOptions = options.requestOptions;
90
- if (requestOptions) {
91
- if (requestOptions.timeout) {
92
- request.timeout = requestOptions.timeout;
67
+ /**
68
+ * Send an HTTP request that is populated using the provided OperationSpec.
69
+ * @typeParam T - The typed result of the request, based on the OperationSpec.
70
+ * @param operationArguments - The arguments that the HTTP request's templated values will be populated from.
71
+ * @param operationSpec - The OperationSpec to use to populate the httpRequest.
72
+ */
73
+ async sendOperationRequest(operationArguments, operationSpec) {
74
+ const endpoint = operationSpec.baseUrl || this._endpoint;
75
+ if (!endpoint) {
76
+ throw new Error("If operationSpec.baseUrl is not specified, then the ServiceClient must have a endpoint string property that contains the base URL to use.");
93
77
  }
94
- if (requestOptions.onUploadProgress) {
95
- request.onUploadProgress = requestOptions.onUploadProgress;
78
+ // Templatized URLs sometimes reference properties on the ServiceClient child class,
79
+ // so we have to pass `this` below in order to search these properties if they're
80
+ // not part of OperationArguments
81
+ const url = getRequestUrl(endpoint, operationSpec, operationArguments, this);
82
+ const request = createPipelineRequest({
83
+ url,
84
+ });
85
+ request.method = operationSpec.httpMethod;
86
+ const operationInfo = getOperationRequestInfo(request);
87
+ operationInfo.operationSpec = operationSpec;
88
+ operationInfo.operationArguments = operationArguments;
89
+ const contentType = operationSpec.contentType || this._requestContentType;
90
+ if (contentType && operationSpec.requestBody) {
91
+ request.headers.set("Content-Type", contentType);
96
92
  }
97
- if (requestOptions.onDownloadProgress) {
98
- request.onDownloadProgress = requestOptions.onDownloadProgress;
93
+ const options = operationArguments.options;
94
+ if (options) {
95
+ const requestOptions = options.requestOptions;
96
+ if (requestOptions) {
97
+ if (requestOptions.timeout) {
98
+ request.timeout = requestOptions.timeout;
99
+ }
100
+ if (requestOptions.onUploadProgress) {
101
+ request.onUploadProgress = requestOptions.onUploadProgress;
102
+ }
103
+ if (requestOptions.onDownloadProgress) {
104
+ request.onDownloadProgress = requestOptions.onDownloadProgress;
105
+ }
106
+ if (requestOptions.shouldDeserialize !== undefined) {
107
+ operationInfo.shouldDeserialize = requestOptions.shouldDeserialize;
108
+ }
109
+ if (requestOptions.allowInsecureConnection) {
110
+ request.allowInsecureConnection = true;
111
+ }
112
+ }
113
+ if (options.abortSignal) {
114
+ request.abortSignal = options.abortSignal;
115
+ }
116
+ if (options.tracingOptions) {
117
+ request.tracingOptions = options.tracingOptions;
118
+ }
99
119
  }
100
- if (requestOptions.shouldDeserialize !== void 0) {
101
- operationInfo.shouldDeserialize = requestOptions.shouldDeserialize;
120
+ if (this._allowInsecureConnection) {
121
+ request.allowInsecureConnection = true;
102
122
  }
103
- if (requestOptions.allowInsecureConnection) {
104
- request.allowInsecureConnection = true;
123
+ if (request.streamResponseStatusCodes === undefined) {
124
+ request.streamResponseStatusCodes = getStreamingResponseStatusCodes(operationSpec);
105
125
  }
106
- }
107
- if (options.abortSignal) {
108
- request.abortSignal = options.abortSignal;
109
- }
110
- if (options.tracingOptions) {
111
- request.tracingOptions = options.tracingOptions;
112
- }
113
- }
114
- if (this._allowInsecureConnection) {
115
- request.allowInsecureConnection = true;
116
- }
117
- if (request.streamResponseStatusCodes === void 0) {
118
- request.streamResponseStatusCodes = getStreamingResponseStatusCodes(operationSpec);
119
- }
120
- try {
121
- const rawResponse = await this.sendRequest(request);
122
- const flatResponse = flattenResponse(
123
- rawResponse,
124
- operationSpec.responses[rawResponse.status]
125
- );
126
- if (options?.onResponse) {
127
- options.onResponse(rawResponse, flatResponse);
128
- }
129
- return flatResponse;
130
- } catch (error) {
131
- if (typeof error === "object" && error?.response) {
132
- const rawResponse = error.response;
133
- const flatResponse = flattenResponse(
134
- rawResponse,
135
- operationSpec.responses[error.statusCode] || operationSpec.responses["default"]
136
- );
137
- error.details = flatResponse;
138
- if (options?.onResponse) {
139
- options.onResponse(rawResponse, flatResponse, error);
126
+ try {
127
+ const rawResponse = await this.sendRequest(request);
128
+ const flatResponse = flattenResponse(rawResponse, operationSpec.responses[rawResponse.status]);
129
+ if (options?.onResponse) {
130
+ options.onResponse(rawResponse, flatResponse);
131
+ }
132
+ return flatResponse;
133
+ }
134
+ catch (error) {
135
+ if (typeof error === "object" && error?.response) {
136
+ const rawResponse = error.response;
137
+ const flatResponse = flattenResponse(rawResponse, operationSpec.responses[error.statusCode] || operationSpec.responses["default"]);
138
+ error.details = flatResponse;
139
+ if (options?.onResponse) {
140
+ options.onResponse(rawResponse, flatResponse, error);
141
+ }
142
+ }
143
+ throw error;
140
144
  }
141
- }
142
- throw error;
143
145
  }
144
- }
145
146
  }
146
147
  function createDefaultPipeline(options) {
147
- const credentialScopes = getCredentialScopes(options);
148
- const credentialOptions = options.credential && credentialScopes ? { credentialScopes, credential: options.credential } : void 0;
149
- return createClientPipeline({
150
- ...options,
151
- credentialOptions
152
- });
148
+ const credentialScopes = getCredentialScopes(options);
149
+ const credentialOptions = options.credential && credentialScopes
150
+ ? { credentialScopes, credential: options.credential }
151
+ : undefined;
152
+ return createClientPipeline({
153
+ ...options,
154
+ credentialOptions,
155
+ });
153
156
  }
154
157
  function getCredentialScopes(options) {
155
- if (options.credentialScopes) {
156
- return options.credentialScopes;
157
- }
158
- if (options.endpoint) {
159
- return `${options.endpoint}/.default`;
160
- }
161
- if (options.baseUri) {
162
- return `${options.baseUri}/.default`;
163
- }
164
- if (options.credential && !options.credentialScopes) {
165
- throw new Error(
166
- `When using credentials, the ServiceClientOptions must contain either a endpoint or a credentialScopes. Unable to create a bearerTokenAuthenticationPolicy`
167
- );
168
- }
169
- return void 0;
158
+ if (options.credentialScopes) {
159
+ return options.credentialScopes;
160
+ }
161
+ if (options.endpoint) {
162
+ return `${options.endpoint}/.default`;
163
+ }
164
+ if (options.baseUri) {
165
+ return `${options.baseUri}/.default`;
166
+ }
167
+ if (options.credential) {
168
+ throw new Error(`When using credentials, the ServiceClientOptions must contain either a endpoint or a credentialScopes. Unable to create a bearerTokenAuthenticationPolicy`);
169
+ }
170
+ return undefined;
170
171
  }
171
- export {
172
- ServiceClient
173
- };
172
+ //# sourceMappingURL=serviceClient.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["/mnt/vss/_work/1/s/sdk/core/core-client/src/serviceClient.ts"],
4
- "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n CommonClientOptions,\n OperationArguments,\n OperationRequest,\n OperationSpec,\n} from \"./interfaces.js\";\nimport type {\n HttpClient,\n Pipeline,\n PipelineRequest,\n PipelineResponse,\n} from \"@azure/core-rest-pipeline\";\nimport { createPipelineRequest } from \"@azure/core-rest-pipeline\";\nimport type { 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"],
5
- "mappings": "AAeA,SAAS,6BAA6B;AAEtC,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,+BAA+B;AACxC,SAAS,qBAAqB;AAC9B,SAAS,uCAAuC;AAChD,SAAS,cAAc;AAwChB,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAKR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhB,YAAY,UAAgC,CAAC,GAAG;AAC9C,SAAK,sBAAsB,QAAQ;AACnC,SAAK,YAAY,QAAQ,YAAY,QAAQ;AAC7C,QAAI,QA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,CAAC;gBAC7B,IAAI,OAAO,EAAE,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,CAAC;QAC1B,GAAG,OAAO;QACV,iBAAiB;KAClB,CAAC,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,EAAE,CAAC;QACvB,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 type {\n CommonClientOptions,\n OperationArguments,\n OperationRequest,\n OperationSpec,\n} from \"./interfaces.js\";\nimport type {\n HttpClient,\n Pipeline,\n PipelineRequest,\n PipelineResponse,\n} from \"@azure/core-rest-pipeline\";\nimport { createPipelineRequest } from \"@azure/core-rest-pipeline\";\nimport type { 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 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) {\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"]}
@@ -0,0 +1,8 @@
1
+ import type { OperationRequestInfo } from "./interfaces.js";
2
+ /**
3
+ * Holds the singleton operationRequestMap, to be shared across CJS and ESM imports.
4
+ */
5
+ export declare const state: {
6
+ operationRequestMap: WeakMap<import("@azure/core-rest-pipeline").PipelineRequest, OperationRequestInfo>;
7
+ };
8
+ //# sourceMappingURL=state-cjs.d.ts.map
@@ -0,0 +1,9 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /**
4
+ * Holds the singleton operationRequestMap, to be shared across CJS and ESM imports.
5
+ */
6
+ export const state = {
7
+ operationRequestMap: new WeakMap(),
8
+ };
9
+ //# sourceMappingURL=state-cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-cjs.js","sourceRoot":"","sources":["../../src/state-cjs.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,mBAAmB,EAAE,IAAI,OAAO,EAA0C;CAC3E,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationRequest, OperationRequestInfo } from \"./interfaces.js\";\n\n/**\n * Holds the singleton operationRequestMap, to be shared across CJS and ESM imports.\n */\nexport const state = {\n operationRequestMap: new WeakMap<OperationRequest, OperationRequestInfo>(),\n};\n"]}
package/dist/esm/state.js CHANGED
@@ -1,5 +1,10 @@
1
- import { state as cjsState } from "../commonjs/state.js";
2
- const state = cjsState;
3
- export {
4
- state
5
- };
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ // @ts-expect-error The recommended approach to sharing module state between ESM and CJS.
4
+ // See https://github.com/isaacs/tshy/blob/main/README.md#module-local-state for additional information.
5
+ import { state as cjsState } from "../commonjs/state-cjs.js";
6
+ /**
7
+ * Defines the shared state between CJS and ESM by re-exporting the CJS state.
8
+ */
9
+ export const state = cjsState;
10
+ //# sourceMappingURL=state.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["/mnt/vss/_work/1/s/sdk/core/core-client/src/state.ts"],
4
- "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationRequest, OperationRequestInfo } from \"./interfaces.js\";\n\n// @ts-expect-error The recommended approach to sharing module state between ESM and CJS.\n// See https://github.com/isaacs/tshy/blob/main/README.md#module-local-state for additional information.\nimport { state as cjsState } from \"../commonjs/state.js\";\n\n/**\n * Defines the shared state between CJS and ESM by re-exporting the CJS state.\n */\nexport const state = cjsState as {\n operationRequestMap: WeakMap<OperationRequest, OperationRequestInfo>;\n};\n"],
5
- "mappings": "AAOA,SAAS,SAAS,gBAAgB;AAK3B,MAAM,QAAQ;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,yFAAyF;AACzF,wGAAwG;AACxG,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,QAEpB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationRequest, OperationRequestInfo } from \"./interfaces.js\";\n\n// @ts-expect-error The recommended approach to sharing module state between ESM and CJS.\n// See https://github.com/isaacs/tshy/blob/main/README.md#module-local-state for additional information.\nimport { state as cjsState } from \"../commonjs/state-cjs.js\";\n\n/**\n * Defines the shared state between CJS and ESM by re-exporting the CJS state.\n */\nexport const state = cjsState as {\n operationRequestMap: WeakMap<OperationRequest, OperationRequestInfo>;\n};\n"]}