@typespec/ts-http-runtime 1.0.0-alpha.20240618.1 → 1.0.0-alpha.20240621.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/policies/proxyPolicy-browser.d.mts.map +1 -1
- package/dist/browser/policies/proxyPolicy-browser.mjs.map +1 -1
- package/dist/browser/policies/proxyPolicy.common.d.ts +15 -0
- package/dist/browser/policies/proxyPolicy.common.d.ts.map +1 -0
- package/dist/browser/policies/proxyPolicy.common.js +24 -0
- package/dist/browser/policies/proxyPolicy.common.js.map +1 -0
- package/dist/browser/policies/proxyPolicy.d.ts +1 -14
- package/dist/browser/policies/proxyPolicy.js +1 -24
- package/dist/browser/policies/tracingPolicy.d.ts.map +1 -1
- package/dist/browser/policies/tracingPolicy.js +2 -1
- package/dist/browser/policies/tracingPolicy.js.map +1 -1
- package/dist/browser/policies/userAgentPolicy.js +1 -1
- package/dist/browser/policies/userAgentPolicy.js.map +1 -1
- package/dist/browser/util/bytesEncoding-browser.d.mts.map +1 -1
- package/dist/browser/util/bytesEncoding-browser.mjs.map +1 -1
- package/dist/browser/util/bytesEncoding.common.d.ts +61 -0
- package/dist/browser/util/bytesEncoding.common.d.ts.map +1 -0
- package/dist/browser/util/bytesEncoding.common.js +110 -0
- package/dist/browser/util/bytesEncoding.common.js.map +1 -0
- package/dist/browser/util/bytesEncoding.d.ts +1 -60
- package/dist/browser/util/bytesEncoding.js +1 -107
- package/dist/browser/util/concat-browser.d.mts.map +1 -1
- package/dist/browser/util/concat-browser.mjs.map +1 -1
- package/dist/browser/util/concat.common.d.ts +19 -0
- package/dist/browser/util/concat.common.d.ts.map +1 -0
- package/dist/browser/util/concat.common.js +45 -0
- package/dist/browser/util/concat.common.js.map +1 -0
- package/dist/browser/util/concat.d.ts +1 -18
- package/dist/browser/util/concat.js +1 -42
- package/dist/browser/util/inspect-browser.d.mts.map +1 -1
- package/dist/browser/util/inspect-browser.mjs.map +1 -1
- package/dist/browser/util/inspect.common.d.ts +2 -0
- package/dist/browser/util/inspect.common.d.ts.map +1 -0
- package/dist/browser/util/inspect.common.js +4 -0
- package/dist/browser/util/inspect.common.js.map +1 -0
- package/dist/browser/util/inspect.d.ts +1 -1
- package/dist/browser/util/inspect.js +1 -1
- package/dist/browser/util/sha256-browser.d.mts.map +1 -1
- package/dist/browser/util/sha256-browser.mjs.map +1 -1
- package/dist/browser/util/sha256.common.d.ts +14 -0
- package/dist/browser/util/sha256.common.d.ts.map +1 -0
- package/dist/browser/util/sha256.common.js +49 -0
- package/dist/browser/util/sha256.common.js.map +1 -0
- package/dist/browser/util/sha256.d.ts +1 -13
- package/dist/browser/util/sha256.js +1 -46
- package/dist/browser/util/userAgent.d.ts +1 -1
- package/dist/browser/util/userAgent.d.ts.map +1 -1
- package/dist/browser/util/userAgent.js +2 -2
- package/dist/browser/util/userAgent.js.map +1 -1
- package/dist/browser/util/userAgentPlatform-browser.d.mts.map +1 -1
- package/dist/browser/util/userAgentPlatform-browser.mjs.map +1 -1
- package/dist/browser/util/userAgentPlatform.d.ts +1 -1
- package/dist/browser/util/userAgentPlatform.js +28 -6
- package/dist/commonjs/policies/proxyPolicy.common.d.ts +15 -0
- package/dist/commonjs/policies/proxyPolicy.common.d.ts.map +1 -0
- package/dist/commonjs/policies/proxyPolicy.common.js +30 -0
- package/dist/commonjs/policies/proxyPolicy.common.js.map +1 -0
- package/dist/commonjs/policies/tracingPolicy.d.ts.map +1 -1
- package/dist/commonjs/policies/tracingPolicy.js +2 -1
- package/dist/commonjs/policies/tracingPolicy.js.map +1 -1
- package/dist/commonjs/policies/userAgentPolicy.js +1 -1
- package/dist/commonjs/policies/userAgentPolicy.js.map +1 -1
- package/dist/commonjs/util/bytesEncoding.common.d.ts +61 -0
- package/dist/commonjs/util/bytesEncoding.common.d.ts.map +1 -0
- package/dist/commonjs/util/bytesEncoding.common.js +123 -0
- package/dist/commonjs/util/bytesEncoding.common.js.map +1 -0
- package/dist/commonjs/util/concat.common.d.ts +19 -0
- package/dist/commonjs/util/concat.common.d.ts.map +1 -0
- package/dist/commonjs/util/concat.common.js +49 -0
- package/dist/commonjs/util/concat.common.js.map +1 -0
- package/dist/commonjs/util/inspect.common.d.ts +2 -0
- package/dist/commonjs/util/inspect.common.d.ts.map +1 -0
- package/dist/commonjs/util/inspect.common.js +7 -0
- package/dist/commonjs/util/inspect.common.js.map +1 -0
- package/dist/commonjs/util/sha256.common.d.ts +14 -0
- package/dist/commonjs/util/sha256.common.d.ts.map +1 -0
- package/dist/commonjs/util/sha256.common.js +54 -0
- package/dist/commonjs/util/sha256.common.js.map +1 -0
- package/dist/commonjs/util/userAgent.d.ts +1 -1
- package/dist/commonjs/util/userAgent.d.ts.map +1 -1
- package/dist/commonjs/util/userAgent.js +2 -2
- package/dist/commonjs/util/userAgent.js.map +1 -1
- package/dist/commonjs/util/userAgentPlatform.d.ts +1 -1
- package/dist/commonjs/util/userAgentPlatform.d.ts.map +1 -1
- package/dist/commonjs/util/userAgentPlatform.js +1 -1
- package/dist/commonjs/util/userAgentPlatform.js.map +1 -1
- package/dist/esm/policies/proxyPolicy.common.d.ts +15 -0
- package/dist/esm/policies/proxyPolicy.common.d.ts.map +1 -0
- package/dist/esm/policies/proxyPolicy.common.js +24 -0
- package/dist/esm/policies/proxyPolicy.common.js.map +1 -0
- package/dist/esm/policies/tracingPolicy.d.ts.map +1 -1
- package/dist/esm/policies/tracingPolicy.js +2 -1
- package/dist/esm/policies/tracingPolicy.js.map +1 -1
- package/dist/esm/policies/userAgentPolicy.js +1 -1
- package/dist/esm/policies/userAgentPolicy.js.map +1 -1
- package/dist/esm/util/bytesEncoding.common.d.ts +61 -0
- package/dist/esm/util/bytesEncoding.common.d.ts.map +1 -0
- package/dist/esm/util/bytesEncoding.common.js +110 -0
- package/dist/esm/util/bytesEncoding.common.js.map +1 -0
- package/dist/esm/util/concat.common.d.ts +19 -0
- package/dist/esm/util/concat.common.d.ts.map +1 -0
- package/dist/esm/util/concat.common.js +45 -0
- package/dist/esm/util/concat.common.js.map +1 -0
- package/dist/esm/util/inspect.common.d.ts +2 -0
- package/dist/esm/util/inspect.common.d.ts.map +1 -0
- package/dist/esm/util/inspect.common.js +4 -0
- package/dist/esm/util/inspect.common.js.map +1 -0
- package/dist/esm/util/sha256.common.d.ts +14 -0
- package/dist/esm/util/sha256.common.d.ts.map +1 -0
- package/dist/esm/util/sha256.common.js +49 -0
- package/dist/esm/util/sha256.common.js.map +1 -0
- package/dist/esm/util/userAgent.d.ts +1 -1
- package/dist/esm/util/userAgent.d.ts.map +1 -1
- package/dist/esm/util/userAgent.js +2 -2
- package/dist/esm/util/userAgent.js.map +1 -1
- package/dist/esm/util/userAgentPlatform.d.ts +1 -1
- package/dist/esm/util/userAgentPlatform.d.ts.map +1 -1
- package/dist/esm/util/userAgentPlatform.js +1 -1
- package/dist/esm/util/userAgentPlatform.js.map +1 -1
- package/dist/react-native/policies/proxyPolicy-react-native.d.mts.map +1 -0
- package/dist/react-native/policies/proxyPolicy-react-native.mjs.map +1 -0
- package/dist/react-native/policies/proxyPolicy.common.d.ts +15 -0
- package/dist/react-native/policies/proxyPolicy.common.d.ts.map +1 -0
- package/dist/react-native/policies/proxyPolicy.common.js +24 -0
- package/dist/react-native/policies/proxyPolicy.common.js.map +1 -0
- package/dist/react-native/policies/proxyPolicy.d.ts +2 -32
- package/dist/react-native/policies/proxyPolicy.js +2 -189
- package/dist/react-native/policies/tracingPolicy.d.ts.map +1 -1
- package/dist/react-native/policies/tracingPolicy.js +2 -1
- package/dist/react-native/policies/tracingPolicy.js.map +1 -1
- package/dist/react-native/policies/userAgentPolicy.js +1 -1
- package/dist/react-native/policies/userAgentPolicy.js.map +1 -1
- package/dist/react-native/util/bytesEncoding-react-native.d.mts.map +1 -0
- package/dist/react-native/util/bytesEncoding-react-native.mjs.map +1 -0
- package/dist/react-native/util/bytesEncoding.common.d.ts +61 -0
- package/dist/react-native/util/bytesEncoding.common.d.ts.map +1 -0
- package/dist/react-native/util/bytesEncoding.common.js +110 -0
- package/dist/react-native/util/bytesEncoding.common.js.map +1 -0
- package/dist/react-native/util/bytesEncoding.d.ts +2 -17
- package/dist/react-native/util/bytesEncoding.js +2 -19
- package/dist/react-native/util/concat-react-native.d.mts.map +1 -0
- package/dist/react-native/util/concat-react-native.mjs.map +1 -0
- package/dist/react-native/util/concat.common.d.ts +19 -0
- package/dist/react-native/util/concat.common.d.ts.map +1 -0
- package/dist/react-native/util/concat.common.js +45 -0
- package/dist/react-native/util/concat.common.js.map +1 -0
- package/dist/react-native/util/concat.d.ts +2 -18
- package/dist/react-native/util/concat.js +2 -86
- package/dist/react-native/util/inspect-react-native.d.mts.map +1 -0
- package/dist/react-native/util/inspect-react-native.mjs.map +1 -0
- package/dist/react-native/util/inspect.common.d.ts +2 -0
- package/dist/react-native/util/inspect.common.d.ts.map +1 -0
- package/dist/react-native/util/inspect.common.js +4 -0
- package/dist/react-native/util/inspect.common.js.map +1 -0
- package/dist/react-native/util/inspect.d.ts +2 -2
- package/dist/react-native/util/inspect.js +2 -3
- package/dist/react-native/util/sha256-react-native.d.mts.map +1 -0
- package/dist/react-native/util/sha256-react-native.mjs.map +1 -0
- package/dist/react-native/util/sha256.common.d.ts +14 -0
- package/dist/react-native/util/sha256.common.d.ts.map +1 -0
- package/dist/react-native/util/sha256.common.js +49 -0
- package/dist/react-native/util/sha256.common.js.map +1 -0
- package/dist/react-native/util/sha256.d.ts +2 -14
- package/dist/react-native/util/sha256.js +2 -20
- package/dist/react-native/util/userAgent.d.ts +1 -1
- package/dist/react-native/util/userAgent.d.ts.map +1 -1
- package/dist/react-native/util/userAgent.js +2 -2
- package/dist/react-native/util/userAgent.js.map +1 -1
- package/dist/react-native/util/userAgentPlatform-react-native.d.mts.map +1 -1
- package/dist/react-native/util/userAgentPlatform-react-native.mjs.map +1 -1
- package/dist/react-native/util/userAgentPlatform.d.ts +1 -1
- package/dist/react-native/util/userAgentPlatform.js +2 -4
- package/package.json +2 -2
- package/dist/react-native/policies/proxyPolicy.d.ts.map +0 -1
- package/dist/react-native/policies/proxyPolicy.js.map +0 -1
- package/dist/react-native/util/bytesEncoding.d.ts.map +0 -1
- package/dist/react-native/util/bytesEncoding.js.map +0 -1
- package/dist/react-native/util/concat.d.ts.map +0 -1
- package/dist/react-native/util/concat.js.map +0 -1
- package/dist/react-native/util/inspect.d.ts.map +0 -1
- package/dist/react-native/util/inspect.js.map +0 -1
- package/dist/react-native/util/sha256.d.ts.map +0 -1
- package/dist/react-native/util/sha256.js.map +0 -1
|
@@ -1,191 +1,4 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { logger } from "../log.js";
|
|
6
|
-
const HTTPS_PROXY = "HTTPS_PROXY";
|
|
7
|
-
const HTTP_PROXY = "HTTP_PROXY";
|
|
8
|
-
const ALL_PROXY = "ALL_PROXY";
|
|
9
|
-
const NO_PROXY = "NO_PROXY";
|
|
10
|
-
/**
|
|
11
|
-
* The programmatic identifier of the proxyPolicy.
|
|
12
|
-
*/
|
|
13
|
-
export const proxyPolicyName = "proxyPolicy";
|
|
14
|
-
/**
|
|
15
|
-
* Stores the patterns specified in NO_PROXY environment variable.
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
export const globalNoProxyList = [];
|
|
19
|
-
let noProxyListLoaded = false;
|
|
20
|
-
/** A cache of whether a host should bypass the proxy. */
|
|
21
|
-
const globalBypassedMap = new Map();
|
|
22
|
-
function getEnvironmentValue(name) {
|
|
23
|
-
if (process.env[name]) {
|
|
24
|
-
return process.env[name];
|
|
25
|
-
}
|
|
26
|
-
else if (process.env[name.toLowerCase()]) {
|
|
27
|
-
return process.env[name.toLowerCase()];
|
|
28
|
-
}
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
function loadEnvironmentProxyValue() {
|
|
32
|
-
if (!process) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
const httpsProxy = getEnvironmentValue(HTTPS_PROXY);
|
|
36
|
-
const allProxy = getEnvironmentValue(ALL_PROXY);
|
|
37
|
-
const httpProxy = getEnvironmentValue(HTTP_PROXY);
|
|
38
|
-
return httpsProxy || allProxy || httpProxy;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Check whether the host of a given `uri` matches any pattern in the no proxy list.
|
|
42
|
-
* If there's a match, any request sent to the same host shouldn't have the proxy settings set.
|
|
43
|
-
* 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
|
|
44
|
-
*/
|
|
45
|
-
function isBypassed(uri, noProxyList, bypassedMap) {
|
|
46
|
-
if (noProxyList.length === 0) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
const host = new URL(uri).hostname;
|
|
50
|
-
if (bypassedMap === null || bypassedMap === void 0 ? void 0 : bypassedMap.has(host)) {
|
|
51
|
-
return bypassedMap.get(host);
|
|
52
|
-
}
|
|
53
|
-
let isBypassedFlag = false;
|
|
54
|
-
for (const pattern of noProxyList) {
|
|
55
|
-
if (pattern[0] === ".") {
|
|
56
|
-
// This should match either domain it self or any subdomain or host
|
|
57
|
-
// .foo.com will match foo.com it self or *.foo.com
|
|
58
|
-
if (host.endsWith(pattern)) {
|
|
59
|
-
isBypassedFlag = true;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
if (host.length === pattern.length - 1 && host === pattern.slice(1)) {
|
|
63
|
-
isBypassedFlag = true;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
if (host === pattern) {
|
|
69
|
-
isBypassedFlag = true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
bypassedMap === null || bypassedMap === void 0 ? void 0 : bypassedMap.set(host, isBypassedFlag);
|
|
74
|
-
return isBypassedFlag;
|
|
75
|
-
}
|
|
76
|
-
export function loadNoProxy() {
|
|
77
|
-
const noProxy = getEnvironmentValue(NO_PROXY);
|
|
78
|
-
noProxyListLoaded = true;
|
|
79
|
-
if (noProxy) {
|
|
80
|
-
return noProxy
|
|
81
|
-
.split(",")
|
|
82
|
-
.map((item) => item.trim())
|
|
83
|
-
.filter((item) => item.length);
|
|
84
|
-
}
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* This method converts a proxy url into `ProxySettings` for use with ProxyPolicy.
|
|
89
|
-
* If no argument is given, it attempts to parse a proxy URL from the environment
|
|
90
|
-
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
91
|
-
* @param proxyUrl - The url of the proxy to use. May contain authentication information.
|
|
92
|
-
* @deprecated - Internally this method is no longer necessary when setting proxy information.
|
|
93
|
-
*/
|
|
94
|
-
export function getDefaultProxySettings(proxyUrl) {
|
|
95
|
-
if (!proxyUrl) {
|
|
96
|
-
proxyUrl = loadEnvironmentProxyValue();
|
|
97
|
-
if (!proxyUrl) {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const parsedUrl = new URL(proxyUrl);
|
|
102
|
-
const schema = parsedUrl.protocol ? parsedUrl.protocol + "//" : "";
|
|
103
|
-
return {
|
|
104
|
-
host: schema + parsedUrl.hostname,
|
|
105
|
-
port: Number.parseInt(parsedUrl.port || "80"),
|
|
106
|
-
username: parsedUrl.username,
|
|
107
|
-
password: parsedUrl.password,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* This method attempts to parse a proxy URL from the environment
|
|
112
|
-
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
113
|
-
*/
|
|
114
|
-
function getDefaultProxySettingsInternal() {
|
|
115
|
-
const envProxy = loadEnvironmentProxyValue();
|
|
116
|
-
return envProxy ? new URL(envProxy) : undefined;
|
|
117
|
-
}
|
|
118
|
-
function getUrlFromProxySettings(settings) {
|
|
119
|
-
let parsedProxyUrl;
|
|
120
|
-
try {
|
|
121
|
-
parsedProxyUrl = new URL(settings.host);
|
|
122
|
-
}
|
|
123
|
-
catch (_error) {
|
|
124
|
-
throw new Error(`Expecting a valid host string in proxy settings, but found "${settings.host}".`);
|
|
125
|
-
}
|
|
126
|
-
parsedProxyUrl.port = String(settings.port);
|
|
127
|
-
if (settings.username) {
|
|
128
|
-
parsedProxyUrl.username = settings.username;
|
|
129
|
-
}
|
|
130
|
-
if (settings.password) {
|
|
131
|
-
parsedProxyUrl.password = settings.password;
|
|
132
|
-
}
|
|
133
|
-
return parsedProxyUrl;
|
|
134
|
-
}
|
|
135
|
-
function setProxyAgentOnRequest(request, cachedAgents, proxyUrl) {
|
|
136
|
-
// Custom Agent should take precedence so if one is present
|
|
137
|
-
// we should skip to avoid overwriting it.
|
|
138
|
-
if (request.agent) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const url = new URL(request.url);
|
|
142
|
-
const isInsecure = url.protocol !== "https:";
|
|
143
|
-
if (request.tlsSettings) {
|
|
144
|
-
logger.warning("TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.");
|
|
145
|
-
}
|
|
146
|
-
const headers = request.headers.toJSON();
|
|
147
|
-
if (isInsecure) {
|
|
148
|
-
if (!cachedAgents.httpProxyAgent) {
|
|
149
|
-
cachedAgents.httpProxyAgent = new HttpProxyAgent(proxyUrl, { headers });
|
|
150
|
-
}
|
|
151
|
-
request.agent = cachedAgents.httpProxyAgent;
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
if (!cachedAgents.httpsProxyAgent) {
|
|
155
|
-
cachedAgents.httpsProxyAgent = new HttpsProxyAgent(proxyUrl, { headers });
|
|
156
|
-
}
|
|
157
|
-
request.agent = cachedAgents.httpsProxyAgent;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* A policy that allows one to apply proxy settings to all requests.
|
|
162
|
-
* If not passed static settings, they will be retrieved from the HTTPS_PROXY
|
|
163
|
-
* or HTTP_PROXY environment variables.
|
|
164
|
-
* @param proxySettings - ProxySettings to use on each request.
|
|
165
|
-
* @param options - additional settings, for example, custom NO_PROXY patterns
|
|
166
|
-
*/
|
|
167
|
-
export function proxyPolicy(proxySettings, options) {
|
|
168
|
-
if (!noProxyListLoaded) {
|
|
169
|
-
globalNoProxyList.push(...loadNoProxy());
|
|
170
|
-
}
|
|
171
|
-
const defaultProxy = proxySettings
|
|
172
|
-
? getUrlFromProxySettings(proxySettings)
|
|
173
|
-
: getDefaultProxySettingsInternal();
|
|
174
|
-
const cachedAgents = {};
|
|
175
|
-
return {
|
|
176
|
-
name: proxyPolicyName,
|
|
177
|
-
async sendRequest(request, next) {
|
|
178
|
-
var _a;
|
|
179
|
-
if (!request.proxySettings &&
|
|
180
|
-
defaultProxy &&
|
|
181
|
-
!isBypassed(request.url, (_a = options === null || options === void 0 ? void 0 : options.customNoProxyList) !== null && _a !== void 0 ? _a : globalNoProxyList, (options === null || options === void 0 ? void 0 : options.customNoProxyList) ? undefined : globalBypassedMap)) {
|
|
182
|
-
setProxyAgentOnRequest(request, cachedAgents, defaultProxy);
|
|
183
|
-
}
|
|
184
|
-
else if (request.proxySettings) {
|
|
185
|
-
setProxyAgentOnRequest(request, cachedAgents, getUrlFromProxySettings(request.proxySettings));
|
|
186
|
-
}
|
|
187
|
-
return next(request);
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
//# sourceMappingURL=proxyPolicy.js.map
|
|
3
|
+
export * from "./proxyPolicy.common.js";
|
|
4
|
+
//# sourceMappingURL=proxyPolicy-react-native.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracingPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/tracingPolicy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAOhD;;GAEG;AACH,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,gCAAgC,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"tracingPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/tracingPolicy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAOhD;;GAEG;AACH,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,gCAAgC,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,cAAc,CA0ChF"}
|
|
@@ -18,7 +18,7 @@ export const tracingPolicyName = "tracingPolicy";
|
|
|
18
18
|
* @param options - Options to configure the telemetry logged by the tracing policy.
|
|
19
19
|
*/
|
|
20
20
|
export function tracingPolicy(options = {}) {
|
|
21
|
-
const
|
|
21
|
+
const userAgentValue = getUserAgentValue(options.userAgentPrefix);
|
|
22
22
|
const sanitizer = new Sanitizer({
|
|
23
23
|
additionalAllowedQueryParameters: options.additionalAllowedQueryParameters,
|
|
24
24
|
});
|
|
@@ -30,6 +30,7 @@ export function tracingPolicy(options = {}) {
|
|
|
30
30
|
if (!tracingClient || !((_a = request.tracingOptions) === null || _a === void 0 ? void 0 : _a.tracingContext)) {
|
|
31
31
|
return next(request);
|
|
32
32
|
}
|
|
33
|
+
const userAgent = await userAgentValue;
|
|
33
34
|
const spanAttributes = {
|
|
34
35
|
"http.url": sanitizer.sanitizeUrl(request.url),
|
|
35
36
|
"http.method": request.method,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracingPolicy.js","sourceRoot":"","sources":["../../../src/policies/tracingPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAmBjD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,UAAgC,EAAE;IAC9D,MAAM,
|
|
1
|
+
{"version":3,"file":"tracingPolicy.js","sourceRoot":"","sources":["../../../src/policies/tracingPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM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CAAC;QACD,IAAI,CAAC,SAAS,CAAC;YACb,MAAM,EAAE,SAAS;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,MAAM,CAAC,OAAO,CAAC,qDAAqD,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5F,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { TracingClient, TracingContext, TracingSpan } from \"../tracing/interfaces.js\";\nimport { createTracingClient } from \"../tracing/tracingClient.js\";\nimport { SDK_VERSION } from \"../constants.js\";\nimport { PipelineRequest, PipelineResponse, SendRequest } from \"../interfaces.js\";\nimport { PipelinePolicy } from \"../pipeline.js\";\nimport { getUserAgentValue } from \"../util/userAgent.js\";\nimport { logger } from \"../log.js\";\nimport { getErrorMessage, isError } from \"../util/error.js\";\nimport { isRestError } from \"../restError.js\";\nimport { Sanitizer } from \"../util/sanitizer.js\";\n\n/**\n * The programmatic identifier of the tracingPolicy.\n */\nexport const tracingPolicyName = \"tracingPolicy\";\n\n/**\n * Options to configure the tracing policy.\n */\nexport interface TracingPolicyOptions {\n /**\n * String prefix to add to the user agent logged as metadata\n * on the generated Span.\n * Defaults to an empty string.\n */\n userAgentPrefix?: string;\n /**\n * Query string names whose values will be logged when logging is enabled. By default no\n * query string values are logged.\n */\n additionalAllowedQueryParameters?: string[];\n}\n\n/**\n * A simple policy to create OpenTelemetry Spans for each request made by the pipeline\n * that has SpanOptions with a parent.\n * Requests made without a parent Span will not be recorded.\n * @param options - Options to configure the telemetry logged by the tracing policy.\n */\nexport function tracingPolicy(options: TracingPolicyOptions = {}): PipelinePolicy {\n const userAgentValue = getUserAgentValue(options.userAgentPrefix);\n const sanitizer = new Sanitizer({\n additionalAllowedQueryParameters: options.additionalAllowedQueryParameters,\n });\n const tracingClient = tryCreateTracingClient();\n\n return {\n name: tracingPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (!tracingClient || !request.tracingOptions?.tracingContext) {\n return next(request);\n }\n\n const userAgent = await userAgentValue;\n\n const spanAttributes = {\n \"http.url\": sanitizer.sanitizeUrl(request.url),\n \"http.method\": request.method,\n \"http.user_agent\": userAgent,\n requestId: request.requestId,\n };\n if (userAgent) {\n spanAttributes[\"http.user_agent\"] = userAgent;\n }\n\n const { span, tracingContext } = tryCreateSpan(tracingClient, request, spanAttributes) ?? {};\n\n if (!span || !tracingContext) {\n return next(request);\n }\n\n try {\n const response = await tracingClient.withContext(tracingContext, next, request);\n tryProcessResponse(span, response);\n return response;\n } catch (err: any) {\n tryProcessError(span, err);\n throw err;\n }\n },\n };\n}\n\nfunction tryCreateTracingClient(): TracingClient | undefined {\n try {\n return createTracingClient({\n namespace: \"\",\n packageName: \"@typespec/ts-http-runtime\",\n packageVersion: SDK_VERSION,\n });\n } catch (e: unknown) {\n logger.warning(`Error when creating the TracingClient: ${getErrorMessage(e)}`);\n return undefined;\n }\n}\n\nfunction tryCreateSpan(\n tracingClient: TracingClient,\n request: PipelineRequest,\n spanAttributes: Record<string, unknown>,\n): { span: TracingSpan; tracingContext: TracingContext } | undefined {\n try {\n // As per spec, we do not need to differentiate between HTTP and HTTPS in span name.\n const { span, updatedOptions } = tracingClient.startSpan(\n `HTTP ${request.method}`,\n { tracingOptions: request.tracingOptions },\n {\n spanKind: \"client\",\n spanAttributes,\n },\n );\n\n // If the span is not recording, don't do any more work.\n if (!span.isRecording()) {\n span.end();\n return undefined;\n }\n\n // set headers\n const headers = tracingClient.createRequestHeaders(\n updatedOptions.tracingOptions.tracingContext,\n );\n for (const [key, value] of Object.entries(headers)) {\n request.headers.set(key, value);\n }\n return { span, tracingContext: updatedOptions.tracingOptions.tracingContext };\n } catch (e: any) {\n logger.warning(`Skipping creating a tracing span due to an error: ${getErrorMessage(e)}`);\n return undefined;\n }\n}\n\nfunction tryProcessError(span: TracingSpan, error: unknown): void {\n try {\n span.setStatus({\n status: \"error\",\n error: isError(error) ? error : undefined,\n });\n if (isRestError(error) && error.statusCode) {\n span.setAttribute(\"http.status_code\", error.statusCode);\n }\n span.end();\n } catch (e: any) {\n logger.warning(`Skipping tracing span processing due to an error: ${getErrorMessage(e)}`);\n }\n}\n\nfunction tryProcessResponse(span: TracingSpan, response: PipelineResponse): void {\n try {\n span.setAttribute(\"http.status_code\", response.status);\n const serviceRequestId = response.headers.get(\"x-ms-request-id\");\n if (serviceRequestId) {\n span.setAttribute(\"serviceRequestId\", serviceRequestId);\n }\n span.setStatus({\n status: \"success\",\n });\n span.end();\n } catch (e: any) {\n logger.warning(`Skipping tracing span processing due to an error: ${getErrorMessage(e)}`);\n }\n}\n"]}
|
|
@@ -17,7 +17,7 @@ export function userAgentPolicy(options = {}) {
|
|
|
17
17
|
name: userAgentPolicyName,
|
|
18
18
|
async sendRequest(request, next) {
|
|
19
19
|
if (!request.headers.has(UserAgentHeaderName)) {
|
|
20
|
-
request.headers.set(UserAgentHeaderName, userAgentValue);
|
|
20
|
+
request.headers.set(UserAgentHeaderName, await userAgentValue);
|
|
21
21
|
}
|
|
22
22
|
return next(request);
|
|
23
23
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userAgentPolicy.js","sourceRoot":"","sources":["../../../src/policies/userAgentPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEjF,MAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAC;AAErD;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAarD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,UAAkC,EAAE;IAClE,MAAM,cAAc,GAAG,iBAAiB,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAClE,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,CAAC;gBAC9C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"userAgentPolicy.js","sourceRoot":"","sources":["../../../src/policies/userAgentPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEjF,MAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAC;AAErD;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAarD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,UAAkC,EAAE;IAClE,MAAM,cAAc,GAAG,iBAAiB,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAClE,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,CAAC;gBAC9C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,MAAM,cAAc,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { PipelineRequest, PipelineResponse, SendRequest } from \"../interfaces.js\";\nimport { PipelinePolicy } from \"../pipeline.js\";\nimport { getUserAgentHeaderName, getUserAgentValue } from \"../util/userAgent.js\";\n\nconst UserAgentHeaderName = getUserAgentHeaderName();\n\n/**\n * The programmatic identifier of the userAgentPolicy.\n */\nexport const userAgentPolicyName = \"userAgentPolicy\";\n\n/**\n * Options for adding user agent details to outgoing requests.\n */\nexport interface UserAgentPolicyOptions {\n /**\n * String prefix to add to the user agent for outgoing requests.\n * Defaults to an empty string.\n */\n userAgentPrefix?: string;\n}\n\n/**\n * A policy that sets the User-Agent header (or equivalent) to reflect\n * the library version.\n * @param options - Options to customize the user agent value.\n */\nexport function userAgentPolicy(options: UserAgentPolicyOptions = {}): PipelinePolicy {\n const userAgentValue = getUserAgentValue(options.userAgentPrefix);\n return {\n name: userAgentPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (!request.headers.has(UserAgentHeaderName)) {\n request.headers.set(UserAgentHeaderName, await userAgentValue);\n }\n return next(request);\n },\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytesEncoding-react-native.d.mts","sourceRoot":"","sources":["../../../src/util/bytesEncoding-react-native.mts"],"names":[],"mappings":"AAGA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytesEncoding-react-native.mjs","sourceRoot":"","sources":["../../../src/util/bytesEncoding-react-native.mts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,2BAA2B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport * from \"./bytesEncoding.common.js\";\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
function btoa(input: string): string;
|
|
3
|
+
function atob(input: string): string;
|
|
4
|
+
}
|
|
5
|
+
/** The supported character encoding type */
|
|
6
|
+
export type EncodingType = "utf-8" | "base64" | "base64url" | "hex";
|
|
7
|
+
/**
|
|
8
|
+
* The helper that transforms bytes with specific character encoding into string
|
|
9
|
+
* @param bytes - the uint8array bytes
|
|
10
|
+
* @param format - the format we use to encode the byte
|
|
11
|
+
* @returns a string of the encoded string
|
|
12
|
+
*/
|
|
13
|
+
export declare function uint8ArrayToString(bytes: Uint8Array, format: EncodingType): string;
|
|
14
|
+
/**
|
|
15
|
+
* The helper that transforms string to specific character encoded bytes array.
|
|
16
|
+
* @param value - the string to be converted
|
|
17
|
+
* @param format - the format we use to decode the value
|
|
18
|
+
* @returns a uint8array
|
|
19
|
+
*/
|
|
20
|
+
export declare function stringToUint8Array(value: string, format: EncodingType): Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* Decodes a Uint8Array into a Base64 string.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function uint8ArrayToBase64(bytes: Uint8Array): string;
|
|
26
|
+
/**
|
|
27
|
+
* Decodes a Uint8Array into a Base64Url string.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare function uint8ArrayToBase64Url(bytes: Uint8Array): string;
|
|
31
|
+
/**
|
|
32
|
+
* Decodes a Uint8Array into a javascript string.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare function uint8ArrayToUtf8String(bytes: Uint8Array): string;
|
|
36
|
+
/**
|
|
37
|
+
* Decodes a Uint8Array into a hex string
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export declare function uint8ArrayToHexString(bytes: Uint8Array): string;
|
|
41
|
+
/**
|
|
42
|
+
* Encodes a JavaScript string into a Uint8Array.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export declare function utf8StringToUint8Array(value: string): Uint8Array;
|
|
46
|
+
/**
|
|
47
|
+
* Encodes a Base64 string into a Uint8Array.
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export declare function base64ToUint8Array(value: string): Uint8Array;
|
|
51
|
+
/**
|
|
52
|
+
* Encodes a Base64Url string into a Uint8Array.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export declare function base64UrlToUint8Array(value: string): Uint8Array;
|
|
56
|
+
/**
|
|
57
|
+
* Encodes a hex string into a Uint8Array
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export declare function hexStringToUint8Array(value: string): Uint8Array;
|
|
61
|
+
//# sourceMappingURL=bytesEncoding.common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytesEncoding.common.d.ts","sourceRoot":"","sources":["../../../src/util/bytesEncoding.common.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,CAAC;IAEb,SAAS,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACrC,SAAS,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACtC;AAED,4CAA4C;AAC5C,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,GAAG,KAAK,CAAC;AAEpE;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,GAAG,MAAM,CAWlF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,UAAU,CAWlF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE5D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE/D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIhE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE/D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAEhE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAE5D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAG/D;AAID;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAe/D"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
/**
|
|
4
|
+
* The helper that transforms bytes with specific character encoding into string
|
|
5
|
+
* @param bytes - the uint8array bytes
|
|
6
|
+
* @param format - the format we use to encode the byte
|
|
7
|
+
* @returns a string of the encoded string
|
|
8
|
+
*/
|
|
9
|
+
export function uint8ArrayToString(bytes, format) {
|
|
10
|
+
switch (format) {
|
|
11
|
+
case "utf-8":
|
|
12
|
+
return uint8ArrayToUtf8String(bytes);
|
|
13
|
+
case "base64":
|
|
14
|
+
return uint8ArrayToBase64(bytes);
|
|
15
|
+
case "base64url":
|
|
16
|
+
return uint8ArrayToBase64Url(bytes);
|
|
17
|
+
case "hex":
|
|
18
|
+
return uint8ArrayToHexString(bytes);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The helper that transforms string to specific character encoded bytes array.
|
|
23
|
+
* @param value - the string to be converted
|
|
24
|
+
* @param format - the format we use to decode the value
|
|
25
|
+
* @returns a uint8array
|
|
26
|
+
*/
|
|
27
|
+
export function stringToUint8Array(value, format) {
|
|
28
|
+
switch (format) {
|
|
29
|
+
case "utf-8":
|
|
30
|
+
return utf8StringToUint8Array(value);
|
|
31
|
+
case "base64":
|
|
32
|
+
return base64ToUint8Array(value);
|
|
33
|
+
case "base64url":
|
|
34
|
+
return base64UrlToUint8Array(value);
|
|
35
|
+
case "hex":
|
|
36
|
+
return hexStringToUint8Array(value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Decodes a Uint8Array into a Base64 string.
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
export function uint8ArrayToBase64(bytes) {
|
|
44
|
+
return btoa([...bytes].map((x) => String.fromCharCode(x)).join(""));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Decodes a Uint8Array into a Base64Url string.
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export function uint8ArrayToBase64Url(bytes) {
|
|
51
|
+
return uint8ArrayToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Decodes a Uint8Array into a javascript string.
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export function uint8ArrayToUtf8String(bytes) {
|
|
58
|
+
const decoder = new TextDecoder();
|
|
59
|
+
const dataString = decoder.decode(bytes);
|
|
60
|
+
return dataString;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Decodes a Uint8Array into a hex string
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export function uint8ArrayToHexString(bytes) {
|
|
67
|
+
return [...bytes].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Encodes a JavaScript string into a Uint8Array.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
export function utf8StringToUint8Array(value) {
|
|
74
|
+
return new TextEncoder().encode(value);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Encodes a Base64 string into a Uint8Array.
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
export function base64ToUint8Array(value) {
|
|
81
|
+
return new Uint8Array([...atob(value)].map((x) => x.charCodeAt(0)));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Encodes a Base64Url string into a Uint8Array.
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
export function base64UrlToUint8Array(value) {
|
|
88
|
+
const base64String = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
89
|
+
return base64ToUint8Array(base64String);
|
|
90
|
+
}
|
|
91
|
+
const hexDigits = new Set("0123456789abcdefABCDEF");
|
|
92
|
+
/**
|
|
93
|
+
* Encodes a hex string into a Uint8Array
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
export function hexStringToUint8Array(value) {
|
|
97
|
+
// If value has odd length, the last character will be ignored, consistent with NodeJS Buffer behavior
|
|
98
|
+
const bytes = new Uint8Array(value.length / 2);
|
|
99
|
+
for (let i = 0; i < value.length / 2; ++i) {
|
|
100
|
+
const highNibble = value[2 * i];
|
|
101
|
+
const lowNibble = value[2 * i + 1];
|
|
102
|
+
if (!hexDigits.has(highNibble) || !hexDigits.has(lowNibble)) {
|
|
103
|
+
// Replicate Node Buffer behavior by exiting early when we encounter an invalid byte
|
|
104
|
+
return bytes.slice(0, i);
|
|
105
|
+
}
|
|
106
|
+
bytes[i] = parseInt(`${highNibble}${lowNibble}`, 16);
|
|
107
|
+
}
|
|
108
|
+
return bytes;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=bytesEncoding.common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytesEncoding.common.js","sourceRoot":"","sources":["../../../src/util/bytesEncoding.common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAWlC;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAiB,EAAE,MAAoB;IACxE,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,OAAO;YACV,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;QACvC,KAAK,QAAQ;YACX,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACnC,KAAK,WAAW;YACd,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;QACtC,KAAK,KAAK;YACR,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,MAA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AO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3B,CAAC;QAED,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,UAAU,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\ndeclare global {\n // stub these out for the browser\n function btoa(input: string): string;\n function atob(input: string): string;\n}\n\n/** The supported character encoding type */\nexport type EncodingType = \"utf-8\" | \"base64\" | \"base64url\" | \"hex\";\n\n/**\n * The helper that transforms bytes with specific character encoding into string\n * @param bytes - the uint8array bytes\n * @param format - the format we use to encode the byte\n * @returns a string of the encoded string\n */\nexport function uint8ArrayToString(bytes: Uint8Array, format: EncodingType): string {\n switch (format) {\n case \"utf-8\":\n return uint8ArrayToUtf8String(bytes);\n case \"base64\":\n return uint8ArrayToBase64(bytes);\n case \"base64url\":\n return uint8ArrayToBase64Url(bytes);\n case \"hex\":\n return uint8ArrayToHexString(bytes);\n }\n}\n\n/**\n * The helper that transforms string to specific character encoded bytes array.\n * @param value - the string to be converted\n * @param format - the format we use to decode the value\n * @returns a uint8array\n */\nexport function stringToUint8Array(value: string, format: EncodingType): Uint8Array {\n switch (format) {\n case \"utf-8\":\n return utf8StringToUint8Array(value);\n case \"base64\":\n return base64ToUint8Array(value);\n case \"base64url\":\n return base64UrlToUint8Array(value);\n case \"hex\":\n return hexStringToUint8Array(value);\n }\n}\n\n/**\n * Decodes a Uint8Array into a Base64 string.\n * @internal\n */\nexport function uint8ArrayToBase64(bytes: Uint8Array): string {\n return btoa([...bytes].map((x) => String.fromCharCode(x)).join(\"\"));\n}\n\n/**\n * Decodes a Uint8Array into a Base64Url string.\n * @internal\n */\nexport function uint8ArrayToBase64Url(bytes: Uint8Array): string {\n return uint8ArrayToBase64(bytes).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=/g, \"\");\n}\n\n/**\n * Decodes a Uint8Array into a javascript string.\n * @internal\n */\nexport function uint8ArrayToUtf8String(bytes: Uint8Array): string {\n const decoder = new TextDecoder();\n const dataString = decoder.decode(bytes);\n return dataString;\n}\n\n/**\n * Decodes a Uint8Array into a hex string\n * @internal\n */\nexport function uint8ArrayToHexString(bytes: Uint8Array): string {\n return [...bytes].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/**\n * Encodes a JavaScript string into a Uint8Array.\n * @internal\n */\nexport function utf8StringToUint8Array(value: string): Uint8Array {\n return new TextEncoder().encode(value);\n}\n\n/**\n * Encodes a Base64 string into a Uint8Array.\n * @internal\n */\nexport function base64ToUint8Array(value: string): Uint8Array {\n return new Uint8Array([...atob(value)].map((x) => x.charCodeAt(0)));\n}\n\n/**\n * Encodes a Base64Url string into a Uint8Array.\n * @internal\n */\nexport function base64UrlToUint8Array(value: string): Uint8Array {\n const base64String = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n return base64ToUint8Array(base64String);\n}\n\nconst hexDigits = new Set(\"0123456789abcdefABCDEF\");\n\n/**\n * Encodes a hex string into a Uint8Array\n * @internal\n */\nexport function hexStringToUint8Array(value: string): Uint8Array {\n // If value has odd length, the last character will be ignored, consistent with NodeJS Buffer behavior\n const bytes = new Uint8Array(value.length / 2);\n for (let i = 0; i < value.length / 2; ++i) {\n const highNibble = value[2 * i];\n const lowNibble = value[2 * i + 1];\n if (!hexDigits.has(highNibble) || !hexDigits.has(lowNibble)) {\n // Replicate Node Buffer behavior by exiting early when we encounter an invalid byte\n return bytes.slice(0, i);\n }\n\n bytes[i] = parseInt(`${highNibble}${lowNibble}`, 16);\n }\n\n return bytes;\n}\n"]}
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The helper that transforms bytes with specific character encoding into string
|
|
5
|
-
* @param bytes - the uint8array bytes
|
|
6
|
-
* @param format - the format we use to encode the byte
|
|
7
|
-
* @returns a string of the encoded string
|
|
8
|
-
*/
|
|
9
|
-
export declare function uint8ArrayToString(bytes: Uint8Array, format: EncodingType): string;
|
|
10
|
-
/**
|
|
11
|
-
* The helper that transforms string to specific character encoded bytes array.
|
|
12
|
-
* @param value - the string to be converted
|
|
13
|
-
* @param format - the format we use to decode the value
|
|
14
|
-
* @returns a uint8array
|
|
15
|
-
*/
|
|
16
|
-
export declare function stringToUint8Array(value: string, format: EncodingType): Uint8Array;
|
|
17
|
-
//# sourceMappingURL=bytesEncoding.d.ts.map
|
|
1
|
+
export * from "./bytesEncoding.common.js";
|
|
2
|
+
//# sourceMappingURL=bytesEncoding-react-native.d.mts.map
|
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @param bytes - the uint8array bytes
|
|
6
|
-
* @param format - the format we use to encode the byte
|
|
7
|
-
* @returns a string of the encoded string
|
|
8
|
-
*/
|
|
9
|
-
export function uint8ArrayToString(bytes, format) {
|
|
10
|
-
return Buffer.from(bytes).toString(format);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* The helper that transforms string to specific character encoded bytes array.
|
|
14
|
-
* @param value - the string to be converted
|
|
15
|
-
* @param format - the format we use to decode the value
|
|
16
|
-
* @returns a uint8array
|
|
17
|
-
*/
|
|
18
|
-
export function stringToUint8Array(value, format) {
|
|
19
|
-
return Buffer.from(value, format);
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=bytesEncoding.js.map
|
|
3
|
+
export * from "./bytesEncoding.common.js";
|
|
4
|
+
//# sourceMappingURL=bytesEncoding-react-native.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concat-react-native.d.mts","sourceRoot":"","sources":["../../../src/util/concat-react-native.mts"],"names":[],"mappings":"AAGA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concat-react-native.mjs","sourceRoot":"","sources":["../../../src/util/concat-react-native.mts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,oBAAoB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport * from \"./concat.common.js\";\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/**
|
|
3
|
+
* Accepted binary data types for concat
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
type ConcatSource = ReadableStream<Uint8Array> | Blob | Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Utility function that concatenates a set of binary inputs into one combined output.
|
|
10
|
+
*
|
|
11
|
+
* @param sources - array of sources for the concatenation
|
|
12
|
+
* @returns - in Node, a (() =\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.
|
|
13
|
+
* In browser, returns a `Blob` representing all the concatenated inputs.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function concat(sources: (ConcatSource | (() => ConcatSource))[]): Promise<(() => NodeJS.ReadableStream) | Blob>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=concat.common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concat.common.d.ts","sourceRoot":"","sources":["../../../src/util/concat.common.ts"],"names":[],"mappings":";AAwCA;;;;GAIG;AACH,KAAK,YAAY,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,UAAU,CAAC;AAEnE;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE,CAAC,YAAY,GAAG,CAAC,MAAM,YAAY,CAAC,CAAC,EAAE,GAC/C,OAAO,CAAC,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAO/C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { getRawContent } from "./file.js";
|
|
4
|
+
import { isNodeReadableStream, isWebReadableStream } from "./typeGuards.js";
|
|
5
|
+
/**
|
|
6
|
+
* Drain the content of the given ReadableStream into a Blob.
|
|
7
|
+
* The blob's content may end up in memory or on disk dependent on size.
|
|
8
|
+
*/
|
|
9
|
+
function drain(stream) {
|
|
10
|
+
return new Response(stream).blob();
|
|
11
|
+
}
|
|
12
|
+
async function toBlobPart(source) {
|
|
13
|
+
if (source instanceof Blob || source instanceof Uint8Array) {
|
|
14
|
+
return source;
|
|
15
|
+
}
|
|
16
|
+
if (isWebReadableStream(source)) {
|
|
17
|
+
return drain(source);
|
|
18
|
+
}
|
|
19
|
+
// If it's not a true Blob, and it's not a Uint8Array, we can assume the source
|
|
20
|
+
// is a fake File created by createFileFromStream and we can get the original stream
|
|
21
|
+
// using getRawContent.
|
|
22
|
+
const rawContent = getRawContent(source);
|
|
23
|
+
// Shouldn't happen but guard for it anyway
|
|
24
|
+
if (isNodeReadableStream(rawContent)) {
|
|
25
|
+
throw new Error("Encountered unexpected type. In the browser, `concat` supports Web ReadableStream, Blob, Uint8Array, and files created using `createFile` only.");
|
|
26
|
+
}
|
|
27
|
+
return toBlobPart(rawContent);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Utility function that concatenates a set of binary inputs into one combined output.
|
|
31
|
+
*
|
|
32
|
+
* @param sources - array of sources for the concatenation
|
|
33
|
+
* @returns - in Node, a (() =\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.
|
|
34
|
+
* In browser, returns a `Blob` representing all the concatenated inputs.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export async function concat(sources) {
|
|
39
|
+
const parts = [];
|
|
40
|
+
for (const source of sources) {
|
|
41
|
+
parts.push(await toBlobPart(typeof source === "function" ? source() : source));
|
|
42
|
+
}
|
|
43
|
+
return new Blob(parts);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=concat.common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concat.common.js","sourceRoot":"","sources":["../../../src/util/concat.common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE5E;;;GAGG;AACH,SAAS,KAAK,CAAC,MAAkC;IAC/C,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;AACrC,CAAC;AAED,KAAK,UAAU,UAAU,CACvB,MAAsD;IAEtD,IAAI,MAAM,YAAY,IAAI,IAAI,MAAM,YAAY,UAAU,EAAE,CAAC;QAC3D,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,+EAA+E;IAC/E,oFAAoF;IACpF,uBAAuB;IACvB,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAEzC,2CAA2C;IAC3C,IAAI,oBAAoB,CAAC,UAAU,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,iJAAiJ,CAClJ,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC,UAAU,CAAC,CAAC;AAChC,CAAC;AASD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAgD;IAEhD,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { getRawContent } from \"./file.js\";\nimport { isNodeReadableStream, isWebReadableStream } from \"./typeGuards.js\";\n\n/**\n * Drain the content of the given ReadableStream into a Blob.\n * The blob's content may end up in memory or on disk dependent on size.\n */\nfunction drain(stream: ReadableStream<Uint8Array>): Promise<Blob> {\n return new Response(stream).blob();\n}\n\nasync function toBlobPart(\n source: ReadableStream<Uint8Array> | Blob | Uint8Array,\n): Promise<BlobPart> {\n if (source instanceof Blob || source instanceof Uint8Array) {\n return source;\n }\n\n if (isWebReadableStream(source)) {\n return drain(source);\n }\n\n // If it's not a true Blob, and it's not a Uint8Array, we can assume the source\n // is a fake File created by createFileFromStream and we can get the original stream\n // using getRawContent.\n const rawContent = getRawContent(source);\n\n // Shouldn't happen but guard for it anyway\n if (isNodeReadableStream(rawContent)) {\n throw new Error(\n \"Encountered unexpected type. In the browser, `concat` supports Web ReadableStream, Blob, Uint8Array, and files created using `createFile` only.\",\n );\n }\n\n return toBlobPart(rawContent);\n}\n\n/**\n * Accepted binary data types for concat\n *\n * @internal\n */\ntype ConcatSource = ReadableStream<Uint8Array> | Blob | Uint8Array;\n\n/**\n * Utility function that concatenates a set of binary inputs into one combined output.\n *\n * @param sources - array of sources for the concatenation\n * @returns - in Node, a (() =\\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.\n * In browser, returns a `Blob` representing all the concatenated inputs.\n *\n * @internal\n */\nexport async function concat(\n sources: (ConcatSource | (() => ConcatSource))[],\n): Promise<(() => NodeJS.ReadableStream) | Blob> {\n const parts = [];\n for (const source of sources) {\n parts.push(await toBlobPart(typeof source === \"function\" ? source() : source));\n }\n\n return new Blob(parts);\n}\n"]}
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Accepted binary data types for concat
|
|
4
|
-
*
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export type ConcatSource = ReadableStream<Uint8Array> | NodeJS.ReadableStream | Uint8Array | Blob;
|
|
8
|
-
/**
|
|
9
|
-
* Utility function that concatenates a set of binary inputs into one combined output.
|
|
10
|
-
*
|
|
11
|
-
* @param sources - array of sources for the concatenation
|
|
12
|
-
* @returns - in Node, a (() =\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.
|
|
13
|
-
* In browser, returns a `Blob` representing all the concatenated inputs.
|
|
14
|
-
*
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export declare function concat(sources: (ConcatSource | (() => ConcatSource))[]): Promise<(() => NodeJS.ReadableStream) | Blob>;
|
|
18
|
-
//# sourceMappingURL=concat.d.ts.map
|
|
1
|
+
export * from "./concat.common.js";
|
|
2
|
+
//# sourceMappingURL=concat-react-native.d.mts.map
|