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,123 @@
1
+ export type UpdateState = 'idle' | 'checking' | 'downloading' | 'ready';
2
+
3
+ export function feedUrl(
4
+ base: string,
5
+ channel: string,
6
+ platform: string,
7
+ arch: string,
8
+ ) {
9
+ if (!base || !/^[a-z0-9][a-z0-9-]*$/.test(channel)) return '';
10
+ try {
11
+ const url = new URL(base);
12
+ if (
13
+ url.protocol !== 'https:' ||
14
+ url.username ||
15
+ url.password ||
16
+ url.search ||
17
+ url.hash
18
+ )
19
+ return '';
20
+ url.pathname = `${url.pathname.replace(/\/+$/, '')}/${channel}/${platform}/${arch}`;
21
+ return url.toString();
22
+ } catch {
23
+ return '';
24
+ }
25
+ }
26
+
27
+ export function createUpdateController(options: {
28
+ supported: boolean;
29
+ feed: string;
30
+ readyAt?: number;
31
+ now?: () => number;
32
+ start: () => void;
33
+ install: () => void | Promise<void>;
34
+ show: (kind: 'info' | 'error', message: string, detail?: string) => void;
35
+ confirmRestart: () => Promise<boolean>;
36
+ onState?: (state: UpdateState) => void;
37
+ }) {
38
+ let state: UpdateState = 'idle';
39
+ let confirming = false;
40
+ const setState = (next: UpdateState) => {
41
+ state = next;
42
+ options.onState?.(next);
43
+ };
44
+ const restartError = () =>
45
+ options.show(
46
+ 'error',
47
+ 'Could not restart to install the update.',
48
+ 'Your update is still downloaded. Try Restart to update again.',
49
+ );
50
+ const restart = async () => {
51
+ if (state !== 'ready' || confirming) return;
52
+ confirming = true;
53
+ try {
54
+ if (await options.confirmRestart()) await options.install();
55
+ } catch {
56
+ restartError();
57
+ } finally {
58
+ confirming = false;
59
+ }
60
+ };
61
+ return {
62
+ get state() {
63
+ return state;
64
+ },
65
+ check() {
66
+ if (!options.supported)
67
+ return options.show(
68
+ 'info',
69
+ 'Automatic updates are unavailable for this build.',
70
+ 'Download the latest installer from the app’s download page.',
71
+ );
72
+ if (!options.feed)
73
+ return options.show(
74
+ 'error',
75
+ 'Updates are not configured for this build.',
76
+ );
77
+ if ((options.now ?? Date.now)() < (options.readyAt ?? 0))
78
+ return options.show(
79
+ 'info',
80
+ 'Finishing installation. Try checking for updates in a few seconds.',
81
+ );
82
+ if (state === 'ready') {
83
+ void restart();
84
+ return;
85
+ }
86
+ if (state !== 'idle')
87
+ return options.show('info', 'An update check is already in progress.');
88
+ setState('checking');
89
+ try {
90
+ options.start();
91
+ } catch {
92
+ setState('idle');
93
+ options.show(
94
+ 'error',
95
+ 'Could not check for updates.',
96
+ 'Please try again later.',
97
+ );
98
+ }
99
+ },
100
+ available() {
101
+ if (state === 'checking') setState('downloading');
102
+ },
103
+ unavailable() {
104
+ if (state !== 'checking') return;
105
+ setState('idle');
106
+ options.show('info', 'This app is up to date.');
107
+ },
108
+ downloaded() {
109
+ if (state !== 'checking' && state !== 'downloading') return;
110
+ setState('ready');
111
+ void restart();
112
+ },
113
+ error() {
114
+ if (state === 'ready') return restartError();
115
+ setState('idle');
116
+ options.show(
117
+ 'error',
118
+ 'Could not check for updates.',
119
+ 'Check your connection and try again.',
120
+ );
121
+ },
122
+ };
123
+ }
@@ -0,0 +1,70 @@
1
+ import { cp, mkdir, readdir, readFile, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const root = fileURLToPath(new URL('../..', import.meta.url));
6
+ const {
7
+ DISPOSABL_DESKTOP_UPDATE_URL: base,
8
+ DISPOSABL_DESKTOP_UPDATE_CHANNEL: channel = 'production',
9
+ DISPOSABL_DESKTOP_PLATFORM: platform,
10
+ DISPOSABL_RELEASE_VERSION: version,
11
+ } = process.env;
12
+ if (!base) process.exit(0);
13
+ const url = new URL(base);
14
+ if (
15
+ url.protocol !== 'https:' ||
16
+ url.username ||
17
+ url.password ||
18
+ url.search ||
19
+ url.hash ||
20
+ !/^[a-z0-9][a-z0-9-]*$/.test(channel)
21
+ )
22
+ throw new Error('Invalid desktop update URL or channel');
23
+ if (!/^\d+\.\d+\.\d+$/.test(version ?? ''))
24
+ throw new Error('Invalid update version');
25
+ const targets = { macos: ['darwin', 'arm64'], windows: ['win32', 'x64'] };
26
+ if (!targets[platform]) process.exit(0);
27
+ // Never stage an ad-hoc signed Mac app as an update.
28
+ if (platform === 'macos' && process.env.MACOS_NOTARIZE !== 'true')
29
+ process.exit(0);
30
+ const [os, arch] = targets[platform];
31
+ url.pathname = `${url.pathname.replace(/\/+$/, '')}/${channel}/${os}/${arch}/`;
32
+ const release = join(root, 'dist/release');
33
+ const output = join(root, 'dist/update', channel, os, arch);
34
+ await mkdir(output, { recursive: true });
35
+ const files = await readdir(release);
36
+ if (platform === 'macos') {
37
+ const zips = files.filter((name) => name.endsWith('.zip'));
38
+ if (zips.length !== 1) throw new Error('Expected one macOS ZIP');
39
+ const name = zips[0];
40
+ await cp(join(release, name), join(output, name));
41
+ const updateTo = {
42
+ version,
43
+ name: version,
44
+ pub_date: new Date().toISOString(),
45
+ url: new URL(encodeURIComponent(name), url).href,
46
+ };
47
+ await writeFile(
48
+ join(output, 'RELEASES.json'),
49
+ JSON.stringify(
50
+ { currentRelease: version, releases: [{ version, updateTo }] },
51
+ null,
52
+ 2,
53
+ ) + '\n',
54
+ );
55
+ } else {
56
+ const releases = await readFile(join(release, 'RELEASES'), 'utf8');
57
+ const names = [
58
+ ...releases.matchAll(/^[A-Fa-f0-9]{40}\s+(\S+)\s+\d+\s*$/gm),
59
+ ].map((match) => match[1]);
60
+ if (
61
+ !names.length ||
62
+ names.some(
63
+ (name) =>
64
+ !files.includes(name) || name.includes('/') || name.includes('\\'),
65
+ )
66
+ )
67
+ throw new Error('Invalid Squirrel RELEASES');
68
+ for (const name of names) await cp(join(release, name), join(output, name));
69
+ await writeFile(join(output, 'RELEASES'), releases);
70
+ }
@@ -1,7 +1,17 @@
1
1
  import { defineConfig } from 'vite';
2
+ import manifest from './package.json' with { type: 'json' };
2
3
 
3
4
  export default defineConfig({
4
5
  define: {
6
+ DISPOSABL_DESKTOP_ID: JSON.stringify(
7
+ 'disposablDesktopId' in manifest ? manifest.disposablDesktopId : '',
8
+ ),
9
+ DISPOSABL_UPDATE_URL: JSON.stringify(
10
+ process.env.DISPOSABL_DESKTOP_UPDATE_URL || '',
11
+ ),
12
+ DISPOSABL_UPDATE_CHANNEL: JSON.stringify(
13
+ process.env.DISPOSABL_DESKTOP_UPDATE_CHANNEL || 'production',
14
+ ),
5
15
  DISPOSABL_WEB_URL: JSON.stringify(
6
16
  process.env.CONVEX_SITE_URL || process.env.VITE_CONVEX_SITE_URL || '',
7
17
  ),
@@ -23,6 +23,7 @@
23
23
  "@electron-forge/maker-dmg": "8.0.1",
24
24
  "@electron-forge/maker-rpm": "8.0.1",
25
25
  "@electron-forge/maker-squirrel": "8.0.1",
26
+ "@electron-forge/maker-zip": "8.0.1",
26
27
  "@electron-forge/plugin-fuses": "8.0.1",
27
28
  "@electron-forge/plugin-vite": "8.0.1",
28
29
  "@electron-forge/publisher-github": "8.0.1",
@@ -526,6 +527,8 @@
526
527
 
527
528
  "@electron-forge/maker-squirrel": ["@electron-forge/maker-squirrel@8.0.1", "", { "dependencies": { "@electron-forge/core-utils": "8.0.1", "@electron-forge/maker-base": "8.0.1", "@electron-forge/shared-types": "8.0.1" }, "optionalDependencies": { "electron-winstaller": "^5.3.0" } }, "sha512-V6QrJvvmX2xbITXP1+/bXYe2hkMM7BYnQ8vzVHDOca2P6pn68MZsCSewqm8wiBIBSEeYuRhrztvV8aMlJ5n5Mg=="],
528
529
 
530
+ "@electron-forge/maker-zip": ["@electron-forge/maker-zip@8.0.1", "", { "dependencies": { "@electron-forge/core-utils": "8.0.1", "@electron-forge/maker-base": "8.0.1", "@electron-forge/shared-types": "8.0.1", "cross-zip": "^4.0.0" } }, "sha512-EyMyAMFRZTPKbe6K1HEAgnpAMC7OvR8tQ2iG/5Vd++iG2AVdFJ9usChfW72n172jk9CTfFc7L88IF8lXMYYvIQ=="],
531
+
529
532
  "@electron-forge/multi-logger": ["@electron-forge/multi-logger@8.0.1", "", { "dependencies": { "debug": "^4.3.1", "ink": "^7.1.1", "react": "^19.2.0", "string-width": "^8.2.0", "wrap-ansi": "^10.0.0" } }, "sha512-cgYcETMtlkcYiMC8YcaaW8jFDmVZ6mbNBL0Yi0ekjoOjcBecJS/uy7+9GvM9DWq3Ie5YCfe4+AWuVR3HF56/sQ=="],
530
533
 
531
534
  "@electron-forge/plugin-base": ["@electron-forge/plugin-base@8.0.1", "", { "dependencies": { "@electron-forge/shared-types": "8.0.1" } }, "sha512-lN0ZQyRmMNC/m/XV+Pc7mb/YnLlmSGzWb46McZrk5/vwDyS6t4ZqyA9LDpKs21chjEoQS7q7PLNDRuyh4Lb6KQ=="],
@@ -1898,6 +1901,8 @@
1898
1901
 
1899
1902
  "cross-spawn": ["cross-spawn@7.0.6", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA=="],
1900
1903
 
1904
+ "cross-zip": ["cross-zip@4.0.1", "", {}, "sha512-n63i0lZ0rvQ6FXiGQ+/JFCKAUyPFhLQYJIqKaa+tSJtfKeULF/IDNDAbdnSIxgS4NTuw2b0+lj8LzfITuq+ZxQ=="],
1905
+
1901
1906
  "crypto-random-string": ["crypto-random-string@4.0.0", "", { "dependencies": { "type-fest": "^1.0.1" } }, "sha512-x8dy3RnvYdlUcPOjkEHqozhiwzKNSq7GcPuXFbnyMOCHxX8V3OgIg/pYuabl2sbUPfIJaeAQB7PMOK8DFIdoRA=="],
1902
1907
 
1903
1908
  "css-select": ["css-select@5.2.2", "", { "dependencies": { "boolbase": "^1.0.0", "css-what": "^6.1.0", "domhandler": "^5.0.2", "domutils": "^3.0.1", "nth-check": "^2.0.1" } }, "sha512-TizTzUddG/xYLA3NXodFM0fSbNizXjOKhqiQQwvhlspadZokn1KDy0NZFS0wuEubIYAV5/c1/lAr0TaaFXEXzw=="],
@@ -0,0 +1,62 @@
1
+ import { defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+
4
+ export const feed = {
5
+ app: v.string(),
6
+ channel: v.string(),
7
+ platform: v.string(),
8
+ arch: v.string(),
9
+ };
10
+ export const publication = {
11
+ ...feed,
12
+ version: v.string(),
13
+ build: v.number(),
14
+ attempt: v.number(),
15
+ filename: v.string(),
16
+ storageId: v.id("_storage"),
17
+ sha256: v.string(),
18
+ sha1: v.string(),
19
+ size: v.number(),
20
+ };
21
+
22
+ export const resolvedUpdate = v.union(
23
+ v.null(),
24
+ v.object({
25
+ version: v.string(),
26
+ filename: v.string(),
27
+ sha1: v.string(),
28
+ size: v.number(),
29
+ url: v.string(),
30
+ }),
31
+ );
32
+
33
+ export const desktopUpdateTable = defineTable({
34
+ app: v.string(),
35
+ channel: v.string(),
36
+ platform: v.string(),
37
+ arch: v.string(),
38
+ version: v.string(),
39
+ build: v.number(),
40
+ attempt: v.number(),
41
+ filename: v.string(),
42
+ storageId: v.id("_storage"),
43
+ sha256: v.string(),
44
+ sha1: v.string(),
45
+ size: v.number(),
46
+ })
47
+ .index("by_feed_build", [
48
+ "app",
49
+ "channel",
50
+ "platform",
51
+ "arch",
52
+ "build",
53
+ "attempt",
54
+ ])
55
+ .index("by_storageId", ["storageId"])
56
+ .index("by_feed_filename", [
57
+ "app",
58
+ "channel",
59
+ "platform",
60
+ "arch",
61
+ "filename",
62
+ ]);
@@ -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
+ }
@@ -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(),