create-disposabl-app 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/disposabl.js +35 -4
- package/dist/index.js +1 -1
- package/dist/templates/default/.github/workflows/pipeline.yml +10 -10
- package/dist/templates/default/dev.ts +2 -1
- package/dist/templates/default/packages/backend/AGENTS.md +2 -0
- package/dist/templates/default/packages/backend/README.md +2 -2
- package/dist/templates/default/packages/backend/convex/_generated/api.d.ts +10 -0
- package/dist/templates/default/packages/backend/convex/apps/actions/cleanup.ts +295 -0
- package/dist/templates/default/packages/backend/convex/apps/actions/delete.ts +15 -0
- package/dist/templates/default/packages/backend/convex/apps/actions/expo.ts +174 -0
- package/dist/templates/default/packages/backend/convex/apps/internal.ts +4 -21
- package/dist/templates/default/packages/backend/convex/apps/operations/internal.ts +213 -0
- package/dist/templates/default/packages/backend/convex/apps/validator.ts +23 -0
- package/dist/templates/default/packages/backend/convex/connections/actions/github.ts +1 -3
- package/dist/templates/default/packages/backend/convex/connections/index.ts +8 -8
- package/dist/templates/default/packages/backend/convex/connections/internal.ts +1 -2
- package/dist/templates/default/packages/backend/convex/github/actions/internal.ts +6 -0
- package/dist/templates/default/packages/backend/convex/github/actions/secrets.ts +35 -2
- package/dist/templates/default/packages/backend/convex/github/actions/tokens.ts +6 -2
- package/dist/templates/default/packages/backend/convex/github/internal.ts +5 -4
- package/dist/templates/default/packages/backend/convex/previews/internal.ts +5 -5
- package/dist/templates/default/packages/backend/convex/previews/token/actions/create.ts +30 -19
- package/dist/templates/default/packages/backend/convex/previews/token/actions/management.ts +2 -1
- package/dist/templates/default/packages/backend/convex/schema.ts +10 -0
- package/dist/templates/default/packages/backend/generated/openapi.json +5 -2
- package/dist/templates/default/packages/backend/generated/platforms.ts +14 -12
- package/dist/templates/default/packages/cli/README.md +3 -1
- package/dist/templates/default/packages/cli/commands.ts +23 -2
- package/dist/templates/default/packages/cli/delete.ts +39 -0
- package/dist/templates/default/packages/disposabl-kit/server/lib/platform-spec.ts +10 -2
- package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +1 -0
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
paginationResultValidator,
|
|
9
9
|
} from "convex/server";
|
|
10
10
|
import { ConvexError, v, type Infer } from "convex/values";
|
|
11
|
+
import { assertActive } from "../apps/operations/internal";
|
|
11
12
|
import { ownedApp } from "../apps/internal";
|
|
12
13
|
import {
|
|
13
14
|
deployment,
|
|
@@ -173,6 +174,7 @@ export const finish = internalMutation({
|
|
|
173
174
|
/** Only the GitHub OIDC HTTP handler can report build outcomes. */
|
|
174
175
|
export const report = internalMutation({
|
|
175
176
|
args: {
|
|
177
|
+
...identityFields,
|
|
176
178
|
appId: v.string(),
|
|
177
179
|
githubOwner: v.string(),
|
|
178
180
|
githubRepo: v.string(),
|
|
@@ -184,12 +186,9 @@ export const report = internalMutation({
|
|
|
184
186
|
},
|
|
185
187
|
returns: v.null(),
|
|
186
188
|
handler: async (ctx, args) => {
|
|
187
|
-
const app = await ctx.
|
|
188
|
-
|
|
189
|
-
.withIndex("by_appId", (q) => q.eq("appId", args.appId))
|
|
190
|
-
.unique();
|
|
189
|
+
const app = await ownedApp(ctx, args.userId, args.appId);
|
|
190
|
+
assertActive(app);
|
|
191
191
|
if (
|
|
192
|
-
!app ||
|
|
193
192
|
app.githubOwner !== args.githubOwner ||
|
|
194
193
|
app.githubRepo !== args.githubRepo
|
|
195
194
|
)
|
|
@@ -221,6 +220,7 @@ export const report = internalMutation({
|
|
|
221
220
|
return null;
|
|
222
221
|
}
|
|
223
222
|
const {
|
|
223
|
+
userId: _user,
|
|
224
224
|
appId: _app,
|
|
225
225
|
githubOwner: _owner,
|
|
226
226
|
githubRepo: _repo,
|
|
@@ -30,25 +30,36 @@ export const create = internalAction({
|
|
|
30
30
|
deployKey: string;
|
|
31
31
|
}> => {
|
|
32
32
|
validateReference(args.reference);
|
|
33
|
-
|
|
34
|
-
await ctx.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
userId: args.userId,
|
|
41
|
-
appId: args.appId,
|
|
42
|
-
});
|
|
43
|
-
const { deployKey, ...deployment } = await ensureDevelopment(
|
|
44
|
-
(await credential(ctx, args.userId, "convex")).token,
|
|
45
|
-
projectId,
|
|
46
|
-
args.reference,
|
|
33
|
+
const identity = { userId: args.userId, appId: args.appId };
|
|
34
|
+
const { until } = await ctx.runMutation(
|
|
35
|
+
internal.apps.operations.internal.begin,
|
|
36
|
+
{
|
|
37
|
+
...identity,
|
|
38
|
+
kind: "setup",
|
|
39
|
+
},
|
|
47
40
|
);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
try {
|
|
42
|
+
await ctx.runMutation(internal.previews.internal.create, args);
|
|
43
|
+
const projectId = await ctx.runAction(internal.apps.actions.setup.setup, {
|
|
44
|
+
userId: args.userId,
|
|
45
|
+
appId: args.appId,
|
|
46
|
+
});
|
|
47
|
+
const { deployKey, ...deployment } = await ensureDevelopment(
|
|
48
|
+
(await credential(ctx, args.userId, "convex")).token,
|
|
49
|
+
projectId,
|
|
50
|
+
args.reference,
|
|
51
|
+
);
|
|
52
|
+
await ctx.runMutation(internal.previews.internal.finish, {
|
|
53
|
+
...args,
|
|
54
|
+
deployment,
|
|
55
|
+
});
|
|
56
|
+
return { appId: args.appId, ...deployment, deployKey };
|
|
57
|
+
} finally {
|
|
58
|
+
await ctx.runMutation(internal.apps.operations.internal.finish, {
|
|
59
|
+
...identity,
|
|
60
|
+
until,
|
|
61
|
+
retryDelete: false,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
53
64
|
},
|
|
54
65
|
});
|
|
@@ -19,7 +19,8 @@ export async function management<T>(
|
|
|
19
19
|
signal: AbortSignal.timeout(30_000),
|
|
20
20
|
});
|
|
21
21
|
if (!response.ok) throw new ManagementError(response.status);
|
|
22
|
-
|
|
22
|
+
const text = await response.text();
|
|
23
|
+
return (text ? JSON.parse(text) : undefined) as T;
|
|
23
24
|
}
|
|
24
25
|
/** Recover a project after a lost create response; names include the immutable app UUID. */
|
|
25
26
|
export async function ensureProject(
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineSchema, defineTable } from "convex/server";
|
|
2
2
|
import { v } from "convex/values";
|
|
3
|
+
import { pendingDelete } from "./apps/validator";
|
|
3
4
|
import { deployment, platform, releases } from "./validator";
|
|
4
5
|
|
|
5
6
|
export default defineSchema({
|
|
@@ -28,6 +29,15 @@ export default defineSchema({
|
|
|
28
29
|
githubOwner: v.optional(v.string()),
|
|
29
30
|
githubRepo: v.optional(v.string()),
|
|
30
31
|
convexProjectId: v.optional(v.number()),
|
|
32
|
+
expoProjectId: v.optional(v.string()),
|
|
33
|
+
expoAccountId: v.optional(v.union(v.string(), v.null())),
|
|
34
|
+
operation: v.optional(
|
|
35
|
+
v.object({
|
|
36
|
+
kind: v.union(v.literal("setup"), v.literal("delete")),
|
|
37
|
+
until: v.number(),
|
|
38
|
+
pending: v.optional(pendingDelete),
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
31
41
|
})
|
|
32
42
|
.index("by_appId", ["appId"])
|
|
33
43
|
.index("by_userId", ["userId"]),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"openapi": "3.1.0",
|
|
3
3
|
"info": {
|
|
4
4
|
"title": "Application API",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "2.0.0"
|
|
6
6
|
},
|
|
7
7
|
"security": [
|
|
8
8
|
{
|
|
@@ -131,9 +131,12 @@
|
|
|
131
131
|
"properties": {
|
|
132
132
|
"appId": {
|
|
133
133
|
"type": "string"
|
|
134
|
+
},
|
|
135
|
+
"dangerouslyDeleteApp": {
|
|
136
|
+
"const": true
|
|
134
137
|
}
|
|
135
138
|
},
|
|
136
|
-
"required": ["appId"],
|
|
139
|
+
"required": ["appId", "dangerouslyDeleteApp"],
|
|
137
140
|
"additionalProperties": false
|
|
138
141
|
}
|
|
139
142
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
// Generated by bun run generate. Do not edit.
|
|
2
2
|
import * as m0 from "../convex/apps/internal";
|
|
3
|
-
import * as m1 from "../convex/
|
|
4
|
-
import * as m2 from "../convex/
|
|
5
|
-
import * as m3 from "../convex/
|
|
6
|
-
import * as m4 from "../convex/previews/
|
|
7
|
-
import * as m5 from "../convex/
|
|
8
|
-
import * as m6 from "../convex/
|
|
3
|
+
import * as m1 from "../convex/apps/operations/internal";
|
|
4
|
+
import * as m2 from "../convex/connections/internal";
|
|
5
|
+
import * as m3 from "../convex/github/internal";
|
|
6
|
+
import * as m4 from "../convex/previews/internal";
|
|
7
|
+
import * as m5 from "../convex/previews/token/internal";
|
|
8
|
+
import * as m6 from "../convex/releases/internal";
|
|
9
|
+
import * as m7 from "../convex/users/internal";
|
|
9
10
|
export default {
|
|
10
11
|
"apps/internal": m0,
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"previews/
|
|
15
|
-
"
|
|
16
|
-
"
|
|
12
|
+
"apps/operations/internal": m1,
|
|
13
|
+
"connections/internal": m2,
|
|
14
|
+
"github/internal": m3,
|
|
15
|
+
"previews/internal": m4,
|
|
16
|
+
"previews/token/internal": m5,
|
|
17
|
+
"releases/internal": m6,
|
|
18
|
+
"users/internal": m7,
|
|
17
19
|
};
|
|
@@ -10,7 +10,7 @@ disposabl apps list --paginationOpts '{"numItems":20,"cursor":null}'
|
|
|
10
10
|
disposabl apps get --appId <uuid>
|
|
11
11
|
disposabl previews token create --configure .
|
|
12
12
|
disposabl previews get
|
|
13
|
-
disposabl apps delete --appId <uuid>
|
|
13
|
+
disposabl apps delete --appId <uuid> --dangerously-delete-app
|
|
14
14
|
disposabl logout
|
|
15
15
|
```
|
|
16
16
|
|
|
@@ -21,3 +21,5 @@ Save the returned app UUID as `appId` in `disposabl.json`. Preview commands read
|
|
|
21
21
|
Credentials live under `~/.config/disposabl` with restricted file permissions. `DISPOSABL_CONFIG_DIR` changes the local credential directory. `DISPOSABL_API_KEY` provides an automation credential. The service origin has no public override.
|
|
22
22
|
|
|
23
23
|
Use `--json` for machine-readable preview output. Other commands return JSON; `--help` lists their arguments.
|
|
24
|
+
|
|
25
|
+
App deletion permanently removes linked GitHub, Convex, and Expo projects, then previews and the app record. Apps with production releases cannot be deleted. Expo requires a signed-in user and password confirmation; the CLI opens the official EAS deletion flow when needed. API/MCP callers receive the project ID and must complete this Expo step before retrying. If cleanup is interrupted, run the same command again; keep the owning accounts connected until it finishes.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { completeExpoDeletion } from "./delete";
|
|
1
2
|
import { Command } from "commander";
|
|
2
3
|
import manifest from "./package.json";
|
|
3
4
|
import {
|
|
@@ -125,6 +126,7 @@ export async function runCli(
|
|
|
125
126
|
"--wait",
|
|
126
127
|
"Open Connections and continue when GitHub and Convex are connected",
|
|
127
128
|
);
|
|
129
|
+
const deleteApp = path === "/api/apps/delete";
|
|
128
130
|
const previewGet = path === "/api/previews/get";
|
|
129
131
|
const tokenCreate = path === "/api/previews/token/create";
|
|
130
132
|
if (previewGet)
|
|
@@ -151,6 +153,13 @@ export async function runCli(
|
|
|
151
153
|
}),
|
|
152
154
|
);
|
|
153
155
|
for (const field of fields) {
|
|
156
|
+
if (deleteApp && field.name === "dangerouslyDeleteApp") {
|
|
157
|
+
command.option(
|
|
158
|
+
"--dangerously-delete-app",
|
|
159
|
+
"Permanently delete this preview app and its GitHub, Convex and Expo projects",
|
|
160
|
+
);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
154
163
|
const flag = `--${field.name} <value>`;
|
|
155
164
|
if (
|
|
156
165
|
field.required &&
|
|
@@ -166,6 +175,10 @@ export async function runCli(
|
|
|
166
175
|
else command.option(flag, field.name);
|
|
167
176
|
}
|
|
168
177
|
command.action(async (options) => {
|
|
178
|
+
if (deleteApp && options.dangerouslyDeleteApp !== true)
|
|
179
|
+
throw new Error(
|
|
180
|
+
"Permanent deletion requires --dangerously-delete-app. Apps with production releases cannot be deleted.",
|
|
181
|
+
);
|
|
169
182
|
if ((previewGet || tokenCreate) && !options.appId) {
|
|
170
183
|
const config = JSON.parse(
|
|
171
184
|
await readFile(
|
|
@@ -186,7 +199,8 @@ export async function runCli(
|
|
|
186
199
|
.filter((field) => options[field.name] !== undefined)
|
|
187
200
|
.map((field) => [
|
|
188
201
|
field.name,
|
|
189
|
-
field.schema.type === "string"
|
|
202
|
+
field.schema.type === "string" ||
|
|
203
|
+
typeof options[field.name] === "boolean"
|
|
190
204
|
? options[field.name]
|
|
191
205
|
: JSON.parse(options[field.name]),
|
|
192
206
|
]),
|
|
@@ -201,7 +215,7 @@ export async function runCli(
|
|
|
201
215
|
fetch(target, {
|
|
202
216
|
method: method.toUpperCase(),
|
|
203
217
|
redirect: "error",
|
|
204
|
-
signal: AbortSignal.timeout(30_000),
|
|
218
|
+
signal: AbortSignal.timeout(deleteApp ? 300_000 : 30_000),
|
|
205
219
|
headers: {
|
|
206
220
|
Authorization: `Bearer ${await accessToken(base, refresh)}`,
|
|
207
221
|
"Content-Type": "application/json",
|
|
@@ -211,6 +225,13 @@ export async function runCli(
|
|
|
211
225
|
let result = await send();
|
|
212
226
|
if (result.status === 401 && !process.env.DISPOSABL_API_KEY)
|
|
213
227
|
result = await send(true);
|
|
228
|
+
if (deleteApp && result.status === 400) {
|
|
229
|
+
const body = await result.clone().json();
|
|
230
|
+
if (body.error?.code === "expo_delete_requires_login") {
|
|
231
|
+
await completeExpoDeletion(body.error.projectId);
|
|
232
|
+
result = await send();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
214
235
|
if (!result.ok)
|
|
215
236
|
throw new Error(
|
|
216
237
|
`API request failed (${result.status}): ${await result.text()}`,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
/** Expo requires a user session in sudo mode; access tokens cannot provide it. */
|
|
4
|
+
export async function completeExpoDeletion(projectId: unknown) {
|
|
5
|
+
if (
|
|
6
|
+
typeof projectId !== "string" ||
|
|
7
|
+
!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
|
8
|
+
projectId,
|
|
9
|
+
)
|
|
10
|
+
)
|
|
11
|
+
throw new Error("The service returned an invalid Expo project ID.");
|
|
12
|
+
const command = `bunx eas-cli@27.2.0 project:delete ${projectId}`;
|
|
13
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
14
|
+
throw new Error(
|
|
15
|
+
`Expo needs an interactive login and password confirmation. Run ${command}, then retry apps delete. Your app and remaining resources are retained.`,
|
|
16
|
+
);
|
|
17
|
+
console.error(
|
|
18
|
+
"Expo requires you to confirm deletion in your Expo account. Complete the following EAS prompts to continue.",
|
|
19
|
+
);
|
|
20
|
+
// EAS owns login, password confirmation and MFA. Do not pass the CI robot token.
|
|
21
|
+
const { EXPO_TOKEN: _token, ...env } = process.env;
|
|
22
|
+
await new Promise<void>((resolve, reject) => {
|
|
23
|
+
const child = spawn(
|
|
24
|
+
"bunx",
|
|
25
|
+
["eas-cli@27.2.0", "project:delete", projectId],
|
|
26
|
+
{ stdio: "inherit", env },
|
|
27
|
+
);
|
|
28
|
+
child.on("error", reject);
|
|
29
|
+
child.on("exit", (code) =>
|
|
30
|
+
code === 0
|
|
31
|
+
? resolve()
|
|
32
|
+
: reject(
|
|
33
|
+
new Error(
|
|
34
|
+
"Expo deletion was not completed. Retry apps delete when ready.",
|
|
35
|
+
),
|
|
36
|
+
),
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -56,6 +56,7 @@ export function createPlatforms(
|
|
|
56
56
|
)
|
|
57
57
|
throw new Error(`${id}: expected function kind, args and returns`);
|
|
58
58
|
const { userId, ...args } = fn.args;
|
|
59
|
+
if (!userId) throw new Error(`${id}: platform functions require userId`);
|
|
59
60
|
const type = fn.isQuery ? "query" : fn.isMutation ? "mutation" : "action";
|
|
60
61
|
spec.push({
|
|
61
62
|
name: id,
|
|
@@ -72,7 +73,7 @@ export function createPlatforms(
|
|
|
72
73
|
handler: async (ctx, input, user) => {
|
|
73
74
|
const params = {
|
|
74
75
|
...input,
|
|
75
|
-
|
|
76
|
+
userId: user.userId,
|
|
76
77
|
};
|
|
77
78
|
if (type === "query")
|
|
78
79
|
return ctx.runQuery(reference<"query">(id), params);
|
|
@@ -145,7 +146,14 @@ export function createPlatforms(
|
|
|
145
146
|
{ headers: { "Content-Type": "application/json" } },
|
|
146
147
|
);
|
|
147
148
|
} catch (error) {
|
|
148
|
-
if (error instanceof
|
|
149
|
+
if (error instanceof ConvexError)
|
|
150
|
+
return Response.json(
|
|
151
|
+
{
|
|
152
|
+
error: error.data,
|
|
153
|
+
},
|
|
154
|
+
{ status: 400 },
|
|
155
|
+
);
|
|
156
|
+
if (error instanceof SyntaxError)
|
|
149
157
|
return Response.json({ error: "invalid_request" }, { status: 400 });
|
|
150
158
|
console.error(error);
|
|
151
159
|
return Response.json({ error: "internal_error" }, { status: 500 });
|