vercel 41.7.8 → 42.1.0

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.
Files changed (2) hide show
  1. package/dist/index.js +372 -296
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -60305,8 +60305,254 @@ var init_promise = __esm({
60305
60305
  }
60306
60306
  });
60307
60307
 
60308
+ // src/util/oauth.ts
60309
+ async function as() {
60310
+ if (!_as) {
60311
+ const discoveryResponse = await discoveryEndpointRequest(VERCEL_ISSUER);
60312
+ const [discoveryResponseError, as2] = await processDiscoveryEndpointResponse(discoveryResponse);
60313
+ if (discoveryResponseError) {
60314
+ throw discoveryResponseError;
60315
+ }
60316
+ _as = as2;
60317
+ }
60318
+ return _as;
60319
+ }
60320
+ async function discoveryEndpointRequest(issuer) {
60321
+ return await (0, import_node_fetch.default)(new URL(".well-known/openid-configuration", issuer), {
60322
+ headers: { "Content-Type": "application/json", "user-agent": userAgent }
60323
+ });
60324
+ }
60325
+ async function processDiscoveryEndpointResponse(response) {
60326
+ const json = await response.json();
60327
+ if (!response.ok) {
60328
+ return [new Error("Discovery endpoint request failed")];
60329
+ }
60330
+ if (typeof json !== "object" || json === null || !canParseURL(json.issuer) || !canParseURL(json.device_authorization_endpoint) || !canParseURL(json.token_endpoint) || !canParseURL(json.revocation_endpoint) || !canParseURL(json.jwks_uri)) {
60331
+ return [new TypeError("Invalid discovery response")];
60332
+ }
60333
+ const issuer = new URL(json.issuer);
60334
+ if (issuer.href !== VERCEL_ISSUER.href) {
60335
+ return [new Error("Issuer mismatch")];
60336
+ }
60337
+ return [
60338
+ null,
60339
+ {
60340
+ issuer,
60341
+ device_authorization_endpoint: new URL(
60342
+ json.device_authorization_endpoint
60343
+ ),
60344
+ token_endpoint: new URL(json.token_endpoint),
60345
+ revocation_endpoint: new URL(json.revocation_endpoint),
60346
+ jwks_uri: new URL(json.jwks_uri)
60347
+ }
60348
+ ];
60349
+ }
60350
+ async function deviceAuthorizationRequest() {
60351
+ return await (0, import_node_fetch.default)((await as()).device_authorization_endpoint, {
60352
+ method: "POST",
60353
+ headers: {
60354
+ "Content-Type": "application/x-www-form-urlencoded",
60355
+ "user-agent": userAgent
60356
+ },
60357
+ body: new URLSearchParams({
60358
+ client_id: VERCEL_CLI_CLIENT_ID,
60359
+ scope: "openid offline_access"
60360
+ })
60361
+ });
60362
+ }
60363
+ async function processDeviceAuthorizationResponse(response) {
60364
+ const json = await response.json();
60365
+ if (!response.ok) {
60366
+ return [new OAuthError("Device authorization request failed", json)];
60367
+ }
60368
+ if (typeof json !== "object" || json === null)
60369
+ return [new TypeError("Expected response to be an object")];
60370
+ if (!("device_code" in json) || typeof json.device_code !== "string")
60371
+ return [new TypeError("Expected `device_code` to be a string")];
60372
+ if (!("user_code" in json) || typeof json.user_code !== "string")
60373
+ return [new TypeError("Expected `user_code` to be a string")];
60374
+ if (!("verification_uri" in json) || typeof json.verification_uri !== "string" || !canParseURL(json.verification_uri)) {
60375
+ return [new TypeError("Expected `verification_uri` to be a string")];
60376
+ }
60377
+ if (!("verification_uri_complete" in json) || typeof json.verification_uri_complete !== "string" || !canParseURL(json.verification_uri_complete)) {
60378
+ return [
60379
+ new TypeError("Expected `verification_uri_complete` to be a string")
60380
+ ];
60381
+ }
60382
+ if (!("expires_in" in json) || typeof json.expires_in !== "number")
60383
+ return [new TypeError("Expected `expires_in` to be a number")];
60384
+ if (!("interval" in json) || typeof json.interval !== "number")
60385
+ return [new TypeError("Expected `interval` to be a number")];
60386
+ return [
60387
+ null,
60388
+ {
60389
+ device_code: json.device_code,
60390
+ user_code: json.user_code,
60391
+ verification_uri: json.verification_uri,
60392
+ verification_uri_complete: json.verification_uri_complete,
60393
+ expiresAt: Date.now() + json.expires_in * 1e3,
60394
+ interval: json.interval
60395
+ }
60396
+ ];
60397
+ }
60398
+ async function deviceAccessTokenRequest(options) {
60399
+ try {
60400
+ return [
60401
+ null,
60402
+ await (0, import_node_fetch.default)((await as()).token_endpoint, {
60403
+ method: "POST",
60404
+ headers: {
60405
+ "Content-Type": "application/x-www-form-urlencoded",
60406
+ "user-agent": userAgent
60407
+ },
60408
+ body: new URLSearchParams({
60409
+ client_id: VERCEL_CLI_CLIENT_ID,
60410
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code",
60411
+ ...options
60412
+ }),
60413
+ // TODO: Drop `node-fetch` and just use `signal`
60414
+ timeout: 10 * 1e3,
60415
+ // @ts-expect-error: Signal is part of `fetch` spec, should drop `node-fetch`
60416
+ signal: AbortSignal.timeout(10 * 1e3)
60417
+ })
60418
+ ];
60419
+ } catch (error3) {
60420
+ if (error3 instanceof Error)
60421
+ return [error3];
60422
+ return [
60423
+ new Error("An unknown error occurred. See the logs for details.", {
60424
+ cause: error3
60425
+ })
60426
+ ];
60427
+ }
60428
+ }
60429
+ async function processTokenResponse(response) {
60430
+ const json = await response.json();
60431
+ if (!response.ok) {
60432
+ return [new OAuthError("Device access token request failed", json)];
60433
+ }
60434
+ if (typeof json !== "object" || json === null)
60435
+ return [new TypeError("Expected response to be an object")];
60436
+ if (!("access_token" in json) || typeof json.access_token !== "string")
60437
+ return [new TypeError("Expected `access_token` to be a string")];
60438
+ if (!("token_type" in json) || json.token_type !== "Bearer")
60439
+ return [new TypeError('Expected `token_type` to be "Bearer"')];
60440
+ if (!("expires_in" in json) || typeof json.expires_in !== "number")
60441
+ return [new TypeError("Expected `expires_in` to be a number")];
60442
+ if ("refresh_token" in json && (typeof json.refresh_token !== "string" || !json.refresh_token))
60443
+ return [new TypeError("Expected `refresh_token` to be a string")];
60444
+ if ("scope" in json && typeof json.scope !== "string")
60445
+ return [new TypeError("Expected `scope` to be a string")];
60446
+ return [null, json];
60447
+ }
60448
+ async function revocationRequest(options) {
60449
+ return await (0, import_node_fetch.default)((await as()).revocation_endpoint, {
60450
+ method: "POST",
60451
+ headers: {
60452
+ "Content-Type": "application/x-www-form-urlencoded",
60453
+ "user-agent": userAgent
60454
+ },
60455
+ body: new URLSearchParams({ ...options, client_id: VERCEL_CLI_CLIENT_ID })
60456
+ });
60457
+ }
60458
+ async function processRevocationResponse(response) {
60459
+ if (response.ok)
60460
+ return [null, null];
60461
+ const json = await response.json();
60462
+ return [new OAuthError("Revocation request failed", json)];
60463
+ }
60464
+ async function refreshTokenRequest(options) {
60465
+ return await (0, import_node_fetch.default)((await as()).token_endpoint, {
60466
+ method: "POST",
60467
+ headers: {
60468
+ "Content-Type": "application/x-www-form-urlencoded",
60469
+ "user-agent": ua_default
60470
+ },
60471
+ body: new URLSearchParams({
60472
+ client_id: VERCEL_CLI_CLIENT_ID,
60473
+ grant_type: "refresh_token",
60474
+ ...options
60475
+ })
60476
+ });
60477
+ }
60478
+ function processOAuthErrorResponse(json) {
60479
+ if (typeof json !== "object" || json === null)
60480
+ return new TypeError("Expected response to be an object");
60481
+ if (!("error" in json) || typeof json.error !== "string")
60482
+ return new TypeError("Expected `error` to be a string");
60483
+ if ("error_description" in json && typeof json.error_description !== "string")
60484
+ return new TypeError("Expected `error_description` to be a string");
60485
+ if ("error_uri" in json && typeof json.error_uri !== "string")
60486
+ return new TypeError("Expected `error_uri` to be a string");
60487
+ return json;
60488
+ }
60489
+ function isOAuthError(error3) {
60490
+ return error3 instanceof OAuthError;
60491
+ }
60492
+ function canParseURL(url3) {
60493
+ try {
60494
+ return !!new URL(url3);
60495
+ } catch {
60496
+ return false;
60497
+ }
60498
+ }
60499
+ function inspectToken(token) {
60500
+ try {
60501
+ return [null, (0, import_jose.decodeJwt)(token)];
60502
+ } catch (cause) {
60503
+ return [new InspectionError("Could not inspect token.", { cause })];
60504
+ }
60505
+ }
60506
+ var import_node_fetch, import_jose, import_os5, VERCEL_ISSUER, VERCEL_CLI_CLIENT_ID, userAgent, _as, OAuthError, InspectionError;
60507
+ var init_oauth2 = __esm({
60508
+ "src/util/oauth.ts"() {
60509
+ "use strict";
60510
+ import_node_fetch = __toESM3(require_lib7());
60511
+ import_jose = require("jose");
60512
+ init_ua();
60513
+ import_os5 = require("os");
60514
+ VERCEL_ISSUER = new URL("https://vercel.com");
60515
+ VERCEL_CLI_CLIENT_ID = "cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp";
60516
+ userAgent = `${(0, import_os5.hostname)()} @ ${ua_default}`;
60517
+ OAuthError = class extends Error {
60518
+ constructor(message2, response) {
60519
+ var __super = (...args) => {
60520
+ super(...args);
60521
+ };
60522
+ const error3 = processOAuthErrorResponse(response);
60523
+ if (error3 instanceof TypeError) {
60524
+ const message3 = `Unexpected server response: ${JSON.stringify(response)}`;
60525
+ __super(message3);
60526
+ this.cause = new Error(message3, { cause: error3 });
60527
+ this.code = "server_error";
60528
+ return;
60529
+ }
60530
+ let cause = error3.error;
60531
+ if (error3.error_description)
60532
+ cause += `: ${error3.error_description}`;
60533
+ if (error3.error_uri)
60534
+ cause += ` (${error3.error_uri})`;
60535
+ __super(message2, { cause });
60536
+ this.cause = new Error(cause);
60537
+ this.code = error3.error;
60538
+ }
60539
+ };
60540
+ InspectionError = class extends Error {
60541
+ };
60542
+ }
60543
+ });
60544
+
60308
60545
  // src/util/client.ts
