create-disposabl-app 0.8.10 → 0.8.11

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 (66) hide show
  1. package/README.md +8 -1
  2. package/dist/disposabl.js +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/templates/default/bun.lock +1 -7
  5. package/dist/templates/default/packages/backend/README.md +4 -8
  6. package/dist/templates/default/packages/backend/convex/_generated/api.d.ts +0 -67
  7. package/dist/templates/default/packages/backend/convex/_generated/server.d.ts +0 -9
  8. package/dist/templates/default/packages/backend/convex/convex.config.ts +0 -11
  9. package/dist/templates/default/packages/backend/convex/http.ts +1 -9
  10. package/dist/templates/default/packages/backend/convex/schema.ts +1 -70
  11. package/dist/templates/default/packages/backend/generated/openapi.json +1 -1262
  12. package/dist/templates/default/packages/backend/generated/pages.json +0 -4
  13. package/dist/templates/default/packages/backend/generated/platforms.ts +2 -20
  14. package/dist/templates/default/packages/backend/package.json +1 -7
  15. package/dist/templates/default/packages/skill/SKILL.md +5 -5
  16. package/dist/templates/default/packages/skill/references/delivery.md +1 -1
  17. package/package.json +1 -1
  18. package/dist/templates/default/packages/backend/convex/apps/actions/cleanup.ts +0 -317
  19. package/dist/templates/default/packages/backend/convex/apps/actions/create.ts +0 -30
  20. package/dist/templates/default/packages/backend/convex/apps/actions/delete.ts +0 -15
  21. package/dist/templates/default/packages/backend/convex/apps/actions/expo.ts +0 -180
  22. package/dist/templates/default/packages/backend/convex/apps/actions/setup.ts +0 -48
  23. package/dist/templates/default/packages/backend/convex/apps/internal.ts +0 -211
  24. package/dist/templates/default/packages/backend/convex/apps/operations/internal.ts +0 -239
  25. package/dist/templates/default/packages/backend/convex/apps/validator.ts +0 -23
  26. package/dist/templates/default/packages/backend/convex/connections/actions/credentials.ts +0 -56
  27. package/dist/templates/default/packages/backend/convex/connections/actions/expo.ts +0 -79
  28. package/dist/templates/default/packages/backend/convex/connections/actions/github.ts +0 -119
  29. package/dist/templates/default/packages/backend/convex/connections/actions/oauth.ts +0 -128
  30. package/dist/templates/default/packages/backend/convex/connections/index.ts +0 -80
  31. package/dist/templates/default/packages/backend/convex/connections/internal.ts +0 -147
  32. package/dist/templates/default/packages/backend/convex/connections/validator.ts +0 -35
  33. package/dist/templates/default/packages/backend/convex/downloads/action.ts +0 -136
  34. package/dist/templates/default/packages/backend/convex/downloads/http.ts +0 -32
  35. package/dist/templates/default/packages/backend/convex/downloads/internal.ts +0 -58
  36. package/dist/templates/default/packages/backend/convex/github/actions/http.ts +0 -69
  37. package/dist/templates/default/packages/backend/convex/github/actions/internal.ts +0 -196
  38. package/dist/templates/default/packages/backend/convex/github/actions/oidc.ts +0 -75
  39. package/dist/templates/default/packages/backend/convex/github/actions/provision.ts +0 -76
  40. package/dist/templates/default/packages/backend/convex/github/actions/secrets.ts +0 -180
  41. package/dist/templates/default/packages/backend/convex/github/actions/signing.ts +0 -41
  42. package/dist/templates/default/packages/backend/convex/github/actions/tokens.ts +0 -145
  43. package/dist/templates/default/packages/backend/convex/github/identityCache.ts +0 -54
  44. package/dist/templates/default/packages/backend/convex/github/internal.ts +0 -33
  45. package/dist/templates/default/packages/backend/convex/previews/internal.ts +0 -257
  46. package/dist/templates/default/packages/backend/convex/previews/token/actions/create.ts +0 -83
  47. package/dist/templates/default/packages/backend/convex/previews/token/actions/management.ts +0 -182
  48. package/dist/templates/default/packages/backend/convex/previews/token/internal.ts +0 -32
  49. package/dist/templates/default/packages/backend/convex/releases/internal.ts +0 -28
  50. package/dist/templates/default/packages/backend/convex/validator.ts +0 -87
  51. package/dist/templates/default/packages/sdk/src/generated/client/client.gen.ts +0 -300
  52. package/dist/templates/default/packages/sdk/src/generated/client/index.ts +0 -27
  53. package/dist/templates/default/packages/sdk/src/generated/client/types.gen.ts +0 -238
  54. package/dist/templates/default/packages/sdk/src/generated/client/utils.gen.ts +0 -337
  55. package/dist/templates/default/packages/sdk/src/generated/client.gen.ts +0 -28
  56. package/dist/templates/default/packages/sdk/src/generated/core/auth.gen.ts +0 -49
  57. package/dist/templates/default/packages/sdk/src/generated/core/bodySerializer.gen.ts +0 -96
  58. package/dist/templates/default/packages/sdk/src/generated/core/params.gen.ts +0 -188
  59. package/dist/templates/default/packages/sdk/src/generated/core/pathSerializer.gen.ts +0 -186
  60. package/dist/templates/default/packages/sdk/src/generated/core/queryKeySerializer.gen.ts +0 -134
  61. package/dist/templates/default/packages/sdk/src/generated/core/serverSentEvents.gen.ts +0 -265
  62. package/dist/templates/default/packages/sdk/src/generated/core/types.gen.ts +0 -126
  63. package/dist/templates/default/packages/sdk/src/generated/core/utils.gen.ts +0 -146
  64. package/dist/templates/default/packages/sdk/src/generated/index.ts +0 -63
  65. package/dist/templates/default/packages/sdk/src/generated/sdk.gen.ts +0 -234
  66. package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +0 -660
