create-disposabl-app 0.4.2 → 0.6.0

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.
Files changed (151) hide show
  1. package/README.md +18 -0
  2. package/dist/disposabl.js +541 -0
  3. package/dist/index.js +154 -61
  4. package/dist/templates/default/.github/scripts/android-build.sh +18 -0
  5. package/dist/templates/default/.github/scripts/disposabl.mjs +95 -0
  6. package/dist/templates/default/.github/scripts/expo-channel.sh +10 -0
  7. package/dist/templates/default/.github/scripts/expo-env.sh +17 -0
  8. package/dist/templates/default/.github/scripts/expo-fingerprint.sh +19 -0
  9. package/dist/templates/default/.github/scripts/expo-update.sh +11 -0
  10. package/dist/templates/default/.github/scripts/package-release.sh +23 -0
  11. package/dist/templates/default/.github/scripts/platforms.sh +37 -0
  12. package/dist/templates/default/.github/scripts/release-publish.sh +28 -0
  13. package/dist/templates/default/.github/scripts/release-source.sh +14 -0
  14. package/dist/templates/default/.github/scripts/verify-artifacts.sh +13 -0
  15. package/dist/templates/default/.github/scripts/web-deploy.sh +10 -0
  16. package/dist/templates/default/.github/workflows/pipeline.yml +299 -0
  17. package/dist/templates/default/apps/docs/README.md +37 -0
  18. package/dist/templates/default/apps/docs/content/guides/writing.mdx +15 -0
  19. package/dist/templates/default/apps/docs/content/index.mdx +10 -0
  20. package/dist/templates/default/apps/docs/package.json +29 -1
  21. package/dist/templates/default/apps/docs/press.config.ts +20 -0
  22. package/dist/templates/default/apps/docs/src/app.css +4 -0
  23. package/dist/templates/default/apps/docs/tsconfig.json +14 -0
  24. package/dist/templates/default/apps/docs/vite.config.ts +8 -0
  25. package/dist/templates/default/apps/mobile/.env.example +2 -0
  26. package/dist/templates/default/apps/mobile/AGENTS.md +2 -2
  27. package/dist/templates/default/apps/mobile/README.md +64 -4
  28. package/dist/templates/default/apps/mobile/app.json +5 -4
  29. package/dist/templates/default/apps/mobile/assets/images/android-icon-foreground.png +0 -0
  30. package/dist/templates/default/apps/mobile/assets/images/android-icon-monochrome.png +0 -0
  31. package/dist/templates/default/apps/mobile/assets/images/icon.png +0 -0
  32. package/dist/templates/default/apps/mobile/assets/images/splash-icon.png +0 -0
  33. package/dist/templates/default/apps/mobile/eas.json +5 -0
  34. package/dist/templates/default/apps/mobile/package.json +18 -4
  35. package/dist/templates/default/apps/mobile/src/app/(auth)/_layout.tsx +1 -0
  36. package/dist/templates/default/apps/mobile/src/app/(auth)/login.tsx +1 -0
  37. package/dist/templates/default/apps/mobile/src/app/(auth)/signup.tsx +1 -0
  38. package/dist/templates/default/apps/mobile/src/app/(authenticated)/_layout.tsx +1 -0
  39. package/dist/templates/default/apps/mobile/src/app/(authenticated)/account.tsx +1 -0
  40. package/dist/templates/default/apps/mobile/src/app/_layout.tsx +1 -5
  41. package/dist/templates/default/apps/mobile/src/app/index.tsx +1 -17
  42. package/dist/templates/default/apps/mobile/tsconfig.json +8 -1
  43. package/dist/templates/default/apps/web/package.json +3 -2
  44. package/dist/templates/default/apps/web/src/routeTree.gen.ts +0 -44
  45. package/dist/templates/default/apps/web/src/router/__root.tsx +1 -1
  46. package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.api-keys.tsx +1 -1
  47. package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.tsx +2 -1
  48. package/dist/templates/default/apps/web/src/router/index.tsx +11 -3
  49. package/dist/templates/default/apps/web/tests/auth-branches.test.tsx +44 -0
  50. package/dist/templates/default/apps/web/vite.config.ts +15 -0
  51. package/dist/templates/default/bun.lock +583 -23
  52. package/dist/templates/default/bunfig.toml +0 -2
  53. package/dist/templates/default/disposabl.json +2 -13
  54. package/dist/templates/default/package.json +3 -3
  55. package/dist/templates/default/packages/backend/AGENTS.md +15 -13
  56. package/dist/templates/default/packages/backend/README.md +6 -28
  57. package/dist/templates/default/packages/backend/convex/_generated/ai/ai-files.state.json +1 -1
  58. package/dist/templates/default/packages/backend/convex/_generated/api.d.ts +32 -6
  59. package/dist/templates/default/packages/backend/convex/_generated/server.d.ts +8 -0
  60. package/dist/templates/default/packages/backend/convex/apps/actions/create.ts +19 -0
  61. package/dist/templates/default/packages/backend/convex/apps/internal.ts +197 -0
  62. package/dist/templates/default/packages/backend/convex/auth.ts +1 -1
  63. package/dist/templates/default/packages/backend/convex/convex.config.ts +8 -0
  64. package/dist/templates/default/packages/backend/convex/github/actions/http.ts +40 -0
  65. package/dist/templates/default/packages/backend/convex/github/actions/internal.ts +189 -0
  66. package/dist/templates/default/packages/backend/convex/github/actions/oidc.ts +75 -0
  67. package/dist/templates/default/packages/backend/convex/github/actions/provision.ts +80 -0
  68. package/dist/templates/default/packages/backend/convex/github/actions/tokens.ts +66 -0
  69. package/dist/templates/default/packages/backend/convex/github/internal.ts +34 -0
  70. package/dist/templates/default/packages/backend/convex/http.ts +3 -0
  71. package/dist/templates/default/packages/backend/convex/previews/internal.ts +270 -0
  72. package/dist/templates/default/packages/backend/convex/previews/token/actions/create.ts +69 -0
  73. package/dist/templates/default/packages/backend/convex/previews/token/actions/management.ts +133 -0
  74. package/dist/templates/default/packages/backend/convex/previews/token/internal.ts +1 -0
  75. package/dist/templates/default/packages/backend/convex/releases/internal.ts +28 -0
  76. package/dist/templates/default/packages/backend/convex/schema.ts +34 -4
  77. package/dist/templates/default/packages/backend/convex/users/index.ts +21 -0
  78. package/dist/templates/default/packages/backend/convex/users/internal.ts +44 -0
  79. package/dist/templates/default/packages/backend/convex/validator.ts +87 -0
  80. package/dist/templates/default/packages/backend/generate.ts +6 -1
  81. package/dist/templates/default/packages/backend/generated/openapi.json +961 -43
  82. package/dist/templates/default/packages/backend/generated/pages.json +0 -8
  83. package/dist/templates/default/packages/backend/generated/platforms.ts +14 -2
  84. package/dist/templates/default/packages/backend/package.json +1 -1
  85. package/dist/templates/default/packages/cli/README.md +15 -9
  86. package/dist/templates/default/packages/cli/auth.ts +11 -3
  87. package/dist/templates/default/packages/cli/commands.ts +236 -0
  88. package/dist/templates/default/packages/cli/index.ts +2 -142
  89. package/dist/templates/default/packages/cli/preview.ts +157 -0
  90. package/dist/templates/default/packages/disposabl-kit/client/components/ui/log-out.tsx +16 -0
  91. package/dist/templates/default/packages/disposabl-kit/client/lib/prerender.ts +6 -3
  92. package/dist/templates/default/packages/disposabl-kit/client/routes/_auth-pages/login.tsx +1 -1
  93. package/dist/templates/default/packages/disposabl-kit/client/routes/_auth-pages/signUp.tsx +1 -1
  94. package/dist/templates/default/packages/disposabl-kit/client/routes/_authenticated/route.tsx +25 -16
  95. package/dist/templates/default/packages/disposabl-kit/client/routes/consent.tsx +3 -2
  96. package/dist/templates/default/packages/disposabl-kit/client/routes/route.tsx +57 -2
  97. package/dist/templates/default/packages/disposabl-kit/client/vite.config.ts +20 -9
  98. package/dist/templates/default/packages/disposabl-kit/eslint.config.js +1 -1
  99. package/dist/templates/default/packages/disposabl-kit/features.ts +4 -0
  100. package/dist/templates/default/packages/disposabl-kit/mobile/components/auth-form.tsx +125 -0
  101. package/dist/templates/default/packages/disposabl-kit/mobile/components/auth-ui.tsx +107 -0
  102. package/dist/templates/default/packages/disposabl-kit/mobile/expo-plugin.cjs +26 -0
  103. package/dist/templates/default/packages/disposabl-kit/mobile/index.ts +10 -0
  104. package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +101 -0
  105. package/dist/templates/default/packages/disposabl-kit/mobile/lib/auth-errors.ts +40 -0
  106. package/dist/templates/default/packages/disposabl-kit/mobile/lib/auth-storage.ts +9 -0
  107. package/dist/templates/default/packages/disposabl-kit/mobile/lib/convex.ts +1 -0
  108. package/dist/templates/default/packages/disposabl-kit/mobile/lib/logo.png +0 -0
  109. package/dist/templates/default/packages/disposabl-kit/mobile/screens/account.tsx +67 -0
  110. package/dist/templates/default/packages/disposabl-kit/mobile/screens/home.tsx +65 -0
  111. package/dist/templates/default/packages/disposabl-kit/mobile/screens/login.tsx +5 -0
  112. package/dist/templates/default/packages/disposabl-kit/mobile/screens/signup.tsx +5 -0
  113. package/dist/templates/default/packages/disposabl-kit/package.json +24 -1
  114. package/dist/templates/default/packages/disposabl-kit/platforms.ts +1 -27
  115. package/dist/templates/default/packages/disposabl-kit/server/http.ts +6 -0
  116. package/dist/templates/default/packages/disposabl-kit/server/lib/docs.test.ts +111 -0
  117. package/dist/templates/default/packages/disposabl-kit/server/lib/docs.ts +62 -0
  118. package/dist/templates/default/packages/disposabl-kit/tsconfig.json +1 -1
  119. package/dist/templates/default/packages/sdk/README.md +8 -4
  120. package/dist/templates/default/packages/sdk/src/config.ts +14 -7
  121. package/dist/templates/default/packages/sdk/src/generated/index.ts +48 -13
  122. package/dist/templates/default/packages/sdk/src/generated/sdk.gen.ts +139 -27
  123. package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +440 -37
  124. package/dist/templates/default/turbo.json +7 -0
  125. package/package.json +6 -3
  126. package/dist/templates/default/.github/README.md +0 -99
  127. package/dist/templates/default/.github/actionlint.yaml +0 -6
  128. package/dist/templates/default/.github/workflows/pipeline.yml.example +0 -546
  129. package/dist/templates/default/apps/blog/package.json +0 -1
  130. package/dist/templates/default/apps/changelog/package.json +0 -1
  131. package/dist/templates/default/apps/desktop/.oxfmtrc.json +0 -5
  132. package/dist/templates/default/apps/desktop/.oxlintrc.json +0 -6
  133. package/dist/templates/default/apps/desktop/README.md +0 -88
  134. package/dist/templates/default/apps/desktop/build-ci.mjs +0 -56
  135. package/dist/templates/default/apps/desktop/forge.config.mts +0 -109
  136. package/dist/templates/default/apps/desktop/index.html +0 -12
  137. package/dist/templates/default/apps/desktop/package.json +0 -55
  138. package/dist/templates/default/apps/desktop/src/declarations.d.ts +0 -2
  139. package/dist/templates/default/apps/desktop/src/index.css +0 -8
  140. package/dist/templates/default/apps/desktop/src/main.ts +0 -58
  141. package/dist/templates/default/apps/desktop/src/preload.ts +0 -3
  142. package/dist/templates/default/apps/desktop/src/renderer.ts +0 -19
  143. package/dist/templates/default/apps/desktop/tsconfig.json +0 -14
  144. package/dist/templates/default/apps/desktop/vite.main.config.mts +0 -4
  145. package/dist/templates/default/apps/desktop/vite.preload.config.mts +0 -4
  146. package/dist/templates/default/apps/desktop/vite.renderer.config.mts +0 -4
  147. package/dist/templates/default/apps/web/src/router/_authenticated/todos/$id.tsx +0 -27
  148. package/dist/templates/default/apps/web/src/router/_authenticated/todos/index.tsx +0 -33
  149. package/dist/templates/default/packages/backend/convex/todos/index.ts +0 -26
  150. package/dist/templates/default/packages/backend/convex/todos/internal.ts +0 -43
  151. package/dist/templates/default/packages/backend/convex/users.ts +0 -20
