eas-cli 21.2.0 → 21.3.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 (49) hide show
  1. package/README.md +243 -115
  2. package/build/commandUtils/context/contextUtils/getProjectIdAsync.js +31 -16
  3. package/build/commands/observe/events.js +5 -4
  4. package/build/commands/observe/metrics-summary.js +2 -1
  5. package/build/commands/observe/metrics.js +3 -2
  6. package/build/commands/observe/routes.js +3 -2
  7. package/build/commands/observe/session.js +8 -2
  8. package/build/commands/project/icon/set.d.ts +15 -0
  9. package/build/commands/project/icon/set.js +93 -0
  10. package/build/commands/project/init.d.ts +3 -0
  11. package/build/commands/project/init.js +34 -7
  12. package/build/commands/testflight/crashes.d.ts +23 -0
  13. package/build/commands/testflight/crashes.js +82 -0
  14. package/build/commands/testflight/feedback.d.ts +23 -0
  15. package/build/commands/testflight/feedback.js +82 -0
  16. package/build/graphql/generated.d.ts +206 -254
  17. package/build/graphql/generated.js +18 -23
  18. package/build/graphql/mutations/UploadSessionMutation.d.ts +5 -1
  19. package/build/graphql/mutations/UploadSessionMutation.js +15 -0
  20. package/build/graphql/queries/AppQuery.d.ts +1 -0
  21. package/build/graphql/queries/AppQuery.js +19 -0
  22. package/build/observe/fetchEvents.js +7 -1
  23. package/build/observe/fetchMetrics.js +6 -0
  24. package/build/observe/fetchNavigationRoutes.js +6 -0
  25. package/build/observe/fetchSessions.d.ts +7 -0
  26. package/build/observe/fetchSessions.js +16 -0
  27. package/build/observe/planGating.d.ts +15 -0
  28. package/build/observe/planGating.js +48 -0
  29. package/build/project/accountSelection.d.ts +4 -0
  30. package/build/project/accountSelection.js +56 -0
  31. package/build/project/fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync.js +4 -3
  32. package/build/project/projectInitialization.d.ts +13 -3
  33. package/build/project/projectInitialization.js +52 -80
  34. package/build/testflight/app.d.ts +18 -0
  35. package/build/testflight/app.js +124 -0
  36. package/build/testflight/fetch.d.ts +56 -0
  37. package/build/testflight/fetch.js +116 -0
  38. package/build/testflight/format.d.ts +4 -0
  39. package/build/testflight/format.js +104 -0
  40. package/build/testflight/queries.d.ts +16 -0
  41. package/build/testflight/queries.js +123 -0
  42. package/build/testflight/target.d.ts +15 -0
  43. package/build/testflight/target.js +32 -0
  44. package/build/uploads.d.ts +7 -1
  45. package/build/uploads.js +9 -0
  46. package/build/user/User.d.ts +6 -0
  47. package/build/user/User.js +18 -0
  48. package/oclif.manifest.json +1494 -1138
  49. package/package.json +8 -5
@@ -7,17 +7,18 @@ const tslib_1 = require("tslib");
7
7
  const config_1 = require("@expo/config");
8
8
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
9
9
  const nullthrows_1 = tslib_1.__importDefault(require("nullthrows"));
10
+ const accountSelection_1 = require("./accountSelection");
10
11
  const expoConfig_1 = require("./expoConfig");
11
12
  const fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync_1 = require("./fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync");
12
13
  const url_1 = require("../build/utils/url");
13
14
  const getProjectIdAsync_1 = require("../commandUtils/context/contextUtils/getProjectIdAsync");
14
15
  const projectNameValidation_1 = require("../commandUtils/projectNameValidation");
15
- const generated_1 = require("../graphql/generated");
16
16
  const AppMutation_1 = require("../graphql/mutations/AppMutation");
17
17
  const AppQuery_1 = require("../graphql/queries/AppQuery");
18
18
  const log_1 = tslib_1.__importStar(require("../log"));
19
19
  const ora_1 = require("../ora");
20
20
  const prompts_1 = require("../prompts");
