@opendatalabs/personal-server-ts-core 0.0.1-canary.052d47e → 0.0.1-canary.05cdd81
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/account-storage-mode.d.ts +77 -0
- package/dist/api/account-storage-mode.d.ts.map +1 -0
- package/dist/api/account-storage-mode.js +72 -0
- package/dist/api/account-storage-mode.js.map +1 -0
- package/dist/api/index.d.ts +320 -10
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1758 -181
- package/dist/api/index.js.map +1 -1
- package/dist/api/legacy-write-gate.d.ts +51 -0
- package/dist/api/legacy-write-gate.d.ts.map +1 -0
- package/dist/api/legacy-write-gate.js +88 -0
- package/dist/api/legacy-write-gate.js.map +1 -0
- 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/owner-connector-delete.d.ts +79 -0
- package/dist/api/owner-connector-delete.d.ts.map +1 -0
- package/dist/api/owner-connector-delete.js +109 -0
- package/dist/api/owner-connector-delete.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/api/switched-delete-refusal.d.ts +16 -0
- package/dist/api/switched-delete-refusal.d.ts.map +1 -0
- package/dist/api/switched-delete-refusal.js +30 -0
- package/dist/api/switched-delete-refusal.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 +78 -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 +326 -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 +9 -1
- package/dist/contracts/sync.d.ts.map +1 -1
- package/dist/contracts/sync.js +7 -2
- 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 +87 -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 +92 -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/keys/index.d.ts +1 -0
- package/dist/keys/index.d.ts.map +1 -1
- package/dist/keys/index.js +1 -0
- package/dist/keys/index.js.map +1 -1
- package/dist/keys/owner-master-key.d.ts +37 -0
- package/dist/keys/owner-master-key.d.ts.map +1 -0
- package/dist/keys/owner-master-key.js +45 -0
- package/dist/keys/owner-master-key.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/erase-connector.d.ts +18 -0
- package/dist/legacy-projection/erase-connector.d.ts.map +1 -0
- package/dist/legacy-projection/erase-connector.js +29 -0
- package/dist/legacy-projection/erase-connector.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 +48 -0
- package/dist/legacy-projection/index.d.ts.map +1 -0
- package/dist/legacy-projection/index.js +255 -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/lineage/gateway.d.ts +3 -1
- package/dist/lineage/gateway.d.ts.map +1 -1
- package/dist/lineage/gateway.js +2 -1
- package/dist/lineage/gateway.js.map +1 -1
- package/dist/localdb/apply.d.ts +13 -0
- package/dist/localdb/apply.d.ts.map +1 -0
- package/dist/localdb/apply.js +565 -0
- package/dist/localdb/apply.js.map +1 -0
- package/dist/localdb/batch-commit.d.ts +67 -0
- package/dist/localdb/batch-commit.d.ts.map +1 -0
- package/dist/localdb/batch-commit.js +121 -0
- package/dist/localdb/batch-commit.js.map +1 -0
- package/dist/localdb/blobs.d.ts +71 -0
- package/dist/localdb/blobs.d.ts.map +1 -0
- package/dist/localdb/blobs.js +306 -0
- package/dist/localdb/blobs.js.map +1 -0
- package/dist/localdb/bootstrap.d.ts +20 -0
- package/dist/localdb/bootstrap.d.ts.map +1 -0
- package/dist/localdb/bootstrap.js +157 -0
- package/dist/localdb/bootstrap.js.map +1 -0
- package/dist/localdb/connection-link.d.ts +12 -0
- package/dist/localdb/connection-link.d.ts.map +1 -0
- package/dist/localdb/connection-link.js +72 -0
- package/dist/localdb/connection-link.js.map +1 -0
- package/dist/localdb/cycle.d.ts +32 -0
- package/dist/localdb/cycle.d.ts.map +1 -0
- package/dist/localdb/cycle.js +46 -0
- package/dist/localdb/cycle.js.map +1 -0
- package/dist/localdb/delete-batch.d.ts +51 -0
- package/dist/localdb/delete-batch.d.ts.map +1 -0
- package/dist/localdb/delete-batch.js +132 -0
- package/dist/localdb/delete-batch.js.map +1 -0
- package/dist/localdb/delete.d.ts +81 -0
- package/dist/localdb/delete.d.ts.map +1 -0
- package/dist/localdb/delete.js +736 -0
- package/dist/localdb/delete.js.map +1 -0
- package/dist/localdb/deps.d.ts +54 -0
- package/dist/localdb/deps.d.ts.map +1 -0
- package/dist/localdb/deps.js +10 -0
- package/dist/localdb/deps.js.map +1 -0
- package/dist/localdb/driver.d.ts +67 -0
- package/dist/localdb/driver.d.ts.map +1 -0
- package/dist/localdb/driver.js +3 -0
- package/dist/localdb/driver.js.map +1 -0
- package/dist/localdb/encode.d.ts +217 -0
- package/dist/localdb/encode.d.ts.map +1 -0
- package/dist/localdb/encode.js +502 -0
- package/dist/localdb/encode.js.map +1 -0
- package/dist/localdb/fence.d.ts +31 -0
- package/dist/localdb/fence.d.ts.map +1 -0
- package/dist/localdb/fence.js +69 -0
- package/dist/localdb/fence.js.map +1 -0
- package/dist/localdb/history.d.ts +74 -0
- package/dist/localdb/history.d.ts.map +1 -0
- package/dist/localdb/history.js +266 -0
- package/dist/localdb/history.js.map +1 -0
- package/dist/localdb/import-fingerprint.d.ts +8 -0
- package/dist/localdb/import-fingerprint.d.ts.map +1 -0
- package/dist/localdb/import-fingerprint.js +35 -0
- package/dist/localdb/import-fingerprint.js.map +1 -0
- package/dist/localdb/import-ledger.d.ts +27 -0
- package/dist/localdb/import-ledger.d.ts.map +1 -0
- package/dist/localdb/import-ledger.js +197 -0
- package/dist/localdb/import-ledger.js.map +1 -0
- package/dist/localdb/import-readback.d.ts +8 -0
- package/dist/localdb/import-readback.d.ts.map +1 -0
- package/dist/localdb/import-readback.js +69 -0
- package/dist/localdb/import-readback.js.map +1 -0
- package/dist/localdb/import-snapshot.d.ts +21 -0
- package/dist/localdb/import-snapshot.d.ts.map +1 -0
- package/dist/localdb/import-snapshot.js +94 -0
- package/dist/localdb/import-snapshot.js.map +1 -0
- package/dist/localdb/index.d.ts +39 -0
- package/dist/localdb/index.d.ts.map +1 -0
- package/dist/localdb/index.js +36 -0
- package/dist/localdb/index.js.map +1 -0
- package/dist/localdb/legacy-import-types.d.ts +110 -0
- package/dist/localdb/legacy-import-types.d.ts.map +1 -0
- package/dist/localdb/legacy-import-types.js +2 -0
- package/dist/localdb/legacy-import-types.js.map +1 -0
- package/dist/localdb/legacy-import.d.ts +36 -0
- package/dist/localdb/legacy-import.d.ts.map +1 -0
- package/dist/localdb/legacy-import.js +288 -0
- package/dist/localdb/legacy-import.js.map +1 -0
- package/dist/localdb/legacy-retire.d.ts +26 -0
- package/dist/localdb/legacy-retire.d.ts.map +1 -0
- package/dist/localdb/legacy-retire.js +93 -0
- package/dist/localdb/legacy-retire.js.map +1 -0
- package/dist/localdb/lifetime-boundary.d.ts +49 -0
- package/dist/localdb/lifetime-boundary.d.ts.map +1 -0
- package/dist/localdb/lifetime-boundary.js +74 -0
- package/dist/localdb/lifetime-boundary.js.map +1 -0
- package/dist/localdb/listing.d.ts +51 -0
- package/dist/localdb/listing.d.ts.map +1 -0
- package/dist/localdb/listing.js +231 -0
- package/dist/localdb/listing.js.map +1 -0
- package/dist/localdb/merge.d.ts +95 -0
- package/dist/localdb/merge.d.ts.map +1 -0
- package/dist/localdb/merge.js +282 -0
- package/dist/localdb/merge.js.map +1 -0
- package/dist/localdb/migrate.d.ts +10 -0
- package/dist/localdb/migrate.d.ts.map +1 -0
- package/dist/localdb/migrate.js +27 -0
- package/dist/localdb/migrate.js.map +1 -0
- package/dist/localdb/name.d.ts +3 -0
- package/dist/localdb/name.d.ts.map +1 -0
- package/dist/localdb/name.js +8 -0
- package/dist/localdb/name.js.map +1 -0
- package/dist/localdb/older-versions.d.ts +49 -0
- package/dist/localdb/older-versions.d.ts.map +1 -0
- package/dist/localdb/older-versions.js +172 -0
- package/dist/localdb/older-versions.js.map +1 -0
- package/dist/localdb/open.d.ts +19 -0
- package/dist/localdb/open.d.ts.map +1 -0
- package/dist/localdb/open.js +46 -0
- package/dist/localdb/open.js.map +1 -0
- package/dist/localdb/part-layout.d.ts +74 -0
- package/dist/localdb/part-layout.d.ts.map +1 -0
- package/dist/localdb/part-layout.js +203 -0
- package/dist/localdb/part-layout.js.map +1 -0
- package/dist/localdb/publish-meter.d.ts +45 -0
- package/dist/localdb/publish-meter.d.ts.map +1 -0
- package/dist/localdb/publish-meter.js +62 -0
- package/dist/localdb/publish-meter.js.map +1 -0
- package/dist/localdb/publish.d.ts +47 -0
- package/dist/localdb/publish.d.ts.map +1 -0
- package/dist/localdb/publish.js +2100 -0
- package/dist/localdb/publish.js.map +1 -0
- package/dist/localdb/purge.d.ts +23 -0
- package/dist/localdb/purge.d.ts.map +1 -0
- package/dist/localdb/purge.js +75 -0
- package/dist/localdb/purge.js.map +1 -0
- package/dist/localdb/query.d.ts +69 -0
- package/dist/localdb/query.d.ts.map +1 -0
- package/dist/localdb/query.js +306 -0
- package/dist/localdb/query.js.map +1 -0
- package/dist/localdb/queue.d.ts +10 -0
- package/dist/localdb/queue.d.ts.map +1 -0
- package/dist/localdb/queue.js +31 -0
- package/dist/localdb/queue.js.map +1 -0
- package/dist/localdb/read-selection.d.ts +103 -0
- package/dist/localdb/read-selection.d.ts.map +1 -0
- package/dist/localdb/read-selection.js +141 -0
- package/dist/localdb/read-selection.js.map +1 -0
- package/dist/localdb/registry-view.d.ts +65 -0
- package/dist/localdb/registry-view.d.ts.map +1 -0
- package/dist/localdb/registry-view.js +73 -0
- package/dist/localdb/registry-view.js.map +1 -0
- package/dist/localdb/replace.d.ts +33 -0
- package/dist/localdb/replace.d.ts.map +1 -0
- package/dist/localdb/replace.js +22 -0
- package/dist/localdb/replace.js.map +1 -0
- package/dist/localdb/requirements.d.ts +35 -0
- package/dist/localdb/requirements.d.ts.map +1 -0
- package/dist/localdb/requirements.js +66 -0
- package/dist/localdb/requirements.js.map +1 -0
- package/dist/localdb/resolve.d.ts +43 -0
- package/dist/localdb/resolve.d.ts.map +1 -0
- package/dist/localdb/resolve.js +265 -0
- package/dist/localdb/resolve.js.map +1 -0
- package/dist/localdb/run-end.d.ts +19 -0
- package/dist/localdb/run-end.d.ts.map +1 -0
- package/dist/localdb/run-end.js +283 -0
- package/dist/localdb/run-end.js.map +1 -0
- package/dist/localdb/run-intake.d.ts +16 -0
- package/dist/localdb/run-intake.d.ts.map +1 -0
- package/dist/localdb/run-intake.js +441 -0
- package/dist/localdb/run-intake.js.map +1 -0
- package/dist/localdb/run-receipts.d.ts +19 -0
- package/dist/localdb/run-receipts.d.ts.map +1 -0
- package/dist/localdb/run-receipts.js +151 -0
- package/dist/localdb/run-receipts.js.map +1 -0
- package/dist/localdb/schema.d.ts +7 -0
- package/dist/localdb/schema.d.ts.map +1 -0
- package/dist/localdb/schema.js +312 -0
- package/dist/localdb/schema.js.map +1 -0
- package/dist/localdb/seed.d.ts +39 -0
- package/dist/localdb/seed.d.ts.map +1 -0
- package/dist/localdb/seed.js +188 -0
- package/dist/localdb/seed.js.map +1 -0
- package/dist/localdb/slot.d.ts +9 -0
- package/dist/localdb/slot.d.ts.map +1 -0
- package/dist/localdb/slot.js +15 -0
- package/dist/localdb/slot.js.map +1 -0
- package/dist/localdb/sync.d.ts +53 -0
- package/dist/localdb/sync.d.ts.map +1 -0
- package/dist/localdb/sync.js +211 -0
- package/dist/localdb/sync.js.map +1 -0
- package/dist/localdb/transfer-memory.d.ts +17 -0
- package/dist/localdb/transfer-memory.d.ts.map +1 -0
- package/dist/localdb/transfer-memory.js +17 -0
- package/dist/localdb/transfer-memory.js.map +1 -0
- package/dist/localdb/unwrite.d.ts +22 -0
- package/dist/localdb/unwrite.d.ts.map +1 -0
- package/dist/localdb/unwrite.js +46 -0
- package/dist/localdb/unwrite.js.map +1 -0
- package/dist/localdb/upload-wave.d.ts +34 -0
- package/dist/localdb/upload-wave.d.ts.map +1 -0
- package/dist/localdb/upload-wave.js +30 -0
- package/dist/localdb/upload-wave.js.map +1 -0
- package/dist/localdb/verified-heads.d.ts +13 -0
- package/dist/localdb/verified-heads.d.ts.map +1 -0
- package/dist/localdb/verified-heads.js +56 -0
- package/dist/localdb/verified-heads.js.map +1 -0
- package/dist/localdb/view-changes.d.ts +58 -0
- package/dist/localdb/view-changes.d.ts.map +1 -0
- package/dist/localdb/view-changes.js +174 -0
- package/dist/localdb/view-changes.js.map +1 -0
- package/dist/mcp/approval-url.d.ts +100 -0
- package/dist/mcp/approval-url.d.ts.map +1 -0
- package/dist/mcp/approval-url.js +171 -0
- package/dist/mcp/approval-url.js.map +1 -0
- package/dist/mcp/connection-api.d.ts +239 -3
- package/dist/mcp/connection-api.d.ts.map +1 -1
- package/dist/mcp/connection-api.js +792 -27
- package/dist/mcp/connection-api.js.map +1 -1
- package/dist/mcp/grant-registration.d.ts +15 -0
- package/dist/mcp/grant-registration.d.ts.map +1 -0
- package/dist/mcp/grant-registration.js +44 -0
- package/dist/mcp/grant-registration.js.map +1 -0
- package/dist/mcp/grantee.d.ts +1 -1
- package/dist/mcp/grantee.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +5 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +5 -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 +27 -3
- package/dist/mcp/read-client.d.ts.map +1 -1
- package/dist/mcp/read-client.js +325 -19
- package/dist/mcp/read-client.js.map +1 -1
- package/dist/mcp/resources.d.ts +3 -1
- package/dist/mcp/resources.d.ts.map +1 -1
- package/dist/mcp/resources.js +14 -2
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/server.d.ts +47 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +219 -17
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session.d.ts +3 -1
- package/dist/mcp/session.d.ts.map +1 -1
- package/dist/mcp/session.js +58 -11
- package/dist/mcp/session.js.map +1 -1
- package/dist/mcp/store.d.ts +23 -1
- package/dist/mcp/store.d.ts.map +1 -1
- package/dist/mcp/store.js +102 -1
- 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 +154 -3
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +660 -39
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +105 -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 +330 -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 +19 -0
- package/dist/policy/reserved-scopes.js.map +1 -0
- package/dist/ports/index.d.ts +323 -10
- 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 +137 -0
- package/dist/publication/publish.d.ts.map +1 -0
- package/dist/publication/publish.js +278 -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 +81 -0
- package/dist/schemas/server-config.d.ts.map +1 -1
- package/dist/schemas/server-config.js +179 -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 +33 -3
- 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/rate-limit-policy.d.ts +66 -0
- package/dist/storage/adapters/rate-limit-policy.d.ts.map +1 -0
- package/dist/storage/adapters/rate-limit-policy.js +103 -0
- package/dist/storage/adapters/rate-limit-policy.js.map +1 -0
- package/dist/storage/adapters/sdk.d.ts +9 -1
- package/dist/storage/adapters/sdk.d.ts.map +1 -1
- package/dist/storage/adapters/sdk.js +32 -8
- package/dist/storage/adapters/sdk.js.map +1 -1
- package/dist/storage/adapters/throttle.d.ts +30 -0
- package/dist/storage/adapters/throttle.d.ts.map +1 -0
- package/dist/storage/adapters/throttle.js +94 -0
- package/dist/storage/adapters/throttle.js.map +1 -0
- package/dist/storage/adapters/vana-audience.d.ts +27 -0
- package/dist/storage/adapters/vana-audience.d.ts.map +1 -0
- package/dist/storage/adapters/vana-audience.js +99 -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 +128 -18
- 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 +46 -5
- 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 +201 -0
- package/dist/storage/legacy-scope-view.d.ts.map +1 -0
- package/dist/storage/legacy-scope-view.js +1044 -0
- package/dist/storage/legacy-scope-view.js.map +1 -0
- package/dist/storage/legacy-write-seal.d.ts +73 -0
- package/dist/storage/legacy-write-seal.d.ts.map +1 -0
- package/dist/storage/legacy-write-seal.js +71 -0
- package/dist/storage/legacy-write-seal.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 +204 -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 +38 -0
- package/dist/stream-sync/artifacts.d.ts.map +1 -0
- package/dist/stream-sync/artifacts.js +141 -0
- package/dist/stream-sync/artifacts.js.map +1 -0
- package/dist/stream-sync/blobs.d.ts +18 -0
- package/dist/stream-sync/blobs.d.ts.map +1 -0
- package/dist/stream-sync/blobs.js +83 -0
- package/dist/stream-sync/blobs.js.map +1 -0
- package/dist/stream-sync/crypto-port.d.ts +20 -0
- package/dist/stream-sync/crypto-port.d.ts.map +1 -0
- package/dist/stream-sync/crypto-port.js +19 -0
- package/dist/stream-sync/crypto-port.js.map +1 -0
- package/dist/stream-sync/crypto.d.ts +27 -0
- package/dist/stream-sync/crypto.d.ts.map +1 -0
- package/dist/stream-sync/crypto.js +67 -0
- package/dist/stream-sync/crypto.js.map +1 -0
- package/dist/stream-sync/delete-metadata.d.ts +23 -0
- package/dist/stream-sync/delete-metadata.d.ts.map +1 -0
- package/dist/stream-sync/delete-metadata.js +40 -0
- package/dist/stream-sync/delete-metadata.js.map +1 -0
- package/dist/stream-sync/index.d.ts +13 -0
- package/dist/stream-sync/index.d.ts.map +1 -0
- package/dist/stream-sync/index.js +13 -0
- package/dist/stream-sync/index.js.map +1 -0
- package/dist/stream-sync/intake.d.ts +185 -0
- package/dist/stream-sync/intake.d.ts.map +1 -0
- package/dist/stream-sync/intake.js +36 -0
- package/dist/stream-sync/intake.js.map +1 -0
- package/dist/stream-sync/memory-registry.d.ts +58 -0
- package/dist/stream-sync/memory-registry.d.ts.map +1 -0
- package/dist/stream-sync/memory-registry.js +119 -0
- package/dist/stream-sync/memory-registry.js.map +1 -0
- package/dist/stream-sync/ports.d.ts +363 -0
- package/dist/stream-sync/ports.d.ts.map +1 -0
- package/dist/stream-sync/ports.js +68 -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 +217 -0
- package/dist/stream-sync/publish-plan.js.map +1 -0
- package/dist/stream-sync/registry.d.ts +24 -0
- package/dist/stream-sync/registry.d.ts.map +1 -0
- package/dist/stream-sync/registry.js +389 -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/seed-staging.d.ts +85 -0
- package/dist/stream-sync/seed-staging.d.ts.map +1 -0
- package/dist/stream-sync/seed-staging.js +325 -0
- package/dist/stream-sync/seed-staging.js.map +1 -0
- package/dist/stream-sync/send-gate.d.ts +149 -0
- package/dist/stream-sync/send-gate.d.ts.map +1 -0
- package/dist/stream-sync/send-gate.js +382 -0
- package/dist/stream-sync/send-gate.js.map +1 -0
- package/dist/stream-sync/storage-retry.d.ts +210 -0
- package/dist/stream-sync/storage-retry.d.ts.map +1 -0
- package/dist/stream-sync/storage-retry.js +314 -0
- package/dist/stream-sync/storage-retry.js.map +1 -0
- package/dist/stream-sync/stream-aead.d.ts +33 -0
- package/dist/stream-sync/stream-aead.d.ts.map +1 -0
- package/dist/stream-sync/stream-aead.js +183 -0
- package/dist/stream-sync/stream-aead.js.map +1 -0
- package/dist/stream-sync-read/index.d.ts +4 -0
- package/dist/stream-sync-read/index.d.ts.map +1 -0
- package/dist/stream-sync-read/index.js +3 -0
- package/dist/stream-sync-read/index.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.d.ts +196 -0
- package/dist/stream-sync-read/service.d.ts.map +1 -0
- package/dist/stream-sync-read/service.js +17 -0
- package/dist/stream-sync-read/service.js.map +1 -0
- package/dist/sync/account-mode/authority.d.ts +56 -0
- package/dist/sync/account-mode/authority.d.ts.map +1 -0
- package/dist/sync/account-mode/authority.js +145 -0
- package/dist/sync/account-mode/authority.js.map +1 -0
- package/dist/sync/account-mode/evidence-wire.d.ts +23 -0
- package/dist/sync/account-mode/evidence-wire.d.ts.map +1 -0
- package/dist/sync/account-mode/evidence-wire.js +37 -0
- package/dist/sync/account-mode/evidence-wire.js.map +1 -0
- package/dist/sync/account-mode/import-waker.d.ts +36 -0
- package/dist/sync/account-mode/import-waker.d.ts.map +1 -0
- package/dist/sync/account-mode/import-waker.js +55 -0
- package/dist/sync/account-mode/import-waker.js.map +1 -0
- package/dist/sync/account-mode/index.d.ts +10 -0
- package/dist/sync/account-mode/index.d.ts.map +1 -0
- package/dist/sync/account-mode/index.js +10 -0
- package/dist/sync/account-mode/index.js.map +1 -0
- package/dist/sync/account-mode/port.d.ts +11 -0
- package/dist/sync/account-mode/port.d.ts.map +1 -0
- package/dist/sync/account-mode/port.js +21 -0
- package/dist/sync/account-mode/port.js.map +1 -0
- package/dist/sync/account-mode/record.d.ts +52 -0
- package/dist/sync/account-mode/record.d.ts.map +1 -0
- package/dist/sync/account-mode/record.js +60 -0
- package/dist/sync/account-mode/record.js.map +1 -0
- package/dist/sync/account-mode/rw-lock.d.ts +14 -0
- package/dist/sync/account-mode/rw-lock.d.ts.map +1 -0
- package/dist/sync/account-mode/rw-lock.js +59 -0
- package/dist/sync/account-mode/rw-lock.js.map +1 -0
- package/dist/sync/cancellable-gateway.d.ts +25 -0
- package/dist/sync/cancellable-gateway.d.ts.map +1 -0
- package/dist/sync/cancellable-gateway.js +64 -0
- package/dist/sync/cancellable-gateway.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/change-probe.d.ts +42 -0
- package/dist/sync/engine/change-probe.d.ts.map +1 -0
- package/dist/sync/engine/change-probe.js +79 -0
- package/dist/sync/engine/change-probe.js.map +1 -0
- package/dist/sync/engine/change-push.d.ts +53 -0
- package/dist/sync/engine/change-push.d.ts.map +1 -0
- package/dist/sync/engine/change-push.js +153 -0
- package/dist/sync/engine/change-push.js.map +1 -0
- package/dist/sync/engine/sync-manager.d.ts +181 -2
- package/dist/sync/engine/sync-manager.d.ts.map +1 -1
- package/dist/sync/engine/sync-manager.js +642 -19
- package/dist/sync/engine/sync-manager.js.map +1 -1
- package/dist/sync/index.d.ts +11 -3
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +11 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/pdpp-import.d.ts +202 -0
- package/dist/sync/pdpp-import.d.ts.map +1 -0
- package/dist/sync/pdpp-import.js +466 -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 +26 -0
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/sync/upload-attempts.d.ts +218 -0
- package/dist/sync/upload-attempts.d.ts.map +1 -0
- package/dist/sync/upload-attempts.js +500 -0
- package/dist/sync/upload-attempts.js.map +1 -0
- package/dist/sync/upload-state.d.ts +163 -0
- package/dist/sync/upload-state.d.ts.map +1 -0
- package/dist/sync/upload-state.js +239 -0
- package/dist/sync/upload-state.js.map +1 -0
- package/dist/sync/workers/delete.d.ts +63 -6
- package/dist/sync/workers/delete.d.ts.map +1 -1
- package/dist/sync/workers/delete.js +621 -168
- package/dist/sync/workers/delete.js.map +1 -1
- package/dist/sync/workers/download.d.ts +27 -1
- package/dist/sync/workers/download.d.ts.map +1 -1
- package/dist/sync/workers/download.js +368 -27
- 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 +97 -8
- package/dist/sync/workers/upload.d.ts.map +1 -1
- package/dist/sync/workers/upload.js +498 -277
- package/dist/sync/workers/upload.js.map +1 -1
- package/dist/test-support/memory-oracle.calibration.d.ts +16 -0
- package/dist/test-support/memory-oracle.calibration.d.ts.map +1 -0
- package/dist/test-support/memory-oracle.calibration.js +43 -0
- package/dist/test-support/memory-oracle.calibration.js.map +1 -0
- package/dist/test-support/memory-oracle.d.ts +82 -0
- package/dist/test-support/memory-oracle.d.ts.map +1 -0
- package/dist/test-support/memory-oracle.js +104 -0
- package/dist/test-support/memory-oracle.js.map +1 -0
- package/dist/test-utils/account-mode.d.ts +36 -0
- package/dist/test-utils/account-mode.d.ts.map +1 -0
- package/dist/test-utils/account-mode.js +77 -0
- package/dist/test-utils/account-mode.js.map +1 -0
- package/dist/test-utils/index.d.ts +2 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/index.js +2 -0
- package/dist/test-utils/index.js.map +1 -1
- package/dist/test-utils/legacy-write-seal.d.ts +16 -0
- package/dist/test-utils/legacy-write-seal.d.ts.map +1 -0
- package/dist/test-utils/legacy-write-seal.js +20 -0
- package/dist/test-utils/legacy-write-seal.js.map +1 -0
- package/dist/test-utils/live-grants.d.ts +24 -0
- package/dist/test-utils/live-grants.d.ts.map +1 -0
- package/dist/test-utils/live-grants.js +6 -0
- package/dist/test-utils/live-grants.js.map +1 -0
- package/dist/test-utils/memory-storage.d.ts +18 -2
- package/dist/test-utils/memory-storage.d.ts.map +1 -1
- package/dist/test-utils/memory-storage.js +156 -42
- 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/dist-test/localdb/conformance.d.ts +13 -0
- package/dist-test/localdb/conformance.d.ts.map +1 -0
- package/dist-test/localdb/conformance.js +292 -0
- package/dist-test/localdb/conformance.js.map +1 -0
- package/dist-test/tsconfig.tsbuildinfo +1 -0
- package/package.json +131 -5
package/dist/api/index.js
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
|
+
import { isOwnAppRead } from "../payment/own-app.js";
|
|
2
|
+
import { HISTORY_PAGE_LIMIT } from "../localdb/history.js";
|
|
3
|
+
import { isSystemScope } from "../policy/reserved-scopes.js";
|
|
1
4
|
import { DataDeletedError, DeleteTombstoneFailedError, GrantRequiredError, InvalidCascadeError, LineageCascadeUnavailableError, LineageGatewayError, LineageUnavailableError, ProtocolError, ServerNotConfiguredError, } from "../errors/catalog.js";
|
|
2
5
|
import { computeDataPointId } from "../sync/data-point-id.js";
|
|
3
6
|
import { isEntryCoveredByTombstone, } from "../sync/scope-deletions.js";
|
|
7
|
+
import { isPermanentRejection, } from "../sync/pdpp-import.js";
|
|
8
|
+
import { supersedeLegacyVersions, } from "../storage/legacy-projection.js";
|
|
4
9
|
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";
|
|
10
|
+
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";
|
|
11
|
+
import { canonicalJsonBytes } from "../derivatives/e2ee/jcs.js";
|
|
12
|
+
// Imported directly: the contracts barrel does not re-export this addition.
|
|
13
|
+
import { summarizeDataAdditionsContract } from "../contracts/data.js";
|
|
14
|
+
import { scopeCoveredByGrant } from "@opendatalabs/vana-sdk/browser";
|
|
6
15
|
import { WRITER_ATTRIBUTION_KEY, } from "../write/attribution.js";
|
|
7
16
|
import { extractLineageField, LINEAGE_KEY, prepareLineage, } from "../lineage/lineage.js";
|
|
17
|
+
import { ScopeUploadError } from "./scope-uploads.js";
|
|
18
|
+
import { accountModeUnknownResponse, } from "./account-storage-mode.js";
|
|
19
|
+
import { LegacyWriteRefusedError, refuseLegacyWrite, updateRequiredResponse, } from "./legacy-write-gate.js";
|
|
20
|
+
import { switchedDeleteRefusalResponse } from "./switched-delete-refusal.js";
|
|
21
|
+
import { deletionHistoryOf, } from "../storage/legacy-scope-view.js";
|
|
8
22
|
import { binaryFilename, binaryMimeType, isJsonContentType, } from "../contracts/binary.js";
|
|
9
23
|
import { buildChallenge, parsePaymentHeader, verifyPayment, } from "../payment/index.js";
|
|
24
|
+
/**
|
|
25
|
+
* Stand-in for a grant/grantee that does not exist on a denial — a scope that
|
|
26
|
+
* no grant covers has no grant id and no builder to attribute the read to.
|
|
27
|
+
*/
|
|
28
|
+
export const READ_FULFILLMENT_NONE = "none";
|
|
10
29
|
function jsonResponse(body, init) {
|
|
11
30
|
const headers = new Headers(init?.headers);
|
|
12
31
|
headers.set("Content-Type", "application/json");
|
|
@@ -32,20 +51,211 @@ function encodePaymentResponseHeader(body) {
|
|
|
32
51
|
function contractResponse(result) {
|
|
33
52
|
return jsonResponse(result.body, { status: result.status });
|
|
34
53
|
}
|
|
35
|
-
|
|
36
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Runs after the write committed, so a failure here must not fail the
|
|
56
|
+
* write: it is logged and the response lists no superseded versions.
|
|
57
|
+
*/
|
|
58
|
+
async function supersedeAfterCommit(deps, scope, committedAt) {
|
|
59
|
+
try {
|
|
60
|
+
const result = await supersedeLegacyVersions(deps.storage, scope, committedAt);
|
|
61
|
+
if (result.superseded.length > 0) {
|
|
62
|
+
deps.logger?.info?.({ scope, committedAt, superseded: result.superseded }, "Deleted legacy-form versions superseded by a PDPP write");
|
|
63
|
+
}
|
|
64
|
+
if (result.refused) {
|
|
65
|
+
deps.logger?.info?.({ scope, committedAt, refused: result.refused }, "Kept legacy-form versions; superseding was refused");
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
deps.logger?.warn?.({
|
|
71
|
+
scope,
|
|
72
|
+
committedAt,
|
|
73
|
+
error: err instanceof Error ? err.message : String(err),
|
|
74
|
+
}, "Superseding legacy-form versions failed; the write is stored");
|
|
75
|
+
return { superseded: [], refused: "superseding failed" };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function contractErrorResponse(err, notes) {
|
|
79
|
+
return jsonResponse(withOwnerBody(err.body, notes), {
|
|
80
|
+
status: err.status,
|
|
81
|
+
headers: ownerNoteHeaders(notes),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** What only the owner is told when the existing path answers a stream read. */
|
|
85
|
+
function ownerNoteHeaders(notes) {
|
|
86
|
+
const headers = {};
|
|
87
|
+
if (notes?.withheld?.length) {
|
|
88
|
+
headers["X-Stream-Sync-Withheld"] = withheldReasons(notes.withheld);
|
|
89
|
+
}
|
|
90
|
+
if (notes?.pending) {
|
|
91
|
+
headers["X-Stream-Sync-Pending"] = String(notes.pending.runs);
|
|
92
|
+
}
|
|
93
|
+
if (notes?.awaitingImport) {
|
|
94
|
+
headers["X-Stream-Sync-Awaiting-Import"] = String(notes.awaitingImport.runs);
|
|
95
|
+
}
|
|
96
|
+
if (notes?.notReflected) {
|
|
97
|
+
headers["X-Stream-Sync-Not-Reflected"] = String(notes.notReflected.streams);
|
|
98
|
+
}
|
|
99
|
+
return headers;
|
|
100
|
+
}
|
|
101
|
+
function withOwnerBody(body, notes) {
|
|
102
|
+
return notes?.withheld?.length ? { ...body, withheld: notes.withheld } : body;
|
|
37
103
|
}
|
|
38
104
|
function protocolErrorResponse(err) {
|
|
39
105
|
return jsonResponse(err.toJSON(), { status: err.code });
|
|
40
106
|
}
|
|
41
|
-
function errorResponse(status, errorCode, message) {
|
|
42
|
-
return jsonResponse({
|
|
107
|
+
function errorResponse(status, errorCode, message, notes) {
|
|
108
|
+
return jsonResponse(withOwnerBody({
|
|
43
109
|
error: {
|
|
44
110
|
code: status,
|
|
45
111
|
errorCode,
|
|
46
112
|
message,
|
|
47
113
|
},
|
|
48
|
-
}, { status });
|
|
114
|
+
}, notes), { status, headers: ownerNoteHeaders(notes) });
|
|
115
|
+
}
|
|
116
|
+
function legacyMutationRefusal(mode) {
|
|
117
|
+
if (mode === "unknown")
|
|
118
|
+
return accountModeUnknownResponse();
|
|
119
|
+
if (mode === "switched")
|
|
120
|
+
return updateRequiredResponse();
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
/** The response for a stream-sync decision that serves nothing; `null` otherwise. */
|
|
124
|
+
function streamSyncRefusal(decision) {
|
|
125
|
+
switch (decision.kind) {
|
|
126
|
+
case "unavailable":
|
|
127
|
+
return decision.reason === "connection_not_found"
|
|
128
|
+
? errorResponse(404, "CONNECTION_NOT_FOUND", "No connection of this name's connector matches the connection parameter", decision)
|
|
129
|
+
: null;
|
|
130
|
+
case "key_mismatch":
|
|
131
|
+
return errorResponse(503, "KEY_MISMATCH", "This data was written with another owner key and cannot be read here");
|
|
132
|
+
case "cursor_stale":
|
|
133
|
+
return errorResponse(409, "CURSOR_STALE", "The cursor names a version this server no longer holds; read again without it");
|
|
134
|
+
case "busy":
|
|
135
|
+
return jsonResponse({
|
|
136
|
+
error: {
|
|
137
|
+
code: 503,
|
|
138
|
+
errorCode: "STREAM_SYNC_READ_BUSY",
|
|
139
|
+
message: "This data is changing; read again shortly",
|
|
140
|
+
},
|
|
141
|
+
}, {
|
|
142
|
+
status: 503,
|
|
143
|
+
headers: { "Retry-After": String(decision.retryAfterSeconds) },
|
|
144
|
+
});
|
|
145
|
+
case "invalid_cursor":
|
|
146
|
+
return errorResponse(400, "INVALID_CURSOR", "cursor is not valid");
|
|
147
|
+
case "invalid_connection":
|
|
148
|
+
return errorResponse(400, "INVALID_CONNECTION", "connection must be empty or 16 lowercase hex characters");
|
|
149
|
+
case "too_large":
|
|
150
|
+
return errorResponse(503, "TOO_LARGE", "This legacy view is larger than this server can build; read its streams instead");
|
|
151
|
+
default:
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* An in-process stream read is checked against the body it will serve. The
|
|
157
|
+
* view is read in full first, so the check and the served bytes are one body.
|
|
158
|
+
* Without a check the stream passes through unchanged.
|
|
159
|
+
*/
|
|
160
|
+
async function validateStreamBody(decision, inProcess) {
|
|
161
|
+
if (!inProcess?.validateBody)
|
|
162
|
+
return decision;
|
|
163
|
+
const text = await new Response(decision.body).text();
|
|
164
|
+
let body;
|
|
165
|
+
try {
|
|
166
|
+
body = JSON.parse(text);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
throw new ProtocolError(422, "NOT_BLOCK_READABLE", "The stream view has no JSON body to read as blocks.");
|
|
170
|
+
}
|
|
171
|
+
await inProcess.validateBody(body, { fromStreamView: true });
|
|
172
|
+
return { ...decision, body: new Response(text).body };
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Serve a stream view: the envelope streams part by part. A charged read
|
|
176
|
+
* has already paid (`paymentResponseHeader`).
|
|
177
|
+
*/
|
|
178
|
+
async function serveStreamSyncView(deps, request, input) {
|
|
179
|
+
const { authResult, decision, inProcess } = input;
|
|
180
|
+
const logId = deps.createLogId?.() ?? crypto.randomUUID();
|
|
181
|
+
const timestamp = (deps.now ?? (() => new Date()))().toISOString();
|
|
182
|
+
const ipAddress = request.headers.get("x-forwarded-for") ??
|
|
183
|
+
request.headers.get("x-real-ip") ??
|
|
184
|
+
"unknown";
|
|
185
|
+
const userAgent = request.headers.get("user-agent") ?? "unknown";
|
|
186
|
+
if (inProcess?.logAccess !== false) {
|
|
187
|
+
try {
|
|
188
|
+
await deps.accessLogWriter.write({
|
|
189
|
+
logId,
|
|
190
|
+
grantId: authResult?.grantId ?? input.grantId ?? "unknown",
|
|
191
|
+
builder: authResult?.builder ?? "unknown",
|
|
192
|
+
action: "read",
|
|
193
|
+
scope: input.scope,
|
|
194
|
+
timestamp,
|
|
195
|
+
ipAddress,
|
|
196
|
+
userAgent,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
await decision.body.cancel();
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (authResult?.grantId && authResult.builder) {
|
|
205
|
+
const served = {
|
|
206
|
+
builder: authResult.builder,
|
|
207
|
+
fileId: undefined,
|
|
208
|
+
grantId: authResult.grantId,
|
|
209
|
+
ipAddress,
|
|
210
|
+
logId,
|
|
211
|
+
outcome: "served",
|
|
212
|
+
scope: input.scope,
|
|
213
|
+
servedAt: timestamp,
|
|
214
|
+
source: "api",
|
|
215
|
+
userAgent,
|
|
216
|
+
};
|
|
217
|
+
// An in-process caller decides completion itself, after any paging.
|
|
218
|
+
if (inProcess) {
|
|
219
|
+
inProcess.onServed({
|
|
220
|
+
scope: input.scope,
|
|
221
|
+
builder: authResult.builder,
|
|
222
|
+
grantId: authResult.grantId,
|
|
223
|
+
fileId: undefined,
|
|
224
|
+
logId,
|
|
225
|
+
ipAddress,
|
|
226
|
+
servedAt: timestamp,
|
|
227
|
+
userAgent,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
reportPersonalServerReadFulfillment(deps, served);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// A projection can fail after the 200 status. The client must then see
|
|
235
|
+
// the connection abort, never a complete shorter body. Chunked framing
|
|
236
|
+
// also keeps @hono/node-server from reading the body ahead of the status:
|
|
237
|
+
// a failure in that read-ahead would end the response with a
|
|
238
|
+
// content-length of the bytes read so far, as if it were whole.
|
|
239
|
+
return new Response(decision.body, {
|
|
240
|
+
status: 200,
|
|
241
|
+
headers: {
|
|
242
|
+
"Content-Type": "application/json",
|
|
243
|
+
"Transfer-Encoding": "chunked",
|
|
244
|
+
"X-Vana-Data-Source": "stream-sync",
|
|
245
|
+
"X-Stream-Sync-Cursor": decision.cursor,
|
|
246
|
+
// Owner only: the service attaches this to no other audience.
|
|
247
|
+
...(decision.withheld?.length
|
|
248
|
+
? { "X-Stream-Sync-Withheld": withheldReasons(decision.withheld) }
|
|
249
|
+
: {}),
|
|
250
|
+
...(input.paymentResponseHeader
|
|
251
|
+
? { "X-PAYMENT-RESPONSE": input.paymentResponseHeader }
|
|
252
|
+
: {}),
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/** The distinct reasons of the withheld runs, for the response header. */
|
|
257
|
+
function withheldReasons(withheld) {
|
|
258
|
+
return [...new Set(withheld.map((w) => w.reason))].join(",");
|
|
49
259
|
}
|
|
50
260
|
function methodNotAllowed() {
|
|
51
261
|
return errorResponse(405, "METHOD_NOT_ALLOWED", "Method not allowed");
|
|
@@ -53,17 +263,86 @@ function methodNotAllowed() {
|
|
|
53
263
|
function notFound() {
|
|
54
264
|
return errorResponse(404, "NOT_FOUND", "Not found");
|
|
55
265
|
}
|
|
56
|
-
async function withApiErrors(handler) {
|
|
266
|
+
async function withApiErrors(handler, context) {
|
|
57
267
|
try {
|
|
58
|
-
|
|
268
|
+
const response = await handler();
|
|
269
|
+
// A handled 4xx that means "the index and the disk disagree" is an
|
|
270
|
+
// operator-facing fault even though it is not a 500 — log it once, here,
|
|
271
|
+
// rather than at the contract that cannot see the route.
|
|
272
|
+
if (response.status === 404 && context) {
|
|
273
|
+
await logMissingDataFile(response, context);
|
|
274
|
+
}
|
|
275
|
+
return response;
|
|
59
276
|
}
|
|
60
277
|
catch (err) {
|
|
61
278
|
if (err instanceof ProtocolError) {
|
|
62
279
|
return protocolErrorResponse(err);
|
|
63
280
|
}
|
|
281
|
+
// A durable step refused by the legacy-write seal (the account switched,
|
|
282
|
+
// or its mode is not known) after the route's early check passed. The
|
|
283
|
+
// answer is the same 426 or 503 the early check gives, never a 500.
|
|
284
|
+
if (err instanceof LegacyWriteRefusedError) {
|
|
285
|
+
return err.response;
|
|
286
|
+
}
|
|
287
|
+
if (context) {
|
|
288
|
+
context.logger?.error?.({
|
|
289
|
+
route: context.route,
|
|
290
|
+
requestId: context.requestId ?? crypto.randomUUID(),
|
|
291
|
+
errorCode: "INTERNAL_ERROR",
|
|
292
|
+
...stripUndefined(context.detail),
|
|
293
|
+
err: describeError(err),
|
|
294
|
+
}, "Unhandled error in personal server API");
|
|
295
|
+
}
|
|
64
296
|
return errorResponse(500, "INTERNAL_ERROR", "Internal server error");
|
|
65
297
|
}
|
|
66
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* The `DATA_FILE_MISSING` 404 the read contract produces, logged at the one
|
|
301
|
+
* layer that knows which route served it. Peeks at a clone so the response
|
|
302
|
+
* body stays readable by the caller.
|
|
303
|
+
*/
|
|
304
|
+
async function logMissingDataFile(response, context) {
|
|
305
|
+
if (!context.logger?.error)
|
|
306
|
+
return;
|
|
307
|
+
try {
|
|
308
|
+
const body = await response.clone().json();
|
|
309
|
+
if (typeof body !== "object" ||
|
|
310
|
+
body === null ||
|
|
311
|
+
body.error !== "DATA_FILE_MISSING") {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
context.logger.error({
|
|
315
|
+
route: context.route,
|
|
316
|
+
requestId: context.requestId ?? crypto.randomUUID(),
|
|
317
|
+
errorCode: "DATA_FILE_MISSING",
|
|
318
|
+
...stripUndefined(context.detail),
|
|
319
|
+
}, "Indexed data file is missing on disk");
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
// A diagnostic log must not change the response sent to the caller.
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* An error rendered for a log line — name, message and stack only. Never the
|
|
327
|
+
* whole object: a thrown error can carry a request, a config or a token on an
|
|
328
|
+
* arbitrary property, and a structured logger would serialize all of it.
|
|
329
|
+
*/
|
|
330
|
+
function describeError(err) {
|
|
331
|
+
if (err instanceof Error) {
|
|
332
|
+
return {
|
|
333
|
+
name: err.name,
|
|
334
|
+
message: err.message,
|
|
335
|
+
...("code" in err && { code: err.code }),
|
|
336
|
+
stack: err.stack,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
return { message: String(err) };
|
|
340
|
+
}
|
|
341
|
+
function stripUndefined(detail) {
|
|
342
|
+
if (!detail)
|
|
343
|
+
return {};
|
|
344
|
+
return Object.fromEntries(Object.entries(detail).filter((pair) => pair[1] !== undefined));
|
|
345
|
+
}
|
|
67
346
|
function normalizeLimit(value, fallback) {
|
|
68
347
|
if (value === null)
|
|
69
348
|
return fallback;
|
|
@@ -95,6 +374,144 @@ export function selectedGrantId(request, url) {
|
|
|
95
374
|
request.headers.get("x-ps-grant-id") ??
|
|
96
375
|
undefined);
|
|
97
376
|
}
|
|
377
|
+
function listAuthCovers(listAuth, scope) {
|
|
378
|
+
return (!isSystemScope(scope) &&
|
|
379
|
+
scopeCoveredByGrant(scope, [...listAuth.grantedScopes]));
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Whether the app reading is the data owner's own app, which is exempt from
|
|
383
|
+
* the read fee. `false` when no Account authority is configured or the read
|
|
384
|
+
* is owner-signalled; a `Response` (503) when eligibility cannot be
|
|
385
|
+
* verified, so a read is never served free on missing evidence.
|
|
386
|
+
*/
|
|
387
|
+
async function ownAppReadStatus(deps, authResult) {
|
|
388
|
+
const isOwnerSignal = authResult?.grantId === "owner" || authResult?.grantId === "policy-bypass";
|
|
389
|
+
const builder = authResult?.builder;
|
|
390
|
+
if (!deps.paymentEnabled ||
|
|
391
|
+
isOwnerSignal ||
|
|
392
|
+
!authResult?.grantId ||
|
|
393
|
+
!builder ||
|
|
394
|
+
!deps.ownAppAccountUrl) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
const unavailable = () => errorResponse(503, "OWN_APP_ELIGIBILITY_UNAVAILABLE", "Own-app fee eligibility could not be verified");
|
|
398
|
+
if (!deps.serverOwner || !deps.gatewayConfig)
|
|
399
|
+
return unavailable();
|
|
400
|
+
try {
|
|
401
|
+
return await isOwnAppRead({
|
|
402
|
+
accountUrl: deps.ownAppAccountUrl,
|
|
403
|
+
appAddress: builder,
|
|
404
|
+
dataOwner: deps.serverOwner,
|
|
405
|
+
chainId: deps.gatewayConfig.chainId,
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
return unavailable();
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Whether a read is charged, and with what. Owner-exempt reads (the grantId
|
|
414
|
+
* sentinels "owner" / "policy-bypass") are never charged: there is no
|
|
415
|
+
* payable op to attach the payment to. The grantId paid against is the one
|
|
416
|
+
* verifyDataReadPolicy resolved from the Web3Signed payload (authoritative
|
|
417
|
+
* source), not the URL / header hint, which may be absent when the payload
|
|
418
|
+
* carries it. `null` = served free.
|
|
419
|
+
*/
|
|
420
|
+
function readCharge(deps, scope, authResult, ownAppRead) {
|
|
421
|
+
const isOwnerSignal = authResult?.grantId === "owner" || authResult?.grantId === "policy-bypass";
|
|
422
|
+
const builder = authResult?.builder;
|
|
423
|
+
const resolvedGrantId = !isOwnerSignal && authResult?.grantId ? authResult.grantId : undefined;
|
|
424
|
+
const willCharge = Boolean(deps.paymentEnabled &&
|
|
425
|
+
!isOwnerSignal &&
|
|
426
|
+
!ownAppRead &&
|
|
427
|
+
typeof builder === "string" &&
|
|
428
|
+
builder.startsWith("0x") &&
|
|
429
|
+
resolvedGrantId &&
|
|
430
|
+
deps.gateway &&
|
|
431
|
+
deps.gatewayConfig &&
|
|
432
|
+
deps.gatewayUrl);
|
|
433
|
+
// Diagnostic: makes it explicit why a read is/isn't charged. x402 has
|
|
434
|
+
// many "served free" branches (owner read, payment disabled, missing
|
|
435
|
+
// gateway deps); this surfaces the deciding inputs.
|
|
436
|
+
//
|
|
437
|
+
// Routing: when a logger is wired (the Node server always provides one),
|
|
438
|
+
// log the full detail through it at debug level so the operator's level
|
|
439
|
+
// controls + redaction apply and access metadata (scope/grantId/builder)
|
|
440
|
+
// doesn't unconditionally hit stdout. The browser PS-Lite runtime wires
|
|
441
|
+
// no logger; there we fall back to console but log ONLY the non-identifying
|
|
442
|
+
// decision booleans — never scope/grantId/builder.
|
|
443
|
+
if (deps.logger?.debug) {
|
|
444
|
+
deps.logger.debug({
|
|
445
|
+
scope,
|
|
446
|
+
grantId: authResult?.grantId,
|
|
447
|
+
isOwnerSignal,
|
|
448
|
+
builder,
|
|
449
|
+
resolvedGrantId,
|
|
450
|
+
paymentEnabled: Boolean(deps.paymentEnabled),
|
|
451
|
+
hasGateway: Boolean(deps.gateway),
|
|
452
|
+
hasGatewayConfig: Boolean(deps.gatewayConfig),
|
|
453
|
+
hasGatewayUrl: Boolean(deps.gatewayUrl),
|
|
454
|
+
willCharge,
|
|
455
|
+
}, "[x402-gate] read");
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
console.info("[x402-gate] read", {
|
|
459
|
+
isOwnerSignal,
|
|
460
|
+
paymentEnabled: Boolean(deps.paymentEnabled),
|
|
461
|
+
hasGateway: Boolean(deps.gateway),
|
|
462
|
+
hasGatewayConfig: Boolean(deps.gatewayConfig),
|
|
463
|
+
hasGatewayUrl: Boolean(deps.gatewayUrl),
|
|
464
|
+
willCharge,
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
if (!willCharge ||
|
|
468
|
+
!resolvedGrantId ||
|
|
469
|
+
!deps.gateway ||
|
|
470
|
+
!deps.gatewayConfig ||
|
|
471
|
+
!deps.gatewayUrl) {
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
return {
|
|
475
|
+
grantId: resolvedGrantId,
|
|
476
|
+
builder: builder,
|
|
477
|
+
gateway: deps.gateway,
|
|
478
|
+
gatewayConfig: deps.gatewayConfig,
|
|
479
|
+
gatewayUrl: deps.gatewayUrl,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* The X402 step of a charged read: a response to return instead of the
|
|
484
|
+
* body (a fresh 402 challenge, or the gateway's error relayed verbatim so
|
|
485
|
+
* the builder can dispatch on it), or the X-PAYMENT-RESPONSE value to send
|
|
486
|
+
* with the body once the gateway accepted the payment.
|
|
487
|
+
*/
|
|
488
|
+
async function payForRead(deps, request, charge, read) {
|
|
489
|
+
const x402Result = await handleX402Cycle({
|
|
490
|
+
deps,
|
|
491
|
+
request,
|
|
492
|
+
...read,
|
|
493
|
+
...charge,
|
|
494
|
+
});
|
|
495
|
+
if (x402Result.kind === "challenge") {
|
|
496
|
+
return {
|
|
497
|
+
kind: "refused",
|
|
498
|
+
response: jsonResponse(x402Result.body, { status: 402 }),
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
if (x402Result.kind === "gateway-error") {
|
|
502
|
+
return {
|
|
503
|
+
kind: "refused",
|
|
504
|
+
response: jsonResponse(x402Result.body, { status: x402Result.status }),
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
// The gateway's success body goes back to the builder in
|
|
508
|
+
// X-PAYMENT-RESPONSE (canonical X402 convention) so callers can see
|
|
509
|
+
// breakdown / paidAt / paymentNonce without a second gateway round-trip.
|
|
510
|
+
return {
|
|
511
|
+
kind: "paid",
|
|
512
|
+
paymentResponseHeader: encodePaymentResponseHeader(x402Result.payResponse),
|
|
513
|
+
};
|
|
514
|
+
}
|
|
98
515
|
/**
|
|
99
516
|
* Run the X402 dispatch for one read:
|
|
100
517
|
*
|
|
@@ -131,19 +548,30 @@ export async function handleX402Cycle(input) {
|
|
|
131
548
|
};
|
|
132
549
|
}
|
|
133
550
|
// 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,
|
|
551
|
+
// been registered with DPv2 yet. A served stream head is registered: it
|
|
552
|
+
// was listed from the registry.
|
|
553
|
+
const entryRow = input.servedEntry
|
|
554
|
+
? undefined
|
|
555
|
+
: deps.storage.findEntry({
|
|
143
556
|
scope,
|
|
144
|
-
|
|
557
|
+
fileId: input.fileIdParam,
|
|
558
|
+
at: input.atParam,
|
|
559
|
+
});
|
|
560
|
+
const entryForChallenge = input.servedEntry
|
|
561
|
+
? {
|
|
562
|
+
dataPointId: deps.serverOwner
|
|
563
|
+
? computeDataPointId(deps.serverOwner, input.servedEntry.scope)
|
|
564
|
+
: null,
|
|
565
|
+
scope: input.servedEntry.scope,
|
|
566
|
+
version: input.servedEntry.version,
|
|
145
567
|
}
|
|
146
|
-
:
|
|
568
|
+
: entryRow
|
|
569
|
+
? {
|
|
570
|
+
dataPointId: entryRow.dataPointId,
|
|
571
|
+
scope,
|
|
572
|
+
version: entryRow.version,
|
|
573
|
+
}
|
|
574
|
+
: undefined;
|
|
147
575
|
// `grant` is narrowed to non-null above, but that narrowing is not carried
|
|
148
576
|
// into this closure (vana-sdk 3.14.0 made getGrant return `... | null`), so
|
|
149
577
|
// capture the guaranteed-present value via a typed alias for the closure.
|
|
@@ -257,10 +685,102 @@ export async function handleX402Cycle(input) {
|
|
|
257
685
|
}
|
|
258
686
|
return { kind: "gateway-error", status: gatewayRes.status, body: errorBody };
|
|
259
687
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
688
|
+
const pendingIngestStamps = new WeakMap();
|
|
689
|
+
function reserveIngestStamp(now, storage, scope) {
|
|
690
|
+
// Bound allocation to 60 millisecond slots per scope, anchored to wall time.
|
|
691
|
+
// Failed requests release their slot; neither failures nor other scopes
|
|
692
|
+
// advance this scope's clock. The durable head protects restart/clock rollback.
|
|
693
|
+
const wall = now().getTime();
|
|
694
|
+
const latest = Date.parse(storage.findEntry({ scope })?.collectedAt ?? "");
|
|
695
|
+
let scopes = pendingIngestStamps.get(storage);
|
|
696
|
+
const pending = scopes?.get(scope) ?? new Set();
|
|
697
|
+
for (let stamp = wall; stamp < wall + 60; stamp += 1) {
|
|
698
|
+
if ((Number.isFinite(latest) && stamp <= latest) || pending.has(stamp)) {
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
if (!scopes) {
|
|
702
|
+
scopes = new Map();
|
|
703
|
+
pendingIngestStamps.set(storage, scopes);
|
|
704
|
+
}
|
|
705
|
+
scopes.set(scope, pending);
|
|
706
|
+
pending.add(stamp);
|
|
707
|
+
const reservations = scopes;
|
|
708
|
+
return {
|
|
709
|
+
collectedAt: new Date(stamp).toISOString(),
|
|
710
|
+
release() {
|
|
711
|
+
pending.delete(stamp);
|
|
712
|
+
if (pending.size === 0)
|
|
713
|
+
reservations.delete(scope);
|
|
714
|
+
},
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
return undefined;
|
|
718
|
+
}
|
|
719
|
+
function parseLegacyPrecondition(request) {
|
|
720
|
+
const none = request.headers.get("if-none-match");
|
|
721
|
+
const match = request.headers.get("if-match");
|
|
722
|
+
if (none !== null && match !== null) {
|
|
723
|
+
return errorResponse(400, "INVALID_PRECONDITION", "Supply only one precondition");
|
|
724
|
+
}
|
|
725
|
+
if (none !== null) {
|
|
726
|
+
return none === "*"
|
|
727
|
+
? { kind: "none" }
|
|
728
|
+
: errorResponse(400, "INVALID_PRECONDITION", "If-None-Match must be *");
|
|
729
|
+
}
|
|
730
|
+
if (match !== null) {
|
|
731
|
+
const parsed = /^"([1-9]\d*)"$/.exec(match);
|
|
732
|
+
const version = parsed ? Number(parsed[1]) : NaN;
|
|
733
|
+
return Number.isSafeInteger(version)
|
|
734
|
+
? { kind: "match", version }
|
|
735
|
+
: errorResponse(400, "INVALID_PRECONDITION", "If-Match must be a quoted positive version");
|
|
736
|
+
}
|
|
737
|
+
return undefined;
|
|
738
|
+
}
|
|
739
|
+
function parseProducerHeader(request) {
|
|
740
|
+
const producer = request.headers.get("vana-producer");
|
|
741
|
+
const encodedProvenance = request.headers.get("vana-producer-provenance") ?? undefined;
|
|
742
|
+
if (producer === null && !encodedProvenance)
|
|
743
|
+
return {};
|
|
744
|
+
if (producer !== "pdpp-projector" && producer !== "pdpp-import-projection") {
|
|
745
|
+
return errorResponse(400, "INVALID_PRODUCER", "Vana-Producer is unrecognized or missing");
|
|
746
|
+
}
|
|
747
|
+
if (encodedProvenance &&
|
|
748
|
+
(encodedProvenance.length > 8192 ||
|
|
749
|
+
!/^[A-Za-z0-9_-]+$/.test(encodedProvenance))) {
|
|
750
|
+
return errorResponse(400, "INVALID_PROVENANCE", "Vana-Producer-Provenance is malformed");
|
|
751
|
+
}
|
|
752
|
+
return { producer, encodedProvenance };
|
|
753
|
+
}
|
|
754
|
+
async function parseProducerProvenance(encoded, body) {
|
|
755
|
+
if (!encoded)
|
|
756
|
+
return undefined;
|
|
757
|
+
try {
|
|
758
|
+
const value = JSON.parse(new TextDecoder().decode(Uint8Array.from(atob(encoded.replace(/-/g, "+").replace(/_/g, "/")), (char) => char.charCodeAt(0))));
|
|
759
|
+
if (!value ||
|
|
760
|
+
typeof value !== "object" ||
|
|
761
|
+
typeof value.projector_version !== "string" ||
|
|
762
|
+
!value.projector_version ||
|
|
763
|
+
typeof value.declaration_digest !== "string" ||
|
|
764
|
+
!value.declaration_digest ||
|
|
765
|
+
!Array.isArray(value.inputs) ||
|
|
766
|
+
!value.inputs.every((input) => input &&
|
|
767
|
+
typeof input.stream === "string" &&
|
|
768
|
+
input.stream &&
|
|
769
|
+
typeof input.changes_since_token === "string" &&
|
|
770
|
+
input.changes_since_token) ||
|
|
771
|
+
typeof value.payload_sha256 !== "string" ||
|
|
772
|
+
!/^(?:0x)?[0-9a-fA-F]{64}$/.test(value.payload_sha256)) {
|
|
773
|
+
return errorResponse(400, "INVALID_PROVENANCE", "Producer provenance has invalid fields");
|
|
774
|
+
}
|
|
775
|
+
const actual = (await sha256Hex(canonicalJsonBytes(body))).slice(2);
|
|
776
|
+
if (actual !== value.payload_sha256.replace(/^0x/, "").toLowerCase()) {
|
|
777
|
+
return errorResponse(400, "PAYLOAD_HASH_MISMATCH", "Provenance payload_sha256 does not match the JSON body");
|
|
778
|
+
}
|
|
779
|
+
return value;
|
|
780
|
+
}
|
|
781
|
+
catch {
|
|
782
|
+
return errorResponse(400, "INVALID_PROVENANCE", "Vana-Producer-Provenance is not base64url JSON");
|
|
783
|
+
}
|
|
264
784
|
}
|
|
265
785
|
/**
|
|
266
786
|
* The deletion that applies to a read of `scope`, or null when the read may
|
|
@@ -276,15 +796,26 @@ function collectedAt(now) {
|
|
|
276
796
|
* Gateway unreachability never fails the read: the tracker answers from its
|
|
277
797
|
* last known state, which is the documented offline behaviour.
|
|
278
798
|
*/
|
|
279
|
-
export async function resolveReadDeletion(deps, scope, entry) {
|
|
799
|
+
export async function resolveReadDeletion(deps, scope, entry, body = "file", gatewayTimeoutMs) {
|
|
280
800
|
if (!deps.scopeDeletions)
|
|
281
801
|
return null;
|
|
282
802
|
const verdict = await deps.scopeDeletions.resolve(scope, {
|
|
283
803
|
consultGateway: entry ? "if-stale" : "always",
|
|
804
|
+
...(gatewayTimeoutMs === undefined ? {} : { gatewayTimeoutMs }),
|
|
284
805
|
});
|
|
285
|
-
|
|
806
|
+
// A live DPv2 file cannot establish that a different canonical body was
|
|
807
|
+
// re-added. Keep this refusal until a genuine canonical re-add seam exists.
|
|
808
|
+
const tombstone = body === "canonical"
|
|
809
|
+
? (deps.scopeDeletions.deletionHistory?.get(scope) ??
|
|
810
|
+
(verdict.deleted ? verdict : null))
|
|
811
|
+
: verdict.deleted
|
|
812
|
+
? verdict
|
|
813
|
+
: null;
|
|
814
|
+
if (!tombstone)
|
|
286
815
|
return null;
|
|
287
|
-
if (
|
|
816
|
+
if (body === "file" &&
|
|
817
|
+
entry &&
|
|
818
|
+
!isEntryCoveredByTombstone(entry, tombstone)) {
|
|
288
819
|
return null;
|
|
289
820
|
}
|
|
290
821
|
return {
|
|
@@ -292,7 +823,7 @@ export async function resolveReadDeletion(deps, scope, entry) {
|
|
|
292
823
|
dataPointId: deps.serverOwner
|
|
293
824
|
? computeDataPointId(deps.serverOwner, scope)
|
|
294
825
|
: null,
|
|
295
|
-
deletedAt:
|
|
826
|
+
deletedAt: tombstone.deletedAt,
|
|
296
827
|
};
|
|
297
828
|
}
|
|
298
829
|
/**
|
|
@@ -300,8 +831,8 @@ export async function resolveReadDeletion(deps, scope, entry) {
|
|
|
300
831
|
* served. Call it before any payment step: a builder must never be charged
|
|
301
832
|
* for a scope the owner deleted.
|
|
302
833
|
*/
|
|
303
|
-
export async function assertScopeNotDeleted(deps, scope, entry) {
|
|
304
|
-
const deletion = await resolveReadDeletion(deps, scope, entry);
|
|
834
|
+
export async function assertScopeNotDeleted(deps, scope, entry, body = "file") {
|
|
835
|
+
const deletion = await resolveReadDeletion(deps, scope, entry, body);
|
|
305
836
|
if (deletion)
|
|
306
837
|
throw new DataDeletedError(deletion);
|
|
307
838
|
}
|
|
@@ -315,6 +846,83 @@ function discoveryVisibility(deps) {
|
|
|
315
846
|
return undefined;
|
|
316
847
|
return async (scope, entry) => (await resolveReadDeletion(deps, scope, entry)) === null;
|
|
317
848
|
}
|
|
849
|
+
/**
|
|
850
|
+
* Discovery filter for the scope listing: the deletion filter, and a
|
|
851
|
+
* canonical scope is listed only when the view could serve it.
|
|
852
|
+
*/
|
|
853
|
+
function listingVisibility(deps, deadlineAtMs) {
|
|
854
|
+
const deletion = deps.scopeDeletions
|
|
855
|
+
? async (scope, entry) => (await resolveReadDeletion(deps, scope, entry, "file", Math.max(0, deadlineAtMs - Date.now()))) === null
|
|
856
|
+
: undefined;
|
|
857
|
+
const view = deps.legacyScopeView;
|
|
858
|
+
if (!view)
|
|
859
|
+
return deletion;
|
|
860
|
+
return async (scope, entry) => {
|
|
861
|
+
const listing = view.listingFor(scope);
|
|
862
|
+
if (listing.kind === "refused")
|
|
863
|
+
return false;
|
|
864
|
+
const canonicalOwned = deletionHistoryOf(listing) === "canonical";
|
|
865
|
+
// A file's re-add marker cannot revive the canonical body this row
|
|
866
|
+
// describes. Canonical re-adds have no registered version yet.
|
|
867
|
+
return ((await resolveReadDeletion(deps, scope, canonicalOwned ? undefined : entry, canonicalOwned ? "canonical" : "file", Math.max(0, deadlineAtMs - Date.now()))) === null);
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Bound scopes served only from canonical records, for the listing: no
|
|
872
|
+
* legacy write is needed to discover them. A gateway deletion hides them
|
|
873
|
+
* the way it hides a stored scope.
|
|
874
|
+
*/
|
|
875
|
+
function canonicalOnlyScopes(deps, deadlineAtMs) {
|
|
876
|
+
const view = deps.legacyScopeView;
|
|
877
|
+
if (!view)
|
|
878
|
+
return undefined;
|
|
879
|
+
return async (scopePrefix, stored) => {
|
|
880
|
+
const listed = [];
|
|
881
|
+
for (const { scope, collectedAt } of view.listCanonicalScopes(scopePrefix)) {
|
|
882
|
+
if (stored.has(scope))
|
|
883
|
+
continue;
|
|
884
|
+
if ((await resolveReadDeletion(deps, scope, undefined, "canonical", Math.max(0, deadlineAtMs - Date.now()))) !== null) {
|
|
885
|
+
continue;
|
|
886
|
+
}
|
|
887
|
+
// No legacy version exists to count or to ask `/versions` for.
|
|
888
|
+
listed.push({ scope, latestCollectedAt: collectedAt, versionCount: 0 });
|
|
889
|
+
}
|
|
890
|
+
return listed;
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* A canonical scope's listing row carries the canonical freshness. The
|
|
895
|
+
* legacy head's size and block readiness describe a file the latest read
|
|
896
|
+
* does not serve, so they are dropped.
|
|
897
|
+
*/
|
|
898
|
+
function withCanonicalListing(deps, summary) {
|
|
899
|
+
const listing = deps.legacyScopeView?.listingFor(summary.scope);
|
|
900
|
+
if (listing?.kind !== "canonical")
|
|
901
|
+
return summary;
|
|
902
|
+
return {
|
|
903
|
+
scope: summary.scope,
|
|
904
|
+
latestCollectedAt: listing.collectedAt,
|
|
905
|
+
versionCount: summary.versionCount,
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* 409 when the owner must choose between connections, 503 otherwise. The
|
|
910
|
+
* body names the reason and stream names only: no instance id, no row data,
|
|
911
|
+
* no legacy content.
|
|
912
|
+
*/
|
|
913
|
+
function legacyViewRefusalResponse(scope, refusal) {
|
|
914
|
+
const status = refusal.reason === "ambiguous_connection" ? 409 : 503;
|
|
915
|
+
return jsonResponse({
|
|
916
|
+
error: "CANONICAL_VIEW_UNAVAILABLE",
|
|
917
|
+
message: `The latest data for scope "${scope}" cannot be served from the owner's connector records (${refusal.reason}).`,
|
|
918
|
+
status: refusal.status,
|
|
919
|
+
reason: refusal.reason,
|
|
920
|
+
...("detail" in refusal ? { detail: refusal.detail } : {}),
|
|
921
|
+
...("streams" in refusal ? { streams: refusal.streams } : {}),
|
|
922
|
+
...("stream" in refusal ? { stream: refusal.stream } : {}),
|
|
923
|
+
...("candidates" in refusal ? { candidates: refusal.candidates } : {}),
|
|
924
|
+
}, { status });
|
|
925
|
+
}
|
|
318
926
|
/**
|
|
319
927
|
* The causal marker a fresh ingest carries: the tombstone version this
|
|
320
928
|
* replica currently knows for the scope, if any, so the new entry is a
|
|
@@ -334,12 +942,11 @@ async function ingestTombstoneMarker(deps, scope) {
|
|
|
334
942
|
}
|
|
335
943
|
// The delete worker wants a full Logger; the API logger is all-optional.
|
|
336
944
|
function apiLoggerAsLogger(logger) {
|
|
337
|
-
const noop = () => undefined;
|
|
338
945
|
return {
|
|
339
|
-
debug: (payload, message) =>
|
|
340
|
-
info: (payload, message) =>
|
|
341
|
-
warn: (payload, message) =>
|
|
342
|
-
error: (payload, message) =>
|
|
946
|
+
debug: (payload, message) => logger?.debug?.(payload, message ?? ""),
|
|
947
|
+
info: (payload, message) => logger?.info?.(payload, message ?? ""),
|
|
948
|
+
warn: (payload, message) => logger?.warn?.(payload, message ?? ""),
|
|
949
|
+
error: (payload, message) => logger?.error?.(payload, message ?? ""),
|
|
343
950
|
};
|
|
344
951
|
}
|
|
345
952
|
function notifyDataWritten(deps, event) {
|
|
@@ -355,6 +962,63 @@ function notifyDataWritten(deps, event) {
|
|
|
355
962
|
}, "onDataWritten hook failed; record already stored");
|
|
356
963
|
}
|
|
357
964
|
}
|
|
965
|
+
/**
|
|
966
|
+
* Offer a just-ingested envelope to the PDPP importer.
|
|
967
|
+
*
|
|
968
|
+
* The local-ingest twin of the download worker's `importIntoPdpp`, and
|
|
969
|
+
* deliberately the same shape: same `ImportableEnvelope`, same total handling
|
|
970
|
+
* of every outcome, same permanent-vs-transient logging split. Keeping the
|
|
971
|
+
* two symmetric is the point — a `$pdpp` envelope must mean the same thing
|
|
972
|
+
* and reach the same store whether the gateway handed it over or a local
|
|
973
|
+
* producer POSTed it, otherwise "imported" would depend on which door the
|
|
974
|
+
* bytes came through.
|
|
975
|
+
*
|
|
976
|
+
* `skipped` is the ordinary legacy case (no `$pdpp` block) and stays silent.
|
|
977
|
+
* A rejection is a WARNING, not an error: it means the producer sent
|
|
978
|
+
* something this deployment could not verify — actionable, but not a failure
|
|
979
|
+
* of the write, which has already committed.
|
|
980
|
+
*/
|
|
981
|
+
async function importIngestedIntoPdpp(deps, envelope) {
|
|
982
|
+
if (!deps.pdppImporter)
|
|
983
|
+
return;
|
|
984
|
+
try {
|
|
985
|
+
const outcome = await deps.pdppImporter.importEnvelope(envelope);
|
|
986
|
+
if (outcome.status === "rejected") {
|
|
987
|
+
const permanent = isPermanentRejection(outcome.rejection);
|
|
988
|
+
deps.logger?.warn?.({
|
|
989
|
+
scope: envelope.scope,
|
|
990
|
+
collectedAt: envelope.collectedAt,
|
|
991
|
+
code: outcome.rejection.code,
|
|
992
|
+
message: outcome.rejection.message,
|
|
993
|
+
permanent,
|
|
994
|
+
}, permanent
|
|
995
|
+
? "Ingested data point was refused by the PDPP importer and will not be retried"
|
|
996
|
+
: "PDPP import unavailable for this ingested data point");
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
catch (err) {
|
|
1000
|
+
// A throwing importer is infrastructure failing, not the envelope being
|
|
1001
|
+
// wrong. The record is stored and indexed already, so this must never
|
|
1002
|
+
// turn a committed write into a 500.
|
|
1003
|
+
deps.logger?.warn?.({
|
|
1004
|
+
scope: envelope.scope,
|
|
1005
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1006
|
+
}, "PDPP import threw on ingest; record already stored and indexed");
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
function notifyDataRead(deps, event) {
|
|
1010
|
+
if (!deps.onDataRead)
|
|
1011
|
+
return;
|
|
1012
|
+
try {
|
|
1013
|
+
deps.onDataRead(event);
|
|
1014
|
+
}
|
|
1015
|
+
catch (err) {
|
|
1016
|
+
deps.logger?.warn?.({
|
|
1017
|
+
scope: event.scope,
|
|
1018
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1019
|
+
}, "onDataRead hook failed; the read is unaffected");
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
358
1022
|
function notifyNewData(syncManager) {
|
|
359
1023
|
if (!syncManager)
|
|
360
1024
|
return;
|
|
@@ -377,12 +1041,26 @@ function warnReadFulfillmentReporterFailed(deps, event, err) {
|
|
|
377
1041
|
}, "Read fulfillment reporter failed");
|
|
378
1042
|
}
|
|
379
1043
|
export function reportPersonalServerReadFulfillment(deps, event) {
|
|
380
|
-
|
|
381
|
-
|
|
1044
|
+
const reporter = deps.readFulfillmentReporter;
|
|
1045
|
+
if (!reporter || !shouldReportReadFulfillment(event.grantId)) {
|
|
382
1046
|
return;
|
|
383
1047
|
}
|
|
1048
|
+
fireReadReport(deps, event, reporter.report.bind(reporter));
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Denials mirror fulfillments but skip the grant filter: a refused read has no
|
|
1052
|
+
* grant to filter on, and the record is what proves the refusal happened.
|
|
1053
|
+
*/
|
|
1054
|
+
export function reportPersonalServerReadDenial(deps, event) {
|
|
1055
|
+
const reporter = deps.readFulfillmentReporter;
|
|
1056
|
+
if (!reporter?.reportDenied)
|
|
1057
|
+
return;
|
|
1058
|
+
fireReadReport(deps, event, reporter.reportDenied.bind(reporter));
|
|
1059
|
+
}
|
|
1060
|
+
/** Fire-and-forget: reporting must never fail or delay the read it describes. */
|
|
1061
|
+
function fireReadReport(deps, event, send) {
|
|
384
1062
|
try {
|
|
385
|
-
void Promise.resolve(
|
|
1063
|
+
void Promise.resolve(send(event)).catch((err) => warnReadFulfillmentReporterFailed(deps, event, err));
|
|
386
1064
|
}
|
|
387
1065
|
catch (err) {
|
|
388
1066
|
warnReadFulfillmentReporterFailed(deps, event, err);
|
|
@@ -483,33 +1161,550 @@ export function redactEnvelopeForGrantee(envelope) {
|
|
|
483
1161
|
}
|
|
484
1162
|
return { ...envelope, data };
|
|
485
1163
|
}
|
|
1164
|
+
export { redactJsonEnvelopeBytesForGrantee } from "./raw-envelope.js";
|
|
1165
|
+
export { ACCOUNT_MODE_RETRY_AFTER_SECONDS, ACCOUNT_MODE_UNKNOWN_CODE, ACCOUNT_MODE_UNKNOWN_STATUS, accountModeUnknownResponse, accountStorageModeFor, selectAccountStorageMode, } from "./account-storage-mode.js";
|
|
1166
|
+
export { USE_CONNECTOR_DELETE_CODE, USE_CONNECTOR_DELETE_MESSAGE, USE_CONNECTOR_DELETE_STATUS, switchedDeleteRefusalResponse, } from "./switched-delete-refusal.js";
|
|
1167
|
+
export { STREAM_SYNC_CLIENT_HEADER, UPDATE_REQUIRED_CODE, UPDATE_REQUIRED_MESSAGE, UPDATE_REQUIRED_STATUS, LegacyWriteRefusedError, legacyWriteRefusedErrorFor, refuseLegacyWrite, updateRequiredResponse, } from "./legacy-write-gate.js";
|
|
1168
|
+
export { handleOwnerConnectorDelete, ownerConnectorRefusal, } from "./owner-connector-delete.js";
|
|
1169
|
+
/**
|
|
1170
|
+
* `/v1/data/:scope/uploads...`: an owner writes one new version of a scope as
|
|
1171
|
+
* a sequence of record batches. The protocol and its guarantees are in
|
|
1172
|
+
* `scope-uploads.ts`; this adds HTTP, owner auth and the post-commit hooks.
|
|
1173
|
+
*/
|
|
1174
|
+
async function handleScopeUploadRequest(request, deps, parts, prepared, mode = deps.accountStorageMode?.read() ??
|
|
1175
|
+
deps.accountMode?.read(deps.serverOwner) ??
|
|
1176
|
+
"unknown") {
|
|
1177
|
+
const route = (() => {
|
|
1178
|
+
if (parts.length === 2)
|
|
1179
|
+
return { kind: "begin", method: "POST" };
|
|
1180
|
+
if (parts.length === 3)
|
|
1181
|
+
return { kind: "abort", method: "DELETE" };
|
|
1182
|
+
if (parts.length === 4 && parts[3] === "commit")
|
|
1183
|
+
return { kind: "commit", method: "POST" };
|
|
1184
|
+
if (parts.length === 5 && parts[3] === "batches")
|
|
1185
|
+
return { kind: "append", method: "PUT" };
|
|
1186
|
+
return undefined;
|
|
1187
|
+
})();
|
|
1188
|
+
if (!route) {
|
|
1189
|
+
return errorResponse(404, "NOT_FOUND", "Unknown upload route");
|
|
1190
|
+
}
|
|
1191
|
+
if (request.method !== route.method)
|
|
1192
|
+
return methodNotAllowed();
|
|
1193
|
+
await deps.auth.authorizeOwner(request);
|
|
1194
|
+
// A switched account cannot mutate legacy import state, including abort.
|
|
1195
|
+
const modeRefusal = legacyMutationRefusal(mode);
|
|
1196
|
+
if (modeRefusal)
|
|
1197
|
+
return modeRefusal;
|
|
1198
|
+
if (route.kind !== "abort") {
|
|
1199
|
+
const refusal = refuseLegacyWrite(deps.accountStorageMode);
|
|
1200
|
+
if (refusal)
|
|
1201
|
+
return refusal;
|
|
1202
|
+
}
|
|
1203
|
+
const scopeResult = parseDataScopeContract(decodePathPart(parts[0]));
|
|
1204
|
+
if (!scopeResult.ok)
|
|
1205
|
+
return contractErrorResponse(scopeResult);
|
|
1206
|
+
const scope = scopeResult.scope;
|
|
1207
|
+
const uploads = deps.scopeUploads;
|
|
1208
|
+
if (!uploads) {
|
|
1209
|
+
return errorResponse(501, "UPLOAD_UNSUPPORTED", "This server cannot stream a scope version");
|
|
1210
|
+
}
|
|
1211
|
+
const readBody = async () => {
|
|
1212
|
+
const text = await request.text();
|
|
1213
|
+
if (text.trim() === "")
|
|
1214
|
+
return {};
|
|
1215
|
+
try {
|
|
1216
|
+
return JSON.parse(text);
|
|
1217
|
+
}
|
|
1218
|
+
catch {
|
|
1219
|
+
throw new ScopeUploadError(400, "INVALID_UPLOAD", "Request body must be valid JSON");
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
try {
|
|
1223
|
+
switch (route.kind) {
|
|
1224
|
+
case "begin": {
|
|
1225
|
+
const body = await readBody();
|
|
1226
|
+
const stamp = reserveIngestStamp(deps.now ?? (() => new Date()), deps.storage, scope);
|
|
1227
|
+
if (!stamp) {
|
|
1228
|
+
return errorResponse(429, "INGEST_CAPACITY", "Too many writes for this scope; retry when the clock advances");
|
|
1229
|
+
}
|
|
1230
|
+
const begun = await uploads.begin({
|
|
1231
|
+
storage: deps.storage,
|
|
1232
|
+
scope,
|
|
1233
|
+
collectedAt: stamp.collectedAt,
|
|
1234
|
+
release: stamp.release,
|
|
1235
|
+
body,
|
|
1236
|
+
});
|
|
1237
|
+
return jsonResponse({ ...begun, scope, maxBatchBytes: uploads.maxBatchBytes }, { status: 201 });
|
|
1238
|
+
}
|
|
1239
|
+
case "append": {
|
|
1240
|
+
const seqText = decodePathPart(parts[4]);
|
|
1241
|
+
const input = {
|
|
1242
|
+
scope,
|
|
1243
|
+
uploadId: decodePathPart(parts[2]),
|
|
1244
|
+
seq: /^\d{1,9}$/.test(seqText) ? Number(seqText) : Number.NaN,
|
|
1245
|
+
};
|
|
1246
|
+
let appended;
|
|
1247
|
+
if (prepared) {
|
|
1248
|
+
if (!uploads.appendPrepared) {
|
|
1249
|
+
throw new ScopeUploadError(501, "UPLOAD_UNSUPPORTED", "This server cannot append prepared batches");
|
|
1250
|
+
}
|
|
1251
|
+
// Authenticate the small commitment on EVERY append, with the
|
|
1252
|
+
// existing owner gate. Bulk bytes never cross a Request boundary.
|
|
1253
|
+
const body = await readBody();
|
|
1254
|
+
if (body === null ||
|
|
1255
|
+
typeof body !== "object" ||
|
|
1256
|
+
Array.isArray(body) ||
|
|
1257
|
+
Object.keys(body).length !== 1 ||
|
|
1258
|
+
body.bodySha256 !==
|
|
1259
|
+
prepared.bodySha256) {
|
|
1260
|
+
throw new ScopeUploadError(400, "INVALID_UPLOAD", "Prepared batch commitment does not match");
|
|
1261
|
+
}
|
|
1262
|
+
appended = await uploads.appendPrepared({
|
|
1263
|
+
...input,
|
|
1264
|
+
batch: prepared,
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
else {
|
|
1268
|
+
appended = await uploads.append({
|
|
1269
|
+
...input,
|
|
1270
|
+
text: await request.text(),
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
return jsonResponse(appended, {
|
|
1274
|
+
status: appended.replay ? 200 : 201,
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
case "commit": {
|
|
1278
|
+
const body = await readBody();
|
|
1279
|
+
const committed = await uploads.commit({
|
|
1280
|
+
scope,
|
|
1281
|
+
uploadId: decodePathPart(parts[2]),
|
|
1282
|
+
body,
|
|
1283
|
+
afterTombstoneVersion: await ingestTombstoneMarker(deps, scope),
|
|
1284
|
+
});
|
|
1285
|
+
deps.logger?.info?.({
|
|
1286
|
+
scope,
|
|
1287
|
+
collectedAt: committed.collectedAt,
|
|
1288
|
+
path: committed.writeResult.relativePath,
|
|
1289
|
+
records: committed.records,
|
|
1290
|
+
}, "Streamed data file committed");
|
|
1291
|
+
// Block sidecars and the first-seen ledger are not built here: both
|
|
1292
|
+
// need the whole envelope in memory, which is what an upload avoids.
|
|
1293
|
+
// Both are caches: a scope with no block manifest is read whole, and
|
|
1294
|
+
// the owner's `/additions` read folds the version into the ledger.
|
|
1295
|
+
notifyNewData(deps.syncManager);
|
|
1296
|
+
notifyDataWritten(deps, { scope, collectedAt: committed.collectedAt });
|
|
1297
|
+
return jsonResponse({
|
|
1298
|
+
scope,
|
|
1299
|
+
collectedAt: committed.collectedAt,
|
|
1300
|
+
status: deps.syncManager ? "syncing" : "stored",
|
|
1301
|
+
records: committed.records,
|
|
1302
|
+
sizeBytes: committed.writeResult.sizeBytes,
|
|
1303
|
+
}, { status: 201 });
|
|
1304
|
+
}
|
|
1305
|
+
case "abort": {
|
|
1306
|
+
await uploads.abort({ scope, uploadId: decodePathPart(parts[2]) });
|
|
1307
|
+
return new Response(null, { status: 204 });
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
catch (err) {
|
|
1312
|
+
if (err instanceof ScopeUploadError) {
|
|
1313
|
+
return errorResponse(err.status, err.code, err.message);
|
|
1314
|
+
}
|
|
1315
|
+
throw err;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* In-process bulk transport, deliberately not dispatched by the HTTP router.
|
|
1320
|
+
* The Request carries only a signed digest commitment, not the item envelope.
|
|
1321
|
+
* It authenticates the same method, URI and owner as a remote append.
|
|
1322
|
+
*/
|
|
1323
|
+
export async function handlePersonalServerScopeUploadAppend(request, deps, batch) {
|
|
1324
|
+
return withApiErrors(async () => {
|
|
1325
|
+
const url = new URL(request.url);
|
|
1326
|
+
if (!url.pathname.startsWith("/v1/data/")) {
|
|
1327
|
+
return errorResponse(404, "NOT_FOUND", "Unknown upload route");
|
|
1328
|
+
}
|
|
1329
|
+
const pathname = stripBasePath(url.pathname, "/v1/data");
|
|
1330
|
+
const parts = pathname.split("/").filter(Boolean);
|
|
1331
|
+
if (parts.length !== 5 ||
|
|
1332
|
+
parts[1] !== "uploads" ||
|
|
1333
|
+
parts[3] !== "batches") {
|
|
1334
|
+
return errorResponse(404, "NOT_FOUND", "Unknown upload route");
|
|
1335
|
+
}
|
|
1336
|
+
return handleScopeUploadRequest(request, deps, parts, batch);
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
// Symbol.for, not a module-local symbol: a bundle that loads two copies of
|
|
1340
|
+
// core must still find the observer. Nothing on the wire can set it.
|
|
1341
|
+
const READ_GRANTEE_OBSERVER = Symbol.for("@opendatalabs/personal-server-ts-core/read-grantee-observer");
|
|
1342
|
+
/**
|
|
1343
|
+
* In-process only: asks the data read handler to report the grantee label
|
|
1344
|
+
* for this exact Request object. Used by the PS-Lite relay for telemetry; the
|
|
1345
|
+
* Node server never attaches one, so no requester can switch it on.
|
|
1346
|
+
*/
|
|
1347
|
+
export function attachPersonalServerReadGranteeObserver(request, observer) {
|
|
1348
|
+
Object.defineProperty(request, READ_GRANTEE_OBSERVER, {
|
|
1349
|
+
value: observer,
|
|
1350
|
+
configurable: true,
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
function readGranteeObserverOf(request) {
|
|
1354
|
+
const observer = request[READ_GRANTEE_OBSERVER];
|
|
1355
|
+
return typeof observer === "function"
|
|
1356
|
+
? observer
|
|
1357
|
+
: undefined;
|
|
1358
|
+
}
|
|
1359
|
+
async function granteeRefFor(authResult) {
|
|
1360
|
+
if (authResult?.grantId === "owner" ||
|
|
1361
|
+
authResult?.grantId === "policy-bypass") {
|
|
1362
|
+
return "owner";
|
|
1363
|
+
}
|
|
1364
|
+
const builder = authResult?.builder;
|
|
1365
|
+
if (typeof builder !== "string" || !/^0x[0-9a-fA-F]{40}$/.test(builder)) {
|
|
1366
|
+
return undefined;
|
|
1367
|
+
}
|
|
1368
|
+
const digest = await sha256Hex(new TextEncoder().encode(builder.toLowerCase()));
|
|
1369
|
+
return digest.slice(2, 14);
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Hands the grantee label to an attached observer without blocking or
|
|
1373
|
+
* failing the read: hashing runs off the response path and every error is
|
|
1374
|
+
* swallowed.
|
|
1375
|
+
*/
|
|
1376
|
+
function notifyReadGrantee(request, authResult) {
|
|
1377
|
+
const observer = readGranteeObserverOf(request);
|
|
1378
|
+
if (!observer)
|
|
1379
|
+
return;
|
|
1380
|
+
try {
|
|
1381
|
+
observer(granteeRefFor(authResult).catch(() => undefined));
|
|
1382
|
+
}
|
|
1383
|
+
catch {
|
|
1384
|
+
// Telemetry only: an observer fault never affects the read.
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
function historyInteger(value, fallback, name) {
|
|
1388
|
+
if (value === null)
|
|
1389
|
+
return fallback;
|
|
1390
|
+
const parsed = /^\d+$/.test(value) ? Number(value) : Number.NaN;
|
|
1391
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0) {
|
|
1392
|
+
throw new ProtocolError(400, "invalid_request", name + " must be a safe non-negative decimal integer");
|
|
1393
|
+
}
|
|
1394
|
+
return parsed;
|
|
1395
|
+
}
|
|
1396
|
+
/** The account's storage mode as one request freezes it before any read. */
|
|
1397
|
+
function readAccountStorageMode(deps) {
|
|
1398
|
+
return (deps.accountStorageMode?.read() ??
|
|
1399
|
+
deps.accountMode?.read(deps.serverOwner) ??
|
|
1400
|
+
"unknown");
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* One page of every scope this server holds data for, under the filters the
|
|
1404
|
+
* `GET /v1/data` listing applies (tombstones, canonical-only scopes, system
|
|
1405
|
+
* scopes) but with no grant filter. In-process only: the caller must itself
|
|
1406
|
+
* decide who may see the result (MCP exposes it only through `notShared`).
|
|
1407
|
+
*
|
|
1408
|
+
* It takes the same account-mode decision as that listing: a switched account
|
|
1409
|
+
* lists from the stream port and never touches legacy storage; an unknown
|
|
1410
|
+
* account, or a switched one with no stream listing, throws rather than
|
|
1411
|
+
* answering with an empty page.
|
|
1412
|
+
*/
|
|
1413
|
+
export async function listOwnerVisibleScopes(deps, page) {
|
|
1414
|
+
const mode = readAccountStorageMode(deps);
|
|
1415
|
+
if (mode === "unknown") {
|
|
1416
|
+
throw new Error("Owner scope listing unavailable: account mode unknown");
|
|
1417
|
+
}
|
|
1418
|
+
if (mode === "switched") {
|
|
1419
|
+
const listScopes = deps.streamSyncRead?.listScopes;
|
|
1420
|
+
if (!listScopes) {
|
|
1421
|
+
throw new Error("Owner scope listing unavailable: no stream listing");
|
|
1422
|
+
}
|
|
1423
|
+
const listed = await listScopes({
|
|
1424
|
+
canRead: (scope) => !isSystemScope(scope),
|
|
1425
|
+
});
|
|
1426
|
+
return {
|
|
1427
|
+
// The stream listing applies the resolver's own selection rule, so a
|
|
1428
|
+
// listed scope is one a read can serve: that is its readiness.
|
|
1429
|
+
scopes: listed
|
|
1430
|
+
.slice(page.offset, page.offset + page.limit)
|
|
1431
|
+
.map((row) => ({
|
|
1432
|
+
scope: row.scope,
|
|
1433
|
+
...(row.latestCollectedAt && {
|
|
1434
|
+
latestCollectedAt: row.latestCollectedAt,
|
|
1435
|
+
}),
|
|
1436
|
+
dataStatus: "ready",
|
|
1437
|
+
})),
|
|
1438
|
+
total: listed.length,
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
const deletionDeadlineAtMs = Date.now() + 250;
|
|
1442
|
+
const result = await listDataScopesContract({
|
|
1443
|
+
storage: deps.storage,
|
|
1444
|
+
limit: page.limit,
|
|
1445
|
+
offset: page.offset,
|
|
1446
|
+
isVisible: listingVisibility(deps, deletionDeadlineAtMs),
|
|
1447
|
+
isListable: (scope) => !isSystemScope(scope),
|
|
1448
|
+
extraScopes: canonicalOnlyScopes(deps, deletionDeadlineAtMs),
|
|
1449
|
+
});
|
|
1450
|
+
return {
|
|
1451
|
+
scopes: result.response.scopes.map((summary) => withCanonicalListing(deps, summary)),
|
|
1452
|
+
total: result.response.total,
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
486
1455
|
export async function handlePersonalServerDataRequest(request, deps, options = {}) {
|
|
1456
|
+
// Filled in as the dispatch narrows, so a 500 thrown deep in a read is
|
|
1457
|
+
// logged against the route that served it rather than a generic label. It
|
|
1458
|
+
// is mutable for exactly that reason: the route is not known until the path
|
|
1459
|
+
// has been parsed, and by then we are already inside the try.
|
|
1460
|
+
const logContext = {
|
|
1461
|
+
logger: deps.logger,
|
|
1462
|
+
route: `${request.method} ${options.basePath ?? "/v1/data"}`,
|
|
1463
|
+
requestId: crypto.randomUUID(),
|
|
1464
|
+
};
|
|
487
1465
|
return withApiErrors(async () => {
|
|
1466
|
+
// Freeze the routing decision before consulting any data source.
|
|
1467
|
+
const mode = readAccountStorageMode(deps);
|
|
488
1468
|
const url = new URL(request.url);
|
|
489
1469
|
const pathname = stripBasePath(url.pathname, options.basePath);
|
|
1470
|
+
// The account's storage mode, decided once before any list, version,
|
|
1471
|
+
// lineage or body branch. No read site acts on the decision yet (they are
|
|
1472
|
+
// routed through it one by one), so a switched account still reads as
|
|
1473
|
+
// before; it is recorded with every error this request logs.
|
|
1474
|
+
if (request.method === "GET") {
|
|
1475
|
+
logContext.detail = {
|
|
1476
|
+
storageSelection: mode,
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
490
1479
|
if (pathname === "/" || pathname === "") {
|
|
491
1480
|
if (request.method !== "GET")
|
|
492
1481
|
return methodNotAllowed();
|
|
493
|
-
await deps.auth.authorizeBuilderList(request
|
|
1482
|
+
const listAuth = await deps.auth.authorizeBuilderList(request, {
|
|
1483
|
+
grantId: selectedGrantId(request, url),
|
|
1484
|
+
});
|
|
1485
|
+
if (mode === "unknown")
|
|
1486
|
+
return accountModeUnknownResponse();
|
|
1487
|
+
if (mode === "switched") {
|
|
1488
|
+
if (!deps.streamSyncRead?.listScopes)
|
|
1489
|
+
return errorResponse(503, "STREAM_LIST_UNAVAILABLE", "Stream scope listing is not available");
|
|
1490
|
+
const scopes = await deps.streamSyncRead.listScopes({
|
|
1491
|
+
canRead: (scope) => !isSystemScope(scope) &&
|
|
1492
|
+
(!listAuth || listAuthCovers(listAuth, scope)),
|
|
1493
|
+
});
|
|
1494
|
+
const prefix = url.searchParams.get("scopePrefix") ?? "";
|
|
1495
|
+
const filtered = scopes.filter((row) => row.scope.startsWith(prefix));
|
|
1496
|
+
const offset = normalizeLimit(url.searchParams.get("offset"), 0);
|
|
1497
|
+
const limit = normalizeLimit(url.searchParams.get("limit"), 20);
|
|
1498
|
+
return jsonResponse({
|
|
1499
|
+
scopes: filtered.slice(offset, offset + limit),
|
|
1500
|
+
total: filtered.length,
|
|
1501
|
+
limit,
|
|
1502
|
+
offset,
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
// One budget for every stored and canonical-only scope, not per row.
|
|
1506
|
+
const deletionDeadlineAtMs = Date.now() + 250;
|
|
494
1507
|
const result = await listDataScopesContract({
|
|
495
1508
|
storage: deps.storage,
|
|
496
1509
|
scopePrefix: url.searchParams.get("scopePrefix") ?? undefined,
|
|
497
1510
|
limit: normalizeLimit(url.searchParams.get("limit"), 20),
|
|
498
1511
|
offset: normalizeLimit(url.searchParams.get("offset"), 0),
|
|
499
|
-
isVisible:
|
|
1512
|
+
isVisible: listingVisibility(deps, deletionDeadlineAtMs),
|
|
1513
|
+
isListable: (scope) => !isSystemScope(scope) &&
|
|
1514
|
+
(!listAuth || listAuthCovers(listAuth, scope)),
|
|
1515
|
+
extraScopes: canonicalOnlyScopes(deps, deletionDeadlineAtMs),
|
|
1516
|
+
});
|
|
1517
|
+
return jsonResponse({
|
|
1518
|
+
...result.response,
|
|
1519
|
+
scopes: result.response.scopes.map((summary) => withCanonicalListing(deps, summary)),
|
|
500
1520
|
});
|
|
501
|
-
|
|
1521
|
+
}
|
|
1522
|
+
// "additions" has no dot, so it can never be a real scope name (scopes are
|
|
1523
|
+
// "source.dataset"); handle it before the single-segment scope path.
|
|
1524
|
+
if (pathname === "/additions") {
|
|
1525
|
+
if (request.method !== "GET")
|
|
1526
|
+
return methodNotAllowed();
|
|
1527
|
+
// The counts span every scope, so only the owner may read them.
|
|
1528
|
+
await deps.auth.authorizeOwner(request);
|
|
1529
|
+
if (mode === "unknown")
|
|
1530
|
+
return accountModeUnknownResponse();
|
|
1531
|
+
const daysRaw = url.searchParams.get("days");
|
|
1532
|
+
const timezone = url.searchParams.get("tz") ?? "UTC";
|
|
1533
|
+
// Digits only: Number() would also accept "", "1e1", "0x7" and " 7".
|
|
1534
|
+
const days = daysRaw === null
|
|
1535
|
+
? 7
|
|
1536
|
+
: /^\d{1,3}$/.test(daysRaw)
|
|
1537
|
+
? Number(daysRaw)
|
|
1538
|
+
: Number.NaN;
|
|
1539
|
+
if (!Number.isInteger(days) || days < 1 || days > 31) {
|
|
1540
|
+
if (mode === "unswitched")
|
|
1541
|
+
return contractErrorResponse({
|
|
1542
|
+
ok: false,
|
|
1543
|
+
status: 400,
|
|
1544
|
+
body: {
|
|
1545
|
+
error: "INVALID_QUERY",
|
|
1546
|
+
message: "days must be an integer between 1 and 31",
|
|
1547
|
+
},
|
|
1548
|
+
});
|
|
1549
|
+
return errorResponse(400, "invalid_request", "days must be an integer from 1 to 31");
|
|
1550
|
+
}
|
|
1551
|
+
if (mode === "unswitched") {
|
|
1552
|
+
// Preserve the legacy query error contract before any storage access.
|
|
1553
|
+
const result = await summarizeDataAdditionsContract({
|
|
1554
|
+
additions: deps.additions,
|
|
1555
|
+
storage: deps.storage,
|
|
1556
|
+
isVisible: discoveryVisibility(deps),
|
|
1557
|
+
timezone,
|
|
1558
|
+
days,
|
|
1559
|
+
now: (deps.now ?? (() => new Date()))(),
|
|
1560
|
+
});
|
|
1561
|
+
if ("ok" in result)
|
|
1562
|
+
return contractErrorResponse(result);
|
|
1563
|
+
return jsonResponse(result);
|
|
1564
|
+
}
|
|
1565
|
+
if (!deps.history) {
|
|
1566
|
+
return errorResponse(503, "STREAM_SYNC_UNAVAILABLE", "Local history is not available on this server.");
|
|
1567
|
+
}
|
|
1568
|
+
return jsonResponse(await deps.history.additions({ timezone, days }));
|
|
502
1569
|
}
|
|
503
1570
|
const parts = pathname.split("/").filter(Boolean);
|
|
1571
|
+
if (parts.length >= 2 && parts[1] === "uploads") {
|
|
1572
|
+
return await handleScopeUploadRequest(request, deps, parts, undefined, mode);
|
|
1573
|
+
}
|
|
1574
|
+
if (parts.length === 3 && parts[1] === "imports") {
|
|
1575
|
+
if (request.method !== "PUT")
|
|
1576
|
+
return methodNotAllowed();
|
|
1577
|
+
await deps.auth.authorizeOwner(request);
|
|
1578
|
+
const modeRefusal = legacyMutationRefusal(mode);
|
|
1579
|
+
if (modeRefusal)
|
|
1580
|
+
return modeRefusal;
|
|
1581
|
+
// Owner-only: a builder has no durable-import route, so a signature
|
|
1582
|
+
// header earns no exemption here. This runs on the normalized path, so
|
|
1583
|
+
// `/imports/<op>/` and repeated slashes land here too.
|
|
1584
|
+
const refusal = refuseLegacyWrite(deps.accountStorageMode);
|
|
1585
|
+
if (refusal)
|
|
1586
|
+
return refusal;
|
|
1587
|
+
const scopeResult = parseDataScopeContract(decodePathPart(parts[0]));
|
|
1588
|
+
if (!scopeResult.ok)
|
|
1589
|
+
return contractErrorResponse(scopeResult);
|
|
1590
|
+
const operation = decodePathPart(parts[2]);
|
|
1591
|
+
if (!/^[a-f0-9]{64}$/.test(operation)) {
|
|
1592
|
+
return errorResponse(400, "INVALID_IMPORT_OPERATION", "operation must be 64 lowercase hexadecimal characters");
|
|
1593
|
+
}
|
|
1594
|
+
if (!deps.storage.commitVersion) {
|
|
1595
|
+
throw new ProtocolError(501, "IMPORT_UNSUPPORTED", "This storage backend does not support durable owner imports");
|
|
1596
|
+
}
|
|
1597
|
+
if (!deps.serverOwner)
|
|
1598
|
+
throw new ServerNotConfiguredError({
|
|
1599
|
+
reason: "serverOwner is required for durable owner imports",
|
|
1600
|
+
});
|
|
1601
|
+
if (!isJsonContentType(request) || url.search.length > 0) {
|
|
1602
|
+
return errorResponse(400, "INVALID_IMPORT", "Owner imports accept JSON root writes without query parameters");
|
|
1603
|
+
}
|
|
1604
|
+
const parsed = await parseJsonObjectBody(request, "Request body must be valid JSON");
|
|
1605
|
+
if (!parsed.ok)
|
|
1606
|
+
return contractResponse(parsed.result);
|
|
1607
|
+
if ("lineage" in parsed.body || "$binary" in parsed.body) {
|
|
1608
|
+
return errorResponse(400, "INVALID_IMPORT", "Owner imports do not accept binary or lineage writes");
|
|
1609
|
+
}
|
|
1610
|
+
const bodySha256 = await sha256Hex(canonicalJsonBytes(parsed.body));
|
|
1611
|
+
const authority = deps.gatewayConfig
|
|
1612
|
+
? `${deps.gatewayConfig.chainId}:${deps.gatewayConfig.contracts.dataRegistry.toLowerCase()}`
|
|
1613
|
+
: "local";
|
|
1614
|
+
const result = await ingestDataContract({
|
|
1615
|
+
storage: deps.storage,
|
|
1616
|
+
scopeParam: scopeResult.scope,
|
|
1617
|
+
body: parsed.body,
|
|
1618
|
+
collectedAt: (deps.now ?? (() => new Date()))().toISOString(),
|
|
1619
|
+
status: deps.syncManager ? "syncing" : "stored",
|
|
1620
|
+
afterTombstoneVersion: await ingestTombstoneMarker(deps, scopeResult.scope),
|
|
1621
|
+
import: {
|
|
1622
|
+
operation,
|
|
1623
|
+
bodySha256,
|
|
1624
|
+
owner: deps.serverOwner.toLowerCase(),
|
|
1625
|
+
authority,
|
|
1626
|
+
},
|
|
1627
|
+
});
|
|
1628
|
+
if (!result.ok)
|
|
1629
|
+
return contractErrorResponse(result);
|
|
1630
|
+
notifyNewData(deps.syncManager);
|
|
1631
|
+
if (!result.replay)
|
|
1632
|
+
notifyDataWritten(deps, {
|
|
1633
|
+
scope: result.scope,
|
|
1634
|
+
collectedAt: result.collectedAt,
|
|
1635
|
+
});
|
|
1636
|
+
return jsonResponse(result.response, {
|
|
1637
|
+
status: result.replay ? 200 : 201,
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
504
1640
|
if (parts.length === 2 && parts[1] === "versions") {
|
|
505
1641
|
if (request.method !== "GET")
|
|
506
1642
|
return methodNotAllowed();
|
|
507
|
-
|
|
1643
|
+
const versionsScopeParam = decodePathPart(parts[0]);
|
|
1644
|
+
const versionsGrantId = selectedGrantId(request, url);
|
|
1645
|
+
const listAuth = deps.auth.authorizeScopeVersions
|
|
1646
|
+
? await deps.auth.authorizeScopeVersions({
|
|
1647
|
+
request,
|
|
1648
|
+
scope: versionsScopeParam,
|
|
1649
|
+
grantId: versionsGrantId,
|
|
1650
|
+
})
|
|
1651
|
+
: await deps.auth.authorizeBuilderList(request, {
|
|
1652
|
+
grantId: versionsGrantId,
|
|
1653
|
+
});
|
|
1654
|
+
// A scope's version history is as much its data as its content is, so
|
|
1655
|
+
// a non-owner needs a grant covering it, exactly like a read.
|
|
1656
|
+
// Switched history reads the stream-sync stream the read route names
|
|
1657
|
+
// (`pdpp.<connector>.<stream>`), so it uses the read rule; legacy history
|
|
1658
|
+
// keeps the strict rule.
|
|
1659
|
+
const scopeResult = mode === "switched"
|
|
1660
|
+
? parseDataReadScopeContract(versionsScopeParam)
|
|
1661
|
+
: parseDataScopeContract(versionsScopeParam);
|
|
1662
|
+
if (scopeResult.ok &&
|
|
1663
|
+
listAuth &&
|
|
1664
|
+
!listAuthCovers(listAuth, scopeResult.scope)) {
|
|
1665
|
+
throw new GrantRequiredError({
|
|
1666
|
+
reason: "No grant covers this scope",
|
|
1667
|
+
requestedScope: scopeResult.scope,
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
if (mode !== "switched" && mode !== "unswitched") {
|
|
1671
|
+
return accountModeUnknownResponse();
|
|
1672
|
+
}
|
|
1673
|
+
const limit = Math.min(historyInteger(url.searchParams.get("limit"), 20, "limit"), HISTORY_PAGE_LIMIT);
|
|
1674
|
+
const offset = historyInteger(url.searchParams.get("offset"), 0, "offset");
|
|
1675
|
+
const cursorRaw = url.searchParams.get("cursor");
|
|
1676
|
+
const cursor = cursorRaw === null ? undefined : historyInteger(cursorRaw, 0, "cursor");
|
|
1677
|
+
if (limit < 1 ||
|
|
1678
|
+
cursor === 0 ||
|
|
1679
|
+
(mode === "switched" && offset !== 0) ||
|
|
1680
|
+
(mode === "unswitched" && cursor !== undefined)) {
|
|
1681
|
+
return errorResponse(400, "invalid_request", "Use a positive limit; switched history continues with cursor, not offset");
|
|
1682
|
+
}
|
|
1683
|
+
if (mode === "switched") {
|
|
1684
|
+
if (!scopeResult.ok)
|
|
1685
|
+
return contractErrorResponse(scopeResult);
|
|
1686
|
+
if (!deps.history) {
|
|
1687
|
+
return errorResponse(503, "STREAM_SYNC_UNAVAILABLE", "Local history is not available on this server.");
|
|
1688
|
+
}
|
|
1689
|
+
const result = await deps.history.versions({
|
|
1690
|
+
scope: scopeResult.scope,
|
|
1691
|
+
limit,
|
|
1692
|
+
offset,
|
|
1693
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
1694
|
+
});
|
|
1695
|
+
if (!result.ok) {
|
|
1696
|
+
if (result.reason === "deleted") {
|
|
1697
|
+
throw new DataDeletedError({ scope: scopeResult.scope });
|
|
1698
|
+
}
|
|
1699
|
+
return errorResponse(404, "NOT_FOUND", `Scope "${scopeResult.scope}" has no history`);
|
|
1700
|
+
}
|
|
1701
|
+
return jsonResponse(result.value);
|
|
1702
|
+
}
|
|
508
1703
|
const result = await listDataVersionsContract({
|
|
509
1704
|
storage: deps.storage,
|
|
510
1705
|
scopeParam: decodePathPart(parts[0]),
|
|
511
|
-
limit
|
|
512
|
-
offset
|
|
1706
|
+
limit,
|
|
1707
|
+
offset,
|
|
513
1708
|
isVisible: discoveryVisibility(deps),
|
|
514
1709
|
});
|
|
515
1710
|
if (!result.ok)
|
|
@@ -524,7 +1719,10 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
524
1719
|
if ((parts.length === 2 || parts.length === 3) && parts[1] === "lineage") {
|
|
525
1720
|
if (request.method !== "GET")
|
|
526
1721
|
return methodNotAllowed();
|
|
527
|
-
|
|
1722
|
+
// Like versions: switched lineage names the streams the read route does.
|
|
1723
|
+
const scopeResult = mode === "switched"
|
|
1724
|
+
? parseDataReadScopeContract(decodePathPart(parts[0]))
|
|
1725
|
+
: parseDataScopeContract(decodePathPart(parts[0]));
|
|
528
1726
|
if (!scopeResult.ok)
|
|
529
1727
|
return contractErrorResponse(scopeResult);
|
|
530
1728
|
// The version is a PATH segment (/v1/data/:scope/lineage/:version), so
|
|
@@ -550,6 +1748,44 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
550
1748
|
scope: scopeResult.scope,
|
|
551
1749
|
grantId: selectedGrantId(request, url),
|
|
552
1750
|
});
|
|
1751
|
+
if (mode !== "switched" && mode !== "unswitched") {
|
|
1752
|
+
return accountModeUnknownResponse();
|
|
1753
|
+
}
|
|
1754
|
+
if (mode === "switched") {
|
|
1755
|
+
resolveLineageGrantView(authResult);
|
|
1756
|
+
const historyVersion = version === undefined ? undefined : Number(version);
|
|
1757
|
+
if (historyVersion !== undefined &&
|
|
1758
|
+
!Number.isSafeInteger(historyVersion)) {
|
|
1759
|
+
return errorResponse(400, "INVALID_VERSION", "version must be a safe positive decimal integer");
|
|
1760
|
+
}
|
|
1761
|
+
if (!deps.history) {
|
|
1762
|
+
return errorResponse(503, "STREAM_SYNC_UNAVAILABLE", "Local history is not available on this server.");
|
|
1763
|
+
}
|
|
1764
|
+
const result = await deps.history.lineage({
|
|
1765
|
+
scope: scopeResult.scope,
|
|
1766
|
+
version: historyVersion,
|
|
1767
|
+
});
|
|
1768
|
+
if (!result.ok) {
|
|
1769
|
+
if (result.reason === "deleted") {
|
|
1770
|
+
throw new DataDeletedError({ scope: scopeResult.scope });
|
|
1771
|
+
}
|
|
1772
|
+
return errorResponse(404, "NOT_FOUND", `Scope "${scopeResult.scope}" has no history`);
|
|
1773
|
+
}
|
|
1774
|
+
await deps.accessLogWriter.write({
|
|
1775
|
+
logId: deps.createLogId?.() ?? crypto.randomUUID(),
|
|
1776
|
+
grantId: authResult?.grantId ?? "owner",
|
|
1777
|
+
builder: authResult?.builder ?? "unknown",
|
|
1778
|
+
action: "lineage",
|
|
1779
|
+
scope: scopeResult.scope,
|
|
1780
|
+
timestamp: (deps.now ?? (() => new Date()))().toISOString(),
|
|
1781
|
+
ipAddress: request.headers.get("x-forwarded-for") ??
|
|
1782
|
+
request.headers.get("x-real-ip") ??
|
|
1783
|
+
"unknown",
|
|
1784
|
+
userAgent: request.headers.get("user-agent") ?? "unknown",
|
|
1785
|
+
});
|
|
1786
|
+
const { proof, ...data } = result.value;
|
|
1787
|
+
return jsonResponse({ data, proof });
|
|
1788
|
+
}
|
|
553
1789
|
if (!deps.serverOwner) {
|
|
554
1790
|
throw new ServerNotConfiguredError({
|
|
555
1791
|
reason: "serverOwner is required to resolve the data point id",
|
|
@@ -609,137 +1845,341 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
609
1845
|
if (parts.length !== 1)
|
|
610
1846
|
return notFound();
|
|
611
1847
|
const scopeParam = decodePathPart(parts[0]);
|
|
1848
|
+
logContext.route = `${request.method} ${options.basePath ?? "/v1/data"}/:scope`;
|
|
612
1849
|
if (request.method === "GET") {
|
|
613
|
-
|
|
1850
|
+
// The account mode chooses the read surface, not reader availability.
|
|
1851
|
+
const scopeResult = mode === "switched"
|
|
1852
|
+
? parseDataReadScopeContract(scopeParam)
|
|
1853
|
+
: parseDataScopeContract(scopeParam);
|
|
614
1854
|
if (!scopeResult.ok)
|
|
615
1855
|
return contractErrorResponse(scopeResult);
|
|
616
|
-
|
|
1856
|
+
logContext.detail = {
|
|
1857
|
+
...logContext.detail,
|
|
617
1858
|
scope: scopeResult.scope,
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
1859
|
+
};
|
|
1860
|
+
// An empty `fileId=` or `at=` selects no version: it is the latest
|
|
1861
|
+
// read, as storage already treats it.
|
|
1862
|
+
const fileIdParam = url.searchParams.get("fileId") || undefined;
|
|
1863
|
+
const atParam = url.searchParams.get("at") || undefined;
|
|
1864
|
+
// `?view=stored` returns the body as stored, without the read-time
|
|
1865
|
+
// legacy projection. Owner only; checked after auth below.
|
|
1866
|
+
const view = url.searchParams.get("view");
|
|
1867
|
+
if (view !== null && view !== "stored") {
|
|
1868
|
+
return errorResponse(400, "INVALID_VIEW", 'view must be "stored" or absent');
|
|
1869
|
+
}
|
|
1870
|
+
const selectedEntry = mode === "unswitched"
|
|
1871
|
+
? deps.storage.findEntry({
|
|
1872
|
+
scope: scopeResult.scope,
|
|
1873
|
+
fileId: fileIdParam,
|
|
1874
|
+
at: atParam,
|
|
1875
|
+
})
|
|
1876
|
+
: undefined;
|
|
621
1877
|
// Holds the base64-encoded gateway payForOperation response body when
|
|
622
1878
|
// X402 succeeds — emitted on the final read response as X-PAYMENT-RESPONSE.
|
|
623
1879
|
let paymentResponseHeader;
|
|
624
1880
|
const grantId = selectedGrantId(request, url);
|
|
625
|
-
const
|
|
1881
|
+
const wantsRawContent = url.searchParams.get("content") === "raw";
|
|
1882
|
+
const inProcess = options.inProcess;
|
|
1883
|
+
// Check the grant without charging before resolving a switched read.
|
|
1884
|
+
// Settlement receives the exact served head, never a legacy lookup.
|
|
1885
|
+
// In-process legacy reads also settle only after their refusal gates.
|
|
1886
|
+
const settleLast = (mode === "switched" || inProcess !== undefined) &&
|
|
1887
|
+
!inProcess?.metadataOnly;
|
|
1888
|
+
const authInput = {
|
|
626
1889
|
request,
|
|
627
1890
|
scope: scopeResult.scope,
|
|
628
1891
|
grantId,
|
|
629
|
-
|
|
630
|
-
|
|
1892
|
+
// Only a file id that resolved inside this scope reaches policy. A
|
|
1893
|
+
// wrong-scope id and a nonexistent one both resolve to nothing, so
|
|
1894
|
+
// neither takes a different path and no foreign id leaves the process.
|
|
1895
|
+
fileId: selectedEntry?.fileId ?? undefined,
|
|
1896
|
+
at: atParam,
|
|
1897
|
+
};
|
|
1898
|
+
const authResult = await deps.auth.authorizeBuilderRead({
|
|
1899
|
+
...authInput,
|
|
1900
|
+
...(mode === "unknown" || inProcess?.metadataOnly || settleLast
|
|
1901
|
+
? { metadataOnly: true }
|
|
1902
|
+
: {}),
|
|
631
1903
|
});
|
|
1904
|
+
notifyReadGrantee(request, authResult);
|
|
1905
|
+
if (mode === "unknown")
|
|
1906
|
+
return accountModeUnknownResponse();
|
|
1907
|
+
// `served` is the stream head the read decision chose and validated.
|
|
1908
|
+
// It is passed through as is: settlement never looks the head up again.
|
|
1909
|
+
const settle = async (served) => {
|
|
1910
|
+
if (!settleLast)
|
|
1911
|
+
return;
|
|
1912
|
+
await deps.auth.authorizeBuilderRead(served ? { ...authInput, servedEntry: served } : authInput);
|
|
1913
|
+
};
|
|
1914
|
+
// Select the body after auth and before deletion or payment. A file's
|
|
1915
|
+
// version and re-add marker authorize that file, not canonical rows.
|
|
1916
|
+
// `?view=stored` asks for the stored file's body, so it never reads the
|
|
1917
|
+
// canonical view either.
|
|
1918
|
+
const latest = mode === "unswitched" &&
|
|
1919
|
+
fileIdParam === undefined &&
|
|
1920
|
+
atParam === undefined &&
|
|
1921
|
+
view === null
|
|
1922
|
+
? await deps.legacyScopeView?.readLatest(scopeResult.scope)
|
|
1923
|
+
: undefined;
|
|
1924
|
+
// On serves database stream views or a refusal, including historical
|
|
1925
|
+
// selectors. Only Off reaches the separate legacy body path below.
|
|
1926
|
+
const latestRead = fileIdParam === undefined && atParam === undefined && view === null;
|
|
1927
|
+
if (mode === "switched") {
|
|
1928
|
+
let ownerNotes;
|
|
1929
|
+
if (!deps.streamSyncRead) {
|
|
1930
|
+
return errorResponse(503, "STREAM_READ_UNAVAILABLE", "Stream reads are not available");
|
|
1931
|
+
}
|
|
1932
|
+
let historical;
|
|
1933
|
+
if (!latestRead) {
|
|
1934
|
+
let selected;
|
|
1935
|
+
const body = await deps.streamSyncRead.olderVersions?.read(scopeResult.scope, { fileId: fileIdParam, at: atParam }, (head) => {
|
|
1936
|
+
selected = head;
|
|
1937
|
+
});
|
|
1938
|
+
if (!body || body === "gone")
|
|
1939
|
+
return errorResponse(410, "STREAM_HISTORY_UNAVAILABLE", "Older versions are not available");
|
|
1940
|
+
if (!selected) {
|
|
1941
|
+
await body.cancel();
|
|
1942
|
+
return errorResponse(503, "STREAM_READ_UNAVAILABLE", "The selected stream head is unavailable");
|
|
1943
|
+
}
|
|
1944
|
+
const head = selected;
|
|
1945
|
+
const encoder = new TextEncoder();
|
|
1946
|
+
const reader = body.getReader();
|
|
1947
|
+
let started = false;
|
|
1948
|
+
const wrapped = new ReadableStream({
|
|
1949
|
+
async pull(controller) {
|
|
1950
|
+
if (!started) {
|
|
1951
|
+
started = true;
|
|
1952
|
+
controller.enqueue(encoder.encode(JSON.stringify({
|
|
1953
|
+
version: "1.0",
|
|
1954
|
+
scope: scopeResult.scope,
|
|
1955
|
+
collectedAt: new Date(head.observedAt).toISOString(),
|
|
1956
|
+
}).slice(0, -1) + ',"data":{"records":'));
|
|
1957
|
+
return;
|
|
1958
|
+
}
|
|
1959
|
+
try {
|
|
1960
|
+
const chunk = await reader.read();
|
|
1961
|
+
if (chunk.done) {
|
|
1962
|
+
controller.enqueue(encoder.encode("}}"));
|
|
1963
|
+
controller.close();
|
|
1964
|
+
reader.releaseLock();
|
|
1965
|
+
}
|
|
1966
|
+
else
|
|
1967
|
+
controller.enqueue(chunk.value);
|
|
1968
|
+
}
|
|
1969
|
+
catch (error) {
|
|
1970
|
+
controller.error(error);
|
|
1971
|
+
reader.releaseLock();
|
|
1972
|
+
}
|
|
1973
|
+
},
|
|
1974
|
+
async cancel(reason) {
|
|
1975
|
+
try {
|
|
1976
|
+
await reader.cancel(reason);
|
|
1977
|
+
}
|
|
1978
|
+
finally {
|
|
1979
|
+
reader.releaseLock();
|
|
1980
|
+
}
|
|
1981
|
+
},
|
|
1982
|
+
});
|
|
1983
|
+
historical = {
|
|
1984
|
+
kind: "view",
|
|
1985
|
+
connector: "",
|
|
1986
|
+
ns: "",
|
|
1987
|
+
cursor: "",
|
|
1988
|
+
served: head,
|
|
1989
|
+
body: wrapped,
|
|
1990
|
+
};
|
|
1991
|
+
}
|
|
1992
|
+
const decision = historical ??
|
|
1993
|
+
(await deps.streamSyncRead.resolve({
|
|
1994
|
+
scope: scopeResult.scope,
|
|
1995
|
+
connection: latestRead ? url.searchParams.get("connection") : null,
|
|
1996
|
+
cursor: latestRead ? url.searchParams.get("cursor") : null,
|
|
1997
|
+
legacyFile: false,
|
|
1998
|
+
isOwnerView: isOwnerView(authResult),
|
|
1999
|
+
}));
|
|
2000
|
+
if (decision.kind === "local_pending") {
|
|
2001
|
+
await decision.body.cancel();
|
|
2002
|
+
return errorResponse(404, "STREAM_DATA_NOT_FOUND", "No complete stream data is available for this scope", decision);
|
|
2003
|
+
}
|
|
2004
|
+
if (decision.kind === "unavailable" && decision.reason === "deleted") {
|
|
2005
|
+
throw new DataDeletedError({ scope: scopeResult.scope });
|
|
2006
|
+
}
|
|
2007
|
+
if (latestRead || historical) {
|
|
2008
|
+
if (decision.kind === "pass" ||
|
|
2009
|
+
decision.kind === "legacy" ||
|
|
2010
|
+
decision.kind === "unavailable") {
|
|
2011
|
+
ownerNotes = decision;
|
|
2012
|
+
}
|
|
2013
|
+
const refusal = streamSyncRefusal(decision);
|
|
2014
|
+
if (refusal)
|
|
2015
|
+
return refusal;
|
|
2016
|
+
if (inProcess && wantsRawContent && decision.kind === "view") {
|
|
2017
|
+
// A view has no raw bytes. Refused before any charge, log or
|
|
2018
|
+
// fulfilment, so a caller never pays for a read it cannot use.
|
|
2019
|
+
await decision.body.cancel();
|
|
2020
|
+
return jsonResponse({
|
|
2021
|
+
error: "STREAM_VIEW_NOT_RAW",
|
|
2022
|
+
message: `Scope "${scopeResult.scope}" is served from its stream view, which has no raw binary content.`,
|
|
2023
|
+
scope: scopeResult.scope,
|
|
2024
|
+
}, { status: 409 });
|
|
2025
|
+
}
|
|
2026
|
+
if (decision.kind === "view") {
|
|
2027
|
+
notifyDataRead(deps, { scope: scopeResult.scope });
|
|
2028
|
+
// The same charge as a file read; the access record binds the
|
|
2029
|
+
// stream head the view serves.
|
|
2030
|
+
let paymentResponseHeader;
|
|
2031
|
+
// An owner-only view with no registered head has nothing to
|
|
2032
|
+
// charge against: the service serves it to the owner alone.
|
|
2033
|
+
if (decision.served !== null) {
|
|
2034
|
+
const served = decision.served;
|
|
2035
|
+
const ownApp = await ownAppReadStatus(deps, authResult);
|
|
2036
|
+
if (ownApp instanceof Response) {
|
|
2037
|
+
await decision.body.cancel();
|
|
2038
|
+
return ownApp;
|
|
2039
|
+
}
|
|
2040
|
+
const charge = readCharge(deps, scopeResult.scope, authResult, ownApp);
|
|
2041
|
+
if (charge) {
|
|
2042
|
+
let paid;
|
|
2043
|
+
try {
|
|
2044
|
+
paid = await payForRead(deps, request, charge, {
|
|
2045
|
+
scope: scopeResult.scope,
|
|
2046
|
+
servedEntry: served,
|
|
2047
|
+
});
|
|
2048
|
+
}
|
|
2049
|
+
catch (error) {
|
|
2050
|
+
await decision.body.cancel();
|
|
2051
|
+
throw error;
|
|
2052
|
+
}
|
|
2053
|
+
if (paid.kind === "refused") {
|
|
2054
|
+
await decision.body.cancel();
|
|
2055
|
+
return paid.response;
|
|
2056
|
+
}
|
|
2057
|
+
paymentResponseHeader = paid.paymentResponseHeader;
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
const checked = await validateStreamBody(decision, inProcess);
|
|
2061
|
+
await settle(decision.served);
|
|
2062
|
+
return serveStreamSyncView(deps, request, {
|
|
2063
|
+
scope: scopeResult.scope,
|
|
2064
|
+
grantId,
|
|
2065
|
+
authResult,
|
|
2066
|
+
decision: checked,
|
|
2067
|
+
paymentResponseHeader,
|
|
2068
|
+
inProcess,
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
return errorResponse(404, "STREAM_DATA_NOT_FOUND", "No complete stream data is available for this scope", ownerNotes);
|
|
2073
|
+
}
|
|
2074
|
+
// The deletion history comes with the body the view chose, never from
|
|
2075
|
+
// a later ownership query a concurrent write could change.
|
|
2076
|
+
const canonicalOwned = latest !== undefined && deletionHistoryOf(latest) === "canonical";
|
|
632
2077
|
// Deletion gate, after auth (so unauthenticated callers learn nothing)
|
|
633
2078
|
// and before payment (so nobody is charged for deleted data). Covers
|
|
634
2079
|
// 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");
|
|
2080
|
+
await assertScopeNotDeleted(deps, scopeResult.scope, canonicalOwned ? undefined : selectedEntry, canonicalOwned ? "canonical" : "file");
|
|
2081
|
+
if (view === "stored" && !isOwnerView(authResult)) {
|
|
2082
|
+
return errorResponse(403, "FORBIDDEN", "Only the owner can read the stored view");
|
|
678
2083
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
2084
|
+
// Demand: this authorized read is what pays for a recompute of a
|
|
2085
|
+
// derivative whose sources have moved on. It runs after the gates
|
|
2086
|
+
// above (an unauthenticated or refused read must never spend an
|
|
2087
|
+
// inference call) and before the payment dance, because the status
|
|
2088
|
+
// route grants the same caller the same trigger for free — gating it
|
|
2089
|
+
// on payment would buy nothing and would leave a never-computed
|
|
2090
|
+
// answer unreachable through this route. Nothing here blocks: a
|
|
2091
|
+
// previous version is served now, the fresh one lands in a later read.
|
|
2092
|
+
notifyDataRead(deps, { scope: scopeResult.scope });
|
|
2093
|
+
// A canonical scope's latest body is the canonical view, and only it:
|
|
2094
|
+
// a refusal is answered, never replaced by the legacy file. Explicit
|
|
2095
|
+
// versions stay legacy history. Read before payment, so a builder is
|
|
2096
|
+
// never challenged or charged for a read that is then refused.
|
|
2097
|
+
if (latest?.kind === "refused") {
|
|
2098
|
+
return legacyViewRefusalResponse(scopeResult.scope, latest.refusal);
|
|
2099
|
+
}
|
|
2100
|
+
// X402 payment dance for builder reads (see `readCharge`).
|
|
2101
|
+
const ownApp = await ownAppReadStatus(deps, authResult);
|
|
2102
|
+
if (ownApp instanceof Response)
|
|
2103
|
+
return ownApp;
|
|
2104
|
+
const charge = readCharge(deps, scopeResult.scope, authResult, ownApp);
|
|
2105
|
+
if (charge && latest?.kind === "canonical") {
|
|
2106
|
+
return legacyViewRefusalResponse(scopeResult.scope, {
|
|
2107
|
+
status: "unavailable",
|
|
2108
|
+
reason: "paid_read_unsupported",
|
|
687
2109
|
});
|
|
688
2110
|
}
|
|
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,
|
|
2111
|
+
if (charge) {
|
|
2112
|
+
const paid = await payForRead(deps, request, charge, {
|
|
702
2113
|
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,
|
|
2114
|
+
fileIdParam,
|
|
2115
|
+
atParam,
|
|
710
2116
|
});
|
|
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);
|
|
2117
|
+
if (paid.kind === "refused")
|
|
2118
|
+
return paid.response;
|
|
2119
|
+
paymentResponseHeader = paid.paymentResponseHeader;
|
|
724
2120
|
}
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
2121
|
+
const headers = {};
|
|
2122
|
+
if (ownApp)
|
|
2123
|
+
headers["X-Vana-Payment-Exemption"] = "own-app";
|
|
2124
|
+
headers["X-Vana-Data-Source"] =
|
|
2125
|
+
latest?.kind === "canonical" ? "canonical" : "legacy";
|
|
2126
|
+
let envelope;
|
|
2127
|
+
let servedFileId;
|
|
2128
|
+
if (latest?.kind === "canonical") {
|
|
2129
|
+
envelope = latest.envelope;
|
|
2130
|
+
headers.ETag = `"${latest.revision}"`;
|
|
2131
|
+
}
|
|
2132
|
+
else {
|
|
2133
|
+
const result = await readDataContract({
|
|
2134
|
+
storage: deps.storage,
|
|
2135
|
+
scopeParam: scopeResult.scope,
|
|
2136
|
+
// An in-process read names the version it selected above, so the
|
|
2137
|
+
// body served is the version the payment and fulfilment name.
|
|
2138
|
+
fileId: inProcess
|
|
2139
|
+
? (fileIdParam ?? selectedEntry?.fileId ?? undefined)
|
|
2140
|
+
: fileIdParam,
|
|
2141
|
+
at: atParam,
|
|
2142
|
+
...(view === "stored" ? { view } : {}),
|
|
2143
|
+
});
|
|
2144
|
+
if (!result.ok) {
|
|
2145
|
+
if (result.status === 404) {
|
|
2146
|
+
// The entry selected above can vanish before the read (a sync
|
|
2147
|
+
// reconcile applying a tombstone concurrently); answer 410, not
|
|
2148
|
+
// 404, when that is why.
|
|
2149
|
+
await assertScopeNotDeleted(deps, scopeResult.scope, undefined);
|
|
2150
|
+
}
|
|
2151
|
+
return contractErrorResponse(result);
|
|
737
2152
|
}
|
|
738
|
-
|
|
2153
|
+
envelope = result.envelope;
|
|
2154
|
+
servedFileId = fileIdParam ?? selectedEntry?.fileId ?? undefined;
|
|
739
2155
|
}
|
|
740
2156
|
const servedEnvelope = isOwnerView(authResult)
|
|
741
|
-
?
|
|
742
|
-
: redactEnvelopeForGrantee(
|
|
2157
|
+
? envelope
|
|
2158
|
+
: redactEnvelopeForGrantee(envelope);
|
|
2159
|
+
// An in-process raw read is refused, or decoded, before it pays or logs.
|
|
2160
|
+
// HTTP keeps its order: the same checks run after the access log.
|
|
2161
|
+
let rawBinary;
|
|
2162
|
+
if (inProcess && wantsRawContent) {
|
|
2163
|
+
if (!isBinaryEnvelope(servedEnvelope)) {
|
|
2164
|
+
return jsonResponse({
|
|
2165
|
+
error: "NOT_BINARY_SCOPE",
|
|
2166
|
+
message: `Scope "${scopeResult.scope}" does not expose raw binary content.`,
|
|
2167
|
+
}, { status: 400, headers });
|
|
2168
|
+
}
|
|
2169
|
+
rawBinary = decodeBinaryEnvelope(servedEnvelope);
|
|
2170
|
+
inProcess.onRawSelected?.({
|
|
2171
|
+
fileId: servedFileId,
|
|
2172
|
+
collectedAt: envelope.collectedAt,
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
// A JSON read is checked against the body it will serve, before it pays.
|
|
2176
|
+
if (inProcess && !wantsRawContent) {
|
|
2177
|
+
await inProcess.validateBody?.(servedEnvelope, {
|
|
2178
|
+
fromStreamView: false,
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
// Every refusal above has run; only a read that will be served pays.
|
|
2182
|
+
await settle();
|
|
743
2183
|
const logId = deps.createLogId?.() ?? crypto.randomUUID();
|
|
744
2184
|
const timestamp = (deps.now ?? (() => new Date()))().toISOString();
|
|
745
2185
|
const ipAddress = request.headers.get("x-forwarded-for") ??
|
|
@@ -748,37 +2188,50 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
748
2188
|
const userAgent = request.headers.get("user-agent") ?? "unknown";
|
|
749
2189
|
const loggedGrantId = authResult?.grantId ?? grantId ?? "unknown";
|
|
750
2190
|
const loggedBuilder = authResult?.builder ?? "unknown";
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
2191
|
+
if (options.inProcess?.logAccess !== false) {
|
|
2192
|
+
await deps.accessLogWriter.write({
|
|
2193
|
+
logId,
|
|
2194
|
+
grantId: loggedGrantId,
|
|
2195
|
+
builder: loggedBuilder,
|
|
2196
|
+
action: "read",
|
|
2197
|
+
scope: scopeResult.scope,
|
|
2198
|
+
timestamp,
|
|
2199
|
+
ipAddress,
|
|
2200
|
+
userAgent,
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
761
2203
|
const reportReadFulfillment = () => {
|
|
762
2204
|
if (!authResult?.grantId || !authResult.builder)
|
|
763
2205
|
return;
|
|
2206
|
+
if (options.inProcess) {
|
|
2207
|
+
options.inProcess.onServed({
|
|
2208
|
+
scope: scopeResult.scope,
|
|
2209
|
+
builder: authResult.builder,
|
|
2210
|
+
grantId: authResult.grantId,
|
|
2211
|
+
fileId: servedFileId,
|
|
2212
|
+
logId,
|
|
2213
|
+
ipAddress,
|
|
2214
|
+
servedAt: timestamp,
|
|
2215
|
+
userAgent,
|
|
2216
|
+
});
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
764
2219
|
reportPersonalServerReadFulfillment(deps, {
|
|
765
2220
|
builder: authResult.builder,
|
|
766
|
-
fileId:
|
|
767
|
-
selectedEntry?.fileId ??
|
|
768
|
-
undefined,
|
|
2221
|
+
fileId: servedFileId,
|
|
769
2222
|
grantId: authResult.grantId,
|
|
770
2223
|
ipAddress,
|
|
771
2224
|
logId,
|
|
2225
|
+
outcome: "served",
|
|
772
2226
|
scope: scopeResult.scope,
|
|
773
2227
|
servedAt: timestamp,
|
|
2228
|
+
source: "api",
|
|
774
2229
|
userAgent,
|
|
775
2230
|
});
|
|
776
2231
|
};
|
|
777
|
-
const headers = {};
|
|
778
2232
|
if (paymentResponseHeader) {
|
|
779
2233
|
headers["X-PAYMENT-RESPONSE"] = paymentResponseHeader;
|
|
780
2234
|
}
|
|
781
|
-
const wantsRawContent = url.searchParams.get("content") === "raw";
|
|
782
2235
|
// `?content=raw` streams the decoded bytes of a binary envelope with its
|
|
783
2236
|
// original media type, so a builder can download the file directly. The
|
|
784
2237
|
// X-PAYMENT-RESPONSE header (if any) rides along on the raw response too.
|
|
@@ -789,7 +2242,7 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
789
2242
|
message: `Scope "${scopeResult.scope}" does not expose raw binary content.`,
|
|
790
2243
|
}, { status: 400, headers });
|
|
791
2244
|
}
|
|
792
|
-
const decoded = decodeBinaryEnvelope(servedEnvelope);
|
|
2245
|
+
const decoded = rawBinary ?? decodeBinaryEnvelope(servedEnvelope);
|
|
793
2246
|
headers["Content-Type"] = decoded.mimeType;
|
|
794
2247
|
headers["Content-Length"] = String(decoded.bytes.length);
|
|
795
2248
|
if (decoded.filename) {
|
|
@@ -805,7 +2258,9 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
805
2258
|
});
|
|
806
2259
|
return response;
|
|
807
2260
|
}
|
|
808
|
-
const response = jsonResponse(servedEnvelope, {
|
|
2261
|
+
const response = jsonResponse(servedEnvelope, {
|
|
2262
|
+
headers,
|
|
2263
|
+
});
|
|
809
2264
|
reportReadFulfillment();
|
|
810
2265
|
return response;
|
|
811
2266
|
}
|
|
@@ -823,10 +2278,28 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
823
2278
|
else {
|
|
824
2279
|
await deps.auth.authorizeOwner(request);
|
|
825
2280
|
}
|
|
2281
|
+
const modeRefusal = legacyMutationRefusal(mode);
|
|
2282
|
+
if (modeRefusal) {
|
|
2283
|
+
await writeAuth?.releaseProof?.();
|
|
2284
|
+
return modeRefusal;
|
|
2285
|
+
}
|
|
2286
|
+
// `?supersede=legacy`: once this write commits, delete the scope's
|
|
2287
|
+
// older legacy-form versions (see supersedeLegacyVersions). It deletes
|
|
2288
|
+
// data, so only the owner may ask for it.
|
|
2289
|
+
const supersede = url.searchParams.get("supersede");
|
|
2290
|
+
if (supersede !== null && supersede !== "legacy") {
|
|
2291
|
+
await writeAuth?.releaseProof?.();
|
|
2292
|
+
return errorResponse(400, "INVALID_SUPERSEDE", 'supersede must be "legacy" or absent');
|
|
2293
|
+
}
|
|
2294
|
+
if (supersede !== null && writeAuth) {
|
|
2295
|
+
await writeAuth.releaseProof?.();
|
|
2296
|
+
return errorResponse(403, "FORBIDDEN", "Only the owner can supersede stored versions");
|
|
2297
|
+
}
|
|
826
2298
|
// A write that fails before commit hands the proof back (replay guard)
|
|
827
2299
|
// so the builder's retry with the same still-valid proof is accepted;
|
|
828
2300
|
// after commit the proof stays consumed (a retry would be a duplicate).
|
|
829
2301
|
let committed = false;
|
|
2302
|
+
let ingestStamp;
|
|
830
2303
|
const failWrite = async (response) => {
|
|
831
2304
|
await writeAuth?.releaseProof?.();
|
|
832
2305
|
return response;
|
|
@@ -835,7 +2308,20 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
835
2308
|
const scopeResult = parseDataScopeContract(scopeParam);
|
|
836
2309
|
if (!scopeResult.ok)
|
|
837
2310
|
return failWrite(contractErrorResponse(scopeResult));
|
|
838
|
-
const
|
|
2311
|
+
const parsedPrecondition = parseLegacyPrecondition(request);
|
|
2312
|
+
if (parsedPrecondition instanceof Response)
|
|
2313
|
+
return failWrite(parsedPrecondition);
|
|
2314
|
+
const producerHeader = parseProducerHeader(request);
|
|
2315
|
+
if (producerHeader instanceof Response)
|
|
2316
|
+
return failWrite(producerHeader);
|
|
2317
|
+
if (writeAuth && producerHeader.producer) {
|
|
2318
|
+
return failWrite(errorResponse(403, "NOT_OWNER", "Only the owner may assert a producer"));
|
|
2319
|
+
}
|
|
2320
|
+
ingestStamp = reserveIngestStamp(deps.now ?? (() => new Date()), deps.storage, scopeResult.scope);
|
|
2321
|
+
if (!ingestStamp) {
|
|
2322
|
+
return failWrite(errorResponse(429, "INGEST_CAPACITY", "Too many writes for this scope; retry when the clock advances"));
|
|
2323
|
+
}
|
|
2324
|
+
const collectedAtValue = ingestStamp.collectedAt;
|
|
839
2325
|
const status = deps.syncManager ? "syncing" : "stored";
|
|
840
2326
|
const afterTombstoneVersion = await ingestTombstoneMarker(deps, scopeResult.scope);
|
|
841
2327
|
// Builder writes land in the same access log as builder reads, so the
|
|
@@ -875,6 +2361,12 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
875
2361
|
// data needs no schema at all — we ingest it schemaless. (Structured JSON
|
|
876
2362
|
// below still resolves a schema for validation/metadata.)
|
|
877
2363
|
if (!isJsonContentType(request)) {
|
|
2364
|
+
if (producerHeader.producer) {
|
|
2365
|
+
return failWrite(errorResponse(400, "INVALID_PRODUCER", "Producer attribution requires a JSON body"));
|
|
2366
|
+
}
|
|
2367
|
+
if (supersede !== null) {
|
|
2368
|
+
return failWrite(errorResponse(400, "INVALID_SUPERSEDE", "supersede applies to JSON writes only"));
|
|
2369
|
+
}
|
|
878
2370
|
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
879
2371
|
const metadata = parseMetadataHeader(request.headers.get("x-vana-metadata"));
|
|
880
2372
|
// A binary derivative names its sources inside the metadata
|
|
@@ -892,6 +2384,7 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
892
2384
|
attribution: writeAuth?.attribution,
|
|
893
2385
|
lineage,
|
|
894
2386
|
afterTombstoneVersion,
|
|
2387
|
+
precondition: parsedPrecondition,
|
|
895
2388
|
});
|
|
896
2389
|
if (!result.ok)
|
|
897
2390
|
return failWrite(contractErrorResponse(result));
|
|
@@ -916,6 +2409,9 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
916
2409
|
const parsed = await parseJsonObjectBody(request, "Request body must be valid JSON");
|
|
917
2410
|
if (!parsed.ok)
|
|
918
2411
|
return failWrite(contractResponse(parsed.result));
|
|
2412
|
+
const provenance = await parseProducerProvenance(producerHeader.encodedProvenance, parsed.body);
|
|
2413
|
+
if (provenance instanceof Response)
|
|
2414
|
+
return failWrite(provenance);
|
|
919
2415
|
// Derivative writes: validate the caller's `lineage` before anything
|
|
920
2416
|
// is stored (a failure here throws, releasing the builder's proof).
|
|
921
2417
|
const lineage = await prepareWriteLineage(deps, scopeResult.scope, extractLineageField(parsed.body));
|
|
@@ -930,9 +2426,14 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
930
2426
|
attribution: writeAuth?.attribution,
|
|
931
2427
|
lineage,
|
|
932
2428
|
afterTombstoneVersion,
|
|
2429
|
+
precondition: parsedPrecondition,
|
|
2430
|
+
producer: producerHeader.producer,
|
|
2431
|
+
producerProvenance: provenance,
|
|
933
2432
|
});
|
|
934
2433
|
if (!result.ok)
|
|
935
2434
|
return failWrite(contractErrorResponse(result));
|
|
2435
|
+
if (result.replay)
|
|
2436
|
+
throw new Error("Ordinary POST cannot replay an import");
|
|
936
2437
|
committed = true;
|
|
937
2438
|
deps.logger?.info?.({
|
|
938
2439
|
scope: scopeResult.scope,
|
|
@@ -941,13 +2442,32 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
941
2442
|
...(writeAuth ? { builder: writeAuth.builder } : {}),
|
|
942
2443
|
}, "Data file ingested");
|
|
943
2444
|
await logBuilderWrite();
|
|
2445
|
+
const supersedeResult = supersede === "legacy"
|
|
2446
|
+
? await supersedeAfterCommit(deps, scopeResult.scope, collectedAtValue)
|
|
2447
|
+
: undefined;
|
|
944
2448
|
notifyNewData(deps.syncManager);
|
|
2449
|
+
// The parsed body is the envelope's `data`, which is where a producer
|
|
2450
|
+
// stamps `$pdpp`. Offered here rather than inside the ingest contract
|
|
2451
|
+
// so the import stays strictly after the record is durable.
|
|
2452
|
+
await importIngestedIntoPdpp(deps, {
|
|
2453
|
+
scope: scopeResult.scope,
|
|
2454
|
+
collectedAt: collectedAtValue,
|
|
2455
|
+
data: parsed.body,
|
|
2456
|
+
});
|
|
945
2457
|
notifyDataWritten(deps, {
|
|
946
2458
|
scope: scopeResult.scope,
|
|
947
2459
|
collectedAt: collectedAtValue,
|
|
948
2460
|
lineageSources: lineage?.sources,
|
|
949
2461
|
});
|
|
950
|
-
return jsonResponse(
|
|
2462
|
+
return jsonResponse(supersedeResult
|
|
2463
|
+
? {
|
|
2464
|
+
...result.response,
|
|
2465
|
+
superseded: supersedeResult.superseded,
|
|
2466
|
+
...(supersedeResult.refused
|
|
2467
|
+
? { supersedeRefused: supersedeResult.refused }
|
|
2468
|
+
: {}),
|
|
2469
|
+
}
|
|
2470
|
+
: result.response, { status: 201 });
|
|
951
2471
|
}
|
|
952
2472
|
catch (err) {
|
|
953
2473
|
// An envelope that reached storage before indexing failed is
|
|
@@ -960,16 +2480,33 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
960
2480
|
error: err.cause instanceof Error
|
|
961
2481
|
? err.cause.message
|
|
962
2482
|
: String(err.cause),
|
|
963
|
-
}, "Envelope
|
|
2483
|
+
}, "Envelope write incomplete after durable commit; boot recovery may finish it");
|
|
964
2484
|
}
|
|
965
2485
|
else if (!committed) {
|
|
966
2486
|
await writeAuth?.releaseProof?.();
|
|
967
2487
|
}
|
|
968
2488
|
throw err;
|
|
969
2489
|
}
|
|
2490
|
+
finally {
|
|
2491
|
+
ingestStamp?.release();
|
|
2492
|
+
}
|
|
970
2493
|
}
|
|
971
2494
|
if (request.method === "DELETE") {
|
|
972
2495
|
await deps.auth.authorizeOwner(request);
|
|
2496
|
+
// A data set is not a connection, and mapping one to streams needs the
|
|
2497
|
+
// bindings (C2). Once the account is switched the connection delete is
|
|
2498
|
+
// the way to erase data, so this refuses every client, one that declares
|
|
2499
|
+
// stream sync included.
|
|
2500
|
+
if (mode === "unknown")
|
|
2501
|
+
return accountModeUnknownResponse();
|
|
2502
|
+
if (mode === "switched") {
|
|
2503
|
+
const control = /^pdpp\.[^.~]+~[0-9a-f]{16}$/.test(scopeParam);
|
|
2504
|
+
if (!control)
|
|
2505
|
+
return switchedDeleteRefusalResponse();
|
|
2506
|
+
const response = errorResponse(409, "STREAM_SYNC_CONTROL_SCOPE", "Delete the connection instead of an individual data scope");
|
|
2507
|
+
response.headers.set("cache-control", "no-store");
|
|
2508
|
+
return response;
|
|
2509
|
+
}
|
|
973
2510
|
const cascade = url.searchParams.get("cascade");
|
|
974
2511
|
if (cascade !== null && cascade !== "lineage") {
|
|
975
2512
|
throw new InvalidCascadeError({ cascade });
|
|
@@ -988,18 +2525,50 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
988
2525
|
// first tombstone). Until that lands the only honest answer is 501.
|
|
989
2526
|
throw new LineageCascadeUnavailableError({ scope: parsed.scope });
|
|
990
2527
|
}
|
|
2528
|
+
// A canonical-owned scope's latest body is its connection's rows. No
|
|
2529
|
+
// store seam deletes one legacy scope's rows (streams can be shared,
|
|
2530
|
+
// and the account and its generation are the unit of erasure), so a
|
|
2531
|
+
// 200 here would leave the data readable. Refuse before any gateway or
|
|
2532
|
+
// file change; the connection's own delete erases its rows.
|
|
2533
|
+
if (deps.legacyScopeView?.ownsScope(parsed.scope)) {
|
|
2534
|
+
return jsonResponse({
|
|
2535
|
+
error: "CANONICAL_DELETE_UNSUPPORTED",
|
|
2536
|
+
message: `Scope "${parsed.scope}" has connector records that this route cannot delete. Nothing was deleted; delete the connection to erase its records.`,
|
|
2537
|
+
scope: parsed.scope,
|
|
2538
|
+
}, { status: 409 });
|
|
2539
|
+
}
|
|
991
2540
|
// Durable order: gateway tombstone -> storage blobs -> local copy. The
|
|
992
2541
|
// sync manager owns the remote ports; without one (sync disabled or
|
|
993
2542
|
// no owner key material) only the local copy goes and the result says
|
|
994
2543
|
// so (`durable: false`) rather than pretending.
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
2544
|
+
//
|
|
2545
|
+
// The mode decision and the delete are one `commit`: on a switched
|
|
2546
|
+
// account a legacy-only delete would report "deleted" while the stream
|
|
2547
|
+
// rows stay readable, so it is refused (409) and the connector delete is
|
|
2548
|
+
// the way to erase. An unknown mode (or a storage with no seal) is a
|
|
2549
|
+
// retryable 503. An On cannot land between the decision and the delete.
|
|
2550
|
+
const seal = deps.storage.legacyWriteSeal;
|
|
2551
|
+
if (!seal)
|
|
2552
|
+
return accountModeUnknownResponse();
|
|
2553
|
+
let result;
|
|
2554
|
+
try {
|
|
2555
|
+
result = deps.syncManager?.deleteScope
|
|
2556
|
+
? await deps.syncManager.deleteScope(parsed.scope, seal.commit.bind(seal))
|
|
2557
|
+
: await seal.commit((hold) => deleteScopeLocally({
|
|
2558
|
+
storage: deps.storage,
|
|
2559
|
+
serverOwner: deps.serverOwner,
|
|
2560
|
+
deleteData: null,
|
|
2561
|
+
logger: apiLoggerAsLogger(deps.logger),
|
|
2562
|
+
}, parsed.scope, { hold }));
|
|
2563
|
+
}
|
|
2564
|
+
catch (err) {
|
|
2565
|
+
if (err instanceof LegacyWriteRefusedError) {
|
|
2566
|
+
return err.verdict === "switched"
|
|
2567
|
+
? switchedDeleteRefusalResponse()
|
|
2568
|
+
: err.response;
|
|
2569
|
+
}
|
|
2570
|
+
throw err;
|
|
2571
|
+
}
|
|
1003
2572
|
if (result.steps.gateway.status === "failed") {
|
|
1004
2573
|
// Nothing was deleted: the local copy is kept on purpose so sync
|
|
1005
2574
|
// cannot resurrect a half-deleted scope. Surface it as an upstream
|
|
@@ -1043,7 +2612,7 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1043
2612
|
return jsonResponse(result, { status: 200 });
|
|
1044
2613
|
}
|
|
1045
2614
|
return methodNotAllowed();
|
|
1046
|
-
});
|
|
2615
|
+
}, logContext);
|
|
1047
2616
|
}
|
|
1048
2617
|
export async function handlePersonalServerAccessLogsRequest(request, deps, options = {}) {
|
|
1049
2618
|
return withApiErrors(async () => {
|
|
@@ -1069,7 +2638,9 @@ export async function handlePersonalServerSyncRequest(request, deps, options = {
|
|
|
1069
2638
|
if (request.method !== "POST")
|
|
1070
2639
|
return methodNotAllowed();
|
|
1071
2640
|
await deps.auth.authorizeOwner(request);
|
|
1072
|
-
return contractResponse(await triggerSyncContract(deps.syncManager
|
|
2641
|
+
return contractResponse(await triggerSyncContract(deps.syncManager, {
|
|
2642
|
+
whenChanged: url.searchParams.get("when") === "changed",
|
|
2643
|
+
}));
|
|
1073
2644
|
}
|
|
1074
2645
|
if (pathname === "/status") {
|
|
1075
2646
|
if (request.method !== "GET")
|
|
@@ -1089,6 +2660,9 @@ export async function handlePersonalServerSyncRequest(request, deps, options = {
|
|
|
1089
2660
|
}));
|
|
1090
2661
|
}
|
|
1091
2662
|
return notFound();
|
|
2663
|
+
}, {
|
|
2664
|
+
logger: deps.logger,
|
|
2665
|
+
route: `${request.method} ${options.basePath ?? "/v1/sync"}`,
|
|
1092
2666
|
});
|
|
1093
2667
|
}
|
|
1094
2668
|
export async function handlePersonalServerGrantsRequest(request, deps, options = {}) {
|
|
@@ -1210,4 +2784,7 @@ export async function handlePersonalServerOauthTokenRequest(request, deps) {
|
|
|
1210
2784
|
});
|
|
1211
2785
|
});
|
|
1212
2786
|
}
|
|
2787
|
+
export { handleOuraCollectionRequirementsRequest, readOuraCollectionRequirements, OURA_LEGACY_TAKEOVER_CONTRACT, } from "./oura-collection-requirements.js";
|
|
2788
|
+
export { createScopeUploadRegistry, ScopeUploadError, SCOPE_UPLOAD_MAX_BATCH_BYTES, SCOPE_UPLOAD_IDLE_TIMEOUT_MS, } from "./scope-uploads.js";
|
|
2789
|
+
export { prepareScopeUploadBatches, } from "./scope-upload-batches.js";
|
|
1213
2790
|
//# sourceMappingURL=index.js.map
|