60309
- var import_chalk17, import_events, import_url8, import_async_retry, import_node_fetch, import_error_utils6, isSAMLError, isJSONObject, Client;
60546
+ function isOAuthAuth(authConfig) {
60547
+ return authConfig.type === "oauth";
60548
+ }
60549
+ function isValidAccessToken(authConfig) {
60550
+ return "token" in authConfig && (authConfig.expiresAt ?? 0) >= Date.now();
60551
+ }
60552
+ function hasRefreshToken(authConfig) {
60553
+ return "refreshToken" in authConfig;
60554
+ }
60555
+ var import_chalk17, import_events, import_url8, import_async_retry, import_node_fetch2, import_error_utils6, isSAMLError, isJSONObject, Client;
60310
60556
  var init_client = __esm({
60311
60557
  "src/util/client.ts"() {
60312
60558
  "use strict";
@@ -60319,7 +60565,7 @@ var init_client = __esm({
60319
60565
  import_events = require("events");
60320
60566
  import_url8 = require("url");
60321
60567
  import_async_retry = __toESM3(require_dist5());
60322
- import_node_fetch = __toESM3(require_lib7());
60568
+ import_node_fetch2 = __toESM3(require_lib7());
60323
60569
  init_ua();
60324
60570
  init_response_error();
60325
60571
  init_print_indications();
@@ -60330,6 +60576,7 @@ var init_client = __esm({
60330
60576
  import_error_utils6 = __toESM3(require_dist2());
60331
60577
  init_sleep();
60332
60578
  init_output_manager();
60579
+ init_oauth2();
60333
60580
  isSAMLError = (v) => {
60334
60581
  return v && v.saml;
60335
60582
  };
@@ -60398,7 +60645,65 @@ ${error3.stack}`);
60398
60645
  onRetry: this._onRetry
60399
60646
  });
60400
60647
  }
60401
- _fetch(_url, opts = {}) {
60648
+ /**
60649
+ * When the auth config is of type `OAuthAuthConfig`,
60650
+ * this method silently tries to refresh the access_token if it is expired.
60651
+ *
60652
+ * If the refresh_token is also expired, it will not attempt to refresh it.
60653
+ * If there is any error during the refresh process, it will not throw an error.
60654
+ */
60655
+ async ensureAuthorized() {
60656
+ if (!isOAuthAuth(this.authConfig))
60657
+ return;
60658
+ const { authConfig } = this;
60659
+ if (isValidAccessToken(authConfig)) {
60660
+ output_manager_default.debug("Valid access token, skipping token refresh.");
60661
+ return;
60662
+ }
60663
+ if (!hasRefreshToken(authConfig)) {
60664
+ output_manager_default.debug("No refresh token found, emptying auth config.");
60665
+ this.emptyAuthConfig();
60666
+ this.writeToAuthConfigFile();
60667
+ return;
60668
+ }
60669
+ const tokenResponse = await refreshTokenRequest({
60670
+ refresh_token: authConfig.refreshToken
60671
+ });
60672
+ const [tokensError, tokens] = await processTokenResponse(tokenResponse);
60673
+ if (tokensError) {
60674
+ output_manager_default.debug("Error refreshing token, emptying auth config.");
60675
+ this.emptyAuthConfig();
60676
+ this.writeToAuthConfigFile();
60677
+ return;
60678
+ }
60679
+ this.updateAuthConfig({
60680
+ type: "oauth",
60681
+ token: tokens.access_token,
60682
+ expiresAt: Math.floor(Date.now() / 1e3) + tokens.expires_in
60683
+ });
60684
+ if (tokens.refresh_token) {
60685
+ this.updateAuthConfig({ refreshToken: tokens.refresh_token });
60686
+ }
60687
+ this.writeToAuthConfigFile();
60688
+ this.writeToConfigFile();
60689
+ output_manager_default.debug("Tokens refreshed successfully.");
60690
+ }
60691
+ updateConfig(config2) {
60692
+ this.config = { ...this.config, ...config2 };
60693
+ }
60694
+ writeToConfigFile() {
60695
+ writeToConfigFile(this.config);
60696
+ }
60697
+ updateAuthConfig(authConfig) {
60698
+ this.authConfig = { ...this.authConfig, ...authConfig };
60699
+ }
60700
+ emptyAuthConfig() {
60701
+ this.authConfig = {};
60702
+ }
60703
+ writeToAuthConfigFile() {
60704
+ writeToAuthConfigFile(this.authConfig);
60705
+ }
60706
+ async _fetch(_url, opts = {}) {
60402
60707
  const url3 = new import_url8.URL(_url, this.apiUrl);
60403
60708
  if (opts.accountId || opts.useCurrentTeam !== false) {
60404
60709
  if (opts.accountId) {
@@ -60411,8 +60716,9 @@ ${error3.stack}`);
60411
60716
  url3.searchParams.set("teamId", this.config.currentTeam);
60412
60717
  }
60413
60718
  }
60414
- const headers = new import_node_fetch.Headers(opts.headers);
60719
+ const headers = new import_node_fetch2.Headers(opts.headers);
60415
60720
  headers.set("user-agent", ua_default);
60721
+ await this.ensureAuthorized();
60416
60722
  if (this.authConfig.token) {
60417
60723
  headers.set("authorization", `Bearer ${this.authConfig.token}`);
60418
60724
  }
@@ -60432,7 +60738,7 @@ ${error3.stack}`);
60432
60738
  return `#${requestId} \u2192 ${opts.method || "GET"} ${url3.href}`;
60433
60739
  }
60434
60740
  },
60435
- (0, import_node_fetch.default)(url3, { agent: this.agent, ...opts, headers, body })
60741
+ (0, import_node_fetch2.default)(url3, { agent: this.agent, ...opts, headers, body })
60436
60742
  );
60437
60743
  }