@@ -22,9 +22,5 @@
22
22
  {
23
23
  "path": "/dashboard/api-keys",
24
24
  "authenticated": true
25
- },
26
- {
27
- "path": "/dashboard/connections",
28
- "authenticated": true
29
25
  }
30
26
  ]
@@ -1,21 +1,3 @@
1
1
  // Generated by bun run generate. Do not edit.
2
- import * as m0 from "../convex/apps/internal";
3
- import * as m1 from "../convex/apps/operations/internal";
4
- import * as m2 from "../convex/connections/internal";
5
- import * as m3 from "../convex/downloads/internal";
6
- import * as m4 from "../convex/github/internal";
7
- import * as m5 from "../convex/previews/internal";
8
- import * as m6 from "../convex/previews/token/internal";
9
- import * as m7 from "../convex/releases/internal";
10
- import * as m8 from "../convex/users/internal";
11
- export default {
12
- "apps/internal": m0,
13
- "apps/operations/internal": m1,
14
- "connections/internal": m2,
15
- "downloads/internal": m3,
16
- "github/internal": m4,
17
- "previews/internal": m5,
18
- "previews/token/internal": m6,
19
- "releases/internal": m7,
20
- "users/internal": m8,
21
- };
2
+ import * as m0 from "../convex/users/internal";
3
+ export default { "users/internal": m0 };
@@ -16,20 +16,14 @@
16
16
  "@convex-dev/auth": "catalog:",
17
17
  "@convex-dev/mcp": "catalog:",
18
18
  "@convex-dev/static-hosting": "catalog:",
19
- "@convex-dev/workflow": "^0.4.10",
20
19
  "@disposabl/disposabl-kit": "workspace:*",
21
- "@octokit/rest": "^22.0.1",
22
- "@vercel/connect": "^2.5.2",
23
- "convex": "catalog:",
24
- "libsodium-wrappers": "^0.8.4",
25
- "node-forge": "^1.4.2"
20
+ "convex": "catalog:"
26
21
  },