@@ -0,0 +1,270 @@
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 { ownedApp } from "../apps/internal";
12
+ import {
13
+ deployment,
14
+ platform,
15
+ platformNames,
16
+ previewIdentity,
17
+ previewResult,
18
+ releaseDetails,
19
+ run,
20
+ } from "../validator";
21
+ import type { Doc } from "../_generated/dataModel";
22
+ import type { QueryCtx } from "../_generated/server";
23
+
24
+ export function validateReference(reference: string) {
25
+ if (
26
+ !reference ||
27
+ reference !== reference.trim() ||
28
+ reference.length > 200 ||
29
+ [...reference].some(
30
+ (char) => char.charCodeAt(0) <= 32 || char.charCodeAt(0) === 127,
31
+ )
32
+ )
33
+ throw new ConvexError(
34
+ "Provide a branch, worktree, or PR name (1–200 characters, no whitespace).",
35
+ );
36
+ }
37
+ const platformKey = (name: string) =>
38
+ name === "typescript-sdk" ? "sdk" : name;
39
+ export function presentPlatforms(
40
+ app: Doc<"apps">,
41
+ releases: Doc<"previews">["releases"],
42
+ site?: string,
43
+ ) {
44
+ const routes: Record<string, string> = {
45
+ web: "",
46
+ api: "/openapi.json",
47
+ mcp: "/mcp",
48
+ };
49
+ return Object.fromEntries(
50
+ platformNames.map((name) => {
51
+ const release = releases[platformKey(name)];
52
+ const { url: releasedUrl, ...latest } = release ?? {};
53
+ const url =
54
+ releasedUrl ??
55
+ (site && Object.hasOwn(routes, name) ? site + routes[name] : undefined);
56
+ const enabled = app.platforms.includes(name);
57
+ return [
58
+ platformKey(name),
59
+ {
60
+ enabled,
61
+ ...(enabled && url ? { url } : {}),
62
+ ...(release
63
+ ? {
64
+ latest: { ...latest, status: release.status, run: release.run },
65
+ }
66
+ : {}),
67
+ },
68
+ ];
69
+ }),
70
+ );
71
+ }
72
+ function present(
73
+ preview: Doc<"previews">,
74
+ app: Doc<"apps">,
75
+ ): Infer<typeof previewResult> {
76
+ return {
77
+ appId: preview.appId,
78
+ reference: preview.reference,
79
+ stage: preview.stage,
80
+ ...(preview.deployment ? { deployment: preview.deployment } : {}),
81
+ updatedAt: preview.updatedAt,
82
+ platforms: presentPlatforms(
83
+ app,
84
+ preview.releases,
85
+ preview.deployment?.convexSiteUrl,
86
+ ),
87
+ };
88
+ }
89
+ async function findPreview(
90
+ ctx: Pick<QueryCtx, "db">,
91
+ args: { appId: string; reference: string },
92
+ ) {
93
+ validateReference(args.reference);
94
+ return ctx.db
95
+ .query("previews")
96
+ .withIndex("by_appId_reference", (q) =>
97
+ q.eq("appId", args.appId).eq("reference", args.reference),
98
+ )
99
+ .unique();
100
+ }
101
+ export const get = internalQuery({
102
+ platforms: true,
103
+ args: { ...identityFields, ...previewIdentity },
104
+ returns: v.union(previewResult, v.null()),
105
+ handler: async (ctx, args) => {
106
+ const app = await ownedApp(ctx, args.userId, args.appId);
107
+ const preview = await findPreview(ctx, args);
108
+ return preview ? present(preview, app) : null;
109
+ },
110
+ });
111
+ export const list = internalQuery({
112
+ platforms: true,
113
+ args: {
114
+ ...identityFields,
115
+ appId: v.string(),
116
+ paginationOpts: paginationOptsValidator,
117
+ },
118
+ returns: paginationResultValidator(previewResult),
119
+ handler: async (ctx, { userId, appId, paginationOpts }) => {
120
+ const app = await ownedApp(ctx, userId, appId);
121
+ if (
122
+ !Number.isInteger(paginationOpts.numItems) ||
123
+ paginationOpts.numItems < 1 ||
124
+ paginationOpts.numItems > 100
125
+ )
126
+ throw new ConvexError("Page size must be between 1 and 100.");
127
+ const result = await ctx.db
128
+ .query("previews")
129
+ .withIndex("by_appId_reference", (q) => q.eq("appId", appId))
130
+ .paginate(paginationOpts);
131
+ return {
132
+ ...result,
133
+ page: result.page.map((preview) => present(preview, app)),
134
+ };
135
+ },
136
+ });
137
+ export const create = internalMutation({
138
+ args: { ...identityFields, ...previewIdentity },
139
+ returns: v.union(v.number(), v.null()),
140
+ handler: async (ctx, args) => {
141
+ const app = await ownedApp(ctx, args.userId, args.appId);
142
+ const preview = await findPreview(ctx, args);
143
+ if (preview)
144
+ await ctx.db.patch("previews", preview._id, {
145
+ stage: "generating",
146
+ updatedAt: Date.now(),
147
+ });
148
+ else
149
+ await ctx.db.insert("previews", {
150
+ appId: args.appId,
151
+ reference: args.reference,
152
+ stage: "generating",
153
+ releases: {},
154
+ updatedAt: Date.now(),
155
+ });
156
+ return app.convexProjectId ?? null;
157
+ },
158
+ });
159
+ export const saveProject = internalMutation({
160
+ args: {
161
+ ...identityFields,
162
+ appId: v.string(),
163
+ projectId: v.number(),
164
+ },
165
+ returns: v.null(),
166
+ handler: async (ctx, args) => {
167
+ const app = await ownedApp(ctx, args.userId, args.appId);
168
+ await ctx.db.patch("apps", app._id, { convexProjectId: args.projectId });
169
+ return null;
170
+ },
171
+ });
172
+ export const finish = internalMutation({
173
+ args: { ...identityFields, ...previewIdentity, deployment },
174
+ returns: v.null(),
175
+ handler: async (ctx, args) => {
176
+ await ownedApp(ctx, args.userId, args.appId);
177
+ const preview = await findPreview(ctx, args);
178
+ if (!preview) throw new ConvexError("Preview not found.");
179
+ await ctx.db.patch("previews", preview._id, {
180
+ deployment: args.deployment,
181
+ updatedAt: Date.now(),
182
+ });
183
+ return null;
184
+ },
185
+ });
186
+ /** Only the GitHub OIDC HTTP handler can report build outcomes. */
187
+ export const report = internalMutation({
188
+ args: {
189
+ appId: v.string(),
190
+ githubOwner: v.string(),
191
+ githubRepo: v.string(),
192
+ reference: v.string(),
193
+ production: v.boolean(),
194
+ run,
195
+ platform,
196
+ ...releaseDetails,
197
+ },
198
+ returns: v.null(),
199
+ handler: async (ctx, args) => {
200
+ const app = await ctx.db
201
+ .query("apps")
202
+ .withIndex("by_appId", (q) => q.eq("appId", args.appId))
203
+ .unique();
204
+ if (
205
+ !app ||
206
+ app.githubOwner !== args.githubOwner ||
207
+ app.githubRepo !== args.githubRepo
208
+ )
209
+ throw new ConvexError("Repository is not linked to this app.");
210
+ if (!app.platforms.includes(args.platform)) return null;
211
+ validateReference(args.reference);
212
+ const table = args.production ? "appReleases" : "previews";
213
+ const existing = args.production
214
+ ? await ctx.db
215
+ .query("appReleases")
216
+ .withIndex("by_appId", (q) => q.eq("appId", args.appId))
217
+ .unique()
218
+ : await findPreview(ctx, args);
219
+ const key = platformKey(args.platform);
220
+ const previous = existing?.releases[key];
221
+ if (previous) {
222
+ if (
223
+ args.run.id < previous.run.id ||
224
+ (args.run.id === previous.run.id &&
225
+ args.run.attempt < previous.run.attempt)
226
+ )
227
+ return null;
228
+ if (
229
+ args.run.id === previous.run.id &&
230
+ args.run.attempt === previous.run.attempt &&
231
+ previous.status !== "building" &&
232
+ args.status !== "failed"
233
+ )
234
+ return null;
235
+ }
236
+ const {
237
+ appId: _app,
238
+ githubOwner: _owner,
239
+ githubRepo: _repo,
240
+ reference: _ref,
241
+ production: _prod,
242
+ platform: _platform,
243
+ ...latest
244
+ } = args;
245
+ const values = {
246
+ releases: { ...existing?.releases, [key]: latest },
247
+ updatedAt: Date.now(),
248
+ };
249
+ if (table === "appReleases") {
250
+ const record = existing as Doc<"appReleases"> | null;
251
+ if (record) await ctx.db.patch("appReleases", record._id, values);
252
+ else await ctx.db.insert("appReleases", { appId: args.appId, ...values });
253
+ } else {
254
+ const record = existing as Doc<"previews"> | null;
255
+ if (record)
256
+ await ctx.db.patch("previews", record._id, {
257
+ ...values,
258
+ stage: "building",
259
+ });
260
+ else
261
+ await ctx.db.insert("previews", {
262
+ appId: args.appId,
263
+ reference: args.reference,
264
+ stage: "building",
265
+ ...values,
266
+ });
267
+ }
268
+ return null;
269
+ },
270
+ });
@@ -0,0 +1,69 @@
1
+ import {
2
+ identityFields,
3
+ internalAction,
4
+ } from "@disposabl/disposabl-kit/server/lib/functions";
5
+ import { ConvexError, v } from "convex/values";
6
+ import { internal } from "../../../_generated/api";
7
+ import { env } from "../../../_generated/server";
8
+ import { previewIdentity, deployment } from "../../../validator";
9
+ import { validateReference } from "../../internal";
10
+ import { ensureDevelopment, ensureProject } from "./management";
11
+
12
+ export const create = internalAction({
13
+ platforms: true,
14
+ args: { ...identityFields, ...previewIdentity },
15
+ returns: v.object({
16
+ appId: v.string(),
17
+ ...deployment.fields,
18
+ deployKey: v.string(),
19
+ }),
20
+ handler: async (
21
+ ctx,
22
+ args,
23
+ ): Promise<{
24
+ appId: string;
25
+ name: string;
26
+ reference: string;
27
+ convexUrl: string;
28
+ convexSiteUrl: string;
29
+ deployKey: string;
30
+ }> => {
31
+ validateReference(args.reference);
32
+ // Authorization precedes all external calls. Tokens never enter the database.
33
+ await ctx.runQuery(internal.apps.internal.get, {
34
+ userId: args.userId,
35
+ appId: args.appId,
36
+ });
37
+ const token = env.CONVEX_TEAM_TOKEN;
38
+ const teamId = env.CONVEX_TEAM_ID;
39
+ if (!token || !teamId || !/^\d+$/.test(teamId))
40
+ throw new ConvexError(
41
+ "Managed setup requires CONVEX_TEAM_ID and CONVEX_TEAM_TOKEN on the service backend.",
42
+ );
43
+ const saved = await ctx.runMutation(
44
+ internal.previews.internal.create,
45
+ args,
46
+ );
47
+ await ctx.runAction(internal.github.actions.provision.run, {
48
+ userId: args.userId,
49
+ appId: args.appId,
50
+ });
51
+ const projectId = saved ?? (await ensureProject(token, teamId, args.appId));
52
+ if (saved === null)
53
+ await ctx.runMutation(internal.previews.internal.saveProject, {
54
+ userId: args.userId,
55
+ appId: args.appId,
56
+ projectId,
57
+ });
58
+ const { deployKey, ...deployment } = await ensureDevelopment(
59
+ token,
60
+ projectId,
61
+ args.reference,
62
+ );
63
+ await ctx.runMutation(internal.previews.internal.finish, {
64
+ ...args,
65
+ deployment,
66
+ });
67
+ return { appId: args.appId, ...deployment, deployKey };
68
+ },
69
+ });
@@ -0,0 +1,133 @@
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
+ return response.json() as Promise<T>;
23
+ }
24
+ /** Recover a project after a lost create response; names include the immutable app UUID. */
25
+ export async function ensureProject(
26
+ token: string,
27
+ teamId: string,
28
+ appId: string,
29
+ ) {
30
+ const name = `disposabl-${appId}`;
31
+ const lookup = async () => {
32
+ const result = await management<{ items: { id: number; name: string }[] }>(
33
+ token,
34
+ `/teams/${teamId}/projects?q=${encodeURIComponent(name)}&limit=100`,
35
+ );
36
+ const matches = result.items.filter((project) => project.name === name);
37
+ if (matches.length > 1)
38
+ throw new Error(
39
+ "Multiple Convex projects match this app. Reconcile before retrying.",
40
+ );
41
+ return matches[0];
42
+ };
43
+ const existing = await lookup();
44
+ if (existing) return existing.id;
45
+ try {
46
+ return (
47
+ await management<{ id: number }>(
48
+ token,
49
+ `/teams/${teamId}/create_project`,
50
+ { projectName: name },
51
+ )
52
+ ).id;
53
+ } catch (error) {
54
+ const recovered = await lookup();
55
+ if (recovered) return recovered.id;
56
+ throw error;
57
+ }
58
+ }
59
+ type Deployment = {
60
+ name: string;
61
+ projectId: number;
62
+ deploymentType: string;
63
+ kind: string;
64
+ reference: string;
65
+ deploymentUrl: string;
66
+ };
67
+ export async function ensureDevelopment(
68
+ token: string,
69
+ projectId: number,
70
+ reference: string,
71
+ ) {
72
+ const path = `/projects/${projectId}`;
73
+ const lookup = () =>
74
+ management<Deployment>(
75
+ token,
76
+ `${path}/deployment?reference=${encodeURIComponent(reference)}`,
77
+ );
78
+ let deployment: Deployment;
79
+ try {
80
+ deployment = await lookup();
81
+ } catch (error) {
82
+ if (!(error instanceof ManagementError) || error.status !== 404)
83
+ throw error;
84
+ try {
85
+ deployment = await management<Deployment>(
86
+ token,
87
+ `${path}/create_deployment`,
88
+ { type: "dev", reference, isDefault: false },
89
+ );
90
+ } catch (error) {
91
+ try {
92
+ deployment = await lookup();
93
+ } catch {
94
+ throw error;
95
+ }
96
+ }
97
+ }
98
+ if (
99
+ deployment.kind !== "cloud" ||
100
+ deployment.deploymentType !== "dev" ||
101
+ deployment.projectId !== projectId ||
102
+ deployment.reference !== reference
103
+ )
104
+ throw new Error("Expected this app's named development deployment.");
105
+ const url = new URL(deployment.deploymentUrl);
106
+ if (
107
+ url.protocol !== "https:" ||
108
+ !url.hostname.endsWith(".convex.cloud") ||
109
+ url.username ||
110
+ url.password ||
111
+ url.port ||
112
+ url.pathname !== "/" ||
113
+ url.search ||
114
+ url.hash
115
+ )
116
+ throw new Error("Unexpected Convex deployment URL.");
117
+ const convexUrl = url.origin;
118
+ const convexSiteUrl = convexUrl.replace(/\.convex\.cloud$/, ".convex.site");
119
+ const { deployKey } = await management<{ deployKey: string }>(
120
+ token,
121
+ `/deployments/${encodeURIComponent(deployment.name)}/create_deploy_key`,
122
+ { name: `disposabl-${reference}` },
123
+ );
124
+ if (!deployKey.startsWith(`dev:${deployment.name}|`))
125
+ throw new Error("Expected a development-scoped key.");
126
+ return {
127
+ name: deployment.name,
128
+ reference,
129
+ convexUrl,
130
+ convexSiteUrl,
131
+ deployKey,
132
+ };
133
+ }
@@ -0,0 +1 @@
1
+ export { create } from "./actions/create";
@@ -0,0 +1,28 @@
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,10 +1,40 @@
1
1
  import { defineSchema, defineTable } from "convex/server";
