eas-cli 24.10.0 → 24.12.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.
@@ -1,5 +1,5 @@
1
1
  import { Actor } from '../user/User';
2
- export type AnalyticsEvent = CommandEvent | BuildEvent | SubmissionEvent | MetadataEvent | BillingEvent;
2
+ export type AnalyticsEvent = CommandEvent | BuildEvent | SubmissionEvent | MetadataEvent | BillingEvent | SimulatorEvent;
3
3
  export declare enum CommandEvent {
4
4
  ACTION = "action"
5
5
  }
@@ -48,6 +48,11 @@ export declare enum BuildEvent {
48
48
  CREDENTIALS_SYNC_UPDATE_REMOTE_FAIL = "build cli credentials sync update remote fail",
49
49
  ANDROID_KEYSTORE_CREATE = "build cli credentials keystore create"
50
50
  }
51
+ export declare enum SimulatorEvent {
52
+ REQUEST_SENT = "sim session request sent",
53
+ REQUEST_CANCELLED = "sim session request cancelled",
54
+ REQUEST_FAILED = "sim session request failed"
55
+ }
51
56
  export declare enum MetadataEvent {
52
57
  APPLE_METADATA_DOWNLOAD = "metadata cli download apple response",
53
58
  APPLE_METADATA_UPLOAD = "metadata cli upload apple response"
@@ -76,6 +81,10 @@ export declare function setAnalyticsEnabledAsync(enabled: boolean): Promise<void
76
81
  * Returns the user's analytics enabled preference.
77
82
  */
78
83
  export declare function getAnalyticsEnabledAsync(): Promise<boolean>;
84
+ /**
85
+ * Returns true when the user opted out of analytics with DISABLE_EAS_ANALYTICS or `eas analytics off`.
86
+ */
87
+ export declare function isAnalyticsOptedOutAsync(): Promise<boolean>;
79
88
  /**
80
89
  * Create an instance of Analytics based on the user's analytics enabled preferences.
81
90
  */
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MetadataEvent = exports.BuildEvent = exports.SubmissionEvent = exports.BillingEvent = exports.CommandEvent = void 0;
3
+ exports.MetadataEvent = exports.SimulatorEvent = exports.BuildEvent = exports.SubmissionEvent = exports.BillingEvent = exports.CommandEvent = void 0;
4
4
  exports.setAnalyticsEnabledAsync = setAnalyticsEnabledAsync;
5
5
  exports.getAnalyticsEnabledAsync = getAnalyticsEnabledAsync;
6
+ exports.isAnalyticsOptedOutAsync = isAnalyticsOptedOutAsync;
6
7
  exports.createAnalyticsAsync = createAnalyticsAsync;
7
8
  const tslib_1 = require("tslib");
8
9
  const rudder_sdk_node_1 = tslib_1.__importDefault(require("@expo/rudder-sdk-node"));
@@ -71,6 +72,12 @@ var BuildEvent;
71
72
  BuildEvent["CREDENTIALS_SYNC_UPDATE_REMOTE_FAIL"] = "build cli credentials sync update remote fail";
72
73
  BuildEvent["ANDROID_KEYSTORE_CREATE"] = "build cli credentials keystore create";
73
74
  })(BuildEvent || (exports.BuildEvent = BuildEvent = {}));
75
+ var SimulatorEvent;
76
+ (function (SimulatorEvent) {
77
+ SimulatorEvent["REQUEST_SENT"] = "sim session request sent";
78
+ SimulatorEvent["REQUEST_CANCELLED"] = "sim session request cancelled";
79
+ SimulatorEvent["REQUEST_FAILED"] = "sim session request failed";
80
+ })(SimulatorEvent || (exports.SimulatorEvent = SimulatorEvent = {}));
74
81
  var MetadataEvent;