27
22
  "devDependencies": {
28
23
  "@convex-dev/eslint-plugin": "^5.0.1",
29
24
  "@eslint/eslintrc": "^3.3.6",
30
25
  "@eslint/js": "^10.0.1",
31
26
  "@types/node": "^24.13.3",
32
- "@types/node-forge": "^1.3.14",
33
27
  "@typescript-eslint/eslint-plugin": "^8.66.0",
34
28
  "@typescript-eslint/parser": "^8.66.0",
35
29
  "@typescript/native": "npm:typescript@^7.0.2",
@@ -21,12 +21,10 @@ Before designing a new app, locate and read the `frontend-design` skill and use
21
21
 
22
22
  Create a separate Git branch and worktree for each change. In that worktree run `disposabl previews token create --configure .`, `bun install`, and `bun dev`. Implement the request and verify the actual behavior on the requested platforms. Commit and push the branch and open a pull request when the task authorizes delivery.
23
23
 
24
- For a newly generated app, publish its scaffold to `main` first so GitHub has the trusted publishing workflow. Setup configures `origin` for the provisioned repository. Then work on the requested features in an isolated branch:
24
+ A newly generated app already has an Initial commit. Publish its scaffold to `main` first so GitHub has the trusted publishing workflow. Setup configures `origin` for the provisioned repository. Then work on the requested features in an isolated branch:
25
25
 
26
26
  ```sh
27
27
  cd my-app
28
- git add .
29
- git commit -m "chore: initialize app"
30
28
  git push -u origin main
31
29
  git worktree add ../my-app-feature -b feat/first-version
32
30
  cd ../my-app-feature
@@ -35,9 +33,11 @@ bun install
35
33
  bun run dev
36
34
  ```
37
35
 
38
- The configured token is scoped to this worktree's development backend. Never copy another worktree's environment files or use a production deploy key for development. Commit implementation changes, push `feat/first-version`, and create the PR with `gh pr create`. Keep credentials in ignored environment files.
36
+ The configured token is scoped to this worktree's development backend. Never copy another worktree's environment files or use a production deploy key for development. Token provisioning or refresh alone does not deploy or require git operations. Keep credentials in ignored environment files. A branch push alone does not trigger deployment: a same-repository PR to `main` triggers the `pr-N` preview, and a push to `main` triggers production. Local development is separate; preview reports are tracked by head branch.
39
37
 
40
- After pushing the PR, run `disposabl previews get` in the worktree and check each requested platform's status and available preview, workflow, release, or download URLs. Wait for relevant builds or report failures; do not claim readiness without evidence. For Android, install the preview APK on the target and verify the requested behavior and authentication. Do not run `eas submit`. After an authorized merge, verify production status and actual URLs. If a platform or URL is missing, inspect the relevant workflow and report the gap.
38
+ For background delivery, hand a subagent a fixed, reviewed commit snapshot in an isolated worktree. Its brief must name the repository, branch, SHA, scope, PR base, required checks, push ownership, and expected result evidence. It pushes that snapshot and opens or updates the same-repository PR while the main agent continues separately. Never sweep concurrent edits or the index, or push later commits without a new handoff. Do not block implementation on push or PR creation.
39
+
40
+ After opening the PR, run `disposabl previews get` in the worktree and check each requested platform's status and available preview, workflow, release, or download URLs. Report the deployed SHA, checks, and each platform URL and status. Readiness requires successful CI and actual endpoint or device behavior; a provisioned development URL is not a hosted preview. For Android, install the preview APK on the target and verify the requested behavior and authentication. Do not run `eas submit`. After an authorized merge, verify production status and actual URLs. If a platform or URL is missing, inspect the relevant workflow and report the gap.
41
41
 
42
42
  Use `disposabl previews get --json` when an agent needs structured status. Query again as builds progress, respecting the host's PR watcher rules, and stop waiting when every requested platform has a terminal status. Inspect and repair failures instead of repeatedly polling an unchanged failure. After merging, run `disposabl releases get --appId <appId-from-disposabl.json>`; production results are separate from the worktree's preview. Install the production Android APK alongside its preview and verify login and saved data against the production backend. Store submission is not required for Android APK delivery. TestFlight is available only after Apple signing and App Store Connect submission credentials are configured.
43
43
 
@@ -15,7 +15,7 @@ Read before a first native build, a toolchain change, or a failed preview/produc
15
15
 
16
16
  ## Avoid repeating expensive work
17
17
 
18
- Diagnose independent platform failures in parallel when available, with separate owners and checkouts. Keep each device and browser session under one owner. Give a delivery delegate an observable success condition, such as an uploaded artifact or a verified login on its assigned device; a commit and local checks alone do not satisfy that condition. Batch related repairs before pushing, because PR concurrency can cancel running native builds. Keep source-commit validation when publishing so an old build cannot become the current release.
18
+ Diagnose independent platform failures in parallel when available, with separate owners and checkouts. Keep each device and browser session under one owner. Give a delivery delegate an observable success condition, such as an uploaded artifact or a verified login on its assigned device; a commit and local checks alone do not satisfy that condition. Batch related repairs before pushing, because PR concurrency can cancel running native builds. Use host PR watchers where applicable; do not busy poll. Hand off a new reviewed SHA before pushing subsequent changes. Keep source-commit validation when publishing so an old build cannot become the current release.
19
19
 
20
20
  Separate an application change from a starter/pipeline defect. Repair a reusable defect in the generator and the generated app. For a new repository, establish its trusted publishing workflow on `main` before the feature preview; later workflow changes must follow the repository's review and merge policy. Do not weaken workflow-source identity checks to bypass a mismatch.
21
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-disposabl-app",
3
- "version": "0.8.10",
3
+ "version": "0.8.11",
4
4
  "description": "Create a Disposabl app",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -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
- }