2
2
  import { v } from "convex/values";
3
+ import { deployment, platform, releases } from "./validator";
3
4
 
4
5
  export default defineSchema({
5
6
  users: defineTable({}),
6
- todos: defineTable({ userId: v.string(), title: v.string() }).index(
7
- "by_userId",
8
- ["userId"],
9
- ),
7
+ apps: defineTable({
8
+ appId: v.string(),
9
+ userId: v.string(),
10
+ name: v.string(),
11
+ platforms: v.array(platform),
12
+ githubOwner: v.optional(v.string()),
13
+ githubRepo: v.optional(v.string()),
14
+ convexProjectId: v.optional(v.number()),
15
+ })
16
+ .index("by_appId", ["appId"])
17
+ .index("by_userId", ["userId"]),
18
+ previews: defineTable({
19
+ appId: v.string(),
20
+ reference: v.string(),
21
+ stage: v.union(v.literal("generating"), v.literal("building")),
22
+ deployment: v.optional(deployment),
23
+ releases,
24
+ updatedAt: v.number(),
25
+ }).index("by_appId_reference", ["appId", "reference"]),
26
+ appReleases: defineTable({
27
+ appId: v.string(),
28
+ releases,
29
+ updatedAt: v.number(),
30
+ }).index("by_appId", ["appId"]),
31
+ githubConnections: defineTable({
32
+ userId: v.string(),
33
+ owner: v.string(),
34
+ installationId: v.string(),
35
+ })
36
+ // Latest connection uses creation order; owner lookup uses the compound index.
37
+ // eslint-disable-next-line @convex-dev/no-duplicate-indexes
38
+ .index("by_userId", ["userId"])
39
+ .index("by_userId_owner", ["userId", "owner"]),
10
40
  });
