create-disposabl-app 0.7.1 → 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 +4 -4
- 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
|
@@ -29,6 +29,7 @@ export const insert = internalMutation({
|
|
|
29
29
|
appId: args.appId,
|
|
30
30
|
name,
|
|
31
31
|
platforms,
|
|
32
|
+
expoAccountId: null,
|
|
32
33
|
});
|
|
33
34
|
return presentApp((await ctx.db.get("apps", id))!);
|
|
34
35
|
},
|
|
@@ -59,27 +60,7 @@ export const get = internalQuery({
|
|
|
59
60
|
handler: async (ctx, { userId, appId }) =>
|
|
60
61
|
presentApp(await ownedApp(ctx, userId, appId)),
|
|
61
62
|
});
|
|
62
|
-
|
|
63
|
-
platforms: true,
|
|
64
|
-
args: { ...identityFields, appId: v.string() },
|
|
65
|
-
returns: v.null(),
|
|
66
|
-
handler: async (ctx, { userId, appId }) => {
|
|
67
|
-
const app = await ownedApp(ctx, userId, appId);
|
|
68
|
-
for await (const preview of ctx.db
|
|
69
|
-
.query("previews")
|
|
70
|
-
.withIndex("by_appId_reference", (q) => q.eq("appId", appId))) {
|
|
71
|
-
await ctx.db.delete("previews", preview._id);
|
|
72
|
-
}
|
|
73
|
-
const production = await ctx.db
|
|
74
|
-
.query("appReleases")
|
|
75
|
-
.withIndex("by_appId", (q) => q.eq("appId", appId))
|
|
76
|
-
.unique();
|
|
77
|
-
if (production) await ctx.db.delete("appReleases", production._id);
|
|
78
|
-
await ctx.db.delete("apps", app._id);
|
|
79
|
-
return null;
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
export { remove as delete };
|
|
63
|
+
export { remove as delete } from "./actions/delete";
|
|
83
64
|
|
|
84
65
|
function assertAppId(appId: string) {
|
|
85
66
|
if (
|
|
@@ -120,6 +101,7 @@ export const githubApp = internalQuery({
|
|
|
120
101
|
githubOwner: v.string(),
|
|
121
102
|
githubRepo: v.string(),
|
|
122
103
|
installationId: v.string(),
|
|
104
|
+
userId: v.string(),
|
|
123
105
|
}),
|
|
124
106
|
),
|
|
125
107
|
handler: async (ctx, { appId }) => {
|
|
@@ -141,6 +123,7 @@ export const githubApp = internalQuery({
|
|
|
141
123
|
githubOwner: app.githubOwner,
|
|
142
124
|
githubRepo: app.githubRepo,
|
|
143
125
|
installationId,
|
|
126
|
+
userId: app.userId,
|
|
144
127
|
}
|
|
145
128
|
: null;
|
|
146
129
|
},
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import {
|
|
2
|
+
identityFields,
|
|
3
|
+
internalMutation,
|
|
4
|
+
internalQuery,
|
|
5
|
+
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
6
|
+
import { ConvexError, v } from "convex/values";
|
|
7
|
+
import type { Doc } from "../../_generated/dataModel";
|
|
8
|
+
import type { QueryCtx } from "../../_generated/server";
|
|
9
|
+
import { ownedApp } from "../internal";
|
|
10
|
+
import { pendingDelete, resources } from "../validator";
|
|
11
|
+
|
|
12
|
+
export function assertActive(app: Doc<"apps">) {
|
|
13
|
+
if (app.operation?.kind === "delete")
|
|
14
|
+
throw new ConvexError(
|
|
15
|
+
"App deletion is in progress. Retry apps delete to finish cleanup.",
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
async function assertPreviewOnly(ctx: Pick<QueryCtx, "db">, appId: string) {
|
|
19
|
+
const release = await ctx.db
|
|
20
|
+
.query("appReleases")
|
|
21
|
+
.withIndex("by_appId", (q) => q.eq("appId", appId))
|
|
22
|
+
.unique();
|
|
23
|
+
if (release)
|
|
24
|
+
throw new ConvexError("Apps with production releases cannot be deleted.");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// One lease prevents setup, deletion and production publishing from racing.
|
|
28
|
+
export const begin = internalMutation({
|
|
29
|
+
args: {
|
|
30
|
+
...identityFields,
|
|
31
|
+
appId: v.string(),
|
|
32
|
+
kind: v.union(v.literal("setup"), v.literal("delete")),
|
|
33
|
+
},
|
|
34
|
+
returns: v.object({
|
|
35
|
+
until: v.number(),
|
|
36
|
+
resuming: v.boolean(),
|
|
37
|
+
pending: v.optional(pendingDelete),
|
|
38
|
+
}),
|
|
39
|
+
handler: async (ctx, { userId, appId, kind }) => {
|
|
40
|
+
const app = await ownedApp(ctx, userId, appId);
|
|
41
|
+
if (kind === "setup") assertActive(app);
|
|
42
|
+
else await assertPreviewOnly(ctx, appId);
|
|
43
|
+
if (app.operation && app.operation.until > Date.now())
|
|
44
|
+
throw new ConvexError(
|
|
45
|
+
"This app has an operation in progress. Try again when it finishes.",
|
|
46
|
+
);
|
|
47
|
+
// Longer than Convex's maximum action runtime, including nested actions.
|
|
48
|
+
const until = Date.now() + 15 * 60_000;
|
|
49
|
+
await ctx.db.patch("apps", app._id, {
|
|
50
|
+
operation: { ...app.operation, kind, until },
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
until,
|
|
54
|
+
resuming: app.operation?.kind === "delete",
|
|
55
|
+
pending: app.operation?.pending,
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
export const finish = internalMutation({
|
|
60
|
+
args: {
|
|
61
|
+
...identityFields,
|
|
62
|
+
appId: v.string(),
|
|
63
|
+
until: v.number(),
|
|
64
|
+
retryDelete: v.boolean(),
|
|
65
|
+
},
|
|
66
|
+
returns: v.null(),
|
|
67
|
+
handler: async (ctx, { userId, appId, until, retryDelete }) => {
|
|
68
|
+
const app = await ownedApp(ctx, userId, appId);
|
|
69
|
+
if (app.operation?.until === until)
|
|
70
|
+
await ctx.db.patch("apps", app._id, {
|
|
71
|
+
operation: retryDelete
|
|
72
|
+
? { ...app.operation, kind: "delete", until: 0 }
|
|
73
|
+
: undefined,
|
|
74
|
+
});
|
|
75
|
+
return null;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
export const linked = internalQuery({
|
|
79
|
+
args: { ...identityFields, appId: v.string() },
|
|
80
|
+
returns: resources,
|
|
81
|
+
handler: async (ctx, { userId, appId }) => {
|
|
82
|
+
const {
|
|
83
|
+
githubOwner,
|
|
84
|
+
githubRepo,
|
|
85
|
+
convexProjectId,
|
|
86
|
+
expoProjectId,
|
|
87
|
+
expoAccountId,
|
|
88
|
+
} = await ownedApp(ctx, userId, appId);
|
|
89
|
+
return {
|
|
90
|
+
githubOwner,
|
|
91
|
+
githubRepo,
|
|
92
|
+
convexProjectId,
|
|
93
|
+
expoProjectId,
|
|
94
|
+
expoAccountId,
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
export const saveExpo = internalMutation({
|
|
99
|
+
args: {
|
|
100
|
+
...identityFields,
|
|
101
|
+
appId: v.string(),
|
|
102
|
+
accountId: v.string(),
|
|
103
|
+
projectId: v.optional(v.string()),
|
|
104
|
+
},
|
|
105
|
+
returns: v.null(),
|
|
106
|
+
handler: async (ctx, { userId, appId, accountId, projectId }) => {
|
|
107
|
+
const app = await ownedApp(ctx, userId, appId);
|
|
108
|
+
assertActive(app);
|
|
109
|
+
if (
|
|
110
|
+
(app.expoAccountId && app.expoAccountId !== accountId) ||
|
|
111
|
+
(projectId && app.expoProjectId && app.expoProjectId !== projectId)
|
|
112
|
+
)
|
|
113
|
+
throw new ConvexError("App is already linked to another Expo project.");
|
|
114
|
+
await ctx.db.patch("apps", app._id, {
|
|
115
|
+
expoAccountId: accountId,
|
|
116
|
+
...(projectId ? { expoProjectId: projectId } : {}),
|
|
117
|
+
});
|
|
118
|
+
return null;
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
export const forget = internalMutation({
|
|
122
|
+
args: {
|
|
123
|
+
...identityFields,
|
|
124
|
+
appId: v.string(),
|
|
125
|
+
until: v.number(),
|
|
126
|
+
provider: v.union(
|
|
127
|
+
v.literal("github"),
|
|
128
|
+
v.literal("convex"),
|
|
129
|
+
v.literal("expo"),
|
|
130
|
+
),
|
|
131
|
+
},
|
|
132
|
+
returns: v.null(),
|
|
133
|
+
handler: async (ctx, { userId, appId, until, provider }) => {
|
|
134
|
+
const app = await ownedApp(ctx, userId, appId);
|
|
135
|
+
if (app.operation?.kind !== "delete" || app.operation.until !== until)
|
|
136
|
+
throw new ConvexError("Deletion must be restarted.");
|
|
137
|
+
await ctx.db.patch(
|
|
138
|
+
"apps",
|
|
139
|
+
app._id,
|
|
140
|
+
provider === "github"
|
|
141
|
+
? { githubOwner: undefined, githubRepo: undefined }
|
|
142
|
+
: provider === "convex"
|
|
143
|
+
? { convexProjectId: undefined }
|
|
144
|
+
: { expoProjectId: undefined, expoAccountId: null },
|
|
145
|
+
);
|
|
146
|
+
return null;
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
export const deletingResource = internalMutation({
|
|
150
|
+
args: {
|
|
151
|
+
...identityFields,
|
|
152
|
+
appId: v.string(),
|
|
153
|
+
until: v.number(),
|
|
154
|
+
pending: pendingDelete,
|
|
155
|
+
},
|
|
156
|
+
returns: v.null(),
|
|
157
|
+
handler: async (ctx, { userId, appId, until, pending }) => {
|
|
158
|
+
const app = await ownedApp(ctx, userId, appId);
|
|
159
|
+
if (app.operation?.kind !== "delete" || app.operation.until !== until)
|
|
160
|
+
throw new ConvexError("Deletion must be restarted.");
|
|
161
|
+
await ctx.db.patch("apps", app._id, {
|
|
162
|
+
operation: { ...app.operation, pending },
|
|
163
|
+
});
|
|
164
|
+
return null;
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
export const erase = internalMutation({
|
|
168
|
+
args: { ...identityFields, appId: v.string(), until: v.number() },
|
|
169
|
+
returns: v.boolean(),
|
|
170
|
+
handler: async (ctx, { userId, appId, until }) => {
|
|
171
|
+
const app = await ownedApp(ctx, userId, appId);
|
|
172
|
+
await assertPreviewOnly(ctx, appId);
|
|
173
|
+
if (
|
|
174
|
+
app.operation?.kind !== "delete" ||
|
|
175
|
+
app.operation.until !== until ||
|
|
176
|
+
app.githubRepo ||
|
|
177
|
+
app.convexProjectId ||
|
|
178
|
+
app.expoProjectId ||
|
|
179
|
+
app.expoAccountId
|
|
180
|
+
)
|
|
181
|
+
throw new ConvexError("Linked projects must be deleted first.");
|
|
182
|
+
const previews = await ctx.db
|
|
183
|
+
.query("previews")
|
|
184
|
+
.withIndex("by_appId_reference", (q) => q.eq("appId", appId))
|
|
185
|
+
.take(100);
|
|
186
|
+
for (const preview of previews)
|
|
187
|
+
await ctx.db.delete("previews", preview._id);
|
|
188
|
+
if (previews.length === 100) return false;
|
|
189
|
+
await ctx.db.delete("apps", app._id);
|
|
190
|
+
return true;
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
export const workflow = internalMutation({
|
|
194
|
+
args: { ...identityFields, appId: v.string(), production: v.boolean() },
|
|
195
|
+
returns: v.null(),
|
|
196
|
+
handler: async (ctx, { userId, appId, production }) => {
|
|
197
|
+
const app = await ownedApp(ctx, userId, appId);
|
|
198
|
+
assertActive(app);
|
|
199
|
+
if (
|
|
200
|
+
production &&
|
|
201
|
+
!(await ctx.db
|
|
202
|
+
.query("appReleases")
|
|
203
|
+
.withIndex("by_appId", (q) => q.eq("appId", appId))
|
|
204
|
+
.unique())
|
|
205
|
+
)
|
|
206
|
+
await ctx.db.insert("appReleases", {
|
|
207
|
+
appId,
|
|
208
|
+
releases: {},
|
|
209
|
+
updatedAt: Date.now(),
|
|
210
|
+
});
|
|
211
|
+
return null;
|
|
212
|
+
},
|
|
213
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
|
|
3
|
+
export const deleteArgs = {
|
|
4
|
+
appId: v.string(),
|
|
5
|
+
dangerouslyDeleteApp: v.literal(true),
|
|
6
|
+
};
|
|
7
|
+
export const resources = v.object({
|
|
8
|
+
githubOwner: v.optional(v.string()),
|
|
9
|
+
githubRepo: v.optional(v.string()),
|
|
10
|
+
convexProjectId: v.optional(v.number()),
|
|
11
|
+
expoProjectId: v.optional(v.string()),
|
|
12
|
+
expoAccountId: v.optional(v.union(v.string(), v.null())),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const pendingDelete = v.object({
|
|
16
|
+
provider: v.union(
|
|
17
|
+
v.literal("github"),
|
|
18
|
+
v.literal("convex"),
|
|
19
|
+
v.literal("expo"),
|
|
20
|
+
),
|
|
21
|
+
accountId: v.string(),
|
|
22
|
+
receipt: v.optional(v.string()),
|
|
23
|
+
});
|
|
@@ -109,10 +109,8 @@ export const selectGithub = internalAction({
|
|
|
109
109
|
installationId,
|
|
110
110
|
permissions.map((p) => `${p}:write`),
|
|
111
111
|
);
|
|
112
|
-
const id = await ctx.runQuery(internal.users.internal.current, { userId });
|
|
113
|
-
if (!id) throw new ConvexError("Sign in to connect GitHub.");
|
|
114
112
|
await ctx.runMutation(internal.github.internal.connect, {
|
|
115
|
-
userId
|
|
113
|
+
userId,
|
|
116
114
|
...chosen,
|
|
117
115
|
});
|
|
118
116
|
return null;
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
provider,
|
|
12
12
|
} from "./validator";
|
|
13
13
|
|
|
14
|
-
async function
|
|
14
|
+
async function requireUser(ctx: QueryCtx | MutationCtx | ActionCtx) {
|
|
15
15
|
const id = await getAuthUserId(ctx);
|
|
16
16
|
if (!id) throw new ConvexError("Sign in to manage your connections.");
|
|
17
17
|
return id;
|
|
@@ -21,7 +21,7 @@ export const status = query({
|
|
|
21
21
|
returns: connectionStatus,
|
|
22
22
|
handler: async (ctx): Promise<Infer<typeof connectionStatus>> =>
|
|
23
23
|
ctx.runQuery(internal.connections.internal.status, {
|
|
24
|
-
userId: await
|
|
24
|
+
userId: await requireUser(ctx),
|
|
25
25
|
}),
|
|
26
26
|
});
|
|
27
27
|
export const start = action({
|
|
@@ -30,7 +30,7 @@ export const start = action({
|
|
|
30
30
|
handler: async (ctx, args): Promise<string> =>
|
|
31
31
|
ctx.runAction(internal.connections.actions.oauth.start, {
|
|
32
32
|
...args,
|
|
33
|
-
userId: await
|
|
33
|
+
userId: await requireUser(ctx),
|
|
34
34
|
}),
|
|
35
35
|
});
|
|
36
36
|
export const complete = action({
|
|
@@ -39,7 +39,7 @@ export const complete = action({
|
|
|
39
39
|
handler: async (ctx, args): Promise<Infer<typeof completion>> =>
|
|
40
40
|
ctx.runAction(internal.connections.actions.oauth.complete, {
|
|
41
41
|
...args,
|
|
42
|
-
userId: await
|
|
42
|
+
userId: await requireUser(ctx),
|
|
43
43
|
}),
|
|
44
44
|
});
|
|
45
45
|
export const selectGithub = action({
|
|
@@ -48,7 +48,7 @@ export const selectGithub = action({
|
|
|
48
48
|
handler: async (ctx, args): Promise<null> =>
|
|
49
49
|
ctx.runAction(internal.connections.actions.github.selectGithub, {
|
|
50
50
|
...args,
|
|
51
|
-
userId: await
|
|
51
|
+
userId: await requireUser(ctx),
|
|
52
52
|
}),
|
|
53
53
|
});
|
|
54
54
|
export const expoAccounts = action({
|
|
@@ -57,7 +57,7 @@ export const expoAccounts = action({
|
|
|
57
57
|
handler: async (ctx, args): Promise<Infer<typeof account>[]> =>
|
|
58
58
|
ctx.runAction(internal.connections.actions.expo.expoAccounts, {
|
|
59
59
|
...args,
|
|
60
|
-
userId: await
|
|
60
|
+
userId: await requireUser(ctx),
|
|
61
61
|
}),
|
|
62
62
|
});
|
|
63
63
|
export const connectExpo = action({
|
|
@@ -66,7 +66,7 @@ export const connectExpo = action({
|
|
|
66
66
|
handler: async (ctx, args): Promise<null> =>
|
|
67
67
|
ctx.runAction(internal.connections.actions.expo.connectExpo, {
|
|
68
68
|
...args,
|
|
69
|
-
userId: await
|
|
69
|
+
userId: await requireUser(ctx),
|
|
70
70
|
}),
|
|
71
71
|
});
|
|
72
72
|
export const disconnect = mutation({
|
|
@@ -75,6 +75,6 @@ export const disconnect = mutation({
|
|
|
75
75
|
handler: async (ctx, args): Promise<null> =>
|
|
76
76
|
ctx.runMutation(internal.connections.internal.disconnect, {
|
|
77
77
|
...args,
|
|
78
|
-
userId: await
|
|
78
|
+
userId: await requireUser(ctx),
|
|
79
79
|
}),
|
|
80
80
|
});
|
|
@@ -116,8 +116,7 @@ export const begin = internalMutation({
|
|
|
116
116
|
returns: v.null(),
|
|
117
117
|
handler: async (ctx, { userId, ...state }) => {
|
|
118
118
|
const id = ctx.db.normalizeId("users", userId);
|
|
119
|
-
if (!id
|
|
120
|
-
throw new ConvexError("Sign in to connect an account.");
|
|
119
|
+
if (!id) throw new ConvexError("Invalid userId.");
|
|
121
120
|
await ctx.db.patch("users", id, {
|
|
122
121
|
connectionState: { ...state, expiresAt: Date.now() + 10 * 60_000 },
|
|
123
122
|
});
|
|
@@ -96,6 +96,11 @@ async function authorize(ctx: ActionCtx, appId: string, token: string) {
|
|
|
96
96
|
claims.head_ref !== workflowRun.head_branch
|
|
97
97
|
)
|
|
98
98
|
throw new Error("Unexpected preview branch.");
|
|
99
|
+
await ctx.runMutation(internal.apps.operations.internal.workflow, {
|
|
100
|
+
userId: app.userId,
|
|
101
|
+
appId,
|
|
102
|
+
production,
|
|
103
|
+
});
|
|
99
104
|
return {
|
|
100
105
|
app,
|
|
101
106
|
repository,
|
|
@@ -178,6 +183,7 @@ export const report = internalAction({
|
|
|
178
183
|
const { token: _token, ...result } = args;
|
|
179
184
|
await ctx.runMutation(internal.previews.internal.report, {
|
|
180
185
|
...result,
|
|
186
|
+
userId: verified.app.userId,
|
|
181
187
|
githubOwner: verified.app.githubOwner,
|
|
182
188
|
githubRepo: verified.app.githubRepo,
|
|
183
189
|
reference: verified.reference,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { v } from "convex/values";
|
|
9
9
|
import { internal } from "../../_generated/api";
|
|
10
10
|
import { credential, unseal } from "../../connections/actions/credentials";
|
|
11
|
+
import { ensureExpo } from "../../apps/actions/expo";
|
|
11
12
|
import { validateExpo } from "../../connections/actions/expo";
|
|
12
13
|
import {
|
|
13
14
|
management,
|
|
@@ -19,7 +20,7 @@ export const configure = internalAction({
|
|
|
19
20
|
args: { ...identityFields, appId: v.string(), projectId: v.number() },
|
|
20
21
|
returns: v.null(),
|
|
21
22
|
handler: async (ctx, args) => {
|
|
22
|
-
await ctx.runQuery(internal.apps.internal.get, {
|
|
23
|
+
const details = await ctx.runQuery(internal.apps.internal.get, {
|
|
23
24
|
userId: args.userId,
|
|
24
25
|
appId: args.appId,
|
|
25
26
|
});
|
|
@@ -100,13 +101,45 @@ export const configure = internalAction({
|
|
|
100
101
|
userId: args.userId,
|
|
101
102
|
provider: "expo",
|
|
102
103
|
});
|
|
103
|
-
if (
|
|
104
|
+
if (
|
|
105
|
+
expo &&
|
|
106
|
+
details.platforms.some(
|
|
107
|
+
(platform) => platform === "android" || platform === "ios",
|
|
108
|
+
)
|
|
109
|
+
) {
|
|
104
110
|
const token = unseal(expo.token, `${args.userId}:expo`);
|
|
105
111
|
const accounts = await validateExpo(token);
|
|
106
112
|
if (!accounts.some((account) => account.id === expo.accountId))
|
|
107
113
|
throw new Error(
|
|
108
114
|
"Reconnect your Expo account before setting up mobile builds.",
|
|
109
115
|
);
|
|
116
|
+
const linked = await ctx.runQuery(
|
|
117
|
+
internal.apps.operations.internal.linked,
|
|
118
|
+
{
|
|
119
|
+
userId: args.userId,
|
|
120
|
+
appId: args.appId,
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
await ctx.runMutation(internal.apps.operations.internal.saveExpo, {
|
|
124
|
+
userId: args.userId,
|
|
125
|
+
appId: args.appId,
|
|
126
|
+
accountId: expo.accountId,
|
|
127
|
+
});
|
|
128
|
+
const project = await ensureExpo(
|
|
129
|
+
token,
|
|
130
|
+
expo.accountId,
|
|
131
|
+
expo.name,
|
|
132
|
+
args.appId,
|
|
133
|
+
linked.expoProjectId,
|
|
134
|
+
);
|
|
135
|
+
await ctx.runMutation(internal.apps.operations.internal.saveExpo, {
|
|
136
|
+
userId: args.userId,
|
|
137
|
+
appId: args.appId,
|
|
138
|
+
projectId: project.id,
|
|
139
|
+
accountId: expo.accountId,
|
|
140
|
+
});
|
|
141
|
+
await save("EXPO_PROJECT_ID", project.id);
|
|
142
|
+
await save("EXPO_SLUG", project.slug);
|
|
110
143
|
await save("EXPO_TOKEN", token);
|
|
111
144
|
await save("EXPO_OWNER", expo.name);
|
|
112
145
|
}
|
|
@@ -47,6 +47,11 @@ export async function vercelIdentity() {
|
|
|
47
47
|
const { token } = (await response.json()) as { token: string };
|
|
48
48
|
return token;
|
|
49
49
|
}
|
|
50
|
+
export class GitHubError extends Error {
|
|
51
|
+
constructor(readonly status: number) {
|
|
52
|
+
super(`GitHub request failed (${status}).`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
50
55
|
export async function githubRequest<T>(
|
|
51
56
|
token: string,
|
|
52
57
|
path: string,
|
|
@@ -65,8 +70,7 @@ export async function githubRequest<T>(
|
|
|
65
70
|
},
|
|
66
71
|
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
67
72
|
});
|
|
68
|
-
if (!response.ok)
|
|
69
|
-
throw new Error(`GitHub request failed (${response.status}).`);
|
|
73
|
+
if (!response.ok) throw new GitHubError(response.status);
|
|
70
74
|
return (
|
|
71
75
|
response.status === 204 || response.headers.get("content-length") === "0"
|
|
72
76
|
? undefined
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
identityFields,
|
|
3
|
+
internalMutation,
|
|
4
|
+
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
2
5
|
import { ConvexError, v } from "convex/values";
|
|
3
6
|
|
|
4
7
|
/** A trusted installation callback supplies this verified binding, never a client API. */
|
|
5
8
|
export const connect = internalMutation({
|
|
6
9
|
args: {
|
|
7
|
-
|
|
10
|
+
...identityFields,
|
|
8
11
|
owner: v.string(),
|
|
9
12
|
installationId: v.string(),
|
|
10
13
|
},
|
|
11
14
|
returns: v.null(),
|
|
12
15
|
handler: async (ctx, { userId, owner, installationId }) => {
|
|
13
|
-
if (!(await ctx.db.get("users", userId)))
|
|
14
|
-
throw new ConvexError("User not found.");
|
|
15
16
|
if (!/^[a-zA-Z0-9-]+$/.test(owner) || !/^\d+$/.test(installationId))
|
|
16
17
|
throw new ConvexError("Invalid GitHub installation.");
|
|
17
18
|
owner = owner.toLowerCase();
|
|
@@ -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
|
}
|