create-disposabl-app 0.11.0 → 0.13.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 (42) hide show
  1. package/dist/disposabl.js +14 -10
  2. package/dist/index.js +40 -2
  3. package/dist/templates/default/.github/scripts/disposabl.mjs +15 -1
  4. package/dist/templates/default/.github/scripts/platforms.sh +1 -1
  5. package/dist/templates/default/.github/scripts/release.sh +1 -1
  6. package/dist/templates/default/.github/workflows/pipeline.yml +30 -2
  7. package/dist/templates/default/apps/desktop/README.md +16 -4
  8. package/dist/templates/default/apps/desktop/build-ci.mjs +7 -0
  9. package/dist/templates/default/apps/desktop/forge.config.mts +8 -4
  10. package/dist/templates/default/apps/desktop/package.json +3 -2
  11. package/dist/templates/default/apps/desktop/publish-update.mjs +93 -0
  12. package/dist/templates/default/apps/desktop/src/declarations.d.ts +4 -0
  13. package/dist/templates/default/apps/desktop/src/main.ts +86 -1
  14. package/dist/templates/default/apps/desktop/src/updates.ts +123 -0
  15. package/dist/templates/default/apps/desktop/stage-update.mjs +70 -0
  16. package/dist/templates/default/apps/desktop/vite.main.config.mts +10 -0
  17. package/dist/templates/default/apps/web/src/routeTree.gen.ts +31 -0
  18. package/dist/templates/default/apps/web/src/router/mobile-login.tsx +84 -0
  19. package/dist/templates/default/bun.lock +7 -2
  20. package/dist/templates/default/package.json +1 -1
  21. package/dist/templates/default/packages/backend/convex/authSetup.ts +9 -1
  22. package/dist/templates/default/packages/backend/convex/desktopUpdates/validator.ts +62 -0
  23. package/dist/templates/default/packages/backend/convex/desktopUpdates.ts +216 -0
  24. package/dist/templates/default/packages/backend/convex/http.ts +6 -0
  25. package/dist/templates/default/packages/backend/convex/schema.ts +2 -0
  26. package/dist/templates/default/packages/cli/auth.ts +1 -20
  27. package/dist/templates/default/packages/cli/origin.ts +22 -0
  28. package/dist/templates/default/packages/disposabl-kit/lib/indexing.ts +1 -0
  29. package/dist/templates/default/packages/disposabl-kit/server/files-functions.ts +1 -1
  30. package/dist/templates/default/packages/disposabl-kit/server/lib/static.ts +7 -0
  31. package/dist/templates/default/packages/disposabl-kit/server/lib/telemetry.ts +62 -12
  32. package/dist/templates/default/packages/tests/README.md +2 -0
  33. package/dist/templates/default/packages/tests/ci-platform-selection.test.ts +53 -0
  34. package/dist/templates/default/packages/tests/desktop-publication.test.ts +251 -0
  35. package/dist/templates/default/packages/tests/desktop-updates.test.ts +200 -0
  36. package/dist/templates/default/packages/tests/flows/desktop-updates.e2e.ts +102 -0
  37. package/dist/templates/default/packages/tests/flows/files.e2e.ts +48 -0
  38. package/dist/templates/default/packages/tests/telemetry.test.ts +170 -0
  39. package/dist/templates/default/vendor/README.md +7 -4
  40. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.3.tgz +0 -0
  41. package/package.json +1 -1
  42. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.1.tgz +0 -0
