@enbox/dwn-sdk-js 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +8 -8
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +817 -911
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/constants.js +11 -0
- package/dist/esm/src/core/constants.js.map +1 -0
- package/dist/esm/src/core/core-protocol.js +44 -0
- package/dist/esm/src/core/core-protocol.js.map +1 -0
- package/dist/esm/src/core/dwn-error.js +12 -12
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/grant-authorization.js +16 -3
- package/dist/esm/src/core/grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +5 -0
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-validation.js +91 -0
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization.js +53 -30
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/records-grant-authorization.js +6 -8
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/resumable-task-manager.js +2 -0
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/dwn.js +42 -18
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-event-log.js +204 -0
- package/dist/esm/src/event-stream/event-emitter-event-log.js.map +1 -0
- package/dist/esm/src/handlers/messages-read.js +7 -11
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +22 -24
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/messages-sync.js +11 -15
- package/dist/esm/src/handlers/messages-sync.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +37 -27
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +7 -11
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +10 -12
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +10 -18
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +11 -15
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +31 -26
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +39 -26
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +128 -105
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +5 -2
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js +1 -0
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +33 -3
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +1 -1
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-delete.js +1 -1
- package/dist/esm/src/interfaces/records-delete.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +1 -1
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-read.js +1 -1
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +2 -1
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write-signing.js +1 -12
- package/dist/esm/src/interfaces/records-write-signing.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +25 -41
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/protocols/permission-grant.js +1 -1
- package/dist/esm/src/protocols/permission-grant.js.map +1 -1
- package/dist/esm/src/protocols/permission-request.js +1 -1
- package/dist/esm/src/protocols/permission-request.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +113 -5
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/state-index/state-index-level.js +5 -7
- package/dist/esm/src/state-index/state-index-level.js.map +1 -1
- package/dist/esm/src/store/data-store-level.js +110 -33
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/index-level.js +42 -32
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +70 -6
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/types/permission-types.js.map +1 -1
- package/dist/esm/src/types/protocols-types.js +11 -0
- package/dist/esm/src/types/protocols-types.js.map +1 -1
- package/dist/esm/src/types/records-types.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +0 -8
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/messages.js +16 -34
- package/dist/esm/src/utils/messages.js.map +1 -1
- package/dist/esm/src/utils/records.js +5 -43
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +2 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +32 -43
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/event-emitter-event-log.spec.js +305 -0
- package/dist/esm/tests/event-emitter-event-log.spec.js.map +1 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js +14 -7
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +9 -5
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +14 -7
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +12 -12
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +636 -5
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-create-action.spec.js +4 -4
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +7 -7
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +4 -4
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-delivery.spec.js +236 -0
- package/dist/esm/tests/features/records-delivery.spec.js.map +1 -0
- package/dist/esm/tests/features/records-immutable.spec.js +315 -0
- package/dist/esm/tests/features/records-immutable.spec.js.map +1 -0
- package/dist/esm/tests/features/records-prune.spec.js +4 -4
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js +542 -0
- package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -0
- package/dist/esm/tests/features/records-squash.spec.js +1055 -0
- package/dist/esm/tests/features/records-squash.spec.js.map +1 -0
- package/dist/esm/tests/features/records-tags.spec.js +16 -4
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +7 -8
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +11 -5
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +169 -22
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +103 -21
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +5 -5
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +5 -5
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +9 -4
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +24 -25
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +68 -9
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +24 -138
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +175 -35
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +176 -72
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +52 -68
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-grant.spec.js +6 -6
- package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-request.spec.js +4 -4
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +4 -4
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +4 -4
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +350 -5
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +4 -4
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +4 -4
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +93 -40
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/store/data-store-level.spec.js +102 -41
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
- package/dist/esm/tests/test-event-stream.js +12 -13
- package/dist/esm/tests/test-event-stream.js.map +1 -1
- package/dist/esm/tests/test-suite.js +10 -4
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/messages.spec.js +12 -5
- package/dist/esm/tests/utils/messages.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +8 -12
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +36 -2
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +37 -8
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts +49 -40
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +11 -0
- package/dist/types/src/core/constants.d.ts.map +1 -0
- package/dist/types/src/core/core-protocol.d.ts +89 -0
- package/dist/types/src/core/core-protocol.d.ts.map +1 -0
- package/dist/types/src/core/dwn-error.d.ts +12 -12
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/grant-authorization.d.ts +6 -2
- package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-validation.d.ts +30 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization.d.ts +19 -11
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/resumable-task-manager.d.ts +2 -1
- package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -1
- package/dist/types/src/dwn.d.ts +19 -7
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts +50 -0
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-read.d.ts +3 -8
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-subscribe.d.ts +6 -10
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-sync.d.ts +3 -8
- package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-configure.d.ts +3 -10
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-query.d.ts +3 -8
- package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +3 -6
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-delete.d.ts +3 -8
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +3 -8
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts +3 -8
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-subscribe.d.ts +8 -10
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +12 -25
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +8 -4
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-subscribe.d.ts +5 -0
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts +5 -0
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write-signing.d.ts +3 -4
- package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +11 -11
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-request.d.ts +1 -1
- package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
- package/dist/types/src/protocols/permissions.d.ts +40 -3
- package/dist/types/src/protocols/permissions.d.ts.map +1 -1
- package/dist/types/src/state-index/state-index-level.d.ts.map +1 -1
- package/dist/types/src/store/data-store-level.d.ts +20 -4
- package/dist/types/src/store/data-store-level.d.ts.map +1 -1
- package/dist/types/src/store/index-level.d.ts +4 -0
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/store/storage-controller.d.ts +20 -6
- package/dist/types/src/store/storage-controller.d.ts.map +1 -1
- package/dist/types/src/types/message-types.d.ts +3 -3
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/messages-types.d.ts +12 -3
- package/dist/types/src/types/messages-types.d.ts.map +1 -1
- package/dist/types/src/types/method-handler.d.ts +24 -3
- package/dist/types/src/types/method-handler.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +7 -0
- package/dist/types/src/types/permission-types.d.ts.map +1 -1
- package/dist/types/src/types/protocols-types.d.ts +69 -2
- package/dist/types/src/types/protocols-types.d.ts.map +1 -1
- package/dist/types/src/types/records-types.d.ts +23 -6
- package/dist/types/src/types/records-types.d.ts.map +1 -1
- package/dist/types/src/types/subscriptions.d.ts +151 -13
- package/dist/types/src/types/subscriptions.d.ts.map +1 -1
- package/dist/types/src/utils/hd-key.d.ts +1 -9
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/messages.d.ts +7 -5
- package/dist/types/src/utils/messages.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +1 -11
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/event-emitter-event-log.spec.d.ts +2 -0
- package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +1 -0
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-delivery.spec.d.ts +2 -0
- package/dist/types/tests/features/records-delivery.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-immutable.spec.d.ts +2 -0
- package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-record-limit.spec.d.ts +2 -0
- package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-squash.spec.d.ts +2 -0
- package/dist/types/tests/features/records-squash.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
- package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
- package/dist/types/tests/test-event-stream.d.ts +11 -12
- package/dist/types/tests/test-event-stream.d.ts.map +1 -1
- package/dist/types/tests/test-suite.d.ts +2 -2
- package/dist/types/tests/test-suite.d.ts.map +1 -1
- package/dist/types/tests/utils/test-data-generator.d.ts +19 -0
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/core/constants.ts +11 -0
- package/src/core/core-protocol.ts +129 -0
- package/src/core/dwn-error.ts +18 -12
- package/src/core/grant-authorization.ts +20 -3
- package/src/core/protocol-authorization-action.ts +5 -0
- package/src/core/protocol-authorization-validation.ts +133 -0
- package/src/core/protocol-authorization.ts +71 -23
- package/src/core/records-grant-authorization.ts +6 -8
- package/src/core/resumable-task-manager.ts +3 -1
- package/src/dwn.ts +58 -73
- package/src/event-stream/event-emitter-event-log.ts +283 -0
- package/src/handlers/messages-read.ts +8 -9
- package/src/handlers/messages-subscribe.ts +24 -28
- package/src/handlers/messages-sync.ts +10 -16
- package/src/handlers/protocols-configure.ts +47 -32
- package/src/handlers/protocols-query.ts +6 -9
- package/src/handlers/records-count.ts +11 -10
- package/src/handlers/records-delete.ts +12 -21
- package/src/handlers/records-query.ts +12 -12
- package/src/handlers/records-read.ts +34 -22
- package/src/handlers/records-subscribe.ts +47 -26
- package/src/handlers/records-write.ts +152 -119
- package/src/index.ts +9 -5
- package/src/interfaces/messages-subscribe.ts +7 -1
- package/src/interfaces/protocols-configure.ts +51 -3
- package/src/interfaces/records-count.ts +1 -1
- package/src/interfaces/records-delete.ts +1 -1
- package/src/interfaces/records-query.ts +1 -1
- package/src/interfaces/records-read.ts +1 -1
- package/src/interfaces/records-subscribe.ts +8 -1
- package/src/interfaces/records-write-signing.ts +2 -22
- package/src/interfaces/records-write.ts +35 -48
- package/src/protocols/permission-grant.ts +1 -1
- package/src/protocols/permission-request.ts +1 -1
- package/src/protocols/permissions.ts +148 -6
- package/src/state-index/state-index-level.ts +5 -7
- package/src/store/data-store-level.ts +124 -34
- package/src/store/index-level.ts +44 -35
- package/src/store/storage-controller.ts +89 -12
- package/src/types/message-types.ts +3 -3
- package/src/types/messages-types.ts +12 -3
- package/src/types/method-handler.ts +26 -4
- package/src/types/mitt.d.ts +28 -0
- package/src/types/permission-types.ts +7 -0
- package/src/types/protocols-types.ts +78 -1
- package/src/types/records-types.ts +24 -6
- package/src/types/subscriptions.ts +178 -14
- package/src/utils/hd-key.ts +0 -9
- package/src/utils/messages.ts +17 -37
- package/src/utils/records.ts +7 -58
- package/dist/esm/src/event-stream/event-emitter-stream.js +0 -46
- package/dist/esm/src/event-stream/event-emitter-stream.js.map +0 -1
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +0 -68
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +0 -1
- package/dist/esm/tests/event-stream/event-stream.spec.js +0 -114
- package/dist/esm/tests/event-stream/event-stream.spec.js.map +0 -1
- package/dist/types/src/event-stream/event-emitter-stream.d.ts +0 -23
- package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +0 -1
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts +0 -2
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +0 -1
- package/dist/types/tests/event-stream/event-stream.spec.d.ts +0 -2
- package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +0 -1
- package/src/event-stream/event-emitter-stream.ts +0 -69
|
@@ -3,6 +3,8 @@ import type { MessageStore } from '../types/message-store.js';
|
|
|
3
3
|
import type { RecordsWriteMessage } from '../types/records-types.js';
|
|
4
4
|
import type { ProtocolDefinition, ProtocolRuleSet, ProtocolType, ProtocolTypes } from '../types/protocols-types.js';
|
|
5
5
|
|
|
6
|
+
import { ProtocolRecordLimitStrategy } from '../types/protocols-types.js';
|
|
7
|
+
|
|
6
8
|
import type { RecordsWrite } from '../interfaces/records-write.js';
|
|
7
9
|
|
|
8
10
|
import Ajv from 'ajv/dist/2020.js';
|
|
@@ -389,3 +391,134 @@ export async function verifyAsRoleRecordIfNeeded(
|
|
|
389
391
|
);
|
|
390
392
|
}
|
|
391
393
|
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Verifies that a new record creation does not exceed the `$recordLimit` defined in the rule set.
|
|
397
|
+
*
|
|
398
|
+
* This check only applies to initial writes (new records). Updates to existing records are not counted.
|
|
399
|
+
* The count is scoped to the same `protocol + protocolPath` within the parent context:
|
|
400
|
+
* - For root-level records: counted across the entire protocol for the tenant.
|
|
401
|
+
* - For nested records: counted within the parent record's context.
|
|
402
|
+
*
|
|
403
|
+
* @throws {DwnError} with `ProtocolAuthorizationRecordLimitExceeded` if the limit is reached and strategy is `reject`.
|
|
404
|
+
* @throws {DwnError} with `ProtocolAuthorizationRecordLimitStrategyNotImplemented` if strategy is not yet implemented.
|
|
405
|
+
*/
|
|
406
|
+
export async function verifyRecordLimit(
|
|
407
|
+
tenant: string,
|
|
408
|
+
incomingMessage: RecordsWrite,
|
|
409
|
+
ruleSet: ProtocolRuleSet,
|
|
410
|
+
messageStore: MessageStore,
|
|
411
|
+
): Promise<void> {
|
|
412
|
+
if (ruleSet.$recordLimit === undefined) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Only enforce on initial writes — updates to existing records do not count as new records.
|
|
417
|
+
const isInitialWrite = await incomingMessage.isInitialWrite();
|
|
418
|
+
if (!isInitialWrite) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const { max, strategy } = ruleSet.$recordLimit;
|
|
423
|
+
|
|
424
|
+
// Build a filter to count existing records at the same protocol path and parent context.
|
|
425
|
+
const protocolPath = incomingMessage.message.descriptor.protocolPath!;
|
|
426
|
+
const filter: Filter = {
|
|
427
|
+
interface : DwnInterfaceName.Records,
|
|
428
|
+
method : DwnMethodName.Write,
|
|
429
|
+
isLatestBaseState : true,
|
|
430
|
+
protocol : incomingMessage.message.descriptor.protocol!,
|
|
431
|
+
protocolPath,
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
// Scope by parent context for nested records.
|
|
435
|
+
const parentContextId = Records.getParentContextFromOfContextId(incomingMessage.message.contextId)!;
|
|
436
|
+
if (parentContextId !== '') {
|
|
437
|
+
const prefixFilter = FilterUtility.constructPrefixFilterAsRangeFilter(parentContextId);
|
|
438
|
+
filter.contextId = prefixFilter;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const existingCount = await messageStore.count(tenant, [filter]);
|
|
442
|
+
|
|
443
|
+
if (existingCount >= max) {
|
|
444
|
+
if (strategy === ProtocolRecordLimitStrategy.Reject) {
|
|
445
|
+
throw new DwnError(
|
|
446
|
+
DwnErrorCode.ProtocolAuthorizationRecordLimitExceeded,
|
|
447
|
+
`record limit of ${max} reached at protocol path '${protocolPath}'` +
|
|
448
|
+
`${parentContextId !== '' ? ` under parent context '${parentContextId}'` : ''}` +
|
|
449
|
+
`: new records are rejected until existing records are deleted.`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Future strategies (e.g. purgeOldest) will be implemented here.
|
|
454
|
+
// For now, any non-reject strategy that somehow passes schema validation is rejected.
|
|
455
|
+
throw new DwnError(
|
|
456
|
+
DwnErrorCode.ProtocolAuthorizationRecordLimitStrategyNotImplemented,
|
|
457
|
+
`record limit strategy '${strategy}' is not yet implemented.`
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Verifies that a `RecordsWrite` with `squash: true` is eligible:
|
|
464
|
+
* 1. The protocol rule set at the record's `protocolPath` must have `$squash: true`.
|
|
465
|
+
* 2. The squash write must be an initial write (a new record, not an update).
|
|
466
|
+
*
|
|
467
|
+
* @throws {DwnError} with `ProtocolAuthorizationSquashNotEnabled` if `$squash` is not enabled.
|
|
468
|
+
* @throws {DwnError} with `ProtocolAuthorizationSquashNotInitialWrite` if the squash write is not an initial write.
|
|
469
|
+
*/
|
|
470
|
+
export async function verifySquashEligibility(
|
|
471
|
+
incomingMessage: RecordsWrite,
|
|
472
|
+
ruleSet: ProtocolRuleSet,
|
|
473
|
+
): Promise<void> {
|
|
474
|
+
const squash = incomingMessage.message.descriptor.squash;
|
|
475
|
+
|
|
476
|
+
if (squash !== true) {
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// squash write must be at a protocol path with $squash: true
|
|
481
|
+
if (ruleSet.$squash !== true) {
|
|
482
|
+
throw new DwnError(
|
|
483
|
+
DwnErrorCode.ProtocolAuthorizationSquashNotEnabled,
|
|
484
|
+
`squash writes are not enabled at protocol path '${incomingMessage.message.descriptor.protocolPath}': ` +
|
|
485
|
+
`rule set must have $squash: true.`
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// squash write must be an initial write (a new record, not an update)
|
|
490
|
+
const isInitialWrite = await incomingMessage.isInitialWrite();
|
|
491
|
+
if (!isInitialWrite) {
|
|
492
|
+
throw new DwnError(
|
|
493
|
+
DwnErrorCode.ProtocolAuthorizationSquashNotInitialWrite,
|
|
494
|
+
`squash write must be an initial write (a new record): updates cannot be squash writes.`
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Verifies that an update is not attempted on a record whose protocol path has `$immutable: true`.
|
|
501
|
+
*
|
|
502
|
+
* Only non-initial writes (updates) are rejected — initial writes are always allowed.
|
|
503
|
+
* `RecordsDelete` is not affected by this check; immutability prevents data mutation, not removal.
|
|
504
|
+
*
|
|
505
|
+
* @throws {DwnError} with `ProtocolAuthorizationImmutableRecord` if an update is attempted on an immutable record.
|
|
506
|
+
*/
|
|
507
|
+
export async function verifyImmutability(
|
|
508
|
+
incomingMessage: RecordsWrite,
|
|
509
|
+
ruleSet: ProtocolRuleSet,
|
|
510
|
+
): Promise<void> {
|
|
511
|
+
if (ruleSet.$immutable !== true) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const isInitialWrite = await incomingMessage.isInitialWrite();
|
|
516
|
+
if (isInitialWrite) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
throw new DwnError(
|
|
521
|
+
DwnErrorCode.ProtocolAuthorizationImmutableRecord,
|
|
522
|
+
`record at protocol path '${incomingMessage.message.descriptor.protocolPath}' is immutable: updates are not allowed.`
|
|
523
|
+
);
|
|
524
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { CoreProtocolRegistry } from './core-protocol.js';
|
|
1
2
|
import type { Filter } from '../types/query-types.js';
|
|
2
3
|
import type { MessageStore } from '../types/message-store.js';
|
|
3
|
-
import type { ProtocolAction } from '../types/protocols-types.js';
|
|
4
4
|
import type { RecordsCount } from '../interfaces/records-count.js';
|
|
5
5
|
import type { RecordsDelete } from '../interfaces/records-delete.js';
|
|
6
6
|
import type { RecordsQuery } from '../interfaces/records-query.js';
|
|
@@ -11,17 +11,19 @@ import type { RecordsWriteMessage } from '../types/records-types.js';
|
|
|
11
11
|
import type { ProtocolDefinition, ProtocolRuleSet, ProtocolsConfigureMessage } from '../types/protocols-types.js';
|
|
12
12
|
|
|
13
13
|
import { getRuleSetAtPath } from '../utils/protocols.js';
|
|
14
|
-
import { PermissionsProtocol } from '../protocols/permissions.js';
|
|
15
14
|
import { SortDirection } from '../types/query-types.js';
|
|
16
15
|
import { DwnError, DwnErrorCode } from './dwn-error.js';
|
|
17
16
|
import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
|
|
18
17
|
|
|
19
|
-
import { authorizeAgainstAllowedActions,
|
|
18
|
+
import { authorizeAgainstAllowedActions, verifyInvokedRole } from './protocol-authorization-action.js';
|
|
20
19
|
import { constructRecordChain, fetchInitialWrite, getGoverningTimestamp } from './record-chain.js';
|
|
21
20
|
import {
|
|
22
21
|
verifyAsRoleRecordIfNeeded,
|
|
22
|
+
verifyImmutability,
|
|
23
23
|
verifyProtocolPathAndContextId,
|
|
24
|
+
verifyRecordLimit,
|
|
24
25
|
verifySizeLimit,
|
|
26
|
+
verifySquashEligibility,
|
|
25
27
|
verifyTagsIfNeeded,
|
|
26
28
|
verifyTypeWithComposition,
|
|
27
29
|
} from './protocol-authorization-validation.js';
|
|
@@ -47,6 +49,7 @@ export class ProtocolAuthorization {
|
|
|
47
49
|
tenant: string,
|
|
48
50
|
incomingMessage: RecordsWrite,
|
|
49
51
|
messageStore: MessageStore,
|
|
52
|
+
coreProtocols?: CoreProtocolRegistry,
|
|
50
53
|
): Promise<void> {
|
|
51
54
|
// Determine the governing timestamp for protocol definition lookup.
|
|
52
55
|
// For an initial write, this is the message's own timestamp.
|
|
@@ -61,19 +64,23 @@ export class ProtocolAuthorization {
|
|
|
61
64
|
incomingMessage.message.descriptor.protocol!,
|
|
62
65
|
messageStore,
|
|
63
66
|
governingTimestamp,
|
|
67
|
+
coreProtocols,
|
|
64
68
|
);
|
|
65
69
|
|
|
70
|
+
// Create a bound fetch function that captures the registry for downstream callbacks.
|
|
71
|
+
const boundFetchDefinition = ProtocolAuthorization.createBoundFetchDefinition(coreProtocols);
|
|
72
|
+
|
|
66
73
|
// verify declared protocol type exists in protocol and that it conforms to type specification.
|
|
67
74
|
// For cross-protocol composition, the type may be defined in a referenced protocol.
|
|
68
75
|
await verifyTypeWithComposition(
|
|
69
76
|
tenant, incomingMessage.message, protocolDefinition, messageStore,
|
|
70
|
-
|
|
77
|
+
boundFetchDefinition, governingTimestamp
|
|
71
78
|
);
|
|
72
79
|
|
|
73
80
|
// validate `protocolPath`
|
|
74
81
|
await verifyProtocolPathAndContextId(
|
|
75
82
|
tenant, incomingMessage, messageStore,
|
|
76
|
-
|
|
83
|
+
boundFetchDefinition, governingTimestamp,
|
|
77
84
|
);
|
|
78
85
|
|
|
79
86
|
// get the rule set for the inbound message
|
|
@@ -95,6 +102,15 @@ export class ProtocolAuthorization {
|
|
|
95
102
|
|
|
96
103
|
// Verify protocol tags
|
|
97
104
|
verifyTagsIfNeeded(incomingMessage, ruleSet);
|
|
105
|
+
|
|
106
|
+
// Verify immutability — reject updates to write-once records
|
|
107
|
+
await verifyImmutability(incomingMessage, ruleSet);
|
|
108
|
+
|
|
109
|
+
// Verify squash eligibility — ensure squash writes are at $squash: true paths and are initial writes
|
|
110
|
+
await verifySquashEligibility(incomingMessage, ruleSet);
|
|
111
|
+
|
|
112
|
+
// Verify record count limit
|
|
113
|
+
await verifyRecordLimit(tenant, incomingMessage, ruleSet, messageStore);
|
|
98
114
|
}
|
|
99
115
|
|
|
100
116
|
/**
|
|
@@ -105,6 +121,7 @@ export class ProtocolAuthorization {
|
|
|
105
121
|
tenant: string,
|
|
106
122
|
incomingMessage: RecordsWrite,
|
|
107
123
|
messageStore: MessageStore,
|
|
124
|
+
coreProtocols?: CoreProtocolRegistry,
|
|
108
125
|
): Promise<void> {
|
|
109
126
|
const existingInitialWrite = await fetchInitialWrite(tenant, incomingMessage.message.recordId, messageStore);
|
|
110
127
|
|
|
@@ -129,6 +146,7 @@ export class ProtocolAuthorization {
|
|
|
129
146
|
incomingMessage.message.descriptor.protocol!,
|
|
130
147
|
messageStore,
|
|
131
148
|
governingTimestamp,
|
|
149
|
+
coreProtocols,
|
|
132
150
|
);
|
|
133
151
|
|
|
134
152
|
// get the rule set for the inbound message
|
|
@@ -137,6 +155,8 @@ export class ProtocolAuthorization {
|
|
|
137
155
|
protocolDefinition,
|
|
138
156
|
);
|
|
139
157
|
|
|
158
|
+
const boundFetchDefinition = ProtocolAuthorization.createBoundFetchDefinition(coreProtocols);
|
|
159
|
+
|
|
140
160
|
// If the incoming message has `protocolRole` in the descriptor, validate the invoked role
|
|
141
161
|
await verifyInvokedRole(
|
|
142
162
|
tenant,
|
|
@@ -145,7 +165,7 @@ export class ProtocolAuthorization {
|
|
|
145
165
|
incomingMessage.message.contextId!,
|
|
146
166
|
protocolDefinition,
|
|
147
167
|
messageStore,
|
|
148
|
-
|
|
168
|
+
boundFetchDefinition,
|
|
149
169
|
governingTimestamp,
|
|
150
170
|
);
|
|
151
171
|
|
|
@@ -170,6 +190,7 @@ export class ProtocolAuthorization {
|
|
|
170
190
|
incomingMessage: RecordsRead,
|
|
171
191
|
newestRecordsWrite: RecordsWrite,
|
|
172
192
|
messageStore: MessageStore,
|
|
193
|
+
coreProtocols?: CoreProtocolRegistry,
|
|
173
194
|
): Promise<void> {
|
|
174
195
|
// fetch record chain
|
|
175
196
|
const recordChain: RecordsWriteMessage[] =
|
|
@@ -190,6 +211,7 @@ export class ProtocolAuthorization {
|
|
|
190
211
|
newestRecordsWrite.message.descriptor.protocol!,
|
|
191
212
|
messageStore,
|
|
192
213
|
governingTimestamp,
|
|
214
|
+
coreProtocols,
|
|
193
215
|
);
|
|
194
216
|
|
|
195
217
|
// get the rule set for the inbound message
|
|
@@ -198,6 +220,8 @@ export class ProtocolAuthorization {
|
|
|
198
220
|
protocolDefinition,
|
|
199
221
|
);
|
|
200
222
|
|
|
223
|
+
const boundFetchDefinition = ProtocolAuthorization.createBoundFetchDefinition(coreProtocols);
|
|
224
|
+
|
|
201
225
|
// If the incoming message has `protocolRole` in the descriptor, validate the invoked role
|
|
202
226
|
await verifyInvokedRole(
|
|
203
227
|
tenant,
|
|
@@ -206,7 +230,7 @@ export class ProtocolAuthorization {
|
|
|
206
230
|
newestRecordsWrite.message.contextId!,
|
|
207
231
|
protocolDefinition,
|
|
208
232
|
messageStore,
|
|
209
|
-
|
|
233
|
+
boundFetchDefinition,
|
|
210
234
|
governingTimestamp,
|
|
211
235
|
);
|
|
212
236
|
|
|
@@ -225,6 +249,7 @@ export class ProtocolAuthorization {
|
|
|
225
249
|
tenant: string,
|
|
226
250
|
incomingMessage: RecordsCount | RecordsQuery | RecordsSubscribe,
|
|
227
251
|
messageStore: MessageStore,
|
|
252
|
+
coreProtocols?: CoreProtocolRegistry,
|
|
228
253
|
): Promise<void> {
|
|
229
254
|
const { protocol, protocolPath, contextId } = incomingMessage.message.descriptor.filter;
|
|
230
255
|
|
|
@@ -233,6 +258,8 @@ export class ProtocolAuthorization {
|
|
|
233
258
|
tenant,
|
|
234
259
|
protocol!, // `authorizeQueryOrSubscribe` is only called if `protocol` is present
|
|
235
260
|
messageStore,
|
|
261
|
+
undefined,
|
|
262
|
+
coreProtocols,
|
|
236
263
|
);
|
|
237
264
|
|
|
238
265
|
// get the rule set for the inbound message
|
|
@@ -241,6 +268,8 @@ export class ProtocolAuthorization {
|
|
|
241
268
|
protocolDefinition,
|
|
242
269
|
);
|
|
243
270
|
|
|
271
|
+
const boundFetchDefinition = ProtocolAuthorization.createBoundFetchDefinition(coreProtocols);
|
|
272
|
+
|
|
244
273
|
// If the incoming message has `protocolRole` in the descriptor, validate the invoked role
|
|
245
274
|
await verifyInvokedRole(
|
|
246
275
|
tenant,
|
|
@@ -249,7 +278,7 @@ export class ProtocolAuthorization {
|
|
|
249
278
|
contextId,
|
|
250
279
|
protocolDefinition,
|
|
251
280
|
messageStore,
|
|
252
|
-
|
|
281
|
+
boundFetchDefinition,
|
|
253
282
|
);
|
|
254
283
|
|
|
255
284
|
// verify method invoked against the allowed actions in the rule set
|
|
@@ -272,6 +301,7 @@ export class ProtocolAuthorization {
|
|
|
272
301
|
incomingMessage: RecordsDelete,
|
|
273
302
|
recordsWrite: RecordsWrite,
|
|
274
303
|
messageStore: MessageStore,
|
|
304
|
+
coreProtocols?: CoreProtocolRegistry,
|
|
275
305
|
): Promise<void> {
|
|
276
306
|
|
|
277
307
|
// fetch record chain
|
|
@@ -292,6 +322,7 @@ export class ProtocolAuthorization {
|
|
|
292
322
|
recordsWrite.message.descriptor.protocol!,
|
|
293
323
|
messageStore,
|
|
294
324
|
governingTimestamp,
|
|
325
|
+
coreProtocols,
|
|
295
326
|
);
|
|
296
327
|
|
|
297
328
|
// get the rule set for the inbound message
|
|
@@ -300,6 +331,8 @@ export class ProtocolAuthorization {
|
|
|
300
331
|
protocolDefinition,
|
|
301
332
|
);
|
|
302
333
|
|
|
334
|
+
const boundFetchDefinition = ProtocolAuthorization.createBoundFetchDefinition(coreProtocols);
|
|
335
|
+
|
|
303
336
|
// If the incoming message has `protocolRole` in the descriptor, validate the invoked role
|
|
304
337
|
await verifyInvokedRole(
|
|
305
338
|
tenant,
|
|
@@ -308,7 +341,7 @@ export class ProtocolAuthorization {
|
|
|
308
341
|
recordsWrite.message.contextId!,
|
|
309
342
|
protocolDefinition,
|
|
310
343
|
messageStore,
|
|
311
|
-
|
|
344
|
+
boundFetchDefinition,
|
|
312
345
|
governingTimestamp,
|
|
313
346
|
);
|
|
314
347
|
|
|
@@ -328,16 +361,25 @@ export class ProtocolAuthorization {
|
|
|
328
361
|
* When `messageTimestamp` is provided, returns the protocol definition that was active at that
|
|
329
362
|
* point in time — i.e. the ProtocolsConfigure with the greatest `messageTimestamp` that is <= the
|
|
330
363
|
* given timestamp. When not provided, returns the latest (current) protocol definition.
|
|
364
|
+
*
|
|
365
|
+
* When `coreProtocols` is provided, core protocol definitions are returned directly from the
|
|
366
|
+
* registry without a message store query. The extra parameter does not affect the
|
|
367
|
+
* `FetchProtocolDefinitionFn` callback type — callers that pass this function as a callback
|
|
368
|
+
* should bind the registry via a closure (see `createBoundFetchDefinition`).
|
|
331
369
|
*/
|
|
332
370
|
public static async fetchProtocolDefinition(
|
|
333
371
|
tenant: string,
|
|
334
372
|
protocolUri: string,
|
|
335
373
|
messageStore: MessageStore,
|
|
336
374
|
messageTimestamp?: string,
|
|
375
|
+
coreProtocols?: CoreProtocolRegistry,
|
|
337
376
|
): Promise<ProtocolDefinition> {
|
|
338
|
-
// if
|
|
339
|
-
if (
|
|
340
|
-
|
|
377
|
+
// if the protocol is a registered core protocol, return the definition directly without a store query
|
|
378
|
+
if (coreProtocols !== undefined) {
|
|
379
|
+
const coreDefinition = coreProtocols.getDefinition(protocolUri);
|
|
380
|
+
if (coreDefinition !== undefined) {
|
|
381
|
+
return coreDefinition;
|
|
382
|
+
}
|
|
341
383
|
}
|
|
342
384
|
|
|
343
385
|
// fetch the corresponding protocol definition
|
|
@@ -370,6 +412,23 @@ export class ProtocolAuthorization {
|
|
|
370
412
|
return protocolMessage.descriptor.definition;
|
|
371
413
|
}
|
|
372
414
|
|
|
415
|
+
/**
|
|
416
|
+
* Creates a `FetchProtocolDefinitionFn` closure that binds the given `CoreProtocolRegistry`.
|
|
417
|
+
* This allows core protocol definitions to be resolved from the registry without changing
|
|
418
|
+
* the `FetchProtocolDefinitionFn` type signature — zero ripple to downstream consumers
|
|
419
|
+
* like `protocol-authorization-action.ts` and `protocol-authorization-validation.ts`.
|
|
420
|
+
*/
|
|
421
|
+
private static createBoundFetchDefinition(coreProtocols?: CoreProtocolRegistry): FetchProtocolDefinitionFn {
|
|
422
|
+
return (
|
|
423
|
+
tenant: string,
|
|
424
|
+
protocolUri: string,
|
|
425
|
+
messageStore: MessageStore,
|
|
426
|
+
messageTimestamp?: string,
|
|
427
|
+
): Promise<ProtocolDefinition> => {
|
|
428
|
+
return ProtocolAuthorization.fetchProtocolDefinition(tenant, protocolUri, messageStore, messageTimestamp, coreProtocols);
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
|
|
373
432
|
/**
|
|
374
433
|
* Gets the rule set corresponding to the given protocolPath.
|
|
375
434
|
*/
|
|
@@ -385,15 +444,4 @@ export class ProtocolAuthorization {
|
|
|
385
444
|
return ruleSet;
|
|
386
445
|
}
|
|
387
446
|
|
|
388
|
-
/**
|
|
389
|
-
* Returns all the ProtocolActions that would authorize the incoming message.
|
|
390
|
-
* Delegates to the standalone function in `protocol-authorization-action.ts`.
|
|
391
|
-
*/
|
|
392
|
-
private static async getActionsSeekingARuleMatch(
|
|
393
|
-
tenant: string,
|
|
394
|
-
incomingMessage: RecordsCount | RecordsDelete | RecordsQuery | RecordsRead | RecordsSubscribe | RecordsWrite,
|
|
395
|
-
messageStore: MessageStore,
|
|
396
|
-
): Promise<ProtocolAction[]> {
|
|
397
|
-
return getActionsSeekingARuleMatch(tenant, incomingMessage, messageStore);
|
|
398
|
-
}
|
|
399
447
|
}
|
|
@@ -87,15 +87,14 @@ export class RecordsGrantAuthorization {
|
|
|
87
87
|
messageStore
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
//
|
|
90
|
+
// The grant's protocol must match the query/subscribe filter's protocol.
|
|
91
91
|
// NOTE: validated the invoked permission is for Records in GrantAuthorization.performBaseValidation()
|
|
92
92
|
const permissionScope = permissionGrant.scope as RecordsPermissionScope;
|
|
93
|
-
const protocolInGrant = permissionScope.protocol;
|
|
94
93
|
const protocolInMessage = incomingMessage.descriptor.filter.protocol;
|
|
95
|
-
if (
|
|
94
|
+
if (protocolInMessage !== permissionScope.protocol) {
|
|
96
95
|
throw new DwnError(
|
|
97
96
|
DwnErrorCode.RecordsGrantAuthorizationQueryOrSubscribeProtocolScopeMismatch,
|
|
98
|
-
`Grant protocol scope ${
|
|
97
|
+
`Grant protocol scope ${permissionScope.protocol} does not match protocol in message ${protocolInMessage}`
|
|
99
98
|
);
|
|
100
99
|
}
|
|
101
100
|
}
|
|
@@ -124,15 +123,14 @@ export class RecordsGrantAuthorization {
|
|
|
124
123
|
messageStore
|
|
125
124
|
});
|
|
126
125
|
|
|
127
|
-
//
|
|
126
|
+
// The grant's protocol must match the protocol of the record being deleted.
|
|
128
127
|
// NOTE: validated the invoked permission is for Records in GrantAuthorization.performBaseValidation()
|
|
129
128
|
const permissionScope = permissionGrant.scope as RecordsPermissionScope;
|
|
130
|
-
const protocolInGrant = permissionScope.protocol;
|
|
131
129
|
const protocolOfRecordToDelete = recordsWriteToDelete.descriptor.protocol;
|
|
132
|
-
if (
|
|
130
|
+
if (protocolOfRecordToDelete !== permissionScope.protocol) {
|
|
133
131
|
throw new DwnError(
|
|
134
132
|
DwnErrorCode.RecordsGrantAuthorizationDeleteProtocolScopeMismatch,
|
|
135
|
-
`Grant protocol scope ${
|
|
133
|
+
`Grant protocol scope ${permissionScope.protocol} does not match protocol in record to delete ${protocolOfRecordToDelete}`
|
|
136
134
|
);
|
|
137
135
|
}
|
|
138
136
|
}
|
|
@@ -3,6 +3,7 @@ import type { ManagedResumableTask, ResumableTaskStore } from '../types/resumabl
|
|
|
3
3
|
|
|
4
4
|
export enum ResumableTaskName {
|
|
5
5
|
RecordsDelete = 'RecordsDelete',
|
|
6
|
+
RecordsSquash = 'RecordsSquash',
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
export type ResumableTask = {
|
|
@@ -26,7 +27,8 @@ export class ResumableTaskManager {
|
|
|
26
27
|
this.resumableTaskHandlers = {
|
|
27
28
|
// NOTE: The arrow function is IMPORTANT here, else the `this` context will be lost within the invoked method.
|
|
28
29
|
// e.g. code within performRecordsDelete() won't know `this` refers to the `storageController` instance.
|
|
29
|
-
[ResumableTaskName.RecordsDelete]: async (task): Promise<void> => await storageController.performRecordsDelete(task),
|
|
30
|
+
[ResumableTaskName.RecordsDelete] : async (task): Promise<void> => await storageController.performRecordsDelete(task),
|
|
31
|
+
[ResumableTaskName.RecordsSquash] : async (task): Promise<void> => await storageController.performRecordsSquash(task),
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
|