@@ -0,0 +1,21 @@
1
+ import { getAuthUserId } from "@convex-dev/auth/server";
2
+ import { v } from "convex/values";
3
+ import { internal } from "../_generated/api";
4
+ import { query } from "../_generated/server";
5
+ import type { Id } from "../_generated/dataModel";
6
+
7
+ export const current = query({
8
+ args: {},
9
+ returns: v.union(
10
+ v.null(),
11
+ v.object({ id: v.id("users"), username: v.union(v.string(), v.null()) }),
12
+ ),
13
+ handler: async (
14
+ ctx,
15
+ ): Promise<{ id: Id<"users">; username: string | null } | null> => {
16
+ const userId = await getAuthUserId(ctx);
17
+ return userId === null
18
+ ? null
19
+ : ctx.runQuery(internal.users.internal.current, { userId });
20
+ },
21
+ });
@@ -0,0 +1,44 @@
1
+ import {
2
+ identityFields,
3
+ internalQuery,
4
+ internalMutation,
5
+ } from "@disposabl/disposabl-kit/server/lib/functions";
6
+ import { v } from "convex/values";
7
+ import { components } from "../_generated/api";
8
+
9
+ export const current = internalQuery({
10
+ platforms: true,
11
+ args: identityFields,
12
+ returns: v.union(
13
+ v.null(),
14
+ v.object({ id: v.id("users"), username: v.union(v.string(), v.null()) }),
15
+ ),
16
+ handler: async (ctx, { userId }) => {
17
+ const id = ctx.db.normalizeId("users", userId);
18
+ if (!id || !(await ctx.db.get("users", id))) return null;
19
+ return {
20
+ id,
21
+ username: await ctx.runQuery(components.authUsername.public.getUsername, {
22
+ userId: id,
23
+ }),
24
+ };
25
+ },
26
+ });
27
+
28
+ /**
29
+ * Create the user row for a new password account and return its id. This
30
+ * example keeps no data in the row, but your app can put a profile here.
31
+ */
32
+ export const createUser = internalMutation({
33
+ args: {
34
+ provider: v.object({
35
+ name: v.literal("password"),
36
+ accountId: v.string(),
37
+ profile: v.object({}),
38
+ }),
39
+ },
40
+ returns: v.id("users"),
41
+ handler: async (ctx) => {
42
+ return await ctx.db.insert("users", {});
43
+ },
44
+ });
@@ -0,0 +1,87 @@
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
+ });