21
+ const User_1 = require("../user/User");
21
22
  async function saveProjectIdAndLogSuccessAsync(projectDir, projectId) {
22
23
  await (0, getProjectIdAsync_1.saveProjectIdToAppConfigAsync)(projectDir, projectId);
23
24
  log_1.default.withTick(`Project successfully linked (ID: ${chalk_1.default.bold(projectId)}) (modified app.json)`);
@@ -103,69 +104,83 @@ async function ensureOwnerSlugConsistencyAsync(graphqlClient, projectId, project
103
104
  else if (!exp.slug) {
104
105
  await modifyExpoConfigAsync(projectDir, { slug: correctSlug });
105
106
  }
107
+ return { owner: correctOwner, slug: correctSlug };
106
108
  }
107
109
  async function setExplicitIDAsync(projectId, projectDir, { force, nonInteractive }) {
108
110
  const exp = await (0, expoConfig_1.getPrivateExpoConfigAsync)(projectDir);
109
111
  const existingProjectId = exp.extra?.eas?.projectId;
110
112
  if (projectId === existingProjectId) {
111
113
  log_1.default.succeed(`Project already linked (ID: ${chalk_1.default.bold(existingProjectId)})`);
112
- return;
114
+ return 'already-linked';
113
115
  }
114
116
  if (!existingProjectId) {
115
117
  await saveProjectIdAndLogSuccessAsync(projectDir, projectId);
116
- return;
118
+ return 'linked';
117
119
  }
118
- if (projectId !== existingProjectId) {
119
- if (force) {
120
- await saveProjectIdAndLogSuccessAsync(projectDir, projectId);
121
- return;
122
- }
123
- if (nonInteractive) {
124
- throw new Error(`Project is already linked to a different ID: ${chalk_1.default.bold(existingProjectId)}. Use --force flag to overwrite.`);
125
- }
126
- const confirm = await (0, prompts_1.confirmAsync)({
127
- message: `Project is already linked to a different ID: ${chalk_1.default.bold(existingProjectId)}. Do you wish to overwrite it?`,
128
- });
129
- if (!confirm) {
130
- throw new Error('Aborting');
131
- }
120
+ if (force) {
132
121
  await saveProjectIdAndLogSuccessAsync(projectDir, projectId);
122
+ return 'linked';
123
+ }
124
+ if (nonInteractive) {
125
+ throw new Error(`Project is already linked to a different ID: ${chalk_1.default.bold(existingProjectId)}. Use --force flag to overwrite.`);
126
+ }
127
+ const confirm = await (0, prompts_1.confirmAsync)({
128
+ message: `Project is already linked to a different ID: ${chalk_1.default.bold(existingProjectId)}. Do you wish to overwrite it?`,
129
+ });
130
+ if (!confirm) {
131
+ throw new Error('Aborting');
133
132
  }
133
+ await saveProjectIdAndLogSuccessAsync(projectDir, projectId);
134
+ return 'linked';
134
135
  }
135
136
  async function initializeWithExplicitIDAsync(projectId, projectDir, { force, nonInteractive }) {
136
- await setExplicitIDAsync(projectId, projectDir, {
137
+ return await setExplicitIDAsync(projectId, projectDir, {
137
138
  force,
138
139
  nonInteractive,
139
140
  });
140
141
  }
141
- async function initializeWithoutExplicitIDAsync(graphqlClient, actor, projectDir, { force, nonInteractive }) {
142
+ async function initializeWithoutExplicitIDAsync(graphqlClient, actor, projectDir, { force, nonInteractive, accountName: accountNameArgument, }) {
142
143
  const exp = await (0, expoConfig_1.getPrivateExpoConfigAsync)(projectDir);
143
144
  const existingProjectId = exp.extra?.eas?.projectId;
144
145
  if (existingProjectId) {
145
- log_1.default.succeed(`Project already linked (ID: ${chalk_1.default.bold(existingProjectId)}). To re-configure, remove the "extra.eas.projectId" field from your app config.`);
146
- return existingProjectId;
146
+ const ownerAccountName = accountNameArgument
147
+ ? (await AppQuery_1.AppQuery.byIdAsync(graphqlClient, existingProjectId)).ownerAccount.name
148
+ : undefined;
149
+ if (!accountNameArgument || ownerAccountName === accountNameArgument) {
150
+ log_1.default.succeed(`Project already linked (ID: ${chalk_1.default.bold(existingProjectId)}). To re-configure, remove the "extra.eas.projectId" field from your app config.`);
151
+ return { projectId: existingProjectId, status: 'already-linked' };
152
+ }
153
+ if (!force) {
154
+ throw new Error(`This project is already linked to @${ownerAccountName} (ID: ${existingProjectId}). Pass --force to re-link it to a project owned by ${accountNameArgument}, or remove the "extra.eas.projectId" field from your app config.`);
155
+ }
156
+ // --force with a different --account: fall through to re-link under the new account
147
157
  }
148
158
  const allAccounts = actor.accounts;
149
- const accountNamesWhereUserHasSufficientPermissionsToCreateApp = new Set(allAccounts
150
- .filter(a => a.users.find(it => it.actor.id === actor.id)?.role !== generated_1.Role.ViewOnly)
151
- .map(it => it.name));
152
- // if no owner field, ask the user which account they want to use to create/link the project
153
- let accountName = exp.owner;
159
+ const accountNamesWhereUserHasSufficientPermissionsToCreateApp = (0, accountSelection_1.getAccountNamesWhereUserHasSufficientPermissionsToCreateApp)(actor);
160
+ if (accountNameArgument) {
161
+ // with --force, a conflicting "owner" field is rewritten after linking
162
+ if (exp.owner && exp.owner !== accountNameArgument && !force) {
163
+ throw new Error(`The account specified with --account (${accountNameArgument}) does not match the "owner" field in your app config (${exp.owner}). Provide a matching --account or update the "owner" field.`);
164
+ }
165
+ if (!accountNamesWhereUserHasSufficientPermissionsToCreateApp.has(accountNameArgument)) {
166
+ throw new Error(`You are not able to create projects in the "${accountNameArgument}" account. Accounts you have permissions to create projects in: ${(0, User_1.getCreatableAccountNames)(actor).join(', ')}`);
167
+ }
168
+ }
169
+ // if no --account flag or owner field, ask the user which account they want to use to create/link the project
170
+ let accountName = accountNameArgument ?? exp.owner;
154
171
  if (!accountName) {
155
172
  if (allAccounts.length === 1) {
156
173
  accountName = allAccounts[0].name;
157
174
  }
158
175
  else if (nonInteractive) {
159
176
  if (!force) {
160
- throw new Error(`There are multiple accounts that you have access to: ${allAccounts
161
- .map(a => a.name)
162
- .join(', ')}. Explicitly set the owner property in your app config or run this command with the --force flag to proceed with a default account: ${allAccounts[0].name}.`);
177
+ throw new Error(`You have access to multiple accounts. Choose the account that should own this project with the --account flag:\n\n eas init --account <name> --non-interactive\n\nAccounts you have permissions to create projects in: ${(0, User_1.getCreatableAccountNames)(actor).join(', ')}\n\nAlternatively, set the "owner" field in your app config. (Deprecated: --force without --account will proceed with the default account ${allAccounts[0].name}.)`);
163
178
  }
164
179
  accountName = allAccounts[0].name;
165
180
  log_1.default.log(`Using default account ${accountName} for non-interactive and force mode`);
166
181
  }
167
182
  else {
168
- const choices = getAccountChoices(actor, accountNamesWhereUserHasSufficientPermissionsToCreateApp);
183
+ const choices = (0, accountSelection_1.getAccountChoices)(actor, accountNamesWhereUserHasSufficientPermissionsToCreateApp);
169
184
  accountName = (await (0, prompts_1.promptAsync)({
170
185
  type: 'select',
171
186
  name: 'account',
@@ -180,9 +195,12 @@ async function initializeWithoutExplicitIDAsync(graphqlClient, actor, projectDir
180
195
  const projectName = (0, projectNameValidation_1.validSlugName)(exp.slug); // This filters out invalid characters
181
196
  const projectFullName = `@${accountName}/${projectName}`;
182
197
  (0, projectNameValidation_1.validateFullNameAndSlug)(projectFullName, projectName);
198
+ // An explicit --account fully specifies the intended project (@account/slug), so linking or
199
+ // creating it requires no confirmation in non-interactive mode.
200
+ const skipConfirmation = force || (nonInteractive && accountNameArgument !== undefined);
183
201
  const existingProjectIdOnServer = await (0, fetchOrCreateProjectIDForWriteToConfigWithConfirmationAsync_1.findProjectIdByAccountNameAndSlugNullableAsync)(graphqlClient, accountName, projectName);
184
202
  if (existingProjectIdOnServer) {
185
- if (!force) {
203
+ if (!skipConfirmation) {
186
204
  if (nonInteractive) {
187
205
  throw new Error(`Existing project found: ${projectFullName} (ID: ${existingProjectIdOnServer}). Use --force flag to continue with this project.`);
188
206
  }
@@ -194,12 +212,12 @@ async function initializeWithoutExplicitIDAsync(graphqlClient, actor, projectDir
194
212
  }
195
213
  }
196
214
  await saveProjectIdAndLogSuccessAsync(projectDir, existingProjectIdOnServer);
197
- return existingProjectIdOnServer;
215
+ return { projectId: existingProjectIdOnServer, status: 'linked' };
198
216
  }
199
217
  if (!accountNamesWhereUserHasSufficientPermissionsToCreateApp.has(accountName)) {
200
218
  throw new Error(`You don't have permission to create a new project on the ${accountName} account and no matching project already exists on the account.`);
201
219
  }
202
- if (!force) {
220
+ if (!skipConfirmation) {
203
221
  if (nonInteractive) {
204
222
  throw new Error(`Project does not exist: ${projectFullName}. Use --force flag to create this project.`);
205
223
  }
@@ -227,51 +245,5 @@ async function initializeWithoutExplicitIDAsync(graphqlClient, actor, projectDir
227
245
  throw err;
228
246
  }
229
247
  await saveProjectIdAndLogSuccessAsync(projectDir, createdProjectId);
230
- return createdProjectId;
231
- }
232
- function getAccountChoices(actor, namesWithSufficientPermissions) {
233
- const allAccounts = actor.accounts;
234
- const sortedAccounts = actor.__typename === 'Robot'
235
- ? allAccounts
236
- : [...allAccounts].sort((a, _b) => actor.__typename === 'User' ? (a.name === actor.username ? -1 : 1) : 0);
237
- if (actor.__typename !== 'Robot') {
238
- const personalAccount = allAccounts?.find(account => account?.ownerUserActor?.id === actor.id);
239
- const personalAccountChoice = personalAccount
240
- ? {
241
- title: personalAccount.name,
242
- value: personalAccount,
243
- description: !namesWithSufficientPermissions.has(personalAccount.name)
244
- ? '(Personal) (Viewer Role)'
245
- : '(Personal)',
246
- }
247
- : undefined;
248
- const userAccounts = allAccounts
249
- ?.filter(account => account.ownerUserActor && account.name !== actor.username)
250
- .map(account => ({
251
- title: account.name,
252
- value: account,
253
- description: !namesWithSufficientPermissions.has(account.name)
254
- ? '(Team) (Viewer Role)'
255
- : '(Team)',
256
- }));
257
- const organizationAccounts = allAccounts
258
- ?.filter(account => account.name !== actor.username && !account.ownerUserActor)
259
- .map(account => ({
260
- title: account.name,
261
- value: account,
262
- description: !namesWithSufficientPermissions.has(account.name)
263
- ? '(Organization) (Viewer Role)'
264
- : '(Organization)',
265
- }));
266
- let choices = [];
267
- if (personalAccountChoice) {
268
- choices = [personalAccountChoice];
269
- }
270
- return [...choices, ...userAccounts, ...organizationAccounts].sort((a, _b) => actor.__typename === 'User' ? (a.value.name === actor.username ? -1 : 1) : 0);
271
- }
272
- return sortedAccounts.map(account => ({
273
- title: account.name,
274
- value: account,
275
- description: !namesWithSufficientPermissions.has(account.name) ? '(Viewer Role)' : undefined,
276
- }));
248
+ return { projectId: createdProjectId, status: 'created' };
277
249
  }
@@ -0,0 +1,18 @@
1
+ import { App } from '@expo/apple-utils';
2
+ import { ExpoConfig } from '@expo/config';
3
+ import { Analytics } from '../analytics/AnalyticsManager';
4
+ import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
5
+ import { Actor } from '../user/User';
6
+ import { Client } from '../vcs/vcs';
7
+ /** Resolve the App Store Connect app that TestFlight feedback and crashes should be read from. */
8
+ export declare function resolveTestFlightAppAsync({ actor, analytics, exp, graphqlClient, nonInteractive, profileName, projectDir, projectId, vcsClient, }: {
9
+ actor: Actor;
10
+ analytics: Analytics;
11
+ exp: ExpoConfig;
12
+ graphqlClient: ExpoGraphqlClient;
13
+ nonInteractive: boolean;
14
+ profileName?: string;
15
+ projectDir: string;
16
+ projectId: string;
17
+ vcsClient: Client;
18
+ }): Promise<App>;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveTestFlightAppAsync = resolveTestFlightAppAsync;
4
+ const tslib_1 = require("tslib");
5
+ const apple_utils_1 = require("@expo/apple-utils");
6
+ const eas_build_job_1 = require("@expo/eas-build-job");
7
+ const eas_json_1 = require("@expo/eas-json");
8
+ const errors_1 = require("@expo/eas-json/build/errors");
9
+ const assert_1 = tslib_1.__importDefault(require("assert"));
10
+ const context_1 = require("../credentials/context");
11
+ const AppStoreConnectApiKeyQuery_1 = require("../credentials/ios/api/graphql/queries/AppStoreConnectApiKeyQuery");
12
+ const authenticate_1 = require("../credentials/ios/appstore/authenticate");
13
+ const AppStoreConnectApiKeyQuery_2 = require("../graphql/queries/AppStoreConnectApiKeyQuery");
14
+ const log_1 = tslib_1.__importDefault(require("../log"));
15
+ const auth_1 = require("../metadata/auth");
16
+ const bundleIdentifier_1 = require("../project/ios/bundleIdentifier");
17
+ const projectUtils_1 = require("../project/projectUtils");
18
+ /** How long the ASC JWTs we mint stay valid, matching the credentials service default. */
19
+ const ASC_TOKEN_DURATION_SECONDS = 1200;
20
+ /**
21
+ * TestFlight data lives in App Store Connect, so we resolve the bundle identifier and the ASC API
22
+ * key from the submit profile the same way `eas metadata` does. When the project has no eas.json
23
+ * we fall back to an empty profile, which resolves the bundle identifier from the app config and
24
+ * the API key from env vars or the EAS credentials service.
25
+ */
26
+ async function resolveSubmitProfileAsync({ projectDir, profileName, }) {
27
+ try {
28
+ return await eas_json_1.EasJsonUtils.getSubmitProfileAsync(eas_json_1.EasJsonAccessor.fromProjectPath(projectDir), eas_build_job_1.Platform.IOS, profileName);
29
+ }
30
+ catch (error) {
31
+ if (error instanceof errors_1.MissingEasJsonError && !profileName) {
32
+ return {};
33
+ }
34
+ throw error;
35
+ }
36
+ }
37
+ /**
38
+ * Look for the app in every ASC API key registered on the account that owns the project. This is
39
+ * the resolution the Expo MCP server uses for its TestFlight tools, and it covers projects that
40
+ * have no ASC API key assigned to their iOS submission credentials.
41
+ */
42
+ async function findAppWithAccountAscApiKeysAsync({ bundleId, graphqlClient, projectId, }) {
43
+ const account = await (0, projectUtils_1.getOwnerAccountForProjectIdAsync)(graphqlClient, projectId);
44
+ const keys = await AppStoreConnectApiKeyQuery_1.AppStoreConnectApiKeyQuery.getAllForAccountAsync(graphqlClient, account.name);
45
+ for (const key of keys) {
46
+ try {
47
+ const { keyP8, keyIdentifier, issuerIdentifier } = await AppStoreConnectApiKeyQuery_2.AppStoreConnectApiKeyQuery.getByIdAsync(graphqlClient, key.id);
48
+ const context = {
49
+ token: new apple_utils_1.Token({
50
+ key: keyP8,
51
+ keyId: keyIdentifier,
52
+ issuerId: issuerIdentifier,
53
+ duration: ASC_TOKEN_DURATION_SECONDS,
54
+ }),
55
+ };
56
+ const app = await apple_utils_1.App.findAsync(context, { bundleId });
57
+ if (app) {
58
+ log_1.default.log(`Using App Store Connect API Key ${key.name ?? key.keyIdentifier} from your Expo account.`);
59
+ return app;
60
+ }
61
+ }
62
+ catch (error) {
63
+ // Never read `.message` off an unknown rejection: a non-Error value (a string, or
64
+ // null from a wrapped fetch) would make this handler throw a TypeError, hiding the
65
+ // real failure and aborting the loop instead of falling through to the next key.
66
+ log_1.default.debug(`ASC API Key ${key.keyIdentifier} cannot access ${bundleId}: ${error instanceof Error ? error.message : String(error)}`);
67
+ }
68
+ }
69
+ return null;
70
+ }
71
+ /** Resolve the App Store Connect app that TestFlight feedback and crashes should be read from. */
72
+ async function resolveTestFlightAppAsync({ actor, analytics, exp, graphqlClient, nonInteractive, profileName, projectDir, projectId, vcsClient, }) {
73
+ const profile = await resolveSubmitProfileAsync({ projectDir, profileName });
74
+ const createCredentialsContext = (contextNonInteractive) => new context_1.CredentialsContext({
75
+ projectInfo: { exp, projectId },
76
+ projectDir,
77
+ user: actor,
78
+ graphqlClient,
79
+ analytics,
80
+ nonInteractive: contextNonInteractive,
81
+ vcsClient,
82
+ });
83
+ // Prefer the key configured for this project: ASC env vars, the submit profile, or the key
84
+ // assigned to its iOS submission credentials. Forced non-interactive so that a project without
85
+ // any of those falls through to the account-wide lookup instead of prompting for an Apple login.
86
+ try {
87
+ const { app } = await (0, auth_1.getAppStoreAuthAsync)({
88
+ exp,
89
+ credentialsCtx: createCredentialsContext(true),
90
+ graphqlClient,
91
+ nonInteractive: true,
92
+ profile,
93
+ projectDir,
94
+ projectId,
95
+ });
96
+ return app;
97
+ }
98
+ catch (error) {
99
+ log_1.default.debug(`Could not resolve an App Store Connect API Key for this project: ${error instanceof Error ? error.message : String(error)}`);
100
+ }
101
+ const bundleId = ('bundleIdentifier' in profile ? profile.bundleIdentifier : undefined) ??
102
+ (await (0, bundleIdentifier_1.getBundleIdentifierAsync)(projectDir, exp, vcsClient));
103
+ const appFromAccountKeys = await findAppWithAccountAscApiKeysAsync({
104
+ bundleId,
105
+ graphqlClient,
106
+ projectId,
107
+ });
108
+ if (appFromAccountKeys) {
109
+ return appFromAccountKeys;
110
+ }
111
+ if (nonInteractive) {
112
+ throw new Error(`Could not find "${bundleId}" in App Store Connect with any App Store Connect API Key available to this project.\n` +
113
+ 'Provide a key with access to the app via:\n' +
114
+ ' - Environment variables: EXPO_ASC_API_KEY_PATH, EXPO_ASC_KEY_ID, EXPO_ASC_ISSUER_ID\n' +
115
+ ' - eas.json submit profile: ascApiKeyPath, ascApiKeyId, ascApiKeyIssuerId\n' +
116
+ ' - EAS credentials service: run `eas credentials` to set up an API key');
117
+ }
118
+ // Last resort: an interactive Apple ID login.
119
+ const credentialsCtx = createCredentialsContext(false);
120
+ const authCtx = await credentialsCtx.appStore.ensureUserAuthenticatedAsync();
121
+ const app = await apple_utils_1.App.findAsync((0, authenticate_1.getRequestContext)(authCtx), { bundleId });
122
+ (0, assert_1.default)(app, `Failed to load app "${bundleId}" from App Store Connect`);
123
+ return app;
124
+ }
@@ -0,0 +1,56 @@
1
+ import { App } from '@expo/apple-utils';
2
+ /** Which kind of TestFlight beta feedback a submission is. Matches the workflow trigger context. */
3
+ export type BetaFeedbackType = 'crash' | 'screenshot';
4
+ /** Screenshot attached to a piece of TestFlight feedback. Its URL expires after a short while. */
5
+ export type TestFlightScreenshot = {
6
+ url: string;
7
+ width: number;
8
+ height: number;
9
+ expirationDate: string;
10
+ };
11
+ /** Fields shared by TestFlight screenshot feedback and TestFlight crash submissions. */
12
+ export type TestFlightSubmission = {
13
+ id: string;
14
+ createdDate: string;
15
+ comment: string | null;
16
+ deviceModel: string;
17
+ osVersion: string;
18
+ locale: string | null;
19
+ timeZone: string | null;
20
+ architecture: string | null;
21
+ connectionType: string | null;
22
+ deviceFamily: string | null;
23
+ appUptimeInMilliseconds: number | null;
24
+ batteryPercentage: number | null;
25
+ diskBytesAvailable: number | null;
26
+ diskBytesTotal: number | null;
27
+ buildVersion: string | null;
28
+ testerName: string | null;
29
+ testerEmail: string | null;
30
+ };
31
+ export type TestFlightFeedback = TestFlightSubmission & {
32
+ screenshots: TestFlightScreenshot[];
33
+ };
34
+ export type TestFlightCrash = TestFlightSubmission;
35
+ /**
36
+ * A paginated view over one App Store Connect collection. App Store Connect has no offset-based
37
+ * paging and apple-utils always walks every page, so the underlying fetch happens once and pages
38
+ * are served from that result — which also makes the total count available for free.
39
+ */
40
+ export type TestFlightQuery<T> = {
41
+ queryAsync(limit: number, offset: number): Promise<T[]>;
42
+ getTotalAsync(): Promise<number>;
43
+ };
44
+ /** Screenshot feedback that TestFlight testers submitted for the app, newest first. */
45
+ export declare function getTestFlightFeedbackQuery(app: App): TestFlightQuery<TestFlightFeedback>;
46
+ /** Crashes that TestFlight testers reported for the app, newest first. */
47
+ export declare function getTestFlightCrashesQuery(app: App): TestFlightQuery<TestFlightCrash>;
48
+ /** Fetch a single screenshot feedback submission by ID. */
49
+ export declare function fetchTestFlightFeedbackAsync(app: App, feedbackId: string): Promise<TestFlightFeedback>;
50
+ export type TestFlightCrashDetails = {
51
+ crash: TestFlightCrash;
52
+ /** The crash log, or `null` when App Store Connect has none for this submission. */
53
+ logText: string | null;
54
+ };
55
+ /** Fetch a single crash submission together with its full crash log. */
56
+ export declare function fetchTestFlightCrashAsync(app: App, crashId: string): Promise<TestFlightCrashDetails>;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTestFlightFeedbackQuery = getTestFlightFeedbackQuery;
4
+ exports.getTestFlightCrashesQuery = getTestFlightCrashesQuery;
5
+ exports.fetchTestFlightFeedbackAsync = fetchTestFlightFeedbackAsync;
6
+ exports.fetchTestFlightCrashAsync = fetchTestFlightCrashAsync;
7
+ const apple_utils_1 = require("@expo/apple-utils");
8
+ /**
9
+ * The largest page size the App Store Connect API accepts. The apple-utils helpers always walk
10
+ * every page, so we ask for the largest pages possible and paginate client-side from there.
11
+ */
12
+ const MAX_PAGE_SIZE = 200;
13
+ function createQuery(fetchAllAsync) {
14
+ let all;
15
+ const allAsync = async () => {
16
+ all ??= fetchAllAsync();
17
+ return await all;
18
+ };
19
+ return {
20
+ async queryAsync(limit, offset) {
21
+ return (await allAsync()).slice(offset, offset + limit);
22
+ },
23
+ async getTotalAsync() {
24
+ return (await allAsync()).length;
25
+ },
26
+ };
27
+ }
28
+ /**
29
+ * Everything here is attacker-influenced text: any TestFlight tester can put arbitrary bytes in a
30
+ * feedback comment or their own name, and crash logs carry thread and symbol names from the build.
31
+ * Terminal escape sequences in that text could clear the screen or spoof output when it is printed,
32
+ * so strip control characters at the boundary — before the data reaches either the formatters or
33
+ * `--json`. Newlines and tabs survive because multi-line comments and crash logs need them.
34
+ */
35
+ const CONTROL_CHARACTERS = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g;
36
+ function sanitizeText(value) {
37
+ return value.replace(/\r\n?/g, '\n').replace(CONTROL_CHARACTERS, '');
38
+ }
39
+ function sanitizeOptionalText(value) {
40
+ return typeof value === 'string' ? sanitizeText(value) : null;
41
+ }
42
+ function formatTesterName(tester) {
43
+ const parts = [tester?.attributes?.firstName, tester?.attributes?.lastName].filter((part) => !!part);
44
+ return parts.length > 0 ? sanitizeText(parts.join(' ')) : null;
45
+ }
46
+ function normalizeSubmission(submission) {
47
+ const attributes = submission.attributes;
48
+ return {
49
+ id: submission.id,
50
+ createdDate: attributes.createdDate,
51
+ comment: sanitizeOptionalText(attributes.comment),
52
+ deviceModel: sanitizeText(attributes.deviceModel ?? ''),
53
+ osVersion: sanitizeText(attributes.osVersion ?? ''),
54
+ locale: sanitizeOptionalText(attributes.locale),
55
+ timeZone: sanitizeOptionalText(attributes.timeZone),
56
+ architecture: sanitizeOptionalText(attributes.architecture),
57
+ connectionType: sanitizeOptionalText(attributes.connectionType),
58
+ deviceFamily: sanitizeOptionalText(attributes.deviceFamily),
59
+ appUptimeInMilliseconds: attributes.appUptimeInMilliseconds ?? null,
60
+ batteryPercentage: attributes.batteryPercentage ?? null,
61
+ diskBytesAvailable: attributes.diskBytesAvailable ?? null,
62
+ diskBytesTotal: attributes.diskBytesTotal ?? null,
63
+ buildVersion: sanitizeOptionalText(attributes.build?.attributes?.version),
64
+ testerName: formatTesterName(attributes.tester),
65
+ // The tester relationship hides the email of testers who joined through a public link, in
66
+ // which case the submission itself still carries the address they submitted feedback with.
67
+ testerEmail: sanitizeOptionalText(attributes.tester?.attributes?.email ?? attributes.email),
68
+ };
69
+ }
70
+ function normalizeFeedback(submission) {
71
+ return {
72
+ ...normalizeSubmission(submission),
73
+ screenshots: (submission.attributes.screenshots ?? []).map(screenshot => ({
74
+ url: sanitizeText(screenshot.url ?? ''),
75
+ width: screenshot.width,
76
+ height: screenshot.height,
77
+ expirationDate: screenshot.expirationDate,
78
+ })),
79
+ };
80
+ }
81
+ /** Screenshot feedback that TestFlight testers submitted for the app, newest first. */
82
+ function getTestFlightFeedbackQuery(app) {
83
+ return createQuery(async () => {
84
+ const submissions = await app.getBetaFeedbackScreenshotSubmissionsAsync({
85
+ query: { limit: MAX_PAGE_SIZE },
86
+ });
87
+ return submissions.map(normalizeFeedback);
88
+ });
89
+ }
90
+ /** Crashes that TestFlight testers reported for the app, newest first. */
91
+ function getTestFlightCrashesQuery(app) {
92
+ return createQuery(async () => {
93
+ const submissions = await app.getBetaFeedbackCrashSubmissionsAsync({
94
+ query: { limit: MAX_PAGE_SIZE },
95
+ });
96
+ return submissions.map(normalizeSubmission);
97
+ });
98
+ }
99
+ /** Fetch a single screenshot feedback submission by ID. */
100
+ async function fetchTestFlightFeedbackAsync(app, feedbackId) {
101
+ const submission = await apple_utils_1.BetaFeedbackScreenshotSubmission.infoAsync(app.context, {
102
+ id: feedbackId,
103
+ });
104
+ return normalizeFeedback(submission);
105
+ }
106
+ /** Fetch a single crash submission together with its full crash log. */
107
+ async function fetchTestFlightCrashAsync(app, crashId) {
108
+ const submission = await apple_utils_1.BetaFeedbackCrashSubmission.infoAsync(app.context, { id: crashId });
109
+ const crashLog = await apple_utils_1.BetaCrashLog.getCrashLogAsync(app.context, {
110
+ betaFeedbackCrashSubmissionId: crashId,
111
+ });
112
+ return {
113
+ crash: normalizeSubmission(submission),
114
+ logText: sanitizeOptionalText(crashLog.attributes.logText),
115
+ };
116
+ }
@@ -0,0 +1,4 @@
1
+ import { TestFlightCrash, TestFlightFeedback } from './fetch';
2
+ export declare function formatTestFlightFeedback(feedback: TestFlightFeedback, position?: number): string;
3
+ export declare function formatTestFlightCrash(crash: TestFlightCrash, position?: number): string;
4
+ export declare function formatTestFlightCrashDetails(crash: TestFlightCrash, logText: string | null): string;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatTestFlightFeedback = formatTestFlightFeedback;
4
+ exports.formatTestFlightCrash = formatTestFlightCrash;
5
+ exports.formatTestFlightCrashDetails = formatTestFlightCrashDetails;
6
+ const tslib_1 = require("tslib");
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ const formatFields_1 = tslib_1.__importDefault(require("../utils/formatFields"));
9
+ const date_1 = require("../utils/date");
10
+ function formatCreatedDate(createdDate) {
11
+ const date = new Date(createdDate);
12
+ if (isNaN(date.getTime())) {
13
+ return createdDate;
14
+ }
15
+ return `${date.toLocaleString()} (${(0, date_1.fromNow)(date)} ago)`;
16
+ }
17
+ function formatDevice(submission) {
18
+ return [submission.deviceModel, `iOS ${submission.osVersion}`].join(', ');
19
+ }
20
+ function formatTester(submission) {
21
+ if (submission.testerName && submission.testerEmail) {
22
+ return `${submission.testerName} <${submission.testerEmail}>`;
23
+ }
24
+ return submission.testerName ?? submission.testerEmail ?? null;
25
+ }
26
+ function formatBytes(bytes) {
27
+ const gigabytes = bytes / 1024 ** 3;
28
+ if (gigabytes >= 1) {
29
+ return `${gigabytes.toFixed(1)} GB`;
30
+ }
31
+ return `${(bytes / 1024 ** 2).toFixed(0)} MB`;
32
+ }
33
+ function formatDeviceState(submission) {
34
+ const parts = [];
35
+ if (submission.batteryPercentage !== null) {
36
+ parts.push(`battery ${submission.batteryPercentage}%`);
37
+ }
38
+ if (submission.diskBytesAvailable !== null && submission.diskBytesTotal !== null) {
39
+ parts.push(`disk ${formatBytes(submission.diskBytesAvailable)} free of ${formatBytes(submission.diskBytesTotal)}`);
40
+ }
41
+ if (submission.connectionType) {
42
+ parts.push(submission.connectionType.toLowerCase().replace('_', ' '));
43
+ }
44
+ return parts.length > 0 ? parts.join(', ') : null;
45
+ }
46
+ /** Indent every line of a possibly multi-line value so it lines up under its label. */
47
+ function indentValue(value, indent) {
48
+ return value.split('\n').join(`\n${' '.repeat(indent)}`);
49
+ }
50
+ function commonFields(submission) {
51
+ const tester = formatTester(submission);
52
+ const deviceState = formatDeviceState(submission);
53
+ return [
54
+ { label: 'Submitted', value: formatCreatedDate(submission.createdDate) },
55
+ ...(submission.buildVersion ? [{ label: 'Build', value: submission.buildVersion }] : []),
56
+ { label: 'Device', value: formatDevice(submission) },
57
+ ...(tester ? [{ label: 'Tester', value: tester }] : []),
58
+ ...(submission.locale ? [{ label: 'Locale', value: submission.locale }] : []),
59
+ ...(deviceState ? [{ label: 'State', value: deviceState }] : []),
60
+ ];
61
+ }
62
+ function formatBlock(heading, fields) {
63
+ // `formatFields` pads labels to the widest one, so multi-line values must be indented by that
64
+ // width plus the two spaces it puts between label and value.
65
+ const labelWidth = Math.max(...fields.map(field => field.label.length)) + 2;
66
+ return [
67
+ chalk_1.default.bold(heading),
68
+ (0, formatFields_1.default)(fields.map(field => ({ ...field, value: indentValue(field.value, labelWidth) }))),
69
+ ].join('\n');
70
+ }
71
+ /** Prefix list entries with their absolute position, so `--offset` numbering stays meaningful. */
72
+ function heading(kind, id, position) {
73
+ return position === undefined ? `${kind} ${id}` : `${position}. ${kind} ${id}`;
74
+ }
75
+ function formatTestFlightFeedback(feedback, position) {
76
+ const screenshots = feedback.screenshots.map(screenshot => `${screenshot.url} (${screenshot.width}x${screenshot.height})`);
77
+ return formatBlock(heading('Feedback', feedback.id, position), [
78
+ ...commonFields(feedback),
79
+ { label: 'Comment', value: feedback.comment ?? chalk_1.default.dim('(no comment)') },
80
+ ...(screenshots.length > 0 ? [{ label: 'Screenshots', value: screenshots.join('\n') }] : []),
81
+ ]);
82
+ }
83
+ function formatTestFlightCrash(crash, position) {
84
+ return formatBlock(heading('Crash', crash.id, position), [
85
+ ...commonFields(crash),
86
+ ...(crash.comment ? [{ label: 'Comment', value: crash.comment }] : []),
87
+ ]);
88
+ }
89
+ function formatTestFlightCrashDetails(crash, logText) {
90
+ const details = formatBlock(heading('Crash', crash.id), [
91
+ ...commonFields(crash),
92
+ ...(crash.architecture ? [{ label: 'Arch', value: crash.architecture }] : []),
93
+ ...(crash.appUptimeInMilliseconds !== null
94
+ ? [{ label: 'Uptime', value: `${(crash.appUptimeInMilliseconds / 1000).toFixed(1)}s` }]
95
+ : []),
96
+ ...(crash.comment ? [{ label: 'Comment', value: crash.comment }] : []),
97
+ ]);
98
+ return [
99
+ details,
100
+ '',
101
+ chalk_1.default.bold('Crash log'),
102
+ logText ?? chalk_1.default.dim('No crash log is available for this submission yet.'),
103
+ ].join('\n');
104
+ }
@@ -0,0 +1,16 @@
1
+ import { App } from '@expo/apple-utils';
2
+ import { BetaFeedbackTarget } from './target';
3
+ import { PaginatedQueryOptions } from '../commandUtils/pagination';
4
+ /** Feedback and crashes render as multi-line blocks, so default to a smaller page than lists do. */
5
+ export declare const TESTFLIGHT_PAGE_SIZE = 20;
6
+ /** List screenshot feedback submitted by TestFlight testers. */
7
+ export declare function listAndRenderTestFlightFeedbackAsync(app: App, paginatedQueryOptions: PaginatedQueryOptions): Promise<void>;
8
+ /** List crashes reported by TestFlight testers. */
9
+ export declare function listAndRenderTestFlightCrashesAsync(app: App, paginatedQueryOptions: PaginatedQueryOptions): Promise<void>;
10
+ /**
11
+ * Render a single submission identified by an EAS workflow trigger's
12
+ * `app_store_connect.beta_feedback` payload. Crashes are rendered with their full crash log.
13
+ */
14
+ export declare function viewAndRenderBetaFeedbackAsync(app: App, target: BetaFeedbackTarget, { json }: {
15
+ json: boolean;
16
+ }): Promise<void>;