create-disposabl-app 0.12.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 (33) 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/bun.lock +5 -0
  18. package/dist/templates/default/packages/backend/convex/desktopUpdates/validator.ts +62 -0
  19. package/dist/templates/default/packages/backend/convex/desktopUpdates.ts +216 -0
  20. package/dist/templates/default/packages/backend/convex/http.ts +6 -0
  21. package/dist/templates/default/packages/backend/convex/schema.ts +2 -0
  22. package/dist/templates/default/packages/cli/auth.ts +1 -20
  23. package/dist/templates/default/packages/cli/origin.ts +22 -0
  24. package/dist/templates/default/packages/disposabl-kit/server/files-functions.ts +1 -1
  25. package/dist/templates/default/packages/disposabl-kit/server/lib/telemetry.ts +62 -12
  26. package/dist/templates/default/packages/tests/README.md +2 -0
  27. package/dist/templates/default/packages/tests/ci-platform-selection.test.ts +53 -0
  28. package/dist/templates/default/packages/tests/desktop-publication.test.ts +251 -0
  29. package/dist/templates/default/packages/tests/desktop-updates.test.ts +200 -0
  30. package/dist/templates/default/packages/tests/flows/desktop-updates.e2e.ts +102 -0
  31. package/dist/templates/default/packages/tests/flows/files.e2e.ts +48 -0
  32. package/dist/templates/default/packages/tests/telemetry.test.ts +170 -0
  33. package/package.json +1 -1
