jazz-tools 2.0.0-alpha.60 → 2.0.0-alpha.61
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 +1 -1
- package/bin/jazz-tools.js +3 -0
- package/dist/_dev/native-account-session.d.ts +8 -1
- package/dist/_dev/native-account-session.d.ts.map +1 -1
- package/dist/_dev/native-account-session.js +10 -0
- package/dist/_dev/native-account-session.js.map +1 -1
- package/dist/accounts/account-manager-core.d.ts +6 -0
- package/dist/accounts/account-manager-core.d.ts.map +1 -1
- package/dist/accounts/account-manager-core.js +26 -2
- package/dist/accounts/account-manager-core.js.map +1 -1
- package/dist/accounts/enrollment.d.ts.map +1 -1
- package/dist/accounts/enrollment.js +11 -4
- package/dist/accounts/enrollment.js.map +1 -1
- package/dist/accounts/exports.d.ts +1 -2
- package/dist/accounts/exports.d.ts.map +1 -1
- package/dist/accounts/exports.js +4 -1
- package/dist/accounts/exports.js.map +1 -1
- package/dist/accounts/persistence.d.ts +8 -0
- package/dist/accounts/persistence.d.ts.map +1 -1
- package/dist/accounts/persistence.js +12 -0
- package/dist/accounts/persistence.js.map +1 -1
- package/dist/accounts/registry-client.d.ts +20 -0
- package/dist/accounts/registry-client.d.ts.map +1 -1
- package/dist/accounts/registry-client.js +34 -0
- package/dist/accounts/registry-client.js.map +1 -1
- package/dist/accounts/state.d.ts.map +1 -1
- package/dist/accounts/state.js +2 -1
- package/dist/accounts/state.js.map +1 -1
- package/dist/backend/create-jazz-session.d.ts +9 -7
- package/dist/backend/create-jazz-session.d.ts.map +1 -1
- package/dist/backend/create-jazz-session.js +55 -17
- package/dist/backend/create-jazz-session.js.map +1 -1
- package/dist/backend/create-jazz.d.ts +122 -34
- package/dist/backend/create-jazz.d.ts.map +1 -1
- package/dist/backend/create-jazz.js +396 -101
- package/dist/backend/create-jazz.js.map +1 -1
- package/dist/backend/early-db.d.ts.map +1 -1
- package/dist/backend/early-db.js +1 -0
- package/dist/backend/early-db.js.map +1 -1
- package/dist/backend/from-jwt.d.ts +2 -2
- package/dist/backend/from-jwt.d.ts.map +1 -1
- package/dist/backend/from-jwt.js +7 -1
- package/dist/backend/from-jwt.js.map +1 -1
- package/dist/backend/index.d.ts +2 -1
- package/dist/backend/index.d.ts.map +1 -1
- package/dist/backend/index.js +3 -1
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/inspect-ui.d.ts +14 -0
- package/dist/backend/inspect-ui.d.ts.map +1 -0
- package/dist/backend/inspect-ui.js +156 -0
- package/dist/backend/inspect-ui.js.map +1 -0
- package/dist/backend/inspect.d.ts +129 -0
- package/dist/backend/inspect.d.ts.map +1 -0
- package/dist/backend/inspect.js +763 -0
- package/dist/backend/inspect.js.map +1 -0
- package/dist/backend/inspector-ui/0.js +2 -0
- package/dist/backend/inspector-ui/1.js +2 -0
- package/dist/backend/inspector-ui/10.js +2 -0
- package/dist/backend/inspector-ui/11.js +2 -0
- package/dist/backend/inspector-ui/12.js +2 -0
- package/dist/backend/inspector-ui/13.js +2 -0
- package/dist/backend/inspector-ui/14.js +2 -0
- package/dist/backend/inspector-ui/15.js +2 -0
- package/dist/backend/inspector-ui/16.js +2 -0
- package/dist/backend/inspector-ui/17.js +2 -0
- package/dist/backend/inspector-ui/18.js +2 -0
- package/dist/backend/inspector-ui/19.js +2 -0
- package/dist/backend/inspector-ui/2.js +2 -0
- package/dist/backend/inspector-ui/20.js +2 -0
- package/dist/backend/inspector-ui/3.js +2 -0
- package/dist/backend/inspector-ui/4.js +2 -0
- package/dist/backend/inspector-ui/5.js +2 -0
- package/dist/backend/inspector-ui/6.js +2 -0
- package/dist/backend/inspector-ui/7.js +2 -0
- package/dist/backend/inspector-ui/8.js +2 -0
- package/dist/backend/inspector-ui/9.js +2 -0
- package/dist/backend/inspector-ui-files.d.ts +4 -0
- package/dist/backend/inspector-ui-files.d.ts.map +1 -0
- package/dist/backend/inspector-ui-files.js +25 -0
- package/dist/backend/session-expiry.d.ts +61 -0
- package/dist/backend/session-expiry.d.ts.map +1 -0
- package/dist/backend/session-expiry.js +102 -0
- package/dist/backend/session-expiry.js.map +1 -0
- package/dist/backend/upgrade-status.d.ts +19 -0
- package/dist/backend/upgrade-status.d.ts.map +1 -0
- package/dist/backend/upgrade-status.js +55 -0
- package/dist/backend/upgrade-status.js.map +1 -0
- package/dist/backend/vercel-sockets.d.ts +16 -0
- package/dist/backend/vercel-sockets.d.ts.map +1 -0
- package/dist/backend/vercel-sockets.js +24 -0
- package/dist/backend/vercel-sockets.js.map +1 -0
- package/dist/backend/vercel-store.d.ts.map +1 -1
- package/dist/backend/vercel-store.js +77 -10
- package/dist/backend/vercel-store.js.map +1 -1
- package/dist/classic-api.d.ts.map +1 -1
- package/dist/classic-api.js +36 -0
- package/dist/classic-api.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +30 -2
- package/dist/cli.js.map +1 -1
- package/dist/client/index.d.ts +2 -6
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -3
- package/dist/client/index.js.map +1 -1
- package/dist/cloud/credentials.d.ts +1 -1
- package/dist/cloud/credentials.d.ts.map +1 -1
- package/dist/cloud/credentials.js.map +1 -1
- package/dist/dev/catalogue.d.ts +12 -0
- package/dist/dev/catalogue.d.ts.map +1 -1
- package/dist/dev/catalogue.js +31 -0
- package/dist/dev/catalogue.js.map +1 -1
- package/dist/dev/inspector-overlay/embedded/assets/backend-DHeT1LCS.css +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/backend-Dt5FYVfX.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/{create-legacy-browser-delegate-X_T_QKCN.js → create-legacy-browser-delegate-Bf58kV5i.js} +1 -1
- package/dist/dev/inspector-overlay/embedded/assets/esm-BQhYkCKN.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/{esm-aRzpnC3u.js → esm-CI6IodCN.js} +1 -1
- package/dist/dev/inspector-overlay/embedded/assets/{esm-ezD5H765.js → esm-D5aLlEYl.js} +1 -1
- package/dist/dev/inspector-overlay/embedded/assets/{esm-7mP3GQX4.js → esm-D_R-EGgt.js} +1 -1
- package/dist/dev/inspector-overlay/embedded/assets/{esm-BX6IY2Mv.js → esm-WihpI9g6.js} +1 -1
- package/dist/dev/inspector-overlay/embedded/assets/index-CjhxdwQ7.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/jazz-broker-worker-CaVlHITU.js +3 -0
- package/dist/dev/inspector-overlay/embedded/assets/{jazz-broker-worker-XRRxJUcx.js → jazz-broker-worker-D-HQuhdu.js} +160 -557
- package/dist/dev/inspector-overlay/embedded/assets/jazz_wasm-t1Mm3faf.js +1 -0
- package/dist/dev/inspector-overlay/embedded/assets/{jazz_wasm_bg-KR7h3v27.wasm → jazz_wasm_bg-BazWJnU4.wasm} +0 -0
- package/dist/dev/inspector-overlay/embedded/assets/{index-C78Pprka.css → src-Cq8gSOLx.css} +1 -1
- package/dist/dev/inspector-overlay/embedded/assets/src-Dg6641Mj.js +22 -0
- package/dist/dev/inspector-overlay/embedded/assets/{trace-api-B5CaetI0.js → trace-api-BctnwbUf.js} +1 -1
- package/dist/dev/inspector-overlay/embedded/backend.html +16 -0
- package/dist/dev/inspector-overlay/embedded/embedded.html +3 -2
- package/dist/dev/inspector-overlay/host-bridge.d.ts.map +1 -1
- package/dist/dev/inspector-overlay/host-bridge.js +4 -1
- package/dist/dev/inspector-overlay/host-bridge.js.map +1 -1
- package/dist/dev/inspector-overlay/loader.d.ts +12 -1
- package/dist/dev/inspector-overlay/loader.d.ts.map +1 -1
- package/dist/dev/inspector-overlay/loader.js +31 -4
- package/dist/dev/inspector-overlay/loader.js.map +1 -1
- package/dist/drivers/schema-wire.d.ts +6 -2
- package/dist/drivers/schema-wire.d.ts.map +1 -1
- package/dist/drivers/schema-wire.js +6 -2
- package/dist/drivers/schema-wire.js.map +1 -1
- package/dist/effect/jazz.d.ts +12 -5
- package/dist/effect/jazz.d.ts.map +1 -1
- package/dist/effect/jazz.js +28 -5
- package/dist/effect/jazz.js.map +1 -1
- package/dist/expo/create-account-manager.d.ts +1 -1
- package/dist/expo/create-account-manager.d.ts.map +1 -1
- package/dist/expo/create-jazz-session.d.ts +37 -17
- package/dist/expo/create-jazz-session.d.ts.map +1 -1
- package/dist/expo/create-jazz-session.js +49 -10
- package/dist/expo/create-jazz-session.js.map +1 -1
- package/dist/expo/index.d.ts +5 -8
- package/dist/expo/index.d.ts.map +1 -1
- package/dist/expo/index.js +5 -7
- package/dist/expo/index.js.map +1 -1
- package/dist/expo/provider.d.ts +6 -3
- package/dist/expo/provider.d.ts.map +1 -1
- package/dist/expo/provider.js +7 -6
- package/dist/expo/provider.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/inspect/cli.d.ts +12 -0
- package/dist/inspect/cli.d.ts.map +1 -0
- package/dist/inspect/cli.js +292 -0
- package/dist/inspect/cli.js.map +1 -0
- package/dist/inspect/client.d.ts +60 -0
- package/dist/inspect/client.d.ts.map +1 -0
- package/dist/inspect/client.js +241 -0
- package/dist/inspect/client.js.map +1 -0
- package/dist/inspect/mcp.d.ts +17 -0
- package/dist/inspect/mcp.d.ts.map +1 -0
- package/dist/inspect/mcp.js +308 -0
- package/dist/inspect/mcp.js.map +1 -0
- package/dist/inspect/protocol.d.ts +218 -0
- package/dist/inspect/protocol.d.ts.map +1 -0
- package/dist/inspect/protocol.js +357 -0
- package/dist/inspect/protocol.js.map +1 -0
- package/dist/inspector/index.d.ts +10 -0
- package/dist/inspector/index.d.ts.map +1 -0
- package/dist/inspector/index.js +27 -0
- package/dist/inspector/index.js.map +1 -0
- package/dist/migrations.d.ts +1 -1
- package/dist/migrations.js +1 -1
- package/dist/migrations.js.map +1 -1
- package/dist/react/index.d.ts +4 -9
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +4 -6
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider-props.d.ts +7 -0
- package/dist/react/provider-props.d.ts.map +1 -0
- package/dist/react/provider-props.js +15 -0
- package/dist/react/provider-props.js.map +1 -0
- package/dist/react/provider.d.ts +9 -15
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js +19 -38
- package/dist/react/provider.js.map +1 -1
- package/dist/react-core/index.d.ts +3 -4
- package/dist/react-core/index.d.ts.map +1 -1
- package/dist/react-core/index.js +8 -4
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/provider.d.ts +6 -6
- package/dist/react-core/provider.d.ts.map +1 -1
- package/dist/react-core/provider.js +5 -6
- package/dist/react-core/provider.js.map +1 -1
- package/dist/react-core/session.d.ts +41 -33
- package/dist/react-core/session.d.ts.map +1 -1
- package/dist/react-core/session.js +41 -89
- package/dist/react-core/session.js.map +1 -1
- package/dist/react-native/account-session.js +1 -1
- package/dist/react-native/account-session.js.map +1 -1
- package/dist/react-native/create-account-manager.d.ts +1 -1
- package/dist/react-native/create-account-manager.d.ts.map +1 -1
- package/dist/react-native/create-jazz-session.d.ts +37 -17
- package/dist/react-native/create-jazz-session.d.ts.map +1 -1
- package/dist/react-native/create-jazz-session.js +49 -10
- package/dist/react-native/create-jazz-session.js.map +1 -1
- package/dist/react-native/index.d.ts +5 -10
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +5 -7
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/native-foreground-db.d.ts +7 -0
- package/dist/react-native/native-foreground-db.d.ts.map +1 -1
- package/dist/react-native/native-foreground-db.js +29 -0
- package/dist/react-native/native-foreground-db.js.map +1 -1
- package/dist/react-native/provider.d.ts +14 -19
- package/dist/react-native/provider.d.ts.map +1 -1
- package/dist/react-native/provider.js +19 -18
- package/dist/react-native/provider.js.map +1 -1
- package/dist/react-native/runtime-source.js +1 -1
- package/dist/react-native/runtime-source.js.map +1 -1
- package/dist/removed-api.d.ts +87 -0
- package/dist/removed-api.d.ts.map +1 -0
- package/dist/removed-api.js +95 -0
- package/dist/removed-api.js.map +1 -0
- package/dist/runtime/auth-secret-store.d.ts +0 -44
- package/dist/runtime/auth-secret-store.d.ts.map +1 -1
- package/dist/runtime/auth-secret-store.js +1 -103
- package/dist/runtime/auth-secret-store.js.map +1 -1
- package/dist/runtime/client.d.ts +10 -4
- package/dist/runtime/client.d.ts.map +1 -1
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/connection-manager/browser-connection-manager.d.ts +4 -1
- package/dist/runtime/connection-manager/browser-connection-manager.d.ts.map +1 -1
- package/dist/runtime/connection-manager/browser-connection-manager.js +33 -2
- package/dist/runtime/connection-manager/browser-connection-manager.js.map +1 -1
- package/dist/runtime/connection-manager/types.d.ts +17 -2
- package/dist/runtime/connection-manager/types.d.ts.map +1 -1
- package/dist/runtime/connection-manager/types.js +19 -5
- package/dist/runtime/connection-manager/types.js.map +1 -1
- package/dist/runtime/credentialed-transport.d.ts +5 -2
- package/dist/runtime/credentialed-transport.d.ts.map +1 -1
- package/dist/runtime/credentialed-transport.js +12 -3
- package/dist/runtime/credentialed-transport.js.map +1 -1
- package/dist/runtime/db-replaced-error.d.ts +3 -1
- package/dist/runtime/db-replaced-error.d.ts.map +1 -1
- package/dist/runtime/db-replaced-error.js +4 -2
- package/dist/runtime/db-replaced-error.js.map +1 -1
- package/dist/runtime/db.d.ts +35 -7
- package/dist/runtime/db.d.ts.map +1 -1
- package/dist/runtime/db.js +65 -9
- package/dist/runtime/db.js.map +1 -1
- package/dist/runtime/index.d.ts +3 -4
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/native-artifact-fingerprint-napi.d.ts +1 -1
- package/dist/runtime/native-artifact-fingerprint-napi.js +1 -1
- package/dist/runtime/native-artifact-fingerprint-napi.js.map +1 -1
- package/dist/runtime/native-artifact-fingerprint-wasm.d.ts +1 -1
- package/dist/runtime/native-artifact-fingerprint-wasm.js +1 -1
- package/dist/runtime/native-artifact-fingerprint-wasm.js.map +1 -1
- package/dist/runtime/native-artifact-fingerprints.d.ts +2 -2
- package/dist/runtime/native-runtime/attached-browser-worker-connection.d.ts +3 -1
- package/dist/runtime/native-runtime/attached-browser-worker-connection.d.ts.map +1 -1
- package/dist/runtime/native-runtime/attached-browser-worker-connection.js.map +1 -1
- package/dist/runtime/native-runtime/broker-worker-load-failure.d.ts +31 -0
- package/dist/runtime/native-runtime/broker-worker-load-failure.d.ts.map +1 -0
- package/dist/runtime/native-runtime/broker-worker-load-failure.js +66 -0
- package/dist/runtime/native-runtime/broker-worker-load-failure.js.map +1 -0
- package/dist/runtime/native-runtime/browser-follower-connection.d.ts +5 -1
- package/dist/runtime/native-runtime/browser-follower-connection.d.ts.map +1 -1
- package/dist/runtime/native-runtime/browser-follower-connection.js +4 -3
- package/dist/runtime/native-runtime/browser-follower-connection.js.map +1 -1
- package/dist/runtime/native-runtime/browser-shared-worker-connection.d.ts +3 -1
- package/dist/runtime/native-runtime/browser-shared-worker-connection.d.ts.map +1 -1
- package/dist/runtime/native-runtime/browser-shared-worker-connection.js +55 -4
- package/dist/runtime/native-runtime/browser-shared-worker-connection.js.map +1 -1
- package/dist/runtime/native-runtime/browser-worker-protocol.d.ts +5 -0
- package/dist/runtime/native-runtime/browser-worker-protocol.d.ts.map +1 -1
- package/dist/runtime/native-runtime/browser-worker-protocol.js.map +1 -1
- package/dist/runtime/native-runtime/http-stream-socket.d.ts +25 -7
- package/dist/runtime/native-runtime/http-stream-socket.d.ts.map +1 -1
- package/dist/runtime/native-runtime/http-stream-socket.js +56 -29
- package/dist/runtime/native-runtime/http-stream-socket.js.map +1 -1
- package/dist/runtime/native-runtime/native-runtime-adapter.d.ts +13 -5
- package/dist/runtime/native-runtime/native-runtime-adapter.d.ts.map +1 -1
- package/dist/runtime/native-runtime/native-runtime-adapter.js +38 -10
- package/dist/runtime/native-runtime/native-runtime-adapter.js.map +1 -1
- package/dist/runtime/native-runtime/websocket.d.ts +13 -0
- package/dist/runtime/native-runtime/websocket.d.ts.map +1 -1
- package/dist/runtime/native-runtime/websocket.js +23 -4
- package/dist/runtime/native-runtime/websocket.js.map +1 -1
- package/dist/runtime/page-handle.d.ts +87 -0
- package/dist/runtime/page-handle.d.ts.map +1 -0
- package/dist/runtime/page-handle.js +144 -0
- package/dist/runtime/page-handle.js.map +1 -0
- package/dist/runtime/removed-provider-props.d.ts +17 -0
- package/dist/runtime/removed-provider-props.d.ts.map +1 -0
- package/dist/runtime/removed-provider-props.js +16 -0
- package/dist/runtime/removed-provider-props.js.map +1 -0
- package/dist/runtime/runtime-source.d.ts +4 -1
- package/dist/runtime/runtime-source.d.ts.map +1 -1
- package/dist/runtime/runtime-source.js.map +1 -1
- package/dist/runtime/store-held-by-another-tab-error.d.ts +11 -0
- package/dist/runtime/store-held-by-another-tab-error.d.ts.map +1 -1
- package/dist/runtime/store-held-by-another-tab-error.js +11 -0
- package/dist/runtime/store-held-by-another-tab-error.js.map +1 -1
- package/dist/runtime/sync-status.d.ts +60 -1
- package/dist/runtime/sync-status.d.ts.map +1 -1
- package/dist/runtime/sync-status.js +64 -4
- package/dist/runtime/sync-status.js.map +1 -1
- package/dist/session/backend-watch.d.ts +53 -14
- package/dist/session/backend-watch.d.ts.map +1 -1
- package/dist/session/backend-watch.js +99 -22
- package/dist/session/backend-watch.js.map +1 -1
- package/dist/session/config-options.d.ts +15 -0
- package/dist/session/config-options.d.ts.map +1 -0
- package/dist/session/config-options.js +55 -0
- package/dist/session/config-options.js.map +1 -0
- package/dist/session/consumer.d.ts +1 -1
- package/dist/session/consumer.js +1 -1
- package/dist/session/consumer.js.map +1 -1
- package/dist/session/create-jazz-session.d.ts +57 -21
- package/dist/session/create-jazz-session.d.ts.map +1 -1
- package/dist/session/create-jazz-session.js +257 -58
- package/dist/session/create-jazz-session.js.map +1 -1
- package/dist/session/follow-user.d.ts +17 -7
- package/dist/session/follow-user.d.ts.map +1 -1
- package/dist/session/follow-user.js +23 -2
- package/dist/session/follow-user.js.map +1 -1
- package/dist/session/jazz-session.d.ts +164 -0
- package/dist/session/jazz-session.d.ts.map +1 -0
- package/dist/session/jazz-session.js +432 -0
- package/dist/session/jazz-session.js.map +1 -0
- package/dist/session/left-behind-replicas.d.ts +8 -1
- package/dist/session/left-behind-replicas.d.ts.map +1 -1
- package/dist/session/left-behind-replicas.js +21 -4
- package/dist/session/left-behind-replicas.js.map +1 -1
- package/dist/session/state.d.ts +20 -13
- package/dist/session/state.d.ts.map +1 -1
- package/dist/session/state.js +68 -23
- package/dist/session/state.js.map +1 -1
- package/dist/solid/index.d.ts +3 -9
- package/dist/solid/index.d.ts.map +1 -1
- package/dist/solid/index.js +8 -11
- package/dist/solid/index.ssr.js +3 -6
- package/dist/solid/provider.d.ts +3 -3
- package/dist/solid/provider.d.ts.map +1 -1
- package/dist/solid/provider.js +23 -39
- package/dist/solid/provider.js.map +1 -1
- package/dist/solid/provider.ssr.js +6 -23
- package/dist/solid/provider.ssr.js.map +1 -1
- package/dist/solid/session.d.ts +42 -12
- package/dist/solid/session.d.ts.map +1 -1
- package/dist/solid/session.js +82 -35
- package/dist/solid/session.js.map +1 -1
- package/dist/solid/session.ssr.js +85 -22
- package/dist/solid/session.ssr.js.map +1 -1
- package/dist/svelte/JazzProvider.svelte +54 -20
- package/dist/svelte/JazzProvider.svelte.d.ts +14 -4
- package/dist/svelte/JazzProvider.svelte.d.ts.map +1 -1
- package/dist/svelte/JazzSvelteClientProvider.svelte +1 -7
- package/dist/svelte/JazzSvelteClientProvider.svelte.d.ts +0 -1
- package/dist/svelte/JazzSvelteClientProvider.svelte.d.ts.map +1 -1
- package/dist/svelte/JazzSvelteProvider.svelte +5 -4
- package/dist/svelte/JazzSvelteProvider.svelte.d.ts +2 -2
- package/dist/svelte/JazzSvelteProvider.svelte.d.ts.map +1 -1
- package/dist/svelte/index.d.ts +4 -12
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +4 -8
- package/dist/svelte/session-state.d.ts +14 -4
- package/dist/svelte/session-state.d.ts.map +1 -1
- package/dist/svelte/session-state.js +10 -4
- package/dist/testing/policy-test-app.d.ts.map +1 -1
- package/dist/testing/policy-test-app.js +5 -4
- package/dist/testing/policy-test-app.js.map +1 -1
- package/dist/testing/test-jazz.d.ts +2 -2
- package/dist/testing/test-jazz.d.ts.map +1 -1
- package/dist/testing/test-jazz.js +5 -2
- package/dist/testing/test-jazz.js.map +1 -1
- package/dist/thin/index.d.ts +7 -10
- package/dist/thin/index.d.ts.map +1 -1
- package/dist/thin/index.js +28 -11
- package/dist/thin/index.js.map +1 -1
- package/dist/thin/thin-runtime.d.ts +22 -2
- package/dist/thin/thin-runtime.d.ts.map +1 -1
- package/dist/thin/thin-runtime.js +157 -24
- package/dist/thin/thin-runtime.js.map +1 -1
- package/dist/vue/index.d.ts +3 -8
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +3 -5
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/provider.d.ts +6 -27
- package/dist/vue/provider.d.ts.map +1 -1
- package/dist/vue/provider.js +10 -19
- package/dist/vue/provider.js.map +1 -1
- package/dist/vue/session.d.ts +29 -28
- package/dist/vue/session.d.ts.map +1 -1
- package/dist/vue/session.js +79 -22
- package/dist/vue/session.js.map +1 -1
- package/dist/window-client-storage.d.ts +4 -30
- package/dist/window-client-storage.d.ts.map +1 -1
- package/dist/window-client-storage.js +2 -63
- package/dist/window-client-storage.js.map +1 -1
- package/dist/worker/jazz-broker-worker-core.d.ts.map +1 -1
- package/dist/worker/jazz-broker-worker-core.js +16 -19
- package/dist/worker/jazz-broker-worker-core.js.map +1 -1
- package/dist/worker/jazz-broker-worker.js +160 -557
- package/dist/worker/jazz_wasm_bg.wasm +0 -0
- package/dist/worker/runtime-admission.d.ts +19 -0
- package/dist/worker/runtime-admission.d.ts.map +1 -0
- package/dist/worker/runtime-admission.js +34 -0
- package/dist/worker/runtime-admission.js.map +1 -0
- package/package.json +18 -5
- package/dist/backend/session-recheck.d.ts +0 -18
- package/dist/backend/session-recheck.d.ts.map +0 -1
- package/dist/backend/session-recheck.js +0 -57
- package/dist/backend/session-recheck.js.map +0 -1
- package/dist/dev/inspector-overlay/embedded/assets/esm-k3rsq4Gn.js +0 -1
- package/dist/dev/inspector-overlay/embedded/assets/index-C-btvLcw.js +0 -20
- package/dist/dev/inspector-overlay/embedded/assets/jazz-broker-worker-CAMcDeUa.js +0 -3
- package/dist/dev/inspector-overlay/embedded/assets/jazz_wasm-Cc71x_6y.js +0 -1
- package/dist/dev/inspector-overlay/serve.d.ts +0 -46
- package/dist/dev/inspector-overlay/serve.d.ts.map +0 -1
- package/dist/dev/inspector-overlay/serve.js +0 -131
- package/dist/dev/inspector-overlay/serve.js.map +0 -1
- package/dist/dev-tools/auto-attach.d.ts +0 -11
- package/dist/dev-tools/auto-attach.d.ts.map +0 -1
- package/dist/dev-tools/auto-attach.js +0 -26
- package/dist/dev-tools/auto-attach.js.map +0 -1
- package/dist/expo/auth-secret-store.d.ts +0 -37
- package/dist/expo/auth-secret-store.d.ts.map +0 -1
- package/dist/expo/auth-secret-store.js +0 -139
- package/dist/expo/auth-secret-store.js.map +0 -1
- package/dist/expo/session.d.ts +0 -10
- package/dist/expo/session.d.ts.map +0 -1
- package/dist/expo/session.js +0 -5
- package/dist/expo/session.js.map +0 -1
- package/dist/expo/use-local-first-auth.d.ts +0 -12
- package/dist/expo/use-local-first-auth.d.ts.map +0 -1
- package/dist/expo/use-local-first-auth.js +0 -13
- package/dist/expo/use-local-first-auth.js.map +0 -1
- package/dist/react/devtools-auto-attach.d.ts +0 -2
- package/dist/react/devtools-auto-attach.d.ts.map +0 -1
- package/dist/react/devtools-auto-attach.js +0 -11
- package/dist/react/devtools-auto-attach.js.map +0 -1
- package/dist/react/session.d.ts +0 -18
- package/dist/react/session.d.ts.map +0 -1
- package/dist/react/session.js +0 -28
- package/dist/react/session.js.map +0 -1
- package/dist/react/use-local-first-auth.d.ts +0 -11
- package/dist/react/use-local-first-auth.d.ts.map +0 -1
- package/dist/react/use-local-first-auth.js +0 -13
- package/dist/react/use-local-first-auth.js.map +0 -1
- package/dist/react-core/app.d.ts +0 -31
- package/dist/react-core/app.d.ts.map +0 -1
- package/dist/react-core/app.js +0 -65
- package/dist/react-core/app.js.map +0 -1
- package/dist/react-core/use-account-state.d.ts +0 -4
- package/dist/react-core/use-account-state.d.ts.map +0 -1
- package/dist/react-core/use-account-state.js +0 -6
- package/dist/react-core/use-account-state.js.map +0 -1
- package/dist/react-core/use-local-first-auth.d.ts +0 -12
- package/dist/react-core/use-local-first-auth.d.ts.map +0 -1
- package/dist/react-core/use-local-first-auth.js +0 -14
- package/dist/react-core/use-local-first-auth.js.map +0 -1
- package/dist/react-native/session.d.ts +0 -10
- package/dist/react-native/session.d.ts.map +0 -1
- package/dist/react-native/session.js +0 -5
- package/dist/react-native/session.js.map +0 -1
- package/dist/react-native/use-local-first-auth.d.ts +0 -15
- package/dist/react-native/use-local-first-auth.d.ts.map +0 -1
- package/dist/react-native/use-local-first-auth.js +0 -14
- package/dist/react-native/use-local-first-auth.js.map +0 -1
- package/dist/runtime/local-first-auth-controller.d.ts +0 -29
- package/dist/runtime/local-first-auth-controller.d.ts.map +0 -1
- package/dist/runtime/local-first-auth-controller.js +0 -101
- package/dist/runtime/local-first-auth-controller.js.map +0 -1
- package/dist/session/app.d.ts +0 -58
- package/dist/session/app.d.ts.map +0 -1
- package/dist/session/app.js +0 -325
- package/dist/session/app.js.map +0 -1
- package/dist/session/create-jazz-app.d.ts +0 -11
- package/dist/session/create-jazz-app.d.ts.map +0 -1
- package/dist/session/create-jazz-app.js +0 -11
- package/dist/session/create-jazz-app.js.map +0 -1
- package/dist/solid/app.d.ts +0 -30
- package/dist/solid/app.d.ts.map +0 -1
- package/dist/solid/app.js +0 -95
- package/dist/solid/app.js.map +0 -1
- package/dist/solid/app.ssr.js +0 -109
- package/dist/solid/app.ssr.js.map +0 -1
- package/dist/solid/create-account-state.d.ts +0 -4
- package/dist/solid/create-account-state.d.ts.map +0 -1
- package/dist/solid/create-account-state.js +0 -10
- package/dist/solid/create-account-state.js.map +0 -1
- package/dist/solid/create-account-state.ssr.js +0 -12
- package/dist/solid/create-account-state.ssr.js.map +0 -1
- package/dist/solid/use-local-first-auth.d.ts +0 -11
- package/dist/solid/use-local-first-auth.d.ts.map +0 -1
- package/dist/solid/use-local-first-auth.js +0 -30
- package/dist/solid/use-local-first-auth.js.map +0 -1
- package/dist/solid/use-local-first-auth.ssr.js +0 -31
- package/dist/solid/use-local-first-auth.ssr.js.map +0 -1
- package/dist/svelte/JazzSessionClientProvider.svelte +0 -42
- package/dist/svelte/JazzSessionClientProvider.svelte.d.ts +0 -13
- package/dist/svelte/JazzSessionClientProvider.svelte.d.ts.map +0 -1
- package/dist/svelte/JazzSessionProvider.svelte +0 -68
- package/dist/svelte/JazzSessionProvider.svelte.d.ts +0 -19
- package/dist/svelte/JazzSessionProvider.svelte.d.ts.map +0 -1
- package/dist/svelte/account-state.d.ts +0 -5
- package/dist/svelte/account-state.d.ts.map +0 -1
- package/dist/svelte/account-state.js +0 -9
- package/dist/svelte/auth-state.d.ts +0 -23
- package/dist/svelte/auth-state.d.ts.map +0 -1
- package/dist/svelte/auth-state.js +0 -16
- package/dist/svelte/local-first-auth.svelte.d.ts +0 -50
- package/dist/svelte/local-first-auth.svelte.d.ts.map +0 -1
- package/dist/svelte/local-first-auth.svelte.js +0 -58
- package/dist/vue/app.d.ts +0 -76
- package/dist/vue/app.d.ts.map +0 -1
- package/dist/vue/app.js +0 -100
- package/dist/vue/app.js.map +0 -1
- package/dist/vue/use-account-state.d.ts +0 -5
- package/dist/vue/use-account-state.d.ts.map +0 -1
- package/dist/vue/use-account-state.js +0 -10
- package/dist/vue/use-account-state.js.map +0 -1
- package/dist/vue/use-local-first-auth.d.ts +0 -53
- package/dist/vue/use-local-first-auth.d.ts.map +0 -1
- package/dist/vue/use-local-first-auth.js +0 -67
- package/dist/vue/use-local-first-auth.js.map +0 -1
- /package/dist/dev/inspector-overlay/embedded/assets/{esm-CH5eVyQQ.js → esm-xNe3wI_B.js} +0 -0
- /package/dist/dev/inspector-overlay/embedded/assets/{node-foreground-node-lease.browser-Bm3gYjlT.js → node-foreground-node-lease.browser-CH8w-D6S.js} +0 -0
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
// The Inspector and agent debug access, served by the app's own backend.
|
|
2
|
+
//
|
|
3
|
+
// Every way in ends here: the Inspector UI the backend serves, the
|
|
4
|
+
// `jazz-tools inspect` CLI and the `jazz-tools inspect mcp` server all call the one
|
|
5
|
+
// JSON API at `<basePath>/inspect/api`. A request is let in by exactly one of:
|
|
6
|
+
//
|
|
7
|
+
// - the app's `inspect` hook, which decides from the request (usually the
|
|
8
|
+
// person's own sign-in, or an infrastructure gate in front of the app) who
|
|
9
|
+
// is inspecting and whether they may write;
|
|
10
|
+
// - an agent token a person minted after passing the hook, which is
|
|
11
|
+
// time-limited, read-only unless the person allowed writes, can be limited
|
|
12
|
+
// to some tables, and has redacted columns hidden;
|
|
13
|
+
// - with no hook at all, the local development default: a request from this
|
|
14
|
+
// machine to a backend running with NODE_ENV=development.
|
|
15
|
+
//
|
|
16
|
+
// Whoever is let in reads and writes with the backend's own authority (every
|
|
17
|
+
// row, permissions not checked) unless they ask to act as a user. That is
|
|
18
|
+
// the point of the Inspector, and it is why the hook must be narrow.
|
|
19
|
+
import { NoJazzAccountError } from "./no-account-error.js";
|
|
20
|
+
import { createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
21
|
+
import { historySourceTable, historyTableName } from "../runtime/history-relation.js";
|
|
22
|
+
import { INSPECT_API_PATH, INSPECT_ERRORS, INSPECT_PATH, INSPECT_PROTOCOL_VERSION, INSPECT_TOKEN_PREFIX, InspectError, MAX_ANSWER_BYTES, buildQueryJson, fromJsonForColumn, inspectorLink, isLoopbackHost, readsClaims, rowLimit, toJsonValue, } from "../inspect/protocol.js";
|
|
23
|
+
const DEFAULT_TOKEN_TTL_SECONDS = 3600;
|
|
24
|
+
const DEFAULT_MAX_TOKEN_TTL_SECONDS = 24 * 3600;
|
|
25
|
+
const MAX_REQUEST_BYTES = 1024 * 1024;
|
|
26
|
+
const REDACTED = "[redacted]";
|
|
27
|
+
const PROVENANCE = ["$createdBy", "$createdAt", "$updatedBy", "$updatedAt"];
|
|
28
|
+
function defaultAudit(event) {
|
|
29
|
+
const parts = [
|
|
30
|
+
`jazz inspect: ${event.by} (${event.via})`,
|
|
31
|
+
event.op,
|
|
32
|
+
event.table,
|
|
33
|
+
event.as && `as ${event.as}`,
|
|
34
|
+
event.rows !== undefined && `${event.rows} row(s)`,
|
|
35
|
+
event.error && `refused: ${event.error}`,
|
|
36
|
+
].filter(Boolean);
|
|
37
|
+
console.info(parts.join(" "));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check `options` and read them as the Inspector applies them. createJazz
|
|
41
|
+
* calls it when it starts and on each reload, so bad options fail there,
|
|
42
|
+
* not on the next Inspector call.
|
|
43
|
+
*/
|
|
44
|
+
export function inspectorSettings(options) {
|
|
45
|
+
const maxTtl = options.maxTokenTtlSeconds ?? DEFAULT_MAX_TOKEN_TTL_SECONDS;
|
|
46
|
+
if (!Number.isSafeInteger(maxTtl) || maxTtl < 60) {
|
|
47
|
+
throw new Error("createJazz: inspector.maxTokenTtlSeconds must be at least 60");
|
|
48
|
+
}
|
|
49
|
+
let issuedAfter;
|
|
50
|
+
if (options.tokensIssuedAfter !== undefined) {
|
|
51
|
+
const at = new Date(options.tokensIssuedAfter).getTime();
|
|
52
|
+
if (Number.isNaN(at)) {
|
|
53
|
+
throw new Error("createJazz: inspector.tokensIssuedAfter must be a date");
|
|
54
|
+
}
|
|
55
|
+
issuedAfter = Math.floor(at / 1000);
|
|
56
|
+
}
|
|
57
|
+
if (options.tokenSecret !== undefined && !options.tokenSecret.trim()) {
|
|
58
|
+
throw new Error("createJazz: inspector.tokenSecret is empty");
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
redact: new Map(Object.entries(options.redact ?? {}).map(([table, columns]) => [table, new Set(columns)])),
|
|
62
|
+
audit: options.audit ?? defaultAudit,
|
|
63
|
+
issuedAfter,
|
|
64
|
+
maxTtl,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function createInspector(deps) {
|
|
68
|
+
const now = deps.now ?? (() => Date.now());
|
|
69
|
+
const env = deps.env ?? process.env;
|
|
70
|
+
// The options follow a reload of createJazz: they are read again whenever
|
|
71
|
+
// the options object changes.
|
|
72
|
+
let settingsOf;
|
|
73
|
+
function settings() {
|
|
74
|
+
const options = deps.options;
|
|
75
|
+
if (settingsOf?.options !== options) {
|
|
76
|
+
settingsOf = { options, settings: inspectorSettings(options) };
|
|
77
|
+
}
|
|
78
|
+
return settingsOf.settings;
|
|
79
|
+
}
|
|
80
|
+
settings();
|
|
81
|
+
const audit = (event) => settings().audit(event);
|
|
82
|
+
// The signing key follows the secret: a reload that rotates it revokes
|
|
83
|
+
// every token signed with the old one.
|
|
84
|
+
let keyOf;
|
|
85
|
+
async function tokenKey() {
|
|
86
|
+
const secret = await deps.tokenSecret();
|
|
87
|
+
if (secret === null)
|
|
88
|
+
return null;
|
|
89
|
+
if (keyOf?.secret !== secret) {
|
|
90
|
+
keyOf = {
|
|
91
|
+
secret,
|
|
92
|
+
key: createHmac("sha256", secret).update(`jazz-inspect-token-v1\0${deps.appId}`).digest(),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return keyOf.key;
|
|
96
|
+
}
|
|
97
|
+
// ---------------------------------------------------------------- admission
|
|
98
|
+
/**
|
|
99
|
+
* The local development default: no hook, NODE_ENV=development, and a
|
|
100
|
+
* request from this machine. "This machine" is the socket's peer address,
|
|
101
|
+
* which only a host that hands Jazz its Node request knows (`attach()`,
|
|
102
|
+
* `nodeHandler`). The Host header can't stand in for it: anyone who reaches
|
|
103
|
+
* a dev server listening on every interface (as `next dev` does) can send
|
|
104
|
+
* `Host: localhost`. So on other hosts the default is off, and says so.
|
|
105
|
+
*/
|
|
106
|
+
function devAllowed(request) {
|
|
107
|
+
if (env.NODE_ENV !== "development")
|
|
108
|
+
return false;
|
|
109
|
+
// A proxy in front of the backend makes every request look local.
|
|
110
|
+
for (const header of ["x-forwarded-for", "x-forwarded-host", "x-real-ip", "forwarded"]) {
|
|
111
|
+
if (request.headers.has(header))
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
// A browser names the page a request comes from. A dev proxy that adds
|
|
115
|
+
// no forwarding headers (Vite's `server.proxy` with `changeOrigin`, on a
|
|
116
|
+
// dev server started with `--host`) passes another machine's request on
|
|
117
|
+
// from 127.0.0.1 with a loopback Host, but keeps the browser's Origin
|
|
118
|
+
// and Sec-Fetch-Site: only a page on this machine is let in.
|
|
119
|
+
const origin = request.headers.get("origin");
|
|
120
|
+
if (origin !== null) {
|
|
121
|
+
let originHost;
|
|
122
|
+
try {
|
|
123
|
+
originHost = new URL(origin).hostname;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (!isLoopbackHost(originHost))
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
if (request.headers.get("sec-fetch-site") === "cross-site")
|
|
132
|
+
return false;
|
|
133
|
+
const remote = deps.remoteAddress(request);
|
|
134
|
+
if (remote === undefined)
|
|
135
|
+
return "no_peer";
|
|
136
|
+
if (!isLoopbackAddress(remote))
|
|
137
|
+
return false;
|
|
138
|
+
const host = request.headers.get("host") ?? new URL(request.url).host;
|
|
139
|
+
let hostname;
|
|
140
|
+
try {
|
|
141
|
+
hostname = new URL(`http://${host}`).hostname;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return isLoopbackHost(hostname);
|
|
147
|
+
}
|
|
148
|
+
async function admit(request) {
|
|
149
|
+
const authorization = request.headers.get("authorization");
|
|
150
|
+
if (authorization?.startsWith(`Bearer ${INSPECT_TOKEN_PREFIX}`)) {
|
|
151
|
+
return verifyToken(authorization.slice("Bearer ".length));
|
|
152
|
+
}
|
|
153
|
+
if (deps.hook) {
|
|
154
|
+
let grant;
|
|
155
|
+
try {
|
|
156
|
+
grant = await deps.hook(request);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
// Its reason is the app's (a sign-in service's error, a stack), and
|
|
160
|
+
// this caller isn't let in: it goes to the log, not the answer.
|
|
161
|
+
console.error("jazz inspect: the app's inspect hook threw", error);
|
|
162
|
+
throw new InspectError("failed", "the app's inspect hook failed; the backend's log has the error");
|
|
163
|
+
}
|
|
164
|
+
if (!grant)
|
|
165
|
+
throw new InspectError("unauthorized", "the app's inspect hook refused this request");
|
|
166
|
+
if (typeof grant.by !== "string" || !grant.by.trim()) {
|
|
167
|
+
throw new InspectError("failed", "the app's inspect hook returned a grant without `by`");
|
|
168
|
+
}
|
|
169
|
+
return { by: grant.by, via: "hook", write: grant.write === true };
|
|
170
|
+
}
|
|
171
|
+
const dev = devAllowed(request);
|
|
172
|
+
if (dev === true)
|
|
173
|
+
return { by: "local development", via: "dev", write: true };
|
|
174
|
+
if (dev === "no_peer") {
|
|
175
|
+
throw new InspectError("unauthorized", "Local inspection without an `inspect` hook is not supported on this host yet: it doesn't tell Jazz the request's peer address, and the Host header proves nothing (anyone who reaches a dev server listening on every interface can send `Host: localhost`). Serve Jazz through `attach()` or `nodeHandler`, or pass an `inspect` hook that names who may inspect from your own sign-in");
|
|
176
|
+
}
|
|
177
|
+
throw new InspectError("unauthorized", "Inspecting this app needs an `inspect` hook in createJazz (or, in local development, NODE_ENV=development and a request from this machine)");
|
|
178
|
+
}
|
|
179
|
+
async function mintToken(admitted, request) {
|
|
180
|
+
// A token is a person's delegation: another token can't make one.
|
|
181
|
+
if (admitted.via === "token") {
|
|
182
|
+
throw new InspectError("forbidden", "an agent token can't mint tokens; a person must approve");
|
|
183
|
+
}
|
|
184
|
+
if (request.write && !admitted.write) {
|
|
185
|
+
throw new InspectError("forbidden", "you may not write, so you can't grant writes");
|
|
186
|
+
}
|
|
187
|
+
const ttl = request.ttlSeconds ?? DEFAULT_TOKEN_TTL_SECONDS;
|
|
188
|
+
const { maxTtl } = settings();
|
|
189
|
+
if (!Number.isSafeInteger(ttl) || ttl < 60 || ttl > maxTtl) {
|
|
190
|
+
throw new InspectError("bad_request", `ttlSeconds must be between 60 and ${maxTtl}`);
|
|
191
|
+
}
|
|
192
|
+
const tables = request.tables;
|
|
193
|
+
if (tables !== undefined) {
|
|
194
|
+
if (!Array.isArray(tables) || tables.length === 0) {
|
|
195
|
+
throw new InspectError("bad_request", "tables must list at least one table");
|
|
196
|
+
}
|
|
197
|
+
const schema = deps.schema();
|
|
198
|
+
for (const table of tables) {
|
|
199
|
+
if (typeof table !== "string" || !Object.hasOwn(schema, table)) {
|
|
200
|
+
throw new InspectError("bad_request", `no table ${JSON.stringify(table)}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const key = await tokenKey();
|
|
205
|
+
if (!key) {
|
|
206
|
+
throw new InspectError("not_supported", "Agent tokens on this store need a signing secret shared by every backend instance: set `inspector: { tokenSecret }` in createJazz");
|
|
207
|
+
}
|
|
208
|
+
const iat = Math.floor(now() / 1000);
|
|
209
|
+
const claims = {
|
|
210
|
+
v: 1,
|
|
211
|
+
app: deps.appId,
|
|
212
|
+
by: admitted.by,
|
|
213
|
+
write: request.write === true,
|
|
214
|
+
...(tables ? { tables: [...new Set(tables)] } : {}),
|
|
215
|
+
...(request.label ? { label: String(request.label).slice(0, 200) } : {}),
|
|
216
|
+
iat,
|
|
217
|
+
exp: iat + ttl,
|
|
218
|
+
jti: randomUUID(),
|
|
219
|
+
};
|
|
220
|
+
const payload = Buffer.from(JSON.stringify(claims)).toString("base64url");
|
|
221
|
+
const mac = createHmac("sha256", key).update(payload).digest("base64url");
|
|
222
|
+
return {
|
|
223
|
+
token: `${INSPECT_TOKEN_PREFIX}${payload}.${mac}`,
|
|
224
|
+
expiresAt: claims.exp,
|
|
225
|
+
tokenId: claims.jti,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
async function verifyToken(token) {
|
|
229
|
+
const refused = (why) => new InspectError("unauthorized", `agent token refused: ${why}`);
|
|
230
|
+
const key = await tokenKey();
|
|
231
|
+
if (!key)
|
|
232
|
+
throw refused("this backend has no token signing secret");
|
|
233
|
+
const body = token.slice(INSPECT_TOKEN_PREFIX.length);
|
|
234
|
+
const [payload, mac, extra] = body.split(".");
|
|
235
|
+
if (!payload || !mac || extra !== undefined || body.length > 4096)
|
|
236
|
+
throw refused("malformed");
|
|
237
|
+
const expected = Buffer.from(createHmac("sha256", key).update(payload).digest("base64url"));
|
|
238
|
+
const given = Buffer.from(mac);
|
|
239
|
+
if (expected.length !== given.length || !timingSafeEqual(expected, given)) {
|
|
240
|
+
throw refused("not signed by this backend");
|
|
241
|
+
}
|
|
242
|
+
let claims;
|
|
243
|
+
try {
|
|
244
|
+
claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
throw refused("malformed");
|
|
248
|
+
}
|
|
249
|
+
const at = Math.floor(now() / 1000);
|
|
250
|
+
if (claims.v !== 1 || claims.app !== deps.appId)
|
|
251
|
+
throw refused("for another app");
|
|
252
|
+
if (typeof claims.exp !== "number" || claims.exp <= at)
|
|
253
|
+
throw refused("expired");
|
|
254
|
+
const { issuedAfter } = settings();
|
|
255
|
+
if (issuedAfter !== undefined && claims.iat < issuedAfter)
|
|
256
|
+
throw refused("revoked");
|
|
257
|
+
return {
|
|
258
|
+
by: claims.by,
|
|
259
|
+
via: "token",
|
|
260
|
+
write: claims.write === true,
|
|
261
|
+
...(claims.tables ? { tables: claims.tables } : {}),
|
|
262
|
+
expiresAt: claims.exp,
|
|
263
|
+
tokenId: claims.jti,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
// ---------------------------------------------------------------- reads and writes
|
|
267
|
+
function inspectorUrl(request) {
|
|
268
|
+
if (deps.publicUrls[0])
|
|
269
|
+
return `${deps.publicUrls[0]}${INSPECT_PATH}/`;
|
|
270
|
+
const url = new URL(request.url);
|
|
271
|
+
return `${url.origin}${deps.basePath}${INSPECT_PATH}/`;
|
|
272
|
+
}
|
|
273
|
+
function tableOf(name) {
|
|
274
|
+
if (typeof name !== "string" || !name)
|
|
275
|
+
throw new InspectError("bad_request", "name a table");
|
|
276
|
+
const schema = deps.schema();
|
|
277
|
+
const source = historySourceTable(name) ?? name;
|
|
278
|
+
const table = Object.hasOwn(schema, source) ? schema[source] : undefined;
|
|
279
|
+
if (!table)
|
|
280
|
+
throw new InspectError("not_found", `no table ${JSON.stringify(name)}`);
|
|
281
|
+
return {
|
|
282
|
+
source,
|
|
283
|
+
columns: new Map(table.columns.map((column) => [column.name, column.column_type])),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function checkTable(admitted, name) {
|
|
287
|
+
const { source } = tableOf(name);
|
|
288
|
+
if (admitted.tables && !admitted.tables.includes(source)) {
|
|
289
|
+
throw new InspectError("forbidden", `this token is limited to ${admitted.tables.join(", ")}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function redactedFor(admitted, table) {
|
|
293
|
+
if (admitted.via !== "token")
|
|
294
|
+
return undefined;
|
|
295
|
+
return settings().redact.get(historySourceTable(table) ?? table);
|
|
296
|
+
}
|
|
297
|
+
function queryBuilder(table, json) {
|
|
298
|
+
return {
|
|
299
|
+
_table: table,
|
|
300
|
+
_schema: deps.schema(),
|
|
301
|
+
_build: () => json,
|
|
302
|
+
_rowType: undefined,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function tableProxy(table) {
|
|
306
|
+
return {
|
|
307
|
+
_table: table,
|
|
308
|
+
_schema: deps.schema(),
|
|
309
|
+
_rowType: undefined,
|
|
310
|
+
_initType: undefined,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
let claimsReadFor;
|
|
314
|
+
/** Whether the app's permissions read anything from `session.claims`. */
|
|
315
|
+
function permissionsReadClaims() {
|
|
316
|
+
if (!claimsReadFor || claimsReadFor.permissions !== deps.permissions) {
|
|
317
|
+
claimsReadFor = { permissions: deps.permissions, reads: readsClaims(deps.permissions) };
|
|
318
|
+
}
|
|
319
|
+
return claimsReadFor.reads;
|
|
320
|
+
}
|
|
321
|
+
async function dbFor(as) {
|
|
322
|
+
if (as === undefined)
|
|
323
|
+
return { db: deps.db() };
|
|
324
|
+
const user = typeof as === "string" ? { userId: as } : as;
|
|
325
|
+
if (!user || typeof user.userId !== "string" || !user.userId) {
|
|
326
|
+
throw new InspectError("bad_request", "as must name a user id");
|
|
327
|
+
}
|
|
328
|
+
if (user.claims !== undefined &&
|
|
329
|
+
(user.claims === null || typeof user.claims !== "object" || Array.isArray(user.claims))) {
|
|
330
|
+
throw new InspectError("bad_request", "as.claims must be an object of the user's claims");
|
|
331
|
+
}
|
|
332
|
+
// A user's claims come from their sign-in, which the Inspector doesn't
|
|
333
|
+
// have: viewing as them without claims sees what a session with none
|
|
334
|
+
// would, and policies that read claims then quietly allow less.
|
|
335
|
+
const warning = user.claims === undefined && permissionsReadClaims()
|
|
336
|
+
? `This app's permissions read session claims, and none were given for ${user.userId}, so this ran as a session with no claims: rows or writes a claim would allow are missing or refused. Pass the user's claims with as: { userId, claims } (CLI: --claims '<json>'; MCP: claims; Inspector: the claims field next to "View as user").`
|
|
337
|
+
: undefined;
|
|
338
|
+
try {
|
|
339
|
+
return {
|
|
340
|
+
db: await deps.dbAs(user),
|
|
341
|
+
as: user.userId,
|
|
342
|
+
...(user.claims ? { asClaims: Object.keys(user.claims).sort() } : {}),
|
|
343
|
+
...(warning ? { warning } : {}),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
// Viewing as a user who never signed in: there is no one to be.
|
|
348
|
+
if (error instanceof NoJazzAccountError)
|
|
349
|
+
throw new InspectError("not_found", error.message);
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
async function readRows(admitted, query, as) {
|
|
354
|
+
if (!query || typeof query !== "object") {
|
|
355
|
+
throw new InspectError("bad_request", "query needs { table, ... }");
|
|
356
|
+
}
|
|
357
|
+
checkTable(admitted, query.table);
|
|
358
|
+
const hidden = redactedFor(admitted, query.table);
|
|
359
|
+
if (hidden) {
|
|
360
|
+
const named = [
|
|
361
|
+
...Object.keys(query.where ?? {}),
|
|
362
|
+
...(query.orderBy ?? []).map(([column]) => column),
|
|
363
|
+
].filter((column) => hidden.has(column));
|
|
364
|
+
if (named.length) {
|
|
365
|
+
throw new InspectError("forbidden", `${named.join(", ")} ${named.length === 1 ? "is" : "are"} redacted for agents: a token can't filter or sort by ${named.length === 1 ? "it" : "them"}`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const limit = rowLimit(query.limit);
|
|
369
|
+
const { columns } = tableOf(query.table);
|
|
370
|
+
// One more than the limit, to tell whether more matched.
|
|
371
|
+
const json = buildQueryJson(query, limit + 1, (column, value) => fromJsonForColumn(columns.get(column), value));
|
|
372
|
+
const { db, as: asUser, asClaims, warning } = await dbFor(as);
|
|
373
|
+
const found = await db.all(queryBuilder(query.table, json), {
|
|
374
|
+
tier: "remote",
|
|
375
|
+
});
|
|
376
|
+
let truncated = found.length > limit;
|
|
377
|
+
const rows = [];
|
|
378
|
+
let bytes = 0;
|
|
379
|
+
for (const row of found.slice(0, limit)) {
|
|
380
|
+
const shown = toJsonValue(row);
|
|
381
|
+
if (hidden)
|
|
382
|
+
for (const column of hidden)
|
|
383
|
+
if (column in shown)
|
|
384
|
+
shown[column] = REDACTED;
|
|
385
|
+
bytes += JSON.stringify(shown).length;
|
|
386
|
+
if (bytes > MAX_ANSWER_BYTES) {
|
|
387
|
+
truncated = true;
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
rows.push(shown);
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
rows,
|
|
394
|
+
truncated,
|
|
395
|
+
...(asUser ? { as: asUser } : {}),
|
|
396
|
+
...(asClaims ? { asClaims } : {}),
|
|
397
|
+
...(warning ? { warning } : {}),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
async function write(admitted, ops, as) {
|
|
401
|
+
if (!admitted.write) {
|
|
402
|
+
throw new InspectError("forbidden", admitted.via === "token"
|
|
403
|
+
? "this token is read-only; ask for one that allows writes"
|
|
404
|
+
: "you may read but not write (the inspect hook's grant has no `write: true`)");
|
|
405
|
+
}
|
|
406
|
+
if (!Array.isArray(ops) || ops.length === 0 || ops.length > 1000) {
|
|
407
|
+
throw new InspectError("bad_request", "ops must list between 1 and 1000 writes");
|
|
408
|
+
}
|
|
409
|
+
const prepared = ops.map((op) => {
|
|
410
|
+
if (!op || typeof op !== "object" || !["insert", "update", "delete"].includes(op.kind)) {
|
|
411
|
+
throw new InspectError("bad_request", "each op is an insert, update or delete");
|
|
412
|
+
}
|
|
413
|
+
if (typeof op.table !== "string" || !op.table) {
|
|
414
|
+
throw new InspectError("bad_request", `${op.kind} needs a table`);
|
|
415
|
+
}
|
|
416
|
+
if (historySourceTable(op.table) !== undefined) {
|
|
417
|
+
throw new InspectError("bad_request", `${op.table} is a history table and is read-only`);
|
|
418
|
+
}
|
|
419
|
+
checkTable(admitted, op.table);
|
|
420
|
+
const { columns } = tableOf(op.table);
|
|
421
|
+
if (op.kind === "delete") {
|
|
422
|
+
if (typeof op.id !== "string")
|
|
423
|
+
throw new InspectError("bad_request", "delete needs an id");
|
|
424
|
+
return { op, values: undefined };
|
|
425
|
+
}
|
|
426
|
+
if (!op.values || typeof op.values !== "object" || Array.isArray(op.values)) {
|
|
427
|
+
throw new InspectError("bad_request", `${op.kind} needs values`);
|
|
428
|
+
}
|
|
429
|
+
if (op.kind === "update" && typeof op.id !== "string") {
|
|
430
|
+
throw new InspectError("bad_request", "update needs an id");
|
|
431
|
+
}
|
|
432
|
+
const hidden = redactedFor(admitted, op.table);
|
|
433
|
+
const values = {};
|
|
434
|
+
for (const [column, value] of Object.entries(op.values)) {
|
|
435
|
+
if (!columns.has(column)) {
|
|
436
|
+
throw new InspectError("bad_request", `${op.table} has no column ${column}`);
|
|
437
|
+
}
|
|
438
|
+
if (hidden?.has(column)) {
|
|
439
|
+
throw new InspectError("forbidden", `${op.table}.${column} is redacted for agents`);
|
|
440
|
+
}
|
|
441
|
+
values[column] = fromJsonForColumn(columns.get(column), value);
|
|
442
|
+
}
|
|
443
|
+
return { op, values };
|
|
444
|
+
});
|
|
445
|
+
const { db, as: asUser, asClaims, warning } = await dbFor(as);
|
|
446
|
+
const ids = [];
|
|
447
|
+
let result;
|
|
448
|
+
try {
|
|
449
|
+
result = await db.transaction((tx) => {
|
|
450
|
+
for (const { op, values } of prepared) {
|
|
451
|
+
const table = tableProxy(op.table);
|
|
452
|
+
if (op.kind === "insert") {
|
|
453
|
+
const inserted = tx.insert(table, values, op.id ? { id: op.id } : undefined);
|
|
454
|
+
ids.push(String(inserted.id ?? op.id ?? ""));
|
|
455
|
+
}
|
|
456
|
+
else if (op.kind === "update") {
|
|
457
|
+
tx.update(table, op.id, values);
|
|
458
|
+
ids.push(op.id);
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
tx.delete(table, op.id);
|
|
462
|
+
ids.push(op.id);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
// The answer says the write stands: the core accepted it.
|
|
467
|
+
await result.wait({ tier: "global" });
|
|
468
|
+
}
|
|
469
|
+
catch (error) {
|
|
470
|
+
if (error instanceof InspectError)
|
|
471
|
+
throw error;
|
|
472
|
+
throw new InspectError("forbidden", `the write was refused: ${errorMessage(error)}${warning ? `. ${warning}` : ""}`);
|
|
473
|
+
}
|
|
474
|
+
return {
|
|
475
|
+
ids,
|
|
476
|
+
...(asUser ? { as: asUser } : {}),
|
|
477
|
+
...(asClaims ? { asClaims } : {}),
|
|
478
|
+
...(warning ? { warning } : {}),
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
function schemaAnswer(admitted) {
|
|
482
|
+
const schema = deps.schema();
|
|
483
|
+
const tables = {};
|
|
484
|
+
for (const [name, table] of Object.entries(schema)) {
|
|
485
|
+
if (admitted.tables && !admitted.tables.includes(name))
|
|
486
|
+
continue;
|
|
487
|
+
const hidden = redactedFor(admitted, name);
|
|
488
|
+
tables[name] = {
|
|
489
|
+
...table,
|
|
490
|
+
...(hidden ? { redacted: [...hidden] } : {}),
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
tables,
|
|
495
|
+
// What agents may query besides each table: its row history.
|
|
496
|
+
history: Object.keys(tables).map(historyTableName),
|
|
497
|
+
provenanceColumns: PROVENANCE,
|
|
498
|
+
...(admitted.via === "token" && admitted.tables ? {} : { permissions: deps.permissions }),
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
async function answer(request, admitted, body) {
|
|
502
|
+
const url = inspectorUrl(request);
|
|
503
|
+
switch (body.op) {
|
|
504
|
+
case "whoami": {
|
|
505
|
+
const whoami = {
|
|
506
|
+
appId: deps.appId,
|
|
507
|
+
by: admitted.by,
|
|
508
|
+
via: admitted.via,
|
|
509
|
+
write: admitted.write,
|
|
510
|
+
...(admitted.tables ? { tables: admitted.tables } : {}),
|
|
511
|
+
...(admitted.expiresAt ? { expiresAt: admitted.expiresAt } : {}),
|
|
512
|
+
inspectorUrl: url,
|
|
513
|
+
protocol: INSPECT_PROTOCOL_VERSION,
|
|
514
|
+
};
|
|
515
|
+
return { answer: whoami, event: {} };
|
|
516
|
+
}
|
|
517
|
+
case "schema":
|
|
518
|
+
return { answer: schemaAnswer(admitted), event: {} };
|
|
519
|
+
case "query": {
|
|
520
|
+
const read = await readRows(admitted, body.query, body.as);
|
|
521
|
+
return {
|
|
522
|
+
answer: {
|
|
523
|
+
rows: read.rows,
|
|
524
|
+
truncated: read.truncated,
|
|
525
|
+
...(read.warning ? { warning: read.warning } : {}),
|
|
526
|
+
inspectorUrl: inspectorLink(url, {
|
|
527
|
+
query: body.query,
|
|
528
|
+
as: body.as,
|
|
529
|
+
}),
|
|
530
|
+
},
|
|
531
|
+
event: {
|
|
532
|
+
table: body.query.table,
|
|
533
|
+
rows: read.rows.length,
|
|
534
|
+
as: read.as,
|
|
535
|
+
asClaims: read.asClaims,
|
|
536
|
+
},
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
case "get": {
|
|
540
|
+
if (typeof body.id !== "string")
|
|
541
|
+
throw new InspectError("bad_request", "get needs an id");
|
|
542
|
+
const read = await readRows(admitted, {
|
|
543
|
+
table: body.table,
|
|
544
|
+
where: { id: body.id },
|
|
545
|
+
select: ["*", ...PROVENANCE],
|
|
546
|
+
limit: 1,
|
|
547
|
+
}, body.as);
|
|
548
|
+
return {
|
|
549
|
+
answer: {
|
|
550
|
+
row: read.rows[0] ?? null,
|
|
551
|
+
...(read.warning ? { warning: read.warning } : {}),
|
|
552
|
+
inspectorUrl: inspectorLink(url, {
|
|
553
|
+
table: body.table,
|
|
554
|
+
row: body.id,
|
|
555
|
+
as: body.as,
|
|
556
|
+
}),
|
|
557
|
+
},
|
|
558
|
+
event: {
|
|
559
|
+
table: body.table,
|
|
560
|
+
rows: read.rows.length,
|
|
561
|
+
as: read.as,
|
|
562
|
+
asClaims: read.asClaims,
|
|
563
|
+
},
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
case "history": {
|
|
567
|
+
if (typeof body.table !== "string" || !body.table) {
|
|
568
|
+
throw new InspectError("bad_request", "history needs a table");
|
|
569
|
+
}
|
|
570
|
+
if (typeof body.id !== "string") {
|
|
571
|
+
throw new InspectError("bad_request", "history needs an id");
|
|
572
|
+
}
|
|
573
|
+
const query = {
|
|
574
|
+
table: historyTableName(body.table),
|
|
575
|
+
where: { id: body.id },
|
|
576
|
+
select: ["*", "$updatedBy", "$updatedAt"],
|
|
577
|
+
orderBy: [["$acceptedAt", "asc"]],
|
|
578
|
+
limit: body.limit ?? 100,
|
|
579
|
+
};
|
|
580
|
+
const read = await readRows(admitted, query, undefined);
|
|
581
|
+
return {
|
|
582
|
+
answer: {
|
|
583
|
+
versions: read.rows,
|
|
584
|
+
truncated: read.truncated,
|
|
585
|
+
inspectorUrl: inspectorLink(url, { query, row: body.id }),
|
|
586
|
+
},
|
|
587
|
+
event: { table: body.table, rows: read.rows.length },
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
case "write": {
|
|
591
|
+
const done = await write(admitted, body.ops, body.as);
|
|
592
|
+
return {
|
|
593
|
+
answer: { ids: done.ids, ...(done.warning ? { warning: done.warning } : {}) },
|
|
594
|
+
event: {
|
|
595
|
+
table: [...new Set(body.ops.map((op) => op.table))].join(","),
|
|
596
|
+
rows: done.ids.length,
|
|
597
|
+
as: done.as,
|
|
598
|
+
asClaims: done.asClaims,
|
|
599
|
+
write: true,
|
|
600
|
+
},
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
case "sessions":
|
|
604
|
+
// Who is connected is about the whole app, not one table.
|
|
605
|
+
if (admitted.tables) {
|
|
606
|
+
throw new InspectError("forbidden", `this token is limited to ${admitted.tables.join(", ")}; listing sessions needs one for the whole app`);
|
|
607
|
+
}
|
|
608
|
+
return {
|
|
609
|
+
answer: {
|
|
610
|
+
// Each backend instance knows only the sessions it serves.
|
|
611
|
+
scope: "this backend instance",
|
|
612
|
+
sessions: deps.sessions(),
|
|
613
|
+
},
|
|
614
|
+
event: {},
|
|
615
|
+
};
|
|
616
|
+
case "explain":
|
|
617
|
+
throw new InspectError("not_supported", "explain (which policy allowed or denied each row) is not supported yet; compare `query` with and without `as` meanwhile");
|
|
618
|
+
case "link": {
|
|
619
|
+
if (body.query)
|
|
620
|
+
checkTable(admitted, body.query.table);
|
|
621
|
+
else if (body.table)
|
|
622
|
+
checkTable(admitted, body.table);
|
|
623
|
+
return {
|
|
624
|
+
answer: {
|
|
625
|
+
inspectorUrl: inspectorLink(url, {
|
|
626
|
+
query: body.query,
|
|
627
|
+
table: body.table,
|
|
628
|
+
row: body.row,
|
|
629
|
+
as: body.as,
|
|
630
|
+
}),
|
|
631
|
+
},
|
|
632
|
+
event: {},
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
case "mint_token": {
|
|
636
|
+
const minted = await mintToken(admitted, body);
|
|
637
|
+
return {
|
|
638
|
+
answer: { token: minted.token, expiresAt: minted.expiresAt },
|
|
639
|
+
event: { tokenId: minted.tokenId, write: body.write === true },
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
default:
|
|
643
|
+
throw new InspectError("bad_request", `unknown op ${JSON.stringify(body.op)}`);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function errorResponse(error) {
|
|
647
|
+
return Response.json({ error: error.code, message: error.message }, {
|
|
648
|
+
status: INSPECT_ERRORS[error.code],
|
|
649
|
+
headers: { "Cache-Control": "no-store" },
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
async function handleApi(request) {
|
|
653
|
+
if (request.method !== "POST") {
|
|
654
|
+
return new Response(null, { status: 405, headers: { Allow: "POST" } });
|
|
655
|
+
}
|
|
656
|
+
// A form or a plain-text POST from another page can't be JSON: this
|
|
657
|
+
// keeps cross-site requests that a browser sends without asking out.
|
|
658
|
+
if (!request.headers.get("content-type")?.toLowerCase().startsWith("application/json")) {
|
|
659
|
+
return errorResponse(new InspectError("bad_request", "send application/json"));
|
|
660
|
+
}
|
|
661
|
+
let admitted;
|
|
662
|
+
try {
|
|
663
|
+
admitted = await admit(request);
|
|
664
|
+
}
|
|
665
|
+
catch (error) {
|
|
666
|
+
const refused = asInspectError(error);
|
|
667
|
+
audit({
|
|
668
|
+
at: now(),
|
|
669
|
+
by: "?",
|
|
670
|
+
via: request.headers.get("authorization")?.startsWith(`Bearer ${INSPECT_TOKEN_PREFIX}`)
|
|
671
|
+
? "token"
|
|
672
|
+
: deps.hook
|
|
673
|
+
? "hook"
|
|
674
|
+
: "dev",
|
|
675
|
+
op: "whoami",
|
|
676
|
+
write: false,
|
|
677
|
+
error: refused.code,
|
|
678
|
+
});
|
|
679
|
+
return errorResponse(refused);
|
|
680
|
+
}
|
|
681
|
+
let body;
|
|
682
|
+
try {
|
|
683
|
+
const text = await request.text();
|
|
684
|
+
if (text.length > MAX_REQUEST_BYTES)
|
|
685
|
+
throw new InspectError("too_large", "request too large");
|
|
686
|
+
body = JSON.parse(text);
|
|
687
|
+
if (!body || typeof body !== "object" || typeof body.op !== "string") {
|
|
688
|
+
throw new InspectError("bad_request", "send { op, ... }");
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
catch (error) {
|
|
692
|
+
return errorResponse(error instanceof InspectError ? error : new InspectError("bad_request", "invalid JSON"));
|
|
693
|
+
}
|
|
694
|
+
const base = {
|
|
695
|
+
at: now(),
|
|
696
|
+
by: admitted.by,
|
|
697
|
+
via: admitted.via,
|
|
698
|
+
op: body.op,
|
|
699
|
+
write: false,
|
|
700
|
+
...(admitted.tokenId ? { tokenId: admitted.tokenId } : {}),
|
|
701
|
+
};
|
|
702
|
+
try {
|
|
703
|
+
const { answer: result, event } = await answer(request, admitted, body);
|
|
704
|
+
audit(clean({ ...base, ...event }));
|
|
705
|
+
return Response.json(result, {
|
|
706
|
+
headers: { "Cache-Control": "no-store" },
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
catch (error) {
|
|
710
|
+
const failed = asInspectError(error);
|
|
711
|
+
audit(clean({ ...base, write: body.op === "write", error: failed.code }));
|
|
712
|
+
if (!(error instanceof InspectError))
|
|
713
|
+
console.error("jazz inspect: call failed", error);
|
|
714
|
+
return errorResponse(failed);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
return {
|
|
718
|
+
/** Answer a request for `path` (below `basePath`), which starts with `/inspect`. */
|
|
719
|
+
async handle(request, path) {
|
|
720
|
+
if (path === INSPECT_API_PATH)
|
|
721
|
+
return handleApi(request);
|
|
722
|
+
if (path === INSPECT_PATH || path.startsWith(`${INSPECT_PATH}/`)) {
|
|
723
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
724
|
+
return new Response(null, { status: 405 });
|
|
725
|
+
}
|
|
726
|
+
const served = await deps.serveUi(request, path.slice(INSPECT_PATH.length));
|
|
727
|
+
return (served ??
|
|
728
|
+
new Response("This jazz-tools build has no Inspector UI. The API at " +
|
|
729
|
+
`${deps.basePath}${INSPECT_API_PATH} works: try \`npx jazz-tools inspect\`.`, {
|
|
730
|
+
status: 404,
|
|
731
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
|
732
|
+
}));
|
|
733
|
+
}
|
|
734
|
+
return new Response("Not found", { status: 404 });
|
|
735
|
+
},
|
|
736
|
+
// For tests.
|
|
737
|
+
mintToken,
|
|
738
|
+
verifyToken,
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
function asInspectError(error) {
|
|
742
|
+
if (error instanceof InspectError)
|
|
743
|
+
return error;
|
|
744
|
+
// Whoever got this far may read every row, so the runtime's reason (an
|
|
745
|
+
// unknown column, a bad operator) is theirs to see.
|
|
746
|
+
return new InspectError("failed", errorMessage(error));
|
|
747
|
+
}
|
|
748
|
+
function errorMessage(error) {
|
|
749
|
+
return error instanceof Error ? error.message : String(error);
|
|
750
|
+
}
|
|
751
|
+
function clean(event) {
|
|
752
|
+
return Object.fromEntries(Object.entries(event).filter(([, value]) => value !== undefined && value !== ""));
|
|
753
|
+
}
|
|
754
|
+
function isLoopbackAddress(address) {
|
|
755
|
+
return (address === "::1" ||
|
|
756
|
+
/^127\.\d+\.\d+\.\d+$/.test(address) ||
|
|
757
|
+
/^::ffff:127\.\d+\.\d+\.\d+$/.test(address));
|
|
758
|
+
}
|
|
759
|
+
/** A random secret for stores that keep one beside their data. */
|
|
760
|
+
export function newTokenSecret() {
|
|
761
|
+
return randomBytes(32).toString("base64url");
|
|
762
|
+
}
|
|
763
|
+
//# sourceMappingURL=inspect.js.map
|