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.
- package/README.md +8 -1
- package/dist/disposabl.js +1 -1
- 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 -70
- package/dist/templates/default/packages/backend/generated/openapi.json +1 -1262
- package/dist/templates/default/packages/backend/generated/pages.json +0 -4
- package/dist/templates/default/packages/backend/generated/platforms.ts +2 -20
- package/dist/templates/default/packages/backend/package.json +1 -7
- package/dist/templates/default/packages/skill/SKILL.md +5 -5
- package/dist/templates/default/packages/skill/references/delivery.md +1 -1
- package/package.json +1 -1
- package/dist/templates/default/packages/backend/convex/apps/actions/cleanup.ts +0 -317
- package/dist/templates/default/packages/backend/convex/apps/actions/create.ts +0 -30
- package/dist/templates/default/packages/backend/convex/apps/actions/delete.ts +0 -15
- package/dist/templates/default/packages/backend/convex/apps/actions/expo.ts +0 -180
- package/dist/templates/default/packages/backend/convex/apps/actions/setup.ts +0 -48
- package/dist/templates/default/packages/backend/convex/apps/internal.ts +0 -211
- package/dist/templates/default/packages/backend/convex/apps/operations/internal.ts +0 -239
- package/dist/templates/default/packages/backend/convex/apps/validator.ts +0 -23
- package/dist/templates/default/packages/backend/convex/connections/actions/credentials.ts +0 -56
- package/dist/templates/default/packages/backend/convex/connections/actions/expo.ts +0 -79
- package/dist/templates/default/packages/backend/convex/connections/actions/github.ts +0 -119
- package/dist/templates/default/packages/backend/convex/connections/actions/oauth.ts +0 -128
- package/dist/templates/default/packages/backend/convex/connections/index.ts +0 -80
- package/dist/templates/default/packages/backend/convex/connections/internal.ts +0 -147
- package/dist/templates/default/packages/backend/convex/connections/validator.ts +0 -35
- package/dist/templates/default/packages/backend/convex/downloads/action.ts +0 -136
- package/dist/templates/default/packages/backend/convex/downloads/http.ts +0 -32
- package/dist/templates/default/packages/backend/convex/downloads/internal.ts +0 -58
- package/dist/templates/default/packages/backend/convex/github/actions/http.ts +0 -69
- package/dist/templates/default/packages/backend/convex/github/actions/internal.ts +0 -196
- package/dist/templates/default/packages/backend/convex/github/actions/oidc.ts +0 -75
- package/dist/templates/default/packages/backend/convex/github/actions/provision.ts +0 -76
- package/dist/templates/default/packages/backend/convex/github/actions/secrets.ts +0 -180
- package/dist/templates/default/packages/backend/convex/github/actions/signing.ts +0 -41
- package/dist/templates/default/packages/backend/convex/github/actions/tokens.ts +0 -145
- package/dist/templates/default/packages/backend/convex/github/identityCache.ts +0 -54
- package/dist/templates/default/packages/backend/convex/github/internal.ts +0 -33
- package/dist/templates/default/packages/backend/convex/previews/internal.ts +0 -257
- package/dist/templates/default/packages/backend/convex/previews/token/actions/create.ts +0 -83
- package/dist/templates/default/packages/backend/convex/previews/token/actions/management.ts +0 -182
- package/dist/templates/default/packages/backend/convex/previews/token/internal.ts +0 -32
- package/dist/templates/default/packages/backend/convex/releases/internal.ts +0 -28
- package/dist/templates/default/packages/backend/convex/validator.ts +0 -87
- package/dist/templates/default/packages/sdk/src/generated/client/client.gen.ts +0 -300
- package/dist/templates/default/packages/sdk/src/generated/client/index.ts +0 -27
- package/dist/templates/default/packages/sdk/src/generated/client/types.gen.ts +0 -238
- package/dist/templates/default/packages/sdk/src/generated/client/utils.gen.ts +0 -337
- package/dist/templates/default/packages/sdk/src/generated/client.gen.ts +0 -28
- package/dist/templates/default/packages/sdk/src/generated/core/auth.gen.ts +0 -49
- package/dist/templates/default/packages/sdk/src/generated/core/bodySerializer.gen.ts +0 -96
- package/dist/templates/default/packages/sdk/src/generated/core/params.gen.ts +0 -188
- package/dist/templates/default/packages/sdk/src/generated/core/pathSerializer.gen.ts +0 -186
- package/dist/templates/default/packages/sdk/src/generated/core/queryKeySerializer.gen.ts +0 -134
- package/dist/templates/default/packages/sdk/src/generated/core/serverSentEvents.gen.ts +0 -265
- package/dist/templates/default/packages/sdk/src/generated/core/types.gen.ts +0 -126
- package/dist/templates/default/packages/sdk/src/generated/core/utils.gen.ts +0 -146
- package/dist/templates/default/packages/sdk/src/generated/index.ts +0 -63
- package/dist/templates/default/packages/sdk/src/generated/sdk.gen.ts +0 -234
- package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +0 -660
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { v } from "convex/values";
|
|
2
|
-
import { internalQuery } from "@disposabl/disposabl-kit/server/lib/functions";
|
|
3
|
-
|
|
4
|
-
export const candidate = internalQuery({
|
|
5
|
-
args: { appId: v.string(), platform: v.string() },
|
|
6
|
-
returns: v.union(
|
|
7
|
-
v.null(),
|
|
8
|
-
v.object({
|
|
9
|
-
owner: v.string(),
|
|
10
|
-
repo: v.string(),
|
|
11
|
-
installationId: v.string(),
|
|
12
|
-
releaseUrl: v.string(),
|
|
13
|
-
artifactUrl: v.string(),
|
|
14
|
-
runId: v.number(),
|
|
15
|
-
attempt: v.number(),
|
|
16
|
-
}),
|
|
17
|
-
),
|
|
18
|
-
handler: async (ctx, { appId, platform }) => {
|
|
19
|
-
const app = await ctx.db
|
|
20
|
-
.query("apps")
|
|
21
|
-
.withIndex("by_appId", (q) => q.eq("appId", appId))
|
|
22
|
-
.unique();
|
|
23
|
-
if (
|
|
24
|
-
!app?.githubOwner ||
|
|
25
|
-
!app.githubRepo ||
|
|
26
|
-
app.operation?.kind === "delete" ||
|
|
27
|
-
!app.platforms.some((p) => p === platform)
|
|
28
|
-
)
|
|
29
|
-
return null;
|
|
30
|
-
const release = await ctx.db
|
|
31
|
-
.query("appReleases")
|
|
32
|
-
.withIndex("by_appId", (q) => q.eq("appId", appId))
|
|
33
|
-
.unique();
|
|
34
|
-
const latest = release?.releases[platform];
|
|
35
|
-
if (
|
|
36
|
-
latest?.status !== "ready" ||
|
|
37
|
-
!latest.githubReleaseUrl ||
|
|
38
|
-
!latest.artifactUrl
|
|
39
|
-
)
|
|
40
|
-
return null;
|
|
41
|
-
const connection = await ctx.db
|
|
42
|
-
.query("githubConnections")
|
|
43
|
-
.withIndex("by_userId_owner", (q) =>
|
|
44
|
-
q.eq("userId", app.userId).eq("owner", app.githubOwner!),
|
|
45
|
-
)
|
|
46
|
-
.unique();
|
|
47
|
-
if (!connection) return null;
|
|
48
|
-
return {
|
|
49
|
-
owner: app.githubOwner,
|
|
50
|
-
repo: app.githubRepo,
|
|
51
|
-
installationId: connection.installationId,
|
|
52
|
-
releaseUrl: latest.githubReleaseUrl,
|
|
53
|
-
artifactUrl: latest.artifactUrl,
|
|
54
|
-
runId: latest.run.id,
|
|
55
|
-
attempt: latest.run.attempt,
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { httpAction } from "../../_generated/server";
|
|
2
|
-
import { internal } from "../../_generated/api";
|
|
3
|
-
import { ConvexError } from "convex/values";
|
|
4
|
-
|
|
5
|
-
function retryResponse(error: unknown) {
|
|
6
|
-
const data = error instanceof ConvexError ? error.data : undefined;
|
|
7
|
-
if (
|
|
8
|
-
data &&
|
|
9
|
-
typeof data === "object" &&
|
|
10
|
-
"code" in data &&
|
|
11
|
-
data.code === "UPSTREAM_RETRY"
|
|
12
|
-
) {
|
|
13
|
-
const seconds = "retryAfter" in data ? Number(data.retryAfter) : 5;
|
|
14
|
-
return Response.json(
|
|
15
|
-
{ error: "GitHub connection is temporarily busy. Retry this request." },
|
|
16
|
-
{
|
|
17
|
-
status: 503,
|
|
18
|
-
headers: {
|
|
19
|
-
"Retry-After": String(
|
|
20
|
-
Math.max(1, Math.min(3600, Number.isFinite(seconds) ? seconds : 5)),
|
|
21
|
-
),
|
|
22
|
-
"Cache-Control": "no-store",
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const token = httpAction(async (ctx, request) => {
|
|
31
|
-
try {
|
|
32
|
-
const body = await request.json();
|
|
33
|
-
const token = request.headers.get("Authorization")?.replace(/^Bearer /, "");
|
|
34
|
-
if (!token) return new Response("Unauthorized", { status: 401 });
|
|
35
|
-
const result = await ctx.runAction(internal.github.actions.internal.token, {
|
|
36
|
-
appId: body.appId,
|
|
37
|
-
token,
|
|
38
|
-
});
|
|
39
|
-
return Response.json(result, { headers: { "Cache-Control": "no-store" } });
|
|
40
|
-
} catch (error) {
|
|
41
|
-
return (
|
|
42
|
-
retryResponse(error) ??
|
|
43
|
-
Response.json(
|
|
44
|
-
{ error: "Actions identity or app binding rejected." },
|
|
45
|
-
{ status: 403 },
|
|
46
|
-
)
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
export const report = httpAction(async (ctx, request) => {
|
|
51
|
-
try {
|
|
52
|
-
const body = await request.json();
|
|
53
|
-
const token = request.headers.get("Authorization")?.replace(/^Bearer /, "");
|
|
54
|
-
if (!token) return new Response("Unauthorized", { status: 401 });
|
|
55
|
-
await ctx.runAction(internal.github.actions.internal.report, {
|
|
56
|
-
...body,
|
|
57
|
-
token,
|
|
58
|
-
});
|
|
59
|
-
return Response.json(
|
|
60
|
-
{ ok: true },
|
|
61
|
-
{ headers: { "Cache-Control": "no-store" } },
|
|
62
|
-
);
|
|
63
|
-
} catch (error) {
|
|
64
|
-
return (
|
|
65
|
-
retryResponse(error) ??
|
|
66
|
-
Response.json({ error: "Actions report rejected." }, { status: 403 })
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use node";
|
|
2
|
-
|
|
3
|
-
import { internalAction } from "@disposabl/disposabl-kit/server/lib/functions";
|
|
4
|
-
import { v } from "convex/values";
|
|
5
|
-
import { internal } from "../../_generated/api";
|
|
6
|
-
import type { ActionCtx } from "../../_generated/server";
|
|
7
|
-
import { platform, releaseDetails } from "../../validator";
|
|
8
|
-
import { githubRequest, githubToken } from "./tokens";
|
|
9
|
-
import { verifyGitHubToken } from "./oidc";
|
|
10
|
-
|
|
11
|
-
type WorkflowRun = {
|
|
12
|
-
id: number;
|
|
13
|
-
run_attempt: number;
|
|
14
|
-
run_number: number;
|
|
15
|
-
head_sha: string;
|
|
16
|
-
head_branch: string;
|
|
17
|
-
event: string;
|
|
18
|
-
html_url: string;
|
|
19
|
-
path: string;
|
|
20
|
-
repository: { id: number };
|
|
21
|
-
head_repository: { id: number };
|
|
22
|
-
};
|
|
23
|
-
async function authorize(ctx: ActionCtx, appId: string, token: string) {
|
|
24
|
-
const claims = await verifyGitHubToken(token);
|
|
25
|
-
const app = await ctx.runQuery(internal.apps.internal.githubApp, { appId });
|
|
26
|
-
if (!app) throw new Error("Repository is not linked to this app.");
|
|
27
|
-
const repository = `${app.githubOwner}/${app.githubRepo}`;
|
|
28
|
-
const publisher = claims.environment === "publishing";
|
|
29
|
-
const workflowPath = ".github/workflows/pipeline.yml";
|
|
30
|
-
const workflow = `${repository}/${workflowPath}@${claims.ref}`;
|
|
31
|
-
if (
|
|
32
|
-
claims.repository !== repository ||
|
|
33
|
-
claims.workflow_ref !== workflow ||
|
|
34
|
-
(claims.job_workflow_ref && claims.job_workflow_ref !== workflow)
|
|
35
|
-
)
|
|
36
|
-
throw new Error("Unexpected workflow.");
|
|
37
|
-
const productionEvent =
|
|
38
|
-
claims.event_name === "push" && claims.ref === "refs/heads/main";
|
|
39
|
-
if (claims.event_name !== "pull_request" && !productionEvent)
|
|
40
|
-
throw new Error("Unexpected workflow event.");
|
|
41
|
-
// PR build code only receives read access. Write tokens go to main or its trusted artifact publisher.
|
|
42
|
-
const installationToken = await githubToken(
|
|
43
|
-
ctx,
|
|
44
|
-
app.installationId,
|
|
45
|
-
[
|
|
46
|
-
publisher || productionEvent ? "contents:write" : "contents:read",
|
|
47
|
-
"actions:read",
|
|
48
|
-
"pull_requests:read",
|
|
49
|
-
],
|
|
50
|
-
repository,
|
|
51
|
-
);
|
|
52
|
-
const { id: repositoryId } = await githubRequest<{ id: number }>(
|
|
53
|
-
installationToken,
|
|
54
|
-
`/repos/${repository}`,
|
|
55
|
-
);
|
|
56
|
-
if (String(repositoryId) !== claims.repository_id)
|
|
57
|
-
throw new Error("Repository does not match Actions identity.");
|
|
58
|
-
const workflowRun = await githubRequest<WorkflowRun>(
|
|
59
|
-
installationToken,
|
|
60
|
-
`/repos/${repository}/actions/runs/${claims.run_id}`,
|
|
61
|
-
);
|
|
62
|
-
if (
|
|
63
|
-
workflowRun.id !== Number(claims.run_id) ||
|
|
64
|
-
workflowRun.run_attempt !== Number(claims.run_attempt) ||
|
|
65
|
-
workflowRun.repository.id !== repositoryId ||
|
|
66
|
-
workflowRun.head_repository.id !== repositoryId ||
|
|
67
|
-
workflowRun.event !== claims.event_name ||
|
|
68
|
-
workflowRun.path.split("@")[0] !== workflowPath
|
|
69
|
-
)
|
|
70
|
-
throw new Error("Workflow run does not match Actions identity.");
|
|
71
|
-
if (publisher && !productionEvent) {
|
|
72
|
-
// PR changes cannot grant themselves a publishing environment or execute different publisher steps.
|
|
73
|
-
if (!/^[a-f0-9]{40}$/.test(claims.workflow_sha ?? ""))
|
|
74
|
-
throw new Error("Missing workflow source identity.");
|
|
75
|
-
const workflowFile = `/repos/${repository}/contents/${workflowPath}`;
|
|
76
|
-
const [source, trusted] = await Promise.all([
|
|
77
|
-
githubRequest<{ sha: string }>(
|
|
78
|
-
installationToken,
|
|
79
|
-
`${workflowFile}?ref=${claims.workflow_sha}`,
|
|
80
|
-
),
|
|
81
|
-
githubRequest<{ sha: string }>(
|
|
82
|
-
installationToken,
|
|
83
|
-
`${workflowFile}?ref=main`,
|
|
84
|
-
),
|
|
85
|
-
]);
|
|
86
|
-
if (source.sha !== trusted.sha)
|
|
87
|
-
throw new Error(
|
|
88
|
-
"Merge workflow changes before publishing preview artifacts.",
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
const production = workflowRun.event === "push";
|
|
92
|
-
if (production && workflowRun.head_branch !== "main")
|
|
93
|
-
throw new Error("Production requires main.");
|
|
94
|
-
if (
|
|
95
|
-
!production &&
|
|
96
|
-
claims.head_ref &&
|
|
97
|
-
claims.head_ref !== workflowRun.head_branch
|
|
98
|
-
)
|
|
99
|
-
throw new Error("Unexpected preview branch.");
|
|
100
|
-
await ctx.runMutation(internal.apps.operations.internal.workflow, {
|
|
101
|
-
userId: app.userId,
|
|
102
|
-
appId,
|
|
103
|
-
production,
|
|
104
|
-
});
|
|
105
|
-
return {
|
|
106
|
-
app,
|
|
107
|
-
repository,
|
|
108
|
-
installationToken,
|
|
109
|
-
production,
|
|
110
|
-
reference: production ? "main" : workflowRun.head_branch,
|
|
111
|
-
run: {
|
|
112
|
-
id: workflowRun.id,
|
|
113
|
-
attempt: workflowRun.run_attempt,
|
|
114
|
-
number: workflowRun.run_number,
|
|
115
|
-
commitSha: workflowRun.head_sha,
|
|
116
|
-
url: workflowRun.html_url,
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
export const token = internalAction({
|
|
121
|
-
args: {
|
|
122
|
-
appId: v.string(),
|
|
123
|
-
token: v.string(),
|
|
124
|
-
},
|
|
125
|
-
returns: v.object({ token: v.string() }),
|
|
126
|
-
handler: async (ctx, args): Promise<{ token: string }> => ({
|
|
127
|
-
token: (await authorize(ctx, args.appId, args.token)).installationToken,
|
|
128
|
-
}),
|
|
129
|
-
});
|
|
130
|
-
export const report = internalAction({
|
|
131
|
-
args: {
|
|
132
|
-
appId: v.string(),
|
|
133
|
-
token: v.string(),
|
|
134
|
-
platform,
|
|
135
|
-
...releaseDetails,
|
|
136
|
-
},
|
|
137
|
-
returns: v.null(),
|
|
138
|
-
handler: async (ctx, args) => {
|
|
139
|
-
const verified = await authorize(ctx, args.appId, args.token);
|
|
140
|
-
for (const field of [
|
|
141
|
-
"url",
|
|
142
|
-
"githubReleaseUrl",
|
|
143
|
-
"artifactUrl",
|
|
144
|
-
"updateUrl",
|
|
145
|
-
] as const) {
|
|
146
|
-
if (!args[field]) continue;
|
|
147
|
-
const url = new URL(args[field]);
|
|
148
|
-
if (url.protocol !== "https:" || url.username || url.password)
|
|
149
|
-
throw new Error("Release links must use HTTPS.");
|
|
150
|
-
if (
|
|
151
|
-
field === "githubReleaseUrl" ||
|
|
152
|
-
(field === "artifactUrl" && url.hostname === "github.com")
|
|
153
|
-
) {
|
|
154
|
-
if (
|
|
155
|
-
url.hostname !== "github.com" ||
|
|
156
|
-
!url.pathname.startsWith(`/${verified.repository}/releases/`)
|
|
157
|
-
)
|
|
158
|
-
throw new Error("Release belongs to another repository.");
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (args.githubReleaseUrl) {
|
|
162
|
-
const tag = new URL(args.githubReleaseUrl).pathname.split(
|
|
163
|
-
"/releases/tag/",
|
|
164
|
-
)[1];
|
|
165
|
-
if (!tag) throw new Error("Expected a GitHub release link.");
|
|
166
|
-
const release = await githubRequest<{
|
|
167
|
-
html_url: string;
|
|
168
|
-
draft: boolean;
|
|
169
|
-
assets: { browser_download_url: string }[];
|
|
170
|
-
}>(
|
|
171
|
-
verified.installationToken,
|
|
172
|
-
`/repos/${verified.repository}/releases/tags/${encodeURIComponent(decodeURIComponent(tag))}`,
|
|
173
|
-
);
|
|
174
|
-
if (
|
|
175
|
-
release.draft ||
|
|
176
|
-
release.html_url !== args.githubReleaseUrl ||
|
|
177
|
-
(args.artifactUrl &&
|
|
178
|
-
!release.assets.some(
|
|
179
|
-
(asset) => asset.browser_download_url === args.artifactUrl,
|
|
180
|
-
))
|
|
181
|
-
)
|
|
182
|
-
throw new Error("Release or download is not published.");
|
|
183
|
-
}
|
|
184
|
-
const { token: _token, ...result } = args;
|
|
185
|
-
await ctx.runMutation(internal.previews.internal.report, {
|
|
186
|
-
...result,
|
|
187
|
-
userId: verified.app.userId,
|
|
188
|
-
githubOwner: verified.app.githubOwner,
|
|
189
|
-
githubRepo: verified.app.githubRepo,
|
|
190
|
-
reference: verified.reference,
|
|
191
|
-
production: verified.production,
|
|
192
|
-
run: verified.run,
|
|
193
|
-
});
|
|
194
|
-
return null;
|
|
195
|
-
},
|
|
196
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use node";
|
|
2
|
-
|
|
3
|
-
const decode = (value: string) =>
|
|
4
|
-
Uint8Array.from(atob(value.replace(/-/g, "+").replace(/_/g, "/")), (char) =>
|
|
5
|
-
char.charCodeAt(0),
|
|
6
|
-
);
|
|
7
|
-
const json = (value: string) =>
|
|
8
|
-
JSON.parse(new TextDecoder().decode(decode(value)));
|
|
9
|
-
|
|
10
|
-
/** GitHub alone signs the repository, workflow and run identity. */
|
|
11
|
-
export async function verifyGitHubToken(token: string) {
|
|
12
|
-
if (token.length > 16_000) throw new Error("Invalid Actions token.");
|
|
13
|
-
const parts = token.split(".");
|
|
14
|
-
if (parts.length !== 3) throw new Error("Invalid Actions token.");
|
|
15
|
-
const [headerPart, bodyPart, signature] = parts as [string, string, string];
|
|
16
|
-
const header = json(headerPart);
|
|
17
|
-
if (header.alg !== "RS256" || typeof header.kid !== "string")
|
|
18
|
-
throw new Error("Invalid Actions signature.");
|
|
19
|
-
const response = await fetch(
|
|
20
|
-
"https://token.actions.githubusercontent.com/.well-known/jwks",
|
|
21
|
-
{ redirect: "error", signal: AbortSignal.timeout(15_000) },
|
|
22
|
-
);
|
|
23
|
-
if (!response.ok) throw new Error("Cannot verify Actions identity.");
|
|
24
|
-
const { keys } = (await response.json()) as {
|
|
25
|
-
keys: (JsonWebKey & { kid: string })[];
|
|
26
|
-
};
|
|
27
|
-
const key = keys.find((key) => key.kid === header.kid);
|
|
28
|
-
if (!key) throw new Error("Invalid Actions signature.");
|
|
29
|
-
const publicKey = await crypto.subtle.importKey(
|
|
30
|
-
"jwk",
|
|
31
|
-
key,
|
|
32
|
-
{
|
|
33
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
34
|
-
hash: "SHA-256",
|
|
35
|
-
},
|
|
36
|
-
false,
|
|
37
|
-
["verify"],
|
|
38
|
-
);
|
|
39
|
-
if (
|
|
40
|
-
!(await crypto.subtle.verify(
|
|
41
|
-
"RSASSA-PKCS1-v1_5",
|
|
42
|
-
publicKey,
|
|
43
|
-
decode(signature),
|
|
44
|
-
new TextEncoder().encode(`${headerPart}.${bodyPart}`),
|
|
45
|
-
))
|
|
46
|
-
)
|
|
47
|
-
throw new Error("Invalid Actions signature.");
|
|
48
|
-
const claims = json(bodyPart) as Record<string, unknown>;
|
|
49
|
-
const now = Date.now() / 1000;
|
|
50
|
-
if (
|
|
51
|
-
claims.iss !== "https://token.actions.githubusercontent.com" ||
|
|
52
|
-
claims.aud !== "https://disposabl.dev" ||
|
|
53
|
-
typeof claims.exp !== "number" ||
|
|
54
|
-
claims.exp <= now ||
|
|
55
|
-
typeof claims.nbf !== "number" ||
|
|
56
|
-
claims.nbf > now + 30
|
|
57
|
-
)
|
|
58
|
-
throw new Error("Expired or invalid Actions identity.");
|
|
59
|
-
for (const key of ["repository_id", "run_id", "run_attempt"] as const)
|
|
60
|
-
if (
|
|
61
|
-
typeof claims[key] !== "string" ||
|
|
62
|
-
!/^[1-9]\d*$/.test(claims[key]) ||
|
|
63
|
-
!Number.isSafeInteger(Number(claims[key]))
|
|
64
|
-
)
|
|
65
|
-
throw new Error("Invalid Actions run.");
|
|
66
|
-
for (const key of [
|
|
67
|
-
"repository",
|
|
68
|
-
"workflow_ref",
|
|
69
|
-
"ref",
|
|
70
|
-
"event_name",
|
|
71
|
-
] as const)
|
|
72
|
-
if (typeof claims[key] !== "string")
|
|
73
|
-
throw new Error("Missing Actions identity.");
|
|
74
|
-
return claims as Record<string, string>;
|
|
75
|
-
}
|
|
@@ -1,76 +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 { githubRequest, githubToken } from "./tokens";
|
|
10
|
-
|
|
11
|
-
type Repository = {
|
|
12
|
-
id: number;
|
|
13
|
-
name: string;
|
|
14
|
-
private: boolean;
|
|
15
|
-
description: string | null;
|
|
16
|
-
owner: { login: string };
|
|
17
|
-
};
|
|
18
|
-
export const run = internalAction({
|
|
19
|
-
args: { ...identityFields, appId: v.string() },
|
|
20
|
-
returns: v.null(),
|
|
21
|
-
handler: async (ctx, args) => {
|
|
22
|
-
const { app, connection } = await ctx.runQuery(
|
|
23
|
-
internal.apps.internal.githubSetup,
|
|
24
|
-
args,
|
|
25
|
-
);
|
|
26
|
-
if (app.githubOwner && app.githubRepo) return null;
|
|
27
|
-
const owner = connection?.owner;
|
|
28
|
-
const installationId = connection?.installationId;
|
|
29
|
-
if (!owner || !installationId || !/^[a-zA-Z0-9-]+$/.test(owner))
|
|
30
|
-
throw new Error("Configure a verified GitHub installation.");
|
|
31
|
-
const token = await githubToken(ctx, installationId, [
|
|
32
|
-
"administration:write",
|
|
33
|
-
"contents:read",
|
|
34
|
-
]);
|
|
35
|
-
const name = `${app.name
|
|
36
|
-
.toLowerCase()
|
|
37
|
-
.replace(/[^a-z0-9_.-]/g, "-")
|
|
38
|
-
.slice(0, 55)}-${app.appId}`;
|
|
39
|
-
const description = `Disposabl app ${app.appId}`;
|
|
40
|
-
const account = await githubRequest<{ type: string }>(
|
|
41
|
-
token,
|
|
42
|
-
`/users/${owner}`,
|
|
43
|
-
);
|
|
44
|
-
let repo: Repository;
|
|
45
|
-
try {
|
|
46
|
-
repo = await githubRequest<Repository>(
|
|
47
|
-
token,
|
|
48
|
-
account.type === "Organization"
|
|
49
|
-
? `/orgs/${owner}/repos`
|
|
50
|
-
: "/user/repos",
|
|
51
|
-
{ name, description, private: true, auto_init: false },
|
|
52
|
-
);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
try {
|
|
55
|
-
repo = await githubRequest<Repository>(
|
|
56
|
-
token,
|
|
57
|
-
`/repos/${owner}/${name}`,
|
|
58
|
-
);
|
|
59
|
-
} catch {
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (
|
|
64
|
-
!repo.private ||
|
|
65
|
-
repo.owner.login.toLowerCase() !== owner.toLowerCase() ||
|
|
66
|
-
repo.description !== description
|
|
67
|
-
)
|
|
68
|
-
throw new Error("Repository does not match this app.");
|
|
69
|
-
await ctx.runMutation(internal.apps.internal.connectGithub, {
|
|
70
|
-
...args,
|
|
71
|
-
githubOwner: repo.owner.login,
|
|
72
|
-
githubRepo: repo.name,
|
|
73
|
-
});
|
|
74
|
-
return null;
|
|
75
|
-
},
|
|
76
|
-
});
|
|
@@ -1,180 +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, unseal } from "../../connections/actions/credentials";
|
|
10
|
-
import { ensureExpo } from "../../apps/actions/expo";
|
|
11
|
-
import { validateExpo } from "../../connections/actions/expo";
|
|
12
|
-
import {
|
|
13
|
-
management,
|
|
14
|
-
ensureProduction,
|
|
15
|
-
} from "../../previews/token/actions/management";
|
|
16
|
-
import { githubRequest, githubToken } from "./tokens";
|
|
17
|
-
import { generateAndroidSigning } from "./signing";
|
|
18
|
-
|
|
19
|
-
export const configure = internalAction({
|
|
20
|
-
args: { ...identityFields, appId: v.string(), projectId: v.number() },
|
|
21
|
-
returns: v.null(),
|
|
22
|
-
handler: async (ctx, args) => {
|
|
23
|
-
const details = await ctx.runQuery(internal.apps.internal.get, {
|
|
24
|
-
userId: args.userId,
|
|
25
|
-
appId: args.appId,
|
|
26
|
-
});
|
|
27
|
-
const app = await ctx.runQuery(internal.apps.internal.githubApp, {
|
|
28
|
-
appId: args.appId,
|
|
29
|
-
});
|
|
30
|
-
if (!app)
|
|
31
|
-
throw new Error(
|
|
32
|
-
"Reconnect the GitHub account that owns this app before continuing setup.",
|
|
33
|
-
);
|
|
34
|
-
const repository = `${app.githubOwner}/${app.githubRepo}`;
|
|
35
|
-
const token = await githubToken(
|
|
36
|
-
ctx,
|
|
37
|
-
app.installationId,
|
|
38
|
-
["secrets:write"],
|
|
39
|
-
repository,
|
|
40
|
-
);
|
|
41
|
-
const path = `/repos/${repository}/actions/secrets`;
|
|
42
|
-
const names = new Set<string>();
|
|
43
|
-
for (let page = 1; ; page++) {
|
|
44
|
-
const existing = await githubRequest<{ secrets: { name: string }[] }>(
|
|
45
|
-
token,
|
|
46
|
-
`${path}?per_page=100&page=${page}`,
|
|
47
|
-
);
|
|
48
|
-
for (const secret of existing.secrets) names.add(secret.name);
|
|
49
|
-
if (existing.secrets.length < 100) break;
|
|
50
|
-
}
|
|
51
|
-
const legacySigning = [
|
|
52
|
-
"ANDROID_KEYSTORE_BASE64",
|
|
53
|
-
"ANDROID_KEYSTORE_PASSWORD",
|
|
54
|
-
"ANDROID_KEY_ALIAS",
|
|
55
|
-
"ANDROID_KEY_PASSWORD",
|
|
56
|
-
];
|
|
57
|
-
const legacyCount = legacySigning.filter((name) => names.has(name)).length;
|
|
58
|
-
if (
|
|
59
|
-
details.platforms.includes("android") &&
|
|
60
|
-
!names.has("DISPOSABL_ANDROID_SIGNING") &&
|
|
61
|
-
legacyCount > 0 &&
|
|
62
|
-
legacyCount < legacySigning.length
|
|
63
|
-
)
|
|
64
|
-
throw new Error(
|
|
65
|
-
"Android signing secrets are incomplete. Restore all four legacy ANDROID_* signing secrets before retrying setup. If this app has never shipped, remove the partial set to generate a new key.",
|
|
66
|
-
);
|
|
67
|
-
const publicKey = await githubRequest<{ key_id: string; key: string }>(
|
|
68
|
-
token,
|
|
69
|
-
`${path}/public-key`,
|
|
70
|
-
);
|
|
71
|
-
const { default: sodium } = await import("libsodium-wrappers");
|
|
72
|
-
await sodium.ready;
|
|
73
|
-
const save = async (name: string, value: string) => {
|
|
74
|
-
const encrypted = sodium.crypto_box_seal(
|
|
75
|
-
value,
|
|
76
|
-
sodium.from_base64(publicKey.key, sodium.base64_variants.ORIGINAL),
|
|
77
|
-
);
|
|
78
|
-
await githubRequest(
|
|
79
|
-
token,
|
|
80
|
-
`${path}/${name}`,
|
|
81
|
-
{
|
|
82
|
-
key_id: publicKey.key_id,
|
|
83
|
-
encrypted_value: sodium.to_base64(
|
|
84
|
-
encrypted,
|
|
85
|
-
sodium.base64_variants.ORIGINAL,
|
|
86
|
-
),
|
|
87
|
-
},
|
|
88
|
-
"PUT",
|
|
89
|
-
);
|
|
90
|
-
};
|
|
91
|
-
if (
|
|
92
|
-
details.platforms.includes("android") &&
|
|
93
|
-
!names.has("DISPOSABL_ANDROID_SIGNING") &&
|
|
94
|
-
legacyCount === 0
|
|
95
|
-
) {
|
|
96
|
-
await save(
|
|
97
|
-
"DISPOSABL_ANDROID_SIGNING",
|
|
98
|
-
JSON.stringify(await generateAndroidSigning()),
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
const { token: managementToken } = await credential(
|
|
102
|
-
ctx,
|
|
103
|
-
args.userId,
|
|
104
|
-
"convex",
|
|
105
|
-
);
|
|
106
|
-
if (!names.has("CONVEX_DEPLOY_KEY")) {
|
|
107
|
-
const deployment = await ensureProduction(
|
|
108
|
-
managementToken,
|
|
109
|
-
args.projectId,
|
|
110
|
-
);
|
|
111
|
-
const { deployKey } = await management<{ deployKey: string }>(
|
|
112
|
-
managementToken,
|
|
113
|
-
`/deployments/${deployment}/create_deploy_key`,
|
|
114
|
-
{ name: "github-actions-production" },
|
|
115
|
-
);
|
|
116
|
-
if (!deployKey.startsWith(`prod:${deployment}|`))
|
|
117
|
-
throw new Error("Expected a production deploy key.");
|
|
118
|
-
await save("CONVEX_DEPLOY_KEY", deployKey);
|
|
119
|
-
}
|
|
120
|
-
if (!names.has("CONVEX_DEPLOY_KEY_PREVIEW")) {
|
|
121
|
-
const { previewDeployKey } = await management<{
|
|
122
|
-
previewDeployKey: string;
|
|
123
|
-
}>(
|
|
124
|
-
managementToken,
|
|
125
|
-
`/projects/${args.projectId}/create_preview_deploy_key`,
|
|
126
|
-
{ name: "github-actions-preview" },
|
|
127
|
-
);
|
|
128
|
-
if (!previewDeployKey.startsWith("preview:"))
|
|
129
|
-
throw new Error("Expected a preview deploy key.");
|
|
130
|
-
await save("CONVEX_DEPLOY_KEY_PREVIEW", previewDeployKey);
|
|
131
|
-
}
|
|
132
|
-
const expo = await ctx.runQuery(internal.connections.internal.get, {
|
|
133
|
-
userId: args.userId,
|
|
134
|
-
provider: "expo",
|
|
135
|
-
});
|
|
136
|
-
if (
|
|
137
|
-
expo &&
|
|
138
|
-
details.platforms.some(
|
|
139
|
-
(platform) => platform === "android" || platform === "ios",
|
|
140
|
-
)
|
|
141
|
-
) {
|
|
142
|
-
const token = unseal(expo.token, `${args.userId}:expo`);
|
|
143
|
-
const accounts = await validateExpo(token);
|
|
144
|
-
if (!accounts.some((account) => account.id === expo.accountId))
|
|
145
|
-
throw new Error(
|
|
146
|
-
"Reconnect your Expo account before setting up mobile builds.",
|
|
147
|
-
);
|
|
148
|
-
const linked = await ctx.runQuery(
|
|
149
|
-
internal.apps.operations.internal.linked,
|
|
150
|
-
{
|
|
151
|
-
userId: args.userId,
|
|
152
|
-
appId: args.appId,
|
|
153
|
-
},
|
|
154
|
-
);
|
|
155
|
-
await ctx.runMutation(internal.apps.operations.internal.saveExpo, {
|
|
156
|
-
userId: args.userId,
|
|
157
|
-
appId: args.appId,
|
|
158
|
-
accountId: expo.accountId,
|
|
159
|
-
});
|
|
160
|
-
const project = await ensureExpo(
|
|
161
|
-
token,
|
|
162
|
-
expo.accountId,
|
|
163
|
-
expo.name,
|
|
164
|
-
args.appId,
|
|
165
|
-
linked.expoProjectId,
|
|
166
|
-
);
|
|
167
|
-
await ctx.runMutation(internal.apps.operations.internal.saveExpo, {
|
|
168
|
-
userId: args.userId,
|
|
169
|
-
appId: args.appId,
|
|
170
|
-
projectId: project.id,
|
|
171
|
-
accountId: expo.accountId,
|
|
172
|
-
});
|
|
173
|
-
await save("EXPO_PROJECT_ID", project.id);
|
|
174
|
-
await save("EXPO_SLUG", project.slug);
|
|
175
|
-
await save("EXPO_TOKEN", token);
|
|
176
|
-
await save("EXPO_OWNER", expo.name);
|
|
177
|
-
}
|
|
178
|
-
return null;
|
|
179
|
-
},
|
|
180
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use node";
|
|
2
|
-
|
|
3
|
-
import { generateKeyPair, randomBytes } from "node:crypto";
|
|
4
|
-
import { promisify } from "node:util";
|
|
5
|
-
import forge from "node-forge";
|
|
6
|
-
|
|
7
|
-
export async function generateAndroidSigning() {
|
|
8
|
-
const { privateKey, publicKey } = await promisify(generateKeyPair)("rsa", {
|
|
9
|
-
modulusLength: 2048,
|
|
10
|
-
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
11
|
-
privateKeyEncoding: { type: "pkcs8", format: "pem" },
|
|
12
|
-
});
|
|
13
|
-
const key = forge.pki.privateKeyFromPem(privateKey);
|
|
14
|
-
const certificate = forge.pki.createCertificate();
|
|
15
|
-
certificate.publicKey = forge.pki.publicKeyFromPem(publicKey);
|
|
16
|
-
certificate.serialNumber = `01${randomBytes(16).toString("hex")}`;
|
|
17
|
-
certificate.validity.notBefore = new Date();
|
|
18
|
-
certificate.validity.notAfter = new Date();
|
|
19
|
-
certificate.validity.notAfter.setUTCFullYear(
|
|
20
|
-
certificate.validity.notAfter.getUTCFullYear() + 30,
|
|
21
|
-
);
|
|
22
|
-
const subject = [{ name: "commonName", value: "Android Release" }];
|
|
23
|
-
certificate.setSubject(subject);
|
|
24
|
-
certificate.setIssuer(subject);
|
|
25
|
-
certificate.sign(key, forge.md.sha256.create());
|
|
26
|
-
const storePassword = randomBytes(32).toString("base64url");
|
|
27
|
-
const keyAlias = "android-release";
|
|
28
|
-
const p12 = forge.pkcs12.toPkcs12Asn1(key, [certificate], storePassword, {
|
|
29
|
-
algorithm: "3des",
|
|
30
|
-
friendlyName: keyAlias,
|
|
31
|
-
});
|
|
32
|
-
return {
|
|
33
|
-
keystoreBase64: Buffer.from(
|
|
34
|
-
forge.asn1.toDer(p12).getBytes(),
|
|
35
|
-
"binary",
|
|
36
|
-
).toString("base64"),
|
|
37
|
-
storePassword,
|
|
38
|
-
keyAlias,
|
|
39
|
-
keyPassword: storePassword,
|
|
40
|
-
};
|
|
41
|
-
}
|