airlock-bot 0.3.1 → 0.4.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 +46 -33
- package/airlock.service +1 -0
- package/dist/airlock/context.d.ts.map +1 -1
- package/dist/airlock/context.js +5 -3
- package/dist/airlock/context.js.map +1 -1
- package/dist/airlock/tools.d.ts +15 -3
- package/dist/airlock/tools.d.ts.map +1 -1
- package/dist/airlock/tools.js +29 -1
- package/dist/airlock/tools.js.map +1 -1
- package/dist/allowlist/engine.d.ts +3 -0
- package/dist/allowlist/engine.d.ts.map +1 -1
- package/dist/allowlist/engine.js +46 -2
- package/dist/allowlist/engine.js.map +1 -1
- package/dist/audit/db.d.ts +22 -1
- package/dist/audit/db.d.ts.map +1 -1
- package/dist/audit/db.js +77 -10
- package/dist/audit/db.js.map +1 -1
- package/dist/audit/logger.d.ts +7 -2
- package/dist/audit/logger.d.ts.map +1 -1
- package/dist/audit/logger.js +18 -3
- package/dist/audit/logger.js.map +1 -1
- package/dist/audit/redactor.d.ts.map +1 -1
- package/dist/audit/redactor.js +6 -6
- package/dist/audit/redactor.js.map +1 -1
- package/dist/backend/airlock-adapter.d.ts +20 -2
- package/dist/backend/airlock-adapter.d.ts.map +1 -1
- package/dist/backend/airlock-adapter.js +443 -10
- package/dist/backend/airlock-adapter.js.map +1 -1
- package/dist/backend/cli/adapter.d.ts +4 -2
- package/dist/backend/cli/adapter.d.ts.map +1 -1
- package/dist/backend/cli/adapter.js +36 -11
- package/dist/backend/cli/adapter.js.map +1 -1
- package/dist/backend/cli/builder.d.ts +1 -1
- package/dist/backend/cli/builder.d.ts.map +1 -1
- package/dist/backend/cli/builder.js +28 -12
- package/dist/backend/cli/builder.js.map +1 -1
- package/dist/backend/exec-adapter.d.ts +1 -1
- package/dist/backend/exec-adapter.d.ts.map +1 -1
- package/dist/backend/exec-adapter.js +1 -5
- package/dist/backend/exec-adapter.js.map +1 -1
- package/dist/backend/factory.d.ts +2 -0
- package/dist/backend/factory.d.ts.map +1 -1
- package/dist/backend/factory.js +19 -5
- package/dist/backend/factory.js.map +1 -1
- package/dist/backend/http-adapter.d.ts +6 -3
- package/dist/backend/http-adapter.d.ts.map +1 -1
- package/dist/backend/http-adapter.js +24 -10
- package/dist/backend/http-adapter.js.map +1 -1
- package/dist/backend/mcp-adapter.d.ts +7 -2
- package/dist/backend/mcp-adapter.d.ts.map +1 -1
- package/dist/backend/mcp-adapter.js +74 -16
- package/dist/backend/mcp-adapter.js.map +1 -1
- package/dist/backend/openapi/adapter.d.ts +8 -2
- package/dist/backend/openapi/adapter.d.ts.map +1 -1
- package/dist/backend/openapi/adapter.js +196 -17
- package/dist/backend/openapi/adapter.js.map +1 -1
- package/dist/backend/openapi/parser.d.ts +15 -1
- package/dist/backend/openapi/parser.d.ts.map +1 -1
- package/dist/backend/openapi/parser.js +153 -11
- package/dist/backend/openapi/parser.js.map +1 -1
- package/dist/backend/types.d.ts +12 -1
- package/dist/backend/types.d.ts.map +1 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +334 -50
- package/dist/config/loader.js.map +1 -1
- package/dist/config/mutator.d.ts.map +1 -1
- package/dist/config/mutator.js +13 -3
- package/dist/config/mutator.js.map +1 -1
- package/dist/config/profiles.d.ts +2 -1
- package/dist/config/profiles.d.ts.map +1 -1
- package/dist/config/profiles.js +50 -2
- package/dist/config/profiles.js.map +1 -1
- package/dist/config/provider-credentials.d.ts +4 -0
- package/dist/config/provider-credentials.d.ts.map +1 -0
- package/dist/config/provider-credentials.js +48 -0
- package/dist/config/provider-credentials.js.map +1 -0
- package/dist/config/schema.d.ts +2829 -8642
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +337 -122
- package/dist/config/schema.js.map +1 -1
- package/dist/config/watcher.d.ts.map +1 -1
- package/dist/config/watcher.js +3 -0
- package/dist/config/watcher.js.map +1 -1
- package/dist/config/yaml-merge.d.ts +9 -0
- package/dist/config/yaml-merge.d.ts.map +1 -0
- package/dist/config/yaml-merge.js +54 -0
- package/dist/config/yaml-merge.js.map +1 -0
- package/dist/configure-agent/cli.d.ts +26 -0
- package/dist/configure-agent/cli.d.ts.map +1 -1
- package/dist/configure-agent/cli.js +70 -35
- package/dist/configure-agent/cli.js.map +1 -1
- package/dist/configure-cli/cli.d.ts +6 -0
- package/dist/configure-cli/cli.d.ts.map +1 -1
- package/dist/configure-cli/cli.js +45 -14
- package/dist/configure-cli/cli.js.map +1 -1
- package/dist/configure-web/assistant.d.ts +49 -0
- package/dist/configure-web/assistant.d.ts.map +1 -0
- package/dist/configure-web/assistant.js +312 -0
- package/dist/configure-web/assistant.js.map +1 -0
- package/dist/configure-web/changes.d.ts +214 -0
- package/dist/configure-web/changes.d.ts.map +1 -0
- package/dist/configure-web/changes.js +317 -0
- package/dist/configure-web/changes.js.map +1 -0
- package/dist/configure-web/cli.d.ts +33 -11
- package/dist/configure-web/cli.d.ts.map +1 -1
- package/dist/configure-web/cli.js +704 -151
- package/dist/configure-web/cli.js.map +1 -1
- package/dist/discover/cli.js +2 -2
- package/dist/discover/cli.js.map +1 -1
- package/dist/discover/index.d.ts.map +1 -1
- package/dist/discover/index.js +16 -22
- package/dist/discover/index.js.map +1 -1
- package/dist/discover/openapi.d.ts.map +1 -1
- package/dist/discover/openapi.js +2 -0
- package/dist/discover/openapi.js.map +1 -1
- package/dist/discover/strategies/completion.d.ts.map +1 -1
- package/dist/discover/strategies/completion.js +19 -2
- package/dist/discover/strategies/completion.js.map +1 -1
- package/dist/discover/strategies/fig.d.ts +10 -1
- package/dist/discover/strategies/fig.d.ts.map +1 -1
- package/dist/discover/strategies/fig.js +24 -10
- package/dist/discover/strategies/fig.js.map +1 -1
- package/dist/discover/strategies/help-parser.d.ts.map +1 -1
- package/dist/discover/strategies/help-parser.js +9 -6
- package/dist/discover/strategies/help-parser.js.map +1 -1
- package/dist/events/payload-inspector.d.ts +25 -0
- package/dist/events/payload-inspector.d.ts.map +1 -0
- package/dist/events/payload-inspector.js +210 -0
- package/dist/events/payload-inspector.js.map +1 -0
- package/dist/events/protocol.d.ts +227 -0
- package/dist/events/protocol.d.ts.map +1 -0
- package/dist/events/protocol.js +422 -0
- package/dist/events/protocol.js.map +1 -0
- package/dist/events/registry.d.ts +57 -0
- package/dist/events/registry.d.ts.map +1 -0
- package/dist/events/registry.js +179 -0
- package/dist/events/registry.js.map +1 -0
- package/dist/events/schema-validator.d.ts +13 -0
- package/dist/events/schema-validator.d.ts.map +1 -0
- package/dist/events/schema-validator.js +54 -0
- package/dist/events/schema-validator.js.map +1 -0
- package/dist/events/service.d.ts +97 -0
- package/dist/events/service.d.ts.map +1 -0
- package/dist/events/service.js +918 -0
- package/dist/events/service.js.map +1 -0
- package/dist/events/stream-manager.d.ts +58 -0
- package/dist/events/stream-manager.d.ts.map +1 -0
- package/dist/events/stream-manager.js +94 -0
- package/dist/events/stream-manager.js.map +1 -0
- package/dist/events/upstream-client.d.ts +88 -0
- package/dist/events/upstream-client.d.ts.map +1 -0
- package/dist/events/upstream-client.js +437 -0
- package/dist/events/upstream-client.js.map +1 -0
- package/dist/gateway.d.ts +14 -0
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +208 -33
- package/dist/gateway.js.map +1 -1
- package/dist/hitl/api.d.ts.map +1 -1
- package/dist/hitl/api.js +9 -2
- package/dist/hitl/api.js.map +1 -1
- package/dist/hitl/approval-dashboard.d.ts +5 -0
- package/dist/hitl/approval-dashboard.d.ts.map +1 -1
- package/dist/hitl/approval-dashboard.js +107 -20
- package/dist/hitl/approval-dashboard.js.map +1 -1
- package/dist/hitl/approval-stream.d.ts +2 -0
- package/dist/hitl/approval-stream.d.ts.map +1 -1
- package/dist/hitl/approval-stream.js +11 -0
- package/dist/hitl/approval-stream.js.map +1 -1
- package/dist/hitl/engine.d.ts +154 -4
- package/dist/hitl/engine.d.ts.map +1 -1
- package/dist/hitl/engine.js +616 -102
- package/dist/hitl/engine.js.map +1 -1
- package/dist/hitl/formatter.d.ts.map +1 -1
- package/dist/hitl/formatter.js +60 -10
- package/dist/hitl/formatter.js.map +1 -1
- package/dist/hitl/grant-api.d.ts +32 -0
- package/dist/hitl/grant-api.d.ts.map +1 -0
- package/dist/hitl/grant-api.js +249 -0
- package/dist/hitl/grant-api.js.map +1 -0
- package/dist/hitl/grants.d.ts +153 -0
- package/dist/hitl/grants.d.ts.map +1 -0
- package/dist/hitl/grants.js +273 -0
- package/dist/hitl/grants.js.map +1 -0
- package/dist/hitl/parser.d.ts +9 -0
- package/dist/hitl/parser.d.ts.map +1 -1
- package/dist/hitl/parser.js +60 -4
- package/dist/hitl/parser.js.map +1 -1
- package/dist/hitl/provider-factory.js +6 -1
- package/dist/hitl/provider-factory.js.map +1 -1
- package/dist/hitl/providers/composite.d.ts +0 -1
- package/dist/hitl/providers/composite.d.ts.map +1 -1
- package/dist/hitl/providers/composite.js +0 -3
- package/dist/hitl/providers/composite.js.map +1 -1
- package/dist/hitl/providers/dashboard.d.ts +1 -0
- package/dist/hitl/providers/dashboard.d.ts.map +1 -1
- package/dist/hitl/providers/dashboard.js +9 -2
- package/dist/hitl/providers/dashboard.js.map +1 -1
- package/dist/hitl/providers/ios.d.ts +0 -1
- package/dist/hitl/providers/ios.d.ts.map +1 -1
- package/dist/hitl/providers/ios.js +94 -39
- package/dist/hitl/providers/ios.js.map +1 -1
- package/dist/hitl/providers/macos.d.ts +2 -0
- package/dist/hitl/providers/macos.d.ts.map +1 -1
- package/dist/hitl/providers/macos.js +90 -3
- package/dist/hitl/providers/macos.js.map +1 -1
- package/dist/hitl/providers/openclaw.js +3 -9
- package/dist/hitl/providers/openclaw.js.map +1 -1
- package/dist/hitl/providers/stdio.js +3 -9
- package/dist/hitl/providers/stdio.js.map +1 -1
- package/dist/hitl/providers/telegram.d.ts.map +1 -1
- package/dist/hitl/providers/telegram.js +6 -10
- package/dist/hitl/providers/telegram.js.map +1 -1
- package/dist/hitl/providers/tui.d.ts +1 -1
- package/dist/hitl/providers/tui.d.ts.map +1 -1
- package/dist/hitl/providers/tui.js +91 -31
- package/dist/hitl/providers/tui.js.map +1 -1
- package/dist/hitl/providers/types.d.ts +38 -3
- package/dist/hitl/providers/types.d.ts.map +1 -1
- package/dist/hitl/runtime.d.ts +18 -0
- package/dist/hitl/runtime.d.ts.map +1 -0
- package/dist/hitl/runtime.js +60 -0
- package/dist/hitl/runtime.js.map +1 -0
- package/dist/hook/api.d.ts +6 -1
- package/dist/hook/api.d.ts.map +1 -1
- package/dist/hook/api.js +51 -12
- package/dist/hook/api.js.map +1 -1
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/dist/introspect/cli.d.ts.map +1 -1
- package/dist/introspect/cli.js +5 -2
- package/dist/introspect/cli.js.map +1 -1
- package/dist/mcp-apps/ui.d.ts +69 -0
- package/dist/mcp-apps/ui.d.ts.map +1 -0
- package/dist/mcp-apps/ui.js +143 -0
- package/dist/mcp-apps/ui.js.map +1 -0
- package/dist/middleware/audit-args.d.ts +7 -0
- package/dist/middleware/audit-args.d.ts.map +1 -0
- package/dist/middleware/audit-args.js +23 -0
- package/dist/middleware/audit-args.js.map +1 -0
- package/dist/middleware/chain-builder.d.ts +2 -2
- package/dist/middleware/chain-builder.d.ts.map +1 -1
- package/dist/middleware/chain-builder.js +7 -3
- package/dist/middleware/chain-builder.js.map +1 -1
- package/dist/middleware/core/allowlist.d.ts.map +1 -1
- package/dist/middleware/core/allowlist.js +8 -5
- package/dist/middleware/core/allowlist.js.map +1 -1
- package/dist/middleware/core/arg-policy.d.ts +1 -0
- package/dist/middleware/core/arg-policy.d.ts.map +1 -1
- package/dist/middleware/core/arg-policy.js +34 -37
- package/dist/middleware/core/arg-policy.js.map +1 -1
- package/dist/middleware/core/command-policy.d.ts +4 -1
- package/dist/middleware/core/command-policy.d.ts.map +1 -1
- package/dist/middleware/core/command-policy.js +50 -4
- package/dist/middleware/core/command-policy.js.map +1 -1
- package/dist/middleware/core/exec-policy.d.ts.map +1 -1
- package/dist/middleware/core/exec-policy.js +5 -5
- package/dist/middleware/core/exec-policy.js.map +1 -1
- package/dist/middleware/core/execute.d.ts +5 -1
- package/dist/middleware/core/execute.d.ts.map +1 -1
- package/dist/middleware/core/execute.js +18 -15
- package/dist/middleware/core/execute.js.map +1 -1
- package/dist/middleware/core/hitl-gate.d.ts +4 -1
- package/dist/middleware/core/hitl-gate.d.ts.map +1 -1
- package/dist/middleware/core/hitl-gate.js +153 -45
- package/dist/middleware/core/hitl-gate.js.map +1 -1
- package/dist/middleware/core/rate-limiter.d.ts.map +1 -1
- package/dist/middleware/core/rate-limiter.js +23 -7
- package/dist/middleware/core/rate-limiter.js.map +1 -1
- package/dist/middleware/core/schema-validator.d.ts +3 -0
- package/dist/middleware/core/schema-validator.d.ts.map +1 -1
- package/dist/middleware/core/schema-validator.js +31 -12
- package/dist/middleware/core/schema-validator.js.map +1 -1
- package/dist/middleware/core/upload-policy.d.ts +18 -0
- package/dist/middleware/core/upload-policy.d.ts.map +1 -0
- package/dist/middleware/core/upload-policy.js +98 -0
- package/dist/middleware/core/upload-policy.js.map +1 -0
- package/dist/middleware/detectors/injection-detector.d.ts.map +1 -1
- package/dist/middleware/detectors/injection-detector.js +8 -6
- package/dist/middleware/detectors/injection-detector.js.map +1 -1
- package/dist/middleware/detectors/sensitivity-classifier.d.ts.map +1 -1
- package/dist/middleware/detectors/sensitivity-classifier.js +19 -5
- package/dist/middleware/detectors/sensitivity-classifier.js.map +1 -1
- package/dist/middleware/post/untrusted-envelope.d.ts.map +1 -1
- package/dist/middleware/post/untrusted-envelope.js +4 -1
- package/dist/middleware/post/untrusted-envelope.js.map +1 -1
- package/dist/middleware/response.d.ts +33 -0
- package/dist/middleware/response.d.ts.map +1 -0
- package/dist/middleware/response.js +110 -0
- package/dist/middleware/response.js.map +1 -0
- package/dist/middleware/types.d.ts +13 -0
- package/dist/middleware/types.d.ts.map +1 -1
- package/dist/mobile/api.d.ts.map +1 -1
- package/dist/mobile/api.js +57 -34
- package/dist/mobile/api.js.map +1 -1
- package/dist/mobile/apns.d.ts +39 -2
- package/dist/mobile/apns.d.ts.map +1 -1
- package/dist/mobile/apns.js +84 -83
- package/dist/mobile/apns.js.map +1 -1
- package/dist/pool/client-credentials.d.ts +2 -0
- package/dist/pool/client-credentials.d.ts.map +1 -1
- package/dist/pool/client-credentials.js +18 -3
- package/dist/pool/client-credentials.js.map +1 -1
- package/dist/pool/credential-health.d.ts +2 -2
- package/dist/pool/credential-health.d.ts.map +1 -1
- package/dist/pool/credential-health.js +7 -2
- package/dist/pool/credential-health.js.map +1 -1
- package/dist/pool/http-client.d.ts +105 -16
- package/dist/pool/http-client.d.ts.map +1 -1
- package/dist/pool/http-client.js +712 -116
- package/dist/pool/http-client.js.map +1 -1
- package/dist/pool/oauth-callback-router.d.ts +35 -0
- package/dist/pool/oauth-callback-router.d.ts.map +1 -0
- package/dist/pool/oauth-callback-router.js +84 -0
- package/dist/pool/oauth-callback-router.js.map +1 -0
- package/dist/pool/oauth-cli.d.ts +10 -0
- package/dist/pool/oauth-cli.d.ts.map +1 -0
- package/dist/pool/oauth-cli.js +318 -0
- package/dist/pool/oauth-cli.js.map +1 -0
- package/dist/pool/oauth-lock.d.ts +149 -0
- package/dist/pool/oauth-lock.d.ts.map +1 -0
- package/dist/pool/oauth-lock.js +575 -0
- package/dist/pool/oauth-lock.js.map +1 -0
- package/dist/pool/oauth-provider.d.ts +231 -27
- package/dist/pool/oauth-provider.d.ts.map +1 -1
- package/dist/pool/oauth-provider.js +802 -142
- package/dist/pool/oauth-provider.js.map +1 -1
- package/dist/pool/oauth-refresh.d.ts +94 -0
- package/dist/pool/oauth-refresh.d.ts.map +1 -0
- package/dist/pool/oauth-refresh.js +477 -0
- package/dist/pool/oauth-refresh.js.map +1 -0
- package/dist/pool/oauth-store.d.ts +304 -0
- package/dist/pool/oauth-store.d.ts.map +1 -0
- package/dist/pool/oauth-store.js +684 -0
- package/dist/pool/oauth-store.js.map +1 -0
- package/dist/pool/pool.d.ts +37 -4
- package/dist/pool/pool.d.ts.map +1 -1
- package/dist/pool/pool.js +170 -8
- package/dist/pool/pool.js.map +1 -1
- package/dist/pool/required-mcps.d.ts +7 -0
- package/dist/pool/required-mcps.d.ts.map +1 -1
- package/dist/pool/required-mcps.js +40 -2
- package/dist/pool/required-mcps.js.map +1 -1
- package/dist/pool/sse-client.d.ts +17 -3
- package/dist/pool/sse-client.d.ts.map +1 -1
- package/dist/pool/sse-client.js +59 -6
- package/dist/pool/sse-client.js.map +1 -1
- package/dist/pool/status.d.ts +53 -0
- package/dist/pool/status.d.ts.map +1 -1
- package/dist/pool/stdio-client.d.ts +23 -3
- package/dist/pool/stdio-client.d.ts.map +1 -1
- package/dist/pool/stdio-client.js +84 -6
- package/dist/pool/stdio-client.js.map +1 -1
- package/dist/registry/airlock-policy.d.ts +1 -1
- package/dist/registry/airlock-policy.d.ts.map +1 -1
- package/dist/registry/airlock-policy.js +1 -1
- package/dist/registry/airlock-policy.js.map +1 -1
- package/dist/registry/registry.d.ts +22 -2
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +176 -22
- package/dist/registry/registry.js.map +1 -1
- package/dist/registry/sanitizer.d.ts +5 -0
- package/dist/registry/sanitizer.d.ts.map +1 -1
- package/dist/registry/sanitizer.js +17 -13
- package/dist/registry/sanitizer.js.map +1 -1
- package/dist/security/request.d.ts +19 -0
- package/dist/security/request.d.ts.map +1 -1
- package/dist/security/request.js +35 -1
- package/dist/security/request.js.map +1 -1
- package/dist/stdio-mode.d.ts.map +1 -1
- package/dist/stdio-mode.js +237 -50
- package/dist/stdio-mode.js.map +1 -1
- package/dist/tools/api.d.ts.map +1 -1
- package/dist/tools/api.js +49 -15
- package/dist/tools/api.js.map +1 -1
- package/dist/tools/exec.d.ts +1 -1
- package/dist/tools/exec.d.ts.map +1 -1
- package/dist/tools/http.d.ts +7 -3
- package/dist/tools/http.d.ts.map +1 -1
- package/dist/tools/http.js +179 -25
- package/dist/tools/http.js.map +1 -1
- package/dist/transport/agent-server.d.ts +29 -2
- package/dist/transport/agent-server.d.ts.map +1 -1
- package/dist/transport/agent-server.js +190 -32
- package/dist/transport/agent-server.js.map +1 -1
- package/dist/transport/http-server.d.ts +17 -2
- package/dist/transport/http-server.d.ts.map +1 -1
- package/dist/transport/http-server.js +109 -96
- package/dist/transport/http-server.js.map +1 -1
- package/dist/transport/keepalive.d.ts +11 -13
- package/dist/transport/keepalive.d.ts.map +1 -1
- package/dist/transport/keepalive.js +11 -13
- package/dist/transport/keepalive.js.map +1 -1
- package/dist/transport/oauth-callback.d.ts +19 -0
- package/dist/transport/oauth-callback.d.ts.map +1 -0
- package/dist/transport/oauth-callback.js +30 -0
- package/dist/transport/oauth-callback.js.map +1 -0
- package/dist/transport/session-limiter.d.ts +10 -3
- package/dist/transport/session-limiter.d.ts.map +1 -1
- package/dist/transport/session-limiter.js +13 -3
- package/dist/transport/session-limiter.js.map +1 -1
- package/dist/transport/sse-server.d.ts.map +1 -1
- package/dist/transport/sse-server.js +54 -24
- package/dist/transport/sse-server.js.map +1 -1
- package/dist/transport/stdio-server.d.ts +6 -0
- package/dist/transport/stdio-server.d.ts.map +1 -1
- package/dist/transport/stdio-server.js +19 -7
- package/dist/transport/stdio-server.js.map +1 -1
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/uploads/api.d.ts +20 -0
- package/dist/uploads/api.d.ts.map +1 -0
- package/dist/uploads/api.js +280 -0
- package/dist/uploads/api.js.map +1 -0
- package/dist/uploads/refs.d.ts +48 -0
- package/dist/uploads/refs.d.ts.map +1 -0
- package/dist/uploads/refs.js +273 -0
- package/dist/uploads/refs.js.map +1 -0
- package/dist/uploads/resolve.d.ts +117 -0
- package/dist/uploads/resolve.d.ts.map +1 -0
- package/dist/uploads/resolve.js +581 -0
- package/dist/uploads/resolve.js.map +1 -0
- package/dist/uploads/store.d.ts +224 -0
- package/dist/uploads/store.d.ts.map +1 -0
- package/dist/uploads/store.js +1908 -0
- package/dist/uploads/store.js.map +1 -0
- package/dist/util/atomic-file.d.ts +6 -0
- package/dist/util/atomic-file.d.ts.map +1 -1
- package/dist/util/atomic-file.js +42 -2
- package/dist/util/atomic-file.js.map +1 -1
- package/dist/util/is-record.d.ts +3 -0
- package/dist/util/is-record.d.ts.map +1 -0
- package/dist/util/is-record.js +5 -0
- package/dist/util/is-record.js.map +1 -0
- package/dist/util/stable-json.d.ts +3 -0
- package/dist/util/stable-json.d.ts.map +1 -0
- package/dist/util/stable-json.js +10 -0
- package/dist/util/stable-json.js.map +1 -0
- package/dist/util/tool-name.d.ts +9 -0
- package/dist/util/tool-name.d.ts.map +1 -0
- package/dist/util/tool-name.js +14 -0
- package/dist/util/tool-name.js.map +1 -0
- package/dist/web/assets/airlock-shield-fPu067nB.png +0 -0
- package/dist/web/assets/favicon-DL7sWXGq.png +0 -0
- package/dist/web/assets/index-B_qY7DgQ.js +225 -0
- package/dist/web/assets/index-Bc_jHlFK.css +1 -0
- package/dist/web/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/web/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/web/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/web/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/web/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/web/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/web/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/web/index.html +17 -0
- package/examples/airlock.yaml +3 -1
- package/examples/claude-code-setup.md +1 -1
- package/examples/docker-compose.yaml +3 -1
- package/examples/docker-gateway.yaml +2 -1
- package/examples/gateway.yaml +1 -1
- package/examples/profiles.yaml +5 -2
- package/examples/sandbox-presets.yaml +4 -1
- package/extensions/openclaw/index.ts +3 -3
- package/extensions/openclaw/openclaw.plugin.json +4 -4
- package/package.json +25 -10
- package/schema.json +2819 -2029
- package/dist/transport/mcp-normalizer.d.ts +0 -9
- package/dist/transport/mcp-normalizer.d.ts.map +0 -1
- package/dist/transport/mcp-normalizer.js +0 -12
- package/dist/transport/mcp-normalizer.js.map +0 -1
- package/extensions/openclaw/package-lock.json +0 -8548
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
import { link, mkdir, open, readdir, readFile, stat, unlink } from 'fs/promises';
|
|
2
|
+
import { createHash, randomUUID } from 'crypto';
|
|
3
|
+
import { dirname, join } from 'path';
|
|
4
|
+
import { atomicWritePrivateFile } from '../util/atomic-file.js';
|
|
5
|
+
import { setLockAcquiredHook, writerLockFor } from './oauth-lock.js';
|
|
6
|
+
import { childLogger } from '../util/logger.js';
|
|
7
|
+
const log = childLogger('oauth-store');
|
|
8
|
+
/** Versions of each provider's grant file kept under `.history/<id>/`. */
|
|
9
|
+
export const HISTORY_LIMIT = 10;
|
|
10
|
+
export const HISTORY_DIR = '.history';
|
|
11
|
+
/** Successors obtained by a process that lost the writer lock mid-exchange (see adoption). */
|
|
12
|
+
export const ORPHAN_DIR = '.successors';
|
|
13
|
+
/**
|
|
14
|
+
* Immutable grant revisions: `.grants/<id>/r<NNNNNNNNNNNN>.json`. The highest readable revision is
|
|
15
|
+
* the grant. `<id>.json` next to it is a compatibility mirror (status tools, `ls`), never read
|
|
16
|
+
* once revisions exist.
|
|
17
|
+
*/
|
|
18
|
+
export const REVISION_DIR = '.grants';
|
|
19
|
+
/** Revisions kept per grant (older ones are pruned after a newer one is durable). */
|
|
20
|
+
export const REVISIONS_KEPT = 5;
|
|
21
|
+
/** Crash-left temp files are removed after this age. */
|
|
22
|
+
const TMP_TTL_MS = 60 * 60 * 1000;
|
|
23
|
+
export class OAuthStoreReadOnlyError extends Error {
|
|
24
|
+
constructor(serverId, reason) {
|
|
25
|
+
super(`OAuth storage for ${serverId} is read-only in this process (${reason})`);
|
|
26
|
+
this.name = 'OAuthStoreReadOnlyError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** The grant file changed under this process (operator restore, another writer). */
|
|
30
|
+
/** A provider id that OAuth storage refuses (it would not map to its own files verbatim). */
|
|
31
|
+
export class OAuthStoreIdError extends Error {
|
|
32
|
+
constructor(serverId) {
|
|
33
|
+
super(`OAuth provider id ${JSON.stringify(serverId)} is not supported for OAuth grant storage (use letters, digits, ".", "_", "-"; not starting with ".")`);
|
|
34
|
+
this.name = 'OAuthStoreIdError';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Provider ids are used verbatim in every OAuth path (`<id>.json`, `.grants/<id>/`, …), so only
|
|
39
|
+
* ids that are already safe file names are accepted. No encoding, so no two ids can collide.
|
|
40
|
+
*/
|
|
41
|
+
export const OAUTH_PROVIDER_ID_RE = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/;
|
|
42
|
+
export function isValidProviderId(serverId) {
|
|
43
|
+
return OAUTH_PROVIDER_ID_RE.test(serverId) && serverId.length <= 200;
|
|
44
|
+
}
|
|
45
|
+
/** The filesystem cannot provide the guarantees OAuth storage relies on (hard links). */
|
|
46
|
+
export class OAuthStoreUnsupportedError extends Error {
|
|
47
|
+
constructor(reason) {
|
|
48
|
+
super(`OAuth store directory is unsupported: ${reason}; no refresh token will be spent`);
|
|
49
|
+
this.name = 'OAuthStoreUnsupportedError';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class OAuthStoreConflictError extends Error {
|
|
53
|
+
constructor(serverId) {
|
|
54
|
+
super(`OAuth grant file for ${serverId} changed on disk since it was read`);
|
|
55
|
+
this.name = 'OAuthStoreConflictError';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function oauthStoreDir() {
|
|
59
|
+
const override = process.env.AIRLOCK_OAUTH_DIR?.trim();
|
|
60
|
+
if (override)
|
|
61
|
+
return override;
|
|
62
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? '.';
|
|
63
|
+
return join(home, '.airlock', 'oauth');
|
|
64
|
+
}
|
|
65
|
+
export function sha256(value) {
|
|
66
|
+
return createHash('sha256').update(value).digest('hex');
|
|
67
|
+
}
|
|
68
|
+
/** The issuer a stored grant belongs to (explicit field, else the SDK's SEP-2352 stamps). */
|
|
69
|
+
export function grantIssuer(data) {
|
|
70
|
+
const stampedTokens = data.tokens;
|
|
71
|
+
const stampedClient = data.clientInfo;
|
|
72
|
+
if (data.issuer)
|
|
73
|
+
return data.issuer;
|
|
74
|
+
if (typeof stampedTokens?.issuer === 'string')
|
|
75
|
+
return stampedTokens.issuer;
|
|
76
|
+
if (typeof stampedClient?.issuer === 'string')
|
|
77
|
+
return stampedClient.issuer;
|
|
78
|
+
return (data.discovery?.authorizationServerMetadata?.issuer ?? data.discovery?.authorizationServerUrl);
|
|
79
|
+
}
|
|
80
|
+
export function summarizeGrant(data) {
|
|
81
|
+
const expiresAt = data.obtainedAt && data.tokens?.expires_in
|
|
82
|
+
? new Date(data.obtainedAt + data.tokens.expires_in * 1000).toISOString()
|
|
83
|
+
: undefined;
|
|
84
|
+
return {
|
|
85
|
+
hasAccessToken: Boolean(data.tokens?.access_token),
|
|
86
|
+
hasRefreshToken: Boolean(data.tokens?.refresh_token),
|
|
87
|
+
hasClientInfo: Boolean(data.clientInfo?.client_id),
|
|
88
|
+
issuer: grantIssuer(data),
|
|
89
|
+
obtainedAt: data.obtainedAt ? new Date(data.obtainedAt).toISOString() : undefined,
|
|
90
|
+
accessExpiresAt: expiresAt,
|
|
91
|
+
resource: data.resource,
|
|
92
|
+
hasDiscovery: Boolean(data.discovery),
|
|
93
|
+
pendingAuthorization: Boolean(data.pending),
|
|
94
|
+
...(data.exchange
|
|
95
|
+
? {
|
|
96
|
+
exchange: {
|
|
97
|
+
state: data.exchange.state === 'in_flight' ? 'interrupted' : 'ambiguous',
|
|
98
|
+
since: new Date(data.exchange.at ?? data.exchange.startedAt).toISOString(),
|
|
99
|
+
tokenEndpoint: data.exchange.tokenEndpoint,
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
: {}),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** The part of a file whose loss would force re-authorization. */
|
|
106
|
+
function grantFingerprint(data) {
|
|
107
|
+
return JSON.stringify({ c: data.clientInfo ?? null, t: data.tokens ?? null });
|
|
108
|
+
}
|
|
109
|
+
function sanitizeId(serverId) {
|
|
110
|
+
return serverId.replace(/[^A-Za-z0-9._-]/g, '_');
|
|
111
|
+
}
|
|
112
|
+
function historyStamp() {
|
|
113
|
+
return new Date().toISOString().replace(/[-:.]/g, '');
|
|
114
|
+
}
|
|
115
|
+
// ─── Per-grant operation serialization ──────────────────────────────────────────────────────────
|
|
116
|
+
const grantOps = new Map();
|
|
117
|
+
/**
|
|
118
|
+
* Run `fn` exclusively for one grant file within this process. Refresh exchanges, authorization-
|
|
119
|
+
* code exchanges, orphan adoption, and restores all run through here, so no two of them can
|
|
120
|
+
* interleave their read → network → commit sequences on the same grant.
|
|
121
|
+
*/
|
|
122
|
+
export async function withGrantOperation(path, fn) {
|
|
123
|
+
const previous = grantOps.get(path) ?? Promise.resolve();
|
|
124
|
+
let release;
|
|
125
|
+
const mine = new Promise((resolve) => (release = resolve));
|
|
126
|
+
const tail = previous.then(() => mine);
|
|
127
|
+
grantOps.set(path, tail);
|
|
128
|
+
await previous;
|
|
129
|
+
try {
|
|
130
|
+
return await fn();
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
release();
|
|
134
|
+
if (grantOps.get(path) === tail)
|
|
135
|
+
grantOps.delete(path);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Whoever acquires a store's writer lock removes crash-left temp files there (bounded cleanup).
|
|
139
|
+
setLockAcquiredHook((dir) => cleanupStaleTemp(dir));
|
|
140
|
+
/**
|
|
141
|
+
* Mirror writes for one grant are serialized within the process, and each one re-checks under
|
|
142
|
+
* this queue that its revision is still the newest before writing: an older revision can never be
|
|
143
|
+
* written over a newer mirror, however the writes are delayed.
|
|
144
|
+
*/
|
|
145
|
+
const mirrorQueues = new Map();
|
|
146
|
+
/**
|
|
147
|
+
* Wait until no grant operation (refresh exchange + commit, code exchange, restore) is running
|
|
148
|
+
* for `path` in this process, up to `timeoutMs`. Returns false on timeout. Used at shutdown, after
|
|
149
|
+
* new exchanges stopped being admitted, so a token request already sent is committed (or its
|
|
150
|
+
* successor parked) before the writer lock is released and the process exits.
|
|
151
|
+
*/
|
|
152
|
+
export async function drainGrantOperations(timeoutMs, path) {
|
|
153
|
+
const deadline = Date.now() + timeoutMs;
|
|
154
|
+
for (;;) {
|
|
155
|
+
const pending = path
|
|
156
|
+
? grantOps.has(path)
|
|
157
|
+
? [grantOps.get(path)]
|
|
158
|
+
: []
|
|
159
|
+
: Array.from(grantOps.values());
|
|
160
|
+
if (pending.length === 0)
|
|
161
|
+
return true;
|
|
162
|
+
const remaining = deadline - Date.now();
|
|
163
|
+
if (remaining <= 0)
|
|
164
|
+
return false;
|
|
165
|
+
let timer;
|
|
166
|
+
await Promise.race([
|
|
167
|
+
Promise.allSettled(pending),
|
|
168
|
+
new Promise((r) => (timer = setTimeout(r, remaining))),
|
|
169
|
+
]);
|
|
170
|
+
if (timer)
|
|
171
|
+
clearTimeout(timer);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** Fingerprint of the credentials a successor was derived from (refresh + access token + client). */
|
|
175
|
+
export function credentialFingerprint(data) {
|
|
176
|
+
return sha256(JSON.stringify([
|
|
177
|
+
data.tokens?.refresh_token ?? null,
|
|
178
|
+
data.tokens?.access_token ?? null,
|
|
179
|
+
data.clientInfo?.client_id ?? null,
|
|
180
|
+
]));
|
|
181
|
+
}
|
|
182
|
+
function revFile(rev) {
|
|
183
|
+
return `r${String(rev).padStart(12, '0')}.json`;
|
|
184
|
+
}
|
|
185
|
+
function parseRev(name) {
|
|
186
|
+
const m = /^r(\d{12})\.json$/.exec(name);
|
|
187
|
+
return m ? Number(m[1]) : undefined;
|
|
188
|
+
}
|
|
189
|
+
/** fsync a directory so entries created/renamed in it survive a crash. Errors propagate. */
|
|
190
|
+
export async function fsyncDir(dir) {
|
|
191
|
+
if (process.platform === 'win32')
|
|
192
|
+
return; // directories cannot be opened there
|
|
193
|
+
const handle = await open(dir, 'r');
|
|
194
|
+
try {
|
|
195
|
+
await handle.sync();
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
await handle.close().catch(() => { });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Create `target` (and missing parents below `root`) with mode 0700, fsyncing the parent of every
|
|
203
|
+
* directory created so the new entries are durable before anything is written inside them.
|
|
204
|
+
*/
|
|
205
|
+
export async function mkdirDurable(root, target) {
|
|
206
|
+
const chain = [];
|
|
207
|
+
for (let d = target; d !== root && d.startsWith(root); d = dirname(d))
|
|
208
|
+
chain.unshift(d);
|
|
209
|
+
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
210
|
+
// Always fsync the parents, also when the directories already exist: a previous attempt may
|
|
211
|
+
// have created one and then failed its parent fsync. Directory fsyncs are cheap.
|
|
212
|
+
await fsyncDir(dirname(root));
|
|
213
|
+
for (const d of chain) {
|
|
214
|
+
try {
|
|
215
|
+
await mkdir(d, { mode: 0o700 });
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
if (err.code !== 'EEXIST')
|
|
219
|
+
throw err;
|
|
220
|
+
}
|
|
221
|
+
await fsyncDir(dirname(d));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/** Remove crash-left `*.tmp` files older than an hour (bounded cleanup, run by the lock holder). */
|
|
225
|
+
export async function cleanupStaleTemp(dir) {
|
|
226
|
+
const dirs = [dir];
|
|
227
|
+
for (const sub of [REVISION_DIR, HISTORY_DIR, ORPHAN_DIR]) {
|
|
228
|
+
const names = await readdir(join(dir, sub)).catch(() => []);
|
|
229
|
+
for (const name of names)
|
|
230
|
+
dirs.push(join(dir, sub, name));
|
|
231
|
+
}
|
|
232
|
+
for (const d of dirs) {
|
|
233
|
+
const names = await readdir(d).catch(() => []);
|
|
234
|
+
for (const name of names) {
|
|
235
|
+
if (!name.endsWith('.tmp'))
|
|
236
|
+
continue;
|
|
237
|
+
const path = join(d, name);
|
|
238
|
+
const info = await stat(path).catch(() => undefined);
|
|
239
|
+
if (info && Date.now() - info.mtimeMs > TMP_TTL_MS)
|
|
240
|
+
await unlink(path).catch(() => { });
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Persistence for one provider's OAuth grant.
|
|
246
|
+
*
|
|
247
|
+
* Each committed grant is a new immutable revision file, published with `link()` (exclusive
|
|
248
|
+
* create): exactly one writer can publish revision N, and readers take the highest revision. A
|
|
249
|
+
* writer that was frozen after its ownership check and resumes after a takeover can therefore
|
|
250
|
+
* never replace a newer grant: its publication either fails (`EEXIST`) or lands below the new
|
|
251
|
+
* owner's revisions. Writes are also fenced by the writer lock and compare-and-swap against the
|
|
252
|
+
* revision the caller last read. History backups of a same-lineage predecessor are written after
|
|
253
|
+
* the new revision is durable; replacing a different grant (restore, new authorization, a corrupt
|
|
254
|
+
* file) requires a durable backup first.
|
|
255
|
+
*/
|
|
256
|
+
export class OAuthGrantStore {
|
|
257
|
+
serverId;
|
|
258
|
+
mode;
|
|
259
|
+
dir;
|
|
260
|
+
/** Compatibility mirror `<id>.json` (also the legacy, pre-revision grant file). */
|
|
261
|
+
path;
|
|
262
|
+
revisionDir;
|
|
263
|
+
historyDir;
|
|
264
|
+
orphanDir;
|
|
265
|
+
validId;
|
|
266
|
+
lock;
|
|
267
|
+
/** Serializes publications so an older snapshot can never be published after a newer one. */
|
|
268
|
+
queue = Promise.resolve();
|
|
269
|
+
/** Backups run here, after the primary commit, and never delay it. */
|
|
270
|
+
historyQueue = Promise.resolve();
|
|
271
|
+
/** Revision this store instance last published. */
|
|
272
|
+
lastWrittenRev;
|
|
273
|
+
constructor(serverId, mode = 'writer', dir = oauthStoreDir()) {
|
|
274
|
+
this.serverId = serverId;
|
|
275
|
+
this.mode = mode;
|
|
276
|
+
this.dir = dir;
|
|
277
|
+
this.validId = isValidProviderId(serverId);
|
|
278
|
+
// Verbatim (validated) id everywhere: no encoding, no collisions between providers.
|
|
279
|
+
const safe = this.validId ? serverId : '_invalid_';
|
|
280
|
+
this.path = join(dir, `${safe}.json`);
|
|
281
|
+
this.revisionDir = join(dir, REVISION_DIR, safe);
|
|
282
|
+
this.historyDir = join(dir, HISTORY_DIR, safe);
|
|
283
|
+
this.orphanDir = join(dir, ORPHAN_DIR, safe);
|
|
284
|
+
this.lock = writerLockFor(dir);
|
|
285
|
+
if (mode === 'writer')
|
|
286
|
+
this.lock.keepAcquiring();
|
|
287
|
+
}
|
|
288
|
+
assertValidId() {
|
|
289
|
+
if (!this.validId)
|
|
290
|
+
throw new OAuthStoreIdError(this.serverId);
|
|
291
|
+
}
|
|
292
|
+
/** Whether this process may write right now (acquires the writer lock on demand). */
|
|
293
|
+
async canWrite() {
|
|
294
|
+
if (this.mode === 'readonly')
|
|
295
|
+
return false;
|
|
296
|
+
return this.lock.ensure();
|
|
297
|
+
}
|
|
298
|
+
/** Why the last lock check failed, for outcome messages. */
|
|
299
|
+
get lockProblem() {
|
|
300
|
+
return this.lock.lastProblem;
|
|
301
|
+
}
|
|
302
|
+
/** Subscribe to "this process just acquired the writer lock". Returns an unsubscribe. */
|
|
303
|
+
onLockAcquired(cb) {
|
|
304
|
+
return this.lock.onAcquired(cb);
|
|
305
|
+
}
|
|
306
|
+
async revisions() {
|
|
307
|
+
const names = await readdir(this.revisionDir).catch((err) => {
|
|
308
|
+
if (err.code === 'ENOENT')
|
|
309
|
+
return [];
|
|
310
|
+
throw err;
|
|
311
|
+
});
|
|
312
|
+
return names
|
|
313
|
+
.map(parseRev)
|
|
314
|
+
.filter((r) => r !== undefined)
|
|
315
|
+
.sort((a, b) => b - a);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Read the grant: the highest revision, or the legacy `<id>.json` when no revision exists yet.
|
|
319
|
+
* A missing grant is `{}`; an unparseable one is reported (and backed up before any newer
|
|
320
|
+
* revision is published), never silently replaced.
|
|
321
|
+
*/
|
|
322
|
+
async read() {
|
|
323
|
+
this.assertValidId();
|
|
324
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
325
|
+
const revs = await this.revisions();
|
|
326
|
+
if (revs.length === 0)
|
|
327
|
+
return this.readLegacy();
|
|
328
|
+
let raced = false;
|
|
329
|
+
for (const rev of revs) {
|
|
330
|
+
let raw;
|
|
331
|
+
try {
|
|
332
|
+
raw = await readFile(join(this.revisionDir, revFile(rev)), 'utf-8');
|
|
333
|
+
}
|
|
334
|
+
catch (err) {
|
|
335
|
+
if (err.code === 'ENOENT') {
|
|
336
|
+
raced = true; // pruned meanwhile: list again
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
throw err;
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
return { data: JSON.parse(raw), raw, rev, hash: sha256(raw) };
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
return { data: {}, raw, corrupt: true, rev, hash: sha256(raw) };
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (!raced)
|
|
349
|
+
return this.readLegacy();
|
|
350
|
+
}
|
|
351
|
+
throw new Error(`OAuth grant revisions for ${this.serverId} kept changing while reading`);
|
|
352
|
+
}
|
|
353
|
+
async readLegacy() {
|
|
354
|
+
let raw;
|
|
355
|
+
try {
|
|
356
|
+
raw = await readFile(this.path, 'utf-8');
|
|
357
|
+
}
|
|
358
|
+
catch (err) {
|
|
359
|
+
if (err.code === 'ENOENT')
|
|
360
|
+
return { data: {}, rev: 0, hash: null };
|
|
361
|
+
throw err;
|
|
362
|
+
}
|
|
363
|
+
try {
|
|
364
|
+
return { data: JSON.parse(raw), raw, rev: 0, hash: sha256(raw) };
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
return { data: {}, raw, corrupt: true, rev: 0, hash: sha256(raw) };
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/** Test seam: runs after the new revision is fsynced and right before it is published. */
|
|
371
|
+
async beforePublish() { }
|
|
372
|
+
/**
|
|
373
|
+
* Publish a new grant revision. Requires (and re-verifies) the writer lock immediately before.
|
|
374
|
+
*
|
|
375
|
+
* `expectRev` makes it a compare-and-swap: refused with {@link OAuthStoreConflictError} when
|
|
376
|
+
* the current revision is neither what the caller last read nor what this store last published
|
|
377
|
+
* (omit to skip the check, e.g. a restore). Publication itself is exclusive (`link()`), so a
|
|
378
|
+
* stale writer that slipped past every check still cannot replace a newer revision.
|
|
379
|
+
*
|
|
380
|
+
* `backup: 'before'` makes a durable history copy of the current grant a precondition (used
|
|
381
|
+
* when replacing a different grant); the default backs it up afterwards, best-effort.
|
|
382
|
+
*/
|
|
383
|
+
async write(data, reason, opts = {}) {
|
|
384
|
+
this.assertValidId();
|
|
385
|
+
if (this.mode === 'readonly') {
|
|
386
|
+
throw new OAuthStoreReadOnlyError(this.serverId, 'read-only command');
|
|
387
|
+
}
|
|
388
|
+
const snapshot = JSON.stringify(data, null, 2);
|
|
389
|
+
const run = this.queue.then(async () => {
|
|
390
|
+
if (!(await this.lock.ensure())) {
|
|
391
|
+
throw new OAuthStoreReadOnlyError(this.serverId, this.lock.lastProblem ?? 'another Airlock process holds the writer lock');
|
|
392
|
+
}
|
|
393
|
+
const current = await this.read();
|
|
394
|
+
if (opts.expectRev !== undefined &&
|
|
395
|
+
current.rev !== opts.expectRev &&
|
|
396
|
+
(this.lastWrittenRev === undefined || current.rev !== this.lastWrittenRev)) {
|
|
397
|
+
throw new OAuthStoreConflictError(this.serverId);
|
|
398
|
+
}
|
|
399
|
+
const needsBackup = current.raw !== undefined &&
|
|
400
|
+
(current.corrupt ||
|
|
401
|
+
((current.data.tokens || current.data.clientInfo) &&
|
|
402
|
+
grantFingerprint(current.data) !== grantFingerprint(data)));
|
|
403
|
+
if (needsBackup && (opts.backup === 'before' || current.corrupt)) {
|
|
404
|
+
if (!(await this.enqueueHistory(current.raw, `replaced-by-${reason}`))) {
|
|
405
|
+
throw new Error('could not durably back up the grant being replaced');
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const rev = current.rev + 1;
|
|
409
|
+
await this.publish(rev, snapshot);
|
|
410
|
+
this.lastWrittenRev = rev;
|
|
411
|
+
// Mirror this exact revision, synchronously, before the publish queue moves on.
|
|
412
|
+
await this.mirrorRevision(rev, snapshot);
|
|
413
|
+
await this.pruneRevisions(rev);
|
|
414
|
+
if (needsBackup && opts.backup !== 'before' && !current.corrupt) {
|
|
415
|
+
// Not awaited: the new revision is already durable; history must never delay it.
|
|
416
|
+
void this.enqueueHistory(current.raw, reason);
|
|
417
|
+
}
|
|
418
|
+
return { rev, hash: sha256(snapshot) };
|
|
419
|
+
});
|
|
420
|
+
this.queue = run.catch(() => { });
|
|
421
|
+
return run;
|
|
422
|
+
}
|
|
423
|
+
async publish(rev, snapshot) {
|
|
424
|
+
await mkdirDurable(this.dir, this.revisionDir);
|
|
425
|
+
const target = join(this.revisionDir, revFile(rev));
|
|
426
|
+
const tmp = `${target}.${process.pid}.${randomUUID()}.tmp`;
|
|
427
|
+
const handle = await open(tmp, 'wx', 0o600);
|
|
428
|
+
try {
|
|
429
|
+
await handle.writeFile(snapshot, 'utf-8');
|
|
430
|
+
await handle.sync();
|
|
431
|
+
}
|
|
432
|
+
finally {
|
|
433
|
+
await handle.close();
|
|
434
|
+
}
|
|
435
|
+
try {
|
|
436
|
+
await this.beforePublish();
|
|
437
|
+
try {
|
|
438
|
+
// The revision appears complete and exactly once, or not at all.
|
|
439
|
+
await link(tmp, target);
|
|
440
|
+
}
|
|
441
|
+
catch (err) {
|
|
442
|
+
const code = err.code;
|
|
443
|
+
if (code === 'EEXIST')
|
|
444
|
+
throw new OAuthStoreConflictError(this.serverId);
|
|
445
|
+
if (code === 'EPERM' || code === 'ENOTSUP' || code === 'EOPNOTSUPP' || code === 'ENOSYS') {
|
|
446
|
+
throw new OAuthStoreUnsupportedError(`hard links are not supported (${code})`);
|
|
447
|
+
}
|
|
448
|
+
throw err;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
finally {
|
|
452
|
+
await unlink(tmp).catch(() => { });
|
|
453
|
+
}
|
|
454
|
+
await fsyncDir(this.revisionDir);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Rollback step (gateway stopped, writer lock held, parked successors already adopted): write
|
|
458
|
+
* the newest revision to `<id>.json` so an older Airlock reads the current grant, and verify it.
|
|
459
|
+
* A corrupt newest revision is never exported (the mirror is left untouched; the call fails).
|
|
460
|
+
*/
|
|
461
|
+
async exportLegacy() {
|
|
462
|
+
this.assertValidId();
|
|
463
|
+
const current = await this.read();
|
|
464
|
+
if (current.corrupt) {
|
|
465
|
+
throw new Error(current.rev === 0
|
|
466
|
+
? `legacy file ${this.serverId}.json is not valid JSON (no revisions exist); nothing exported`
|
|
467
|
+
: `newest revision ${current.rev} is not valid JSON; not exporting it`);
|
|
468
|
+
}
|
|
469
|
+
if (current.rev === 0 || current.raw === undefined)
|
|
470
|
+
return { rev: 0, exported: false };
|
|
471
|
+
await this.mirrorRevision(current.rev, current.raw, { required: true });
|
|
472
|
+
if ((await readFile(this.path, 'utf-8')) !== current.raw) {
|
|
473
|
+
throw new Error(`verification of ${this.path} failed`);
|
|
474
|
+
}
|
|
475
|
+
return { rev: current.rev, exported: true };
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Roll-forward step, run explicitly by the operator (gateway stopped, writer lock held), and
|
|
479
|
+
* only after an older Airlock actually ran against this store: publish the given `<id>.json`
|
|
480
|
+
* content (read by the caller before anything else ran) as the newest revision. This PROMOTES
|
|
481
|
+
* the legacy file over newer revisions (the superseded revision is backed up first).
|
|
482
|
+
*/
|
|
483
|
+
async importLegacy(raw) {
|
|
484
|
+
this.assertValidId();
|
|
485
|
+
const data = JSON.parse(raw);
|
|
486
|
+
return this.write(data, 'import-legacy', { backup: 'before' });
|
|
487
|
+
}
|
|
488
|
+
/** Test seam: write the `<id>.json` mirror. */
|
|
489
|
+
async writeMirrorFile(path, raw) {
|
|
490
|
+
await atomicWritePrivateFile(path, raw);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Write revision `rev` (content `raw`) to the `<id>.json` mirror if it is still the newest
|
|
494
|
+
* revision. Serialized per grant (see mirrorQueues). Best-effort unless `required`: the mirror
|
|
495
|
+
* is never read once revisions exist and never blocks anything.
|
|
496
|
+
*/
|
|
497
|
+
mirrorRevision(rev, raw, opts = {}) {
|
|
498
|
+
const previous = mirrorQueues.get(this.path) ?? Promise.resolve();
|
|
499
|
+
const run = previous.then(async () => {
|
|
500
|
+
try {
|
|
501
|
+
const top = (await this.revisions())[0];
|
|
502
|
+
if (top !== rev)
|
|
503
|
+
return; // a newer revision exists: its writer mirrors it
|
|
504
|
+
await this.writeMirrorFile(this.path, raw);
|
|
505
|
+
}
|
|
506
|
+
catch (err) {
|
|
507
|
+
if (opts.required)
|
|
508
|
+
throw err;
|
|
509
|
+
log.warn({ serverId: this.serverId, reason: err instanceof Error ? err.message : String(err) }, 'Could not update the OAuth grant mirror file (the grant revision itself is durable)');
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
const tail = run.catch(() => { });
|
|
513
|
+
mirrorQueues.set(this.path, tail);
|
|
514
|
+
void tail.then(() => {
|
|
515
|
+
if (mirrorQueues.get(this.path) === tail)
|
|
516
|
+
mirrorQueues.delete(this.path);
|
|
517
|
+
});
|
|
518
|
+
return run;
|
|
519
|
+
}
|
|
520
|
+
async pruneRevisions(latest) {
|
|
521
|
+
const revs = await this.revisions().catch(() => []);
|
|
522
|
+
for (const rev of revs) {
|
|
523
|
+
if (rev <= latest - REVISIONS_KEPT) {
|
|
524
|
+
await unlink(join(this.revisionDir, revFile(rev))).catch(() => { });
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/** Resolves once every scheduled backup has been written (or failed). */
|
|
529
|
+
async flushHistory() {
|
|
530
|
+
await this.queue;
|
|
531
|
+
await this.historyQueue;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Durably keep a copy of an arbitrary grant (e.g. a superseded refresh result) in history.
|
|
535
|
+
* Resolves true only when the copy is on disk (file and directory fsynced).
|
|
536
|
+
*/
|
|
537
|
+
archive(data, reason) {
|
|
538
|
+
if (this.mode === 'readonly')
|
|
539
|
+
return Promise.resolve(false);
|
|
540
|
+
return this.enqueueHistory(JSON.stringify(data, null, 2), reason);
|
|
541
|
+
}
|
|
542
|
+
/** Test seam: write one history file (atomic + durable). */
|
|
543
|
+
async writeHistoryFile(path, raw) {
|
|
544
|
+
await atomicWritePrivateFile(path, raw);
|
|
545
|
+
}
|
|
546
|
+
enqueueHistory(raw, reason) {
|
|
547
|
+
const run = this.historyQueue.then(async () => {
|
|
548
|
+
try {
|
|
549
|
+
await mkdirDurable(this.dir, this.historyDir);
|
|
550
|
+
const stamp = historyStamp();
|
|
551
|
+
let version = `${stamp}-${sanitizeId(reason)}`;
|
|
552
|
+
const existing = new Set(await readdir(this.historyDir).catch(() => []));
|
|
553
|
+
for (let i = 1; existing.has(`${version}.json`); i++) {
|
|
554
|
+
version = `${stamp}-${sanitizeId(reason)}-${i}`;
|
|
555
|
+
}
|
|
556
|
+
await this.writeHistoryFile(join(this.historyDir, `${version}.json`), raw);
|
|
557
|
+
await this.prune();
|
|
558
|
+
return true;
|
|
559
|
+
}
|
|
560
|
+
catch (err) {
|
|
561
|
+
log.warn({ serverId: this.serverId, reason: err instanceof Error ? err.message : String(err) }, 'Could not back up an OAuth grant version');
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
this.historyQueue = run;
|
|
566
|
+
return run;
|
|
567
|
+
}
|
|
568
|
+
async prune() {
|
|
569
|
+
const files = (await readdir(this.historyDir)).filter((f) => f.endsWith('.json')).sort();
|
|
570
|
+
const excess = files.length - HISTORY_LIMIT;
|
|
571
|
+
for (let i = 0; i < excess; i++) {
|
|
572
|
+
await unlink(join(this.historyDir, files[i])).catch(() => { });
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
/** Newest first. Never returns token values. */
|
|
576
|
+
async history() {
|
|
577
|
+
let files;
|
|
578
|
+
try {
|
|
579
|
+
files = (await readdir(this.historyDir)).filter((f) => f.endsWith('.json'));
|
|
580
|
+
}
|
|
581
|
+
catch {
|
|
582
|
+
return [];
|
|
583
|
+
}
|
|
584
|
+
files.sort().reverse();
|
|
585
|
+
const entries = [];
|
|
586
|
+
for (const file of files) {
|
|
587
|
+
const version = file.slice(0, -'.json'.length);
|
|
588
|
+
const fullPath = join(this.historyDir, file);
|
|
589
|
+
let summary;
|
|
590
|
+
try {
|
|
591
|
+
summary = summarizeGrant(JSON.parse(await readFile(fullPath, 'utf-8')));
|
|
592
|
+
}
|
|
593
|
+
catch {
|
|
594
|
+
summary = {
|
|
595
|
+
hasAccessToken: false,
|
|
596
|
+
hasRefreshToken: false,
|
|
597
|
+
hasClientInfo: false,
|
|
598
|
+
hasDiscovery: false,
|
|
599
|
+
pendingAuthorization: false,
|
|
600
|
+
unreadable: true,
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
const savedAt = (await stat(fullPath).catch(() => undefined))?.mtime.toISOString() ?? '';
|
|
604
|
+
const reason = version.split('-').slice(1).join('-');
|
|
605
|
+
entries.push({ version, savedAt, reason, summary });
|
|
606
|
+
}
|
|
607
|
+
return entries;
|
|
608
|
+
}
|
|
609
|
+
async readBackup(version) {
|
|
610
|
+
this.assertValidId();
|
|
611
|
+
if (!/^[A-Za-z0-9._-]+$/.test(version))
|
|
612
|
+
throw new Error(`Invalid backup version: ${version}`);
|
|
613
|
+
const raw = await readFile(join(this.historyDir, `${version}.json`), 'utf-8');
|
|
614
|
+
return JSON.parse(raw);
|
|
615
|
+
}
|
|
616
|
+
// ─── Orphaned successors ────────────────────────────────────────────────────────────────────
|
|
617
|
+
/**
|
|
618
|
+
* Durably park a successor grant that this process obtained but may not commit (it lost the
|
|
619
|
+
* writer lock, or its publication lost to a newer revision). The lock holder adopts it (see
|
|
620
|
+
* FileOAuthProvider). Needs no lock: every orphan gets its own file.
|
|
621
|
+
*/
|
|
622
|
+
async writeOrphan(grant, basis) {
|
|
623
|
+
this.assertValidId();
|
|
624
|
+
const file = `${historyStamp()}-${randomUUID()}.json`;
|
|
625
|
+
const body = {
|
|
626
|
+
savedAt: Date.now(),
|
|
627
|
+
predecessor: sha256(basis.presentedRefreshToken),
|
|
628
|
+
predecessorCredentials: basis.predecessorCredentials,
|
|
629
|
+
...(basis.predecessorRevision !== undefined
|
|
630
|
+
? { predecessorRevision: basis.predecessorRevision }
|
|
631
|
+
: {}),
|
|
632
|
+
...(basis.exchangeId ? { exchangeId: basis.exchangeId } : {}),
|
|
633
|
+
grant,
|
|
634
|
+
};
|
|
635
|
+
await mkdirDurable(this.dir, this.orphanDir);
|
|
636
|
+
await atomicWritePrivateFile(join(this.orphanDir, file), JSON.stringify(body, null, 2));
|
|
637
|
+
return file;
|
|
638
|
+
}
|
|
639
|
+
async listOrphans() {
|
|
640
|
+
let files;
|
|
641
|
+
try {
|
|
642
|
+
files = (await readdir(this.orphanDir)).filter((f) => f.endsWith('.json')).sort();
|
|
643
|
+
}
|
|
644
|
+
catch {
|
|
645
|
+
return [];
|
|
646
|
+
}
|
|
647
|
+
const out = [];
|
|
648
|
+
for (const file of files) {
|
|
649
|
+
try {
|
|
650
|
+
const parsed = JSON.parse(await readFile(join(this.orphanDir, file), 'utf-8'));
|
|
651
|
+
if (typeof parsed.predecessor === 'string' && parsed.grant)
|
|
652
|
+
out.push({ ...parsed, file });
|
|
653
|
+
}
|
|
654
|
+
catch {
|
|
655
|
+
// Unreadable orphan: leave it for the operator.
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return out;
|
|
659
|
+
}
|
|
660
|
+
async removeOrphan(file) {
|
|
661
|
+
await unlink(join(this.orphanDir, file)).catch(() => { });
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
// ─── Operator restore ───────────────────────────────────────────────────────────────────────────
|
|
665
|
+
/**
|
|
666
|
+
* Restore a backup. The caller must hold the writer lock (`airlock oauth restore` takes it, so a
|
|
667
|
+
* restore only runs while no gateway owns the store, or after an explicit `--force` takeover).
|
|
668
|
+
* Serialized with refresh/authorization in this process.
|
|
669
|
+
*/
|
|
670
|
+
export async function restoreGrant(dir, serverId, version) {
|
|
671
|
+
if (!isValidProviderId(serverId))
|
|
672
|
+
throw new OAuthStoreIdError(serverId);
|
|
673
|
+
const store = new OAuthGrantStore(serverId, 'writer', dir);
|
|
674
|
+
return withGrantOperation(store.path, async () => {
|
|
675
|
+
// Staged authorization state and exchange markers belong to the moment the backup was taken,
|
|
676
|
+
// not to the restored grant.
|
|
677
|
+
const { pending: _pending, exchange: _exchange, ...data } = await store.readBackup(version);
|
|
678
|
+
// A restore replaces a possibly valid grant: it must be durably backed up first.
|
|
679
|
+
await store.write(data, 'restore', { backup: 'before' });
|
|
680
|
+
log.warn({ serverId, version }, 'OAuth grant restored from backup by operator request');
|
|
681
|
+
return summarizeGrant(data);
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
//# sourceMappingURL=oauth-store.js.map
|