create-disposabl-app 0.8.9 → 0.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/disposabl.js +42 -42
- package/dist/index.js +1 -1
- package/dist/templates/default/bun.lock +1 -7
- package/dist/templates/default/packages/backend/README.md +4 -8
- package/dist/templates/default/packages/backend/convex/_generated/api.d.ts +0 -67
- package/dist/templates/default/packages/backend/convex/_generated/server.d.ts +0 -9
- package/dist/templates/default/packages/backend/convex/convex.config.ts +0 -11
- package/dist/templates/default/packages/backend/convex/http.ts +1 -9
- package/dist/templates/default/packages/backend/convex/schema.ts +1 -69
- package/dist/templates/default/packages/backend/generated/openapi.json +1 -1262
- package/dist/templates/default/packages/backend/generated/pages.json +0 -4
- package/dist/templates/default/packages/backend/generated/platforms.ts +2 -20
- package/dist/templates/default/packages/backend/package.json +1 -7
- package/dist/templates/default/packages/cli/README.md +5 -1
- package/dist/templates/default/packages/cli/commands.ts +15 -8
- package/dist/templates/default/packages/cli/delete.ts +40 -31
- package/dist/templates/default/packages/skill/SKILL.md +13 -5
- package/dist/templates/default/packages/skill/references/delivery.md +1 -1
- package/package.json +1 -1
- package/dist/templates/default/packages/backend/convex/apps/actions/cleanup.ts +0 -296
- package/dist/templates/default/packages/backend/convex/apps/actions/create.ts +0 -30
- package/dist/templates/default/packages/backend/convex/apps/actions/delete.ts +0 -15
- package/dist/templates/default/packages/backend/convex/apps/actions/expo.ts +0 -174
- package/dist/templates/default/packages/backend/convex/apps/actions/setup.ts +0 -48
- package/dist/templates/default/packages/backend/convex/apps/internal.ts +0 -211
- package/dist/templates/default/packages/backend/convex/apps/operations/internal.ts +0 -213
- package/dist/templates/default/packages/backend/convex/apps/validator.ts +0 -23
- package/dist/templates/default/packages/backend/convex/connections/actions/credentials.ts +0 -56
- package/dist/templates/default/packages/backend/convex/connections/actions/expo.ts +0 -79
- package/dist/templates/default/packages/backend/convex/connections/actions/github.ts +0 -119
- package/dist/templates/default/packages/backend/convex/connections/actions/oauth.ts +0 -128
- package/dist/templates/default/packages/backend/convex/connections/index.ts +0 -80
- package/dist/templates/default/packages/backend/convex/connections/internal.ts +0 -147
- package/dist/templates/default/packages/backend/convex/connections/validator.ts +0 -35
- package/dist/templates/default/packages/backend/convex/downloads/action.ts +0 -136
- package/dist/templates/default/packages/backend/convex/downloads/http.ts +0 -32
- package/dist/templates/default/packages/backend/convex/downloads/internal.ts +0 -58
- package/dist/templates/default/packages/backend/convex/github/actions/http.ts +0 -69
- package/dist/templates/default/packages/backend/convex/github/actions/internal.ts +0 -196
- package/dist/templates/default/packages/backend/convex/github/actions/oidc.ts +0 -75
- package/dist/templates/default/packages/backend/convex/github/actions/provision.ts +0 -76
- package/dist/templates/default/packages/backend/convex/github/actions/secrets.ts +0 -180
- package/dist/templates/default/packages/backend/convex/github/actions/signing.ts +0 -41
- package/dist/templates/default/packages/backend/convex/github/actions/tokens.ts +0 -145
- package/dist/templates/default/packages/backend/convex/github/identityCache.ts +0 -54
- package/dist/templates/default/packages/backend/convex/github/internal.ts +0 -33
- package/dist/templates/default/packages/backend/convex/previews/internal.ts +0 -257
- package/dist/templates/default/packages/backend/convex/previews/token/actions/create.ts +0 -83
- package/dist/templates/default/packages/backend/convex/previews/token/actions/management.ts +0 -182
- package/dist/templates/default/packages/backend/convex/previews/token/internal.ts +0 -32
- package/dist/templates/default/packages/backend/convex/releases/internal.ts +0 -28
- package/dist/templates/default/packages/backend/convex/validator.ts +0 -87
- package/dist/templates/default/packages/sdk/src/generated/client/client.gen.ts +0 -300
- package/dist/templates/default/packages/sdk/src/generated/client/index.ts +0 -27
- package/dist/templates/default/packages/sdk/src/generated/client/types.gen.ts +0 -238
- package/dist/templates/default/packages/sdk/src/generated/client/utils.gen.ts +0 -337
- package/dist/templates/default/packages/sdk/src/generated/client.gen.ts +0 -28
- package/dist/templates/default/packages/sdk/src/generated/core/auth.gen.ts +0 -49
- package/dist/templates/default/packages/sdk/src/generated/core/bodySerializer.gen.ts +0 -96
- package/dist/templates/default/packages/sdk/src/generated/core/params.gen.ts +0 -188
- package/dist/templates/default/packages/sdk/src/generated/core/pathSerializer.gen.ts +0 -186
- package/dist/templates/default/packages/sdk/src/generated/core/queryKeySerializer.gen.ts +0 -134
- package/dist/templates/default/packages/sdk/src/generated/core/serverSentEvents.gen.ts +0 -265
- package/dist/templates/default/packages/sdk/src/generated/core/types.gen.ts +0 -126
- package/dist/templates/default/packages/sdk/src/generated/core/utils.gen.ts +0 -146
- package/dist/templates/default/packages/sdk/src/generated/index.ts +0 -63
- package/dist/templates/default/packages/sdk/src/generated/sdk.gen.ts +0 -234
- package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +0 -660
|
@@ -1,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
|
-
});
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
export class ManagementError extends Error {
|
|
2
|
-
constructor(readonly status: number) {
|
|
3
|
-
super(`Convex management request failed (${status}).`);
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
export async function management<T>(
|
|
7
|
-
token: string,
|
|
8
|
-
path: string,
|
|
9
|
-
body?: unknown,
|
|
10
|
-
): Promise<T> {
|
|
11
|
-
const response = await fetch(`https://api.convex.dev/v1${path}`, {
|
|
12
|
-
method: body === undefined ? "GET" : "POST",
|
|
13
|
-
redirect: "error",
|
|
14
|
-
headers: {
|
|
15
|
-
Authorization: `Bearer ${token}`,
|
|
16
|
-
"Content-Type": "application/json",
|
|
17
|
-
},
|
|
18
|
-
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
19
|
-
signal: AbortSignal.timeout(30_000),
|
|
20
|
-
});
|
|
21
|
-
if (!response.ok) throw new ManagementError(response.status);
|
|
22
|
-
const text = await response.text();
|
|
23
|
-
return (text ? JSON.parse(text) : undefined) as T;
|
|
24
|
-
}
|
|
25
|
-
/** Recover a project after a lost create response; names include the immutable app UUID. */
|
|
26
|
-
export async function ensureProject(
|
|
27
|
-
token: string,
|
|
28
|
-
teamId: string,
|
|
29
|
-
appId: string,
|
|
30
|
-
) {
|
|
31
|
-
const name = `disposabl-${appId}`;
|
|
32
|
-
const lookup = async () => {
|
|
33
|
-
const result = await management<{ items: { id: number; name: string }[] }>(
|
|
34
|
-
token,
|
|
35
|
-
`/teams/${teamId}/projects?q=${encodeURIComponent(name)}&limit=100`,
|
|
36
|
-
);
|
|
37
|
-
const matches = result.items.filter((project) => project.name === name);
|
|
38
|
-
if (matches.length > 1)
|
|
39
|
-
throw new Error(
|
|
40
|
-
"Multiple Convex projects match this app. Reconcile before retrying.",
|
|
41
|
-
);
|
|
42
|
-
return matches[0];
|
|
43
|
-
};
|
|
44
|
-
const existing = await lookup();
|
|
45
|
-
if (existing) return existing.id;
|
|
46
|
-
try {
|
|
47
|
-
return (
|
|
48
|
-
await management<{ id: number }>(
|
|
49
|
-
token,
|
|
50
|
-
`/teams/${teamId}/create_project`,
|
|
51
|
-
{ projectName: name },
|
|
52
|
-
)
|
|
53
|
-
).id;
|
|
54
|
-
} catch (error) {
|
|
55
|
-
const recovered = await lookup();
|
|
56
|
-
if (recovered) return recovered.id;
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
type Deployment = {
|
|
61
|
-
name: string;
|
|
62
|
-
projectId: number;
|
|
63
|
-
deploymentType: string;
|
|
64
|
-
kind: string;
|
|
65
|
-
reference: string;
|
|
66
|
-
deploymentUrl: string;
|
|
67
|
-
};
|
|
68
|
-
export async function ensureDevelopment(
|
|
69
|
-
token: string,
|
|
70
|
-
projectId: number,
|
|
71
|
-
reference: string,
|
|
72
|
-
) {
|
|
73
|
-
const path = `/projects/${projectId}`;
|
|
74
|
-
const lookup = () =>
|
|
75
|
-
management<Deployment>(
|
|
76
|
-
token,
|
|
77
|
-
`${path}/deployment?reference=${encodeURIComponent(reference)}`,
|
|
78
|
-
);
|
|
79
|
-
let deployment: Deployment;
|
|
80
|
-
try {
|
|
81
|
-
deployment = await lookup();
|
|
82
|
-
} catch (error) {
|
|
83
|
-
if (!(error instanceof ManagementError) || error.status !== 404)
|
|
84
|
-
throw error;
|
|
85
|
-
try {
|
|
86
|
-
deployment = await management<Deployment>(
|
|
87
|
-
token,
|
|
88
|
-
`${path}/create_deployment`,
|
|
89
|
-
{ type: "dev", reference, isDefault: false },
|
|
90
|
-
);
|
|
91
|
-
} catch (error) {
|
|
92
|
-
try {
|
|
93
|
-
deployment = await lookup();
|
|
94
|
-
} catch {
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (
|
|
100
|
-
deployment.kind !== "cloud" ||
|
|
101
|
-
deployment.deploymentType !== "dev" ||
|
|
102
|
-
deployment.projectId !== projectId ||
|
|
103
|
-
deployment.reference !== reference
|
|
104
|
-
)
|
|
105
|
-
throw new Error("Expected this app's named development deployment.");
|
|
106
|
-
const url = new URL(deployment.deploymentUrl);
|
|
107
|
-
if (
|
|
108
|
-
url.protocol !== "https:" ||
|
|
109
|
-
!url.hostname.endsWith(".convex.cloud") ||
|
|
110
|
-
url.username ||
|
|
111
|
-
url.password ||
|
|
112
|
-
url.port ||
|
|
113
|
-
url.pathname !== "/" ||
|
|
114
|
-
url.search ||
|
|
115
|
-
url.hash
|
|
116
|
-
)
|
|
117
|
-
throw new Error("Unexpected Convex deployment URL.");
|
|
118
|
-
const convexUrl = url.origin;
|
|
119
|
-
const convexSiteUrl = convexUrl.replace(/\.convex\.cloud$/, ".convex.site");
|
|
120
|
-
const { deployKey } = await management<{ deployKey: string }>(
|
|
121
|
-
token,
|
|
122
|
-
`/deployments/${encodeURIComponent(deployment.name)}/create_deploy_key`,
|
|
123
|
-
{ name: `disposabl-${reference}` },
|
|
124
|
-
);
|
|
125
|
-
if (!deployKey.startsWith(`dev:${deployment.name}|`))
|
|
126
|
-
throw new Error("Expected a development-scoped key.");
|
|
127
|
-
return {
|
|
128
|
-
name: deployment.name,
|
|
129
|
-
reference,
|
|
130
|
-
convexUrl,
|
|
131
|
-
convexSiteUrl,
|
|
132
|
-
deployKey,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export async function productionDeployment(token: string, projectId: number) {
|
|
137
|
-
const path = `/projects/${projectId}`;
|
|
138
|
-
const lookup = () =>
|
|
139
|
-
management<Deployment>(token, `${path}/deployment?defaultProd=true`);
|
|
140
|
-
let deployment: Deployment;
|
|
141
|
-
try {
|
|
142
|
-
deployment = await lookup();
|
|
143
|
-
} catch (error) {
|
|
144
|
-
if (!(error instanceof ManagementError) || error.status !== 404)
|
|
145
|
-
throw error;
|
|
146
|
-
try {
|
|
147
|
-
deployment = await management<Deployment>(
|
|
148
|
-
token,
|
|
149
|
-
`${path}/create_deployment`,
|
|
150
|
-
{ type: "prod" },
|
|
151
|
-
);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
try {
|
|
154
|
-
deployment = await lookup();
|
|
155
|
-
} catch {
|
|
156
|
-
throw error;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (
|
|
161
|
-
deployment.kind !== "cloud" ||
|
|
162
|
-
deployment.deploymentType !== "prod" ||
|
|
163
|
-
deployment.projectId !== projectId
|
|
164
|
-
)
|
|
165
|
-
throw new Error("Expected this app's production deployment.");
|
|
166
|
-
const url = new URL(deployment.deploymentUrl);
|
|
167
|
-
if (
|
|
168
|
-
!/^[a-z0-9-]+$/.test(deployment.name) ||
|
|
169
|
-
url.origin !== `https://${deployment.name}.convex.cloud` ||
|
|
170
|
-
url.pathname !== "/" ||
|
|
171
|
-
url.search ||
|
|
172
|
-
url.hash ||
|
|
173
|
-
url.username ||
|
|
174
|
-
url.password
|
|
175
|
-
)
|
|
176
|
-
throw new Error("Unexpected Convex production URL.");
|
|
177
|
-
return deployment;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export async function ensureProduction(token: string, projectId: number) {
|
|
181
|
-
return (await productionDeployment(token, projectId)).name;
|
|
182
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
identityFields,
|
|
3
|
-
internalAction,
|
|
4
|
-
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
5
|
-
import { v } from "convex/values";
|
|
6
|
-
import { internal } from "../../_generated/api";
|
|
7
|
-
import { deployment, previewIdentity } from "../../validator";
|
|
8
|
-
|
|
9
|
-
export const create = internalAction({
|
|
10
|
-
platforms: true,
|
|
11
|
-
args: { ...identityFields, ...previewIdentity },
|
|
12
|
-
returns: v.object({
|
|
13
|
-
appId: v.string(),
|
|
14
|
-
...deployment.fields,
|
|
15
|
-
deployKey: v.string(),
|
|
16
|
-
productionConvexSiteUrl: v.optional(v.string()),
|
|
17
|
-
repositoryUrl: v.optional(v.string()),
|
|
18
|
-
}),
|
|
19
|
-
handler: async (
|
|
20
|
-
ctx,
|
|
21
|
-
args,
|
|
22
|
-
): Promise<{
|
|
23
|
-
appId: string;
|
|
24
|
-
name: string;
|
|
25
|
-
reference: string;
|
|
26
|
-
convexUrl: string;
|
|
27
|
-
convexSiteUrl: string;
|
|
28
|
-
deployKey: string;
|
|
29
|
-
productionConvexSiteUrl?: string;
|
|
30
|
-
repositoryUrl?: string;
|
|
31
|
-
}> => ctx.runAction(internal.previews.token.actions.create.create, args),
|
|
32
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
identityFields,
|
|
3
|
-
internalQuery,
|
|
4
|
-
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
5
|
-
import { v } from "convex/values";
|
|
6
|
-
import { releasesResult } from "../validator";
|
|
7
|
-
import { ownedApp } from "../apps/internal";
|
|
8
|
-
import { presentPlatforms } from "../previews/internal";
|
|
9
|
-
|
|
10
|
-
export const get = internalQuery({
|
|
11
|
-
platforms: true,
|
|
12
|
-
args: { ...identityFields, appId: v.string() },
|
|
13
|
-
returns: v.union(releasesResult, v.null()),
|
|
14
|
-
handler: async (ctx, { userId, appId }) => {
|
|
15
|
-
const app = await ownedApp(ctx, userId, appId);
|
|
16
|
-
const release = await ctx.db
|
|
17
|
-
.query("appReleases")
|
|
18
|
-
.withIndex("by_appId", (q) => q.eq("appId", appId))
|
|
19
|
-
.unique();
|
|
20
|
-
return release
|
|
21
|
-
? {
|
|
22
|
-
appId,
|
|
23
|
-
platforms: presentPlatforms(app, release.releases),
|
|
24
|
-
updatedAt: release.updatedAt,
|
|
25
|
-
}
|
|
26
|
-
: null;
|
|
27
|
-
},
|
|
28
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { v } from "convex/values";
|
|
2
|
-
|
|
3
|
-
export const platformNames = [
|
|
4
|
-
"web",
|
|
5
|
-
"android",
|
|
6
|
-
"ios",
|
|
7
|
-
"macos",
|
|
8
|
-
"windows",
|
|
9
|
-
"linux",
|
|
10
|
-
"api",
|
|
11
|
-
"mcp",
|
|
12
|
-
"typescript-sdk",
|
|
13
|
-
"cli",
|
|
14
|
-
] as const;
|
|
15
|
-
export const platform = v.union(
|
|
16
|
-
...platformNames.map((name) => v.literal(name)),
|
|
17
|
-
);
|
|
18
|
-
export const githubConnection = v.object({
|
|
19
|
-
owner: v.string(),
|
|
20
|
-
installationId: v.string(),
|
|
21
|
-
});
|
|
22
|
-
export const appFields = {
|
|
23
|
-
appId: v.string(),
|
|
24
|
-
name: v.string(),
|
|
25
|
-
platforms: v.array(platform),
|
|
26
|
-
};
|
|
27
|
-
export const appArgs = {
|
|
28
|
-
name: v.string(),
|
|
29
|
-
platforms: v.array(platform),
|
|
30
|
-
};
|
|
31
|
-
export const appResult = v.object({
|
|
32
|
-
...appFields,
|
|
33
|
-
githubOwner: v.optional(v.string()),
|
|
34
|
-
githubRepo: v.optional(v.string()),
|
|
35
|
-
createdAt: v.number(),
|
|
36
|
-
});
|
|
37
|
-
export const previewIdentity = { appId: v.string(), reference: v.string() };
|
|
38
|
-
export const deployment = v.object({
|
|
39
|
-
name: v.string(),
|
|
40
|
-
reference: v.string(),
|
|
41
|
-
convexUrl: v.string(),
|
|
42
|
-
convexSiteUrl: v.string(),
|
|
43
|
-
});
|
|
44
|
-
export const run = v.object({
|
|
45
|
-
id: v.number(),
|
|
46
|
-
attempt: v.number(),
|
|
47
|
-
number: v.number(),
|
|
48
|
-
commitSha: v.string(),
|
|
49
|
-
url: v.string(),
|
|
50
|
-
});
|
|
51
|
-
export const releaseDetails = {
|
|
52
|
-
status: v.union(
|
|
53
|
-
v.literal("building"),
|
|
54
|
-
v.literal("ready"),
|
|
55
|
-
v.literal("failed"),
|
|
56
|
-
v.literal("blocked"),
|
|
57
|
-
),
|
|
58
|
-
reason: v.optional(v.string()),
|
|
59
|
-
version: v.optional(v.string()),
|
|
60
|
-
url: v.optional(v.string()),
|
|
61
|
-
githubReleaseUrl: v.optional(v.string()),
|
|
62
|
-
artifactUrl: v.optional(v.string()),
|
|
63
|
-
updateUrl: v.optional(v.string()),
|
|
64
|
-
};
|
|
65
|
-
export const release = v.object({ ...releaseDetails, run });
|
|
66
|
-
export const releases = v.record(v.string(), release);
|
|
67
|
-
const platformStates = v.record(
|
|
68
|
-
v.string(),
|
|
69
|
-
v.object({
|
|
70
|
-
enabled: v.boolean(),
|
|
71
|
-
url: v.optional(v.string()),
|
|
72
|
-
latest: v.optional(release.omit("url")),
|
|
73
|
-
}),
|
|
74
|
-
);
|
|
75
|
-
export const previewResult = v.object({
|
|
76
|
-
appId: v.string(),
|
|
77
|
-
reference: v.string(),
|
|
78
|
-
stage: v.union(v.literal("generating"), v.literal("building")),
|
|
79
|
-
deployment: v.optional(deployment),
|
|
80
|
-
platforms: platformStates,
|
|
81
|
-
updatedAt: v.number(),
|
|
82
|
-
});
|
|
83
|
-
export const releasesResult = v.object({
|
|
84
|
-
appId: v.string(),
|
|
85
|
-
platforms: platformStates,
|
|
86
|
-
updatedAt: v.number(),
|
|
87
|
-
});
|