Skip to content

Commit af67fd8

Browse files
committed
[eas-cli] Add eas update:view-embedded command
1 parent e21ac36 commit af67fd8

2 files changed

Lines changed: 198 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Args } from '@oclif/core';
2+
3+
import EasCommand from '../../commandUtils/EasCommand';
4+
import { EasJsonOnlyFlag } from '../../commandUtils/flags';
5+
import {
6+
EmbeddedUpdateFragment,
7+
EmbeddedUpdateQuery,
8+
} from '../../graphql/queries/EmbeddedUpdateQuery';
9+
import Log from '../../log';
10+
import formatFields from '../../utils/formatFields';
11+
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
12+
13+
export default class UpdateViewEmbedded extends EasCommand {
14+
static override description = 'view details of an embedded update registered with EAS Update';
15+
16+
static override args = {
17+
id: Args.string({
18+
required: true,
19+
description: 'The ID of the embedded update (manifest UUID from app.manifest).',
20+
}),
21+
};
22+
23+
static override flags = {
24+
...EasJsonOnlyFlag,
25+
};
26+
27+
static override contextDefinition = {
28+
...this.ContextOptions.ProjectId,
29+
...this.ContextOptions.LoggedIn,
30+
};
31+
32+
async runAsync(): Promise<void> {
33+
const {
34+
args: { id: embeddedUpdateId },
35+
flags: { json: jsonFlag },
36+
} = await this.parse(UpdateViewEmbedded);
37+
38+
const {
39+
projectId,
40+
loggedIn: { graphqlClient },
41+
} = await this.getContextAsync(UpdateViewEmbedded, { nonInteractive: true });
42+
43+
if (jsonFlag) {
44+
enableJsonOutput();
45+
}
46+
47+
const embeddedUpdate = await EmbeddedUpdateQuery.viewByIdAsync(graphqlClient, {
48+
embeddedUpdateId,
49+
appId: projectId,
50+
});
51+
52+
if (jsonFlag) {
53+
printJsonOnlyOutput(embeddedUpdate);
54+
return;
55+
}
56+
57+
Log.log(formatEmbeddedUpdate(embeddedUpdate));
58+
}
59+
}
60+
61+
export function formatEmbeddedUpdate(embeddedUpdate: EmbeddedUpdateFragment): string {
62+
return formatFields([
63+
{ label: 'ID', value: embeddedUpdate.id },
64+
{ label: 'Platform', value: embeddedUpdate.platform.toLowerCase() },
65+
{ label: 'Runtime version', value: embeddedUpdate.runtimeVersion },
66+
{ label: 'Channel', value: embeddedUpdate.channel },
67+
{ label: 'Created at', value: new Date(embeddedUpdate.createdAt).toLocaleString() },
68+
]);
69+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import gql from 'graphql-tag';
2+
3+
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
4+
import { AppPlatform } from '../generated';
5+
import { Connection } from '../../utils/relay';
6+
import { withErrorHandlingAsync } from '../client';
7+
8+
export type EmbeddedUpdateFragment = {
9+
id: string;
10+
platform: AppPlatform;
11+
runtimeVersion: string;
12+
channel: string;
13+
createdAt: string;
14+
};
15+
16+
type ViewEmbeddedUpdateByIdQueryResult = {
17+
embeddedUpdates: {
18+
byId: EmbeddedUpdateFragment;
19+
};
20+
};
21+
22+
type ViewEmbeddedUpdatesPaginatedQueryResult = {
23+
app: {
24+
byId: {
25+
embeddedUpdatesPaginated: {
26+
edges: { cursor: string; node: EmbeddedUpdateFragment }[];
27+
pageInfo: {
28+
hasNextPage: boolean;
29+
hasPreviousPage: boolean;
30+
startCursor: string | null;
31+
endCursor: string | null;
32+
};
33+
};
34+
};
35+
};
36+
};
37+
38+
export type EmbeddedUpdateFilter = {
39+
platform?: AppPlatform;
40+
runtimeVersion?: string;
41+
channel?: string;
42+
};
43+
44+
export const EmbeddedUpdateQuery = {
45+
async viewByIdAsync(
46+
graphqlClient: ExpoGraphqlClient,
47+
{ embeddedUpdateId, appId }: { embeddedUpdateId: string; appId: string }
48+
): Promise<EmbeddedUpdateFragment> {
49+
const data = await withErrorHandlingAsync(
50+
graphqlClient
51+
.query<ViewEmbeddedUpdateByIdQueryResult>(
52+
gql`
53+
query ViewEmbeddedUpdateById($embeddedUpdateId: ID!, $appId: ID!) {
54+
embeddedUpdates {
55+
byId(embeddedUpdateId: $embeddedUpdateId, appId: $appId) {
56+
id
57+
platform
58+
runtimeVersion
59+
channel
60+
createdAt
61+
}
62+
}
63+
}
64+
`,
65+
{ embeddedUpdateId, appId },
66+
{ additionalTypenames: ['EmbeddedUpdate'] }
67+
)
68+
.toPromise()
69+
);
70+
return data.embeddedUpdates.byId;
71+
},
72+
73+
async viewPaginatedAsync(
74+
graphqlClient: ExpoGraphqlClient,
75+
{
76+
appId,
77+
filter,
78+
first,
79+
after,
80+
}: {
81+
appId: string;
82+
filter?: EmbeddedUpdateFilter;
83+
first: number;
84+
after?: string;
85+
}
86+
): Promise<Connection<EmbeddedUpdateFragment>> {
87+
const data = await withErrorHandlingAsync(
88+
graphqlClient
89+
.query<ViewEmbeddedUpdatesPaginatedQueryResult>(
90+
gql`
91+
query ViewEmbeddedUpdatesPaginated(
92+
$appId: String!
93+
$first: Int!
94+
$after: String
95+
$filter: EmbeddedUpdateFilterInput
96+
) {
97+
app {
98+
byId(appId: $appId) {
99+
id
100+
embeddedUpdatesPaginated(first: $first, after: $after, filter: $filter) {
101+
edges {
102+
cursor
103+
node {
104+
id
105+
platform
106+
runtimeVersion
107+
channel
108+
createdAt
109+
}
110+
}
111+
pageInfo {
112+
hasNextPage
113+
hasPreviousPage
114+
startCursor
115+
endCursor
116+
}
117+
}
118+
}
119+
}
120+
}
121+
`,
122+
{ appId, first, after, filter },
123+
{ additionalTypenames: ['EmbeddedUpdate'] }
124+
)
125+
.toPromise()
126+
);
127+
return data.app.byId.embeddedUpdatesPaginated;
128+
},
129+
};

0 commit comments

Comments
 (0)