@azure/core-lro 3.3.2-alpha.20260227.2 → 3.3.2-alpha.20260305.6
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/dist/browser/index.d.ts +2 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/commonjs/http/models.js +15 -5
- package/dist/commonjs/http/models.js.map +7 -1
- package/dist/commonjs/http/operation.js +244 -222
- package/dist/commonjs/http/operation.js.map +7 -1
- package/dist/commonjs/http/poller.js +73 -48
- package/dist/commonjs/http/poller.js.map +7 -1
- package/dist/commonjs/http/utils.js +55 -44
- package/dist/commonjs/http/utils.js.map +7 -1
- package/dist/commonjs/index.d.ts +2 -2
- package/dist/commonjs/index.js +30 -10
- package/dist/commonjs/index.js.map +7 -1
- package/dist/commonjs/logger.js +28 -12
- package/dist/commonjs/logger.js.map +7 -1
- package/dist/commonjs/poller/constants.js +30 -14
- package/dist/commonjs/poller/constants.js.map +7 -1
- package/dist/commonjs/poller/models.js +15 -5
- package/dist/commonjs/poller/models.js.map +7 -1
- package/dist/commonjs/poller/operation.js +200 -154
- package/dist/commonjs/poller/operation.js.map +7 -1
- package/dist/commonjs/poller/poller.js +202 -181
- package/dist/commonjs/poller/poller.js.map +7 -1
- package/dist/esm/http/models.js +0 -4
- package/dist/esm/http/models.js.map +7 -1
- package/dist/esm/http/operation.js +219 -217
- package/dist/esm/http/operation.js.map +7 -1
- package/dist/esm/http/poller.js +58 -44
- package/dist/esm/http/poller.js.map +7 -1
- package/dist/esm/http/utils.js +32 -41
- package/dist/esm/http/utils.js.map +7 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +6 -5
- package/dist/esm/index.js.map +7 -1
- package/dist/esm/logger.js +4 -8
- package/dist/esm/logger.js.map +7 -1
- package/dist/esm/poller/constants.js +6 -11
- package/dist/esm/poller/constants.js.map +7 -1
- package/dist/esm/poller/models.js +0 -4
- package/dist/esm/poller/models.js.map +7 -1
- package/dist/esm/poller/operation.js +176 -150
- package/dist/esm/poller/operation.js.map +7 -1
- package/dist/esm/poller/poller.js +177 -176
- package/dist/esm/poller/poller.js.map +7 -1
- package/dist/react-native/index.d.ts +2 -2
- package/dist/react-native/index.js.map +1 -1
- package/package.json +4 -21
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createHttpPoller } from "./http/poller.js";
|
|
2
|
-
export { CancelOnProgress, OperationState, OperationStatus, PollerLike, RestorableOperationState, OperationConfig, } from "./poller/models.js";
|
|
3
|
-
export { ResourceLocationConfig, RunningOperation, OperationResponse, RawResponse, RawRequest, CreateHttpPollerOptions, } from "./http/models.js";
|
|
2
|
+
export type { CancelOnProgress, OperationState, OperationStatus, PollerLike, RestorableOperationState, OperationConfig, } from "./poller/models.js";
|
|
3
|
+
export type { ResourceLocationConfig, RunningOperation, OperationResponse, RawResponse, RawRequest, CreateHttpPollerOptions, } from "./http/models.js";
|
|
4
4
|
export { deserializeState } from "./poller/operation.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAiBpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport { createHttpPoller } from \"./http/poller.js\";\nexport {\n CancelOnProgress,\n OperationState,\n OperationStatus,\n PollerLike,\n RestorableOperationState,\n OperationConfig,\n} from \"./poller/models.js\";\nexport {\n ResourceLocationConfig,\n RunningOperation,\n OperationResponse,\n RawResponse,\n RawRequest,\n CreateHttpPollerOptions,\n} from \"./http/models.js\";\nexport { deserializeState } from \"./poller/operation.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAiBpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport { createHttpPoller } from \"./http/poller.js\";\nexport type {\n CancelOnProgress,\n OperationState,\n OperationStatus,\n PollerLike,\n RestorableOperationState,\n OperationConfig,\n} from \"./poller/models.js\";\nexport type {\n ResourceLocationConfig,\n RunningOperation,\n OperationResponse,\n RawResponse,\n RawRequest,\n CreateHttpPollerOptions,\n} from \"./http/models.js\";\nexport { deserializeState } from \"./poller/operation.js\";\n"]}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var models_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(models_exports);
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["/mnt/vss/_work/1/s/sdk/core/core-lro/src/http/models.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { LroError } from \"../poller/models.js\";\n\n/**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\nexport type ResourceLocationConfig =\n | \"azure-async-operation\"\n | \"location\"\n | \"original-uri\"\n | \"operation-location\";\n\n/**\n * The type of a LRO response body. This is just a convenience type for checking the status of the operation.\n */\n\nexport interface ResponseBody extends Record<string, unknown> {\n /** The status of the operation. */\n status?: unknown;\n /** The state of the provisioning process */\n provisioningState?: unknown;\n /** The properties of the provisioning process */\n properties?: { provisioningState?: unknown } & Record<string, unknown>;\n /** The error if the operation failed */\n error?: Partial<LroError>;\n /** The location of the created resource */\n resourceLocation?: string;\n}\n\n/**\n * Simple type of the raw request.\n */\nexport interface RawRequest {\n /** The HTTP request method */\n method: string;\n /** The request path */\n url: string;\n /** The request body */\n body?: unknown;\n}\n\n/**\n * Simple type of the raw response.\n */\nexport interface RawResponse<TRequest extends RawRequest = RawRequest> {\n /** The HTTP status code */\n statusCode: number;\n /** The raw request that was sent to the server */\n request: TRequest;\n /** A HttpHeaders collection in the response represented as a simple JSON object where all header names have been normalized to be lower-case. */\n headers: {\n [headerName: string]: string;\n };\n /** The parsed response body */\n body?: unknown;\n}\n\n/**\n * The type of the response of a LRO.\n */\nexport interface OperationResponse<T = unknown, TRequest extends RawRequest = RawRequest> {\n /** The flattened response */\n flatResponse: T;\n /** The raw response */\n rawResponse: RawResponse<TRequest>;\n}\n\n/**\n * Description of a long running operation.\n */\nexport interface RunningOperation<T = unknown> {\n /**\n * A function that can be used to send initial request to the service.\n */\n sendInitialRequest: () => Promise<OperationResponse<unknown>>;\n /**\n * A function that can be used to poll for the current status of a long running operation.\n */\n sendPollRequest: (\n path: string,\n options?: { abortSignal?: AbortSignalLike },\n ) => Promise<OperationResponse<T>>;\n}\n\nexport type HttpOperationMode = \"OperationLocation\" | \"ResourceLocation\" | \"Body\";\n\n/**\n * Options for `createPoller`.\n */\nexport interface CreateHttpPollerOptions<TResult, TState> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n intervalInMs?: number;\n /**\n * A serialized poller which can be used to resume an existing paused Long-Running-Operation.\n */\n restoreFrom?: string;\n /**\n * The potential location of the result of the LRO if specified by the LRO extension in the swagger.\n */\n resourceLocationConfig?: ResourceLocationConfig;\n /**\n * The base URL to use when making requests.\n */\n baseUrl?: string;\n /**\n * A function to process the result of the LRO.\n */\n processResult?: (result: unknown, state: TState) => Promise<TResult>;\n /**\n * A function to process the state of the LRO.\n */\n updateState?: (state: TState, response: OperationResponse) => void;\n /**\n * A function to be called each time the operation location is updated by the\n * service.\n */\n withOperationLocation?: (operationLocation: string) => void;\n /**\n * Control whether to throw an exception if the operation failed or was canceled.\n */\n resolveOnUnsuccessful?: boolean;\n /**\n * A flag to skip the final GET request that would normally fetch the final resource\n */\n skipFinalGet?: boolean;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,268 +1,290 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var operation_exports = {};
|
|
19
|
+
__export(operation_exports, {
|
|
20
|
+
getErrorFromResponse: () => getErrorFromResponse,
|
|
21
|
+
getOperationLocation: () => getOperationLocation,
|
|
22
|
+
getOperationStatus: () => getOperationStatus,
|
|
23
|
+
getResourceLocation: () => getResourceLocation,
|
|
24
|
+
getStatusFromInitialResponse: () => getStatusFromInitialResponse,
|
|
25
|
+
inferLroMode: () => inferLroMode,
|
|
26
|
+
isOperationError: () => isOperationError,
|
|
27
|
+
parseRetryAfter: () => parseRetryAfter,
|
|
28
|
+
pollHttpOperation: () => pollHttpOperation
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(operation_exports);
|
|
31
|
+
var import_operation = require("../poller/operation.js");
|
|
32
|
+
var import_logger = require("../logger.js");
|
|
16
33
|
function getOperationLocationPollingUrl(inputs) {
|
|
17
|
-
|
|
18
|
-
|
|
34
|
+
const { azureAsyncOperation, operationLocation } = inputs;
|
|
35
|
+
return operationLocation ?? azureAsyncOperation;
|
|
19
36
|
}
|
|
20
37
|
function getLocationHeader(rawResponse) {
|
|
21
|
-
|
|
38
|
+
return rawResponse.headers["location"];
|
|
22
39
|
}
|
|
23
40
|
function getOperationLocationHeader(rawResponse) {
|
|
24
|
-
|
|
41
|
+
return rawResponse.headers["operation-location"];
|
|
25
42
|
}
|
|
26
43
|
function getAzureAsyncOperationHeader(rawResponse) {
|
|
27
|
-
|
|
44
|
+
return rawResponse.headers["azure-asyncoperation"];
|
|
28
45
|
}
|
|
29
46
|
function findResourceLocation(inputs) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
const { location, requestMethod, requestPath, resourceLocationConfig, skipFinalGet } = inputs;
|
|
48
|
+
if (skipFinalGet) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
switch (requestMethod) {
|
|
52
|
+
case "PUT": {
|
|
53
|
+
return requestPath;
|
|
34
54
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return requestPath;
|
|
38
|
-
}
|
|
39
|
-
case "DELETE": {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
case "PATCH": {
|
|
43
|
-
return getDefault() ?? requestPath;
|
|
44
|
-
}
|
|
45
|
-
default: {
|
|
46
|
-
return getDefault();
|
|
47
|
-
}
|
|
55
|
+
case "DELETE": {
|
|
56
|
+
return void 0;
|
|
48
57
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
case "operation-location":
|
|
52
|
-
case "azure-async-operation": {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
case "original-uri": {
|
|
56
|
-
return requestPath;
|
|
57
|
-
}
|
|
58
|
-
case "location":
|
|
59
|
-
default: {
|
|
60
|
-
return location;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
58
|
+
case "PATCH": {
|
|
59
|
+
return getDefault() ?? requestPath;
|
|
63
60
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const requestPath = rawResponse.request.url;
|
|
67
|
-
const requestMethod = rawResponse.request.method;
|
|
68
|
-
const operationLocation = getOperationLocationHeader(rawResponse);
|
|
69
|
-
const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);
|
|
70
|
-
const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });
|
|
71
|
-
const location = getLocationHeader(rawResponse);
|
|
72
|
-
const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();
|
|
73
|
-
if (pollingUrl !== undefined) {
|
|
74
|
-
return {
|
|
75
|
-
mode: "OperationLocation",
|
|
76
|
-
operationLocation: pollingUrl,
|
|
77
|
-
resourceLocation: findResourceLocation({
|
|
78
|
-
requestMethod: normalizedRequestMethod,
|
|
79
|
-
location,
|
|
80
|
-
requestPath,
|
|
81
|
-
resourceLocationConfig,
|
|
82
|
-
skipFinalGet,
|
|
83
|
-
}),
|
|
84
|
-
initialRequestUrl: requestPath,
|
|
85
|
-
requestMethod,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
else if (location !== undefined) {
|
|
89
|
-
return {
|
|
90
|
-
mode: "ResourceLocation",
|
|
91
|
-
operationLocation: location,
|
|
92
|
-
initialRequestUrl: requestPath,
|
|
93
|
-
requestMethod,
|
|
94
|
-
};
|
|
61
|
+
default: {
|
|
62
|
+
return getDefault();
|
|
95
63
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
64
|
+
}
|
|
65
|
+
function getDefault() {
|
|
66
|
+
switch (resourceLocationConfig) {
|
|
67
|
+
case "operation-location":
|
|
68
|
+
case "azure-async-operation": {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
case "original-uri": {
|
|
72
|
+
return requestPath;
|
|
73
|
+
}
|
|
74
|
+
case "location":
|
|
75
|
+
default: {
|
|
76
|
+
return location;
|
|
77
|
+
}
|
|
106
78
|
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function inferLroMode(rawResponse, resourceLocationConfig, skipFinalGet) {
|
|
82
|
+
const requestPath = rawResponse.request.url;
|
|
83
|
+
const requestMethod = rawResponse.request.method;
|
|
84
|
+
const operationLocation = getOperationLocationHeader(rawResponse);
|
|
85
|
+
const azureAsyncOperation = getAzureAsyncOperationHeader(rawResponse);
|
|
86
|
+
const pollingUrl = getOperationLocationPollingUrl({ operationLocation, azureAsyncOperation });
|
|
87
|
+
const location = getLocationHeader(rawResponse);
|
|
88
|
+
const normalizedRequestMethod = requestMethod?.toLocaleUpperCase();
|
|
89
|
+
if (pollingUrl !== void 0) {
|
|
90
|
+
return {
|
|
91
|
+
mode: "OperationLocation",
|
|
92
|
+
operationLocation: pollingUrl,
|
|
93
|
+
resourceLocation: findResourceLocation({
|
|
94
|
+
requestMethod: normalizedRequestMethod,
|
|
95
|
+
location,
|
|
96
|
+
requestPath,
|
|
97
|
+
resourceLocationConfig,
|
|
98
|
+
skipFinalGet
|
|
99
|
+
}),
|
|
100
|
+
initialRequestUrl: requestPath,
|
|
101
|
+
requestMethod
|
|
102
|
+
};
|
|
103
|
+
} else if (location !== void 0) {
|
|
104
|
+
return {
|
|
105
|
+
mode: "ResourceLocation",
|
|
106
|
+
operationLocation: location,
|
|
107
|
+
initialRequestUrl: requestPath,
|
|
108
|
+
requestMethod
|
|
109
|
+
};
|
|
110
|
+
} else if (normalizedRequestMethod === "PUT" && requestPath) {
|
|
111
|
+
return {
|
|
112
|
+
mode: "Body",
|
|
113
|
+
operationLocation: requestPath,
|
|
114
|
+
initialRequestUrl: requestPath,
|
|
115
|
+
requestMethod
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
return void 0;
|
|
119
|
+
}
|
|
107
120
|
}
|
|
108
121
|
function transformStatus(inputs) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return "
|
|
122
|
+
const { status, statusCode } = inputs;
|
|
123
|
+
if (typeof status !== "string" && status !== void 0) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Polling was unsuccessful. Expected status to have a string value or no value but it has instead: ${status}. This doesn't necessarily indicate the operation has failed. Check your Azure subscription or resource status for more information.`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
import_logger.logger.verbose(`LRO: Transforming status: ${status} with status code: ${statusCode}.`);
|
|
129
|
+
const lowerCaseStatus = status?.toLocaleLowerCase();
|
|
130
|
+
if (!lowerCaseStatus) {
|
|
131
|
+
return toOperationStatus(statusCode);
|
|
132
|
+
}
|
|
133
|
+
if (lowerCaseStatus.includes("succeeded")) {
|
|
134
|
+
return "succeeded";
|
|
135
|
+
}
|
|
136
|
+
if (lowerCaseStatus.includes("fail")) {
|
|
137
|
+
return "failed";
|
|
138
|
+
}
|
|
139
|
+
if (["canceled", "cancelled"].includes(lowerCaseStatus)) {
|
|
140
|
+
return "canceled";
|
|
141
|
+
}
|
|
142
|
+
return "running";
|
|
128
143
|
}
|
|
129
144
|
function getStatus(rawResponse) {
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
const { status } = rawResponse.body ?? {};
|
|
146
|
+
return transformStatus({ status, statusCode: rawResponse.statusCode });
|
|
132
147
|
}
|
|
133
148
|
function getProvisioningState(rawResponse) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
149
|
+
const { properties, provisioningState } = rawResponse.body ?? {};
|
|
150
|
+
const status = properties?.provisioningState ?? provisioningState;
|
|
151
|
+
return transformStatus({ status, statusCode: rawResponse.statusCode });
|
|
137
152
|
}
|
|
138
153
|
function toOperationStatus(statusCode) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return "failed";
|
|
147
|
-
}
|
|
154
|
+
if (statusCode === 202) {
|
|
155
|
+
return "running";
|
|
156
|
+
} else if (statusCode < 300) {
|
|
157
|
+
return "succeeded";
|
|
158
|
+
} else {
|
|
159
|
+
return "failed";
|
|
160
|
+
}
|
|
148
161
|
}
|
|
149
162
|
function parseRetryAfter({ rawResponse }) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
: retryAfterInSeconds * 1000;
|
|
157
|
-
}
|
|
158
|
-
return undefined;
|
|
163
|
+
const retryAfter = rawResponse.headers["retry-after"];
|
|
164
|
+
if (retryAfter !== void 0) {
|
|
165
|
+
const retryAfterInSeconds = parseInt(retryAfter);
|
|
166
|
+
return isNaN(retryAfterInSeconds) ? calculatePollingIntervalFromDate(new Date(retryAfter)) : retryAfterInSeconds * 1e3;
|
|
167
|
+
}
|
|
168
|
+
return void 0;
|
|
159
169
|
}
|
|
160
170
|
function getErrorFromResponse(response) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
+
const error = accessBodyProperty(response, "error");
|
|
172
|
+
if (!error) {
|
|
173
|
+
import_logger.logger.warning(
|
|
174
|
+
`The long-running operation failed but there is no error property in the response's body`
|
|
175
|
+
);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (!error.code || !error.message) {
|
|
179
|
+
import_logger.logger.warning(
|
|
180
|
+
`The long-running operation failed but the error property in the response's body doesn't contain code or message`
|
|
181
|
+
);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
return error;
|
|
171
185
|
}
|
|
172
186
|
function calculatePollingIntervalFromDate(retryAfterDate) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
187
|
+
const timeNow = Math.floor((/* @__PURE__ */ new Date()).getTime());
|
|
188
|
+
const retryAfterTime = retryAfterDate.getTime();
|
|
189
|
+
if (timeNow < retryAfterTime) {
|
|
190
|
+
return retryAfterTime - timeNow;
|
|
191
|
+
}
|
|
192
|
+
return void 0;
|
|
179
193
|
}
|
|
180
194
|
function getStatusFromInitialResponse(inputs) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
195
|
+
const { response, state, operationLocation } = inputs;
|
|
196
|
+
function helper() {
|
|
197
|
+
const mode = state.config.metadata?.["mode"];
|
|
198
|
+
switch (mode) {
|
|
199
|
+
case void 0:
|
|
200
|
+
return toOperationStatus(response.rawResponse.statusCode);
|
|
201
|
+
case "Body":
|
|
202
|
+
return getOperationStatus(response, state);
|
|
203
|
+
default:
|
|
204
|
+
return "running";
|
|
192
205
|
}
|
|
193
|
-
|
|
194
|
-
|
|
206
|
+
}
|
|
207
|
+
const status = helper();
|
|
208
|
+
return status === "running" && operationLocation === void 0 ? "succeeded" : status;
|
|
195
209
|
}
|
|
196
210
|
function getOperationLocation({ rawResponse }, state) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
case "Body":
|
|
209
|
-
default: {
|
|
210
|
-
return undefined;
|
|
211
|
-
}
|
|
211
|
+
const mode = state.config.metadata?.["mode"];
|
|
212
|
+
switch (mode) {
|
|
213
|
+
case "OperationLocation": {
|
|
214
|
+
return getOperationLocationPollingUrl({
|
|
215
|
+
operationLocation: getOperationLocationHeader(rawResponse),
|
|
216
|
+
azureAsyncOperation: getAzureAsyncOperationHeader(rawResponse)
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
case "ResourceLocation": {
|
|
220
|
+
return getLocationHeader(rawResponse);
|
|
212
221
|
}
|
|
222
|
+
case "Body":
|
|
223
|
+
default: {
|
|
224
|
+
return void 0;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
213
227
|
}
|
|
214
228
|
function getOperationStatus({ rawResponse }, state) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
case "Body": {
|
|
224
|
-
return getProvisioningState(rawResponse);
|
|
225
|
-
}
|
|
226
|
-
default:
|
|
227
|
-
throw new Error(`Internal error: Unexpected operation mode: ${mode}`);
|
|
229
|
+
const mode = state.config.metadata?.["mode"];
|
|
230
|
+
switch (mode) {
|
|
231
|
+
case "OperationLocation": {
|
|
232
|
+
return getStatus(rawResponse);
|
|
233
|
+
}
|
|
234
|
+
case "ResourceLocation": {
|
|
235
|
+
return toOperationStatus(rawResponse.statusCode);
|
|
228
236
|
}
|
|
237
|
+
case "Body": {
|
|
238
|
+
return getProvisioningState(rawResponse);
|
|
239
|
+
}
|
|
240
|
+
default:
|
|
241
|
+
throw new Error(`Internal error: Unexpected operation mode: ${mode}`);
|
|
242
|
+
}
|
|
229
243
|
}
|
|
230
244
|
function accessBodyProperty({ flatResponse, rawResponse }, prop) {
|
|
231
|
-
|
|
245
|
+
return flatResponse?.[prop] ?? rawResponse.body?.[prop];
|
|
232
246
|
}
|
|
233
247
|
function getResourceLocation(res, state) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
248
|
+
const loc = accessBodyProperty(res, "resourceLocation");
|
|
249
|
+
if (loc && typeof loc === "string") {
|
|
250
|
+
state.config.resourceLocation = loc;
|
|
251
|
+
}
|
|
252
|
+
return state.config.resourceLocation;
|
|
239
253
|
}
|
|
240
254
|
function isOperationError(e) {
|
|
241
|
-
|
|
255
|
+
return e.name === "RestError";
|
|
242
256
|
}
|
|
243
|
-
/** Polls the long-running operation. */
|
|
244
257
|
async function pollHttpOperation(inputs) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
setErrorAsResult,
|
|
266
|
-
});
|
|
258
|
+
const { lro, options, processResult, updateState, setDelay, state, setErrorAsResult } = inputs;
|
|
259
|
+
return (0, import_operation.pollOperation)({
|
|
260
|
+
state,
|
|
261
|
+
setDelay,
|
|
262
|
+
processResult: processResult ? ({ flatResponse }, inputState) => processResult(flatResponse, inputState) : ({ flatResponse }) => flatResponse,
|
|
263
|
+
getError: getErrorFromResponse,
|
|
264
|
+
updateState,
|
|
265
|
+
getPollingInterval: parseRetryAfter,
|
|
266
|
+
getOperationLocation,
|
|
267
|
+
getOperationStatus,
|
|
268
|
+
isOperationError,
|
|
269
|
+
getResourceLocation,
|
|
270
|
+
options,
|
|
271
|
+
/**
|
|
272
|
+
* The expansion here is intentional because `lro` could be an object that
|
|
273
|
+
* references an inner this, so we need to preserve a reference to it.
|
|
274
|
+
*/
|
|
275
|
+
poll: async (location, inputOptions) => lro.sendPollRequest(location, inputOptions),
|
|
276
|
+
setErrorAsResult
|
|
277
|
+
});
|
|
267
278
|
}
|
|
268
|
-
|
|
279
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
280
|
+
0 && (module.exports = {
|
|
281
|
+
getErrorFromResponse,
|
|
282
|
+
getOperationLocation,
|
|
283
|
+
getOperationStatus,
|
|
284
|
+
getResourceLocation,
|
|
285
|
+
getStatusFromInitialResponse,
|
|
286
|
+
inferLroMode,
|
|
287
|
+
isOperationError,
|
|
288
|
+
parseRetryAfter,
|
|
289
|
+
pollHttpOperation
|
|
290
|
+
});
|