@air-jam/devtools 0.0.0-stage → 1.0.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +112 -2
- package/dist/chunk-2O67AXCU.js +470 -0
- package/dist/chunk-2O67AXCU.js.map +1 -0
- package/dist/chunk-AO3ZDXF6.js +142 -0
- package/dist/chunk-AO3ZDXF6.js.map +1 -0
- package/dist/chunk-ART5TEYT.js +472 -0
- package/dist/chunk-ART5TEYT.js.map +1 -0
- package/dist/chunk-ASC2CK2R.js +77 -0
- package/dist/chunk-ASC2CK2R.js.map +1 -0
- package/dist/chunk-E3UZZGAV.js +50 -0
- package/dist/chunk-E3UZZGAV.js.map +1 -0
- package/dist/chunk-EJTE7UKX.js +64 -0
- package/dist/chunk-EJTE7UKX.js.map +1 -0
- package/dist/chunk-ESFKNN75.js +110 -0
- package/dist/chunk-ESFKNN75.js.map +1 -0
- package/dist/chunk-EU7A6PXW.js +1339 -0
- package/dist/chunk-EU7A6PXW.js.map +1 -0
- package/dist/chunk-FN7E6EA7.js +549 -0
- package/dist/chunk-FN7E6EA7.js.map +1 -0
- package/dist/chunk-GDFAWHGA.js +190 -0
- package/dist/chunk-GDFAWHGA.js.map +1 -0
- package/dist/chunk-HZUGBH4Y.js +347 -0
- package/dist/chunk-HZUGBH4Y.js.map +1 -0
- package/dist/chunk-ITKAOEGX.js +93 -0
- package/dist/chunk-ITKAOEGX.js.map +1 -0
- package/dist/chunk-JBCUTWRI.js +897 -0
- package/dist/chunk-JBCUTWRI.js.map +1 -0
- package/dist/chunk-JSI5S4WP.js +1174 -0
- package/dist/chunk-JSI5S4WP.js.map +1 -0
- package/dist/chunk-L4D675BG.js +97 -0
- package/dist/chunk-L4D675BG.js.map +1 -0
- package/dist/chunk-M6CJ7GQC.js +133 -0
- package/dist/chunk-M6CJ7GQC.js.map +1 -0
- package/dist/chunk-MEIMOSZC.js +749 -0
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/chunk-O3XG3FNL.js +1014 -0
- package/dist/chunk-O3XG3FNL.js.map +1 -0
- package/dist/chunk-OM6SCJ7H.js +18 -0
- package/dist/chunk-OM6SCJ7H.js.map +1 -0
- package/dist/chunk-PKD4WVX5.js +63 -0
- package/dist/chunk-PKD4WVX5.js.map +1 -0
- package/dist/chunk-PMBLXGFM.js +3384 -0
- package/dist/chunk-PMBLXGFM.js.map +1 -0
- package/dist/chunk-PMNE5GIN.js +279 -0
- package/dist/chunk-PMNE5GIN.js.map +1 -0
- package/dist/chunk-QAWI64VR.js +148 -0
- package/dist/chunk-QAWI64VR.js.map +1 -0
- package/dist/chunk-QGADSPHZ.js +449 -0
- package/dist/chunk-QGADSPHZ.js.map +1 -0
- package/dist/chunk-SPYN66UV.js +338 -0
- package/dist/chunk-SPYN66UV.js.map +1 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.js +10 -0
- package/dist/context.js.map +1 -0
- package/dist/controller.d.ts +67 -0
- package/dist/controller.js +40 -0
- package/dist/controller.js.map +1 -0
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dependencies.js.map +1 -0
- package/dist/dev.d.ts +21 -0
- package/dist/dev.js +19 -0
- package/dist/dev.js.map +1 -0
- package/dist/game-builds.d.ts +200 -0
- package/dist/game-builds.js +16 -0
- package/dist/game-builds.js.map +1 -0
- package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
- package/dist/game-runs.d.ts +1452 -0
- package/dist/game-runs.js +76 -0
- package/dist/game-runs.js.map +1 -0
- package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
- package/dist/game-session-broker.d.ts +4 -0
- package/dist/game-session-broker.js +40 -0
- package/dist/game-session-broker.js.map +1 -0
- package/dist/game-session.d.ts +3934 -0
- package/dist/game-session.js +195 -0
- package/dist/game-session.js.map +1 -0
- package/dist/game-settings.d.ts +16 -0
- package/dist/game-settings.js +237 -0
- package/dist/game-settings.js.map +1 -0
- package/dist/games.d.ts +28 -0
- package/dist/games.js +16 -0
- package/dist/games.js.map +1 -0
- package/dist/harness/visual.d.ts +204 -0
- package/dist/harness/visual.js +46 -0
- package/dist/harness/visual.js.map +1 -0
- package/dist/logs.d.ts +15 -0
- package/dist/logs.js +57 -0
- package/dist/logs.js.map +1 -0
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.d.ts +63 -0
- package/dist/mcp-config.js +191 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/platform-auth.d.ts +9 -0
- package/dist/platform-auth.js +45 -0
- package/dist/platform-auth.js.map +1 -0
- package/dist/platform-game-analytics.d.ts +51 -0
- package/dist/platform-game-analytics.js +49 -0
- package/dist/platform-game-analytics.js.map +1 -0
- package/dist/platform-game-app-id.d.ts +46 -0
- package/dist/platform-game-app-id.js +93 -0
- package/dist/platform-game-app-id.js.map +1 -0
- package/dist/platform-game-media.d.ts +347 -0
- package/dist/platform-game-media.js +168 -0
- package/dist/platform-game-media.js.map +1 -0
- package/dist/platform-games.d.ts +87 -0
- package/dist/platform-games.js +183 -0
- package/dist/platform-games.js.map +1 -0
- package/dist/quality.d.ts +16 -0
- package/dist/quality.js +62 -0
- package/dist/quality.js.map +1 -0
- package/dist/release.d.ts +1304 -0
- package/dist/release.js +34 -0
- package/dist/release.js.map +1 -0
- package/dist/rooms-check.d.ts +90 -0
- package/dist/rooms-check.js +717 -0
- package/dist/rooms-check.js.map +1 -0
- package/dist/source-tree-contract.d.ts +16 -0
- package/dist/source-tree-contract.js +13 -0
- package/dist/source-tree-contract.js.map +1 -0
- package/dist/testing.d.ts +464 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/dist/tooling/describe-game.d.ts +2 -0
- package/dist/tooling/describe-game.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -0
- package/dist/tooling/game-session-broker.d.ts +2 -0
- package/dist/tooling/game-session-broker.js +28 -0
- package/dist/tooling/game-session-broker.js.map +1 -0
- package/dist/tooling/hold-runtime-host.d.ts +2 -0
- package/dist/tooling/hold-runtime-host.js +931 -0
- package/dist/tooling/hold-runtime-host.js.map +1 -0
- package/dist/tooling/list-visual-scenarios.d.ts +2 -0
- package/dist/tooling/list-visual-scenarios.js +25 -0
- package/dist/tooling/list-visual-scenarios.js.map +1 -0
- package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
- package/dist/tooling/managed-dev-supervisor.js +51 -0
- package/dist/tooling/managed-dev-supervisor.js.map +1 -0
- package/dist/tooling/process-scope-bootstrap.mjs +24 -0
- package/dist/tooling/process-scope-guard.d.ts +2 -0
- package/dist/tooling/process-scope-guard.js +388 -0
- package/dist/tooling/process-scope-guard.js.map +1 -0
- package/dist/tooling/process-scope-windows.ps1 +148 -0
- package/dist/tooling/rooms-check-device.d.ts +2 -0
- package/dist/tooling/rooms-check-device.js +498 -0
- package/dist/tooling/rooms-check-device.js.map +1 -0
- package/dist/tooling/run-headless-room.d.ts +2 -0
- package/dist/tooling/run-headless-room.js +287 -0
- package/dist/tooling/run-headless-room.js.map +1 -0
- package/dist/tooling/run-test-profile.d.ts +2 -0
- package/dist/tooling/run-test-profile.js +181 -0
- package/dist/tooling/run-test-profile.js.map +1 -0
- package/dist/tooling/run-visual-capture.d.ts +2 -0
- package/dist/tooling/run-visual-capture.js +203 -0
- package/dist/tooling/run-visual-capture.js.map +1 -0
- package/dist/tooling/seal-game-build.d.ts +2 -0
- package/dist/tooling/seal-game-build.js +120 -0
- package/dist/tooling/seal-game-build.js.map +1 -0
- package/dist/types-CdYrgrG_.d.ts +1036 -0
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +21 -0
- package/dist/visual.js +219 -0
- package/dist/visual.js.map +1 -0
- package/package.json +150 -3
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/commands.ts +40 -0
- package/src/context.ts +218 -0
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +1526 -0
- package/src/current-room-host.ts +166 -0
- package/src/decision-provider.ts +102 -0
- package/src/dependencies.ts +176 -0
- package/src/dependency-install-contract.ts +12 -0
- package/src/dev.ts +995 -0
- package/src/fs-utils.ts +93 -0
- package/src/game-action-observation.ts +106 -0
- package/src/game-build-protocol.ts +72 -0
- package/src/game-build.ts +483 -0
- package/src/game-run-owner.ts +2358 -0
- package/src/game-run-protocol.ts +448 -0
- package/src/game-run-record.ts +92 -0
- package/src/game-run-replay.ts +95 -0
- package/src/game-run-watch.ts +155 -0
- package/src/game-session-broker.ts +793 -0
- package/src/game-session-operations.ts +61 -0
- package/src/game-session-protocol.ts +180 -0
- package/src/game-session-runtime.ts +861 -0
- package/src/game-session.ts +206 -0
- package/src/game-settings.ts +295 -0
- package/src/games.ts +262 -0
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/prefab-contract.ts +29 -0
- package/src/harness/visual/prefab-runner.ts +178 -0
- package/src/harness/visual/runner.ts +549 -0
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +8 -0
- package/src/harness/visual/scenario-helpers.ts +67 -0
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +400 -0
- package/src/harness/visual/types.ts +184 -0
- package/src/harness/visual.ts +7 -0
- package/src/headless-room-protocol.ts +112 -0
- package/src/headless-room.ts +222 -0
- package/src/helper-channel.ts +229 -0
- package/src/helper-scripts.ts +69 -0
- package/src/installed-dependencies.ts +74 -0
- package/src/logs.ts +67 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/mcp-config.ts +262 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +594 -0
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-game-media.ts +209 -0
- package/src/platform-games.ts +217 -0
- package/src/policy-artifact-contract.ts +52 -0
- package/src/policy-artifacts.ts +134 -0
- package/src/process-scope-admission.ts +50 -0
- package/src/process-scope-protocol.ts +66 -0
- package/src/process-scope.ts +327 -0
- package/src/quality.ts +82 -0
- package/src/release.ts +1683 -0
- package/src/rooms-check-fleet.ts +194 -0
- package/src/rooms-check-link.ts +138 -0
- package/src/rooms-check-protocol.ts +244 -0
- package/src/rooms-check.ts +797 -0
- package/src/runtime-owner-protocol.ts +218 -0
- package/src/source-tree-contract.ts +70 -0
- package/src/source-tree.ts +84 -0
- package/src/test-profile-process.ts +153 -0
- package/src/test-profile-protocol.ts +116 -0
- package/src/testing.ts +430 -0
- package/src/tooling/declaration-hook.ts +52 -0
- package/src/tooling/describe-game.ts +49 -0
- package/src/tooling/game-session-broker.ts +7 -0
- package/src/tooling/hold-runtime-host.ts +441 -0
- package/src/tooling/list-visual-scenarios.ts +21 -0
- package/src/tooling/load-game.ts +79 -0
- package/src/tooling/managed-dev-supervisor.ts +71 -0
- package/src/tooling/process-scope-bootstrap.mjs +24 -0
- package/src/tooling/process-scope-guard.ts +213 -0
- package/src/tooling/process-scope-windows.ps1 +148 -0
- package/src/tooling/rooms-check-device.ts +493 -0
- package/src/tooling/run-headless-room.ts +326 -0
- package/src/tooling/run-test-profile.ts +190 -0
- package/src/tooling/run-visual-capture.ts +231 -0
- package/src/tooling/runtime-owner-actions.ts +65 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +11 -0
- package/src/types.ts +928 -0
- package/src/visual.ts +296 -0
- package/src/windows-process-scopes.ts +189 -0
- package/src/workspace-contract.ts +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Air Jam contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,113 @@
|
|
|
1
|
-
|
|
1
|
+
> **Prerelease `1.0.0-beta.1`** from Air Jam's `beta` channel. It is not stable and may change or break between prereleases; install `@latest` for the stable release.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# Air Jam Devtools
|
|
4
|
+
|
|
5
|
+
The Node authoring and evaluation toolchain shared by Air Jam CLI, MCP and
|
|
6
|
+
Studio consumers. Games use `@air-jam/sdk`; tools use the explicit devtools
|
|
7
|
+
module that owns their operation. There is no catch-all root import.
|
|
8
|
+
|
|
9
|
+
## Entry points
|
|
10
|
+
|
|
11
|
+
| Import suffix | Responsibility |
|
|
12
|
+
| --------------------- | ----------------------------------------------------------------- |
|
|
13
|
+
| `context` | Discover and inspect a game or declared workspace |
|
|
14
|
+
| `games` | Inspect games and their available capabilities |
|
|
15
|
+
| `dev` | Start, inspect, reset and stop managed development |
|
|
16
|
+
| `logs` | Read the unified development log stream |
|
|
17
|
+
| `controller` | Connect virtual controllers, send input and inspect runtime state |
|
|
18
|
+
| `agent` | Inspect semantic game contracts and invoke actions |
|
|
19
|
+
| `game-session` | Own a complete semantic playtest session |
|
|
20
|
+
| `game-session-broker` | Broker sessions for tool hosts |
|
|
21
|
+
| `visual` | List scenarios and capture game visuals |
|
|
22
|
+
| `harness/visual` | Define and run visual or prefab capture harnesses |
|
|
23
|
+
| `quality` | Run project quality gates and complete evaluations |
|
|
24
|
+
| `mcp-config` | Inspect, write and repair project MCP configuration |
|
|
25
|
+
| `platform-auth` | Authenticate optional hosted operations |
|
|
26
|
+
| `platform-games` | Manage optional hosted game metadata |
|
|
27
|
+
| `platform-game-media` | Manage optional hosted game media |
|
|
28
|
+
| `release` | Prepare and operate optional hosted releases |
|
|
29
|
+
| `rooms-check` | Run the room acceptance scenarios against any rooms origin |
|
|
30
|
+
|
|
31
|
+
Functions and their public option/result types share an entry point:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { startDev, type StartDevOptions } from "@air-jam/devtools/dev";
|
|
35
|
+
|
|
36
|
+
const options: StartDevOptions = { cwd: process.cwd(), mode: "standalone-dev" };
|
|
37
|
+
const development = await startDev(options);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
CLI and MCP are the normal human/agent front doors. Import these modules when
|
|
41
|
+
embedding the same operations in another tool host. Packaged executable helpers
|
|
42
|
+
are implementation details used by that version of devtools, not independent
|
|
43
|
+
public entry points.
|
|
44
|
+
|
|
45
|
+
## Workspace and package contracts
|
|
46
|
+
|
|
47
|
+
Ordinary game projects need no workspace declaration. A workspace owns its
|
|
48
|
+
entrypoint and supported modes through the
|
|
49
|
+
[workspace runtime contract](../../docs/contracts/workspace-runtime-contract.md),
|
|
50
|
+
not through a guessed repository layout or a root SDK dependency.
|
|
51
|
+
|
|
52
|
+
All six Air Jam packages release together. Upgrade the coordinated family
|
|
53
|
+
together; documented module exports and their types follow the
|
|
54
|
+
[public support contract](../../docs/contracts/public-package-support-contract.md).
|
|
55
|
+
Hosted clients are optional: local development, inspection and evaluation do
|
|
56
|
+
not require an Air Jam platform account.
|
|
57
|
+
|
|
58
|
+
## Dependency installation
|
|
59
|
+
|
|
60
|
+
`installDependencies` from `@air-jam/devtools/dependencies` installs with frozen
|
|
61
|
+
lockfiles and independent package copies by default. Its `packageImportMethod`
|
|
62
|
+
option accepts `"copy"` (default) or `"clone-or-copy"`, passed directly to pnpm.
|
|
63
|
+
Use `clone-or-copy` for copy-on-write clones on supporting filesystems such as
|
|
64
|
+
APFS, with pnpm copying elsewhere:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { installDependencies } from "@air-jam/devtools/dependencies";
|
|
68
|
+
|
|
69
|
+
await installDependencies(projectDirectory, {
|
|
70
|
+
packageImportMethod: "clone-or-copy",
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The returned observation reports actual import methods (`copy` or `clone`).
|
|
75
|
+
Hardlinks remain rejected because workspace writes must not mutate the store.
|
|
76
|
+
|
|
77
|
+
## Owned process lifetime
|
|
78
|
+
|
|
79
|
+
Owned runtimes and policy/evaluator helpers enter a process scope before loading
|
|
80
|
+
game profiles or opening browser pages. One guardian per tool process owns their
|
|
81
|
+
cleanup. POSIX uses marked process groups, inherited ownership and creation
|
|
82
|
+
identities; its recovery records live under `.airjam/devtools/process-scopes`.
|
|
83
|
+
Windows uses verified kernel jobs with kill-on-close and no breakaway. It requires
|
|
84
|
+
PowerShell 7.4+ (`pwsh`), which most Windows desktops do not include by default;
|
|
85
|
+
install it with `winget install Microsoft.PowerShell`. Its packaged job helper
|
|
86
|
+
compiles in memory. Blocked initialization fails admission without weakening the
|
|
87
|
+
machine's policy; unrelated commands do not require the guardian.
|
|
88
|
+
Sanitized Node helper environments preserve the parent's `ELECTRON_RUN_AS_NODE`
|
|
89
|
+
when set, so an embedded Electron executable continues running as Node.
|
|
90
|
+
Set `NODE_DEBUG=airjam-process-scope` to inspect Windows guardian startup phases.
|
|
91
|
+
Failures include bounded startup diagnostics without requiring debug logging.
|
|
92
|
+
|
|
93
|
+
Guardian preparation has a separate ceiling: 30 seconds on Windows, 10 seconds
|
|
94
|
+
on POSIX. Four fresh Windows runner measurements took 3.65–4.38 seconds; an
|
|
95
|
+
earlier cold compilation was cut off at 7.5 seconds, so its full duration is
|
|
96
|
+
unknown. The Windows ceiling leaves room for first-use compilation rather than
|
|
97
|
+
changing gameplay or input deadlines. Run cancellation interrupts its wait;
|
|
98
|
+
preparation remains part of end-to-end operation time. One monotonic deadline
|
|
99
|
+
owns readiness across the broker and helper, with a margin for reporting errors.
|
|
100
|
+
`NODE_DEBUG=airjam-process-scope` records preparation duration and helper stages.
|
|
101
|
+
|
|
102
|
+
Maintainers can measure first-use startup on fresh Windows runners with
|
|
103
|
+
`gh workflow run public-install-matrix.yml --ref <branch> -f windows_startup_diagnostics=true`.
|
|
104
|
+
That diagnostic uses a 120-second measurement ceiling, then checks normal process
|
|
105
|
+
ownership and policy deadlines. The measured probe alone does not qualify normal
|
|
106
|
+
admission; the full package matrix remains the delivery gate.
|
|
107
|
+
|
|
108
|
+
Closing a direct child is insufficient. Stop and unexpected root exit close the
|
|
109
|
+
scope and require a bounded cleanup receipt. A lost broker triggers the same
|
|
110
|
+
cleanup through the guardian. Unconfirmed cleanup refuses further admission;
|
|
111
|
+
Studio can preserve the draft and recycle game compute. Other scopes remain
|
|
112
|
+
independent. These mechanisms manage trusted process lifetimes; the container or
|
|
113
|
+
VM remains the boundary for hostile game code and filesystem access.
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
// src/platform-auth.ts
|
|
2
|
+
import {
|
|
3
|
+
platformMachineApiErrorSchema,
|
|
4
|
+
platformMachineDevicePollResultSchema,
|
|
5
|
+
platformMachineDeviceStartResultSchema,
|
|
6
|
+
platformMachineLogoutResultSchema,
|
|
7
|
+
platformMachineMeResultSchema,
|
|
8
|
+
platformMachineProfileInputSchema,
|
|
9
|
+
platformMachineRevokeSessionInputSchema,
|
|
10
|
+
platformMachineSessionSchema,
|
|
11
|
+
platformMachineSessionsResultSchema,
|
|
12
|
+
platformMachineUserSchema
|
|
13
|
+
} from "@air-jam/sdk/platform-machine";
|
|
14
|
+
import { randomUUID } from "crypto";
|
|
15
|
+
import {
|
|
16
|
+
chmod,
|
|
17
|
+
mkdir,
|
|
18
|
+
readFile,
|
|
19
|
+
rename,
|
|
20
|
+
rm,
|
|
21
|
+
writeFile
|
|
22
|
+
} from "fs/promises";
|
|
23
|
+
import { isIP } from "net";
|
|
24
|
+
import os from "os";
|
|
25
|
+
import path from "path";
|
|
26
|
+
import lockfile from "proper-lockfile";
|
|
27
|
+
import { z } from "zod";
|
|
28
|
+
var LOCAL_PLATFORM_FALLBACK = "http://localhost:3000";
|
|
29
|
+
var resolveAirJamStateDirectory = () => {
|
|
30
|
+
const configured = process.env.AIRJAM_STATE_DIR?.trim();
|
|
31
|
+
if (!configured) return path.join(os.homedir(), ".airjam");
|
|
32
|
+
if (!path.isAbsolute(configured)) {
|
|
33
|
+
throw new Error("AIRJAM_STATE_DIR must be an absolute path.");
|
|
34
|
+
}
|
|
35
|
+
return path.normalize(configured);
|
|
36
|
+
};
|
|
37
|
+
var resolvePlatformAuthDirectory = () => path.join(resolveAirJamStateDirectory(), "auth");
|
|
38
|
+
var resolvePlatformAuthFile = () => path.join(resolvePlatformAuthDirectory(), "platform-session.json");
|
|
39
|
+
var storedPlatformSessionFields = z.object({
|
|
40
|
+
platformBaseUrl: z.string().url(),
|
|
41
|
+
clientName: z.string().nullable(),
|
|
42
|
+
storedAt: z.string().min(1),
|
|
43
|
+
user: platformMachineUserSchema
|
|
44
|
+
});
|
|
45
|
+
var storedPlatformSessionSchema = storedPlatformSessionFields.extend({
|
|
46
|
+
version: z.literal(2),
|
|
47
|
+
session: platformMachineSessionSchema
|
|
48
|
+
});
|
|
49
|
+
var legacyStoredPlatformSessionSchema = storedPlatformSessionFields.extend({
|
|
50
|
+
version: z.literal(1),
|
|
51
|
+
session: platformMachineSessionSchema.omit({
|
|
52
|
+
refreshToken: true,
|
|
53
|
+
refreshExpiresAt: true
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
var readableStoredPlatformSessionSchema = z.discriminatedUnion("version", [
|
|
57
|
+
storedPlatformSessionSchema,
|
|
58
|
+
legacyStoredPlatformSessionSchema
|
|
59
|
+
]);
|
|
60
|
+
var withPlatformSessionLock = async (operation) => {
|
|
61
|
+
await mkdir(resolvePlatformAuthDirectory(), { recursive: true, mode: 448 });
|
|
62
|
+
const release = await lockfile.lock(resolvePlatformAuthFile(), {
|
|
63
|
+
realpath: false,
|
|
64
|
+
retries: { retries: 10, minTimeout: 50, maxTimeout: 1e3 }
|
|
65
|
+
});
|
|
66
|
+
try {
|
|
67
|
+
return await operation();
|
|
68
|
+
} finally {
|
|
69
|
+
await release();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var AirJamPlatformApiError = class extends Error {
|
|
73
|
+
code;
|
|
74
|
+
status;
|
|
75
|
+
details;
|
|
76
|
+
retryAfterSeconds;
|
|
77
|
+
constructor({
|
|
78
|
+
code,
|
|
79
|
+
message,
|
|
80
|
+
status,
|
|
81
|
+
details,
|
|
82
|
+
retryAfterSeconds = null
|
|
83
|
+
}) {
|
|
84
|
+
super(message);
|
|
85
|
+
this.name = "AirJamPlatformApiError";
|
|
86
|
+
this.code = code;
|
|
87
|
+
this.status = status;
|
|
88
|
+
this.details = details;
|
|
89
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var AirJamStoredPlatformSessionError = class extends Error {
|
|
93
|
+
storagePath;
|
|
94
|
+
constructor(storagePath, cause) {
|
|
95
|
+
super(`The stored Air Jam platform session is unreadable: ${storagePath}`, {
|
|
96
|
+
cause
|
|
97
|
+
});
|
|
98
|
+
this.name = "AirJamStoredPlatformSessionError";
|
|
99
|
+
this.storagePath = storagePath;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var parsePlatformUrl = (rawUrl) => {
|
|
103
|
+
const trimmed = rawUrl.trim();
|
|
104
|
+
let url;
|
|
105
|
+
try {
|
|
106
|
+
if (!trimmed) throw new Error("Empty URL");
|
|
107
|
+
const hasScheme = /^[a-z][a-z\d+.-]*:/iu.test(trimmed);
|
|
108
|
+
const hasHostPort = /^[^/?#]+:\d+(?:[/?#]|$)/u.test(trimmed);
|
|
109
|
+
if (hasScheme && !hasHostPort && !/^[a-z][a-z\d+.-]*:\/\//iu.test(trimmed)) {
|
|
110
|
+
throw new Error("Invalid URL scheme");
|
|
111
|
+
}
|
|
112
|
+
url = new URL(hasScheme && !hasHostPort ? trimmed : `https://${trimmed}`);
|
|
113
|
+
} catch {
|
|
114
|
+
throw new Error("Invalid Air Jam platform URL.");
|
|
115
|
+
}
|
|
116
|
+
const loopback = url.hostname === "localhost" || url.hostname === "[::1]" || isIP(url.hostname) === 4 && url.hostname.startsWith("127.");
|
|
117
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback) || url.username || url.password) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
"Air Jam platform URLs require HTTPS, except HTTP on loopback, and must not contain credentials."
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return url;
|
|
123
|
+
};
|
|
124
|
+
var resolvePlatformBaseUrl = (value = process.env.AIRJAM_PLATFORM_URL) => {
|
|
125
|
+
const candidate = value ?? process.env.AIR_JAM_PLATFORM_URL ?? process.env.NEXT_PUBLIC_AIR_JAM_PUBLIC_HOST ?? process.env.NEXT_PUBLIC_APP_URL ?? LOCAL_PLATFORM_FALLBACK;
|
|
126
|
+
return parsePlatformUrl(candidate).toString().replace(/\/$/, "");
|
|
127
|
+
};
|
|
128
|
+
var sleep = async (durationMs) => new Promise((resolve) => setTimeout(resolve, durationMs));
|
|
129
|
+
var requestPlatformMachineApi = async ({
|
|
130
|
+
baseUrl,
|
|
131
|
+
pathname,
|
|
132
|
+
method = "GET",
|
|
133
|
+
body,
|
|
134
|
+
token,
|
|
135
|
+
schema
|
|
136
|
+
}) => {
|
|
137
|
+
const platformUrl = parsePlatformUrl(baseUrl);
|
|
138
|
+
const requestUrl = new URL(pathname, platformUrl);
|
|
139
|
+
if (requestUrl.origin !== platformUrl.origin || requestUrl.username || requestUrl.password) {
|
|
140
|
+
throw new Error(
|
|
141
|
+
"Platform agent API requests must stay on the platform origin."
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
const response = await fetch(requestUrl, {
|
|
145
|
+
method,
|
|
146
|
+
// Redirects can replay device codes or credentials, even on the same origin.
|
|
147
|
+
redirect: "error",
|
|
148
|
+
headers: {
|
|
149
|
+
...body === void 0 ? {} : { "content-type": "application/json" },
|
|
150
|
+
...token ? { authorization: `Bearer ${token}` } : {}
|
|
151
|
+
},
|
|
152
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
153
|
+
});
|
|
154
|
+
const payload = await response.json().catch(() => null);
|
|
155
|
+
if (!response.ok) {
|
|
156
|
+
const parsedError = platformMachineApiErrorSchema.safeParse(payload);
|
|
157
|
+
if (parsedError.success) {
|
|
158
|
+
throw new AirJamPlatformApiError({
|
|
159
|
+
code: parsedError.data.error,
|
|
160
|
+
message: parsedError.data.error === "invalid_token" ? `${parsedError.data.message} Run airjam auth login to sign in again.` : parsedError.data.message,
|
|
161
|
+
status: response.status,
|
|
162
|
+
details: parsedError.data.details,
|
|
163
|
+
retryAfterSeconds: parsedError.data.retryAfterSeconds
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
throw new AirJamPlatformApiError({
|
|
167
|
+
code: "invalid_request",
|
|
168
|
+
message: `Platform agent API request failed: ${response.status}`,
|
|
169
|
+
status: response.status
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return schema.parse(payload);
|
|
173
|
+
};
|
|
174
|
+
var readStoredPlatformMachineSession = async () => {
|
|
175
|
+
const storagePath = resolvePlatformAuthFile();
|
|
176
|
+
let source;
|
|
177
|
+
try {
|
|
178
|
+
source = await readFile(storagePath, "utf8");
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error?.code === "ENOENT") {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
return readableStoredPlatformSessionSchema.parse(
|
|
187
|
+
JSON.parse(source)
|
|
188
|
+
);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
throw new AirJamStoredPlatformSessionError(storagePath, error);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
var writeStoredPlatformMachineSession = async (value) => {
|
|
194
|
+
const authDirectory = resolvePlatformAuthDirectory();
|
|
195
|
+
const storagePath = resolvePlatformAuthFile();
|
|
196
|
+
const temporaryPath = `${storagePath}.tmp-${process.pid}-${randomUUID()}`;
|
|
197
|
+
await mkdir(authDirectory, { recursive: true, mode: 448 });
|
|
198
|
+
await chmod(authDirectory, 448);
|
|
199
|
+
try {
|
|
200
|
+
await writeFile(
|
|
201
|
+
temporaryPath,
|
|
202
|
+
`${JSON.stringify(storedPlatformSessionSchema.parse(value), null, 2)}
|
|
203
|
+
`,
|
|
204
|
+
{ encoding: "utf8", flag: "wx", mode: 384 }
|
|
205
|
+
);
|
|
206
|
+
await rename(temporaryPath, storagePath);
|
|
207
|
+
await chmod(storagePath, 384);
|
|
208
|
+
} finally {
|
|
209
|
+
await rm(temporaryPath, { force: true });
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
var clearStoredPlatformMachineSession = async () => {
|
|
213
|
+
await rm(resolvePlatformAuthFile(), { force: true });
|
|
214
|
+
};
|
|
215
|
+
var startPlatformDeviceAuthorization = async ({
|
|
216
|
+
platformUrl,
|
|
217
|
+
clientName
|
|
218
|
+
} = {}) => requestPlatformMachineApi({
|
|
219
|
+
baseUrl: resolvePlatformBaseUrl(platformUrl),
|
|
220
|
+
pathname: "/api/cli/auth/device/start",
|
|
221
|
+
method: "POST",
|
|
222
|
+
body: {
|
|
223
|
+
...clientName?.trim() ? { clientName: clientName.trim() } : {}
|
|
224
|
+
},
|
|
225
|
+
schema: platformMachineDeviceStartResultSchema
|
|
226
|
+
});
|
|
227
|
+
var pollPlatformDeviceAuthorization = async ({
|
|
228
|
+
platformUrl,
|
|
229
|
+
deviceCode
|
|
230
|
+
}) => requestPlatformMachineApi({
|
|
231
|
+
baseUrl: resolvePlatformBaseUrl(platformUrl),
|
|
232
|
+
pathname: "/api/cli/auth/device/poll",
|
|
233
|
+
method: "POST",
|
|
234
|
+
body: {
|
|
235
|
+
deviceCode
|
|
236
|
+
},
|
|
237
|
+
schema: platformMachineDevicePollResultSchema
|
|
238
|
+
});
|
|
239
|
+
var loginPlatformWithDeviceFlow = async ({
|
|
240
|
+
platformUrl,
|
|
241
|
+
clientName,
|
|
242
|
+
onPrompt
|
|
243
|
+
} = {}) => {
|
|
244
|
+
const baseUrl = resolvePlatformBaseUrl(platformUrl);
|
|
245
|
+
const authorization = await startPlatformDeviceAuthorization({
|
|
246
|
+
platformUrl: baseUrl,
|
|
247
|
+
clientName
|
|
248
|
+
});
|
|
249
|
+
await onPrompt?.(authorization);
|
|
250
|
+
const expiresAtMs = Date.parse(authorization.expiresAt);
|
|
251
|
+
let intervalSeconds = authorization.intervalSeconds;
|
|
252
|
+
while (Date.now() < expiresAtMs) {
|
|
253
|
+
await sleep(intervalSeconds * 1e3);
|
|
254
|
+
if (Date.now() >= expiresAtMs) break;
|
|
255
|
+
try {
|
|
256
|
+
const authenticated = await pollPlatformDeviceAuthorization({
|
|
257
|
+
platformUrl: baseUrl,
|
|
258
|
+
deviceCode: authorization.deviceCode
|
|
259
|
+
});
|
|
260
|
+
if (parsePlatformUrl(authenticated.platformBaseUrl).origin !== parsePlatformUrl(baseUrl).origin) {
|
|
261
|
+
throw new Error(
|
|
262
|
+
"The login response does not match the requested platform origin."
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
const storedSession = {
|
|
266
|
+
version: 2,
|
|
267
|
+
platformBaseUrl: baseUrl,
|
|
268
|
+
clientName: clientName?.trim() || null,
|
|
269
|
+
storedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
270
|
+
user: authenticated.user,
|
|
271
|
+
session: authenticated.session
|
|
272
|
+
};
|
|
273
|
+
await withPlatformSessionLock(
|
|
274
|
+
() => writeStoredPlatformMachineSession(storedSession)
|
|
275
|
+
);
|
|
276
|
+
return {
|
|
277
|
+
authorization,
|
|
278
|
+
authenticated,
|
|
279
|
+
storedSession
|
|
280
|
+
};
|
|
281
|
+
} catch (error) {
|
|
282
|
+
if (error instanceof AirJamPlatformApiError) {
|
|
283
|
+
if (error.code === "slow_down") {
|
|
284
|
+
intervalSeconds += 5;
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (error.code === "authorization_pending") continue;
|
|
288
|
+
}
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
throw new AirJamPlatformApiError({
|
|
293
|
+
code: "expired_token",
|
|
294
|
+
message: "The Air Jam CLI login expired before it was approved.",
|
|
295
|
+
status: 410
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
var resolvePlatformMachineAuthUnlocked = async ({
|
|
299
|
+
platformUrl,
|
|
300
|
+
token
|
|
301
|
+
}) => {
|
|
302
|
+
if (token?.trim()) {
|
|
303
|
+
return {
|
|
304
|
+
baseUrl: resolvePlatformBaseUrl(platformUrl),
|
|
305
|
+
token: token.trim()
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
let stored = await readStoredPlatformMachineSession();
|
|
309
|
+
if (!stored) {
|
|
310
|
+
throw new Error(
|
|
311
|
+
"No stored Air Jam platform session was found. Run airjam auth login to sign in."
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
const baseUrl = resolvePlatformBaseUrl(platformUrl ?? stored.platformBaseUrl);
|
|
315
|
+
if (parsePlatformUrl(baseUrl).origin !== parsePlatformUrl(stored.platformBaseUrl).origin) {
|
|
316
|
+
throw new Error(
|
|
317
|
+
"The stored Air Jam session belongs to a different platform origin. Log in to that platform or supply an explicit token."
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
if (stored.version === 1 || Date.parse(stored.session.expiresAt) <= Date.now() + 3e4) {
|
|
321
|
+
const authenticated = await requestPlatformMachineApi({
|
|
322
|
+
baseUrl,
|
|
323
|
+
pathname: "/api/cli/auth/refresh",
|
|
324
|
+
method: "POST",
|
|
325
|
+
body: {
|
|
326
|
+
refreshToken: stored.version === 1 ? stored.session.token : stored.session.refreshToken
|
|
327
|
+
},
|
|
328
|
+
schema: platformMachineDevicePollResultSchema
|
|
329
|
+
});
|
|
330
|
+
if (parsePlatformUrl(authenticated.platformBaseUrl).origin !== parsePlatformUrl(baseUrl).origin) {
|
|
331
|
+
throw new Error(
|
|
332
|
+
"The refresh response does not match the requested platform origin."
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
stored = {
|
|
336
|
+
...stored,
|
|
337
|
+
version: 2,
|
|
338
|
+
user: authenticated.user,
|
|
339
|
+
session: authenticated.session,
|
|
340
|
+
storedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
341
|
+
};
|
|
342
|
+
await writeStoredPlatformMachineSession(stored);
|
|
343
|
+
}
|
|
344
|
+
return { baseUrl, token: stored.session.token };
|
|
345
|
+
};
|
|
346
|
+
var resolvePlatformMachineAuth = async (options) => options.token?.trim() ? resolvePlatformMachineAuthUnlocked(options) : withPlatformSessionLock(
|
|
347
|
+
() => resolvePlatformMachineAuthUnlocked(options)
|
|
348
|
+
);
|
|
349
|
+
var listPlatformMachineSessions = async (options = {}) => {
|
|
350
|
+
const resolved = await resolvePlatformMachineAuth(options);
|
|
351
|
+
return requestPlatformMachineApi({
|
|
352
|
+
baseUrl: resolved.baseUrl,
|
|
353
|
+
pathname: "/api/cli/auth/sessions",
|
|
354
|
+
token: resolved.token,
|
|
355
|
+
schema: platformMachineSessionsResultSchema
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
var revokePlatformMachineSession = async (options) => {
|
|
359
|
+
const resolved = await resolvePlatformMachineAuth(options);
|
|
360
|
+
return requestPlatformMachineApi({
|
|
361
|
+
baseUrl: resolved.baseUrl,
|
|
362
|
+
pathname: "/api/cli/auth/sessions/revoke",
|
|
363
|
+
method: "POST",
|
|
364
|
+
token: resolved.token,
|
|
365
|
+
body: platformMachineRevokeSessionInputSchema.parse(options),
|
|
366
|
+
schema: platformMachineLogoutResultSchema
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
var getPlatformMachineProfile = async ({
|
|
370
|
+
platformUrl,
|
|
371
|
+
token
|
|
372
|
+
} = {}) => {
|
|
373
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
374
|
+
return requestPlatformMachineApi({
|
|
375
|
+
baseUrl: resolved.baseUrl,
|
|
376
|
+
pathname: "/api/cli/auth/me",
|
|
377
|
+
token: resolved.token,
|
|
378
|
+
schema: platformMachineMeResultSchema
|
|
379
|
+
});
|
|
380
|
+
};
|
|
381
|
+
var updatePlatformMachineProfile = async ({
|
|
382
|
+
platformUrl,
|
|
383
|
+
token,
|
|
384
|
+
displayName
|
|
385
|
+
}) => {
|
|
386
|
+
const input = platformMachineProfileInputSchema.parse({ displayName });
|
|
387
|
+
const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
|
|
388
|
+
return requestPlatformMachineApi({
|
|
389
|
+
baseUrl: resolved.baseUrl,
|
|
390
|
+
pathname: "/api/cli/auth/profile",
|
|
391
|
+
method: "POST",
|
|
392
|
+
token: resolved.token,
|
|
393
|
+
body: input,
|
|
394
|
+
schema: platformMachineUserSchema
|
|
395
|
+
});
|
|
396
|
+
};
|
|
397
|
+
var logoutPlatformMachineSession = async ({
|
|
398
|
+
platformUrl,
|
|
399
|
+
token
|
|
400
|
+
} = {}) => {
|
|
401
|
+
return withPlatformSessionLock(async () => {
|
|
402
|
+
const resolved = await resolvePlatformMachineAuthUnlocked({
|
|
403
|
+
platformUrl,
|
|
404
|
+
token
|
|
405
|
+
});
|
|
406
|
+
const result = await requestPlatformMachineApi({
|
|
407
|
+
baseUrl: resolved.baseUrl,
|
|
408
|
+
pathname: "/api/cli/auth/logout",
|
|
409
|
+
method: "POST",
|
|
410
|
+
token: resolved.token,
|
|
411
|
+
schema: platformMachineLogoutResultSchema
|
|
412
|
+
});
|
|
413
|
+
if (!token) await clearStoredPlatformMachineSession();
|
|
414
|
+
return result;
|
|
415
|
+
});
|
|
416
|
+
};
|
|
417
|
+
var getPlatformMachineAuthStatus = async () => {
|
|
418
|
+
const stored = await readStoredPlatformMachineSession();
|
|
419
|
+
if (!stored) {
|
|
420
|
+
return {
|
|
421
|
+
authenticated: false,
|
|
422
|
+
storagePath: resolvePlatformAuthFile(),
|
|
423
|
+
platformBaseUrl: null,
|
|
424
|
+
clientName: null,
|
|
425
|
+
storedAt: null,
|
|
426
|
+
user: null,
|
|
427
|
+
session: null
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
return {
|
|
431
|
+
authenticated: true,
|
|
432
|
+
storagePath: resolvePlatformAuthFile(),
|
|
433
|
+
platformBaseUrl: stored.platformBaseUrl,
|
|
434
|
+
clientName: stored.clientName,
|
|
435
|
+
storedAt: stored.storedAt,
|
|
436
|
+
user: stored.user,
|
|
437
|
+
session: {
|
|
438
|
+
id: stored.session.id,
|
|
439
|
+
expiresAt: stored.session.expiresAt,
|
|
440
|
+
refreshExpiresAt: stored.version === 1 ? stored.session.expiresAt : stored.session.refreshExpiresAt,
|
|
441
|
+
createdAt: stored.session.createdAt,
|
|
442
|
+
userAgent: stored.session.userAgent
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
var getPlatformAuthStoragePath = () => resolvePlatformAuthFile();
|
|
447
|
+
|
|
448
|
+
export {
|
|
449
|
+
resolveAirJamStateDirectory,
|
|
450
|
+
storedPlatformSessionSchema,
|
|
451
|
+
AirJamPlatformApiError,
|
|
452
|
+
AirJamStoredPlatformSessionError,
|
|
453
|
+
resolvePlatformBaseUrl,
|
|
454
|
+
requestPlatformMachineApi,
|
|
455
|
+
readStoredPlatformMachineSession,
|
|
456
|
+
writeStoredPlatformMachineSession,
|
|
457
|
+
clearStoredPlatformMachineSession,
|
|
458
|
+
startPlatformDeviceAuthorization,
|
|
459
|
+
pollPlatformDeviceAuthorization,
|
|
460
|
+
loginPlatformWithDeviceFlow,
|
|
461
|
+
resolvePlatformMachineAuth,
|
|
462
|
+
listPlatformMachineSessions,
|
|
463
|
+
revokePlatformMachineSession,
|
|
464
|
+
getPlatformMachineProfile,
|
|
465
|
+
updatePlatformMachineProfile,
|
|
466
|
+
logoutPlatformMachineSession,
|
|
467
|
+
getPlatformMachineAuthStatus,
|
|
468
|
+
getPlatformAuthStoragePath
|
|
469
|
+
};
|
|
470
|
+
//# sourceMappingURL=chunk-2O67AXCU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/platform-auth.ts"],"sourcesContent":["import {\n type PlatformMachineErrorCode,\n platformMachineApiErrorSchema,\n platformMachineDevicePollResultSchema,\n platformMachineDeviceStartResultSchema,\n platformMachineLogoutResultSchema,\n platformMachineMeResultSchema,\n platformMachineProfileInputSchema,\n platformMachineRevokeSessionInputSchema,\n platformMachineSessionSchema,\n platformMachineSessionsResultSchema,\n platformMachineUserSchema,\n} from \"@air-jam/sdk/platform-machine\";\nimport { randomUUID } from \"node:crypto\";\nimport {\n chmod,\n mkdir,\n readFile,\n rename,\n rm,\n writeFile,\n} from \"node:fs/promises\";\nimport { isIP } from \"node:net\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport lockfile from \"proper-lockfile\";\nimport { z } from \"zod\";\nimport type {\n AirJamPlatformAuthStatus,\n AirJamPlatformMachineSessionStore,\n GetPlatformMachineProfileOptions,\n LoginPlatformWithDeviceFlowOptions,\n LogoutPlatformMachineSessionOptions,\n PollPlatformDeviceAuthorizationOptions,\n StartPlatformDeviceAuthorizationOptions,\n} from \"./types.js\";\n\nexport type {\n AirJamPlatformAuthStatus,\n AirJamPlatformMachineSessionStore,\n GetPlatformMachineProfileOptions,\n LoginPlatformWithDeviceFlowOptions,\n LogoutPlatformMachineSessionOptions,\n PollPlatformDeviceAuthorizationOptions,\n StartPlatformDeviceAuthorizationOptions,\n} from \"./types.js\";\n\nconst LOCAL_PLATFORM_FALLBACK = \"http://localhost:3000\";\n\nexport const resolveAirJamStateDirectory = (): string => {\n const configured = process.env.AIRJAM_STATE_DIR?.trim();\n if (!configured) return path.join(os.homedir(), \".airjam\");\n if (!path.isAbsolute(configured)) {\n throw new Error(\"AIRJAM_STATE_DIR must be an absolute path.\");\n }\n return path.normalize(configured);\n};\n\nconst resolvePlatformAuthDirectory = () =>\n path.join(resolveAirJamStateDirectory(), \"auth\");\n\nconst resolvePlatformAuthFile = () =>\n path.join(resolvePlatformAuthDirectory(), \"platform-session.json\");\n\nconst storedPlatformSessionFields = z.object({\n platformBaseUrl: z.string().url(),\n clientName: z.string().nullable(),\n storedAt: z.string().min(1),\n user: platformMachineUserSchema,\n});\n\nexport const storedPlatformSessionSchema = storedPlatformSessionFields.extend({\n version: z.literal(2),\n session: platformMachineSessionSchema,\n});\n\n// Read the former credential only to exchange it through the refresh endpoint.\nconst legacyStoredPlatformSessionSchema = storedPlatformSessionFields.extend({\n version: z.literal(1),\n session: platformMachineSessionSchema.omit({\n refreshToken: true,\n refreshExpiresAt: true,\n }),\n});\n\nconst readableStoredPlatformSessionSchema = z.discriminatedUnion(\"version\", [\n storedPlatformSessionSchema,\n legacyStoredPlatformSessionSchema,\n]);\n\nconst withPlatformSessionLock = async <T>(\n operation: () => Promise<T>,\n): Promise<T> => {\n await mkdir(resolvePlatformAuthDirectory(), { recursive: true, mode: 0o700 });\n const release = await lockfile.lock(resolvePlatformAuthFile(), {\n realpath: false,\n retries: { retries: 10, minTimeout: 50, maxTimeout: 1000 },\n });\n try {\n return await operation();\n } finally {\n await release();\n }\n};\n\nexport class AirJamPlatformApiError extends Error {\n readonly code: PlatformMachineErrorCode;\n readonly status: number;\n readonly details: Record<string, unknown> | undefined;\n readonly retryAfterSeconds: number | null;\n\n constructor({\n code,\n message,\n status,\n details,\n retryAfterSeconds = null,\n }: {\n code: PlatformMachineErrorCode;\n message: string;\n status: number;\n details?: Record<string, unknown>;\n retryAfterSeconds?: number | null;\n }) {\n super(message);\n this.name = \"AirJamPlatformApiError\";\n this.code = code;\n this.status = status;\n this.details = details;\n this.retryAfterSeconds = retryAfterSeconds;\n }\n}\n\nexport class AirJamStoredPlatformSessionError extends Error {\n readonly storagePath: string;\n\n constructor(storagePath: string, cause: unknown) {\n super(`The stored Air Jam platform session is unreadable: ${storagePath}`, {\n cause,\n });\n this.name = \"AirJamStoredPlatformSessionError\";\n this.storagePath = storagePath;\n }\n}\n\nconst parsePlatformUrl = (rawUrl: string): URL => {\n const trimmed = rawUrl.trim();\n let url: URL;\n try {\n if (!trimmed) throw new Error(\"Empty URL\");\n const hasScheme = /^[a-z][a-z\\d+.-]*:/iu.test(trimmed);\n const hasHostPort = /^[^/?#]+:\\d+(?:[/?#]|$)/u.test(trimmed);\n if (\n hasScheme &&\n !hasHostPort &&\n !/^[a-z][a-z\\d+.-]*:\\/\\//iu.test(trimmed)\n ) {\n throw new Error(\"Invalid URL scheme\");\n }\n url = new URL(hasScheme && !hasHostPort ? trimmed : `https://${trimmed}`);\n } catch {\n throw new Error(\"Invalid Air Jam platform URL.\");\n }\n\n const loopback =\n url.hostname === \"localhost\" ||\n url.hostname === \"[::1]\" ||\n (isIP(url.hostname) === 4 && url.hostname.startsWith(\"127.\"));\n if (\n (url.protocol !== \"https:\" && !(url.protocol === \"http:\" && loopback)) ||\n url.username ||\n url.password\n ) {\n throw new Error(\n \"Air Jam platform URLs require HTTPS, except HTTP on loopback, and must not contain credentials.\",\n );\n }\n return url;\n};\n\nexport const resolvePlatformBaseUrl = (\n value: string | undefined = process.env.AIRJAM_PLATFORM_URL,\n): string => {\n const candidate =\n value ??\n process.env.AIR_JAM_PLATFORM_URL ??\n process.env.NEXT_PUBLIC_AIR_JAM_PUBLIC_HOST ??\n process.env.NEXT_PUBLIC_APP_URL ??\n LOCAL_PLATFORM_FALLBACK;\n\n return parsePlatformUrl(candidate).toString().replace(/\\/$/, \"\");\n};\n\nconst sleep = async (durationMs: number) =>\n new Promise((resolve) => setTimeout(resolve, durationMs));\n\nexport const requestPlatformMachineApi = async <T>({\n baseUrl,\n pathname,\n method = \"GET\",\n body,\n token,\n schema,\n}: {\n baseUrl: string;\n pathname: string;\n method?: \"GET\" | \"POST\" | \"PATCH\";\n body?: unknown;\n token?: string;\n schema: { parse: (value: unknown) => T };\n}): Promise<T> => {\n const platformUrl = parsePlatformUrl(baseUrl);\n const requestUrl = new URL(pathname, platformUrl);\n if (\n requestUrl.origin !== platformUrl.origin ||\n requestUrl.username ||\n requestUrl.password\n ) {\n throw new Error(\n \"Platform agent API requests must stay on the platform origin.\",\n );\n }\n const response = await fetch(requestUrl, {\n method,\n // Redirects can replay device codes or credentials, even on the same origin.\n redirect: \"error\",\n headers: {\n ...(body === undefined ? {} : { \"content-type\": \"application/json\" }),\n ...(token ? { authorization: `Bearer ${token}` } : {}),\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n\n const payload = (await response.json().catch(() => null)) as unknown;\n\n if (!response.ok) {\n const parsedError = platformMachineApiErrorSchema.safeParse(payload);\n if (parsedError.success) {\n throw new AirJamPlatformApiError({\n code: parsedError.data.error,\n message:\n parsedError.data.error === \"invalid_token\"\n ? `${parsedError.data.message} Run airjam auth login to sign in again.`\n : parsedError.data.message,\n status: response.status,\n details: parsedError.data.details,\n retryAfterSeconds: parsedError.data.retryAfterSeconds,\n });\n }\n\n throw new AirJamPlatformApiError({\n code: \"invalid_request\",\n message: `Platform agent API request failed: ${response.status}`,\n status: response.status,\n });\n }\n\n return schema.parse(payload);\n};\n\nexport const readStoredPlatformMachineSession = async () => {\n const storagePath = resolvePlatformAuthFile();\n let source: string;\n try {\n source = await readFile(storagePath, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException)?.code === \"ENOENT\") {\n return null;\n }\n throw error;\n }\n\n try {\n return readableStoredPlatformSessionSchema.parse(\n JSON.parse(source) as unknown,\n );\n } catch (error) {\n throw new AirJamStoredPlatformSessionError(storagePath, error);\n }\n};\n\nexport const writeStoredPlatformMachineSession = async (\n value: AirJamPlatformMachineSessionStore,\n): Promise<void> => {\n const authDirectory = resolvePlatformAuthDirectory();\n const storagePath = resolvePlatformAuthFile();\n const temporaryPath = `${storagePath}.tmp-${process.pid}-${randomUUID()}`;\n await mkdir(authDirectory, { recursive: true, mode: 0o700 });\n await chmod(authDirectory, 0o700);\n try {\n await writeFile(\n temporaryPath,\n `${JSON.stringify(storedPlatformSessionSchema.parse(value), null, 2)}\\n`,\n { encoding: \"utf8\", flag: \"wx\", mode: 0o600 },\n );\n await rename(temporaryPath, storagePath);\n await chmod(storagePath, 0o600);\n } finally {\n await rm(temporaryPath, { force: true });\n }\n};\n\nexport const clearStoredPlatformMachineSession = async (): Promise<void> => {\n await rm(resolvePlatformAuthFile(), { force: true });\n};\n\nexport const startPlatformDeviceAuthorization = async ({\n platformUrl,\n clientName,\n}: StartPlatformDeviceAuthorizationOptions = {}) =>\n requestPlatformMachineApi({\n baseUrl: resolvePlatformBaseUrl(platformUrl),\n pathname: \"/api/cli/auth/device/start\",\n method: \"POST\",\n body: {\n ...(clientName?.trim() ? { clientName: clientName.trim() } : {}),\n },\n schema: platformMachineDeviceStartResultSchema,\n });\n\nexport const pollPlatformDeviceAuthorization = async ({\n platformUrl,\n deviceCode,\n}: PollPlatformDeviceAuthorizationOptions) =>\n requestPlatformMachineApi({\n baseUrl: resolvePlatformBaseUrl(platformUrl),\n pathname: \"/api/cli/auth/device/poll\",\n method: \"POST\",\n body: {\n deviceCode,\n },\n schema: platformMachineDevicePollResultSchema,\n });\n\nexport const loginPlatformWithDeviceFlow = async ({\n platformUrl,\n clientName,\n onPrompt,\n}: LoginPlatformWithDeviceFlowOptions = {}) => {\n const baseUrl = resolvePlatformBaseUrl(platformUrl);\n const authorization = await startPlatformDeviceAuthorization({\n platformUrl: baseUrl,\n clientName,\n });\n\n await onPrompt?.(authorization);\n\n const expiresAtMs = Date.parse(authorization.expiresAt);\n let intervalSeconds = authorization.intervalSeconds;\n while (Date.now() < expiresAtMs) {\n await sleep(intervalSeconds * 1000);\n if (Date.now() >= expiresAtMs) break;\n\n try {\n const authenticated = await pollPlatformDeviceAuthorization({\n platformUrl: baseUrl,\n deviceCode: authorization.deviceCode,\n });\n\n if (\n parsePlatformUrl(authenticated.platformBaseUrl).origin !==\n parsePlatformUrl(baseUrl).origin\n ) {\n throw new Error(\n \"The login response does not match the requested platform origin.\",\n );\n }\n const storedSession: AirJamPlatformMachineSessionStore = {\n version: 2,\n platformBaseUrl: baseUrl,\n clientName: clientName?.trim() || null,\n storedAt: new Date().toISOString(),\n user: authenticated.user,\n session: authenticated.session,\n };\n\n await withPlatformSessionLock(() =>\n writeStoredPlatformMachineSession(storedSession),\n );\n\n return {\n authorization,\n authenticated,\n storedSession,\n };\n } catch (error) {\n if (error instanceof AirJamPlatformApiError) {\n if (error.code === \"slow_down\") {\n intervalSeconds += 5;\n continue;\n }\n if (error.code === \"authorization_pending\") continue;\n }\n\n throw error;\n }\n }\n\n throw new AirJamPlatformApiError({\n code: \"expired_token\",\n message: \"The Air Jam CLI login expired before it was approved.\",\n status: 410,\n });\n};\n\nconst resolvePlatformMachineAuthUnlocked = async ({\n platformUrl,\n token,\n}: {\n platformUrl?: string;\n token?: string;\n}) => {\n if (token?.trim()) {\n return {\n baseUrl: resolvePlatformBaseUrl(platformUrl),\n token: token.trim(),\n };\n }\n\n let stored = await readStoredPlatformMachineSession();\n if (!stored) {\n throw new Error(\n \"No stored Air Jam platform session was found. Run airjam auth login to sign in.\",\n );\n }\n const baseUrl = resolvePlatformBaseUrl(platformUrl ?? stored.platformBaseUrl);\n if (\n parsePlatformUrl(baseUrl).origin !==\n parsePlatformUrl(stored.platformBaseUrl).origin\n ) {\n throw new Error(\n \"The stored Air Jam session belongs to a different platform origin. Log in to that platform or supply an explicit token.\",\n );\n }\n if (\n stored.version === 1 ||\n Date.parse(stored.session.expiresAt) <= Date.now() + 30_000\n ) {\n const authenticated = await requestPlatformMachineApi({\n baseUrl,\n pathname: \"/api/cli/auth/refresh\",\n method: \"POST\",\n body: {\n refreshToken:\n stored.version === 1\n ? stored.session.token\n : stored.session.refreshToken,\n },\n schema: platformMachineDevicePollResultSchema,\n });\n if (\n parsePlatformUrl(authenticated.platformBaseUrl).origin !==\n parsePlatformUrl(baseUrl).origin\n ) {\n throw new Error(\n \"The refresh response does not match the requested platform origin.\",\n );\n }\n stored = {\n ...stored,\n version: 2,\n user: authenticated.user,\n session: authenticated.session,\n storedAt: new Date().toISOString(),\n };\n await writeStoredPlatformMachineSession(stored);\n }\n return { baseUrl, token: stored.session.token };\n};\n\nexport const resolvePlatformMachineAuth = async (options: {\n platformUrl?: string;\n token?: string;\n}) =>\n options.token?.trim()\n ? resolvePlatformMachineAuthUnlocked(options)\n : withPlatformSessionLock(() =>\n resolvePlatformMachineAuthUnlocked(options),\n );\n\nexport const listPlatformMachineSessions = async (\n options: GetPlatformMachineProfileOptions = {},\n) => {\n const resolved = await resolvePlatformMachineAuth(options);\n return requestPlatformMachineApi({\n baseUrl: resolved.baseUrl,\n pathname: \"/api/cli/auth/sessions\",\n token: resolved.token,\n schema: platformMachineSessionsResultSchema,\n });\n};\n\nexport const revokePlatformMachineSession = async (\n options: GetPlatformMachineProfileOptions & { id: string },\n) => {\n const resolved = await resolvePlatformMachineAuth(options);\n return requestPlatformMachineApi({\n baseUrl: resolved.baseUrl,\n pathname: \"/api/cli/auth/sessions/revoke\",\n method: \"POST\",\n token: resolved.token,\n body: platformMachineRevokeSessionInputSchema.parse(options),\n schema: platformMachineLogoutResultSchema,\n });\n};\n\nexport const getPlatformMachineProfile = async ({\n platformUrl,\n token,\n}: GetPlatformMachineProfileOptions = {}) => {\n const resolved = await resolvePlatformMachineAuth({ platformUrl, token });\n return requestPlatformMachineApi({\n baseUrl: resolved.baseUrl,\n pathname: \"/api/cli/auth/me\",\n token: resolved.token,\n schema: platformMachineMeResultSchema,\n });\n};\n\nexport const updatePlatformMachineProfile = async ({\n platformUrl,\n token,\n displayName,\n}: GetPlatformMachineProfileOptions & { displayName: string }) => {\n const input = platformMachineProfileInputSchema.parse({ displayName });\n const resolved = await resolvePlatformMachineAuth({ platformUrl, token });\n return requestPlatformMachineApi({\n baseUrl: resolved.baseUrl,\n pathname: \"/api/cli/auth/profile\",\n method: \"POST\",\n token: resolved.token,\n body: input,\n schema: platformMachineUserSchema,\n });\n};\n\nexport const logoutPlatformMachineSession = async ({\n platformUrl,\n token,\n}: LogoutPlatformMachineSessionOptions = {}) => {\n return withPlatformSessionLock(async () => {\n const resolved = await resolvePlatformMachineAuthUnlocked({\n platformUrl,\n token,\n });\n const result = await requestPlatformMachineApi({\n baseUrl: resolved.baseUrl,\n pathname: \"/api/cli/auth/logout\",\n method: \"POST\",\n token: resolved.token,\n schema: platformMachineLogoutResultSchema,\n });\n if (!token) await clearStoredPlatformMachineSession();\n return result;\n });\n};\n\nexport const getPlatformMachineAuthStatus =\n async (): Promise<AirJamPlatformAuthStatus> => {\n const stored = await readStoredPlatformMachineSession();\n\n if (!stored) {\n return {\n authenticated: false,\n storagePath: resolvePlatformAuthFile(),\n platformBaseUrl: null,\n clientName: null,\n storedAt: null,\n user: null,\n session: null,\n };\n }\n\n return {\n authenticated: true,\n storagePath: resolvePlatformAuthFile(),\n platformBaseUrl: stored.platformBaseUrl,\n clientName: stored.clientName,\n storedAt: stored.storedAt,\n user: stored.user,\n session: {\n id: stored.session.id,\n expiresAt: stored.session.expiresAt,\n refreshExpiresAt:\n stored.version === 1\n ? stored.session.expiresAt\n : stored.session.refreshExpiresAt,\n createdAt: stored.session.createdAt,\n userAgent: stored.session.userAgent,\n },\n };\n };\n\nexport const getPlatformAuthStoragePath = () => resolvePlatformAuthFile();\n"],"mappings":";AA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