@azure-rest/developer-devcenter 1.0.0-beta.2 → 1.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.
- package/README.md +11 -10
- package/dist/index.js +96 -150
- package/dist/index.js.map +1 -1
- package/dist-esm/src/{generated/azureDevCenter.js → azureDeveloperDevCenter.js} +13 -10
- package/dist-esm/src/azureDeveloperDevCenter.js.map +1 -0
- package/dist-esm/src/clientDefinitions.js.map +1 -0
- package/dist-esm/src/index.js +11 -11
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/isUnexpected.js +111 -0
- package/dist-esm/src/isUnexpected.js.map +1 -0
- package/dist-esm/src/logger.js +5 -0
- package/dist-esm/src/logger.js.map +1 -0
- package/dist-esm/src/models.js.map +1 -0
- package/dist-esm/src/outputModels.js.map +1 -0
- package/dist-esm/src/{generated/paginateHelper.js → paginateHelper.js} +4 -17
- package/dist-esm/src/paginateHelper.js.map +1 -0
- package/dist-esm/src/parameters.js.map +1 -0
- package/dist-esm/src/{generated/pollingHelper.js → pollingHelper.js} +11 -19
- package/dist-esm/src/pollingHelper.js.map +1 -0
- package/dist-esm/src/responses.js.map +1 -0
- package/package.json +35 -33
- package/review/developer-devcenter.api.md +930 -935
- package/types/developer-devcenter.d.ts +1138 -1177
- package/dist-esm/src/generated/azureDevCenter.js.map +0 -1
- package/dist-esm/src/generated/clientDefinitions.js.map +0 -1
- package/dist-esm/src/generated/index.js +0 -14
- package/dist-esm/src/generated/index.js.map +0 -1
- package/dist-esm/src/generated/isUnexpected.js +0 -155
- package/dist-esm/src/generated/isUnexpected.js.map +0 -1
- package/dist-esm/src/generated/models.js.map +0 -1
- package/dist-esm/src/generated/outputModels.js.map +0 -1
- package/dist-esm/src/generated/paginateHelper.js.map +0 -1
- package/dist-esm/src/generated/parameters.js.map +0 -1
- package/dist-esm/src/generated/pollingHelper.js.map +0 -1
- package/dist-esm/src/generated/responses.js.map +0 -1
- /package/dist-esm/src/{generated/clientDefinitions.js → clientDefinitions.js} +0 -0
- /package/dist-esm/src/{generated/models.js → models.js} +0 -0
- /package/dist-esm/src/{generated/outputModels.js → outputModels.js} +0 -0
- /package/dist-esm/src/{generated/parameters.js → parameters.js} +0 -0
- /package/dist-esm/src/{generated/responses.js → responses.js} +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Azure DevCenter REST client library for JavaScript
|
|
2
|
+
|
|
2
3
|
|
|
3
4
|
The Azure DevCenter library provides access to manage resources for Microsoft Dev Box and Azure Deployment Environments. This package enables managing developer machines and environments in Azure.
|
|
4
5
|
|
|
@@ -6,6 +7,7 @@ Use the package for Azure DevCenter to:
|
|
|
6
7
|
> Create, access, manage, and delete Dev Box resources
|
|
7
8
|
> Create, deploy, manage, and delete Environment resources
|
|
8
9
|
|
|
10
|
+
DevCenter service
|
|
9
11
|
|
|
10
12
|
**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**
|
|
11
13
|
|
|
@@ -13,30 +15,30 @@ Key links:
|
|
|
13
15
|
|
|
14
16
|
- [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/devcenter/developer-devcenter-rest)
|
|
15
17
|
- [Package (NPM)](https://www.npmjs.com/package/@azure-rest/developer-devcenter)
|
|
16
|
-
- [API reference documentation](https://
|
|
18
|
+
- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure-rest/developer-devcenter?view=azure-node-preview)
|
|
17
19
|
- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/devcenter/developer-devcenter-rest/samples)
|
|
18
20
|
|
|
19
21
|
## Getting started
|
|
20
22
|
|
|
21
23
|
### Currently supported environments
|
|
22
24
|
|
|
23
|
-
- Node.js
|
|
25
|
+
- LTS versions of Node.js
|
|
24
26
|
|
|
25
27
|
### Prerequisites
|
|
26
28
|
|
|
27
29
|
- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.
|
|
28
30
|
- You must have [configured](https://learn.microsoft.com/azure/dev-box/quickstart-configure-dev-box-service) a DevCenter, Project, Network Connection, Dev Box Definition, and Pool before you can create Dev Boxes
|
|
29
31
|
- You must have [configured](https://learn.microsoft.com/azure/deployment-environments/) a DevCenter, Project, Catalog, and Environment Type before you can create Environments
|
|
30
|
-
|
|
32
|
+
|
|
31
33
|
### Install the `@azure-rest/developer-devcenter` package
|
|
32
34
|
|
|
33
|
-
Install the
|
|
35
|
+
Install the Azure DevCenter REST client REST client library for JavaScript with `npm`:
|
|
34
36
|
|
|
35
37
|
```bash
|
|
36
38
|
npm install @azure-rest/developer-devcenter
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
### Create and authenticate
|
|
41
|
+
### Create and authenticate a `AzureDeveloperDevCenterClient`
|
|
40
42
|
|
|
41
43
|
To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
|
|
42
44
|
provide an instance of the desired credential type obtained from the
|
|
@@ -48,8 +50,8 @@ After setup, you can choose which type of [credential](https://github.com/Azure/
|
|
|
48
50
|
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
|
|
49
51
|
can be used to authenticate the client.
|
|
50
52
|
|
|
51
|
-
Set the
|
|
52
|
-
|
|
53
|
+
Set the value of dev center endpoint as environment variable:
|
|
54
|
+
DEVCENTER_ENDPOINT
|
|
53
55
|
|
|
54
56
|
## Key Concepts
|
|
55
57
|
|
|
@@ -69,10 +71,9 @@ Environments refer to templated developer environments, which combine a template
|
|
|
69
71
|
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
70
72
|
|
|
71
73
|
```javascript
|
|
72
|
-
|
|
74
|
+
const { setLogLevel } = require("@azure/logger");
|
|
73
75
|
|
|
74
76
|
setLogLevel("info");
|
|
75
77
|
```
|
|
76
78
|
|
|
77
79
|
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
|
|
78
|
-
|
package/dist/index.js
CHANGED
|
@@ -3,28 +3,36 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var coreClient = require('@azure-rest/core-client');
|
|
6
|
+
var logger$1 = require('@azure/logger');
|
|
6
7
|
var corePaging = require('@azure/core-paging');
|
|
7
8
|
var coreLro = require('@azure/core-lro');
|
|
8
9
|
|
|
9
10
|
// Copyright (c) Microsoft Corporation.
|
|
11
|
+
// Licensed under the MIT license.
|
|
12
|
+
const logger = logger$1.createClientLogger("developer-devcenter");
|
|
13
|
+
|
|
14
|
+
// Copyright (c) Microsoft Corporation.
|
|
15
|
+
// Licensed under the MIT license.
|
|
10
16
|
/**
|
|
11
|
-
* Initialize a new instance of
|
|
12
|
-
* @param endpoint
|
|
13
|
-
* @param credentials
|
|
17
|
+
* Initialize a new instance of `AzureDeveloperDevCenterClient`
|
|
18
|
+
* @param endpoint - The DevCenter-specific URI to operate on.
|
|
19
|
+
* @param credentials - uniquely identify client credential
|
|
20
|
+
* @param options - the parameter for all optional parameters
|
|
14
21
|
*/
|
|
15
22
|
function createClient(endpoint, credentials, options = {}) {
|
|
16
|
-
var _a, _b;
|
|
23
|
+
var _a, _b, _c, _d, _e, _f;
|
|
17
24
|
const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${endpoint}`;
|
|
18
|
-
options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "
|
|
19
|
-
options = Object.assign(Object.assign({}, options), { credentials: {
|
|
20
|
-
scopes: ["https://devcenter.azure.com/.default"]
|
|
21
|
-
} });
|
|
25
|
+
options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2023-04-01";
|
|
22
26
|
const userAgentInfo = `azsdk-js-developer-devcenter-rest/1.0.0-beta.3`;
|
|
23
27
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
24
28
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
25
29
|
: `${userAgentInfo}`;
|
|
26
30
|
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
|
27
|
-
userAgentPrefix
|
|
31
|
+
userAgentPrefix,
|
|
32
|
+
}, loggingOptions: {
|
|
33
|
+
logger: (_d = (_c = options.loggingOptions) === null || _c === void 0 ? void 0 : _c.logger) !== null && _d !== void 0 ? _d : logger.info,
|
|
34
|
+
}, credentials: {
|
|
35
|
+
scopes: (_f = (_e = options.credentials) === null || _e === void 0 ? void 0 : _e.scopes) !== null && _f !== void 0 ? _f : ["https://devcenter.azure.com/.default"],
|
|
28
36
|
} });
|
|
29
37
|
const client = coreClient.getClient(baseUrl, credentials, options);
|
|
30
38
|
return client;
|
|
@@ -35,91 +43,46 @@ function createClient(endpoint, credentials, options = {}) {
|
|
|
35
43
|
const responseMap = {
|
|
36
44
|
"GET /projects": ["200"],
|
|
37
45
|
"GET /projects/{projectName}": ["200"],
|
|
38
|
-
"GET /
|
|
39
|
-
"GET /users/{userId}/devboxes": ["200"],
|
|
46
|
+
"GET /projects/{projectName}/operationstatuses/{operationId}": ["200"],
|
|
40
47
|
"GET /projects/{projectName}/pools": ["200"],
|
|
41
48
|
"GET /projects/{projectName}/pools/{poolName}": ["200"],
|
|
42
49
|
"GET /projects/{projectName}/pools/{poolName}/schedules": ["200"],
|
|
43
|
-
"GET /projects/{projectName}/pools/{poolName}/schedules/{scheduleName}": [
|
|
44
|
-
"200"
|
|
45
|
-
],
|
|
50
|
+
"GET /projects/{projectName}/pools/{poolName}/schedules/{scheduleName}": ["200"],
|
|
46
51
|
"GET /projects/{projectName}/users/{userId}/devboxes": ["200"],
|
|
47
52
|
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}": ["200"],
|
|
48
|
-
"PUT /projects/{projectName}/users/{userId}/devboxes/{devBoxName}": [
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
],
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
],
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
],
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
],
|
|
62
|
-
"POST /projects/{projectName}/users/{userId}/devboxes/{devBoxName}:stop": [
|
|
63
|
-
"202"
|
|
64
|
-
],
|
|
65
|
-
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}:stop": [
|
|
66
|
-
"202"
|
|
67
|
-
],
|
|
68
|
-
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/remoteConnection": [
|
|
69
|
-
"200"
|
|
70
|
-
],
|
|
71
|
-
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/upcomingActions": [
|
|
72
|
-
"200"
|
|
73
|
-
],
|
|
74
|
-
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/upcomingActions/{upcomingActionId}": [
|
|
75
|
-
"200"
|
|
76
|
-
],
|
|
77
|
-
"POST /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/upcomingActions/{upcomingActionId}:skip": [
|
|
78
|
-
"204"
|
|
53
|
+
"PUT /projects/{projectName}/users/{userId}/devboxes/{devBoxName}": ["200", "201"],
|
|
54
|
+
"DELETE /projects/{projectName}/users/{userId}/devboxes/{devBoxName}": ["202", "204"],
|
|
55
|
+
"POST /projects/{projectName}/users/{userId}/devboxes/{devBoxName}:start": ["202"],
|
|
56
|
+
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}:start": ["200", "202"],
|
|
57
|
+
"POST /projects/{projectName}/users/{userId}/devboxes/{devBoxName}:stop": ["202"],
|
|
58
|
+
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}:stop": ["200", "202"],
|
|
59
|
+
"POST /projects/{projectName}/users/{userId}/devboxes/{devBoxName}:restart": ["202"],
|
|
60
|
+
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}:restart": ["200", "202"],
|
|
61
|
+
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/remoteConnection": ["200"],
|
|
62
|
+
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/actions": ["200"],
|
|
63
|
+
"GET /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/actions/{actionName}": ["200"],
|
|
64
|
+
"POST /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/actions/{actionName}:skip": [
|
|
65
|
+
"204",
|
|
79
66
|
],
|
|
80
|
-
"POST /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/
|
|
81
|
-
"200"
|
|
67
|
+
"POST /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/actions/{actionName}:delay": [
|
|
68
|
+
"200",
|
|
82
69
|
],
|
|
70
|
+
"POST /projects/{projectName}/users/{userId}/devboxes/{devBoxName}/actions:delay": ["200"],
|
|
71
|
+
"GET /devboxes": ["200"],
|
|
72
|
+
"GET /users/{userId}/devboxes": ["200"],
|
|
83
73
|
"GET /projects/{projectName}/environments": ["200"],
|
|
84
74
|
"GET /projects/{projectName}/users/{userId}/environments": ["200"],
|
|
85
|
-
"GET /projects/{projectName}/users/{userId}/environments/{environmentName}": [
|
|
86
|
-
|
|
87
|
-
],
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
],
|
|
92
|
-
"
|
|
93
|
-
"200"
|
|
94
|
-
],
|
|
95
|
-
"DELETE /projects/{projectName}/users/{userId}/environments/{environmentName}": [
|
|
96
|
-
"200",
|
|
97
|
-
"202",
|
|
98
|
-
"204"
|
|
99
|
-
],
|
|
100
|
-
"POST /projects/{projectName}/users/{userId}/environments/{environmentName}:deploy": [
|
|
101
|
-
"200",
|
|
102
|
-
"202"
|
|
103
|
-
],
|
|
104
|
-
"GET /projects/{projectName}/users/{userId}/environments/{environmentName}:deploy": [
|
|
75
|
+
"GET /projects/{projectName}/users/{userId}/environments/{environmentName}": ["200"],
|
|
76
|
+
"PUT /projects/{projectName}/users/{userId}/environments/{environmentName}": ["201"],
|
|
77
|
+
"DELETE /projects/{projectName}/users/{userId}/environments/{environmentName}": ["202", "204"],
|
|
78
|
+
"GET /projects/{projectName}/catalogs": ["200"],
|
|
79
|
+
"GET /projects/{projectName}/catalogs/{catalogName}": ["200"],
|
|
80
|
+
"GET /projects/{projectName}/environmentDefinitions": ["200"],
|
|
81
|
+
"GET /projects/{projectName}/catalogs/{catalogName}/environmentDefinitions": ["200"],
|
|
82
|
+
"GET /projects/{projectName}/catalogs/{catalogName}/environmentDefinitions/{definitionName}": [
|
|
105
83
|
"200",
|
|
106
|
-
"202"
|
|
107
84
|
],
|
|
108
|
-
"
|
|
109
|
-
"200",
|
|
110
|
-
"202"
|
|
111
|
-
],
|
|
112
|
-
"GET /projects/{projectName}/users/{userId}/environments/{environmentName}:custom": [
|
|
113
|
-
"200",
|
|
114
|
-
"202"
|
|
115
|
-
],
|
|
116
|
-
"GET /projects/{projectName}/catalogItems": ["200"],
|
|
117
|
-
"GET /projects/{projectName}/catalogItems/{catalogItemId}": ["200"],
|
|
118
|
-
"GET /projects/{projectName}/catalogItems/{catalogItemId}/versions": ["200"],
|
|
119
|
-
"GET /projects/{projectName}/catalogItems/{catalogItemId}/versions/{version}": [
|
|
120
|
-
"200"
|
|
121
|
-
],
|
|
122
|
-
"GET /projects/{projectName}/environmentTypes": ["200"]
|
|
85
|
+
"GET /projects/{projectName}/environmentTypes": ["200"],
|
|
123
86
|
};
|
|
124
87
|
function isUnexpected(response) {
|
|
125
88
|
const lroOriginal = response.headers["x-ms-original-url"];
|
|
@@ -127,13 +90,17 @@ function isUnexpected(response) {
|
|
|
127
90
|
const method = response.request.method;
|
|
128
91
|
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
129
92
|
if (!pathDetails) {
|
|
130
|
-
pathDetails =
|
|
93
|
+
pathDetails = getParametrizedPathSuccess(method, url.pathname);
|
|
131
94
|
}
|
|
132
95
|
return !pathDetails.includes(response.status);
|
|
133
96
|
}
|
|
134
|
-
function
|
|
135
|
-
var _a, _b;
|
|
97
|
+
function getParametrizedPathSuccess(method, path) {
|
|
98
|
+
var _a, _b, _c, _d;
|
|
136
99
|
const pathParts = path.split("/");
|
|
100
|
+
// Traverse list to match the longest candidate
|
|
101
|
+
// matchedLen: the length of candidate path
|
|
102
|
+
// matchedValue: the matched status code array
|
|
103
|
+
let matchedLen = -1, matchedValue = [];
|
|
137
104
|
// Iterate the responseMap to find a match
|
|
138
105
|
for (const [key, value] of Object.entries(responseMap)) {
|
|
139
106
|
// Extracting the path from the map key which is in format
|
|
@@ -144,41 +111,38 @@ function geParametrizedPathSuccess(method, path) {
|
|
|
144
111
|
const candidatePath = getPathFromMapKey(key);
|
|
145
112
|
// Get each part of the url path
|
|
146
113
|
const candidateParts = candidatePath.split("/");
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// skip as the parameterized part can match anything
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
// If the candidate part is not a template and
|
|
162
|
-
// the parts don't match mark the candidate as not found
|
|
163
|
-
// to move on with the next candidate path.
|
|
164
|
-
if (candidateParts[i] !== pathParts[i]) {
|
|
114
|
+
// track if we have found a match to return the values found.
|
|
115
|
+
let found = true;
|
|
116
|
+
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
117
|
+
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
|
|
118
|
+
const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
|
|
119
|
+
// If the current part of the candidate is a "template" part
|
|
120
|
+
// Try to use the suffix of pattern to match the path
|
|
121
|
+
// {guid} ==> $
|
|
122
|
+
// {guid}:export ==> :export$
|
|
123
|
+
const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
|
|
124
|
+
if (!isMatched) {
|
|
165
125
|
found = false;
|
|
166
126
|
break;
|
|
167
127
|
}
|
|
128
|
+
continue;
|
|
168
129
|
}
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
// the path
|
|
172
|
-
if (
|
|
173
|
-
|
|
130
|
+
// If the candidate part is not a template and
|
|
131
|
+
// the parts don't match mark the candidate as not found
|
|
132
|
+
// to move on with the next candidate path.
|
|
133
|
+
if (candidateParts[i] !== pathParts[j]) {
|
|
134
|
+
found = false;
|
|
135
|
+
break;
|
|
174
136
|
}
|
|
175
137
|
}
|
|
138
|
+
// We finished evaluating the current candidate parts
|
|
139
|
+
// Update the matched value if and only if we found the longer pattern
|
|
140
|
+
if (found && candidatePath.length > matchedLen) {
|
|
141
|
+
matchedLen = candidatePath.length;
|
|
142
|
+
matchedValue = value;
|
|
143
|
+
}
|
|
176
144
|
}
|
|
177
|
-
|
|
178
|
-
return [];
|
|
179
|
-
}
|
|
180
|
-
function hasParametrizedPath(path) {
|
|
181
|
-
return path.includes("/{");
|
|
145
|
+
return matchedValue;
|
|
182
146
|
}
|
|
183
147
|
function getPathFromMapKey(mapKey) {
|
|
184
148
|
const pathStart = mapKey.indexOf("/");
|
|
@@ -186,6 +150,7 @@ function getPathFromMapKey(mapKey) {
|
|
|
186
150
|
}
|
|
187
151
|
|
|
188
152
|
// Copyright (c) Microsoft Corporation.
|
|
153
|
+
// Licensed under the MIT license.
|
|
189
154
|
/**
|
|
190
155
|
* Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension
|
|
191
156
|
* @param client - Client to use for sending the next page requests
|
|
@@ -203,18 +168,16 @@ function paginate(client, initialResponse, options = {}) {
|
|
|
203
168
|
getPage: typeof customGetPage === "function"
|
|
204
169
|
? customGetPage
|
|
205
170
|
: async (pageLink) => {
|
|
206
|
-
const result = firstRun
|
|
207
|
-
? initialResponse
|
|
208
|
-
: await client.pathUnchecked(pageLink).get();
|
|
171
|
+
const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();
|
|
209
172
|
firstRun = false;
|
|
210
173
|
checkPagingRequest(result);
|
|
211
174
|
const nextLink = getNextLink(result.body, nextLinkName);
|
|
212
175
|
const values = getElements(result.body, itemName);
|
|
213
176
|
return {
|
|
214
177
|
page: values,
|
|
215
|
-
nextPageLink: nextLink
|
|
178
|
+
nextPageLink: nextLink,
|
|
216
179
|
};
|
|
217
|
-
}
|
|
180
|
+
},
|
|
218
181
|
};
|
|
219
182
|
return corePaging.getPagedAsyncIterator(pagedResult);
|
|
220
183
|
}
|
|
@@ -248,32 +211,16 @@ function getElements(body, itemName) {
|
|
|
248
211
|
* Checks if a request failed
|
|
249
212
|
*/
|
|
250
213
|
function checkPagingRequest(response) {
|
|
251
|
-
const Http2xxStatusCodes = [
|
|
252
|
-
"200",
|
|
253
|
-
"201",
|
|
254
|
-
"202",
|
|
255
|
-
"203",
|
|
256
|
-
"204",
|
|
257
|
-
"205",
|
|
258
|
-
"206",
|
|
259
|
-
"207",
|
|
260
|
-
"208",
|
|
261
|
-
"226"
|
|
262
|
-
];
|
|
214
|
+
const Http2xxStatusCodes = ["200", "201", "202", "203", "204", "205", "206", "207", "208", "226"];
|
|
263
215
|
if (!Http2xxStatusCodes.includes(response.status)) {
|
|
264
216
|
throw coreClient.createRestError(`Pagination failed with unexpected statusCode ${response.status}`, response);
|
|
265
217
|
}
|
|
266
218
|
}
|
|
267
219
|
|
|
268
220
|
// Copyright (c) Microsoft Corporation.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
* @param initialResponse - The initial response.
|
|
273
|
-
* @param options - Options to set a resume state or custom polling interval.
|
|
274
|
-
* @returns - A poller object to poll for operation state updates and eventually get the final response.
|
|
275
|
-
*/
|
|
276
|
-
function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
221
|
+
// Licensed under the MIT license.
|
|
222
|
+
async function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
223
|
+
var _a;
|
|
277
224
|
const poller = {
|
|
278
225
|
requestMethod: initialResponse.request.method,
|
|
279
226
|
requestPath: initialResponse.request.url,
|
|
@@ -288,21 +235,19 @@ function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
|
288
235
|
// to get the latest status. We use the client provided and the polling path
|
|
289
236
|
// which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location
|
|
290
237
|
// depending on the lro pattern that the service implements. If non is provided we default to the initial path.
|
|
291
|
-
const response = await client
|
|
292
|
-
.pathUnchecked(path !== null && path !== void 0 ? path : initialResponse.request.url)
|
|
293
|
-
.get();
|
|
238
|
+
const response = await client.pathUnchecked(path !== null && path !== void 0 ? path : initialResponse.request.url).get();
|
|
294
239
|
const lroResponse = getLroResponse(response);
|
|
295
|
-
lroResponse.rawResponse.headers["x-ms-original-url"] =
|
|
296
|
-
initialResponse.request.url;
|
|
240
|
+
lroResponse.rawResponse.headers["x-ms-original-url"] = initialResponse.request.url;
|
|
297
241
|
return lroResponse;
|
|
298
|
-
}
|
|
242
|
+
},
|
|
299
243
|
};
|
|
300
|
-
|
|
244
|
+
options.resolveOnUnsuccessful = (_a = options.resolveOnUnsuccessful) !== null && _a !== void 0 ? _a : true;
|
|
245
|
+
return coreLro.createHttpPoller(poller, options);
|
|
301
246
|
}
|
|
302
247
|
/**
|
|
303
|
-
* Converts a Rest Client response to a response that the LRO
|
|
248
|
+
* Converts a Rest Client response to a response that the LRO implementation understands
|
|
304
249
|
* @param response - a rest client http response
|
|
305
|
-
* @returns - An LRO response that the LRO
|
|
250
|
+
* @returns - An LRO response that the LRO implementation understands
|
|
306
251
|
*/
|
|
307
252
|
function getLroResponse(response) {
|
|
308
253
|
if (Number.isNaN(response.status)) {
|
|
@@ -310,13 +255,14 @@ function getLroResponse(response) {
|
|
|
310
255
|
}
|
|
311
256
|
return {
|
|
312
257
|
flatResponse: response,
|
|
313
|
-
rawResponse: Object.assign(Object.assign({}, response), { statusCode: Number.parseInt(response.status), body: response.body })
|
|
258
|
+
rawResponse: Object.assign(Object.assign({}, response), { statusCode: Number.parseInt(response.status), body: response.body }),
|
|
314
259
|
};
|
|
315
260
|
}
|
|
316
261
|
|
|
317
262
|
// Copyright (c) Microsoft Corporation.
|
|
263
|
+
// Licensed under the MIT license.
|
|
318
264
|
|
|
319
|
-
exports
|
|
265
|
+
exports.default = createClient;
|
|
320
266
|
exports.getLongRunningPoller = getLongRunningPoller;
|
|
321
267
|
exports.isUnexpected = isUnexpected;
|
|
322
268
|
exports.paginate = paginate;
|