@opendatalabs/personal-server-ts-core 0.0.1-canary.052d47e → 0.0.1-canary.0620a9a
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/dist/additions/budget.d.ts +34 -0
- package/dist/additions/budget.d.ts.map +1 -0
- package/dist/additions/budget.js +144 -0
- package/dist/additions/budget.js.map +1 -0
- package/dist/additions/durable.d.ts +94 -0
- package/dist/additions/durable.d.ts.map +1 -0
- package/dist/additions/durable.js +823 -0
- package/dist/additions/durable.js.map +1 -0
- package/dist/additions/first-added.d.ts +204 -0
- package/dist/additions/first-added.d.ts.map +1 -0
- package/dist/additions/first-added.js +598 -0
- package/dist/additions/first-added.js.map +1 -0
- package/dist/additions/index.d.ts +9 -0
- package/dist/additions/index.d.ts.map +1 -0
- package/dist/additions/index.js +9 -0
- package/dist/additions/index.js.map +1 -0
- package/dist/additions/ledger-store.d.ts +69 -0
- package/dist/additions/ledger-store.d.ts.map +1 -0
- package/dist/additions/ledger-store.js +407 -0
- package/dist/additions/ledger-store.js.map +1 -0
- package/dist/additions/record-rules.d.ts +54 -0
- package/dist/additions/record-rules.d.ts.map +1 -0
- package/dist/additions/record-rules.js +198 -0
- package/dist/additions/record-rules.js.map +1 -0
- package/dist/additions/scope-lock.d.ts +14 -0
- package/dist/additions/scope-lock.d.ts.map +1 -0
- package/dist/additions/scope-lock.js +32 -0
- package/dist/additions/scope-lock.js.map +1 -0
- package/dist/additions/summary.d.ts +143 -0
- package/dist/additions/summary.d.ts.map +1 -0
- package/dist/additions/summary.js +279 -0
- package/dist/additions/summary.js.map +1 -0
- package/dist/additions/version-inventory.d.ts +86 -0
- package/dist/additions/version-inventory.d.ts.map +1 -0
- package/dist/additions/version-inventory.js +244 -0
- package/dist/additions/version-inventory.js.map +1 -0
- package/dist/api/index.d.ts +192 -8
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1227 -153
- package/dist/api/index.js.map +1 -1
- package/dist/api/oura-collection-requirements.d.ts +16 -0
- package/dist/api/oura-collection-requirements.d.ts.map +1 -0
- package/dist/api/oura-collection-requirements.js +70 -0
- package/dist/api/oura-collection-requirements.js.map +1 -0
- package/dist/api/raw-envelope.d.ts +3 -0
- package/dist/api/raw-envelope.d.ts.map +1 -0
- package/dist/api/raw-envelope.js +215 -0
- package/dist/api/raw-envelope.js.map +1 -0
- package/dist/api/scope-upload-batches.d.ts +18 -0
- package/dist/api/scope-upload-batches.d.ts.map +1 -0
- package/dist/api/scope-upload-batches.js +71 -0
- package/dist/api/scope-upload-batches.js.map +1 -0
- package/dist/api/scope-uploads.d.ts +112 -0
- package/dist/api/scope-uploads.d.ts.map +1 -0
- package/dist/api/scope-uploads.js +369 -0
- package/dist/api/scope-uploads.js.map +1 -0
- package/dist/auth/index.d.ts +3 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +3 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/proof-id.d.ts +8 -0
- package/dist/auth/proof-id.d.ts.map +1 -0
- package/dist/auth/proof-id.js +29 -0
- package/dist/auth/proof-id.js.map +1 -0
- package/dist/auth/request.d.ts +24 -0
- package/dist/auth/request.d.ts.map +1 -1
- package/dist/auth/request.js +99 -4
- package/dist/auth/request.js.map +1 -1
- package/dist/client.d.ts +70 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -0
- package/dist/client.js.map +1 -1
- package/dist/contracts/auth-device.d.ts +10 -0
- package/dist/contracts/auth-device.d.ts.map +1 -1
- package/dist/contracts/auth-device.js +2 -0
- package/dist/contracts/auth-device.js.map +1 -1
- package/dist/contracts/data.d.ts +102 -8
- package/dist/contracts/data.d.ts.map +1 -1
- package/dist/contracts/data.js +320 -47
- package/dist/contracts/data.js.map +1 -1
- package/dist/contracts/grants.d.ts.map +1 -1
- package/dist/contracts/grants.js +7 -0
- package/dist/contracts/grants.js.map +1 -1
- package/dist/contracts/index.d.ts +4 -2
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +3 -1
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/oura-collection-requirements.d.ts +17 -0
- package/dist/contracts/oura-collection-requirements.d.ts.map +1 -0
- package/dist/contracts/oura-collection-requirements.js +49 -0
- package/dist/contracts/oura-collection-requirements.js.map +1 -0
- package/dist/contracts/sync.d.ts.map +1 -1
- package/dist/contracts/sync.js +1 -0
- package/dist/contracts/sync.js.map +1 -1
- package/dist/derivatives/answer-shape.d.ts +83 -0
- package/dist/derivatives/answer-shape.d.ts.map +1 -0
- package/dist/derivatives/answer-shape.js +320 -0
- package/dist/derivatives/answer-shape.js.map +1 -0
- package/dist/derivatives/api.d.ts +1 -1
- package/dist/derivatives/api.d.ts.map +1 -1
- package/dist/derivatives/api.js +8 -0
- package/dist/derivatives/api.js.map +1 -1
- package/dist/derivatives/compute.d.ts +9 -3
- package/dist/derivatives/compute.d.ts.map +1 -1
- package/dist/derivatives/compute.js +68 -6
- package/dist/derivatives/compute.js.map +1 -1
- package/dist/derivatives/index.d.ts +2 -1
- package/dist/derivatives/index.d.ts.map +1 -1
- package/dist/derivatives/index.js +2 -1
- package/dist/derivatives/index.js.map +1 -1
- package/dist/derivatives/prompt.d.ts +35 -0
- package/dist/derivatives/prompt.d.ts.map +1 -1
- package/dist/derivatives/prompt.js +96 -8
- package/dist/derivatives/prompt.js.map +1 -1
- package/dist/derivatives/registration.d.ts +6 -9
- package/dist/derivatives/registration.d.ts.map +1 -1
- package/dist/derivatives/registration.js +14 -6
- package/dist/derivatives/registration.js.map +1 -1
- package/dist/derivatives/scheduler.d.ts +39 -9
- package/dist/derivatives/scheduler.d.ts.map +1 -1
- package/dist/derivatives/scheduler.js +99 -8
- package/dist/derivatives/scheduler.js.map +1 -1
- package/dist/derivatives/store.d.ts.map +1 -1
- package/dist/derivatives/store.js +2 -0
- package/dist/derivatives/store.js.map +1 -1
- package/dist/derivatives/types.d.ts +13 -3
- package/dist/derivatives/types.d.ts.map +1 -1
- package/dist/derivatives/types.js +2 -0
- package/dist/derivatives/types.js.map +1 -1
- package/dist/errors/pdpp-catalog.d.ts +36 -0
- package/dist/errors/pdpp-catalog.d.ts.map +1 -0
- package/dist/errors/pdpp-catalog.js +86 -0
- package/dist/errors/pdpp-catalog.js.map +1 -0
- package/dist/grants/index.d.ts +2 -0
- package/dist/grants/index.d.ts.map +1 -1
- package/dist/grants/index.js +4 -0
- package/dist/grants/index.js.map +1 -1
- package/dist/grants/pdpp-binding-store.d.ts +89 -0
- package/dist/grants/pdpp-binding-store.d.ts.map +1 -0
- package/dist/grants/pdpp-binding-store.js +112 -0
- package/dist/grants/pdpp-binding-store.js.map +1 -0
- package/dist/grants/pdpp-binding.d.ts +169 -0
- package/dist/grants/pdpp-binding.d.ts.map +1 -0
- package/dist/grants/pdpp-binding.js +236 -0
- package/dist/grants/pdpp-binding.js.map +1 -0
- package/dist/legacy-projection/bindings.d.ts +31 -0
- package/dist/legacy-projection/bindings.d.ts.map +1 -0
- package/dist/legacy-projection/bindings.js +4512 -0
- package/dist/legacy-projection/bindings.js.map +1 -0
- package/dist/legacy-projection/claude-source-record.d.ts +22 -0
- package/dist/legacy-projection/claude-source-record.d.ts.map +1 -0
- package/dist/legacy-projection/claude-source-record.js +360 -0
- package/dist/legacy-projection/claude-source-record.js.map +1 -0
- package/dist/legacy-projection/declared-text.d.ts +41 -0
- package/dist/legacy-projection/declared-text.d.ts.map +1 -0
- package/dist/legacy-projection/declared-text.js +199 -0
- package/dist/legacy-projection/declared-text.js.map +1 -0
- package/dist/legacy-projection/github-browser-bindings.d.ts +3 -0
- package/dist/legacy-projection/github-browser-bindings.d.ts.map +1 -0
- package/dist/legacy-projection/github-browser-bindings.js +212 -0
- package/dist/legacy-projection/github-browser-bindings.js.map +1 -0
- package/dist/legacy-projection/github-legacy-fields.d.ts +6 -0
- package/dist/legacy-projection/github-legacy-fields.d.ts.map +1 -0
- package/dist/legacy-projection/github-legacy-fields.js +202 -0
- package/dist/legacy-projection/github-legacy-fields.js.map +1 -0
- package/dist/legacy-projection/index.d.ts +38 -0
- package/dist/legacy-projection/index.d.ts.map +1 -0
- package/dist/legacy-projection/index.js +231 -0
- package/dist/legacy-projection/index.js.map +1 -0
- package/dist/legacy-projection/meta-040-bindings.d.ts +3 -0
- package/dist/legacy-projection/meta-040-bindings.d.ts.map +1 -0
- package/dist/legacy-projection/meta-040-bindings.js +112 -0
- package/dist/legacy-projection/meta-040-bindings.js.map +1 -0
- package/dist/legacy-projection/oura-browser-bindings.d.ts +5 -0
- package/dist/legacy-projection/oura-browser-bindings.d.ts.map +1 -0
- package/dist/legacy-projection/oura-browser-bindings.js +141 -0
- package/dist/legacy-projection/oura-browser-bindings.js.map +1 -0
- package/dist/legacy-projection/provenance.d.ts +57 -0
- package/dist/legacy-projection/provenance.d.ts.map +1 -0
- package/dist/legacy-projection/provenance.js +2 -0
- package/dist/legacy-projection/provenance.js.map +1 -0
- package/dist/legacy-projection/strava-browser-bindings.d.ts +3 -0
- package/dist/legacy-projection/strava-browser-bindings.d.ts.map +1 -0
- package/dist/legacy-projection/strava-browser-bindings.js +32 -0
- package/dist/legacy-projection/strava-browser-bindings.js.map +1 -0
- package/dist/legacy-projection/test-debris.d.ts +2 -0
- package/dist/legacy-projection/test-debris.d.ts.map +1 -0
- package/dist/legacy-projection/test-debris.js +49 -0
- package/dist/legacy-projection/test-debris.js.map +1 -0
- package/dist/legacy-projection/types.d.ts +235 -0
- package/dist/legacy-projection/types.d.ts.map +1 -0
- package/dist/legacy-projection/types.js +2 -0
- package/dist/legacy-projection/types.js.map +1 -0
- package/dist/mcp/approval-url.d.ts +68 -0
- package/dist/mcp/approval-url.d.ts.map +1 -0
- package/dist/mcp/approval-url.js +95 -0
- package/dist/mcp/approval-url.js.map +1 -0
- package/dist/mcp/connection-api.d.ts +187 -3
- package/dist/mcp/connection-api.d.ts.map +1 -1
- package/dist/mcp/connection-api.js +600 -26
- package/dist/mcp/connection-api.js.map +1 -1
- package/dist/mcp/grantee.d.ts +1 -1
- package/dist/mcp/grantee.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +4 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/oauth-redirect.d.ts +14 -0
- package/dist/mcp/oauth-redirect.d.ts.map +1 -0
- package/dist/mcp/oauth-redirect.js +51 -0
- package/dist/mcp/oauth-redirect.js.map +1 -0
- package/dist/mcp/read-client.d.ts +5 -1
- package/dist/mcp/read-client.d.ts.map +1 -1
- package/dist/mcp/read-client.js +18 -4
- package/dist/mcp/read-client.js.map +1 -1
- package/dist/mcp/resources.d.ts.map +1 -1
- package/dist/mcp/resources.js +3 -0
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/server.d.ts +30 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +172 -17
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session.d.ts +1 -1
- package/dist/mcp/session.d.ts.map +1 -1
- package/dist/mcp/session.js +17 -3
- package/dist/mcp/session.js.map +1 -1
- package/dist/mcp/store.d.ts +10 -1
- package/dist/mcp/store.d.ts.map +1 -1
- package/dist/mcp/store.js +72 -0
- package/dist/mcp/store.js.map +1 -1
- package/dist/mcp/token-expiry.d.ts +48 -0
- package/dist/mcp/token-expiry.d.ts.map +1 -0
- package/dist/mcp/token-expiry.js +69 -0
- package/dist/mcp/token-expiry.js.map +1 -0
- package/dist/mcp/tools.d.ts +92 -3
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +513 -28
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +103 -4
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/types.js +13 -1
- package/dist/mcp/types.js.map +1 -1
- package/dist/mcp/write-client.d.ts +81 -0
- package/dist/mcp/write-client.d.ts.map +1 -0
- package/dist/mcp/write-client.js +140 -0
- package/dist/mcp/write-client.js.map +1 -0
- package/dist/oura/history-policy.d.ts +12 -0
- package/dist/oura/history-policy.d.ts.map +1 -0
- package/dist/oura/history-policy.js +54 -0
- package/dist/oura/history-policy.js.map +1 -0
- package/dist/oura/index.d.ts +51 -0
- package/dist/oura/index.d.ts.map +1 -0
- package/dist/oura/index.js +315 -0
- package/dist/oura/index.js.map +1 -0
- package/dist/payment/own-app.d.ts +8 -0
- package/dist/payment/own-app.d.ts.map +1 -0
- package/dist/payment/own-app.js +47 -0
- package/dist/payment/own-app.js.map +1 -0
- package/dist/pdpp/approval.d.ts +271 -0
- package/dist/pdpp/approval.d.ts.map +1 -0
- package/dist/pdpp/approval.js +486 -0
- package/dist/pdpp/approval.js.map +1 -0
- package/dist/pdpp/client-identity.d.ts +88 -0
- package/dist/pdpp/client-identity.d.ts.map +1 -0
- package/dist/pdpp/client-identity.js +196 -0
- package/dist/pdpp/client-identity.js.map +1 -0
- package/dist/pdpp/client-metadata.d.ts +95 -0
- package/dist/pdpp/client-metadata.d.ts.map +1 -0
- package/dist/pdpp/client-metadata.js +96 -0
- package/dist/pdpp/client-metadata.js.map +1 -0
- package/dist/pdpp/commitments.d.ts +75 -0
- package/dist/pdpp/commitments.d.ts.map +1 -0
- package/dist/pdpp/commitments.js +113 -0
- package/dist/pdpp/commitments.js.map +1 -0
- package/dist/pdpp/declaration-limits.d.ts +7 -0
- package/dist/pdpp/declaration-limits.d.ts.map +1 -0
- package/dist/pdpp/declaration-limits.js +7 -0
- package/dist/pdpp/declaration-limits.js.map +1 -0
- package/dist/pdpp/declaration.d.ts +119 -0
- package/dist/pdpp/declaration.d.ts.map +1 -0
- package/dist/pdpp/declaration.js +837 -0
- package/dist/pdpp/declaration.js.map +1 -0
- package/dist/pdpp/index.d.ts +38 -0
- package/dist/pdpp/index.d.ts.map +1 -0
- package/dist/pdpp/index.js +24 -0
- package/dist/pdpp/index.js.map +1 -0
- package/dist/pdpp/issuance.d.ts +126 -0
- package/dist/pdpp/issuance.d.ts.map +1 -0
- package/dist/pdpp/issuance.js +184 -0
- package/dist/pdpp/issuance.js.map +1 -0
- package/dist/pdpp/pkce.d.ts +53 -0
- package/dist/pdpp/pkce.d.ts.map +1 -0
- package/dist/pdpp/pkce.js +109 -0
- package/dist/pdpp/pkce.js.map +1 -0
- package/dist/pdpp/redirect.d.ts +60 -0
- package/dist/pdpp/redirect.d.ts.map +1 -0
- package/dist/pdpp/redirect.js +125 -0
- package/dist/pdpp/redirect.js.map +1 -0
- package/dist/pdpp/resolve.d.ts +120 -0
- package/dist/pdpp/resolve.d.ts.map +1 -0
- package/dist/pdpp/resolve.js +491 -0
- package/dist/pdpp/resolve.js.map +1 -0
- package/dist/pdpp/review.d.ts +280 -0
- package/dist/pdpp/review.d.ts.map +1 -0
- package/dist/pdpp/review.js +205 -0
- package/dist/pdpp/review.js.map +1 -0
- package/dist/pdpp/selection.d.ts +79 -0
- package/dist/pdpp/selection.d.ts.map +1 -0
- package/dist/pdpp/selection.js +493 -0
- package/dist/pdpp/selection.js.map +1 -0
- package/dist/pdpp/store.d.ts +228 -0
- package/dist/pdpp/store.d.ts.map +1 -0
- package/dist/pdpp/store.js +542 -0
- package/dist/pdpp/store.js.map +1 -0
- package/dist/pdpp/time.d.ts +39 -0
- package/dist/pdpp/time.d.ts.map +1 -0
- package/dist/pdpp/time.js +173 -0
- package/dist/pdpp/time.js.map +1 -0
- package/dist/pdpp/tokens.d.ts +181 -0
- package/dist/pdpp/tokens.d.ts.map +1 -0
- package/dist/pdpp/tokens.js +421 -0
- package/dist/pdpp/tokens.js.map +1 -0
- package/dist/pdpp/types.d.ts +457 -0
- package/dist/pdpp/types.d.ts.map +1 -0
- package/dist/pdpp/types.js +68 -0
- package/dist/pdpp/types.js.map +1 -0
- package/dist/pdpp-version.d.ts +28 -0
- package/dist/pdpp-version.d.ts.map +1 -0
- package/dist/pdpp-version.js +28 -0
- package/dist/pdpp-version.js.map +1 -0
- package/dist/policy/data-read.d.ts +52 -1
- package/dist/policy/data-read.d.ts.map +1 -1
- package/dist/policy/data-read.js +157 -3
- package/dist/policy/data-read.js.map +1 -1
- package/dist/policy/data-write.d.ts.map +1 -1
- package/dist/policy/data-write.js +18 -1
- package/dist/policy/data-write.js.map +1 -1
- package/dist/policy/index.d.ts +2 -1
- package/dist/policy/index.d.ts.map +1 -1
- package/dist/policy/index.js +2 -1
- package/dist/policy/index.js.map +1 -1
- package/dist/policy/reserved-scopes.d.ts +10 -0
- package/dist/policy/reserved-scopes.d.ts.map +1 -0
- package/dist/policy/reserved-scopes.js +16 -0
- package/dist/policy/reserved-scopes.js.map +1 -0
- package/dist/ports/index.d.ts +266 -5
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/pdpp-auth.d.ts +119 -0
- package/dist/ports/pdpp-auth.d.ts.map +1 -0
- package/dist/ports/pdpp-auth.js +46 -0
- package/dist/ports/pdpp-auth.js.map +1 -0
- package/dist/ports/pdpp-auth.test-utils.d.ts +9 -0
- package/dist/ports/pdpp-auth.test-utils.d.ts.map +1 -0
- package/dist/ports/pdpp-auth.test-utils.js +18 -0
- package/dist/ports/pdpp-auth.test-utils.js.map +1 -0
- package/dist/publication/publish.d.ts +109 -0
- package/dist/publication/publish.d.ts.map +1 -0
- package/dist/publication/publish.js +263 -0
- package/dist/publication/publish.js.map +1 -0
- package/dist/replication/completion.d.ts +20 -0
- package/dist/replication/completion.d.ts.map +1 -0
- package/dist/replication/completion.js +73 -0
- package/dist/replication/completion.js.map +1 -0
- package/dist/replication/coordinator-state.d.ts +29 -0
- package/dist/replication/coordinator-state.d.ts.map +1 -0
- package/dist/replication/coordinator-state.js +88 -0
- package/dist/replication/coordinator-state.js.map +1 -0
- package/dist/replication/coordinator-state.test-utils.d.ts +32 -0
- package/dist/replication/coordinator-state.test-utils.d.ts.map +1 -0
- package/dist/replication/coordinator-state.test-utils.js +113 -0
- package/dist/replication/coordinator-state.test-utils.js.map +1 -0
- package/dist/replication/coordinator.d.ts +264 -0
- package/dist/replication/coordinator.d.ts.map +1 -0
- package/dist/replication/coordinator.js +499 -0
- package/dist/replication/coordinator.js.map +1 -0
- package/dist/replication/copies.d.ts +126 -0
- package/dist/replication/copies.d.ts.map +1 -0
- package/dist/replication/copies.js +437 -0
- package/dist/replication/copies.js.map +1 -0
- package/dist/replication/copy-promotion.d.ts +132 -0
- package/dist/replication/copy-promotion.d.ts.map +1 -0
- package/dist/replication/copy-promotion.js +126 -0
- package/dist/replication/copy-promotion.js.map +1 -0
- package/dist/replication/door.d.ts +33 -0
- package/dist/replication/door.d.ts.map +1 -0
- package/dist/replication/door.js +10 -0
- package/dist/replication/door.js.map +1 -0
- package/dist/replication/dpv2.d.ts +141 -0
- package/dist/replication/dpv2.d.ts.map +1 -0
- package/dist/replication/dpv2.js +320 -0
- package/dist/replication/dpv2.js.map +1 -0
- package/dist/replication/effects.d.ts +68 -0
- package/dist/replication/effects.d.ts.map +1 -0
- package/dist/replication/effects.js +89 -0
- package/dist/replication/effects.js.map +1 -0
- package/dist/replication/engine.d.ts +378 -0
- package/dist/replication/engine.d.ts.map +1 -0
- package/dist/replication/engine.js +3197 -0
- package/dist/replication/engine.js.map +1 -0
- package/dist/replication/envelope.d.ts +481 -0
- package/dist/replication/envelope.d.ts.map +1 -0
- package/dist/replication/envelope.js +192 -0
- package/dist/replication/envelope.js.map +1 -0
- package/dist/replication/evidence.d.ts +118 -0
- package/dist/replication/evidence.d.ts.map +1 -0
- package/dist/replication/evidence.js +198 -0
- package/dist/replication/evidence.js.map +1 -0
- package/dist/replication/finality.d.ts +16 -0
- package/dist/replication/finality.d.ts.map +1 -0
- package/dist/replication/finality.js +11 -0
- package/dist/replication/finality.js.map +1 -0
- package/dist/replication/fixtures.d.ts +16 -0
- package/dist/replication/fixtures.d.ts.map +1 -0
- package/dist/replication/fixtures.js +47 -0
- package/dist/replication/fixtures.js.map +1 -0
- package/dist/replication/host-config.d.ts +52 -0
- package/dist/replication/host-config.d.ts.map +1 -0
- package/dist/replication/host-config.js +111 -0
- package/dist/replication/host-config.js.map +1 -0
- package/dist/replication/host-driver.d.ts +95 -0
- package/dist/replication/host-driver.d.ts.map +1 -0
- package/dist/replication/host-driver.js +202 -0
- package/dist/replication/host-driver.js.map +1 -0
- package/dist/replication/host-ports.d.ts +48 -0
- package/dist/replication/host-ports.d.ts.map +1 -0
- package/dist/replication/host-ports.js +69 -0
- package/dist/replication/host-ports.js.map +1 -0
- package/dist/replication/identity.d.ts +13 -0
- package/dist/replication/identity.d.ts.map +1 -0
- package/dist/replication/identity.js +22 -0
- package/dist/replication/identity.js.map +1 -0
- package/dist/replication/limits.d.ts +124 -0
- package/dist/replication/limits.d.ts.map +1 -0
- package/dist/replication/limits.js +182 -0
- package/dist/replication/limits.js.map +1 -0
- package/dist/replication/merge-plan.d.ts +92 -0
- package/dist/replication/merge-plan.d.ts.map +1 -0
- package/dist/replication/merge-plan.js +229 -0
- package/dist/replication/merge-plan.js.map +1 -0
- package/dist/replication/namespace.d.ts +4 -0
- package/dist/replication/namespace.d.ts.map +1 -0
- package/dist/replication/namespace.js +7 -0
- package/dist/replication/namespace.js.map +1 -0
- package/dist/replication/outcome.d.ts +178 -0
- package/dist/replication/outcome.d.ts.map +1 -0
- package/dist/replication/outcome.js +83 -0
- package/dist/replication/outcome.js.map +1 -0
- package/dist/replication/payload.d.ts +39 -0
- package/dist/replication/payload.d.ts.map +1 -0
- package/dist/replication/payload.js +137 -0
- package/dist/replication/payload.js.map +1 -0
- package/dist/replication/preparation.d.ts +42 -0
- package/dist/replication/preparation.d.ts.map +1 -0
- package/dist/replication/preparation.js +118 -0
- package/dist/replication/preparation.js.map +1 -0
- package/dist/replication/rebaseline.d.ts +33 -0
- package/dist/replication/rebaseline.d.ts.map +1 -0
- package/dist/replication/rebaseline.js +40 -0
- package/dist/replication/rebaseline.js.map +1 -0
- package/dist/replication/rebinding.d.ts +43 -0
- package/dist/replication/rebinding.d.ts.map +1 -0
- package/dist/replication/rebinding.js +52 -0
- package/dist/replication/rebinding.js.map +1 -0
- package/dist/replication/receive.d.ts +57 -0
- package/dist/replication/receive.d.ts.map +1 -0
- package/dist/replication/receive.js +114 -0
- package/dist/replication/receive.js.map +1 -0
- package/dist/replication/record-reducer.d.ts +16 -0
- package/dist/replication/record-reducer.d.ts.map +1 -0
- package/dist/replication/record-reducer.js +52 -0
- package/dist/replication/record-reducer.js.map +1 -0
- package/dist/replication/revision.d.ts +24 -0
- package/dist/replication/revision.d.ts.map +1 -0
- package/dist/replication/revision.js +35 -0
- package/dist/replication/revision.js.map +1 -0
- package/dist/replication/roster.d.ts +53 -0
- package/dist/replication/roster.d.ts.map +1 -0
- package/dist/replication/roster.js +115 -0
- package/dist/replication/roster.js.map +1 -0
- package/dist/replication/schedule.d.ts +73 -0
- package/dist/replication/schedule.d.ts.map +1 -0
- package/dist/replication/schedule.js +182 -0
- package/dist/replication/schedule.js.map +1 -0
- package/dist/replication/stream.d.ts +73 -0
- package/dist/replication/stream.d.ts.map +1 -0
- package/dist/replication/stream.js +542 -0
- package/dist/replication/stream.js.map +1 -0
- package/dist/replication/transport.d.ts +236 -0
- package/dist/replication/transport.d.ts.map +1 -0
- package/dist/replication/transport.js +440 -0
- package/dist/replication/transport.js.map +1 -0
- package/dist/replication/visibility-engine.d.ts +337 -0
- package/dist/replication/visibility-engine.d.ts.map +1 -0
- package/dist/replication/visibility-engine.js +602 -0
- package/dist/replication/visibility-engine.js.map +1 -0
- package/dist/replication/visibility-policy.d.ts +26 -0
- package/dist/replication/visibility-policy.d.ts.map +1 -0
- package/dist/replication/visibility-policy.js +33 -0
- package/dist/replication/visibility-policy.js.map +1 -0
- package/dist/replication/writer-identity-store.d.ts +100 -0
- package/dist/replication/writer-identity-store.d.ts.map +1 -0
- package/dist/replication/writer-identity-store.js +218 -0
- package/dist/replication/writer-identity-store.js.map +1 -0
- package/dist/replication/writer-identity.d.ts +252 -0
- package/dist/replication/writer-identity.d.ts.map +1 -0
- package/dist/replication/writer-identity.js +281 -0
- package/dist/replication/writer-identity.js.map +1 -0
- package/dist/replication/writer-identity.test-utils.d.ts +24 -0
- package/dist/replication/writer-identity.test-utils.d.ts.map +1 -0
- package/dist/replication/writer-identity.test-utils.js +86 -0
- package/dist/replication/writer-identity.test-utils.js.map +1 -0
- package/dist/schemas/server-config.d.ts +71 -0
- package/dist/schemas/server-config.d.ts.map +1 -1
- package/dist/schemas/server-config.js +151 -0
- package/dist/schemas/server-config.js.map +1 -1
- package/dist/signing/request-signer.d.ts +2 -0
- package/dist/signing/request-signer.d.ts.map +1 -1
- package/dist/signing/request-signer.js +1 -0
- package/dist/signing/request-signer.js.map +1 -1
- package/dist/storage/adapters/index.d.ts +3 -1
- package/dist/storage/adapters/index.d.ts.map +1 -1
- package/dist/storage/adapters/index.js +2 -0
- package/dist/storage/adapters/index.js.map +1 -1
- package/dist/storage/adapters/interface.d.ts +21 -1
- package/dist/storage/adapters/interface.d.ts.map +1 -1
- package/dist/storage/adapters/interface.js +13 -1
- package/dist/storage/adapters/interface.js.map +1 -1
- package/dist/storage/adapters/sdk.d.ts +2 -1
- package/dist/storage/adapters/sdk.d.ts.map +1 -1
- package/dist/storage/adapters/sdk.js +21 -3
- package/dist/storage/adapters/sdk.js.map +1 -1
- package/dist/storage/adapters/vana-audience.d.ts +24 -0
- package/dist/storage/adapters/vana-audience.d.ts.map +1 -0
- package/dist/storage/adapters/vana-audience.js +87 -0
- package/dist/storage/adapters/vana-audience.js.map +1 -0
- package/dist/storage/adapters/vana.d.ts +5 -3
- package/dist/storage/adapters/vana.d.ts.map +1 -1
- package/dist/storage/adapters/vana.js +69 -23
- package/dist/storage/adapters/vana.js.map +1 -1
- package/dist/storage/blocks/cursor.d.ts +5 -1
- package/dist/storage/blocks/cursor.d.ts.map +1 -1
- package/dist/storage/blocks/cursor.js +13 -1
- package/dist/storage/blocks/cursor.js.map +1 -1
- package/dist/storage/blocks/page.d.ts +18 -0
- package/dist/storage/blocks/page.d.ts.map +1 -0
- package/dist/storage/blocks/page.js +113 -0
- package/dist/storage/blocks/page.js.map +1 -0
- package/dist/storage/canonical-legacy-projection.d.ts +262 -0
- package/dist/storage/canonical-legacy-projection.d.ts.map +1 -0
- package/dist/storage/canonical-legacy-projection.js +759 -0
- package/dist/storage/canonical-legacy-projection.js.map +1 -0
- package/dist/storage/hierarchy/paths.d.ts.map +1 -1
- package/dist/storage/hierarchy/paths.js +9 -2
- package/dist/storage/hierarchy/paths.js.map +1 -1
- package/dist/storage/index/manager.d.ts +30 -3
- package/dist/storage/index/manager.d.ts.map +1 -1
- package/dist/storage/index/schema.d.ts +1 -1
- package/dist/storage/index/schema.js +1 -1
- package/dist/storage/index/types.d.ts +7 -1
- package/dist/storage/index/types.d.ts.map +1 -1
- package/dist/storage/legacy-projection.d.ts +88 -0
- package/dist/storage/legacy-projection.d.ts.map +1 -0
- package/dist/storage/legacy-projection.js +755 -0
- package/dist/storage/legacy-projection.js.map +1 -0
- package/dist/storage/legacy-scope-coverage-exceptions.d.ts +13 -0
- package/dist/storage/legacy-scope-coverage-exceptions.d.ts.map +1 -0
- package/dist/storage/legacy-scope-coverage-exceptions.js +14 -0
- package/dist/storage/legacy-scope-coverage-exceptions.js.map +1 -0
- package/dist/storage/legacy-scope-coverage.d.ts +53 -0
- package/dist/storage/legacy-scope-coverage.d.ts.map +1 -0
- package/dist/storage/legacy-scope-coverage.js +416 -0
- package/dist/storage/legacy-scope-coverage.js.map +1 -0
- package/dist/storage/legacy-scope-entity-keys.d.ts +17 -0
- package/dist/storage/legacy-scope-entity-keys.d.ts.map +1 -0
- package/dist/storage/legacy-scope-entity-keys.js +109 -0
- package/dist/storage/legacy-scope-entity-keys.js.map +1 -0
- package/dist/storage/legacy-scope-view.d.ts +206 -0
- package/dist/storage/legacy-scope-view.d.ts.map +1 -0
- package/dist/storage/legacy-scope-view.js +1061 -0
- package/dist/storage/legacy-scope-view.js.map +1 -0
- package/dist/storage/pdpp-records/completion.d.ts +91 -0
- package/dist/storage/pdpp-records/completion.d.ts.map +1 -0
- package/dist/storage/pdpp-records/completion.js +170 -0
- package/dist/storage/pdpp-records/completion.js.map +1 -0
- package/dist/storage/pdpp-records/cursor.d.ts +86 -0
- package/dist/storage/pdpp-records/cursor.d.ts.map +1 -0
- package/dist/storage/pdpp-records/cursor.js +56 -0
- package/dist/storage/pdpp-records/cursor.js.map +1 -0
- package/dist/storage/pdpp-records/declaration-witness.d.ts +58 -0
- package/dist/storage/pdpp-records/declaration-witness.d.ts.map +1 -0
- package/dist/storage/pdpp-records/declaration-witness.js +230 -0
- package/dist/storage/pdpp-records/declaration-witness.js.map +1 -0
- package/dist/storage/pdpp-records/enforcement.d.ts +39 -0
- package/dist/storage/pdpp-records/enforcement.d.ts.map +1 -0
- package/dist/storage/pdpp-records/enforcement.js +143 -0
- package/dist/storage/pdpp-records/enforcement.js.map +1 -0
- package/dist/storage/pdpp-records/index.d.ts +7 -0
- package/dist/storage/pdpp-records/index.d.ts.map +1 -0
- package/dist/storage/pdpp-records/index.js +6 -0
- package/dist/storage/pdpp-records/index.js.map +1 -0
- package/dist/storage/pdpp-records/ingest-plan.d.ts +39 -0
- package/dist/storage/pdpp-records/ingest-plan.d.ts.map +1 -0
- package/dist/storage/pdpp-records/ingest-plan.js +103 -0
- package/dist/storage/pdpp-records/ingest-plan.js.map +1 -0
- package/dist/storage/pdpp-records/interface.d.ts +111 -0
- package/dist/storage/pdpp-records/interface.d.ts.map +1 -0
- package/dist/storage/pdpp-records/interface.js +2 -0
- package/dist/storage/pdpp-records/interface.js.map +1 -0
- package/dist/storage/pdpp-records/list-page.d.ts +35 -0
- package/dist/storage/pdpp-records/list-page.d.ts.map +1 -0
- package/dist/storage/pdpp-records/list-page.js +106 -0
- package/dist/storage/pdpp-records/list-page.js.map +1 -0
- package/dist/storage/pdpp-records/memory-store.d.ts +9 -0
- package/dist/storage/pdpp-records/memory-store.d.ts.map +1 -0
- package/dist/storage/pdpp-records/memory-store.js +462 -0
- package/dist/storage/pdpp-records/memory-store.js.map +1 -0
- package/dist/storage/pdpp-records/portable.d.ts +12 -0
- package/dist/storage/pdpp-records/portable.d.ts.map +1 -0
- package/dist/storage/pdpp-records/portable.js +11 -0
- package/dist/storage/pdpp-records/portable.js.map +1 -0
- package/dist/storage/pdpp-records/read-port.d.ts +44 -0
- package/dist/storage/pdpp-records/read-port.d.ts.map +1 -0
- package/dist/storage/pdpp-records/read-port.js +22 -0
- package/dist/storage/pdpp-records/read-port.js.map +1 -0
- package/dist/storage/pdpp-records/record-key.d.ts +52 -0
- package/dist/storage/pdpp-records/record-key.d.ts.map +1 -0
- package/dist/storage/pdpp-records/record-key.js +97 -0
- package/dist/storage/pdpp-records/record-key.js.map +1 -0
- package/dist/storage/pdpp-records/replication-journal.d.ts +20 -0
- package/dist/storage/pdpp-records/replication-journal.d.ts.map +1 -0
- package/dist/storage/pdpp-records/replication-journal.js +2 -0
- package/dist/storage/pdpp-records/replication-journal.js.map +1 -0
- package/dist/storage/pdpp-records/schema.d.ts +41 -0
- package/dist/storage/pdpp-records/schema.d.ts.map +1 -0
- package/dist/storage/pdpp-records/schema.js +153 -0
- package/dist/storage/pdpp-records/schema.js.map +1 -0
- package/dist/storage/pdpp-records/stream-declaration.d.ts +86 -0
- package/dist/storage/pdpp-records/stream-declaration.d.ts.map +1 -0
- package/dist/storage/pdpp-records/stream-declaration.js +48 -0
- package/dist/storage/pdpp-records/stream-declaration.js.map +1 -0
- package/dist/storage/pdpp-records/sync-selection.d.ts +4 -0
- package/dist/storage/pdpp-records/sync-selection.d.ts.map +1 -0
- package/dist/storage/pdpp-records/sync-selection.js +37 -0
- package/dist/storage/pdpp-records/sync-selection.js.map +1 -0
- package/dist/storage/pdpp-records/types.d.ts +202 -0
- package/dist/storage/pdpp-records/types.d.ts.map +1 -0
- package/dist/storage/pdpp-records/types.js +38 -0
- package/dist/storage/pdpp-records/types.js.map +1 -0
- package/dist/stream-sync/artifacts.d.ts +31 -0
- package/dist/stream-sync/artifacts.d.ts.map +1 -0
- package/dist/stream-sync/artifacts.js +106 -0
- package/dist/stream-sync/artifacts.js.map +1 -0
- package/dist/stream-sync/blobs.d.ts +11 -0
- package/dist/stream-sync/blobs.d.ts.map +1 -0
- package/dist/stream-sync/blobs.js +34 -0
- package/dist/stream-sync/blobs.js.map +1 -0
- package/dist/stream-sync/crypto.d.ts +21 -0
- package/dist/stream-sync/crypto.d.ts.map +1 -0
- package/dist/stream-sync/crypto.js +45 -0
- package/dist/stream-sync/crypto.js.map +1 -0
- package/dist/stream-sync/home.d.ts +46 -0
- package/dist/stream-sync/home.d.ts.map +1 -0
- package/dist/stream-sync/home.js +37 -0
- package/dist/stream-sync/home.js.map +1 -0
- package/dist/stream-sync/index.d.ts +14 -0
- package/dist/stream-sync/index.d.ts.map +1 -0
- package/dist/stream-sync/index.js +14 -0
- package/dist/stream-sync/index.js.map +1 -0
- package/dist/stream-sync/intake.d.ts +165 -0
- package/dist/stream-sync/intake.d.ts.map +1 -0
- package/dist/stream-sync/intake.js +467 -0
- package/dist/stream-sync/intake.js.map +1 -0
- package/dist/stream-sync/io-barrier.d.ts +39 -0
- package/dist/stream-sync/io-barrier.d.ts.map +1 -0
- package/dist/stream-sync/io-barrier.js +130 -0
- package/dist/stream-sync/io-barrier.js.map +1 -0
- package/dist/stream-sync/memory-files.d.ts +6 -0
- package/dist/stream-sync/memory-files.d.ts.map +1 -0
- package/dist/stream-sync/memory-files.js +50 -0
- package/dist/stream-sync/memory-files.js.map +1 -0
- package/dist/stream-sync/ports.d.ts +134 -0
- package/dist/stream-sync/ports.d.ts.map +1 -0
- package/dist/stream-sync/ports.js +26 -0
- package/dist/stream-sync/ports.js.map +1 -0
- package/dist/stream-sync/publish-plan.d.ts +157 -0
- package/dist/stream-sync/publish-plan.d.ts.map +1 -0
- package/dist/stream-sync/publish-plan.js +212 -0
- package/dist/stream-sync/publish-plan.js.map +1 -0
- package/dist/stream-sync/registry.d.ts +19 -0
- package/dist/stream-sync/registry.d.ts.map +1 -0
- package/dist/stream-sync/registry.js +125 -0
- package/dist/stream-sync/registry.js.map +1 -0
- package/dist/stream-sync/scope-routing.d.ts +17 -0
- package/dist/stream-sync/scope-routing.d.ts.map +1 -0
- package/dist/stream-sync/scope-routing.js +24 -0
- package/dist/stream-sync/scope-routing.js.map +1 -0
- package/dist/stream-sync/spool.d.ts +69 -0
- package/dist/stream-sync/spool.d.ts.map +1 -0
- package/dist/stream-sync/spool.js +197 -0
- package/dist/stream-sync/spool.js.map +1 -0
- package/dist/stream-sync/writer-overlay.d.ts +19 -0
- package/dist/stream-sync/writer-overlay.d.ts.map +1 -0
- package/dist/stream-sync/writer-overlay.js +55 -0
- package/dist/stream-sync/writer-overlay.js.map +1 -0
- package/dist/stream-sync/writer.d.ts +404 -0
- package/dist/stream-sync/writer.d.ts.map +1 -0
- package/dist/stream-sync/writer.js +1994 -0
- package/dist/stream-sync/writer.js.map +1 -0
- package/dist/stream-sync-read/fold.d.ts +69 -0
- package/dist/stream-sync-read/fold.d.ts.map +1 -0
- package/dist/stream-sync-read/fold.js +83 -0
- package/dist/stream-sync-read/fold.js.map +1 -0
- package/dist/stream-sync-read/importer.d.ts +81 -0
- package/dist/stream-sync-read/importer.d.ts.map +1 -0
- package/dist/stream-sync-read/importer.js +226 -0
- package/dist/stream-sync-read/importer.js.map +1 -0
- package/dist/stream-sync-read/index.d.ts +8 -0
- package/dist/stream-sync-read/index.d.ts.map +1 -0
- package/dist/stream-sync-read/index.js +5 -0
- package/dist/stream-sync-read/index.js.map +1 -0
- package/dist/stream-sync-read/keys.d.ts +16 -0
- package/dist/stream-sync-read/keys.d.ts.map +1 -0
- package/dist/stream-sync-read/keys.js +48 -0
- package/dist/stream-sync-read/keys.js.map +1 -0
- package/dist/stream-sync-read/lines.d.ts +37 -0
- package/dist/stream-sync-read/lines.d.ts.map +1 -0
- package/dist/stream-sync-read/lines.js +98 -0
- package/dist/stream-sync-read/lines.js.map +1 -0
- package/dist/stream-sync-read/memory-files.d.ts +6 -0
- package/dist/stream-sync-read/memory-files.d.ts.map +1 -0
- package/dist/stream-sync-read/memory-files.js +34 -0
- package/dist/stream-sync-read/memory-files.js.map +1 -0
- package/dist/stream-sync-read/mirror.d.ts +80 -0
- package/dist/stream-sync-read/mirror.d.ts.map +1 -0
- package/dist/stream-sync-read/mirror.js +189 -0
- package/dist/stream-sync-read/mirror.js.map +1 -0
- package/dist/stream-sync-read/ports.d.ts +155 -0
- package/dist/stream-sync-read/ports.d.ts.map +1 -0
- package/dist/stream-sync-read/ports.js +9 -0
- package/dist/stream-sync-read/ports.js.map +1 -0
- package/dist/stream-sync-read/projection.d.ts +47 -0
- package/dist/stream-sync-read/projection.d.ts.map +1 -0
- package/dist/stream-sync-read/projection.js +338 -0
- package/dist/stream-sync-read/projection.js.map +1 -0
- package/dist/stream-sync-read/routing.d.ts +27 -0
- package/dist/stream-sync-read/routing.d.ts.map +1 -0
- package/dist/stream-sync-read/routing.js +49 -0
- package/dist/stream-sync-read/routing.js.map +1 -0
- package/dist/stream-sync-read/service-fixture.d.ts +94 -0
- package/dist/stream-sync-read/service-fixture.d.ts.map +1 -0
- package/dist/stream-sync-read/service-fixture.js +227 -0
- package/dist/stream-sync-read/service-fixture.js.map +1 -0
- package/dist/stream-sync-read/service.d.ts +260 -0
- package/dist/stream-sync-read/service.d.ts.map +1 -0
- package/dist/stream-sync-read/service.js +975 -0
- package/dist/stream-sync-read/service.js.map +1 -0
- package/dist/stream-sync-read/testing.d.ts +54 -0
- package/dist/stream-sync-read/testing.d.ts.map +1 -0
- package/dist/stream-sync-read/testing.js +80 -0
- package/dist/stream-sync-read/testing.js.map +1 -0
- package/dist/stream-sync-read/view-store.d.ts +98 -0
- package/dist/stream-sync-read/view-store.d.ts.map +1 -0
- package/dist/stream-sync-read/view-store.js +278 -0
- package/dist/stream-sync-read/view-store.js.map +1 -0
- package/dist/stream-sync-read/writer-rig.d.ts +122 -0
- package/dist/stream-sync-read/writer-rig.d.ts.map +1 -0
- package/dist/stream-sync-read/writer-rig.js +301 -0
- package/dist/stream-sync-read/writer-rig.js.map +1 -0
- package/dist/sync/data-point-feed.d.ts +3 -0
- package/dist/sync/data-point-feed.d.ts.map +1 -1
- package/dist/sync/data-point-feed.js +20 -1
- package/dist/sync/data-point-feed.js.map +1 -1
- package/dist/sync/delete-data-port.d.ts +19 -0
- package/dist/sync/delete-data-port.d.ts.map +1 -1
- package/dist/sync/delete-data-port.js +42 -9
- package/dist/sync/delete-data-port.js.map +1 -1
- package/dist/sync/engine/sync-manager.d.ts +21 -1
- package/dist/sync/engine/sync-manager.d.ts.map +1 -1
- package/dist/sync/engine/sync-manager.js +140 -11
- package/dist/sync/engine/sync-manager.js.map +1 -1
- package/dist/sync/index.d.ts +6 -2
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +7 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/pdpp-import.d.ts +192 -0
- package/dist/sync/pdpp-import.d.ts.map +1 -0
- package/dist/sync/pdpp-import.js +441 -0
- package/dist/sync/pdpp-import.js.map +1 -0
- package/dist/sync/pending-blob-deletions.d.ts +18 -2
- package/dist/sync/pending-blob-deletions.d.ts.map +1 -1
- package/dist/sync/pending-blob-deletions.js +97 -23
- package/dist/sync/pending-blob-deletions.js.map +1 -1
- package/dist/sync/scope-deletions.d.ts +12 -0
- package/dist/sync/scope-deletions.d.ts.map +1 -1
- package/dist/sync/scope-deletions.js +99 -25
- package/dist/sync/scope-deletions.js.map +1 -1
- package/dist/sync/tombstone-finality.d.ts +36 -0
- package/dist/sync/tombstone-finality.d.ts.map +1 -0
- package/dist/sync/tombstone-finality.js +142 -0
- package/dist/sync/tombstone-finality.js.map +1 -0
- package/dist/sync/tombstone-resubmits.d.ts +61 -0
- package/dist/sync/tombstone-resubmits.d.ts.map +1 -0
- package/dist/sync/tombstone-resubmits.js +85 -0
- package/dist/sync/tombstone-resubmits.js.map +1 -0
- package/dist/sync/types.d.ts +10 -0
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/sync/workers/delete.d.ts +54 -5
- package/dist/sync/workers/delete.d.ts.map +1 -1
- package/dist/sync/workers/delete.js +594 -170
- package/dist/sync/workers/delete.js.map +1 -1
- package/dist/sync/workers/download.d.ts +42 -1
- package/dist/sync/workers/download.d.ts.map +1 -1
- package/dist/sync/workers/download.js +344 -24
- package/dist/sync/workers/download.js.map +1 -1
- package/dist/sync/workers/lost-data-points.d.ts +38 -0
- package/dist/sync/workers/lost-data-points.d.ts.map +1 -0
- package/dist/sync/workers/lost-data-points.js +72 -0
- package/dist/sync/workers/lost-data-points.js.map +1 -0
- package/dist/sync/workers/upload.d.ts +27 -6
- package/dist/sync/workers/upload.d.ts.map +1 -1
- package/dist/sync/workers/upload.js +169 -274
- package/dist/sync/workers/upload.js.map +1 -1
- package/dist/test-utils/memory-storage.d.ts +1 -1
- package/dist/test-utils/memory-storage.d.ts.map +1 -1
- package/dist/test-utils/memory-storage.js +83 -17
- package/dist/test-utils/memory-storage.js.map +1 -1
- package/dist/write/attribution.d.ts.map +1 -1
- package/dist/write/attribution.js +8 -4
- package/dist/write/attribution.js.map +1 -1
- package/dist/write/route.d.ts.map +1 -1
- package/dist/write/route.js +9 -10
- package/dist/write/route.js.map +1 -1
- package/dist/write/session.d.ts.map +1 -1
- package/dist/write/session.js +13 -0
- package/dist/write/session.js.map +1 -1
- package/package.json +103 -3
package/dist/api/index.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
+
import { isOwnAppRead } from "../payment/own-app.js";
|
|
2
|
+
import { isSystemScope } from "../policy/reserved-scopes.js";
|
|
1
3
|
import { DataDeletedError, DeleteTombstoneFailedError, GrantRequiredError, InvalidCascadeError, LineageCascadeUnavailableError, LineageGatewayError, LineageUnavailableError, ProtocolError, ServerNotConfiguredError, } from "../errors/catalog.js";
|
|
2
4
|
import { computeDataPointId } from "../sync/data-point-id.js";
|
|
3
5
|
import { isEntryCoveredByTombstone, } from "../sync/scope-deletions.js";
|
|
6
|
+
import { isPermanentRejection, } from "../sync/pdpp-import.js";
|
|
7
|
+
import { supersedeLegacyVersions, } from "../storage/legacy-projection.js";
|
|
4
8
|
import { deleteScope as deleteScopeLocally, } from "../sync/workers/delete.js";
|
|
5
|
-
import { ingestDataContract, ingestBinaryDataContract, listAccessLogsContract, listDataScopesContract, listDataVersionsContract, parseDataScopeContract, parseJsonObjectBody, readDataContract, syncFileContract, triggerSyncContract, getSyncStatusContract, configReadErrorContract, configWriteErrorContract, createGrantContract, listGrantsContract, oauthTokenContract, revokeGrantContract, validateServerConfigContract, verifyGrantContract, decodeBinaryEnvelope, isBinaryEnvelope, parseMetadataHeader, stringifyMetadataHeader, IngestPersistedError, } from "../contracts/index.js";
|
|
9
|
+
import { ingestDataContract, ingestBinaryDataContract, listAccessLogsContract, listDataScopesContract, listDataVersionsContract, parseDataReadScopeContract, parseDataScopeContract, parseJsonObjectBody, readDataContract, syncFileContract, triggerSyncContract, getSyncStatusContract, configReadErrorContract, configWriteErrorContract, createGrantContract, listGrantsContract, oauthTokenContract, revokeGrantContract, validateServerConfigContract, verifyGrantContract, decodeBinaryEnvelope, isBinaryEnvelope, parseMetadataHeader, stringifyMetadataHeader, IngestPersistedError, sha256Hex, } from "../contracts/index.js";
|
|
10
|
+
import { canonicalJsonBytes } from "../derivatives/e2ee/jcs.js";
|
|
11
|
+
// Imported directly: the contracts barrel does not re-export this addition.
|
|
12
|
+
import { summarizeDataAdditionsContract } from "../contracts/data.js";
|
|
13
|
+
import { scopeCoveredByGrant } from "@opendatalabs/vana-sdk/browser";
|
|
6
14
|
import { WRITER_ATTRIBUTION_KEY, } from "../write/attribution.js";
|
|
7
15
|
import { extractLineageField, LINEAGE_KEY, prepareLineage, } from "../lineage/lineage.js";
|
|
16
|
+
import { ScopeUploadError } from "./scope-uploads.js";
|
|
17
|
+
import { deletionHistoryOf, } from "../storage/legacy-scope-view.js";
|
|
8
18
|
import { binaryFilename, binaryMimeType, isJsonContentType, } from "../contracts/binary.js";
|
|
9
19
|
import { buildChallenge, parsePaymentHeader, verifyPayment, } from "../payment/index.js";
|
|
20
|
+
/**
|
|
21
|
+
* Stand-in for a grant/grantee that does not exist on a denial — a scope that
|
|
22
|
+
* no grant covers has no grant id and no builder to attribute the read to.
|
|
23
|
+
*/
|
|
24
|
+
export const READ_FULFILLMENT_NONE = "none";
|
|
10
25
|
function jsonResponse(body, init) {
|
|
11
26
|
const headers = new Headers(init?.headers);
|
|
12
27
|
headers.set("Content-Type", "application/json");
|
|
@@ -32,20 +47,174 @@ function encodePaymentResponseHeader(body) {
|
|
|
32
47
|
function contractResponse(result) {
|
|
33
48
|
return jsonResponse(result.body, { status: result.status });
|
|
34
49
|
}
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Runs after the write committed, so a failure here must not fail the
|
|
52
|
+
* write: it is logged and the response lists no superseded versions.
|
|
53
|
+
*/
|
|
54
|
+
async function supersedeAfterCommit(deps, scope, committedAt) {
|
|
55
|
+
try {
|
|
56
|
+
const result = await supersedeLegacyVersions(deps.storage, scope, committedAt);
|
|
57
|
+
if (result.superseded.length > 0) {
|
|
58
|
+
deps.logger?.info?.({ scope, committedAt, superseded: result.superseded }, "Deleted legacy-form versions superseded by a PDPP write");
|
|
59
|
+
}
|
|
60
|
+
if (result.refused) {
|
|
61
|
+
deps.logger?.info?.({ scope, committedAt, refused: result.refused }, "Kept legacy-form versions; superseding was refused");
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
deps.logger?.warn?.({
|
|
67
|
+
scope,
|
|
68
|
+
committedAt,
|
|
69
|
+
error: err instanceof Error ? err.message : String(err),
|
|
70
|
+
}, "Superseding legacy-form versions failed; the write is stored");
|
|
71
|
+
return { superseded: [], refused: "superseding failed" };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function contractErrorResponse(err, notes) {
|
|
75
|
+
return jsonResponse(withOwnerBody(err.body, notes), {
|
|
76
|
+
status: err.status,
|
|
77
|
+
headers: ownerNoteHeaders(notes),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** What only the owner is told when the existing path answers a stream read. */
|
|
81
|
+
function ownerNoteHeaders(notes) {
|
|
82
|
+
const headers = {};
|
|
83
|
+
if (notes?.withheld?.length) {
|
|
84
|
+
headers["X-Stream-Sync-Withheld"] = withheldReasons(notes.withheld);
|
|
85
|
+
}
|
|
86
|
+
if (notes?.pending) {
|
|
87
|
+
headers["X-Stream-Sync-Pending"] = String(notes.pending.runs);
|
|
88
|
+
}
|
|
89
|
+
if (notes?.awaitingImport) {
|
|
90
|
+
headers["X-Stream-Sync-Awaiting-Import"] = String(notes.awaitingImport.runs);
|
|
91
|
+
}
|
|
92
|
+
if (notes?.notReflected) {
|
|
93
|
+
headers["X-Stream-Sync-Not-Reflected"] = String(notes.notReflected.streams);
|
|
94
|
+
}
|
|
95
|
+
return headers;
|
|
96
|
+
}
|
|
97
|
+
function withOwnerBody(body, notes) {
|
|
98
|
+
return notes?.withheld?.length ? { ...body, withheld: notes.withheld } : body;
|
|
37
99
|
}
|
|
38
100
|
function protocolErrorResponse(err) {
|
|
39
101
|
return jsonResponse(err.toJSON(), { status: err.code });
|
|
40
102
|
}
|
|
41
|
-
function errorResponse(status, errorCode, message) {
|
|
42
|
-
return jsonResponse({
|
|
103
|
+
function errorResponse(status, errorCode, message, notes) {
|
|
104
|
+
return jsonResponse(withOwnerBody({
|
|
43
105
|
error: {
|
|
44
106
|
code: status,
|
|
45
107
|
errorCode,
|
|
46
108
|
message,
|
|
47
109
|
},
|
|
48
|
-
}, { status });
|
|
110
|
+
}, notes), { status, headers: ownerNoteHeaders(notes) });
|
|
111
|
+
}
|
|
112
|
+
/** The response for a stream-sync decision that serves nothing; `null` otherwise. */
|
|
113
|
+
function streamSyncRefusal(decision) {
|
|
114
|
+
switch (decision.kind) {
|
|
115
|
+
case "unavailable":
|
|
116
|
+
return decision.reason === "connection_not_found"
|
|
117
|
+
? errorResponse(404, "CONNECTION_NOT_FOUND", "No connection of this name's connector matches the connection parameter", decision)
|
|
118
|
+
: null;
|
|
119
|
+
case "key_mismatch":
|
|
120
|
+
return errorResponse(503, "KEY_MISMATCH", "This data was written with another owner key and cannot be read here");
|
|
121
|
+
case "cursor_stale":
|
|
122
|
+
return errorResponse(409, "CURSOR_STALE", "The cursor names a version this server no longer holds; read again without it");
|
|
123
|
+
case "busy":
|
|
124
|
+
return jsonResponse({
|
|
125
|
+
error: {
|
|
126
|
+
code: 503,
|
|
127
|
+
errorCode: "STREAM_SYNC_READ_BUSY",
|
|
128
|
+
message: "This data is changing; read again shortly",
|
|
129
|
+
},
|
|
130
|
+
}, {
|
|
131
|
+
status: 503,
|
|
132
|
+
headers: { "Retry-After": String(decision.retryAfterSeconds) },
|
|
133
|
+
});
|
|
134
|
+
case "invalid_cursor":
|
|
135
|
+
return errorResponse(400, "INVALID_CURSOR", "cursor is not valid");
|
|
136
|
+
case "invalid_connection":
|
|
137
|
+
return errorResponse(400, "INVALID_CONNECTION", "connection must be empty or 16 lowercase hex characters");
|
|
138
|
+
case "too_large":
|
|
139
|
+
return errorResponse(503, "TOO_LARGE", "This legacy view is larger than this server can build; read its streams instead");
|
|
140
|
+
default:
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Serve a stream view: the envelope streams part by part. A charged read
|
|
146
|
+
* has already paid (`paymentResponseHeader`).
|
|
147
|
+
*/
|
|
148
|
+
async function serveStreamSyncView(deps, request, input) {
|
|
149
|
+
const { authResult, decision } = input;
|
|
150
|
+
const logId = deps.createLogId?.() ?? crypto.randomUUID();
|
|
151
|
+
const timestamp = (deps.now ?? (() => new Date()))().toISOString();
|
|
152
|
+
const ipAddress = request.headers.get("x-forwarded-for") ??
|
|
153
|
+
request.headers.get("x-real-ip") ??
|
|
154
|
+
"unknown";
|
|
155
|
+
const userAgent = request.headers.get("user-agent") ?? "unknown";
|
|
156
|
+
try {
|
|
157
|
+
await deps.accessLogWriter.write({
|
|
158
|
+
logId,
|
|
159
|
+
grantId: authResult?.grantId ?? input.grantId ?? "unknown",
|
|
160
|
+
builder: authResult?.builder ?? "unknown",
|
|
161
|
+
action: "read",
|
|
162
|
+
scope: input.scope,
|
|
163
|
+
timestamp,
|
|
164
|
+
ipAddress,
|
|
165
|
+
userAgent,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
await decision.body.cancel();
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
if (authResult?.grantId && authResult.builder) {
|
|
173
|
+
reportPersonalServerReadFulfillment(deps, {
|
|
174
|
+
builder: authResult.builder,
|
|
175
|
+
fileId: undefined,
|
|
176
|
+
grantId: authResult.grantId,
|
|
177
|
+
ipAddress,
|
|
178
|
+
logId,
|
|
179
|
+
outcome: "served",
|
|
180
|
+
scope: input.scope,
|
|
181
|
+
servedAt: timestamp,
|
|
182
|
+
source: "api",
|
|
183
|
+
userAgent,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
// A projection can fail after the 200 status. The client must then see
|
|
187
|
+
// the connection abort, never a complete shorter body. Chunked framing
|
|
188
|
+
// also keeps @hono/node-server from reading the body ahead of the status:
|
|
189
|
+
// a failure in that read-ahead would end the response with a
|
|
190
|
+
// content-length of the bytes read so far, as if it were whole.
|
|
191
|
+
return new Response(decision.body, {
|
|
192
|
+
status: 200,
|
|
193
|
+
headers: {
|
|
194
|
+
"Content-Type": "application/json",
|
|
195
|
+
"Transfer-Encoding": "chunked",
|
|
196
|
+
"X-Vana-Data-Source": "stream-sync",
|
|
197
|
+
"X-Stream-Sync-Cursor": decision.cursor,
|
|
198
|
+
// An owner-only view built on this device; it may be partial.
|
|
199
|
+
...(decision.kind === "local_pending"
|
|
200
|
+
? {
|
|
201
|
+
"X-Stream-Sync-Origin": "local-pending",
|
|
202
|
+
"X-Stream-Sync-Complete": String(decision.complete),
|
|
203
|
+
}
|
|
204
|
+
: {}),
|
|
205
|
+
// Owner only: the service attaches this to no other audience.
|
|
206
|
+
...(decision.withheld?.length
|
|
207
|
+
? { "X-Stream-Sync-Withheld": withheldReasons(decision.withheld) }
|
|
208
|
+
: {}),
|
|
209
|
+
...(input.paymentResponseHeader
|
|
210
|
+
? { "X-PAYMENT-RESPONSE": input.paymentResponseHeader }
|
|
211
|
+
: {}),
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/** The distinct reasons of the withheld runs, for the response header. */
|
|
216
|
+
function withheldReasons(withheld) {
|
|
217
|
+
return [...new Set(withheld.map((w) => w.reason))].join(",");
|
|
49
218
|
}
|
|
50
219
|
function methodNotAllowed() {
|
|
51
220
|
return errorResponse(405, "METHOD_NOT_ALLOWED", "Method not allowed");
|
|
@@ -53,17 +222,80 @@ function methodNotAllowed() {
|
|
|
53
222
|
function notFound() {
|
|
54
223
|
return errorResponse(404, "NOT_FOUND", "Not found");
|
|
55
224
|
}
|
|
56
|
-
async function withApiErrors(handler) {
|
|
225
|
+
async function withApiErrors(handler, context) {
|
|
57
226
|
try {
|
|
58
|
-
|
|
227
|
+
const response = await handler();
|
|
228
|
+
// A handled 4xx that means "the index and the disk disagree" is an
|
|
229
|
+
// operator-facing fault even though it is not a 500 — log it once, here,
|
|
230
|
+
// rather than at the contract that cannot see the route.
|
|
231
|
+
if (response.status === 404 && context) {
|
|
232
|
+
await logMissingDataFile(response, context);
|
|
233
|
+
}
|
|
234
|
+
return response;
|
|
59
235
|
}
|
|
60
236
|
catch (err) {
|
|
61
237
|
if (err instanceof ProtocolError) {
|
|
62
238
|
return protocolErrorResponse(err);
|
|
63
239
|
}
|
|
240
|
+
if (context) {
|
|
241
|
+
context.logger?.error?.({
|
|
242
|
+
route: context.route,
|
|
243
|
+
requestId: context.requestId ?? crypto.randomUUID(),
|
|
244
|
+
errorCode: "INTERNAL_ERROR",
|
|
245
|
+
...stripUndefined(context.detail),
|
|
246
|
+
err: describeError(err),
|
|
247
|
+
}, "Unhandled error in personal server API");
|
|
248
|
+
}
|
|
64
249
|
return errorResponse(500, "INTERNAL_ERROR", "Internal server error");
|
|
65
250
|
}
|
|
66
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* The `DATA_FILE_MISSING` 404 the read contract produces, logged at the one
|
|
254
|
+
* layer that knows which route served it. Peeks at a clone so the response
|
|
255
|
+
* body stays readable by the caller.
|
|
256
|
+
*/
|
|
257
|
+
async function logMissingDataFile(response, context) {
|
|
258
|
+
if (!context.logger?.error)
|
|
259
|
+
return;
|
|
260
|
+
try {
|
|
261
|
+
const body = await response.clone().json();
|
|
262
|
+
if (typeof body !== "object" ||
|
|
263
|
+
body === null ||
|
|
264
|
+
body.error !== "DATA_FILE_MISSING") {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
context.logger.error({
|
|
268
|
+
route: context.route,
|
|
269
|
+
requestId: context.requestId ?? crypto.randomUUID(),
|
|
270
|
+
errorCode: "DATA_FILE_MISSING",
|
|
271
|
+
...stripUndefined(context.detail),
|
|
272
|
+
}, "Indexed data file is missing on disk");
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
// A diagnostic log must not change the response sent to the caller.
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* An error rendered for a log line — name, message and stack only. Never the
|
|
280
|
+
* whole object: a thrown error can carry a request, a config or a token on an
|
|
281
|
+
* arbitrary property, and a structured logger would serialize all of it.
|
|
282
|
+
*/
|
|
283
|
+
function describeError(err) {
|
|
284
|
+
if (err instanceof Error) {
|
|
285
|
+
return {
|
|
286
|
+
name: err.name,
|
|
287
|
+
message: err.message,
|
|
288
|
+
...("code" in err && { code: err.code }),
|
|
289
|
+
stack: err.stack,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return { message: String(err) };
|
|
293
|
+
}
|
|
294
|
+
function stripUndefined(detail) {
|
|
295
|
+
if (!detail)
|
|
296
|
+
return {};
|
|
297
|
+
return Object.fromEntries(Object.entries(detail).filter((pair) => pair[1] !== undefined));
|
|
298
|
+
}
|
|
67
299
|
function normalizeLimit(value, fallback) {
|
|
68
300
|
if (value === null)
|
|
69
301
|
return fallback;
|
|
@@ -95,6 +327,144 @@ export function selectedGrantId(request, url) {
|
|
|
95
327
|
request.headers.get("x-ps-grant-id") ??
|
|
96
328
|
undefined);
|
|
97
329
|
}
|
|
330
|
+
function listAuthCovers(listAuth, scope) {
|
|
331
|
+
return (!isSystemScope(scope) &&
|
|
332
|
+
scopeCoveredByGrant(scope, [...listAuth.grantedScopes]));
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Whether the app reading is the data owner's own app, which is exempt from
|
|
336
|
+
* the read fee. `false` when no Account authority is configured or the read
|
|
337
|
+
* is owner-signalled; a `Response` (503) when eligibility cannot be
|
|
338
|
+
* verified, so a read is never served free on missing evidence.
|
|
339
|
+
*/
|
|
340
|
+
async function ownAppReadStatus(deps, authResult) {
|
|
341
|
+
const isOwnerSignal = authResult?.grantId === "owner" || authResult?.grantId === "policy-bypass";
|
|
342
|
+
const builder = authResult?.builder;
|
|
343
|
+
if (!deps.paymentEnabled ||
|
|
344
|
+
isOwnerSignal ||
|
|
345
|
+
!authResult?.grantId ||
|
|
346
|
+
!builder ||
|
|
347
|
+
!deps.ownAppAccountUrl) {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
const unavailable = () => errorResponse(503, "OWN_APP_ELIGIBILITY_UNAVAILABLE", "Own-app fee eligibility could not be verified");
|
|
351
|
+
if (!deps.serverOwner || !deps.gatewayConfig)
|
|
352
|
+
return unavailable();
|
|
353
|
+
try {
|
|
354
|
+
return await isOwnAppRead({
|
|
355
|
+
accountUrl: deps.ownAppAccountUrl,
|
|
356
|
+
appAddress: builder,
|
|
357
|
+
dataOwner: deps.serverOwner,
|
|
358
|
+
chainId: deps.gatewayConfig.chainId,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
return unavailable();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Whether a read is charged, and with what. Owner-exempt reads (the grantId
|
|
367
|
+
* sentinels "owner" / "policy-bypass") are never charged: there is no
|
|
368
|
+
* payable op to attach the payment to. The grantId paid against is the one
|
|
369
|
+
* verifyDataReadPolicy resolved from the Web3Signed payload (authoritative
|
|
370
|
+
* source), not the URL / header hint, which may be absent when the payload
|
|
371
|
+
* carries it. `null` = served free.
|
|
372
|
+
*/
|
|
373
|
+
function readCharge(deps, scope, authResult, ownAppRead) {
|
|
374
|
+
const isOwnerSignal = authResult?.grantId === "owner" || authResult?.grantId === "policy-bypass";
|
|
375
|
+
const builder = authResult?.builder;
|
|
376
|
+
const resolvedGrantId = !isOwnerSignal && authResult?.grantId ? authResult.grantId : undefined;
|
|
377
|
+
const willCharge = Boolean(deps.paymentEnabled &&
|
|
378
|
+
!isOwnerSignal &&
|
|
379
|
+
!ownAppRead &&
|
|
380
|
+
typeof builder === "string" &&
|
|
381
|
+
builder.startsWith("0x") &&
|
|
382
|
+
resolvedGrantId &&
|
|
383
|
+
deps.gateway &&
|
|
384
|
+
deps.gatewayConfig &&
|
|
385
|
+
deps.gatewayUrl);
|
|
386
|
+
// Diagnostic: makes it explicit why a read is/isn't charged. x402 has
|
|
387
|
+
// many "served free" branches (owner read, payment disabled, missing
|
|
388
|
+
// gateway deps); this surfaces the deciding inputs.
|
|
389
|
+
//
|
|
390
|
+
// Routing: when a logger is wired (the Node server always provides one),
|
|
391
|
+
// log the full detail through it at debug level so the operator's level
|
|
392
|
+
// controls + redaction apply and access metadata (scope/grantId/builder)
|
|
393
|
+
// doesn't unconditionally hit stdout. The browser PS-Lite runtime wires
|
|
394
|
+
// no logger; there we fall back to console but log ONLY the non-identifying
|
|
395
|
+
// decision booleans — never scope/grantId/builder.
|
|
396
|
+
if (deps.logger?.debug) {
|
|
397
|
+
deps.logger.debug({
|
|
398
|
+
scope,
|
|
399
|
+
grantId: authResult?.grantId,
|
|
400
|
+
isOwnerSignal,
|
|
401
|
+
builder,
|
|
402
|
+
resolvedGrantId,
|
|
403
|
+
paymentEnabled: Boolean(deps.paymentEnabled),
|
|
404
|
+
hasGateway: Boolean(deps.gateway),
|
|
405
|
+
hasGatewayConfig: Boolean(deps.gatewayConfig),
|
|
406
|
+
hasGatewayUrl: Boolean(deps.gatewayUrl),
|
|
407
|
+
willCharge,
|
|
408
|
+
}, "[x402-gate] read");
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
console.info("[x402-gate] read", {
|
|
412
|
+
isOwnerSignal,
|
|
413
|
+
paymentEnabled: Boolean(deps.paymentEnabled),
|
|
414
|
+
hasGateway: Boolean(deps.gateway),
|
|
415
|
+
hasGatewayConfig: Boolean(deps.gatewayConfig),
|
|
416
|
+
hasGatewayUrl: Boolean(deps.gatewayUrl),
|
|
417
|
+
willCharge,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
if (!willCharge ||
|
|
421
|
+
!resolvedGrantId ||
|
|
422
|
+
!deps.gateway ||
|
|
423
|
+
!deps.gatewayConfig ||
|
|
424
|
+
!deps.gatewayUrl) {
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
grantId: resolvedGrantId,
|
|
429
|
+
builder: builder,
|
|
430
|
+
gateway: deps.gateway,
|
|
431
|
+
gatewayConfig: deps.gatewayConfig,
|
|
432
|
+
gatewayUrl: deps.gatewayUrl,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* The X402 step of a charged read: a response to return instead of the
|
|
437
|
+
* body (a fresh 402 challenge, or the gateway's error relayed verbatim so
|
|
438
|
+
* the builder can dispatch on it), or the X-PAYMENT-RESPONSE value to send
|
|
439
|
+
* with the body once the gateway accepted the payment.
|
|
440
|
+
*/
|
|
441
|
+
async function payForRead(deps, request, charge, read) {
|
|
442
|
+
const x402Result = await handleX402Cycle({
|
|
443
|
+
deps,
|
|
444
|
+
request,
|
|
445
|
+
...read,
|
|
446
|
+
...charge,
|
|
447
|
+
});
|
|
448
|
+
if (x402Result.kind === "challenge") {
|
|
449
|
+
return {
|
|
450
|
+
kind: "refused",
|
|
451
|
+
response: jsonResponse(x402Result.body, { status: 402 }),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
if (x402Result.kind === "gateway-error") {
|
|
455
|
+
return {
|
|
456
|
+
kind: "refused",
|
|
457
|
+
response: jsonResponse(x402Result.body, { status: x402Result.status }),
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
// The gateway's success body goes back to the builder in
|
|
461
|
+
// X-PAYMENT-RESPONSE (canonical X402 convention) so callers can see
|
|
462
|
+
// breakdown / paidAt / paymentNonce without a second gateway round-trip.
|
|
463
|
+
return {
|
|
464
|
+
kind: "paid",
|
|
465
|
+
paymentResponseHeader: encodePaymentResponseHeader(x402Result.payResponse),
|
|
466
|
+
};
|
|
467
|
+
}
|
|
98
468
|
/**
|
|
99
469
|
* Run the X402 dispatch for one read:
|
|
100
470
|
*
|
|
@@ -131,19 +501,30 @@ export async function handleX402Cycle(input) {
|
|
|
131
501
|
};
|
|
132
502
|
}
|
|
133
503
|
// Bind the accessRecord to the entry being served, if it exists and has
|
|
134
|
-
// been registered with DPv2 yet.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
140
|
-
const entryForChallenge = entryRow
|
|
141
|
-
? {
|
|
142
|
-
dataPointId: entryRow.dataPointId,
|
|
504
|
+
// been registered with DPv2 yet. A served stream head is registered: it
|
|
505
|
+
// was listed from the registry.
|
|
506
|
+
const entryRow = input.servedEntry
|
|
507
|
+
? undefined
|
|
508
|
+
: deps.storage.findEntry({
|
|
143
509
|
scope,
|
|
144
|
-
|
|
510
|
+
fileId: input.fileIdParam,
|
|
511
|
+
at: input.atParam,
|
|
512
|
+
});
|
|
513
|
+
const entryForChallenge = input.servedEntry
|
|
514
|
+
? {
|
|
515
|
+
dataPointId: deps.serverOwner
|
|
516
|
+
? computeDataPointId(deps.serverOwner, input.servedEntry.scope)
|
|
517
|
+
: null,
|
|
518
|
+
scope: input.servedEntry.scope,
|
|
519
|
+
version: input.servedEntry.version,
|
|
145
520
|
}
|
|
146
|
-
:
|
|
521
|
+
: entryRow
|
|
522
|
+
? {
|
|
523
|
+
dataPointId: entryRow.dataPointId,
|
|
524
|
+
scope,
|
|
525
|
+
version: entryRow.version,
|
|
526
|
+
}
|
|
527
|
+
: undefined;
|
|
147
528
|
// `grant` is narrowed to non-null above, but that narrowing is not carried
|
|
148
529
|
// into this closure (vana-sdk 3.14.0 made getGrant return `... | null`), so
|
|
149
530
|
// capture the guaranteed-present value via a typed alias for the closure.
|
|
@@ -257,10 +638,102 @@ export async function handleX402Cycle(input) {
|
|
|
257
638
|
}
|
|
258
639
|
return { kind: "gateway-error", status: gatewayRes.status, body: errorBody };
|
|
259
640
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
641
|
+
const pendingIngestStamps = new WeakMap();
|
|
642
|
+
function reserveIngestStamp(now, storage, scope) {
|
|
643
|
+
// Bound allocation to 60 millisecond slots per scope, anchored to wall time.
|
|
644
|
+
// Failed requests release their slot; neither failures nor other scopes
|
|
645
|
+
// advance this scope's clock. The durable head protects restart/clock rollback.
|
|
646
|
+
const wall = now().getTime();
|
|
647
|
+
const latest = Date.parse(storage.findEntry({ scope })?.collectedAt ?? "");
|
|
648
|
+
let scopes = pendingIngestStamps.get(storage);
|
|
649
|
+
const pending = scopes?.get(scope) ?? new Set();
|
|
650
|
+
for (let stamp = wall; stamp < wall + 60; stamp += 1) {
|
|
651
|
+
if ((Number.isFinite(latest) && stamp <= latest) || pending.has(stamp)) {
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
if (!scopes) {
|
|
655
|
+
scopes = new Map();
|
|
656
|
+
pendingIngestStamps.set(storage, scopes);
|
|
657
|
+
}
|
|
658
|
+
scopes.set(scope, pending);
|
|
659
|
+
pending.add(stamp);
|
|
660
|
+
const reservations = scopes;
|
|
661
|
+
return {
|
|
662
|
+
collectedAt: new Date(stamp).toISOString(),
|
|
663
|
+
release() {
|
|
664
|
+
pending.delete(stamp);
|
|
665
|
+
if (pending.size === 0)
|
|
666
|
+
reservations.delete(scope);
|
|
667
|
+
},
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
return undefined;
|
|
671
|
+
}
|
|
672
|
+
function parseLegacyPrecondition(request) {
|
|
673
|
+
const none = request.headers.get("if-none-match");
|
|
674
|
+
const match = request.headers.get("if-match");
|
|
675
|
+
if (none !== null && match !== null) {
|
|
676
|
+
return errorResponse(400, "INVALID_PRECONDITION", "Supply only one precondition");
|
|
677
|
+
}
|
|
678
|
+
if (none !== null) {
|
|
679
|
+
return none === "*"
|
|
680
|
+
? { kind: "none" }
|
|
681
|
+
: errorResponse(400, "INVALID_PRECONDITION", "If-None-Match must be *");
|
|
682
|
+
}
|
|
683
|
+
if (match !== null) {
|
|
684
|
+
const parsed = /^"([1-9]\d*)"$/.exec(match);
|
|
685
|
+
const version = parsed ? Number(parsed[1]) : NaN;
|
|
686
|
+
return Number.isSafeInteger(version)
|
|
687
|
+
? { kind: "match", version }
|
|
688
|
+
: errorResponse(400, "INVALID_PRECONDITION", "If-Match must be a quoted positive version");
|
|
689
|
+
}
|
|
690
|
+
return undefined;
|
|
691
|
+
}
|
|
692
|
+
function parseProducerHeader(request) {
|
|
693
|
+
const producer = request.headers.get("vana-producer");
|
|
694
|
+
const encodedProvenance = request.headers.get("vana-producer-provenance") ?? undefined;
|
|
695
|
+
if (producer === null && !encodedProvenance)
|
|
696
|
+
return {};
|
|
697
|
+
if (producer !== "pdpp-projector" && producer !== "pdpp-import-projection") {
|
|
698
|
+
return errorResponse(400, "INVALID_PRODUCER", "Vana-Producer is unrecognized or missing");
|
|
699
|
+
}
|
|
700
|
+
if (encodedProvenance &&
|
|
701
|
+
(encodedProvenance.length > 8192 ||
|
|
702
|
+
!/^[A-Za-z0-9_-]+$/.test(encodedProvenance))) {
|
|
703
|
+
return errorResponse(400, "INVALID_PROVENANCE", "Vana-Producer-Provenance is malformed");
|
|
704
|
+
}
|
|
705
|
+
return { producer, encodedProvenance };
|
|
706
|
+
}
|
|
707
|
+
async function parseProducerProvenance(encoded, body) {
|
|
708
|
+
if (!encoded)
|
|
709
|
+
return undefined;
|
|
710
|
+
try {
|
|
711
|
+
const value = JSON.parse(new TextDecoder().decode(Uint8Array.from(atob(encoded.replace(/-/g, "+").replace(/_/g, "/")), (char) => char.charCodeAt(0))));
|
|
712
|
+
if (!value ||
|
|
713
|
+
typeof value !== "object" ||
|
|
714
|
+
typeof value.projector_version !== "string" ||
|
|
715
|
+
!value.projector_version ||
|
|
716
|
+
typeof value.declaration_digest !== "string" ||
|
|
717
|
+
!value.declaration_digest ||
|
|
718
|
+
!Array.isArray(value.inputs) ||
|
|
719
|
+
!value.inputs.every((input) => input &&
|
|
720
|
+
typeof input.stream === "string" &&
|
|
721
|
+
input.stream &&
|
|
722
|
+
typeof input.changes_since_token === "string" &&
|
|
723
|
+
input.changes_since_token) ||
|
|
724
|
+
typeof value.payload_sha256 !== "string" ||
|
|
725
|
+
!/^(?:0x)?[0-9a-fA-F]{64}$/.test(value.payload_sha256)) {
|
|
726
|
+
return errorResponse(400, "INVALID_PROVENANCE", "Producer provenance has invalid fields");
|
|
727
|
+
}
|
|
728
|
+
const actual = (await sha256Hex(canonicalJsonBytes(body))).slice(2);
|
|
729
|
+
if (actual !== value.payload_sha256.replace(/^0x/, "").toLowerCase()) {
|
|
730
|
+
return errorResponse(400, "PAYLOAD_HASH_MISMATCH", "Provenance payload_sha256 does not match the JSON body");
|
|
731
|
+
}
|
|
732
|
+
return value;
|
|
733
|
+
}
|
|
734
|
+
catch {
|
|
735
|
+
return errorResponse(400, "INVALID_PROVENANCE", "Vana-Producer-Provenance is not base64url JSON");
|
|
736
|
+
}
|
|
264
737
|
}
|
|
265
738
|
/**
|
|
266
739
|
* The deletion that applies to a read of `scope`, or null when the read may
|
|
@@ -276,15 +749,26 @@ function collectedAt(now) {
|
|
|
276
749
|
* Gateway unreachability never fails the read: the tracker answers from its
|
|
277
750
|
* last known state, which is the documented offline behaviour.
|
|
278
751
|
*/
|
|
279
|
-
export async function resolveReadDeletion(deps, scope, entry) {
|
|
752
|
+
export async function resolveReadDeletion(deps, scope, entry, body = "file", gatewayTimeoutMs) {
|
|
280
753
|
if (!deps.scopeDeletions)
|
|
281
754
|
return null;
|
|
282
755
|
const verdict = await deps.scopeDeletions.resolve(scope, {
|
|
283
756
|
consultGateway: entry ? "if-stale" : "always",
|
|
757
|
+
...(gatewayTimeoutMs === undefined ? {} : { gatewayTimeoutMs }),
|
|
284
758
|
});
|
|
285
|
-
|
|
759
|
+
// A live DPv2 file cannot establish that a different canonical body was
|
|
760
|
+
// re-added. Keep this refusal until a genuine canonical re-add seam exists.
|
|
761
|
+
const tombstone = body === "canonical"
|
|
762
|
+
? (deps.scopeDeletions.deletionHistory?.get(scope) ??
|
|
763
|
+
(verdict.deleted ? verdict : null))
|
|
764
|
+
: verdict.deleted
|
|
765
|
+
? verdict
|
|
766
|
+
: null;
|
|
767
|
+
if (!tombstone)
|
|
286
768
|
return null;
|
|
287
|
-
if (
|
|
769
|
+
if (body === "file" &&
|
|
770
|
+
entry &&
|
|
771
|
+
!isEntryCoveredByTombstone(entry, tombstone)) {
|
|
288
772
|
return null;
|
|
289
773
|
}
|
|
290
774
|
return {
|
|
@@ -292,7 +776,7 @@ export async function resolveReadDeletion(deps, scope, entry) {
|
|
|
292
776
|
dataPointId: deps.serverOwner
|
|
293
777
|
? computeDataPointId(deps.serverOwner, scope)
|
|
294
778
|
: null,
|
|
295
|
-
deletedAt:
|
|
779
|
+
deletedAt: tombstone.deletedAt,
|
|
296
780
|
};
|
|
297
781
|
}
|
|
298
782
|
/**
|
|
@@ -300,8 +784,8 @@ export async function resolveReadDeletion(deps, scope, entry) {
|
|
|
300
784
|
* served. Call it before any payment step: a builder must never be charged
|
|
301
785
|
* for a scope the owner deleted.
|
|
302
786
|
*/
|
|
303
|
-
export async function assertScopeNotDeleted(deps, scope, entry) {
|
|
304
|
-
const deletion = await resolveReadDeletion(deps, scope, entry);
|
|
787
|
+
export async function assertScopeNotDeleted(deps, scope, entry, body = "file") {
|
|
788
|
+
const deletion = await resolveReadDeletion(deps, scope, entry, body);
|
|
305
789
|
if (deletion)
|
|
306
790
|
throw new DataDeletedError(deletion);
|
|
307
791
|
}
|
|
@@ -315,6 +799,83 @@ function discoveryVisibility(deps) {
|
|
|
315
799
|
return undefined;
|
|
316
800
|
return async (scope, entry) => (await resolveReadDeletion(deps, scope, entry)) === null;
|
|
317
801
|
}
|
|
802
|
+
/**
|
|
803
|
+
* Discovery filter for the scope listing: the deletion filter, and a
|
|
804
|
+
* canonical scope is listed only when the view could serve it.
|
|
805
|
+
*/
|
|
806
|
+
function listingVisibility(deps, deadlineAtMs) {
|
|
807
|
+
const deletion = deps.scopeDeletions
|
|
808
|
+
? async (scope, entry) => (await resolveReadDeletion(deps, scope, entry, "file", Math.max(0, deadlineAtMs - Date.now()))) === null
|
|
809
|
+
: undefined;
|
|
810
|
+
const view = deps.legacyScopeView;
|
|
811
|
+
if (!view)
|
|
812
|
+
return deletion;
|
|
813
|
+
return async (scope, entry) => {
|
|
814
|
+
const listing = view.listingFor(scope);
|
|
815
|
+
if (listing.kind === "refused")
|
|
816
|
+
return false;
|
|
817
|
+
const canonicalOwned = deletionHistoryOf(listing) === "canonical";
|
|
818
|
+
// A file's re-add marker cannot revive the canonical body this row
|
|
819
|
+
// describes. Canonical re-adds have no registered version yet.
|
|
820
|
+
return ((await resolveReadDeletion(deps, scope, canonicalOwned ? undefined : entry, canonicalOwned ? "canonical" : "file", Math.max(0, deadlineAtMs - Date.now()))) === null);
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Bound scopes served only from canonical records, for the listing: no
|
|
825
|
+
* legacy write is needed to discover them. A gateway deletion hides them
|
|
826
|
+
* the way it hides a stored scope.
|
|
827
|
+
*/
|
|
828
|
+
function canonicalOnlyScopes(deps, deadlineAtMs) {
|
|
829
|
+
const view = deps.legacyScopeView;
|
|
830
|
+
if (!view)
|
|
831
|
+
return undefined;
|
|
832
|
+
return async (scopePrefix, stored) => {
|
|
833
|
+
const listed = [];
|
|
834
|
+
for (const { scope, collectedAt } of view.listCanonicalScopes(scopePrefix)) {
|
|
835
|
+
if (stored.has(scope))
|
|
836
|
+
continue;
|
|
837
|
+
if ((await resolveReadDeletion(deps, scope, undefined, "canonical", Math.max(0, deadlineAtMs - Date.now()))) !== null) {
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
// No legacy version exists to count or to ask `/versions` for.
|
|
841
|
+
listed.push({ scope, latestCollectedAt: collectedAt, versionCount: 0 });
|
|
842
|
+
}
|
|
843
|
+
return listed;
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* A canonical scope's listing row carries the canonical freshness. The
|
|
848
|
+
* legacy head's size and block readiness describe a file the latest read
|
|
849
|
+
* does not serve, so they are dropped.
|
|
850
|
+
*/
|
|
851
|
+
function withCanonicalListing(deps, summary) {
|
|
852
|
+
const listing = deps.legacyScopeView?.listingFor(summary.scope);
|
|
853
|
+
if (listing?.kind !== "canonical")
|
|
854
|
+
return summary;
|
|
855
|
+
return {
|
|
856
|
+
scope: summary.scope,
|
|
857
|
+
latestCollectedAt: listing.collectedAt,
|
|
858
|
+
versionCount: summary.versionCount,
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* 409 when the owner must choose between connections, 503 otherwise. The
|
|
863
|
+
* body names the reason and stream names only: no instance id, no row data,
|
|
864
|
+
* no legacy content.
|
|
865
|
+
*/
|
|
866
|
+
function legacyViewRefusalResponse(scope, refusal) {
|
|
867
|
+
const status = refusal.reason === "ambiguous_connection" ? 409 : 503;
|
|
868
|
+
return jsonResponse({
|
|
869
|
+
error: "CANONICAL_VIEW_UNAVAILABLE",
|
|
870
|
+
message: `The latest data for scope "${scope}" cannot be served from the owner's connector records (${refusal.reason}).`,
|
|
871
|
+
status: refusal.status,
|
|
872
|
+
reason: refusal.reason,
|
|
873
|
+
...("detail" in refusal ? { detail: refusal.detail } : {}),
|
|
874
|
+
...("streams" in refusal ? { streams: refusal.streams } : {}),
|
|
875
|
+
...("stream" in refusal ? { stream: refusal.stream } : {}),
|
|
876
|
+
...("candidates" in refusal ? { candidates: refusal.candidates } : {}),
|
|
877
|
+
}, { status });
|
|
878
|
+
}
|
|
318
879
|
/**
|
|
319
880
|
* The causal marker a fresh ingest carries: the tombstone version this
|
|
320
881
|
* replica currently knows for the scope, if any, so the new entry is a
|
|
@@ -334,12 +895,11 @@ async function ingestTombstoneMarker(deps, scope) {
|
|
|
334
895
|
}
|
|
335
896
|
// The delete worker wants a full Logger; the API logger is all-optional.
|
|
336
897
|
function apiLoggerAsLogger(logger) {
|
|
337
|
-
const noop = () => undefined;
|
|
338
898
|
return {
|
|
339
|
-
debug: (payload, message) =>
|
|
340
|
-
info: (payload, message) =>
|
|
341
|
-
warn: (payload, message) =>
|
|
342
|
-
error: (payload, message) =>
|
|
899
|
+
debug: (payload, message) => logger?.debug?.(payload, message ?? ""),
|
|
900
|
+
info: (payload, message) => logger?.info?.(payload, message ?? ""),
|
|
901
|
+
warn: (payload, message) => logger?.warn?.(payload, message ?? ""),
|
|
902
|
+
error: (payload, message) => logger?.error?.(payload, message ?? ""),
|
|
343
903
|
};
|
|
344
904
|
}
|
|
345
905
|
function notifyDataWritten(deps, event) {
|
|
@@ -355,6 +915,63 @@ function notifyDataWritten(deps, event) {
|
|
|
355
915
|
}, "onDataWritten hook failed; record already stored");
|
|
356
916
|
}
|
|
357
917
|
}
|
|
918
|
+
/**
|
|
919
|
+
* Offer a just-ingested envelope to the PDPP importer.
|
|
920
|
+
*
|
|
921
|
+
* The local-ingest twin of the download worker's `importIntoPdpp`, and
|
|
922
|
+
* deliberately the same shape: same `ImportableEnvelope`, same total handling
|
|
923
|
+
* of every outcome, same permanent-vs-transient logging split. Keeping the
|
|
924
|
+
* two symmetric is the point — a `$pdpp` envelope must mean the same thing
|
|
925
|
+
* and reach the same store whether the gateway handed it over or a local
|
|
926
|
+
* producer POSTed it, otherwise "imported" would depend on which door the
|
|
927
|
+
* bytes came through.
|
|
928
|
+
*
|
|
929
|
+
* `skipped` is the ordinary legacy case (no `$pdpp` block) and stays silent.
|
|
930
|
+
* A rejection is a WARNING, not an error: it means the producer sent
|
|
931
|
+
* something this deployment could not verify — actionable, but not a failure
|
|
932
|
+
* of the write, which has already committed.
|
|
933
|
+
*/
|
|
934
|
+
function importIngestedIntoPdpp(deps, envelope) {
|
|
935
|
+
if (!deps.pdppImporter)
|
|
936
|
+
return;
|
|
937
|
+
try {
|
|
938
|
+
const outcome = deps.pdppImporter.importEnvelope(envelope);
|
|
939
|
+
if (outcome.status === "rejected") {
|
|
940
|
+
const permanent = isPermanentRejection(outcome.rejection);
|
|
941
|
+
deps.logger?.warn?.({
|
|
942
|
+
scope: envelope.scope,
|
|
943
|
+
collectedAt: envelope.collectedAt,
|
|
944
|
+
code: outcome.rejection.code,
|
|
945
|
+
message: outcome.rejection.message,
|
|
946
|
+
permanent,
|
|
947
|
+
}, permanent
|
|
948
|
+
? "Ingested data point was refused by the PDPP importer and will not be retried"
|
|
949
|
+
: "PDPP import unavailable for this ingested data point");
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
catch (err) {
|
|
953
|
+
// A throwing importer is infrastructure failing, not the envelope being
|
|
954
|
+
// wrong. The record is stored and indexed already, so this must never
|
|
955
|
+
// turn a committed write into a 500.
|
|
956
|
+
deps.logger?.warn?.({
|
|
957
|
+
scope: envelope.scope,
|
|
958
|
+
error: err instanceof Error ? err.message : String(err),
|
|
959
|
+
}, "PDPP import threw on ingest; record already stored and indexed");
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
function notifyDataRead(deps, event) {
|
|
963
|
+
if (!deps.onDataRead)
|
|
964
|
+
return;
|
|
965
|
+
try {
|
|
966
|
+
deps.onDataRead(event);
|
|
967
|
+
}
|
|
968
|
+
catch (err) {
|
|
969
|
+
deps.logger?.warn?.({
|
|
970
|
+
scope: event.scope,
|
|
971
|
+
error: err instanceof Error ? err.message : String(err),
|
|
972
|
+
}, "onDataRead hook failed; the read is unaffected");
|
|
973
|
+
}
|
|
974
|
+
}
|
|
358
975
|
function notifyNewData(syncManager) {
|
|
359
976
|
if (!syncManager)
|
|
360
977
|
return;
|
|
@@ -377,12 +994,26 @@ function warnReadFulfillmentReporterFailed(deps, event, err) {
|
|
|
377
994
|
}, "Read fulfillment reporter failed");
|
|
378
995
|
}
|
|
379
996
|
export function reportPersonalServerReadFulfillment(deps, event) {
|
|
380
|
-
|
|
381
|
-
|
|
997
|
+
const reporter = deps.readFulfillmentReporter;
|
|
998
|
+
if (!reporter || !shouldReportReadFulfillment(event.grantId)) {
|
|
382
999
|
return;
|
|
383
1000
|
}
|
|
1001
|
+
fireReadReport(deps, event, reporter.report.bind(reporter));
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Denials mirror fulfillments but skip the grant filter: a refused read has no
|
|
1005
|
+
* grant to filter on, and the record is what proves the refusal happened.
|
|
1006
|
+
*/
|
|
1007
|
+
export function reportPersonalServerReadDenial(deps, event) {
|
|
1008
|
+
const reporter = deps.readFulfillmentReporter;
|
|
1009
|
+
if (!reporter?.reportDenied)
|
|
1010
|
+
return;
|
|
1011
|
+
fireReadReport(deps, event, reporter.reportDenied.bind(reporter));
|
|
1012
|
+
}
|
|
1013
|
+
/** Fire-and-forget: reporting must never fail or delay the read it describes. */
|
|
1014
|
+
function fireReadReport(deps, event, send) {
|
|
384
1015
|
try {
|
|
385
|
-
void Promise.resolve(
|
|
1016
|
+
void Promise.resolve(send(event)).catch((err) => warnReadFulfillmentReporterFailed(deps, event, err));
|
|
386
1017
|
}
|
|
387
1018
|
catch (err) {
|
|
388
1019
|
warnReadFulfillmentReporterFailed(deps, event, err);
|
|
@@ -483,28 +1114,313 @@ export function redactEnvelopeForGrantee(envelope) {
|
|
|
483
1114
|
}
|
|
484
1115
|
return { ...envelope, data };
|
|
485
1116
|
}
|
|
1117
|
+
export { redactJsonEnvelopeBytesForGrantee } from "./raw-envelope.js";
|
|
1118
|
+
/**
|
|
1119
|
+
* `/v1/data/:scope/uploads...`: an owner writes one new version of a scope as
|
|
1120
|
+
* a sequence of record batches. The protocol and its guarantees are in
|
|
1121
|
+
* `scope-uploads.ts`; this adds HTTP, owner auth and the post-commit hooks.
|
|
1122
|
+
*/
|
|
1123
|
+
async function handleScopeUploadRequest(request, deps, parts, prepared) {
|
|
1124
|
+
const route = (() => {
|
|
1125
|
+
if (parts.length === 2)
|
|
1126
|
+
return { kind: "begin", method: "POST" };
|
|
1127
|
+
if (parts.length === 3)
|
|
1128
|
+
return { kind: "abort", method: "DELETE" };
|
|
1129
|
+
if (parts.length === 4 && parts[3] === "commit")
|
|
1130
|
+
return { kind: "commit", method: "POST" };
|
|
1131
|
+
if (parts.length === 5 && parts[3] === "batches")
|
|
1132
|
+
return { kind: "append", method: "PUT" };
|
|
1133
|
+
return undefined;
|
|
1134
|
+
})();
|
|
1135
|
+
if (!route) {
|
|
1136
|
+
return errorResponse(404, "NOT_FOUND", "Unknown upload route");
|
|
1137
|
+
}
|
|
1138
|
+
if (request.method !== route.method)
|
|
1139
|
+
return methodNotAllowed();
|
|
1140
|
+
await deps.auth.authorizeOwner(request);
|
|
1141
|
+
const scopeResult = parseDataScopeContract(decodePathPart(parts[0]));
|
|
1142
|
+
if (!scopeResult.ok)
|
|
1143
|
+
return contractErrorResponse(scopeResult);
|
|
1144
|
+
const scope = scopeResult.scope;
|
|
1145
|
+
const uploads = deps.scopeUploads;
|
|
1146
|
+
if (!uploads) {
|
|
1147
|
+
return errorResponse(501, "UPLOAD_UNSUPPORTED", "This server cannot stream a scope version");
|
|
1148
|
+
}
|
|
1149
|
+
const readBody = async () => {
|
|
1150
|
+
const text = await request.text();
|
|
1151
|
+
if (text.trim() === "")
|
|
1152
|
+
return {};
|
|
1153
|
+
try {
|
|
1154
|
+
return JSON.parse(text);
|
|
1155
|
+
}
|
|
1156
|
+
catch {
|
|
1157
|
+
throw new ScopeUploadError(400, "INVALID_UPLOAD", "Request body must be valid JSON");
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
try {
|
|
1161
|
+
switch (route.kind) {
|
|
1162
|
+
case "begin": {
|
|
1163
|
+
const body = await readBody();
|
|
1164
|
+
const stamp = reserveIngestStamp(deps.now ?? (() => new Date()), deps.storage, scope);
|
|
1165
|
+
if (!stamp) {
|
|
1166
|
+
return errorResponse(429, "INGEST_CAPACITY", "Too many writes for this scope; retry when the clock advances");
|
|
1167
|
+
}
|
|
1168
|
+
const begun = await uploads.begin({
|
|
1169
|
+
storage: deps.storage,
|
|
1170
|
+
scope,
|
|
1171
|
+
collectedAt: stamp.collectedAt,
|
|
1172
|
+
release: stamp.release,
|
|
1173
|
+
body,
|
|
1174
|
+
});
|
|
1175
|
+
return jsonResponse({ ...begun, scope, maxBatchBytes: uploads.maxBatchBytes }, { status: 201 });
|
|
1176
|
+
}
|
|
1177
|
+
case "append": {
|
|
1178
|
+
const seqText = decodePathPart(parts[4]);
|
|
1179
|
+
const input = {
|
|
1180
|
+
scope,
|
|
1181
|
+
uploadId: decodePathPart(parts[2]),
|
|
1182
|
+
seq: /^\d{1,9}$/.test(seqText) ? Number(seqText) : Number.NaN,
|
|
1183
|
+
};
|
|
1184
|
+
let appended;
|
|
1185
|
+
if (prepared) {
|
|
1186
|
+
if (!uploads.appendPrepared) {
|
|
1187
|
+
throw new ScopeUploadError(501, "UPLOAD_UNSUPPORTED", "This server cannot append prepared batches");
|
|
1188
|
+
}
|
|
1189
|
+
// Authenticate the small commitment on EVERY append, with the
|
|
1190
|
+
// existing owner gate. Bulk bytes never cross a Request boundary.
|
|
1191
|
+
const body = await readBody();
|
|
1192
|
+
if (body === null ||
|
|
1193
|
+
typeof body !== "object" ||
|
|
1194
|
+
Array.isArray(body) ||
|
|
1195
|
+
Object.keys(body).length !== 1 ||
|
|
1196
|
+
body.bodySha256 !==
|
|
1197
|
+
prepared.bodySha256) {
|
|
1198
|
+
throw new ScopeUploadError(400, "INVALID_UPLOAD", "Prepared batch commitment does not match");
|
|
1199
|
+
}
|
|
1200
|
+
appended = await uploads.appendPrepared({
|
|
1201
|
+
...input,
|
|
1202
|
+
batch: prepared,
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
else {
|
|
1206
|
+
appended = await uploads.append({
|
|
1207
|
+
...input,
|
|
1208
|
+
text: await request.text(),
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
return jsonResponse(appended, {
|
|
1212
|
+
status: appended.replay ? 200 : 201,
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
case "commit": {
|
|
1216
|
+
const body = await readBody();
|
|
1217
|
+
const committed = await uploads.commit({
|
|
1218
|
+
scope,
|
|
1219
|
+
uploadId: decodePathPart(parts[2]),
|
|
1220
|
+
body,
|
|
1221
|
+
afterTombstoneVersion: await ingestTombstoneMarker(deps, scope),
|
|
1222
|
+
});
|
|
1223
|
+
deps.logger?.info?.({
|
|
1224
|
+
scope,
|
|
1225
|
+
collectedAt: committed.collectedAt,
|
|
1226
|
+
path: committed.writeResult.relativePath,
|
|
1227
|
+
records: committed.records,
|
|
1228
|
+
}, "Streamed data file committed");
|
|
1229
|
+
// Block sidecars and the first-seen ledger are not built here: both
|
|
1230
|
+
// need the whole envelope in memory, which is what an upload avoids.
|
|
1231
|
+
// Both are caches: a scope with no block manifest is read whole, and
|
|
1232
|
+
// the owner's `/additions` read folds the version into the ledger.
|
|
1233
|
+
notifyNewData(deps.syncManager);
|
|
1234
|
+
notifyDataWritten(deps, { scope, collectedAt: committed.collectedAt });
|
|
1235
|
+
return jsonResponse({
|
|
1236
|
+
scope,
|
|
1237
|
+
collectedAt: committed.collectedAt,
|
|
1238
|
+
status: deps.syncManager ? "syncing" : "stored",
|
|
1239
|
+
records: committed.records,
|
|
1240
|
+
sizeBytes: committed.writeResult.sizeBytes,
|
|
1241
|
+
}, { status: 201 });
|
|
1242
|
+
}
|
|
1243
|
+
case "abort": {
|
|
1244
|
+
await uploads.abort({ scope, uploadId: decodePathPart(parts[2]) });
|
|
1245
|
+
return new Response(null, { status: 204 });
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
catch (err) {
|
|
1250
|
+
if (err instanceof ScopeUploadError) {
|
|
1251
|
+
return errorResponse(err.status, err.code, err.message);
|
|
1252
|
+
}
|
|
1253
|
+
throw err;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* In-process bulk transport, deliberately not dispatched by the HTTP router.
|
|
1258
|
+
* The Request carries only a signed digest commitment, not the item envelope.
|
|
1259
|
+
* It authenticates the same method, URI and owner as a remote append.
|
|
1260
|
+
*/
|
|
1261
|
+
export async function handlePersonalServerScopeUploadAppend(request, deps, batch) {
|
|
1262
|
+
return withApiErrors(async () => {
|
|
1263
|
+
const url = new URL(request.url);
|
|
1264
|
+
if (!url.pathname.startsWith("/v1/data/")) {
|
|
1265
|
+
return errorResponse(404, "NOT_FOUND", "Unknown upload route");
|
|
1266
|
+
}
|
|
1267
|
+
const pathname = stripBasePath(url.pathname, "/v1/data");
|
|
1268
|
+
const parts = pathname.split("/").filter(Boolean);
|
|
1269
|
+
if (parts.length !== 5 ||
|
|
1270
|
+
parts[1] !== "uploads" ||
|
|
1271
|
+
parts[3] !== "batches") {
|
|
1272
|
+
return errorResponse(404, "NOT_FOUND", "Unknown upload route");
|
|
1273
|
+
}
|
|
1274
|
+
return handleScopeUploadRequest(request, deps, parts, batch);
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
486
1277
|
export async function handlePersonalServerDataRequest(request, deps, options = {}) {
|
|
1278
|
+
// Filled in as the dispatch narrows, so a 500 thrown deep in a read is
|
|
1279
|
+
// logged against the route that served it rather than a generic label. It
|
|
1280
|
+
// is mutable for exactly that reason: the route is not known until the path
|
|
1281
|
+
// has been parsed, and by then we are already inside the try.
|
|
1282
|
+
const logContext = {
|
|
1283
|
+
logger: deps.logger,
|
|
1284
|
+
route: `${request.method} ${options.basePath ?? "/v1/data"}`,
|
|
1285
|
+
requestId: crypto.randomUUID(),
|
|
1286
|
+
};
|
|
487
1287
|
return withApiErrors(async () => {
|
|
488
1288
|
const url = new URL(request.url);
|
|
489
1289
|
const pathname = stripBasePath(url.pathname, options.basePath);
|
|
490
1290
|
if (pathname === "/" || pathname === "") {
|
|
491
1291
|
if (request.method !== "GET")
|
|
492
1292
|
return methodNotAllowed();
|
|
493
|
-
await deps.auth.authorizeBuilderList(request
|
|
1293
|
+
const listAuth = await deps.auth.authorizeBuilderList(request, {
|
|
1294
|
+
grantId: selectedGrantId(request, url),
|
|
1295
|
+
});
|
|
1296
|
+
// One budget for every stored and canonical-only scope, not per row.
|
|
1297
|
+
const deletionDeadlineAtMs = Date.now() + 250;
|
|
494
1298
|
const result = await listDataScopesContract({
|
|
495
1299
|
storage: deps.storage,
|
|
496
1300
|
scopePrefix: url.searchParams.get("scopePrefix") ?? undefined,
|
|
497
1301
|
limit: normalizeLimit(url.searchParams.get("limit"), 20),
|
|
498
1302
|
offset: normalizeLimit(url.searchParams.get("offset"), 0),
|
|
1303
|
+
isVisible: listingVisibility(deps, deletionDeadlineAtMs),
|
|
1304
|
+
isListable: (scope) => !isSystemScope(scope) &&
|
|
1305
|
+
(!listAuth || listAuthCovers(listAuth, scope)),
|
|
1306
|
+
extraScopes: canonicalOnlyScopes(deps, deletionDeadlineAtMs),
|
|
1307
|
+
});
|
|
1308
|
+
return jsonResponse({
|
|
1309
|
+
...result.response,
|
|
1310
|
+
scopes: result.response.scopes.map((summary) => withCanonicalListing(deps, summary)),
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
// "additions" has no dot, so it can never be a real scope name (scopes are
|
|
1314
|
+
// "source.dataset"); handle it before the single-segment scope path.
|
|
1315
|
+
if (pathname === "/additions") {
|
|
1316
|
+
if (request.method !== "GET")
|
|
1317
|
+
return methodNotAllowed();
|
|
1318
|
+
// The counts span every scope, so only the owner may read them.
|
|
1319
|
+
await deps.auth.authorizeOwner(request);
|
|
1320
|
+
const daysRaw = url.searchParams.get("days");
|
|
1321
|
+
const result = await summarizeDataAdditionsContract({
|
|
1322
|
+
additions: deps.additions,
|
|
1323
|
+
storage: deps.storage,
|
|
499
1324
|
isVisible: discoveryVisibility(deps),
|
|
1325
|
+
timezone: url.searchParams.get("tz") ?? "UTC",
|
|
1326
|
+
// Digits only: Number() would also accept "", "1e1", "0x7" and " 7".
|
|
1327
|
+
days: daysRaw === null
|
|
1328
|
+
? 7
|
|
1329
|
+
: /^\d{1,3}$/.test(daysRaw)
|
|
1330
|
+
? Number(daysRaw)
|
|
1331
|
+
: Number.NaN,
|
|
1332
|
+
now: (deps.now ?? (() => new Date()))(),
|
|
500
1333
|
});
|
|
501
|
-
|
|
1334
|
+
if ("ok" in result)
|
|
1335
|
+
return contractErrorResponse(result);
|
|
1336
|
+
return jsonResponse(result);
|
|
502
1337
|
}
|
|
503
1338
|
const parts = pathname.split("/").filter(Boolean);
|
|
1339
|
+
if (parts.length >= 2 && parts[1] === "uploads") {
|
|
1340
|
+
return await handleScopeUploadRequest(request, deps, parts);
|
|
1341
|
+
}
|
|
1342
|
+
if (parts.length === 3 && parts[1] === "imports") {
|
|
1343
|
+
if (request.method !== "PUT")
|
|
1344
|
+
return methodNotAllowed();
|
|
1345
|
+
await deps.auth.authorizeOwner(request);
|
|
1346
|
+
const scopeResult = parseDataScopeContract(decodePathPart(parts[0]));
|
|
1347
|
+
if (!scopeResult.ok)
|
|
1348
|
+
return contractErrorResponse(scopeResult);
|
|
1349
|
+
const operation = decodePathPart(parts[2]);
|
|
1350
|
+
if (!/^[a-f0-9]{64}$/.test(operation)) {
|
|
1351
|
+
return errorResponse(400, "INVALID_IMPORT_OPERATION", "operation must be 64 lowercase hexadecimal characters");
|
|
1352
|
+
}
|
|
1353
|
+
if (!deps.storage.commitVersion) {
|
|
1354
|
+
throw new ProtocolError(501, "IMPORT_UNSUPPORTED", "This storage backend does not support durable owner imports");
|
|
1355
|
+
}
|
|
1356
|
+
if (!deps.serverOwner)
|
|
1357
|
+
throw new ServerNotConfiguredError({
|
|
1358
|
+
reason: "serverOwner is required for durable owner imports",
|
|
1359
|
+
});
|
|
1360
|
+
if (!isJsonContentType(request) || url.search.length > 0) {
|
|
1361
|
+
return errorResponse(400, "INVALID_IMPORT", "Owner imports accept JSON root writes without query parameters");
|
|
1362
|
+
}
|
|
1363
|
+
const parsed = await parseJsonObjectBody(request, "Request body must be valid JSON");
|
|
1364
|
+
if (!parsed.ok)
|
|
1365
|
+
return contractResponse(parsed.result);
|
|
1366
|
+
if ("lineage" in parsed.body || "$binary" in parsed.body) {
|
|
1367
|
+
return errorResponse(400, "INVALID_IMPORT", "Owner imports do not accept binary or lineage writes");
|
|
1368
|
+
}
|
|
1369
|
+
const bodySha256 = await sha256Hex(canonicalJsonBytes(parsed.body));
|
|
1370
|
+
const authority = deps.gatewayConfig
|
|
1371
|
+
? `${deps.gatewayConfig.chainId}:${deps.gatewayConfig.contracts.dataRegistry.toLowerCase()}`
|
|
1372
|
+
: "local";
|
|
1373
|
+
const result = await ingestDataContract({
|
|
1374
|
+
storage: deps.storage,
|
|
1375
|
+
scopeParam: scopeResult.scope,
|
|
1376
|
+
body: parsed.body,
|
|
1377
|
+
collectedAt: (deps.now ?? (() => new Date()))().toISOString(),
|
|
1378
|
+
status: deps.syncManager ? "syncing" : "stored",
|
|
1379
|
+
afterTombstoneVersion: await ingestTombstoneMarker(deps, scopeResult.scope),
|
|
1380
|
+
import: {
|
|
1381
|
+
operation,
|
|
1382
|
+
bodySha256,
|
|
1383
|
+
owner: deps.serverOwner.toLowerCase(),
|
|
1384
|
+
authority,
|
|
1385
|
+
},
|
|
1386
|
+
});
|
|
1387
|
+
if (!result.ok)
|
|
1388
|
+
return contractErrorResponse(result);
|
|
1389
|
+
notifyNewData(deps.syncManager);
|
|
1390
|
+
if (!result.replay)
|
|
1391
|
+
notifyDataWritten(deps, {
|
|
1392
|
+
scope: result.scope,
|
|
1393
|
+
collectedAt: result.collectedAt,
|
|
1394
|
+
});
|
|
1395
|
+
return jsonResponse(result.response, {
|
|
1396
|
+
status: result.replay ? 200 : 201,
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
504
1399
|
if (parts.length === 2 && parts[1] === "versions") {
|
|
505
1400
|
if (request.method !== "GET")
|
|
506
1401
|
return methodNotAllowed();
|
|
507
|
-
|
|
1402
|
+
const versionsScopeParam = decodePathPart(parts[0]);
|
|
1403
|
+
const versionsGrantId = selectedGrantId(request, url);
|
|
1404
|
+
const listAuth = deps.auth.authorizeScopeVersions
|
|
1405
|
+
? await deps.auth.authorizeScopeVersions({
|
|
1406
|
+
request,
|
|
1407
|
+
scope: versionsScopeParam,
|
|
1408
|
+
grantId: versionsGrantId,
|
|
1409
|
+
})
|
|
1410
|
+
: await deps.auth.authorizeBuilderList(request, {
|
|
1411
|
+
grantId: versionsGrantId,
|
|
1412
|
+
});
|
|
1413
|
+
// A scope's version history is as much its data as its content is, so
|
|
1414
|
+
// a non-owner needs a grant covering it, exactly like a read.
|
|
1415
|
+
const scopeResult = parseDataScopeContract(versionsScopeParam);
|
|
1416
|
+
if (scopeResult.ok &&
|
|
1417
|
+
listAuth &&
|
|
1418
|
+
!listAuthCovers(listAuth, scopeResult.scope)) {
|
|
1419
|
+
throw new GrantRequiredError({
|
|
1420
|
+
reason: "No grant covers this scope",
|
|
1421
|
+
requestedScope: scopeResult.scope,
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
508
1424
|
const result = await listDataVersionsContract({
|
|
509
1425
|
storage: deps.storage,
|
|
510
1426
|
scopeParam: decodePathPart(parts[0]),
|
|
@@ -609,14 +1525,30 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
609
1525
|
if (parts.length !== 1)
|
|
610
1526
|
return notFound();
|
|
611
1527
|
const scopeParam = decodePathPart(parts[0]);
|
|
1528
|
+
logContext.route = `${request.method} ${options.basePath ?? "/v1/data"}/:scope`;
|
|
612
1529
|
if (request.method === "GET") {
|
|
613
|
-
|
|
1530
|
+
// Stream names are read names only while stream-sync reads are on; with
|
|
1531
|
+
// the flag off every read answers as before.
|
|
1532
|
+
const scopeResult = deps.streamSyncRead
|
|
1533
|
+
? parseDataReadScopeContract(scopeParam)
|
|
1534
|
+
: parseDataScopeContract(scopeParam);
|
|
614
1535
|
if (!scopeResult.ok)
|
|
615
1536
|
return contractErrorResponse(scopeResult);
|
|
1537
|
+
logContext.detail = { scope: scopeResult.scope };
|
|
1538
|
+
// An empty `fileId=` or `at=` selects no version: it is the latest
|
|
1539
|
+
// read, as storage already treats it.
|
|
1540
|
+
const fileIdParam = url.searchParams.get("fileId") || undefined;
|
|
1541
|
+
const atParam = url.searchParams.get("at") || undefined;
|
|
1542
|
+
// `?view=stored` returns the body as stored, without the read-time
|
|
1543
|
+
// legacy projection. Owner only; checked after auth below.
|
|
1544
|
+
const view = url.searchParams.get("view");
|
|
1545
|
+
if (view !== null && view !== "stored") {
|
|
1546
|
+
return errorResponse(400, "INVALID_VIEW", 'view must be "stored" or absent');
|
|
1547
|
+
}
|
|
616
1548
|
const selectedEntry = deps.storage.findEntry({
|
|
617
1549
|
scope: scopeResult.scope,
|
|
618
|
-
fileId:
|
|
619
|
-
at:
|
|
1550
|
+
fileId: fileIdParam,
|
|
1551
|
+
at: atParam,
|
|
620
1552
|
});
|
|
621
1553
|
// Holds the base64-encoded gateway payForOperation response body when
|
|
622
1554
|
// X402 succeeds — emitted on the final read response as X-PAYMENT-RESPONSE.
|
|
@@ -626,120 +1558,180 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
626
1558
|
request,
|
|
627
1559
|
scope: scopeResult.scope,
|
|
628
1560
|
grantId,
|
|
629
|
-
fileId:
|
|
630
|
-
at:
|
|
1561
|
+
fileId: fileIdParam ?? selectedEntry?.fileId ?? undefined,
|
|
1562
|
+
at: atParam,
|
|
631
1563
|
});
|
|
1564
|
+
// Select the body after auth and before deletion or payment. A file's
|
|
1565
|
+
// version and re-add marker authorize that file, not canonical rows.
|
|
1566
|
+
// `?view=stored` asks for the stored file's body, so it never reads the
|
|
1567
|
+
// canonical view either.
|
|
1568
|
+
const latest = fileIdParam === undefined && atParam === undefined && view === null
|
|
1569
|
+
? await deps.legacyScopeView?.readLatest(scopeResult.scope)
|
|
1570
|
+
: undefined;
|
|
1571
|
+
// Stream-sync (§2.10): the one eligibility rule decides between the
|
|
1572
|
+
// stream view, the existing body and a refusal. Explicit versions stay
|
|
1573
|
+
// legacy history, but a deleted connector serves nothing at all.
|
|
1574
|
+
const latestRead = fileIdParam === undefined && atParam === undefined && view === null;
|
|
1575
|
+
// What only the owner is told when the existing path answers a stream
|
|
1576
|
+
// read: local runs the writer will not publish.
|
|
1577
|
+
let ownerNotes;
|
|
1578
|
+
if (deps.streamSyncRead) {
|
|
1579
|
+
const decision = await deps.streamSyncRead.resolve({
|
|
1580
|
+
scope: scopeResult.scope,
|
|
1581
|
+
connection: latestRead ? url.searchParams.get("connection") : null,
|
|
1582
|
+
cursor: latestRead ? url.searchParams.get("cursor") : null,
|
|
1583
|
+
legacyFile: Boolean(selectedEntry) || latest?.kind === "canonical",
|
|
1584
|
+
isOwnerView: isOwnerView(authResult),
|
|
1585
|
+
});
|
|
1586
|
+
if (decision.kind === "unavailable" && decision.reason === "deleted") {
|
|
1587
|
+
throw new DataDeletedError({ scope: scopeResult.scope });
|
|
1588
|
+
}
|
|
1589
|
+
if (latestRead) {
|
|
1590
|
+
if (decision.kind === "pass" ||
|
|
1591
|
+
decision.kind === "legacy" ||
|
|
1592
|
+
decision.kind === "unavailable") {
|
|
1593
|
+
ownerNotes = decision;
|
|
1594
|
+
}
|
|
1595
|
+
const refusal = streamSyncRefusal(decision);
|
|
1596
|
+
if (refusal)
|
|
1597
|
+
return refusal;
|
|
1598
|
+
if (decision.kind === "local_pending") {
|
|
1599
|
+
// Owner-only and unregistered: nothing to bill and no version to
|
|
1600
|
+
// bind in an access record.
|
|
1601
|
+
notifyDataRead(deps, { scope: scopeResult.scope });
|
|
1602
|
+
return serveStreamSyncView(deps, request, {
|
|
1603
|
+
scope: scopeResult.scope,
|
|
1604
|
+
grantId,
|
|
1605
|
+
authResult,
|
|
1606
|
+
decision,
|
|
1607
|
+
paymentResponseHeader: undefined,
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
if (decision.kind === "view") {
|
|
1611
|
+
notifyDataRead(deps, { scope: scopeResult.scope });
|
|
1612
|
+
// The same charge as a file read; the access record binds the
|
|
1613
|
+
// stream head the view serves.
|
|
1614
|
+
let paymentResponseHeader;
|
|
1615
|
+
// An owner-only view with no registered head has nothing to
|
|
1616
|
+
// charge against: the service serves it to the owner alone.
|
|
1617
|
+
if (decision.served !== null) {
|
|
1618
|
+
const served = decision.served;
|
|
1619
|
+
const ownApp = await ownAppReadStatus(deps, authResult);
|
|
1620
|
+
if (ownApp instanceof Response) {
|
|
1621
|
+
await decision.body.cancel();
|
|
1622
|
+
return ownApp;
|
|
1623
|
+
}
|
|
1624
|
+
const charge = readCharge(deps, scopeResult.scope, authResult, ownApp);
|
|
1625
|
+
if (charge) {
|
|
1626
|
+
let paid;
|
|
1627
|
+
try {
|
|
1628
|
+
paid = await payForRead(deps, request, charge, {
|
|
1629
|
+
scope: scopeResult.scope,
|
|
1630
|
+
servedEntry: served,
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
catch (error) {
|
|
1634
|
+
await decision.body.cancel();
|
|
1635
|
+
throw error;
|
|
1636
|
+
}
|
|
1637
|
+
if (paid.kind === "refused") {
|
|
1638
|
+
await decision.body.cancel();
|
|
1639
|
+
return paid.response;
|
|
1640
|
+
}
|
|
1641
|
+
paymentResponseHeader = paid.paymentResponseHeader;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
return serveStreamSyncView(deps, request, {
|
|
1645
|
+
scope: scopeResult.scope,
|
|
1646
|
+
grantId,
|
|
1647
|
+
authResult,
|
|
1648
|
+
decision,
|
|
1649
|
+
paymentResponseHeader,
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
// The deletion history comes with the body the view chose, never from
|
|
1655
|
+
// a later ownership query a concurrent write could change.
|
|
1656
|
+
const canonicalOwned = latest !== undefined && deletionHistoryOf(latest) === "canonical";
|
|
632
1657
|
// Deletion gate, after auth (so unauthenticated callers learn nothing)
|
|
633
1658
|
// and before payment (so nobody is charged for deleted data). Covers
|
|
634
1659
|
// both a stale local copy of a tombstoned scope and a local miss.
|
|
635
|
-
await assertScopeNotDeleted(deps, scopeResult.scope, selectedEntry);
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
// since there's no payable op to attach the payment to.
|
|
639
|
-
//
|
|
640
|
-
// The grantId we pay against is the one verifyDataReadPolicy resolved
|
|
641
|
-
// from the Web3Signed payload (authoritative source) — not the URL /
|
|
642
|
-
// header hint, which may be absent when the payload carries it.
|
|
643
|
-
const isOwnerSignal = authResult?.grantId === "owner" ||
|
|
644
|
-
authResult?.grantId === "policy-bypass";
|
|
645
|
-
const builder = authResult?.builder;
|
|
646
|
-
const resolvedGrantId = !isOwnerSignal && authResult?.grantId ? authResult.grantId : undefined;
|
|
647
|
-
const willCharge = Boolean(deps.paymentEnabled &&
|
|
648
|
-
!isOwnerSignal &&
|
|
649
|
-
typeof builder === "string" &&
|
|
650
|
-
builder.startsWith("0x") &&
|
|
651
|
-
resolvedGrantId &&
|
|
652
|
-
deps.gateway &&
|
|
653
|
-
deps.gatewayConfig &&
|
|
654
|
-
deps.gatewayUrl);
|
|
655
|
-
// Diagnostic: makes it explicit why a read is/isn't charged. x402 has
|
|
656
|
-
// many "served free" branches (owner read, payment disabled, missing
|
|
657
|
-
// gateway deps); this surfaces the deciding inputs.
|
|
658
|
-
//
|
|
659
|
-
// Routing: when a logger is wired (the Node server always provides one),
|
|
660
|
-
// log the full detail through it at debug level so the operator's level
|
|
661
|
-
// controls + redaction apply and access metadata (scope/grantId/builder)
|
|
662
|
-
// doesn't unconditionally hit stdout. The browser PS-Lite runtime wires
|
|
663
|
-
// no logger; there we fall back to console but log ONLY the non-identifying
|
|
664
|
-
// decision booleans — never scope/grantId/builder.
|
|
665
|
-
if (deps.logger?.debug) {
|
|
666
|
-
deps.logger.debug({
|
|
667
|
-
scope: scopeResult.scope,
|
|
668
|
-
grantId: authResult?.grantId,
|
|
669
|
-
isOwnerSignal,
|
|
670
|
-
builder,
|
|
671
|
-
resolvedGrantId,
|
|
672
|
-
paymentEnabled: Boolean(deps.paymentEnabled),
|
|
673
|
-
hasGateway: Boolean(deps.gateway),
|
|
674
|
-
hasGatewayConfig: Boolean(deps.gatewayConfig),
|
|
675
|
-
hasGatewayUrl: Boolean(deps.gatewayUrl),
|
|
676
|
-
willCharge,
|
|
677
|
-
}, "[x402-gate] read");
|
|
1660
|
+
await assertScopeNotDeleted(deps, scopeResult.scope, canonicalOwned ? undefined : selectedEntry, canonicalOwned ? "canonical" : "file");
|
|
1661
|
+
if (view === "stored" && !isOwnerView(authResult)) {
|
|
1662
|
+
return errorResponse(403, "FORBIDDEN", "Only the owner can read the stored view");
|
|
678
1663
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
1664
|
+
// Demand: this authorized read is what pays for a recompute of a
|
|
1665
|
+
// derivative whose sources have moved on. It runs after the gates
|
|
1666
|
+
// above (an unauthenticated or refused read must never spend an
|
|
1667
|
+
// inference call) and before the payment dance, because the status
|
|
1668
|
+
// route grants the same caller the same trigger for free — gating it
|
|
1669
|
+
// on payment would buy nothing and would leave a never-computed
|
|
1670
|
+
// answer unreachable through this route. Nothing here blocks: a
|
|
1671
|
+
// previous version is served now, the fresh one lands in a later read.
|
|
1672
|
+
notifyDataRead(deps, { scope: scopeResult.scope });
|
|
1673
|
+
// A canonical scope's latest body is the canonical view, and only it:
|
|
1674
|
+
// a refusal is answered, never replaced by the legacy file. Explicit
|
|
1675
|
+
// versions stay legacy history. Read before payment, so a builder is
|
|
1676
|
+
// never challenged or charged for a read that is then refused.
|
|
1677
|
+
if (latest?.kind === "refused") {
|
|
1678
|
+
return legacyViewRefusalResponse(scopeResult.scope, latest.refusal);
|
|
1679
|
+
}
|
|
1680
|
+
// X402 payment dance for builder reads (see `readCharge`).
|
|
1681
|
+
const ownApp = await ownAppReadStatus(deps, authResult);
|
|
1682
|
+
if (ownApp instanceof Response)
|
|
1683
|
+
return ownApp;
|
|
1684
|
+
const charge = readCharge(deps, scopeResult.scope, authResult, ownApp);
|
|
1685
|
+
if (charge && latest?.kind === "canonical") {
|
|
1686
|
+
return legacyViewRefusalResponse(scopeResult.scope, {
|
|
1687
|
+
status: "unavailable",
|
|
1688
|
+
reason: "paid_read_unsupported",
|
|
687
1689
|
});
|
|
688
1690
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
if (deps.paymentEnabled &&
|
|
692
|
-
!isOwnerSignal &&
|
|
693
|
-
typeof builder === "string" &&
|
|
694
|
-
builder.startsWith("0x") &&
|
|
695
|
-
resolvedGrantId &&
|
|
696
|
-
deps.gateway &&
|
|
697
|
-
deps.gatewayConfig &&
|
|
698
|
-
deps.gatewayUrl) {
|
|
699
|
-
const x402Result = await handleX402Cycle({
|
|
700
|
-
deps,
|
|
701
|
-
request,
|
|
1691
|
+
if (charge) {
|
|
1692
|
+
const paid = await payForRead(deps, request, charge, {
|
|
702
1693
|
scope: scopeResult.scope,
|
|
703
|
-
fileIdParam
|
|
704
|
-
atParam
|
|
705
|
-
grantId: resolvedGrantId,
|
|
706
|
-
builder: builder,
|
|
707
|
-
gateway: deps.gateway,
|
|
708
|
-
gatewayConfig: deps.gatewayConfig,
|
|
709
|
-
gatewayUrl: deps.gatewayUrl,
|
|
1694
|
+
fileIdParam,
|
|
1695
|
+
atParam,
|
|
710
1696
|
});
|
|
711
|
-
if (
|
|
712
|
-
return
|
|
713
|
-
|
|
714
|
-
if (x402Result.kind === "gateway-error") {
|
|
715
|
-
// Relay the gateway's structured body verbatim so the builder can
|
|
716
|
-
// dispatch on it (insufficient balance vs. replay vs. race etc.).
|
|
717
|
-
return jsonResponse(x402Result.body, { status: x402Result.status });
|
|
718
|
-
}
|
|
719
|
-
// x402Result.kind === "ok" — payment accepted, proceed to read.
|
|
720
|
-
// The gateway's success body is forwarded back to the builder via
|
|
721
|
-
// X-PAYMENT-RESPONSE (canonical X402 convention) so callers can see
|
|
722
|
-
// breakdown / paidAt / paymentNonce without a second gateway round-trip.
|
|
723
|
-
paymentResponseHeader = encodePaymentResponseHeader(x402Result.payResponse);
|
|
1697
|
+
if (paid.kind === "refused")
|
|
1698
|
+
return paid.response;
|
|
1699
|
+
paymentResponseHeader = paid.paymentResponseHeader;
|
|
724
1700
|
}
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
1701
|
+
const headers = ownerNoteHeaders(ownerNotes);
|
|
1702
|
+
if (ownApp)
|
|
1703
|
+
headers["X-Vana-Payment-Exemption"] = "own-app";
|
|
1704
|
+
headers["X-Vana-Data-Source"] =
|
|
1705
|
+
latest?.kind === "canonical" ? "canonical" : "legacy";
|
|
1706
|
+
let envelope;
|
|
1707
|
+
let servedFileId;
|
|
1708
|
+
if (latest?.kind === "canonical") {
|
|
1709
|
+
envelope = latest.envelope;
|
|
1710
|
+
headers.ETag = `"${latest.revision}"`;
|
|
1711
|
+
}
|
|
1712
|
+
else {
|
|
1713
|
+
const result = await readDataContract({
|
|
1714
|
+
storage: deps.storage,
|
|
1715
|
+
scopeParam: scopeResult.scope,
|
|
1716
|
+
fileId: fileIdParam,
|
|
1717
|
+
at: atParam,
|
|
1718
|
+
...(view === "stored" ? { view } : {}),
|
|
1719
|
+
});
|
|
1720
|
+
if (!result.ok) {
|
|
1721
|
+
if (result.status === 404) {
|
|
1722
|
+
// The entry selected above can vanish before the read (a sync
|
|
1723
|
+
// reconcile applying a tombstone concurrently); answer 410, not
|
|
1724
|
+
// 404, when that is why.
|
|
1725
|
+
await assertScopeNotDeleted(deps, scopeResult.scope, undefined);
|
|
1726
|
+
}
|
|
1727
|
+
return contractErrorResponse(result, ownerNotes);
|
|
737
1728
|
}
|
|
738
|
-
|
|
1729
|
+
envelope = result.envelope;
|
|
1730
|
+
servedFileId = fileIdParam ?? selectedEntry?.fileId ?? undefined;
|
|
739
1731
|
}
|
|
740
1732
|
const servedEnvelope = isOwnerView(authResult)
|
|
741
|
-
?
|
|
742
|
-
: redactEnvelopeForGrantee(
|
|
1733
|
+
? envelope
|
|
1734
|
+
: redactEnvelopeForGrantee(envelope);
|
|
743
1735
|
const logId = deps.createLogId?.() ?? crypto.randomUUID();
|
|
744
1736
|
const timestamp = (deps.now ?? (() => new Date()))().toISOString();
|
|
745
1737
|
const ipAddress = request.headers.get("x-forwarded-for") ??
|
|
@@ -763,18 +1755,17 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
763
1755
|
return;
|
|
764
1756
|
reportPersonalServerReadFulfillment(deps, {
|
|
765
1757
|
builder: authResult.builder,
|
|
766
|
-
fileId:
|
|
767
|
-
selectedEntry?.fileId ??
|
|
768
|
-
undefined,
|
|
1758
|
+
fileId: servedFileId,
|
|
769
1759
|
grantId: authResult.grantId,
|
|
770
1760
|
ipAddress,
|
|
771
1761
|
logId,
|
|
1762
|
+
outcome: "served",
|
|
772
1763
|
scope: scopeResult.scope,
|
|
773
1764
|
servedAt: timestamp,
|
|
1765
|
+
source: "api",
|
|
774
1766
|
userAgent,
|
|
775
1767
|
});
|
|
776
1768
|
};
|
|
777
|
-
const headers = {};
|
|
778
1769
|
if (paymentResponseHeader) {
|
|
779
1770
|
headers["X-PAYMENT-RESPONSE"] = paymentResponseHeader;
|
|
780
1771
|
}
|
|
@@ -805,7 +1796,9 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
805
1796
|
});
|
|
806
1797
|
return response;
|
|
807
1798
|
}
|
|
808
|
-
const response = jsonResponse(servedEnvelope, {
|
|
1799
|
+
const response = jsonResponse(withOwnerBody(servedEnvelope, ownerNotes), {
|
|
1800
|
+
headers,
|
|
1801
|
+
});
|
|
809
1802
|
reportReadFulfillment();
|
|
810
1803
|
return response;
|
|
811
1804
|
}
|
|
@@ -823,10 +1816,23 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
823
1816
|
else {
|
|
824
1817
|
await deps.auth.authorizeOwner(request);
|
|
825
1818
|
}
|
|
1819
|
+
// `?supersede=legacy`: once this write commits, delete the scope's
|
|
1820
|
+
// older legacy-form versions (see supersedeLegacyVersions). It deletes
|
|
1821
|
+
// data, so only the owner may ask for it.
|
|
1822
|
+
const supersede = url.searchParams.get("supersede");
|
|
1823
|
+
if (supersede !== null && supersede !== "legacy") {
|
|
1824
|
+
await writeAuth?.releaseProof?.();
|
|
1825
|
+
return errorResponse(400, "INVALID_SUPERSEDE", 'supersede must be "legacy" or absent');
|
|
1826
|
+
}
|
|
1827
|
+
if (supersede !== null && writeAuth) {
|
|
1828
|
+
await writeAuth.releaseProof?.();
|
|
1829
|
+
return errorResponse(403, "FORBIDDEN", "Only the owner can supersede stored versions");
|
|
1830
|
+
}
|
|
826
1831
|
// A write that fails before commit hands the proof back (replay guard)
|
|
827
1832
|
// so the builder's retry with the same still-valid proof is accepted;
|
|
828
1833
|
// after commit the proof stays consumed (a retry would be a duplicate).
|
|
829
1834
|
let committed = false;
|
|
1835
|
+
let ingestStamp;
|
|
830
1836
|
const failWrite = async (response) => {
|
|
831
1837
|
await writeAuth?.releaseProof?.();
|
|
832
1838
|
return response;
|
|
@@ -835,7 +1841,20 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
835
1841
|
const scopeResult = parseDataScopeContract(scopeParam);
|
|
836
1842
|
if (!scopeResult.ok)
|
|
837
1843
|
return failWrite(contractErrorResponse(scopeResult));
|
|
838
|
-
const
|
|
1844
|
+
const parsedPrecondition = parseLegacyPrecondition(request);
|
|
1845
|
+
if (parsedPrecondition instanceof Response)
|
|
1846
|
+
return failWrite(parsedPrecondition);
|
|
1847
|
+
const producerHeader = parseProducerHeader(request);
|
|
1848
|
+
if (producerHeader instanceof Response)
|
|
1849
|
+
return failWrite(producerHeader);
|
|
1850
|
+
if (writeAuth && producerHeader.producer) {
|
|
1851
|
+
return failWrite(errorResponse(403, "NOT_OWNER", "Only the owner may assert a producer"));
|
|
1852
|
+
}
|
|
1853
|
+
ingestStamp = reserveIngestStamp(deps.now ?? (() => new Date()), deps.storage, scopeResult.scope);
|
|
1854
|
+
if (!ingestStamp) {
|
|
1855
|
+
return failWrite(errorResponse(429, "INGEST_CAPACITY", "Too many writes for this scope; retry when the clock advances"));
|
|
1856
|
+
}
|
|
1857
|
+
const collectedAtValue = ingestStamp.collectedAt;
|
|
839
1858
|
const status = deps.syncManager ? "syncing" : "stored";
|
|
840
1859
|
const afterTombstoneVersion = await ingestTombstoneMarker(deps, scopeResult.scope);
|
|
841
1860
|
// Builder writes land in the same access log as builder reads, so the
|
|
@@ -875,6 +1894,12 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
875
1894
|
// data needs no schema at all — we ingest it schemaless. (Structured JSON
|
|
876
1895
|
// below still resolves a schema for validation/metadata.)
|
|
877
1896
|
if (!isJsonContentType(request)) {
|
|
1897
|
+
if (producerHeader.producer) {
|
|
1898
|
+
return failWrite(errorResponse(400, "INVALID_PRODUCER", "Producer attribution requires a JSON body"));
|
|
1899
|
+
}
|
|
1900
|
+
if (supersede !== null) {
|
|
1901
|
+
return failWrite(errorResponse(400, "INVALID_SUPERSEDE", "supersede applies to JSON writes only"));
|
|
1902
|
+
}
|
|
878
1903
|
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
879
1904
|
const metadata = parseMetadataHeader(request.headers.get("x-vana-metadata"));
|
|
880
1905
|
// A binary derivative names its sources inside the metadata
|
|
@@ -892,6 +1917,7 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
892
1917
|
attribution: writeAuth?.attribution,
|
|
893
1918
|
lineage,
|
|
894
1919
|
afterTombstoneVersion,
|
|
1920
|
+
precondition: parsedPrecondition,
|
|
895
1921
|
});
|
|
896
1922
|
if (!result.ok)
|
|
897
1923
|
return failWrite(contractErrorResponse(result));
|
|
@@ -916,6 +1942,9 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
916
1942
|
const parsed = await parseJsonObjectBody(request, "Request body must be valid JSON");
|
|
917
1943
|
if (!parsed.ok)
|
|
918
1944
|
return failWrite(contractResponse(parsed.result));
|
|
1945
|
+
const provenance = await parseProducerProvenance(producerHeader.encodedProvenance, parsed.body);
|
|
1946
|
+
if (provenance instanceof Response)
|
|
1947
|
+
return failWrite(provenance);
|
|
919
1948
|
// Derivative writes: validate the caller's `lineage` before anything
|
|
920
1949
|
// is stored (a failure here throws, releasing the builder's proof).
|
|
921
1950
|
const lineage = await prepareWriteLineage(deps, scopeResult.scope, extractLineageField(parsed.body));
|
|
@@ -930,9 +1959,14 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
930
1959
|
attribution: writeAuth?.attribution,
|
|
931
1960
|
lineage,
|
|
932
1961
|
afterTombstoneVersion,
|
|
1962
|
+
precondition: parsedPrecondition,
|
|
1963
|
+
producer: producerHeader.producer,
|
|
1964
|
+
producerProvenance: provenance,
|
|
933
1965
|
});
|
|
934
1966
|
if (!result.ok)
|
|
935
1967
|
return failWrite(contractErrorResponse(result));
|
|
1968
|
+
if (result.replay)
|
|
1969
|
+
throw new Error("Ordinary POST cannot replay an import");
|
|
936
1970
|
committed = true;
|
|
937
1971
|
deps.logger?.info?.({
|
|
938
1972
|
scope: scopeResult.scope,
|
|
@@ -941,13 +1975,32 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
941
1975
|
...(writeAuth ? { builder: writeAuth.builder } : {}),
|
|
942
1976
|
}, "Data file ingested");
|
|
943
1977
|
await logBuilderWrite();
|
|
1978
|
+
const supersedeResult = supersede === "legacy"
|
|
1979
|
+
? await supersedeAfterCommit(deps, scopeResult.scope, collectedAtValue)
|
|
1980
|
+
: undefined;
|
|
944
1981
|
notifyNewData(deps.syncManager);
|
|
1982
|
+
// The parsed body is the envelope's `data`, which is where a producer
|
|
1983
|
+
// stamps `$pdpp`. Offered here rather than inside the ingest contract
|
|
1984
|
+
// so the import stays strictly after the record is durable.
|
|
1985
|
+
importIngestedIntoPdpp(deps, {
|
|
1986
|
+
scope: scopeResult.scope,
|
|
1987
|
+
collectedAt: collectedAtValue,
|
|
1988
|
+
data: parsed.body,
|
|
1989
|
+
});
|
|
945
1990
|
notifyDataWritten(deps, {
|
|
946
1991
|
scope: scopeResult.scope,
|
|
947
1992
|
collectedAt: collectedAtValue,
|
|
948
1993
|
lineageSources: lineage?.sources,
|
|
949
1994
|
});
|
|
950
|
-
return jsonResponse(
|
|
1995
|
+
return jsonResponse(supersedeResult
|
|
1996
|
+
? {
|
|
1997
|
+
...result.response,
|
|
1998
|
+
superseded: supersedeResult.superseded,
|
|
1999
|
+
...(supersedeResult.refused
|
|
2000
|
+
? { supersedeRefused: supersedeResult.refused }
|
|
2001
|
+
: {}),
|
|
2002
|
+
}
|
|
2003
|
+
: result.response, { status: 201 });
|
|
951
2004
|
}
|
|
952
2005
|
catch (err) {
|
|
953
2006
|
// An envelope that reached storage before indexing failed is
|
|
@@ -960,13 +2013,16 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
960
2013
|
error: err.cause instanceof Error
|
|
961
2014
|
? err.cause.message
|
|
962
2015
|
: String(err.cause),
|
|
963
|
-
}, "Envelope
|
|
2016
|
+
}, "Envelope write incomplete after durable commit; boot recovery may finish it");
|
|
964
2017
|
}
|
|
965
2018
|
else if (!committed) {
|
|
966
2019
|
await writeAuth?.releaseProof?.();
|
|
967
2020
|
}
|
|
968
2021
|
throw err;
|
|
969
2022
|
}
|
|
2023
|
+
finally {
|
|
2024
|
+
ingestStamp?.release();
|
|
2025
|
+
}
|
|
970
2026
|
}
|
|
971
2027
|
if (request.method === "DELETE") {
|
|
972
2028
|
await deps.auth.authorizeOwner(request);
|
|
@@ -988,6 +2044,18 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
988
2044
|
// first tombstone). Until that lands the only honest answer is 501.
|
|
989
2045
|
throw new LineageCascadeUnavailableError({ scope: parsed.scope });
|
|
990
2046
|
}
|
|
2047
|
+
// A canonical-owned scope's latest body is its connection's rows. No
|
|
2048
|
+
// store seam deletes one legacy scope's rows (streams can be shared,
|
|
2049
|
+
// and the account and its generation are the unit of erasure), so a
|
|
2050
|
+
// 200 here would leave the data readable. Refuse before any gateway or
|
|
2051
|
+
// file change; the connection's own delete erases its rows.
|
|
2052
|
+
if (deps.legacyScopeView?.ownsScope(parsed.scope)) {
|
|
2053
|
+
return jsonResponse({
|
|
2054
|
+
error: "CANONICAL_DELETE_UNSUPPORTED",
|
|
2055
|
+
message: `Scope "${parsed.scope}" has connector records that this route cannot delete. Nothing was deleted; delete the connection to erase its records.`,
|
|
2056
|
+
scope: parsed.scope,
|
|
2057
|
+
}, { status: 409 });
|
|
2058
|
+
}
|
|
991
2059
|
// Durable order: gateway tombstone -> storage blobs -> local copy. The
|
|
992
2060
|
// sync manager owns the remote ports; without one (sync disabled or
|
|
993
2061
|
// no owner key material) only the local copy goes and the result says
|
|
@@ -1043,7 +2111,7 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1043
2111
|
return jsonResponse(result, { status: 200 });
|
|
1044
2112
|
}
|
|
1045
2113
|
return methodNotAllowed();
|
|
1046
|
-
});
|
|
2114
|
+
}, logContext);
|
|
1047
2115
|
}
|
|
1048
2116
|
export async function handlePersonalServerAccessLogsRequest(request, deps, options = {}) {
|
|
1049
2117
|
return withApiErrors(async () => {
|
|
@@ -1089,6 +2157,9 @@ export async function handlePersonalServerSyncRequest(request, deps, options = {
|
|
|
1089
2157
|
}));
|
|
1090
2158
|
}
|
|
1091
2159
|
return notFound();
|
|
2160
|
+
}, {
|
|
2161
|
+
logger: deps.logger,
|
|
2162
|
+
route: `${request.method} ${options.basePath ?? "/v1/sync"}`,
|
|
1092
2163
|
});
|
|
1093
2164
|
}
|
|
1094
2165
|
export async function handlePersonalServerGrantsRequest(request, deps, options = {}) {
|
|
@@ -1210,4 +2281,7 @@ export async function handlePersonalServerOauthTokenRequest(request, deps) {
|
|
|
1210
2281
|
});
|
|
1211
2282
|
});
|
|
1212
2283
|
}
|
|
2284
|
+
export { handleOuraCollectionRequirementsRequest, readOuraCollectionRequirements, OURA_LEGACY_TAKEOVER_CONTRACT, } from "./oura-collection-requirements.js";
|
|
2285
|
+
export { createScopeUploadRegistry, ScopeUploadError, SCOPE_UPLOAD_MAX_BATCH_BYTES, SCOPE_UPLOAD_IDLE_TIMEOUT_MS, } from "./scope-uploads.js";
|
|
2286
|
+
export { prepareScopeUploadBatches, } from "./scope-upload-batches.js";
|
|
1213
2287
|
//# sourceMappingURL=index.js.map
|