@azure/arm-commerce 4.0.0-beta.2 → 4.0.0-beta.3

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 (35) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/README.md +1 -1
  3. package/dist/index.js +106 -14
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/dist-esm/src/index.d.ts +1 -0
  8. package/dist-esm/src/index.d.ts.map +1 -1
  9. package/dist-esm/src/index.js +1 -0
  10. package/dist-esm/src/index.js.map +1 -1
  11. package/dist-esm/src/models/index.d.ts +6 -6
  12. package/dist-esm/src/models/index.d.ts.map +1 -1
  13. package/dist-esm/src/operations/usageAggregates.d.ts.map +1 -1
  14. package/dist-esm/src/operations/usageAggregates.js +19 -7
  15. package/dist-esm/src/operations/usageAggregates.js.map +1 -1
  16. package/dist-esm/src/pagingHelper.d.ts +13 -0
  17. package/dist-esm/src/pagingHelper.d.ts.map +1 -0
  18. package/dist-esm/src/pagingHelper.js +32 -0
  19. package/dist-esm/src/pagingHelper.js.map +1 -0
  20. package/dist-esm/src/usageManagementClient.d.ts +2 -0
  21. package/dist-esm/src/usageManagementClient.d.ts.map +1 -1
  22. package/dist-esm/src/usageManagementClient.js +54 -6
  23. package/dist-esm/src/usageManagementClient.js.map +1 -1
  24. package/dist-esm/test/commerce_examples.d.ts.map +1 -1
  25. package/dist-esm/test/commerce_examples.js +16 -18
  26. package/dist-esm/test/commerce_examples.js.map +1 -1
  27. package/package.json +15 -11
  28. package/review/arm-commerce.api.md +11 -8
  29. package/src/index.ts +1 -0
  30. package/src/models/index.ts +7 -6
  31. package/src/operations/usageAggregates.ts +26 -8
  32. package/src/pagingHelper.ts +39 -0
  33. package/src/usageManagementClient.ts +69 -5
  34. package/types/arm-commerce.d.ts +17 -6
  35. package/types/tsdoc-metadata.json +1 -1
@@ -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
+ }
@@ -7,6 +7,12 @@
7
7
  */
8
8
 
9
9
  import * as coreClient from "@azure/core-client";
10
+ import * as coreRestPipeline from "@azure/core-rest-pipeline";
11
+ import {
12
+ PipelineRequest,
13
+ PipelineResponse,
14
+ SendRequest
15
+ } from "@azure/core-rest-pipeline";
10
16
  import * as coreAuth from "@azure/core-auth";
11
17
  import { UsageAggregatesImpl, RateCardImpl } from "./operations";
12
18
  import { UsageAggregates, RateCard } from "./operationsInterfaces";
@@ -45,25 +51,54 @@ export class UsageManagementClient extends coreClient.ServiceClient {
45
51
  credential: credentials
46
52
  };
47
53
 
48
- const packageDetails = `azsdk-js-arm-commerce/4.0.0-beta.2`;
54
+ const packageDetails = `azsdk-js-arm-commerce/4.0.0-beta.3`;
49
55
  const userAgentPrefix =
50
56
  options.userAgentOptions && options.userAgentOptions.userAgentPrefix
51
57
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
52
58
  : `${packageDetails}`;
53
59
 
54
- if (!options.credentialScopes) {
55
- options.credentialScopes = ["https://management.azure.com/.default"];
56
- }
57
60
  const optionsWithDefaults = {
58
61
  ...defaults,
59
62
  ...options,
60
63
  userAgentOptions: {
61
64
  userAgentPrefix
62
65
  },
63
- baseUri:
66
+ endpoint:
64
67
  options.endpoint ?? options.baseUri ?? "https://management.azure.com"
65
68
  };
66
69
  super(optionsWithDefaults);
70
+
71
+ let bearerTokenAuthenticationPolicyFound: boolean = false;
72
+ if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) {
73
+ const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies();
74
+ bearerTokenAuthenticationPolicyFound = pipelinePolicies.some(
75
+ (pipelinePolicy) =>
76
+ pipelinePolicy.name ===
77
+ coreRestPipeline.bearerTokenAuthenticationPolicyName
78
+ );
79
+ }
80
+ if (
81
+ !options ||
82
+ !options.pipeline ||
83
+ options.pipeline.getOrderedPolicies().length == 0 ||
84
+ !bearerTokenAuthenticationPolicyFound
85
+ ) {
86
+ this.pipeline.removePolicy({
87
+ name: coreRestPipeline.bearerTokenAuthenticationPolicyName
88
+ });
89
+ this.pipeline.addPolicy(
90
+ coreRestPipeline.bearerTokenAuthenticationPolicy({
91
+ credential: credentials,
92
+ scopes:
93
+ optionsWithDefaults.credentialScopes ??
94
+ `${optionsWithDefaults.endpoint}/.default`,
95
+ challengeCallbacks: {
96
+ authorizeRequestOnChallenge:
97
+ coreClient.authorizeRequestOnClaimChallenge
98
+ }
99
+ })
100
+ );
101
+ }
67
102
  // Parameter assignments
68
103
  this.subscriptionId = subscriptionId;
69
104
 
