@adea-ai/app-framework 0.24.0 → 0.24.1

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 (128) hide show
  1. package/README.md +43 -1
  2. package/dist/framework-source.json +1 -1
  3. package/dist/release/framework-package-publish.js +4 -2
  4. package/dist/shell/app-shell.js +21 -33
  5. package/dist/shell/navigation-drawer.d.ts +12 -0
  6. package/dist/shell/navigation-drawer.js +42 -0
  7. package/package.json +13 -2
  8. package/src/shell/app-shell.tsx +29 -20
  9. package/src/shell/navigation-drawer.tsx +36 -0
  10. package/src/app/create-application.ts +0 -245
  11. package/src/app/service-registry.ts +0 -124
  12. package/src/ci/toolchain-identity.ts +0 -244
  13. package/src/cli/cef-helper-cli.ts +0 -21
  14. package/src/cli/cli-runner.ts +0 -29
  15. package/src/cli/create-application-cli.ts +0 -62
  16. package/src/cli/electrobun-shortcut-patch-cli.ts +0 -24
  17. package/src/cli/framework-update-cli.ts +0 -41
  18. package/src/cli/release-assets-plan-cli.ts +0 -14
  19. package/src/cli/release-cut-cli.ts +0 -41
  20. package/src/cli/release-descriptor-staging-cli.ts +0 -57
  21. package/src/cli/release-finalize-cli.ts +0 -34
  22. package/src/cli/release-promote-cli.ts +0 -31
  23. package/src/cli/release-publish-cli.ts +0 -46
  24. package/src/cli/release-sign-cli.ts +0 -24
  25. package/src/cli/release-step-cli.ts +0 -71
  26. package/src/cli/toolchain-identity-cli.ts +0 -12
  27. package/src/cli/update-helper-cli.ts +0 -12
  28. package/src/cli/windows-runtime-patch-cli.ts +0 -17
  29. package/src/desktop/application-command-client.ts +0 -43
  30. package/src/desktop/channel-handshake.ts +0 -136
  31. package/src/desktop/channel-proof.ts +0 -122
  32. package/src/desktop/desktop-client.ts +0 -303
  33. package/src/desktop/desktop-gateway.ts +0 -189
  34. package/src/desktop/desktop-host.ts +0 -335
  35. package/src/desktop/desktop-stream.ts +0 -324
  36. package/src/desktop/loopback-policy.ts +0 -41
  37. package/src/desktop/open-url-channel.ts +0 -79
  38. package/src/desktop/string-policy.ts +0 -9
  39. package/src/installer/archive-entry.ts +0 -32
  40. package/src/installer/command-artifact.ts +0 -307
  41. package/src/installer/command-qualification-command.ts +0 -75
  42. package/src/installer/hosted-runner.ts +0 -11
  43. package/src/installer/installed-payload.ts +0 -408
  44. package/src/installer/installer-ci-bootstrap.ts +0 -199
  45. package/src/installer/installer-ci-preflight.ts +0 -61
  46. package/src/installer/installer-ci-worker.ts +0 -105
  47. package/src/installer/installer-extraction.ts +0 -367
  48. package/src/installer/installer-fetch-guard.ts +0 -75
  49. package/src/installer/installer-identity.ts +0 -331
  50. package/src/installer/installer-layout.ts +0 -167
  51. package/src/installer/installer-observation.ts +0 -671
  52. package/src/installer/installer-process-cleanup.ts +0 -167
  53. package/src/installer/installer-qualification-command.ts +0 -81
  54. package/src/installer/installer-renderer-evidence.ts +0 -268
  55. package/src/installer/installer-upgrade-command.ts +0 -226
  56. package/src/installer/installer-worker-guard.ts +0 -112
  57. package/src/installer/native-executable.ts +0 -37
  58. package/src/installer/upgrade-asset-download.ts +0 -72
  59. package/src/installer/write-all.ts +0 -19
  60. package/src/native/app-bundle.ts +0 -86
  61. package/src/native/cef-helper.ts +0 -471
  62. package/src/native/desktop-build-hook.ts +0 -21
  63. package/src/native/electrobun-source-patch.ts +0 -107
  64. package/src/native/linux-cef-links.ts +0 -14
  65. package/src/native/native-secret-store.ts +0 -99
  66. package/src/native/native-utilities.ts +0 -166
  67. package/src/native/partitioned-window.ts +0 -62
  68. package/src/native/secure-window.ts +0 -115
  69. package/src/native/sidecar-services.ts +0 -71
  70. package/src/native/sidecar.ts +0 -387
  71. package/src/native/window-bootstrap.ts +0 -77
  72. package/src/native/windows-build-hook-internal.ts +0 -49
  73. package/src/native/windows-build-hook.ts +0 -12
  74. package/src/native/windows-runtime-patch-internal.ts +0 -48
  75. package/src/native/windows-runtime-patch.ts +0 -15
  76. package/src/release/feed-release-cut.ts +0 -110
  77. package/src/release/feed-state.ts +0 -135
  78. package/src/release/framework-package-publish.ts +0 -163
  79. package/src/release/framework-update.ts +0 -196
  80. package/src/release/github-cli.ts +0 -27
  81. package/src/release/github-release-assets.ts +0 -36
  82. package/src/release/github-release-cut.ts +0 -237
  83. package/src/release/github-release-lookup.ts +0 -39
  84. package/src/release/github-release-promotion.ts +0 -112
  85. package/src/release/github-release-provenance.ts +0 -65
  86. package/src/release/github-release-publisher.ts +0 -90
  87. package/src/release/github-release-qualification.ts +0 -144
  88. package/src/release/local-provenance.ts +0 -92
  89. package/src/release/local-release.ts +0 -525
  90. package/src/release/macos-dmg.ts +0 -113
  91. package/src/release/release-artifact.ts +0 -53
  92. package/src/release/release-assets-plan.ts +0 -118
  93. package/src/release/release-config.ts +0 -420
  94. package/src/release/release-cut-command.ts +0 -80
  95. package/src/release/release-cut.ts +0 -133
  96. package/src/release/release-descriptor-staging.ts +0 -242
  97. package/src/release/release-finalize.ts +0 -191
  98. package/src/release/release-promotion-command.ts +0 -36
  99. package/src/release/release-promotion.ts +0 -132
  100. package/src/release/release-publication.ts +0 -213
  101. package/src/release/release-publish-command.ts +0 -163
  102. package/src/release/release-qualification.ts +0 -397
  103. package/src/release/release-staging.ts +0 -87
  104. package/src/release/release-steps.ts +0 -173
  105. package/src/release/retained-release-build.ts +0 -217
  106. package/src/shell/application-menu-commands.ts +0 -6
  107. package/src/shell/application-menu.ts +0 -250
  108. package/src/updates/channel-update-manager.ts +0 -127
  109. package/src/updates/desktop-updater.ts +0 -440
  110. package/src/updates/release-feed.ts +0 -187
  111. package/src/updates/release-location.ts +0 -101
  112. package/src/updates/signed-release.ts +0 -311
  113. package/src/updates/stable-file.ts +0 -32
  114. package/src/updates/update-arm.ts +0 -107
  115. package/src/updates/update-channel-store.ts +0 -86
  116. package/src/updates/update-discovery.ts +0 -113
  117. package/src/updates/update-download.ts +0 -82
  118. package/src/updates/update-exclusive-rename.ts +0 -58
  119. package/src/updates/update-extraction.ts +0 -261
  120. package/src/updates/update-handoff-plan.ts +0 -75
  121. package/src/updates/update-helper.ts +0 -87
  122. package/src/updates/update-launch.ts +0 -33
  123. package/src/updates/update-manager.ts +0 -130
  124. package/src/updates/update-process-fence.ts +0 -125
  125. package/src/updates/update-resume.ts +0 -34
  126. package/src/updates/update-shutdown.ts +0 -37
  127. package/src/updates/update-swap-stage.ts +0 -75
  128. package/src/updates/update-swap.ts +0 -30
