freecode-sh 0.1.0-alpha.42 → 0.1.0-rc.4

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.
package/release.mjs ADDED
@@ -0,0 +1,64 @@
1
+ import { verifyReleaseSignature } from './release-trust.mjs'
2
+ import versions from './release-version.cjs'
3
+ export const DESKTOP_ORIGIN = 'https://releases.freecode.sh'
4
+ export const NATIVE_TARGETS = ['darwin-arm64', 'windows-x64']
5
+ export function desktopAssetName(version, target) {
6
+ versions.releaseVersion(version)
7
+ if (!NATIVE_TARGETS.includes(target)) throw new Error('Unsupported desktop target')
8
+ return `freecode-desktop-${version}-${target}.${target === 'darwin-arm64' ? 'dmg' : 'zip'}`
9
+ }
10
+ export function terminalAssetName(version, target) {
11
+ desktopAssetName(version, target) // Shared version and platform validation.
12
+ return `freecode-terminal-${version}-${target}.zip`
13
+ }
14
+ export function candidateAssetNames(version, target, terminalVersion = version) {
15
+ const desktop = desktopAssetName(version, target)
16
+ return [desktop, ...(target === 'darwin-arm64' ? [desktop.replace(/\.dmg$/, '.zip')] : []), terminalAssetName(terminalVersion, target)]
17
+ }
18
+ function validateInventory(manifest, surface, archives, assetName) {
19
+ if (manifest.product !== `freecode-${surface}` || manifest.automaticUpdates !== false || manifest.engineVersion !== '2.1.1' ||
20
+ !/^[a-f0-9]{40}$/.test(manifest.sourceRevision)) throw new Error(`Invalid ${surface} release metadata`)
21
+ if (!Number.isSafeInteger(manifest.buildNumber)) throw new Error('Invalid release build number')
22
+ versions.nativeVersions(manifest.version, manifest.buildNumber)
23
+ if (Object.keys(manifest.assets || {}).sort().join(',') !== NATIVE_TARGETS.join(',')) throw new Error(`Unexpected ${surface} targets`)
24
+ if (Object.keys(manifest.archives || {}).sort().join(',') !== archives.sort().join(',')) throw new Error(`Incomplete ${surface} archive inventory`)
25
+ for (const name of archives) {
26
+ const asset = manifest.archives[name]
27
+ if (!/^[a-f0-9]{64}$/.test(asset?.sha256) || !Number.isSafeInteger(asset?.size) || asset.size < 1) throw new Error('Invalid archive digest')
28
+ }
29
+ for (const target of NATIVE_TARGETS) {
30
+ const name = assetName(manifest.version, target), asset = manifest.assets[target]
31
+ if (asset?.name !== name || asset.url !== `${DESKTOP_ORIGIN}/native/${surface}/releases/v${manifest.version}/${name}` ||
32
+ asset.sha256 !== manifest.archives[name].sha256 || asset.size !== manifest.archives[name].size)
33
+ throw new Error(`Invalid ${surface} asset: ${target}`)
34
+ }
35
+ return manifest
36
+ }
37
+ export function validateDesktopManifest(manifest) {
38
+ if (manifest.schemaVersion !== 2) throw new Error('Invalid desktop release metadata')
39
+ if (!Number.isSafeInteger(manifest.terminal?.buildNumber)) throw new Error('Invalid bundled terminal build number')
40
+ versions.nativeVersions(manifest.terminal?.version, manifest.terminal.buildNumber)
41
+ const archives = NATIVE_TARGETS.flatMap(target => candidateAssetNames(manifest.version, target))
42
+ .filter(name => name.startsWith('freecode-desktop-'))
43
+ return validateInventory(manifest, 'desktop', archives, desktopAssetName)
44
+ }
45
+ export function validateTerminalManifest(manifest) {
46
+ if (manifest.schemaVersion !== 1) throw new Error('Invalid terminal release metadata')
47
+ return validateInventory(manifest, 'terminal', NATIVE_TARGETS.map(target => terminalAssetName(manifest.version, target)), terminalAssetName)
48
+ }
49
+ export function signedDesktopManifest(bytes, signature, publicKey) {
50
+ if (!verifyReleaseSignature(bytes, signature, publicKey)) throw new Error('Invalid desktop release signature')
51
+ return validateDesktopManifest(JSON.parse(bytes.toString('utf8')))
52
+ }
53
+ export function signedTerminalManifest(bytes, signature, publicKey) {
54
+ if (!verifyReleaseSignature(bytes, signature, publicKey)) throw new Error('Invalid terminal release signature')
55
+ return validateTerminalManifest(JSON.parse(bytes.toString('utf8')))
56
+ }
57
+ // Runtime readers accept only the current per-product format. Migration is offline tooling.
58
+ export async function downloadManifest(surface, { publicFetch = fetch, publicKey } = {}) {
59
+ if (!['desktop', 'terminal'].includes(surface)) throw new Error('Unsupported release product')
60
+ const response = await publicFetch(`${DESKTOP_ORIGIN}/native/${surface}/channels/rc.json`, { cache: 'no-store', redirect: 'error', signal: AbortSignal.timeout(10000) })
61
+ if (!response.ok) throw new Error(`${surface} RC unavailable`)
62
+ const envelope = await response.json()
63
+ return (surface === 'terminal' ? signedTerminalManifest : signedDesktopManifest)(Buffer.from(envelope.manifest, 'base64'), Buffer.from(envelope.signature, 'base64'), publicKey)
64
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "product": "freecode-terminal",
4
+ "version": "0.1.0-rc.4",
5
+ "buildNumber": 56,
6
+ "engineVersion": "2.1.1",
7
+ "sourceRevision": "f4853b72980d4dddc6d8126bd0cb5017b785b83d",
8
+ "automaticUpdates": false,
9
+ "assets": {
10
+ "darwin-arm64": {
11
+ "name": "freecode-terminal-0.1.0-rc.4-darwin-arm64.zip",
12
+ "sha256": "4a3c31c3d1e8501f5a446d5bf3a35c49913bc56362e32605c91f092935cd9a83",
13
+ "size": 111313948,
14
+ "url": "https://releases.freecode.sh/native/terminal/releases/v0.1.0-rc.4/freecode-terminal-0.1.0-rc.4-darwin-arm64.zip"
15
+ },
16
+ "windows-x64": {
17
+ "name": "freecode-terminal-0.1.0-rc.4-windows-x64.zip",
18
+ "sha256": "9c2155e099cc83dae6cc6de0c66a8dd03452c17fadb03de6168a86f2bd05fdb8",
19
+ "size": 143622315,
20
+ "url": "https://releases.freecode.sh/native/terminal/releases/v0.1.0-rc.4/freecode-terminal-0.1.0-rc.4-windows-x64.zip"
21
+ }
22
+ },
23
+ "archives": {
24
+ "freecode-terminal-0.1.0-rc.4-darwin-arm64.zip": {
25
+ "sha256": "4a3c31c3d1e8501f5a446d5bf3a35c49913bc56362e32605c91f092935cd9a83",
26
+ "size": 111313948
27
+ },
28
+ "freecode-terminal-0.1.0-rc.4-windows-x64.zip": {
29
+ "sha256": "9c2155e099cc83dae6cc6de0c66a8dd03452c17fadb03de6168a86f2bd05fdb8",
30
+ "size": 143622315
31
+ }
32
+ }
33
+ }
Binary file