@@ -72,6 +107,35 @@ export class UsageManagementClient extends coreClient.ServiceClient {
72
107
  this.apiVersion = options.apiVersion || "2015-06-01-preview";
73
108
  this.usageAggregates = new UsageAggregatesImpl(this);
74
109
  this.rateCard = new RateCardImpl(this);
110
+ this.addCustomApiVersionPolicy(options.apiVersion);
111
+ }
112
+
113
+ /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
114
+ private addCustomApiVersionPolicy(apiVersion?: string) {
115
+ if (!apiVersion) {
116
+ return;
117
+ }
118
+ const apiVersionPolicy = {
119
+ name: "CustomApiVersionPolicy",
120
+ async sendRequest(
121
+ request: PipelineRequest,
122
+ next: SendRequest
123
+ ): Promise<PipelineResponse> {
124
+ const param = request.url.split("?");
125
+ if (param.length > 1) {
126
+ const newParams = param[1].split("&").map((item) => {
127
+ if (item.indexOf("api-version") > -1) {
128
+ return "api-version=" + apiVersion;
129
+ } else {
130
+ return item;
131
+ }
132
+ });
133
+ request.url = param[0] + "?" + newParams.join("&");
134
+ }
135
+ return next(request);
136
+ }
137
+ };
138
+ this.pipeline.addPolicy(apiVersionPolicy);
75
139
  }
76
140
 
77
141
  usageAggregates: UsageAggregates;
@@ -13,6 +13,15 @@ export declare interface ErrorResponse {
13
13
  message?: string;
14
14
  }
15
15
 
16
+ /**
17
+ * Given a result page from a pageable operation, returns a
18
+ * continuation token that can be used to begin paging from
19
+ * that point later.
20
+ * @param page A result object from calling .byPage() on a paged operation.
21
+ * @returns The continuation token that can be passed into byPage().
22
+ */
23
+ export declare function getContinuationToken(page: unknown): string | undefined;
24
+
16
25
  /** Key-value pairs of instance details in the legacy format. */
17
26
  export declare interface InfoField {
18
27
  /** Identifies the name of the instance provisioned by the user. */
@@ -46,7 +55,7 @@ export declare interface MeterInfo {
46
55
  }
47
56
 
48
57
  /** Indicates that a monetary commitment is required for this offer */
49
- export declare type MonetaryCommitment = OfferTermInfoAutoGenerated & {
58
+ export declare interface MonetaryCommitment extends OfferTermInfoAutoGenerated {
50
59
  /** Polymorphic discriminator, which specifies the different types this object can be */
51
60
  name: "Monetary Commitment";
52
61
  /** The list of key/value pairs for the tiered meter rates, in the format 'key':'value' where key = price, and value = the corresponding discount percentage. This field is used only by offer terms of type 'Monetary Commitment'. */
@@ -55,17 +64,17 @@ export declare type MonetaryCommitment = OfferTermInfoAutoGenerated & {
55
64
  };
56
65
  /** An array of meter ids that are excluded from the given offer terms. */
57
66
  excludedMeterIds?: string[];
58
- };
67
+ }
59
68
 
60
69
  /** Indicates that this is a monetary credit offer. */
61
- export declare type MonetaryCredit = OfferTermInfoAutoGenerated & {
70
+ export declare interface MonetaryCredit extends OfferTermInfoAutoGenerated {
62
71
  /** Polymorphic discriminator, which specifies the different types this object can be */
63
72
  name: "Monetary Credit";
64
73
  /** The amount of credit provided under the terms of the given offer level. */
65
74
  credit?: number;
66
75
  /** An array of meter ids that are excluded from the given offer terms. */
67
76
  excludedMeterIds?: string[];
68
- };
77
+ }
69
78
 
70
79
  /** Defines values for OfferTermInfo. */
71
80
  export declare type OfferTermInfo = "Recurring Charge" | "Monetary Commitment" | "Monetary Credit";
@@ -118,12 +127,12 @@ export declare interface RateCardQueryParameters {
118
127
  }
119
128
 
120
129
  /** Indicates a recurring charge is present for this offer. */
121
- export declare type RecurringCharge = OfferTermInfoAutoGenerated & {
130
+ export declare interface RecurringCharge extends OfferTermInfoAutoGenerated {
122
131
  /** Polymorphic discriminator, which specifies the different types this object can be */
123
132
  name: "Recurring Charge";
124
133
  /** The amount of recurring charge as per the offer term. */
125
134
  recurringCharge?: number;
126
- };
135
+ }
127
136
 
128
137
  /** Price and Metadata information for resources */
129
138
  export declare interface ResourceRateCardInfo {
@@ -230,6 +239,8 @@ export declare class UsageManagementClient extends coreClient.ServiceClient {
230
239
  * @param options The parameter options
231
240
  */
232
241
  constructor(credentials: coreAuth.TokenCredential, subscriptionId: string, options?: UsageManagementClientOptionalParams);
242
+ /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
243
+ private addCustomApiVersionPolicy;
233
244
  usageAggregates: UsageAggregates;
234
245
  rateCard: RateCard;
235
246
  }
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.22.1"
8
+ "packageVersion": "7.33.6"
9
9
  }
10
10
  ]
11
11
  }