create-disposabl-app 0.8.9 → 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.
- package/README.md +8 -1
- package/dist/disposabl.js +42 -42
- package/dist/index.js +1 -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 -69
- 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/cli/README.md +5 -1
- package/dist/templates/default/packages/cli/commands.ts +15 -8
- package/dist/templates/default/packages/cli/delete.ts +40 -31
- package/dist/templates/default/packages/skill/SKILL.md +13 -5
- package/dist/templates/default/packages/skill/references/delivery.md +1 -1
- package/package.json +1 -1
- package/dist/templates/default/packages/backend/convex/apps/actions/cleanup.ts +0 -296
- 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 -174
- 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 -213
- 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,174 +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
|
-
if (
|
|
34
|
-
result.errors?.some(
|
|
35
|
-
(error) =>
|
|
36
|
-
error.extensions?.errorCode === "SUDO_MODE_REQUIRED" ||
|
|
37
|
-
error.message ===
|
|
38
|
-
"Only regular user and SSO user access to this API is supported",
|
|
39
|
-
)
|
|
40
|
-
)
|
|
41
|
-
throw new ExpoLoginRequired();
|
|
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 ExpoLoginRequired extends Error {}
|
|
57
|
-
class ExpoNotFound extends Error {}
|
|
58
|
-
export async function findExpo(
|
|
59
|
-
token: string,
|
|
60
|
-
fullName: string,
|
|
61
|
-
projectId?: string,
|
|
62
|
-
) {
|
|
63
|
-
try {
|
|
64
|
-
const data = projectId
|
|
65
|
-
? await expoRequest<{ app: { project: Project } }>(
|
|
66
|
-
token,
|
|
67
|
-
`query($id: String!) { app { project: byId(appId: $id) { ${fields} } } }`,
|
|
68
|
-
{ id: projectId },
|
|
69
|
-
)
|
|
70
|
-
: await expoRequest<{ app: { project: Project } }>(
|
|
71
|
-
token,
|
|
72
|
-
`query($name: String!) { app { project: byFullName(fullName: $name) { ${fields} } } }`,
|
|
73
|
-
{ name: fullName },
|
|
74
|
-
);
|
|
75
|
-
if (!data.app.project)
|
|
76
|
-
throw new ConvexError("Expo returned no project details.");
|
|
77
|
-
return data.app.project;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
if (error instanceof ExpoNotFound) return null;
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
export function verifyExpo(project: Project, accountId: string, appId: string) {
|
|
84
|
-
if (project.ownerAccount.id !== accountId || project.slug !== `app-${appId}`)
|
|
85
|
-
throw new ConvexError(
|
|
86
|
-
"Reconnect the Expo account that owns this app. The linked project must match this app's UUID.",
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
export async function ensureExpo(
|
|
90
|
-
token: string,
|
|
91
|
-
accountId: string,
|
|
92
|
-
owner: string,
|
|
93
|
-
appId: string,
|
|
94
|
-
saved?: string,
|
|
95
|
-
) {
|
|
96
|
-
const fullName = `@${owner}/app-${appId}`;
|
|
97
|
-
let project = await findExpo(token, fullName, saved);
|
|
98
|
-
if (!project) {
|
|
99
|
-
if (saved)
|
|
100
|
-
throw new ConvexError(
|
|
101
|
-
"The linked Expo project is unavailable. Reconnect its owner before continuing.",
|
|
102
|
-
);
|
|
103
|
-
try {
|
|
104
|
-
const created = await expoRequest<{ app: { createApp: { id: string } } }>(
|
|
105
|
-
token,
|
|
106
|
-
"mutation($input: AppInput!) { app { createApp(appInput: $input) { id } } }",
|
|
107
|
-
{ input: { accountId, projectName: `app-${appId}` } },
|
|
108
|
-
);
|
|
109
|
-
project = await findExpo(token, fullName, created.app.createApp.id);
|
|
110
|
-
} catch (error) {
|
|
111
|
-
project = await findExpo(token, fullName);
|
|
112
|
-
if (!project) throw error;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (!project)
|
|
116
|
-
throw new ConvexError("Expo project creation is incomplete. Retry setup.");
|
|
117
|
-
verifyExpo(project, accountId, appId);
|
|
118
|
-
return project;
|
|
119
|
-
}
|
|
120
|
-
export async function deleteExpo(
|
|
121
|
-
token: string,
|
|
122
|
-
projectId: string,
|
|
123
|
-
savedReceipt: string | undefined,
|
|
124
|
-
saveReceipt: (id: string) => Promise<void>,
|
|
125
|
-
) {
|
|
126
|
-
let receipt: Receipt;
|
|
127
|
-
if (savedReceipt) {
|
|
128
|
-
const data = await expoRequest<{
|
|
129
|
-
backgroundJobReceipt: { byId: Receipt | null };
|
|
130
|
-
}>(
|
|
131
|
-
token,
|
|
132
|
-
"query($id: ID!) { backgroundJobReceipt { byId(id: $id) { id state willRetry } } }",
|
|
133
|
-
{ id: savedReceipt },
|
|
134
|
-
);
|
|
135
|
-
if (!data.backgroundJobReceipt.byId)
|
|
136
|
-
throw new ConvexError(
|
|
137
|
-
"Expo deletion receipt is unavailable. Reconnect the owning account.",
|
|
138
|
-
);
|
|
139
|
-
receipt = data.backgroundJobReceipt.byId;
|
|
140
|
-
} else {
|
|
141
|
-
receipt = (
|
|
142
|
-
await expoRequest<{ app: { scheduleAppDeletion: Receipt } }>(
|
|
143
|
-
token,
|
|
144
|
-
"mutation($id: ID!) { app { scheduleAppDeletion(appId: $id) { id state willRetry } } }",
|
|
145
|
-
{ id: projectId },
|
|
146
|
-
)
|
|
147
|
-
).app.scheduleAppDeletion;
|
|
148
|
-
await saveReceipt(receipt.id);
|
|
149
|
-
}
|
|
150
|
-
const deadline = Date.now() + 90_000;
|
|
151
|
-
while (receipt.state !== "SUCCESS") {
|
|
152
|
-
if (receipt.state === "FAILURE" && !receipt.willRetry)
|
|
153
|
-
throw new ConvexError(
|
|
154
|
-
"Expo project deletion failed. Check your Expo account and retry apps delete.",
|
|
155
|
-
);
|
|
156
|
-
if (Date.now() >= deadline)
|
|
157
|
-
throw new ConvexError(
|
|
158
|
-
"Expo is still deleting the project. Retry apps delete to finish cleanup.",
|
|
159
|
-
);
|
|
160
|
-
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
161
|
-
const data = await expoRequest<{
|
|
162
|
-
backgroundJobReceipt: { byId: Receipt | null };
|
|
163
|
-
}>(
|
|
164
|
-
token,
|
|
165
|
-
"query($id: ID!) { backgroundJobReceipt { byId(id: $id) { id state willRetry } } }",
|
|
166
|
-
{ id: receipt.id },
|
|
167
|
-
);
|
|
168
|
-
if (!data.backgroundJobReceipt.byId)
|
|
169
|
-
throw new ConvexError(
|
|
170
|
-
"Expo deletion could not be confirmed. Retry apps delete.",
|
|
171
|
-
);
|
|
172
|
-
receipt = data.backgroundJobReceipt.byId;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
@@ -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
|
-
});
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
identityFields,
|
|
3
|
-
internalMutation,
|
|
4
|
-
internalQuery,
|
|
5
|
-
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
6
|
-
import {
|
|
7
|
-
paginationOptsValidator,
|
|
8
|
-
paginationResultValidator,
|
|
9
|
-
} from "convex/server";
|
|
10
|
-
import { ConvexError, v, type Infer } from "convex/values";
|
|
11
|
-
import { appArgs, appResult, platform } from "../validator";
|
|
12
|
-
import { validatePlatforms } from "@disposabl/disposabl-kit/platforms";
|
|
13
|
-
import { githubConnection } from "../validator";
|
|
14
|
-
import type { Doc } from "../_generated/dataModel";
|
|
15
|
-
import type { QueryCtx } from "../_generated/server";
|
|
16
|
-
type AppResult = Infer<typeof appResult>;
|
|
17
|
-
|
|
18
|
-
export { create } from "./actions/create";
|
|
19
|
-
export const insert = internalMutation({
|
|
20
|
-
args: { ...identityFields, ...appArgs, appId: v.string() },
|
|
21
|
-
returns: appResult,
|
|
22
|
-
handler: async (ctx, args) => {
|
|
23
|
-
assertAppId(args.appId);
|
|
24
|
-
const name = args.name.trim();
|
|
25
|
-
if (!name || name.length > 214)
|
|
26
|
-
throw new ConvexError("App name must contain 1–214 characters.");
|
|
27
|
-
const platforms = [...new Set(args.platforms)];
|
|
28
|
-
const id = await ctx.db.insert("apps", {
|
|
29
|
-
userId: args.userId,
|
|
30
|
-
appId: args.appId,
|
|
31
|
-
name,
|
|
32
|
-
platforms,
|
|
33
|
-
expoAccountId: null,
|
|
34
|
-
});
|
|
35
|
-
return presentApp((await ctx.db.get("apps", id))!);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
export const list = internalQuery({
|
|
39
|
-
platforms: true,
|
|
40
|
-
args: { ...identityFields, paginationOpts: paginationOptsValidator },
|
|
41
|
-
returns: paginationResultValidator(appResult),
|
|
42
|
-
handler: async (ctx, { userId, paginationOpts }) => {
|
|
43
|
-
if (
|
|
44
|
-
!Number.isInteger(paginationOpts.numItems) ||
|
|
45
|
-
paginationOpts.numItems < 1 ||
|
|
46
|
-
paginationOpts.numItems > 100
|
|
47
|
-
)
|
|
48
|
-
throw new ConvexError("Page size must be between 1 and 100.");
|
|
49
|
-
const result = await ctx.db
|
|
50
|
-
.query("apps")
|
|
51
|
-
.withIndex("by_userId", (q) => q.eq("userId", userId))
|
|
52
|
-
.order("desc")
|
|
53
|
-
.paginate(paginationOpts);
|
|
54
|
-
return { ...result, page: result.page.map(presentApp) };
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
export const get = internalQuery({
|
|
58
|
-
platforms: true,
|
|
59
|
-
args: { ...identityFields, appId: v.string() },
|
|
60
|
-
returns: appResult,
|
|
61
|
-
handler: async (ctx, { userId, appId }) =>
|
|
62
|
-
presentApp(await ownedApp(ctx, userId, appId)),
|
|
63
|
-
});
|
|
64
|
-
export const update = internalMutation({
|
|
65
|
-
platforms: true,
|
|
66
|
-
args: { ...identityFields, appId: v.string(), platforms: v.array(platform) },
|
|
67
|
-
returns: appResult,
|
|
68
|
-
handler: async (ctx, { userId, appId, platforms }) => {
|
|
69
|
-
const app = await ownedApp(ctx, userId, appId);
|
|
70
|
-
if (app.operation)
|
|
71
|
-
throw new ConvexError(
|
|
72
|
-
"Wait for app setup to finish before changing platforms.",
|
|
73
|
-
);
|
|
74
|
-
const selected = validatePlatforms(platforms);
|
|
75
|
-
await ctx.db.patch("apps", app._id, { platforms: selected });
|
|
76
|
-
return presentApp({ ...app, platforms: selected });
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
export { remove as delete } from "./actions/delete";
|
|
80
|
-
|
|
81
|
-
function assertAppId(appId: string) {
|
|
82
|
-
if (
|
|
83
|
-
!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(
|
|
84
|
-
appId,
|
|
85
|
-
)
|
|
86
|
-
)
|
|
87
|
-
throw new ConvexError("appId must be a lowercase UUID v4.");
|
|
88
|
-
}
|
|
89
|
-
export async function ownedApp(
|
|
90
|
-
ctx: Pick<QueryCtx, "db">,
|
|
91
|
-
userId: string,
|
|
92
|
-
appId: string,
|
|
93
|
-
) {
|
|
94
|
-
assertAppId(appId);
|
|
95
|
-
const app = await ctx.db
|
|
96
|
-
.query("apps")
|
|
97
|
-
.withIndex("by_appId", (q) => q.eq("appId", appId))
|
|
98
|
-
.unique();
|
|
99
|
-
if (!app || app.userId !== userId) throw new ConvexError("App not found.");
|
|
100
|
-
return app;
|
|
101
|
-
}
|
|
102
|
-
function presentApp(app: Doc<"apps">): AppResult {
|
|
103
|
-
return {
|
|
104
|
-
appId: app.appId,
|
|
105
|
-
name: app.name,
|
|
106
|
-
platforms: app.platforms,
|
|
107
|
-
...(app.githubOwner ? { githubOwner: app.githubOwner } : {}),
|
|
108
|
-
...(app.githubRepo ? { githubRepo: app.githubRepo } : {}),
|
|
109
|
-
createdAt: app._creationTime,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
export const githubApp = internalQuery({
|
|
113
|
-
args: { appId: v.string() },
|
|
114
|
-
returns: v.union(
|
|
115
|
-
v.null(),
|
|
116
|
-
v.object({
|
|
117
|
-
githubOwner: v.string(),
|
|
118
|
-
githubRepo: v.string(),
|
|
119
|
-
installationId: v.string(),
|
|
120
|
-
userId: v.string(),
|
|
121
|
-
}),
|
|
122
|
-
),
|
|
123
|
-
handler: async (ctx, { appId }) => {
|
|
124
|
-
assertAppId(appId);
|
|
125
|
-
const app = await ctx.db
|
|
126
|
-
.query("apps")
|
|
127
|
-
.withIndex("by_appId", (q) => q.eq("appId", appId))
|
|
128
|
-
.unique();
|
|
129
|
-
if (!app?.githubOwner || !app.githubRepo) return null;
|
|
130
|
-
const connection = await ctx.db
|
|
131
|
-
.query("githubConnections")
|
|
132
|
-
.withIndex("by_userId_owner", (q) =>
|
|
133
|
-
q.eq("userId", app.userId).eq("owner", app.githubOwner!),
|
|
134
|
-
)
|
|
135
|
-
.unique();
|
|
136
|
-
const installationId = connection?.installationId;
|
|
137
|
-
return installationId
|
|
138
|
-
? {
|
|
139
|
-
githubOwner: app.githubOwner,
|
|
140
|
-
githubRepo: app.githubRepo,
|
|
141
|
-
installationId,
|
|
142
|
-
userId: app.userId,
|
|
143
|
-
}
|
|
144
|
-
: null;
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
/** Only trusted repository provisioning can link an app. */
|
|
148
|
-
export const connectGithub = internalMutation({
|
|
149
|
-
args: {
|
|
150
|
-
...identityFields,
|
|
151
|
-
appId: v.string(),
|
|
152
|
-
githubOwner: v.string(),
|
|
153
|
-
githubRepo: v.string(),
|
|
154
|
-
},
|
|
155
|
-
returns: v.null(),
|
|
156
|
-
handler: async (ctx, { userId, appId, githubOwner, githubRepo }) => {
|
|
157
|
-
const app = await ownedApp(ctx, userId, appId);
|
|
158
|
-
githubOwner = githubOwner.toLowerCase();
|
|
159
|
-
if (
|
|
160
|
-
app.githubOwner &&
|
|
161
|
-
(app.githubOwner !== githubOwner || app.githubRepo !== githubRepo)
|
|
162
|
-
)
|
|
163
|
-
throw new ConvexError("App is already linked to a different repository.");
|
|
164
|
-
await ctx.db.patch("apps", app._id, { githubOwner, githubRepo });
|
|
165
|
-
return null;
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
export const githubSetup = internalQuery({
|
|
169
|
-
args: { ...identityFields, appId: v.string() },
|
|
170
|
-
returns: v.object({
|
|
171
|
-
app: appResult,
|
|
172
|
-
connection: v.union(githubConnection, v.null()),
|
|
173
|
-
}),
|
|
174
|
-
handler: async (ctx, { userId, appId }) => {
|
|
175
|
-
const app = await ownedApp(ctx, userId, appId);
|
|
176
|
-
const connection = await ctx.db
|
|
177
|
-
.query("githubConnections")
|
|
178
|
-
.withIndex("by_userId", (q) => q.eq("userId", userId))
|
|
179
|
-
.order("desc")
|
|
180
|
-
.first();
|
|
181
|
-
return {
|
|
182
|
-
app: presentApp(app),
|
|
183
|
-
connection: connection
|
|
184
|
-
? {
|
|
185
|
-
owner: connection.owner,
|
|
186
|
-
installationId: connection.installationId,
|
|
187
|
-
}
|
|
188
|
-
: null,
|
|
189
|
-
};
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
export const project = internalQuery({
|
|
194
|
-
args: { ...identityFields, appId: v.string() },
|
|
195
|
-
returns: v.union(v.number(), v.null()),
|
|
196
|
-
handler: async (ctx, { userId, appId }) =>
|
|
197
|
-
(await ownedApp(ctx, userId, appId)).convexProjectId ?? null,
|
|
198
|
-
});
|
|
199
|
-
export const saveProject = internalMutation({
|
|
200
|
-
args: {
|
|
201
|
-
...identityFields,
|
|
202
|
-
appId: v.string(),
|
|
203
|
-
projectId: v.number(),
|
|
204
|
-
},
|
|
205
|
-
returns: v.null(),
|
|
206
|
-
handler: async (ctx, args) => {
|
|
207
|
-
const app = await ownedApp(ctx, args.userId, args.appId);
|
|
208
|
-
await ctx.db.patch("apps", app._id, { convexProjectId: args.projectId });
|
|
209
|
-
return null;
|
|
210
|
-
},
|
|
211
|
-
});
|
|
@@ -1,213 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
});
|