vercel 42.0.0 → 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 +363 -290
  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
 
@@ -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
  }
@@ -145493,7 +145799,7 @@ var init_process_deployment = __esm({
145493
145799
  });
145494
145800
 
145495
145801
  // src/util/index.ts
145496
- 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;
145497
145803
  var init_util = __esm({
145498
145804
  "src/util/index.ts"() {
145499
145805
  "use strict";
@@ -145501,7 +145807,7 @@ var init_util = __esm({
145501
145807
  import_url15 = require("url");
145502
145808
  import_async_retry5 = __toESM3(require_dist5());
145503
145809
  import_ms10 = __toESM3(require_ms());
145504
- import_node_fetch3 = __toESM3(require_lib7());
145810
+ import_node_fetch4 = __toESM3(require_lib7());
145505
145811
  import_bytes4 = __toESM3(require_bytes());
145506
145812
  import_chalk55 = __toESM3(require_source());
145507
145813
  init_ua();
@@ -145719,7 +146025,7 @@ ${err.stack}`);
145719
146025
  _url = `${parsedUrl.pathname}?${import_querystring4.default.stringify(query)}`;
145720
146026
  delete opts.useCurrentTeam;
145721
146027
  }
145722
- opts.headers = new import_node_fetch3.Headers(opts.headers);
146028
+ opts.headers = new import_node_fetch4.Headers(opts.headers);
145723
146029
  opts.headers.set("accept", "application/json");
145724
146030
  if (this._token) {
145725
146031
  opts.headers.set("authorization", `Bearer ${this._token}`);
@@ -145734,7 +146040,7 @@ ${err.stack}`);
145734
146040
  }
145735
146041
  const res = await output_manager_default.time(
145736
146042
  `${opts.method || "GET"} ${this._apiUrl}${_url} ${opts.body || ""}`,
145737
- (0, import_node_fetch3.default)(`${this._apiUrl}${_url}`, { ...opts, body })
146043
+ (0, import_node_fetch4.default)(`${this._apiUrl}${_url}`, { ...opts, body })
145738
146044
  );
145739
146045
  printIndications(res);
145740
146046
  return res;
@@ -164192,7 +164498,7 @@ var init_redirect = __esm({
164192
164498
 
164193
164499
  // src/util/dev/headers.ts
164194
164500
  function nodeHeadersToFetchHeaders(nodeHeaders) {
164195
- const headers = new import_node_fetch4.Headers();
164501
+ const headers = new import_node_fetch5.Headers();
164196
164502
  for (const [name, value] of Object.entries(nodeHeaders)) {
164197
164503
  if (Array.isArray(value)) {
164198
164504
  for (const val of value) {
@@ -164236,11 +164542,11 @@ function applyOverriddenHeaders(reqHeaders, respHeaders) {
164236
164542
  respHeaders.delete(valueKey);
164237
164543
  }
164238
164544
  }
164239
- var import_node_fetch4, NONOVERRIDABLE_HEADERS;
164545
+ var import_node_fetch5, NONOVERRIDABLE_HEADERS;
164240
164546
  var init_headers = __esm({
164241
164547
  "src/util/dev/headers.ts"() {
164242
164548
  "use strict";
164243
- import_node_fetch4 = __toESM3(require_lib7());
164549
+ import_node_fetch5 = __toESM3(require_lib7());
164244
164550
  NONOVERRIDABLE_HEADERS = /* @__PURE__ */ new Set([
164245
164551
  "host",
164246
164552
  "connection",
@@ -164526,7 +164832,7 @@ function buildMatchEquals(a, b) {
164526
164832
  return false;
164527
164833
  return true;
164528
164834
  }
164529
- 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;
164530
164836
  var init_server = __esm({
164531
164837
  "src/util/dev/server.ts"() {
164532
164838
  "use strict";
@@ -164535,7 +164841,7 @@ var init_server = __esm({
164535
164841
  import_fs_extra21 = __toESM3(require_lib());
164536
164842
  import_ms13 = __toESM3(require_ms());
164537
164843
  import_chalk58 = __toESM3(require_source());
164538
- import_node_fetch5 = __toESM3(require_lib7());
164844
+ import_node_fetch6 = __toESM3(require_lib7());
164539
164845
  import_pluralize7 = __toESM3(require_pluralize());
164540
164846
  import_raw_body = __toESM3(require_raw_body());
164541
164847
  import_async_listen3 = __toESM3(require_dist6());
@@ -164731,7 +165037,7 @@ var init_server = __esm({
164731
165037
  for (const [name, value] of nodeHeadersToFetchHeaders(proxyHeaders)) {
164732
165038
  middlewareReqHeaders.set(name, value);
164733
165039
  }
164734
- const middlewareRes = await (0, import_node_fetch5.default)(
165040
+ const middlewareRes = await (0, import_node_fetch6.default)(
164735
165041
  `http://127.0.0.1:${port}${parsed.path}`,
164736
165042
  {
164737
165043
  headers: middlewareReqHeaders,
@@ -166280,7 +166586,7 @@ async function* refreshOidcToken(signal, client2, projectId, envValues, source,
166280
166586
  const now = clock();
166281
166587
  let expiresAfterMillis;
166282
166588
  try {
166283
- const { exp } = (0, import_jose.decodeJwt)(oidcToken);
166589
+ const { exp } = (0, import_jose2.decodeJwt)(oidcToken);
166284
166590
  expiresAfterMillis = exp !== void 0 ? exp * 1e3 - now : void 0;
166285
166591
  } catch (error3) {
166286
166592
  }
@@ -166344,12 +166650,12 @@ function clock() {
166344
166650
  function millisToSecs(millis) {
166345
166651
  return millis / 1e3;
166346
166652
  }
166347
- 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;
166348
166654
  var init_refresh_oidc_token = __esm({
166349
166655
  "src/util/env/refresh-oidc-token.ts"() {
166350
166656
  "use strict";
166351
166657
  import_promises2 = require("timers/promises");
166352
- import_jose = require("jose");
166658
+ import_jose2 = require("jose");
166353
166659
  import_ms14 = __toESM3(require_ms());
166354
166660
  import_perf_hooks = require("perf_hooks");
166355
166661
  init_output_manager();
@@ -175592,234 +175898,6 @@ var init_login2 = __esm({
175592
175898
  }
175593
175899
  });
175594
175900
 
175595
- // src/util/oauth.ts
175596
- async function as() {
175597
- if (!_as) {
175598
- const discoveryResponse = await discoveryEndpointRequest(VERCEL_ISSUER);
175599
- const [discoveryResponseError, as2] = await processDiscoveryEndpointResponse(discoveryResponse);
175600
- if (discoveryResponseError) {
175601
- throw discoveryResponseError;
175602
- }
175603
- _as = as2;
175604
- }
175605
- return _as;
175606
- }
175607
- async function discoveryEndpointRequest(issuer) {
175608
- return await (0, import_node_fetch6.default)(new URL(".well-known/openid-configuration", issuer), {
175609
- headers: { "Content-Type": "application/json", "user-agent": userAgent }
175610
- });
175611
- }
175612
- async function processDiscoveryEndpointResponse(response) {
175613
- const json = await response.json();
175614
- if (!response.ok) {
175615
- return [new Error("Discovery endpoint request failed")];
175616
- }
175617
- 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)) {
175618
- return [new TypeError("Invalid discovery response")];
175619
- }
175620
- const issuer = new URL(json.issuer);
175621
- if (issuer.href !== VERCEL_ISSUER.href) {
175622
- return [new Error("Issuer mismatch")];
175623
- }
175624
- return [
175625
- null,
175626
- {
175627
- issuer,
175628
- device_authorization_endpoint: new URL(
175629
- json.device_authorization_endpoint
175630
- ),
175631
- token_endpoint: new URL(json.token_endpoint),
175632
- revocation_endpoint: new URL(json.revocation_endpoint),
175633
- jwks_uri: new URL(json.jwks_uri)
175634
- }
175635
- ];
175636
- }
175637
- async function deviceAuthorizationRequest() {
175638
- return await (0, import_node_fetch6.default)((await as()).device_authorization_endpoint, {
175639
- method: "POST",
175640
- headers: {
175641
- "Content-Type": "application/x-www-form-urlencoded",
175642
- "user-agent": userAgent
175643
- },
175644
- body: new URLSearchParams({
175645
- client_id: VERCEL_CLI_CLIENT_ID,
175646
- scope: "openid"
175647
- })
175648
- });
175649
- }
175650
- async function processDeviceAuthorizationResponse(response) {
175651
- const json = await response.json();
175652
- if (!response.ok) {
175653
- return [new OAuthError("Device authorization request failed", json)];
175654
- }
175655
- if (typeof json !== "object" || json === null)
175656
- return [new TypeError("Expected response to be an object")];
175657
- if (!("device_code" in json) || typeof json.device_code !== "string")
175658
- return [new TypeError("Expected `device_code` to be a string")];
175659
- if (!("user_code" in json) || typeof json.user_code !== "string")
175660
- return [new TypeError("Expected `user_code` to be a string")];
175661
- if (!("verification_uri" in json) || typeof json.verification_uri !== "string" || !canParseURL(json.verification_uri)) {
175662
- return [new TypeError("Expected `verification_uri` to be a string")];
175663
- }
175664
- if (!("verification_uri_complete" in json) || typeof json.verification_uri_complete !== "string" || !canParseURL(json.verification_uri_complete)) {
175665
- return [
175666
- new TypeError("Expected `verification_uri_complete` to be a string")
175667
- ];
175668
- }
175669
- if (!("expires_in" in json) || typeof json.expires_in !== "number")
175670
- return [new TypeError("Expected `expires_in` to be a number")];
175671
- if (!("interval" in json) || typeof json.interval !== "number")
175672
- return [new TypeError("Expected `interval` to be a number")];
175673
- return [
175674
- null,
175675
- {
175676
- device_code: json.device_code,
175677
- user_code: json.user_code,
175678
- verification_uri: json.verification_uri,
175679
- verification_uri_complete: json.verification_uri_complete,
175680
- expiresAt: Date.now() + json.expires_in * 1e3,
175681
- interval: json.interval
175682
- }
175683
- ];
175684
- }
175685
- async function deviceAccessTokenRequest(options) {
175686
- try {
175687
- return [
175688
- null,
175689
- await (0, import_node_fetch6.default)((await as()).token_endpoint, {
175690
- method: "POST",
175691
- headers: {
175692
- "Content-Type": "application/x-www-form-urlencoded",
175693
- "user-agent": userAgent
175694
- },
175695
- body: new URLSearchParams({
175696
- client_id: VERCEL_CLI_CLIENT_ID,
175697
- grant_type: "urn:ietf:params:oauth:grant-type:device_code",
175698
- ...options
175699
- }),
175700
- // TODO: Drop `node-fetch` and just use `signal`
175701
- timeout: 10 * 1e3,
175702
- // @ts-expect-error: Signal is part of `fetch` spec, should drop `node-fetch`
175703
- signal: AbortSignal.timeout(10 * 1e3)
175704
- })
175705
- ];
175706
- } catch (error3) {
175707
- if (error3 instanceof Error)
175708
- return [error3];
175709
- return [
175710
- new Error("An unknown error occurred. See the logs for details.", {
175711
- cause: error3
175712
- })
175713
- ];
175714
- }
175715
- }
175716
- async function processDeviceAccessTokenResponse(response) {
175717
- const json = await response.json();
175718
- if (!response.ok) {
175719
- return [new OAuthError("Device access token request failed", json)];
175720
- }
175721
- if (typeof json !== "object" || json === null)
175722
- return [new TypeError("Expected response to be an object")];
175723
- if (!("access_token" in json) || typeof json.access_token !== "string")
175724
- return [new TypeError("Expected `access_token` to be a string")];
175725
- if (!("token_type" in json) || json.token_type !== "Bearer")
175726
- return [new TypeError('Expected `token_type` to be "Bearer"')];
175727
- if (!("expires_in" in json) || typeof json.expires_in !== "number")
175728
- return [new TypeError("Expected `expires_in` to be a number")];
175729
- if ("refresh_token" in json && (typeof json.refresh_token !== "string" || !json.refresh_token))
175730
- return [new TypeError("Expected `refresh_token` to be a string")];
175731
- if ("scope" in json && typeof json.scope !== "string")
175732
- return [new TypeError("Expected `scope` to be a string")];
175733
- return [null, json];
175734
- }
175735
- async function revocationRequest(options) {
175736
- return await (0, import_node_fetch6.default)((await as()).revocation_endpoint, {
175737
- method: "POST",
175738
- headers: {
175739
- "Content-Type": "application/x-www-form-urlencoded",
175740
- "user-agent": userAgent
175741
- },
175742
- body: new URLSearchParams({ ...options, client_id: VERCEL_CLI_CLIENT_ID })
175743
- });
175744
- }
175745
- async function processRevocationResponse(response) {
175746
- if (response.ok)
175747
- return [null, null];
175748
- const json = await response.json();
175749
- return [new OAuthError("Revocation request failed", json)];
175750
- }
175751
- function processOAuthErrorResponse(json) {
175752
- if (typeof json !== "object" || json === null)
175753
- return new TypeError("Expected response to be an object");
175754
- if (!("error" in json) || typeof json.error !== "string")
175755
- return new TypeError("Expected `error` to be a string");
175756
- if ("error_description" in json && typeof json.error_description !== "string")
175757
- return new TypeError("Expected `error_description` to be a string");
175758
- if ("error_uri" in json && typeof json.error_uri !== "string")
175759
- return new TypeError("Expected `error_uri` to be a string");
175760
- return json;
175761
- }
175762
- function isOAuthError(error3) {
175763
- return error3 instanceof OAuthError;
175764
- }
175765
- function canParseURL(url3) {
175766
- try {
175767
- return !!new URL(url3);
175768
- } catch {
175769
- return false;
175770
- }
175771
- }
175772
- async function verifyJWT(token) {
175773
- try {
175774
- const JWKS = (0, import_jose2.createRemoteJWKSet)((await as()).jwks_uri);
175775
- const { payload } = await (0, import_jose2.jwtVerify)(token, JWKS, {
175776
- issuer: "https://vercel.com",
175777
- audience: ["https://api.vercel.com", "https://vercel.com/api"]
175778
- });
175779
- return [null, payload];
175780
- } catch (error3) {
175781
- if (error3 instanceof Error)
175782
- return [error3];
175783
- return [new Error("Could not verify JWT.", { cause: error3 })];
175784
- }
175785
- }
175786
- var import_node_fetch6, import_jose2, import_os8, VERCEL_ISSUER, VERCEL_CLI_CLIENT_ID, userAgent, _as, OAuthError;
175787
- var init_oauth2 = __esm({
175788
- "src/util/oauth.ts"() {
175789
- "use strict";
175790
- import_node_fetch6 = __toESM3(require_lib7());
175791
- import_jose2 = require("jose");
175792
- init_ua();
175793
- import_os8 = require("os");
175794
- VERCEL_ISSUER = new URL("https://vercel.com");
175795
- VERCEL_CLI_CLIENT_ID = "cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp";
175796
- userAgent = `${(0, import_os8.hostname)()} @ ${ua_default}`;
175797
- OAuthError = class extends Error {
175798
- constructor(message2, response) {
175799
- var __super = (...args) => {
175800
- super(...args);
175801
- };
175802
- const error3 = processOAuthErrorResponse(response);
175803
- if (error3 instanceof TypeError) {
175804
- const message3 = `Unexpected server response: ${JSON.stringify(response)}`;
175805
- __super(message3);
175806
- this.cause = new Error(message3, { cause: error3 });
175807
- this.code = "server_error";
175808
- return;
175809
- }
175810
- let cause = error3.error;
175811
- if (error3.error_description)
175812
- cause += `: ${error3.error_description}`;
175813
- if (error3.error_uri)
175814
- cause += ` (${error3.error_uri})`;
175815
- __super(message2, { cause });
175816
- this.cause = new Error(cause);
175817
- this.code = error3.error;
175818
- }
175819
- };
175820
- }
175821
- });
175822
-
175823
175901
  // src/commands/login/future.ts
175824
175902
  async function login2(client2) {
175825
175903
  const deviceAuthorizationResponse = await deviceAuthorizationRequest();
@@ -175883,9 +175961,9 @@ async function login2(client2) {
175883
175961
  output_manager_default.debug(
175884
175962
  `'Device Access Token response:', ${await tokenResponse.clone().text()}`
175885
175963
  );
175886
- const [tokenError, token] = await processDeviceAccessTokenResponse(tokenResponse);
175887
- if (isOAuthError(tokenError)) {
175888
- const { code: code2 } = tokenError;
175964
+ const [tokensError, tokens] = await processTokenResponse(tokenResponse);
175965
+ if (isOAuthError(tokensError)) {
175966
+ const { code: code2 } = tokensError;
175889
175967
  switch (code2) {
175890
175968
  case "authorization_pending":
175891
175969
  continue;
@@ -175896,34 +175974,36 @@ async function login2(client2) {
175896
175974
  );
175897
175975
  continue;
175898
175976
  default:
175899
- return tokenError.cause;
175977
+ return tokensError.cause;
175900
175978
  }
175901
175979
  }
175902
- if (tokenError)
175903
- return tokenError;
175980
+ if (tokensError)
175981
+ return tokensError;
175982
+ error3 = void 0;
175904
175983
  output_manager_default.print((0, import_ansi_escapes6.eraseLines)(2));
175905
175984
  const isInitialLogin = !client2.authConfig.token;
175906
- client2.authConfig.token = token.access_token;
175907
- error3 = void 0;
175908
- const [accessTokenError, accessToken] = await verifyJWT(
175909
- token.access_token
175910
- );
175911
- if (accessTokenError) {
175912
- return accessTokenError;
175913
- }
175914
- output_manager_default.debug("access_token verified");
175915
- 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)
175916
175995
  output_manager_default.debug("Current team updated");
175917
- client2.config.currentTeam = accessToken.team_id;
175918
- } else {
175996
+ else
175919
175997
  output_manager_default.debug("Current team deleted");
175920
- delete client2.config.currentTeam;
175998
+ client2.updateConfig({ currentTeam: payload.team_id });
175999
+ if (tokens.refresh_token) {
176000
+ client2.updateAuthConfig({ refreshToken: tokens.refresh_token });
175921
176001
  }
175922
176002
  if (isInitialLogin) {
175923
176003
  await updateCurrentTeamAfterLogin(client2, client2.config.currentTeam);
175924
176004
  }
175925
- writeToAuthConfigFile(client2.authConfig);
175926
- writeToConfigFile(client2.config);
176005
+ client2.writeToAuthConfigFile();
176006
+ client2.writeToConfigFile();
175927
176007
  output_manager_default.debug(`Saved credentials in "${humanizePath(global_path_default())}"`);
175928
176008
  output_manager_default.print(`
175929
176009
  ${import_chalk101.default.cyan("Congratulations!")} You are now signed in.
@@ -175954,7 +176034,6 @@ var init_future = __esm({
175954
176034
  import_ansi_escapes6 = __toESM3(require_ansi_escapes());
175955
176035
  init_error2();
175956
176036
  init_update_current_team_after_login();
175957
- init_files();
175958
176037
  init_global_path();
175959
176038
  init_pkg_name();
175960
176039
  init_emoji();
@@ -176084,7 +176163,7 @@ var init_logout = __esm({
176084
176163
 
176085
176164
  // src/commands/logout/future.ts
176086
176165
  async function logout(client2) {
176087
- const { config: config2, authConfig } = client2;
176166
+ const { authConfig } = client2;
176088
176167
  if (!authConfig.token) {
176089
176168
  output_manager_default.note(
176090
176169
  `Not currently logged in, so ${getCommandName("logout --future")} did nothing`
@@ -176104,13 +176183,11 @@ async function logout(client2) {
176104
176183
  output_manager_default.error("Failed during logout");
176105
176184
  logoutError = true;
176106
176185
  }
176107
- delete config2.currentTeam;
176108
- if (config2.desktop)
176109
- delete config2.desktop.teamOrder;
176110
- delete authConfig.token;
176111
176186
  try {
176112
- writeToConfigFile(config2);
176113
- writeToAuthConfigFile(authConfig);
176187
+ client2.updateConfig({ currentTeam: void 0 });
176188
+ client2.writeToConfigFile();
176189
+ client2.emptyAuthConfig();
176190
+ client2.writeToAuthConfigFile();
176114
176191
  output_manager_default.debug("Configuration has been deleted");
176115
176192
  if (!logoutError) {
176116
176193
  output_manager_default.success("Logged out!");
@@ -176127,7 +176204,6 @@ var init_future2 = __esm({
176127
176204
  "src/commands/logout/future.ts"() {
176128
176205
  "use strict";
176129
176206
  import_error_utils30 = __toESM3(require_dist2());
176130
- init_files();
176131
176207
  init_pkg_name();
176132
176208
  init_oauth2();
176133
176209
  init_output_manager();
@@ -176187,9 +176263,6 @@ async function logout2(client2) {
176187
176263
  }
176188
176264
  }
176189
176265
  delete config2.currentTeam;
176190
- if (config2.desktop) {
176191
- delete config2.desktop.teamOrder;
176192
- }
176193
176266
  delete authConfig.token;
176194
176267
  try {
176195
176268
  writeToConfigFile(config2);
@@ -179990,10 +180063,10 @@ var import_build_utils3 = require("@vercel/build-utils");
179990
180063
 
179991
180064
  // src/util/extension/proxy.ts
179992
180065
  var import_http2 = require("http");
179993
- var import_node_fetch2 = __toESM3(require_lib7());
180066
+ var import_node_fetch3 = __toESM3(require_lib7());
179994
180067
  var import_node_utils = __toESM3(require_dist19());
179995
180068
  init_output_manager();
179996
- 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 });
179997
180070
  function createProxy(client2) {
179998
180071
  return (0, import_http2.createServer)(async (req, res) => {
179999
180072
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vercel",
3
- "version": "42.0.0",
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",
163
162
  "@vercel-internals/constants": "1.0.4",
164
- "@vercel-internals/types": "3.0.6"
163
+ "@vercel-internals/types": "3.0.6",
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",