@spyglasshq/sdk 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -14
- package/dist/cjs/BaseClient.d.ts +4 -4
- package/dist/cjs/BaseClient.js +7 -7
- package/dist/cjs/Client.d.ts +5 -5
- package/dist/cjs/Client.js +38 -56
- package/dist/cjs/api/client/index.d.ts +1 -1
- package/dist/cjs/api/client/requests/SearchBrandsRequest.js +6 -6
- package/dist/cjs/api/client/requests/SearchCreatorsRequest.js +174 -174
- package/dist/cjs/api/client/requests/SearchMediaRequest.d.ts +4 -0
- package/dist/cjs/api/client/requests/SearchMediaRequest.js +227 -223
- package/dist/cjs/api/client/requests/index.d.ts +5 -5
- package/dist/cjs/api/errors/BadRequestError.d.ts +3 -3
- package/dist/cjs/api/errors/BadRequestError.js +2 -2
- package/dist/cjs/api/errors/ContentTooLargeError.d.ts +3 -3
- package/dist/cjs/api/errors/ContentTooLargeError.js +2 -2
- package/dist/cjs/api/errors/ForbiddenError.d.ts +3 -3
- package/dist/cjs/api/errors/ForbiddenError.js +2 -2
- package/dist/cjs/api/errors/InternalServerError.d.ts +3 -3
- package/dist/cjs/api/errors/InternalServerError.js +2 -2
- package/dist/cjs/api/errors/MethodNotAllowedError.d.ts +3 -3
- package/dist/cjs/api/errors/MethodNotAllowedError.js +2 -2
- package/dist/cjs/api/errors/NotFoundError.d.ts +3 -3
- package/dist/cjs/api/errors/NotFoundError.js +2 -2
- package/dist/cjs/api/errors/PaymentRequiredError.d.ts +3 -3
- package/dist/cjs/api/errors/PaymentRequiredError.js +2 -2
- package/dist/cjs/api/errors/TooManyRequestsError.d.ts +3 -3
- package/dist/cjs/api/errors/TooManyRequestsError.js +2 -2
- package/dist/cjs/api/errors/UnauthorizedError.d.ts +3 -3
- package/dist/cjs/api/errors/UnauthorizedError.js +2 -2
- package/dist/cjs/api/errors/index.d.ts +9 -9
- package/dist/cjs/api/index.d.ts +4 -4
- package/dist/cjs/api/resources/account/client/Client.d.ts +4 -4
- package/dist/cjs/api/resources/account/client/Client.js +31 -52
- package/dist/cjs/api/resources/account/client/index.d.ts +1 -1
- package/dist/cjs/api/resources/account/client/requests/CampaignsAccountRequest.d.ts +1 -1
- package/dist/cjs/api/resources/account/client/requests/InsightsAccountRequest.d.ts +1 -1
- package/dist/cjs/api/resources/account/client/requests/LandingPagesAccountRequest.d.ts +1 -1
- package/dist/cjs/api/resources/account/client/requests/index.d.ts +7 -7
- package/dist/cjs/api/resources/account/exports.d.ts +2 -2
- package/dist/cjs/api/resources/account/index.d.ts +2 -2
- package/dist/cjs/api/resources/account/types/CampaignsAccountRequestDatePreset.js +14 -14
- package/dist/cjs/api/resources/account/types/CampaignsAccountRequestSortBy.js +2 -2
- package/dist/cjs/api/resources/account/types/CampaignsAccountRequestType.js +2 -2
- package/dist/cjs/api/resources/account/types/GetAccountResponse.d.ts +3 -3
- package/dist/cjs/api/resources/account/types/IndexAccountResponse.js +2 -2
- package/dist/cjs/api/resources/account/types/IndexStatusAccountResponse.js +2 -2
- package/dist/cjs/api/resources/account/types/InsightsAccountRequestType.js +4 -4
- package/dist/cjs/api/resources/account/types/InsightsAccountResponse.d.ts +2 -2
- package/dist/cjs/api/resources/account/types/LandingPagesAccountRequestShowInactive.js +2 -2
- package/dist/cjs/api/resources/account/types/index.d.ts +12 -12
- package/dist/cjs/api/resources/index.d.ts +3 -3
- package/dist/cjs/api/types/Error_.js +11 -11
- package/dist/cjs/api/types/SearchBrandsResponse.js +1 -1
- package/dist/cjs/api/types/SearchCreatorsResponse.js +1 -1
- package/dist/cjs/api/types/SearchMediaResponse.js +26 -26
- package/dist/cjs/api/types/index.d.ts +7 -7
- package/dist/cjs/auth/BearerAuthProvider.d.ts +1 -1
- package/dist/cjs/auth/BearerAuthProvider.js +2 -2
- package/dist/cjs/auth/index.d.ts +1 -1
- package/dist/cjs/core/auth/AuthProvider.d.ts +2 -2
- package/dist/cjs/core/auth/AuthProvider.js +3 -3
- package/dist/cjs/core/auth/BasicAuth.js +7 -7
- package/dist/cjs/core/auth/BearerToken.js +1 -1
- package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +2 -2
- package/dist/cjs/core/auth/index.d.ts +5 -5
- package/dist/cjs/core/base64.js +4 -4
- package/dist/cjs/core/exports.d.ts +1 -1
- package/dist/cjs/core/fetcher/APIResponse.d.ts +1 -1
- package/dist/cjs/core/fetcher/BinaryResponse.d.ts +4 -4
- package/dist/cjs/core/fetcher/BinaryResponse.js +1 -1
- package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +2 -2
- package/dist/cjs/core/fetcher/EndpointSupplier.js +1 -1
- package/dist/cjs/core/fetcher/Fetcher.d.ts +11 -11
- package/dist/cjs/core/fetcher/Fetcher.js +50 -56
- package/dist/cjs/core/fetcher/Headers.js +10 -10
- package/dist/cjs/core/fetcher/HttpResponsePromise.d.ts +2 -2
- package/dist/cjs/core/fetcher/RawResponse.d.ts +1 -1
- package/dist/cjs/core/fetcher/RawResponse.js +6 -6
- package/dist/cjs/core/fetcher/Supplier.js +1 -1
- package/dist/cjs/core/fetcher/createRequestUrl.js +1 -1
- package/dist/cjs/core/fetcher/getErrorResponseBody.js +11 -11
- package/dist/cjs/core/fetcher/getRequestBody.d.ts +2 -2
- package/dist/cjs/core/fetcher/getRequestBody.js +4 -4
- package/dist/cjs/core/fetcher/getResponseBody.d.ts +2 -2
- package/dist/cjs/core/fetcher/getResponseBody.js +11 -11
- package/dist/cjs/core/fetcher/index.d.ts +13 -13
- package/dist/cjs/core/fetcher/makePassthroughRequest.d.ts +2 -2
- package/dist/cjs/core/fetcher/makePassthroughRequest.js +7 -7
- package/dist/cjs/core/fetcher/makeRequest.js +3 -3
- package/dist/cjs/core/fetcher/redactUrl.js +36 -36
- package/dist/cjs/core/fetcher/requestWithRetries.js +4 -4
- package/dist/cjs/core/fetcher/signals.js +2 -2
- package/dist/cjs/core/index.d.ts +6 -6
- package/dist/cjs/core/logging/exports.d.ts +1 -1
- package/dist/cjs/core/logging/index.d.ts +1 -1
- package/dist/cjs/core/logging/logger.js +4 -4
- package/dist/cjs/core/requestBody.js +1 -1
- package/dist/cjs/core/runtime/index.d.ts +1 -1
- package/dist/cjs/core/runtime/runtime.d.ts +1 -1
- package/dist/cjs/core/runtime/runtime.js +35 -37
- package/dist/cjs/core/url/QueryStringBuilder.d.ts +1 -1
- package/dist/cjs/core/url/QueryStringBuilder.js +3 -3
- package/dist/cjs/core/url/encodePathParam.js +8 -10
- package/dist/cjs/core/url/index.d.ts +4 -4
- package/dist/cjs/core/url/join.js +11 -11
- package/dist/cjs/core/url/qs.d.ts +1 -1
- package/dist/cjs/core/url/qs.js +14 -14
- package/dist/cjs/environments.js +1 -1
- package/dist/cjs/errors/SpyglassError.d.ts +1 -1
- package/dist/cjs/errors/SpyglassError.js +3 -3
- package/dist/cjs/errors/SpyglassTimeoutError.d.ts +1 -1
- package/dist/cjs/errors/SpyglassTimeoutError.js +1 -1
- package/dist/cjs/errors/handleNonStatusCodeError.d.ts +1 -1
- package/dist/cjs/errors/handleNonStatusCodeError.js +5 -5
- package/dist/cjs/errors/index.d.ts +2 -2
- package/dist/cjs/exports.d.ts +1 -1
- package/dist/cjs/index.d.ts +6 -6
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +4 -4
- package/dist/esm/BaseClient.mjs +10 -10
- package/dist/esm/Client.d.mts +5 -5
- package/dist/esm/Client.mjs +47 -65
- package/dist/esm/api/client/index.d.mts +1 -1
- package/dist/esm/api/client/index.mjs +1 -1
- package/dist/esm/api/client/requests/SearchBrandsRequest.mjs +6 -6
- package/dist/esm/api/client/requests/SearchCreatorsRequest.mjs +174 -174
- package/dist/esm/api/client/requests/SearchMediaRequest.d.mts +4 -0
- package/dist/esm/api/client/requests/SearchMediaRequest.mjs +227 -223
- package/dist/esm/api/client/requests/index.d.mts +5 -5
- package/dist/esm/api/client/requests/index.mjs +3 -3
- package/dist/esm/api/errors/BadRequestError.d.mts +3 -3
- package/dist/esm/api/errors/BadRequestError.mjs +3 -3
- package/dist/esm/api/errors/ContentTooLargeError.d.mts +3 -3
- package/dist/esm/api/errors/ContentTooLargeError.mjs +3 -3
- package/dist/esm/api/errors/ForbiddenError.d.mts +3 -3
- package/dist/esm/api/errors/ForbiddenError.mjs +3 -3
- package/dist/esm/api/errors/InternalServerError.d.mts +3 -3
- package/dist/esm/api/errors/InternalServerError.mjs +3 -3
- package/dist/esm/api/errors/MethodNotAllowedError.d.mts +3 -3
- package/dist/esm/api/errors/MethodNotAllowedError.mjs +3 -3
- package/dist/esm/api/errors/NotFoundError.d.mts +3 -3
- package/dist/esm/api/errors/NotFoundError.mjs +3 -3
- package/dist/esm/api/errors/PaymentRequiredError.d.mts +3 -3
- package/dist/esm/api/errors/PaymentRequiredError.mjs +3 -3
- package/dist/esm/api/errors/TooManyRequestsError.d.mts +3 -3
- package/dist/esm/api/errors/TooManyRequestsError.mjs +3 -3
- package/dist/esm/api/errors/UnauthorizedError.d.mts +3 -3
- package/dist/esm/api/errors/UnauthorizedError.mjs +3 -3
- package/dist/esm/api/errors/index.d.mts +9 -9
- package/dist/esm/api/errors/index.mjs +9 -9
- package/dist/esm/api/index.d.mts +4 -4
- package/dist/esm/api/index.mjs +4 -4
- package/dist/esm/api/resources/account/client/Client.d.mts +4 -4
- package/dist/esm/api/resources/account/client/Client.mjs +39 -60
- package/dist/esm/api/resources/account/client/index.d.mts +1 -1
- package/dist/esm/api/resources/account/client/index.mjs +1 -1
- package/dist/esm/api/resources/account/client/requests/CampaignsAccountRequest.d.mts +1 -1
- package/dist/esm/api/resources/account/client/requests/InsightsAccountRequest.d.mts +1 -1
- package/dist/esm/api/resources/account/client/requests/LandingPagesAccountRequest.d.mts +1 -1
- package/dist/esm/api/resources/account/client/requests/index.d.mts +7 -7
- package/dist/esm/api/resources/account/exports.d.mts +2 -2
- package/dist/esm/api/resources/account/exports.mjs +2 -2
- package/dist/esm/api/resources/account/index.d.mts +2 -2
- package/dist/esm/api/resources/account/index.mjs +2 -2
- package/dist/esm/api/resources/account/types/CampaignsAccountRequestDatePreset.mjs +14 -14
- package/dist/esm/api/resources/account/types/CampaignsAccountRequestSortBy.mjs +2 -2
- package/dist/esm/api/resources/account/types/CampaignsAccountRequestType.mjs +2 -2
- package/dist/esm/api/resources/account/types/GetAccountResponse.d.mts +3 -3
- package/dist/esm/api/resources/account/types/IndexAccountResponse.mjs +2 -2
- package/dist/esm/api/resources/account/types/IndexStatusAccountResponse.mjs +2 -2
- package/dist/esm/api/resources/account/types/InsightsAccountRequestType.mjs +4 -4
- package/dist/esm/api/resources/account/types/InsightsAccountResponse.d.mts +2 -2
- package/dist/esm/api/resources/account/types/LandingPagesAccountRequestShowInactive.mjs +2 -2
- package/dist/esm/api/resources/account/types/index.d.mts +12 -12
- package/dist/esm/api/resources/account/types/index.mjs +12 -12
- package/dist/esm/api/resources/index.d.mts +3 -3
- package/dist/esm/api/resources/index.mjs +3 -3
- package/dist/esm/api/types/Error_.mjs +11 -11
- package/dist/esm/api/types/SearchBrandsResponse.mjs +1 -1
- package/dist/esm/api/types/SearchCreatorsResponse.mjs +1 -1
- package/dist/esm/api/types/SearchMediaResponse.mjs +26 -26
- package/dist/esm/api/types/index.d.mts +7 -7
- package/dist/esm/api/types/index.mjs +7 -7
- package/dist/esm/auth/BearerAuthProvider.d.mts +1 -1
- package/dist/esm/auth/BearerAuthProvider.mjs +4 -4
- package/dist/esm/auth/index.d.mts +1 -1
- package/dist/esm/auth/index.mjs +1 -1
- package/dist/esm/core/auth/AuthProvider.d.mts +2 -2
- package/dist/esm/core/auth/AuthProvider.mjs +3 -3
- package/dist/esm/core/auth/BasicAuth.mjs +8 -8
- package/dist/esm/core/auth/BearerToken.mjs +1 -1
- package/dist/esm/core/auth/NoOpAuthProvider.d.mts +2 -2
- package/dist/esm/core/auth/index.d.mts +5 -5
- package/dist/esm/core/auth/index.mjs +4 -4
- package/dist/esm/core/base64.mjs +4 -4
- package/dist/esm/core/exports.d.mts +1 -1
- package/dist/esm/core/exports.mjs +1 -1
- package/dist/esm/core/fetcher/APIResponse.d.mts +1 -1
- package/dist/esm/core/fetcher/BinaryResponse.d.mts +4 -4
- package/dist/esm/core/fetcher/BinaryResponse.mjs +1 -1
- package/dist/esm/core/fetcher/EndpointSupplier.d.mts +2 -2
- package/dist/esm/core/fetcher/EndpointSupplier.mjs +1 -1
- package/dist/esm/core/fetcher/Fetcher.d.mts +11 -11
- package/dist/esm/core/fetcher/Fetcher.mjs +64 -70
- package/dist/esm/core/fetcher/Headers.mjs +10 -10
- package/dist/esm/core/fetcher/HttpResponsePromise.d.mts +2 -2
- package/dist/esm/core/fetcher/RawResponse.d.mts +1 -1
- package/dist/esm/core/fetcher/RawResponse.mjs +7 -7
- package/dist/esm/core/fetcher/Supplier.mjs +1 -1
- package/dist/esm/core/fetcher/createRequestUrl.mjs +2 -2
- package/dist/esm/core/fetcher/getErrorResponseBody.mjs +13 -13
- package/dist/esm/core/fetcher/getRequestBody.d.mts +2 -2
- package/dist/esm/core/fetcher/getRequestBody.mjs +6 -6
- package/dist/esm/core/fetcher/getResponseBody.d.mts +2 -2
- package/dist/esm/core/fetcher/getResponseBody.mjs +13 -13
- package/dist/esm/core/fetcher/index.d.mts +13 -13
- package/dist/esm/core/fetcher/index.mjs +7 -7
- package/dist/esm/core/fetcher/makePassthroughRequest.d.mts +2 -2
- package/dist/esm/core/fetcher/makePassthroughRequest.mjs +16 -16
- package/dist/esm/core/fetcher/makeRequest.mjs +4 -4
- package/dist/esm/core/fetcher/redactUrl.mjs +36 -36
- package/dist/esm/core/fetcher/requestWithRetries.mjs +4 -4
- package/dist/esm/core/fetcher/signals.mjs +2 -2
- package/dist/esm/core/index.d.mts +6 -6
- package/dist/esm/core/index.mjs +6 -6
- package/dist/esm/core/logging/exports.d.mts +1 -1
- package/dist/esm/core/logging/exports.mjs +1 -1
- package/dist/esm/core/logging/index.d.mts +1 -1
- package/dist/esm/core/logging/index.mjs +1 -1
- package/dist/esm/core/logging/logger.mjs +4 -4
- package/dist/esm/core/requestBody.mjs +1 -1
- package/dist/esm/core/runtime/index.d.mts +1 -1
- package/dist/esm/core/runtime/index.mjs +1 -1
- package/dist/esm/core/runtime/runtime.d.mts +1 -1
- package/dist/esm/core/runtime/runtime.mjs +35 -37
- package/dist/esm/core/url/QueryStringBuilder.d.mts +1 -1
- package/dist/esm/core/url/QueryStringBuilder.mjs +4 -4
- package/dist/esm/core/url/encodePathParam.mjs +8 -10
- package/dist/esm/core/url/index.d.mts +4 -4
- package/dist/esm/core/url/index.mjs +4 -4
- package/dist/esm/core/url/join.mjs +11 -11
- package/dist/esm/core/url/qs.d.mts +1 -1
- package/dist/esm/core/url/qs.mjs +14 -14
- package/dist/esm/environments.mjs +1 -1
- package/dist/esm/errors/SpyglassError.d.mts +1 -1
- package/dist/esm/errors/SpyglassError.mjs +4 -4
- package/dist/esm/errors/SpyglassTimeoutError.d.mts +1 -1
- package/dist/esm/errors/SpyglassTimeoutError.mjs +2 -2
- package/dist/esm/errors/handleNonStatusCodeError.d.mts +1 -1
- package/dist/esm/errors/handleNonStatusCodeError.mjs +6 -6
- package/dist/esm/errors/index.d.mts +2 -2
- package/dist/esm/errors/index.mjs +2 -2
- package/dist/esm/exports.d.mts +1 -1
- package/dist/esm/exports.mjs +1 -1
- package/dist/esm/index.d.mts +6 -6
- package/dist/esm/index.mjs +5 -5
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +91 -91
- package/reference.md +97 -98
|
@@ -25,7 +25,7 @@ function isCacheNoStoreSupported() {
|
|
|
25
25
|
return _cacheNoStoreSupported;
|
|
26
26
|
}
|
|
27
27
|
try {
|
|
28
|
-
new Request(
|
|
28
|
+
new Request("http://localhost", { cache: "no-store" });
|
|
29
29
|
_cacheNoStoreSupported = true;
|
|
30
30
|
}
|
|
31
31
|
catch (_a) {
|
|
@@ -67,9 +67,9 @@ const makeRequest = (fetchFn, url, method, headers, requestBody, timeoutMs, abor
|
|
|
67
67
|
const newSignals = (0, signals_js_1.anySignal)(signals);
|
|
68
68
|
let response;
|
|
69
69
|
try {
|
|
70
|
-
response = yield fetchFn(url, Object.assign({ method: method, headers, body: requestBody, signal: newSignals, credentials: withCredentials ?
|
|
70
|
+
response = yield fetchFn(url, Object.assign({ method: method, headers, body: requestBody, signal: newSignals, credentials: withCredentials ? "include" : undefined,
|
|
71
71
|
// @ts-ignore
|
|
72
|
-
duplex }, (disableCache && isCacheNoStoreSupported() ? { cache:
|
|
72
|
+
duplex }, (disableCache && isCacheNoStoreSupported() ? { cache: "no-store" } : {})));
|
|
73
73
|
}
|
|
74
74
|
catch (error) {
|
|
75
75
|
if (timeoutAbortId != null) {
|
|
@@ -3,39 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SENSITIVE_QUERY_PARAMS = void 0;
|
|
4
4
|
exports.redactUrl = redactUrl;
|
|
5
5
|
exports.SENSITIVE_QUERY_PARAMS = new Set([
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
"api_key",
|
|
7
|
+
"api-key",
|
|
8
|
+
"apikey",
|
|
9
|
+
"token",
|
|
10
|
+
"access_token",
|
|
11
|
+
"access-token",
|
|
12
|
+
"auth_token",
|
|
13
|
+
"auth-token",
|
|
14
|
+
"password",
|
|
15
|
+
"passwd",
|
|
16
|
+
"secret",
|
|
17
|
+
"api_secret",
|
|
18
|
+
"api-secret",
|
|
19
|
+
"apisecret",
|
|
20
|
+
"key",
|
|
21
|
+
"session",
|
|
22
|
+
"session_id",
|
|
23
|
+
"session-id",
|
|
24
24
|
]);
|
|
25
25
|
function redactUrl(url) {
|
|
26
|
-
const protocolIndex = url.indexOf(
|
|
26
|
+
const protocolIndex = url.indexOf("://");
|
|
27
27
|
if (protocolIndex === -1)
|
|
28
28
|
return url;
|
|
29
29
|
const afterProtocol = protocolIndex + 3;
|
|
30
30
|
// Find the first delimiter that marks the end of the authority section
|
|
31
|
-
const pathStart = url.indexOf(
|
|
32
|
-
let queryStart = url.indexOf(
|
|
33
|
-
let fragmentStart = url.indexOf(
|
|
31
|
+
const pathStart = url.indexOf("/", afterProtocol);
|
|
32
|
+
let queryStart = url.indexOf("?", afterProtocol);
|
|
33
|
+
let fragmentStart = url.indexOf("#", afterProtocol);
|
|
34
34
|
const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
|
|
35
35
|
// Find the LAST @ before the delimiter (handles multiple @ in credentials)
|
|
36
36
|
let atIndex = -1;
|
|
37
37
|
for (let i = afterProtocol; i < firstDelimiter; i++) {
|
|
38
|
-
if (url[i] ===
|
|
38
|
+
if (url[i] === "@") {
|
|
39
39
|
atIndex = i;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -43,10 +43,10 @@ function redactUrl(url) {
|
|
|
43
43
|
url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
|
|
44
44
|
}
|
|
45
45
|
// Recalculate queryStart since url might have changed
|
|
46
|
-
queryStart = url.indexOf(
|
|
46
|
+
queryStart = url.indexOf("?");
|
|
47
47
|
if (queryStart === -1)
|
|
48
48
|
return url;
|
|
49
|
-
fragmentStart = url.indexOf(
|
|
49
|
+
fragmentStart = url.indexOf("#", queryStart);
|
|
50
50
|
const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
|
|
51
51
|
const queryString = url.slice(queryStart + 1, queryEnd);
|
|
52
52
|
if (queryString.length === 0)
|
|
@@ -54,28 +54,28 @@ function redactUrl(url) {
|
|
|
54
54
|
// FAST PATH: Quick check if any sensitive keywords present
|
|
55
55
|
// Using indexOf is faster than regex for simple substring matching
|
|
56
56
|
const lower = queryString.toLowerCase();
|
|
57
|
-
const hasSensitive = lower.includes(
|
|
58
|
-
lower.includes(
|
|
59
|
-
lower.includes(
|
|
60
|
-
lower.includes(
|
|
61
|
-
lower.includes(
|
|
62
|
-
lower.includes(
|
|
63
|
-
lower.includes(
|
|
57
|
+
const hasSensitive = lower.includes("token") ||
|
|
58
|
+
lower.includes("key") ||
|
|
59
|
+
lower.includes("password") ||
|
|
60
|
+
lower.includes("passwd") ||
|
|
61
|
+
lower.includes("secret") ||
|
|
62
|
+
lower.includes("session") ||
|
|
63
|
+
lower.includes("auth");
|
|
64
64
|
if (!hasSensitive) {
|
|
65
65
|
return url;
|
|
66
66
|
}
|
|
67
67
|
// SLOW PATH: Parse and redact
|
|
68
68
|
const redactedParams = [];
|
|
69
|
-
const params = queryString.split(
|
|
69
|
+
const params = queryString.split("&");
|
|
70
70
|
for (const param of params) {
|
|
71
|
-
const equalIndex = param.indexOf(
|
|
71
|
+
const equalIndex = param.indexOf("=");
|
|
72
72
|
if (equalIndex === -1) {
|
|
73
73
|
redactedParams.push(param);
|
|
74
74
|
continue;
|
|
75
75
|
}
|
|
76
76
|
const key = param.slice(0, equalIndex);
|
|
77
77
|
let shouldRedact = exports.SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
|
|
78
|
-
if (!shouldRedact && key.includes(
|
|
78
|
+
if (!shouldRedact && key.includes("%")) {
|
|
79
79
|
try {
|
|
80
80
|
const decodedKey = decodeURIComponent(key);
|
|
81
81
|
shouldRedact = exports.SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
|
|
@@ -84,5 +84,5 @@ function redactUrl(url) {
|
|
|
84
84
|
}
|
|
85
85
|
redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
|
|
86
86
|
}
|
|
87
|
-
return url.slice(0, queryStart + 1) + redactedParams.join(
|
|
87
|
+
return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
|
|
88
88
|
}
|
|
@@ -26,7 +26,7 @@ function addSymmetricJitter(delay) {
|
|
|
26
26
|
return delay * jitterMultiplier;
|
|
27
27
|
}
|
|
28
28
|
function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
29
|
-
const retryAfter = response.headers.get(
|
|
29
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
30
30
|
if (retryAfter) {
|
|
31
31
|
const retryAfterSeconds = parseInt(retryAfter, 10);
|
|
32
32
|
if (!Number.isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
|
|
@@ -40,7 +40,7 @@ function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
const rateLimitReset = response.headers.get(
|
|
43
|
+
const rateLimitReset = response.headers.get("X-RateLimit-Reset");
|
|
44
44
|
if (rateLimitReset) {
|
|
45
45
|
const resetTime = parseInt(rateLimitReset, 10);
|
|
46
46
|
if (!Number.isNaN(resetTime)) {
|
|
@@ -67,10 +67,10 @@ function sleep(ms, abortSignal) {
|
|
|
67
67
|
reject(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.reason);
|
|
68
68
|
};
|
|
69
69
|
const timeoutId = setTimeout(() => {
|
|
70
|
-
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener(
|
|
70
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener("abort", onAbort);
|
|
71
71
|
resolve();
|
|
72
72
|
}, ms);
|
|
73
|
-
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener(
|
|
73
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
function requestWithRetries(requestFn_1) {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TIMEOUT = void 0;
|
|
4
4
|
exports.getTimeoutSignal = getTimeoutSignal;
|
|
5
5
|
exports.anySignal = anySignal;
|
|
6
|
-
exports.TIMEOUT =
|
|
6
|
+
exports.TIMEOUT = "timeout";
|
|
7
7
|
function getTimeoutSignal(timeoutMs) {
|
|
8
8
|
const controller = new AbortController();
|
|
9
9
|
const abortId = setTimeout(() => controller.abort(exports.TIMEOUT), timeoutMs);
|
|
@@ -17,7 +17,7 @@ function anySignal(...args) {
|
|
|
17
17
|
controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
|
|
18
18
|
return controller.signal;
|
|
19
19
|
}
|
|
20
|
-
signal.addEventListener(
|
|
20
|
+
signal.addEventListener("abort", () => controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason), {
|
|
21
21
|
signal: controller.signal,
|
|
22
22
|
});
|
|
23
23
|
// Re-check after adding listener: the signal may have aborted
|
package/dist/cjs/core/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * as logging from
|
|
5
|
-
export * from
|
|
6
|
-
export * as url from
|
|
1
|
+
export * from "./auth/index.js";
|
|
2
|
+
export * from "./base64.js";
|
|
3
|
+
export * from "./fetcher/index.js";
|
|
4
|
+
export * as logging from "./logging/index.js";
|
|
5
|
+
export * from "./runtime/index.js";
|
|
6
|
+
export * as url from "./url/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./logger.js";
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Logger = exports.ConsoleLogger = exports.LogLevel = void 0;
|
|
4
4
|
exports.createLogger = createLogger;
|
|
5
5
|
exports.LogLevel = {
|
|
6
|
-
Debug:
|
|
7
|
-
Info:
|
|
8
|
-
Warn:
|
|
9
|
-
Error:
|
|
6
|
+
Debug: "debug",
|
|
7
|
+
Info: "info",
|
|
8
|
+
Warn: "warn",
|
|
9
|
+
Error: "error",
|
|
10
10
|
};
|
|
11
11
|
const logLevelMap = {
|
|
12
12
|
[exports.LogLevel.Debug]: 1,
|
|
@@ -19,7 +19,7 @@ function mergeAdditionalBodyParameters(body, additionalBodyParameters) {
|
|
|
19
19
|
if (body == null) {
|
|
20
20
|
return Object.assign({}, additionalBodyParameters);
|
|
21
21
|
}
|
|
22
|
-
if (typeof body ===
|
|
22
|
+
if (typeof body === "object" && !Array.isArray(body)) {
|
|
23
23
|
return Object.assign(Object.assign({}, body), additionalBodyParameters);
|
|
24
24
|
}
|
|
25
25
|
return body;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getUserAgent, RUNTIME } from
|
|
1
|
+
export { getUserAgent, RUNTIME } from "./runtime.js";
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export declare const RUNTIME: Runtime;
|
|
5
5
|
export interface Runtime {
|
|
6
|
-
type:
|
|
6
|
+
type: "browser" | "web-worker" | "deno" | "bun" | "node" | "react-native" | "unknown" | "workerd" | "edge-runtime";
|
|
7
7
|
version?: string;
|
|
8
8
|
parsedVersion?: number;
|
|
9
9
|
/**
|
|
@@ -11,10 +11,10 @@ function evaluateRuntime() {
|
|
|
11
11
|
/**
|
|
12
12
|
* A constant that indicates whether the environment the code is running is a Web Browser.
|
|
13
13
|
*/
|
|
14
|
-
const isBrowser = typeof window !==
|
|
14
|
+
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
15
15
|
if (isBrowser) {
|
|
16
16
|
return {
|
|
17
|
-
type:
|
|
17
|
+
type: "browser",
|
|
18
18
|
version: window.navigator.userAgent,
|
|
19
19
|
};
|
|
20
20
|
}
|
|
@@ -22,45 +22,43 @@ function evaluateRuntime() {
|
|
|
22
22
|
* A constant that indicates whether the environment the code is running is Cloudflare.
|
|
23
23
|
* https://developers.cloudflare.com/workers/runtime-apis/web-standards/#navigatoruseragent
|
|
24
24
|
*/
|
|
25
|
-
const isCloudflare = typeof globalThis !==
|
|
25
|
+
const isCloudflare = typeof globalThis !== "undefined" && ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === "Cloudflare-Workers";
|
|
26
26
|
if (isCloudflare) {
|
|
27
27
|
return {
|
|
28
|
-
type:
|
|
28
|
+
type: "workerd",
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* A constant that indicates whether the environment the code is running is Edge Runtime.
|
|
33
33
|
* https://vercel.com/docs/functions/runtimes/edge-runtime#check-if-you're-running-on-the-edge-runtime
|
|
34
34
|
*/
|
|
35
|
-
const isEdgeRuntime = typeof EdgeRuntime ===
|
|
35
|
+
const isEdgeRuntime = typeof EdgeRuntime === "string";
|
|
36
36
|
if (isEdgeRuntime) {
|
|
37
37
|
return {
|
|
38
|
-
type:
|
|
38
|
+
type: "edge-runtime",
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* A constant that indicates whether the environment the code is running is a Web Worker.
|
|
43
43
|
*/
|
|
44
|
-
const isWebWorker = typeof self ===
|
|
45
|
-
typeof (self === null || self === void 0 ? void 0 : self.importScripts) ===
|
|
46
|
-
(((_b = self.constructor) === null || _b === void 0 ? void 0 : _b.name) ===
|
|
47
|
-
((_c = self.constructor) === null || _c === void 0 ? void 0 : _c.name) ===
|
|
48
|
-
((_d = self.constructor) === null || _d === void 0 ? void 0 : _d.name) ===
|
|
44
|
+
const isWebWorker = typeof self === "object" &&
|
|
45
|
+
typeof (self === null || self === void 0 ? void 0 : self.importScripts) === "function" &&
|
|
46
|
+
(((_b = self.constructor) === null || _b === void 0 ? void 0 : _b.name) === "DedicatedWorkerGlobalScope" ||
|
|
47
|
+
((_c = self.constructor) === null || _c === void 0 ? void 0 : _c.name) === "ServiceWorkerGlobalScope" ||
|
|
48
|
+
((_d = self.constructor) === null || _d === void 0 ? void 0 : _d.name) === "SharedWorkerGlobalScope");
|
|
49
49
|
if (isWebWorker) {
|
|
50
50
|
return {
|
|
51
|
-
type:
|
|
51
|
+
type: "web-worker",
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* A constant that indicates whether the environment the code is running is Deno.
|
|
56
56
|
* FYI Deno spoofs process.versions.node, see https://deno.land/std@0.177.0/node/process.ts?s=versions
|
|
57
57
|
*/
|
|
58
|
-
const isDeno = typeof Deno !==
|
|
59
|
-
typeof Deno.version !== 'undefined' &&
|
|
60
|
-
typeof Deno.version.deno !== 'undefined';
|
|
58
|
+
const isDeno = typeof Deno !== "undefined" && typeof Deno.version !== "undefined" && typeof Deno.version.deno !== "undefined";
|
|
61
59
|
if (isDeno) {
|
|
62
60
|
return {
|
|
63
|
-
type:
|
|
61
|
+
type: "deno",
|
|
64
62
|
version: Deno.version.deno,
|
|
65
63
|
os: (_e = Deno.build) === null || _e === void 0 ? void 0 : _e.os,
|
|
66
64
|
arch: (_f = Deno.build) === null || _f === void 0 ? void 0 : _f.arch,
|
|
@@ -69,13 +67,13 @@ function evaluateRuntime() {
|
|
|
69
67
|
/**
|
|
70
68
|
* A constant that indicates whether the environment the code is running is Bun.sh.
|
|
71
69
|
*/
|
|
72
|
-
const isBun = typeof Bun !==
|
|
70
|
+
const isBun = typeof Bun !== "undefined" && typeof Bun.version !== "undefined";
|
|
73
71
|
if (isBun) {
|
|
74
72
|
return {
|
|
75
|
-
type:
|
|
73
|
+
type: "bun",
|
|
76
74
|
version: Bun.version,
|
|
77
|
-
os: typeof process !==
|
|
78
|
-
arch: typeof process !==
|
|
75
|
+
os: typeof process !== "undefined" ? process.platform : undefined,
|
|
76
|
+
arch: typeof process !== "undefined" ? process.arch : undefined,
|
|
79
77
|
};
|
|
80
78
|
}
|
|
81
79
|
/**
|
|
@@ -83,10 +81,10 @@ function evaluateRuntime() {
|
|
|
83
81
|
* This check should come before Node.js detection since React Native may have a process polyfill.
|
|
84
82
|
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
|
|
85
83
|
*/
|
|
86
|
-
const isReactNative = typeof navigator !==
|
|
84
|
+
const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
|
|
87
85
|
if (isReactNative) {
|
|
88
86
|
return {
|
|
89
|
-
type:
|
|
87
|
+
type: "react-native",
|
|
90
88
|
};
|
|
91
89
|
}
|
|
92
90
|
/**
|
|
@@ -96,19 +94,19 @@ function evaluateRuntime() {
|
|
|
96
94
|
* bundlers that perform static analysis on `process.versions` (e.g. Next.js
|
|
97
95
|
* Edge Runtime warns about Node.js APIs even when they are guarded).
|
|
98
96
|
*/
|
|
99
|
-
const _process = typeof process !==
|
|
100
|
-
const isNode = typeof _process !==
|
|
97
|
+
const _process = typeof process !== "undefined" ? process : undefined;
|
|
98
|
+
const isNode = typeof _process !== "undefined" && typeof ((_g = _process.versions) === null || _g === void 0 ? void 0 : _g.node) === "string";
|
|
101
99
|
if (isNode) {
|
|
102
100
|
return {
|
|
103
|
-
type:
|
|
101
|
+
type: "node",
|
|
104
102
|
version: _process.versions.node,
|
|
105
|
-
parsedVersion: Number(_process.versions.node.split(
|
|
103
|
+
parsedVersion: Number(_process.versions.node.split(".")[0]),
|
|
106
104
|
os: _process.platform,
|
|
107
105
|
arch: _process.arch,
|
|
108
106
|
};
|
|
109
107
|
}
|
|
110
108
|
return {
|
|
111
|
-
type:
|
|
109
|
+
type: "unknown",
|
|
112
110
|
};
|
|
113
111
|
}
|
|
114
112
|
/**
|
|
@@ -118,14 +116,14 @@ function evaluateRuntime() {
|
|
|
118
116
|
* to `undefined` so they are omitted from the User-Agent.
|
|
119
117
|
*/
|
|
120
118
|
const RUNTIME_DISPLAY_NAMES = {
|
|
121
|
-
node:
|
|
122
|
-
deno:
|
|
123
|
-
bun:
|
|
119
|
+
node: "Node",
|
|
120
|
+
deno: "Deno",
|
|
121
|
+
bun: "Bun",
|
|
124
122
|
browser: undefined,
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
"web-worker": undefined,
|
|
124
|
+
"react-native": undefined,
|
|
127
125
|
workerd: undefined,
|
|
128
|
-
|
|
126
|
+
"edge-runtime": undefined,
|
|
129
127
|
unknown: undefined,
|
|
130
128
|
};
|
|
131
129
|
/**
|
|
@@ -134,7 +132,7 @@ const RUNTIME_DISPLAY_NAMES = {
|
|
|
134
132
|
* consistent regardless of which runtime reports it (Node reports `x64`, others
|
|
135
133
|
* report `amd64` or `x86_64`).
|
|
136
134
|
*/
|
|
137
|
-
const X86_64_ARCH_ALIASES = new Set([
|
|
135
|
+
const X86_64_ARCH_ALIASES = new Set(["x64", "amd64", "x86_64"]);
|
|
138
136
|
/**
|
|
139
137
|
* Normalizes a CPU architecture token, collapsing the 64-bit x86 aliases
|
|
140
138
|
* (`x64`, `amd64`, `x86_64`) to `x86_64`. Other architectures are returned
|
|
@@ -144,7 +142,7 @@ function normalizeArch(arch) {
|
|
|
144
142
|
if (arch == null) {
|
|
145
143
|
return arch;
|
|
146
144
|
}
|
|
147
|
-
return X86_64_ARCH_ALIASES.has(arch.toLowerCase()) ?
|
|
145
|
+
return X86_64_ARCH_ALIASES.has(arch.toLowerCase()) ? "x86_64" : arch;
|
|
148
146
|
}
|
|
149
147
|
/**
|
|
150
148
|
* Percent-encodes the `@` and `/` characters in an npm package name so the
|
|
@@ -153,7 +151,7 @@ function normalizeArch(arch) {
|
|
|
153
151
|
* `@dummy/sdk` becomes `%40dummy%2Fsdk`).
|
|
154
152
|
*/
|
|
155
153
|
function encodeProductName(sdkName) {
|
|
156
|
-
return sdkName.replace(/@/g,
|
|
154
|
+
return sdkName.replace(/@/g, "%40").replace(/\//g, "%2F");
|
|
157
155
|
}
|
|
158
156
|
/**
|
|
159
157
|
* Builds a structured User-Agent string of the form
|
|
@@ -165,7 +163,7 @@ function getUserAgent(sdkName, sdkVersion) {
|
|
|
165
163
|
let userAgent = `${encodeProductName(sdkName)}/${sdkVersion}`;
|
|
166
164
|
const platform = [exports.RUNTIME.os, normalizeArch(exports.RUNTIME.arch)].filter((part) => part != null && part.length > 0);
|
|
167
165
|
if (platform.length > 0) {
|
|
168
|
-
userAgent += ` (${platform.join(
|
|
166
|
+
userAgent += ` (${platform.join("; ")})`;
|
|
169
167
|
}
|
|
170
168
|
const runtimeName = RUNTIME_DISPLAY_NAMES[exports.RUNTIME.type];
|
|
171
169
|
if (runtimeName != null) {
|
|
@@ -36,7 +36,7 @@ class QueryStringBuilder {
|
|
|
36
36
|
if (value === undefined || value === null) {
|
|
37
37
|
return this;
|
|
38
38
|
}
|
|
39
|
-
const serialized = (0, qs_js_1.toQueryString)({ [key]: value }, { arrayFormat: (options === null || options === void 0 ? void 0 : options.style) ===
|
|
39
|
+
const serialized = (0, qs_js_1.toQueryString)({ [key]: value }, { arrayFormat: (options === null || options === void 0 ? void 0 : options.style) === "comma" ? "comma" : "repeat" });
|
|
40
40
|
if (serialized.length > 0) {
|
|
41
41
|
this.parts.set(key, serialized);
|
|
42
42
|
}
|
|
@@ -65,7 +65,7 @@ class QueryStringBuilder {
|
|
|
65
65
|
if (value === undefined || value === null) {
|
|
66
66
|
continue;
|
|
67
67
|
}
|
|
68
|
-
const serialized = (0, qs_js_1.toQueryString)({ [key]: value }, { arrayFormat:
|
|
68
|
+
const serialized = (0, qs_js_1.toQueryString)({ [key]: value }, { arrayFormat: "repeat" });
|
|
69
69
|
if (serialized.length > 0) {
|
|
70
70
|
this.parts.set(key, serialized);
|
|
71
71
|
}
|
|
@@ -78,6 +78,6 @@ class QueryStringBuilder {
|
|
|
78
78
|
* Returns an empty string when no parameters were added.
|
|
79
79
|
*/
|
|
80
80
|
build() {
|
|
81
|
-
return [...this.parts.values()].join(
|
|
81
|
+
return [...this.parts.values()].join("&");
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.encodePathParam = encodePathParam;
|
|
4
4
|
function encodePathParam(param, InvalidPathParameterError) {
|
|
5
5
|
if (param === null) {
|
|
6
|
-
return
|
|
6
|
+
return "null";
|
|
7
7
|
}
|
|
8
8
|
const typeofParam = typeof param;
|
|
9
9
|
switch (typeofParam) {
|
|
10
|
-
case
|
|
11
|
-
return
|
|
12
|
-
case
|
|
13
|
-
case
|
|
14
|
-
case
|
|
10
|
+
case "undefined":
|
|
11
|
+
return "undefined";
|
|
12
|
+
case "string":
|
|
13
|
+
case "number":
|
|
14
|
+
case "boolean":
|
|
15
15
|
break;
|
|
16
16
|
default:
|
|
17
17
|
param = String(param);
|
|
@@ -19,11 +19,9 @@ function encodePathParam(param, InvalidPathParameterError) {
|
|
|
19
19
|
}
|
|
20
20
|
const encoded = encodeURIComponent(param);
|
|
21
21
|
// "." and ".." are dot segments: URL resolution would remove them and send the request to a different path.
|
|
22
|
-
if (encoded ===
|
|
22
|
+
if (encoded === "." || encoded === "..") {
|
|
23
23
|
const message = `Invalid path parameter "${encoded}": "." and ".." are not allowed because they change the request path.`;
|
|
24
|
-
throw InvalidPathParameterError != null
|
|
25
|
-
? new InvalidPathParameterError({ message })
|
|
26
|
-
: new Error(message);
|
|
24
|
+
throw InvalidPathParameterError != null ? new InvalidPathParameterError({ message }) : new Error(message);
|
|
27
25
|
}
|
|
28
26
|
return encoded;
|
|
29
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { encodePathParam } from
|
|
2
|
-
export { join } from
|
|
3
|
-
export { queryBuilder } from
|
|
4
|
-
export { toQueryString } from
|
|
1
|
+
export { encodePathParam } from "./encodePathParam.js";
|
|
2
|
+
export { join } from "./join.js";
|
|
3
|
+
export { queryBuilder } from "./QueryStringBuilder.js";
|
|
4
|
+
export { toQueryString } from "./qs.js";
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.join = join;
|
|
4
4
|
function join(base, ...segments) {
|
|
5
5
|
if (!base) {
|
|
6
|
-
return
|
|
6
|
+
return "";
|
|
7
7
|
}
|
|
8
8
|
if (segments.length === 0) {
|
|
9
9
|
return base;
|
|
10
10
|
}
|
|
11
|
-
if (base.includes(
|
|
11
|
+
if (base.includes("://")) {
|
|
12
12
|
let url;
|
|
13
13
|
try {
|
|
14
14
|
url = new URL(base);
|
|
@@ -17,15 +17,15 @@ function join(base, ...segments) {
|
|
|
17
17
|
return joinPath(base, ...segments);
|
|
18
18
|
}
|
|
19
19
|
const lastSegment = segments[segments.length - 1];
|
|
20
|
-
const shouldPreserveTrailingSlash = lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.endsWith(
|
|
20
|
+
const shouldPreserveTrailingSlash = lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.endsWith("/");
|
|
21
21
|
for (const segment of segments) {
|
|
22
22
|
const cleanSegment = trimSlashes(segment);
|
|
23
23
|
if (cleanSegment) {
|
|
24
24
|
url.pathname = joinPathSegments(url.pathname, cleanSegment);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
if (shouldPreserveTrailingSlash && !url.pathname.endsWith(
|
|
28
|
-
url.pathname +=
|
|
27
|
+
if (shouldPreserveTrailingSlash && !url.pathname.endsWith("/")) {
|
|
28
|
+
url.pathname += "/";
|
|
29
29
|
}
|
|
30
30
|
return url.toString();
|
|
31
31
|
}
|
|
@@ -37,20 +37,20 @@ function joinPath(base, ...segments) {
|
|
|
37
37
|
}
|
|
38
38
|
let result = base;
|
|
39
39
|
const lastSegment = segments[segments.length - 1];
|
|
40
|
-
const shouldPreserveTrailingSlash = lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.endsWith(
|
|
40
|
+
const shouldPreserveTrailingSlash = lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.endsWith("/");
|
|
41
41
|
for (const segment of segments) {
|
|
42
42
|
const cleanSegment = trimSlashes(segment);
|
|
43
43
|
if (cleanSegment) {
|
|
44
44
|
result = joinPathSegments(result, cleanSegment);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
if (shouldPreserveTrailingSlash && !result.endsWith(
|
|
48
|
-
result +=
|
|
47
|
+
if (shouldPreserveTrailingSlash && !result.endsWith("/")) {
|
|
48
|
+
result += "/";
|
|
49
49
|
}
|
|
50
50
|
return result;
|
|
51
51
|
}
|
|
52
52
|
function joinPathSegments(left, right) {
|
|
53
|
-
if (left.endsWith(
|
|
53
|
+
if (left.endsWith("/")) {
|
|
54
54
|
return left + right;
|
|
55
55
|
}
|
|
56
56
|
return `${left}/${right}`;
|
|
@@ -60,9 +60,9 @@ function trimSlashes(str) {
|
|
|
60
60
|
return str;
|
|
61
61
|
let start = 0;
|
|
62
62
|
let end = str.length;
|
|
63
|
-
if (str.startsWith(
|
|
63
|
+
if (str.startsWith("/"))
|
|
64
64
|
start = 1;
|
|
65
|
-
if (str.endsWith(
|
|
65
|
+
if (str.endsWith("/"))
|
|
66
66
|
end = str.length - 1;
|
|
67
67
|
return start === 0 && end === str.length ? str : str.slice(start, end);
|
|
68
68
|
}
|