eas-cli 21.0.0 → 21.0.2

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.
@@ -51,7 +51,6 @@ exports.DeviceRunSessionQuery = {
51
51
  }
52
52
  ... on ServeSimRunSessionRemoteConfig {
53
53
  previewUrl
54
- streamUrl
55
54
  }
56
55
  }
57
56
  turtleJobRun {
@@ -0,0 +1,14 @@
1
+ import { LoggedInAuthenticationInfo } from './SessionManager';
2
+ export declare const SUDO_MODE_REQUIRED_ERROR_CODE = "SUDO_MODE_REQUIRED";
3
+ /**
4
+ * Whether the error is the server signaling that the current session must be upgraded
5
+ * to sudo mode before performing this operation.
6
+ */
7
+ export declare function isSudoModeRequiredError(error: unknown): boolean;
8
+ /**
9
+ * Upgrade the current session to sudo mode by re-confirming the user's password
10
+ * (and OTP if two-factor authentication is enabled). Sudo mode is required for
11
+ * destructive operations like project deletion, and expires server-side after a
12
+ * few minutes.
13
+ */
14
+ export declare function promptForSudoModeUpgradeAsync(authenticationInfo: LoggedInAuthenticationInfo): Promise<void>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUDO_MODE_REQUIRED_ERROR_CODE = void 0;
4
+ exports.isSudoModeRequiredError = isSudoModeRequiredError;
5
+ exports.promptForSudoModeUpgradeAsync = promptForSudoModeUpgradeAsync;
6
+ const tslib_1 = require("tslib");
7
+ const ApiV2Error_1 = require("../ApiV2Error");
8
+ const api_1 = require("../api");
9
+ const client_1 = require("../graphql/client");
10
+ const log_1 = tslib_1.__importDefault(require("../log"));
11
+ const prompts_1 = require("../prompts");
12
+ exports.SUDO_MODE_REQUIRED_ERROR_CODE = 'SUDO_MODE_REQUIRED';
13
+ /**
14
+ * Whether the error is the server signaling that the current session must be upgraded
15
+ * to sudo mode before performing this operation.
16
+ */
17
+ function isSudoModeRequiredError(error) {
18
+ return (error instanceof client_1.GraphqlError &&
19
+ error.graphQLErrors.some(e => e?.extensions?.errorCode === exports.SUDO_MODE_REQUIRED_ERROR_CODE));
20
+ }
21
+ /**
22
+ * Upgrade the current session to sudo mode by re-confirming the user's password
23
+ * (and OTP if two-factor authentication is enabled). Sudo mode is required for
24
+ * destructive operations like project deletion, and expires server-side after a
25
+ * few minutes.
26
+ */
27
+ async function promptForSudoModeUpgradeAsync(authenticationInfo) {
28
+ if (!authenticationInfo.sessionSecret) {
29
+ throw new Error('This action requires sudo mode, which is only available for user sessions. ' +
30
+ 'Access tokens (EXPO_TOKEN) cannot be upgraded to sudo mode; log in with `eas login` instead.');
31
+ }
32
+ log_1.default.log('This action requires sudo mode. Confirm your password to continue.');
33
+ const { password } = await (0, prompts_1.promptAsync)({
34
+ type: 'password',
35
+ name: 'password',
36
+ message: 'Password:',
37
+ });
38
+ if (!password) {
39
+ throw new Error('Password is required for sudo mode.');
40
+ }
41
+ const apiV2Client = new api_1.ApiV2Client(authenticationInfo);
42
+ try {
43
+ await apiV2Client.postAsync('auth/upgradeSudo', { body: { password } });
44
+ }
45
+ catch (error) {
46
+ if (error instanceof ApiV2Error_1.ApiV2Error && error.expoApiV2ErrorCode === 'ONE_TIME_PASSWORD_REQUIRED') {
47
+ log_1.default.log('One-time password from authenticator required.');
48
+ const { otp } = await (0, prompts_1.promptAsync)({
49
+ type: 'text',
50
+ name: 'otp',
51
+ message: 'One-time password or backup code:',
52
+ });
53
+ if (!otp) {
54
+ throw new Error('Cancelled sudo mode upgrade.');
55
+ }
56
+ await apiV2Client.postAsync('auth/upgradeSudo', { body: { password, otp } });
57
+ }
58
+ else {
59
+ throw error;
60
+ }
61
+ }
62
+ }
@@ -23,7 +23,12 @@ async function maybeWarnAboutUsageOveragesAsync({ graphqlClient, accountId, }) {
23
23
  if (!planMetric || !subscription) {
24
24
  return;
25
25
  }
26
- const overageCount = buildMetrics.overageMetrics.reduce((sum, o) => sum + o.value, 0);
26
+ // Count only genuine per-worker build overage rows. `overageMetrics` can also
27
+ // contain rows without build metadata (e.g. rollups), which must not be summed
28
+ // in — otherwise the displayed "N builds beyond your credits" count is inflated.
29
+ const overageCount = buildMetrics.overageMetrics
30
+ .filter(o => o.metadata?.billingResourceClass && o.metadata?.platform)
31
+ .reduce((sum, o) => sum + o.value, 0);
27
32
  const overageCostCents = buildMetrics.totalCost;
28
33
  const hasFreePlan = subscription.name === 'Free';
29
34
  const tier = classifyUsageTier({
@@ -5,19 +5,29 @@ import { selectPaginatedAsync } from '../utils/relay';
5
5
  export declare function getSignedDeploymentUrlAsync(graphqlClient: ExpoGraphqlClient, options: {
6
6
  appId: string;
7
7
  deploymentIdentifier?: string | null;
8
+ /** Custom dev domain name (preview URL subdomain) requested through the `--dev-domain` flag */
9
+ devDomainName?: string;
8
10
  /** Callback which is invoked when the project is going to setup the dev domain */
9
11
  onSetupDevDomain?: () => any;
10
12
  /** If the terminal is running in non interactive mode or not */
11
13
  nonInteractive?: boolean;
12
14
  }): Promise<string>;
15
+ /**
16
+ * Assert that a user-provided dev domain name (preview URL subdomain) is valid.
17
+ * Unlike the interactive prompt, which reformats invalid input while typing,
18
+ * this throws an error when the name contains invalid characters.
19
+ */
20
+ export declare function assertValidDevDomainName(name: string): void;
13
21
  /**
14
22
  * Assign a dev domain name to a project.
23
+ * - When a dev domain name is provided, it will assign that name without prompting.
15
24
  * - When running in interactive mode, it will prompt the user with a suggested domain name.
16
25
  * - When running in non interactive mode, it will auto-assign the suggested domain name.
17
26
  */
18
- export declare function assignDevDomainNameAsync({ graphqlClient, appId, nonInteractive, }: {
27
+ export declare function assignDevDomainNameAsync({ graphqlClient, appId, devDomainName: requestedDevDomainName, nonInteractive, }: {
19
28
  graphqlClient: ExpoGraphqlClient;
20
29
  appId: string;
30
+ devDomainName?: string;
21
31
  nonInteractive?: boolean;
22
32
  }): ReturnType<typeof DeploymentsMutation.assignDevDomainNameAsync>;
23
33
  export declare function assignWorkerDeploymentAliasAsync({ graphqlClient, appId, deploymentId, aliasName, }: {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSignedDeploymentUrlAsync = getSignedDeploymentUrlAsync;
4
+ exports.assertValidDevDomainName = assertValidDevDomainName;
4
5
  exports.assignDevDomainNameAsync = assignDevDomainNameAsync;
5
6
  exports.assignWorkerDeploymentAliasAsync = assignWorkerDeploymentAliasAsync;
6
7
  exports.assignWorkerDeploymentProductionAsync = assignWorkerDeploymentProductionAsync;
@@ -18,8 +19,18 @@ const prompts_1 = require("../prompts");
18
19
  const memoize_1 = require("../utils/expodash/memoize");
19
20
  const relay_1 = require("../utils/relay");
20
21
  async function getSignedDeploymentUrlAsync(graphqlClient, options) {
22
+ let currentDevDomainName = null;
23
+ if (options.devDomainName) {
24
+ currentDevDomainName = await queries_1.DeploymentsQuery.getDevDomainNameByAppIdAsync(graphqlClient, {
25
+ appId: options.appId,
26
+ });
27
+ if (currentDevDomainName && currentDevDomainName !== options.devDomainName) {
28
+ throw new Error(`The project's preview URL is already set to "${currentDevDomainName}.${logs_1.EXPO_BASE_DOMAIN}.app" and cannot be changed to "${options.devDomainName}.${logs_1.EXPO_BASE_DOMAIN}.app" through "eas deploy".\nRemove the --dev-domain flag to deploy to the existing preview URL.`);
29
+ }
30
+ }
31
+ let signedUrl;
21
32
  try {
22
- return await mutations_1.DeploymentsMutation.createSignedDeploymentUrlAsync(graphqlClient, {
33
+ signedUrl = await mutations_1.DeploymentsMutation.createSignedDeploymentUrlAsync(graphqlClient, {
23
34
  appId: options.appId,
24
35
  deploymentIdentifier: options.deploymentIdentifier,
25
36
  });
@@ -36,11 +47,23 @@ async function getSignedDeploymentUrlAsync(graphqlClient, options) {
36
47
  await assignDevDomainNameAsync({
37
48
  graphqlClient,
38
49
  appId: options.appId,
50
+ devDomainName: options.devDomainName,
39
51
  nonInteractive: options.nonInteractive,
40
52
  });
41
- // Retry creating the signed URL
42
- return await getSignedDeploymentUrlAsync(graphqlClient, options);
53
+ // Retry creating the signed URL. The dev domain name was just assigned, so drop it from
54
+ // the retry to skip the pre-checks (and their extra query) — it is known to be set now.
55
+ return await getSignedDeploymentUrlAsync(graphqlClient, {
56
+ ...options,
57
+ devDomainName: undefined,
58
+ });
59
+ }
60
+ // The --dev-domain flag is applied when the server requires a preview URL to be assigned
61
+ // before the first deployment. If the deployment was accepted without that assignment,
62
+ // fail instead of silently deploying without the requested preview URL.
63
+ if (options.devDomainName && !currentDevDomainName) {
64
+ throw new Error(`The --dev-domain flag was provided, but the project's preview URL was not assigned as part of this deployment.\nRemove the --dev-domain flag and set the preview URL from the project's hosting settings on the website instead.`);
43
65
  }
66
+ return signedUrl;
44
67
  }
45
68
  const DEV_DOMAIN_INVALID_START_END_CHARACTERS = /^[^a-z0-9]+|[^a-z0-9-]+$/;
46
69
  const DEV_DOMAIN_INVALID_REPLACEMENT_HYPHEN = /[^a-z0-9-]+/;
@@ -58,6 +81,36 @@ function formatDevDomainName(name = '') {
58
81
  .replace(DEV_DOMAIN_INVALID_MULTIPLE_HYPHENS, '-')
59
82
  .trim();
60
83
  }
84
+ /**
85
+ * Validate a dev domain name (preview URL subdomain), matching the rules of the interactive prompt.
86
+ * Returns `true` when valid, or an error message describing why the name is invalid.
87
+ */
88
+ function validateDevDomainName(value) {
89
+ if (!value) {
90
+ return 'You have to choose a preview URL for your project';
91
+ }
92
+ if (value.length < 3) {
93
+ return 'Preview URLs must be at least 3 characters long';
94
+ }
95
+ if (value.endsWith('-')) {
96
+ return 'Preview URLs cannot end with a hyphen (-)';
97
+ }
98
+ return true;
99
+ }
100
+ /**
101
+ * Assert that a user-provided dev domain name (preview URL subdomain) is valid.
102
+ * Unlike the interactive prompt, which reformats invalid input while typing,
103
+ * this throws an error when the name contains invalid characters.
104
+ */
105
+ function assertValidDevDomainName(name) {
106
+ const validationResult = validateDevDomainName(name);
107
+ if (validationResult !== true) {
108
+ throw new Error(validationResult);
109
+ }
110
+ if (formatDevDomainName(name) !== name) {
111
+ throw new Error(`Preview URLs can only contain lowercase letters, numbers, and non-consecutive hyphens (-), and cannot start or end with a hyphen: "${name}"`);
112
+ }
113
+ }
61
114
  async function promptDevDomainNameAsync(initialDevDomain) {
62
115
  const rootDomain = `.${logs_1.EXPO_BASE_DOMAIN}.app`;
63
116
  const memoizedFormatDevDomainName = (0, memoize_1.memoize)(formatDevDomainName);
@@ -66,18 +119,7 @@ async function promptDevDomainNameAsync(initialDevDomain) {
66
119
  name: 'name',
67
120
  message: 'Choose a preview URL for your project:',
68
121
  initial: initialDevDomain,
69
- validate: (value) => {
70
- if (!value) {
71
- return 'You have to choose a preview URL for your project';
72
- }
73
- if (value.length < 3) {
74
- return 'Preview URLs must be at least 3 characters long';
75
- }
76
- if (value.endsWith('-')) {
77
- return 'Preview URLs cannot end with a hyphen (-)';
78
- }
79
- return true;
80
- },
122
+ validate: validateDevDomainName,
81
123
  onState(state) {
82
124
  const value = memoizedFormatDevDomainName(state.value);
83
125
  if (value !== state.value) {
@@ -106,14 +148,16 @@ async function promptDevDomainNameAsync(initialDevDomain) {
106
148
  }
107
149
  /**
108
150
  * Assign a dev domain name to a project.
151
+ * - When a dev domain name is provided, it will assign that name without prompting.
109
152
  * - When running in interactive mode, it will prompt the user with a suggested domain name.
110
153
  * - When running in non interactive mode, it will auto-assign the suggested domain name.
111
154
  */
112
- async function assignDevDomainNameAsync({ graphqlClient, appId, nonInteractive, }) {
113
- let devDomainName = await queries_1.DeploymentsQuery.getSuggestedDevDomainByAppIdAsync(graphqlClient, {
114
- appId,
115
- });
116
- if (!nonInteractive) {
155
+ async function assignDevDomainNameAsync({ graphqlClient, appId, devDomainName: requestedDevDomainName, nonInteractive, }) {
156
+ let devDomainName = requestedDevDomainName ??
157
+ (await queries_1.DeploymentsQuery.getSuggestedDevDomainByAppIdAsync(graphqlClient, {
158
+ appId,
159
+ }));
160
+ if (!requestedDevDomainName && !nonInteractive) {
117
161
  devDomainName = await promptDevDomainNameAsync(devDomainName);
118
162
  }
119
163
  try {
@@ -128,9 +172,14 @@ async function assignDevDomainNameAsync({ graphqlClient, appId, nonInteractive,
128
172
  if (!isChosenNameTaken) {
129
173
  throw error;
130
174
  }
131
- if (!nonInteractive) {
132
- log_1.default.error(`The preview URL "${devDomainName}" is already taken, choose a different URL.`);
175
+ if (nonInteractive) {
176
+ throw new Error(requestedDevDomainName
177
+ ? `The preview URL "${requestedDevDomainName}" is already taken, choose a different URL with the --dev-domain flag.`
178
+ : `The suggested preview URL "${devDomainName}" is already taken, choose a different URL with the --dev-domain flag.`);
133
179
  }
180
+ // In interactive mode, fall back to the prompt so a taken name (requested or suggested)
181
+ // does not abort the deployment.
182
+ log_1.default.error(`The preview URL "${devDomainName}" is already taken, choose a different URL.`);
134
183
  return await assignDevDomainNameAsync({ graphqlClient, appId, nonInteractive });
135
184
  }
136
185
  }
@@ -1,9 +1,10 @@
1
1
  import type { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
2
- import { type PaginatedWorkerDeploymentsQueryVariables, SuggestedDevDomainNameQueryVariables, type WorkerDeploymentAliasFragment, type WorkerDeploymentFragment } from '../graphql/generated';
2
+ import { DevDomainNameByAppIdQueryVariables, type PaginatedWorkerDeploymentsQueryVariables, SuggestedDevDomainNameQueryVariables, type WorkerDeploymentAliasFragment, type WorkerDeploymentFragment } from '../graphql/generated';
3
3
  import type { Connection } from '../utils/relay';
4
4
  export declare const DeploymentsQuery: {
5
5
  getAllDeploymentsPaginatedAsync(graphqlClient: ExpoGraphqlClient, { appId, first, after, last, before }: PaginatedWorkerDeploymentsQueryVariables): Promise<Connection<WorkerDeploymentFragment>>;
6
6
  getSuggestedDevDomainByAppIdAsync(graphqlClient: ExpoGraphqlClient, { appId }: SuggestedDevDomainNameQueryVariables): Promise<string>;
7
+ getDevDomainNameByAppIdAsync(graphqlClient: ExpoGraphqlClient, { appId }: DevDomainNameByAppIdQueryVariables): Promise<string | null>;
7
8
  getAllAliasesPaginatedAsync(graphqlClient: ExpoGraphqlClient, { appId, first, after, last, before, }: {
8
9
  appId: string;
9
10
  first?: number;
@@ -59,6 +59,24 @@ exports.DeploymentsQuery = {
59
59
  .toPromise());
60
60
  return data.app.byId.suggestedDevDomainName;
61
61
  },
62
+ async getDevDomainNameByAppIdAsync(graphqlClient, { appId }) {
63
+ const data = await (0, client_1.withErrorHandlingAsync)(graphqlClient
64
+ .query((0, graphql_tag_1.default) `
65
+ query DevDomainNameByAppId($appId: String!) {
66
+ app {
67
+ byId(appId: $appId) {
68
+ id
69
+ devDomainName {
70
+ id
71
+ name
72
+ }
73
+ }
74
+ }
75
+ }
76
+ `, { appId }, { additionalTypenames: ['AppDevDomainName'] })
77
+ .toPromise());
78
+ return data.app.byId.devDomainName?.name ?? null;
79
+ },
62
80
  async getAllAliasesPaginatedAsync(graphqlClient, { appId, first, after, last, before, }) {
63
81
  const data = await (0, client_1.withErrorHandlingAsync)(graphqlClient
64
82
  .query((0, graphql_tag_1.default) `