@azure/arm-resources-subscriptions 2.0.2-alpha.20221102.1 → 2.0.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 (39) hide show
  1. package/CHANGELOG.md +5 -5
  2. package/dist/index.js +132 -36
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist-esm/src/index.d.ts +1 -0
  7. package/dist-esm/src/index.d.ts.map +1 -1
  8. package/dist-esm/src/index.js +1 -0
  9. package/dist-esm/src/index.js.map +1 -1
  10. package/dist-esm/src/models/index.d.ts +7 -0
  11. package/dist-esm/src/models/index.d.ts.map +1 -1
  12. package/dist-esm/src/models/index.js +7 -0
  13. package/dist-esm/src/models/index.js.map +1 -1
  14. package/dist-esm/src/operations/subscriptions.d.ts.map +1 -1
  15. package/dist-esm/src/operations/subscriptions.js +27 -11
  16. package/dist-esm/src/operations/subscriptions.js.map +1 -1
  17. package/dist-esm/src/operations/tenants.d.ts.map +1 -1
  18. package/dist-esm/src/operations/tenants.js +19 -7
  19. package/dist-esm/src/operations/tenants.js.map +1 -1
  20. package/dist-esm/src/pagingHelper.d.ts +13 -0
  21. package/dist-esm/src/pagingHelper.d.ts.map +1 -0
  22. package/dist-esm/src/pagingHelper.js +32 -0
  23. package/dist-esm/src/pagingHelper.js.map +1 -0
  24. package/dist-esm/src/subscriptionClient.d.ts +2 -0
  25. package/dist-esm/src/subscriptionClient.d.ts.map +1 -1
  26. package/dist-esm/src/subscriptionClient.js +48 -17
  27. package/dist-esm/src/subscriptionClient.js.map +1 -1
  28. package/dist-esm/test/sampleTest.js +11 -13
  29. package/dist-esm/test/sampleTest.js.map +1 -1
  30. package/package.json +13 -9
  31. package/review/arm-resources-subscriptions.api.md +3 -7
  32. package/src/index.ts +1 -0
  33. package/src/models/index.ts +7 -0
  34. package/src/operations/subscriptions.ts +32 -14
  35. package/src/operations/tenants.ts +21 -8
  36. package/src/pagingHelper.ts +39 -0
  37. package/src/subscriptionClient.ts +59 -19
  38. package/tsconfig.json +0 -2
  39. package/types/arm-resources-subscriptions.d.ts +18 -0
package/CHANGELOG.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # Release History
2
2
 
3
- ## 2.0.2 (Unreleased)
3
+ ## 2.0.2 (2022-11-22)
4
4
 
5
- ### Features Added
5
+ **Features**
6
6
 
7
- ### Breaking Changes
7
+ - Exposes `getContinuationToken` helper function to extract continuation token
8
8
 
9
- ### Bugs Fixed
9
+ **Bugs Fixed**
10
10
 
11
- ### Other Changes
11
+ - A series of small bug fixs relevant to authentication and apiVersion policy
12
12
 
13
13
  ## 2.0.1 (2022-04-18)
14
14
 
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var tslib = require('tslib');
5
6
  var coreClient = require('@azure/core-client');
6
7
  var coreRestPipeline = require('@azure/core-rest-pipeline');
7
- var tslib = require('tslib');
8
8
 
