@alienplatform/sdk 1.10.7 → 1.11.1
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/.turbo/turbo-build.log +37 -8
- package/dist/bearerTokenAuthenticationPolicy.js +3028 -0
- package/dist/bindings/index.d.ts +1 -0
- package/dist/bindings/index.d.ts.map +1 -1
- package/dist/bindings/postgres.d.ts +90 -0
- package/dist/bindings/postgres.d.ts.map +1 -0
- package/dist/bindings/postgres.test.d.ts +2 -0
- package/dist/bindings/postgres.test.d.ts.map +1 -0
- package/dist/client.js +2376 -0
- package/dist/commands/index.js +1 -1
- package/dist/dist-cjs.js +3 -0
- package/dist/dist-cjs2.js +718 -0
- package/dist/dist-cjs3.js +2486 -0
- package/dist/dist-cjs4.js +171 -0
- package/dist/dist-cjs5.js +429 -0
- package/dist/dist-cjs6.js +60 -0
- package/dist/dist-cjs7.js +978 -0
- package/dist/dist-cjs8.js +86 -0
- package/dist/dist-cjs9.js +319 -0
- package/dist/dist.js +498 -36
- package/dist/dist2.js +1239 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/es5.js +1624 -0
- package/dist/esm.js +18211 -0
- package/dist/esm2.js +3104 -0
- package/dist/event-streams.js +203 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +336 -24996
- package/dist/jws.js +611 -0
- package/dist/open.js +460 -0
- package/dist/package.js +4 -0
- package/dist/protocols.js +954 -0
- package/dist/protocols2.js +5565 -0
- package/dist/rolldown-runtime.js +37 -0
- package/dist/serde.js +5542 -0
- package/dist/signin.js +723 -0
- package/dist/src.js +24900 -0
- package/dist/src2.js +114030 -0
- package/dist/sso-oidc.js +940 -0
- package/dist/sts.js +1329 -0
- package/dist/tslib.es6.js +543 -0
- package/package.json +26 -2
- package/src/bindings/index.ts +1 -0
- package/src/bindings/postgres.test.ts +17 -0
- package/src/bindings/postgres.ts +446 -0
- package/src/errors.ts +21 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,3028 @@
|
|
|
1
|
+
import { i as __require, t as __commonJSMin } from "./rolldown-runtime.js";
|
|
2
|
+
import { n as require_dist$1, r as require_src, t as require_dist$2 } from "./dist2.js";
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
import { Transform } from "node:stream";
|
|
5
|
+
import os, { EOL } from "node:os";
|
|
6
|
+
import process$1 from "node:process";
|
|
7
|
+
import https from "node:https";
|
|
8
|
+
import util, { inspect } from "node:util";
|
|
9
|
+
import http from "node:http";
|
|
10
|
+
import zlib from "node:zlib";
|
|
11
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/logger/log.js
|
|
12
|
+
function log(message, ...args) {
|
|
13
|
+
process$1.stderr.write(`${util.format(message, ...args)}${EOL}`);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/logger/debug.js
|
|
17
|
+
const debugEnvVariable = typeof process !== "undefined" && process.env && process.env.DEBUG || void 0;
|
|
18
|
+
let enabledString;
|
|
19
|
+
let enabledNamespaces = [];
|
|
20
|
+
let skippedNamespaces = [];
|
|
21
|
+
const debuggers = [];
|
|
22
|
+
if (debugEnvVariable) enable(debugEnvVariable);
|
|
23
|
+
const debugObj = Object.assign((namespace) => {
|
|
24
|
+
return createDebugger(namespace);
|
|
25
|
+
}, {
|
|
26
|
+
enable,
|
|
27
|
+
enabled,
|
|
28
|
+
disable,
|
|
29
|
+
log
|
|
30
|
+
});
|
|
31
|
+
function enable(namespaces) {
|
|
32
|
+
enabledString = namespaces;
|
|
33
|
+
enabledNamespaces = [];
|
|
34
|
+
skippedNamespaces = [];
|
|
35
|
+
const namespaceList = namespaces.split(",").map((ns) => ns.trim());
|
|
36
|
+
for (const ns of namespaceList) if (ns.startsWith("-")) skippedNamespaces.push(ns.substring(1));
|
|
37
|
+
else enabledNamespaces.push(ns);
|
|
38
|
+
for (const instance of debuggers) instance.enabled = enabled(instance.namespace);
|
|
39
|
+
}
|
|
40
|
+
function enabled(namespace) {
|
|
41
|
+
if (namespace.endsWith("*")) return true;
|
|
42
|
+
for (const skipped of skippedNamespaces) if (namespaceMatches(namespace, skipped)) return false;
|
|
43
|
+
for (const enabledNamespace of enabledNamespaces) if (namespaceMatches(namespace, enabledNamespace)) return true;
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Given a namespace, check if it matches a pattern.
|
|
48
|
+
* Patterns only have a single wildcard character which is *.
|
|
49
|
+
* The behavior of * is that it matches zero or more other characters.
|
|
50
|
+
*/
|
|
51
|
+
function namespaceMatches(namespace, patternToMatch) {
|
|
52
|
+
if (patternToMatch.indexOf("*") === -1) return namespace === patternToMatch;
|
|
53
|
+
let pattern = patternToMatch;
|
|
54
|
+
if (patternToMatch.indexOf("**") !== -1) {
|
|
55
|
+
const patternParts = [];
|
|
56
|
+
let lastCharacter = "";
|
|
57
|
+
for (const character of patternToMatch) if (character === "*" && lastCharacter === "*") continue;
|
|
58
|
+
else {
|
|
59
|
+
lastCharacter = character;
|
|
60
|
+
patternParts.push(character);
|
|
61
|
+
}
|
|
62
|
+
pattern = patternParts.join("");
|
|
63
|
+
}
|
|
64
|
+
let namespaceIndex = 0;
|
|
65
|
+
let patternIndex = 0;
|
|
66
|
+
const patternLength = pattern.length;
|
|
67
|
+
const namespaceLength = namespace.length;
|
|
68
|
+
let lastWildcard = -1;
|
|
69
|
+
let lastWildcardNamespace = -1;
|
|
70
|
+
while (namespaceIndex < namespaceLength && patternIndex < patternLength) if (pattern[patternIndex] === "*") {
|
|
71
|
+
lastWildcard = patternIndex;
|
|
72
|
+
patternIndex++;
|
|
73
|
+
if (patternIndex === patternLength) return true;
|
|
74
|
+
while (namespace[namespaceIndex] !== pattern[patternIndex]) {
|
|
75
|
+
namespaceIndex++;
|
|
76
|
+
if (namespaceIndex === namespaceLength) return false;
|
|
77
|
+
}
|
|
78
|
+
lastWildcardNamespace = namespaceIndex;
|
|
79
|
+
namespaceIndex++;
|
|
80
|
+
patternIndex++;
|
|
81
|
+
continue;
|
|
82
|
+
} else if (pattern[patternIndex] === namespace[namespaceIndex]) {
|
|
83
|
+
patternIndex++;
|
|
84
|
+
namespaceIndex++;
|
|
85
|
+
} else if (lastWildcard >= 0) {
|
|
86
|
+
patternIndex = lastWildcard + 1;
|
|
87
|
+
namespaceIndex = lastWildcardNamespace + 1;
|
|
88
|
+
if (namespaceIndex === namespaceLength) return false;
|
|
89
|
+
while (namespace[namespaceIndex] !== pattern[patternIndex]) {
|
|
90
|
+
namespaceIndex++;
|
|
91
|
+
if (namespaceIndex === namespaceLength) return false;
|
|
92
|
+
}
|
|
93
|
+
lastWildcardNamespace = namespaceIndex;
|
|
94
|
+
namespaceIndex++;
|
|
95
|
+
patternIndex++;
|
|
96
|
+
continue;
|
|
97
|
+
} else return false;
|
|
98
|
+
const namespaceDone = namespaceIndex === namespace.length;
|
|
99
|
+
const patternDone = patternIndex === pattern.length;
|
|
100
|
+
const trailingWildCard = patternIndex === pattern.length - 1 && pattern[patternIndex] === "*";
|
|
101
|
+
return namespaceDone && (patternDone || trailingWildCard);
|
|
102
|
+
}
|
|
103
|
+
function disable() {
|
|
104
|
+
const result = enabledString || "";
|
|
105
|
+
enable("");
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
function createDebugger(namespace) {
|
|
109
|
+
const newDebugger = Object.assign(debug, {
|
|
110
|
+
enabled: enabled(namespace),
|
|
111
|
+
destroy,
|
|
112
|
+
log: debugObj.log,
|
|
113
|
+
namespace,
|
|
114
|
+
extend
|
|
115
|
+
});
|
|
116
|
+
function debug(...args) {
|
|
117
|
+
if (!newDebugger.enabled) return;
|
|
118
|
+
if (args.length > 0) args[0] = `${namespace} ${args[0]}`;
|
|
119
|
+
newDebugger.log(...args);
|
|
120
|
+
}
|
|
121
|
+
debuggers.push(newDebugger);
|
|
122
|
+
return newDebugger;
|
|
123
|
+
}
|
|
124
|
+
function destroy() {
|
|
125
|
+
const index = debuggers.indexOf(this);
|
|
126
|
+
if (index >= 0) {
|
|
127
|
+
debuggers.splice(index, 1);
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
function extend(namespace) {
|
|
133
|
+
const newDebugger = createDebugger(`${this.namespace}:${namespace}`);
|
|
134
|
+
newDebugger.log = this.log;
|
|
135
|
+
return newDebugger;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/logger/logger.js
|
|
139
|
+
const TYPESPEC_RUNTIME_LOG_LEVELS = [
|
|
140
|
+
"verbose",
|
|
141
|
+
"info",
|
|
142
|
+
"warning",
|
|
143
|
+
"error"
|
|
144
|
+
];
|
|
145
|
+
const levelMap = {
|
|
146
|
+
verbose: 400,
|
|
147
|
+
info: 300,
|
|
148
|
+
warning: 200,
|
|
149
|
+
error: 100
|
|
150
|
+
};
|
|
151
|
+
function patchLogMethod(parent, child) {
|
|
152
|
+
child.log = (...args) => {
|
|
153
|
+
parent.log(...args);
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function isTypeSpecRuntimeLogLevel(level) {
|
|
157
|
+
return TYPESPEC_RUNTIME_LOG_LEVELS.includes(level);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Creates a logger context base on the provided options.
|
|
161
|
+
* @param options - The options for creating a logger context.
|
|
162
|
+
* @returns The logger context.
|
|
163
|
+
*/
|
|
164
|
+
function createLoggerContext(options) {
|
|
165
|
+
const registeredLoggers = /* @__PURE__ */ new Set();
|
|
166
|
+
const logLevelFromEnv = typeof process !== "undefined" && process.env && process.env[options.logLevelEnvVarName] || void 0;
|
|
167
|
+
let logLevel;
|
|
168
|
+
const clientLogger = debugObj(options.namespace);
|
|
169
|
+
clientLogger.log = (...args) => {
|
|
170
|
+
debugObj.log(...args);
|
|
171
|
+
};
|
|
172
|
+
function contextSetLogLevel(level) {
|
|
173
|
+
if (level && !isTypeSpecRuntimeLogLevel(level)) throw new Error(`Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(",")}`);
|
|
174
|
+
logLevel = level;
|
|
175
|
+
const enabledNamespaces = [];
|
|
176
|
+
for (const logger of registeredLoggers) if (shouldEnable(logger)) enabledNamespaces.push(logger.namespace);
|
|
177
|
+
debugObj.enable(enabledNamespaces.join(","));
|
|
178
|
+
}
|
|
179
|
+
if (logLevelFromEnv) if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) contextSetLogLevel(logLevelFromEnv);
|
|
180
|
+
else console.error(`${options.logLevelEnvVarName} set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(", ")}.`);
|
|
181
|
+
function shouldEnable(logger) {
|
|
182
|
+
return Boolean(logLevel && levelMap[logger.level] <= levelMap[logLevel]);
|
|
183
|
+
}
|
|
184
|
+
function createLogger(parent, level) {
|
|
185
|
+
const logger = Object.assign(parent.extend(level), { level });
|
|
186
|
+
patchLogMethod(parent, logger);
|
|
187
|
+
if (shouldEnable(logger)) {
|
|
188
|
+
const enabledNamespaces = debugObj.disable();
|
|
189
|
+
debugObj.enable(enabledNamespaces + "," + logger.namespace);
|
|
190
|
+
}
|
|
191
|
+
registeredLoggers.add(logger);
|
|
192
|
+
return logger;
|
|
193
|
+
}
|
|
194
|
+
function contextGetLogLevel() {
|
|
195
|
+
return logLevel;
|
|
196
|
+
}
|
|
197
|
+
function contextCreateClientLogger(namespace) {
|
|
198
|
+
const clientRootLogger = clientLogger.extend(namespace);
|
|
199
|
+
patchLogMethod(clientLogger, clientRootLogger);
|
|
200
|
+
return {
|
|
201
|
+
error: createLogger(clientRootLogger, "error"),
|
|
202
|
+
warning: createLogger(clientRootLogger, "warning"),
|
|
203
|
+
info: createLogger(clientRootLogger, "info"),
|
|
204
|
+
verbose: createLogger(clientRootLogger, "verbose")
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
setLogLevel: contextSetLogLevel,
|
|
209
|
+
getLogLevel: contextGetLogLevel,
|
|
210
|
+
createClientLogger: contextCreateClientLogger,
|
|
211
|
+
logger: clientLogger
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const context$1 = createLoggerContext({
|
|
215
|
+
logLevelEnvVarName: "TYPESPEC_RUNTIME_LOG_LEVEL",
|
|
216
|
+
namespace: "typeSpecRuntime"
|
|
217
|
+
});
|
|
218
|
+
context$1.logger;
|
|
219
|
+
/**
|
|
220
|
+
* Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
|
|
221
|
+
* @param namespace - The name of the SDK package.
|
|
222
|
+
* @hidden
|
|
223
|
+
*/
|
|
224
|
+
function createClientLogger$1(namespace) {
|
|
225
|
+
return context$1.createClientLogger(namespace);
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region ../../node_modules/.pnpm/@azure+logger@1.3.0/node_modules/@azure/logger/dist/esm/index.js
|
|
229
|
+
const context = createLoggerContext({
|
|
230
|
+
logLevelEnvVarName: "AZURE_LOG_LEVEL",
|
|
231
|
+
namespace: "azure"
|
|
232
|
+
});
|
|
233
|
+
context.logger;
|
|
234
|
+
/**
|
|
235
|
+
* Retrieves the currently specified log level.
|
|
236
|
+
*/
|
|
237
|
+
function getLogLevel() {
|
|
238
|
+
return context.getLogLevel();
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Creates a logger for use by the Azure SDKs that inherits from `AzureLogger`.
|
|
242
|
+
* @param namespace - The name of the SDK package.
|
|
243
|
+
* @hidden
|
|
244
|
+
*/
|
|
245
|
+
function createClientLogger(namespace) {
|
|
246
|
+
return context.createClientLogger(namespace);
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region ../../node_modules/.pnpm/@azure+core-tracing@1.3.1/node_modules/@azure/core-tracing/dist/esm/tracingContext.js
|
|
250
|
+
/** @internal */
|
|
251
|
+
const knownContextKeys = {
|
|
252
|
+
span: Symbol.for("@azure/core-tracing span"),
|
|
253
|
+
namespace: Symbol.for("@azure/core-tracing namespace")
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Creates a new {@link TracingContext} with the given options.
|
|
257
|
+
* @param options - A set of known keys that may be set on the context.
|
|
258
|
+
* @returns A new {@link TracingContext} with the given options.
|
|
259
|
+
*
|
|
260
|
+
* @internal
|
|
261
|
+
*/
|
|
262
|
+
function createTracingContext(options = {}) {
|
|
263
|
+
let context = new TracingContextImpl(options.parentContext);
|
|
264
|
+
if (options.span) context = context.setValue(knownContextKeys.span, options.span);
|
|
265
|
+
if (options.namespace) context = context.setValue(knownContextKeys.namespace, options.namespace);
|
|
266
|
+
return context;
|
|
267
|
+
}
|
|
268
|
+
/** @internal */
|
|
269
|
+
var TracingContextImpl = class TracingContextImpl {
|
|
270
|
+
_contextMap;
|
|
271
|
+
constructor(initialContext) {
|
|
272
|
+
this._contextMap = initialContext instanceof TracingContextImpl ? new Map(initialContext._contextMap) : /* @__PURE__ */ new Map();
|
|
273
|
+
}
|
|
274
|
+
setValue(key, value) {
|
|
275
|
+
const newContext = new TracingContextImpl(this);
|
|
276
|
+
newContext._contextMap.set(key, value);
|
|
277
|
+
return newContext;
|
|
278
|
+
}
|
|
279
|
+
getValue(key) {
|
|
280
|
+
return this._contextMap.get(key);
|
|
281
|
+
}
|
|
282
|
+
deleteValue(key) {
|
|
283
|
+
const newContext = new TracingContextImpl(this);
|
|
284
|
+
newContext._contextMap.delete(key);
|
|
285
|
+
return newContext;
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Defines the shared state between CJS and ESM by re-exporting the CJS state.
|
|
290
|
+
*/
|
|
291
|
+
const state = (/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
292
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
293
|
+
exports.state = void 0;
|
|
294
|
+
/**
|
|
295
|
+
* @internal
|
|
296
|
+
*
|
|
297
|
+
* Holds the singleton instrumenter, to be shared across CJS and ESM imports.
|
|
298
|
+
*/
|
|
299
|
+
exports.state = { instrumenterImplementation: void 0 };
|
|
300
|
+
})))().state;
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region ../../node_modules/.pnpm/@azure+core-tracing@1.3.1/node_modules/@azure/core-tracing/dist/esm/instrumenter.js
|
|
303
|
+
function createDefaultTracingSpan() {
|
|
304
|
+
return {
|
|
305
|
+
end: () => {},
|
|
306
|
+
isRecording: () => false,
|
|
307
|
+
recordException: () => {},
|
|
308
|
+
setAttribute: () => {},
|
|
309
|
+
setStatus: () => {},
|
|
310
|
+
addEvent: () => {}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function createDefaultInstrumenter() {
|
|
314
|
+
return {
|
|
315
|
+
createRequestHeaders: () => {
|
|
316
|
+
return {};
|
|
317
|
+
},
|
|
318
|
+
parseTraceparentHeader: () => {},
|
|
319
|
+
startSpan: (_name, spanOptions) => {
|
|
320
|
+
return {
|
|
321
|
+
span: createDefaultTracingSpan(),
|
|
322
|
+
tracingContext: createTracingContext({ parentContext: spanOptions.tracingContext })
|
|
323
|
+
};
|
|
324
|
+
},
|
|
325
|
+
withContext(_context, callback, ...callbackArgs) {
|
|
326
|
+
return callback(...callbackArgs);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Gets the currently set instrumenter, a No-Op instrumenter by default.
|
|
332
|
+
*
|
|
333
|
+
* @returns The currently set instrumenter
|
|
334
|
+
*/
|
|
335
|
+
function getInstrumenter() {
|
|
336
|
+
if (!state.instrumenterImplementation) state.instrumenterImplementation = createDefaultInstrumenter();
|
|
337
|
+
return state.instrumenterImplementation;
|
|
338
|
+
}
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region ../../node_modules/.pnpm/@azure+core-tracing@1.3.1/node_modules/@azure/core-tracing/dist/esm/tracingClient.js
|
|
341
|
+
/**
|
|
342
|
+
* Creates a new tracing client.
|
|
343
|
+
*
|
|
344
|
+
* @param options - Options used to configure the tracing client.
|
|
345
|
+
* @returns - An instance of {@link TracingClient}.
|
|
346
|
+
*/
|
|
347
|
+
function createTracingClient(options) {
|
|
348
|
+
const { namespace, packageName, packageVersion } = options;
|
|
349
|
+
function startSpan(name, operationOptions, spanOptions) {
|
|
350
|
+
const startSpanResult = getInstrumenter().startSpan(name, {
|
|
351
|
+
...spanOptions,
|
|
352
|
+
packageName,
|
|
353
|
+
packageVersion,
|
|
354
|
+
tracingContext: operationOptions?.tracingOptions?.tracingContext
|
|
355
|
+
});
|
|
356
|
+
let tracingContext = startSpanResult.tracingContext;
|
|
357
|
+
const span = startSpanResult.span;
|
|
358
|
+
if (!tracingContext.getValue(knownContextKeys.namespace)) tracingContext = tracingContext.setValue(knownContextKeys.namespace, namespace);
|
|
359
|
+
span.setAttribute("az.namespace", tracingContext.getValue(knownContextKeys.namespace));
|
|
360
|
+
return {
|
|
361
|
+
span,
|
|
362
|
+
updatedOptions: Object.assign({}, operationOptions, { tracingOptions: {
|
|
363
|
+
...operationOptions?.tracingOptions,
|
|
364
|
+
tracingContext
|
|
365
|
+
} })
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
async function withSpan(name, operationOptions, callback, spanOptions) {
|
|
369
|
+
const { span, updatedOptions } = startSpan(name, operationOptions, spanOptions);
|
|
370
|
+
try {
|
|
371
|
+
const result = await withContext(updatedOptions.tracingOptions.tracingContext, () => Promise.resolve(callback(updatedOptions, span)));
|
|
372
|
+
span.setStatus({ status: "success" });
|
|
373
|
+
return result;
|
|
374
|
+
} catch (err) {
|
|
375
|
+
span.setStatus({
|
|
376
|
+
status: "error",
|
|
377
|
+
error: err
|
|
378
|
+
});
|
|
379
|
+
throw err;
|
|
380
|
+
} finally {
|
|
381
|
+
span.end();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function withContext(context, callback, ...callbackArgs) {
|
|
385
|
+
return getInstrumenter().withContext(context, callback, ...callbackArgs);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Parses a traceparent header value into a span identifier.
|
|
389
|
+
*
|
|
390
|
+
* @param traceparentHeader - The traceparent header to parse.
|
|
391
|
+
* @returns An implementation-specific identifier for the span.
|
|
392
|
+
*/
|
|
393
|
+
function parseTraceparentHeader(traceparentHeader) {
|
|
394
|
+
return getInstrumenter().parseTraceparentHeader(traceparentHeader);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Creates a set of request headers to propagate tracing information to a backend.
|
|
398
|
+
*
|
|
399
|
+
* @param tracingContext - The context containing the span to serialize.
|
|
400
|
+
* @returns The set of headers to add to a request.
|
|
401
|
+
*/
|
|
402
|
+
function createRequestHeaders(tracingContext) {
|
|
403
|
+
return getInstrumenter().createRequestHeaders(tracingContext);
|
|
404
|
+
}
|
|
405
|
+
return {
|
|
406
|
+
startSpan,
|
|
407
|
+
withSpan,
|
|
408
|
+
withContext,
|
|
409
|
+
parseTraceparentHeader,
|
|
410
|
+
createRequestHeaders
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/random.js
|
|
415
|
+
/**
|
|
416
|
+
* Returns a random integer value between a lower and upper bound,
|
|
417
|
+
* inclusive of both bounds.
|
|
418
|
+
* Note that this uses Math.random and isn't secure. If you need to use
|
|
419
|
+
* this for any kind of security purpose, find a better source of random.
|
|
420
|
+
* @param min - The smallest integer value allowed.
|
|
421
|
+
* @param max - The largest integer value allowed.
|
|
422
|
+
*/
|
|
423
|
+
function getRandomIntegerInclusive(min, max) {
|
|
424
|
+
min = Math.ceil(min);
|
|
425
|
+
max = Math.floor(max);
|
|
426
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
427
|
+
}
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/delay.js
|
|
430
|
+
/**
|
|
431
|
+
* Calculates the delay interval for retry attempts using exponential delay with jitter.
|
|
432
|
+
* @param retryAttempt - The current retry attempt number.
|
|
433
|
+
* @param config - The exponential retry configuration.
|
|
434
|
+
* @returns An object containing the calculated retry delay.
|
|
435
|
+
*/
|
|
436
|
+
function calculateRetryDelay$1(retryAttempt, config) {
|
|
437
|
+
const exponentialDelay = config.retryDelayInMs * Math.pow(2, retryAttempt);
|
|
438
|
+
const clampedDelay = Math.min(config.maxRetryDelayInMs, exponentialDelay);
|
|
439
|
+
return { retryAfterInMs: clampedDelay / 2 + getRandomIntegerInclusive(0, clampedDelay / 2) };
|
|
440
|
+
}
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/object.js
|
|
443
|
+
/**
|
|
444
|
+
* Helper to determine when an input is a generic JS object.
|
|
445
|
+
* @returns true when input is an object type that is not null, Array, RegExp, or Date.
|
|
446
|
+
*/
|
|
447
|
+
function isObject(input) {
|
|
448
|
+
return typeof input === "object" && input !== null && !Array.isArray(input) && !(input instanceof RegExp) && !(input instanceof Date);
|
|
449
|
+
}
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/error.js
|
|
452
|
+
/**
|
|
453
|
+
* Typeguard for an error object shape (has name and message)
|
|
454
|
+
* @param e - Something caught by a catch clause.
|
|
455
|
+
*/
|
|
456
|
+
function isError$1(e) {
|
|
457
|
+
if (isObject(e)) {
|
|
458
|
+
const hasName = typeof e.name === "string";
|
|
459
|
+
const hasMessage = typeof e.message === "string";
|
|
460
|
+
return hasName && hasMessage;
|
|
461
|
+
}
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/uuidUtils.js
|
|
466
|
+
/**
|
|
467
|
+
* Generated Universally Unique Identifier
|
|
468
|
+
*
|
|
469
|
+
* @returns RFC4122 v4 UUID.
|
|
470
|
+
*/
|
|
471
|
+
function randomUUID() {
|
|
472
|
+
return crypto.randomUUID();
|
|
473
|
+
}
|
|
474
|
+
typeof window !== "undefined" && window.document;
|
|
475
|
+
typeof self === "object" && typeof self?.importScripts === "function" && (self.constructor?.name === "DedicatedWorkerGlobalScope" || self.constructor?.name === "ServiceWorkerGlobalScope" || self.constructor?.name);
|
|
476
|
+
typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && Deno.version.deno;
|
|
477
|
+
typeof Bun !== "undefined" && Bun.version;
|
|
478
|
+
/**
|
|
479
|
+
* A constant that indicates whether the environment the code is running is a Node.js compatible environment.
|
|
480
|
+
*/
|
|
481
|
+
const isNodeLike$1 = typeof globalThis.process !== "undefined" && Boolean(globalThis.process.version) && Boolean(globalThis.process.versions?.node);
|
|
482
|
+
typeof navigator !== "undefined" && navigator?.product;
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/bytesEncoding.js
|
|
485
|
+
/**
|
|
486
|
+
* The helper that transforms bytes with specific character encoding into string
|
|
487
|
+
* @param bytes - the uint8array bytes
|
|
488
|
+
* @param format - the format we use to encode the byte
|
|
489
|
+
* @returns a string of the encoded string
|
|
490
|
+
*/
|
|
491
|
+
function uint8ArrayToString$1(bytes, format) {
|
|
492
|
+
return Buffer.from(bytes).toString(format);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* The helper that transforms string to specific character encoded bytes array.
|
|
496
|
+
* @param value - the string to be converted
|
|
497
|
+
* @param format - the format we use to decode the value
|
|
498
|
+
* @returns a uint8array
|
|
499
|
+
*/
|
|
500
|
+
function stringToUint8Array$1(value, format) {
|
|
501
|
+
return Buffer.from(value, format);
|
|
502
|
+
}
|
|
503
|
+
//#endregion
|
|
504
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/sanitizer.js
|
|
505
|
+
const RedactedString = "REDACTED";
|
|
506
|
+
const defaultAllowedHeaderNames = [
|
|
507
|
+
"x-ms-client-request-id",
|
|
508
|
+
"x-ms-return-client-request-id",
|
|
509
|
+
"x-ms-useragent",
|
|
510
|
+
"x-ms-correlation-request-id",
|
|
511
|
+
"x-ms-request-id",
|
|
512
|
+
"client-request-id",
|
|
513
|
+
"ms-cv",
|
|
514
|
+
"return-client-request-id",
|
|
515
|
+
"traceparent",
|
|
516
|
+
"Access-Control-Allow-Credentials",
|
|
517
|
+
"Access-Control-Allow-Headers",
|
|
518
|
+
"Access-Control-Allow-Methods",
|
|
519
|
+
"Access-Control-Allow-Origin",
|
|
520
|
+
"Access-Control-Expose-Headers",
|
|
521
|
+
"Access-Control-Max-Age",
|
|
522
|
+
"Access-Control-Request-Headers",
|
|
523
|
+
"Access-Control-Request-Method",
|
|
524
|
+
"Origin",
|
|
525
|
+
"Accept",
|
|
526
|
+
"Accept-Encoding",
|
|
527
|
+
"Cache-Control",
|
|
528
|
+
"Connection",
|
|
529
|
+
"Content-Length",
|
|
530
|
+
"Content-Type",
|
|
531
|
+
"Date",
|
|
532
|
+
"ETag",
|
|
533
|
+
"Expires",
|
|
534
|
+
"If-Match",
|
|
535
|
+
"If-Modified-Since",
|
|
536
|
+
"If-None-Match",
|
|
537
|
+
"If-Unmodified-Since",
|
|
538
|
+
"Last-Modified",
|
|
539
|
+
"Pragma",
|
|
540
|
+
"Request-Id",
|
|
541
|
+
"Retry-After",
|
|
542
|
+
"Server",
|
|
543
|
+
"Transfer-Encoding",
|
|
544
|
+
"User-Agent",
|
|
545
|
+
"WWW-Authenticate"
|
|
546
|
+
];
|
|
547
|
+
const defaultAllowedQueryParameters = ["api-version"];
|
|
548
|
+
/**
|
|
549
|
+
* A utility class to sanitize objects for logging.
|
|
550
|
+
*/
|
|
551
|
+
var Sanitizer = class {
|
|
552
|
+
allowedHeaderNames;
|
|
553
|
+
allowedQueryParameters;
|
|
554
|
+
constructor({ additionalAllowedHeaderNames: allowedHeaderNames = [], additionalAllowedQueryParameters: allowedQueryParameters = [] } = {}) {
|
|
555
|
+
allowedHeaderNames = defaultAllowedHeaderNames.concat(allowedHeaderNames);
|
|
556
|
+
allowedQueryParameters = defaultAllowedQueryParameters.concat(allowedQueryParameters);
|
|
557
|
+
this.allowedHeaderNames = new Set(allowedHeaderNames.map((n) => n.toLowerCase()));
|
|
558
|
+
this.allowedQueryParameters = new Set(allowedQueryParameters.map((p) => p.toLowerCase()));
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Sanitizes an object for logging.
|
|
562
|
+
* @param obj - The object to sanitize
|
|
563
|
+
* @returns - The sanitized object as a string
|
|
564
|
+
*/
|
|
565
|
+
sanitize(obj) {
|
|
566
|
+
const seen = /* @__PURE__ */ new Set();
|
|
567
|
+
return JSON.stringify(obj, (key, value) => {
|
|
568
|
+
if (value instanceof Error) return {
|
|
569
|
+
...value,
|
|
570
|
+
name: value.name,
|
|
571
|
+
message: value.message
|
|
572
|
+
};
|
|
573
|
+
if (key === "headers") return this.sanitizeHeaders(value);
|
|
574
|
+
else if (key === "url") return this.sanitizeUrl(value);
|
|
575
|
+
else if (key === "query") return this.sanitizeQuery(value);
|
|
576
|
+
else if (key === "body") return;
|
|
577
|
+
else if (key === "response") return;
|
|
578
|
+
else if (key === "operationSpec") return;
|
|
579
|
+
else if (Array.isArray(value) || isObject(value)) {
|
|
580
|
+
if (seen.has(value)) return "[Circular]";
|
|
581
|
+
seen.add(value);
|
|
582
|
+
}
|
|
583
|
+
return value;
|
|
584
|
+
}, 2);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Sanitizes a URL for logging.
|
|
588
|
+
* @param value - The URL to sanitize
|
|
589
|
+
* @returns - The sanitized URL as a string
|
|
590
|
+
*/
|
|
591
|
+
sanitizeUrl(value) {
|
|
592
|
+
if (typeof value !== "string" || value === null || value === "") return value;
|
|
593
|
+
const url = new URL(value);
|
|
594
|
+
if (!url.search) return value;
|
|
595
|
+
for (const [key] of url.searchParams) if (!this.allowedQueryParameters.has(key.toLowerCase())) url.searchParams.set(key, RedactedString);
|
|
596
|
+
return url.toString();
|
|
597
|
+
}
|
|
598
|
+
sanitizeHeaders(obj) {
|
|
599
|
+
const sanitized = {};
|
|
600
|
+
for (const key of Object.keys(obj)) if (this.allowedHeaderNames.has(key.toLowerCase())) sanitized[key] = obj[key];
|
|
601
|
+
else sanitized[key] = RedactedString;
|
|
602
|
+
return sanitized;
|
|
603
|
+
}
|
|
604
|
+
sanitizeQuery(value) {
|
|
605
|
+
if (typeof value !== "object" || value === null) return value;
|
|
606
|
+
const sanitized = {};
|
|
607
|
+
for (const k of Object.keys(value)) if (this.allowedQueryParameters.has(k.toLowerCase())) sanitized[k] = value[k];
|
|
608
|
+
else sanitized[k] = RedactedString;
|
|
609
|
+
return sanitized;
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region ../../node_modules/.pnpm/@azure+abort-controller@2.1.2/node_modules/@azure/abort-controller/dist/esm/AbortError.js
|
|
614
|
+
/**
|
|
615
|
+
* This error is thrown when an asynchronous operation has been aborted.
|
|
616
|
+
* Check for this error by testing the `name` that the name property of the
|
|
617
|
+
* error matches `"AbortError"`.
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```ts
|
|
621
|
+
* const controller = new AbortController();
|
|
622
|
+
* controller.abort();
|
|
623
|
+
* try {
|
|
624
|
+
* doAsyncWork(controller.signal)
|
|
625
|
+
* } catch (e) {
|
|
626
|
+
* if (e.name === 'AbortError') {
|
|
627
|
+
* // handle abort error here.
|
|
628
|
+
* }
|
|
629
|
+
* }
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
var AbortError$1 = class extends Error {
|
|
633
|
+
constructor(message) {
|
|
634
|
+
super(message);
|
|
635
|
+
this.name = "AbortError";
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
//#endregion
|
|
639
|
+
//#region ../../node_modules/.pnpm/@azure+core-util@1.13.1/node_modules/@azure/core-util/dist/esm/createAbortablePromise.js
|
|
640
|
+
/**
|
|
641
|
+
* Creates an abortable promise.
|
|
642
|
+
* @param buildPromise - A function that takes the resolve and reject functions as parameters.
|
|
643
|
+
* @param options - The options for the abortable promise.
|
|
644
|
+
* @returns A promise that can be aborted.
|
|
645
|
+
*/
|
|
646
|
+
function createAbortablePromise(buildPromise, options) {
|
|
647
|
+
const { cleanupBeforeAbort, abortSignal, abortErrorMsg } = options ?? {};
|
|
648
|
+
return new Promise((resolve, reject) => {
|
|
649
|
+
function rejectOnAbort() {
|
|
650
|
+
reject(new AbortError$1(abortErrorMsg ?? "The operation was aborted."));
|
|
651
|
+
}
|
|
652
|
+
function removeListeners() {
|
|
653
|
+
abortSignal?.removeEventListener("abort", onAbort);
|
|
654
|
+
}
|
|
655
|
+
function onAbort() {
|
|
656
|
+
cleanupBeforeAbort?.();
|
|
657
|
+
removeListeners();
|
|
658
|
+
rejectOnAbort();
|
|
659
|
+
}
|
|
660
|
+
if (abortSignal?.aborted) return rejectOnAbort();
|
|
661
|
+
try {
|
|
662
|
+
buildPromise((x) => {
|
|
663
|
+
removeListeners();
|
|
664
|
+
resolve(x);
|
|
665
|
+
}, (x) => {
|
|
666
|
+
removeListeners();
|
|
667
|
+
reject(x);
|
|
668
|
+
});
|
|
669
|
+
} catch (err) {
|
|
670
|
+
reject(err);
|
|
671
|
+
}
|
|
672
|
+
abortSignal?.addEventListener("abort", onAbort);
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region ../../node_modules/.pnpm/@azure+core-util@1.13.1/node_modules/@azure/core-util/dist/esm/delay.js
|
|
677
|
+
const StandardAbortMessage$1 = "The delay was aborted.";
|
|
678
|
+
/**
|
|
679
|
+
* A wrapper for setTimeout that resolves a promise after timeInMs milliseconds.
|
|
680
|
+
* @param timeInMs - The number of milliseconds to be delayed.
|
|
681
|
+
* @param options - The options for delay - currently abort options
|
|
682
|
+
* @returns Promise that is resolved after timeInMs
|
|
683
|
+
*/
|
|
684
|
+
function delay$1(timeInMs, options) {
|
|
685
|
+
let token;
|
|
686
|
+
const { abortSignal, abortErrorMsg } = options ?? {};
|
|
687
|
+
return createAbortablePromise((resolve) => {
|
|
688
|
+
token = setTimeout(resolve, timeInMs);
|
|
689
|
+
}, {
|
|
690
|
+
cleanupBeforeAbort: () => clearTimeout(token),
|
|
691
|
+
abortSignal,
|
|
692
|
+
abortErrorMsg: abortErrorMsg ?? StandardAbortMessage$1
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
//#endregion
|
|
696
|
+
//#region ../../node_modules/.pnpm/@azure+core-util@1.13.1/node_modules/@azure/core-util/dist/esm/error.js
|
|
697
|
+
/**
|
|
698
|
+
* Given what is thought to be an error object, return the message if possible.
|
|
699
|
+
* If the message is missing, returns a stringified version of the input.
|
|
700
|
+
* @param e - Something thrown from a try block
|
|
701
|
+
* @returns The error message or a string of the input
|
|
702
|
+
*/
|
|
703
|
+
function getErrorMessage(e) {
|
|
704
|
+
if (isError$1(e)) return e.message;
|
|
705
|
+
else {
|
|
706
|
+
let stringified;
|
|
707
|
+
try {
|
|
708
|
+
if (typeof e === "object" && e) stringified = JSON.stringify(e);
|
|
709
|
+
else stringified = String(e);
|
|
710
|
+
} catch (err) {
|
|
711
|
+
stringified = "[unable to stringify input]";
|
|
712
|
+
}
|
|
713
|
+
return `Unknown error ${stringified}`;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
//#endregion
|
|
717
|
+
//#region ../../node_modules/.pnpm/@azure+core-util@1.13.1/node_modules/@azure/core-util/dist/esm/typeGuards.js
|
|
718
|
+
/**
|
|
719
|
+
* Helper TypeGuard that checks if something is defined or not.
|
|
720
|
+
* @param thing - Anything
|
|
721
|
+
*/
|
|
722
|
+
function isDefined(thing) {
|
|
723
|
+
return typeof thing !== "undefined" && thing !== null;
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Helper TypeGuard that checks if the input is an object with the specified properties.
|
|
727
|
+
* @param thing - Anything.
|
|
728
|
+
* @param properties - The name of the properties that should appear in the object.
|
|
729
|
+
*/
|
|
730
|
+
function isObjectWithProperties(thing, properties) {
|
|
731
|
+
if (!isDefined(thing) || typeof thing !== "object") return false;
|
|
732
|
+
for (const property of properties) if (!objectHasProperty(thing, property)) return false;
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Helper TypeGuard that checks if the input is an object with the specified property.
|
|
737
|
+
* @param thing - Any object.
|
|
738
|
+
* @param property - The name of the property that should appear in the object.
|
|
739
|
+
*/
|
|
740
|
+
function objectHasProperty(thing, property) {
|
|
741
|
+
return isDefined(thing) && typeof thing === "object" && property in thing;
|
|
742
|
+
}
|
|
743
|
+
//#endregion
|
|
744
|
+
//#region ../../node_modules/.pnpm/@azure+core-util@1.13.1/node_modules/@azure/core-util/dist/esm/index.js
|
|
745
|
+
/**
|
|
746
|
+
* Calculates the delay interval for retry attempts using exponential delay with jitter.
|
|
747
|
+
*
|
|
748
|
+
* @param retryAttempt - The current retry attempt number.
|
|
749
|
+
*
|
|
750
|
+
* @param config - The exponential retry configuration.
|
|
751
|
+
*
|
|
752
|
+
* @returns An object containing the calculated retry delay.
|
|
753
|
+
*/
|
|
754
|
+
function calculateRetryDelay(retryAttempt, config) {
|
|
755
|
+
return calculateRetryDelay$1(retryAttempt, config);
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Typeguard for an error object shape (has name and message)
|
|
759
|
+
*
|
|
760
|
+
* @param e - Something caught by a catch clause.
|
|
761
|
+
*/
|
|
762
|
+
function isError(e) {
|
|
763
|
+
return isError$1(e);
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* A constant that indicates whether the environment the code is running is a Node.js compatible environment.
|
|
767
|
+
*
|
|
768
|
+
* @deprecated
|
|
769
|
+
*
|
|
770
|
+
* Use `isNodeLike` instead.
|
|
771
|
+
*/
|
|
772
|
+
const isNode = isNodeLike$1;
|
|
773
|
+
/**
|
|
774
|
+
* A constant that indicates whether the environment the code is running is a Node.js compatible environment.
|
|
775
|
+
*/
|
|
776
|
+
const isNodeLike = isNodeLike$1;
|
|
777
|
+
/**
|
|
778
|
+
* The helper that transforms bytes with specific character encoding into string
|
|
779
|
+
* @param bytes - the uint8array bytes
|
|
780
|
+
* @param format - the format we use to encode the byte
|
|
781
|
+
* @returns a string of the encoded string
|
|
782
|
+
*/
|
|
783
|
+
function uint8ArrayToString(bytes, format) {
|
|
784
|
+
return uint8ArrayToString$1(bytes, format);
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* The helper that transforms string to specific character encoded bytes array.
|
|
788
|
+
* @param value - the string to be converted
|
|
789
|
+
* @param format - the format we use to decode the value
|
|
790
|
+
* @returns a uint8array
|
|
791
|
+
*/
|
|
792
|
+
function stringToUint8Array(value, format) {
|
|
793
|
+
return stringToUint8Array$1(value, format);
|
|
794
|
+
}
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/httpHeaders.js
|
|
797
|
+
function normalizeName(name) {
|
|
798
|
+
return name.toLowerCase();
|
|
799
|
+
}
|
|
800
|
+
function* headerIterator(map) {
|
|
801
|
+
for (const entry of map.values()) yield [entry.name, entry.value];
|
|
802
|
+
}
|
|
803
|
+
var HttpHeadersImpl = class {
|
|
804
|
+
_headersMap;
|
|
805
|
+
constructor(rawHeaders) {
|
|
806
|
+
this._headersMap = /* @__PURE__ */ new Map();
|
|
807
|
+
if (rawHeaders) for (const headerName of Object.keys(rawHeaders)) this.set(headerName, rawHeaders[headerName]);
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Set a header in this collection with the provided name and value. The name is
|
|
811
|
+
* case-insensitive.
|
|
812
|
+
* @param name - The name of the header to set. This value is case-insensitive.
|
|
813
|
+
* @param value - The value of the header to set.
|
|
814
|
+
*/
|
|
815
|
+
set(name, value) {
|
|
816
|
+
this._headersMap.set(normalizeName(name), {
|
|
817
|
+
name,
|
|
818
|
+
value: String(value).trim()
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Get the header value for the provided header name, or undefined if no header exists in this
|
|
823
|
+
* collection with the provided name.
|
|
824
|
+
* @param name - The name of the header. This value is case-insensitive.
|
|
825
|
+
*/
|
|
826
|
+
get(name) {
|
|
827
|
+
return this._headersMap.get(normalizeName(name))?.value;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Get whether or not this header collection contains a header entry for the provided header name.
|
|
831
|
+
* @param name - The name of the header to set. This value is case-insensitive.
|
|
832
|
+
*/
|
|
833
|
+
has(name) {
|
|
834
|
+
return this._headersMap.has(normalizeName(name));
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Remove the header with the provided headerName.
|
|
838
|
+
* @param name - The name of the header to remove.
|
|
839
|
+
*/
|
|
840
|
+
delete(name) {
|
|
841
|
+
this._headersMap.delete(normalizeName(name));
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Get the JSON object representation of this HTTP header collection.
|
|
845
|
+
*/
|
|
846
|
+
toJSON(options = {}) {
|
|
847
|
+
const result = {};
|
|
848
|
+
if (options.preserveCase) for (const entry of this._headersMap.values()) result[entry.name] = entry.value;
|
|
849
|
+
else for (const [normalizedName, entry] of this._headersMap) result[normalizedName] = entry.value;
|
|
850
|
+
return result;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Get the string representation of this HTTP header collection.
|
|
854
|
+
*/
|
|
855
|
+
toString() {
|
|
856
|
+
return JSON.stringify(this.toJSON({ preserveCase: true }));
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Iterate over tuples of header [name, value] pairs.
|
|
860
|
+
*/
|
|
861
|
+
[Symbol.iterator]() {
|
|
862
|
+
return headerIterator(this._headersMap);
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
/**
|
|
866
|
+
* Creates an object that satisfies the `HttpHeaders` interface.
|
|
867
|
+
* @param rawHeaders - A simple object representing initial headers
|
|
868
|
+
*/
|
|
869
|
+
function createHttpHeaders(rawHeaders) {
|
|
870
|
+
return new HttpHeadersImpl(rawHeaders);
|
|
871
|
+
}
|
|
872
|
+
//#endregion
|
|
873
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/pipelineRequest.js
|
|
874
|
+
var PipelineRequestImpl = class {
|
|
875
|
+
url;
|
|
876
|
+
method;
|
|
877
|
+
headers;
|
|
878
|
+
timeout;
|
|
879
|
+
withCredentials;
|
|
880
|
+
body;
|
|
881
|
+
multipartBody;
|
|
882
|
+
formData;
|
|
883
|
+
streamResponseStatusCodes;
|
|
884
|
+
enableBrowserStreams;
|
|
885
|
+
proxySettings;
|
|
886
|
+
disableKeepAlive;
|
|
887
|
+
abortSignal;
|
|
888
|
+
requestId;
|
|
889
|
+
allowInsecureConnection;
|
|
890
|
+
onUploadProgress;
|
|
891
|
+
onDownloadProgress;
|
|
892
|
+
requestOverrides;
|
|
893
|
+
authSchemes;
|
|
894
|
+
constructor(options) {
|
|
895
|
+
this.url = options.url;
|
|
896
|
+
this.body = options.body;
|
|
897
|
+
this.headers = options.headers ?? createHttpHeaders();
|
|
898
|
+
this.method = options.method ?? "GET";
|
|
899
|
+
this.timeout = options.timeout ?? 0;
|
|
900
|
+
this.multipartBody = options.multipartBody;
|
|
901
|
+
this.formData = options.formData;
|
|
902
|
+
this.disableKeepAlive = options.disableKeepAlive ?? false;
|
|
903
|
+
this.proxySettings = options.proxySettings;
|
|
904
|
+
this.streamResponseStatusCodes = options.streamResponseStatusCodes;
|
|
905
|
+
this.withCredentials = options.withCredentials ?? false;
|
|
906
|
+
this.abortSignal = options.abortSignal;
|
|
907
|
+
this.onUploadProgress = options.onUploadProgress;
|
|
908
|
+
this.onDownloadProgress = options.onDownloadProgress;
|
|
909
|
+
this.requestId = options.requestId || randomUUID();
|
|
910
|
+
this.allowInsecureConnection = options.allowInsecureConnection ?? false;
|
|
911
|
+
this.enableBrowserStreams = options.enableBrowserStreams ?? false;
|
|
912
|
+
this.requestOverrides = options.requestOverrides;
|
|
913
|
+
this.authSchemes = options.authSchemes;
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
/**
|
|
917
|
+
* Creates a new pipeline request with the given options.
|
|
918
|
+
* This method is to allow for the easy setting of default values and not required.
|
|
919
|
+
* @param options - The options to create the request with.
|
|
920
|
+
*/
|
|
921
|
+
function createPipelineRequest(options) {
|
|
922
|
+
return new PipelineRequestImpl(options);
|
|
923
|
+
}
|
|
924
|
+
//#endregion
|
|
925
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/pipeline.js
|
|
926
|
+
const ValidPhaseNames = new Set([
|
|
927
|
+
"Deserialize",
|
|
928
|
+
"Serialize",
|
|
929
|
+
"Retry",
|
|
930
|
+
"Sign"
|
|
931
|
+
]);
|
|
932
|
+
/**
|
|
933
|
+
* A private implementation of Pipeline.
|
|
934
|
+
* Do not export this class from the package.
|
|
935
|
+
* @internal
|
|
936
|
+
*/
|
|
937
|
+
var HttpPipeline = class HttpPipeline {
|
|
938
|
+
_policies = [];
|
|
939
|
+
_orderedPolicies;
|
|
940
|
+
constructor(policies) {
|
|
941
|
+
this._policies = policies?.slice(0) ?? [];
|
|
942
|
+
this._orderedPolicies = void 0;
|
|
943
|
+
}
|
|
944
|
+
addPolicy(policy, options = {}) {
|
|
945
|
+
if (options.phase && options.afterPhase) throw new Error("Policies inside a phase cannot specify afterPhase.");
|
|
946
|
+
if (options.phase && !ValidPhaseNames.has(options.phase)) throw new Error(`Invalid phase name: ${options.phase}`);
|
|
947
|
+
if (options.afterPhase && !ValidPhaseNames.has(options.afterPhase)) throw new Error(`Invalid afterPhase name: ${options.afterPhase}`);
|
|
948
|
+
this._policies.push({
|
|
949
|
+
policy,
|
|
950
|
+
options
|
|
951
|
+
});
|
|
952
|
+
this._orderedPolicies = void 0;
|
|
953
|
+
}
|
|
954
|
+
removePolicy(options) {
|
|
955
|
+
const removedPolicies = [];
|
|
956
|
+
this._policies = this._policies.filter((policyDescriptor) => {
|
|
957
|
+
if (options.name && policyDescriptor.policy.name === options.name || options.phase && policyDescriptor.options.phase === options.phase) {
|
|
958
|
+
removedPolicies.push(policyDescriptor.policy);
|
|
959
|
+
return false;
|
|
960
|
+
} else return true;
|
|
961
|
+
});
|
|
962
|
+
this._orderedPolicies = void 0;
|
|
963
|
+
return removedPolicies;
|
|
964
|
+
}
|
|
965
|
+
sendRequest(httpClient, request) {
|
|
966
|
+
return this.getOrderedPolicies().reduceRight((next, policy) => {
|
|
967
|
+
return (req) => {
|
|
968
|
+
return policy.sendRequest(req, next);
|
|
969
|
+
};
|
|
970
|
+
}, (req) => httpClient.sendRequest(req))(request);
|
|
971
|
+
}
|
|
972
|
+
getOrderedPolicies() {
|
|
973
|
+
if (!this._orderedPolicies) this._orderedPolicies = this.orderPolicies();
|
|
974
|
+
return this._orderedPolicies;
|
|
975
|
+
}
|
|
976
|
+
clone() {
|
|
977
|
+
return new HttpPipeline(this._policies);
|
|
978
|
+
}
|
|
979
|
+
static create() {
|
|
980
|
+
return new HttpPipeline();
|
|
981
|
+
}
|
|
982
|
+
orderPolicies() {
|
|
983
|
+
/**
|
|
984
|
+
* The goal of this method is to reliably order pipeline policies
|
|
985
|
+
* based on their declared requirements when they were added.
|
|
986
|
+
*
|
|
987
|
+
* Order is first determined by phase:
|
|
988
|
+
*
|
|
989
|
+
* 1. Serialize Phase
|
|
990
|
+
* 2. Policies not in a phase
|
|
991
|
+
* 3. Deserialize Phase
|
|
992
|
+
* 4. Retry Phase
|
|
993
|
+
* 5. Sign Phase
|
|
994
|
+
*
|
|
995
|
+
* Within each phase, policies are executed in the order
|
|
996
|
+
* they were added unless they were specified to execute
|
|
997
|
+
* before/after other policies or after a particular phase.
|
|
998
|
+
*
|
|
999
|
+
* To determine the final order, we will walk the policy list
|
|
1000
|
+
* in phase order multiple times until all dependencies are
|
|
1001
|
+
* satisfied.
|
|
1002
|
+
*
|
|
1003
|
+
* `afterPolicies` are the set of policies that must be
|
|
1004
|
+
* executed before a given policy. This requirement is
|
|
1005
|
+
* considered satisfied when each of the listed policies
|
|
1006
|
+
* have been scheduled.
|
|
1007
|
+
*
|
|
1008
|
+
* `beforePolicies` are the set of policies that must be
|
|
1009
|
+
* executed after a given policy. Since this dependency
|
|
1010
|
+
* can be expressed by converting it into a equivalent
|
|
1011
|
+
* `afterPolicies` declarations, they are normalized
|
|
1012
|
+
* into that form for simplicity.
|
|
1013
|
+
*
|
|
1014
|
+
* An `afterPhase` dependency is considered satisfied when all
|
|
1015
|
+
* policies in that phase have scheduled.
|
|
1016
|
+
*
|
|
1017
|
+
*/
|
|
1018
|
+
const result = [];
|
|
1019
|
+
const policyMap = /* @__PURE__ */ new Map();
|
|
1020
|
+
function createPhase(name) {
|
|
1021
|
+
return {
|
|
1022
|
+
name,
|
|
1023
|
+
policies: /* @__PURE__ */ new Set(),
|
|
1024
|
+
hasRun: false,
|
|
1025
|
+
hasAfterPolicies: false
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
const serializePhase = createPhase("Serialize");
|
|
1029
|
+
const noPhase = createPhase("None");
|
|
1030
|
+
const deserializePhase = createPhase("Deserialize");
|
|
1031
|
+
const retryPhase = createPhase("Retry");
|
|
1032
|
+
const signPhase = createPhase("Sign");
|
|
1033
|
+
const orderedPhases = [
|
|
1034
|
+
serializePhase,
|
|
1035
|
+
noPhase,
|
|
1036
|
+
deserializePhase,
|
|
1037
|
+
retryPhase,
|
|
1038
|
+
signPhase
|
|
1039
|
+
];
|
|
1040
|
+
function getPhase(phase) {
|
|
1041
|
+
if (phase === "Retry") return retryPhase;
|
|
1042
|
+
else if (phase === "Serialize") return serializePhase;
|
|
1043
|
+
else if (phase === "Deserialize") return deserializePhase;
|
|
1044
|
+
else if (phase === "Sign") return signPhase;
|
|
1045
|
+
else return noPhase;
|
|
1046
|
+
}
|
|
1047
|
+
for (const descriptor of this._policies) {
|
|
1048
|
+
const policy = descriptor.policy;
|
|
1049
|
+
const options = descriptor.options;
|
|
1050
|
+
const policyName = policy.name;
|
|
1051
|
+
if (policyMap.has(policyName)) throw new Error("Duplicate policy names not allowed in pipeline");
|
|
1052
|
+
const node = {
|
|
1053
|
+
policy,
|
|
1054
|
+
dependsOn: /* @__PURE__ */ new Set(),
|
|
1055
|
+
dependants: /* @__PURE__ */ new Set()
|
|
1056
|
+
};
|
|
1057
|
+
if (options.afterPhase) {
|
|
1058
|
+
node.afterPhase = getPhase(options.afterPhase);
|
|
1059
|
+
node.afterPhase.hasAfterPolicies = true;
|
|
1060
|
+
}
|
|
1061
|
+
policyMap.set(policyName, node);
|
|
1062
|
+
getPhase(options.phase).policies.add(node);
|
|
1063
|
+
}
|
|
1064
|
+
for (const descriptor of this._policies) {
|
|
1065
|
+
const { policy, options } = descriptor;
|
|
1066
|
+
const policyName = policy.name;
|
|
1067
|
+
const node = policyMap.get(policyName);
|
|
1068
|
+
if (!node) throw new Error(`Missing node for policy ${policyName}`);
|
|
1069
|
+
if (options.afterPolicies) for (const afterPolicyName of options.afterPolicies) {
|
|
1070
|
+
const afterNode = policyMap.get(afterPolicyName);
|
|
1071
|
+
if (afterNode) {
|
|
1072
|
+
node.dependsOn.add(afterNode);
|
|
1073
|
+
afterNode.dependants.add(node);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
if (options.beforePolicies) for (const beforePolicyName of options.beforePolicies) {
|
|
1077
|
+
const beforeNode = policyMap.get(beforePolicyName);
|
|
1078
|
+
if (beforeNode) {
|
|
1079
|
+
beforeNode.dependsOn.add(node);
|
|
1080
|
+
node.dependants.add(beforeNode);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
function walkPhase(phase) {
|
|
1085
|
+
phase.hasRun = true;
|
|
1086
|
+
for (const node of phase.policies) {
|
|
1087
|
+
if (node.afterPhase && (!node.afterPhase.hasRun || node.afterPhase.policies.size)) continue;
|
|
1088
|
+
if (node.dependsOn.size === 0) {
|
|
1089
|
+
result.push(node.policy);
|
|
1090
|
+
for (const dependant of node.dependants) dependant.dependsOn.delete(node);
|
|
1091
|
+
policyMap.delete(node.policy.name);
|
|
1092
|
+
phase.policies.delete(node);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
function walkPhases() {
|
|
1097
|
+
for (const phase of orderedPhases) {
|
|
1098
|
+
walkPhase(phase);
|
|
1099
|
+
if (phase.policies.size > 0 && phase !== noPhase) {
|
|
1100
|
+
if (!noPhase.hasRun) walkPhase(noPhase);
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
if (phase.hasAfterPolicies) walkPhase(noPhase);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
let iteration = 0;
|
|
1107
|
+
while (policyMap.size > 0) {
|
|
1108
|
+
iteration++;
|
|
1109
|
+
const initialResultLength = result.length;
|
|
1110
|
+
walkPhases();
|
|
1111
|
+
if (result.length <= initialResultLength && iteration > 1) throw new Error("Cannot satisfy policy dependencies due to requirements cycle.");
|
|
1112
|
+
}
|
|
1113
|
+
return result;
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
/**
|
|
1117
|
+
* Creates a totally empty pipeline.
|
|
1118
|
+
* Useful for testing or creating a custom one.
|
|
1119
|
+
*/
|
|
1120
|
+
function createEmptyPipeline$1() {
|
|
1121
|
+
return HttpPipeline.create();
|
|
1122
|
+
}
|
|
1123
|
+
//#endregion
|
|
1124
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/inspect.js
|
|
1125
|
+
const custom = inspect.custom;
|
|
1126
|
+
//#endregion
|
|
1127
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/restError.js
|
|
1128
|
+
const errorSanitizer = new Sanitizer();
|
|
1129
|
+
/**
|
|
1130
|
+
* A custom error type for failed pipeline requests.
|
|
1131
|
+
*/
|
|
1132
|
+
var RestError$1 = class RestError$1 extends Error {
|
|
1133
|
+
/**
|
|
1134
|
+
* Something went wrong when making the request.
|
|
1135
|
+
* This means the actual request failed for some reason,
|
|
1136
|
+
* such as a DNS issue or the connection being lost.
|
|
1137
|
+
*/
|
|
1138
|
+
static REQUEST_SEND_ERROR = "REQUEST_SEND_ERROR";
|
|
1139
|
+
/**
|
|
1140
|
+
* This means that parsing the response from the server failed.
|
|
1141
|
+
* It may have been malformed.
|
|
1142
|
+
*/
|
|
1143
|
+
static PARSE_ERROR = "PARSE_ERROR";
|
|
1144
|
+
/**
|
|
1145
|
+
* The code of the error itself (use statics on RestError if possible.)
|
|
1146
|
+
*/
|
|
1147
|
+
code;
|
|
1148
|
+
/**
|
|
1149
|
+
* The HTTP status code of the request (if applicable.)
|
|
1150
|
+
*/
|
|
1151
|
+
statusCode;
|
|
1152
|
+
/**
|
|
1153
|
+
* The request that was made.
|
|
1154
|
+
* This property is non-enumerable.
|
|
1155
|
+
*/
|
|
1156
|
+
request;
|
|
1157
|
+
/**
|
|
1158
|
+
* The response received (if any.)
|
|
1159
|
+
* This property is non-enumerable.
|
|
1160
|
+
*/
|
|
1161
|
+
response;
|
|
1162
|
+
/**
|
|
1163
|
+
* Bonus property set by the throw site.
|
|
1164
|
+
*/
|
|
1165
|
+
details;
|
|
1166
|
+
constructor(message, options = {}) {
|
|
1167
|
+
super(message);
|
|
1168
|
+
this.name = "RestError";
|
|
1169
|
+
this.code = options.code;
|
|
1170
|
+
this.statusCode = options.statusCode;
|
|
1171
|
+
Object.defineProperty(this, "request", {
|
|
1172
|
+
value: options.request,
|
|
1173
|
+
enumerable: false
|
|
1174
|
+
});
|
|
1175
|
+
Object.defineProperty(this, "response", {
|
|
1176
|
+
value: options.response,
|
|
1177
|
+
enumerable: false
|
|
1178
|
+
});
|
|
1179
|
+
const agent = this.request?.agent ? {
|
|
1180
|
+
maxFreeSockets: this.request.agent.maxFreeSockets,
|
|
1181
|
+
maxSockets: this.request.agent.maxSockets
|
|
1182
|
+
} : void 0;
|
|
1183
|
+
Object.defineProperty(this, custom, {
|
|
1184
|
+
value: () => {
|
|
1185
|
+
return `RestError: ${this.message} \n ${errorSanitizer.sanitize({
|
|
1186
|
+
...this,
|
|
1187
|
+
request: {
|
|
1188
|
+
...this.request,
|
|
1189
|
+
agent
|
|
1190
|
+
},
|
|
1191
|
+
response: this.response
|
|
1192
|
+
})}`;
|
|
1193
|
+
},
|
|
1194
|
+
enumerable: false
|
|
1195
|
+
});
|
|
1196
|
+
Object.setPrototypeOf(this, RestError$1.prototype);
|
|
1197
|
+
}
|
|
1198
|
+
};
|
|
1199
|
+
/**
|
|
1200
|
+
* Typeguard for RestError
|
|
1201
|
+
* @param e - Something caught by a catch clause.
|
|
1202
|
+
*/
|
|
1203
|
+
function isRestError$1(e) {
|
|
1204
|
+
if (e instanceof RestError$1) return true;
|
|
1205
|
+
return isError$1(e) && e.name === "RestError";
|
|
1206
|
+
}
|
|
1207
|
+
//#endregion
|
|
1208
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/abort-controller/AbortError.js
|
|
1209
|
+
/**
|
|
1210
|
+
* This error is thrown when an asynchronous operation has been aborted.
|
|
1211
|
+
* Check for this error by testing the `name` that the name property of the
|
|
1212
|
+
* error matches `"AbortError"`.
|
|
1213
|
+
*
|
|
1214
|
+
* @example
|
|
1215
|
+
* ```ts snippet:ReadmeSampleAbortError
|
|
1216
|
+
* import { AbortError } from "@typespec/ts-http-runtime";
|
|
1217
|
+
*
|
|
1218
|
+
* async function doAsyncWork(options: { abortSignal: AbortSignal }): Promise<void> {
|
|
1219
|
+
* if (options.abortSignal.aborted) {
|
|
1220
|
+
* throw new AbortError();
|
|
1221
|
+
* }
|
|
1222
|
+
*
|
|
1223
|
+
* // do async work
|
|
1224
|
+
* }
|
|
1225
|
+
*
|
|
1226
|
+
* const controller = new AbortController();
|
|
1227
|
+
* controller.abort();
|
|
1228
|
+
*
|
|
1229
|
+
* try {
|
|
1230
|
+
* doAsyncWork({ abortSignal: controller.signal });
|
|
1231
|
+
* } catch (e) {
|
|
1232
|
+
* if (e instanceof Error && e.name === "AbortError") {
|
|
1233
|
+
* // handle abort error here.
|
|
1234
|
+
* }
|
|
1235
|
+
* }
|
|
1236
|
+
* ```
|
|
1237
|
+
*/
|
|
1238
|
+
var AbortError = class extends Error {
|
|
1239
|
+
constructor(message) {
|
|
1240
|
+
super(message);
|
|
1241
|
+
this.name = "AbortError";
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
//#endregion
|
|
1245
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/log.js
|
|
1246
|
+
const logger$1 = createClientLogger$1("ts-http-runtime");
|
|
1247
|
+
//#endregion
|
|
1248
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/nodeHttpClient.js
|
|
1249
|
+
const DEFAULT_TLS_SETTINGS = {};
|
|
1250
|
+
function isReadableStream$1(body) {
|
|
1251
|
+
return body && typeof body.pipe === "function";
|
|
1252
|
+
}
|
|
1253
|
+
function isStreamComplete(stream) {
|
|
1254
|
+
if (stream.readable === false) return Promise.resolve();
|
|
1255
|
+
return new Promise((resolve) => {
|
|
1256
|
+
const handler = () => {
|
|
1257
|
+
resolve();
|
|
1258
|
+
stream.removeListener("close", handler);
|
|
1259
|
+
stream.removeListener("end", handler);
|
|
1260
|
+
stream.removeListener("error", handler);
|
|
1261
|
+
};
|
|
1262
|
+
stream.on("close", handler);
|
|
1263
|
+
stream.on("end", handler);
|
|
1264
|
+
stream.on("error", handler);
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
function isArrayBuffer(body) {
|
|
1268
|
+
return body && typeof body.byteLength === "number";
|
|
1269
|
+
}
|
|
1270
|
+
var ReportTransform = class extends Transform {
|
|
1271
|
+
loadedBytes = 0;
|
|
1272
|
+
progressCallback;
|
|
1273
|
+
_transform(chunk, _encoding, callback) {
|
|
1274
|
+
this.push(chunk);
|
|
1275
|
+
this.loadedBytes += chunk.length;
|
|
1276
|
+
try {
|
|
1277
|
+
this.progressCallback({ loadedBytes: this.loadedBytes });
|
|
1278
|
+
callback();
|
|
1279
|
+
} catch (e) {
|
|
1280
|
+
callback(e);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
constructor(progressCallback) {
|
|
1284
|
+
super();
|
|
1285
|
+
this.progressCallback = progressCallback;
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
/**
|
|
1289
|
+
* A HttpClient implementation that uses Node's "https" module to send HTTPS requests.
|
|
1290
|
+
* @internal
|
|
1291
|
+
*/
|
|
1292
|
+
var NodeHttpClient = class {
|
|
1293
|
+
cachedHttpAgent;
|
|
1294
|
+
cachedHttpsAgents = /* @__PURE__ */ new WeakMap();
|
|
1295
|
+
/**
|
|
1296
|
+
* Makes a request over an underlying transport layer and returns the response.
|
|
1297
|
+
* @param request - The request to be made.
|
|
1298
|
+
*/
|
|
1299
|
+
async sendRequest(request) {
|
|
1300
|
+
const abortController = new AbortController();
|
|
1301
|
+
let abortListener;
|
|
1302
|
+
if (request.abortSignal) {
|
|
1303
|
+
if (request.abortSignal.aborted) throw new AbortError("The operation was aborted. Request has already been canceled.");
|
|
1304
|
+
abortListener = (event) => {
|
|
1305
|
+
if (event.type === "abort") abortController.abort();
|
|
1306
|
+
};
|
|
1307
|
+
request.abortSignal.addEventListener("abort", abortListener);
|
|
1308
|
+
}
|
|
1309
|
+
let timeoutId;
|
|
1310
|
+
if (request.timeout > 0) timeoutId = setTimeout(() => {
|
|
1311
|
+
const sanitizer = new Sanitizer();
|
|
1312
|
+
logger$1.info(`request to '${sanitizer.sanitizeUrl(request.url)}' timed out. canceling...`);
|
|
1313
|
+
abortController.abort();
|
|
1314
|
+
}, request.timeout);
|
|
1315
|
+
const acceptEncoding = request.headers.get("Accept-Encoding");
|
|
1316
|
+
const shouldDecompress = acceptEncoding?.includes("gzip") || acceptEncoding?.includes("deflate");
|
|
1317
|
+
let body = typeof request.body === "function" ? request.body() : request.body;
|
|
1318
|
+
if (body && !request.headers.has("Content-Length")) {
|
|
1319
|
+
const bodyLength = getBodyLength(body);
|
|
1320
|
+
if (bodyLength !== null) request.headers.set("Content-Length", bodyLength);
|
|
1321
|
+
}
|
|
1322
|
+
let responseStream;
|
|
1323
|
+
try {
|
|
1324
|
+
if (body && request.onUploadProgress) {
|
|
1325
|
+
const onUploadProgress = request.onUploadProgress;
|
|
1326
|
+
const uploadReportStream = new ReportTransform(onUploadProgress);
|
|
1327
|
+
uploadReportStream.on("error", (e) => {
|
|
1328
|
+
logger$1.error("Error in upload progress", e);
|
|
1329
|
+
});
|
|
1330
|
+
if (isReadableStream$1(body)) body.pipe(uploadReportStream);
|
|
1331
|
+
else uploadReportStream.end(body);
|
|
1332
|
+
body = uploadReportStream;
|
|
1333
|
+
}
|
|
1334
|
+
const res = await this.makeRequest(request, abortController, body);
|
|
1335
|
+
if (timeoutId !== void 0) clearTimeout(timeoutId);
|
|
1336
|
+
const headers = getResponseHeaders(res);
|
|
1337
|
+
const response = {
|
|
1338
|
+
status: res.statusCode ?? 0,
|
|
1339
|
+
headers,
|
|
1340
|
+
request
|
|
1341
|
+
};
|
|
1342
|
+
if (request.method === "HEAD") {
|
|
1343
|
+
res.resume();
|
|
1344
|
+
return response;
|
|
1345
|
+
}
|
|
1346
|
+
responseStream = shouldDecompress ? getDecodedResponseStream(res, headers) : res;
|
|
1347
|
+
const onDownloadProgress = request.onDownloadProgress;
|
|
1348
|
+
if (onDownloadProgress) {
|
|
1349
|
+
const downloadReportStream = new ReportTransform(onDownloadProgress);
|
|
1350
|
+
downloadReportStream.on("error", (e) => {
|
|
1351
|
+
logger$1.error("Error in download progress", e);
|
|
1352
|
+
});
|
|
1353
|
+
responseStream.pipe(downloadReportStream);
|
|
1354
|
+
responseStream = downloadReportStream;
|
|
1355
|
+
}
|
|
1356
|
+
if (request.streamResponseStatusCodes?.has(Number.POSITIVE_INFINITY) || request.streamResponseStatusCodes?.has(response.status)) response.readableStreamBody = responseStream;
|
|
1357
|
+
else response.bodyAsText = await streamToText(responseStream);
|
|
1358
|
+
return response;
|
|
1359
|
+
} finally {
|
|
1360
|
+
if (request.abortSignal && abortListener) {
|
|
1361
|
+
let uploadStreamDone = Promise.resolve();
|
|
1362
|
+
if (isReadableStream$1(body)) uploadStreamDone = isStreamComplete(body);
|
|
1363
|
+
let downloadStreamDone = Promise.resolve();
|
|
1364
|
+
if (isReadableStream$1(responseStream)) downloadStreamDone = isStreamComplete(responseStream);
|
|
1365
|
+
Promise.all([uploadStreamDone, downloadStreamDone]).then(() => {
|
|
1366
|
+
if (abortListener) request.abortSignal?.removeEventListener("abort", abortListener);
|
|
1367
|
+
}).catch((e) => {
|
|
1368
|
+
logger$1.warning("Error when cleaning up abortListener on httpRequest", e);
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
makeRequest(request, abortController, body) {
|
|
1374
|
+
const url = new URL(request.url);
|
|
1375
|
+
const isInsecure = url.protocol !== "https:";
|
|
1376
|
+
if (isInsecure && !request.allowInsecureConnection) throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);
|
|
1377
|
+
const options = {
|
|
1378
|
+
agent: request.agent ?? this.getOrCreateAgent(request, isInsecure),
|
|
1379
|
+
hostname: url.hostname,
|
|
1380
|
+
path: `${url.pathname}${url.search}`,
|
|
1381
|
+
port: url.port,
|
|
1382
|
+
method: request.method,
|
|
1383
|
+
headers: request.headers.toJSON({ preserveCase: true }),
|
|
1384
|
+
...request.requestOverrides
|
|
1385
|
+
};
|
|
1386
|
+
return new Promise((resolve, reject) => {
|
|
1387
|
+
const req = isInsecure ? http.request(options, resolve) : https.request(options, resolve);
|
|
1388
|
+
req.once("error", (err) => {
|
|
1389
|
+
reject(new RestError$1(err.message, {
|
|
1390
|
+
code: err.code ?? RestError$1.REQUEST_SEND_ERROR,
|
|
1391
|
+
request
|
|
1392
|
+
}));
|
|
1393
|
+
});
|
|
1394
|
+
abortController.signal.addEventListener("abort", () => {
|
|
1395
|
+
const abortError = new AbortError("The operation was aborted. Rejecting from abort signal callback while making request.");
|
|
1396
|
+
req.destroy(abortError);
|
|
1397
|
+
reject(abortError);
|
|
1398
|
+
});
|
|
1399
|
+
if (body && isReadableStream$1(body)) body.pipe(req);
|
|
1400
|
+
else if (body) if (typeof body === "string" || Buffer.isBuffer(body)) req.end(body);
|
|
1401
|
+
else if (isArrayBuffer(body)) req.end(ArrayBuffer.isView(body) ? Buffer.from(body.buffer) : Buffer.from(body));
|
|
1402
|
+
else {
|
|
1403
|
+
logger$1.error("Unrecognized body type", body);
|
|
1404
|
+
reject(new RestError$1("Unrecognized body type"));
|
|
1405
|
+
}
|
|
1406
|
+
else req.end();
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
getOrCreateAgent(request, isInsecure) {
|
|
1410
|
+
const disableKeepAlive = request.disableKeepAlive;
|
|
1411
|
+
if (isInsecure) {
|
|
1412
|
+
if (disableKeepAlive) return http.globalAgent;
|
|
1413
|
+
if (!this.cachedHttpAgent) this.cachedHttpAgent = new http.Agent({ keepAlive: true });
|
|
1414
|
+
return this.cachedHttpAgent;
|
|
1415
|
+
} else {
|
|
1416
|
+
if (disableKeepAlive && !request.tlsSettings) return https.globalAgent;
|
|
1417
|
+
const tlsSettings = request.tlsSettings ?? DEFAULT_TLS_SETTINGS;
|
|
1418
|
+
let agent = this.cachedHttpsAgents.get(tlsSettings);
|
|
1419
|
+
if (agent && agent.options.keepAlive === !disableKeepAlive) return agent;
|
|
1420
|
+
logger$1.info("No cached TLS Agent exist, creating a new Agent");
|
|
1421
|
+
agent = new https.Agent({
|
|
1422
|
+
keepAlive: !disableKeepAlive,
|
|
1423
|
+
...tlsSettings
|
|
1424
|
+
});
|
|
1425
|
+
this.cachedHttpsAgents.set(tlsSettings, agent);
|
|
1426
|
+
return agent;
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
function getResponseHeaders(res) {
|
|
1431
|
+
const headers = createHttpHeaders();
|
|
1432
|
+
for (const header of Object.keys(res.headers)) {
|
|
1433
|
+
const value = res.headers[header];
|
|
1434
|
+
if (Array.isArray(value)) {
|
|
1435
|
+
if (value.length > 0) headers.set(header, value[0]);
|
|
1436
|
+
} else if (value) headers.set(header, value);
|
|
1437
|
+
}
|
|
1438
|
+
return headers;
|
|
1439
|
+
}
|
|
1440
|
+
function getDecodedResponseStream(stream, headers) {
|
|
1441
|
+
const contentEncoding = headers.get("Content-Encoding");
|
|
1442
|
+
if (contentEncoding === "gzip") {
|
|
1443
|
+
const unzip = zlib.createGunzip();
|
|
1444
|
+
stream.pipe(unzip);
|
|
1445
|
+
return unzip;
|
|
1446
|
+
} else if (contentEncoding === "deflate") {
|
|
1447
|
+
const inflate = zlib.createInflate();
|
|
1448
|
+
stream.pipe(inflate);
|
|
1449
|
+
return inflate;
|
|
1450
|
+
}
|
|
1451
|
+
return stream;
|
|
1452
|
+
}
|
|
1453
|
+
function streamToText(stream) {
|
|
1454
|
+
return new Promise((resolve, reject) => {
|
|
1455
|
+
const buffer = [];
|
|
1456
|
+
stream.on("data", (chunk) => {
|
|
1457
|
+
if (Buffer.isBuffer(chunk)) buffer.push(chunk);
|
|
1458
|
+
else buffer.push(Buffer.from(chunk));
|
|
1459
|
+
});
|
|
1460
|
+
stream.on("end", () => {
|
|
1461
|
+
resolve(Buffer.concat(buffer).toString("utf8"));
|
|
1462
|
+
});
|
|
1463
|
+
stream.on("error", (e) => {
|
|
1464
|
+
if (e && e?.name === "AbortError") reject(e);
|
|
1465
|
+
else reject(new RestError$1(`Error reading response as text: ${e.message}`, { code: RestError$1.PARSE_ERROR }));
|
|
1466
|
+
});
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
/** @internal */
|
|
1470
|
+
function getBodyLength(body) {
|
|
1471
|
+
if (!body) return 0;
|
|
1472
|
+
else if (Buffer.isBuffer(body)) return body.length;
|
|
1473
|
+
else if (isReadableStream$1(body)) return null;
|
|
1474
|
+
else if (isArrayBuffer(body)) return body.byteLength;
|
|
1475
|
+
else if (typeof body === "string") return Buffer.from(body).length;
|
|
1476
|
+
else return null;
|
|
1477
|
+
}
|
|
1478
|
+
/**
|
|
1479
|
+
* Create a new HttpClient instance for the NodeJS environment.
|
|
1480
|
+
* @internal
|
|
1481
|
+
*/
|
|
1482
|
+
function createNodeHttpClient() {
|
|
1483
|
+
return new NodeHttpClient();
|
|
1484
|
+
}
|
|
1485
|
+
//#endregion
|
|
1486
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/defaultHttpClient.js
|
|
1487
|
+
/**
|
|
1488
|
+
* Create the correct HttpClient for the current environment.
|
|
1489
|
+
*/
|
|
1490
|
+
function createDefaultHttpClient() {
|
|
1491
|
+
return createNodeHttpClient();
|
|
1492
|
+
}
|
|
1493
|
+
//#endregion
|
|
1494
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/policies/logPolicy.js
|
|
1495
|
+
/**
|
|
1496
|
+
* The programmatic identifier of the logPolicy.
|
|
1497
|
+
*/
|
|
1498
|
+
const logPolicyName = "logPolicy";
|
|
1499
|
+
/**
|
|
1500
|
+
* A policy that logs all requests and responses.
|
|
1501
|
+
* @param options - Options to configure logPolicy.
|
|
1502
|
+
*/
|
|
1503
|
+
function logPolicy$1(options = {}) {
|
|
1504
|
+
const logger = options.logger ?? logger$1.info;
|
|
1505
|
+
const sanitizer = new Sanitizer({
|
|
1506
|
+
additionalAllowedHeaderNames: options.additionalAllowedHeaderNames,
|
|
1507
|
+
additionalAllowedQueryParameters: options.additionalAllowedQueryParameters
|
|
1508
|
+
});
|
|
1509
|
+
return {
|
|
1510
|
+
name: logPolicyName,
|
|
1511
|
+
async sendRequest(request, next) {
|
|
1512
|
+
if (!logger.enabled) return next(request);
|
|
1513
|
+
logger(`Request: ${sanitizer.sanitize(request)}`);
|
|
1514
|
+
const response = await next(request);
|
|
1515
|
+
logger(`Response status code: ${response.status}`);
|
|
1516
|
+
logger(`Headers: ${sanitizer.sanitize(response.headers)}`);
|
|
1517
|
+
return response;
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
//#endregion
|
|
1522
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/policies/redirectPolicy.js
|
|
1523
|
+
/**
|
|
1524
|
+
* The programmatic identifier of the redirectPolicy.
|
|
1525
|
+
*/
|
|
1526
|
+
const redirectPolicyName = "redirectPolicy";
|
|
1527
|
+
/**
|
|
1528
|
+
* Methods that are allowed to follow redirects 301 and 302
|
|
1529
|
+
*/
|
|
1530
|
+
const allowedRedirect = ["GET", "HEAD"];
|
|
1531
|
+
/**
|
|
1532
|
+
* A policy to follow Location headers from the server in order
|
|
1533
|
+
* to support server-side redirection.
|
|
1534
|
+
* In the browser, this policy is not used.
|
|
1535
|
+
* @param options - Options to control policy behavior.
|
|
1536
|
+
*/
|
|
1537
|
+
function redirectPolicy$1(options = {}) {
|
|
1538
|
+
const { maxRetries = 20 } = options;
|
|
1539
|
+
return {
|
|
1540
|
+
name: redirectPolicyName,
|
|
1541
|
+
async sendRequest(request, next) {
|
|
1542
|
+
return handleRedirect(next, await next(request), maxRetries);
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
async function handleRedirect(next, response, maxRetries, currentRetries = 0) {
|
|
1547
|
+
const { request, status, headers } = response;
|
|
1548
|
+
const locationHeader = headers.get("location");
|
|
1549
|
+
if (locationHeader && (status === 300 || status === 301 && allowedRedirect.includes(request.method) || status === 302 && allowedRedirect.includes(request.method) || status === 303 && request.method === "POST" || status === 307) && currentRetries < maxRetries) {
|
|
1550
|
+
request.url = new URL(locationHeader, request.url).toString();
|
|
1551
|
+
if (status === 303) {
|
|
1552
|
+
request.method = "GET";
|
|
1553
|
+
request.headers.delete("Content-Length");
|
|
1554
|
+
delete request.body;
|
|
1555
|
+
}
|
|
1556
|
+
request.headers.delete("Authorization");
|
|
1557
|
+
return handleRedirect(next, await next(request), maxRetries, currentRetries + 1);
|
|
1558
|
+
}
|
|
1559
|
+
return response;
|
|
1560
|
+
}
|
|
1561
|
+
//#endregion
|
|
1562
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/constants.js
|
|
1563
|
+
const SDK_VERSION$1 = "0.3.2";
|
|
1564
|
+
//#endregion
|
|
1565
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/policies/decompressResponsePolicy.js
|
|
1566
|
+
/**
|
|
1567
|
+
* The programmatic identifier of the decompressResponsePolicy.
|
|
1568
|
+
*/
|
|
1569
|
+
const decompressResponsePolicyName = "decompressResponsePolicy";
|
|
1570
|
+
/**
|
|
1571
|
+
* A policy to enable response decompression according to Accept-Encoding header
|
|
1572
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
|
|
1573
|
+
*/
|
|
1574
|
+
function decompressResponsePolicy$1() {
|
|
1575
|
+
return {
|
|
1576
|
+
name: decompressResponsePolicyName,
|
|
1577
|
+
async sendRequest(request, next) {
|
|
1578
|
+
if (request.method !== "HEAD") request.headers.set("Accept-Encoding", "gzip,deflate");
|
|
1579
|
+
return next(request);
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
//#endregion
|
|
1584
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/helpers.js
|
|
1585
|
+
const StandardAbortMessage = "The operation was aborted.";
|
|
1586
|
+
/**
|
|
1587
|
+
* A wrapper for setTimeout that resolves a promise after delayInMs milliseconds.
|
|
1588
|
+
* @param delayInMs - The number of milliseconds to be delayed.
|
|
1589
|
+
* @param value - The value to be resolved with after a timeout of t milliseconds.
|
|
1590
|
+
* @param options - The options for delay - currently abort options
|
|
1591
|
+
* - abortSignal - The abortSignal associated with containing operation.
|
|
1592
|
+
* - abortErrorMsg - The abort error message associated with containing operation.
|
|
1593
|
+
* @returns Resolved promise
|
|
1594
|
+
*/
|
|
1595
|
+
function delay(delayInMs, value, options) {
|
|
1596
|
+
return new Promise((resolve, reject) => {
|
|
1597
|
+
let timer = void 0;
|
|
1598
|
+
let onAborted = void 0;
|
|
1599
|
+
const rejectOnAbort = () => {
|
|
1600
|
+
return reject(new AbortError(options?.abortErrorMsg ? options?.abortErrorMsg : StandardAbortMessage));
|
|
1601
|
+
};
|
|
1602
|
+
const removeListeners = () => {
|
|
1603
|
+
if (options?.abortSignal && onAborted) options.abortSignal.removeEventListener("abort", onAborted);
|
|
1604
|
+
};
|
|
1605
|
+
onAborted = () => {
|
|
1606
|
+
if (timer) clearTimeout(timer);
|
|
1607
|
+
removeListeners();
|
|
1608
|
+
return rejectOnAbort();
|
|
1609
|
+
};
|
|
1610
|
+
if (options?.abortSignal && options.abortSignal.aborted) return rejectOnAbort();
|
|
1611
|
+
timer = setTimeout(() => {
|
|
1612
|
+
removeListeners();
|
|
1613
|
+
resolve(value);
|
|
1614
|
+
}, delayInMs);
|
|
1615
|
+
if (options?.abortSignal) options.abortSignal.addEventListener("abort", onAborted);
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* @internal
|
|
1620
|
+
* @returns the parsed value or undefined if the parsed value is invalid.
|
|
1621
|
+
*/
|
|
1622
|
+
function parseHeaderValueAsNumber(response, headerName) {
|
|
1623
|
+
const value = response.headers.get(headerName);
|
|
1624
|
+
if (!value) return;
|
|
1625
|
+
const valueAsNum = Number(value);
|
|
1626
|
+
if (Number.isNaN(valueAsNum)) return;
|
|
1627
|
+
return valueAsNum;
|
|
1628
|
+
}
|
|
1629
|
+
//#endregion
|
|
1630
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/retryStrategies/throttlingRetryStrategy.js
|
|
1631
|
+
/**
|
|
1632
|
+
* The header that comes back from services representing
|
|
1633
|
+
* the amount of time (minimum) to wait to retry (in seconds or timestamp after which we can retry).
|
|
1634
|
+
*/
|
|
1635
|
+
const RetryAfterHeader = "Retry-After";
|
|
1636
|
+
/**
|
|
1637
|
+
* The headers that come back from services representing
|
|
1638
|
+
* the amount of time (minimum) to wait to retry.
|
|
1639
|
+
*
|
|
1640
|
+
* "retry-after-ms", "x-ms-retry-after-ms" : milliseconds
|
|
1641
|
+
* "Retry-After" : seconds or timestamp
|
|
1642
|
+
*/
|
|
1643
|
+
const AllRetryAfterHeaders = [
|
|
1644
|
+
"retry-after-ms",
|
|
1645
|
+
"x-ms-retry-after-ms",
|
|
1646
|
+
RetryAfterHeader
|
|
1647
|
+
];
|
|
1648
|
+
/**
|
|
1649
|
+
* A response is a throttling retry response if it has a throttling status code (429 or 503),
|
|
1650
|
+
* as long as one of the [ "Retry-After" or "retry-after-ms" or "x-ms-retry-after-ms" ] headers has a valid value.
|
|
1651
|
+
*
|
|
1652
|
+
* Returns the `retryAfterInMs` value if the response is a throttling retry response.
|
|
1653
|
+
* If not throttling retry response, returns `undefined`.
|
|
1654
|
+
*
|
|
1655
|
+
* @internal
|
|
1656
|
+
*/
|
|
1657
|
+
function getRetryAfterInMs(response) {
|
|
1658
|
+
if (!(response && [429, 503].includes(response.status))) return void 0;
|
|
1659
|
+
try {
|
|
1660
|
+
for (const header of AllRetryAfterHeaders) {
|
|
1661
|
+
const retryAfterValue = parseHeaderValueAsNumber(response, header);
|
|
1662
|
+
if (retryAfterValue === 0 || retryAfterValue) return retryAfterValue * (header === RetryAfterHeader ? 1e3 : 1);
|
|
1663
|
+
}
|
|
1664
|
+
const retryAfterHeader = response.headers.get(RetryAfterHeader);
|
|
1665
|
+
if (!retryAfterHeader) return;
|
|
1666
|
+
const diff = Date.parse(retryAfterHeader) - Date.now();
|
|
1667
|
+
return Number.isFinite(diff) ? Math.max(0, diff) : void 0;
|
|
1668
|
+
} catch {
|
|
1669
|
+
return;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
* A response is a retry response if it has a throttling status code (429 or 503),
|
|
1674
|
+
* as long as one of the [ "Retry-After" or "retry-after-ms" or "x-ms-retry-after-ms" ] headers has a valid value.
|
|
1675
|
+
*/
|
|
1676
|
+
function isThrottlingRetryResponse(response) {
|
|
1677
|
+
return Number.isFinite(getRetryAfterInMs(response));
|
|
1678
|
+
}
|
|
1679
|
+
function throttlingRetryStrategy() {
|
|
1680
|
+
return {
|
|
1681
|
+
name: "throttlingRetryStrategy",
|
|
1682
|
+
retry({ response }) {
|
|
1683
|
+
const retryAfterInMs = getRetryAfterInMs(response);
|
|
1684
|
+
if (!Number.isFinite(retryAfterInMs)) return { skipStrategy: true };
|
|
1685
|
+
return { retryAfterInMs };
|
|
1686
|
+
}
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
//#endregion
|
|
1690
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/retryStrategies/exponentialRetryStrategy.js
|
|
1691
|
+
const DEFAULT_CLIENT_RETRY_INTERVAL = 1e3;
|
|
1692
|
+
const DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1e3 * 64;
|
|
1693
|
+
/**
|
|
1694
|
+
* A retry strategy that retries with an exponentially increasing delay in these two cases:
|
|
1695
|
+
* - When there are errors in the underlying transport layer (e.g. DNS lookup failures).
|
|
1696
|
+
* - Or otherwise if the outgoing request fails (408, greater or equal than 500, except for 501 and 505).
|
|
1697
|
+
*/
|
|
1698
|
+
function exponentialRetryStrategy(options = {}) {
|
|
1699
|
+
const retryInterval = options.retryDelayInMs ?? DEFAULT_CLIENT_RETRY_INTERVAL;
|
|
1700
|
+
const maxRetryInterval = options.maxRetryDelayInMs ?? DEFAULT_CLIENT_MAX_RETRY_INTERVAL;
|
|
1701
|
+
return {
|
|
1702
|
+
name: "exponentialRetryStrategy",
|
|
1703
|
+
retry({ retryCount, response, responseError }) {
|
|
1704
|
+
const matchedSystemError = isSystemError(responseError);
|
|
1705
|
+
const ignoreSystemErrors = matchedSystemError && options.ignoreSystemErrors;
|
|
1706
|
+
const isExponential = isExponentialRetryResponse(response);
|
|
1707
|
+
const ignoreExponentialResponse = isExponential && options.ignoreHttpStatusCodes;
|
|
1708
|
+
if (response && (isThrottlingRetryResponse(response) || !isExponential) || ignoreExponentialResponse || ignoreSystemErrors) return { skipStrategy: true };
|
|
1709
|
+
if (responseError && !matchedSystemError && !isExponential) return { errorToThrow: responseError };
|
|
1710
|
+
return calculateRetryDelay$1(retryCount, {
|
|
1711
|
+
retryDelayInMs: retryInterval,
|
|
1712
|
+
maxRetryDelayInMs: maxRetryInterval
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1716
|
+
}
|
|
1717
|
+
/**
|
|
1718
|
+
* A response is a retry response if it has status codes:
|
|
1719
|
+
* - 408, or
|
|
1720
|
+
* - Greater or equal than 500, except for 501 and 505.
|
|
1721
|
+
*/
|
|
1722
|
+
function isExponentialRetryResponse(response) {
|
|
1723
|
+
return Boolean(response && response.status !== void 0 && (response.status >= 500 || response.status === 408) && response.status !== 501 && response.status !== 505);
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Determines whether an error from a pipeline response was triggered in the network layer.
|
|
1727
|
+
*/
|
|
1728
|
+
function isSystemError(err) {
|
|
1729
|
+
if (!err) return false;
|
|
1730
|
+
return err.code === "ETIMEDOUT" || err.code === "ESOCKETTIMEDOUT" || err.code === "ECONNREFUSED" || err.code === "ECONNRESET" || err.code === "ENOENT" || err.code === "ENOTFOUND";
|
|
1731
|
+
}
|
|
1732
|
+
//#endregion
|
|
1733
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/policies/retryPolicy.js
|
|
1734
|
+
const retryPolicyLogger = createClientLogger$1("ts-http-runtime retryPolicy");
|
|
1735
|
+
/**
|
|
1736
|
+
* The programmatic identifier of the retryPolicy.
|
|
1737
|
+
*/
|
|
1738
|
+
const retryPolicyName = "retryPolicy";
|
|
1739
|
+
/**
|
|
1740
|
+
* retryPolicy is a generic policy to enable retrying requests when certain conditions are met
|
|
1741
|
+
*/
|
|
1742
|
+
function retryPolicy(strategies, options = { maxRetries: 3 }) {
|
|
1743
|
+
const logger = options.logger || retryPolicyLogger;
|
|
1744
|
+
return {
|
|
1745
|
+
name: retryPolicyName,
|
|
1746
|
+
async sendRequest(request, next) {
|
|
1747
|
+
let response;
|
|
1748
|
+
let responseError;
|
|
1749
|
+
let retryCount = -1;
|
|
1750
|
+
retryRequest: while (true) {
|
|
1751
|
+
retryCount += 1;
|
|
1752
|
+
response = void 0;
|
|
1753
|
+
responseError = void 0;
|
|
1754
|
+
try {
|
|
1755
|
+
logger.info(`Retry ${retryCount}: Attempting to send request`, request.requestId);
|
|
1756
|
+
response = await next(request);
|
|
1757
|
+
logger.info(`Retry ${retryCount}: Received a response from request`, request.requestId);
|
|
1758
|
+
} catch (e) {
|
|
1759
|
+
logger.error(`Retry ${retryCount}: Received an error from request`, request.requestId);
|
|
1760
|
+
responseError = e;
|
|
1761
|
+
if (!e || responseError.name !== "RestError") throw e;
|
|
1762
|
+
response = responseError.response;
|
|
1763
|
+
}
|
|
1764
|
+
if (request.abortSignal?.aborted) {
|
|
1765
|
+
logger.error(`Retry ${retryCount}: Request aborted.`);
|
|
1766
|
+
throw new AbortError();
|
|
1767
|
+
}
|
|
1768
|
+
if (retryCount >= (options.maxRetries ?? 3)) {
|
|
1769
|
+
logger.info(`Retry ${retryCount}: Maximum retries reached. Returning the last received response, or throwing the last received error.`);
|
|
1770
|
+
if (responseError) throw responseError;
|
|
1771
|
+
else if (response) return response;
|
|
1772
|
+
else throw new Error("Maximum retries reached with no response or error to throw");
|
|
1773
|
+
}
|
|
1774
|
+
logger.info(`Retry ${retryCount}: Processing ${strategies.length} retry strategies.`);
|
|
1775
|
+
strategiesLoop: for (const strategy of strategies) {
|
|
1776
|
+
const strategyLogger = strategy.logger || logger;
|
|
1777
|
+
strategyLogger.info(`Retry ${retryCount}: Processing retry strategy ${strategy.name}.`);
|
|
1778
|
+
const modifiers = strategy.retry({
|
|
1779
|
+
retryCount,
|
|
1780
|
+
response,
|
|
1781
|
+
responseError
|
|
1782
|
+
});
|
|
1783
|
+
if (modifiers.skipStrategy) {
|
|
1784
|
+
strategyLogger.info(`Retry ${retryCount}: Skipped.`);
|
|
1785
|
+
continue strategiesLoop;
|
|
1786
|
+
}
|
|
1787
|
+
const { errorToThrow, retryAfterInMs, redirectTo } = modifiers;
|
|
1788
|
+
if (errorToThrow) {
|
|
1789
|
+
strategyLogger.error(`Retry ${retryCount}: Retry strategy ${strategy.name} throws error:`, errorToThrow);
|
|
1790
|
+
throw errorToThrow;
|
|
1791
|
+
}
|
|
1792
|
+
if (retryAfterInMs || retryAfterInMs === 0) {
|
|
1793
|
+
strategyLogger.info(`Retry ${retryCount}: Retry strategy ${strategy.name} retries after ${retryAfterInMs}`);
|
|
1794
|
+
await delay(retryAfterInMs, void 0, { abortSignal: request.abortSignal });
|
|
1795
|
+
continue retryRequest;
|
|
1796
|
+
}
|
|
1797
|
+
if (redirectTo) {
|
|
1798
|
+
strategyLogger.info(`Retry ${retryCount}: Retry strategy ${strategy.name} redirects to ${redirectTo}`);
|
|
1799
|
+
request.url = redirectTo;
|
|
1800
|
+
continue retryRequest;
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
if (responseError) {
|
|
1804
|
+
logger.info(`None of the retry strategies could work with the received error. Throwing it.`);
|
|
1805
|
+
throw responseError;
|
|
1806
|
+
}
|
|
1807
|
+
if (response) {
|
|
1808
|
+
logger.info(`None of the retry strategies could work with the received response. Returning it.`);
|
|
1809
|
+
return response;
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
};
|
|
1814
|
+
}
|
|
1815
|
+
//#endregion
|
|
1816
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/policies/defaultRetryPolicy.js
|
|
1817
|
+
/**
|
|
1818
|
+
* Name of the {@link defaultRetryPolicy}
|
|
1819
|
+
*/
|
|
1820
|
+
const defaultRetryPolicyName = "defaultRetryPolicy";
|
|
1821
|
+
/**
|
|
1822
|
+
* A policy that retries according to three strategies:
|
|
1823
|
+
* - When the server sends a 429 response with a Retry-After header.
|
|
1824
|
+
* - When there are errors in the underlying transport layer (e.g. DNS lookup failures).
|
|
1825
|
+
* - Or otherwise if the outgoing request fails, it will retry with an exponentially increasing delay.
|
|
1826
|
+
*/
|
|
1827
|
+
function defaultRetryPolicy$1(options = {}) {
|
|
1828
|
+
return {
|
|
1829
|
+
name: defaultRetryPolicyName,
|
|
1830
|
+
sendRequest: retryPolicy([throttlingRetryStrategy(), exponentialRetryStrategy(options)], { maxRetries: options.maxRetries ?? 3 }).sendRequest
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
//#endregion
|
|
1834
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/policies/formDataPolicy.js
|
|
1835
|
+
/**
|
|
1836
|
+
* The programmatic identifier of the formDataPolicy.
|
|
1837
|
+
*/
|
|
1838
|
+
const formDataPolicyName = "formDataPolicy";
|
|
1839
|
+
function formDataToFormDataMap(formData) {
|
|
1840
|
+
const formDataMap = {};
|
|
1841
|
+
for (const [key, value] of formData.entries()) {
|
|
1842
|
+
formDataMap[key] ??= [];
|
|
1843
|
+
formDataMap[key].push(value);
|
|
1844
|
+
}
|
|
1845
|
+
return formDataMap;
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* A policy that encodes FormData on the request into the body.
|
|
1849
|
+
*/
|
|
1850
|
+
function formDataPolicy$1() {
|
|
1851
|
+
return {
|
|
1852
|
+
name: formDataPolicyName,
|
|
1853
|
+
async sendRequest(request, next) {
|
|
1854
|
+
if (isNodeLike$1 && typeof FormData !== "undefined" && request.body instanceof FormData) {
|
|
1855
|
+
request.formData = formDataToFormDataMap(request.body);
|
|
1856
|
+
request.body = void 0;
|
|
1857
|
+
}
|
|
1858
|
+
if (request.formData) {
|
|
1859
|
+
const contentType = request.headers.get("Content-Type");
|
|
1860
|
+
if (contentType && contentType.indexOf("application/x-www-form-urlencoded") !== -1) request.body = wwwFormUrlEncode(request.formData);
|
|
1861
|
+
else await prepareFormData(request.formData, request);
|
|
1862
|
+
request.formData = void 0;
|
|
1863
|
+
}
|
|
1864
|
+
return next(request);
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
}
|
|
1868
|
+
function wwwFormUrlEncode(formData) {
|
|
1869
|
+
const urlSearchParams = new URLSearchParams();
|
|
1870
|
+
for (const [key, value] of Object.entries(formData)) if (Array.isArray(value)) for (const subValue of value) urlSearchParams.append(key, subValue.toString());
|
|
1871
|
+
else urlSearchParams.append(key, value.toString());
|
|
1872
|
+
return urlSearchParams.toString();
|
|
1873
|
+
}
|
|
1874
|
+
async function prepareFormData(formData, request) {
|
|
1875
|
+
const contentType = request.headers.get("Content-Type");
|
|
1876
|
+
if (contentType && !contentType.startsWith("multipart/form-data")) return;
|
|
1877
|
+
request.headers.set("Content-Type", contentType ?? "multipart/form-data");
|
|
1878
|
+
const parts = [];
|
|
1879
|
+
for (const [fieldName, values] of Object.entries(formData)) for (const value of Array.isArray(values) ? values : [values]) if (typeof value === "string") parts.push({
|
|
1880
|
+
headers: createHttpHeaders({ "Content-Disposition": `form-data; name="${fieldName}"` }),
|
|
1881
|
+
body: stringToUint8Array$1(value, "utf-8")
|
|
1882
|
+
});
|
|
1883
|
+
else if (value === void 0 || value === null || typeof value !== "object") throw new Error(`Unexpected value for key ${fieldName}: ${value}. Value should be serialized to string first.`);
|
|
1884
|
+
else {
|
|
1885
|
+
const fileName = value.name || "blob";
|
|
1886
|
+
const headers = createHttpHeaders();
|
|
1887
|
+
headers.set("Content-Disposition", `form-data; name="${fieldName}"; filename="${fileName}"`);
|
|
1888
|
+
headers.set("Content-Type", value.type || "application/octet-stream");
|
|
1889
|
+
parts.push({
|
|
1890
|
+
headers,
|
|
1891
|
+
body: value
|
|
1892
|
+
});
|
|
1893
|
+
}
|
|
1894
|
+
request.multipartBody = { parts };
|
|
1895
|
+
}
|
|
1896
|
+
//#endregion
|
|
1897
|
+
//#region ../../node_modules/.pnpm/http-proxy-agent@7.0.2/node_modules/http-proxy-agent/dist/index.js
|
|
1898
|
+
var require_dist = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1899
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1900
|
+
if (k2 === void 0) k2 = k;
|
|
1901
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1902
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
1903
|
+
enumerable: true,
|
|
1904
|
+
get: function() {
|
|
1905
|
+
return m[k];
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
Object.defineProperty(o, k2, desc);
|
|
1909
|
+
}) : (function(o, m, k, k2) {
|
|
1910
|
+
if (k2 === void 0) k2 = k;
|
|
1911
|
+
o[k2] = m[k];
|
|
1912
|
+
}));
|
|
1913
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1914
|
+
Object.defineProperty(o, "default", {
|
|
1915
|
+
enumerable: true,
|
|
1916
|
+
value: v
|
|
1917
|
+
});
|
|
1918
|
+
}) : function(o, v) {
|
|
1919
|
+
o["default"] = v;
|
|
1920
|
+
});
|
|
1921
|
+
var __importStar = exports && exports.__importStar || function(mod) {
|
|
1922
|
+
if (mod && mod.__esModule) return mod;
|
|
1923
|
+
var result = {};
|
|
1924
|
+
if (mod != null) {
|
|
1925
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
1926
|
+
}
|
|
1927
|
+
__setModuleDefault(result, mod);
|
|
1928
|
+
return result;
|
|
1929
|
+
};
|
|
1930
|
+
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
1931
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1932
|
+
};
|
|
1933
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1934
|
+
exports.HttpProxyAgent = void 0;
|
|
1935
|
+
const net = __importStar(__require("net"));
|
|
1936
|
+
const tls = __importStar(__require("tls"));
|
|
1937
|
+
const debug_1 = __importDefault(require_src());
|
|
1938
|
+
const events_1 = __require("events");
|
|
1939
|
+
const agent_base_1 = require_dist$1();
|
|
1940
|
+
const url_1 = __require("url");
|
|
1941
|
+
const debug = (0, debug_1.default)("http-proxy-agent");
|
|
1942
|
+
/**
|
|
1943
|
+
* The `HttpProxyAgent` implements an HTTP Agent subclass that connects
|
|
1944
|
+
* to the specified "HTTP proxy server" in order to proxy HTTP requests.
|
|
1945
|
+
*/
|
|
1946
|
+
var HttpProxyAgent = class extends agent_base_1.Agent {
|
|
1947
|
+
constructor(proxy, opts) {
|
|
1948
|
+
super(opts);
|
|
1949
|
+
this.proxy = typeof proxy === "string" ? new url_1.URL(proxy) : proxy;
|
|
1950
|
+
this.proxyHeaders = opts?.headers ?? {};
|
|
1951
|
+
debug("Creating new HttpProxyAgent instance: %o", this.proxy.href);
|
|
1952
|
+
const host = (this.proxy.hostname || this.proxy.host).replace(/^\[|\]$/g, "");
|
|
1953
|
+
const port = this.proxy.port ? parseInt(this.proxy.port, 10) : this.proxy.protocol === "https:" ? 443 : 80;
|
|
1954
|
+
this.connectOpts = {
|
|
1955
|
+
...opts ? omit(opts, "headers") : null,
|
|
1956
|
+
host,
|
|
1957
|
+
port
|
|
1958
|
+
};
|
|
1959
|
+
}
|
|
1960
|
+
addRequest(req, opts) {
|
|
1961
|
+
req._header = null;
|
|
1962
|
+
this.setRequestProps(req, opts);
|
|
1963
|
+
super.addRequest(req, opts);
|
|
1964
|
+
}
|
|
1965
|
+
setRequestProps(req, opts) {
|
|
1966
|
+
const { proxy } = this;
|
|
1967
|
+
const base = `${opts.secureEndpoint ? "https:" : "http:"}//${req.getHeader("host") || "localhost"}`;
|
|
1968
|
+
const url = new url_1.URL(req.path, base);
|
|
1969
|
+
if (opts.port !== 80) url.port = String(opts.port);
|
|
1970
|
+
req.path = String(url);
|
|
1971
|
+
const headers = typeof this.proxyHeaders === "function" ? this.proxyHeaders() : { ...this.proxyHeaders };
|
|
1972
|
+
if (proxy.username || proxy.password) {
|
|
1973
|
+
const auth = `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`;
|
|
1974
|
+
headers["Proxy-Authorization"] = `Basic ${Buffer.from(auth).toString("base64")}`;
|
|
1975
|
+
}
|
|
1976
|
+
if (!headers["Proxy-Connection"]) headers["Proxy-Connection"] = this.keepAlive ? "Keep-Alive" : "close";
|
|
1977
|
+
for (const name of Object.keys(headers)) {
|
|
1978
|
+
const value = headers[name];
|
|
1979
|
+
if (value) req.setHeader(name, value);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
async connect(req, opts) {
|
|
1983
|
+
req._header = null;
|
|
1984
|
+
if (!req.path.includes("://")) this.setRequestProps(req, opts);
|
|
1985
|
+
let first;
|
|
1986
|
+
let endOfHeaders;
|
|
1987
|
+
debug("Regenerating stored HTTP header string for request");
|
|
1988
|
+
req._implicitHeader();
|
|
1989
|
+
if (req.outputData && req.outputData.length > 0) {
|
|
1990
|
+
debug("Patching connection write() output buffer with updated header");
|
|
1991
|
+
first = req.outputData[0].data;
|
|
1992
|
+
endOfHeaders = first.indexOf("\r\n\r\n") + 4;
|
|
1993
|
+
req.outputData[0].data = req._header + first.substring(endOfHeaders);
|
|
1994
|
+
debug("Output buffer: %o", req.outputData[0].data);
|
|
1995
|
+
}
|
|
1996
|
+
let socket;
|
|
1997
|
+
if (this.proxy.protocol === "https:") {
|
|
1998
|
+
debug("Creating `tls.Socket`: %o", this.connectOpts);
|
|
1999
|
+
socket = tls.connect(this.connectOpts);
|
|
2000
|
+
} else {
|
|
2001
|
+
debug("Creating `net.Socket`: %o", this.connectOpts);
|
|
2002
|
+
socket = net.connect(this.connectOpts);
|
|
2003
|
+
}
|
|
2004
|
+
await (0, events_1.once)(socket, "connect");
|
|
2005
|
+
return socket;
|
|
2006
|
+
}
|
|
2007
|
+
};
|
|
2008
|
+
HttpProxyAgent.protocols = ["http", "https"];
|
|
2009
|
+
exports.HttpProxyAgent = HttpProxyAgent;
|
|
2010
|
+
function omit(obj, ...keys) {
|
|
2011
|
+
const ret = {};
|
|
2012
|
+
let key;
|
|
2013
|
+
for (key in obj) if (!keys.includes(key)) ret[key] = obj[key];
|
|
2014
|
+
return ret;
|
|
2015
|
+
}
|
|
2016
|
+
}));
|
|
2017
|
+
//#endregion
|
|
2018
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/policies/proxyPolicy.js
|
|
2019
|
+
var import_dist = require_dist$2();
|
|
2020
|
+
var import_dist$1 = require_dist();
|
|
2021
|
+
const HTTPS_PROXY = "HTTPS_PROXY";
|
|
2022
|
+
const HTTP_PROXY = "HTTP_PROXY";
|
|
2023
|
+
const ALL_PROXY = "ALL_PROXY";
|
|
2024
|
+
const NO_PROXY = "NO_PROXY";
|
|
2025
|
+
/**
|
|
2026
|
+
* The programmatic identifier of the proxyPolicy.
|
|
2027
|
+
*/
|
|
2028
|
+
const proxyPolicyName = "proxyPolicy";
|
|
2029
|
+
/**
|
|
2030
|
+
* Stores the patterns specified in NO_PROXY environment variable.
|
|
2031
|
+
* @internal
|
|
2032
|
+
*/
|
|
2033
|
+
const globalNoProxyList = [];
|
|
2034
|
+
let noProxyListLoaded = false;
|
|
2035
|
+
/** A cache of whether a host should bypass the proxy. */
|
|
2036
|
+
const globalBypassedMap = /* @__PURE__ */ new Map();
|
|
2037
|
+
function getEnvironmentValue(name) {
|
|
2038
|
+
if (process.env[name]) return process.env[name];
|
|
2039
|
+
else if (process.env[name.toLowerCase()]) return process.env[name.toLowerCase()];
|
|
2040
|
+
}
|
|
2041
|
+
function loadEnvironmentProxyValue() {
|
|
2042
|
+
if (!process) return;
|
|
2043
|
+
const httpsProxy = getEnvironmentValue(HTTPS_PROXY);
|
|
2044
|
+
const allProxy = getEnvironmentValue(ALL_PROXY);
|
|
2045
|
+
const httpProxy = getEnvironmentValue(HTTP_PROXY);
|
|
2046
|
+
return httpsProxy || allProxy || httpProxy;
|
|
2047
|
+
}
|
|
2048
|
+
/**
|
|
2049
|
+
* Check whether the host of a given `uri` matches any pattern in the no proxy list.
|
|
2050
|
+
* If there's a match, any request sent to the same host shouldn't have the proxy settings set.
|
|
2051
|
+
* This implementation is a port of https://github.com/Azure/azure-sdk-for-net/blob/8cca811371159e527159c7eb65602477898683e2/sdk/core/Azure.Core/src/Pipeline/Internal/HttpEnvironmentProxy.cs#L210
|
|
2052
|
+
*/
|
|
2053
|
+
function isBypassed(uri, noProxyList, bypassedMap) {
|
|
2054
|
+
if (noProxyList.length === 0) return false;
|
|
2055
|
+
const host = new URL(uri).hostname;
|
|
2056
|
+
if (bypassedMap?.has(host)) return bypassedMap.get(host);
|
|
2057
|
+
let isBypassedFlag = false;
|
|
2058
|
+
for (const pattern of noProxyList) if (pattern[0] === ".") {
|
|
2059
|
+
if (host.endsWith(pattern)) isBypassedFlag = true;
|
|
2060
|
+
else if (host.length === pattern.length - 1 && host === pattern.slice(1)) isBypassedFlag = true;
|
|
2061
|
+
} else if (host === pattern) isBypassedFlag = true;
|
|
2062
|
+
bypassedMap?.set(host, isBypassedFlag);
|
|
2063
|
+
return isBypassedFlag;
|
|
2064
|
+
}
|
|
2065
|
+
function loadNoProxy() {
|
|
2066
|
+
const noProxy = getEnvironmentValue(NO_PROXY);
|
|
2067
|
+
noProxyListLoaded = true;
|
|
2068
|
+
if (noProxy) return noProxy.split(",").map((item) => item.trim()).filter((item) => item.length);
|
|
2069
|
+
return [];
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
* This method attempts to parse a proxy URL from the environment
|
|
2073
|
+
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
2074
|
+
*/
|
|
2075
|
+
function getDefaultProxySettingsInternal() {
|
|
2076
|
+
const envProxy = loadEnvironmentProxyValue();
|
|
2077
|
+
return envProxy ? new URL(envProxy) : void 0;
|
|
2078
|
+
}
|
|
2079
|
+
function getUrlFromProxySettings(settings) {
|
|
2080
|
+
let parsedProxyUrl;
|
|
2081
|
+
try {
|
|
2082
|
+
parsedProxyUrl = new URL(settings.host);
|
|
2083
|
+
} catch {
|
|
2084
|
+
throw new Error(`Expecting a valid host string in proxy settings, but found "${settings.host}".`);
|
|
2085
|
+
}
|
|
2086
|
+
parsedProxyUrl.port = String(settings.port);
|
|
2087
|
+
if (settings.username) parsedProxyUrl.username = settings.username;
|
|
2088
|
+
if (settings.password) parsedProxyUrl.password = settings.password;
|
|
2089
|
+
return parsedProxyUrl;
|
|
2090
|
+
}
|
|
2091
|
+
function setProxyAgentOnRequest(request, cachedAgents, proxyUrl) {
|
|
2092
|
+
if (request.agent) return;
|
|
2093
|
+
const isInsecure = new URL(request.url).protocol !== "https:";
|
|
2094
|
+
if (request.tlsSettings) logger$1.warning("TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.");
|
|
2095
|
+
const headers = request.headers.toJSON();
|
|
2096
|
+
if (isInsecure) {
|
|
2097
|
+
if (!cachedAgents.httpProxyAgent) cachedAgents.httpProxyAgent = new import_dist$1.HttpProxyAgent(proxyUrl, { headers });
|
|
2098
|
+
request.agent = cachedAgents.httpProxyAgent;
|
|
2099
|
+
} else {
|
|
2100
|
+
if (!cachedAgents.httpsProxyAgent) cachedAgents.httpsProxyAgent = new import_dist.HttpsProxyAgent(proxyUrl, { headers });
|
|
2101
|
+
request.agent = cachedAgents.httpsProxyAgent;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* A policy that allows one to apply proxy settings to all requests.
|
|
2106
|
+
* If not passed static settings, they will be retrieved from the HTTPS_PROXY
|
|
2107
|
+
* or HTTP_PROXY environment variables.
|
|
2108
|
+
* @param proxySettings - ProxySettings to use on each request.
|
|
2109
|
+
* @param options - additional settings, for example, custom NO_PROXY patterns
|
|
2110
|
+
*/
|
|
2111
|
+
function proxyPolicy$1(proxySettings, options) {
|
|
2112
|
+
if (!noProxyListLoaded) globalNoProxyList.push(...loadNoProxy());
|
|
2113
|
+
const defaultProxy = proxySettings ? getUrlFromProxySettings(proxySettings) : getDefaultProxySettingsInternal();
|
|
2114
|
+
const cachedAgents = {};
|
|
2115
|
+
return {
|
|
2116
|
+
name: proxyPolicyName,
|
|
2117
|
+
async sendRequest(request, next) {
|
|
2118
|
+
if (!request.proxySettings && defaultProxy && !isBypassed(request.url, options?.customNoProxyList ?? globalNoProxyList, options?.customNoProxyList ? void 0 : globalBypassedMap)) setProxyAgentOnRequest(request, cachedAgents, defaultProxy);
|
|
2119
|
+
else if (request.proxySettings) setProxyAgentOnRequest(request, cachedAgents, getUrlFromProxySettings(request.proxySettings));
|
|
2120
|
+
return next(request);
|
|
2121
|
+
}
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
//#endregion
|
|
2125
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/policies/agentPolicy.js
|
|
2126
|
+
/**
|
|
2127
|
+
* Name of the Agent Policy
|
|
2128
|
+
*/
|
|
2129
|
+
const agentPolicyName = "agentPolicy";
|
|
2130
|
+
/**
|
|
2131
|
+
* Gets a pipeline policy that sets http.agent
|
|
2132
|
+
*/
|
|
2133
|
+
function agentPolicy$1(agent) {
|
|
2134
|
+
return {
|
|
2135
|
+
name: agentPolicyName,
|
|
2136
|
+
sendRequest: async (req, next) => {
|
|
2137
|
+
if (!req.agent) req.agent = agent;
|
|
2138
|
+
return next(req);
|
|
2139
|
+
}
|
|
2140
|
+
};
|
|
2141
|
+
}
|
|
2142
|
+
//#endregion
|
|
2143
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/policies/tlsPolicy.js
|
|
2144
|
+
/**
|
|
2145
|
+
* Name of the TLS Policy
|
|
2146
|
+
*/
|
|
2147
|
+
const tlsPolicyName = "tlsPolicy";
|
|
2148
|
+
/**
|
|
2149
|
+
* Gets a pipeline policy that adds the client certificate to the HttpClient agent for authentication.
|
|
2150
|
+
*/
|
|
2151
|
+
function tlsPolicy$1(tlsSettings) {
|
|
2152
|
+
return {
|
|
2153
|
+
name: tlsPolicyName,
|
|
2154
|
+
sendRequest: async (req, next) => {
|
|
2155
|
+
if (!req.tlsSettings) req.tlsSettings = tlsSettings;
|
|
2156
|
+
return next(req);
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
//#endregion
|
|
2161
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/typeGuards.js
|
|
2162
|
+
function isNodeReadableStream(x) {
|
|
2163
|
+
return Boolean(x && typeof x["pipe"] === "function");
|
|
2164
|
+
}
|
|
2165
|
+
function isWebReadableStream(x) {
|
|
2166
|
+
return Boolean(x && typeof x.getReader === "function" && typeof x.tee === "function");
|
|
2167
|
+
}
|
|
2168
|
+
function isBinaryBody(body) {
|
|
2169
|
+
return body !== void 0 && (body instanceof Uint8Array || isReadableStream(body) || typeof body === "function" || body instanceof Blob);
|
|
2170
|
+
}
|
|
2171
|
+
function isReadableStream(x) {
|
|
2172
|
+
return isNodeReadableStream(x) || isWebReadableStream(x);
|
|
2173
|
+
}
|
|
2174
|
+
function isBlob(x) {
|
|
2175
|
+
return typeof x.stream === "function";
|
|
2176
|
+
}
|
|
2177
|
+
//#endregion
|
|
2178
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/util/concat.js
|
|
2179
|
+
async function* streamAsyncIterator() {
|
|
2180
|
+
const reader = this.getReader();
|
|
2181
|
+
try {
|
|
2182
|
+
while (true) {
|
|
2183
|
+
const { done, value } = await reader.read();
|
|
2184
|
+
if (done) return;
|
|
2185
|
+
yield value;
|
|
2186
|
+
}
|
|
2187
|
+
} finally {
|
|
2188
|
+
reader.releaseLock();
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
function makeAsyncIterable(webStream) {
|
|
2192
|
+
if (!webStream[Symbol.asyncIterator]) webStream[Symbol.asyncIterator] = streamAsyncIterator.bind(webStream);
|
|
2193
|
+
if (!webStream.values) webStream.values = streamAsyncIterator.bind(webStream);
|
|
2194
|
+
}
|
|
2195
|
+
function ensureNodeStream(stream) {
|
|
2196
|
+
if (stream instanceof ReadableStream) {
|
|
2197
|
+
makeAsyncIterable(stream);
|
|
2198
|
+
return Readable.fromWeb(stream);
|
|
2199
|
+
} else return stream;
|
|
2200
|
+
}
|
|
2201
|
+
function toStream(source) {
|
|
2202
|
+
if (source instanceof Uint8Array) return Readable.from(Buffer.from(source));
|
|
2203
|
+
else if (isBlob(source)) return ensureNodeStream(source.stream());
|
|
2204
|
+
else return ensureNodeStream(source);
|
|
2205
|
+
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Utility function that concatenates a set of binary inputs into one combined output.
|
|
2208
|
+
*
|
|
2209
|
+
* @param sources - array of sources for the concatenation
|
|
2210
|
+
* @returns - in Node, a (() =\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.
|
|
2211
|
+
* In browser, returns a `Blob` representing all the concatenated inputs.
|
|
2212
|
+
*
|
|
2213
|
+
* @internal
|
|
2214
|
+
*/
|
|
2215
|
+
async function concat(sources) {
|
|
2216
|
+
return function() {
|
|
2217
|
+
const streams = sources.map((x) => typeof x === "function" ? x() : x).map(toStream);
|
|
2218
|
+
return Readable.from((async function* () {
|
|
2219
|
+
for (const stream of streams) for await (const chunk of stream) yield chunk;
|
|
2220
|
+
})());
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
//#endregion
|
|
2224
|
+
//#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.2/node_modules/@typespec/ts-http-runtime/dist/esm/policies/multipartPolicy.js
|
|
2225
|
+
function generateBoundary() {
|
|
2226
|
+
return `----AzSDKFormBoundary${randomUUID()}`;
|
|
2227
|
+
}
|
|
2228
|
+
function encodeHeaders(headers) {
|
|
2229
|
+
let result = "";
|
|
2230
|
+
for (const [key, value] of headers) result += `${key}: ${value}\r\n`;
|
|
2231
|
+
return result;
|
|
2232
|
+
}
|
|
2233
|
+
function getLength(source) {
|
|
2234
|
+
if (source instanceof Uint8Array) return source.byteLength;
|
|
2235
|
+
else if (isBlob(source)) return source.size === -1 ? void 0 : source.size;
|
|
2236
|
+
else return;
|
|
2237
|
+
}
|
|
2238
|
+
function getTotalLength(sources) {
|
|
2239
|
+
let total = 0;
|
|
2240
|
+
for (const source of sources) {
|
|
2241
|
+
const partLength = getLength(source);
|
|
2242
|
+
if (partLength === void 0) return;
|
|
2243
|
+
else total += partLength;
|
|
2244
|
+
}
|
|
2245
|
+
return total;
|
|
2246
|
+
}
|
|
2247
|
+
async function buildRequestBody(request, parts, boundary) {
|
|
2248
|
+
const sources = [
|
|
2249
|
+
stringToUint8Array$1(`--${boundary}`, "utf-8"),
|
|
2250
|
+
...parts.flatMap((part) => [
|
|
2251
|
+
stringToUint8Array$1("\r\n", "utf-8"),
|
|
2252
|
+
stringToUint8Array$1(encodeHeaders(part.headers), "utf-8"),
|
|
2253
|
+
stringToUint8Array$1("\r\n", "utf-8"),
|
|
2254
|
+
part.body,
|
|
2255
|
+
stringToUint8Array$1(`\r\n--${boundary}`, "utf-8")
|
|
2256
|
+
]),
|
|
2257
|
+
stringToUint8Array$1("--\r\n\r\n", "utf-8")
|
|
2258
|
+
];
|
|
2259
|
+
const contentLength = getTotalLength(sources);
|
|
2260
|
+
if (contentLength) request.headers.set("Content-Length", contentLength);
|
|
2261
|
+
request.body = await concat(sources);
|
|
2262
|
+
}
|
|
2263
|
+
/**
|
|
2264
|
+
* Name of multipart policy
|
|
2265
|
+
*/
|
|
2266
|
+
const multipartPolicyName$1 = "multipartPolicy";
|
|
2267
|
+
const maxBoundaryLength = 70;
|
|
2268
|
+
const validBoundaryCharacters = /* @__PURE__ */ new Set(`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'()+,-./:=?`);
|
|
2269
|
+
function assertValidBoundary(boundary) {
|
|
2270
|
+
if (boundary.length > maxBoundaryLength) throw new Error(`Multipart boundary "${boundary}" exceeds maximum length of 70 characters`);
|
|
2271
|
+
if (Array.from(boundary).some((x) => !validBoundaryCharacters.has(x))) throw new Error(`Multipart boundary "${boundary}" contains invalid characters`);
|
|
2272
|
+
}
|
|
2273
|
+
/**
|
|
2274
|
+
* Pipeline policy for multipart requests
|
|
2275
|
+
*/
|
|
2276
|
+
function multipartPolicy$1() {
|
|
2277
|
+
return {
|
|
2278
|
+
name: multipartPolicyName$1,
|
|
2279
|
+
async sendRequest(request, next) {
|
|
2280
|
+
if (!request.multipartBody) return next(request);
|
|
2281
|
+
if (request.body) throw new Error("multipartBody and regular body cannot be set at the same time");
|
|
2282
|
+
let boundary = request.multipartBody.boundary;
|
|
2283
|
+
const contentTypeHeader = request.headers.get("Content-Type") ?? "multipart/mixed";
|
|
2284
|
+
const parsedHeader = contentTypeHeader.match(/^(multipart\/[^ ;]+)(?:; *boundary=(.+))?$/);
|
|
2285
|
+
if (!parsedHeader) throw new Error(`Got multipart request body, but content-type header was not multipart: ${contentTypeHeader}`);
|
|
2286
|
+
const [, contentType, parsedBoundary] = parsedHeader;
|
|
2287
|
+
if (parsedBoundary && boundary && parsedBoundary !== boundary) throw new Error(`Multipart boundary was specified as ${parsedBoundary} in the header, but got ${boundary} in the request body`);
|
|
2288
|
+
boundary ??= parsedBoundary;
|
|
2289
|
+
if (boundary) assertValidBoundary(boundary);
|
|
2290
|
+
else boundary = generateBoundary();
|
|
2291
|
+
request.headers.set("Content-Type", `${contentType}; boundary=${boundary}`);
|
|
2292
|
+
await buildRequestBody(request, request.multipartBody.parts, boundary);
|
|
2293
|
+
request.multipartBody = void 0;
|
|
2294
|
+
return next(request);
|
|
2295
|
+
}
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
//#endregion
|
|
2299
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/pipeline.js
|
|
2300
|
+
/**
|
|
2301
|
+
* Creates a totally empty pipeline.
|
|
2302
|
+
* Useful for testing or creating a custom one.
|
|
2303
|
+
*/
|
|
2304
|
+
function createEmptyPipeline() {
|
|
2305
|
+
return createEmptyPipeline$1();
|
|
2306
|
+
}
|
|
2307
|
+
//#endregion
|
|
2308
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/log.js
|
|
2309
|
+
const logger = createClientLogger("core-rest-pipeline");
|
|
2310
|
+
//#endregion
|
|
2311
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/logPolicy.js
|
|
2312
|
+
/**
|
|
2313
|
+
* A policy that logs all requests and responses.
|
|
2314
|
+
* @param options - Options to configure logPolicy.
|
|
2315
|
+
*/
|
|
2316
|
+
function logPolicy(options = {}) {
|
|
2317
|
+
return logPolicy$1({
|
|
2318
|
+
logger: logger.info,
|
|
2319
|
+
...options
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
//#endregion
|
|
2323
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/redirectPolicy.js
|
|
2324
|
+
/**
|
|
2325
|
+
* A policy to follow Location headers from the server in order
|
|
2326
|
+
* to support server-side redirection.
|
|
2327
|
+
* In the browser, this policy is not used.
|
|
2328
|
+
* @param options - Options to control policy behavior.
|
|
2329
|
+
*/
|
|
2330
|
+
function redirectPolicy(options = {}) {
|
|
2331
|
+
return redirectPolicy$1(options);
|
|
2332
|
+
}
|
|
2333
|
+
//#endregion
|
|
2334
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/util/userAgentPlatform.js
|
|
2335
|
+
/**
|
|
2336
|
+
* @internal
|
|
2337
|
+
*/
|
|
2338
|
+
function getHeaderName() {
|
|
2339
|
+
return "User-Agent";
|
|
2340
|
+
}
|
|
2341
|
+
/**
|
|
2342
|
+
* @internal
|
|
2343
|
+
*/
|
|
2344
|
+
async function setPlatformSpecificData(map) {
|
|
2345
|
+
if (process$1 && process$1.versions) {
|
|
2346
|
+
const osInfo = `${os.type()} ${os.release()}; ${os.arch()}`;
|
|
2347
|
+
const versions = process$1.versions;
|
|
2348
|
+
if (versions.bun) map.set("Bun", `${versions.bun} (${osInfo})`);
|
|
2349
|
+
else if (versions.deno) map.set("Deno", `${versions.deno} (${osInfo})`);
|
|
2350
|
+
else if (versions.node) map.set("Node", `${versions.node} (${osInfo})`);
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
//#endregion
|
|
2354
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/constants.js
|
|
2355
|
+
const SDK_VERSION = "1.22.2";
|
|
2356
|
+
//#endregion
|
|
2357
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/util/userAgent.js
|
|
2358
|
+
function getUserAgentString(telemetryInfo) {
|
|
2359
|
+
const parts = [];
|
|
2360
|
+
for (const [key, value] of telemetryInfo) {
|
|
2361
|
+
const token = value ? `${key}/${value}` : key;
|
|
2362
|
+
parts.push(token);
|
|
2363
|
+
}
|
|
2364
|
+
return parts.join(" ");
|
|
2365
|
+
}
|
|
2366
|
+
/**
|
|
2367
|
+
* @internal
|
|
2368
|
+
*/
|
|
2369
|
+
function getUserAgentHeaderName() {
|
|
2370
|
+
return getHeaderName();
|
|
2371
|
+
}
|
|
2372
|
+
/**
|
|
2373
|
+
* @internal
|
|
2374
|
+
*/
|
|
2375
|
+
async function getUserAgentValue(prefix) {
|
|
2376
|
+
const runtimeInfo = /* @__PURE__ */ new Map();
|
|
2377
|
+
runtimeInfo.set("core-rest-pipeline", SDK_VERSION);
|
|
2378
|
+
await setPlatformSpecificData(runtimeInfo);
|
|
2379
|
+
const defaultAgent = getUserAgentString(runtimeInfo);
|
|
2380
|
+
return prefix ? `${prefix} ${defaultAgent}` : defaultAgent;
|
|
2381
|
+
}
|
|
2382
|
+
//#endregion
|
|
2383
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/userAgentPolicy.js
|
|
2384
|
+
const UserAgentHeaderName = getUserAgentHeaderName();
|
|
2385
|
+
/**
|
|
2386
|
+
* The programmatic identifier of the userAgentPolicy.
|
|
2387
|
+
*/
|
|
2388
|
+
const userAgentPolicyName = "userAgentPolicy";
|
|
2389
|
+
/**
|
|
2390
|
+
* A policy that sets the User-Agent header (or equivalent) to reflect
|
|
2391
|
+
* the library version.
|
|
2392
|
+
* @param options - Options to customize the user agent value.
|
|
2393
|
+
*/
|
|
2394
|
+
function userAgentPolicy(options = {}) {
|
|
2395
|
+
const userAgentValue = getUserAgentValue(options.userAgentPrefix);
|
|
2396
|
+
return {
|
|
2397
|
+
name: userAgentPolicyName,
|
|
2398
|
+
async sendRequest(request, next) {
|
|
2399
|
+
if (!request.headers.has(UserAgentHeaderName)) request.headers.set(UserAgentHeaderName, await userAgentValue);
|
|
2400
|
+
return next(request);
|
|
2401
|
+
}
|
|
2402
|
+
};
|
|
2403
|
+
}
|
|
2404
|
+
//#endregion
|
|
2405
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/util/file.js
|
|
2406
|
+
/**
|
|
2407
|
+
* Private symbol used as key on objects created using createFile containing the
|
|
2408
|
+
* original source of the file object.
|
|
2409
|
+
*
|
|
2410
|
+
* This is used in Node to access the original Node stream without using Blob#stream, which
|
|
2411
|
+
* returns a web stream. This is done to avoid a couple of bugs to do with Blob#stream and
|
|
2412
|
+
* Readable#to/fromWeb in Node versions we support:
|
|
2413
|
+
* - https://github.com/nodejs/node/issues/42694 (fixed in Node 18.14)
|
|
2414
|
+
* - https://github.com/nodejs/node/issues/48916 (fixed in Node 20.6)
|
|
2415
|
+
*
|
|
2416
|
+
* Once these versions are no longer supported, we may be able to stop doing this.
|
|
2417
|
+
*
|
|
2418
|
+
* @internal
|
|
2419
|
+
*/
|
|
2420
|
+
const rawContent = Symbol("rawContent");
|
|
2421
|
+
/**
|
|
2422
|
+
* Type guard to check if a given object is a blob-like object with a raw content property.
|
|
2423
|
+
*/
|
|
2424
|
+
function hasRawContent(x) {
|
|
2425
|
+
return typeof x[rawContent] === "function";
|
|
2426
|
+
}
|
|
2427
|
+
/**
|
|
2428
|
+
* Extract the raw content from a given blob-like object. If the input was created using createFile
|
|
2429
|
+
* or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.
|
|
2430
|
+
* For true instances of Blob and File, returns the actual blob.
|
|
2431
|
+
*
|
|
2432
|
+
* @internal
|
|
2433
|
+
*/
|
|
2434
|
+
function getRawContent(blob) {
|
|
2435
|
+
if (hasRawContent(blob)) return blob[rawContent]();
|
|
2436
|
+
else return blob;
|
|
2437
|
+
}
|
|
2438
|
+
//#endregion
|
|
2439
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/multipartPolicy.js
|
|
2440
|
+
/**
|
|
2441
|
+
* Name of multipart policy
|
|
2442
|
+
*/
|
|
2443
|
+
const multipartPolicyName = multipartPolicyName$1;
|
|
2444
|
+
/**
|
|
2445
|
+
* Pipeline policy for multipart requests
|
|
2446
|
+
*/
|
|
2447
|
+
function multipartPolicy() {
|
|
2448
|
+
const tspPolicy = multipartPolicy$1();
|
|
2449
|
+
return {
|
|
2450
|
+
name: multipartPolicyName,
|
|
2451
|
+
sendRequest: async (request, next) => {
|
|
2452
|
+
if (request.multipartBody) {
|
|
2453
|
+
for (const part of request.multipartBody.parts) if (hasRawContent(part.body)) part.body = getRawContent(part.body);
|
|
2454
|
+
}
|
|
2455
|
+
return tspPolicy.sendRequest(request, next);
|
|
2456
|
+
}
|
|
2457
|
+
};
|
|
2458
|
+
}
|
|
2459
|
+
//#endregion
|
|
2460
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/decompressResponsePolicy.js
|
|
2461
|
+
/**
|
|
2462
|
+
* A policy to enable response decompression according to Accept-Encoding header
|
|
2463
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
|
|
2464
|
+
*/
|
|
2465
|
+
function decompressResponsePolicy() {
|
|
2466
|
+
return decompressResponsePolicy$1();
|
|
2467
|
+
}
|
|
2468
|
+
//#endregion
|
|
2469
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/defaultRetryPolicy.js
|
|
2470
|
+
/**
|
|
2471
|
+
* A policy that retries according to three strategies:
|
|
2472
|
+
* - When the server sends a 429 response with a Retry-After header.
|
|
2473
|
+
* - When there are errors in the underlying transport layer (e.g. DNS lookup failures).
|
|
2474
|
+
* - Or otherwise if the outgoing request fails, it will retry with an exponentially increasing delay.
|
|
2475
|
+
*/
|
|
2476
|
+
function defaultRetryPolicy(options = {}) {
|
|
2477
|
+
return defaultRetryPolicy$1(options);
|
|
2478
|
+
}
|
|
2479
|
+
//#endregion
|
|
2480
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/formDataPolicy.js
|
|
2481
|
+
/**
|
|
2482
|
+
* A policy that encodes FormData on the request into the body.
|
|
2483
|
+
*/
|
|
2484
|
+
function formDataPolicy() {
|
|
2485
|
+
return formDataPolicy$1();
|
|
2486
|
+
}
|
|
2487
|
+
//#endregion
|
|
2488
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/proxyPolicy.js
|
|
2489
|
+
/**
|
|
2490
|
+
* A policy that allows one to apply proxy settings to all requests.
|
|
2491
|
+
* If not passed static settings, they will be retrieved from the HTTPS_PROXY
|
|
2492
|
+
* or HTTP_PROXY environment variables.
|
|
2493
|
+
* @param proxySettings - ProxySettings to use on each request.
|
|
2494
|
+
* @param options - additional settings, for example, custom NO_PROXY patterns
|
|
2495
|
+
*/
|
|
2496
|
+
function proxyPolicy(proxySettings, options) {
|
|
2497
|
+
return proxyPolicy$1(proxySettings, options);
|
|
2498
|
+
}
|
|
2499
|
+
//#endregion
|
|
2500
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/setClientRequestIdPolicy.js
|
|
2501
|
+
/**
|
|
2502
|
+
* The programmatic identifier of the setClientRequestIdPolicy.
|
|
2503
|
+
*/
|
|
2504
|
+
const setClientRequestIdPolicyName = "setClientRequestIdPolicy";
|
|
2505
|
+
/**
|
|
2506
|
+
* Each PipelineRequest gets a unique id upon creation.
|
|
2507
|
+
* This policy passes that unique id along via an HTTP header to enable better
|
|
2508
|
+
* telemetry and tracing.
|
|
2509
|
+
* @param requestIdHeaderName - The name of the header to pass the request ID to.
|
|
2510
|
+
*/
|
|
2511
|
+
function setClientRequestIdPolicy(requestIdHeaderName = "x-ms-client-request-id") {
|
|
2512
|
+
return {
|
|
2513
|
+
name: setClientRequestIdPolicyName,
|
|
2514
|
+
async sendRequest(request, next) {
|
|
2515
|
+
if (!request.headers.has(requestIdHeaderName)) request.headers.set(requestIdHeaderName, request.requestId);
|
|
2516
|
+
return next(request);
|
|
2517
|
+
}
|
|
2518
|
+
};
|
|
2519
|
+
}
|
|
2520
|
+
//#endregion
|
|
2521
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/agentPolicy.js
|
|
2522
|
+
/**
|
|
2523
|
+
* Gets a pipeline policy that sets http.agent
|
|
2524
|
+
*/
|
|
2525
|
+
function agentPolicy(agent) {
|
|
2526
|
+
return agentPolicy$1(agent);
|
|
2527
|
+
}
|
|
2528
|
+
//#endregion
|
|
2529
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/tlsPolicy.js
|
|
2530
|
+
/**
|
|
2531
|
+
* Gets a pipeline policy that adds the client certificate to the HttpClient agent for authentication.
|
|
2532
|
+
*/
|
|
2533
|
+
function tlsPolicy(tlsSettings) {
|
|
2534
|
+
return tlsPolicy$1(tlsSettings);
|
|
2535
|
+
}
|
|
2536
|
+
//#endregion
|
|
2537
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/restError.js
|
|
2538
|
+
/**
|
|
2539
|
+
* A custom error type for failed pipeline requests.
|
|
2540
|
+
*/
|
|
2541
|
+
const RestError = RestError$1;
|
|
2542
|
+
/**
|
|
2543
|
+
* Typeguard for RestError
|
|
2544
|
+
* @param e - Something caught by a catch clause.
|
|
2545
|
+
*/
|
|
2546
|
+
function isRestError(e) {
|
|
2547
|
+
return isRestError$1(e);
|
|
2548
|
+
}
|
|
2549
|
+
//#endregion
|
|
2550
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/tracingPolicy.js
|
|
2551
|
+
/**
|
|
2552
|
+
* The programmatic identifier of the tracingPolicy.
|
|
2553
|
+
*/
|
|
2554
|
+
const tracingPolicyName = "tracingPolicy";
|
|
2555
|
+
/**
|
|
2556
|
+
* A simple policy to create OpenTelemetry Spans for each request made by the pipeline
|
|
2557
|
+
* that has SpanOptions with a parent.
|
|
2558
|
+
* Requests made without a parent Span will not be recorded.
|
|
2559
|
+
* @param options - Options to configure the telemetry logged by the tracing policy.
|
|
2560
|
+
*/
|
|
2561
|
+
function tracingPolicy(options = {}) {
|
|
2562
|
+
const userAgentPromise = getUserAgentValue(options.userAgentPrefix);
|
|
2563
|
+
const sanitizer = new Sanitizer({ additionalAllowedQueryParameters: options.additionalAllowedQueryParameters });
|
|
2564
|
+
const tracingClient = tryCreateTracingClient();
|
|
2565
|
+
return {
|
|
2566
|
+
name: tracingPolicyName,
|
|
2567
|
+
async sendRequest(request, next) {
|
|
2568
|
+
if (!tracingClient) return next(request);
|
|
2569
|
+
const userAgent = await userAgentPromise;
|
|
2570
|
+
const spanAttributes = {
|
|
2571
|
+
"http.url": sanitizer.sanitizeUrl(request.url),
|
|
2572
|
+
"http.method": request.method,
|
|
2573
|
+
"http.user_agent": userAgent,
|
|
2574
|
+
requestId: request.requestId
|
|
2575
|
+
};
|
|
2576
|
+
if (userAgent) spanAttributes["http.user_agent"] = userAgent;
|
|
2577
|
+
const { span, tracingContext } = tryCreateSpan(tracingClient, request, spanAttributes) ?? {};
|
|
2578
|
+
if (!span || !tracingContext) return next(request);
|
|
2579
|
+
try {
|
|
2580
|
+
const response = await tracingClient.withContext(tracingContext, next, request);
|
|
2581
|
+
tryProcessResponse(span, response);
|
|
2582
|
+
return response;
|
|
2583
|
+
} catch (err) {
|
|
2584
|
+
tryProcessError(span, err);
|
|
2585
|
+
throw err;
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
function tryCreateTracingClient() {
|
|
2591
|
+
try {
|
|
2592
|
+
return createTracingClient({
|
|
2593
|
+
namespace: "",
|
|
2594
|
+
packageName: "@azure/core-rest-pipeline",
|
|
2595
|
+
packageVersion: SDK_VERSION
|
|
2596
|
+
});
|
|
2597
|
+
} catch (e) {
|
|
2598
|
+
logger.warning(`Error when creating the TracingClient: ${getErrorMessage(e)}`);
|
|
2599
|
+
return;
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
function tryCreateSpan(tracingClient, request, spanAttributes) {
|
|
2603
|
+
try {
|
|
2604
|
+
const { span, updatedOptions } = tracingClient.startSpan(`HTTP ${request.method}`, { tracingOptions: request.tracingOptions }, {
|
|
2605
|
+
spanKind: "client",
|
|
2606
|
+
spanAttributes
|
|
2607
|
+
});
|
|
2608
|
+
if (!span.isRecording()) {
|
|
2609
|
+
span.end();
|
|
2610
|
+
return;
|
|
2611
|
+
}
|
|
2612
|
+
const headers = tracingClient.createRequestHeaders(updatedOptions.tracingOptions.tracingContext);
|
|
2613
|
+
for (const [key, value] of Object.entries(headers)) request.headers.set(key, value);
|
|
2614
|
+
return {
|
|
2615
|
+
span,
|
|
2616
|
+
tracingContext: updatedOptions.tracingOptions.tracingContext
|
|
2617
|
+
};
|
|
2618
|
+
} catch (e) {
|
|
2619
|
+
logger.warning(`Skipping creating a tracing span due to an error: ${getErrorMessage(e)}`);
|
|
2620
|
+
return;
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
function tryProcessError(span, error) {
|
|
2624
|
+
try {
|
|
2625
|
+
span.setStatus({
|
|
2626
|
+
status: "error",
|
|
2627
|
+
error: isError(error) ? error : void 0
|
|
2628
|
+
});
|
|
2629
|
+
if (isRestError(error) && error.statusCode) span.setAttribute("http.status_code", error.statusCode);
|
|
2630
|
+
span.end();
|
|
2631
|
+
} catch (e) {
|
|
2632
|
+
logger.warning(`Skipping tracing span processing due to an error: ${getErrorMessage(e)}`);
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
function tryProcessResponse(span, response) {
|
|
2636
|
+
try {
|
|
2637
|
+
span.setAttribute("http.status_code", response.status);
|
|
2638
|
+
const serviceRequestId = response.headers.get("x-ms-request-id");
|
|
2639
|
+
if (serviceRequestId) span.setAttribute("serviceRequestId", serviceRequestId);
|
|
2640
|
+
if (response.status >= 400) span.setStatus({ status: "error" });
|
|
2641
|
+
span.end();
|
|
2642
|
+
} catch (e) {
|
|
2643
|
+
logger.warning(`Skipping tracing span processing due to an error: ${getErrorMessage(e)}`);
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
//#endregion
|
|
2647
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/util/wrapAbortSignal.js
|
|
2648
|
+
/**
|
|
2649
|
+
* Creates a native AbortSignal which reflects the state of the provided AbortSignalLike.
|
|
2650
|
+
* If the AbortSignalLike is already a native AbortSignal, it is returned as is.
|
|
2651
|
+
* @param abortSignalLike - The AbortSignalLike to wrap.
|
|
2652
|
+
* @returns - An object containing the native AbortSignal and an optional cleanup function. The cleanup function should be called when the AbortSignal is no longer needed.
|
|
2653
|
+
*/
|
|
2654
|
+
function wrapAbortSignalLike(abortSignalLike) {
|
|
2655
|
+
if (abortSignalLike instanceof AbortSignal) return { abortSignal: abortSignalLike };
|
|
2656
|
+
if (abortSignalLike.aborted) return { abortSignal: AbortSignal.abort(abortSignalLike.reason) };
|
|
2657
|
+
const controller = new AbortController();
|
|
2658
|
+
let needsCleanup = true;
|
|
2659
|
+
function cleanup() {
|
|
2660
|
+
if (needsCleanup) {
|
|
2661
|
+
abortSignalLike.removeEventListener("abort", listener);
|
|
2662
|
+
needsCleanup = false;
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
function listener() {
|
|
2666
|
+
controller.abort(abortSignalLike.reason);
|
|
2667
|
+
cleanup();
|
|
2668
|
+
}
|
|
2669
|
+
abortSignalLike.addEventListener("abort", listener);
|
|
2670
|
+
return {
|
|
2671
|
+
abortSignal: controller.signal,
|
|
2672
|
+
cleanup
|
|
2673
|
+
};
|
|
2674
|
+
}
|
|
2675
|
+
//#endregion
|
|
2676
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/wrapAbortSignalLikePolicy.js
|
|
2677
|
+
const wrapAbortSignalLikePolicyName = "wrapAbortSignalLikePolicy";
|
|
2678
|
+
/**
|
|
2679
|
+
* Policy that ensure that any AbortSignalLike is wrapped in a native AbortSignal for processing by the pipeline.
|
|
2680
|
+
* Since the ts-http-runtime expects a native AbortSignal, this policy is used to ensure that any AbortSignalLike is wrapped in a native AbortSignal.
|
|
2681
|
+
*
|
|
2682
|
+
* @returns - created policy
|
|
2683
|
+
*/
|
|
2684
|
+
function wrapAbortSignalLikePolicy() {
|
|
2685
|
+
return {
|
|
2686
|
+
name: wrapAbortSignalLikePolicyName,
|
|
2687
|
+
sendRequest: async (request, next) => {
|
|
2688
|
+
if (!request.abortSignal) return next(request);
|
|
2689
|
+
const { abortSignal, cleanup } = wrapAbortSignalLike(request.abortSignal);
|
|
2690
|
+
request.abortSignal = abortSignal;
|
|
2691
|
+
try {
|
|
2692
|
+
return await next(request);
|
|
2693
|
+
} finally {
|
|
2694
|
+
cleanup?.();
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
};
|
|
2698
|
+
}
|
|
2699
|
+
//#endregion
|
|
2700
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/createPipelineFromOptions.js
|
|
2701
|
+
/**
|
|
2702
|
+
* Create a new pipeline with a default set of customizable policies.
|
|
2703
|
+
* @param options - Options to configure a custom pipeline.
|
|
2704
|
+
*/
|
|
2705
|
+
function createPipelineFromOptions(options) {
|
|
2706
|
+
const pipeline = createEmptyPipeline();
|
|
2707
|
+
if (isNodeLike) {
|
|
2708
|
+
if (options.agent) pipeline.addPolicy(agentPolicy(options.agent));
|
|
2709
|
+
if (options.tlsOptions) pipeline.addPolicy(tlsPolicy(options.tlsOptions));
|
|
2710
|
+
pipeline.addPolicy(proxyPolicy(options.proxyOptions));
|
|
2711
|
+
pipeline.addPolicy(decompressResponsePolicy());
|
|
2712
|
+
}
|
|
2713
|
+
pipeline.addPolicy(wrapAbortSignalLikePolicy());
|
|
2714
|
+
pipeline.addPolicy(formDataPolicy(), { beforePolicies: [multipartPolicyName] });
|
|
2715
|
+
pipeline.addPolicy(userAgentPolicy(options.userAgentOptions));
|
|
2716
|
+
pipeline.addPolicy(setClientRequestIdPolicy(options.telemetryOptions?.clientRequestIdHeaderName));
|
|
2717
|
+
pipeline.addPolicy(multipartPolicy(), { afterPhase: "Deserialize" });
|
|
2718
|
+
pipeline.addPolicy(defaultRetryPolicy(options.retryOptions), { phase: "Retry" });
|
|
2719
|
+
pipeline.addPolicy(tracingPolicy({
|
|
2720
|
+
...options.userAgentOptions,
|
|
2721
|
+
...options.loggingOptions
|
|
2722
|
+
}), { afterPhase: "Retry" });
|
|
2723
|
+
if (isNodeLike) pipeline.addPolicy(redirectPolicy(options.redirectOptions), { afterPhase: "Retry" });
|
|
2724
|
+
pipeline.addPolicy(logPolicy(options.loggingOptions), { afterPhase: "Sign" });
|
|
2725
|
+
return pipeline;
|
|
2726
|
+
}
|
|
2727
|
+
//#endregion
|
|
2728
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/util/tokenCycler.js
|
|
2729
|
+
const DEFAULT_CYCLER_OPTIONS = {
|
|
2730
|
+
forcedRefreshWindowInMs: 1e3,
|
|
2731
|
+
retryIntervalInMs: 3e3,
|
|
2732
|
+
refreshWindowInMs: 1e3 * 60 * 2
|
|
2733
|
+
};
|
|
2734
|
+
/**
|
|
2735
|
+
* Converts an an unreliable access token getter (which may resolve with null)
|
|
2736
|
+
* into an AccessTokenGetter by retrying the unreliable getter in a regular
|
|
2737
|
+
* interval.
|
|
2738
|
+
*
|
|
2739
|
+
* @param getAccessToken - A function that produces a promise of an access token that may fail by returning null.
|
|
2740
|
+
* @param retryIntervalInMs - The time (in milliseconds) to wait between retry attempts.
|
|
2741
|
+
* @param refreshTimeout - The timestamp after which the refresh attempt will fail, throwing an exception.
|
|
2742
|
+
* @returns - A promise that, if it resolves, will resolve with an access token.
|
|
2743
|
+
*/
|
|
2744
|
+
async function beginRefresh(getAccessToken, retryIntervalInMs, refreshTimeout) {
|
|
2745
|
+
async function tryGetAccessToken() {
|
|
2746
|
+
if (Date.now() < refreshTimeout) try {
|
|
2747
|
+
return await getAccessToken();
|
|
2748
|
+
} catch {
|
|
2749
|
+
return null;
|
|
2750
|
+
}
|
|
2751
|
+
else {
|
|
2752
|
+
const finalToken = await getAccessToken();
|
|
2753
|
+
if (finalToken === null) throw new Error("Failed to refresh access token.");
|
|
2754
|
+
return finalToken;
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
let token = await tryGetAccessToken();
|
|
2758
|
+
while (token === null) {
|
|
2759
|
+
await delay$1(retryIntervalInMs);
|
|
2760
|
+
token = await tryGetAccessToken();
|
|
2761
|
+
}
|
|
2762
|
+
return token;
|
|
2763
|
+
}
|
|
2764
|
+
/**
|
|
2765
|
+
* Creates a token cycler from a credential, scopes, and optional settings.
|
|
2766
|
+
*
|
|
2767
|
+
* A token cycler represents a way to reliably retrieve a valid access token
|
|
2768
|
+
* from a TokenCredential. It will handle initializing the token, refreshing it
|
|
2769
|
+
* when it nears expiration, and synchronizes refresh attempts to avoid
|
|
2770
|
+
* concurrency hazards.
|
|
2771
|
+
*
|
|
2772
|
+
* @param credential - the underlying TokenCredential that provides the access
|
|
2773
|
+
* token
|
|
2774
|
+
* @param tokenCyclerOptions - optionally override default settings for the cycler
|
|
2775
|
+
*
|
|
2776
|
+
* @returns - a function that reliably produces a valid access token
|
|
2777
|
+
*/
|
|
2778
|
+
function createTokenCycler(credential, tokenCyclerOptions) {
|
|
2779
|
+
let refreshWorker = null;
|
|
2780
|
+
let token = null;
|
|
2781
|
+
let tenantId;
|
|
2782
|
+
const options = {
|
|
2783
|
+
...DEFAULT_CYCLER_OPTIONS,
|
|
2784
|
+
...tokenCyclerOptions
|
|
2785
|
+
};
|
|
2786
|
+
/**
|
|
2787
|
+
* This little holder defines several predicates that we use to construct
|
|
2788
|
+
* the rules of refreshing the token.
|
|
2789
|
+
*/
|
|
2790
|
+
const cycler = {
|
|
2791
|
+
/**
|
|
2792
|
+
* Produces true if a refresh job is currently in progress.
|
|
2793
|
+
*/
|
|
2794
|
+
get isRefreshing() {
|
|
2795
|
+
return refreshWorker !== null;
|
|
2796
|
+
},
|
|
2797
|
+
/**
|
|
2798
|
+
* Produces true if the cycler SHOULD refresh (we are within the refresh
|
|
2799
|
+
* window and not already refreshing)
|
|
2800
|
+
*/
|
|
2801
|
+
get shouldRefresh() {
|
|
2802
|
+
if (cycler.isRefreshing) return false;
|
|
2803
|
+
if (token?.refreshAfterTimestamp && token.refreshAfterTimestamp < Date.now()) return true;
|
|
2804
|
+
return (token?.expiresOnTimestamp ?? 0) - options.refreshWindowInMs < Date.now();
|
|
2805
|
+
},
|
|
2806
|
+
/**
|
|
2807
|
+
* Produces true if the cycler MUST refresh (null or nearly-expired
|
|
2808
|
+
* token).
|
|
2809
|
+
*/
|
|
2810
|
+
get mustRefresh() {
|
|
2811
|
+
return token === null || token.expiresOnTimestamp - options.forcedRefreshWindowInMs < Date.now();
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
/**
|
|
2815
|
+
* Starts a refresh job or returns the existing job if one is already
|
|
2816
|
+
* running.
|
|
2817
|
+
*/
|
|
2818
|
+
function refresh(scopes, getTokenOptions) {
|
|
2819
|
+
if (!cycler.isRefreshing) {
|
|
2820
|
+
const tryGetAccessToken = () => credential.getToken(scopes, getTokenOptions);
|
|
2821
|
+
refreshWorker = beginRefresh(tryGetAccessToken, options.retryIntervalInMs, token?.expiresOnTimestamp ?? Date.now()).then((_token) => {
|
|
2822
|
+
refreshWorker = null;
|
|
2823
|
+
token = _token;
|
|
2824
|
+
tenantId = getTokenOptions.tenantId;
|
|
2825
|
+
return token;
|
|
2826
|
+
}).catch((reason) => {
|
|
2827
|
+
refreshWorker = null;
|
|
2828
|
+
token = null;
|
|
2829
|
+
tenantId = void 0;
|
|
2830
|
+
throw reason;
|
|
2831
|
+
});
|
|
2832
|
+
}
|
|
2833
|
+
return refreshWorker;
|
|
2834
|
+
}
|
|
2835
|
+
return async (scopes, tokenOptions) => {
|
|
2836
|
+
const hasClaimChallenge = Boolean(tokenOptions.claims);
|
|
2837
|
+
const tenantIdChanged = tenantId !== tokenOptions.tenantId;
|
|
2838
|
+
if (hasClaimChallenge) token = null;
|
|
2839
|
+
if (tenantIdChanged || hasClaimChallenge || cycler.mustRefresh) return refresh(scopes, tokenOptions);
|
|
2840
|
+
if (cycler.shouldRefresh) refresh(scopes, tokenOptions);
|
|
2841
|
+
return token;
|
|
2842
|
+
};
|
|
2843
|
+
}
|
|
2844
|
+
//#endregion
|
|
2845
|
+
//#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.2/node_modules/@azure/core-rest-pipeline/dist/esm/policies/bearerTokenAuthenticationPolicy.js
|
|
2846
|
+
/**
|
|
2847
|
+
* The programmatic identifier of the bearerTokenAuthenticationPolicy.
|
|
2848
|
+
*/
|
|
2849
|
+
const bearerTokenAuthenticationPolicyName = "bearerTokenAuthenticationPolicy";
|
|
2850
|
+
/**
|
|
2851
|
+
* Try to send the given request.
|
|
2852
|
+
*
|
|
2853
|
+
* When a response is received, returns a tuple of the response received and, if the response was received
|
|
2854
|
+
* inside a thrown RestError, the RestError that was thrown.
|
|
2855
|
+
*
|
|
2856
|
+
* Otherwise, if an error was thrown while sending the request that did not provide an underlying response, it
|
|
2857
|
+
* will be rethrown.
|
|
2858
|
+
*/
|
|
2859
|
+
async function trySendRequest(request, next) {
|
|
2860
|
+
try {
|
|
2861
|
+
return [await next(request), void 0];
|
|
2862
|
+
} catch (e) {
|
|
2863
|
+
if (isRestError(e) && e.response) return [e.response, e];
|
|
2864
|
+
else throw e;
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
/**
|
|
2868
|
+
* Default authorize request handler
|
|
2869
|
+
*/
|
|
2870
|
+
async function defaultAuthorizeRequest(options) {
|
|
2871
|
+
const { scopes, getAccessToken, request } = options;
|
|
2872
|
+
const accessToken = await getAccessToken(scopes, {
|
|
2873
|
+
abortSignal: request.abortSignal,
|
|
2874
|
+
tracingOptions: request.tracingOptions,
|
|
2875
|
+
enableCae: true
|
|
2876
|
+
});
|
|
2877
|
+
if (accessToken) options.request.headers.set("Authorization", `Bearer ${accessToken.token}`);
|
|
2878
|
+
}
|
|
2879
|
+
/**
|
|
2880
|
+
* We will retrieve the challenge only if the response status code was 401,
|
|
2881
|
+
* and if the response contained the header "WWW-Authenticate" with a non-empty value.
|
|
2882
|
+
*/
|
|
2883
|
+
function isChallengeResponse(response) {
|
|
2884
|
+
return response.status === 401 && response.headers.has("WWW-Authenticate");
|
|
2885
|
+
}
|
|
2886
|
+
/**
|
|
2887
|
+
* Re-authorize the request for CAE challenge.
|
|
2888
|
+
* The response containing the challenge is `options.response`.
|
|
2889
|
+
* If this method returns true, the underlying request will be sent once again.
|
|
2890
|
+
*/
|
|
2891
|
+
async function authorizeRequestOnCaeChallenge(onChallengeOptions, caeClaims) {
|
|
2892
|
+
const { scopes } = onChallengeOptions;
|
|
2893
|
+
const accessToken = await onChallengeOptions.getAccessToken(scopes, {
|
|
2894
|
+
enableCae: true,
|
|
2895
|
+
claims: caeClaims
|
|
2896
|
+
});
|
|
2897
|
+
if (!accessToken) return false;
|
|
2898
|
+
onChallengeOptions.request.headers.set("Authorization", `${accessToken.tokenType ?? "Bearer"} ${accessToken.token}`);
|
|
2899
|
+
return true;
|
|
2900
|
+
}
|
|
2901
|
+
/**
|
|
2902
|
+
* A policy that can request a token from a TokenCredential implementation and
|
|
2903
|
+
* then apply it to the Authorization header of a request as a Bearer token.
|
|
2904
|
+
*/
|
|
2905
|
+
function bearerTokenAuthenticationPolicy(options) {
|
|
2906
|
+
const { credential, scopes, challengeCallbacks } = options;
|
|
2907
|
+
const logger$2 = options.logger || logger;
|
|
2908
|
+
const callbacks = {
|
|
2909
|
+
authorizeRequest: challengeCallbacks?.authorizeRequest?.bind(challengeCallbacks) ?? defaultAuthorizeRequest,
|
|
2910
|
+
authorizeRequestOnChallenge: challengeCallbacks?.authorizeRequestOnChallenge?.bind(challengeCallbacks)
|
|
2911
|
+
};
|
|
2912
|
+
const getAccessToken = credential ? createTokenCycler(credential) : () => Promise.resolve(null);
|
|
2913
|
+
return {
|
|
2914
|
+
name: bearerTokenAuthenticationPolicyName,
|
|
2915
|
+
/**
|
|
2916
|
+
* If there's no challenge parameter:
|
|
2917
|
+
* - It will try to retrieve the token using the cache, or the credential's getToken.
|
|
2918
|
+
* - Then it will try the next policy with or without the retrieved token.
|
|
2919
|
+
*
|
|
2920
|
+
* It uses the challenge parameters to:
|
|
2921
|
+
* - Skip a first attempt to get the token from the credential if there's no cached token,
|
|
2922
|
+
* since it expects the token to be retrievable only after the challenge.
|
|
2923
|
+
* - Prepare the outgoing request if the `prepareRequest` method has been provided.
|
|
2924
|
+
* - Send an initial request to receive the challenge if it fails.
|
|
2925
|
+
* - Process a challenge if the response contains it.
|
|
2926
|
+
* - Retrieve a token with the challenge information, then re-send the request.
|
|
2927
|
+
*/
|
|
2928
|
+
async sendRequest(request, next) {
|
|
2929
|
+
if (!request.url.toLowerCase().startsWith("https://")) throw new Error("Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.");
|
|
2930
|
+
await callbacks.authorizeRequest({
|
|
2931
|
+
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
2932
|
+
request,
|
|
2933
|
+
getAccessToken,
|
|
2934
|
+
logger: logger$2
|
|
2935
|
+
});
|
|
2936
|
+
let response;
|
|
2937
|
+
let error;
|
|
2938
|
+
let shouldSendRequest;
|
|
2939
|
+
[response, error] = await trySendRequest(request, next);
|
|
2940
|
+
if (isChallengeResponse(response)) {
|
|
2941
|
+
let claims = getCaeChallengeClaims(response.headers.get("WWW-Authenticate"));
|
|
2942
|
+
if (claims) {
|
|
2943
|
+
let parsedClaim;
|
|
2944
|
+
try {
|
|
2945
|
+
parsedClaim = atob(claims);
|
|
2946
|
+
} catch (e) {
|
|
2947
|
+
logger$2.warning(`The WWW-Authenticate header contains "claims" that cannot be parsed. Unable to perform the Continuous Access Evaluation authentication flow. Unparsable claims: ${claims}`);
|
|
2948
|
+
return response;
|
|
2949
|
+
}
|
|
2950
|
+
shouldSendRequest = await authorizeRequestOnCaeChallenge({
|
|
2951
|
+
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
2952
|
+
response,
|
|
2953
|
+
request,
|
|
2954
|
+
getAccessToken,
|
|
2955
|
+
logger: logger$2
|
|
2956
|
+
}, parsedClaim);
|
|
2957
|
+
if (shouldSendRequest) [response, error] = await trySendRequest(request, next);
|
|
2958
|
+
} else if (callbacks.authorizeRequestOnChallenge) {
|
|
2959
|
+
shouldSendRequest = await callbacks.authorizeRequestOnChallenge({
|
|
2960
|
+
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
2961
|
+
request,
|
|
2962
|
+
response,
|
|
2963
|
+
getAccessToken,
|
|
2964
|
+
logger: logger$2
|
|
2965
|
+
});
|
|
2966
|
+
if (shouldSendRequest) [response, error] = await trySendRequest(request, next);
|
|
2967
|
+
if (isChallengeResponse(response)) {
|
|
2968
|
+
claims = getCaeChallengeClaims(response.headers.get("WWW-Authenticate"));
|
|
2969
|
+
if (claims) {
|
|
2970
|
+
let parsedClaim;
|
|
2971
|
+
try {
|
|
2972
|
+
parsedClaim = atob(claims);
|
|
2973
|
+
} catch (e) {
|
|
2974
|
+
logger$2.warning(`The WWW-Authenticate header contains "claims" that cannot be parsed. Unable to perform the Continuous Access Evaluation authentication flow. Unparsable claims: ${claims}`);
|
|
2975
|
+
return response;
|
|
2976
|
+
}
|
|
2977
|
+
shouldSendRequest = await authorizeRequestOnCaeChallenge({
|
|
2978
|
+
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
2979
|
+
response,
|
|
2980
|
+
request,
|
|
2981
|
+
getAccessToken,
|
|
2982
|
+
logger: logger$2
|
|
2983
|
+
}, parsedClaim);
|
|
2984
|
+
if (shouldSendRequest) [response, error] = await trySendRequest(request, next);
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
if (error) throw error;
|
|
2990
|
+
else return response;
|
|
2991
|
+
}
|
|
2992
|
+
};
|
|
2993
|
+
}
|
|
2994
|
+
/**
|
|
2995
|
+
* Converts: `Bearer a="b", c="d", Pop e="f", g="h"`.
|
|
2996
|
+
* Into: `[ { scheme: 'Bearer', params: { a: 'b', c: 'd' } }, { scheme: 'Pop', params: { e: 'f', g: 'h' } } ]`.
|
|
2997
|
+
*
|
|
2998
|
+
* @internal
|
|
2999
|
+
*/
|
|
3000
|
+
function parseChallenges(challenges) {
|
|
3001
|
+
const challengeRegex = /(\w+)\s+((?:\w+=(?:"[^"]*"|[^,]*),?\s*)+)/g;
|
|
3002
|
+
const paramRegex = /(\w+)="([^"]*)"/g;
|
|
3003
|
+
const parsedChallenges = [];
|
|
3004
|
+
let match;
|
|
3005
|
+
while ((match = challengeRegex.exec(challenges)) !== null) {
|
|
3006
|
+
const scheme = match[1];
|
|
3007
|
+
const paramsString = match[2];
|
|
3008
|
+
const params = {};
|
|
3009
|
+
let paramMatch;
|
|
3010
|
+
while ((paramMatch = paramRegex.exec(paramsString)) !== null) params[paramMatch[1]] = paramMatch[2];
|
|
3011
|
+
parsedChallenges.push({
|
|
3012
|
+
scheme,
|
|
3013
|
+
params
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
return parsedChallenges;
|
|
3017
|
+
}
|
|
3018
|
+
/**
|
|
3019
|
+
* Parse a pipeline response and look for a CAE challenge with "Bearer" scheme
|
|
3020
|
+
* Return the value in the header without parsing the challenge
|
|
3021
|
+
* @internal
|
|
3022
|
+
*/
|
|
3023
|
+
function getCaeChallengeClaims(challenges) {
|
|
3024
|
+
if (!challenges) return;
|
|
3025
|
+
return parseChallenges(challenges).find((x) => x.scheme === "Bearer" && x.params.claims && x.params.error === "insufficient_claims")?.params.claims;
|
|
3026
|
+
}
|
|
3027
|
+
//#endregion
|
|
3028
|
+
export { isNode as A, createTracingClient as B, RestError$1 as C, createHttpHeaders as D, createPipelineRequest as E, delay$1 as F, getLogLevel as H, AbortError$1 as I, stringToUint8Array$1 as L, stringToUint8Array as M, uint8ArrayToString as N, calculateRetryDelay as O, isObjectWithProperties as P, uint8ArrayToString$1 as R, logger$1 as S, createEmptyPipeline$1 as T, createClientLogger as V, decompressResponsePolicy$1 as _, RestError as a, logPolicy$1 as b, multipartPolicyName$1 as c, tlsPolicy$1 as d, agentPolicy$1 as f, retryPolicy as g, defaultRetryPolicy$1 as h, wrapAbortSignalLike as i, isNodeLike as j, isError as k, isBinaryBody as l, formDataPolicy$1 as m, bearerTokenAuthenticationPolicyName as n, createEmptyPipeline as o, proxyPolicy$1 as p, createPipelineFromOptions as r, multipartPolicy$1 as s, bearerTokenAuthenticationPolicy as t, isReadableStream as u, SDK_VERSION$1 as v, isRestError$1 as w, createDefaultHttpClient as x, redirectPolicy$1 as y, isNodeLike$1 as z };
|