@vercel/client 18.10.0 → 18.11.0-snapshot-dd15927e8ded
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/check-deployment-status.js +1 -0
- package/dist/continue.d.ts +6 -1
- package/dist/continue.js +6 -1
- package/dist/deploy.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -1
- package/dist/types.d.ts +18 -0
- package/dist/upload.d.ts +2 -1
- package/dist/upload.js +7 -0
- package/dist/utils/dpop.d.ts +33 -0
- package/dist/utils/dpop.js +77 -0
- package/dist/utils/index.d.ts +11 -2
- package/dist/utils/index.js +54 -23
- package/package.json +4 -4
package/dist/continue.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ArchiveFormat, DeploymentEventType, FetchDispatcher } from './types';
|
|
1
|
+
import type { ArchiveFormat, DeploymentEventType, FetchDispatcher, GetAuthHeaders } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Continues a manual deployment by uploading build outputs and calling the
|
|
4
4
|
* continue endpoint. Waits for READY state unless the caller stops consuming
|
|
@@ -12,6 +12,11 @@ export declare function continueDeployment(options: {
|
|
|
12
12
|
path: string;
|
|
13
13
|
teamId?: string;
|
|
14
14
|
token: string;
|
|
15
|
+
/**
|
|
16
|
+
* Builds the auth headers for each API request, retries included. When
|
|
17
|
+
* unset, requests send `authorization: Bearer <token>`.
|
|
18
|
+
*/
|
|
19
|
+
getAuthHeaders?: GetAuthHeaders;
|
|
15
20
|
userAgent?: string;
|
|
16
21
|
vercelOutputDir?: string;
|
|
17
22
|
archive?: ArchiveFormat;
|
package/dist/continue.js
CHANGED
|
@@ -90,6 +90,7 @@ async function* continueDeployment(options) {
|
|
|
90
90
|
outputDir,
|
|
91
91
|
path: options.path,
|
|
92
92
|
token: options.token,
|
|
93
|
+
getAuthHeaders: options.getAuthHeaders,
|
|
93
94
|
teamId: options.teamId,
|
|
94
95
|
apiUrl: options.apiUrl,
|
|
95
96
|
userAgent: options.userAgent,
|
|
@@ -111,6 +112,7 @@ async function* continueDeployment(options) {
|
|
|
111
112
|
debug: options.debug,
|
|
112
113
|
teamId: options.teamId,
|
|
113
114
|
token: options.token,
|
|
115
|
+
getAuthHeaders: options.getAuthHeaders,
|
|
114
116
|
userAgent: options.userAgent,
|
|
115
117
|
shas: result.missing,
|
|
116
118
|
files,
|
|
@@ -128,6 +130,7 @@ async function* continueDeployment(options) {
|
|
|
128
130
|
outputDir,
|
|
129
131
|
path: options.path,
|
|
130
132
|
token: options.token,
|
|
133
|
+
getAuthHeaders: options.getAuthHeaders,
|
|
131
134
|
teamId: options.teamId,
|
|
132
135
|
apiUrl: options.apiUrl,
|
|
133
136
|
userAgent: options.userAgent,
|
|
@@ -172,6 +175,7 @@ async function* continueDeployment(options) {
|
|
|
172
175
|
path: options.path,
|
|
173
176
|
teamId: options.teamId,
|
|
174
177
|
token: options.token,
|
|
178
|
+
getAuthHeaders: options.getAuthHeaders,
|
|
175
179
|
userAgent: options.userAgent
|
|
176
180
|
});
|
|
177
181
|
}
|
|
@@ -211,7 +215,8 @@ async function postContinueOnce(options) {
|
|
|
211
215
|
}),
|
|
212
216
|
apiUrl: options.apiUrl,
|
|
213
217
|
userAgent: options.userAgent,
|
|
214
|
-
dispatcher: options.dispatcher
|
|
218
|
+
dispatcher: options.dispatcher,
|
|
219
|
+
getAuthHeaders: options.getAuthHeaders
|
|
215
220
|
},
|
|
216
221
|
options.debug
|
|
217
222
|
);
|
package/dist/deploy.js
CHANGED
|
@@ -56,7 +56,8 @@ async function* postDeployment(files, clientOptions, deploymentOptions) {
|
|
|
56
56
|
}),
|
|
57
57
|
apiUrl: clientOptions.apiUrl,
|
|
58
58
|
userAgent: clientOptions.userAgent,
|
|
59
|
-
dispatcher: clientOptions.dispatcher
|
|
59
|
+
dispatcher: clientOptions.dispatcher,
|
|
60
|
+
getAuthHeaders: clientOptions.getAuthHeaders
|
|
60
61
|
}
|
|
61
62
|
);
|
|
62
63
|
let deployment = void 0;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { continueDeployment } from './continue';
|
|
|
2
2
|
export { checkDeploymentStatus } from './check-deployment-status';
|
|
3
3
|
export { inspectDeploymentFiles } from './inspect-deployment-files';
|
|
4
4
|
export { getVercelIgnore, buildFileTree } from './utils/index';
|
|
5
|
+
export { DPOP_CLOCK_SKEW_TOLERANCE_SECONDS, getDpopServerTime, shouldResendDpopRequest, } from './utils/dpop';
|
|
5
6
|
export declare const createDeployment: (clientOptions: import("./types").VercelClientOptions, deploymentOptions?: import("./types").DeploymentOptions | Promise<import("./types").DeploymentOptions>) => AsyncIterableIterator<{
|
|
6
7
|
type: import("./types").DeploymentEventType;
|
|
7
8
|
payload: any;
|
package/dist/index.js
CHANGED
|
@@ -29,12 +29,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
30
|
var src_exports = {};
|
|
31
31
|
__export(src_exports, {
|
|
32
|
+
DPOP_CLOCK_SKEW_TOLERANCE_SECONDS: () => import_dpop.DPOP_CLOCK_SKEW_TOLERANCE_SECONDS,
|
|
32
33
|
buildFileTree: () => import_utils.buildFileTree,
|
|
33
34
|
checkDeploymentStatus: () => import_check_deployment_status.checkDeploymentStatus,
|
|
34
35
|
continueDeployment: () => import_continue.continueDeployment,
|
|
35
36
|
createDeployment: () => createDeployment,
|
|
37
|
+
getDpopServerTime: () => import_dpop.getDpopServerTime,
|
|
36
38
|
getVercelIgnore: () => import_utils.getVercelIgnore,
|
|
37
|
-
inspectDeploymentFiles: () => import_inspect_deployment_files.inspectDeploymentFiles
|
|
39
|
+
inspectDeploymentFiles: () => import_inspect_deployment_files.inspectDeploymentFiles,
|
|
40
|
+
shouldResendDpopRequest: () => import_dpop.shouldResendDpopRequest
|
|
38
41
|
});
|
|
39
42
|
module.exports = __toCommonJS(src_exports);
|
|
40
43
|
var import_create_deployment = __toESM(require("./create-deployment"));
|
|
@@ -42,17 +45,21 @@ var import_continue = require("./continue");
|
|
|
42
45
|
var import_check_deployment_status = require("./check-deployment-status");
|
|
43
46
|
var import_inspect_deployment_files = require("./inspect-deployment-files");
|
|
44
47
|
var import_utils = require("./utils/index");
|
|
48
|
+
var import_dpop = require("./utils/dpop");
|
|
45
49
|
__reExport(src_exports, require("./errors"), module.exports);
|
|
46
50
|
__reExport(src_exports, require("./types"), module.exports);
|
|
47
51
|
const createDeployment = (0, import_create_deployment.default)();
|
|
48
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49
53
|
0 && (module.exports = {
|
|
54
|
+
DPOP_CLOCK_SKEW_TOLERANCE_SECONDS,
|
|
50
55
|
buildFileTree,
|
|
51
56
|
checkDeploymentStatus,
|
|
52
57
|
continueDeployment,
|
|
53
58
|
createDeployment,
|
|
59
|
+
getDpopServerTime,
|
|
54
60
|
getVercelIgnore,
|
|
55
61
|
inspectDeploymentFiles,
|
|
62
|
+
shouldResendDpopRequest,
|
|
56
63
|
...require("./errors"),
|
|
57
64
|
...require("./types")
|
|
58
65
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -34,8 +34,26 @@ export interface DeploymentAliasAssignedEvent {
|
|
|
34
34
|
aliasError: DeploymentAliasError | null;
|
|
35
35
|
aliasWarning: DeploymentAliasWarning | null;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Builds the auth headers for one API request. Return every header the
|
|
39
|
+
* request needs to authenticate, such as `authorization` and a `dpop` proof
|
|
40
|
+
* (RFC 9449), which is signed for one method and URL. `onResponse` is given
|
|
41
|
+
* each response's headers, so a DPoP proof can carry the server's latest
|
|
42
|
+
* `DPoP-Nonce`.
|
|
43
|
+
*/
|
|
44
|
+
export interface GetAuthHeaders {
|
|
45
|
+
(method: string, url: string): Record<string, string> | Promise<Record<string, string>>;
|
|
46
|
+
onResponse?: (url: string, headers: {
|
|
47
|
+
get(name: string): string | null;
|
|
48
|
+
}) => void;
|
|
49
|
+
}
|
|
37
50
|
export interface VercelClientOptions {
|
|
38
51
|
token: string;
|
|
52
|
+
/**
|
|
53
|
+
* Builds the auth headers for each API request, retries included. When
|
|
54
|
+
* unset, requests send `authorization: Bearer <token>`.
|
|
55
|
+
*/
|
|
56
|
+
getAuthHeaders?: GetAuthHeaders;
|
|
39
57
|
path: string | string[];
|
|
40
58
|
debug?: boolean;
|
|
41
59
|
teamId?: string;
|
package/dist/upload.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
import { DeploymentFile, FilesMap } from './utils/hashes';
|
|
3
|
-
import type { FetchDispatcher, VercelClientOptions, DeploymentOptions, DeploymentEventType } from './types';
|
|
3
|
+
import type { FetchDispatcher, GetAuthHeaders, VercelClientOptions, DeploymentOptions, DeploymentEventType } from './types';
|
|
4
4
|
export declare function upload(files: FilesMap, clientOptions: VercelClientOptions, deploymentOptions: DeploymentOptions): AsyncIterableIterator<any>;
|
|
5
5
|
/**
|
|
6
6
|
* Uploads files to the /v2/files endpoint with retry and fault tolerance.
|
|
@@ -13,6 +13,7 @@ export declare function uploadFiles(options: {
|
|
|
13
13
|
shas: string[];
|
|
14
14
|
teamId?: string;
|
|
15
15
|
token: string;
|
|
16
|
+
getAuthHeaders?: GetAuthHeaders;
|
|
16
17
|
uploads: UploadProgress[];
|
|
17
18
|
userAgent?: string;
|
|
18
19
|
}): AsyncIterableIterator<{
|
package/dist/upload.js
CHANGED
|
@@ -81,6 +81,7 @@ async function* upload(files, clientOptions, deploymentOptions) {
|
|
|
81
81
|
debug: clientOptions.debug,
|
|
82
82
|
teamId: clientOptions.teamId,
|
|
83
83
|
token: clientOptions.token,
|
|
84
|
+
getAuthHeaders: clientOptions.getAuthHeaders,
|
|
84
85
|
userAgent: clientOptions.userAgent,
|
|
85
86
|
files,
|
|
86
87
|
shas,
|
|
@@ -184,6 +185,7 @@ async function* uploadFiles(options) {
|
|
|
184
185
|
teamId: options.teamId,
|
|
185
186
|
apiUrl: options.apiUrl,
|
|
186
187
|
userAgent: options.userAgent,
|
|
188
|
+
getAuthHeaders: options.getAuthHeaders,
|
|
187
189
|
signal: abortController.signal
|
|
188
190
|
},
|
|
189
191
|
options.debug
|
|
@@ -196,6 +198,11 @@ async function* uploadFiles(options) {
|
|
|
196
198
|
type: "file-uploaded",
|
|
197
199
|
payload: { sha, file }
|
|
198
200
|
};
|
|
201
|
+
} else if ((0, import_utils.needsNewDpopProof)(res)) {
|
|
202
|
+
retryableServerError = true;
|
|
203
|
+
throw new Error(
|
|
204
|
+
"The server rejected the DPoP proof for its nonce or time."
|
|
205
|
+
);
|
|
199
206
|
} else if (res.status > 200 && res.status < 500) {
|
|
200
207
|
debug(
|
|
201
208
|
`An internal error occurred in upload request. Not retrying...`
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How far a proof's `iat` can be from the server's time before the proof is
|
|
3
|
+
* taken to have been rejected for a wrong clock, in seconds.
|
|
4
|
+
* @see https://www.rfc-editor.org/rfc/rfc9449.html#section-11.1
|
|
5
|
+
*/
|
|
6
|
+
export declare const DPOP_CLOCK_SKEW_TOLERANCE_SECONDS = 30;
|
|
7
|
+
interface ResponseLike {
|
|
8
|
+
status: number;
|
|
9
|
+
headers: {
|
|
10
|
+
get(name: string): string | null;
|
|
11
|
+
};
|
|
12
|
+
clone(): {
|
|
13
|
+
json(): Promise<unknown>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** The server's time from a response's `Date` header, in seconds. */
|
|
17
|
+
export declare function getDpopServerTime(headers: {
|
|
18
|
+
get(name: string): string | null;
|
|
19
|
+
}): number | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Whether a server rejected the proof for something the next proof fixes, so
|
|
22
|
+
* the request should be sent once more with a new one: a missing or old nonce
|
|
23
|
+
* when the server sent a new one, or an `iat` in `proof` (the one the request
|
|
24
|
+
* sent) that the server's `Date` shows was off. Each request is judged by its
|
|
25
|
+
* own proof, so requests sent at the same time all get resent. API responses
|
|
26
|
+
* send the error in `WWW-Authenticate`, the token endpoint in a 400
|
|
27
|
+
* response's body.
|
|
28
|
+
*
|
|
29
|
+
* @see https://www.rfc-editor.org/rfc/rfc9449.html#section-9
|
|
30
|
+
* @see https://www.rfc-editor.org/rfc/rfc9449.html#section-8
|
|
31
|
+
*/
|
|
32
|
+
export declare function shouldResendDpopRequest(response: ResponseLike, proof: string | undefined): Promise<boolean>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var dpop_exports = {};
|
|
20
|
+
__export(dpop_exports, {
|
|
21
|
+
DPOP_CLOCK_SKEW_TOLERANCE_SECONDS: () => DPOP_CLOCK_SKEW_TOLERANCE_SECONDS,
|
|
22
|
+
getDpopServerTime: () => getDpopServerTime,
|
|
23
|
+
shouldResendDpopRequest: () => shouldResendDpopRequest
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(dpop_exports);
|
|
26
|
+
const DPOP_CLOCK_SKEW_TOLERANCE_SECONDS = 30;
|
|
27
|
+
function getDpopServerTime(headers) {
|
|
28
|
+
const date = headers.get("date");
|
|
29
|
+
const serverTime = date ? Date.parse(date) : Number.NaN;
|
|
30
|
+
return Number.isNaN(serverTime) ? void 0 : serverTime / 1e3;
|
|
31
|
+
}
|
|
32
|
+
function iatOf(proof) {
|
|
33
|
+
try {
|
|
34
|
+
const payload = JSON.parse(
|
|
35
|
+
Buffer.from(proof?.split(".")[1] ?? "", "base64url").toString()
|
|
36
|
+
);
|
|
37
|
+
return typeof payload?.iat === "number" ? payload.iat : void 0;
|
|
38
|
+
} catch {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function shouldResendDpopRequest(response, proof) {
|
|
43
|
+
if (!proof) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const error = await dpopErrorOf(response);
|
|
47
|
+
if (error === "use_dpop_nonce") {
|
|
48
|
+
return Boolean(response.headers.get("dpop-nonce"));
|
|
49
|
+
}
|
|
50
|
+
if (error === "invalid_dpop_proof") {
|
|
51
|
+
const iat = iatOf(proof);
|
|
52
|
+
const serverTime = getDpopServerTime(response.headers);
|
|
53
|
+
return iat !== void 0 && serverTime !== void 0 && Math.abs(serverTime - iat) > DPOP_CLOCK_SKEW_TOLERANCE_SECONDS;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
async function dpopErrorOf(response) {
|
|
58
|
+
if (response.status === 401) {
|
|
59
|
+
const challenge = response.headers.get("www-authenticate") ?? "";
|
|
60
|
+
return /\berror="([^"]*)"/i.exec(challenge)?.[1];
|
|
61
|
+
}
|
|
62
|
+
if (response.status !== 400) {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const json = await response.clone().json();
|
|
67
|
+
return typeof json === "object" && json !== null && "error" in json && typeof json.error === "string" ? json.error : void 0;
|
|
68
|
+
} catch {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
DPOP_CLOCK_SKEW_TOLERANCE_SECONDS,
|
|
75
|
+
getDpopServerTime,
|
|
76
|
+
shouldResendDpopRequest
|
|
77
|
+
});
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { FilesMap } from './hashes';
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
3
|
import ignore from 'ignore';
|
|
4
|
-
import { FetchDispatcher, VercelClientOptions, VercelConfig } from '../types';
|
|
4
|
+
import { FetchDispatcher, GetAuthHeaders, VercelClientOptions, VercelConfig } from '../types';
|
|
5
5
|
type Ignore = ReturnType<typeof ignore>;
|
|
6
6
|
export declare const API_FILES = "/v2/files";
|
|
7
7
|
declare const EVENTS_ARRAY: readonly ["hashes-calculated", "file-count", "file-uploaded", "all-files-uploaded", "created", "building", "ready", "alias-assigned", "warning", "error", "notice", "tip", "canceled", "checks-registered", "checks-completed", "checks-running", "checks-conclusion-succeeded", "checks-conclusion-failed", "checks-conclusion-skipped", "checks-conclusion-canceled", "checks-v2-failed"];
|
|
8
8
|
export type DeploymentEventType = (typeof EVENTS_ARRAY)[number];
|
|
9
|
-
export declare const EVENTS: Set<"alias-assigned" | "hashes-calculated" | "file-count" | "file-uploaded" | "all-files-uploaded" | "created" | "building" | "ready" | "warning" | "
|
|
9
|
+
export declare const EVENTS: Set<"alias-assigned" | "error" | "hashes-calculated" | "file-count" | "file-uploaded" | "all-files-uploaded" | "created" | "building" | "ready" | "warning" | "notice" | "tip" | "canceled" | "checks-registered" | "checks-completed" | "checks-running" | "checks-conclusion-succeeded" | "checks-conclusion-failed" | "checks-conclusion-skipped" | "checks-conclusion-canceled" | "checks-v2-failed">;
|
|
10
10
|
export declare function getApiDeploymentsUrl(): string;
|
|
11
11
|
export declare function parseVercelConfig(filePath?: string): Promise<VercelConfig>;
|
|
12
12
|
export declare function buildFileTree(path: string | string[], { isDirectory, prebuilt, vercelOutputDir, rootDirectory, projectName, bulkRedirectsPath, }: Pick<VercelClientOptions, 'isDirectory' | 'prebuilt' | 'vercelOutputDir' | 'rootDirectory' | 'projectName' | 'bulkRedirectsPath'>, debug: Debug): Promise<{
|
|
@@ -29,7 +29,16 @@ interface FetchOpts extends Omit<NativeRequestInit, 'body' | 'headers' | 'dispat
|
|
|
29
29
|
userAgent?: string;
|
|
30
30
|
body?: NonNullable<NativeRequestInit['body']> | Buffer | Readable;
|
|
31
31
|
dispatcher?: FetchDispatcher;
|
|
32
|
+
/** Builds the auth headers instead of `authorization: Bearer <token>`. */
|
|
33
|
+
getAuthHeaders?: GetAuthHeaders;
|
|
32
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether `fetchApi` got this response for a request whose DPoP proof was
|
|
37
|
+
* rejected for something a new proof fixes (its nonce, or a wrong clock), but
|
|
38
|
+
* didn't send it again because its body was a stream. The caller can send it
|
|
39
|
+
* again with a new body, and `fetchApi` signs a new proof for it.
|
|
40
|
+
*/
|
|
41
|
+
export declare function needsNewDpopProof(res: object): boolean;
|
|
33
42
|
export declare const fetchApi: (url: string, token: string, opts?: FetchOpts, debugEnabled?: boolean) => Promise<any>;
|
|
34
43
|
export interface PreparedFile {
|
|
35
44
|
file: string;
|
package/dist/utils/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(utils_exports, {
|
|
|
35
35
|
fetchApi: () => fetchApi,
|
|
36
36
|
getApiDeploymentsUrl: () => getApiDeploymentsUrl,
|
|
37
37
|
getVercelIgnore: () => getVercelIgnore,
|
|
38
|
+
needsNewDpopProof: () => needsNewDpopProof,
|
|
38
39
|
parseVercelConfig: () => parseVercelConfig,
|
|
39
40
|
prepareFiles: () => prepareFiles,
|
|
40
41
|
shouldInlineStaticFiles: () => shouldInlineStaticFiles
|
|
@@ -50,6 +51,7 @@ var import_build_utils = require("@vercel/build-utils");
|
|
|
50
51
|
var import_async_sema = require("async-sema");
|
|
51
52
|
var import_fs_extra = require("fs-extra");
|
|
52
53
|
var import_readdir_recursive = __toESM(require("./readdir-recursive"));
|
|
54
|
+
var import_dpop = require("./dpop");
|
|
53
55
|
const semaphore = new import_async_sema.Sema(10);
|
|
54
56
|
const API_FILES = "/v2/files";
|
|
55
57
|
const EVENTS_ARRAY = [
|
|
@@ -433,48 +435,76 @@ ${clearRelative(ignoreFile)}`);
|
|
|
433
435
|
function clearRelative(str) {
|
|
434
436
|
return str.replace(/(\n|^)\.\//g, "$1");
|
|
435
437
|
}
|
|
438
|
+
const needsNewDpopProofResponses = /* @__PURE__ */ new WeakSet();
|
|
439
|
+
function needsNewDpopProof(res) {
|
|
440
|
+
return needsNewDpopProofResponses.has(res);
|
|
441
|
+
}
|
|
436
442
|
const fetchApi = async (url, token, opts = {}, debugEnabled) => {
|
|
437
|
-
semaphore.acquire();
|
|
438
443
|
const debug = createDebug(debugEnabled);
|
|
439
444
|
let time;
|
|
440
|
-
|
|
441
|
-
|
|
445
|
+
const {
|
|
446
|
+
apiUrl,
|
|
447
|
+
teamId,
|
|
448
|
+
userAgent = `client-v${import_pkg.pkgVersion}`,
|
|
449
|
+
getAuthHeaders,
|
|
450
|
+
headers,
|
|
451
|
+
...init
|
|
452
|
+
} = opts;
|
|
453
|
+
url = `${apiUrl || "https://api.vercel.com"}${url}`;
|
|
442
454
|
const { VERCEL_TEAM_ID } = process.env;
|
|
443
455
|
if (VERCEL_TEAM_ID) {
|
|
444
456
|
url += `${url.includes("?") ? "&" : "?"}teamId=${VERCEL_TEAM_ID}`;
|
|
445
457
|
}
|
|
446
|
-
if (
|
|
458
|
+
if (teamId) {
|
|
447
459
|
const parsedUrl2 = new import_url.URL(url);
|
|
448
|
-
parsedUrl2.searchParams.set("teamId",
|
|
460
|
+
parsedUrl2.searchParams.set("teamId", teamId);
|
|
449
461
|
url = parsedUrl2.toString();
|
|
450
|
-
delete opts.teamId;
|
|
451
462
|
}
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
463
|
+
const buildRequest = async () => {
|
|
464
|
+
const authHeaders = getAuthHeaders ? await getAuthHeaders(init.method || "GET", url) : { authorization: `Bearer ${token}` };
|
|
465
|
+
return {
|
|
466
|
+
proof: getAuthHeaders ? authHeaders.dpop : void 0,
|
|
467
|
+
request: {
|
|
468
|
+
...init,
|
|
469
|
+
headers: {
|
|
470
|
+
...headers,
|
|
471
|
+
...authHeaders,
|
|
472
|
+
accept: "application/json",
|
|
473
|
+
"user-agent": userAgent
|
|
474
|
+
},
|
|
475
|
+
// Node.js streams must be sent with half duplex, since the request
|
|
476
|
+
// body length is not known upfront.
|
|
477
|
+
...init.body instanceof import_stream.Readable && { duplex: "half" }
|
|
478
|
+
}
|
|
479
|
+
};
|
|
459
480
|
};
|
|
460
|
-
|
|
461
|
-
opts.duplex = "half";
|
|
462
|
-
}
|
|
481
|
+
const { request, proof } = await buildRequest();
|
|
463
482
|
const parsedUrl = new import_url.URL(url);
|
|
464
|
-
const
|
|
465
|
-
debug(
|
|
483
|
+
const label = `${init.method || "GET"} ${parsedUrl.origin}${parsedUrl.pathname}`;
|
|
484
|
+
debug(label);
|
|
485
|
+
semaphore.acquire();
|
|
466
486
|
time = Date.now();
|
|
467
487
|
try {
|
|
468
|
-
|
|
488
|
+
let res = await fetch(url, request);
|
|
489
|
+
const resend = await (0, import_dpop.shouldResendDpopRequest)(res, proof);
|
|
490
|
+
getAuthHeaders?.onResponse?.(url, res.headers);
|
|
491
|
+
if (resend && init.body instanceof import_stream.Readable) {
|
|
492
|
+
needsNewDpopProofResponses.add(res);
|
|
493
|
+
} else if (resend) {
|
|
494
|
+
await res.body?.cancel();
|
|
495
|
+
res = await fetch(
|
|
496
|
+
url,
|
|
497
|
+
(await buildRequest()).request
|
|
498
|
+
);
|
|
499
|
+
getAuthHeaders?.onResponse?.(url, res.headers);
|
|
500
|
+
}
|
|
469
501
|
const requestId = res.headers.get("x-vercel-id");
|
|
470
502
|
const id = requestId && /^[a-zA-Z0-9:_.-]{1,200}$/.test(requestId) ? ` requestId=${requestId}` : "";
|
|
471
|
-
debug(
|
|
472
|
-
`DONE in ${Date.now() - time}ms: ${request} status=${res.status}${id}`
|
|
473
|
-
);
|
|
503
|
+
debug(`DONE in ${Date.now() - time}ms: ${label} status=${res.status}${id}`);
|
|
474
504
|
return res;
|
|
475
505
|
} catch (error) {
|
|
476
506
|
debug(
|
|
477
|
-
`FAILED in ${Date.now() - time}ms: ${
|
|
507
|
+
`FAILED in ${Date.now() - time}ms: ${label} ${(0, import_network_error.formatNetworkError)(error)}`
|
|
478
508
|
);
|
|
479
509
|
throw error;
|
|
480
510
|
} finally {
|
|
@@ -558,6 +588,7 @@ function createDebug(debug) {
|
|
|
558
588
|
fetchApi,
|
|
559
589
|
getApiDeploymentsUrl,
|
|
560
590
|
getVercelIgnore,
|
|
591
|
+
needsNewDpopProof,
|
|
561
592
|
parseVercelConfig,
|
|
562
593
|
prepareFiles,
|
|
563
594
|
shouldInlineStaticFiles
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/client",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.11.0-snapshot-dd15927e8ded",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
6
6
|
"homepage": "https://vercel.com",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"querystring": "^0.2.0",
|
|
38
38
|
"sleep-promise": "8.0.1",
|
|
39
39
|
"tar-fs": "1.16.3",
|
|
40
|
-
"@vercel/build-utils": "15.1.
|
|
41
|
-
"@vercel/
|
|
42
|
-
"@vercel/
|
|
40
|
+
"@vercel/build-utils": "15.1.1",
|
|
41
|
+
"@vercel/routing-utils": "6.6.1",
|
|
42
|
+
"@vercel/error-utils": "2.2.1"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "node ../../utils/build.mjs",
|