eas-cli 26.0.0 → 27.2.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.
- package/README.md +293 -148
- package/build/analytics/AnalyticsManager.d.ts +2 -0
- package/build/analytics/AnalyticsManager.js +2 -0
- package/build/build/build.d.ts +1 -2
- package/build/build/build.js +9 -4
- package/build/build/errors.d.ts +2 -0
- package/build/build/errors.js +4 -1
- package/build/build/evaluateConfigWithEnvVarsAsync.js +1 -3
- package/build/build/freeTierNearLimitAgentUpdatesTip.d.ts +98 -0
- package/build/build/freeTierNearLimitAgentUpdatesTip.js +205 -0
- package/build/build/runBuildAndSubmit.d.ts +2 -0
- package/build/build/runBuildAndSubmit.js +3 -0
- package/build/build/simulatorsLaunchHint.d.ts +7 -0
- package/build/build/simulatorsLaunchHint.js +40 -0
- package/build/build/utils/expoTokenRole.d.ts +4 -0
- package/build/build/utils/expoTokenRole.js +14 -0
- package/build/commandUtils/EasCommand.js +3 -3
- package/build/commandUtils/context/contextUtils/findProjectDirAndVerifyProjectSetupAsync.js +2 -1
- package/build/commandUtils/workflow/referencedFiles.d.ts +6 -0
- package/build/commandUtils/workflow/referencedFiles.js +63 -0
- package/build/commandUtils/workflow/types.d.ts +1 -1
- package/build/commandUtils/workflow/utils.js +34 -5
- package/build/commands/account/login.js +6 -0
- package/build/commands/account/view.d.ts +0 -7
- package/build/commands/account/view.js +4 -74
- package/build/commands/build/index.js +8 -1
- package/build/commands/observe/session.js +4 -3
- package/build/commands/observe/trace.d.ts +17 -0
- package/build/commands/observe/trace.js +58 -0
- package/build/commands/observe/traces.d.ts +33 -0
- package/build/commands/observe/traces.js +159 -0
- package/build/commands/simulator/control.js +41 -6
- package/build/commands/simulator/logs.d.ts +22 -0
- package/build/commands/simulator/logs.js +188 -0
- package/build/commands/workflow/cancel.js +9 -20
- package/build/commands/workflow/run.js +9 -0
- package/build/commands/workflow/runs.js +1 -1
- package/build/graphql/generated.d.ts +698 -5
- package/build/graphql/generated.js +25 -4
- package/build/graphql/mutations/UserPreferenceMutation.d.ts +5 -0
- package/build/graphql/mutations/UserPreferenceMutation.js +24 -0
- package/build/graphql/mutations/WorkflowRevisionMutation.d.ts +3 -2
- package/build/graphql/mutations/WorkflowRevisionMutation.js +12 -3
- package/build/graphql/queries/AccountQuery.d.ts +3 -1
- package/build/graphql/queries/AccountQuery.js +54 -0
- package/build/graphql/queries/ObserveQuery.d.ts +24 -1
- package/build/graphql/queries/ObserveQuery.js +114 -1
- package/build/graphql/queries/UserPreferenceQuery.d.ts +8 -0
- package/build/graphql/queries/UserPreferenceQuery.js +28 -0
- package/build/graphql/queries/WorkflowRunQuery.js +6 -0
- package/build/graphql/types/Observe.d.ts +1 -0
- package/build/graphql/types/Observe.js +53 -1
- package/build/graphql/types/WorkflowRun.js +1 -0
- package/build/help.js +13 -6
- package/build/log.d.ts +2 -0
- package/build/log.js +10 -0
- package/build/observe/fetchSessions.d.ts +12 -1
- package/build/observe/fetchSessions.js +39 -2
- package/build/observe/fetchSpans.d.ts +27 -0
- package/build/observe/fetchSpans.js +36 -0
- package/build/observe/formatSessions.d.ts +3 -1
- package/build/observe/formatSessions.js +40 -3
- package/build/observe/formatSpans.d.ts +110 -0
- package/build/observe/formatSpans.js +250 -0
- package/build/observe/spanFilters.d.ts +5 -0
- package/build/observe/spanFilters.js +32 -0
- package/build/project/projectStatus.js +1 -0
- package/build/simulator/artifacts.d.ts +9 -0
- package/build/simulator/artifacts.js +97 -0
- package/build/simulator/download.d.ts +2 -0
- package/build/simulator/download.js +57 -0
- package/build/simulator/events.js +2 -10
- package/build/simulator/preview.d.ts +26 -0
- package/build/simulator/preview.js +156 -0
- package/build/simulator/utils.d.ts +5 -0
- package/build/simulator/utils.js +42 -0
- package/build/user/accountPermissions.d.ts +11 -0
- package/build/user/accountPermissions.js +89 -0
- package/oclif.manifest.json +920 -422
- package/package.json +6 -6
- package/build/build/freeTierLimitGuidance.d.ts +0 -19
- package/build/build/freeTierLimitGuidance.js +0 -39
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasSimulatorArtifacts = hasSimulatorArtifacts;
|
|
4
|
+
exports.downloadSimulatorArtifactAsync = downloadSimulatorArtifactAsync;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
+
const download_1 = require("./download");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const fetch_1 = tslib_1.__importDefault(require("../fetch"));
|
|
10
|
+
const generated_1 = require("../graphql/generated");
|
|
11
|
+
const log_1 = tslib_1.__importDefault(require("../log"));
|
|
12
|
+
const ora_1 = require("../ora");
|
|
13
|
+
const files_1 = require("../utils/files");
|
|
14
|
+
const prompts_1 = require("../prompts");
|
|
15
|
+
const json_1 = require("../utils/json");
|
|
16
|
+
function hasSimulatorArtifacts(session) {
|
|
17
|
+
return (session.status === generated_1.DeviceRunSessionStatus.Stopped ||
|
|
18
|
+
session.status === generated_1.DeviceRunSessionStatus.Errored);
|
|
19
|
+
}
|
|
20
|
+
async function downloadSimulatorArtifactAsync(session, type, { artifact: index, output, nonInteractive, json, }) {
|
|
21
|
+
const artifacts = session.artifacts
|
|
22
|
+
.filter(artifact => artifact.metadata?.__eas_type === type)
|
|
23
|
+
.sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt) ||
|
|
24
|
+
a.name.localeCompare(b.name) ||
|
|
25
|
+
a.id.localeCompare(b.id));
|
|
26
|
+
if (artifacts.length === 0) {
|
|
27
|
+
throw new Error('No matching artifacts are available for this session. Artifacts may still be uploading or may not have been recorded. Run `eas simulator:get` to check the session, then try again.');
|
|
28
|
+
}
|
|
29
|
+
const titles = artifacts.map((artifact, i) => {
|
|
30
|
+
const metadata = artifact.metadata;
|
|
31
|
+
const device = metadata?.deviceName ?? metadata?.udid;
|
|
32
|
+
const part = metadata?.part;
|
|
33
|
+
return (0, utils_1.stripTerminalControlCharacters)(`${i + 1}. ${artifact.name} — ${artifact.filename} (${(0, files_1.formatBytes)(artifact.fileSizeBytes ?? 0)})${device ? ` (${device})` : ''}${part !== undefined ? ` (part ${part})` : ''}`);
|
|
34
|
+
});
|
|
35
|
+
const selectionMessage = `Choose an artifact with --artifact <index>:\n${titles.join('\n')}`;
|
|
36
|
+
let selectedIndex = index;
|
|
37
|
+
if (selectedIndex !== undefined &&
|
|
38
|
+
(!Number.isInteger(selectedIndex) || selectedIndex < 1 || selectedIndex > artifacts.length)) {
|
|
39
|
+
throw new Error(`The artifact index is out of range. ${selectionMessage}`);
|
|
40
|
+
}
|
|
41
|
+
if (selectedIndex === undefined) {
|
|
42
|
+
if (artifacts.length === 1) {
|
|
43
|
+
selectedIndex = 1;
|
|
44
|
+
}
|
|
45
|
+
else if (nonInteractive) {
|
|
46
|
+
throw new Error(selectionMessage);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
selectedIndex = await (0, prompts_1.selectAsync)('Select an artifact to download:', titles.map((title, i) => ({ title, value: i + 1 })));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const artifact = artifacts[selectedIndex - 1];
|
|
53
|
+
if (!output) {
|
|
54
|
+
if (nonInteractive) {
|
|
55
|
+
throw new Error('Pass --output <path> to save the session artifact in non-interactive mode.');
|
|
56
|
+
}
|
|
57
|
+
const { filePath } = await (0, prompts_1.promptAsync)({
|
|
58
|
+
type: 'text',
|
|
59
|
+
name: 'filePath',
|
|
60
|
+
message: 'Where should the artifact be saved?',
|
|
61
|
+
initial: (0, utils_1.stripTerminalControlCharacters)(node_path_1.default.basename(artifact.filename)),
|
|
62
|
+
validate: value => value.trim().length > 0 || 'Enter an output path.',
|
|
63
|
+
});
|
|
64
|
+
output = typeof filePath === 'string' ? filePath : undefined;
|
|
65
|
+
}
|
|
66
|
+
if (!output) {
|
|
67
|
+
throw new Error('Enter an output path.');
|
|
68
|
+
}
|
|
69
|
+
const spinner = json ? undefined : (0, ora_1.ora)('Downloading session artifact').start();
|
|
70
|
+
let filePath;
|
|
71
|
+
try {
|
|
72
|
+
filePath = await (0, download_1.downloadSimulatorFileAsync)(output, async (signal) => {
|
|
73
|
+
try {
|
|
74
|
+
return await (0, fetch_1.default)(artifact.downloadUrl, { signal, timeout: 30_000 });
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throw new Error('Could not download the session artifact. Check your internet connection and try again.');
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
spinner?.succeed();
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
spinner?.fail();
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
if (json) {
|
|
87
|
+
const { id, name, filename, metadata } = artifact;
|
|
88
|
+
(0, json_1.printJsonOnlyOutput)({
|
|
89
|
+
deviceRunSessionId: session.id,
|
|
90
|
+
artifact: { id, name, filename, metadata },
|
|
91
|
+
filePath,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
log_1.default.log(`Saved ${(0, utils_1.stripTerminalControlCharacters)(artifact.name)} to ${(0, utils_1.stripTerminalControlCharacters)(filePath)}.`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.downloadSimulatorFileAsync = downloadSimulatorFileAsync;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
6
|
+
const promises_1 = require("node:fs/promises");
|
|
7
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
8
|
+
const promises_2 = require("node:stream/promises");
|
|
9
|
+
const DOWNLOAD_TIMEOUT_MS = 10 * 60_000;
|
|
10
|
+
async function downloadSimulatorFileAsync(output, getResponse) {
|
|
11
|
+
const outputPath = node_path_1.default.resolve(output);
|
|
12
|
+
if (await fs_extra_1.default.pathExists(outputPath)) {
|
|
13
|
+
throw new Error('The output file already exists. The command does not overwrite files. Choose another --output path.');
|
|
14
|
+
}
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
const signal = AbortSignal.any([controller.signal, AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS)]);
|
|
17
|
+
const interruptHandler = () => {
|
|
18
|
+
controller.abort();
|
|
19
|
+
};
|
|
20
|
+
let response;
|
|
21
|
+
let created = false;
|
|
22
|
+
process.on('SIGINT', interruptHandler);
|
|
23
|
+
try {
|
|
24
|
+
response = await getResponse(signal);
|
|
25
|
+
const file = await (0, promises_1.open)(outputPath, 'wx', 0o600);
|
|
26
|
+
created = true;
|
|
27
|
+
try {
|
|
28
|
+
await (0, promises_2.pipeline)(response.body, file.createWriteStream(), { signal });
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
await file.close();
|
|
32
|
+
}
|
|
33
|
+
return outputPath;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (created) {
|
|
37
|
+
await fs_extra_1.default.remove(outputPath);
|
|
38
|
+
}
|
|
39
|
+
if (error.code === 'EEXIST') {
|
|
40
|
+
throw new Error('The output file already exists. The command does not overwrite files. Choose another --output path.');
|
|
41
|
+
}
|
|
42
|
+
if (controller.signal.aborted) {
|
|
43
|
+
throw new Error('The download was canceled.');
|
|
44
|
+
}
|
|
45
|
+
if (signal.aborted) {
|
|
46
|
+
throw new Error('The download timed out. It did not finish within 10 minutes. Check your internet connection, then run the command again.');
|
|
47
|
+
}
|
|
48
|
+
if (!response) {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
throw new Error('Could not save the download. Check that the --output directory exists and is writable, then try again.');
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
controller.abort();
|
|
55
|
+
process.removeListener('SIGINT', interruptHandler);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -4,8 +4,8 @@ exports.downloadDeviceRunSessionEventsAsync = downloadDeviceRunSessionEventsAsyn
|
|
|
4
4
|
exports.projectDeviceRunSessionEventsForDisplay = projectDeviceRunSessionEventsForDisplay;
|
|
5
5
|
exports.formatDeviceRunSessionEvent = formatDeviceRunSessionEvent;
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
|
-
const util_1 = require("util");
|
|
8
7
|
const eas_build_job_1 = require("@expo/eas-build-job");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
9
|
const fetch_1 = tslib_1.__importStar(require("../fetch"));
|
|
10
10
|
const timer_1 = require("../utils/timer");
|
|
11
11
|
async function downloadDeviceRunSessionEventsAsync(eventLogUrl) {
|
|
@@ -71,7 +71,7 @@ function formatDeviceRunSessionEvent(event) {
|
|
|
71
71
|
? `${event.summary} ${screenshotFilename}`
|
|
72
72
|
: event.summary;
|
|
73
73
|
const duration = event.durationMs === undefined ? '' : ` (${formatEventDuration(event.durationMs)})`;
|
|
74
|
-
return stripTerminalControlCharacters(`${event.ts} [${event.producer}] ${summary}${duration}`);
|
|
74
|
+
return (0, utils_1.stripTerminalControlCharacters)(`${event.ts} [${event.producer}] ${summary}${duration}`);
|
|
75
75
|
}
|
|
76
76
|
function getOperationKey(event) {
|
|
77
77
|
return JSON.stringify([event.producer, event.operationId]);
|
|
@@ -85,11 +85,3 @@ function getScreenshotFilename(event) {
|
|
|
85
85
|
}
|
|
86
86
|
return event.data.path.split(/[\\/]/).at(-1);
|
|
87
87
|
}
|
|
88
|
-
function stripTerminalControlCharacters(value) {
|
|
89
|
-
return [...(0, util_1.stripVTControlCharacters)(value)]
|
|
90
|
-
.filter(character => {
|
|
91
|
-
const codePoint = character.codePointAt(0) ?? 0;
|
|
92
|
-
return codePoint >= 0x20 && !(codePoint >= 0x7f && codePoint <= 0x9f);
|
|
93
|
-
})
|
|
94
|
-
.join('');
|
|
95
|
-
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type SimulatorSession } from './artifacts';
|
|
2
|
+
import { type Response } from '../fetch';
|
|
3
|
+
export type SimulatorPreview = {
|
|
4
|
+
deviceRunSessionId: string;
|
|
5
|
+
baseUrl: URL;
|
|
6
|
+
token: string;
|
|
7
|
+
};
|
|
8
|
+
type SimulatorPreviewRequestOptions = {
|
|
9
|
+
query?: Record<string, string>;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
/** Message for a 404 response. Defaults to a generic message for unsupported preview data. */
|
|
12
|
+
notFoundMessage?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function resolveSimulatorPreviewAsync(session: SimulatorSession): Promise<SimulatorPreview>;
|
|
15
|
+
export declare function fetchSimulatorPreviewAsync(preview: SimulatorPreview, route: string, { query, signal, notFoundMessage, accept, }?: SimulatorPreviewRequestOptions & {
|
|
16
|
+
accept?: string;
|
|
17
|
+
}): Promise<Response>;
|
|
18
|
+
export declare function fetchSimulatorPreviewJsonAsync<T>(preview: SimulatorPreview, route: string, options?: Omit<SimulatorPreviewRequestOptions, 'signal'>): Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Calls `onData` with each server-sent event's data until `signal` aborts. The stream ending is an error.
|
|
21
|
+
* Errors thrown by `onData` stop the stream and are rethrown unchanged.
|
|
22
|
+
*/
|
|
23
|
+
export declare function streamSimulatorPreviewAsync(preview: SimulatorPreview, route: string, onData: (data: string) => void, { signal, ...options }: SimulatorPreviewRequestOptions & {
|
|
24
|
+
signal: AbortSignal;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveSimulatorPreviewAsync = resolveSimulatorPreviewAsync;
|
|
4
|
+
exports.fetchSimulatorPreviewAsync = fetchSimulatorPreviewAsync;
|
|
5
|
+
exports.fetchSimulatorPreviewJsonAsync = fetchSimulatorPreviewJsonAsync;
|
|
6
|
+
exports.streamSimulatorPreviewAsync = streamSimulatorPreviewAsync;
|
|
7
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
const node_readline_1 = tslib_1.__importDefault(require("node:readline"));
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const fetch_1 = tslib_1.__importStar(require("../fetch"));
|
|
11
|
+
const generated_1 = require("../graphql/generated");
|
|
12
|
+
const PREVIEW_API_TIMEOUT_MS = 30_000;
|
|
13
|
+
// The preview server sends a heartbeat every 15 seconds, so a longer silence means the stream is gone.
|
|
14
|
+
const PREVIEW_STREAM_IDLE_TIMEOUT_MS = 60_000;
|
|
15
|
+
const INVALID_PREVIEW_API_URL_MESSAGE = 'The simulator session has an invalid preview API URL. The session reported a URL that is not a valid HTTP(S) URL. Start a new session with `eas simulator:start`.';
|
|
16
|
+
const PREVIEW_STREAM_ENDED_MESSAGE = "The simulator preview stream ended unexpectedly. The connection to the session's preview server closed. Run `eas simulator:get` to check that the session is still running, then run the command again.";
|
|
17
|
+
const PREVIEW_DATA_NOT_FOUND_MESSAGE = "The requested preview data was not found. The session's preview server does not support this request. Start a new session with `eas simulator:start`, then try again.";
|
|
18
|
+
async function resolveSimulatorPreviewAsync(session) {
|
|
19
|
+
if (session.status !== generated_1.DeviceRunSessionStatus.InProgress) {
|
|
20
|
+
throw new Error('The simulator session is not running. Live preview data is only available while a session runs. Start a new session with `eas simulator:start`.');
|
|
21
|
+
}
|
|
22
|
+
const access = session.remoteConfig ? (0, utils_1.getPreviewApiAccess)(session.remoteConfig) : null;
|
|
23
|
+
if (!access) {
|
|
24
|
+
throw new Error('This simulator session does not expose a preview API. The command reads live data through the preview API, and the session did not report its URL and token. Start a new iOS session with `eas simulator:start --platform ios`.');
|
|
25
|
+
}
|
|
26
|
+
let baseUrl;
|
|
27
|
+
try {
|
|
28
|
+
baseUrl = new URL(access.apiUrl);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
throw new Error(INVALID_PREVIEW_API_URL_MESSAGE);
|
|
32
|
+
}
|
|
33
|
+
if (!['https:', 'http:'].includes(baseUrl.protocol)) {
|
|
34
|
+
throw new Error(INVALID_PREVIEW_API_URL_MESSAGE);
|
|
35
|
+
}
|
|
36
|
+
// Requests send the token in a header, so keep it out of URLs that can appear in errors.
|
|
37
|
+
baseUrl.searchParams.delete('token');
|
|
38
|
+
baseUrl.hash = '';
|
|
39
|
+
return { deviceRunSessionId: session.id, baseUrl, token: access.token };
|
|
40
|
+
}
|
|
41
|
+
async function fetchSimulatorPreviewAsync(preview, route, { query, signal, notFoundMessage = PREVIEW_DATA_NOT_FOUND_MESSAGE, accept, } = {}) {
|
|
42
|
+
const url = new URL(route, preview.baseUrl);
|
|
43
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
44
|
+
url.searchParams.set(key, value);
|
|
45
|
+
}
|
|
46
|
+
// Aborting closes the connection of an error response, whose body is never read.
|
|
47
|
+
const controller = new AbortController();
|
|
48
|
+
try {
|
|
49
|
+
return await (0, fetch_1.default)(url.toString(), {
|
|
50
|
+
timeout: PREVIEW_API_TIMEOUT_MS,
|
|
51
|
+
redirect: 'error',
|
|
52
|
+
signal: signal ? AbortSignal.any([signal, controller.signal]) : controller.signal,
|
|
53
|
+
headers: {
|
|
54
|
+
Authorization: `Bearer ${preview.token}`,
|
|
55
|
+
...(accept ? { Accept: accept } : {}),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (signal?.aborted) {
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
if (error instanceof fetch_1.RequestError) {
|
|
64
|
+
controller.abort();
|
|
65
|
+
if (error.response.headers.get('ngrok-error-code') === 'ERR_NGROK_3200') {
|
|
66
|
+
throw new Error('The simulator preview is offline. The session may have stopped or reached its time limit. Start a new session with `eas simulator:start`.');
|
|
67
|
+
}
|
|
68
|
+
const { status } = error.response;
|
|
69
|
+
if (status === 401 || status === 403) {
|
|
70
|
+
throw new Error("The preview API refused access. It did not accept the session's preview token. Run `eas simulator:get` to check that the session is still running, then try again.");
|
|
71
|
+
}
|
|
72
|
+
if (status === 404) {
|
|
73
|
+
throw new Error(notFoundMessage);
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`The preview API request failed (HTTP ${status}). The session's preview server returned an error. Run \`eas simulator:get\` to check that the session is still running, then try again.`);
|
|
76
|
+
}
|
|
77
|
+
throw new Error("Could not connect to the simulator preview API. The request did not reach the session's preview server. Check your internet connection. Run `eas simulator:get` to check that the session is still running.");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function fetchSimulatorPreviewJsonAsync(preview, route, options = {}) {
|
|
81
|
+
const response = await fetchSimulatorPreviewAsync(preview, route, {
|
|
82
|
+
...options,
|
|
83
|
+
accept: 'application/json',
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
return (await response.json());
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
throw new Error('Could not read the simulator preview API response. The response was incomplete or not valid JSON. Try again.');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Calls `onData` with each server-sent event's data until `signal` aborts. The stream ending is an error.
|
|
94
|
+
* Errors thrown by `onData` stop the stream and are rethrown unchanged.
|
|
95
|
+
*/
|
|
96
|
+
async function streamSimulatorPreviewAsync(preview, route, onData, { signal, ...options }) {
|
|
97
|
+
// Aborting closes the connection, including when the stream stops because of an error.
|
|
98
|
+
const controller = new AbortController();
|
|
99
|
+
let reading = false;
|
|
100
|
+
let onDataError;
|
|
101
|
+
let idleTimer;
|
|
102
|
+
const resetIdleTimer = () => {
|
|
103
|
+
clearTimeout(idleTimer);
|
|
104
|
+
idleTimer = setTimeout(() => {
|
|
105
|
+
controller.abort();
|
|
106
|
+
}, PREVIEW_STREAM_IDLE_TIMEOUT_MS);
|
|
107
|
+
};
|
|
108
|
+
try {
|
|
109
|
+
const response = await fetchSimulatorPreviewAsync(preview, route, {
|
|
110
|
+
...options,
|
|
111
|
+
signal: AbortSignal.any([signal, controller.signal]),
|
|
112
|
+
accept: 'text/event-stream',
|
|
113
|
+
});
|
|
114
|
+
if (!response.headers.get('content-type')?.includes('text/event-stream')) {
|
|
115
|
+
throw new Error('This simulator session does not support streaming. Its preview server did not return an event stream. Run the command without --follow.');
|
|
116
|
+
}
|
|
117
|
+
reading = true;
|
|
118
|
+
resetIdleTimer();
|
|
119
|
+
let data = [];
|
|
120
|
+
for await (const line of node_readline_1.default.createInterface({
|
|
121
|
+
input: response.body,
|
|
122
|
+
crlfDelay: Infinity,
|
|
123
|
+
})) {
|
|
124
|
+
resetIdleTimer();
|
|
125
|
+
if (line === '' && data.length > 0) {
|
|
126
|
+
const frame = data.join('\n');
|
|
127
|
+
data = [];
|
|
128
|
+
try {
|
|
129
|
+
onData(frame);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
onDataError = error;
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (line.startsWith('data:')) {
|
|
137
|
+
data.push(line.slice(5).replace(/^ /, ''));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// The server keeps the stream open while the session runs, so a clean end is unexpected too.
|
|
141
|
+
throw new Error(PREVIEW_STREAM_ENDED_MESSAGE);
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (signal.aborted) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (!reading || error === onDataError) {
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
throw new Error(PREVIEW_STREAM_ENDED_MESSAGE);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
clearTimeout(idleTimer);
|
|
154
|
+
controller.abort();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -114,4 +114,9 @@ export declare function sanitizeRemoteConfigForJson(remoteConfig: DeviceRunSessi
|
|
|
114
114
|
*/
|
|
115
115
|
export declare function formatEmbedPreviewUrl(remoteConfig: DeviceRunSessionRemoteConfig): string | null;
|
|
116
116
|
export declare function formatRemoteSessionInstructions(remoteConfig: DeviceRunSessionRemoteConfig, configType: RemoteSessionInstructionsConfigType, { egressAllow, egressClientRunsInline, sessionUrl, platform, privatePreviewUrl, publicLink, frameAncestors, corsOrigins, }?: LocalEgressOptions & PreviewLinkOptions): string;
|
|
117
|
+
export declare function stripTerminalControlCharacters(value: string, { keepNewlinesAndTabs }?: {
|
|
118
|
+
keepNewlinesAndTabs?: boolean;
|
|
119
|
+
}): string;
|
|
120
|
+
export declare function isValidLogTime(at: unknown): at is number;
|
|
121
|
+
export declare function formatLogLine(raw: string, timestamp?: boolean, at?: number): string;
|
|
117
122
|
export {};
|
package/build/simulator/utils.js
CHANGED
|
@@ -14,8 +14,12 @@ exports.formatPreviewUrl = formatPreviewUrl;
|
|
|
14
14
|
exports.sanitizeRemoteConfigForJson = sanitizeRemoteConfigForJson;
|
|
15
15
|
exports.formatEmbedPreviewUrl = formatEmbedPreviewUrl;
|
|
16
16
|
exports.formatRemoteSessionInstructions = formatRemoteSessionInstructions;
|
|
17
|
+
exports.stripTerminalControlCharacters = stripTerminalControlCharacters;
|
|
18
|
+
exports.isValidLogTime = isValidLogTime;
|
|
19
|
+
exports.formatLogLine = formatLogLine;
|
|
17
20
|
const tslib_1 = require("tslib");
|
|
18
21
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
22
|
+
const util_1 = require("util");
|
|
19
23
|
const generated_1 = require("../graphql/generated");
|
|
20
24
|
const log_1 = require("../log");
|
|
21
25
|
const env_1 = require("./env");
|
|
@@ -435,3 +439,41 @@ function formatControllerInstructions(remoteConfig, configType, previewLinkOptio
|
|
|
435
439
|
].join('\n');
|
|
436
440
|
}
|
|
437
441
|
}
|
|
442
|
+
// Session text is untrusted, so strip terminal escape and control characters before printing it.
|
|
443
|
+
function stripTerminalControlCharacters(value, { keepNewlinesAndTabs = false } = {}) {
|
|
444
|
+
return (0, util_1.stripVTControlCharacters)(value).replace(/\p{Cc}/gu, character => keepNewlinesAndTabs && (character === '\n' || character === '\t') ? character : '');
|
|
445
|
+
}
|
|
446
|
+
function isValidLogTime(at) {
|
|
447
|
+
return typeof at === 'number' && !Number.isNaN(new Date(at).getTime());
|
|
448
|
+
}
|
|
449
|
+
function formatLogLine(raw, timestamp = false, at = Date.now()) {
|
|
450
|
+
const time = new Date(isValidLogTime(at) ? at : Date.now()).toISOString();
|
|
451
|
+
try {
|
|
452
|
+
const entry = JSON.parse(raw);
|
|
453
|
+
if (typeof entry.eventMessage === 'string') {
|
|
454
|
+
const prefix = timestamp
|
|
455
|
+
? `${chalk_1.default.dim(stripTerminalControlCharacters(entry.timestamp ?? time))} `
|
|
456
|
+
: '';
|
|
457
|
+
const processName = entry.processImagePath?.split('/').at(-1) ?? 'unknown';
|
|
458
|
+
const processId = typeof entry.processID === 'number' ? `:${entry.processID}` : '';
|
|
459
|
+
const processLabel = chalk_1.default.cyan(stripTerminalControlCharacters(`[${processName}${processId}]`));
|
|
460
|
+
const level = String(entry.messageType ?? '').toLowerCase();
|
|
461
|
+
let message = stripTerminalControlCharacters(entry.eventMessage, {
|
|
462
|
+
keepNewlinesAndTabs: true,
|
|
463
|
+
});
|
|
464
|
+
if (level === 'error' || level === '16') {
|
|
465
|
+
message = chalk_1.default.red(message);
|
|
466
|
+
}
|
|
467
|
+
else if (level === 'fault' || level === '17') {
|
|
468
|
+
message = chalk_1.default.red.bold(message);
|
|
469
|
+
}
|
|
470
|
+
else if (level === 'debug' || level === '2') {
|
|
471
|
+
message = chalk_1.default.dim(message);
|
|
472
|
+
}
|
|
473
|
+
return `${prefix}${processLabel} ${message}`;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
catch { }
|
|
477
|
+
const prefix = timestamp ? `${chalk_1.default.dim(time)} ` : '';
|
|
478
|
+
return `${prefix}${stripTerminalControlCharacters(raw, { keepNewlinesAndTabs: true })}`;
|
|
479
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Actor } from './User';
|
|
2
|
+
/**
|
|
3
|
+
* Logs the actor's role on each account, and whether the credentials used for this command limit
|
|
4
|
+
* it. The list is skipped when it only contains the personal account and the credentials do not
|
|
5
|
+
* limit it.
|
|
6
|
+
*
|
|
7
|
+
* @returns whether the credentials limit the permissions on any account
|
|
8
|
+
*/
|
|
9
|
+
export declare function logAccountPermissions(actor: Actor): {
|
|
10
|
+
hasLimitedAccount: boolean;
|
|
11
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logAccountPermissions = logAccountPermissions;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
+
const generated_1 = require("../graphql/generated");
|
|
7
|
+
const log_1 = tslib_1.__importDefault(require("../log"));
|
|
8
|
+
const roles_1 = require("./roles");
|
|
9
|
+
/**
|
|
10
|
+
* Logs the actor's role on each account, and whether the credentials used for this command limit
|
|
11
|
+
* it. The list is skipped when it only contains the personal account and the credentials do not
|
|
12
|
+
* limit it.
|
|
13
|
+
*
|
|
14
|
+
* @returns whether the credentials limit the permissions on any account
|
|
15
|
+
*/
|
|
16
|
+
function logAccountPermissions(actor) {
|
|
17
|
+
// personal account is included, only show if more accounts that personal account
|
|
18
|
+
// but do show personal account in list if there are more, or if the credentials used for
|
|
19
|
+
// this command limit the permissions on it
|
|
20
|
+
const accountExcludingPersonalAccount = actor.accounts.filter(account => !('username' in actor) || account.name !== actor.username);
|
|
21
|
+
const hasLimitedAccount = actor.accounts.some(isLimitedByCredentials);
|
|
22
|
+
if (accountExcludingPersonalAccount.length === 0 && !hasLimitedAccount) {
|
|
23
|
+
return { hasLimitedAccount };
|
|
24
|
+
}
|
|
25
|
+
log_1.default.newLine();
|
|
26
|
+
log_1.default.log('Accounts:');
|
|
27
|
+
actor.accounts.forEach(account => {
|
|
28
|
+
const { permissions, effectivePermissions } = account.viewerUserPermission2;
|
|
29
|
+
const roleLabel = getLabelForPermissions(permissions);
|
|
30
|
+
if (isLimitedByCredentials(account)) {
|
|
31
|
+
const effectiveRoleLabel = getLabelForPermissions(effectivePermissions);
|
|
32
|
+
log_1.default.log(`• ${account.name} (Role: ${roleLabel}, ${chalk_1.default.yellow(`limited to ${effectiveRoleLabel} by the current credentials`)})`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
log_1.default.log(`• ${account.name} (Role: ${roleLabel})`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return { hasLimitedAccount };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether the scopes of the credential used for this command remove any of the permissions that
|
|
42
|
+
* the viewer's role grants on the account.
|
|
43
|
+
*/
|
|
44
|
+
function isLimitedByCredentials(account) {
|
|
45
|
+
const { permissions, effectivePermissions } = account.viewerUserPermission2;
|
|
46
|
+
return permissions.some(permission => !effectivePermissions.includes(permission));
|
|
47
|
+
}
|
|
48
|
+
function getLabelForPermissions(permissions) {
|
|
49
|
+
const role = (0, roles_1.getRoleForPermissions)(permissions);
|
|
50
|
+
if (role !== generated_1.Role.Custom) {
|
|
51
|
+
return getLabelForRole(role);
|
|
52
|
+
}
|
|
53
|
+
if (permissions.length === 0) {
|
|
54
|
+
return 'No permissions';
|
|
55
|
+
}
|
|
56
|
+
return `Custom: ${permissions
|
|
57
|
+
.map(permission => permission.toLowerCase().replaceAll('_', ' '))
|
|
58
|
+
.join(', ')}`;
|
|
59
|
+
}
|
|
60
|
+
function getLabelForRole(role) {
|
|
61
|
+
switch (role) {
|
|
62
|
+
case generated_1.Role.Owner:
|
|
63
|
+
return 'Owner';
|
|
64
|
+
case generated_1.Role.Admin:
|
|
65
|
+
return 'Admin';
|
|
66
|
+
case generated_1.Role.Developer:
|
|
67
|
+
return 'Developer';
|
|
68
|
+
case generated_1.Role.ReleaseManager:
|
|
69
|
+
return 'Release Manager';
|
|
70
|
+
case generated_1.Role.Runner:
|
|
71
|
+
return 'Runner';
|
|
72
|
+
case generated_1.Role.ViewOnly:
|
|
73
|
+
return 'Viewer';
|
|
74
|
+
case generated_1.Role.Custom:
|
|
75
|
+
case generated_1.Role.HasAdmin:
|
|
76
|
+
case generated_1.Role.NotAdmin:
|
|
77
|
+
return 'Custom';
|
|
78
|
+
// A role added to the API after this version of the CLI was published. TypeScript narrows
|
|
79
|
+
// `role` to `never` here, but the server can still send one, so render its name rather than
|
|
80
|
+
// returning undefined.
|
|
81
|
+
default: {
|
|
82
|
+
const unknownRole = role;
|
|
83
|
+
return unknownRole
|
|
84
|
+
.split('_')
|
|
85
|
+
.map(word => word.charAt(0) + word.slice(1).toLowerCase())
|
|
86
|
+
.join(' ');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|