create-disposabl-app 0.8.10 → 0.8.12
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 +13 -1
- package/dist/disposabl.js +1 -1
- package/dist/index.js +1 -6
- package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.tsx +0 -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 +2 -2
- package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.connections.tsx +0 -445
- 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,145 +0,0 @@
|
|
|
1
|
-
"use node";
|
|
2
|
-
|
|
3
|
-
import { getToken } from "@vercel/connect";
|
|
4
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
-
import { ConvexError } from "convex/values";
|
|
6
|
-
import { env, type ActionCtx } from "../../_generated/server";
|
|
7
|
-
import { internal } from "../../_generated/api";
|
|
8
|
-
import { seal, unseal } from "../../connections/actions/credentials";
|
|
9
|
-
|
|
10
|
-
export async function githubToken(
|
|
11
|
-
ctx: ActionCtx,
|
|
12
|
-
installationId: string,
|
|
13
|
-
permissions: string[],
|
|
14
|
-
repository?: string,
|
|
15
|
-
) {
|
|
16
|
-
const token = await vercelIdentity(ctx);
|
|
17
|
-
return getToken(
|
|
18
|
-
env.GITHUB_CONNECTOR!,
|
|
19
|
-
{
|
|
20
|
-
subject: { type: "app" },
|
|
21
|
-
installationId,
|
|
22
|
-
authorizationDetails: [
|
|
23
|
-
{
|
|
24
|
-
type: "github_app_installation",
|
|
25
|
-
permissions,
|
|
26
|
-
...(repository ? { repositories: [repository] } : {}),
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
},
|
|
30
|
-
{ vercelToken: token },
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
export async function vercelIdentity(ctx: ActionCtx): Promise<string> {
|
|
34
|
-
if (
|
|
35
|
-
!env.VERCEL_TOKEN ||
|
|
36
|
-
!env.VERCEL_PROJECT_ID ||
|
|
37
|
-
!env.VERCEL_TEAM_ID ||
|
|
38
|
-
!env.GITHUB_CONNECTOR
|
|
39
|
-
)
|
|
40
|
-
throw new Error("GitHub App connection is not configured.");
|
|
41
|
-
const key = createHash("sha256")
|
|
42
|
-
.update(
|
|
43
|
-
JSON.stringify([
|
|
44
|
-
env.VERCEL_PROJECT_ID,
|
|
45
|
-
env.VERCEL_TEAM_ID,
|
|
46
|
-
env.VERCEL_TOKEN,
|
|
47
|
-
env.CONNECTIONS_ENCRYPTION_KEY,
|
|
48
|
-
]),
|
|
49
|
-
)
|
|
50
|
-
.digest("hex");
|
|
51
|
-
const lease = randomUUID();
|
|
52
|
-
const cached = await ctx.runMutation(internal.github.identityCache.acquire, {
|
|
53
|
-
key,
|
|
54
|
-
lease,
|
|
55
|
-
});
|
|
56
|
-
if (cached.token) return unseal(cached.token, `vercel-identity:${key}`);
|
|
57
|
-
if (!cached.acquired)
|
|
58
|
-
throw new ConvexError({
|
|
59
|
-
code: "UPSTREAM_RETRY",
|
|
60
|
-
retryAfter: cached.retryAfter,
|
|
61
|
-
});
|
|
62
|
-
let refreshAfter = Date.now() + 5_000;
|
|
63
|
-
try {
|
|
64
|
-
const response = await fetch(
|
|
65
|
-
`https://api.vercel.com/v1/projects/${encodeURIComponent(env.VERCEL_PROJECT_ID)}/token?teamId=${encodeURIComponent(env.VERCEL_TEAM_ID)}`,
|
|
66
|
-
{
|
|
67
|
-
method: "POST",
|
|
68
|
-
redirect: "error",
|
|
69
|
-
headers: { Authorization: `Bearer ${env.VERCEL_TOKEN}` },
|
|
70
|
-
signal: AbortSignal.timeout(30_000),
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
if (!response.ok) {
|
|
74
|
-
if (response.status === 429 || response.status >= 500) {
|
|
75
|
-
const retry = Number(response.headers.get("retry-after"));
|
|
76
|
-
const reset = Number(response.headers.get("x-ratelimit-reset"));
|
|
77
|
-
const delay = Math.max(
|
|
78
|
-
5,
|
|
79
|
-
Number.isFinite(retry) ? retry : 0,
|
|
80
|
-
Number.isFinite(reset) ? reset - Date.now() / 1000 : 0,
|
|
81
|
-
);
|
|
82
|
-
refreshAfter = Date.now() + Math.min(delay, 3600) * 1000;
|
|
83
|
-
throw new ConvexError({
|
|
84
|
-
code: "UPSTREAM_RETRY",
|
|
85
|
-
retryAfter: Math.ceil((refreshAfter - Date.now()) / 1000),
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
throw new Error(`GitHub connection failed (${response.status}).`);
|
|
89
|
-
}
|
|
90
|
-
const { token } = (await response.json()) as { token: string };
|
|
91
|
-
const payload = token.split(".").at(1);
|
|
92
|
-
const expiresAt = payload
|
|
93
|
-
? Number(JSON.parse(Buffer.from(payload, "base64url").toString()).exp) *
|
|
94
|
-
1000
|
|
95
|
-
: 0;
|
|
96
|
-
if (!Number.isFinite(expiresAt) || expiresAt <= Date.now() + 60_000)
|
|
97
|
-
throw new Error("Vercel returned an expired identity.");
|
|
98
|
-
await ctx.runMutation(internal.github.identityCache.finish, {
|
|
99
|
-
key,
|
|
100
|
-
lease,
|
|
101
|
-
token: seal(token, `vercel-identity:${key}`),
|
|
102
|
-
expiresAt,
|
|
103
|
-
refreshAfter: 0,
|
|
104
|
-
});
|
|
105
|
-
return token;
|
|
106
|
-
} catch (error) {
|
|
107
|
-
await ctx.runMutation(internal.github.identityCache.finish, {
|
|
108
|
-
key,
|
|
109
|
-
lease,
|
|
110
|
-
expiresAt: 0,
|
|
111
|
-
refreshAfter,
|
|
112
|
-
});
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
export class GitHubError extends Error {
|
|
117
|
-
constructor(readonly status: number) {
|
|
118
|
-
super(`GitHub request failed (${status}).`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
export async function githubRequest<T>(
|
|
122
|
-
token: string,
|
|
123
|
-
path: string,
|
|
124
|
-
body?: unknown,
|
|
125
|
-
method = body === undefined ? "GET" : "POST",
|
|
126
|
-
): Promise<T> {
|
|
127
|
-
const response = await fetch(`https://api.github.com${path}`, {
|
|
128
|
-
method,
|
|
129
|
-
redirect: "error",
|
|
130
|
-
signal: AbortSignal.timeout(30_000),
|
|
131
|
-
headers: {
|
|
132
|
-
Authorization: `Bearer ${token}`,
|
|
133
|
-
Accept: "application/vnd.github+json",
|
|
134
|
-
"Content-Type": "application/json",
|
|
135
|
-
"X-GitHub-Api-Version": "2022-11-28",
|
|
136
|
-
},
|
|
137
|
-
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
138
|
-
});
|
|
139
|
-
if (!response.ok) throw new GitHubError(response.status);
|
|
140
|
-
return (
|
|
141
|
-
response.status === 204 || response.headers.get("content-length") === "0"
|
|
142
|
-
? undefined
|
|
143
|
-
: await response.json()
|
|
144
|
-
) as T;
|
|
145
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { internalMutation } from "../_generated/server";
|
|
2
|
-
import { v } from "convex/values";
|
|
3
|
-
|
|
4
|
-
// Internal only: encrypted service identity, shared across action workers.
|
|
5
|
-
export const acquire = internalMutation({
|
|
6
|
-
args: { key: v.string(), lease: v.string() },
|
|
7
|
-
returns: v.object({
|
|
8
|
-
token: v.optional(v.string()),
|
|
9
|
-
acquired: v.boolean(),
|
|
10
|
-
retryAfter: v.number(),
|
|
11
|
-
}),
|
|
12
|
-
handler: async (ctx, { key, lease }) => {
|
|
13
|
-
const row = await ctx.db
|
|
14
|
-
.query("serviceIdentities")
|
|
15
|
-
.withIndex("by_key", (q) => q.eq("key", key))
|
|
16
|
-
.unique();
|
|
17
|
-
const now = Date.now();
|
|
18
|
-
if (row?.token && row.expiresAt > now + 60_000)
|
|
19
|
-
return { token: row.token, acquired: false, retryAfter: 0 };
|
|
20
|
-
if (row && row.refreshAfter > now)
|
|
21
|
-
return {
|
|
22
|
-
acquired: false,
|
|
23
|
-
retryAfter: Math.ceil((row.refreshAfter - now) / 1000),
|
|
24
|
-
};
|
|
25
|
-
const value = { lease, refreshAfter: now + 35_000 };
|
|
26
|
-
if (row) await ctx.db.patch("serviceIdentities", row._id, value);
|
|
27
|
-
else
|
|
28
|
-
await ctx.db.insert("serviceIdentities", { key, expiresAt: 0, ...value });
|
|
29
|
-
return { acquired: true, retryAfter: 0 };
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export const finish = internalMutation({
|
|
34
|
-
args: {
|
|
35
|
-
key: v.string(),
|
|
36
|
-
lease: v.string(),
|
|
37
|
-
token: v.optional(v.string()),
|
|
38
|
-
expiresAt: v.number(),
|
|
39
|
-
refreshAfter: v.number(),
|
|
40
|
-
},
|
|
41
|
-
returns: v.null(),
|
|
42
|
-
handler: async (ctx, { key, lease, ...value }) => {
|
|
43
|
-
const row = await ctx.db
|
|
44
|
-
.query("serviceIdentities")
|
|
45
|
-
.withIndex("by_key", (q) => q.eq("key", key))
|
|
46
|
-
.unique();
|
|
47
|
-
if (row?.lease === lease)
|
|
48
|
-
await ctx.db.patch("serviceIdentities", row._id, {
|
|
49
|
-
...value,
|
|
50
|
-
lease: undefined,
|
|
51
|
-
});
|
|
52
|
-
return null;
|
|
53
|
-
},
|
|
54
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
identityFields,
|
|
3
|
-
internalMutation,
|
|
4
|
-
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
5
|
-
import { ConvexError, v } from "convex/values";
|
|
6
|
-
|
|
7
|
-
/** A trusted installation callback supplies this verified binding, never a client API. */
|
|
8
|
-
export const connect = internalMutation({
|
|
9
|
-
args: {
|
|
10
|
-
...identityFields,
|
|
11
|
-
owner: v.string(),
|
|
12
|
-
installationId: v.string(),
|
|
13
|
-
},
|
|
14
|
-
returns: v.null(),
|
|
15
|
-
handler: async (ctx, { userId, owner, installationId }) => {
|
|
16
|
-
if (!/^[a-zA-Z0-9-]+$/.test(owner) || !/^\d+$/.test(installationId))
|
|
17
|
-
throw new ConvexError("Invalid GitHub installation.");
|
|
18
|
-
owner = owner.toLowerCase();
|
|
19
|
-
const existing = await ctx.db
|
|
20
|
-
.query("githubConnections")
|
|
21
|
-
.withIndex("by_userId_owner", (q) =>
|
|
22
|
-
q.eq("userId", userId).eq("owner", owner),
|
|
23
|
-
)
|
|
24
|
-
.unique();
|
|
25
|
-
if (existing) await ctx.db.delete("githubConnections", existing._id);
|
|
26
|
-
await ctx.db.insert("githubConnections", {
|
|
27
|
-
userId,
|
|
28
|
-
owner,
|
|
29
|
-
installationId,
|
|
30
|
-
});
|
|
31
|
-
return null;
|
|
32
|
-
},
|
|
33
|
-
});
|
|
@@ -1,257 +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 { assertActive } from "../apps/operations/internal";
|
|
12
|
-
import { ownedApp } from "../apps/internal";
|
|
13
|
-
import {
|
|
14
|
-
deployment,
|
|
15
|
-
platform,
|
|
16
|
-
platformNames,
|
|
17
|
-
previewIdentity,
|
|
18
|
-
previewResult,
|
|
19
|
-
releaseDetails,
|
|
20
|
-
run,
|
|
21
|
-
} from "../validator";
|
|
22
|
-
import type { Doc } from "../_generated/dataModel";
|
|
23
|
-
import type { QueryCtx } from "../_generated/server";
|
|
24
|
-
|
|
25
|
-
export function validateReference(reference: string) {
|
|
26
|
-
if (
|
|
27
|
-
!reference ||
|
|
28
|
-
reference !== reference.trim() ||
|
|
29
|
-
reference.length > 200 ||
|
|
30
|
-
[...reference].some(
|
|
31
|
-
(char) => char.charCodeAt(0) <= 32 || char.charCodeAt(0) === 127,
|
|
32
|
-
)
|
|
33
|
-
)
|
|
34
|
-
throw new ConvexError(
|
|
35
|
-
"Provide a branch, worktree, or PR name (1–200 characters, no whitespace).",
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
const platformKey = (name: string) =>
|
|
39
|
-
name === "typescript-sdk" ? "sdk" : name;
|
|
40
|
-
export function presentPlatforms(
|
|
41
|
-
app: Doc<"apps">,
|
|
42
|
-
releases: Doc<"previews">["releases"],
|
|
43
|
-
site?: string,
|
|
44
|
-
) {
|
|
45
|
-
const routes: Record<string, string> = {
|
|
46
|
-
web: "",
|
|
47
|
-
api: "/openapi.json",
|
|
48
|
-
mcp: "/mcp",
|
|
49
|
-
};
|
|
50
|
-
return Object.fromEntries(
|
|
51
|
-
platformNames.map((name) => {
|
|
52
|
-
const release = releases[platformKey(name)];
|
|
53
|
-
const { url: releasedUrl, ...latest } = release ?? {};
|
|
54
|
-
const url =
|
|
55
|
-
releasedUrl ??
|
|
56
|
-
(site && Object.hasOwn(routes, name) ? site + routes[name] : undefined);
|
|
57
|
-
const enabled = app.platforms.includes(name);
|
|
58
|
-
return [
|
|
59
|
-
platformKey(name),
|
|
60
|
-
{
|
|
61
|
-
enabled,
|
|
62
|
-
...(enabled && url ? { url } : {}),
|
|
63
|
-
...(release
|
|
64
|
-
? {
|
|
65
|
-
latest: { ...latest, status: release.status, run: release.run },
|
|
66
|
-
}
|
|
67
|
-
: {}),
|
|
68
|
-
},
|
|
69
|
-
];
|
|
70
|
-
}),
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
function present(
|
|
74
|
-
preview: Doc<"previews">,
|
|
75
|
-
app: Doc<"apps">,
|
|
76
|
-
): Infer<typeof previewResult> {
|
|
77
|
-
return {
|
|
78
|
-
appId: preview.appId,
|
|
79
|
-
reference: preview.reference,
|
|
80
|
-
stage: preview.stage,
|
|
81
|
-
...(preview.deployment ? { deployment: preview.deployment } : {}),
|
|
82
|
-
updatedAt: preview.updatedAt,
|
|
83
|
-
platforms: presentPlatforms(
|
|
84
|
-
app,
|
|
85
|
-
preview.releases,
|
|
86
|
-
preview.deployment?.convexSiteUrl,
|
|
87
|
-
),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
async function findPreview(
|
|
91
|
-
ctx: Pick<QueryCtx, "db">,
|
|
92
|
-
args: { appId: string; reference: string },
|
|
93
|
-
) {
|
|
94
|
-
validateReference(args.reference);
|
|
95
|
-
return ctx.db
|
|
96
|
-
.query("previews")
|
|
97
|
-
.withIndex("by_appId_reference", (q) =>
|
|
98
|
-
q.eq("appId", args.appId).eq("reference", args.reference),
|
|
99
|
-
)
|
|
100
|
-
.unique();
|
|
101
|
-
}
|
|
102
|
-
export const get = internalQuery({
|
|
103
|
-
platforms: true,
|
|
104
|
-
args: { ...identityFields, ...previewIdentity },
|
|
105
|
-
returns: v.union(previewResult, v.null()),
|
|
106
|
-
handler: async (ctx, args) => {
|
|
107
|
-
const app = await ownedApp(ctx, args.userId, args.appId);
|
|
108
|
-
const preview = await findPreview(ctx, args);
|
|
109
|
-
return preview ? present(preview, app) : null;
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
export const list = internalQuery({
|
|
113
|
-
platforms: true,
|
|
114
|
-
args: {
|
|
115
|
-
...identityFields,
|
|
116
|
-
appId: v.string(),
|
|
117
|
-
paginationOpts: paginationOptsValidator,
|
|
118
|
-
},
|
|
119
|
-
returns: paginationResultValidator(previewResult),
|
|
120
|
-
handler: async (ctx, { userId, appId, paginationOpts }) => {
|
|
121
|
-
const app = await ownedApp(ctx, userId, appId);
|
|
122
|
-
if (
|
|
123
|
-
!Number.isInteger(paginationOpts.numItems) ||
|
|
124
|
-
paginationOpts.numItems < 1 ||
|
|
125
|
-
paginationOpts.numItems > 100
|
|
126
|
-
)
|
|
127
|
-
throw new ConvexError("Page size must be between 1 and 100.");
|
|
128
|
-
const result = await ctx.db
|
|
129
|
-
.query("previews")
|
|
130
|
-
.withIndex("by_appId_reference", (q) => q.eq("appId", appId))
|
|
131
|
-
.paginate(paginationOpts);
|
|
132
|
-
return {
|
|
133
|
-
...result,
|
|
134
|
-
page: result.page.map((preview) => present(preview, app)),
|
|
135
|
-
};
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
export const create = internalMutation({
|
|
139
|
-
args: { ...identityFields, ...previewIdentity },
|
|
140
|
-
returns: v.union(v.number(), v.null()),
|
|
141
|
-
handler: async (ctx, args) => {
|
|
142
|
-
const app = await ownedApp(ctx, args.userId, args.appId);
|
|
143
|
-
const preview = await findPreview(ctx, args);
|
|
144
|
-
if (preview)
|
|
145
|
-
await ctx.db.patch("previews", preview._id, {
|
|
146
|
-
stage: "generating",
|
|
147
|
-
updatedAt: Date.now(),
|
|
148
|
-
});
|
|
149
|
-
else
|
|
150
|
-
await ctx.db.insert("previews", {
|
|
151
|
-
appId: args.appId,
|
|
152
|
-
reference: args.reference,
|
|
153
|
-
stage: "generating",
|
|
154
|
-
releases: {},
|
|
155
|
-
updatedAt: Date.now(),
|
|
156
|
-
});
|
|
157
|
-
return app.convexProjectId ?? null;
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
export const finish = internalMutation({
|
|
161
|
-
args: { ...identityFields, ...previewIdentity, deployment },
|
|
162
|
-
returns: v.null(),
|
|
163
|
-
handler: async (ctx, args) => {
|
|
164
|
-
await ownedApp(ctx, args.userId, args.appId);
|
|
165
|
-
const preview = await findPreview(ctx, args);
|
|
166
|
-
if (!preview) throw new ConvexError("Preview not found.");
|
|
167
|
-
await ctx.db.patch("previews", preview._id, {
|
|
168
|
-
deployment: args.deployment,
|
|
169
|
-
updatedAt: Date.now(),
|
|
170
|
-
});
|
|
171
|
-
return null;
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
/** Only the GitHub OIDC HTTP handler can report build outcomes. */
|
|
175
|
-
export const report = internalMutation({
|
|
176
|
-
args: {
|
|
177
|
-
...identityFields,
|
|
178
|
-
appId: v.string(),
|
|
179
|
-
githubOwner: v.string(),
|
|
180
|
-
githubRepo: v.string(),
|
|
181
|
-
reference: v.string(),
|
|
182
|
-
production: v.boolean(),
|
|
183
|
-
run,
|
|
184
|
-
platform,
|
|
185
|
-
...releaseDetails,
|
|
186
|
-
},
|
|
187
|
-
returns: v.null(),
|
|
188
|
-
handler: async (ctx, args) => {
|
|
189
|
-
const app = await ownedApp(ctx, args.userId, args.appId);
|
|
190
|
-
assertActive(app);
|
|
191
|
-
if (
|
|
192
|
-
app.githubOwner !== args.githubOwner ||
|
|
193
|
-
app.githubRepo !== args.githubRepo
|
|
194
|
-
)
|
|
195
|
-
throw new ConvexError("Repository is not linked to this app.");
|
|
196
|
-
if (!app.platforms.includes(args.platform)) return null;
|
|
197
|
-
validateReference(args.reference);
|
|
198
|
-
const table = args.production ? "appReleases" : "previews";
|
|
199
|
-
const existing = args.production
|
|
200
|
-
? await ctx.db
|
|
201
|
-
.query("appReleases")
|
|
202
|
-
.withIndex("by_appId", (q) => q.eq("appId", args.appId))
|
|
203
|
-
.unique()
|
|
204
|
-
: await findPreview(ctx, args);
|
|
205
|
-
const key = platformKey(args.platform);
|
|
206
|
-
const previous = existing?.releases[key];
|
|
207
|
-
if (previous) {
|
|
208
|
-
if (
|
|
209
|
-
args.run.id < previous.run.id ||
|
|
210
|
-
(args.run.id === previous.run.id &&
|
|
211
|
-
args.run.attempt < previous.run.attempt)
|
|
212
|
-
)
|
|
213
|
-
return null;
|
|
214
|
-
if (
|
|
215
|
-
args.run.id === previous.run.id &&
|
|
216
|
-
args.run.attempt === previous.run.attempt &&
|
|
217
|
-
previous.status !== "building" &&
|
|
218
|
-
args.status !== "failed"
|
|
219
|
-
)
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
const {
|
|
223
|
-
userId: _user,
|
|
224
|
-
appId: _app,
|
|
225
|
-
githubOwner: _owner,
|
|
226
|
-
githubRepo: _repo,
|
|
227
|
-
reference: _ref,
|
|
228
|
-
production: _prod,
|
|
229
|
-
platform: _platform,
|
|
230
|
-
...latest
|
|
231
|
-
} = args;
|
|
232
|
-
const values = {
|
|
233
|
-
releases: { ...existing?.releases, [key]: latest },
|
|
234
|
-
updatedAt: Date.now(),
|
|
235
|
-
};
|
|
236
|
-
if (table === "appReleases") {
|
|
237
|
-
const record = existing as Doc<"appReleases"> | null;
|
|
238
|
-
if (record) await ctx.db.patch("appReleases", record._id, values);
|
|
239
|
-
else await ctx.db.insert("appReleases", { appId: args.appId, ...values });
|
|
240
|
-
} else {
|
|
241
|
-
const record = existing as Doc<"previews"> | null;
|
|
242
|
-
if (record)
|
|
243
|
-
await ctx.db.patch("previews", record._id, {
|
|
244
|
-
...values,
|
|
245
|
-
stage: "building",
|
|
246
|
-
});
|
|
247
|
-
else
|
|
248
|
-
await ctx.db.insert("previews", {
|
|
249
|
-
appId: args.appId,
|
|
250
|
-
reference: args.reference,
|
|
251
|
-
stage: "building",
|
|
252
|
-
...values,
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
return null;
|
|
256
|
-
},
|
|
257
|
-
});
|
|
@@ -1,83 +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 { previewIdentity, deployment } from "../../../validator";
|
|
11
|
-
import { validateReference } from "../../internal";
|
|
12
|
-
import { ensureDevelopment, productionDeployment } from "./management";
|
|
13
|
-
|
|
14
|
-
export const create = internalAction({
|
|
15
|
-
args: { ...identityFields, ...previewIdentity },
|
|
16
|
-
returns: v.object({
|
|
17
|
-
appId: v.string(),
|
|
18
|
-
...deployment.fields,
|
|
19
|
-
deployKey: v.string(),
|
|
20
|
-
productionConvexSiteUrl: v.optional(v.string()),
|
|
21
|
-
repositoryUrl: v.optional(v.string()),
|
|
22
|
-
}),
|
|
23
|
-
handler: async (
|
|
24
|
-
ctx,
|
|
25
|
-
args,
|
|
26
|
-
): Promise<{
|
|
27
|
-
appId: string;
|
|
28
|
-
name: string;
|
|
29
|
-
reference: string;
|
|
30
|
-
convexUrl: string;
|
|
31
|
-
convexSiteUrl: string;
|
|
32
|
-
deployKey: string;
|
|
33
|
-
productionConvexSiteUrl?: string;
|
|
34
|
-
repositoryUrl?: string;
|
|
35
|
-
}> => {
|
|
36
|
-
validateReference(args.reference);
|
|
37
|
-
const identity = { userId: args.userId, appId: args.appId };
|
|
38
|
-
const { until } = await ctx.runMutation(
|
|
39
|
-
internal.apps.operations.internal.begin,
|
|
40
|
-
{
|
|
41
|
-
...identity,
|
|
42
|
-
kind: "setup",
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
try {
|
|
46
|
-
await ctx.runMutation(internal.previews.internal.create, args);
|
|
47
|
-
const projectId = await ctx.runAction(internal.apps.actions.setup.setup, {
|
|
48
|
-
userId: args.userId,
|
|
49
|
-
appId: args.appId,
|
|
50
|
-
});
|
|
51
|
-
const token = (await credential(ctx, args.userId, "convex")).token;
|
|
52
|
-
const production = await productionDeployment(token, projectId);
|
|
53
|
-
const app = await ctx.runQuery(internal.apps.internal.get, identity);
|
|
54
|
-
if (!app.githubOwner || !app.githubRepo)
|
|
55
|
-
throw new Error("App repository setup is incomplete.");
|
|
56
|
-
const { deployKey, ...deployment } = await ensureDevelopment(
|
|
57
|
-
token,
|
|
58
|
-
projectId,
|
|
59
|
-
args.reference,
|
|
60
|
-
);
|
|
61
|
-
await ctx.runMutation(internal.previews.internal.finish, {
|
|
62
|
-
...args,
|
|
63
|
-
deployment,
|
|
64
|
-
});
|
|
65
|
-
return {
|
|
66
|
-
appId: args.appId,
|
|
67
|
-
...deployment,
|
|
68
|
-
deployKey,
|
|
69
|
-
productionConvexSiteUrl: production.deploymentUrl.replace(
|
|
70
|
-
/\.convex\.cloud\/?$/,
|
|
71
|
-
".convex.site",
|
|
72
|
-
),
|
|
73
|
-
repositoryUrl: `https://github.com/${app.githubOwner}/${app.githubRepo}.git`,
|
|
74
|
-
};
|
|
75
|
-
} finally {
|
|
76
|
-
await ctx.runMutation(internal.apps.operations.internal.finish, {
|
|
77
|
-
...identity,
|
|
78
|
-
until,
|
|
79
|
-
retryDelete: false,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
});
|