@azure/arm-operations 4.0.0-beta.3 → 4.0.0-beta.4

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.
@@ -8,6 +8,11 @@
8
8
 
9
9
  import * as coreClient from "@azure/core-client";
10
10
  import * as coreRestPipeline from "@azure/core-rest-pipeline";
11
+ import {
12
+ PipelineRequest,
13
+ PipelineResponse,
14
+ SendRequest
15
+ } from "@azure/core-rest-pipeline";
11
16
  import * as coreAuth from "@azure/core-auth";
12
17
  import {
13
18
  SolutionsImpl,
@@ -56,47 +61,53 @@ export class OperationsManagementClient extends coreClient.ServiceClient {
56
61
  credential: credentials
57
62
  };
58
63
 
59
- const packageDetails = `azsdk-js-arm-operations/4.0.0-beta.3`;
64
+ const packageDetails = `azsdk-js-arm-operations/4.0.0-beta.4`;
60
65
  const userAgentPrefix =
61
66
  options.userAgentOptions && options.userAgentOptions.userAgentPrefix
62
67
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
63
68
  : `${packageDetails}`;
64
69
 
65
- if (!options.credentialScopes) {
66
- options.credentialScopes = ["https://management.azure.com/.default"];
67
- }
68
70
  const optionsWithDefaults = {
69
71
  ...defaults,
70
72
  ...options,
71
73
  userAgentOptions: {
72
74
  userAgentPrefix
73
75
  },
74
- baseUri:
76
+ endpoint:
75
77
  options.endpoint ?? options.baseUri ?? "https://management.azure.com"
76
78
  };
77
79
  super(optionsWithDefaults);
78
80
 
81
+ let bearerTokenAuthenticationPolicyFound: boolean = false;
79
82
  if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) {
80
83
  const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies();
81
- const bearerTokenAuthenticationPolicyFound = pipelinePolicies.some(
84
+ bearerTokenAuthenticationPolicyFound = pipelinePolicies.some(
82
85
  (pipelinePolicy) =>
83
86
  pipelinePolicy.name ===
84
87
  coreRestPipeline.bearerTokenAuthenticationPolicyName
85
88
  );
86
- if (!bearerTokenAuthenticationPolicyFound) {
87
- this.pipeline.removePolicy({
88
- name: coreRestPipeline.bearerTokenAuthenticationPolicyName
89
- });
90
- this.pipeline.addPolicy(
91
- coreRestPipeline.bearerTokenAuthenticationPolicy({
92
- scopes: `${optionsWithDefaults.baseUri}/.default`,
93
- challengeCallbacks: {
94
- authorizeRequestOnChallenge:
95
- coreClient.authorizeRequestOnClaimChallenge
96
- }
97
- })
98
- );
99
- }
89
+ }
90
+ if (
91
+ !options ||
92
+ !options.pipeline ||
93
+ options.pipeline.getOrderedPolicies().length == 0 ||
94
+ !bearerTokenAuthenticationPolicyFound
95
+ ) {
96
+ this.pipeline.removePolicy({
97
+ name: coreRestPipeline.bearerTokenAuthenticationPolicyName
98
+ });
99
+ this.pipeline.addPolicy(
100
+ coreRestPipeline.bearerTokenAuthenticationPolicy({
101
+ credential: credentials,
102
+ scopes:
103
+ optionsWithDefaults.credentialScopes ??
104
+ `${optionsWithDefaults.endpoint}/.default`,
105
+ challengeCallbacks: {
106
+ authorizeRequestOnChallenge:
107
+ coreClient.authorizeRequestOnClaimChallenge
108
+ }
109
+ })
110
+ );
100
111
  }
101
112
  // Parameter assignments
102
113
  this.subscriptionId = subscriptionId;
@@ -108,6 +119,35 @@ export class OperationsManagementClient extends coreClient.ServiceClient {
108
119
  this.managementAssociations = new ManagementAssociationsImpl(this);
109
120
  this.managementConfigurations = new ManagementConfigurationsImpl(this);
110
121
  this.operations = new OperationsImpl(this);
122
+ this.addCustomApiVersionPolicy(options.apiVersion);
123
+ }
124
+
125
+ /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
126
+ private addCustomApiVersionPolicy(apiVersion?: string) {
127
+ if (!apiVersion) {
128
+ return;
129
+ }
130
+ const apiVersionPolicy = {
131
+ name: "CustomApiVersionPolicy",
132
+ async sendRequest(
133
+ request: PipelineRequest,
134
+ next: SendRequest
135
+ ): Promise<PipelineResponse> {
136
+ const param = request.url.split("?");
137
+ if (param.length > 1) {
138
+ const newParams = param[1].split("&").map((item) => {
139
+ if (item.indexOf("api-version") > -1) {
140
+ return "api-version=" + apiVersion;
141
+ } else {
142
+ return item;
143
+ }
144
+ });
145
+ request.url = param[0] + "?" + newParams.join("&");
146
+ }
147
+ return next(request);
148
+ }
149
+ };
150
+ this.pipeline.addPolicy(apiVersionPolicy);
111
151
  }
112
152
 
113
153
  solutions: Solutions;
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * Code generated by Microsoft (R) AutoRest Code Generator.
6
+ * Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
+ */
8
+
9
+ export interface PageInfo {
10
+ continuationToken?: string;
11
+ }
12
+
13
+ const pageMap = new WeakMap<object, PageInfo>();
14
+
15
+ /**
16
+ * Given a result page from a pageable operation, returns a
17
+ * continuation token that can be used to begin paging from
18
+ * that point later.
19
+ * @param page A result object from calling .byPage() on a paged operation.
20
+ * @returns The continuation token that can be passed into byPage().
21
+ */
22
+ export function getContinuationToken(page: unknown): string | undefined {
23
+ if (typeof page !== "object" || page === null) {
24
+ return undefined;
25
+ }
26
+ return pageMap.get(page)?.continuationToken;
27
+ }
28
+
29
+ export function setContinuationToken(
30
+ page: unknown,
31
+ continuationToken: string | undefined
32
+ ): void {
33
+ if (typeof page !== "object" || page === null || !continuationToken) {
34
+ return;
35
+ }
36
+ const pageInfo = pageMap.get(page) ?? {};
37
+ pageInfo.continuationToken = continuationToken;
38
+ pageMap.set(page, pageInfo);
39
+ }
@@ -26,6 +26,15 @@ export declare interface CodeMessageErrorError {
26
26
  message?: string;
27
27
  }
28
28
 
29
+ /**
30
+ * Given a result page from a pageable operation, returns a
31
+ * continuation token that can be used to begin paging from
32
+ * that point later.
33
+ * @param page A result object from calling .byPage() on a paged operation.
34
+ * @returns The continuation token that can be passed into byPage().
35
+ */
36
+ export declare function getContinuationToken(page: unknown): string | undefined;
37
+
29
38
  /** The container for solution. */
30
39
  export declare interface ManagementAssociation {
31
40
  /**
@@ -280,6 +289,8 @@ export declare class OperationsManagementClient extends coreClient.ServiceClient
280
289
  * @param options The parameter options
281
290
  */
282
291
  constructor(credentials: coreAuth.TokenCredential, subscriptionId: string, options?: OperationsManagementClientOptionalParams);
292
+ /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
293
+ private addCustomApiVersionPolicy;
283
294
  solutions: Solutions;
284
295
  managementAssociations: ManagementAssociations;
285
296
  managementConfigurations: ManagementConfigurations;
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.18.11"
8
+ "packageVersion": "7.33.6"
9
9
  }
10
10
  ]
11
11
  }