create-disposabl-app 0.8.10 → 0.8.12
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 +13 -1
- package/dist/disposabl.js +1 -1
- package/dist/index.js +1 -6
- package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.tsx +0 -1
- package/dist/templates/default/bun.lock +1 -7
- package/dist/templates/default/packages/backend/README.md +4 -8
- package/dist/templates/default/packages/backend/convex/_generated/api.d.ts +0 -67
- package/dist/templates/default/packages/backend/convex/_generated/server.d.ts +0 -9
- package/dist/templates/default/packages/backend/convex/convex.config.ts +0 -11
- package/dist/templates/default/packages/backend/convex/http.ts +1 -9
- package/dist/templates/default/packages/backend/convex/schema.ts +1 -70
- package/dist/templates/default/packages/backend/generated/openapi.json +1 -1262
- package/dist/templates/default/packages/backend/generated/pages.json +0 -4
- package/dist/templates/default/packages/backend/generated/platforms.ts +2 -20
- package/dist/templates/default/packages/backend/package.json +1 -7
- package/dist/templates/default/packages/skill/SKILL.md +5 -5
- package/dist/templates/default/packages/skill/references/delivery.md +1 -1
- package/package.json +2 -2
- package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.connections.tsx +0 -445
- package/dist/templates/default/packages/backend/convex/apps/actions/cleanup.ts +0 -317
- package/dist/templates/default/packages/backend/convex/apps/actions/create.ts +0 -30
- package/dist/templates/default/packages/backend/convex/apps/actions/delete.ts +0 -15
- package/dist/templates/default/packages/backend/convex/apps/actions/expo.ts +0 -180
- package/dist/templates/default/packages/backend/convex/apps/actions/setup.ts +0 -48
- package/dist/templates/default/packages/backend/convex/apps/internal.ts +0 -211
- package/dist/templates/default/packages/backend/convex/apps/operations/internal.ts +0 -239
- package/dist/templates/default/packages/backend/convex/apps/validator.ts +0 -23
- package/dist/templates/default/packages/backend/convex/connections/actions/credentials.ts +0 -56
- package/dist/templates/default/packages/backend/convex/connections/actions/expo.ts +0 -79
- package/dist/templates/default/packages/backend/convex/connections/actions/github.ts +0 -119
- package/dist/templates/default/packages/backend/convex/connections/actions/oauth.ts +0 -128
- package/dist/templates/default/packages/backend/convex/connections/index.ts +0 -80
- package/dist/templates/default/packages/backend/convex/connections/internal.ts +0 -147
- package/dist/templates/default/packages/backend/convex/connections/validator.ts +0 -35
- package/dist/templates/default/packages/backend/convex/downloads/action.ts +0 -136
- package/dist/templates/default/packages/backend/convex/downloads/http.ts +0 -32
- package/dist/templates/default/packages/backend/convex/downloads/internal.ts +0 -58
- package/dist/templates/default/packages/backend/convex/github/actions/http.ts +0 -69
- package/dist/templates/default/packages/backend/convex/github/actions/internal.ts +0 -196
- package/dist/templates/default/packages/backend/convex/github/actions/oidc.ts +0 -75
- package/dist/templates/default/packages/backend/convex/github/actions/provision.ts +0 -76
- package/dist/templates/default/packages/backend/convex/github/actions/secrets.ts +0 -180
- package/dist/templates/default/packages/backend/convex/github/actions/signing.ts +0 -41
- package/dist/templates/default/packages/backend/convex/github/actions/tokens.ts +0 -145
- package/dist/templates/default/packages/backend/convex/github/identityCache.ts +0 -54
- package/dist/templates/default/packages/backend/convex/github/internal.ts +0 -33
- package/dist/templates/default/packages/backend/convex/previews/internal.ts +0 -257
- package/dist/templates/default/packages/backend/convex/previews/token/actions/create.ts +0 -83
- package/dist/templates/default/packages/backend/convex/previews/token/actions/management.ts +0 -182
- package/dist/templates/default/packages/backend/convex/previews/token/internal.ts +0 -32
- package/dist/templates/default/packages/backend/convex/releases/internal.ts +0 -28
- package/dist/templates/default/packages/backend/convex/validator.ts +0 -87
- package/dist/templates/default/packages/sdk/src/generated/client/client.gen.ts +0 -300
- package/dist/templates/default/packages/sdk/src/generated/client/index.ts +0 -27
- package/dist/templates/default/packages/sdk/src/generated/client/types.gen.ts +0 -238
- package/dist/templates/default/packages/sdk/src/generated/client/utils.gen.ts +0 -337
- package/dist/templates/default/packages/sdk/src/generated/client.gen.ts +0 -28
- package/dist/templates/default/packages/sdk/src/generated/core/auth.gen.ts +0 -49
- package/dist/templates/default/packages/sdk/src/generated/core/bodySerializer.gen.ts +0 -96
- package/dist/templates/default/packages/sdk/src/generated/core/params.gen.ts +0 -188
- package/dist/templates/default/packages/sdk/src/generated/core/pathSerializer.gen.ts +0 -186
- package/dist/templates/default/packages/sdk/src/generated/core/queryKeySerializer.gen.ts +0 -134
- package/dist/templates/default/packages/sdk/src/generated/core/serverSentEvents.gen.ts +0 -265
- package/dist/templates/default/packages/sdk/src/generated/core/types.gen.ts +0 -126
- package/dist/templates/default/packages/sdk/src/generated/core/utils.gen.ts +0 -146
- package/dist/templates/default/packages/sdk/src/generated/index.ts +0 -63
- package/dist/templates/default/packages/sdk/src/generated/sdk.gen.ts +0 -234
- package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +0 -660
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
"use node";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
identityFields,
|
|
5
|
-
internalAction,
|
|
6
|
-
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
7
|
-
import { ConvexError, v } from "convex/values";
|
|
8
|
-
import { internal } from "../../_generated/api";
|
|
9
|
-
import { credential } from "../../connections/actions/credentials";
|
|
10
|
-
import { validateExpo } from "../../connections/actions/expo";
|
|
11
|
-
import {
|
|
12
|
-
GitHubError,
|
|
13
|
-
githubRequest,
|
|
14
|
-
githubToken,
|
|
15
|
-
} from "../../github/actions/tokens";
|
|
16
|
-
import {
|
|
17
|
-
ManagementError,
|
|
18
|
-
management,
|
|
19
|
-
} from "../../previews/token/actions/management";
|
|
20
|
-
import { deleteArgs } from "../validator";
|
|
21
|
-
import {
|
|
22
|
-
ExpoTokenDeletionUnsupported,
|
|
23
|
-
deleteExpo,
|
|
24
|
-
findExpo,
|
|
25
|
-
verifyExpo,
|
|
26
|
-
} from "./expo";
|
|
27
|
-
|
|
28
|
-
export const remove = internalAction({
|
|
29
|
-
args: { ...identityFields, ...deleteArgs },
|
|
30
|
-
returns: v.null(),
|
|
31
|
-
handler: async (ctx, { userId, appId }): Promise<null> => {
|
|
32
|
-
const identity = { userId, appId };
|
|
33
|
-
const { until, resuming, pending, expoManual } = await ctx.runMutation(
|
|
34
|
-
internal.apps.operations.internal.begin,
|
|
35
|
-
{ ...identity, kind: "delete" },
|
|
36
|
-
);
|
|
37
|
-
let started = false;
|
|
38
|
-
const resume = (
|
|
39
|
-
provider: "github" | "convex" | "expo",
|
|
40
|
-
accountId: string,
|
|
41
|
-
) => {
|
|
42
|
-
if (pending?.provider !== provider) return undefined;
|
|
43
|
-
if (pending.accountId !== accountId)
|
|
44
|
-
throw new ConvexError(
|
|
45
|
-
`Reconnect the original ${provider} account to finish deleting this app.`,
|
|
46
|
-
);
|
|
47
|
-
return pending;
|
|
48
|
-
};
|
|
49
|
-
const deleting = (
|
|
50
|
-
provider: "github" | "convex" | "expo",
|
|
51
|
-
accountId: string,
|
|
52
|
-
receipt?: string,
|
|
53
|
-
) =>
|
|
54
|
-
ctx.runMutation(internal.apps.operations.internal.deletingResource, {
|
|
55
|
-
...identity,
|
|
56
|
-
until,
|
|
57
|
-
pending: { provider, accountId, ...(receipt ? { receipt } : {}) },
|
|
58
|
-
});
|
|
59
|
-
const forget = (provider: "github" | "convex" | "expo") =>
|
|
60
|
-
ctx.runMutation(internal.apps.operations.internal.forget, {
|
|
61
|
-
...identity,
|
|
62
|
-
until,
|
|
63
|
-
provider,
|
|
64
|
-
});
|
|
65
|
-
try {
|
|
66
|
-
const linked = await ctx.runQuery(
|
|
67
|
-
internal.apps.operations.internal.linked,
|
|
68
|
-
identity,
|
|
69
|
-
);
|
|
70
|
-
// Preflight every provider before deleting anything. Missing access is never success.
|
|
71
|
-
let github:
|
|
72
|
-
| { token: string; path: string; accountId: string; absent: boolean }
|
|
73
|
-
| undefined;
|
|
74
|
-
if (linked.githubRepo) {
|
|
75
|
-
const app = await ctx.runQuery(internal.apps.internal.githubApp, {
|
|
76
|
-
appId,
|
|
77
|
-
});
|
|
78
|
-
if (!app)
|
|
79
|
-
throw new ConvexError(
|
|
80
|
-
"Reconnect the GitHub account that owns this app before deleting it.",
|
|
81
|
-
);
|
|
82
|
-
const repository = `${app.githubOwner}/${app.githubRepo}`;
|
|
83
|
-
const retry = resume("github", app.githubOwner);
|
|
84
|
-
// An installation-wide token remains usable after this repository is deleted.
|
|
85
|
-
const token = await githubToken(
|
|
86
|
-
ctx,
|
|
87
|
-
app.installationId,
|
|
88
|
-
["administration:write", "contents:read", "actions:read"],
|
|
89
|
-
retry ? undefined : repository,
|
|
90
|
-
);
|
|
91
|
-
const path = `/repos/${repository}`;
|
|
92
|
-
let absent = false;
|
|
93
|
-
try {
|
|
94
|
-
const repo = await githubRequest<{
|
|
95
|
-
full_name: string;
|
|
96
|
-
description: string;
|
|
97
|
-
}>(token, path);
|
|
98
|
-
if (
|
|
99
|
-
repo.full_name.toLowerCase() !== repository.toLowerCase() ||
|
|
100
|
-
repo.description !== `Disposabl app ${appId}`
|
|
101
|
-
)
|
|
102
|
-
throw new ConvexError(
|
|
103
|
-
"The GitHub repository does not match this app. No resources were deleted.",
|
|
104
|
-
);
|
|
105
|
-
} catch (error) {
|
|
106
|
-
if (!retry || !(error instanceof GitHubError) || error.status !== 404)
|
|
107
|
-
throw error;
|
|
108
|
-
await githubRequest(token, "/installation/repositories?per_page=1");
|
|
109
|
-
absent = true;
|
|
110
|
-
}
|
|
111
|
-
if (!absent) {
|
|
112
|
-
for (let page = 1; ; page++) {
|
|
113
|
-
const releases = await githubRequest<
|
|
114
|
-
{ draft: boolean; prerelease: boolean }[]
|
|
115
|
-
>(token, `${path}/releases?per_page=100&page=${page}`);
|
|
116
|
-
if (
|
|
117
|
-
releases.some((release) => !release.draft && !release.prerelease)
|
|
118
|
-
)
|
|
119
|
-
throw new ConvexError(
|
|
120
|
-
"Apps with production releases cannot be deleted.",
|
|
121
|
-
);
|
|
122
|
-
if (releases.length < 100) break;
|
|
123
|
-
}
|
|
124
|
-
for (const status of [
|
|
125
|
-
"queued",
|
|
126
|
-
"in_progress",
|
|
127
|
-
"waiting",
|
|
128
|
-
"pending",
|
|
129
|
-
"requested",
|
|
130
|
-
]) {
|
|
131
|
-
const runs = await githubRequest<{ total_count: number }>(
|
|
132
|
-
token,
|
|
133
|
-
`${path}/actions/runs?status=${status}&per_page=1`,
|
|
134
|
-
);
|
|
135
|
-
if (runs.total_count)
|
|
136
|
-
throw new ConvexError(
|
|
137
|
-
"Wait for this app's GitHub Actions to finish before deleting it.",
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
github = { token, path, accountId: app.githubOwner, absent };
|
|
142
|
-
}
|
|
143
|
-
let convex:
|
|
144
|
-
| {
|
|
145
|
-
token: string;
|
|
146
|
-
projectId: number;
|
|
147
|
-
accountId: string;
|
|
148
|
-
absent: boolean;
|
|
149
|
-
}
|
|
150
|
-
| undefined;
|
|
151
|
-
if (linked.convexProjectId !== undefined) {
|
|
152
|
-
const connection = await credential(ctx, userId, "convex");
|
|
153
|
-
const retry = resume("convex", connection.accountId);
|
|
154
|
-
let absent = false;
|
|
155
|
-
try {
|
|
156
|
-
const project = await management<{
|
|
157
|
-
id: number;
|
|
158
|
-
name: string;
|
|
159
|
-
teamId: number;
|
|
160
|
-
}>(connection.token, `/projects/${linked.convexProjectId}`);
|
|
161
|
-
if (
|
|
162
|
-
project.id !== linked.convexProjectId ||
|
|
163
|
-
String(project.teamId) !== connection.accountId ||
|
|
164
|
-
project.name !== `disposabl-${appId}`
|
|
165
|
-
)
|
|
166
|
-
throw new ConvexError(
|
|
167
|
-
"The Convex project does not match this app and connected team.",
|
|
168
|
-
);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
if (
|
|
171
|
-
!retry ||
|
|
172
|
-
!(error instanceof ManagementError) ||
|
|
173
|
-
error.status !== 404
|
|
174
|
-
)
|
|
175
|
-
throw error;
|
|
176
|
-
await management(
|
|
177
|
-
connection.token,
|
|
178
|
-
`/teams/${connection.accountId}/projects?limit=1`,
|
|
179
|
-
);
|
|
180
|
-
absent = true;
|
|
181
|
-
}
|
|
182
|
-
convex = {
|
|
183
|
-
token: connection.token,
|
|
184
|
-
projectId: linked.convexProjectId,
|
|
185
|
-
accountId: connection.accountId,
|
|
186
|
-
absent,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
if (linked.expoAccountId === undefined && linked.githubRepo) {
|
|
190
|
-
const app = await ctx.runQuery(internal.apps.internal.get, identity);
|
|
191
|
-
if (
|
|
192
|
-
app.platforms.some(
|
|
193
|
-
(platform) => platform === "android" || platform === "ios",
|
|
194
|
-
)
|
|
195
|
-
)
|
|
196
|
-
throw new ConvexError(
|
|
197
|
-
"This older app has no recorded Expo ownership. Link its original Expo project before deleting it.",
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
let expo:
|
|
201
|
-
| {
|
|
202
|
-
token: string;
|
|
203
|
-
projectId?: string;
|
|
204
|
-
accountId: string;
|
|
205
|
-
receipt?: string;
|
|
206
|
-
projectUrl: string;
|
|
207
|
-
}
|
|
208
|
-
| undefined;
|
|
209
|
-
if (linked.expoAccountId || linked.expoProjectId) {
|
|
210
|
-
const connection = await credential(ctx, userId, "expo");
|
|
211
|
-
const retry = resume("expo", connection.accountId);
|
|
212
|
-
if (
|
|
213
|
-
linked.expoAccountId !== connection.accountId ||
|
|
214
|
-
!(await validateExpo(connection.token)).some(
|
|
215
|
-
(account) => account.id === connection.accountId,
|
|
216
|
-
)
|
|
217
|
-
)
|
|
218
|
-
throw new ConvexError(
|
|
219
|
-
"Reconnect the Expo account that owns this app.",
|
|
220
|
-
);
|
|
221
|
-
const project = await findExpo(
|
|
222
|
-
connection.token,
|
|
223
|
-
`@${connection.name}/app-${appId}`,
|
|
224
|
-
linked.expoProjectId,
|
|
225
|
-
);
|
|
226
|
-
if (project) verifyExpo(project, connection.accountId, appId);
|
|
227
|
-
if (!project && linked.expoProjectId && !retry && !expoManual)
|
|
228
|
-
throw new ConvexError(
|
|
229
|
-
"The linked Expo project is unavailable. Reconnect its owner before deleting this app.",
|
|
230
|
-
);
|
|
231
|
-
expo = {
|
|
232
|
-
token: connection.token,
|
|
233
|
-
projectId: project?.id,
|
|
234
|
-
accountId: connection.accountId,
|
|
235
|
-
receipt: retry?.receipt,
|
|
236
|
-
projectUrl: `https://expo.dev/accounts/${encodeURIComponent(project?.ownerAccount.name ?? connection.name)}/projects/${encodeURIComponent(project?.slug ?? `app-${appId}`)}/settings/advanced`,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
started = true;
|
|
240
|
-
let manualExpoDeletion = false;
|
|
241
|
-
if (expo) {
|
|
242
|
-
// Resume the receipt even if Expo has already removed the project from lookup.
|
|
243
|
-
if (expo.projectId || expo.receipt) {
|
|
244
|
-
await deleting("expo", expo.accountId, expo.receipt);
|
|
245
|
-
try {
|
|
246
|
-
await deleteExpo(
|
|
247
|
-
expo.token,
|
|
248
|
-
expo.projectId ?? linked.expoProjectId!,
|
|
249
|
-
expo.receipt,
|
|
250
|
-
async (receipt) => {
|
|
251
|
-
await deleting("expo", expo.accountId, receipt);
|
|
252
|
-
},
|
|
253
|
-
);
|
|
254
|
-
} catch (error) {
|
|
255
|
-
if (!(error instanceof ExpoTokenDeletionUnsupported)) throw error;
|
|
256
|
-
await ctx.runMutation(
|
|
257
|
-
internal.apps.operations.internal.requireExpoDeletion,
|
|
258
|
-
{
|
|
259
|
-
...identity,
|
|
260
|
-
until,
|
|
261
|
-
projectId: expo.projectId ?? linked.expoProjectId!,
|
|
262
|
-
},
|
|
263
|
-
);
|
|
264
|
-
manualExpoDeletion = true;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (!manualExpoDeletion) await forget("expo");
|
|
268
|
-
}
|
|
269
|
-
if (github) {
|
|
270
|
-
await deleting("github", github.accountId);
|
|
271
|
-
if (!github.absent)
|
|
272
|
-
await githubRequest(github.token, github.path, undefined, "DELETE");
|
|
273
|
-
await forget("github");
|
|
274
|
-
}
|
|
275
|
-
if (convex) {
|
|
276
|
-
await deleting("convex", convex.accountId);
|
|
277
|
-
if (!convex.absent)
|
|
278
|
-
await management(
|
|
279
|
-
convex.token,
|
|
280
|
-
`/projects/${convex.projectId}/delete`,
|
|
281
|
-
{},
|
|
282
|
-
);
|
|
283
|
-
await forget("convex");
|
|
284
|
-
}
|
|
285
|
-
if (manualExpoDeletion && expo) {
|
|
286
|
-
await deleting("expo", expo.accountId);
|
|
287
|
-
throw new ConvexError({
|
|
288
|
-
code: "expo_manual_delete_required",
|
|
289
|
-
appId,
|
|
290
|
-
projectId: expo.projectId ?? linked.expoProjectId!,
|
|
291
|
-
projectUrl: expo.projectUrl,
|
|
292
|
-
message:
|
|
293
|
-
"GitHub and Convex cleanup is complete. Open this Expo project's settings, sign in to Expo if needed, and delete the project there. Then retry Disposabl deletion to verify cleanup and remove the app record. Disposabl never asks for your Expo password.",
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
while (
|
|
297
|
-
!(await ctx.runMutation(internal.apps.operations.internal.erase, {
|
|
298
|
-
...identity,
|
|
299
|
-
until,
|
|
300
|
-
}))
|
|
301
|
-
) {
|
|
302
|
-
/* Delete previews in bounded batches. */
|
|
303
|
-
}
|
|
304
|
-
return null;
|
|
305
|
-
} catch (error) {
|
|
306
|
-
await ctx.runMutation(internal.apps.operations.internal.finish, {
|
|
307
|
-
...identity,
|
|
308
|
-
until,
|
|
309
|
-
retryDelete: started || resuming,
|
|
310
|
-
});
|
|
311
|
-
if (error instanceof ConvexError) throw error;
|
|
312
|
-
throw new ConvexError(
|
|
313
|
-
"App deletion could not finish. Check your connected accounts, then retry apps delete with --dangerously-delete-app. The app record has been kept.",
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
identityFields,
|
|
3
|
-
internalAction,
|
|
4
|
-
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
5
|
-
import { internal } from "../../_generated/api";
|
|
6
|
-
import { appArgs, appResult } from "../../validator";
|
|
7
|
-
import { ConvexError } from "convex/values";
|
|
8
|
-
import type { Infer } from "convex/values";
|
|
9
|
-
type AppResult = Infer<typeof appResult>;
|
|
10
|
-
|
|
11
|
-
export const create = internalAction({
|
|
12
|
-
platforms: true,
|
|
13
|
-
args: { ...identityFields, ...appArgs },
|
|
14
|
-
returns: appResult,
|
|
15
|
-
handler: async (ctx, args): Promise<AppResult> => {
|
|
16
|
-
const connections = await ctx.runQuery(
|
|
17
|
-
internal.connections.internal.status,
|
|
18
|
-
{ userId: args.userId },
|
|
19
|
-
);
|
|
20
|
-
if (!connections.ready)
|
|
21
|
-
throw new ConvexError(
|
|
22
|
-
"Connect GitHub and Convex at https://www.disposabl.dev/dashboard/connections, then retry setup. Your login remains active.",
|
|
23
|
-
);
|
|
24
|
-
// Return the UUID before external setup so the CLI can save it and resume safely.
|
|
25
|
-
return ctx.runMutation(internal.apps.internal.insert, {
|
|
26
|
-
...args,
|
|
27
|
-
appId: crypto.randomUUID(),
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
identityFields,
|
|
3
|
-
internalAction,
|
|
4
|
-
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
5
|
-
import { v } from "convex/values";
|
|
6
|
-
import { internal } from "../../_generated/api";
|
|
7
|
-
import { deleteArgs } from "../validator";
|
|
8
|
-
|
|
9
|
-
export const remove = internalAction({
|
|
10
|
-
platforms: true,
|
|
11
|
-
args: { ...identityFields, ...deleteArgs },
|
|
12
|
-
returns: v.null(),
|
|
13
|
-
handler: async (ctx, args): Promise<null> =>
|
|
14
|
-
ctx.runAction(internal.apps.actions.cleanup.remove, args),
|
|
15
|
-
});
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use node";
|
|
2
|
-
|
|
3
|
-
import { ConvexError } from "convex/values";
|
|
4
|
-
|
|
5
|
-
type Project = {
|
|
6
|
-
id: string;
|
|
7
|
-
slug: string;
|
|
8
|
-
ownerAccount: { id: string; name: string };
|
|
9
|
-
};
|
|
10
|
-
type Receipt = { id: string; state: string; willRetry: boolean };
|
|
11
|
-
const fields = "id slug ownerAccount { id name }";
|
|
12
|
-
export async function expoRequest<T>(
|
|
13
|
-
token: string,
|
|
14
|
-
query: string,
|
|
15
|
-
variables: Record<string, unknown>,
|
|
16
|
-
): Promise<T> {
|
|
17
|
-
const response = await fetch("https://api.expo.dev/graphql", {
|
|
18
|
-
method: "POST",
|
|
19
|
-
redirect: "error",
|
|
20
|
-
signal: AbortSignal.timeout(30_000),
|
|
21
|
-
headers: {
|
|
22
|
-
Authorization: `Bearer ${token}`,
|
|
23
|
-
"Content-Type": "application/json",
|
|
24
|
-
},
|
|
25
|
-
body: JSON.stringify({ query, variables }),
|
|
26
|
-
});
|
|
27
|
-
if (!response.ok)
|
|
28
|
-
throw new ConvexError(`Expo request failed (${response.status}).`);
|
|
29
|
-
const result = (await response.json()) as {
|
|
30
|
-
data?: T;
|
|
31
|
-
errors?: { message?: string; extensions?: { errorCode?: string } }[];
|
|
32
|
-
};
|
|
33
|
-
for (const error of result.errors ?? []) {
|
|
34
|
-
if (error.extensions?.errorCode === "SUDO_MODE_REQUIRED")
|
|
35
|
-
throw new ExpoTokenDeletionUnsupported("SUDO_MODE_REQUIRED");
|
|
36
|
-
if (
|
|
37
|
-
error.message ===
|
|
38
|
-
"Only regular user and SSO user access to this API is supported"
|
|
39
|
-
)
|
|
40
|
-
throw new ExpoTokenDeletionUnsupported("USER_SESSION_REQUIRED");
|
|
41
|
-
}
|
|
42
|
-
if (result.errors?.length) {
|
|
43
|
-
if (
|
|
44
|
-
result.errors.every(
|
|
45
|
-
(error) => error.extensions?.errorCode === "EXPERIENCE_NOT_FOUND",
|
|
46
|
-
)
|
|
47
|
-
)
|
|
48
|
-
throw new ExpoNotFound();
|
|
49
|
-
throw new ConvexError(
|
|
50
|
-
"Expo could not complete this request. Check your token and project permissions.",
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
if (!result.data) throw new ConvexError("Expo returned no project details.");
|
|
54
|
-
return result.data;
|
|
55
|
-
}
|
|
56
|
-
export class ExpoTokenDeletionUnsupported extends Error {
|
|
57
|
-
constructor(
|
|
58
|
-
readonly providerCode: "SUDO_MODE_REQUIRED" | "USER_SESSION_REQUIRED",
|
|
59
|
-
) {
|
|
60
|
-
super("Expo rejected project deletion with an access token.");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
class ExpoNotFound extends Error {}
|
|
64
|
-
export async function findExpo(
|
|
65
|
-
token: string,
|
|
66
|
-
fullName: string,
|
|
67
|
-
projectId?: string,
|
|
68
|
-
) {
|
|
69
|
-
try {
|
|
70
|
-
const data = projectId
|
|
71
|
-
? await expoRequest<{ app: { project: Project } }>(
|
|
72
|
-
token,
|
|
73
|
-
`query($id: String!) { app { project: byId(appId: $id) { ${fields} } } }`,
|
|
74
|
-
{ id: projectId },
|
|
75
|
-
)
|
|
76
|
-
: await expoRequest<{ app: { project: Project } }>(
|
|
77
|
-
token,
|
|
78
|
-
`query($name: String!) { app { project: byFullName(fullName: $name) { ${fields} } } }`,
|
|
79
|
-
{ name: fullName },
|
|
80
|
-
);
|
|
81
|
-
if (!data.app.project)
|
|
82
|
-
throw new ConvexError("Expo returned no project details.");
|
|
83
|
-
return data.app.project;
|
|
84
|
-
} catch (error) {
|
|
85
|
-
if (error instanceof ExpoNotFound) return null;
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export function verifyExpo(project: Project, accountId: string, appId: string) {
|
|
90
|
-
if (project.ownerAccount.id !== accountId || project.slug !== `app-${appId}`)
|
|
91
|
-
throw new ConvexError(
|
|
92
|
-
"Reconnect the Expo account that owns this app. The linked project must match this app's UUID.",
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
export async function ensureExpo(
|
|
96
|
-
token: string,
|
|
97
|
-
accountId: string,
|
|
98
|
-
owner: string,
|
|
99
|
-
appId: string,
|
|
100
|
-
saved?: string,
|
|
101
|
-
) {
|
|
102
|
-
const fullName = `@${owner}/app-${appId}`;
|
|
103
|
-
let project = await findExpo(token, fullName, saved);
|
|
104
|
-
if (!project) {
|
|
105
|
-
if (saved)
|
|
106
|
-
throw new ConvexError(
|
|
107
|
-
"The linked Expo project is unavailable. Reconnect its owner before continuing.",
|
|
108
|
-
);
|
|
109
|
-
try {
|
|
110
|
-
const created = await expoRequest<{ app: { createApp: { id: string } } }>(
|
|
111
|
-
token,
|
|
112
|
-
"mutation($input: AppInput!) { app { createApp(appInput: $input) { id } } }",
|
|
113
|
-
{ input: { accountId, projectName: `app-${appId}` } },
|
|
114
|
-
);
|
|
115
|
-
project = await findExpo(token, fullName, created.app.createApp.id);
|
|
116
|
-
} catch (error) {
|
|
117
|
-
project = await findExpo(token, fullName);
|
|
118
|
-
if (!project) throw error;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (!project)
|
|
122
|
-
throw new ConvexError("Expo project creation is incomplete. Retry setup.");
|
|
123
|
-
verifyExpo(project, accountId, appId);
|
|
124
|
-
return project;
|
|
125
|
-
}
|
|
126
|
-
export async function deleteExpo(
|
|
127
|
-
token: string,
|
|
128
|
-
projectId: string,
|
|
129
|
-
savedReceipt: string | undefined,
|
|
130
|
-
saveReceipt: (id: string) => Promise<void>,
|
|
131
|
-
) {
|
|
132
|
-
let receipt: Receipt;
|
|
133
|
-
if (savedReceipt) {
|
|
134
|
-
const data = await expoRequest<{
|
|
135
|
-
backgroundJobReceipt: { byId: Receipt | null };
|
|
136
|
-
}>(
|
|
137
|
-
token,
|
|
138
|
-
"query($id: ID!) { backgroundJobReceipt { byId(id: $id) { id state willRetry } } }",
|
|
139
|
-
{ id: savedReceipt },
|
|
140
|
-
);
|
|
141
|
-
if (!data.backgroundJobReceipt.byId)
|
|
142
|
-
throw new ConvexError(
|
|
143
|
-
"Expo deletion receipt is unavailable. Reconnect the owning account.",
|
|
144
|
-
);
|
|
145
|
-
receipt = data.backgroundJobReceipt.byId;
|
|
146
|
-
} else {
|
|
147
|
-
receipt = (
|
|
148
|
-
await expoRequest<{ app: { scheduleAppDeletion: Receipt } }>(
|
|
149
|
-
token,
|
|
150
|
-
"mutation($id: ID!) { app { scheduleAppDeletion(appId: $id) { id state willRetry } } }",
|
|
151
|
-
{ id: projectId },
|
|
152
|
-
)
|
|
153
|
-
).app.scheduleAppDeletion;
|
|
154
|
-
await saveReceipt(receipt.id);
|
|
155
|
-
}
|
|
156
|
-
const deadline = Date.now() + 90_000;
|
|
157
|
-
while (receipt.state !== "SUCCESS") {
|
|
158
|
-
if (receipt.state === "FAILURE" && !receipt.willRetry)
|
|
159
|
-
throw new ConvexError(
|
|
160
|
-
"Expo project deletion failed. Check your Expo account and retry apps delete.",
|
|
161
|
-
);
|
|
162
|
-
if (Date.now() >= deadline)
|
|
163
|
-
throw new ConvexError(
|
|
164
|
-
"Expo is still deleting the project. Retry apps delete to finish cleanup.",
|
|
165
|
-
);
|
|
166
|
-
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
167
|
-
const data = await expoRequest<{
|
|
168
|
-
backgroundJobReceipt: { byId: Receipt | null };
|
|
169
|
-
}>(
|
|
170
|
-
token,
|
|
171
|
-
"query($id: ID!) { backgroundJobReceipt { byId(id: $id) { id state willRetry } } }",
|
|
172
|
-
{ id: receipt.id },
|
|
173
|
-
);
|
|
174
|
-
if (!data.backgroundJobReceipt.byId)
|
|
175
|
-
throw new ConvexError(
|
|
176
|
-
"Expo deletion could not be confirmed. Retry apps delete.",
|
|
177
|
-
);
|
|
178
|
-
receipt = data.backgroundJobReceipt.byId;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use node";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
identityFields,
|
|
5
|
-
internalAction,
|
|
6
|
-
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
7
|
-
import { v } from "convex/values";
|
|
8
|
-
import { internal } from "../../_generated/api";
|
|
9
|
-
import { credential } from "../../connections/actions/credentials";
|
|
10
|
-
import {
|
|
11
|
-
ensureProject,
|
|
12
|
-
management,
|
|
13
|
-
} from "../../previews/token/actions/management";
|
|
14
|
-
|
|
15
|
-
export const setup = internalAction({
|
|
16
|
-
args: { ...identityFields, appId: v.string() },
|
|
17
|
-
returns: v.number(),
|
|
18
|
-
handler: async (ctx, args): Promise<number> => {
|
|
19
|
-
const saved = await ctx.runQuery(internal.apps.internal.project, args);
|
|
20
|
-
const { token, accountId: teamId } = await credential(
|
|
21
|
-
ctx,
|
|
22
|
-
args.userId,
|
|
23
|
-
"convex",
|
|
24
|
-
);
|
|
25
|
-
if (saved !== null) {
|
|
26
|
-
const projects = await management<{ items: { id: number }[] }>(
|
|
27
|
-
token,
|
|
28
|
-
`/teams/${teamId}/projects?q=${encodeURIComponent(`disposabl-${args.appId}`)}&limit=100`,
|
|
29
|
-
);
|
|
30
|
-
if (!projects.items.some((project) => project.id === saved))
|
|
31
|
-
throw new Error(
|
|
32
|
-
"Reconnect the Convex team that owns this app before continuing setup.",
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
const projectId = saved ?? (await ensureProject(token, teamId, args.appId));
|
|
36
|
-
if (saved === null)
|
|
37
|
-
await ctx.runMutation(internal.apps.internal.saveProject, {
|
|
38
|
-
...args,
|
|
39
|
-
projectId,
|
|
40
|
-
});
|
|
41
|
-
await ctx.runAction(internal.github.actions.provision.run, args);
|
|
42
|
-
await ctx.runAction(internal.github.actions.secrets.configure, {
|
|
43
|
-
...args,
|
|
44
|
-
projectId,
|
|
45
|
-
});
|
|
46
|
-
return projectId;
|
|
47
|
-
},
|
|
48
|
-
});
|