@adea-ai/app-framework 0.24.0 → 0.25.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.
- package/README.md +49 -1
- package/dist/cli/macos-signing-cli.d.ts +2 -0
- package/dist/cli/macos-signing-cli.js +14 -0
- package/dist/desktop/channel-proof.js +7 -1
- package/dist/framework-source.json +1 -1
- package/dist/release/framework-package-publish.js +4 -2
- package/dist/release/local-release.d.ts +2 -0
- package/dist/release/local-release.js +25 -2
- package/dist/release/macos-signing.d.ts +27 -0
- package/dist/release/macos-signing.js +101 -0
- package/dist/shell/app-shell.js +21 -33
- package/dist/shell/navigation-drawer.d.ts +12 -0
- package/dist/shell/navigation-drawer.js +42 -0
- package/dist/updates/release-feed.d.ts +2 -0
- package/dist/updates/release-feed.js +11 -2
- package/package.json +16 -4
- package/src/shell/app-shell.tsx +29 -20
- package/src/shell/navigation-drawer.tsx +36 -0
- package/src/app/create-application.ts +0 -245
- package/src/app/service-registry.ts +0 -124
- package/src/ci/toolchain-identity.ts +0 -244
- package/src/cli/cef-helper-cli.ts +0 -21
- package/src/cli/cli-runner.ts +0 -29
- package/src/cli/create-application-cli.ts +0 -62
- package/src/cli/electrobun-shortcut-patch-cli.ts +0 -24
- package/src/cli/framework-update-cli.ts +0 -41
- package/src/cli/release-assets-plan-cli.ts +0 -14
- package/src/cli/release-cut-cli.ts +0 -41
- package/src/cli/release-descriptor-staging-cli.ts +0 -57
- package/src/cli/release-finalize-cli.ts +0 -34
- package/src/cli/release-promote-cli.ts +0 -31
- package/src/cli/release-publish-cli.ts +0 -46
- package/src/cli/release-sign-cli.ts +0 -24
- package/src/cli/release-step-cli.ts +0 -71
- package/src/cli/toolchain-identity-cli.ts +0 -12
- package/src/cli/update-helper-cli.ts +0 -12
- package/src/cli/windows-runtime-patch-cli.ts +0 -17
- package/src/desktop/application-command-client.ts +0 -43
- package/src/desktop/channel-handshake.ts +0 -136
- package/src/desktop/channel-proof.ts +0 -122
- package/src/desktop/desktop-client.ts +0 -303
- package/src/desktop/desktop-gateway.ts +0 -189
- package/src/desktop/desktop-host.ts +0 -335
- package/src/desktop/desktop-stream.ts +0 -324
- package/src/desktop/loopback-policy.ts +0 -41
- package/src/desktop/open-url-channel.ts +0 -79
- package/src/desktop/string-policy.ts +0 -9
- package/src/installer/archive-entry.ts +0 -32
- package/src/installer/command-artifact.ts +0 -307
- package/src/installer/command-qualification-command.ts +0 -75
- package/src/installer/hosted-runner.ts +0 -11
- package/src/installer/installed-payload.ts +0 -408
- package/src/installer/installer-ci-bootstrap.ts +0 -199
- package/src/installer/installer-ci-preflight.ts +0 -61
- package/src/installer/installer-ci-worker.ts +0 -105
- package/src/installer/installer-extraction.ts +0 -367
- package/src/installer/installer-fetch-guard.ts +0 -75
- package/src/installer/installer-identity.ts +0 -331
- package/src/installer/installer-layout.ts +0 -167
- package/src/installer/installer-observation.ts +0 -671
- package/src/installer/installer-process-cleanup.ts +0 -167
- package/src/installer/installer-qualification-command.ts +0 -81
- package/src/installer/installer-renderer-evidence.ts +0 -268
- package/src/installer/installer-upgrade-command.ts +0 -226
- package/src/installer/installer-worker-guard.ts +0 -112
- package/src/installer/native-executable.ts +0 -37
- package/src/installer/upgrade-asset-download.ts +0 -72
- package/src/installer/write-all.ts +0 -19
- package/src/native/app-bundle.ts +0 -86
- package/src/native/cef-helper.ts +0 -471
- package/src/native/desktop-build-hook.ts +0 -21
- package/src/native/electrobun-source-patch.ts +0 -107
- package/src/native/linux-cef-links.ts +0 -14
- package/src/native/native-secret-store.ts +0 -99
- package/src/native/native-utilities.ts +0 -166
- package/src/native/partitioned-window.ts +0 -62
- package/src/native/secure-window.ts +0 -115
- package/src/native/sidecar-services.ts +0 -71
- package/src/native/sidecar.ts +0 -387
- package/src/native/window-bootstrap.ts +0 -77
- package/src/native/windows-build-hook-internal.ts +0 -49
- package/src/native/windows-build-hook.ts +0 -12
- package/src/native/windows-runtime-patch-internal.ts +0 -48
- package/src/native/windows-runtime-patch.ts +0 -15
- package/src/release/feed-release-cut.ts +0 -110
- package/src/release/feed-state.ts +0 -135
- package/src/release/framework-package-publish.ts +0 -163
- package/src/release/framework-update.ts +0 -196
- package/src/release/github-cli.ts +0 -27
- package/src/release/github-release-assets.ts +0 -36
- package/src/release/github-release-cut.ts +0 -237
- package/src/release/github-release-lookup.ts +0 -39
- package/src/release/github-release-promotion.ts +0 -112
- package/src/release/github-release-provenance.ts +0 -65
- package/src/release/github-release-publisher.ts +0 -90
- package/src/release/github-release-qualification.ts +0 -144
- package/src/release/local-provenance.ts +0 -92
- package/src/release/local-release.ts +0 -525
- package/src/release/macos-dmg.ts +0 -113
- package/src/release/release-artifact.ts +0 -53
- package/src/release/release-assets-plan.ts +0 -118
- package/src/release/release-config.ts +0 -420
- package/src/release/release-cut-command.ts +0 -80
- package/src/release/release-cut.ts +0 -133
- package/src/release/release-descriptor-staging.ts +0 -242
- package/src/release/release-finalize.ts +0 -191
- package/src/release/release-promotion-command.ts +0 -36
- package/src/release/release-promotion.ts +0 -132
- package/src/release/release-publication.ts +0 -213
- package/src/release/release-publish-command.ts +0 -163
- package/src/release/release-qualification.ts +0 -397
- package/src/release/release-staging.ts +0 -87
- package/src/release/release-steps.ts +0 -173
- package/src/release/retained-release-build.ts +0 -217
- package/src/shell/application-menu-commands.ts +0 -6
- package/src/shell/application-menu.ts +0 -250
- package/src/updates/channel-update-manager.ts +0 -127
- package/src/updates/desktop-updater.ts +0 -440
- package/src/updates/release-feed.ts +0 -187
- package/src/updates/release-location.ts +0 -101
- package/src/updates/signed-release.ts +0 -311
- package/src/updates/stable-file.ts +0 -32
- package/src/updates/update-arm.ts +0 -107
- package/src/updates/update-channel-store.ts +0 -86
- package/src/updates/update-discovery.ts +0 -113
- package/src/updates/update-download.ts +0 -82
- package/src/updates/update-exclusive-rename.ts +0 -58
- package/src/updates/update-extraction.ts +0 -261
- package/src/updates/update-handoff-plan.ts +0 -75
- package/src/updates/update-helper.ts +0 -87
- package/src/updates/update-launch.ts +0 -33
- package/src/updates/update-manager.ts +0 -130
- package/src/updates/update-process-fence.ts +0 -125
- package/src/updates/update-resume.ts +0 -34
- package/src/updates/update-shutdown.ts +0 -37
- package/src/updates/update-swap-stage.ts +0 -75
- package/src/updates/update-swap.ts +0 -30
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { lstat, mkdir, open, rename, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { join, resolve } from 'node:path'
|
|
3
|
-
import { observeInstalledApp } from './installer-observation'
|
|
4
|
-
import { downloadAsset } from './upgrade-asset-download'
|
|
5
|
-
import type { InstallerPlatform, InstallerRenderer } from './installer-layout'
|
|
6
|
-
import { planReleaseAssets } from '../release/release-assets-plan'
|
|
7
|
-
import { parseReleaseConfig } from '../release/release-config'
|
|
8
|
-
import { feedUrl } from '../updates/release-feed'
|
|
9
|
-
import type { RendererEvidence } from '../release/release-qualification'
|
|
10
|
-
import { versionLessThan } from '../updates/release-version'
|
|
11
|
-
import { discoverSignedRelease } from '../updates/update-discovery'
|
|
12
|
-
import { downloadVerifiedRelease } from '../updates/update-download'
|
|
13
|
-
import type { FetchFunction } from '../updates/release-location'
|
|
14
|
-
import {
|
|
15
|
-
verifyReleaseDescriptor,
|
|
16
|
-
type ReleaseDescriptor,
|
|
17
|
-
type ReleaseTrust,
|
|
18
|
-
type VerifiedRelease,
|
|
19
|
-
} from '../updates/signed-release'
|
|
20
|
-
|
|
21
|
-
const MAX_COMPRESSED_BYTES = 1024 * 1024 * 1024
|
|
22
|
-
const MAX_EXPANDED_BYTES = 4 * 1024 * 1024 * 1024
|
|
23
|
-
const targets = {
|
|
24
|
-
'macos-arm64': ['darwin', 'arm64'],
|
|
25
|
-
'windows-x64': ['win32', 'x64'],
|
|
26
|
-
'linux-x64': ['linux', 'x64'],
|
|
27
|
-
} as const
|
|
28
|
-
|
|
29
|
-
export type UpgradeReceipt = {
|
|
30
|
-
schema: 1
|
|
31
|
-
tag: string
|
|
32
|
-
platform: InstallerPlatform
|
|
33
|
-
from: { tag: string; version: string; channel: ReleaseDescriptor['channel'] }
|
|
34
|
-
to: { version: string; channel: ReleaseDescriptor['channel'] }
|
|
35
|
-
installed: true
|
|
36
|
-
updated: true
|
|
37
|
-
rendererEvidence?: RendererEvidence
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const object = (value: unknown): value is Record<string, unknown> =>
|
|
41
|
-
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
42
|
-
|
|
43
|
-
/** The channel descriptor the app discovers for `platform`, as the release config names it. */
|
|
44
|
-
function discoveryName(
|
|
45
|
-
config: Record<string, unknown>,
|
|
46
|
-
channel: ReleaseDescriptor['channel'],
|
|
47
|
-
platform: InstallerPlatform
|
|
48
|
-
): string {
|
|
49
|
-
const names = config[`${channel}DiscoveryAssets`],
|
|
50
|
-
policies = config.descriptors
|
|
51
|
-
if (!Array.isArray(names) || !object(policies)) throw new Error('Invalid discovery policy')
|
|
52
|
-
const [os, arch] = targets[platform]
|
|
53
|
-
const matches = names.filter((name): name is string => {
|
|
54
|
-
const policy = typeof name === 'string' ? policies[name] : undefined
|
|
55
|
-
return (
|
|
56
|
-
object(policy) && policy.channel === channel && policy.platform === os && policy.arch === arch
|
|
57
|
-
)
|
|
58
|
-
})
|
|
59
|
-
if (matches.length !== 1 || matches[0]!.includes('{tag}'))
|
|
60
|
-
throw new Error('Invalid discovery policy')
|
|
61
|
-
return matches[0]!
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function readBounded(path: string, maximum: number): Promise<string> {
|
|
65
|
-
const info = await lstat(path)
|
|
66
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > maximum)
|
|
67
|
-
throw new Error('Invalid staged descriptor')
|
|
68
|
-
const file = await open(path, 'r')
|
|
69
|
-
try {
|
|
70
|
-
return await file.readFile('utf8')
|
|
71
|
-
} finally {
|
|
72
|
-
await file.close()
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Prove in the trusted release-assets workflow that an installation of the newest published
|
|
78
|
-
* release takes this release's signed update: install the previous version with its own
|
|
79
|
-
* installer, stage and swap in this payload as the app's updater does, and observe the new
|
|
80
|
-
* version start. Returns null when no earlier release has been published for this platform.
|
|
81
|
-
*/
|
|
82
|
-
export async function qualifyUpgradeCommand(options: {
|
|
83
|
-
env: Record<string, string | undefined>
|
|
84
|
-
config: unknown
|
|
85
|
-
tag: string
|
|
86
|
-
platform: InstallerPlatform
|
|
87
|
-
renderer: InstallerRenderer
|
|
88
|
-
directory: string
|
|
89
|
-
onStage?: (stage: string) => void
|
|
90
|
-
fetch?: FetchFunction
|
|
91
|
-
}): Promise<UpgradeReceipt | null> {
|
|
92
|
-
const { env, config, tag, platform, renderer } = options
|
|
93
|
-
if (
|
|
94
|
-
!Object.hasOwn(targets, platform) ||
|
|
95
|
-
!['native', 'cef'].includes(renderer) ||
|
|
96
|
-
!object(config) ||
|
|
97
|
-
typeof config.appName !== 'string' ||
|
|
98
|
-
typeof config.appId !== 'string' ||
|
|
99
|
-
!object(config.releaseSigningKeys) ||
|
|
100
|
-
typeof env.GITHUB_REPOSITORY !== 'string'
|
|
101
|
-
)
|
|
102
|
-
throw new Error('Invalid upgrade qualification context')
|
|
103
|
-
if (env.RELEASE_TAG !== tag) throw new Error('Upgrade release tag mismatch')
|
|
104
|
-
const plan = await planReleaseAssets({ env, config, tag })
|
|
105
|
-
if (env.SOURCE_SHA !== plan.sourceSha) throw new Error('Upgrade source identity mismatch')
|
|
106
|
-
const parsed = parseReleaseConfig(config),
|
|
107
|
-
feed = feedUrl(parsed.feed),
|
|
108
|
-
requirements = parsed.requirements(tag),
|
|
109
|
-
names = requirements.platforms[platform]
|
|
110
|
-
if (!requirements.offlinePolicy || !names || names.length !== 2)
|
|
111
|
-
throw new Error('Upgrade qualification requires an explicit offline policy and payloads')
|
|
112
|
-
const directory = resolve(options.directory),
|
|
113
|
-
destination = join(directory, `upgrade-test-${platform}.json`)
|
|
114
|
-
try {
|
|
115
|
-
await lstat(destination)
|
|
116
|
-
throw new Error('Upgrade receipt already exists')
|
|
117
|
-
} catch (error) {
|
|
118
|
-
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
119
|
-
}
|
|
120
|
-
const keys = new Map<string, string>()
|
|
121
|
-
for (const [id, value] of Object.entries(config.releaseSigningKeys))
|
|
122
|
-
if (typeof value === 'string') keys.set(id, value)
|
|
123
|
-
const base = {
|
|
124
|
-
appId: config.appId,
|
|
125
|
-
repository: env.GITHUB_REPOSITORY,
|
|
126
|
-
platform: targets[platform][0],
|
|
127
|
-
arch: targets[platform][1],
|
|
128
|
-
feed,
|
|
129
|
-
keys,
|
|
130
|
-
}
|
|
131
|
-
const channel: ReleaseDescriptor['channel'] = tag.includes('-dev.') ? 'dev' : 'daily'
|
|
132
|
-
const trust: ReleaseTrust = { ...base, channel }
|
|
133
|
-
const signed = JSON.parse(
|
|
134
|
-
await readBounded(join(directory, discoveryName(config, channel, platform)), 65536)
|
|
135
|
-
)
|
|
136
|
-
const verified = verifyReleaseDescriptor(signed, trust)
|
|
137
|
-
if (
|
|
138
|
-
!verified.ok ||
|
|
139
|
-
verified.descriptor.tag !== tag ||
|
|
140
|
-
verified.descriptor.asset.name !== names[1]
|
|
141
|
-
)
|
|
142
|
-
throw new Error('Untrusted staged descriptor')
|
|
143
|
-
const descriptor = verified.descriptor
|
|
144
|
-
|
|
145
|
-
const fetcher = options.fetch ?? fetch
|
|
146
|
-
|
|
147
|
-
// The previous version is the newest older release on the same channel, or on dev before a
|
|
148
|
-
// channel's first release. A newer-sorting release from a retired version line (such as an
|
|
149
|
-
// old calendar tag) can never update to this one, so it is not an upgrade path to qualify.
|
|
150
|
-
let previous: VerifiedRelease | undefined
|
|
151
|
-
for (const from of channel === 'dev' ? (['dev'] as const) : (['daily', 'dev'] as const)) {
|
|
152
|
-
try {
|
|
153
|
-
previous = await discoverSignedRelease({
|
|
154
|
-
trust: { ...base, channel: from },
|
|
155
|
-
discoveryName: discoveryName(config, from, platform),
|
|
156
|
-
timeoutMs: 30000,
|
|
157
|
-
fetch: fetcher,
|
|
158
|
-
olderThan: descriptor.version,
|
|
159
|
-
})
|
|
160
|
-
break
|
|
161
|
-
} catch (error) {
|
|
162
|
-
if ((error as Error).message !== 'No qualified channel descriptor is available') throw error
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (!previous) return null
|
|
166
|
-
if (previous.tag === tag || !versionLessThan(previous.version, descriptor.version))
|
|
167
|
-
throw new Error('Previous release is not older than this release')
|
|
168
|
-
|
|
169
|
-
const work = join(directory, `upgrade-${platform}`)
|
|
170
|
-
await mkdir(work, { mode: 0o700 })
|
|
171
|
-
const downloaded = await downloadVerifiedRelease({
|
|
172
|
-
descriptor: previous,
|
|
173
|
-
directory: work,
|
|
174
|
-
maxBytes: MAX_COMPRESSED_BYTES,
|
|
175
|
-
timeoutMs: 600000,
|
|
176
|
-
fetch: fetcher,
|
|
177
|
-
})
|
|
178
|
-
const previousArchive = join(work, previous.asset.name)
|
|
179
|
-
await rename(downloaded.path, previousArchive)
|
|
180
|
-
const installerName = parsed.requirements(previous.tag).platforms[platform]?.[0]
|
|
181
|
-
if (!installerName) throw new Error('Previous release has no installer for this platform')
|
|
182
|
-
const previousInstaller = join(work, installerName)
|
|
183
|
-
await downloadAsset({
|
|
184
|
-
feed,
|
|
185
|
-
tag: previous.tag,
|
|
186
|
-
name: installerName,
|
|
187
|
-
destination: previousInstaller,
|
|
188
|
-
fetch: fetcher,
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
const result = await observeInstalledApp({
|
|
192
|
-
env,
|
|
193
|
-
platform,
|
|
194
|
-
renderer,
|
|
195
|
-
appName: config.appName,
|
|
196
|
-
appId: config.appId,
|
|
197
|
-
version: previous.version,
|
|
198
|
-
installer: previousInstaller,
|
|
199
|
-
archive: previousArchive,
|
|
200
|
-
expectedReads: parsed.expectedReads,
|
|
201
|
-
offlinePolicy: requirements.offlinePolicy,
|
|
202
|
-
sidecars: parsed.sidecars,
|
|
203
|
-
onStage: options.onStage,
|
|
204
|
-
update: {
|
|
205
|
-
descriptor,
|
|
206
|
-
trust,
|
|
207
|
-
archive: join(directory, names[1]),
|
|
208
|
-
maxCompressedBytes: MAX_COMPRESSED_BYTES,
|
|
209
|
-
maxExpandedBytes: MAX_EXPANDED_BYTES,
|
|
210
|
-
},
|
|
211
|
-
})
|
|
212
|
-
if (!result.updated || result.updated.version !== descriptor.version || !result.updated.evidence)
|
|
213
|
-
throw new Error('Missing measured evidence for the updated app')
|
|
214
|
-
const receipt: UpgradeReceipt = {
|
|
215
|
-
schema: 1,
|
|
216
|
-
tag,
|
|
217
|
-
platform,
|
|
218
|
-
from: { tag: previous.tag, version: previous.version, channel: previous.channel },
|
|
219
|
-
to: { version: descriptor.version, channel },
|
|
220
|
-
installed: true,
|
|
221
|
-
updated: true,
|
|
222
|
-
rendererEvidence: result.updated.evidence,
|
|
223
|
-
}
|
|
224
|
-
await writeFile(destination, JSON.stringify(receipt, null, 2) + '\n', { flag: 'wx', mode: 0o600 })
|
|
225
|
-
return receipt
|
|
226
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/** Worker interception adapted from adea-ai/adea scripts/desktop-worker-guard.mjs,
|
|
2
|
-
* commit 6155d18941acbb14d9099bc2a33a50ee9683a068 (Apache-2.0). */
|
|
3
|
-
import { realpathSync } from 'node:fs'
|
|
4
|
-
import { lstat, open, writeFile } from 'node:fs/promises'
|
|
5
|
-
import { resolve } from 'node:path'
|
|
6
|
-
import { pathToFileURL } from 'node:url'
|
|
7
|
-
import { assertHostedRunner } from './hosted-runner'
|
|
8
|
-
|
|
9
|
-
function DeniedWorker(): never {
|
|
10
|
-
throw new Error('Nested workers forbidden in installer qualification')
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Install before Electrobun starts its app worker, in a disposable hosted runner only. */
|
|
14
|
-
export function interceptInstallerWorker(options: {
|
|
15
|
-
env: Record<string, string | undefined>
|
|
16
|
-
globals: { Worker: typeof Worker }
|
|
17
|
-
entry: string
|
|
18
|
-
bootstrap: string
|
|
19
|
-
}): void {
|
|
20
|
-
assertHostedRunner(options.env, 'Worker guard')
|
|
21
|
-
if (!options.entry || !options.bootstrap || typeof options.globals.Worker !== 'function')
|
|
22
|
-
throw new Error('Missing worker guard context')
|
|
23
|
-
const Original = options.globals.Worker
|
|
24
|
-
const expected = resolve(options.entry)
|
|
25
|
-
const matchesEntry = (path: string) => {
|
|
26
|
-
const actual = resolve(path)
|
|
27
|
-
if (actual === expected) return true
|
|
28
|
-
try {
|
|
29
|
-
return realpathSync(actual) === realpathSync(expected)
|
|
30
|
-
} catch {
|
|
31
|
-
return false
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
let used = false
|
|
35
|
-
class GuardedWorker extends Original {
|
|
36
|
-
constructor(path: string | URL, workerOptions?: WorkerOptions) {
|
|
37
|
-
if (
|
|
38
|
-
used ||
|
|
39
|
-
typeof path !== 'string' ||
|
|
40
|
-
!matchesEntry(path) ||
|
|
41
|
-
(workerOptions !== undefined &&
|
|
42
|
-
(workerOptions === null ||
|
|
43
|
-
Object.getPrototypeOf(workerOptions) !== Object.prototype ||
|
|
44
|
-
Reflect.ownKeys(workerOptions).length !== 0))
|
|
45
|
-
)
|
|
46
|
-
throw new Error('Unexpected Electrobun worker')
|
|
47
|
-
used = true
|
|
48
|
-
super(options.bootstrap)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (
|
|
52
|
-
!Reflect.set(options.globals, 'Worker', GuardedWorker) ||
|
|
53
|
-
options.globals.Worker !== GuardedWorker
|
|
54
|
-
)
|
|
55
|
-
throw new Error('Cannot install application worker guard')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Deny nested workers and hold the installed app until its exact runtime has been verified. */
|
|
59
|
-
export async function awaitInstallerWorkerPermit(options: {
|
|
60
|
-
env: Record<string, string | undefined>
|
|
61
|
-
globals: { Worker: typeof Worker }
|
|
62
|
-
entry: string
|
|
63
|
-
nonce: string
|
|
64
|
-
acknowledgement: string
|
|
65
|
-
permit: string
|
|
66
|
-
timeoutMs?: number
|
|
67
|
-
}): Promise<string> {
|
|
68
|
-
assertHostedRunner(options.env, 'Worker guard')
|
|
69
|
-
const { entry, nonce, acknowledgement, permit } = options
|
|
70
|
-
const timeoutMs = options.timeoutMs ?? 90_000
|
|
71
|
-
if (
|
|
72
|
-
!entry ||
|
|
73
|
-
!/^[a-f0-9]{48}$/.test(nonce) ||
|
|
74
|
-
!acknowledgement ||
|
|
75
|
-
!permit ||
|
|
76
|
-
resolve(acknowledgement) === resolve(permit) ||
|
|
77
|
-
!Number.isSafeInteger(timeoutMs) ||
|
|
78
|
-
timeoutMs < 1 ||
|
|
79
|
-
timeoutMs > 90_000
|
|
80
|
-
)
|
|
81
|
-
throw new Error('Invalid worker guard context')
|
|
82
|
-
if (
|
|
83
|
-
!Reflect.set(options.globals, 'Worker', DeniedWorker) ||
|
|
84
|
-
options.globals.Worker !== (DeniedWorker as unknown as typeof Worker)
|
|
85
|
-
)
|
|
86
|
-
throw new Error('Cannot block nested workers')
|
|
87
|
-
await writeFile(acknowledgement, nonce + '\n', { flag: 'wx', mode: 0o600 })
|
|
88
|
-
const deadline = Date.now() + timeoutMs
|
|
89
|
-
while (Date.now() < deadline) {
|
|
90
|
-
try {
|
|
91
|
-
const info = await lstat(permit)
|
|
92
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size > 49)
|
|
93
|
-
throw new Error('Invalid worker permit')
|
|
94
|
-
const file = await open(permit, 'r')
|
|
95
|
-
let contents: string
|
|
96
|
-
try {
|
|
97
|
-
const buffer = Buffer.alloc(50)
|
|
98
|
-
const { bytesRead } = await file.read(buffer, 0, buffer.length, 0)
|
|
99
|
-
contents = buffer.subarray(0, bytesRead).toString('utf8')
|
|
100
|
-
} finally {
|
|
101
|
-
await file.close()
|
|
102
|
-
}
|
|
103
|
-
const expected = nonce + '\n'
|
|
104
|
-
if (!expected.startsWith(contents)) throw new Error('Invalid worker permit')
|
|
105
|
-
if (contents === expected) return pathToFileURL(resolve(entry)).href
|
|
106
|
-
} catch (error) {
|
|
107
|
-
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
108
|
-
}
|
|
109
|
-
await new Promise((done) => setTimeout(done, Math.min(100, Math.max(1, deadline - Date.now()))))
|
|
110
|
-
}
|
|
111
|
-
throw new Error('Worker guard permit missing')
|
|
112
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { FileHandle } from 'node:fs/promises'
|
|
2
|
-
import type { InstallerPlatform } from './installer-layout'
|
|
3
|
-
|
|
4
|
-
/** Require an open file to be a native executable for the platform: an arm64 Mach-O on
|
|
5
|
-
* macOS, an x86-64 ELF on Linux and an x64 PE image on Windows. `what` names it in errors. */
|
|
6
|
-
export async function assertNativeExecutable(
|
|
7
|
-
file: FileHandle,
|
|
8
|
-
size: number,
|
|
9
|
-
platform: InstallerPlatform,
|
|
10
|
-
what: string
|
|
11
|
-
): Promise<void> {
|
|
12
|
-
const head = Buffer.alloc(64)
|
|
13
|
-
if ((await file.read(head, 0, head.length, 0)).bytesRead !== head.length)
|
|
14
|
-
throw new Error(`Invalid ${what}`)
|
|
15
|
-
if (platform === 'macos-arm64') {
|
|
16
|
-
if (head.readUInt32LE(0) !== 0xfeedfacf || head.readUInt32LE(4) !== 0x100000c)
|
|
17
|
-
throw new Error(`Invalid macOS ${what}`)
|
|
18
|
-
} else if (platform === 'linux-x64') {
|
|
19
|
-
if (
|
|
20
|
-
!head.subarray(0, 4).equals(Buffer.from([127, 69, 76, 70])) ||
|
|
21
|
-
head[4] !== 2 ||
|
|
22
|
-
head.readUInt16LE(18) !== 62
|
|
23
|
-
)
|
|
24
|
-
throw new Error(`Invalid Linux ${what}`)
|
|
25
|
-
} else {
|
|
26
|
-
const offset = head.readUInt32LE(60),
|
|
27
|
-
signature = Buffer.alloc(6)
|
|
28
|
-
if (
|
|
29
|
-
head.subarray(0, 2).toString() !== 'MZ' ||
|
|
30
|
-
offset + signature.length > size ||
|
|
31
|
-
(await file.read(signature, 0, signature.length, offset)).bytesRead !== signature.length ||
|
|
32
|
-
signature.subarray(0, 4).toString() !== 'PE\0\0' ||
|
|
33
|
-
signature.readUInt16LE(4) !== 0x8664
|
|
34
|
-
)
|
|
35
|
-
throw new Error(`Invalid Windows ${what}`)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto'
|
|
2
|
-
import { open, unlink } from 'node:fs/promises'
|
|
3
|
-
import { isFeedAssetName, isFeedTag, parseFeedRelease } from '../updates/release-feed'
|
|
4
|
-
import {
|
|
5
|
-
fetchReleaseLocation,
|
|
6
|
-
readReleaseJson,
|
|
7
|
-
type FetchFunction,
|
|
8
|
-
} from '../updates/release-location'
|
|
9
|
-
import { writeAll } from './write-all'
|
|
10
|
-
|
|
11
|
-
const MAX_COMPRESSED_BYTES = 1024 * 1024 * 1024
|
|
12
|
-
|
|
13
|
-
/** Download one published release asset and check it against its release.json inventory. */
|
|
14
|
-
export async function downloadAsset(options: {
|
|
15
|
-
/** The app's feed URL, ending in `/`. */
|
|
16
|
-
feed: string
|
|
17
|
-
tag: string
|
|
18
|
-
name: string
|
|
19
|
-
destination: string
|
|
20
|
-
fetch: FetchFunction
|
|
21
|
-
openFile?: typeof open
|
|
22
|
-
signal?: AbortSignal
|
|
23
|
-
}): Promise<void> {
|
|
24
|
-
const { feed, tag, name, destination, fetch: fetcher } = options
|
|
25
|
-
if (!isFeedTag(tag) || !isFeedAssetName(name)) throw new Error('Invalid release asset')
|
|
26
|
-
const release = parseFeedRelease(
|
|
27
|
-
await readReleaseJson(
|
|
28
|
-
await fetchReleaseLocation(
|
|
29
|
-
`${feed}${tag}/release.json`,
|
|
30
|
-
feed,
|
|
31
|
-
fetcher,
|
|
32
|
-
AbortSignal.timeout(30000)
|
|
33
|
-
),
|
|
34
|
-
262144
|
|
35
|
-
)
|
|
36
|
-
)
|
|
37
|
-
const digest =
|
|
38
|
-
release.tag === tag ? release.assets.find((asset) => asset.name === name)?.sha256 : undefined
|
|
39
|
-
if (!digest) throw new Error('Previous release asset has no recorded digest')
|
|
40
|
-
const response = await fetchReleaseLocation(
|
|
41
|
-
`${feed}${tag}/${name}`,
|
|
42
|
-
feed,
|
|
43
|
-
fetcher,
|
|
44
|
-
options.signal ?? AbortSignal.timeout(600000)
|
|
45
|
-
)
|
|
46
|
-
if (response.status !== 200 || !response.body) {
|
|
47
|
-
await response.body?.cancel()
|
|
48
|
-
throw new Error('Previous release download failed')
|
|
49
|
-
}
|
|
50
|
-
const file = await (options.openFile ?? open)(destination, 'wx', 0o600),
|
|
51
|
-
hash = createHash('sha256')
|
|
52
|
-
let completed = false
|
|
53
|
-
try {
|
|
54
|
-
let size = 0
|
|
55
|
-
for await (const chunk of response.body) {
|
|
56
|
-
size += chunk.length
|
|
57
|
-
if (size > MAX_COMPRESSED_BYTES) throw new Error('Previous release asset exceeds bound')
|
|
58
|
-
hash.update(chunk)
|
|
59
|
-
await writeAll(file, chunk)
|
|
60
|
-
}
|
|
61
|
-
if (hash.digest('hex') !== digest)
|
|
62
|
-
throw new Error('Previous release asset differs from its digest')
|
|
63
|
-
await file.close()
|
|
64
|
-
completed = true
|
|
65
|
-
} finally {
|
|
66
|
-
try {
|
|
67
|
-
if (!completed) await file.close()
|
|
68
|
-
} finally {
|
|
69
|
-
if (!completed) await unlink(destination).catch(() => {})
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/** Write a complete chunk or fail if the destination makes no progress. */
|
|
2
|
-
export async function writeAll(
|
|
3
|
-
file: {
|
|
4
|
-
write(buffer: Uint8Array, offset: number, length: number): Promise<{ bytesWritten: number }>
|
|
5
|
-
},
|
|
6
|
-
chunk: Uint8Array
|
|
7
|
-
): Promise<void> {
|
|
8
|
-
let offset = 0
|
|
9
|
-
while (offset < chunk.length) {
|
|
10
|
-
const { bytesWritten } = await file.write(chunk, offset, chunk.length - offset)
|
|
11
|
-
if (
|
|
12
|
-
!Number.isSafeInteger(bytesWritten) ||
|
|
13
|
-
bytesWritten <= 0 ||
|
|
14
|
-
bytesWritten > chunk.length - offset
|
|
15
|
-
)
|
|
16
|
-
throw new Error('Unable to write previous release asset')
|
|
17
|
-
offset += bytesWritten
|
|
18
|
-
}
|
|
19
|
-
}
|
package/src/native/app-bundle.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { readFileSync, statSync } from 'node:fs'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import { containsAsciiControl } from '../desktop/string-policy'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Electrobun packs the host worker at `Resources/app/bun/index.js`, so the
|
|
7
|
-
* `Resources` directory is two levels above the entry module's directory. Pass
|
|
8
|
-
* the entry's `import.meta.dir`; a framework module cannot know where the app's
|
|
9
|
-
* bundle lives.
|
|
10
|
-
*/
|
|
11
|
-
export function bundleResourcesDirectory(entryDirectory: string): string {
|
|
12
|
-
return join(entryDirectory, '..', '..')
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type PackagedVersion = Readonly<{
|
|
16
|
-
version: string
|
|
17
|
-
channel?: string
|
|
18
|
-
identifier?: string
|
|
19
|
-
hash?: string
|
|
20
|
-
}>
|
|
21
|
-
|
|
22
|
-
const text = (value: unknown, max: number): value is string =>
|
|
23
|
-
typeof value === 'string' &&
|
|
24
|
-
value.length > 0 &&
|
|
25
|
-
value.length <= max &&
|
|
26
|
-
!containsAsciiControl(value)
|
|
27
|
-
|
|
28
|
-
/** Read the version Electrobun wrote to `Resources/version.json` when it packaged the app. */
|
|
29
|
-
export function readPackagedVersion(entryDirectory: string): PackagedVersion {
|
|
30
|
-
const file = join(bundleResourcesDirectory(entryDirectory), 'version.json')
|
|
31
|
-
const info = statSync(file)
|
|
32
|
-
if (!info.isFile() || info.size > 1024 * 1024) throw new Error('Invalid packaged version file')
|
|
33
|
-
const value: unknown = JSON.parse(readFileSync(file, 'utf8'))
|
|
34
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
35
|
-
throw new Error('Invalid packaged version file')
|
|
36
|
-
const record = value as Record<string, unknown>
|
|
37
|
-
if (!text(record.version, 64)) throw new Error('Invalid packaged version')
|
|
38
|
-
const result: { version: string; channel?: string; identifier?: string; hash?: string } = {
|
|
39
|
-
version: record.version,
|
|
40
|
-
}
|
|
41
|
-
for (const key of ['channel', 'identifier', 'hash'] as const) {
|
|
42
|
-
const field = record[key]
|
|
43
|
-
if (field === undefined || field === '') continue
|
|
44
|
-
if (!text(field, 255)) throw new Error(`Invalid packaged ${key}`)
|
|
45
|
-
result[key] = field
|
|
46
|
-
}
|
|
47
|
-
return result
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Bundled sidecars live in `Resources/app/sidecars`; copy them there with Electrobun's `build.copy`. */
|
|
51
|
-
export const SIDECAR_DIRECTORY = 'sidecars'
|
|
52
|
-
|
|
53
|
-
/** Validate the sidecar names an app ships: lowercase, portable, unique, at most 16. */
|
|
54
|
-
export function assertSidecarNames(names: unknown): readonly string[] {
|
|
55
|
-
if (
|
|
56
|
-
!Array.isArray(names) ||
|
|
57
|
-
names.length > 16 ||
|
|
58
|
-
names.some((name) => typeof name !== 'string' || !/^[a-z0-9][a-z0-9_-]{0,63}$/.test(name)) ||
|
|
59
|
-
new Set(names).size !== names.length
|
|
60
|
-
)
|
|
61
|
-
throw new Error('Invalid sidecar names')
|
|
62
|
-
return [...(names as string[])]
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** The executable's file name on a platform (`process.platform` or an installer platform). */
|
|
66
|
-
export function sidecarFileName(name: string, platform: string): string {
|
|
67
|
-
assertSidecarNames([name])
|
|
68
|
-
return platform === 'win32' || platform === 'windows-x64' ? `${name}.exe` : name
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* The sidecar's path inside the packaged bundle, relative to the bundle's content
|
|
73
|
-
* root (`<App>.app/Contents` on macOS, the app directory on Windows and Linux).
|
|
74
|
-
*/
|
|
75
|
-
export function sidecarBundlePath(name: string, platform: string): string {
|
|
76
|
-
return `Resources/app/${SIDECAR_DIRECTORY}/${sidecarFileName(name, platform)}`
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Absolute path of a bundled sidecar for the running host; pass the entry's `import.meta.dir`. */
|
|
80
|
-
export function packagedSidecarPath(
|
|
81
|
-
entryDirectory: string,
|
|
82
|
-
name: string,
|
|
83
|
-
platform: string = process.platform
|
|
84
|
-
): string {
|
|
85
|
-
return join(entryDirectory, '..', SIDECAR_DIRECTORY, sidecarFileName(name, platform))
|
|
86
|
-
}
|