@vercel/client 18.12.5 → 18.13.0-snapshot-c9dfd83f2293
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/deploy.d.ts +2 -1
- package/dist/deploy.js +41 -9
- package/dist/types.d.ts +2 -5
- package/dist/upload.js +14 -2
- package/dist/utils/gzip-request-body.d.ts +36 -0
- package/dist/utils/gzip-request-body.js +95 -0
- package/package.json +2 -2
package/dist/deploy.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FilesMap } from './utils/hashes';
|
|
2
|
+
import { GzipRequestBodies } from './utils/gzip-request-body';
|
|
2
3
|
import { DeploymentOptions, VercelClientOptions, DeploymentEventType } from './types';
|
|
3
|
-
export declare function deploy(files: FilesMap, clientOptions: VercelClientOptions, deploymentOptions: DeploymentOptions): AsyncIterableIterator<{
|
|
4
|
+
export declare function deploy(files: FilesMap, clientOptions: VercelClientOptions, deploymentOptions: DeploymentOptions, gzipRequestBodies?: GzipRequestBodies): AsyncIterableIterator<{
|
|
4
5
|
type: DeploymentEventType;
|
|
5
6
|
payload: any;
|
|
6
7
|
}>;
|
package/dist/deploy.js
CHANGED
|
@@ -25,7 +25,13 @@ var import_query_string = require("./utils/query-string");
|
|
|
25
25
|
var import_ready_state = require("./utils/ready-state");
|
|
26
26
|
var import_check_deployment_status = require("./check-deployment-status");
|
|
27
27
|
var import_utils = require("./utils");
|
|
28
|
-
|
|
28
|
+
var import_gzip_request_body = require("./utils/gzip-request-body");
|
|
29
|
+
function hasEnvValues({ env, build }) {
|
|
30
|
+
return [env, build?.env].some(
|
|
31
|
+
(values) => values && Object.keys(values).length > 0
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
async function* postDeployment(files, clientOptions, deploymentOptions, gzipRequestBodies) {
|
|
29
35
|
const debug = (0, import_utils.createDebug)(clientOptions.debug);
|
|
30
36
|
const inlineFiles = (0, import_utils.shouldInlineStaticFiles)(files) || clientOptions.firstDeployment === true && !clientOptions.prebuilt && !clientOptions.archive && (0, import_utils.shouldInlineSmallProject)(files);
|
|
31
37
|
const apiDeployments = (0, import_utils.getApiDeploymentsUrl)();
|
|
@@ -39,7 +45,7 @@ async function* postDeployment(files, clientOptions, deploymentOptions) {
|
|
|
39
45
|
deploymentOptions.customEnvironmentSlugOrId = deploymentOptions.target;
|
|
40
46
|
deploymentOptions.target = void 0;
|
|
41
47
|
}
|
|
42
|
-
const
|
|
48
|
+
const requestDeployment = async (requestBody) => {
|
|
43
49
|
const response = await (0, import_utils.fetchApi)(
|
|
44
50
|
`${apiDeployments}${(0, import_query_string.generateQueryString)(clientOptions)}`,
|
|
45
51
|
clientOptions.token,
|
|
@@ -47,12 +53,10 @@ async function* postDeployment(files, clientOptions, deploymentOptions) {
|
|
|
47
53
|
method: "POST",
|
|
48
54
|
headers: {
|
|
49
55
|
Accept: "application/json",
|
|
50
|
-
"Content-Type": "application/json"
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
...requestBody.headers
|
|
51
58
|
},
|
|
52
|
-
body:
|
|
53
|
-
...deploymentOptions,
|
|
54
|
-
files: preparedFiles
|
|
55
|
-
}),
|
|
59
|
+
body: requestBody.body,
|
|
56
60
|
apiUrl: clientOptions.apiUrl,
|
|
57
61
|
userAgent: clientOptions.userAgent,
|
|
58
62
|
dispatcher: clientOptions.dispatcher,
|
|
@@ -63,6 +67,33 @@ async function* postDeployment(files, clientOptions, deploymentOptions) {
|
|
|
63
67
|
try {
|
|
64
68
|
deployment = await response.json();
|
|
65
69
|
} catch (_error) {
|
|
70
|
+
}
|
|
71
|
+
return { response, deployment };
|
|
72
|
+
};
|
|
73
|
+
const sendDeployment = async (preparedFiles) => {
|
|
74
|
+
const json = JSON.stringify({
|
|
75
|
+
...deploymentOptions,
|
|
76
|
+
files: preparedFiles
|
|
77
|
+
});
|
|
78
|
+
const requestBody = await gzipRequestBodies.encode(
|
|
79
|
+
json,
|
|
80
|
+
!hasEnvValues(deploymentOptions)
|
|
81
|
+
);
|
|
82
|
+
if (requestBody.gzip) {
|
|
83
|
+
debug(
|
|
84
|
+
`Sending a gzip request body (${requestBody.bytes} of ${requestBody.decodedBytes} bytes)`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
let { response, deployment } = await requestDeployment(requestBody);
|
|
88
|
+
if (gzipRequestBodies.settle(requestBody, response, deployment?.error?.code)) {
|
|
89
|
+
debug(
|
|
90
|
+
`The API refused the gzip request body with status ${response.status}. Sending it uncompressed`
|
|
91
|
+
);
|
|
92
|
+
({ response, deployment } = await requestDeployment(
|
|
93
|
+
await gzipRequestBodies.encode(json, false)
|
|
94
|
+
));
|
|
95
|
+
}
|
|
96
|
+
if (deployment === void 0) {
|
|
66
97
|
throw new Error("Invalid JSON response");
|
|
67
98
|
}
|
|
68
99
|
if (clientOptions.debug) {
|
|
@@ -128,7 +159,7 @@ function getDefaultName(files, clientOptions) {
|
|
|
128
159
|
return filePath.split("/").pop() || filePath;
|
|
129
160
|
}
|
|
130
161
|
}
|
|
131
|
-
async function* deploy(files, clientOptions, deploymentOptions) {
|
|
162
|
+
async function* deploy(files, clientOptions, deploymentOptions, gzipRequestBodies = new import_gzip_request_body.GzipRequestBodies()) {
|
|
132
163
|
const debug = (0, import_utils.createDebug)(clientOptions.debug);
|
|
133
164
|
if (!deploymentOptions.name && files.size > 0) {
|
|
134
165
|
deploymentOptions.version = 2;
|
|
@@ -152,7 +183,8 @@ async function* deploy(files, clientOptions, deploymentOptions) {
|
|
|
152
183
|
for await (const event of postDeployment(
|
|
153
184
|
files,
|
|
154
185
|
clientOptions,
|
|
155
|
-
deploymentOptions
|
|
186
|
+
deploymentOptions,
|
|
187
|
+
gzipRequestBodies
|
|
156
188
|
)) {
|
|
157
189
|
if (event.type === "created") {
|
|
158
190
|
debug("Deployment created");
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Builder, BuilderFunctions, Images, ProjectSettings, Cron, VercelJsonSchedules, ExperimentalServices, ExperimentalServiceGroups, ExperimentalServicesV2, Services, Daemons } from '@vercel/build-utils';
|
|
1
|
+
import type { Builder, BuilderFunctions, Images, ProjectSettings, Cron, VercelJsonSchedules, ExperimentalServices, ExperimentalServiceGroups, ExperimentalServicesV2, Services, Daemons, ProxyConfig } from '@vercel/build-utils';
|
|
2
2
|
import type { Header, Route, Redirect, Rewrite } from '@vercel/routing-utils';
|
|
3
3
|
export type { DeploymentEventType } from './utils';
|
|
4
4
|
/**
|
|
@@ -12,10 +12,7 @@ export interface FetchDispatcher {
|
|
|
12
12
|
export interface Dictionary<T> {
|
|
13
13
|
[key: string]: T;
|
|
14
14
|
}
|
|
15
|
-
export
|
|
16
|
-
entrypoint: string;
|
|
17
|
-
matcher?: string | string[];
|
|
18
|
-
}
|
|
15
|
+
export type { ProxyConfig };
|
|
19
16
|
export declare const VALID_ARCHIVE_FORMATS: readonly ["tgz"];
|
|
20
17
|
export type ArchiveFormat = (typeof VALID_ARCHIVE_FORMATS)[number];
|
|
21
18
|
export interface DeploymentAliasError {
|
package/dist/upload.js
CHANGED
|
@@ -42,6 +42,7 @@ var import_utils = require("./utils");
|
|
|
42
42
|
var import_errors = require("./errors");
|
|
43
43
|
var import_network_error = require("./utils/network-error");
|
|
44
44
|
var import_deploy = require("./deploy");
|
|
45
|
+
var import_gzip_request_body = require("./utils/gzip-request-body");
|
|
45
46
|
async function* upload(files, clientOptions, deploymentOptions) {
|
|
46
47
|
const debug = (0, import_utils.createDebug)(clientOptions.debug);
|
|
47
48
|
if (!files && !clientOptions.token && !clientOptions.teamId) {
|
|
@@ -49,8 +50,14 @@ async function* upload(files, clientOptions, deploymentOptions) {
|
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
52
|
let shas = [];
|
|
53
|
+
const gzipRequestBodies = new import_gzip_request_body.GzipRequestBodies();
|
|
52
54
|
debug("Determining necessary files for upload...");
|
|
53
|
-
for await (const event of (0, import_deploy.deploy)(
|
|
55
|
+
for await (const event of (0, import_deploy.deploy)(
|
|
56
|
+
files,
|
|
57
|
+
clientOptions,
|
|
58
|
+
deploymentOptions,
|
|
59
|
+
gzipRequestBodies
|
|
60
|
+
)) {
|
|
54
61
|
if (event.type === "error") {
|
|
55
62
|
if (event.payload.code === "missing_files") {
|
|
56
63
|
shas = event.payload.missing;
|
|
@@ -98,7 +105,12 @@ async function* upload(files, clientOptions, deploymentOptions) {
|
|
|
98
105
|
yield { type: "all-files-uploaded", payload: files };
|
|
99
106
|
try {
|
|
100
107
|
debug("Starting deployment creation");
|
|
101
|
-
for await (const event of (0, import_deploy.deploy)(
|
|
108
|
+
for await (const event of (0, import_deploy.deploy)(
|
|
109
|
+
files,
|
|
110
|
+
clientOptions,
|
|
111
|
+
deploymentOptions,
|
|
112
|
+
gzipRequestBodies
|
|
113
|
+
)) {
|
|
102
114
|
if (event.type === "alias-assigned" || event.type === "checks-v2-failed") {
|
|
103
115
|
debug("Deployment is ready");
|
|
104
116
|
return yield event;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface RequestBody {
|
|
2
|
+
body: string | Buffer;
|
|
3
|
+
headers: Record<string, string>;
|
|
4
|
+
/** The byte length of `body`. */
|
|
5
|
+
bytes: number;
|
|
6
|
+
/** The byte length of the JSON that `body` carries. */
|
|
7
|
+
decodedBytes: number;
|
|
8
|
+
gzip: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface ApiResponse {
|
|
11
|
+
status: number;
|
|
12
|
+
headers: {
|
|
13
|
+
get(name: string): string | null | undefined;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Decides whether the creation requests of one deployment send a gzip body.
|
|
18
|
+
*
|
|
19
|
+
* The API sends `Accept-Encoding: gzip` on the responses of the creation
|
|
20
|
+
* endpoint when it accepts a gzip body there. A request is compressed only
|
|
21
|
+
* after such a response, so the first request of a deployment never is.
|
|
22
|
+
*/
|
|
23
|
+
export declare class GzipRequestBodies {
|
|
24
|
+
private accepted;
|
|
25
|
+
private refused;
|
|
26
|
+
/** `allowed: false` keeps the body of this request uncompressed. */
|
|
27
|
+
encode(json: string, allowed?: boolean): Promise<RequestBody>;
|
|
28
|
+
/**
|
|
29
|
+
* Takes the response to a creation request. Returns `true` when the answer
|
|
30
|
+
* to a gzip body can come from the encoding. The API created nothing then,
|
|
31
|
+
* so the caller sends the request again, and no later request is
|
|
32
|
+
* compressed.
|
|
33
|
+
*/
|
|
34
|
+
settle(sent: RequestBody, response: ApiResponse, errorCode?: unknown): boolean;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
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 gzip_request_body_exports = {};
|
|
20
|
+
__export(gzip_request_body_exports, {
|
|
21
|
+
GzipRequestBodies: () => GzipRequestBodies
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(gzip_request_body_exports);
|
|
24
|
+
var import_node_util = require("node:util");
|
|
25
|
+
var import_node_zlib = require("node:zlib");
|
|
26
|
+
const gzipAsync = (0, import_node_util.promisify)(import_node_zlib.gzip);
|
|
27
|
+
const MIN_GZIP_BYTES = 16 * 1024;
|
|
28
|
+
class GzipRequestBodies {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.accepted = false;
|
|
31
|
+
this.refused = false;
|
|
32
|
+
}
|
|
33
|
+
/** `allowed: false` keeps the body of this request uncompressed. */
|
|
34
|
+
async encode(json, allowed = true) {
|
|
35
|
+
const decodedBytes = Buffer.byteLength(json);
|
|
36
|
+
const plain = {
|
|
37
|
+
body: json,
|
|
38
|
+
headers: {},
|
|
39
|
+
bytes: decodedBytes,
|
|
40
|
+
decodedBytes,
|
|
41
|
+
gzip: false
|
|
42
|
+
};
|
|
43
|
+
if (!allowed || !this.accepted || this.refused || decodedBytes < MIN_GZIP_BYTES) {
|
|
44
|
+
return plain;
|
|
45
|
+
}
|
|
46
|
+
const body = await gzipAsync(json).catch(() => void 0);
|
|
47
|
+
if (!body || body.byteLength >= decodedBytes) {
|
|
48
|
+
return plain;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
body,
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Encoding": "gzip",
|
|
54
|
+
"x-vercel-decoded-length": String(decodedBytes)
|
|
55
|
+
},
|
|
56
|
+
bytes: body.byteLength,
|
|
57
|
+
decodedBytes,
|
|
58
|
+
gzip: true
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Takes the response to a creation request. Returns `true` when the answer
|
|
63
|
+
* to a gzip body can come from the encoding. The API created nothing then,
|
|
64
|
+
* so the caller sends the request again, and no later request is
|
|
65
|
+
* compressed.
|
|
66
|
+
*/
|
|
67
|
+
settle(sent, response, errorCode) {
|
|
68
|
+
if (sent.gzip && refusedGzip(response.status, errorCode)) {
|
|
69
|
+
this.refused = true;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
this.accepted = acceptsGzip(response);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function refusedGzip(status, errorCode) {
|
|
77
|
+
if (status === 415) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return status === 400 && (errorCode === void 0 || errorCode === "invalid_request_encoding" || errorCode === "bad_request");
|
|
81
|
+
}
|
|
82
|
+
function acceptsGzip(response) {
|
|
83
|
+
const value = response.headers.get("accept-encoding");
|
|
84
|
+
if (!value) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return value.split(",").some((item) => {
|
|
88
|
+
const [coding, ...params] = item.split(";").map((part) => part.trim());
|
|
89
|
+
return coding.toLowerCase() === "gzip" && !params.some((param) => /^q=0(\.0*)?$/i.test(param));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
GzipRequestBodies
|
|
95
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/client",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.13.0-snapshot-c9dfd83f2293",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
6
6
|
"homepage": "https://vercel.com",
|
|
@@ -37,8 +37,8 @@
|
|
|
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.6.0",
|
|
41
40
|
"@vercel/error-utils": "2.2.1",
|
|
41
|
+
"@vercel/build-utils": "15.7.0-snapshot-c9dfd83f2293",
|
|
42
42
|
"@vercel/routing-utils": "6.6.1"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|