60438
60744
  fetch(url3, opts = {}) {
@@ -126659,7 +126965,7 @@ async function addToGitIgnore(path11, ignore = VERCEL_DIR2) {
126659
126965
  try {
126660
126966
  const gitIgnorePath = (0, import_path12.join)(path11, ".gitignore");
126661
126967
  let gitIgnore = await (0, import_fs_extra5.readFile)(gitIgnorePath, "utf8").catch(() => null) ?? "";
126662
- const EOL = gitIgnore.includes("\r\n") ? "\r\n" : import_os5.default.EOL;
126968
+ const EOL = gitIgnore.includes("\r\n") ? "\r\n" : import_os6.default.EOL;
126663
126969
  let contentModified = false;
126664
126970
  if (!gitIgnore.split(EOL).includes(ignore)) {
126665
126971
  gitIgnore += `${gitIgnore.endsWith(EOL) || gitIgnore.length === 0 ? "" : EOL}${ignore}${EOL}`;
@@ -126673,11 +126979,11 @@ async function addToGitIgnore(path11, ignore = VERCEL_DIR2) {
126673
126979
  }
126674
126980
  return isGitIgnoreUpdated;
126675
126981
  }
126676
- var import_os5, import_path12, import_fs_extra5;
126982
+ var import_os6, import_path12, import_fs_extra5;
126677
126983
  var init_add_to_gitignore = __esm({
126678
126984
  "src/util/link/add-to-gitignore.ts"() {
126679
126985
  "use strict";
126680
- import_os5 = __toESM3(require("os"));
126986
+ import_os6 = __toESM3(require("os"));
126681
126987
  import_path12 = require("path");
126682
126988
  import_fs_extra5 = __toESM3(require_lib());
126683
126989
  init_link2();
@@ -127164,14 +127470,14 @@ function findProjectsFromPath(projects, path11) {
127164
127470
  const firstMatch = matches[0];
127165
127471
  return matches.filter((match) => match.directory === firstMatch.directory);
127166
127472
  }
127167
- var import_chalk35, import_pluralize3, import_os6, import_slugify, import_path14, import_build_utils5, import_fs_extra6, home;
127473
+ var import_chalk35, import_pluralize3, import_os7, import_slugify, import_path14, import_build_utils5, import_fs_extra6, home;
127168
127474
  var init_repo = __esm({
127169
127475
  "src/util/link/repo.ts"() {
127170
127476
  "use strict";
127171
127477
  import_chalk35 = __toESM3(require_source());
127172
127478
  init_esm4();
127173
127479
  import_pluralize3 = __toESM3(require_pluralize());
127174
- import_os6 = require("os");
127480
+ import_os7 = require("os");
127175
127481
  import_slugify = __toESM3(require_slugify());
127176
127482
  import_path14 = require("path");
127177
127483
  import_build_utils5 = require("@vercel/build-utils");
@@ -127189,7 +127495,7 @@ var init_repo = __esm({
127189
127495
  init_connect_git_provider();
127190
127496
  init_git_helpers();
127191
127497
  init_output_manager();
127192
- home = (0, import_os6.homedir)();
127498
+ home = (0, import_os7.homedir)();
127193
127499
  }
127194
127500
  });
127195
127501
 
@@ -139605,7 +139911,7 @@ async function pullEnvRecords(client2, projectId, source, { target, gitBranch }
139605
139911
  `Fetching Environment Variables of project ${projectId} and target ${target}`
139606
139912
  );
139607
139913
  const query = new import_url12.URLSearchParams();
139608
- let url3 = `/v2/env/pull/${projectId}`;
139914
+ let url3 = `/v3/env/pull/${projectId}`;
139609
139915
  if (target) {
139610
139916
  url3 += `/${encodeURIComponent(target)}`;
139611
139917
  if (gitBranch) {
@@ -140089,7 +140395,7 @@ async function validatePaths(client2, paths) {
140089
140395
  });
140090
140396
  return { valid: false, exitCode: 1 };
140091
140397
  }
140092
- if (path11 === (0, import_os7.homedir)()) {
140398
+ if (path11 === (0, import_os8.homedir)()) {
140093
140399
  const shouldDeployHomeDirectory = await client2.input.confirm(
140094
140400
  `You are deploying your home directory. Do you want to continue?`,
140095
140401
  false
@@ -140102,13 +140408,13 @@ async function validatePaths(client2, paths) {
140102
140408
  }
140103
140409
  return { valid: true, path: path11 };
140104
140410
  }
140105
- var import_fs_extra16, import_chalk41, import_os7;
140411
+ var import_fs_extra16, import_chalk41, import_os8;
140106
140412
  var init_validate_paths = __esm({
140107
140413
  "src/util/validate-paths.ts"() {
140108
140414
  "use strict";
140109
140415
  import_fs_extra16 = __toESM3(require_lib());
140110
140416
  import_chalk41 = __toESM3(require_source());
140111
- import_os7 = require("os");
140417
+ import_os8 = require("os");
140112
140418
  init_humanize_path();
140113
140419
  init_output_manager();
140114
140420
  }
@@ -140834,10 +141140,13 @@ async function main2(client2) {
140834
141140
  }
140835
141141
  process.env.VERCEL = "1";
140836
141142
  process.env.NOW_BUILDER = "1";
140837
- await rootSpan.child("vc.doBuild").trace(
140838
- (span) => doBuild(client2, project, buildsJson, cwd, outputDir, span)
140839
- );
140840
- await rootSpan.stop();
141143
+ try {
141144
+ await rootSpan.child("vc.doBuild").trace(
141145
+ (span) => doBuild(client2, project, buildsJson, cwd, outputDir, span)
141146
+ );
141147
+ } finally {
141148
+ await rootSpan.stop();
141149
+ }
140841
141150
  return 0;
140842
141151
  } catch (err) {
140843
141152
  output_manager_default.prettyError(err);
@@ -145490,7 +145799,7 @@ var init_process_deployment = __esm({
145490
145799
  });
145491
145800
 
145492
145801
  // src/util/index.ts
145493
- var import_querystring4, import_url15, import_async_retry5, import_ms10, import_node_fetch3, import_bytes4, import_chalk55, Now;
145802
+ var import_querystring4, import_url15, import_async_retry5, import_ms10, import_node_fetch4, import_bytes4, import_chalk55, Now;
145494
145803
  var init_util = __esm({
145495
145804
  "src/util/index.ts"() {
145496
145805
  "use strict";
@@ -145498,7 +145807,7 @@ var init_util = __esm({
145498
145807
  import_url15 = require("url");
145499
145808
  import_async_retry5 = __toESM3(require_dist5());
145500
145809
  import_ms10 = __toESM3(require_ms());
145501
- import_node_fetch3 = __toESM3(require_lib7());
145810
+ import_node_fetch4 = __toESM3(require_lib7());
145502
145811
  import_bytes4 = __toESM3(require_bytes());
145503
145812
  import_chalk55 = __toESM3(require_source());
145504
145813
  init_ua();
@@ -145716,7 +146025,7 @@ ${err.stack}`);
145716
146025
  _url = `${parsedUrl.pathname}?${import_querystring4.default.stringify(query)}`;
145717
146026
  delete opts.useCurrentTeam;
145718
146027
  }
145719
- opts.headers = new import_node_fetch3.Headers(opts.headers);
146028
+ opts.headers = new import_node_fetch4.Headers(opts.headers);
145720
146029
  opts.headers.set("accept", "application/json");
145721
146030
  if (this._token) {
145722
146031
  opts.headers.set("authorization", `Bearer ${this._token}`);
@@ -145731,7 +146040,7 @@ ${err.stack}`);
145731
146040
  }
145732
146041
  const res = await output_manager_default.time(
145733
146042
  `${opts.method || "GET"} ${this._apiUrl}${_url} ${opts.body || ""}`,
145734
- (0, import_node_fetch3.default)(`${this._apiUrl}${_url}`, { ...opts, body })
146043
+ (0, import_node_fetch4.default)(`${this._apiUrl}${_url}`, { ...opts, body })
145735
146044
  );
145736
146045
  printIndications(res);
145737
146046
  return res;
@@ -164189,7 +164498,7 @@ var init_redirect = __esm({
164189
164498
 
164190
164499
  // src/util/dev/headers.ts
164191
164500
  function nodeHeadersToFetchHeaders(nodeHeaders) {
164192
- const headers = new import_node_fetch4.Headers();
164501
+ const headers = new import_node_fetch5.Headers();
164193
164502
  for (const [name, value] of Object.entries(nodeHeaders)) {
164194
164503
  if (Array.isArray(value)) {
164195
164504
  for (const val of value) {
@@ -164233,11 +164542,11 @@ function applyOverriddenHeaders(reqHeaders, respHeaders) {
164233
164542
  respHeaders.delete(valueKey);
164234
164543
  }
164235
164544
  }
164236
- var import_node_fetch4, NONOVERRIDABLE_HEADERS;
164545
+ var import_node_fetch5, NONOVERRIDABLE_HEADERS;
164237
164546
  var init_headers = __esm({
164238
164547
  "src/util/dev/headers.ts"() {
164239
164548
  "use strict";
164240
- import_node_fetch4 = __toESM3(require_lib7());
164549
+ import_node_fetch5 = __toESM3(require_lib7());
164241
164550
  NONOVERRIDABLE_HEADERS = /* @__PURE__ */ new Set([
164242
164551
  "host",
164243
164552
  "connection",
@@ -164523,7 +164832,7 @@ function buildMatchEquals(a, b) {
164523
164832
  return false;
164524
164833
  return true;
164525
164834
  }
164526
- var import_url18, import_http3, import_fs_extra21, import_ms13, import_chalk58, import_node_fetch5, import_pluralize7, import_raw_body, import_async_listen3, import_minimatch4, import_http_proxy, import_crypto2, import_serve_handler, import_chokidar, import_dotenv2, import_path35, import_once, import_directory, import_get_port, import_is_port_reachable, import_fast_deep_equal, import_npm_package_arg2, import_json_parse_better_errors3, import_client12, import_routing_utils5, import_build_utils17, import_fs_detectors6, import_frameworks6, import_error_utils21, frontendRuntimeSet, DEV_SERVER_PORT_BIND_TIMEOUT, DevServer;
164835
+ var import_url18, import_http3, import_fs_extra21, import_ms13, import_chalk58, import_node_fetch6, import_pluralize7, import_raw_body, import_async_listen3, import_minimatch4, import_http_proxy, import_crypto2, import_serve_handler, import_chokidar, import_dotenv2, import_path35, import_once, import_directory, import_get_port, import_is_port_reachable, import_fast_deep_equal, import_npm_package_arg2, import_json_parse_better_errors3, import_client12, import_routing_utils5, import_build_utils17, import_fs_detectors6, import_frameworks6, import_error_utils21, frontendRuntimeSet, DEV_SERVER_PORT_BIND_TIMEOUT, DevServer;
164527
164836
  var init_server = __esm({
164528
164837
  "src/util/dev/server.ts"() {
164529
164838
  "use strict";
@@ -164532,7 +164841,7 @@ var init_server = __esm({
164532
164841
  import_fs_extra21 = __toESM3(require_lib());
164533
164842
  import_ms13 = __toESM3(require_ms());
164534
164843
  import_chalk58 = __toESM3(require_source());
164535
- import_node_fetch5 = __toESM3(require_lib7());
164844
+ import_node_fetch6 = __toESM3(require_lib7());
164536
164845
  import_pluralize7 = __toESM3(require_pluralize());
164537
164846
  import_raw_body = __toESM3(require_raw_body());
164538
164847
  import_async_listen3 = __toESM3(require_dist6());
@@ -164728,7 +165037,7 @@ var init_server = __esm({
164728
165037
  for (const [name, value] of nodeHeadersToFetchHeaders(proxyHeaders)) {
164729
165038
  middlewareReqHeaders.set(name, value);
164730
165039
  }
164731
- const middlewareRes = await (0, import_node_fetch5.default)(
165040
+ const middlewareRes = await (0, import_node_fetch6.default)(
164732
165041
  `http://127.0.0.1:${port}${parsed.path}`,
164733
165042
  {
164734
165043
  headers: middlewareReqHeaders,
@@ -166277,7 +166586,7 @@ async function* refreshOidcToken(signal, client2, projectId, envValues, source,
166277
166586
  const now = clock();
166278
166587
  let expiresAfterMillis;
166279
166588
  try {
166280
- const { exp } = (0, import_jose.decodeJwt)(oidcToken);
166589
+ const { exp } = (0, import_jose2.decodeJwt)(oidcToken);
166281
166590
  expiresAfterMillis = exp !== void 0 ? exp * 1e3 - now : void 0;
166282
166591
  } catch (error3) {
166283
166592
  }
@@ -166341,12 +166650,12 @@ function clock() {
166341
166650
  function millisToSecs(millis) {
166342
166651
  return millis / 1e3;
166343
166652
  }
166344
- var import_promises2, import_jose, import_ms14, import_perf_hooks, REFRESH_BEFORE_EXPIRY_MILLIS, THROTTLE_MILLIS;
166653
+ var import_promises2, import_jose2, import_ms14, import_perf_hooks, REFRESH_BEFORE_EXPIRY_MILLIS, THROTTLE_MILLIS;
166345
166654
  var init_refresh_oidc_token = __esm({
166346
166655
  "src/util/env/refresh-oidc-token.ts"() {
166347
166656
  "use strict";
166348
166657
  import_promises2 = require("timers/promises");
166349
- import_jose = require("jose");
166658
+ import_jose2 = require("jose");
166350
166659
  import_ms14 = __toESM3(require_ms());
166351
166660
  import_perf_hooks = require("perf_hooks");
166352
166661
  init_output_manager();
@@ -166422,7 +166731,7 @@ async function dev(client2, opts, args2, telemetry2) {
166422
166731
  envValues,
166423
166732
  "vercel-cli:dev"
166424
166733
  )) {
166425
- output_manager_default.log(`Refreshing ${import_chalk59.default.green(VERCEL_OIDC_TOKEN)}`);
166734
+ output_manager_default.debug(`Refreshing ${import_chalk59.default.green(VERCEL_OIDC_TOKEN)}`);
166426
166735
  envValues[VERCEL_OIDC_TOKEN] = token;
166427
166736
  await devServer.runDevCommand(true);
166428
166737
  telemetry2.trackOidcTokenRefresh(++refreshCount);
@@ -175589,234 +175898,6 @@ var init_login2 = __esm({
175589
175898
  }
175590
175899
  });
175591
175900
 
175592
- // src/util/oauth.ts
175593
- async function as() {
175594
- if (!_as) {
175595
- const discoveryResponse = await discoveryEndpointRequest(VERCEL_ISSUER);
175596
- const [discoveryResponseError, as2] = await processDiscoveryEndpointResponse(discoveryResponse);
175597
- if (discoveryResponseError) {
175598
- throw discoveryResponseError;
175599
- }
175600
- _as = as2;
175601
- }
175602
- return _as;
175603
- }
175604
- async function discoveryEndpointRequest(issuer) {
175605
- return await (0, import_node_fetch6.default)(new URL(".well-known/openid-configuration", issuer), {
175606
- headers: { "Content-Type": "application/json", "user-agent": userAgent }
175607
- });
175608
- }
175609
- async function processDiscoveryEndpointResponse(response) {
175610
- const json = await response.json();
175611
- if (!response.ok) {
175612
- return [new Error("Discovery endpoint request failed")];
175613
- }
175614
- if (typeof json !== "object" || json === null || !canParseURL(json.issuer) || !canParseURL(json.device_authorization_endpoint) || !canParseURL(json.token_endpoint) || !canParseURL(json.revocation_endpoint) || !canParseURL(json.jwks_uri)) {
175615
- return [new TypeError("Invalid discovery response")];
175616
- }
175617
- const issuer = new URL(json.issuer);
175618
- if (issuer.href !== VERCEL_ISSUER.href) {
175619
- return [new Error("Issuer mismatch")];
175620
- }
175621
- return [
175622
- null,
175623
- {
175624
- issuer,
175625
- device_authorization_endpoint: new URL(
175626
- json.device_authorization_endpoint
175627
- ),
175628
- token_endpoint: new URL(json.token_endpoint),
175629
- revocation_endpoint: new URL(json.revocation_endpoint),
175630
- jwks_uri: new URL(json.jwks_uri)
175631
- }
175632
- ];
175633
- }
175634
- async function deviceAuthorizationRequest() {
175635
- return await (0, import_node_fetch6.default)((await as()).device_authorization_endpoint, {
175636
- method: "POST",
175637
- headers: {
175638
- "Content-Type": "application/x-www-form-urlencoded",
175639
- "user-agent": userAgent
175640
- },
175641
- body: new URLSearchParams({
175642
- client_id: VERCEL_CLI_CLIENT_ID,
175643
- scope: "openid"
175644
- })
175645
- });
175646
- }
175647
- async function processDeviceAuthorizationResponse(response) {
175648
- const json = await response.json();
175649
- if (!response.ok) {
175650
- return [new OAuthError("Device authorization request failed", json)];
175651
- }
175652
- if (typeof json !== "object" || json === null)
175653
- return [new TypeError("Expected response to be an object")];
175654
- if (!("device_code" in json) || typeof json.device_code !== "string")
175655
- return [new TypeError("Expected `device_code` to be a string")];
175656
- if (!("user_code" in json) || typeof json.user_code !== "string")
175657
- return [new TypeError("Expected `user_code` to be a string")];
175658
- if (!("verification_uri" in json) || typeof json.verification_uri !== "string" || !canParseURL(json.verification_uri)) {
175659
- return [new TypeError("Expected `verification_uri` to be a string")];
175660
- }
175661
- if (!("verification_uri_complete" in json) || typeof json.verification_uri_complete !== "string" || !canParseURL(json.verification_uri_complete)) {
175662
- return [
175663
- new TypeError("Expected `verification_uri_complete` to be a string")
175664
- ];
175665
- }
175666
- if (!("expires_in" in json) || typeof json.expires_in !== "number")
175667
- return [new TypeError("Expected `expires_in` to be a number")];
175668
- if (!("interval" in json) || typeof json.interval !== "number")
175669
- return [new TypeError("Expected `interval` to be a number")];
175670
- return [
175671
- null,
175672
- {
175673
- device_code: json.device_code,
175674
- user_code: json.user_code,
175675
- verification_uri: json.verification_uri,
175676
- verification_uri_complete: json.verification_uri_complete,
175677
- expiresAt: Date.now() + json.expires_in * 1e3,
175678
- interval: json.interval
175679
- }
175680
- ];
175681
- }
175682
- async function deviceAccessTokenRequest(options) {
175683
- try {
175684
- return [
175685
- null,
175686
- await (0, import_node_fetch6.default)((await as()).token_endpoint, {
175687
- method: "POST",
175688
- headers: {
175689
- "Content-Type": "application/x-www-form-urlencoded",
175690
- "user-agent": userAgent
175691
- },
175692
- body: new URLSearchParams({
175693
- client_id: VERCEL_CLI_CLIENT_ID,
175694
- grant_type: "urn:ietf:params:oauth:grant-type:device_code",
175695
- ...options
175696
- }),
175697
- // TODO: Drop `node-fetch` and just use `signal`
175698
- timeout: 10 * 1e3,
175699
- // @ts-expect-error: Signal is part of `fetch` spec, should drop `node-fetch`
175700
- signal: AbortSignal.timeout(10 * 1e3)
175701
- })
175702
- ];
175703
- } catch (error3) {
175704
- if (error3 instanceof Error)
175705
- return [error3];
175706
- return [
175707
- new Error("An unknown error occurred. See the logs for details.", {
175708
- cause: error3
175709
- })
175710
- ];
175711
- }
175712
- }
175713
- async function processDeviceAccessTokenResponse(response) {
175714
- const json = await response.json();
175715
- if (!response.ok) {
175716
- return [new OAuthError("Device access token request failed", json)];
175717
- }
175718
- if (typeof json !== "object" || json === null)
175719
- return [new TypeError("Expected response to be an object")];
175720
- if (!("access_token" in json) || typeof json.access_token !== "string")
175721
- return [new TypeError("Expected `access_token` to be a string")];
175722
- if (!("token_type" in json) || json.token_type !== "Bearer")
175723
- return [new TypeError('Expected `token_type` to be "Bearer"')];
175724
- if (!("expires_in" in json) || typeof json.expires_in !== "number")
175725
- return [new TypeError("Expected `expires_in` to be a number")];
175726
- if ("refresh_token" in json && (typeof json.refresh_token !== "string" || !json.refresh_token))
175727
- return [new TypeError("Expected `refresh_token` to be a string")];
175728
- if ("scope" in json && typeof json.scope !== "string")
175729
- return [new TypeError("Expected `scope` to be a string")];
175730
- return [null, json];
175731
- }
175732
- async function revocationRequest(options) {
175733
- return await (0, import_node_fetch6.default)((await as()).revocation_endpoint, {
175734
- method: "POST",
175735
- headers: {
175736
- "Content-Type": "application/x-www-form-urlencoded",
175737
- "user-agent": userAgent
175738
- },
175739
- body: new URLSearchParams({ ...options, client_id: VERCEL_CLI_CLIENT_ID })
175740
- });
175741
- }
175742
- async function processRevocationResponse(response) {
175743
- if (response.ok)
175744
- return [null, null];
175745
- const json = await response.json();
175746
- return [new OAuthError("Revocation request failed", json)];
175747
- }
175748
- function processOAuthErrorResponse(json) {
175749
- if (typeof json !== "object" || json === null)
175750
- return new TypeError("Expected response to be an object");
175751
- if (!("error" in json) || typeof json.error !== "string")
175752
- return new TypeError("Expected `error` to be a string");
175753
- if ("error_description" in json && typeof json.error_description !== "string")
175754
- return new TypeError("Expected `error_description` to be a string");
175755
- if ("error_uri" in json && typeof json.error_uri !== "string")
175756
- return new TypeError("Expected `error_uri` to be a string");
175757
- return json;
175758
- }
175759
- function isOAuthError(error3) {
175760
- return error3 instanceof OAuthError;
175761
- }
175762
- function canParseURL(url3) {
175763
- try {
175764
- return !!new URL(url3);
175765
- } catch {
175766
- return false;
175767
- }
175768
- }
175769
- async function verifyJWT(token) {
175770
- try {
175771
- const JWKS = (0, import_jose2.createRemoteJWKSet)((await as()).jwks_uri);
175772
- const { payload } = await (0, import_jose2.jwtVerify)(token, JWKS, {
175773
- issuer: "https://vercel.com",
175774
- audience: ["https://api.vercel.com", "https://vercel.com/api"]
175775
- });
175776
- return [null, payload];
175777
- } catch (error3) {
175778
- if (error3 instanceof Error)
175779
- return [error3];
175780
- return [new Error("Could not verify JWT.", { cause: error3 })];
175781
- }
175782
- }
175783
- var import_node_fetch6, import_jose2, import_os8, VERCEL_ISSUER, VERCEL_CLI_CLIENT_ID, userAgent, _as, OAuthError;
175784
- var init_oauth2 = __esm({
175785
- "src/util/oauth.ts"() {
175786
- "use strict";
175787
- import_node_fetch6 = __toESM3(require_lib7());
175788
- import_jose2 = require("jose");
175789
- init_ua();
175790
- import_os8 = require("os");
175791
- VERCEL_ISSUER = new URL("https://vercel.com");
175792
- VERCEL_CLI_CLIENT_ID = "cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp";
175793
- userAgent = `${(0, import_os8.hostname)()} @ ${ua_default}`;
175794
- OAuthError = class extends Error {
175795
- constructor(message2, response) {
175796
- var __super = (...args) => {
175797
- super(...args);
175798
- };
175799
- const error3 = processOAuthErrorResponse(response);
175800
- if (error3 instanceof TypeError) {
175801
- const message3 = `Unexpected server response: ${JSON.stringify(response)}`;
175802
- __super(message3);
175803
- this.cause = new Error(message3, { cause: error3 });
175804
- this.code = "server_error";
175805
- return;
175806
- }
175807
- let cause = error3.error;
175808
- if (error3.error_description)
175809
- cause += `: ${error3.error_description}`;
175810
- if (error3.error_uri)
175811
- cause += ` (${error3.error_uri})`;
175812
- __super(message2, { cause });
175813
- this.cause = new Error(cause);
175814
- this.code = error3.error;
175815
- }
175816
- };
175817
- }
175818
- });
175819
-
175820
175901
  // src/commands/login/future.ts
175821
175902
  async function login2(client2) {
175822
175903
  const deviceAuthorizationResponse = await deviceAuthorizationRequest();
@@ -175880,9 +175961,9 @@ async function login2(client2) {
175880
175961
  output_manager_default.debug(
175881
175962
  `'Device Access Token response:', ${await tokenResponse.clone().text()}`
175882
175963
  );
175883
- const [tokenError, token] = await processDeviceAccessTokenResponse(tokenResponse);
175884
- if (isOAuthError(tokenError)) {
175885
- const { code: code2 } = tokenError;
175964
+ const [tokensError, tokens] = await processTokenResponse(tokenResponse);
175965
+ if (isOAuthError(tokensError)) {
175966
+ const { code: code2 } = tokensError;
175886
175967
  switch (code2) {
175887
175968
  case "authorization_pending":
175888
175969
  continue;
@@ -175893,34 +175974,36 @@ async function login2(client2) {
175893
175974
  );
175894
175975
  continue;
175895
175976
  default:
175896
- return tokenError.cause;
175977
+ return tokensError.cause;
175897
175978
  }
175898
175979
  }
175899
- if (tokenError)
175900
- return tokenError;
175980
+ if (tokensError)
175981
+ return tokensError;
175982
+ error3 = void 0;
175901
175983
  output_manager_default.print((0, import_ansi_escapes6.eraseLines)(2));
175902
175984
  const isInitialLogin = !client2.authConfig.token;
175903
- client2.authConfig.token = token.access_token;
175904
- error3 = void 0;
175905
- const [accessTokenError, accessToken] = await verifyJWT(
175906
- token.access_token
175907
- );
175908
- if (accessTokenError) {
175909
- return accessTokenError;
175910
- }
175911
- output_manager_default.debug("access_token verified");
175912
- if (accessToken.team_id) {
175985
+ const [inspectError, payload] = inspectToken(tokens.access_token);
175986
+ if (inspectError)
175987
+ return inspectError;
175988
+ output_manager_default.debug("access_token inspected");
175989
+ client2.updateAuthConfig({
175990
+ token: tokens.access_token,
175991
+ type: "oauth",
175992
+ expiresAt: Math.floor(Date.now() / 1e3) + tokens.expires_in
175993
+ });
175994
+ if (payload.team_id)
175913
175995
  output_manager_default.debug("Current team updated");
175914
- client2.config.currentTeam = accessToken.team_id;
175915
- } else {
175996
+ else
175916
175997
  output_manager_default.debug("Current team deleted");
175917
- delete client2.config.currentTeam;
175998
+ client2.updateConfig({ currentTeam: payload.team_id });
175999
+ if (tokens.refresh_token) {
176000
+ client2.updateAuthConfig({ refreshToken: tokens.refresh_token });
175918
176001
  }
175919
176002
  if (isInitialLogin) {
175920
176003
  await updateCurrentTeamAfterLogin(client2, client2.config.currentTeam);
175921
176004
  }
175922
- writeToAuthConfigFile(client2.authConfig);
175923
- writeToConfigFile(client2.config);
176005
+ client2.writeToAuthConfigFile();
176006
+ client2.writeToConfigFile();
175924
176007
  output_manager_default.debug(`Saved credentials in "${humanizePath(global_path_default())}"`);
175925
176008
  output_manager_default.print(`
175926
176009
  ${import_chalk101.default.cyan("Congratulations!")} You are now signed in.
@@ -175951,7 +176034,6 @@ var init_future = __esm({
175951
176034
  import_ansi_escapes6 = __toESM3(require_ansi_escapes());
175952
176035
  init_error2();
175953
176036
  init_update_current_team_after_login();
175954
- init_files();
175955
176037
  init_global_path();
175956
176038
  init_pkg_name();
175957
176039
  init_emoji();
@@ -176081,7 +176163,7 @@ var init_logout = __esm({
176081
176163
 
176082
176164
  // src/commands/logout/future.ts
176083
176165
  async function logout(client2) {
176084
- const { config: config2, authConfig } = client2;
176166
+ const { authConfig } = client2;
176085
176167
  if (!authConfig.token) {
176086
176168
  output_manager_default.note(
176087
176169
  `Not currently logged in, so ${getCommandName("logout --future")} did nothing`
@@ -176101,13 +176183,11 @@ async function logout(client2) {
176101
176183
  output_manager_default.error("Failed during logout");
176102
176184
  logoutError = true;
176103
176185
  }
176104
- delete config2.currentTeam;
176105
- if (config2.desktop)
176106
- delete config2.desktop.teamOrder;
176107
- delete authConfig.token;
176108
176186
  try {
176109
- writeToConfigFile(config2);
176110
- writeToAuthConfigFile(authConfig);
176187
+ client2.updateConfig({ currentTeam: void 0 });
176188
+ client2.writeToConfigFile();
176189
+ client2.emptyAuthConfig();
176190
+ client2.writeToAuthConfigFile();
176111
176191
  output_manager_default.debug("Configuration has been deleted");
176112
176192
  if (!logoutError) {
176113
176193
  output_manager_default.success("Logged out!");
@@ -176124,7 +176204,6 @@ var init_future2 = __esm({
176124
176204
  "src/commands/logout/future.ts"() {
176125
176205
  "use strict";
176126
176206
  import_error_utils30 = __toESM3(require_dist2());
176127
- init_files();
176128
176207
  init_pkg_name();
176129
176208
  init_oauth2();
176130
176209
  init_output_manager();
@@ -176184,9 +176263,6 @@ async function logout2(client2) {
176184
176263
  }
176185
176264
  }
176186
176265
  delete config2.currentTeam;
176187
- if (config2.desktop) {
176188
- delete config2.desktop.teamOrder;
176189
- }
176190
176266
  delete authConfig.token;
176191
176267
  try {
176192
176268
  writeToConfigFile(config2);
@@ -179987,10 +180063,10 @@ var import_build_utils3 = require("@vercel/build-utils");
179987
180063
 
179988
180064
  // src/util/extension/proxy.ts
179989
180065
  var import_http2 = require("http");
179990
- var import_node_fetch2 = __toESM3(require_lib7());
180066
+ var import_node_fetch3 = __toESM3(require_lib7());
179991
180067
  var import_node_utils = __toESM3(require_dist19());
179992
180068
  init_output_manager();
179993
- var toHeaders = (0, import_node_utils.buildToHeaders)({ Headers: import_node_fetch2.Headers });
180069
+ var toHeaders = (0, import_node_utils.buildToHeaders)({ Headers: import_node_fetch3.Headers });
179994
180070
  function createProxy(client2) {
179995
180071
  return (0, import_http2.createServer)(async (req, res) => {
179996
180072
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vercel",
3
- "version": "41.7.8",
3
+ "version": "42.1.0",
4
4
  "preferGlobal": true,
5
5
  "license": "Apache-2.0",
6
6
  "description": "The command-line interface for Vercel",
@@ -159,9 +159,9 @@
159
159
  "write-json-file": "2.2.0",
160
160
  "xdg-app-paths": "5.1.0",
161
161
  "yauzl-promise": "2.1.3",
162
- "@vercel-internals/get-package-json": "1.0.0",
162
+ "@vercel-internals/constants": "1.0.4",
163
163
  "@vercel-internals/types": "3.0.6",
164
- "@vercel-internals/constants": "1.0.4"
164
+ "@vercel-internals/get-package-json": "1.0.0"
165
165
  },
166
166
  "scripts": {
167
167
  "test": "jest --reporters=default --reporters=jest-junit --env node --verbose --bail",