create-disposabl-app 0.8.1 → 0.8.2
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 +36 -2
- package/dist/index.js +73 -5
- package/dist/templates/default/.github/scripts/apple.sh +62 -0
- package/dist/templates/default/.github/scripts/disposabl.mjs +31 -14
- package/dist/templates/default/.github/scripts/mobile.sh +9 -9
- package/dist/templates/default/.github/scripts/platforms.sh +3 -3
- package/dist/templates/default/.github/scripts/release.sh +1 -1
- package/dist/templates/default/.github/workflows/pipeline.yml +115 -6
- package/dist/templates/default/apps/desktop/.oxfmtrc.json +5 -0
- package/dist/templates/default/apps/desktop/.oxlintrc.json +6 -0
- package/dist/templates/default/apps/desktop/README.md +90 -0
- package/dist/templates/default/apps/desktop/build-ci.mjs +56 -0
- package/dist/templates/default/apps/desktop/forge.config.mts +124 -0
- package/dist/templates/default/apps/desktop/gitignore +146 -0
- package/dist/templates/default/apps/desktop/index.html +16 -0
- package/dist/templates/default/apps/desktop/package.json +55 -0
- package/dist/templates/default/apps/desktop/rpm.spec.ejs +84 -0
- package/dist/templates/default/apps/desktop/src/assets/icon.icns +0 -0
- package/dist/templates/default/apps/desktop/src/assets/icon.ico +0 -0
- package/dist/templates/default/apps/desktop/src/assets/icon.png +0 -0
- package/dist/templates/default/apps/desktop/src/assets/logo.svg +8 -0
- package/dist/templates/default/apps/desktop/src/declarations.d.ts +4 -0
- package/dist/templates/default/apps/desktop/src/index.css +27 -0
- package/dist/templates/default/apps/desktop/src/main.ts +54 -0
- package/dist/templates/default/apps/desktop/src/preload.ts +3 -0
- package/dist/templates/default/apps/desktop/src/renderer.ts +1 -0
- package/dist/templates/default/apps/desktop/tsconfig.json +14 -0
- package/dist/templates/default/apps/desktop/vite.main.config.mts +9 -0
- package/dist/templates/default/apps/desktop/vite.preload.config.mts +4 -0
- package/dist/templates/default/apps/desktop/vite.renderer.config.mts +4 -0
- package/dist/templates/default/apps/mobile/README.md +1 -1
- package/dist/templates/default/apps/mobile/eas.json +2 -2
- package/dist/templates/default/apps/web/src/components/connections/provider-logo.tsx +38 -0
- package/dist/templates/default/apps/web/src/index.css +0 -22
- package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.connections.tsx +244 -153
- package/dist/templates/default/bun.lock +4 -0
- package/dist/templates/default/dev.ts +22 -6
- package/dist/templates/default/packages/backend/convex/_generated/api.d.ts +10 -0
- package/dist/templates/default/packages/backend/convex/apps/actions/cleanup.ts +1 -0
- package/dist/templates/default/packages/backend/convex/apps/internal.ts +17 -1
- package/dist/templates/default/packages/backend/convex/connections/actions/github.ts +5 -4
- package/dist/templates/default/packages/backend/convex/connections/actions/oauth.ts +2 -2
- package/dist/templates/default/packages/backend/convex/downloads/action.ts +136 -0
- package/dist/templates/default/packages/backend/convex/downloads/http.ts +32 -0
- package/dist/templates/default/packages/backend/convex/downloads/internal.ts +58 -0
- package/dist/templates/default/packages/backend/convex/github/actions/http.ts +37 -8
- package/dist/templates/default/packages/backend/convex/github/actions/internal.ts +1 -0
- package/dist/templates/default/packages/backend/convex/github/actions/provision.ts +1 -1
- package/dist/templates/default/packages/backend/convex/github/actions/secrets.ts +38 -6
- package/dist/templates/default/packages/backend/convex/github/actions/signing.ts +41 -0
- package/dist/templates/default/packages/backend/convex/github/actions/tokens.ts +82 -16
- package/dist/templates/default/packages/backend/convex/github/identityCache.ts +54 -0
- package/dist/templates/default/packages/backend/convex/http.ts +3 -0
- package/dist/templates/default/packages/backend/convex/previews/token/actions/create.ts +21 -3
- package/dist/templates/default/packages/backend/convex/previews/token/actions/management.ts +17 -2
- package/dist/templates/default/packages/backend/convex/previews/token/internal.ts +4 -0
- package/dist/templates/default/packages/backend/convex/schema.ts +7 -0
- package/dist/templates/default/packages/backend/generated/openapi.json +107 -1
- package/dist/templates/default/packages/backend/generated/platforms.ts +12 -10
- package/dist/templates/default/packages/backend/package.json +3 -1
- package/dist/templates/default/packages/cli/preview.ts +63 -0
- package/dist/templates/default/packages/disposabl-kit/platforms.ts +3 -0
- package/dist/templates/default/packages/sdk/src/generated/index.ts +5 -0
- package/dist/templates/default/packages/sdk/src/generated/sdk.gen.ts +20 -0
- package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +69 -0
- package/dist/templates/default/packages/skill/SKILL.md +38 -0
- package/package.json +1 -1
|
@@ -143,12 +143,14 @@
|
|
|
143
143
|
"@vercel/connect": "^2.5.2",
|
|
144
144
|
"convex": "catalog:",
|
|
145
145
|
"libsodium-wrappers": "^0.8.4",
|
|
146
|
+
"node-forge": "^1.4.2",
|
|
146
147
|
},
|
|
147
148
|
"devDependencies": {
|
|
148
149
|
"@convex-dev/eslint-plugin": "^5.0.1",
|
|
149
150
|
"@eslint/eslintrc": "^3.3.6",
|
|
150
151
|
"@eslint/js": "^10.0.1",
|
|
151
152
|
"@types/node": "^24.13.3",
|
|
153
|
+
"@types/node-forge": "^1.3.14",
|
|
152
154
|
"@typescript-eslint/eslint-plugin": "^8.66.0",
|
|
153
155
|
"@typescript-eslint/parser": "^8.66.0",
|
|
154
156
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
@@ -1388,6 +1390,8 @@
|
|
|
1388
1390
|
|
|
1389
1391
|
"@types/node": ["@types/node@24.19.2", "", { "dependencies": { "undici-types": ">=7.24.0 <7.24.7" } }, "sha512-93d49wCWJkCyN87MxLpNN6KXPCwFw7bVUg79mGUV1OS40JGWwVCr8n61DXCSqz7CV6/VfPkb7xec7uP2M+QHWQ=="],
|
|
1390
1392
|
|
|
1393
|
+
"@types/node-forge": ["@types/node-forge@1.3.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-mhVF2BnD4BO+jtOp7z1CdzaK4mbuK0LLQYAvdOLqHTavxFNq4zA1EmYkpnFjP8HOUzedfQkRnp0E2ulSAYSzAw=="],
|
|
1394
|
+
|
|
1391
1395
|
"@types/normalize-package-data": ["@types/normalize-package-data@2.4.4", "", {}, "sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA=="],
|
|
1392
1396
|
|
|
1393
1397
|
"@types/proper-lockfile": ["@types/proper-lockfile@4.1.4", "", { "dependencies": { "@types/retry": "*" } }, "sha512-uo2ABllncSqg9F1D4nugVl9v93RmjxF6LJzQLMLDdPaXCUIDPeOJ21Gbqi43xNKzBi/WQ0Q0dICqufzQbMjipQ=="],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile, writeFile, access } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
3
|
import { parseEnv } from "node:util";
|
|
4
4
|
|
|
5
5
|
const root = import.meta.dir;
|
|
@@ -7,21 +7,37 @@ const backend = join(root, "packages/backend");
|
|
|
7
7
|
const read = (path: string) => readFile(path, "utf8").catch(() => "");
|
|
8
8
|
const backendEnv = () => read(join(backend, ".env.local")).then(parseEnv);
|
|
9
9
|
let env = await backendEnv();
|
|
10
|
-
|
|
10
|
+
const config = JSON.parse(await read(join(root, "disposabl.json")));
|
|
11
|
+
if (!env.CONVEX_DEPLOY_KEY && (!env.CONVEX_DEPLOYMENT || config.appId)) {
|
|
12
|
+
console.log("Setting up this app through your Disposabl connections…");
|
|
11
13
|
const configure = Bun.spawn(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
[
|
|
15
|
+
"bun",
|
|
16
|
+
"create",
|
|
17
|
+
"disposabl-app@latest",
|
|
18
|
+
basename(root),
|
|
19
|
+
"--setup",
|
|
20
|
+
"--yes",
|
|
21
|
+
],
|
|
14
22
|
{
|
|
15
|
-
cwd:
|
|
23
|
+
cwd: dirname(root),
|
|
16
24
|
stdin: "inherit",
|
|
17
25
|
stdout: "inherit",
|
|
18
26
|
stderr: "inherit",
|
|
19
27
|
},
|
|
20
28
|
);
|
|
21
29
|
if (await configure.exited)
|
|
22
|
-
throw new Error(
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Disposabl setup did not finish. Your files are saved; run bun run dev to resume.",
|
|
32
|
+
);
|
|
23
33
|
env = await backendEnv();
|
|
34
|
+
if (!env.CONVEX_DEPLOY_KEY?.startsWith("dev:"))
|
|
35
|
+
throw new Error("Disposabl setup must provide a scoped development token.");
|
|
24
36
|
}
|
|
37
|
+
if (env.CONVEX_DEPLOY_KEY && !env.CONVEX_DEPLOY_KEY.startsWith("dev:"))
|
|
38
|
+
throw new Error(
|
|
39
|
+
"Local development requires a development token, not production or CI credentials.",
|
|
40
|
+
);
|
|
25
41
|
const url = env.CONVEX_URL;
|
|
26
42
|
const site =
|
|
27
43
|
env.CONVEX_SITE_URL || url?.replace(/\.convex\.cloud$/, ".convex.site");
|
|
@@ -24,12 +24,17 @@ import type * as connections_actions_oauth from "../connections/actions/oauth.js
|
|
|
24
24
|
import type * as connections_index from "../connections/index.js";
|
|
25
25
|
import type * as connections_internal from "../connections/internal.js";
|
|
26
26
|
import type * as connections_validator from "../connections/validator.js";
|
|
27
|
+
import type * as downloads_action from "../downloads/action.js";
|
|
28
|
+
import type * as downloads_http from "../downloads/http.js";
|
|
29
|
+
import type * as downloads_internal from "../downloads/internal.js";
|
|
27
30
|
import type * as github_actions_http from "../github/actions/http.js";
|
|
28
31
|
import type * as github_actions_internal from "../github/actions/internal.js";
|
|
29
32
|
import type * as github_actions_oidc from "../github/actions/oidc.js";
|
|
30
33
|
import type * as github_actions_provision from "../github/actions/provision.js";
|
|
31
34
|
import type * as github_actions_secrets from "../github/actions/secrets.js";
|
|
35
|
+
import type * as github_actions_signing from "../github/actions/signing.js";
|
|
32
36
|
import type * as github_actions_tokens from "../github/actions/tokens.js";
|
|
37
|
+
import type * as github_identityCache from "../github/identityCache.js";
|
|
33
38
|
import type * as github_internal from "../github/internal.js";
|
|
34
39
|
import type * as http from "../http.js";
|
|
35
40
|
import type * as mcp from "../mcp.js";
|
|
@@ -65,12 +70,17 @@ declare const fullApi: ApiFromModules<{
|
|
|
65
70
|
"connections/index": typeof connections_index;
|
|
66
71
|
"connections/internal": typeof connections_internal;
|
|
67
72
|
"connections/validator": typeof connections_validator;
|
|
73
|
+
"downloads/action": typeof downloads_action;
|
|
74
|
+
"downloads/http": typeof downloads_http;
|
|
75
|
+
"downloads/internal": typeof downloads_internal;
|
|
68
76
|
"github/actions/http": typeof github_actions_http;
|
|
69
77
|
"github/actions/internal": typeof github_actions_internal;
|
|
70
78
|
"github/actions/oidc": typeof github_actions_oidc;
|
|
71
79
|
"github/actions/provision": typeof github_actions_provision;
|
|
72
80
|
"github/actions/secrets": typeof github_actions_secrets;
|
|
81
|
+
"github/actions/signing": typeof github_actions_signing;
|
|
73
82
|
"github/actions/tokens": typeof github_actions_tokens;
|
|
83
|
+
"github/identityCache": typeof github_identityCache;
|
|
74
84
|
"github/internal": typeof github_internal;
|
|
75
85
|
http: typeof http;
|
|
76
86
|
mcp: typeof mcp;
|
|
@@ -78,6 +78,7 @@ export const remove = internalAction({
|
|
|
78
78
|
const retry = resume("github", app.githubOwner);
|
|
79
79
|
// An installation-wide token remains usable after this repository is deleted.
|
|
80
80
|
const token = await githubToken(
|
|
81
|
+
ctx,
|
|
81
82
|
app.installationId,
|
|
82
83
|
["administration:write", "contents:read", "actions:read"],
|
|
83
84
|
retry ? undefined : repository,
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
paginationResultValidator,
|
|
9
9
|
} from "convex/server";
|
|
10
10
|
import { ConvexError, v, type Infer } from "convex/values";
|
|
11
|
-
import { appArgs, appResult } from "../validator";
|
|
11
|
+
import { appArgs, appResult, platform } from "../validator";
|
|
12
|
+
import { validatePlatforms } from "@disposabl/disposabl-kit/platforms";
|
|
12
13
|
import { githubConnection } from "../validator";
|
|
13
14
|
import type { Doc } from "../_generated/dataModel";
|
|
14
15
|
import type { QueryCtx } from "../_generated/server";
|
|
@@ -60,6 +61,21 @@ export const get = internalQuery({
|
|
|
60
61
|
handler: async (ctx, { userId, appId }) =>
|
|
61
62
|
presentApp(await ownedApp(ctx, userId, appId)),
|
|
62
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
|
+
});
|
|
63
79
|
export { remove as delete } from "./actions/delete";
|
|
64
80
|
|
|
65
81
|
function assertAppId(appId: string) {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
8
8
|
import { ConvexError, v, type Infer } from "convex/values";
|
|
9
9
|
import { internal } from "../../_generated/api";
|
|
10
|
-
import { env } from "../../_generated/server";
|
|
10
|
+
import { env, type ActionCtx } from "../../_generated/server";
|
|
11
11
|
import {
|
|
12
12
|
githubRequest,
|
|
13
13
|
githubToken,
|
|
@@ -32,13 +32,13 @@ const permissions = [
|
|
|
32
32
|
"secrets",
|
|
33
33
|
];
|
|
34
34
|
|
|
35
|
-
export async function userInstallations(userId: string) {
|
|
35
|
+
export async function userInstallations(ctx: ActionCtx, userId: string) {
|
|
36
36
|
const token = await getToken(
|
|
37
37
|
env.GITHUB_CONNECTOR!,
|
|
38
38
|
{
|
|
39
39
|
subject: { type: "user", id: userId },
|
|
40
40
|
},
|
|
41
|
-
{ vercelToken: await vercelIdentity(), forceRefresh: true },
|
|
41
|
+
{ vercelToken: await vercelIdentity(ctx), forceRefresh: true },
|
|
42
42
|
);
|
|
43
43
|
const user = await githubRequest<{ login: string }>(token, "/user");
|
|
44
44
|
const organizations = new Set<string>();
|
|
@@ -96,7 +96,7 @@ export const selectGithub = internalAction({
|
|
|
96
96
|
if (!chosen || verified.expiresAt < Date.now())
|
|
97
97
|
throw new ConvexError("Connect GitHub again to choose an account.");
|
|
98
98
|
// Re-check membership and the granted permissions before saving the binding.
|
|
99
|
-
const current = await userInstallations(userId);
|
|
99
|
+
const current = await userInstallations(ctx, userId);
|
|
100
100
|
if (
|
|
101
101
|
!current.installations.some(
|
|
102
102
|
(i) => i.installationId === installationId && i.owner === chosen.owner,
|
|
@@ -106,6 +106,7 @@ export const selectGithub = internalAction({
|
|
|
106
106
|
"GitHub access changed. Install Disposabl with the requested permissions.",
|
|
107
107
|
);
|
|
108
108
|
await githubToken(
|
|
109
|
+
ctx,
|
|
109
110
|
installationId,
|
|
110
111
|
permissions.map((p) => `${p}:write`),
|
|
111
112
|
);
|
|
@@ -42,7 +42,7 @@ export const start = internalAction({
|
|
|
42
42
|
env.GITHUB_CONNECTOR!,
|
|
43
43
|
{ subject: { type: "user", id: userId } },
|
|
44
44
|
{
|
|
45
|
-
vercelToken: await vercelIdentity(),
|
|
45
|
+
vercelToken: await vercelIdentity(ctx),
|
|
46
46
|
callbackUrl: `${callback}&code=connected&state=${state}`,
|
|
47
47
|
expiresInMs: 10 * 60_000,
|
|
48
48
|
},
|
|
@@ -79,7 +79,7 @@ export const complete = internalAction({
|
|
|
79
79
|
internal.connections.internal.consume,
|
|
80
80
|
{ userId, provider, hash: hash(state) },
|
|
81
81
|
);
|
|
82
|
-
if (provider === "github") return userInstallations(userId);
|
|
82
|
+
if (provider === "github") return userInstallations(ctx, userId);
|
|
83
83
|
const response = await fetch("https://api.convex.dev/oauth/token", {
|
|
84
84
|
method: "POST",
|
|
85
85
|
redirect: "error",
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use node";
|
|
2
|
+
|
|
3
|
+
import { v } from "convex/values";
|
|
4
|
+
import { internalAction } from "@disposabl/disposabl-kit/server/lib/functions";
|
|
5
|
+
import { internal } from "../_generated/api";
|
|
6
|
+
import { githubRequest, githubToken } from "../github/actions/tokens";
|
|
7
|
+
|
|
8
|
+
const suffixes: Partial<Record<string, string[]>> = {
|
|
9
|
+
android: [".apk"],
|
|
10
|
+
ios: [".ipa"],
|
|
11
|
+
macos: [".dmg"],
|
|
12
|
+
windows: [".exe"],
|
|
13
|
+
linux: [".AppImage", ".deb"],
|
|
14
|
+
};
|
|
15
|
+
type Candidate = {
|
|
16
|
+
owner: string;
|
|
17
|
+
repo: string;
|
|
18
|
+
installationId: string;
|
|
19
|
+
releaseUrl: string;
|
|
20
|
+
artifactUrl: string;
|
|
21
|
+
runId: number;
|
|
22
|
+
attempt: number;
|
|
23
|
+
};
|
|
24
|
+
type Release = {
|
|
25
|
+
html_url: string;
|
|
26
|
+
draft: boolean;
|
|
27
|
+
prerelease: boolean;
|
|
28
|
+
published_at: string | null;
|
|
29
|
+
assets: {
|
|
30
|
+
id: number;
|
|
31
|
+
name: string;
|
|
32
|
+
state: string;
|
|
33
|
+
browser_download_url: string;
|
|
34
|
+
}[];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const resolve = internalAction({
|
|
38
|
+
args: { appId: v.string(), platform: v.string() },
|
|
39
|
+
returns: v.union(v.string(), v.null()),
|
|
40
|
+
handler: async (ctx, args): Promise<string | null> => {
|
|
41
|
+
if (
|
|
42
|
+
!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(
|
|
43
|
+
args.appId,
|
|
44
|
+
) ||
|
|
45
|
+
!Object.hasOwn(suffixes, args.platform)
|
|
46
|
+
)
|
|
47
|
+
return null;
|
|
48
|
+
const candidate: Candidate | null = await ctx.runQuery(
|
|
49
|
+
internal.downloads.internal.candidate,
|
|
50
|
+
args,
|
|
51
|
+
);
|
|
52
|
+
if (
|
|
53
|
+
!candidate ||
|
|
54
|
+
!/^[a-zA-Z0-9-]+$/.test(candidate.owner) ||
|
|
55
|
+
!/^[a-zA-Z0-9_.-]+$/.test(candidate.repo)
|
|
56
|
+
)
|
|
57
|
+
return null;
|
|
58
|
+
const repository = `${candidate.owner}/${candidate.repo}`;
|
|
59
|
+
const prefix = `https://github.com/${repository}/releases/tag/`;
|
|
60
|
+
if (!candidate.releaseUrl.startsWith(prefix)) return null;
|
|
61
|
+
const encodedTag = candidate.releaseUrl.slice(prefix.length);
|
|
62
|
+
if (!encodedTag || /[?#]/.test(encodedTag)) return null;
|
|
63
|
+
let tag: string;
|
|
64
|
+
try {
|
|
65
|
+
tag = decodeURIComponent(encodedTag);
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
if (
|
|
70
|
+
tag !==
|
|
71
|
+
`app-production-${args.platform}-${candidate.runId}-${candidate.attempt}`
|
|
72
|
+
)
|
|
73
|
+
return null;
|
|
74
|
+
const token = await githubToken(
|
|
75
|
+
ctx,
|
|
76
|
+
candidate.installationId,
|
|
77
|
+
["contents:read"],
|
|
78
|
+
repository,
|
|
79
|
+
);
|
|
80
|
+
const release = await githubRequest<Release>(
|
|
81
|
+
token,
|
|
82
|
+
`/repos/${repository}/releases/tags/${encodeURIComponent(tag)}`,
|
|
83
|
+
);
|
|
84
|
+
if (
|
|
85
|
+
release.html_url !== candidate.releaseUrl ||
|
|
86
|
+
release.draft !== false ||
|
|
87
|
+
release.prerelease !== false ||
|
|
88
|
+
!release.published_at ||
|
|
89
|
+
!Array.isArray(release.assets)
|
|
90
|
+
)
|
|
91
|
+
return null;
|
|
92
|
+
const asset = release.assets.find(
|
|
93
|
+
(a) =>
|
|
94
|
+
a.browser_download_url === candidate.artifactUrl &&
|
|
95
|
+
a.state === "uploaded" &&
|
|
96
|
+
suffixes[args.platform]?.some((s) => a.name.endsWith(s)) &&
|
|
97
|
+
Number.isSafeInteger(a.id) &&
|
|
98
|
+
a.id > 0,
|
|
99
|
+
);
|
|
100
|
+
if (!asset) return null;
|
|
101
|
+
const response = await fetch(
|
|
102
|
+
`https://api.github.com/repos/${repository}/releases/assets/${asset.id}`,
|
|
103
|
+
{
|
|
104
|
+
headers: {
|
|
105
|
+
Authorization: `Bearer ${token}`,
|
|
106
|
+
Accept: "application/octet-stream",
|
|
107
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
108
|
+
},
|
|
109
|
+
redirect: "manual",
|
|
110
|
+
signal: AbortSignal.timeout(30_000),
|
|
111
|
+
},
|
|
112
|
+
);
|
|
113
|
+
if (response.status !== 302) return null;
|
|
114
|
+
const location = response.headers.get("location");
|
|
115
|
+
if (!location) return null;
|
|
116
|
+
const url = new URL(location);
|
|
117
|
+
if (
|
|
118
|
+
url.protocol !== "https:" ||
|
|
119
|
+
url.username ||
|
|
120
|
+
url.password ||
|
|
121
|
+
url.port ||
|
|
122
|
+
![
|
|
123
|
+
"release-assets.githubusercontent.com",
|
|
124
|
+
"objects.githubusercontent.com",
|
|
125
|
+
].includes(url.hostname)
|
|
126
|
+
)
|
|
127
|
+
return null;
|
|
128
|
+
const current: Candidate | null = await ctx.runQuery(
|
|
129
|
+
internal.downloads.internal.candidate,
|
|
130
|
+
args,
|
|
131
|
+
);
|
|
132
|
+
return JSON.stringify(current) === JSON.stringify(candidate)
|
|
133
|
+
? url.href
|
|
134
|
+
: null;
|
|
135
|
+
},
|
|
136
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { httpAction } from "../_generated/server";
|
|
2
|
+
import { internal } from "../_generated/api";
|
|
3
|
+
|
|
4
|
+
export const download = httpAction(async (ctx, request) => {
|
|
5
|
+
const headers = {
|
|
6
|
+
"Cache-Control": "no-store",
|
|
7
|
+
"Referrer-Policy": "no-referrer",
|
|
8
|
+
"X-Content-Type-Options": "nosniff",
|
|
9
|
+
};
|
|
10
|
+
try {
|
|
11
|
+
const match = /^\/downloads\/([^/]+)\/([^/]+)$/.exec(
|
|
12
|
+
new URL(request.url).pathname,
|
|
13
|
+
);
|
|
14
|
+
if (match) {
|
|
15
|
+
const location = await ctx.runAction(internal.downloads.action.resolve, {
|
|
16
|
+
appId: match.at(1) ?? "",
|
|
17
|
+
platform: match.at(2) ?? "",
|
|
18
|
+
});
|
|
19
|
+
if (location)
|
|
20
|
+
return new Response(null, {
|
|
21
|
+
status: 302,
|
|
22
|
+
headers: { ...headers, Location: location },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
// Do not disclose repository, connection, or upstream failure details.
|
|
27
|
+
}
|
|
28
|
+
return Response.json(
|
|
29
|
+
{ error: "Download not found or not ready." },
|
|
30
|
+
{ status: 404, headers },
|
|
31
|
+
);
|
|
32
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
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,5 +1,31 @@
|
|
|
1
1
|
import { httpAction } from "../../_generated/server";
|
|
2
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
|
+
}
|
|
3
29
|
|
|
4
30
|
export const token = httpAction(async (ctx, request) => {
|
|
5
31
|
try {
|
|
@@ -11,10 +37,13 @@ export const token = httpAction(async (ctx, request) => {
|
|
|
11
37
|
token,
|
|
12
38
|
});
|
|
13
39
|
return Response.json(result, { headers: { "Cache-Control": "no-store" } });
|
|
14
|
-
} catch {
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
40
|
+
} catch (error) {
|
|
41
|
+
return (
|
|
42
|
+
retryResponse(error) ??
|
|
43
|
+
Response.json(
|
|
44
|
+
{ error: "Actions identity or app binding rejected." },
|
|
45
|
+
{ status: 403 },
|
|
46
|
+
)
|
|
18
47
|
);
|
|
19
48
|
}
|
|
20
49
|
});
|
|
@@ -31,10 +60,10 @@ export const report = httpAction(async (ctx, request) => {
|
|
|
31
60
|
{ ok: true },
|
|
32
61
|
{ headers: { "Cache-Control": "no-store" } },
|
|
33
62
|
);
|
|
34
|
-
} catch {
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
{ status: 403 }
|
|
63
|
+
} catch (error) {
|
|
64
|
+
return (
|
|
65
|
+
retryResponse(error) ??
|
|
66
|
+
Response.json({ error: "Actions report rejected." }, { status: 403 })
|
|
38
67
|
);
|
|
39
68
|
}
|
|
40
69
|
});
|
|
@@ -40,6 +40,7 @@ async function authorize(ctx: ActionCtx, appId: string, token: string) {
|
|
|
40
40
|
throw new Error("Unexpected workflow event.");
|
|
41
41
|
// PR build code only receives read access. Write tokens go to main or its trusted artifact publisher.
|
|
42
42
|
const installationToken = await githubToken(
|
|
43
|
+
ctx,
|
|
43
44
|
app.installationId,
|
|
44
45
|
[
|
|
45
46
|
publisher || productionEvent ? "contents:write" : "contents:read",
|
|
@@ -28,7 +28,7 @@ export const run = internalAction({
|
|
|
28
28
|
const installationId = connection?.installationId;
|
|
29
29
|
if (!owner || !installationId || !/^[a-zA-Z0-9-]+$/.test(owner))
|
|
30
30
|
throw new Error("Configure a verified GitHub installation.");
|
|
31
|
-
const token = await githubToken(installationId, [
|
|
31
|
+
const token = await githubToken(ctx, installationId, [
|
|
32
32
|
"administration:write",
|
|
33
33
|
"contents:read",
|
|
34
34
|
]);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use node";
|
|
2
2
|
|
|
3
|
-
import sodium from "libsodium-wrappers";
|
|
4
3
|
import {
|
|
5
4
|
identityFields,
|
|
6
5
|
internalAction,
|
|
@@ -15,6 +14,7 @@ import {
|
|
|
15
14
|
ensureProduction,
|
|
16
15
|
} from "../../previews/token/actions/management";
|
|
17
16
|
import { githubRequest, githubToken } from "./tokens";
|
|
17
|
+
import { generateAndroidSigning } from "./signing";
|
|
18
18
|
|
|
19
19
|
export const configure = internalAction({
|
|
20
20
|
args: { ...identityFields, appId: v.string(), projectId: v.number() },
|
|
@@ -33,20 +33,42 @@ export const configure = internalAction({
|
|
|
33
33
|
);
|
|
34
34
|
const repository = `${app.githubOwner}/${app.githubRepo}`;
|
|
35
35
|
const token = await githubToken(
|
|
36
|
+
ctx,
|
|
36
37
|
app.installationId,
|
|
37
38
|
["secrets:write"],
|
|
38
39
|
repository,
|
|
39
40
|
);
|
|
40
41
|
const path = `/repos/${repository}/actions/secrets`;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
+
);
|
|
46
67
|
const publicKey = await githubRequest<{ key_id: string; key: string }>(
|
|
47
68
|
token,
|
|
48
69
|
`${path}/public-key`,
|
|
49
70
|
);
|
|
71
|
+
const { default: sodium } = await import("libsodium-wrappers");
|
|
50
72
|
await sodium.ready;
|
|
51
73
|
const save = async (name: string, value: string) => {
|
|
52
74
|
const encrypted = sodium.crypto_box_seal(
|
|
@@ -66,6 +88,16 @@ export const configure = internalAction({
|
|
|
66
88
|
"PUT",
|
|
67
89
|
);
|
|
68
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
|
+
}
|
|
69
101
|
const { token: managementToken } = await credential(
|
|
70
102
|
ctx,
|
|
71
103
|
args.userId,
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
}
|