@@ -1,113 +0,0 @@
1
- import { createHash } from 'node:crypto'
2
- import {
3
- isRepositorySlug,
4
- verifyReleaseDescriptor,
5
- type ReleaseTrust,
6
- type VerifiedRelease,
7
- } from './signed-release'
8
- import {
9
- fetchReleaseLocation,
10
- readReleaseBytes,
11
- readReleaseJson,
12
- type FetchFunction,
13
- } from './release-location'
14
- import { parseFeedRelease, parseReleaseLedger, type FeedRelease } from './release-feed'
15
- import { versionLessThan } from './release-version'
16
-
17
- const MAX_POINTER_BYTES = 262_144,
18
- MAX_LEDGER_BYTES = 1024 * 1024
19
-
20
- /** Discover and authenticate the app's channel descriptor without trusting feed metadata as an update. */
21
- export async function discoverSignedRelease(options: {
22
- trust: ReleaseTrust
23
- discoveryName: string
24
- timeoutMs?: number
25
- signal?: AbortSignal
26
- fetch?: FetchFunction
27
- /** Take the newest release of the channel that sorts below this version instead of the
28
- * channel pointer's release. */
29
- olderThan?: string
30
- }): Promise<VerifiedRelease> {
31
- const { trust, discoveryName, olderThan } = options
32
- const timeout = options.timeoutMs ?? 10_000
33
- if (
34
- !trust ||
35
- !isRepositorySlug(trust.repository) ||
36
- !['stable', 'daily', 'dev'].includes(trust.channel) ||
37
- typeof trust.feed !== 'string' ||
38
- typeof discoveryName !== 'string' ||
39
- !/^[A-Za-z0-9][A-Za-z0-9._-]{0,199}\.json$/.test(discoveryName) ||
40
- discoveryName === 'release.json' ||
41
- !Number.isSafeInteger(timeout) ||
42
- timeout < 1 ||
43
- timeout > 60_000
44
- )
45
- throw new Error('Invalid release discovery policy')
46
- const controller = new AbortController(),
47
- timer = setTimeout(() => controller.abort(), timeout)
48
- const signal = options.signal
49
- ? AbortSignal.any([controller.signal, options.signal])
50
- : controller.signal
51
- const fetcher = options.fetch ?? globalThis.fetch
52
- const get = (path: string) =>
53
- fetchReleaseLocation(`${trust.feed}${path}`, trust.feed, fetcher, signal)
54
- try {
55
- if (signal.aborted) throw new Error('Release discovery cancelled')
56
- let selected: FeedRelease | null = null
57
- if (olderThan === undefined) {
58
- selected = parseFeedRelease(
59
- await readReleaseJson(await get(`channels/${trust.channel}.json`), MAX_POINTER_BYTES)
60
- )
61
- if (selected.channel !== trust.channel) throw new Error('Invalid channel pointer')
62
- } else {
63
- // A daily stays on the daily channel after promotion; dev builds are their own line.
64
- const kinds =
65
- trust.channel === 'stable'
66
- ? ['stable']
67
- : trust.channel === 'dev'
68
- ? ['dev']
69
- : ['daily', 'stable']
70
- const ledger = parseReleaseLedger(
71
- await readReleaseJson(await get('index.json'), MAX_LEDGER_BYTES),
72
- // The feed URL ends in the app slug the ledger names.
73
- new URL(trust.feed).pathname.split('/').at(-2)!
74
- )
75
- const entry = ledger.releases.find(
76
- (item) => kinds.includes(item.kind) && versionLessThan(item.tag, olderThan)
77
- )
78
- if (entry) {
79
- selected = parseFeedRelease(
80
- await readReleaseJson(await get(`${entry.tag}/release.json`), MAX_POINTER_BYTES)
81
- )
82
- if (selected.tag !== entry.tag) throw new Error('Invalid feed release')
83
- }
84
- }
85
- const listed = selected?.assets.find((asset) => asset.name === discoveryName)
86
- if (!selected || !listed) throw new Error('No qualified channel descriptor is available')
87
- const { tag } = selected
88
- const bytes = await readReleaseBytes(await get(`${tag}/${discoveryName}`), 65_536)
89
- if (
90
- bytes.length !== listed.size ||
91
- createHash('sha256').update(bytes).digest('hex') !== listed.sha256
92
- )
93
- throw new Error('Channel descriptor differs from its release')
94
- let signed: unknown
95
- try {
96
- signed = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes))
97
- } catch {
98
- throw new Error('Invalid release feed response')
99
- }
100
- const result = verifyReleaseDescriptor(signed, trust)
101
- if (!result.ok || result.descriptor.tag !== tag) throw new Error('Untrusted channel descriptor')
102
- const payload = selected.assets.find((asset) => asset.name === result.descriptor.asset.name)
103
- if (
104
- !payload ||
105
- payload.size !== result.descriptor.asset.size ||
106
- payload.sha256 !== result.descriptor.asset.sha256
107
- )
108
- throw new Error('Release payload is missing or differs from its descriptor')
109
- return result.descriptor
110
- } finally {
111
- clearTimeout(timer)
112
- }
113
- }
@@ -1,82 +0,0 @@
1
- import { mkdtemp, open, rm } from 'node:fs/promises'
2
- import { join, resolve } from 'node:path'
3
- import { isVerifiedRelease, verifyReleaseStream, type VerifiedRelease } from './signed-release'
4
- import { fetchReleaseLocation, type FetchFunction } from './release-location'
5
-
6
- /** Download an authenticated release to a new private directory; caller owns cleanup and installation. */
7
- export async function downloadVerifiedRelease(options: {
8
- descriptor: VerifiedRelease
9
- directory: string
10
- maxBytes: number
11
- timeoutMs?: number
12
- signal?: AbortSignal
13
- fetch?: FetchFunction
14
- }): Promise<{ path: string; directory: string }> {
15
- const { descriptor, maxBytes } = options
16
- const timeout = options.timeoutMs ?? 120_000
17
- if (
18
- !isVerifiedRelease(descriptor) ||
19
- !Number.isSafeInteger(maxBytes) ||
20
- maxBytes < 1 ||
21
- descriptor.asset.size > maxBytes ||
22
- !Number.isSafeInteger(timeout) ||
23
- timeout < 1 ||
24
- timeout > 600_000
25
- )
26
- throw new Error('Invalid verified download request')
27
- const controller = new AbortController()
28
- const timer = setTimeout(() => controller.abort(), timeout)
29
- const signal = options.signal
30
- ? AbortSignal.any([controller.signal, options.signal])
31
- : controller.signal
32
- const fetcher = options.fetch ?? globalThis.fetch
33
- let temporary: string | undefined
34
- try {
35
- if (signal.aborted) throw new Error('Release download cancelled')
36
- // Verification bound the URL to `<feed><tag>/<name>`; redirects stay inside that feed.
37
- const { url, name } = descriptor.asset
38
- const feed = url.slice(0, url.length - `${descriptor.tag}/${name}`.length)
39
- const response = await fetchReleaseLocation(url, feed, fetcher, signal)
40
- if (response.status !== 200 || !response.body) {
41
- await response.body?.cancel()
42
- throw new Error('Release download failed')
43
- }
44
- const length = response.headers.get('content-length')
45
- if (length !== null && (!/^\d+$/.test(length) || Number(length) !== descriptor.asset.size)) {
46
- await response.body.cancel()
47
- throw new Error('Release download size mismatch')
48
- }
49
- temporary = await mkdtemp(join(resolve(options.directory), 'framework-update-'))
50
- const path = join(temporary, 'archive')
51
- const file = await open(path, 'wx', 0o600)
52
- try {
53
- async function* writeChunks() {
54
- let size = 0
55
- for await (const chunk of response.body!) {
56
- if (!(chunk instanceof Uint8Array) || signal.aborted)
57
- throw new Error('Invalid download chunk')
58
- size += chunk.length
59
- if (!Number.isSafeInteger(size) || size > descriptor.asset.size)
60
- throw new Error('Release download exceeds signed size')
61
- let offset = 0
62
- while (offset < chunk.length) {
63
- const { bytesWritten } = await file.write(chunk, offset, chunk.length - offset)
64
- if (!bytesWritten) throw new Error('Unable to write update')
65
- offset += bytesWritten
66
- }
67
- yield chunk
68
- }
69
- }
70
- if (!(await verifyReleaseStream(writeChunks(), descriptor)))
71
- throw new Error('Release download verification failed')
72
- } finally {
73
- await file.close()
74
- }
75
- return { path, directory: temporary }
76
- } catch (error) {
77
- if (temporary) await rm(temporary, { recursive: true, force: true })
78
- throw error
79
- } finally {
80
- clearTimeout(timer)
81
- }
82
- }
@@ -1,58 +0,0 @@
1
- import { dlopen, FFIType, ptr } from 'bun:ffi'
2
- import { isAbsolute, resolve } from 'node:path'
3
-
4
- /** Rename without replacing an existing destination. The caller must validate and own both parent directories. */
5
- export function renameUpdateExclusive(source: string, destination: string): void {
6
- if (
7
- typeof source !== 'string' ||
8
- typeof destination !== 'string' ||
9
- !isAbsolute(source) ||
10
- !isAbsolute(destination) ||
11
- resolve(source) !== source ||
12
- resolve(destination) !== destination ||
13
- source === destination ||
14
- source.includes('\0') ||
15
- destination.includes('\0')
16
- )
17
- throw new Error('Invalid exclusive rename paths')
18
- if (process.platform === 'darwin') {
19
- const library = dlopen('libSystem.B.dylib', {
20
- renamex_np: { args: [FFIType.ptr, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
21
- })
22
- try {
23
- const from = Buffer.from(source + '\0'),
24
- to = Buffer.from(destination + '\0')
25
- if (library.symbols.renamex_np(ptr(from), ptr(to), 4) !== 0)
26
- throw new Error('Exclusive rename failed')
27
- } finally {
28
- library.close()
29
- }
30
- } else if (process.platform === 'linux') {
31
- const library = dlopen('libc.so.6', {
32
- renameat2: {
33
- args: [FFIType.i32, FFIType.ptr, FFIType.i32, FFIType.ptr, FFIType.u32],
34
- returns: FFIType.i32,
35
- },
36
- })
37
- try {
38
- const from = Buffer.from(source + '\0'),
39
- to = Buffer.from(destination + '\0')
40
- if (library.symbols.renameat2(-100, ptr(from), -100, ptr(to), 1) !== 0)
41
- throw new Error('Exclusive rename failed')
42
- } finally {
43
- library.close()
44
- }
45
- } else if (process.platform === 'win32') {
46
- const library = dlopen('kernel32.dll', {
47
- MoveFileW: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
48
- })
49
- try {
50
- const from = Buffer.from(source + '\0', 'utf16le'),
51
- to = Buffer.from(destination + '\0', 'utf16le')
52
- if (library.symbols.MoveFileW(ptr(from), ptr(to)) === 0)
53
- throw new Error('Exclusive rename failed')
54
- } finally {
55
- library.close()
56
- }
57
- } else throw new Error('Unsupported exclusive rename platform')
58
- }
@@ -1,261 +0,0 @@
1
- import { createHash } from 'node:crypto'
2
- import { constants } from 'node:fs'
3
- import { lstat, mkdir, mkdtemp, open, readFile, realpath, rm, symlink } from 'node:fs/promises'
4
- import { isAbsolute, join } from 'node:path'
5
- import { Transform } from 'node:stream'
6
- import { pipeline } from 'node:stream/promises'
7
- import { createZstdDecompress } from 'node:zlib'
8
- import { x as extract } from 'tar'
9
- import {
10
- assertBuildMetadata,
11
- assertPayloadLayout,
12
- assertPortableAppName,
13
- type InstallerPlatform,
14
- type InstallerRenderer,
15
- } from '../installer/installer-layout'
16
- import { isVerifiedRelease, verifyReleaseStream, type VerifiedRelease } from './signed-release'
17
- import { isLinuxCefLibraryLink } from '../native/linux-cef-links'
18
- import { safeArchivePath } from '../installer/archive-entry'
19
- import { assertSidecarNames, sidecarBundlePath } from '../native/app-bundle'
20
-
21
- /** Extract a verified full update into a new private directory. Does not replace an installed app. */
22
- export async function extractVerifiedUpdate(options: {
23
- descriptor: VerifiedRelease
24
- archive: string
25
- directory: string
26
- platform: InstallerPlatform
27
- renderer: InstallerRenderer
28
- appName: string
29
- maxCompressedBytes: number
30
- maxExpandedBytes: number
31
- /** Sidecar executables the app bundles; each must be a present, executable file. */
32
- sidecars?: readonly string[]
33
- }): Promise<{ directory: string; payload: string }> {
34
- const { descriptor, archive, platform, renderer, appName, maxCompressedBytes, maxExpandedBytes } =
35
- options
36
- const expected = {
37
- 'macos-arm64': ['darwin', 'arm64'],
38
- 'windows-x64': ['win32', 'x64'],
39
- 'linux-x64': ['linux', 'x64'],
40
- } as const
41
- if (
42
- !isVerifiedRelease(descriptor) ||
43
- !expected[platform] ||
44
- descriptor.platform !== expected[platform][0] ||
45
- descriptor.arch !== expected[platform][1] ||
46
- !isAbsolute(archive) ||
47
- !isAbsolute(options.directory) ||
48
- !Number.isSafeInteger(maxCompressedBytes) ||
49
- maxCompressedBytes < 1 ||
50
- descriptor.asset.size > maxCompressedBytes ||
51
- !Number.isSafeInteger(maxExpandedBytes) ||
52
- maxExpandedBytes < 1
53
- )
54
- throw new Error('Invalid update extraction context')
55
- assertPortableAppName(appName)
56
- const sidecars = assertSidecarNames(options.sidecars ?? [])
57
- const archiveRoot = platform === 'macos-arm64' ? `${appName}.app` : appName.replaceAll(' ', '')
58
- const info = await lstat(archive)
59
- if (!info.isFile() || info.isSymbolicLink() || info.size !== descriptor.asset.size)
60
- throw new Error('Invalid update archive')
61
- const file = await open(archive, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0))
62
- let directory: string | undefined
63
- try {
64
- const before = await file.stat()
65
- if (
66
- !before.isFile() ||
67
- before.dev !== info.dev ||
68
- before.ino !== info.ino ||
69
- before.size !== info.size ||
70
- !(await verifyReleaseStream(
71
- file.createReadStream({ autoClose: false, start: 0 }),
72
- descriptor
73
- ))
74
- )
75
- throw new Error('Update archive verification failed')
76
- const parent = await realpath(options.directory)
77
- if (!(await lstat(parent)).isDirectory()) throw new Error('Invalid update staging directory')
78
- directory = await mkdtemp(join(parent, 'framework-update-extract-'))
79
- const payloadRoot = join(directory, 'payload'),
80
- decompressed = join(directory, 'payload.tar')
81
- await mkdir(payloadRoot, { mode: 0o700 })
82
- const entries: string[] = [],
83
- links: { path: string; target: string }[] = [],
84
- seen = new Set<string>(),
85
- fold = platform === 'windows-x64'
86
- let invalid = false
87
- const reject = () => {
88
- invalid = true
89
- return false
90
- }
91
- let expanded = 0,
92
- fileBytes = 0
93
- const bound = new Transform({
94
- transform(chunk, _encoding, done) {
95
- expanded += chunk.length
96
- if (!Number.isSafeInteger(expanded) || expanded > maxExpandedBytes)
97
- done(new Error('Expanded update exceeds bound'))
98
- else done(null, chunk)
99
- },
100
- })
101
- const hash = createHash('sha256')
102
- let compressedBytes = 0
103
- const verifyInput = new Transform({
104
- transform(chunk, _encoding, done) {
105
- compressedBytes += chunk.length
106
- if (!Number.isSafeInteger(compressedBytes) || compressedBytes > descriptor.asset.size)
107
- done(new Error('Update archive exceeds signed size'))
108
- else {
109
- hash.update(chunk)
110
- done(null, chunk)
111
- }
112
- },
113
- })
114
- const output = await open(decompressed, 'wx', 0o600)
115
- try {
116
- await pipeline(
117
- file.createReadStream({ autoClose: false, start: 0 }),
118
- verifyInput,
119
- createZstdDecompress(),
120
- bound,
121
- output.createWriteStream({ autoClose: true })
122
- )
123
- } finally {
124
- await output.close()
125
- }
126
- if (compressedBytes !== descriptor.asset.size || hash.digest('hex') !== descriptor.asset.sha256)
127
- throw new Error('Update archive changed during decompression')
128
- const unpack = extract({
129
- file: decompressed,
130
- cwd: payloadRoot,
131
- strict: true,
132
- preserveOwner: false,
133
- chmod: true,
134
- umask: 0o7022,
135
- maxMetaEntrySize: 1024 * 1024,
136
- filter(path, entry) {
137
- if (!('type' in entry)) return reject()
138
- if (path === '.' || path === './') {
139
- if (entry.type !== 'Directory') return reject()
140
- return false
141
- }
142
- const normalized = safeArchivePath(path, fold)
143
- if (!normalized) return reject()
144
- const canonical = normalized.normalize('NFC'),
145
- canonicalRoot = archiveRoot.normalize('NFC')
146
- const key = fold ? canonical.toLowerCase() : canonical
147
- const rootKey = fold ? canonicalRoot.toLowerCase() : canonicalRoot
148
- if (key !== rootKey && !key.startsWith(rootKey + '/')) return reject()
149
- if (seen.has(key) || seen.size >= 200000) return reject()
150
- const relative = normalized.slice(archiveRoot.length + 1),
151
- linkTarget = typeof entry.linkpath === 'string' ? entry.linkpath : ''
152
- const cefLink =
153
- platform === 'linux-x64' &&
154
- renderer === 'cef' &&
155
- entry.type === 'SymbolicLink' &&
156
- isLinuxCefLibraryLink(relative, linkTarget)
157
- if (entry.type !== 'File' && entry.type !== 'Directory' && !cefLink) return reject()
158
- seen.add(key)
159
- entries.push(normalized)
160
- // Never let the tar extractor traverse a link: create the known links
161
- // only after every ordinary entry has been extracted and validated.
162
- if (cefLink) {
163
- links.push({ path: normalized, target: linkTarget })
164
- return false
165
- }
166
- if (entry.type === 'File') {
167
- if (!Number.isSafeInteger(entry.size) || entry.size < 0) return reject()
168
- fileBytes += entry.size
169
- if (!Number.isSafeInteger(fileBytes) || fileBytes > maxExpandedBytes) return reject()
170
- }
171
- return true
172
- },
173
- })
174
- await unpack
175
- if (invalid) throw new Error('Unsafe or unsupported update archive entry')
176
- if (links.length) {
177
- const bin = join(payloadRoot, archiveRoot, 'bin'),
178
- cef = join(bin, 'cef')
179
- for (const path of [join(payloadRoot, archiveRoot), bin, cef]) {
180
- const value = await lstat(path)
181
- if (!value.isDirectory() || value.isSymbolicLink())
182
- throw new Error('Invalid CEF link directory')
183
- }
184
- for (const link of links) {
185
- const destination = join(payloadRoot, link.path),
186
- target = join(bin, link.target),
187
- value = await lstat(target)
188
- if (!value.isFile() || value.isSymbolicLink()) throw new Error('Invalid CEF link target')
189
- await symlink(link.target, destination)
190
- }
191
- }
192
- await rm(decompressed)
193
- const after = await file.stat()
194
- if (
195
- after.dev !== before.dev ||
196
- after.ino !== before.ino ||
197
- after.size !== before.size ||
198
- after.mtimeMs !== before.mtimeMs ||
199
- !(await verifyReleaseStream(
200
- file.createReadStream({ autoClose: false, start: 0 }),
201
- descriptor
202
- ))
203
- )
204
- throw new Error('Update archive changed during extraction')
205
- assertPayloadLayout({ platform, renderer, appName, entries, sidecars })
206
- const prefix =
207
- platform === 'macos-arm64' ? join(`${appName}.app`, 'Contents') : appName.replaceAll(' ', '')
208
- const resources = join(payloadRoot, prefix, 'Resources')
209
- const bin = platform === 'macos-arm64' ? 'MacOS' : 'bin',
210
- suffix = platform === 'windows-x64' ? '.exe' : ''
211
- const executables = [
212
- join(bin, `launcher${suffix}`),
213
- join(bin, `bun${suffix}`),
214
- ...sidecars.map((name) => sidecarBundlePath(name, platform)),
215
- ]
216
- const critical = [
217
- ...executables,
218
- 'Resources/main.js',
219
- 'Resources/app/bun/index.js',
220
- 'Resources/app/client/index.html',
221
- ]
222
- for (const path of critical) {
223
- const item = await lstat(join(payloadRoot, prefix, path))
224
- if (
225
- !item.isFile() ||
226
- item.isSymbolicLink() ||
227
- item.size < 1 ||
228
- (platform !== 'windows-x64' &&
229
- process.platform !== 'win32' &&
230
- executables.includes(path) &&
231
- !(item.mode & 0o100))
232
- )
233
- throw new Error('Invalid critical update file')
234
- }
235
- for (const name of ['version.json', 'build.json']) {
236
- const metadata = await lstat(join(resources, name))
237
- if (
238
- !metadata.isFile() ||
239
- metadata.isSymbolicLink() ||
240
- metadata.size < 1 ||
241
- metadata.size > 1024 * 1024
242
- )
243
- throw new Error('Invalid update metadata')
244
- }
245
- if (
246
- JSON.parse(await readFile(join(resources, 'version.json'), 'utf8')).version !==
247
- descriptor.version
248
- )
249
- throw new Error('Update version mismatch')
250
- assertBuildMetadata(JSON.parse(await readFile(join(resources, 'build.json'), 'utf8')), renderer)
251
- return {
252
- directory,
253
- payload: join(payloadRoot, platform === 'macos-arm64' ? `${appName}.app` : prefix),
254
- }
255
- } catch (error) {
256
- if (directory) await rm(directory, { recursive: true, force: true })
257
- throw error
258
- } finally {
259
- await file.close()
260
- }
261
- }
@@ -1,75 +0,0 @@
1
- import { basename, isAbsolute, resolve } from 'node:path'
2
- import {
3
- assertPortableAppName,
4
- type InstallerPlatform,
5
- type InstallerRenderer,
6
- } from '../installer/installer-layout'
7
- import {
8
- isVerifiedReleaseForTrust,
9
- type ReleaseTrust,
10
- type VerifiedRelease,
11
- } from './signed-release'
12
- import { versionLessThan } from './release-version'
13
-
14
- /** Validate an explicitly approved update and its intended installation. This plan does not move files or launch a helper. */
15
- export function planUpdateHandoff(options: {
16
- descriptor: VerifiedRelease
17
- trust: ReleaseTrust
18
- currentVersion: string
19
- approved: boolean
20
- approvedVersion: string
21
- target: string
22
- appName: string
23
- platform: InstallerPlatform
24
- renderer: InstallerRenderer
25
- }) {
26
- const {
27
- descriptor,
28
- trust,
29
- currentVersion,
30
- approved,
31
- approvedVersion,
32
- target,
33
- appName,
34
- platform,
35
- renderer,
36
- } = options
37
- assertPortableAppName(appName)
38
- const expected = {
39
- 'macos-arm64': ['darwin', 'arm64'],
40
- 'windows-x64': ['win32', 'x64'],
41
- 'linux-x64': ['linux', 'x64'],
42
- } as const
43
- if (
44
- !expected[platform] ||
45
- !['native', 'cef'].includes(renderer) ||
46
- !isVerifiedReleaseForTrust(descriptor, trust) ||
47
- descriptor.platform !== expected[platform][0] ||
48
- descriptor.arch !== expected[platform][1] ||
49
- approved !== true ||
50
- approvedVersion !== descriptor.version ||
51
- typeof currentVersion !== 'string' ||
52
- currentVersion.length > 64 ||
53
- !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(currentVersion) ||
54
- !versionLessThan(currentVersion, descriptor.version)
55
- )
56
- throw new Error('Invalid approved update')
57
- // Electrobun installs a macOS bundle by name and Windows/Linux trees at `<identifier>/<channel>/app`.
58
- const name = platform === 'macos-arm64' ? `${appName}.app` : 'app'
59
- if (
60
- typeof target !== 'string' ||
61
- !isAbsolute(target) ||
62
- resolve(target) !== target ||
63
- basename(target) !== name
64
- )
65
- throw new Error('Invalid update target')
66
- return Object.freeze({
67
- target,
68
- appName,
69
- platform,
70
- renderer,
71
- currentVersion,
72
- version: descriptor.version,
73
- archiveSha256: descriptor.asset.sha256,
74
- })
75
- }
@@ -1,87 +0,0 @@
1
- import { constants, writeFileSync } from 'node:fs'
2
- import { lstat, open, writeFile } from 'node:fs/promises'
3
- import { isAbsolute, join, resolve } from 'node:path'
4
- import { launchInstalledApp } from './update-launch'
5
- import { waitForUpdateProcesses } from './update-process-fence'
6
- import { swapUpdateTree, updateStagingFor } from './update-swap'
7
- import type { InstallerPlatform } from '../installer/installer-layout'
8
-
9
- /** Everything the post-exit helper needs, written by the app into its private staging directory. */
10
- export type UpdateHelperRequest = Readonly<{
11
- schema: 1
12
- target: string
13
- platform: InstallerPlatform
14
- version: string
15
- processes: readonly Readonly<{ pid: number; executable: string }>[]
16
- processTimeoutMs: number
17
- }>
18
-
19
- /** Validate a helper request's shape. */
20
- export function parseUpdateHelperRequest(value: unknown): UpdateHelperRequest {
21
- const data = value as Record<string, unknown>
22
- if (
23
- typeof value !== 'object' ||
24
- value === null ||
25
- Array.isArray(value) ||
26
- data.schema !== 1 ||
27
- typeof data.target !== 'string' ||
28
- !isAbsolute(data.target) ||
29
- resolve(data.target) !== data.target ||
30
- !['macos-arm64', 'windows-x64', 'linux-x64'].includes(data.platform as string) ||
31
- typeof data.version !== 'string' ||
32
- !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(data.version) ||
33
- !Array.isArray(data.processes) ||
34
- !Number.isSafeInteger(data.processTimeoutMs) ||
35
- (data.processTimeoutMs as number) < 1 ||
36
- (data.processTimeoutMs as number) > 120000
37
- )
38
- throw new Error('Invalid update helper request')
39
- return Object.freeze(data as UpdateHelperRequest)
40
- }
41
-
42
- async function readRequest(staging: string): Promise<UpdateHelperRequest> {
43
- const path = join(staging, 'request.json'),
44
- info = await lstat(path)
45
- if (!info.isFile() || info.size < 1 || info.size > 65536)
46
- throw new Error('Invalid update helper request')
47
- const file = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0))
48
- try {
49
- return parseUpdateHelperRequest(JSON.parse(await file.readFile('utf8')))
50
- } finally {
51
- await file.close()
52
- }
53
- }
54
-
55
- /**
56
- * The post-exit helper: wait for the app's processes to exit, swap in the
57
- * staged candidate, record the new version and relaunch the app. Run from a
58
- * copy outside the install tree; `armUpdateHelper` prepares that copy.
59
- */
60
- export async function runUpdateHelper(options: {
61
- staging: string
62
- env?: Record<string, string | undefined>
63
- }): Promise<'updated' | 'failed'> {
64
- const request = await readRequest(options.staging)
65
- if (updateStagingFor(request.target) !== options.staging)
66
- throw new Error('Update helper request does not match its staging directory')
67
- await waitForUpdateProcesses({
68
- processes: request.processes,
69
- timeoutMs: request.processTimeoutMs,
70
- // The app waits for this marker before it quits, so the fence sees it alive.
71
- onVerified: () =>
72
- writeFileSync(join(options.staging, 'helper-armed'), String(process.pid), {
73
- flag: 'wx',
74
- mode: 0o600,
75
- }),
76
- })
77
- let outcome: 'updated' | 'failed' = 'failed'
78
- try {
79
- await swapUpdateTree({ target: request.target, staging: options.staging })
80
- await writeFile(join(options.staging, 'updated'), request.version, { mode: 0o600 })
81
- outcome = 'updated'
82
- } catch {
83
- /* Relaunch the unchanged install. */
84
- }
85
- await launchInstalledApp(request.platform, request.target, options.env)
86
- return outcome
87
- }