@@ -0,0 +1,216 @@
1
+ import { v } from "convex/values";
2
+ import { httpAction } from "./_generated/server";
3
+ import {
4
+ internalMutation,
5
+ internalQuery,
6
+ } from "@disposabl/disposabl-kit/server/lib/functions";
7
+ import { makeFunctionReference } from "convex/server";
8
+ import { feed, publication, resolvedUpdate } from "./desktopUpdates/validator";
9
+
10
+ const validFeed = (a: {
11
+ app: string;
12
+ channel: string;
13
+ platform: string;
14
+ arch: string;
15
+ }) =>
16
+ /^[a-f0-9]{32}$/.test(a.app) &&
17
+ /^[a-z0-9][a-z0-9-]*$/.test(a.channel) &&
18
+ ((a.platform === "darwin" && a.arch === "arm64") ||
19
+ (a.platform === "win32" && a.arch === "x64"));
20
+
21
+ export const uploadUrl = internalMutation({
22
+ args: {},
23
+ returns: v.string(),
24
+ handler: (ctx) => ctx.storage.generateUploadUrl(),
25
+ });
26
+
27
+ export const publish = internalMutation({
28
+ args: publication,
29
+ returns: v.null(),
30
+ handler: async (ctx, a) => {
31
+ if (
32
+ !validFeed(a) ||
33
+ !Number.isSafeInteger(a.build) ||
34
+ a.build < 1 ||
35
+ !Number.isSafeInteger(a.attempt) ||
36
+ a.attempt < 1 ||
37
+ a.version !== `1.${a.build}.${a.attempt}` ||
38
+ !/^[a-zA-Z0-9._-]+$/.test(a.filename) ||
39
+ !/^[a-f0-9]{64}$/.test(a.sha256) ||
40
+ !/^[A-Fa-f0-9]{40}$/.test(a.sha1) ||
41
+ !Number.isSafeInteger(a.size) ||
42
+ a.size < 1 ||
43
+ !(a.platform === "darwin"
44
+ ? a.filename.endsWith(`-${a.version}.zip`)
45
+ : a.filename.endsWith(`-${a.version}-full.nupkg`))
46
+ )
47
+ throw new Error("Invalid update metadata");
48
+ const metadata = await ctx.db.system.get("_storage", a.storageId);
49
+ // Compare the digest across the documented hex and backend base64 encodings.
50
+ const digest = metadata?.sha256;
51
+ const expectedBase64 = btoa(
52
+ String.fromCharCode(
53
+ ...a.sha256.match(/../g)!.map((byte) => parseInt(byte, 16)),
54
+ ),
55
+ );
56
+ if (
57
+ !metadata ||
58
+ metadata.size !== a.size ||
59
+ (digest !== a.sha256 && digest !== expectedBase64)
60
+ )
61
+ throw new Error("Uploaded file does not match metadata");
62
+ const latest = await ctx.db
63
+ .query("desktopUpdates")
64
+ .withIndex("by_feed_build", (q) =>
65
+ q
66
+ .eq("app", a.app)
67
+ .eq("channel", a.channel)
68
+ .eq("platform", a.platform)
69
+ .eq("arch", a.arch),
70
+ )
71
+ .order("desc")
72
+ .first();
73
+ const existing = await ctx.db
74
+ .query("desktopUpdates")
75
+ .withIndex("by_feed_filename", (q) =>
76
+ q
77
+ .eq("app", a.app)
78
+ .eq("channel", a.channel)
79
+ .eq("platform", a.platform)
80
+ .eq("arch", a.arch)
81
+ .eq("filename", a.filename),
82
+ )
83
+ .unique();
84
+ if (
85
+ existing &&
86
+ latest?.build === a.build &&
87
+ latest.attempt === a.attempt &&
88
+ existing.build === a.build &&
89
+ existing.attempt === a.attempt &&
90
+ existing.sha256 === a.sha256 &&
91
+ existing.sha1 === a.sha1 &&
92
+ existing.size === a.size
93
+ )
94
+ return null;
95
+ if (
96
+ existing ||
97
+ (latest &&
98
+ (a.build < latest.build ||
99
+ (a.build === latest.build && a.attempt <= latest.attempt)))
100
+ )
101
+ throw new Error("Update is not newer or filename already exists");
102
+ await ctx.db.insert("desktopUpdates", a);
103
+ return null;
104
+ },
105
+ });
106
+
107
+ export const resolve = internalQuery({
108
+ args: { ...feed, filename: v.optional(v.string()) },
109
+ returns: resolvedUpdate,
110
+ handler: async (ctx, a) => {
111
+ if (!validFeed(a)) return null;
112
+ const query = ctx.db.query("desktopUpdates");
113
+ const row = a.filename
114
+ ? await query
115
+ .withIndex("by_feed_filename", (q) =>
116
+ q
117
+ .eq("app", a.app)
118
+ .eq("channel", a.channel)
119
+ .eq("platform", a.platform)
120
+ .eq("arch", a.arch)
121
+ .eq("filename", a.filename!),
122
+ )
123
+ .unique()
124
+ : await query
125
+ .withIndex("by_feed_build", (q) =>
126
+ q
127
+ .eq("app", a.app)
128
+ .eq("channel", a.channel)
129
+ .eq("platform", a.platform)
130
+ .eq("arch", a.arch),
131
+ )
132
+ .order("desc")
133
+ .first();
134
+ if (!row) return null;
135
+ const url = await ctx.storage.getUrl(row.storageId);
136
+ return url
137
+ ? {
138
+ version: row.version,
139
+ filename: row.filename,
140
+ sha1: row.sha1,
141
+ size: row.size,
142
+ url,
143
+ }
144
+ : null;
145
+ },
146
+ });
147
+
148
+ export const desktopUpdate = httpAction(async (ctx, request) => {
149
+ const parts = new URL(request.url).pathname.split("/");
150
+ if (parts.length !== 8 || parts[1] !== "desktop" || parts[2] !== "updates")
151
+ return new Response(null, { status: 404 });
152
+ const [, , , app, channel, platform, arch, name] = parts as [
153
+ string,
154
+ string,
155
+ string,
156
+ string,
157
+ string,
158
+ string,
159
+ string,
160
+ string,
161
+ ];
162
+ const isManifest =
163
+ (platform === "win32" && name === "RELEASES") ||
164
+ (platform === "darwin" && name === "RELEASES.json");
165
+ const result = await ctx.runQuery(
166
+ makeFunctionReference<"query">("desktopUpdates:resolve"),
167
+ { app, channel, platform, arch, ...(isManifest ? {} : { filename: name }) },
168
+ );
169
+ if (!result)
170
+ return new Response(null, {
171
+ status: 404,
172
+ headers: { "Cache-Control": "no-store" },
173
+ });
174
+ if (!isManifest)
175
+ return new Response(null, {
176
+ status: 302,
177
+ headers: { Location: result.url, "Cache-Control": "no-store" },
178
+ });
179
+ const asset = new URL(encodeURIComponent(result.filename), request.url).href;
180
+ const body =
181
+ platform === "win32"
182
+ ? `${result.sha1} ${asset} ${result.size}\n`
183
+ : JSON.stringify({
184
+ currentRelease: result.version,
185
+ releases: [
186
+ {
187
+ version: result.version,
188
+ updateTo: {
189
+ version: result.version,
190
+ name: result.version,
191
+ url: asset,
192
+ },
193
+ },
194
+ ],
195
+ });
196
+ return new Response(body, {
197
+ headers: {
198
+ "Content-Type": platform === "win32" ? "text/plain" : "application/json",
199
+ "Cache-Control": "no-store",
200
+ },
201
+ });
202
+ });
203
+
204
+ // Only discard a newly uploaded blob when no published feed references it.
205
+ export const discardUpload = internalMutation({
206
+ args: { storageId: v.id("_storage") },
207
+ returns: v.null(),
208
+ handler: async (ctx, { storageId }) => {
209
+ const published = await ctx.db
210
+ .query("desktopUpdates")
211
+ .withIndex("by_storageId", (q) => q.eq("storageId", storageId))
212
+ .first();
213
+ if (!published) await ctx.storage.delete(storageId);
214
+ return null;
215
+ },
216
+ });
@@ -1,3 +1,4 @@
1
+ import { desktopUpdate } from "./desktopUpdates";
1
2
  import { page, options as telemetryOptions } from "./telemetry";