9
9
  function _interopNamespace(e) {
10
10
  if (e && e.__esModule) return e;
@@ -27,6 +27,38 @@ function _interopNamespace(e) {
27
27
  var coreClient__namespace = /*#__PURE__*/_interopNamespace(coreClient);
28
28
  var coreRestPipeline__namespace = /*#__PURE__*/_interopNamespace(coreRestPipeline);
29
29
 
30
+ /*
31
+ * Copyright (c) Microsoft Corporation.
32
+ * Licensed under the MIT License.
33
+ *
34
+ * Code generated by Microsoft (R) AutoRest Code Generator.
35
+ * Changes may cause incorrect behavior and will be lost if the code is regenerated.
36
+ */
37
+ const pageMap = new WeakMap();
38
+ /**
39
+ * Given a result page from a pageable operation, returns a
40
+ * continuation token that can be used to begin paging from
41
+ * that point later.
42
+ * @param page A result object from calling .byPage() on a paged operation.
43
+ * @returns The continuation token that can be passed into byPage().
44
+ */
45
+ function getContinuationToken(page) {
46
+ var _a;
47
+ if (typeof page !== "object" || page === null) {
48
+ return undefined;
49
+ }
50
+ return (_a = pageMap.get(page)) === null || _a === void 0 ? void 0 : _a.continuationToken;
51
+ }
52
+ function setContinuationToken(page, continuationToken) {
53
+ var _a;
54
+ if (typeof page !== "object" || page === null || !continuationToken) {
55
+ return;
56
+ }
57
+ const pageInfo = (_a = pageMap.get(page)) !== null && _a !== void 0 ? _a : {};
58
+ pageInfo.continuationToken = continuationToken;
59
+ pageMap.set(page, pageInfo);
60
+ }
61
+
30
62
  /*
31
63
  * Copyright (c) Microsoft Corporation.
32
64
  * Licensed under the MIT License.
@@ -37,20 +69,27 @@ var coreRestPipeline__namespace = /*#__PURE__*/_interopNamespace(coreRestPipelin
37
69
  /** Known values of {@link RegionType} that the service accepts. */
38
70
  exports.KnownRegionType = void 0;
39
71
  (function (KnownRegionType) {
72
+ /** Physical */
40
73
  KnownRegionType["Physical"] = "Physical";
74
+ /** Logical */
41
75
  KnownRegionType["Logical"] = "Logical";
42
76
  })(exports.KnownRegionType || (exports.KnownRegionType = {}));
43
77
  /** Known values of {@link RegionCategory} that the service accepts. */
44
78
  exports.KnownRegionCategory = void 0;
45
79
  (function (KnownRegionCategory) {
80
+ /** Recommended */
46
81
  KnownRegionCategory["Recommended"] = "Recommended";
82
+ /** Extended */
47
83
  KnownRegionCategory["Extended"] = "Extended";
84
+ /** Other */
48
85
  KnownRegionCategory["Other"] = "Other";
49
86
  })(exports.KnownRegionCategory || (exports.KnownRegionCategory = {}));
50
87
  /** Known values of {@link ResourceNameStatus} that the service accepts. */
51
88
  exports.KnownResourceNameStatus = void 0;
52
89
  (function (KnownResourceNameStatus) {
90
+ /** Allowed */
53
91
  KnownResourceNameStatus["Allowed"] = "Allowed";
92
+ /** Reserved */
54
93
  KnownResourceNameStatus["Reserved"] = "Reserved";
55
94
  })(exports.KnownResourceNameStatus || (exports.KnownResourceNameStatus = {}));
56
95
 
@@ -857,14 +896,18 @@ class SubscriptionsImpl {
857
896
  [Symbol.asyncIterator]() {
858
897
  return this;
859
898
  },
860
- byPage: () => {
861
- return this.listLocationsPagingPage(subscriptionId, options);
899
+ byPage: (settings) => {
900
+ if (settings === null || settings === void 0 ? void 0 : settings.maxPageSize) {
901
+ throw new Error("maxPageSize is not supported by this operation.");
902
+ }
903
+ return this.listLocationsPagingPage(subscriptionId, options, settings);
862
904
  }
863
905
  };
864
906
  }
865
- listLocationsPagingPage(subscriptionId, options) {
907
+ listLocationsPagingPage(subscriptionId, options, _settings) {
866
908
  return tslib.__asyncGenerator(this, arguments, function* listLocationsPagingPage_1() {
867
- let result = yield tslib.__await(this._listLocations(subscriptionId, options));
909
+ let result;
910
+ result = yield tslib.__await(this._listLocations(subscriptionId, options));
868
911
  yield yield tslib.__await(result.value || []);
869
912
  });
870
913
  }
@@ -899,20 +942,31 @@ class SubscriptionsImpl {
899
942
  [Symbol.asyncIterator]() {
900
943
  return this;
901
944
  },
902
- byPage: () => {
903
- return this.listPagingPage(options);
945
+ byPage: (settings) => {
946
+ if (settings === null || settings === void 0 ? void 0 : settings.maxPageSize) {
947
+ throw new Error("maxPageSize is not supported by this operation.");
948
+ }
949
+ return this.listPagingPage(options, settings);
904
950
  }
905
951
  };
906
952
  }
907
- listPagingPage(options) {
953
+ listPagingPage(options, settings) {
908
954
  return tslib.__asyncGenerator(this, arguments, function* listPagingPage_1() {
909
- let result = yield tslib.__await(this._list(options));
910
- yield yield tslib.__await(result.value || []);
911
- let continuationToken = result.nextLink;
955
+ let result;
956
+ let continuationToken = settings === null || settings === void 0 ? void 0 : settings.continuationToken;
957
+ if (!continuationToken) {
958
+ result = yield tslib.__await(this._list(options));
959
+ let page = result.value || [];
960
+ continuationToken = result.nextLink;
961
+ setContinuationToken(page, continuationToken);
962
+ yield yield tslib.__await(page);
963
+ }
912
964
  while (continuationToken) {
913
965
  result = yield tslib.__await(this._listNext(continuationToken, options));
914
966
  continuationToken = result.nextLink;
915
- yield yield tslib.__await(result.value || []);
967
+ let page = result.value || [];
968
+ setContinuationToken(page, continuationToken);
969
+ yield yield tslib.__await(page);
916
970
  }
917
971
  });
918
972
  }
@@ -1064,20 +1118,31 @@ class TenantsImpl {
1064
1118
  [Symbol.asyncIterator]() {
1065
1119
  return this;
1066
1120
  },
1067
- byPage: () => {
1068
- return this.listPagingPage(options);
1121
+ byPage: (settings) => {
1122
+ if (settings === null || settings === void 0 ? void 0 : settings.maxPageSize) {
1123
+ throw new Error("maxPageSize is not supported by this operation.");
1124
+ }
1125
+ return this.listPagingPage(options, settings);
1069
1126
  }
1070
1127
  };
1071
1128
  }
1072
- listPagingPage(options) {
1129
+ listPagingPage(options, settings) {
1073
1130
  return tslib.__asyncGenerator(this, arguments, function* listPagingPage_1() {
1074
- let result = yield tslib.__await(this._list(options));
1075
- yield yield tslib.__await(result.value || []);
1076
- let continuationToken = result.nextLink;
1131
+ let result;
1132
+ let continuationToken = settings === null || settings === void 0 ? void 0 : settings.continuationToken;
1133
+ if (!continuationToken) {
1134
+ result = yield tslib.__await(this._list(options));
1135
+ let page = result.value || [];
1136
+ continuationToken = result.nextLink;
1137
+ setContinuationToken(page, continuationToken);
1138
+ yield yield tslib.__await(page);
1139
+ }
1077
1140
  while (continuationToken) {
1078
1141
  result = yield tslib.__await(this._listNext(continuationToken, options));
1079
1142
  continuationToken = result.nextLink;
1080
- yield yield tslib.__await(result.value || []);
1143
+ let page = result.value || [];
1144
+ setContinuationToken(page, continuationToken);
1145
+ yield yield tslib.__await(page);
1081
1146
  }
1082
1147
  });
1083
1148
  }
@@ -1164,7 +1229,7 @@ class SubscriptionClient extends coreClient__namespace.ServiceClient {
1164
1229
  * @param options The parameter options
1165
1230
  */
1166
1231
  constructor(credentials, options) {
1167
- var _a, _b;
1232
+ var _a, _b, _c;
1168
1233
  if (credentials === undefined) {
1169
1234
  throw new Error("'credentials' cannot be null");
1170
1235
  }
@@ -1180,34 +1245,64 @@ class SubscriptionClient extends coreClient__namespace.ServiceClient {
1180
1245
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
1181
1246
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
1182
1247
  : `${packageDetails}`;
1183
- if (!options.credentialScopes) {
1184
- options.credentialScopes = ["https://management.azure.com/.default"];
1185
- }
1186
1248
  const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
1187
1249
  userAgentPrefix
1188
- }, baseUri: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "https://management.azure.com" });
1250
+ }, endpoint: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "https://management.azure.com" });
1189
1251
  super(optionsWithDefaults);
1252
+ let bearerTokenAuthenticationPolicyFound = false;
1190
1253
  if ((options === null || options === void 0 ? void 0 : options.pipeline) && options.pipeline.getOrderedPolicies().length > 0) {
1191
1254
  const pipelinePolicies = options.pipeline.getOrderedPolicies();
1192
- const bearerTokenAuthenticationPolicyFound = pipelinePolicies.some((pipelinePolicy) => pipelinePolicy.name ===
1255
+ bearerTokenAuthenticationPolicyFound = pipelinePolicies.some((pipelinePolicy) => pipelinePolicy.name ===
1193
1256
  coreRestPipeline__namespace.bearerTokenAuthenticationPolicyName);
1194
- if (!bearerTokenAuthenticationPolicyFound) {
1195
- this.pipeline.removePolicy({
1196
- name: coreRestPipeline__namespace.bearerTokenAuthenticationPolicyName
1197
- });
1198
- this.pipeline.addPolicy(coreRestPipeline__namespace.bearerTokenAuthenticationPolicy({
1199
- scopes: `${optionsWithDefaults.baseUri}/.default`,
1200
- challengeCallbacks: {
1201
- authorizeRequestOnChallenge: coreClient__namespace.authorizeRequestOnClaimChallenge
1202
- }
1203
- }));
1204
- }
1257
+ }
1258
+ if (!options ||
1259
+ !options.pipeline ||
1260
+ options.pipeline.getOrderedPolicies().length == 0 ||
1261
+ !bearerTokenAuthenticationPolicyFound) {
1262
+ this.pipeline.removePolicy({
1263
+ name: coreRestPipeline__namespace.bearerTokenAuthenticationPolicyName
1264
+ });
1265
+ this.pipeline.addPolicy(coreRestPipeline__namespace.bearerTokenAuthenticationPolicy({
1266
+ credential: credentials,
1267
+ scopes: (_c = optionsWithDefaults.credentialScopes) !== null && _c !== void 0 ? _c : `${optionsWithDefaults.endpoint}/.default`,
1268
+ challengeCallbacks: {
1269
+ authorizeRequestOnChallenge: coreClient__namespace.authorizeRequestOnClaimChallenge
1270
+ }
1271
+ }));
1205
1272
  }
1206
1273
  // Assigning values to Constant parameters
1207
1274
  this.$host = options.$host || "https://management.azure.com";
1208
1275
  this.apiVersion = options.apiVersion || "2021-01-01";
1209
1276
  this.subscriptions = new SubscriptionsImpl(this);
1210
1277
  this.tenants = new TenantsImpl(this);
1278
+ this.addCustomApiVersionPolicy(options.apiVersion);
1279
+ }
1280
+ /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
1281
+ addCustomApiVersionPolicy(apiVersion) {
1282
+ if (!apiVersion) {
1283
+ return;
1284
+ }
1285
+ const apiVersionPolicy = {
1286
+ name: "CustomApiVersionPolicy",
1287
+ sendRequest(request, next) {
1288
+ return tslib.__awaiter(this, void 0, void 0, function* () {
1289
+ const param = request.url.split("?");
1290
+ if (param.length > 1) {
1291
+ const newParams = param[1].split("&").map((item) => {
1292
+ if (item.indexOf("api-version") > -1) {
1293
+ return "api-version=" + apiVersion;
1294
+ }
1295
+ else {
1296
+ return item;
1297
+ }
1298
+ });
1299
+ request.url = param[0] + "?" + newParams.join("&");
1300
+ }
1301
+ return next(request);
1302
+ });
1303
+ }
1304
+ };
1305
+ this.pipeline.addPolicy(apiVersionPolicy);
1211
1306
  }
1212
1307
  /**
1213
1308
  * A resource name is valid if it is not a reserved word, does not contains a reserved word and does
@@ -1240,4 +1335,5 @@ const checkResourceNameOperationSpec = {
1240
1335
  };
1241
1336
 
1242
1337
  exports.SubscriptionClient = SubscriptionClient;
1338
+ exports.getContinuationToken = getContinuationToken;
1243
1339
  //# sourceMappingURL=index.js.map