@opendatalabs/personal-server-ts-core 1.37.0 → 1.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/host-contract.json +115 -0
- package/contracts/raw-end.json +2360 -0
- package/contracts/replace-conformance.json +729 -0
- package/contracts/routes.json +349 -0
- package/contracts/run-finish-plan.json +3238 -0
- package/contracts/run-saved.json +1308 -0
- package/contracts/scope-delete-receipt.json +616 -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 +139 -3
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +973 -191
- 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/owner-connector-delete.d.ts +103 -0
- package/dist/api/owner-connector-delete.d.ts.map +1 -0
- package/dist/api/owner-connector-delete.js +158 -0
- package/dist/api/owner-connector-delete.js.map +1 -0
- package/dist/api/pdpp-record-query.d.ts +25 -0
- package/dist/api/pdpp-record-query.d.ts.map +1 -0
- package/dist/api/pdpp-record-query.js +72 -0
- package/dist/api/pdpp-record-query.js.map +1 -0
- package/dist/api/pdpp-records-list.d.ts +133 -0
- package/dist/api/pdpp-records-list.d.ts.map +1 -0
- package/dist/api/pdpp-records-list.js +380 -0
- package/dist/api/pdpp-records-list.js.map +1 -0
- package/dist/api/scope-delete-verdict.d.ts +107 -0
- package/dist/api/scope-delete-verdict.d.ts.map +1 -0
- package/dist/api/scope-delete-verdict.js +92 -0
- package/dist/api/scope-delete-verdict.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/client.d.ts +29 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +34 -2
- package/dist/client.js.map +1 -1
- package/dist/contracts/access-logs.d.ts +1 -0
- package/dist/contracts/access-logs.d.ts.map +1 -1
- package/dist/contracts/access-logs.js +7 -1
- package/dist/contracts/access-logs.js.map +1 -1
- package/dist/contracts/data.d.ts +12 -0
- package/dist/contracts/data.d.ts.map +1 -1
- package/dist/contracts/data.js +30 -1
- package/dist/contracts/data.js.map +1 -1
- package/dist/contracts/grants.d.ts.map +1 -1
- package/dist/contracts/grants.js +9 -0
- package/dist/contracts/grants.js.map +1 -1
- package/dist/contracts/index.d.ts +1 -1
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +1 -1
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/sync.d.ts +9 -1
- package/dist/contracts/sync.d.ts.map +1 -1
- package/dist/contracts/sync.js +6 -2
- package/dist/contracts/sync.js.map +1 -1
- package/dist/derivatives/compute.d.ts.map +1 -1
- package/dist/derivatives/compute.js +19 -0
- package/dist/derivatives/compute.js.map +1 -1
- package/dist/encoding/base64url.d.ts +6 -0
- package/dist/encoding/base64url.d.ts.map +1 -0
- package/dist/encoding/base64url.js +29 -0
- package/dist/encoding/base64url.js.map +1 -0
- package/dist/errors/pdpp-catalog.d.ts +1 -1
- package/dist/errors/pdpp-catalog.d.ts.map +1 -1
- package/dist/errors/pdpp-catalog.js +6 -0
- package/dist/errors/pdpp-catalog.js.map +1 -1
- 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.map +1 -1
- package/dist/legacy-projection/bindings.js +10 -4
- package/dist/legacy-projection/bindings.js.map +1 -1
- 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/index.d.ts +17 -0
- package/dist/legacy-projection/index.d.ts.map +1 -1
- package/dist/legacy-projection/index.js +41 -0
- package/dist/legacy-projection/index.js.map +1 -1
- package/dist/legacy-projection/types.d.ts +12 -2
- package/dist/legacy-projection/types.d.ts.map +1 -1
- 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/admit.d.ts +138 -0
- package/dist/localdb/admit.d.ts.map +1 -0
- package/dist/localdb/admit.js +344 -0
- package/dist/localdb/admit.js.map +1 -0
- package/dist/localdb/apply-meter.d.ts +14 -0
- package/dist/localdb/apply-meter.d.ts.map +1 -0
- package/dist/localdb/apply-meter.js +31 -0
- package/dist/localdb/apply-meter.js.map +1 -0
- package/dist/localdb/apply-progress.d.ts +10 -0
- package/dist/localdb/apply-progress.d.ts.map +1 -0
- package/dist/localdb/apply-progress.js +39 -0
- package/dist/localdb/apply-progress.js.map +1 -0
- package/dist/localdb/apply.d.ts +17 -0
- package/dist/localdb/apply.d.ts.map +1 -0
- package/dist/localdb/apply.js +291 -0
- package/dist/localdb/apply.js.map +1 -0
- package/dist/localdb/batch-commit.d.ts +70 -0
- package/dist/localdb/batch-commit.d.ts.map +1 -0
- package/dist/localdb/batch-commit.js +91 -0
- package/dist/localdb/batch-commit.js.map +1 -0
- package/dist/localdb/batch-contract.d.ts +19 -0
- package/dist/localdb/batch-contract.d.ts.map +1 -0
- package/dist/localdb/batch-contract.js +24 -0
- package/dist/localdb/batch-contract.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-copy.d.ts +6 -0
- package/dist/localdb/bootstrap-copy.d.ts.map +1 -0
- package/dist/localdb/bootstrap-copy.js +79 -0
- package/dist/localdb/bootstrap-copy.js.map +1 -0
- package/dist/localdb/bootstrap-keys.d.ts +33 -0
- package/dist/localdb/bootstrap-keys.d.ts.map +1 -0
- package/dist/localdb/bootstrap-keys.js +89 -0
- package/dist/localdb/bootstrap-keys.js.map +1 -0
- package/dist/localdb/bootstrap-swap.d.ts +17 -0
- package/dist/localdb/bootstrap-swap.d.ts.map +1 -0
- package/dist/localdb/bootstrap-swap.js +78 -0
- package/dist/localdb/bootstrap-swap.js.map +1 -0
- package/dist/localdb/bootstrap.d.ts +55 -0
- package/dist/localdb/bootstrap.d.ts.map +1 -0
- package/dist/localdb/bootstrap.js +195 -0
- package/dist/localdb/bootstrap.js.map +1 -0
- package/dist/localdb/complete-read.d.ts +77 -0
- package/dist/localdb/complete-read.d.ts.map +1 -0
- package/dist/localdb/complete-read.js +136 -0
- package/dist/localdb/complete-read.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 +79 -0
- package/dist/localdb/connection-link.js.map +1 -0
- package/dist/localdb/cursor.d.ts +61 -0
- package/dist/localdb/cursor.d.ts.map +1 -0
- package/dist/localdb/cursor.js +178 -0
- package/dist/localdb/cursor.js.map +1 -0
- package/dist/localdb/cycle.d.ts +69 -0
- package/dist/localdb/cycle.d.ts.map +1 -0
- package/dist/localdb/cycle.js +189 -0
- package/dist/localdb/cycle.js.map +1 -0
- package/dist/localdb/delete-batch.d.ts +29 -0
- package/dist/localdb/delete-batch.d.ts.map +1 -0
- package/dist/localdb/delete-batch.js +84 -0
- package/dist/localdb/delete-batch.js.map +1 -0
- package/dist/localdb/delete-lifetime.d.ts +24 -0
- package/dist/localdb/delete-lifetime.d.ts.map +1 -0
- package/dist/localdb/delete-lifetime.js +83 -0
- package/dist/localdb/delete-lifetime.js.map +1 -0
- package/dist/localdb/delete.d.ts +88 -0
- package/dist/localdb/delete.d.ts.map +1 -0
- package/dist/localdb/delete.js +521 -0
- package/dist/localdb/delete.js.map +1 -0
- package/dist/localdb/delta-apply.d.ts +4 -0
- package/dist/localdb/delta-apply.d.ts.map +1 -0
- package/dist/localdb/delta-apply.js +253 -0
- package/dist/localdb/delta-apply.js.map +1 -0
- package/dist/localdb/deps.d.ts +87 -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 +51 -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/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 +76 -0
- package/dist/localdb/history.d.ts.map +1 -0
- package/dist/localdb/history.js +256 -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 +42 -0
- package/dist/localdb/index.d.ts.map +1 -0
- package/dist/localdb/index.js +40 -0
- package/dist/localdb/index.js.map +1 -0
- package/dist/localdb/legacy-import-types.d.ts +112 -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 +67 -0
- package/dist/localdb/legacy-import.d.ts.map +1 -0
- package/dist/localdb/legacy-import.js +320 -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.d.ts +29 -0
- package/dist/localdb/lifetime.d.ts.map +1 -0
- package/dist/localdb/lifetime.js +64 -0
- package/dist/localdb/lifetime.js.map +1 -0
- package/dist/localdb/listing.d.ts +70 -0
- package/dist/localdb/listing.d.ts.map +1 -0
- package/dist/localdb/listing.js +345 -0
- package/dist/localdb/listing.js.map +1 -0
- package/dist/localdb/log-apply.d.ts +46 -0
- package/dist/localdb/log-apply.d.ts.map +1 -0
- package/dist/localdb/log-apply.js +827 -0
- package/dist/localdb/log-apply.js.map +1 -0
- package/dist/localdb/log-batch.d.ts +204 -0
- package/dist/localdb/log-batch.d.ts.map +1 -0
- package/dist/localdb/log-batch.js +418 -0
- package/dist/localdb/log-batch.js.map +1 -0
- package/dist/localdb/log-bodies.d.ts +27 -0
- package/dist/localdb/log-bodies.d.ts.map +1 -0
- package/dist/localdb/log-bodies.js +142 -0
- package/dist/localdb/log-bodies.js.map +1 -0
- package/dist/localdb/log-bootstrap-stage.d.ts +5 -0
- package/dist/localdb/log-bootstrap-stage.d.ts.map +1 -0
- package/dist/localdb/log-bootstrap-stage.js +60 -0
- package/dist/localdb/log-bootstrap-stage.js.map +1 -0
- package/dist/localdb/log-bootstrap.d.ts +23 -0
- package/dist/localdb/log-bootstrap.d.ts.map +1 -0
- package/dist/localdb/log-bootstrap.js +399 -0
- package/dist/localdb/log-bootstrap.js.map +1 -0
- package/dist/localdb/log-compact.d.ts +28 -0
- package/dist/localdb/log-compact.d.ts.map +1 -0
- package/dist/localdb/log-compact.js +83 -0
- package/dist/localdb/log-compact.js.map +1 -0
- package/dist/localdb/log-keyed.d.ts +118 -0
- package/dist/localdb/log-keyed.d.ts.map +1 -0
- package/dist/localdb/log-keyed.js +640 -0
- package/dist/localdb/log-keyed.js.map +1 -0
- package/dist/localdb/log-progressive.d.ts +18 -0
- package/dist/localdb/log-progressive.d.ts.map +1 -0
- package/dist/localdb/log-progressive.js +58 -0
- package/dist/localdb/log-progressive.js.map +1 -0
- package/dist/localdb/log-publish-phases.d.ts +31 -0
- package/dist/localdb/log-publish-phases.d.ts.map +1 -0
- package/dist/localdb/log-publish-phases.js +40 -0
- package/dist/localdb/log-publish-phases.js.map +1 -0
- package/dist/localdb/log-publish.d.ts +16 -0
- package/dist/localdb/log-publish.d.ts.map +1 -0
- package/dist/localdb/log-publish.js +1745 -0
- package/dist/localdb/log-publish.js.map +1 -0
- package/dist/localdb/log-rebase.d.ts +12 -0
- package/dist/localdb/log-rebase.d.ts.map +1 -0
- package/dist/localdb/log-rebase.js +74 -0
- package/dist/localdb/log-rebase.js.map +1 -0
- package/dist/localdb/log-recommit.d.ts +15 -0
- package/dist/localdb/log-recommit.d.ts.map +1 -0
- package/dist/localdb/log-recommit.js +88 -0
- package/dist/localdb/log-recommit.js.map +1 -0
- package/dist/localdb/log-seed.d.ts +25 -0
- package/dist/localdb/log-seed.d.ts.map +1 -0
- package/dist/localdb/log-seed.js +129 -0
- package/dist/localdb/log-seed.js.map +1 -0
- package/dist/localdb/log-state.d.ts +34 -0
- package/dist/localdb/log-state.d.ts.map +1 -0
- package/dist/localdb/log-state.js +79 -0
- package/dist/localdb/log-state.js.map +1 -0
- package/dist/localdb/merge.d.ts +122 -0
- package/dist/localdb/merge.d.ts.map +1 -0
- package/dist/localdb/merge.js +339 -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 +10 -0
- package/dist/localdb/name.d.ts.map +1 -0
- package/dist/localdb/name.js +15 -0
- package/dist/localdb/name.js.map +1 -0
- package/dist/localdb/open.d.ts +33 -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 +6 -0
- package/dist/localdb/part-layout.d.ts.map +1 -0
- package/dist/localdb/part-layout.js +6 -0
- package/dist/localdb/part-layout.js.map +1 -0
- package/dist/localdb/part-readahead.d.ts +87 -0
- package/dist/localdb/part-readahead.d.ts.map +1 -0
- package/dist/localdb/part-readahead.js +130 -0
- package/dist/localdb/part-readahead.js.map +1 -0
- package/dist/localdb/partial-load.d.ts +42 -0
- package/dist/localdb/partial-load.d.ts.map +1 -0
- package/dist/localdb/partial-load.js +120 -0
- package/dist/localdb/partial-load.js.map +1 -0
- package/dist/localdb/partial-read.d.ts +64 -0
- package/dist/localdb/partial-read.d.ts.map +1 -0
- package/dist/localdb/partial-read.js +110 -0
- package/dist/localdb/partial-read.js.map +1 -0
- package/dist/localdb/plan-inputs.d.ts +31 -0
- package/dist/localdb/plan-inputs.d.ts.map +1 -0
- package/dist/localdb/plan-inputs.js +26 -0
- package/dist/localdb/plan-inputs.js.map +1 -0
- package/dist/localdb/publication-work.d.ts +20 -0
- package/dist/localdb/publication-work.d.ts.map +1 -0
- package/dist/localdb/publication-work.js +60 -0
- package/dist/localdb/publication-work.js.map +1 -0
- package/dist/localdb/publish-meter.d.ts +32 -0
- package/dist/localdb/publish-meter.d.ts.map +1 -0
- package/dist/localdb/publish-meter.js +36 -0
- package/dist/localdb/publish-meter.js.map +1 -0
- package/dist/localdb/publish.d.ts +153 -0
- package/dist/localdb/publish.d.ts.map +1 -0
- package/dist/localdb/publish.js +329 -0
- package/dist/localdb/publish.js.map +1 -0
- package/dist/localdb/purge.d.ts +40 -0
- package/dist/localdb/purge.d.ts.map +1 -0
- package/dist/localdb/purge.js +159 -0
- package/dist/localdb/purge.js.map +1 -0
- package/dist/localdb/query.d.ts +77 -0
- package/dist/localdb/query.d.ts.map +1 -0
- package/dist/localdb/query.js +330 -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/raw-end-evidence.d.ts +16 -0
- package/dist/localdb/raw-end-evidence.d.ts.map +1 -0
- package/dist/localdb/raw-end-evidence.js +27 -0
- package/dist/localdb/raw-end-evidence.js.map +1 -0
- package/dist/localdb/read-selection.d.ts +182 -0
- package/dist/localdb/read-selection.d.ts.map +1 -0
- package/dist/localdb/read-selection.js +290 -0
- package/dist/localdb/read-selection.js.map +1 -0
- package/dist/localdb/registered-read.d.ts +15 -0
- package/dist/localdb/registered-read.d.ts.map +1 -0
- package/dist/localdb/registered-read.js +62 -0
- package/dist/localdb/registered-read.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 +69 -0
- package/dist/localdb/resolve.d.ts.map +1 -0
- package/dist/localdb/resolve.js +436 -0
- package/dist/localdb/resolve.js.map +1 -0
- package/dist/localdb/run-end.d.ts +35 -0
- package/dist/localdb/run-end.d.ts.map +1 -0
- package/dist/localdb/run-end.js +520 -0
- package/dist/localdb/run-end.js.map +1 -0
- package/dist/localdb/run-intake.d.ts +17 -0
- package/dist/localdb/run-intake.d.ts.map +1 -0
- package/dist/localdb/run-intake.js +662 -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 +686 -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/stream-digest.d.ts +35 -0
- package/dist/localdb/stream-digest.d.ts.map +1 -0
- package/dist/localdb/stream-digest.js +50 -0
- package/dist/localdb/stream-digest.js.map +1 -0
- package/dist/localdb/sync.d.ts +75 -0
- package/dist/localdb/sync.d.ts.map +1 -0
- package/dist/localdb/sync.js +339 -0
- package/dist/localdb/sync.js.map +1 -0
- package/dist/localdb/system-stream-descriptor.d.ts +22 -0
- package/dist/localdb/system-stream-descriptor.d.ts.map +1 -0
- package/dist/localdb/system-stream-descriptor.js +24 -0
- package/dist/localdb/system-stream-descriptor.js.map +1 -0
- package/dist/localdb/system-stream-page.d.ts +15 -0
- package/dist/localdb/system-stream-page.d.ts.map +1 -0
- package/dist/localdb/system-stream-page.js +98 -0
- package/dist/localdb/system-stream-page.js.map +1 -0
- package/dist/localdb/system-streams.d.ts +35 -0
- package/dist/localdb/system-streams.d.ts.map +1 -0
- package/dist/localdb/system-streams.js +350 -0
- package/dist/localdb/system-streams.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 +28 -0
- package/dist/localdb/unwrite.d.ts.map +1 -0
- package/dist/localdb/unwrite.js +62 -0
- package/dist/localdb/unwrite.js.map +1 -0
- package/dist/localdb/update-required.d.ts +10 -0
- package/dist/localdb/update-required.d.ts.map +1 -0
- package/dist/localdb/update-required.js +27 -0
- package/dist/localdb/update-required.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/logging/access-log.d.ts +2 -2
- package/dist/logging/access-log.d.ts.map +1 -1
- package/dist/logging/access-reader.d.ts +4 -1
- package/dist/logging/access-reader.d.ts.map +1 -1
- package/dist/logging/activity-stream.d.ts +37 -0
- package/dist/logging/activity-stream.d.ts.map +1 -0
- package/dist/logging/activity-stream.js +86 -0
- package/dist/logging/activity-stream.js.map +1 -0
- package/dist/mcp/approval-url.d.ts +32 -0
- package/dist/mcp/approval-url.d.ts.map +1 -1
- package/dist/mcp/approval-url.js +76 -0
- package/dist/mcp/approval-url.js.map +1 -1
- package/dist/mcp/connection-api.d.ts +54 -27
- package/dist/mcp/connection-api.d.ts.map +1 -1
- package/dist/mcp/connection-api.js +267 -77
- 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/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/read-client.d.ts +32 -10
- package/dist/mcp/read-client.d.ts.map +1 -1
- package/dist/mcp/read-client.js +299 -15
- 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 +11 -2
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/server.d.ts +17 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +54 -7
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session.d.ts +2 -0
- package/dist/mcp/session.d.ts.map +1 -1
- package/dist/mcp/session.js +41 -8
- package/dist/mcp/session.js.map +1 -1
- package/dist/mcp/store.d.ts +14 -1
- package/dist/mcp/store.d.ts.map +1 -1
- package/dist/mcp/store.js +31 -2
- package/dist/mcp/store.js.map +1 -1
- package/dist/mcp/tools.d.ts +62 -0
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +186 -64
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +3 -1
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/oura/index.d.ts +1 -1
- package/dist/oura/index.d.ts.map +1 -1
- package/dist/oura/index.js +15 -0
- package/dist/oura/index.js.map +1 -1
- package/dist/payment/x402.d.ts +6 -3
- package/dist/payment/x402.d.ts.map +1 -1
- package/dist/payment/x402.js +35 -0
- package/dist/payment/x402.js.map +1 -1
- package/dist/pdpp/pkce.d.ts +1 -22
- package/dist/pdpp/pkce.d.ts.map +1 -1
- package/dist/pdpp/pkce.js +3 -2
- package/dist/pdpp/pkce.js.map +1 -1
- package/dist/policy/reserved-scopes.d.ts +3 -0
- package/dist/policy/reserved-scopes.d.ts.map +1 -1
- package/dist/policy/reserved-scopes.js +12 -1
- package/dist/policy/reserved-scopes.js.map +1 -1
- package/dist/ports/index.d.ts +61 -9
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js.map +1 -1
- package/dist/publication/publish.d.ts +31 -1
- package/dist/publication/publish.d.ts.map +1 -1
- package/dist/publication/publish.js +30 -14
- package/dist/publication/publish.js.map +1 -1
- package/dist/replication/copies.d.ts +1 -1
- package/dist/replication/dpv2.d.ts.map +1 -1
- package/dist/replication/dpv2.js +33 -0
- package/dist/replication/dpv2.js.map +1 -1
- package/dist/schemas/server-config.d.ts +16 -0
- package/dist/schemas/server-config.d.ts.map +1 -1
- package/dist/schemas/server-config.js +49 -0
- package/dist/schemas/server-config.js.map +1 -1
- package/dist/storage/adapters/interface.d.ts +12 -2
- package/dist/storage/adapters/interface.d.ts.map +1 -1
- package/dist/storage/adapters/interface.js.map +1 -1
- package/dist/storage/adapters/rate-limit-policy.d.ts +71 -0
- package/dist/storage/adapters/rate-limit-policy.d.ts.map +1 -0
- package/dist/storage/adapters/rate-limit-policy.js +107 -0
- package/dist/storage/adapters/rate-limit-policy.js.map +1 -0
- package/dist/storage/adapters/sdk.d.ts +7 -0
- package/dist/storage/adapters/sdk.d.ts.map +1 -1
- package/dist/storage/adapters/sdk.js +12 -6
- 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 +4 -1
- package/dist/storage/adapters/vana-audience.d.ts.map +1 -1
- package/dist/storage/adapters/vana-audience.js +23 -11
- package/dist/storage/adapters/vana-audience.js.map +1 -1
- package/dist/storage/adapters/vana.d.ts +5 -0
- package/dist/storage/adapters/vana.d.ts.map +1 -1
- package/dist/storage/adapters/vana.js +82 -18
- package/dist/storage/adapters/vana.js.map +1 -1
- package/dist/storage/blocks/cursor.d.ts.map +1 -1
- package/dist/storage/blocks/cursor.js +3 -13
- package/dist/storage/blocks/cursor.js.map +1 -1
- package/dist/storage/canonical-legacy-projection.d.ts +13 -1
- package/dist/storage/canonical-legacy-projection.d.ts.map +1 -1
- package/dist/storage/canonical-legacy-projection.js +92 -24
- package/dist/storage/canonical-legacy-projection.js.map +1 -1
- 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 +19 -5
- package/dist/storage/index/manager.d.ts.map +1 -1
- package/dist/storage/legacy-scope-view.d.ts +4 -6
- package/dist/storage/legacy-scope-view.d.ts.map +1 -1
- package/dist/storage/legacy-scope-view.js +50 -57
- package/dist/storage/legacy-scope-view.js.map +1 -1
- 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 +74 -0
- package/dist/storage/legacy-write-seal.js.map +1 -0
- package/dist/storage/pdpp-records/cursor.d.ts.map +1 -1
- package/dist/storage/pdpp-records/cursor.js +3 -29
- package/dist/storage/pdpp-records/cursor.js.map +1 -1
- package/dist/storage/pdpp-records/declaration-witness.d.ts.map +1 -1
- package/dist/storage/pdpp-records/declaration-witness.js +4 -3
- package/dist/storage/pdpp-records/declaration-witness.js.map +1 -1
- package/dist/storage/pdpp-records/types.d.ts +2 -0
- package/dist/storage/pdpp-records/types.d.ts.map +1 -1
- package/dist/storage/pdpp-records/types.js.map +1 -1
- 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 +179 -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 +30 -0
- package/dist/stream-sync/crypto-port.d.ts.map +1 -0
- package/dist/stream-sync/crypto-port.js +29 -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/design-flags.d.ts +31 -0
- package/dist/stream-sync/design-flags.d.ts.map +1 -0
- package/dist/stream-sync/design-flags.js +44 -0
- package/dist/stream-sync/design-flags.js.map +1 -0
- package/dist/stream-sync/host-contract.d.ts +50 -0
- package/dist/stream-sync/host-contract.d.ts.map +1 -0
- package/dist/stream-sync/host-contract.js +80 -0
- package/dist/stream-sync/host-contract.js.map +1 -0
- package/dist/stream-sync/index.d.ts +19 -0
- package/dist/stream-sync/index.d.ts.map +1 -0
- package/dist/stream-sync/index.js +19 -0
- package/dist/stream-sync/index.js.map +1 -0
- package/dist/stream-sync/intake.d.ts +319 -0
- package/dist/stream-sync/intake.d.ts.map +1 -0
- package/dist/stream-sync/intake.js +62 -0
- package/dist/stream-sync/intake.js.map +1 -0
- package/dist/stream-sync/memory-registry.d.ts +85 -0
- package/dist/stream-sync/memory-registry.d.ts.map +1 -0
- package/dist/stream-sync/memory-registry.js +293 -0
- package/dist/stream-sync/memory-registry.js.map +1 -0
- package/dist/stream-sync/normalize-raw-end.d.ts +25 -0
- package/dist/stream-sync/normalize-raw-end.d.ts.map +1 -0
- package/dist/stream-sync/normalize-raw-end.js +177 -0
- package/dist/stream-sync/normalize-raw-end.js.map +1 -0
- package/dist/stream-sync/ports.d.ts +486 -0
- package/dist/stream-sync/ports.d.ts.map +1 -0
- package/dist/stream-sync/ports.js +91 -0
- package/dist/stream-sync/ports.js.map +1 -0
- package/dist/stream-sync/publish-plan.d.ts +129 -0
- package/dist/stream-sync/publish-plan.d.ts.map +1 -0
- package/dist/stream-sync/publish-plan.js +134 -0
- package/dist/stream-sync/publish-plan.js.map +1 -0
- package/dist/stream-sync/raw-end.d.ts +59 -0
- package/dist/stream-sync/raw-end.d.ts.map +1 -0
- package/dist/stream-sync/raw-end.js +113 -0
- package/dist/stream-sync/raw-end.js.map +1 -0
- package/dist/stream-sync/registry.d.ts +31 -0
- package/dist/stream-sync/registry.d.ts.map +1 -0
- package/dist/stream-sync/registry.js +645 -0
- package/dist/stream-sync/registry.js.map +1 -0
- package/dist/stream-sync/run-finish-plan.d.ts +61 -0
- package/dist/stream-sync/run-finish-plan.d.ts.map +1 -0
- package/dist/stream-sync/run-finish-plan.js +373 -0
- package/dist/stream-sync/run-finish-plan.js.map +1 -0
- package/dist/stream-sync/run-saved.d.ts +51 -0
- package/dist/stream-sync/run-saved.d.ts.map +1 -0
- package/dist/stream-sync/run-saved.js +83 -0
- package/dist/stream-sync/run-saved.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/semver.d.ts +3 -0
- package/dist/stream-sync/semver.d.ts.map +1 -0
- package/dist/stream-sync/semver.js +49 -0
- package/dist/stream-sync/semver.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 +216 -0
- package/dist/stream-sync/storage-retry.d.ts.map +1 -0
- package/dist/stream-sync/storage-retry.js +315 -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/timer.d.ts +3 -0
- package/dist/stream-sync/timer.d.ts.map +1 -0
- package/dist/stream-sync/timer.js +3 -0
- package/dist/stream-sync/timer.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 +281 -0
- package/dist/stream-sync-read/service.d.ts.map +1 -0
- package/dist/stream-sync-read/service.js +18 -0
- package/dist/stream-sync-read/service.js.map +1 -0
- package/dist/sync/account-mode/authority.d.ts +121 -0
- package/dist/sync/account-mode/authority.d.ts.map +1 -0
- package/dist/sync/account-mode/authority.js +446 -0
- package/dist/sync/account-mode/authority.js.map +1 -0
- package/dist/sync/account-mode/evidence-wire.d.ts +42 -0
- package/dist/sync/account-mode/evidence-wire.d.ts.map +1 -0
- package/dist/sync/account-mode/evidence-wire.js +76 -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 +54 -0
- package/dist/sync/account-mode/record.d.ts.map +1 -0
- package/dist/sync/account-mode/record.js +62 -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/engine/change-probe.d.ts +49 -0
- package/dist/sync/engine/change-probe.d.ts.map +1 -0
- package/dist/sync/engine/change-probe.js +84 -0
- package/dist/sync/engine/change-probe.js.map +1 -0
- package/dist/sync/engine/change-push.d.ts +56 -0
- package/dist/sync/engine/change-push.d.ts.map +1 -0
- package/dist/sync/engine/change-push.js +176 -0
- package/dist/sync/engine/change-push.js.map +1 -0
- package/dist/sync/engine/sync-manager.d.ts +208 -1
- package/dist/sync/engine/sync-manager.d.ts.map +1 -1
- package/dist/sync/engine/sync-manager.js +1005 -34
- package/dist/sync/engine/sync-manager.js.map +1 -1
- package/dist/sync/index.d.ts +6 -2
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +5 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/pdpp-import.d.ts +12 -2
- package/dist/sync/pdpp-import.d.ts.map +1 -1
- package/dist/sync/pdpp-import.js +32 -7
- package/dist/sync/pdpp-import.js.map +1 -1
- package/dist/sync/tombstone-resubmits.d.ts +7 -4
- package/dist/sync/tombstone-resubmits.d.ts.map +1 -1
- package/dist/sync/tombstone-resubmits.js.map +1 -1
- package/dist/sync/types.d.ts +29 -0
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/sync/upload-attempts.d.ts +244 -0
- package/dist/sync/upload-attempts.d.ts.map +1 -0
- package/dist/sync/upload-attempts.js +548 -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 +33 -1
- package/dist/sync/workers/delete.d.ts.map +1 -1
- package/dist/sync/workers/delete.js +83 -11
- package/dist/sync/workers/delete.js.map +1 -1
- package/dist/sync/workers/download.d.ts +3 -0
- package/dist/sync/workers/download.d.ts.map +1 -1
- package/dist/sync/workers/download.js +67 -12
- package/dist/sync/workers/download.js.map +1 -1
- package/dist/sync/workers/upload.d.ts +70 -2
- package/dist/sync/workers/upload.d.ts.map +1 -1
- package/dist/sync/workers/upload.js +354 -23
- 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 +78 -0
- package/dist/test-utils/account-mode.js.map +1 -0
- package/dist/test-utils/index.d.ts +3 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/index.js +3 -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 +17 -1
- package/dist/test-utils/memory-storage.d.ts.map +1 -1
- package/dist/test-utils/memory-storage.js +94 -46
- package/dist/test-utils/memory-storage.js.map +1 -1
- package/dist/test-utils/run-end.d.ts +27 -0
- package/dist/test-utils/run-end.d.ts.map +1 -0
- package/dist/test-utils/run-end.js +44 -0
- package/dist/test-utils/run-end.js.map +1 -0
- package/dist/test-utils/wallet.d.ts +0 -4
- package/dist/test-utils/wallet.d.ts.map +1 -1
- package/dist/test-utils/wallet.js +3 -12
- package/dist/test-utils/wallet.js.map +1 -1
- package/dist/write/attribution.d.ts.map +1 -1
- package/dist/write/attribution.js +2 -4
- package/dist/write/attribution.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 +372 -0
- package/dist-test/localdb/conformance.js.map +1 -0
- package/dist-test/tsconfig.tsbuildinfo +1 -0
- package/package.json +60 -5
package/dist/api/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { gatewayPaymentReasonCode } from "../payment/x402.js";
|
|
2
|
+
import { decodeBase64UrlUtf8 } from "../encoding/base64url.js";
|
|
1
3
|
import { isOwnAppRead } from "../payment/own-app.js";
|
|
2
|
-
import {
|
|
4
|
+
import { HISTORY_PAGE_LIMIT } from "../localdb/history.js";
|
|
5
|
+
import { isReservedSystemScope, isSystemScope, } from "../policy/reserved-scopes.js";
|
|
3
6
|
import { DataDeletedError, DeleteTombstoneFailedError, GrantRequiredError, InvalidCascadeError, LineageCascadeUnavailableError, LineageGatewayError, LineageUnavailableError, ProtocolError, ServerNotConfiguredError, } from "../errors/catalog.js";
|
|
4
7
|
import { computeDataPointId } from "../sync/data-point-id.js";
|
|
5
8
|
import { isEntryCoveredByTombstone, } from "../sync/scope-deletions.js";
|
|
6
9
|
import { isPermanentRejection, } from "../sync/pdpp-import.js";
|
|
7
10
|
import { supersedeLegacyVersions, } from "../storage/legacy-projection.js";
|
|
8
11
|
import { deleteScope as deleteScopeLocally, } from "../sync/workers/delete.js";
|
|
9
|
-
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, sha256Hex, } from "../contracts/index.js";
|
|
12
|
+
import { ingestDataContract, ingestBinaryDataContract, listAccessLogsContract, listDataScopesContract, listDataVersionsContract, parseDataReadScopeContract, parseDataScopeContract, parseJsonObjectBody, readDataContract, syncFileContract, triggerSyncContract, getSyncStatusContract, configReadErrorContract, configWriteErrorContract, createGrantContract, listGrantsContract, oauthTokenContract, revokeGrantContract, validateServerConfigContract, verifyGrantContract, decodeBinaryEnvelope, isBinaryEnvelope, parseMetadataHeader, stringifyMetadataHeader, IngestPersistedError, sha256Hex, } from "../contracts/index.js";
|
|
10
13
|
import { canonicalJsonBytes } from "../derivatives/e2ee/jcs.js";
|
|
11
14
|
// Imported directly: the contracts barrel does not re-export this addition.
|
|
12
15
|
import { summarizeDataAdditionsContract } from "../contracts/data.js";
|
|
@@ -14,6 +17,9 @@ import { scopeCoveredByGrant } from "@opendatalabs/vana-sdk/browser";
|
|
|
14
17
|
import { WRITER_ATTRIBUTION_KEY, } from "../write/attribution.js";
|
|
15
18
|
import { extractLineageField, LINEAGE_KEY, prepareLineage, } from "../lineage/lineage.js";
|
|
16
19
|
import { ScopeUploadError } from "./scope-uploads.js";
|
|
20
|
+
import { accountModeUnknownResponse, } from "./account-storage-mode.js";
|
|
21
|
+
import { LegacyWriteRefusedError, refuseLegacyWrite, updateRequiredResponse, } from "./legacy-write-gate.js";
|
|
22
|
+
import { switchedDeleteRefusalResponse } from "./switched-delete-refusal.js";
|
|
17
23
|
import { deletionHistoryOf, } from "../storage/legacy-scope-view.js";
|
|
18
24
|
import { binaryFilename, binaryMimeType, isJsonContentType, } from "../contracts/binary.js";
|
|
19
25
|
import { buildChallenge, parsePaymentHeader, verifyPayment, } from "../payment/index.js";
|
|
@@ -71,20 +77,259 @@ async function supersedeAfterCommit(deps, scope, committedAt) {
|
|
|
71
77
|
return { superseded: [], refused: "superseding failed" };
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
|
-
function contractErrorResponse(err) {
|
|
75
|
-
return jsonResponse(err.body, {
|
|
80
|
+
function contractErrorResponse(err, notes) {
|
|
81
|
+
return jsonResponse(withOwnerBody(err.body, notes), {
|
|
82
|
+
status: err.status,
|
|
83
|
+
headers: ownerNoteHeaders(notes),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** What only the owner is told when the existing path answers a stream read. */
|
|
87
|
+
function ownerNoteHeaders(notes) {
|
|
88
|
+
const headers = {};
|
|
89
|
+
if (notes?.withheld?.length) {
|
|
90
|
+
headers["X-Stream-Sync-Withheld"] = withheldReasons(notes.withheld);
|
|
91
|
+
}
|
|
92
|
+
if (notes?.pending) {
|
|
93
|
+
headers["X-Stream-Sync-Pending"] = String(notes.pending.runs);
|
|
94
|
+
}
|
|
95
|
+
if (notes?.awaitingImport) {
|
|
96
|
+
headers["X-Stream-Sync-Awaiting-Import"] = String(notes.awaitingImport.runs);
|
|
97
|
+
}
|
|
98
|
+
if (notes?.notReflected) {
|
|
99
|
+
headers["X-Stream-Sync-Not-Reflected"] = String(notes.notReflected.streams);
|
|
100
|
+
}
|
|
101
|
+
return headers;
|
|
102
|
+
}
|
|
103
|
+
function withOwnerBody(body, notes) {
|
|
104
|
+
return notes?.withheld?.length ? { ...body, withheld: notes.withheld } : body;
|
|
76
105
|
}
|
|
77
106
|
function protocolErrorResponse(err) {
|
|
78
107
|
return jsonResponse(err.toJSON(), { status: err.code });
|
|
79
108
|
}
|
|
80
|
-
function errorResponse(status, errorCode, message) {
|
|
81
|
-
return jsonResponse({
|
|
109
|
+
function errorResponse(status, errorCode, message, notes) {
|
|
110
|
+
return jsonResponse(withOwnerBody({
|
|
82
111
|
error: {
|
|
83
112
|
code: status,
|
|
84
113
|
errorCode,
|
|
85
114
|
message,
|
|
86
115
|
},
|
|
87
|
-
}, { status });
|
|
116
|
+
}, notes), { status, headers: ownerNoteHeaders(notes) });
|
|
117
|
+
}
|
|
118
|
+
function legacyMutationRefusal(mode) {
|
|
119
|
+
if (mode === "unknown")
|
|
120
|
+
return accountModeUnknownResponse();
|
|
121
|
+
if (mode === "switched")
|
|
122
|
+
return updateRequiredResponse();
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
const readAbortedBody = () => ({
|
|
126
|
+
error: {
|
|
127
|
+
code: 503,
|
|
128
|
+
errorCode: "READ_ABORTED",
|
|
129
|
+
message: "This read ended before payment",
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
/** The response for a stream-sync decision that serves nothing; `null` otherwise. */
|
|
133
|
+
function streamSyncRefusal(decision) {
|
|
134
|
+
switch (decision.kind) {
|
|
135
|
+
case "read_aborted":
|
|
136
|
+
return jsonResponse(readAbortedBody(), { status: 503 });
|
|
137
|
+
case "read_not_registered":
|
|
138
|
+
return jsonResponse({
|
|
139
|
+
error: {
|
|
140
|
+
code: 503,
|
|
141
|
+
errorCode: "READ_NOT_REGISTERED",
|
|
142
|
+
message: "This data has not been registered; retry the read",
|
|
143
|
+
},
|
|
144
|
+
}, { status: 503, headers: { "Retry-After": "5" } });
|
|
145
|
+
case "invalid_binding":
|
|
146
|
+
return errorResponse(503, "INVALID_BINDING", "This legacy scope has no required stream");
|
|
147
|
+
case "unavailable":
|
|
148
|
+
return decision.reason === "connection_not_found"
|
|
149
|
+
? errorResponse(404, "CONNECTION_NOT_FOUND", "No connection of this name's connector matches the connection parameter", decision)
|
|
150
|
+
: null;
|
|
151
|
+
case "key_mismatch":
|
|
152
|
+
return errorResponse(503, "KEY_MISMATCH", "This data was written with another owner key and cannot be read here");
|
|
153
|
+
case "cursor_stale":
|
|
154
|
+
return errorResponse(409, "CURSOR_STALE", "The cursor names a version this server no longer holds; read again without it");
|
|
155
|
+
case "busy":
|
|
156
|
+
return jsonResponse({
|
|
157
|
+
error: {
|
|
158
|
+
code: 503,
|
|
159
|
+
errorCode: "STREAM_SYNC_READ_BUSY",
|
|
160
|
+
message: "This data is changing; read again shortly",
|
|
161
|
+
},
|
|
162
|
+
}, {
|
|
163
|
+
status: 503,
|
|
164
|
+
headers: { "Retry-After": String(decision.retryAfterSeconds) },
|
|
165
|
+
});
|
|
166
|
+
case "invalid_cursor":
|
|
167
|
+
return errorResponse(400, "INVALID_CURSOR", "cursor is not valid");
|
|
168
|
+
case "invalid_connection":
|
|
169
|
+
return errorResponse(400, "INVALID_CONNECTION", "connection must be empty or 16 lowercase hex characters");
|
|
170
|
+
case "incomplete":
|
|
171
|
+
// The flag-off refusal (`legacyViewRefusalResponse`), with the rows named.
|
|
172
|
+
return jsonResponse({
|
|
173
|
+
error: "CANONICAL_VIEW_UNAVAILABLE",
|
|
174
|
+
message: "The latest data for this scope cannot be served from the owner's connector records (canonical_view_incomplete).",
|
|
175
|
+
status: "incomplete",
|
|
176
|
+
reason: "canonical_view_incomplete",
|
|
177
|
+
diagnostics: decision.diagnostics,
|
|
178
|
+
}, { status: 503 });
|
|
179
|
+
case "too_large":
|
|
180
|
+
return errorResponse(503, "TOO_LARGE", "This legacy view is larger than this server can build; read its streams instead");
|
|
181
|
+
default:
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* An in-process stream read is checked against the body it will serve. The
|
|
187
|
+
* view is read in full first, so the check and the served bytes are one body.
|
|
188
|
+
* Without a check the stream passes through unchanged.
|
|
189
|
+
*/
|
|
190
|
+
async function validateStreamBody(decision, inProcess) {
|
|
191
|
+
if (!inProcess?.validateBody)
|
|
192
|
+
return decision;
|
|
193
|
+
const text = await new Response(decision.body).text();
|
|
194
|
+
let body;
|
|
195
|
+
try {
|
|
196
|
+
body = JSON.parse(text);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
throw new ProtocolError(422, "NOT_BLOCK_READABLE", "The stream view has no JSON body to read as blocks.");
|
|
200
|
+
}
|
|
201
|
+
await inProcess.validateBody(body, { fromStreamView: true });
|
|
202
|
+
return { ...decision, body: new Response(text).body };
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The body, with its source told to stop when the request is aborted. A
|
|
206
|
+
* response body reaches its source only when its consumer cancels it, and a
|
|
207
|
+
* consumer that has gone away (an aborted fetch, a closed page) may never do
|
|
208
|
+
* so; the abort signal is the one thing it leaves behind.
|
|
209
|
+
*/
|
|
210
|
+
function cancelOnAbort(body, signal) {
|
|
211
|
+
const reader = body.getReader();
|
|
212
|
+
const stop = () => {
|
|
213
|
+
reader.cancel(signal.reason).catch(() => undefined);
|
|
214
|
+
};
|
|
215
|
+
if (signal.aborted)
|
|
216
|
+
stop();
|
|
217
|
+
else
|
|
218
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
219
|
+
return new ReadableStream({
|
|
220
|
+
async pull(controller) {
|
|
221
|
+
try {
|
|
222
|
+
const next = await reader.read();
|
|
223
|
+
if (next.done) {
|
|
224
|
+
signal.removeEventListener("abort", stop);
|
|
225
|
+
controller.close();
|
|
226
|
+
}
|
|
227
|
+
else
|
|
228
|
+
controller.enqueue(next.value);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
signal.removeEventListener("abort", stop);
|
|
232
|
+
controller.error(error);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
cancel(reason) {
|
|
236
|
+
signal.removeEventListener("abort", stop);
|
|
237
|
+
return reader.cancel(reason);
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Serve a stream view: the envelope streams part by part. A charged read
|
|
243
|
+
* has already paid (`paymentResponseHeader`).
|
|
244
|
+
*/
|
|
245
|
+
async function serveStreamSyncView(deps, request, input) {
|
|
246
|
+
const { authResult, decision, inProcess } = input;
|
|
247
|
+
const logId = deps.createLogId?.() ?? crypto.randomUUID();
|
|
248
|
+
const timestamp = (deps.now ?? (() => new Date()))().toISOString();
|
|
249
|
+
const ipAddress = request.headers.get("x-forwarded-for") ??
|
|
250
|
+
request.headers.get("x-real-ip") ??
|
|
251
|
+
"unknown";
|
|
252
|
+
const userAgent = request.headers.get("user-agent") ?? "unknown";
|
|
253
|
+
if (inProcess?.logAccess !== false) {
|
|
254
|
+
try {
|
|
255
|
+
await deps.accessLogWriter.write({
|
|
256
|
+
logId,
|
|
257
|
+
grantId: authResult?.grantId ?? input.grantId ?? "unknown",
|
|
258
|
+
builder: authResult?.builder ?? "unknown",
|
|
259
|
+
action: "read",
|
|
260
|
+
scope: input.scope,
|
|
261
|
+
timestamp,
|
|
262
|
+
ipAddress,
|
|
263
|
+
userAgent,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
await decision.body.cancel();
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (authResult?.grantId && authResult.builder) {
|
|
272
|
+
const served = {
|
|
273
|
+
builder: authResult.builder,
|
|
274
|
+
fileId: undefined,
|
|
275
|
+
grantId: authResult.grantId,
|
|
276
|
+
ipAddress,
|
|
277
|
+
logId,
|
|
278
|
+
outcome: "served",
|
|
279
|
+
scope: input.scope,
|
|
280
|
+
servedAt: timestamp,
|
|
281
|
+
source: "api",
|
|
282
|
+
userAgent,
|
|
283
|
+
};
|
|
284
|
+
// An in-process caller decides completion itself, after any paging.
|
|
285
|
+
if (inProcess) {
|
|
286
|
+
inProcess.onServed({
|
|
287
|
+
scope: input.scope,
|
|
288
|
+
builder: authResult.builder,
|
|
289
|
+
grantId: authResult.grantId,
|
|
290
|
+
fileId: undefined,
|
|
291
|
+
logId,
|
|
292
|
+
ipAddress,
|
|
293
|
+
servedAt: timestamp,
|
|
294
|
+
userAgent,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
reportPersonalServerReadFulfillment(deps, served);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// A projection can fail after the 200 status. The client must then see
|
|
302
|
+
// the connection abort, never a complete shorter body. Chunked framing
|
|
303
|
+
// also keeps @hono/node-server from reading the body ahead of the status:
|
|
304
|
+
// a failure in that read-ahead would end the response with a
|
|
305
|
+
// content-length of the bytes read so far, as if it were whole.
|
|
306
|
+
return new Response(cancelOnAbort(decision.body, request.signal), {
|
|
307
|
+
status: 200,
|
|
308
|
+
headers: {
|
|
309
|
+
"Content-Type": "application/json",
|
|
310
|
+
"Transfer-Encoding": "chunked",
|
|
311
|
+
"X-Vana-Data-Source": "stream-sync",
|
|
312
|
+
"X-Stream-Sync-Cursor": decision.cursor,
|
|
313
|
+
// Owner only: the service attaches this to no other audience.
|
|
314
|
+
...(decision.withheld?.length
|
|
315
|
+
? { "X-Stream-Sync-Withheld": withheldReasons(decision.withheld) }
|
|
316
|
+
: {}),
|
|
317
|
+
// Present only while a first load is still applying parts: the body is
|
|
318
|
+
// the rows applied so far, `<parts applied>/<parts>`. Owner reads only.
|
|
319
|
+
...(decision.partial
|
|
320
|
+
? {
|
|
321
|
+
"X-Stream-Sync-Partial": `${decision.partial.partsApplied}/${decision.partial.partsTotal}`,
|
|
322
|
+
}
|
|
323
|
+
: {}),
|
|
324
|
+
...(input.paymentResponseHeader
|
|
325
|
+
? { "X-PAYMENT-RESPONSE": input.paymentResponseHeader }
|
|
326
|
+
: {}),
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/** The distinct reasons of the withheld runs, for the response header. */
|
|
331
|
+
function withheldReasons(withheld) {
|
|
332
|
+
return [...new Set(withheld.map((w) => w.reason))].join(",");
|
|
88
333
|
}
|
|
89
334
|
function methodNotAllowed() {
|
|
90
335
|
return errorResponse(405, "METHOD_NOT_ALLOWED", "Method not allowed");
|
|
@@ -107,6 +352,12 @@ async function withApiErrors(handler, context) {
|
|
|
107
352
|
if (err instanceof ProtocolError) {
|
|
108
353
|
return protocolErrorResponse(err);
|
|
109
354
|
}
|
|
355
|
+
// A durable step refused by the legacy-write seal (the account switched,
|
|
356
|
+
// or its mode is not known) after the route's early check passed. The
|
|
357
|
+
// answer is the same 426 or 503 the early check gives, never a 500.
|
|
358
|
+
if (err instanceof LegacyWriteRefusedError) {
|
|
359
|
+
return err.response;
|
|
360
|
+
}
|
|
110
361
|
if (context) {
|
|
111
362
|
context.logger?.error?.({
|
|
112
363
|
route: context.route,
|
|
@@ -201,6 +452,140 @@ function listAuthCovers(listAuth, scope) {
|
|
|
201
452
|
return (!isSystemScope(scope) &&
|
|
202
453
|
scopeCoveredByGrant(scope, [...listAuth.grantedScopes]));
|
|
203
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* Whether the app reading is the data owner's own app, which is exempt from
|
|
457
|
+
* the read fee. `false` when no Account authority is configured or the read
|
|
458
|
+
* is owner-signalled; a `Response` (503) when eligibility cannot be
|
|
459
|
+
* verified, so a read is never served free on missing evidence.
|
|
460
|
+
*/
|
|
461
|
+
async function ownAppReadStatus(deps, authResult) {
|
|
462
|
+
const isOwnerSignal = authResult?.grantId === "owner" || authResult?.grantId === "policy-bypass";
|
|
463
|
+
const builder = authResult?.builder;
|
|
464
|
+
if (!deps.paymentEnabled ||
|
|
465
|
+
isOwnerSignal ||
|
|
466
|
+
!authResult?.grantId ||
|
|
467
|
+
!builder ||
|
|
468
|
+
!deps.ownAppAccountUrl) {
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
const unavailable = () => errorResponse(503, "OWN_APP_ELIGIBILITY_UNAVAILABLE", "Own-app fee eligibility could not be verified");
|
|
472
|
+
if (!deps.serverOwner || !deps.gatewayConfig)
|
|
473
|
+
return unavailable();
|
|
474
|
+
try {
|
|
475
|
+
return await isOwnAppRead({
|
|
476
|
+
accountUrl: deps.ownAppAccountUrl,
|
|
477
|
+
appAddress: builder,
|
|
478
|
+
dataOwner: deps.serverOwner,
|
|
479
|
+
chainId: deps.gatewayConfig.chainId,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
return unavailable();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Whether a read is charged, and with what. Owner-exempt reads (the grantId
|
|
488
|
+
* sentinels "owner" / "policy-bypass") are never charged: there is no
|
|
489
|
+
* payable op to attach the payment to. The grantId paid against is the one
|
|
490
|
+
* verifyDataReadPolicy resolved from the Web3Signed payload (authoritative
|
|
491
|
+
* source), not the URL / header hint, which may be absent when the payload
|
|
492
|
+
* carries it. `null` = served free.
|
|
493
|
+
*/
|
|
494
|
+
function readCharge(deps, scope, authResult, ownAppRead) {
|
|
495
|
+
const isOwnerSignal = authResult?.grantId === "owner" || authResult?.grantId === "policy-bypass";
|
|
496
|
+
const builder = authResult?.builder;
|
|
497
|
+
const resolvedGrantId = !isOwnerSignal && authResult?.grantId ? authResult.grantId : undefined;
|
|
498
|
+
const willCharge = Boolean(deps.paymentEnabled &&
|
|
499
|
+
!isOwnerSignal &&
|
|
500
|
+
!ownAppRead &&
|
|
501
|
+
typeof builder === "string" &&
|
|
502
|
+
builder.startsWith("0x") &&
|
|
503
|
+
resolvedGrantId &&
|
|
504
|
+
deps.gateway &&
|
|
505
|
+
deps.gatewayConfig &&
|
|
506
|
+
deps.gatewayUrl);
|
|
507
|
+
// Diagnostic: makes it explicit why a read is/isn't charged. x402 has
|
|
508
|
+
// many "served free" branches (owner read, payment disabled, missing
|
|
509
|
+
// gateway deps); this surfaces the deciding inputs.
|
|
510
|
+
//
|
|
511
|
+
// Routing: when a logger is wired (the Node server always provides one),
|
|
512
|
+
// log the full detail through it at debug level so the operator's level
|
|
513
|
+
// controls + redaction apply and access metadata (scope/grantId/builder)
|
|
514
|
+
// doesn't unconditionally hit stdout. The browser PS-Lite runtime wires
|
|
515
|
+
// no logger; there we fall back to console but log ONLY the non-identifying
|
|
516
|
+
// decision booleans — never scope/grantId/builder.
|
|
517
|
+
if (deps.logger?.debug) {
|
|
518
|
+
deps.logger.debug({
|
|
519
|
+
scope,
|
|
520
|
+
grantId: authResult?.grantId,
|
|
521
|
+
isOwnerSignal,
|
|
522
|
+
builder,
|
|
523
|
+
resolvedGrantId,
|
|
524
|
+
paymentEnabled: Boolean(deps.paymentEnabled),
|
|
525
|
+
hasGateway: Boolean(deps.gateway),
|
|
526
|
+
hasGatewayConfig: Boolean(deps.gatewayConfig),
|
|
527
|
+
hasGatewayUrl: Boolean(deps.gatewayUrl),
|
|
528
|
+
willCharge,
|
|
529
|
+
}, "[x402-gate] read");
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
console.info("[x402-gate] read", {
|
|
533
|
+
isOwnerSignal,
|
|
534
|
+
paymentEnabled: Boolean(deps.paymentEnabled),
|
|
535
|
+
hasGateway: Boolean(deps.gateway),
|
|
536
|
+
hasGatewayConfig: Boolean(deps.gatewayConfig),
|
|
537
|
+
hasGatewayUrl: Boolean(deps.gatewayUrl),
|
|
538
|
+
willCharge,
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
if (!willCharge ||
|
|
542
|
+
!resolvedGrantId ||
|
|
543
|
+
!deps.gateway ||
|
|
544
|
+
!deps.gatewayConfig ||
|
|
545
|
+
!deps.gatewayUrl) {
|
|
546
|
+
return null;
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
grantId: resolvedGrantId,
|
|
550
|
+
builder: builder,
|
|
551
|
+
gateway: deps.gateway,
|
|
552
|
+
gatewayConfig: deps.gatewayConfig,
|
|
553
|
+
gatewayUrl: deps.gatewayUrl,
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* The X402 step of a charged read: a response to return instead of the
|
|
558
|
+
* body (a fresh 402 challenge, or the gateway's error relayed verbatim so
|
|
559
|
+
* the builder can dispatch on it), or the X-PAYMENT-RESPONSE value to send
|
|
560
|
+
* with the body once the gateway accepted the payment.
|
|
561
|
+
*/
|
|
562
|
+
async function payForRead(deps, request, charge, read) {
|
|
563
|
+
const x402Result = await handleX402Cycle({
|
|
564
|
+
deps,
|
|
565
|
+
request,
|
|
566
|
+
...read,
|
|
567
|
+
...charge,
|
|
568
|
+
});
|
|
569
|
+
if (x402Result.kind === "challenge") {
|
|
570
|
+
return {
|
|
571
|
+
kind: "refused",
|
|
572
|
+
response: jsonResponse(x402Result.body, { status: 402 }),
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
if (x402Result.kind === "gateway-error") {
|
|
576
|
+
return {
|
|
577
|
+
kind: "refused",
|
|
578
|
+
response: jsonResponse(x402Result.body, { status: x402Result.status }),
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
// The gateway's success body goes back to the builder in
|
|
582
|
+
// X-PAYMENT-RESPONSE (canonical X402 convention) so callers can see
|
|
583
|
+
// breakdown / paidAt / paymentNonce without a second gateway round-trip.
|
|
584
|
+
return {
|
|
585
|
+
kind: "paid",
|
|
586
|
+
paymentResponseHeader: encodePaymentResponseHeader(x402Result.payResponse),
|
|
587
|
+
};
|
|
588
|
+
}
|
|
204
589
|
/**
|
|
205
590
|
* Run the X402 dispatch for one read:
|
|
206
591
|
*
|
|
@@ -209,7 +594,7 @@ function listAuthCovers(listAuth, scope) {
|
|
|
209
594
|
* X-PAYMENT valid, forward to gateway succeeds
|
|
210
595
|
* → ok: caller proceeds to read the data
|
|
211
596
|
* X-PAYMENT valid, gateway returns 4xx/5xx
|
|
212
|
-
* → gateway-error:
|
|
597
|
+
* → gateway-error: preserve the gateway's error fields with safe diagnostics so the builder
|
|
213
598
|
* can dispatch (insufficient balance vs. replay vs. race etc.)
|
|
214
599
|
*
|
|
215
600
|
* The gateway POST goes through `fetch` directly (not `gateway.payForOperation`)
|
|
@@ -237,19 +622,30 @@ export async function handleX402Cycle(input) {
|
|
|
237
622
|
};
|
|
238
623
|
}
|
|
239
624
|
// Bind the accessRecord to the entry being served, if it exists and has
|
|
240
|
-
// been registered with DPv2 yet.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
});
|
|
246
|
-
const entryForChallenge = entryRow
|
|
247
|
-
? {
|
|
248
|
-
dataPointId: entryRow.dataPointId,
|
|
625
|
+
// been registered with DPv2 yet. Paid database views supply the log
|
|
626
|
+
// identity whose accepted fold the resolver checked before selecting it.
|
|
627
|
+
const entryRow = input.servedEntry
|
|
628
|
+
? undefined
|
|
629
|
+
: deps.storage.findEntry({
|
|
249
630
|
scope,
|
|
250
|
-
|
|
631
|
+
fileId: input.fileIdParam,
|
|
632
|
+
at: input.atParam,
|
|
633
|
+
});
|
|
634
|
+
const entryForChallenge = input.servedEntry
|
|
635
|
+
? {
|
|
636
|
+
dataPointId: deps.serverOwner
|
|
637
|
+
? computeDataPointId(deps.serverOwner, input.servedEntry.scope)
|
|
638
|
+
: null,
|
|
639
|
+
scope: input.servedEntry.scope,
|
|
640
|
+
version: input.servedEntry.version,
|
|
251
641
|
}
|
|
252
|
-
:
|
|
642
|
+
: entryRow
|
|
643
|
+
? {
|
|
644
|
+
dataPointId: entryRow.dataPointId,
|
|
645
|
+
scope,
|
|
646
|
+
version: entryRow.version,
|
|
647
|
+
}
|
|
648
|
+
: undefined;
|
|
253
649
|
// `grant` is narrowed to non-null above, but that narrowing is not carried
|
|
254
650
|
// into this closure (vana-sdk 3.14.0 made getGrant return `... | null`), so
|
|
255
651
|
// capture the guaranteed-present value via a typed alias for the closure.
|
|
@@ -310,10 +706,20 @@ export async function handleX402Cycle(input) {
|
|
|
310
706
|
if (verify.payment.payload.accessRecord) {
|
|
311
707
|
body["accessRecord"] = verify.payment.payload.accessRecord;
|
|
312
708
|
}
|
|
709
|
+
// Own the final cancellation gate here, after every asynchronous read,
|
|
710
|
+
// projection and signature check and immediately before sending payment.
|
|
711
|
+
if (input.request.signal.aborted) {
|
|
712
|
+
return {
|
|
713
|
+
kind: "gateway-error",
|
|
714
|
+
status: 503,
|
|
715
|
+
body: readAbortedBody(),
|
|
716
|
+
};
|
|
717
|
+
}
|
|
313
718
|
let gatewayRes;
|
|
314
719
|
try {
|
|
315
720
|
gatewayRes = await doFetch(`${gatewayUrl.replace(/\/+$/, "")}/v1/escrow/pay`, {
|
|
316
721
|
method: "POST",
|
|
722
|
+
signal: input.request.signal,
|
|
317
723
|
headers: {
|
|
318
724
|
"Content-Type": "application/json",
|
|
319
725
|
Authorization: `Web3Signed ${verify.payment.payload.signature}`,
|
|
@@ -351,17 +757,33 @@ export async function handleX402Cycle(input) {
|
|
|
351
757
|
catch {
|
|
352
758
|
errorBody = { error: gatewayRes.statusText };
|
|
353
759
|
}
|
|
760
|
+
const reasonCode = gatewayPaymentReasonCode(errorBody);
|
|
761
|
+
deps.logger?.info?.({ scope, grantId: opIdLower, status: gatewayRes.status, reasonCode }, "Gateway rejected X-PAYMENT");
|
|
354
762
|
// 409 (replay or race) and 400 (amount mismatch / shape error) are
|
|
355
763
|
// recoverable with a fresh challenge — the builder re-signs with the
|
|
356
|
-
// new state and retries. 402 (insufficient balance)
|
|
764
|
+
// new state and retries. 402 (insufficient balance) retains its error fields
|
|
357
765
|
// because the builder needs to fix their escrow, not their signature.
|
|
358
766
|
// 5xx is treated like 402-relayed since the personal server can't
|
|
359
767
|
// distinguish "transient" from "permanent" without more info.
|
|
360
768
|
if (gatewayRes.status === 409 || gatewayRes.status === 400) {
|
|
361
|
-
|
|
362
|
-
|
|
769
|
+
return {
|
|
770
|
+
kind: "challenge",
|
|
771
|
+
body: {
|
|
772
|
+
...(await buildFreshChallenge()),
|
|
773
|
+
gatewayStatus: gatewayRes.status,
|
|
774
|
+
gatewayReasonCode: reasonCode,
|
|
775
|
+
},
|
|
776
|
+
};
|
|
363
777
|
}
|
|
364
|
-
return {
|
|
778
|
+
return {
|
|
779
|
+
kind: "gateway-error",
|
|
780
|
+
status: gatewayRes.status,
|
|
781
|
+
body: {
|
|
782
|
+
...(errorBody && typeof errorBody === "object" ? errorBody : {}),
|
|
783
|
+
gatewayStatus: gatewayRes.status,
|
|
784
|
+
gatewayReasonCode: reasonCode,
|
|
785
|
+
},
|
|
786
|
+
};
|
|
365
787
|
}
|
|
366
788
|
const pendingIngestStamps = new WeakMap();
|
|
367
789
|
function reserveIngestStamp(now, storage, scope) {
|
|
@@ -433,7 +855,7 @@ async function parseProducerProvenance(encoded, body) {
|
|
|
433
855
|
if (!encoded)
|
|
434
856
|
return undefined;
|
|
435
857
|
try {
|
|
436
|
-
const value = JSON.parse(
|
|
858
|
+
const value = JSON.parse(decodeBase64UrlUtf8(encoded));
|
|
437
859
|
if (!value ||
|
|
438
860
|
typeof value !== "object" ||
|
|
439
861
|
typeof value.projector_version !== "string" ||
|
|
@@ -656,11 +1078,11 @@ function notifyDataWritten(deps, event) {
|
|
|
656
1078
|
* something this deployment could not verify — actionable, but not a failure
|
|
657
1079
|
* of the write, which has already committed.
|
|
658
1080
|
*/
|
|
659
|
-
function importIngestedIntoPdpp(deps, envelope) {
|
|
1081
|
+
async function importIngestedIntoPdpp(deps, envelope) {
|
|
660
1082
|
if (!deps.pdppImporter)
|
|
661
1083
|
return;
|
|
662
1084
|
try {
|
|
663
|
-
const outcome = deps.pdppImporter.importEnvelope(envelope);
|
|
1085
|
+
const outcome = await deps.pdppImporter.importEnvelope(envelope);
|
|
664
1086
|
if (outcome.status === "rejected") {
|
|
665
1087
|
const permanent = isPermanentRejection(outcome.rejection);
|
|
666
1088
|
deps.logger?.warn?.({
|
|
@@ -840,12 +1262,19 @@ export function redactEnvelopeForGrantee(envelope) {
|
|
|
840
1262
|
return { ...envelope, data };
|
|
841
1263
|
}
|
|
842
1264
|
export { redactJsonEnvelopeBytesForGrantee } from "./raw-envelope.js";
|
|
1265
|
+
export { ACCOUNT_MODE_RETRY_AFTER_SECONDS, ACCOUNT_MODE_UNKNOWN_CODE, ACCOUNT_MODE_UNKNOWN_STATUS, accountModeUnknownResponse, accountStorageModeFor, selectAccountStorageMode, } from "./account-storage-mode.js";
|
|
1266
|
+
export { USE_CONNECTOR_DELETE_CODE, USE_CONNECTOR_DELETE_MESSAGE, USE_CONNECTOR_DELETE_STATUS, switchedDeleteRefusalResponse, } from "./switched-delete-refusal.js";
|
|
1267
|
+
export { STREAM_SYNC_CLIENT_HEADER, UPDATE_REQUIRED_CODE, UPDATE_REQUIRED_MESSAGE, UPDATE_REQUIRED_STATUS, LegacyWriteRefusedError, legacyWriteRefusedErrorFor, refuseLegacyWrite, updateRequiredResponse, } from "./legacy-write-gate.js";
|
|
1268
|
+
export { decideScopeDeletion, } from "./scope-delete-verdict.js";
|
|
1269
|
+
export { handleOwnerConnectorDelete, handleOwnerConnectorLifetime, ownerConnectorRefusal, } from "./owner-connector-delete.js";
|
|
843
1270
|
/**
|
|
844
1271
|
* `/v1/data/:scope/uploads...`: an owner writes one new version of a scope as
|
|
845
1272
|
* a sequence of record batches. The protocol and its guarantees are in
|
|
846
1273
|
* `scope-uploads.ts`; this adds HTTP, owner auth and the post-commit hooks.
|
|
847
1274
|
*/
|
|
848
|
-
async function handleScopeUploadRequest(request, deps, parts, prepared)
|
|
1275
|
+
async function handleScopeUploadRequest(request, deps, parts, prepared, mode = deps.accountStorageMode?.read() ??
|
|
1276
|
+
deps.accountMode?.read(deps.serverOwner) ??
|
|
1277
|
+
"unknown") {
|
|
849
1278
|
const route = (() => {
|
|
850
1279
|
if (parts.length === 2)
|
|
851
1280
|
return { kind: "begin", method: "POST" };
|
|
@@ -863,6 +1292,15 @@ async function handleScopeUploadRequest(request, deps, parts, prepared) {
|
|
|
863
1292
|
if (request.method !== route.method)
|
|
864
1293
|
return methodNotAllowed();
|
|
865
1294
|
await deps.auth.authorizeOwner(request);
|
|
1295
|
+
// A switched account cannot mutate legacy import state, including abort.
|
|
1296
|
+
const modeRefusal = legacyMutationRefusal(mode);
|
|
1297
|
+
if (modeRefusal)
|
|
1298
|
+
return modeRefusal;
|
|
1299
|
+
if (route.kind !== "abort") {
|
|
1300
|
+
const refusal = refuseLegacyWrite(deps.accountStorageMode);
|
|
1301
|
+
if (refusal)
|
|
1302
|
+
return refusal;
|
|
1303
|
+
}
|
|
866
1304
|
const scopeResult = parseDataScopeContract(decodePathPart(parts[0]));
|
|
867
1305
|
if (!scopeResult.ok)
|
|
868
1306
|
return contractErrorResponse(scopeResult);
|
|
@@ -1047,6 +1485,76 @@ function notifyReadGrantee(request, authResult) {
|
|
|
1047
1485
|
// Telemetry only: an observer fault never affects the read.
|
|
1048
1486
|
}
|
|
1049
1487
|
}
|
|
1488
|
+
function historyInteger(value, fallback, name) {
|
|
1489
|
+
if (value === null)
|
|
1490
|
+
return fallback;
|
|
1491
|
+
const parsed = /^\d+$/.test(value) ? Number(value) : Number.NaN;
|
|
1492
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0) {
|
|
1493
|
+
throw new ProtocolError(400, "invalid_request", name + " must be a safe non-negative decimal integer");
|
|
1494
|
+
}
|
|
1495
|
+
return parsed;
|
|
1496
|
+
}
|
|
1497
|
+
/** The account's storage mode as one request freezes it before any read. */
|
|
1498
|
+
function readAccountStorageMode(deps) {
|
|
1499
|
+
return (deps.accountStorageMode?.read() ??
|
|
1500
|
+
deps.accountMode?.read(deps.serverOwner) ??
|
|
1501
|
+
"unknown");
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* One page of every scope this server holds data for, under the filters the
|
|
1505
|
+
* `GET /v1/data` listing applies (tombstones, canonical-only scopes, system
|
|
1506
|
+
* scopes) but with no grant filter. In-process only: the caller must itself
|
|
1507
|
+
* decide who may see the result (MCP exposes it only through `notShared`).
|
|
1508
|
+
*
|
|
1509
|
+
* It takes the same account-mode decision as that listing: a switched account
|
|
1510
|
+
* lists from the stream port and never touches legacy storage; an unknown
|
|
1511
|
+
* account, or a switched one with no stream listing, throws rather than
|
|
1512
|
+
* answering with an empty page.
|
|
1513
|
+
*/
|
|
1514
|
+
export async function listOwnerVisibleScopes(deps, page) {
|
|
1515
|
+
const mode = readAccountStorageMode(deps);
|
|
1516
|
+
if (mode === "unknown") {
|
|
1517
|
+
throw new Error("Owner scope listing unavailable: account mode unknown");
|
|
1518
|
+
}
|
|
1519
|
+
if (mode === "switched") {
|
|
1520
|
+
const listScopes = deps.streamSyncRead?.listScopes;
|
|
1521
|
+
if (!listScopes) {
|
|
1522
|
+
throw new Error("Owner scope listing unavailable: no stream listing");
|
|
1523
|
+
}
|
|
1524
|
+
const listed = await listScopes({
|
|
1525
|
+
canRead: (scope) => !isSystemScope(scope),
|
|
1526
|
+
includeLoading: true,
|
|
1527
|
+
});
|
|
1528
|
+
return {
|
|
1529
|
+
// The stream listing applies the resolver's own selection rule, so a
|
|
1530
|
+
// listed scope is one a read can serve: that is its readiness.
|
|
1531
|
+
scopes: listed
|
|
1532
|
+
.slice(page.offset, page.offset + page.limit)
|
|
1533
|
+
.map((row) => ({
|
|
1534
|
+
scope: row.scope,
|
|
1535
|
+
...(row.latestCollectedAt && {
|
|
1536
|
+
latestCollectedAt: row.latestCollectedAt,
|
|
1537
|
+
}),
|
|
1538
|
+
// A scope whose first load is running serves the rows applied so far.
|
|
1539
|
+
dataStatus: row.dataStatus ?? "ready",
|
|
1540
|
+
})),
|
|
1541
|
+
total: listed.length,
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
const deletionDeadlineAtMs = Date.now() + 250;
|
|
1545
|
+
const result = await listDataScopesContract({
|
|
1546
|
+
storage: deps.storage,
|
|
1547
|
+
limit: page.limit,
|
|
1548
|
+
offset: page.offset,
|
|
1549
|
+
isVisible: listingVisibility(deps, deletionDeadlineAtMs),
|
|
1550
|
+
isListable: (scope) => !isSystemScope(scope),
|
|
1551
|
+
extraScopes: canonicalOnlyScopes(deps, deletionDeadlineAtMs),
|
|
1552
|
+
});
|
|
1553
|
+
return {
|
|
1554
|
+
scopes: result.response.scopes.map((summary) => withCanonicalListing(deps, summary)),
|
|
1555
|
+
total: result.response.total,
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1050
1558
|
export async function handlePersonalServerDataRequest(request, deps, options = {}) {
|
|
1051
1559
|
// Filled in as the dispatch narrows, so a 500 thrown deep in a read is
|
|
1052
1560
|
// logged against the route that served it rather than a generic label. It
|
|
@@ -1058,14 +1566,48 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1058
1566
|
requestId: crypto.randomUUID(),
|
|
1059
1567
|
};
|
|
1060
1568
|
return withApiErrors(async () => {
|
|
1569
|
+
// Freeze the routing decision before consulting any data source.
|
|
1570
|
+
const mode = readAccountStorageMode(deps);
|
|
1061
1571
|
const url = new URL(request.url);
|
|
1062
1572
|
const pathname = stripBasePath(url.pathname, options.basePath);
|
|
1573
|
+
// The account's storage mode, decided once before any list, version,
|
|
1574
|
+
// lineage or body branch. No read site acts on the decision yet (they are
|
|
1575
|
+
// routed through it one by one), so a switched account still reads as
|
|
1576
|
+
// before; it is recorded with every error this request logs.
|
|
1577
|
+
if (request.method === "GET") {
|
|
1578
|
+
logContext.detail = {
|
|
1579
|
+
storageSelection: mode,
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1063
1582
|
if (pathname === "/" || pathname === "") {
|
|
1064
1583
|
if (request.method !== "GET")
|
|
1065
1584
|
return methodNotAllowed();
|
|
1066
1585
|
const listAuth = await deps.auth.authorizeBuilderList(request, {
|
|
1067
1586
|
grantId: selectedGrantId(request, url),
|
|
1068
1587
|
});
|
|
1588
|
+
if (mode === "unknown")
|
|
1589
|
+
return accountModeUnknownResponse();
|
|
1590
|
+
if (mode === "switched") {
|
|
1591
|
+
if (!deps.streamSyncRead?.listScopes)
|
|
1592
|
+
return errorResponse(503, "STREAM_LIST_UNAVAILABLE", "Stream scope listing is not available");
|
|
1593
|
+
const scopes = await deps.streamSyncRead.listScopes({
|
|
1594
|
+
canRead: (scope) => !isSystemScope(scope) &&
|
|
1595
|
+
(!listAuth || listAuthCovers(listAuth, scope)),
|
|
1596
|
+
// No grant on the request: the owner's view, which serves loads in progress.
|
|
1597
|
+
includeLoading: !listAuth,
|
|
1598
|
+
});
|
|
1599
|
+
const prefix = url.searchParams.get("scopePrefix") ?? "";
|
|
1600
|
+
const filtered = scopes.filter((row) => row.scope.startsWith(prefix));
|
|
1601
|
+
const offset = normalizeLimit(url.searchParams.get("offset"), 0);
|
|
1602
|
+
const limit = normalizeLimit(url.searchParams.get("limit"), 20);
|
|
1603
|
+
return jsonResponse({
|
|
1604
|
+
listingStore: "stream-sync",
|
|
1605
|
+
scopes: filtered.slice(offset, offset + limit),
|
|
1606
|
+
total: filtered.length,
|
|
1607
|
+
limit,
|
|
1608
|
+
offset,
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1069
1611
|
// One budget for every stored and canonical-only scope, not per row.
|
|
1070
1612
|
const deletionDeadlineAtMs = Date.now() + 250;
|
|
1071
1613
|
const result = await listDataScopesContract({
|
|
@@ -1080,9 +1622,15 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1080
1622
|
});
|
|
1081
1623
|
return jsonResponse({
|
|
1082
1624
|
...result.response,
|
|
1625
|
+
listingStore: "legacy",
|
|
1083
1626
|
scopes: result.response.scopes.map((summary) => withCanonicalListing(deps, summary)),
|
|
1084
1627
|
});
|
|
1085
1628
|
}
|
|
1629
|
+
// Reserved streams have one dedicated owner API, never ordinary body,
|
|
1630
|
+
// version, lineage or write routes (including raw/stored views).
|
|
1631
|
+
const targetScope = decodePathPart(pathname.split("/").filter(Boolean)[0] ?? "");
|
|
1632
|
+
if (isReservedSystemScope(targetScope))
|
|
1633
|
+
return errorResponse(403, "RESERVED_SCOPE", "System streams are private");
|
|
1086
1634
|
// "additions" has no dot, so it can never be a real scope name (scopes are
|
|
1087
1635
|
// "source.dataset"); handle it before the single-segment scope path.
|
|
1088
1636
|
if (pathname === "/additions") {
|
|
@@ -1090,32 +1638,64 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1090
1638
|
return methodNotAllowed();
|
|
1091
1639
|
// The counts span every scope, so only the owner may read them.
|
|
1092
1640
|
await deps.auth.authorizeOwner(request);
|
|
1641
|
+
if (mode === "unknown")
|
|
1642
|
+
return accountModeUnknownResponse();
|
|
1093
1643
|
const daysRaw = url.searchParams.get("days");
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
:
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1644
|
+
const timezone = url.searchParams.get("tz") ?? "UTC";
|
|
1645
|
+
// Digits only: Number() would also accept "", "1e1", "0x7" and " 7".
|
|
1646
|
+
const days = daysRaw === null
|
|
1647
|
+
? 7
|
|
1648
|
+
: /^\d{1,3}$/.test(daysRaw)
|
|
1649
|
+
? Number(daysRaw)
|
|
1650
|
+
: Number.NaN;
|
|
1651
|
+
if (!Number.isInteger(days) || days < 1 || days > 31) {
|
|
1652
|
+
if (mode === "unswitched")
|
|
1653
|
+
return contractErrorResponse({
|
|
1654
|
+
ok: false,
|
|
1655
|
+
status: 400,
|
|
1656
|
+
body: {
|
|
1657
|
+
error: "INVALID_QUERY",
|
|
1658
|
+
message: "days must be an integer between 1 and 31",
|
|
1659
|
+
},
|
|
1660
|
+
});
|
|
1661
|
+
return errorResponse(400, "invalid_request", "days must be an integer from 1 to 31");
|
|
1662
|
+
}
|
|
1663
|
+
if (mode === "unswitched") {
|
|
1664
|
+
// Preserve the legacy query error contract before any storage access.
|
|
1665
|
+
const result = await summarizeDataAdditionsContract({
|
|
1666
|
+
additions: deps.additions,
|
|
1667
|
+
storage: deps.storage,
|
|
1668
|
+
isVisible: discoveryVisibility(deps),
|
|
1669
|
+
timezone,
|
|
1670
|
+
days,
|
|
1671
|
+
now: (deps.now ?? (() => new Date()))(),
|
|
1672
|
+
});
|
|
1673
|
+
if ("ok" in result)
|
|
1674
|
+
return contractErrorResponse(result);
|
|
1675
|
+
return jsonResponse(result);
|
|
1676
|
+
}
|
|
1677
|
+
if (!deps.history) {
|
|
1678
|
+
return errorResponse(503, "STREAM_SYNC_UNAVAILABLE", "Local history is not available on this server.");
|
|
1679
|
+
}
|
|
1680
|
+
return jsonResponse(await deps.history.additions({ timezone, days }));
|
|
1110
1681
|
}
|
|
1111
1682
|
const parts = pathname.split("/").filter(Boolean);
|
|
1112
1683
|
if (parts.length >= 2 && parts[1] === "uploads") {
|
|
1113
|
-
return await handleScopeUploadRequest(request, deps, parts);
|
|
1684
|
+
return await handleScopeUploadRequest(request, deps, parts, undefined, mode);
|
|
1114
1685
|
}
|
|
1115
1686
|
if (parts.length === 3 && parts[1] === "imports") {
|
|
1116
1687
|
if (request.method !== "PUT")
|
|
1117
1688
|
return methodNotAllowed();
|
|
1118
1689
|
await deps.auth.authorizeOwner(request);
|
|
1690
|
+
const modeRefusal = legacyMutationRefusal(mode);
|
|
1691
|
+
if (modeRefusal)
|
|
1692
|
+
return modeRefusal;
|
|
1693
|
+
// Owner-only: a builder has no durable-import route, so a signature
|
|
1694
|
+
// header earns no exemption here. This runs on the normalized path, so
|
|
1695
|
+
// `/imports/<op>/` and repeated slashes land here too.
|
|
1696
|
+
const refusal = refuseLegacyWrite(deps.accountStorageMode);
|
|
1697
|
+
if (refusal)
|
|
1698
|
+
return refusal;
|
|
1119
1699
|
const scopeResult = parseDataScopeContract(decodePathPart(parts[0]));
|
|
1120
1700
|
if (!scopeResult.ok)
|
|
1121
1701
|
return contractErrorResponse(scopeResult);
|
|
@@ -1185,7 +1765,12 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1185
1765
|
});
|
|
1186
1766
|
// A scope's version history is as much its data as its content is, so
|
|
1187
1767
|
// a non-owner needs a grant covering it, exactly like a read.
|
|
1188
|
-
|
|
1768
|
+
// Switched history reads the stream-sync stream the read route names
|
|
1769
|
+
// (`pdpp.<connector>.<stream>`), so it uses the read rule; legacy history
|
|
1770
|
+
// keeps the strict rule.
|
|
1771
|
+
const scopeResult = mode === "switched"
|
|
1772
|
+
? parseDataReadScopeContract(versionsScopeParam)
|
|
1773
|
+
: parseDataScopeContract(versionsScopeParam);
|
|
1189
1774
|
if (scopeResult.ok &&
|
|
1190
1775
|
listAuth &&
|
|
1191
1776
|
!listAuthCovers(listAuth, scopeResult.scope)) {
|
|
@@ -1194,11 +1779,44 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1194
1779
|
requestedScope: scopeResult.scope,
|
|
1195
1780
|
});
|
|
1196
1781
|
}
|
|
1782
|
+
if (mode !== "switched" && mode !== "unswitched") {
|
|
1783
|
+
return accountModeUnknownResponse();
|
|
1784
|
+
}
|
|
1785
|
+
const limit = Math.min(historyInteger(url.searchParams.get("limit"), 20, "limit"), HISTORY_PAGE_LIMIT);
|
|
1786
|
+
const offset = historyInteger(url.searchParams.get("offset"), 0, "offset");
|
|
1787
|
+
const cursorRaw = url.searchParams.get("cursor");
|
|
1788
|
+
const cursor = cursorRaw === null ? undefined : historyInteger(cursorRaw, 0, "cursor");
|
|
1789
|
+
if (limit < 1 ||
|
|
1790
|
+
cursor === 0 ||
|
|
1791
|
+
(mode === "switched" && offset !== 0) ||
|
|
1792
|
+
(mode === "unswitched" && cursor !== undefined)) {
|
|
1793
|
+
return errorResponse(400, "invalid_request", "Use a positive limit; switched history continues with cursor, not offset");
|
|
1794
|
+
}
|
|
1795
|
+
if (mode === "switched") {
|
|
1796
|
+
if (!scopeResult.ok)
|
|
1797
|
+
return contractErrorResponse(scopeResult);
|
|
1798
|
+
if (!deps.history) {
|
|
1799
|
+
return errorResponse(503, "STREAM_SYNC_UNAVAILABLE", "Local history is not available on this server.");
|
|
1800
|
+
}
|
|
1801
|
+
const result = await deps.history.versions({
|
|
1802
|
+
scope: scopeResult.scope,
|
|
1803
|
+
limit,
|
|
1804
|
+
offset,
|
|
1805
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
1806
|
+
});
|
|
1807
|
+
if (!result.ok) {
|
|
1808
|
+
if (result.reason === "deleted") {
|
|
1809
|
+
throw new DataDeletedError({ scope: scopeResult.scope });
|
|
1810
|
+
}
|
|
1811
|
+
return errorResponse(404, "NOT_FOUND", `Scope "${scopeResult.scope}" has no history`);
|
|
1812
|
+
}
|
|
1813
|
+
return jsonResponse(result.value);
|
|
1814
|
+
}
|
|
1197
1815
|
const result = await listDataVersionsContract({
|
|
1198
1816
|
storage: deps.storage,
|
|
1199
1817
|
scopeParam: decodePathPart(parts[0]),
|
|
1200
|
-
limit
|
|
1201
|
-
offset
|
|
1818
|
+
limit,
|
|
1819
|
+
offset,
|
|
1202
1820
|
isVisible: discoveryVisibility(deps),
|
|
1203
1821
|
});
|
|
1204
1822
|
if (!result.ok)
|
|
@@ -1213,7 +1831,10 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1213
1831
|
if ((parts.length === 2 || parts.length === 3) && parts[1] === "lineage") {
|
|
1214
1832
|
if (request.method !== "GET")
|
|
1215
1833
|
return methodNotAllowed();
|
|
1216
|
-
|
|
1834
|
+
// Like versions: switched lineage names the streams the read route does.
|
|
1835
|
+
const scopeResult = mode === "switched"
|
|
1836
|
+
? parseDataReadScopeContract(decodePathPart(parts[0]))
|
|
1837
|
+
: parseDataScopeContract(decodePathPart(parts[0]));
|
|
1217
1838
|
if (!scopeResult.ok)
|
|
1218
1839
|
return contractErrorResponse(scopeResult);
|
|
1219
1840
|
// The version is a PATH segment (/v1/data/:scope/lineage/:version), so
|
|
@@ -1239,6 +1860,44 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1239
1860
|
scope: scopeResult.scope,
|
|
1240
1861
|
grantId: selectedGrantId(request, url),
|
|
1241
1862
|
});
|
|
1863
|
+
if (mode !== "switched" && mode !== "unswitched") {
|
|
1864
|
+
return accountModeUnknownResponse();
|
|
1865
|
+
}
|
|
1866
|
+
if (mode === "switched") {
|
|
1867
|
+
resolveLineageGrantView(authResult);
|
|
1868
|
+
const historyVersion = version === undefined ? undefined : Number(version);
|
|
1869
|
+
if (historyVersion !== undefined &&
|
|
1870
|
+
!Number.isSafeInteger(historyVersion)) {
|
|
1871
|
+
return errorResponse(400, "INVALID_VERSION", "version must be a safe positive decimal integer");
|
|
1872
|
+
}
|
|
1873
|
+
if (!deps.history) {
|
|
1874
|
+
return errorResponse(503, "STREAM_SYNC_UNAVAILABLE", "Local history is not available on this server.");
|
|
1875
|
+
}
|
|
1876
|
+
const result = await deps.history.lineage({
|
|
1877
|
+
scope: scopeResult.scope,
|
|
1878
|
+
version: historyVersion,
|
|
1879
|
+
});
|
|
1880
|
+
if (!result.ok) {
|
|
1881
|
+
if (result.reason === "deleted") {
|
|
1882
|
+
throw new DataDeletedError({ scope: scopeResult.scope });
|
|
1883
|
+
}
|
|
1884
|
+
return errorResponse(404, "NOT_FOUND", `Scope "${scopeResult.scope}" has no history`);
|
|
1885
|
+
}
|
|
1886
|
+
await deps.accessLogWriter.write({
|
|
1887
|
+
logId: deps.createLogId?.() ?? crypto.randomUUID(),
|
|
1888
|
+
grantId: authResult?.grantId ?? "owner",
|
|
1889
|
+
builder: authResult?.builder ?? "unknown",
|
|
1890
|
+
action: "lineage",
|
|
1891
|
+
scope: scopeResult.scope,
|
|
1892
|
+
timestamp: (deps.now ?? (() => new Date()))().toISOString(),
|
|
1893
|
+
ipAddress: request.headers.get("x-forwarded-for") ??
|
|
1894
|
+
request.headers.get("x-real-ip") ??
|
|
1895
|
+
"unknown",
|
|
1896
|
+
userAgent: request.headers.get("user-agent") ?? "unknown",
|
|
1897
|
+
});
|
|
1898
|
+
const { proof, ...data } = result.value;
|
|
1899
|
+
return jsonResponse({ data, proof });
|
|
1900
|
+
}
|
|
1242
1901
|
if (!deps.serverOwner) {
|
|
1243
1902
|
throw new ServerNotConfiguredError({
|
|
1244
1903
|
reason: "serverOwner is required to resolve the data point id",
|
|
@@ -1300,10 +1959,16 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1300
1959
|
const scopeParam = decodePathPart(parts[0]);
|
|
1301
1960
|
logContext.route = `${request.method} ${options.basePath ?? "/v1/data"}/:scope`;
|
|
1302
1961
|
if (request.method === "GET") {
|
|
1303
|
-
|
|
1962
|
+
// The account mode chooses the read surface, not reader availability.
|
|
1963
|
+
const scopeResult = mode === "switched"
|
|
1964
|
+
? parseDataReadScopeContract(scopeParam)
|
|
1965
|
+
: parseDataScopeContract(scopeParam);
|
|
1304
1966
|
if (!scopeResult.ok)
|
|
1305
1967
|
return contractErrorResponse(scopeResult);
|
|
1306
|
-
logContext.detail = {
|
|
1968
|
+
logContext.detail = {
|
|
1969
|
+
...logContext.detail,
|
|
1970
|
+
scope: scopeResult.scope,
|
|
1971
|
+
};
|
|
1307
1972
|
// An empty `fileId=` or `at=` selects no version: it is the latest
|
|
1308
1973
|
// read, as storage already treats it.
|
|
1309
1974
|
const fileIdParam = url.searchParams.get("fileId") || undefined;
|
|
@@ -1314,30 +1979,156 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1314
1979
|
if (view !== null && view !== "stored") {
|
|
1315
1980
|
return errorResponse(400, "INVALID_VIEW", 'view must be "stored" or absent');
|
|
1316
1981
|
}
|
|
1317
|
-
const selectedEntry =
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1982
|
+
const selectedEntry = mode === "unswitched"
|
|
1983
|
+
? deps.storage.findEntry({
|
|
1984
|
+
scope: scopeResult.scope,
|
|
1985
|
+
fileId: fileIdParam,
|
|
1986
|
+
at: atParam,
|
|
1987
|
+
})
|
|
1988
|
+
: undefined;
|
|
1322
1989
|
// Holds the base64-encoded gateway payForOperation response body when
|
|
1323
1990
|
// X402 succeeds — emitted on the final read response as X-PAYMENT-RESPONSE.
|
|
1324
1991
|
let paymentResponseHeader;
|
|
1325
1992
|
const grantId = selectedGrantId(request, url);
|
|
1326
|
-
const
|
|
1993
|
+
const wantsRawContent = url.searchParams.get("content") === "raw";
|
|
1994
|
+
const inProcess = options.inProcess;
|
|
1995
|
+
// Check the grant without charging before resolving a switched read.
|
|
1996
|
+
// Settlement receives the exact served head, never a legacy lookup.
|
|
1997
|
+
// In-process legacy reads also settle only after their refusal gates.
|
|
1998
|
+
const settleLast = (mode === "switched" || inProcess !== undefined) &&
|
|
1999
|
+
!inProcess?.metadataOnly;
|
|
2000
|
+
const authInput = {
|
|
1327
2001
|
request,
|
|
1328
2002
|
scope: scopeResult.scope,
|
|
1329
2003
|
grantId,
|
|
1330
|
-
|
|
2004
|
+
// Only a file id that resolved inside this scope reaches policy. A
|
|
2005
|
+
// wrong-scope id and a nonexistent one both resolve to nothing, so
|
|
2006
|
+
// neither takes a different path and no foreign id leaves the process.
|
|
2007
|
+
fileId: selectedEntry?.fileId ?? undefined,
|
|
1331
2008
|
at: atParam,
|
|
2009
|
+
};
|
|
2010
|
+
const authResult = await deps.auth.authorizeBuilderRead({
|
|
2011
|
+
...authInput,
|
|
2012
|
+
...(mode === "unknown" || inProcess?.metadataOnly || settleLast
|
|
2013
|
+
? { metadataOnly: true }
|
|
2014
|
+
: {}),
|
|
1332
2015
|
});
|
|
1333
2016
|
notifyReadGrantee(request, authResult);
|
|
2017
|
+
if (mode === "unknown")
|
|
2018
|
+
return accountModeUnknownResponse();
|
|
2019
|
+
// `served` is the stream head the read decision chose and validated.
|
|
2020
|
+
// It is passed through as is: settlement never looks the head up again.
|
|
2021
|
+
const settle = async (served) => {
|
|
2022
|
+
if (!settleLast)
|
|
2023
|
+
return;
|
|
2024
|
+
await deps.auth.authorizeBuilderRead(served ? { ...authInput, servedEntry: served } : authInput);
|
|
2025
|
+
};
|
|
1334
2026
|
// Select the body after auth and before deletion or payment. A file's
|
|
1335
2027
|
// version and re-add marker authorize that file, not canonical rows.
|
|
1336
2028
|
// `?view=stored` asks for the stored file's body, so it never reads the
|
|
1337
2029
|
// canonical view either.
|
|
1338
|
-
const latest =
|
|
2030
|
+
const latest = mode === "unswitched" &&
|
|
2031
|
+
fileIdParam === undefined &&
|
|
2032
|
+
atParam === undefined &&
|
|
2033
|
+
view === null
|
|
1339
2034
|
? await deps.legacyScopeView?.readLatest(scopeResult.scope)
|
|
1340
2035
|
: undefined;
|
|
2036
|
+
// On serves database stream views or a refusal, including historical
|
|
2037
|
+
// selectors. Only Off reaches the separate legacy body path below.
|
|
2038
|
+
const latestRead = fileIdParam === undefined && atParam === undefined && view === null;
|
|
2039
|
+
if (mode === "switched") {
|
|
2040
|
+
let ownerNotes;
|
|
2041
|
+
if (!deps.streamSyncRead) {
|
|
2042
|
+
return errorResponse(503, "STREAM_READ_UNAVAILABLE", "Stream reads are not available");
|
|
2043
|
+
}
|
|
2044
|
+
// No older version has a body to serve: the connection log keeps
|
|
2045
|
+
// none per stream. A selector (`fileId`, `at`, `view=stored`) reads
|
|
2046
|
+
// nothing; a read without one serves the installed records.
|
|
2047
|
+
if (!latestRead)
|
|
2048
|
+
return errorResponse(410, "STREAM_HISTORY_UNAVAILABLE", "Older versions are not available");
|
|
2049
|
+
const ownApp = await ownAppReadStatus(deps, authResult);
|
|
2050
|
+
const charge = ownApp instanceof Response
|
|
2051
|
+
? null
|
|
2052
|
+
: readCharge(deps, scopeResult.scope, authResult, ownApp);
|
|
2053
|
+
const decision = await deps.streamSyncRead.resolve({
|
|
2054
|
+
scope: scopeResult.scope,
|
|
2055
|
+
connection: url.searchParams.get("connection"),
|
|
2056
|
+
cursor: url.searchParams.get("cursor"),
|
|
2057
|
+
legacyFile: false,
|
|
2058
|
+
isOwnerView: isOwnerView(authResult),
|
|
2059
|
+
requireRegistered: charge !== null,
|
|
2060
|
+
signal: request.signal,
|
|
2061
|
+
});
|
|
2062
|
+
if (decision.kind === "local_pending") {
|
|
2063
|
+
await decision.body.cancel();
|
|
2064
|
+
return errorResponse(404, "STREAM_DATA_NOT_FOUND", "No complete stream data is available for this scope", decision);
|
|
2065
|
+
}
|
|
2066
|
+
if (decision.kind === "unavailable" && decision.reason === "deleted") {
|
|
2067
|
+
throw new DataDeletedError({ scope: scopeResult.scope });
|
|
2068
|
+
}
|
|
2069
|
+
if (decision.kind === "pass" ||
|
|
2070
|
+
decision.kind === "legacy" ||
|
|
2071
|
+
decision.kind === "unavailable") {
|
|
2072
|
+
ownerNotes = decision;
|
|
2073
|
+
}
|
|
2074
|
+
const refusal = streamSyncRefusal(decision);
|
|
2075
|
+
if (refusal)
|
|
2076
|
+
return refusal;
|
|
2077
|
+
if (inProcess && wantsRawContent && decision.kind === "view") {
|
|
2078
|
+
// A view has no raw bytes. Refused before any charge, log or
|
|
2079
|
+
// fulfilment, so a caller never pays for a read it cannot use.
|
|
2080
|
+
await decision.body.cancel();
|
|
2081
|
+
return jsonResponse({
|
|
2082
|
+
error: "STREAM_VIEW_NOT_RAW",
|
|
2083
|
+
message: `Scope "${scopeResult.scope}" is served from its stream view, which has no raw binary content.`,
|
|
2084
|
+
scope: scopeResult.scope,
|
|
2085
|
+
}, { status: 409 });
|
|
2086
|
+
}
|
|
2087
|
+
if (decision.kind === "view") {
|
|
2088
|
+
if (ownApp instanceof Response) {
|
|
2089
|
+
await decision.body.cancel();
|
|
2090
|
+
return ownApp;
|
|
2091
|
+
}
|
|
2092
|
+
notifyDataRead(deps, { scope: scopeResult.scope });
|
|
2093
|
+
// The same charge as a file read; the access record binds the
|
|
2094
|
+
// accepted log position covering the view.
|
|
2095
|
+
let paymentResponseHeader;
|
|
2096
|
+
// An owner-only view with no registered head has nothing to
|
|
2097
|
+
// charge against: the service serves it to the owner alone.
|
|
2098
|
+
if (decision.served !== null) {
|
|
2099
|
+
const served = decision.served;
|
|
2100
|
+
if (charge) {
|
|
2101
|
+
let paid;
|
|
2102
|
+
try {
|
|
2103
|
+
paid = await payForRead(deps, request, charge, {
|
|
2104
|
+
scope: scopeResult.scope,
|
|
2105
|
+
servedEntry: served,
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
catch (error) {
|
|
2109
|
+
await decision.body.cancel();
|
|
2110
|
+
throw error;
|
|
2111
|
+
}
|
|
2112
|
+
if (paid.kind === "refused") {
|
|
2113
|
+
await decision.body.cancel();
|
|
2114
|
+
return paid.response;
|
|
2115
|
+
}
|
|
2116
|
+
paymentResponseHeader = paid.paymentResponseHeader;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
const checked = await validateStreamBody(decision, inProcess);
|
|
2120
|
+
await settle(decision.served);
|
|
2121
|
+
return serveStreamSyncView(deps, request, {
|
|
2122
|
+
scope: scopeResult.scope,
|
|
2123
|
+
grantId,
|
|
2124
|
+
authResult,
|
|
2125
|
+
decision: checked,
|
|
2126
|
+
paymentResponseHeader,
|
|
2127
|
+
inProcess,
|
|
2128
|
+
});
|
|
2129
|
+
}
|
|
2130
|
+
return errorResponse(404, "STREAM_DATA_NOT_FOUND", "No complete stream data is available for this scope", ownerNotes);
|
|
2131
|
+
}
|
|
1341
2132
|
// The deletion history comes with the body the view chose, never from
|
|
1342
2133
|
// a later ownership query a concurrent write could change.
|
|
1343
2134
|
const canonicalOwned = latest !== undefined && deletionHistoryOf(latest) === "canonical";
|
|
@@ -1364,126 +2155,29 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1364
2155
|
if (latest?.kind === "refused") {
|
|
1365
2156
|
return legacyViewRefusalResponse(scopeResult.scope, latest.refusal);
|
|
1366
2157
|
}
|
|
1367
|
-
// X402 payment dance for builder reads
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
// header hint, which may be absent when the payload carries it.
|
|
1374
|
-
const isOwnerSignal = authResult?.grantId === "owner" ||
|
|
1375
|
-
authResult?.grantId === "policy-bypass";
|
|
1376
|
-
const builder = authResult?.builder;
|
|
1377
|
-
const resolvedGrantId = !isOwnerSignal && authResult?.grantId ? authResult.grantId : undefined;
|
|
1378
|
-
let ownAppRead = false;
|
|
1379
|
-
if (deps.paymentEnabled &&
|
|
1380
|
-
!isOwnerSignal &&
|
|
1381
|
-
resolvedGrantId &&
|
|
1382
|
-
builder &&
|
|
1383
|
-
deps.ownAppAccountUrl) {
|
|
1384
|
-
if (!deps.serverOwner || !deps.gatewayConfig) {
|
|
1385
|
-
return errorResponse(503, "OWN_APP_ELIGIBILITY_UNAVAILABLE", "Own-app fee eligibility could not be verified");
|
|
1386
|
-
}
|
|
1387
|
-
try {
|
|
1388
|
-
ownAppRead = await isOwnAppRead({
|
|
1389
|
-
accountUrl: deps.ownAppAccountUrl,
|
|
1390
|
-
appAddress: builder,
|
|
1391
|
-
dataOwner: deps.serverOwner,
|
|
1392
|
-
chainId: deps.gatewayConfig.chainId,
|
|
1393
|
-
});
|
|
1394
|
-
}
|
|
1395
|
-
catch {
|
|
1396
|
-
return errorResponse(503, "OWN_APP_ELIGIBILITY_UNAVAILABLE", "Own-app fee eligibility could not be verified");
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
const willCharge = Boolean(deps.paymentEnabled &&
|
|
1400
|
-
!isOwnerSignal &&
|
|
1401
|
-
!ownAppRead &&
|
|
1402
|
-
typeof builder === "string" &&
|
|
1403
|
-
builder.startsWith("0x") &&
|
|
1404
|
-
resolvedGrantId &&
|
|
1405
|
-
deps.gateway &&
|
|
1406
|
-
deps.gatewayConfig &&
|
|
1407
|
-
deps.gatewayUrl);
|
|
1408
|
-
// Diagnostic: makes it explicit why a read is/isn't charged. x402 has
|
|
1409
|
-
// many "served free" branches (owner read, payment disabled, missing
|
|
1410
|
-
// gateway deps); this surfaces the deciding inputs.
|
|
1411
|
-
//
|
|
1412
|
-
// Routing: when a logger is wired (the Node server always provides one),
|
|
1413
|
-
// log the full detail through it at debug level so the operator's level
|
|
1414
|
-
// controls + redaction apply and access metadata (scope/grantId/builder)
|
|
1415
|
-
// doesn't unconditionally hit stdout. The browser PS-Lite runtime wires
|
|
1416
|
-
// no logger; there we fall back to console but log ONLY the non-identifying
|
|
1417
|
-
// decision booleans — never scope/grantId/builder.
|
|
1418
|
-
if (deps.logger?.debug) {
|
|
1419
|
-
deps.logger.debug({
|
|
1420
|
-
scope: scopeResult.scope,
|
|
1421
|
-
grantId: authResult?.grantId,
|
|
1422
|
-
isOwnerSignal,
|
|
1423
|
-
builder,
|
|
1424
|
-
resolvedGrantId,
|
|
1425
|
-
paymentEnabled: Boolean(deps.paymentEnabled),
|
|
1426
|
-
hasGateway: Boolean(deps.gateway),
|
|
1427
|
-
hasGatewayConfig: Boolean(deps.gatewayConfig),
|
|
1428
|
-
hasGatewayUrl: Boolean(deps.gatewayUrl),
|
|
1429
|
-
willCharge,
|
|
1430
|
-
}, "[x402-gate] read");
|
|
1431
|
-
}
|
|
1432
|
-
else {
|
|
1433
|
-
console.info("[x402-gate] read", {
|
|
1434
|
-
isOwnerSignal,
|
|
1435
|
-
paymentEnabled: Boolean(deps.paymentEnabled),
|
|
1436
|
-
hasGateway: Boolean(deps.gateway),
|
|
1437
|
-
hasGatewayConfig: Boolean(deps.gatewayConfig),
|
|
1438
|
-
hasGatewayUrl: Boolean(deps.gatewayUrl),
|
|
1439
|
-
willCharge,
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
if (willCharge && latest?.kind === "canonical") {
|
|
2158
|
+
// X402 payment dance for builder reads (see `readCharge`).
|
|
2159
|
+
const ownApp = await ownAppReadStatus(deps, authResult);
|
|
2160
|
+
if (ownApp instanceof Response)
|
|
2161
|
+
return ownApp;
|
|
2162
|
+
const charge = readCharge(deps, scopeResult.scope, authResult, ownApp);
|
|
2163
|
+
if (charge && latest?.kind === "canonical") {
|
|
1443
2164
|
return legacyViewRefusalResponse(scopeResult.scope, {
|
|
1444
2165
|
status: "unavailable",
|
|
1445
2166
|
reason: "paid_read_unsupported",
|
|
1446
2167
|
});
|
|
1447
2168
|
}
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
if (deps.paymentEnabled &&
|
|
1451
|
-
!isOwnerSignal &&
|
|
1452
|
-
!ownAppRead &&
|
|
1453
|
-
typeof builder === "string" &&
|
|
1454
|
-
builder.startsWith("0x") &&
|
|
1455
|
-
resolvedGrantId &&
|
|
1456
|
-
deps.gateway &&
|
|
1457
|
-
deps.gatewayConfig &&
|
|
1458
|
-
deps.gatewayUrl) {
|
|
1459
|
-
const x402Result = await handleX402Cycle({
|
|
1460
|
-
deps,
|
|
1461
|
-
request,
|
|
2169
|
+
if (charge) {
|
|
2170
|
+
const paid = await payForRead(deps, request, charge, {
|
|
1462
2171
|
scope: scopeResult.scope,
|
|
1463
2172
|
fileIdParam,
|
|
1464
2173
|
atParam,
|
|
1465
|
-
grantId: resolvedGrantId,
|
|
1466
|
-
builder: builder,
|
|
1467
|
-
gateway: deps.gateway,
|
|
1468
|
-
gatewayConfig: deps.gatewayConfig,
|
|
1469
|
-
gatewayUrl: deps.gatewayUrl,
|
|
1470
2174
|
});
|
|
1471
|
-
if (
|
|
1472
|
-
return
|
|
1473
|
-
|
|
1474
|
-
if (x402Result.kind === "gateway-error") {
|
|
1475
|
-
// Relay the gateway's structured body verbatim so the builder can
|
|
1476
|
-
// dispatch on it (insufficient balance vs. replay vs. race etc.).
|
|
1477
|
-
return jsonResponse(x402Result.body, { status: x402Result.status });
|
|
1478
|
-
}
|
|
1479
|
-
// x402Result.kind === "ok" — payment accepted, proceed to read.
|
|
1480
|
-
// The gateway's success body is forwarded back to the builder via
|
|
1481
|
-
// X-PAYMENT-RESPONSE (canonical X402 convention) so callers can see
|
|
1482
|
-
// breakdown / paidAt / paymentNonce without a second gateway round-trip.
|
|
1483
|
-
paymentResponseHeader = encodePaymentResponseHeader(x402Result.payResponse);
|
|
2175
|
+
if (paid.kind === "refused")
|
|
2176
|
+
return paid.response;
|
|
2177
|
+
paymentResponseHeader = paid.paymentResponseHeader;
|
|
1484
2178
|
}
|
|
1485
2179
|
const headers = {};
|
|
1486
|
-
if (
|
|
2180
|
+
if (ownApp)
|
|
1487
2181
|
headers["X-Vana-Payment-Exemption"] = "own-app";
|
|
1488
2182
|
headers["X-Vana-Data-Source"] =
|
|
1489
2183
|
latest?.kind === "canonical" ? "canonical" : "legacy";
|
|
@@ -1497,7 +2191,11 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1497
2191
|
const result = await readDataContract({
|
|
1498
2192
|
storage: deps.storage,
|
|
1499
2193
|
scopeParam: scopeResult.scope,
|
|
1500
|
-
|
|
2194
|
+
// An in-process read names the version it selected above, so the
|
|
2195
|
+
// body served is the version the payment and fulfilment name.
|
|
2196
|
+
fileId: inProcess
|
|
2197
|
+
? (fileIdParam ?? selectedEntry?.fileId ?? undefined)
|
|
2198
|
+
: fileIdParam,
|
|
1501
2199
|
at: atParam,
|
|
1502
2200
|
...(view === "stored" ? { view } : {}),
|
|
1503
2201
|
});
|
|
@@ -1516,6 +2214,30 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1516
2214
|
const servedEnvelope = isOwnerView(authResult)
|
|
1517
2215
|
? envelope
|
|
1518
2216
|
: redactEnvelopeForGrantee(envelope);
|
|
2217
|
+
// An in-process raw read is refused, or decoded, before it pays or logs.
|
|
2218
|
+
// HTTP keeps its order: the same checks run after the access log.
|
|
2219
|
+
let rawBinary;
|
|
2220
|
+
if (inProcess && wantsRawContent) {
|
|
2221
|
+
if (!isBinaryEnvelope(servedEnvelope)) {
|
|
2222
|
+
return jsonResponse({
|
|
2223
|
+
error: "NOT_BINARY_SCOPE",
|
|
2224
|
+
message: `Scope "${scopeResult.scope}" does not expose raw binary content.`,
|
|
2225
|
+
}, { status: 400, headers });
|
|
2226
|
+
}
|
|
2227
|
+
rawBinary = decodeBinaryEnvelope(servedEnvelope);
|
|
2228
|
+
inProcess.onRawSelected?.({
|
|
2229
|
+
fileId: servedFileId,
|
|
2230
|
+
collectedAt: envelope.collectedAt,
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2233
|
+
// A JSON read is checked against the body it will serve, before it pays.
|
|
2234
|
+
if (inProcess && !wantsRawContent) {
|
|
2235
|
+
await inProcess.validateBody?.(servedEnvelope, {
|
|
2236
|
+
fromStreamView: false,
|
|
2237
|
+
});
|
|
2238
|
+
}
|
|
2239
|
+
// Every refusal above has run; only a read that will be served pays.
|
|
2240
|
+
await settle();
|
|
1519
2241
|
const logId = deps.createLogId?.() ?? crypto.randomUUID();
|
|
1520
2242
|
const timestamp = (deps.now ?? (() => new Date()))().toISOString();
|
|
1521
2243
|
const ipAddress = request.headers.get("x-forwarded-for") ??
|
|
@@ -1524,19 +2246,34 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1524
2246
|
const userAgent = request.headers.get("user-agent") ?? "unknown";
|
|
1525
2247
|
const loggedGrantId = authResult?.grantId ?? grantId ?? "unknown";
|
|
1526
2248
|
const loggedBuilder = authResult?.builder ?? "unknown";
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
2249
|
+
if (options.inProcess?.logAccess !== false) {
|
|
2250
|
+
await deps.accessLogWriter.write({
|
|
2251
|
+
logId,
|
|
2252
|
+
grantId: loggedGrantId,
|
|
2253
|
+
builder: loggedBuilder,
|
|
2254
|
+
action: "read",
|
|
2255
|
+
scope: scopeResult.scope,
|
|
2256
|
+
timestamp,
|
|
2257
|
+
ipAddress,
|
|
2258
|
+
userAgent,
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
1537
2261
|
const reportReadFulfillment = () => {
|
|
1538
2262
|
if (!authResult?.grantId || !authResult.builder)
|
|
1539
2263
|
return;
|
|
2264
|
+
if (options.inProcess) {
|
|
2265
|
+
options.inProcess.onServed({
|
|
2266
|
+
scope: scopeResult.scope,
|
|
2267
|
+
builder: authResult.builder,
|
|
2268
|
+
grantId: authResult.grantId,
|
|
2269
|
+
fileId: servedFileId,
|
|
2270
|
+
logId,
|
|
2271
|
+
ipAddress,
|
|
2272
|
+
servedAt: timestamp,
|
|
2273
|
+
userAgent,
|
|
2274
|
+
});
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
1540
2277
|
reportPersonalServerReadFulfillment(deps, {
|
|
1541
2278
|
builder: authResult.builder,
|
|
1542
2279
|
fileId: servedFileId,
|
|
@@ -1553,7 +2290,6 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1553
2290
|
if (paymentResponseHeader) {
|
|
1554
2291
|
headers["X-PAYMENT-RESPONSE"] = paymentResponseHeader;
|
|
1555
2292
|
}
|
|
1556
|
-
const wantsRawContent = url.searchParams.get("content") === "raw";
|
|
1557
2293
|
// `?content=raw` streams the decoded bytes of a binary envelope with its
|
|
1558
2294
|
// original media type, so a builder can download the file directly. The
|
|
1559
2295
|
// X-PAYMENT-RESPONSE header (if any) rides along on the raw response too.
|
|
@@ -1564,7 +2300,7 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1564
2300
|
message: `Scope "${scopeResult.scope}" does not expose raw binary content.`,
|
|
1565
2301
|
}, { status: 400, headers });
|
|
1566
2302
|
}
|
|
1567
|
-
const decoded = decodeBinaryEnvelope(servedEnvelope);
|
|
2303
|
+
const decoded = rawBinary ?? decodeBinaryEnvelope(servedEnvelope);
|
|
1568
2304
|
headers["Content-Type"] = decoded.mimeType;
|
|
1569
2305
|
headers["Content-Length"] = String(decoded.bytes.length);
|
|
1570
2306
|
if (decoded.filename) {
|
|
@@ -1580,7 +2316,9 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1580
2316
|
});
|
|
1581
2317
|
return response;
|
|
1582
2318
|
}
|
|
1583
|
-
const response = jsonResponse(servedEnvelope, {
|
|
2319
|
+
const response = jsonResponse(servedEnvelope, {
|
|
2320
|
+
headers,
|
|
2321
|
+
});
|
|
1584
2322
|
reportReadFulfillment();
|
|
1585
2323
|
return response;
|
|
1586
2324
|
}
|
|
@@ -1598,6 +2336,11 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1598
2336
|
else {
|
|
1599
2337
|
await deps.auth.authorizeOwner(request);
|
|
1600
2338
|
}
|
|
2339
|
+
const modeRefusal = legacyMutationRefusal(mode);
|
|
2340
|
+
if (modeRefusal) {
|
|
2341
|
+
await writeAuth?.releaseProof?.();
|
|
2342
|
+
return modeRefusal;
|
|
2343
|
+
}
|
|
1601
2344
|
// `?supersede=legacy`: once this write commits, delete the scope's
|
|
1602
2345
|
// older legacy-form versions (see supersedeLegacyVersions). It deletes
|
|
1603
2346
|
// data, so only the owner may ask for it.
|
|
@@ -1764,7 +2507,7 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1764
2507
|
// The parsed body is the envelope's `data`, which is where a producer
|
|
1765
2508
|
// stamps `$pdpp`. Offered here rather than inside the ingest contract
|
|
1766
2509
|
// so the import stays strictly after the record is durable.
|
|
1767
|
-
importIngestedIntoPdpp(deps, {
|
|
2510
|
+
await importIngestedIntoPdpp(deps, {
|
|
1768
2511
|
scope: scopeResult.scope,
|
|
1769
2512
|
collectedAt: collectedAtValue,
|
|
1770
2513
|
data: parsed.body,
|
|
@@ -1808,6 +2551,20 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1808
2551
|
}
|
|
1809
2552
|
if (request.method === "DELETE") {
|
|
1810
2553
|
await deps.auth.authorizeOwner(request);
|
|
2554
|
+
// A data set is not a connection, and mapping one to streams needs the
|
|
2555
|
+
// bindings (C2). Once the account is switched the connection delete is
|
|
2556
|
+
// the way to erase data, so this refuses every client, one that declares
|
|
2557
|
+
// stream sync included.
|
|
2558
|
+
if (mode === "unknown")
|
|
2559
|
+
return accountModeUnknownResponse();
|
|
2560
|
+
if (mode === "switched") {
|
|
2561
|
+
const control = /^pdpp\.[^.~]+~[0-9a-f]{16}$/.test(scopeParam);
|
|
2562
|
+
if (!control)
|
|
2563
|
+
return switchedDeleteRefusalResponse();
|
|
2564
|
+
const response = errorResponse(409, "STREAM_SYNC_CONTROL_SCOPE", "Delete the connection instead of an individual data scope");
|
|
2565
|
+
response.headers.set("cache-control", "no-store");
|
|
2566
|
+
return response;
|
|
2567
|
+
}
|
|
1811
2568
|
const cascade = url.searchParams.get("cascade");
|
|
1812
2569
|
if (cascade !== null && cascade !== "lineage") {
|
|
1813
2570
|
throw new InvalidCascadeError({ cascade });
|
|
@@ -1842,14 +2599,34 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1842
2599
|
// sync manager owns the remote ports; without one (sync disabled or
|
|
1843
2600
|
// no owner key material) only the local copy goes and the result says
|
|
1844
2601
|
// so (`durable: false`) rather than pretending.
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
2602
|
+
//
|
|
2603
|
+
// The mode decision and the delete are one `commit`: on a switched
|
|
2604
|
+
// account a legacy-only delete would report "deleted" while the stream
|
|
2605
|
+
// rows stay readable, so it is refused (409) and the connector delete is
|
|
2606
|
+
// the way to erase. An unknown mode (or a storage with no seal) is a
|
|
2607
|
+
// retryable 503. An On cannot land between the decision and the delete.
|
|
2608
|
+
const seal = deps.storage.legacyWriteSeal;
|
|
2609
|
+
if (!seal)
|
|
2610
|
+
return accountModeUnknownResponse();
|
|
2611
|
+
let result;
|
|
2612
|
+
try {
|
|
2613
|
+
result = deps.syncManager?.deleteScope
|
|
2614
|
+
? await deps.syncManager.deleteScope(parsed.scope, seal.commit.bind(seal))
|
|
2615
|
+
: await seal.commit((hold) => deleteScopeLocally({
|
|
2616
|
+
storage: deps.storage,
|
|
2617
|
+
serverOwner: deps.serverOwner,
|
|
2618
|
+
deleteData: null,
|
|
2619
|
+
logger: apiLoggerAsLogger(deps.logger),
|
|
2620
|
+
}, parsed.scope, { hold }));
|
|
2621
|
+
}
|
|
2622
|
+
catch (err) {
|
|
2623
|
+
if (err instanceof LegacyWriteRefusedError) {
|
|
2624
|
+
return err.verdict === "switched"
|
|
2625
|
+
? switchedDeleteRefusalResponse()
|
|
2626
|
+
: err.response;
|
|
2627
|
+
}
|
|
2628
|
+
throw err;
|
|
2629
|
+
}
|
|
1853
2630
|
if (result.steps.gateway.status === "failed") {
|
|
1854
2631
|
// Nothing was deleted: the local copy is kept on purpose so sync
|
|
1855
2632
|
// cannot resurrect a half-deleted scope. Surface it as an upstream
|
|
@@ -1906,6 +2683,7 @@ export async function handlePersonalServerAccessLogsRequest(request, deps, optio
|
|
|
1906
2683
|
await deps.auth.authorizeOwner(request);
|
|
1907
2684
|
return contractResponse(await listAccessLogsContract({
|
|
1908
2685
|
accessLogReader: deps.accessLogReader,
|
|
2686
|
+
cursor: url.searchParams.get("cursor"),
|
|
1909
2687
|
limit: url.searchParams.get("limit"),
|
|
1910
2688
|
offset: url.searchParams.get("offset"),
|
|
1911
2689
|
}));
|
|
@@ -1919,7 +2697,9 @@ export async function handlePersonalServerSyncRequest(request, deps, options = {
|
|
|
1919
2697
|
if (request.method !== "POST")
|
|
1920
2698
|
return methodNotAllowed();
|
|
1921
2699
|
await deps.auth.authorizeOwner(request);
|
|
1922
|
-
return contractResponse(await triggerSyncContract(deps.syncManager
|
|
2700
|
+
return contractResponse(await triggerSyncContract(deps.syncManager, {
|
|
2701
|
+
whenChanged: url.searchParams.get("when") === "changed",
|
|
2702
|
+
}));
|
|
1923
2703
|
}
|
|
1924
2704
|
if (pathname === "/status") {
|
|
1925
2705
|
if (request.method !== "GET")
|
|
@@ -2066,4 +2846,6 @@ export async function handlePersonalServerOauthTokenRequest(request, deps) {
|
|
|
2066
2846
|
export { handleOuraCollectionRequirementsRequest, readOuraCollectionRequirements, OURA_LEGACY_TAKEOVER_CONTRACT, } from "./oura-collection-requirements.js";
|
|
2067
2847
|
export { createScopeUploadRegistry, ScopeUploadError, SCOPE_UPLOAD_MAX_BATCH_BYTES, SCOPE_UPLOAD_IDLE_TIMEOUT_MS, } from "./scope-uploads.js";
|
|
2068
2848
|
export { prepareScopeUploadBatches, } from "./scope-upload-batches.js";
|
|
2849
|
+
export * from "./pdpp-records-list.js";
|
|
2850
|
+
export { parseRecordQuery } from "./pdpp-record-query.js";
|
|
2069
2851
|
//# sourceMappingURL=index.js.map
|