2
3
  import createHttpRouter from "@disposabl/disposabl-kit/server/http";
3
4
 
@@ -8,4 +9,9 @@ http.route({
8
9
  method: "OPTIONS",
9
10
  handler: telemetryOptions,
10
11
  });
12
+ http.route({
13
+ pathPrefix: "/desktop/updates/",
14
+ method: "GET",
15
+ handler: desktopUpdate,
16
+ });
11
17
  export default http;
@@ -1,8 +1,10 @@
1
+ import { desktopUpdateTable } from "./desktopUpdates/validator";
1
2
  import { defineSchema, defineTable } from "convex/server";
2
3
  import { v } from "convex/values";
3
4
  import { profile } from "./users/validator";
4
5
 
5
6
  export default defineSchema({
7
+ desktopUpdates: desktopUpdateTable,
6
8
  files: defineTable({
7
9
  owner: v.string(),
8
10
  filename: v.string(),
@@ -48,26 +48,7 @@ const directory = () =>
48
48
  process.env.DISPOSABL_CONFIG_DIR || join(homedir(), ".config", "disposabl");
49
49
  const sessionPath = (url: string) =>
50
50
  join(directory(), `${createHash("sha256").update(url).digest("hex")}.json`);
51
- export function apiUrl(value: string) {
52
- const url = new URL(value);
53
- if (
54
- url.protocol !== "https:" &&
55
- !(
56
- url.protocol === "http:" &&
57
- ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname)
58
- )
59
- )
60
- throw new Error("Use HTTPS, or HTTP on loopback for local development.");
61
- if (
62
- url.username ||
63
- url.password ||
64
- url.search ||
65
- url.hash ||
66
- url.pathname !== "/"
67
- )
68
- throw new Error("Use the API origin without a path or credentials.");
69
- return url.origin;
70
- }
51
+ export { apiUrl } from "./origin";
71
52
  const fetchFor = (origin: string): typeof fetch =>
72
53
  Object.assign(
73
54
  async (
@@ -0,0 +1,22 @@
1
+ export const SERVICE_ORIGIN = "https://www.disposabl.dev";
2
+
3
+ export function apiUrl(value: string) {
4
+ const url = new URL(value);
5
+ if (
6
+ url.protocol !== "https:" &&
7
+ !(
8
+ url.protocol === "http:" &&
9
+ ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname)
10
+ )
11
+ )
12
+ throw new Error("Use HTTPS, or HTTP on loopback for local development.");
13
+ if (
14
+ url.username ||
15
+ url.password ||
16
+ url.search ||
17
+ url.hash ||
18
+ url.pathname !== "/"
19
+ )
20
+ throw new Error("Use the API origin without a path or credentials.");
21
+ return url.origin;
22
+ }
@@ -1,6 +1,7 @@
1
1
  /** Publicly reachable account flows still must not appear in search results. */
2
2
  export const accountPaths = [
3
3
  "/login",
4
+ "/mobile-login",
4
5
  "/signup",
5
6
  "/consent",
6
7
  "/forgot-password",
@@ -36,7 +36,7 @@ const fields = {
36
36
  size: v.number(),
37
37
  location,
38
38
  };
39
- const fileValidator = v.object({
39
+ export const fileValidator = v.object({
40
40
  ...fields,
41
41
  _id: v.id("files"),
42
42
  _creationTime: v.number(),
@@ -85,6 +85,13 @@ export function registerPageRoutes(http: HttpRouter) {
85
85
  ? "no-cache"
86
86
  : "public, max-age=3600",
87
87
  "X-Content-Type-Options": "nosniff",
88
+ ...(path.replace(/\/$/, "") === "/mobile-login"
89
+ ? {
90
+ "Content-Security-Policy": "frame-ancestors 'none'",
91
+ "X-Frame-Options": "DENY",
92
+ "Cache-Control": "no-store",
93
+ }
94
+ : {}),
88
95
  ...(page?.authenticated || isAccountPage(path)
89
96
  ? { "X-Robots-Tag": "noindex" }
90
97
  : {}),
@@ -2,7 +2,13 @@ import config from "../../../../disposabl.json";
2
2
  import { makeFunctionReference } from "convex/server";
3
3
 
4
4
  export type TelemetryEvent =
5
- "api_operation" | "mcp_operation" | "page_view" | "screen_view" | "app_setup";
5
+ | "api_operation"
6
+ | "mcp_operation"
7
+ | "page_view"
8
+ | "screen_view"
9
+ | "app_setup"
10
+ | "app_created"
11
+ | "platform_deployment";
6
12
  export type TelemetryProperties = {
7
13
  source?: "api" | "cli" | "sdk" | "mcp";
8
14
  operation?: string;
@@ -16,6 +22,23 @@ export type TelemetryProperties = {
16
22
  | "account"
17
23
  | "other";
18
24
  duration_ms?: number;
25
+ /** Server-owned app identity; hashed before leaving the backend. */
26
+ app_id?: string;
27
+ time_since_app_creation_ms?: number;
28
+ run_number?: number;
29
+ run_attempt?: number;
30
+ platform?:
31
+ | "web"
32
+ | "android"
33
+ | "ios"
34
+ | "macos"
35
+ | "windows"
36
+ | "linux"
37
+ | "api"
38
+ | "mcp"
39
+ | "typescript-sdk"
40
+ | "cli";
41
+ channel?: "production" | "preview";
19
42
  };
20
43
 
21
44
  type AnalyticsConfig = {
@@ -45,7 +68,16 @@ export function telemetryEnabled(settingsOverride: AnalyticsConfig = settings) {
45
68
  );
46
69
  }
47
70
 
48
- /** Only trusted server callers can supply a user ID. */
71
+ async function opaqueId(value: string) {
72
+ return Array.from(
73
+ new Uint8Array(
74
+ await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value)),
75
+ ),
76
+ (b) => b.toString(16).padStart(2, "0"),
77
+ ).join("");
78
+ }
79
+
80
+ /** Only trusted server callers can supply a user or app ID. */
49
81
  export async function captureTelemetry(
50
82
  event: TelemetryEvent,
51
83
  properties: TelemetryProperties,
@@ -58,17 +90,12 @@ export async function captureTelemetry(
58
90
  process.env.POSTHOG_PROJECT_TOKEN!;
59
91
  const host = settingsOverride.analytics?.host ?? process.env.POSTHOG_HOST!;
60
92
  const identity = userId
61
- ? Array.from(
62
- new Uint8Array(
63
- await crypto.subtle.digest(
64
- "SHA-256",
65
- new TextEncoder().encode(`disposabl:${token}:${userId}`),
66
- ),
67
- ),
68
- (b) => b.toString(16).padStart(2, "0"),
69
- ).join("")
93
+ ? await opaqueId(`disposabl:${token}:${userId}`)
70
94
  : crypto.randomUUID();
71
95
  const safe = {
96
+ ...(properties.app_id && {
97
+ app_id: await opaqueId(`disposabl:${token}:app:${properties.app_id}`),
98
+ }),
72
99
  ...(["api", "cli", "sdk", "mcp"].includes(properties.source ?? "") && {
73
100
  source: properties.source,
74
101
  }),
@@ -88,11 +115,34 @@ export async function captureTelemetry(
88
115
  "account",
89
116
  "other",
90
117
  ].includes(properties.page ?? "") && { page: properties.page }),
118
+ ...([
119
+ "web",
120
+ "android",
121
+ "ios",
122
+ "macos",
123
+ "windows",
124
+ "linux",
125
+ "api",
126
+ "mcp",
127
+ "typescript-sdk",
128
+ "cli",
129
+ ].includes(properties.platform ?? "") && { platform: properties.platform }),
130
+ ...(["production", "preview"].includes(properties.channel ?? "") && {
131
+ channel: properties.channel,
132
+ }),
91
133
  ...(Number.isFinite(properties.duration_ms) &&
92
134
  properties.duration_ms! >= 0 &&
93
- properties.duration_ms! <= 3600000 && {
135
+ properties.duration_ms! <= Number.MAX_SAFE_INTEGER && {
94
136
  duration_ms: Math.round(properties.duration_ms!),
95
137
  }),
138
+ ...Object.fromEntries(
139
+ (["time_since_app_creation_ms", "run_number", "run_attempt"] as const)
140
+ .filter(
141
+ (key) =>
142
+ Number.isSafeInteger(properties[key]) && properties[key]! >= 0,
143
+ )
144
+ .map((key) => [key, properties[key]]),
145
+ ),
96
146
  };
97
147
  try {
98
148
  await fetch(`${host}/capture/`, {
@@ -25,6 +25,8 @@ The initial flows check the public web page, the dashboard's authentication boun
25
25
 
26
26
  The repository's agent fixture flow (`flows/agent.e2e.ts`) creates test users, an app, and component history to verify ownership, pagination, and worker state without calling Boat. It requires `E2E_CONVEX_ADMIN_KEY` and explicitly skips when the key is absent; admin fixture calls are restricted to a loopback backend. Use only a disposable local deployment and keep the key out of source control and logs. Run through the `bun run e2e` or `bun run test` wrappers so E2E telemetry stays disabled.
27
27
 
28
+ The storage fallback flow (`flows/files.e2e.ts`) uses the same loopback/admin restriction to confirm R2 is not configured before uploading. It checks downloaded bytes, anonymous and cross-user rejection, and owner deletion, removing only its own new file. It makes no R2 requests and skips when R2 is fully configured.
29
+
28
30
  The connections browser flow additionally exercises invalid Autumn key submission when `E2E_CONNECTIONS_ENABLED=1`. Set a temporary `CONNECTIONS_ENCRYPTION_KEY` on the isolated backend for that run; the invalid input is rejected before any Autumn request. Restore the backend setting afterward.
29
31
 
30
32
  ## Email provider verification
@@ -0,0 +1,53 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import {
4
+ mkdtempSync,
5
+ mkdirSync,
6
+ writeFileSync,
7
+ readFileSync,
8
+ rmSync,
9
+ } from "node:fs";
10
+ import { tmpdir } from "node:os";
11
+ import { join, resolve } from "node:path";
12
+ import { execFileSync } from "node:child_process";
13
+ test("iOS builds can be paused independently of Android", () => {
14
+ const dir = mkdtempSync(join(tmpdir(), "disposabl-platforms-"));
15
+ try {
16
+ mkdirSync(join(dir, "bin"));
17
+ writeFileSync(
18
+ join(dir, "bin/gh"),
19
+ '#!/bin/sh\ncase "$*" in *pulls/1/files*) echo apps/mobile/src/app/index.tsx;; *) exit 1;; esac\n',
20
+ { mode: 0o755 },
21
+ );
22
+ writeFileSync(
23
+ join(dir, "disposabl.json"),
24
+ JSON.stringify({ platforms: ["web", "android", "ios"], features: [] }),
25
+ );
26
+ const out = join(dir, "output");
27
+ const env = {
28
+ ...process.env,
29
+ PATH: join(dir, "bin") + ":" + process.env.PATH,
30
+ PR: "1",
31
+ GH_REPO: "fixture/app",
32
+ RUNNER_TEMP: dir,
33
+ GITHUB_OUTPUT: out,
34
+ EXPO_CONNECTED: "true",
35
+ };
36
+ execFileSync(
37
+ "bash",
38
+ [resolve(import.meta.dirname, "../../.github/scripts/platforms.sh")],
39
+ { cwd: dir, env: { ...env, IOS_BUILDS_ENABLED: "false" } },
40
+ );
41
+ assert.match(readFileSync(out, "utf8"), /^ios=false$/m);
42
+ assert.match(readFileSync(out, "utf8"), /^android=true$/m);
43
+ writeFileSync(out, "");
44
+ execFileSync(
45
+ "bash",
46
+ [resolve(import.meta.dirname, "../../.github/scripts/platforms.sh")],
47
+ { cwd: dir, env: { ...env, IOS_BUILDS_ENABLED: "true" } },
48
+ );
49
+ assert.match(readFileSync(out, "utf8"), /^ios=true$/m);
50
+ } finally {
51
+ rmSync(dir, { recursive: true, force: true });
52
+ }
53
+ });