Clavem keeps your builds and answers GET /v1/releases/:productId/latest. A license that is valid for the product gets release notes and files with signed download links. Any other key gets only version and published_at. The release docs list the fields. What this page adds is the Electron side: the choice between autoUpdater and a manual flow, the label scheme, a streamed download and the install step.
autoUpdater or a manual flow
Electron’s autoUpdater is built on Squirrel.Mac, Squirrel.Windows or an MSIX updater, depending on how the app is packaged, and each reads a feed in its own format. For the macOS feed, Electron’s documentation describes an url for the update and optional sha256 and size fields. Clavem’s response has no top-level url and no sha256: its links sit inside a files array. So autoUpdater cannot be pointed at it as is.
You have two options. Check and download yourself and let the operating system run the installer, as below. Or serve a small feed of your own, translated from this endpoint, and keep in-place updates. The manual flow costs the customer one extra click and needs no server.
Check
// main/updates.js
import { app, net } from 'electron';
import semver from 'semver';
/** The label you chose at upload, for example darwin-arm64, win32-x64 or linux-x64. */
export const platformLabel = () => `${process.platform}-${process.arch}`;
/** { state: 'up-to-date' | 'available' | 'locked' | 'failed', ... } */
export async function checkForUpdate(base, productId, licenseKey) {
let res;
try {
res = await net.fetch(`${base}/v1/releases/${productId}/latest?${new URLSearchParams({ platform: platformLabel() })}`, {
headers: licenseKey ? { 'X-License-Key': licenseKey } : {},
signal: AbortSignal.timeout(8000),
});
} catch {
return { state: 'failed', reason: 'offline' };
}
if (res.status === 404) return { state: 'up-to-date' }; // nothing published yet
if (res.status === 429) return { state: 'failed', reason: `rate limited, retry in ${res.headers.get('retry-after') ?? 60} s` };
if (!res.ok) return { state: 'failed', reason: `HTTP ${res.status}` };
const release = await res.json();
const current = semver.valid(app.getVersion());
if (!semver.valid(release.version) || !current) return { state: 'failed', reason: 'version is not semver' };
if (!semver.gt(release.version, current)) return { state: 'up-to-date' };
const file = release.files?.find((f) => f.url);
return file
? { state: 'available', version: release.version, notes: release.notes, file }
: { state: 'locked', version: release.version }; // newer, but the key is missing or not valid
}
The semver package orders pre-releases correctly, so 4.0.0-beta.2 is below 4.0.0. net.fetch takes fetch arguments and uses Chromium’s network stack, which follows the system proxy. Against a local stub with release 3.2.1 and the app reporting 3.2.0, plus one live call:
label: darwin-arm64
with key: available 3.2.1 inkwell-3.2.1.zip
without key: { state: 'locked', version: '3.2.1' }
other product: { state: 'up-to-date' }
live demo product: { state: 'up-to-date' }
The live demo product has no published release, so the real API answers 404 with not_found. Handle it as nothing to offer. The first line shows the label trap. The stub’s files were labelled macos and windows, one had no label, and the app asked for darwin-arm64, so only the unlabelled .zip came back. Match your upload labels to what the app sends.
Download, with progress and resume
Request the link when the customer clicks, because it lasts one hour. This function streams to a .part file, resumes with Range, reports each whole percent and renames when the size equals the size field:
import { createWriteStream } from 'node:fs';
import { rename, rm, stat } from 'node:fs/promises';
import { Readable } from 'node:stream';
import { pipeline } from 'node:stream/promises';
export async function downloadFile(file, dest, onPercent = () => {}) {
const part = `${dest}.part`;
let have = await stat(part).then((s) => s.size, () => 0);
if (have > file.size) { await rm(part); have = 0; }
if (have < file.size) {
const res = await net.fetch(file.url, { headers: have ? { Range: `bytes=${have}-` } : {} });
if (res.status === 403) throw new Error('The download link expired. Check for updates again.');
if (res.status !== 200 && res.status !== 206) throw new Error(`HTTP ${res.status}`);
if (res.status === 200) have = 0; // the server ignored Range: start over
let last = -1;
const body = Readable.fromWeb(res.body);
body.on('data', (chunk) => {
have += chunk.length;
const pct = Math.floor((have * 100) / file.size);
if (pct !== last) { last = pct; onPercent(pct); }
});
await pipeline(body, createWriteStream(part, { flags: res.status === 206 ? 'a' : 'w' }));
}
if ((await stat(part)).size !== file.size) throw new Error('Size does not match. Keep the .part file and resume.');
await rename(part, dest);
return dest;
}
With 1 MiB already in the .part file of a 3 MiB download, it resumed and emitted 33 percent events, from 34 to 100. A link with a bad signature threw the expired-link error, which is the 403 path, and a file declared 10 bytes too large threw the size error. The response has no checksum field, so size is the only integrity check the API provides. Sign the installers you upload, and let the operating system verify the signature.
Wire the percentage to the window:
await downloadFile(update.file, join(app.getPath('downloads'), update.file.filename), (pct) => {
win.setProgressBar(pct / 100); // taskbar or dock
win.webContents.send('update:progress', pct); // your own progress bar
});
win.setProgressBar(-1); // remove it
Install
import { shell, app } from 'electron';
const error = await shell.openPath(dest); // resolves to '' on success, or an error message
if (!error && process.platform === 'win32') app.quit(); // let the installer replace the running app
On macOS, open the DMG, and the customer drags the new app over the old one. On Windows, a running executable cannot be replaced, so start the installer and quit.
Limits and timing
The releases endpoint allows 120 requests a minute per IP address, counted apart from validation. Check once at launch or once a day. “Latest” is the most recently published release, not the highest version. A backport published after 3.2.1 becomes the answer, so a customer on 3.2.1 sees nothing newer.
Doing this with Clavem
Upload each installer in the dashboard, give it a platform label and publish. The same key that turns the app on fetches the download. Licenses imported from Lemon Squeezy have no order page, so for them this endpoint is how builds are delivered. See the release docs for limits and storage.
Questions
Can Electron's autoUpdater use Clavem's release endpoint as a feed?
Not directly. autoUpdater is built on Squirrel and reads a feed in Squirrel's format, with a url for the update. Clavem's response lists files with signed links under a files array. You can run the check and download yourself, or serve a translated feed from your own server.
What platform label should my Electron app request?
The one you used when you uploaded each file. A label built from process.platform and process.arch, such as darwin-arm64 or win32-x64, is easy to keep consistent. If your upload labels say macos and the app asks for darwin, it receives only the files with no label.
How do I show download progress in Electron?
Count the bytes as they stream, send the percentage to the renderer, and call BrowserWindow.setProgressBar with a fraction between 0 and 1 for the taskbar or dock.