75
82
  (function (MetadataEvent) {
76
83
  MetadataEvent["APPLE_METADATA_DOWNLOAD"] = "metadata cli download apple response";
@@ -94,6 +101,15 @@ async function getAnalyticsEnabledAsync() {
94
101
  const analyticsEnabled = await UserSettings_1.default.getAsync(USER_SETTINGS_KEY_ANALYTICS_ENABLED, null);
95
102
  return !!analyticsEnabled;
96
103
  }
104
+ /**
105
+ * Returns true when the user opted out of analytics with DISABLE_EAS_ANALYTICS or `eas analytics off`.
106
+ */
107
+ async function isAnalyticsOptedOutAsync() {
108
+ if (process.env.DISABLE_EAS_ANALYTICS) {
109
+ return true;
110
+ }
111
+ return (await UserSettings_1.default.getAsync(USER_SETTINGS_KEY_ANALYTICS_ENABLED, true)) === false;
112
+ }
97
113
  /**
98
114
  * Create an instance of Analytics based on the user's analytics enabled preferences.
99
115
  */
@@ -1,5 +1,5 @@
1
1
  import ContextField, { ContextOptions } from './ContextField';
2
- import { Analytics } from '../../analytics/AnalyticsManager';
3
- export default class AnalyticsContextField extends ContextField<Analytics> {
4
- getValueAsync({ analytics }: ContextOptions): Promise<Analytics>;
2
+ import { AnalyticsWithOrchestration } from '../../analytics/AnalyticsManager';
3
+ export default class AnalyticsContextField extends ContextField<AnalyticsWithOrchestration> {
4
+ getValueAsync({ analytics }: ContextOptions): Promise<AnalyticsWithOrchestration>;
5
5
  }
@@ -1,9 +1,9 @@
1
- import { Analytics } from '../../analytics/AnalyticsManager';
1
+ import { AnalyticsWithOrchestration } from '../../analytics/AnalyticsManager';
2
2
  import SessionManager from '../../user/SessionManager';
3
3
  import { Client } from '../../vcs/vcs';
4
4
  export interface ContextOptions {
5
5
  sessionManager: SessionManager;
6
- analytics: Analytics;
6
+ analytics: AnalyticsWithOrchestration;
7
7
  nonInteractive: boolean;
8
8
  vcsClientOverride?: Client;
9
9
  /** Short-circuits project ID resolution. */
@@ -2,13 +2,19 @@ import EasCommand from '../../commandUtils/EasCommand';
2
2
  export default class AccountLogin extends EasCommand {
3
3
  static description: string;
4
4
  static aliases: string[];
5
+ static examples: string[];
5
6
  static flags: {
7
+ resume: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ match: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
6
9
  sso: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
10
  browser: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
+ device: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
13
  };
9
14
  static contextDefinition: {
10
15
  sessionManager: import("../../commandUtils/context/SessionManagementContextField").default;
11
16
  maybeLoggedIn: import("../../commandUtils/context/MaybeLoggedInContextField").default;
12
17
  };
13
18
  runAsync(): Promise<void>;
19
+ private runDeviceLoginAsync;
14
20
  }
@@ -4,13 +4,33 @@ const tslib_1 = require("tslib");
4
4
  const core_1 = require("@oclif/core");
5
5
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
6
  const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand"));
7
+ const flags_1 = require("../../commandUtils/flags");
7
8
  const log_1 = tslib_1.__importDefault(require("../../log"));
8
9
  const prompts_1 = require("../../prompts");
9
10
  const User_1 = require("../../user/User");
11
+ const deviceLogin_1 = require("../../user/deviceLogin");
10
12
  class AccountLogin extends EasCommand_1.default {
11
13
  static description = 'log in with your Expo account';
12
14
  static aliases = ['login'];
15
+ static examples = [
16
+ '<%= config.bin %> login --device',
17
+ '<%= config.bin %> login --device --non-interactive',
18
+ '<%= config.bin %> login --device --non-interactive --resume REQUEST_ID --match NUMBER_FROM_USER',
19
+ ];
13
20
  static flags = {
21
+ device: core_1.Flags.boolean({
22
+ description: 'Log in using a code in a browser on any device',
23
+ exclusive: ['sso'],
24
+ }),
25
+ ...flags_1.EASNonInteractiveFlag,
26
+ resume: core_1.Flags.string({
27
+ description: 'Resume a saved device login using its request ID (one command at a time)',
28
+ dependsOn: ['device'],
29
+ }),
30
+ match: core_1.Flags.string({
31
+ description: 'Submit the number the user sees in their browser',
32
+ dependsOn: ['device', 'resume'],
33
+ }),
14
34
  // can pass either --sso or -s
15
35
  sso: core_1.Flags.boolean({
16
36
  description: 'Log in with SSO',
@@ -29,22 +49,84 @@ class AccountLogin extends EasCommand_1.default {
29
49
  ...this.ContextOptions.SessionManagment,
30
50
  };
31
51
  async runAsync() {
32
- const { flags: { sso, browser }, } = await this.parse(AccountLogin);
33
- const { sessionManager, maybeLoggedIn: { actor }, } = await this.getContextAsync(AccountLogin, { nonInteractive: false });
52
+ const { flags: { sso, browser, device, 'non-interactive': nonInteractive, resume, match }, } = await this.parse(AccountLogin);
53
+ if (nonInteractive && !device) {
54
+ throw new Error('Use eas login --device --non-interactive to log in without prompts.');
55
+ }
56
+ const { sessionManager, maybeLoggedIn: { actor }, } = await this.getContextAsync(AccountLogin, { nonInteractive });
34
57
  if (sessionManager.getAccessToken()) {
35
- throw new Error('EXPO_TOKEN is set in your environment, and is being used for all EAS authentication. To use username/password authentication, unset EXPO_TOKEN in your environment and re-run the command.');
58
+ throw new Error('EXPO_TOKEN is set in your environment, and is being used for all EAS authentication. Unset EXPO_TOKEN to log in with an Expo account.');
36
59
  }
37
- if (actor) {
60
+ if (actor && !resume) {
38
61
  log_1.default.warn(`You are already logged in as ${chalk_1.default.bold((0, User_1.getActorDisplayName)(actor))}.`);
39
- const shouldContinue = await (0, prompts_1.confirmAsync)({
40
- message: 'Do you want to continue?',
41
- });
62
+ const shouldContinue = nonInteractive ||
63
+ (await (0, prompts_1.confirmAsync)({
64
+ message: 'Do you want to continue?',
65
+ }));
42
66
  if (!shouldContinue) {
43
67
  core_1.Errors.error('Aborted', { exit: 1 });
44
68
  }
45
69
  }
70
+ if (device) {
71
+ await this.runDeviceLoginAsync(sessionManager, { nonInteractive, resume, match });
72
+ return;
73
+ }
46
74
  await sessionManager.showLoginPromptAsync({ sso, browser });
47
75
  log_1.default.log('Logged in');
48
76
  }
77
+ async runDeviceLoginAsync(sessionManager, options) {
78
+ let result = options.resume
79
+ ? await (0, deviceLogin_1.resumeDeviceLoginAsync)(options.resume, sessionManager, options.match)
80
+ : await (0, deviceLogin_1.startDeviceLoginAsync)();
81
+ if (options.nonInteractive) {
82
+ if ((0, deviceLogin_1.isDeviceLoginFailure)(result)) {
83
+ throw new Error(`Device login failed (${result.status}). Start again with eas login --device.`);
84
+ }
85
+ if (result.status === 'authenticated') {
86
+ log_1.default.log(`Logged in as ${result.username}`);
87
+ return;
88
+ }
89
+ const resumeCommand = `eas login --device --non-interactive --resume ${result.request_id}`;
90
+ if (!options.resume) {
91
+ log_1.default.log(`Open ${result.verification_uri_complete}`);
92
+ log_1.default.log(`Code: ${result.user_code}`);
93
+ log_1.default.log('Ask the user to approve the login in their browser and send you any number shown.');
94
+ log_1.default.log(`Then run ${resumeCommand}, adding --match NUMBER_FROM_USER if they saw a number.`);
95
+ }
96
+ else if (result.status === 'matching_required') {
97
+ log_1.default.log('Ask the user for the number shown in their browser, then run:');
98
+ log_1.default.log(`${resumeCommand} --match NUMBER_FROM_USER`);
99
+ }
100
+ else {
101
+ log_1.default.log(`Approval pending. Retry after ${result.retry_after} seconds:`);
102
+ log_1.default.log(`${resumeCommand}${options.match ? ` --match ${options.match}` : ''}`);
103
+ }
104
+ return;
105
+ }
106
+ if ('verification_uri_complete' in result) {
107
+ log_1.default.log(`Open ${result.verification_uri_complete}`);
108
+ log_1.default.log(`Code: ${result.user_code}`);
109
+ log_1.default.log(`You can resume with eas login --device --resume ${result.request_id}`);
110
+ }
111
+ let match = options.match;
112
+ while (result.status !== 'authenticated') {
113
+ if ((0, deviceLogin_1.isDeviceLoginFailure)(result)) {
114
+ throw new Error(`Device login failed (${result.status}). Start again with eas login --device.`);
115
+ }
116
+ if (result.status === 'matching_required') {
117
+ const answer = await (0, prompts_1.promptAsync)({
118
+ type: 'select',
119
+ name: 'match',
120
+ message: 'Select the number shown in your browser',
121
+ choices: result.match_options.map(value => ({ title: value, value })),
122
+ });
123
+ match = answer.match;
124
+ }
125
+ const delayMs = result.retry_after * 1000;
126
+ await new Promise(resolve => setTimeout(resolve, delayMs));
127
+ result = await (0, deviceLogin_1.resumeDeviceLoginAsync)(result.request_id, sessionManager, match);
128
+ }
129
+ log_1.default.log(`Logged in as ${result.username}`);
130
+ }
49
131
  }
50
132
  exports.default = AccountLogin;
@@ -30,6 +30,7 @@ export default class Simulator extends EasCommand {
30
30
  'out-config-type': import("@oclif/core/lib/interfaces").OptionFlag<"env" | "dotenv", import("@oclif/core/lib/interfaces").CustomOptions>;
31
31
  };
32
32
  static contextDefinition: {
33
+ analytics: import("../../commandUtils/context/AnalyticsContextField").default;
33
34
  loggedIn: import("../../commandUtils/context/LoggedInContextField").default;
34
35
  projectDir: import("../../commandUtils/context/ProjectDirContextField").default;
35
36
  projectId: import("../../commandUtils/context/ProjectIdContextField").ProjectIdContextField;
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const core_1 = require("@oclif/core");
5
5
  const nullthrows_1 = tslib_1.__importDefault(require("nullthrows"));
6
+ const AnalyticsManager_1 = require("../../analytics/AnalyticsManager");
7
+ const agent_1 = require("../../analytics/agent");
6
8
  const url_1 = require("../../build/utils/url");
7
9
  const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand"));
8
10
  const errors_1 = require("../../commandUtils/errors");
@@ -18,6 +20,7 @@ const egress_1 = require("../../simulator/egress");
18
20
  const networkCapture_1 = require("../../simulator/networkCapture");
19
21
  const env_1 = require("../../simulator/env");
20
22
  const expoGo_1 = require("../../simulator/expoGo");
23
+ const requestAnalytics_1 = require("../../simulator/requestAnalytics");
21
24
  const utils_1 = require("../../simulator/utils");
22
25
  const json_1 = require("../../utils/json");
23
26
  const promise_1 = require("../../utils/promise");
@@ -133,6 +136,7 @@ class Simulator extends EasCommand_1.default {
133
136
  ...this.ContextOptions.ProjectId,
134
137
  ...this.ContextOptions.ProjectDir,
135
138
  ...this.ContextOptions.LoggedIn,
139
+ ...this.ContextOptions.Analytics,
136
140
  };
137
141
  async runAsync() {
138
142
  const { flags } = await this.parse(Simulator);
@@ -140,7 +144,7 @@ class Simulator extends EasCommand_1.default {
140
144
  if (jsonFlag) {
141
145
  (0, json_1.enableJsonOutput)();
142
146
  }
143
- const { projectId, projectDir, loggedIn: { actor, graphqlClient }, } = await this.getContextAsync(Simulator, {
147
+ const { projectId, projectDir, loggedIn: { actor, graphqlClient }, analytics, } = await this.getContextAsync(Simulator, {
144
148
  nonInteractive,
145
149
  });
146
150
  // The server would reject the session anyway, but check the gate first so gated
@@ -219,7 +223,18 @@ class Simulator extends EasCommand_1.default {
219
223
  let deviceRunSessionUrl;
220
224
  let sessionInterrupt;
221
225
  try {
222
- const session = await DeviceRunSessionMutation_1.DeviceRunSessionMutation.createDeviceRunSessionAsync(graphqlClient, {
226
+ const agentIdentity = await agentIdentityInputAsync();
227
+ const requestProperties = (0, requestAnalytics_1.simulatorRequestProperties)({
228
+ projectId,
229
+ type: flags.type,
230
+ platform,
231
+ hasBuildId: !!buildId || !!buildFingerprint,
232
+ hasArchiveUrl: !!applicationArchiveUrlFromFlag,
233
+ expoGo: !!expoGoSdkVersion,
234
+ packageVersion: flags['package-version'],
235
+ nonInteractive,
236
+ });
237
+ const session = await withSimulatorRequestAnalyticsAsync(analytics, requestProperties, createSpinner, () => DeviceRunSessionMutation_1.DeviceRunSessionMutation.createDeviceRunSessionAsync(graphqlClient, {
223
238
  appId: projectId,
224
239
  name,
225
240
  ...(tags?.length ? { tags } : {}),
@@ -243,9 +258,11 @@ class Simulator extends EasCommand_1.default {
243
258
  ...(openUrl ? { openUrl } : {}),
244
259
  ...(resourceClass ? { resourceClass } : {}),
245
260
  ...(egress ? { egress } : {}),
261
+ requestOrigin: generated_1.DeviceRunSessionRequestOrigin.EasCli,
262
+ ...agentIdentity,
246
263
  maxRunTimeMinutes: flags['max-duration-minutes'],
247
264
  maxIdleTimeMinutes: flags['max-idle-time-minutes'],
248
- });
265
+ }));
249
266
  deviceRunSessionId = session.id;
250
267
  (0, nullthrows_1.default)(session.turtleJobRun?.id, 'Expected simulator session to start');
251
268
  deviceRunSessionUrl = (0, url_1.getDeviceRunSessionUrl)(session.app.ownerAccount.name, session.app.slug, deviceRunSessionId);
@@ -551,3 +568,61 @@ async function ensureDeviceRunSessionStoppedSafelyAsync(graphqlClient, deviceRun
551
568
  return false;
552
569
  }
553
570
  }
571
+ /**
572
+ * How long Ctrl+C waits for analytics to flush. The analytics client has no request timeout, so
573
+ * without a limit a hung network would make Ctrl+C look ignored.
574
+ */
575
+ const CANCEL_FLUSH_TIMEOUT_MS = 1_000;
576
+ class SimulatorRequestCancelledError extends Error {
577
+ }
578
+ /**
579
+ * Runs the create request and logs the client-side funnel events around it: "request sent" before
580
+ * it leaves, "request cancelled" on Ctrl+C before an answer, and "request failed" when no answer
581
+ * arrives. Ctrl+C stops the spinner, flushes analytics, and exits with 130, like the session's own
582
+ * Ctrl+C handler: going through the command's error handling would print the exit as an error and
583
+ * report it to Sentry.
584
+ */
585
+ async function withSimulatorRequestAnalyticsAsync(analytics, properties, spinner, createAsync) {
586
+ let onSigint;
587
+ const cancelled = new Promise((_, reject) => {
588
+ onSigint = () => {
589
+ reject(new SimulatorRequestCancelledError());
590
+ };
591
+ });
592
+ process.once('SIGINT', onSigint);
593
+ analytics.logEvent(AnalyticsManager_1.SimulatorEvent.REQUEST_SENT, properties);
594
+ try {
595
+ return await Promise.race([createAsync(), cancelled]);
596
+ }
597
+ catch (error) {
598
+ if (error instanceof SimulatorRequestCancelledError) {
599
+ analytics.logEvent(AnalyticsManager_1.SimulatorEvent.REQUEST_CANCELLED, { ...properties, reason: 'user_abort' });
600
+ spinner.fail('Simulator session request canceled');
601
+ const flushTimeout = new AbortController();
602
+ await Promise.race([
603
+ analytics.flushAsync(),
604
+ (0, promise_1.sleepAsync)(CANCEL_FLUSH_TIMEOUT_MS, flushTimeout.signal),
605
+ ]);
606
+ flushTimeout.abort();
607
+ process.exit(130);
608
+ }
609
+ const reason = (0, requestAnalytics_1.simulatorRequestFailureReason)(error);
610
+ if (reason) {
611
+ analytics.logEvent(AnalyticsManager_1.SimulatorEvent.REQUEST_FAILED, { ...properties, reason });
612
+ }
613
+ throw error;
614
+ }
615
+ finally {
616
+ process.removeListener('SIGINT', onSigint);
617
+ }
618
+ }
619
+ async function agentIdentityInputAsync() {
620
+ if (await (0, AnalyticsManager_1.isAnalyticsOptedOutAsync)()) {
621
+ return {};
622
+ }
623
+ const agent = (0, agent_1.getAgentTelemetryContext)();
624
+ if (!agent) {
625
+ return {};
626
+ }
627
+ return { agentId: agent.id, ...(agent.sessionId ? { agentSessionId: agent.sessionId } : {}) };
628
+ }
@@ -66,12 +66,12 @@ class UpdateView extends EasCommand_1.default {
66
66
  if (jsonFlag) {
67
67
  if (insightsSummary) {
68
68
  (0, json_1.printJsonOnlyOutput)({
69
- updates: (0, utils_1.getUpdateJsonInfosForUpdates)(updatesByGroup),
69
+ updates: (0, utils_1.getUpdateWithFileUrlsJsonInfosForUpdates)(updatesByGroup),
70
70
  insights: (0, formatInsights_1.buildUpdateInsightsJson)(insightsSummary),
71
71
  });
72
72
  }
73
73
  else {
74
- (0, json_1.printJsonOnlyOutput)((0, utils_1.getUpdateJsonInfosForUpdates)(updatesByGroup));
74
+ (0, json_1.printJsonOnlyOutput)((0, utils_1.getUpdateWithFileUrlsJsonInfosForUpdates)(updatesByGroup));
75
75
  }
76
76
  }
77
77
  else {
@@ -92,7 +92,9 @@ class UpdateView extends EasCommand_1.default {
92
92
  */
93
93
  static async resolveUpdateGroupAsync(graphqlClient, id) {
94
94
  try {
95
- const updatesByGroup = await UpdateQuery_1.UpdateQuery.viewUpdateGroupAsync(graphqlClient, { groupId: id });
95
+ const updatesByGroup = await UpdateQuery_1.UpdateQuery.viewUpdateGroupWithFileUrlsAsync(graphqlClient, {
96
+ groupId: id,
97
+ });
96
98
  return { groupId: id, updatesByGroup };
97
99
  }
98
100
  catch (groupError) {
@@ -105,7 +107,7 @@ class UpdateView extends EasCommand_1.default {
105
107
  // the original group lookup error since the group ID is the primary input.
106
108
  throw groupError;
107
109
  }
108
- const updatesByGroup = await UpdateQuery_1.UpdateQuery.viewUpdateGroupAsync(graphqlClient, {
110
+ const updatesByGroup = await UpdateQuery_1.UpdateQuery.viewUpdateGroupWithFileUrlsAsync(graphqlClient, {
109
111
  groupId: update.group,
110
112
  });
111
113
  return { groupId: update.group, updatesByGroup };