@@ -0,0 +1,102 @@
1
+ import { randomBytes, createHash } from "node:crypto";
2
+ import { test, expect } from "e2e";
3
+ import { backendUrl } from "../project.ts";
4
+
5
+ test(
6
+ "desktop feeds publish immutable packages and recover across build retries",
7
+ { platforms: ["backend"] },
8
+ async () => {
9
+ const origin = new URL(backendUrl());
10
+ const key = process.env.E2E_CONVEX_ADMIN_KEY;
11
+ test.skip(
12
+ !process.env.E2E_CONVEX_URL ||
13
+ !["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname) ||
14
+ !key,
15
+ "Requires an explicit isolated loopback backend and admin fixture key",
16
+ );
17
+ const site = new URL(process.env.E2E_CONVEX_SITE_URL!);
18
+ if (!["localhost", "127.0.0.1", "[::1]"].includes(site.hostname))
19
+ throw new Error("Feed fixtures require loopback HTTP actions");
20
+ async function call(name: string, args: object, admin = true) {
21
+ return fetch(`${origin.origin}/api/mutation`, {
22
+ method: "POST",
23
+ signal: AbortSignal.timeout(15_000),
24
+ headers: {
25
+ "Content-Type": "application/json",
26
+ ...(admin ? { Authorization: `Convex ${key}` } : {}),
27
+ },
28
+ body: JSON.stringify({
29
+ path: `desktopUpdates:${name}`,
30
+ args,
31
+ format: "json",
32
+ }),
33
+ }).then((r) => r.json());
34
+ }
35
+ const app = randomBytes(16).toString("hex");
36
+ const feed = `${site.origin}/desktop/updates/${app}/production/win32/x64/`;
37
+ async function upload(build: number, attempt: number, bytes: string) {
38
+ const url = await call("uploadUrl", {});
39
+ expect(url.status).toBe("success");
40
+ expect(new URL(url.value).hostname).toBe(origin.hostname);
41
+ const response = await fetch(url.value, { method: "POST", body: bytes });
42
+ expect(response.ok).toBe(true);
43
+ const { storageId } = await response.json();
44
+ const version = `1.${build}.${attempt}`;
45
+ return {
46
+ app,
47
+ channel: "production",
48
+ platform: "win32",
49
+ arch: "x64",
50
+ version,
51
+ build,
52
+ attempt,
53
+ filename: `fixture-${version}-full.nupkg`,
54
+ storageId,
55
+ sha256: createHash("sha256").update(bytes).digest("hex"),
56
+ sha1: createHash("sha1").update(bytes).digest("hex").toUpperCase(),
57
+ size: Buffer.byteLength(bytes),
58
+ };
59
+ }
60
+ const first = await upload(1, 1, "original");
61
+ expect((await call("publish", first, false)).status).toBe("error");
62
+ const published = await call("publish", first);
63
+ if (published.status !== "success")
64
+ throw new Error(published.errorMessage ?? "Publication failed");
65
+ const repeat = await upload(1, 1, "original");
66
+ expect((await call("publish", repeat)).status).toBe("success");
67
+ expect(
68
+ (await call("discardUpload", { storageId: repeat.storageId })).status,
69
+ ).toBe("success");
70
+ // A successfully published blob remains referenced and cannot be discarded.
71
+ expect(
72
+ (await call("discardUpload", { storageId: first.storageId })).status,
73
+ ).toBe("success");
74
+ const retry = await upload(1, 2, "rebuilt package");
75
+ expect((await call("publish", retry)).status).toBe("success");
76
+ const manifest = await fetch(`${feed}RELEASES`);
77
+ expect(manifest.headers.get("cache-control")).toBe("no-store");
78
+ expect(await manifest.text()).toBe(
79
+ `${retry.sha1} ${feed}${retry.filename} ${retry.size}\n`,
80
+ );
81
+ expect(await (await fetch(`${feed}${first.filename}`)).text()).toBe(
82
+ "original",
83
+ );
84
+ expect(await (await fetch(`${feed}${retry.filename}`)).text()).toBe(
85
+ "rebuilt package",
86
+ );
87
+ const next = await upload(2, 1, "next run");
88
+ expect((await call("publish", next)).status).toBe("success");
89
+ const stale = await upload(1, 99, "old run retry");
90
+ expect((await call("publish", stale)).status).toBe("error");
91
+ expect(
92
+ (await call("discardUpload", { storageId: stale.storageId })).status,
93
+ ).toBe("success");
94
+ expect(await (await fetch(`${feed}RELEASES`)).text()).toBe(
95
+ `${next.sha1} ${feed}${next.filename} ${next.size}\n`,
96
+ );
97
+ expect(
98
+ (await fetch(feed.replace("/production/", "/preview/") + "RELEASES"))
99
+ .status,
100
+ ).toBe(404);
101
+ },
102
+ );
@@ -11,6 +11,40 @@ test(
11
11
  !["127.0.0.1", "localhost", "[::1]"].includes(url.hostname),
12
12
  "File fixtures require a disposable loopback backend",
13
13
  );
14
+ const adminKey = process.env.E2E_CONVEX_ADMIN_KEY;
15
+ test.skip(
16
+ !adminKey,
17
+ "Local admin access is required to verify R2 is disabled",
18
+ );
19
+ const configured = await Promise.all(
20
+ [
21
+ "R2_ACCOUNT_ID",
22
+ "R2_BUCKET_NAME",
23
+ "R2_ACCESS_KEY_ID",
24
+ "R2_SECRET_ACCESS_KEY",
25
+ ].map(async (name) => {
26
+ const response = await fetch(`${url.origin}/api/query`, {
27
+ method: "POST",
28
+ signal: AbortSignal.timeout(15000),
29
+ headers: {
30
+ "Content-Type": "application/json",
31
+ Authorization: `Convex ${adminKey}`,
32
+ },
33
+ body: JSON.stringify({
34
+ path: "_system/cli/queryEnvironmentVariables:get",
35
+ args: { name },
36
+ format: "json",
37
+ }),
38
+ });
39
+ const result = await response.json();
40
+ expect(result.status).toBe("success");
41
+ return Boolean(result.value?.value?.trim());
42
+ }),
43
+ );
44
+ test.skip(
45
+ configured.every(Boolean),
46
+ "R2 configured; fallback test must not call a cloud provider",
47
+ );
14
48
  async function call(
15
49
  kind: string,
16
50
  path: string,
@@ -42,6 +76,15 @@ test(
42
76
  expect(first.value?.status).toBe("complete");
43
77
  const token = first.value.tokens.accessToken as string;
44
78
  const content = `Owned file ${randomUUID()}`;
79
+ expect(
80
+ (
81
+ await call("action", "files/index:upload", {
82
+ filename: "anonymous.txt",
83
+ mediaType: "text/plain",
84
+ bytes: { $bytes: Buffer.from(content).toString("base64") },
85
+ })
86
+ ).status,
87
+ ).toBe("error");
45
88
  const uploaded = await call(
46
89
  "action",
47
90
  "files/index:upload",
@@ -69,6 +112,11 @@ test(
69
112
  renewed,
70
113
  );
71
114
  expect(download.status).toBe("success");
115
+ expect(
116
+ ["127.0.0.1", "localhost", "[::1]"].includes(
117
+ new URL(download.value.url).hostname,
118
+ ),
119
+ ).toBe(true);
72
120
  expect(await (await fetch(download.value.url)).text()).toBe(content);
73
121
  const other = await call("mutation", "auth:signUpWithUsernamePassword", {
74
122
  username: `other${randomUUID().replaceAll("-", "")}`,
@@ -186,3 +186,173 @@ test("page ingestion derives identity from the verified session, never the body"
186
186
  app.features.splice(0, app.features.length, ...originalFeatures);
187
187
  }
188
188
  });
189
+
190
+ test("deployment telemetry sends only approved platform, channel and elapsed time", async () => {
191
+ process.env.CONVEX_SITE_URL = config.productionConvexSiteUrl;
192
+ delete process.env.E2E_TELEMETRY_DISABLED;
193
+ delete process.env.POSTHOG_ENABLED;
194
+ let body: any;
195
+ globalThis.fetch = (async (_input, init) => {
196
+ body = JSON.parse(String(init?.body));
197
+ return new Response();
198
+ }) as typeof fetch;
199
+ await captureTelemetry(
200
+ "platform_deployment",
201
+ {
202
+ app_id: "private-app",
203
+ platform: "android",
204
+ channel: "preview",
205
+ outcome: "success",
206
+ time_since_app_creation_ms: 7200000,
207
+ run_number: 2,
208
+ run_attempt: 1,
209
+ prompt: "private",
210
+ url: "https://private.example",
211
+ } as any,
212
+ "owner",
213
+ config,
214
+ );
215
+ assert.equal(body.properties.time_since_app_creation_ms, 7200000);
216
+ assert.equal(body.properties.duration_ms, undefined);
217
+ assert.equal(body.properties.run_number, 2);
218
+ assert.equal(body.properties.run_attempt, 1);
219
+ assert.equal(body.properties.platform, "android");
220
+ assert.equal(body.properties.channel, "preview");
221
+ assert.equal(JSON.stringify(body).includes("private"), false);
222
+ const appId = body.properties.app_id;
223
+ assert.match(appId, /^[a-f0-9]{64}$/);
224
+ await captureTelemetry(
225
+ "app_created",
226
+ { app_id: "private-app" },
227
+ "owner",
228
+ config,
229
+ );
230
+ assert.equal(body.properties.app_id, appId);
231
+ await captureTelemetry(
232
+ "app_setup",
233
+ { app_id: "private-app", duration_ms: 400 },
234
+ "owner",
235
+ config,
236
+ );
237
+ assert.equal(body.properties.app_id, appId);
238
+ assert.equal(body.properties.duration_ms, 400);
239
+ await captureTelemetry(
240
+ "app_created",
241
+ { app_id: "another-app" },
242
+ "owner",
243
+ config,
244
+ );
245
+ assert.notEqual(body.properties.app_id, appId);
246
+ });
247
+
248
+ test("release transitions measure from creation and ignore duplicate reports", async () => {
249
+ const { report } = await import("../backend/convex/previews/internal");
250
+ const { default: appConfig } = await import("../../disposabl.json");
251
+ const features = [...appConfig.features];
252
+ const original = Date.now;
253
+ const scheduled: any[] = [];
254
+ let release: any = null;
255
+ const app = {
256
+ _id: "row",
257
+ _creationTime: 1000,
258
+ appId: "11111111-1111-4111-8111-111111111111",
259
+ userId: "owner",
260
+ githubOwner: "owner",
261
+ githubRepo: "repo",
262
+ platforms: ["web"],
263
+ };
264
+ process.env.DISPOSABL_ENVIRONMENT = "production";
265
+ process.env.POSTHOG_PROJECT_TOKEN = "token";
266
+ process.env.POSTHOG_HOST = "https://us.i.posthog.com";
267
+ delete process.env.E2E_TELEMETRY_DISABLED;
268
+ delete process.env.POSTHOG_ENABLED;
269
+ appConfig.features.push("analytics" as never);
270
+ Date.now = () => 6000;
271
+ const ctx = {
272
+ scheduler: {
273
+ runAfter: async (_delay: any, _fn: any, args: any) => {
274
+ scheduled.push(args);
275
+ },
276
+ },
277
+ db: {
278
+ query: (table: string) => ({
279
+ withIndex: () => ({
280
+ unique: async () => (table === "apps" ? app : release),
281
+ }),
282
+ }),
283
+ insert: async (_table: string, data: any) => {
284
+ release = { _id: "release", ...data };
285
+ },
286
+ patch: async (_table: string, _id: string, data: any) => {
287
+ release = { ...release, ...data };
288
+ },
289
+ },
290
+ };
291
+ const args = {
292
+ userId: "owner",
293
+ appId: "11111111-1111-4111-8111-111111111111",
294
+ githubOwner: "owner",
295
+ githubRepo: "repo",
296
+ reference: "main",
297
+ production: true,
298
+ platform: "web",
299
+ status: "ready",
300
+ run: { id: 1, attempt: 1, number: 1, commitSha: "sha", url: "private" },
301
+ };
302
+ try {
303
+ await (report as any)._handler(ctx, args);
304
+ await (report as any)._handler(ctx, args);
305
+ assert.equal(scheduled.length, 1);
306
+ assert.deepEqual(scheduled[0].properties, {
307
+ app_id: app.appId,
308
+ platform: "web",
309
+ channel: "production",
310
+ outcome: "success",
311
+ time_since_app_creation_ms: 5000,
312
+ run_number: 1,
313
+ run_attempt: 1,
314
+ });
315
+ Date.now = () => 604801000;
316
+ const failed = {
317
+ ...args,
318
+ status: "failed",
319
+ run: { ...args.run, id: 2, number: 2 },
320
+ };
321
+ await (report as any)._handler(ctx, failed);
322
+ await (report as any)._handler(ctx, failed);
323
+ assert.equal(scheduled.length, 2);
324
+ assert.equal(scheduled[1].properties.outcome, "error");
325
+ assert.equal(scheduled[1].properties.time_since_app_creation_ms, 604800000);
326
+ assert.equal(
327
+ scheduled[1].properties.app_id,
328
+ scheduled[0].properties.app_id,
329
+ );
330
+ assert.equal(scheduled[1].properties.run_number, 2);
331
+ // Older and duplicate reports cannot alter the latest attempt's observations.
332
+ await (report as any)._handler(ctx, args);
333
+ assert.equal(scheduled.length, 2);
334
+ await (report as any)._handler(ctx, {
335
+ ...failed,
336
+ status: "ready",
337
+ run: { ...failed.run, attempt: 2 },
338
+ });
339
+ assert.equal(scheduled[2].properties.run_attempt, 2);
340
+ assert.equal(scheduled[2].properties.outcome, "success");
341
+ // A same-attempt correction remains reconcilable by app/run/attempt/platform/channel.
342
+ await (report as any)._handler(ctx, {
343
+ ...failed,
344
+ run: { ...failed.run, attempt: 2 },
345
+ });
346
+ assert.equal(scheduled[3].properties.run_attempt, 2);
347
+ assert.equal(scheduled[3].properties.outcome, "error");
348
+ process.env.E2E_TELEMETRY_DISABLED = "1";
349
+ await (report as any)._handler(ctx, {
350
+ ...args,
351
+ run: { ...args.run, id: 3 },
352
+ });
353
+ assert.equal(scheduled.length, 4);
354
+ } finally {
355
+ Date.now = original;
356
+ appConfig.features.splice(0, appConfig.features.length, ...features);
357
+ }
358
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-disposabl-app",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Create a Disposabl app",
5
5
  "type": "module",
6
6
  "license": "MIT",