generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 100
EventsGet
#305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
EventsGet
#305
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5e3488c
start implementing `EventsGet` interface method
mistermoe e80d017
export event-related stuff
mistermoe 329ed1d
add test utility to generate `EventsGet` messages
mistermoe 75e8a3f
add more tests
mistermoe d8c8b8a
make linter happy
mistermoe bc5c122
add more tests
mistermoe 7000fc3
fix typo
mistermoe 0d09122
remove use of generics for MessageReply
mistermoe 3a0e157
Merge branch 'main' into events-get
mistermoe 57a3519
address PR comment
mistermoe 1af68e3
Merge branch 'events-get' of github.com:TBD54566975/dwn-sdk-js into e…
mistermoe 3ad4b66
make linter happy
mistermoe 874d89b
address PR comments
mistermoe 2b7f169
address PR comment
mistermoe 1268eeb
Merge branch 'main' into events-get
mistermoe 5a7da49
0.0.30
mistermoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "$id": "https://identity.foundation/dwn/json-schemas/events-get.json", | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": [ | ||
| "authorization", | ||
| "descriptor" | ||
| ], | ||
| "properties": { | ||
| "authorization": { | ||
| "$ref": "https://identity.foundation/dwn/json-schemas/general-jws.json" | ||
| }, | ||
| "descriptor": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": [ | ||
| "interface", | ||
| "method" | ||
| ], | ||
| "properties": { | ||
| "interface": { | ||
| "enum": [ | ||
| "Events" | ||
| ], | ||
| "type": "string" | ||
| }, | ||
| "method": { | ||
| "enum": [ | ||
| "Get" | ||
| ], | ||
| "type": "string" | ||
| }, | ||
| "watermark": { | ||
| "type": "string" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import type { DidResolver } from '../../../index.js'; | ||
| import type { EventLog } from '../../../event-log/event-log.js'; | ||
| import type { GetEventsOptions } from '../../../event-log/event-log.js'; | ||
| import type { MethodHandler } from '../../types.js'; | ||
| import type { EventsGetMessage, EventsGetReply } from '../types.js'; | ||
|
|
||
| import { EventsGet } from '../messages/events-get.js'; | ||
| import { MessageReply } from '../../../core/message-reply.js'; | ||
| import { authenticate, authorize } from '../../../core/auth.js'; | ||
|
|
||
| type HandleArgs = {tenant: string, message: EventsGetMessage}; | ||
|
|
||
| export class EventsGetHandler implements MethodHandler { | ||
| constructor(private didResolver: DidResolver, private eventLog: EventLog) {} | ||
|
|
||
| public async handle({ tenant, message }: HandleArgs): Promise<EventsGetReply> { | ||
| let eventsGet: EventsGet; | ||
|
|
||
| try { | ||
| eventsGet = await EventsGet.parse(message); | ||
| } catch (e) { | ||
| return MessageReply.fromError(e, 400); | ||
| } | ||
|
|
||
| try { | ||
| await authenticate(message.authorization, this.didResolver); | ||
| await authorize(tenant, eventsGet); | ||
| } catch (e) { | ||
| return MessageReply.fromError(e, 401); | ||
| } | ||
|
|
||
| // if watermark was provided in message, get all events _after_ the watermark. | ||
| // Otherwise, get all events. | ||
| let options: GetEventsOptions | undefined; | ||
| if (message.descriptor.watermark) { | ||
| options = { gt: message.descriptor.watermark }; | ||
| } | ||
|
|
||
| const events = await this.eventLog.getEvents(tenant, options); | ||
|
|
||
| return { | ||
| status: { code: 200, detail: 'OK' }, | ||
| events | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import type { SignatureInput } from '../../../jose/jws/general/types.js'; | ||
| import type { EventsGetDescriptor, EventsGetMessage } from '../types.js'; | ||
|
|
||
| import { validateAuthorizationIntegrity } from '../../../core/auth.js'; | ||
| import { DwnInterfaceName, DwnMethodName, Message } from '../../../core/message.js'; | ||
|
|
||
| export type EventsGetOptions = { | ||
| watermark?: string; | ||
| authorizationSignatureInput: SignatureInput; | ||
| }; | ||
|
|
||
| export class EventsGet extends Message<EventsGetMessage> { | ||
|
|
||
| public static async parse(message: EventsGetMessage): Promise<EventsGet> { | ||
| Message.validateJsonSchema(message); | ||
| await validateAuthorizationIntegrity(message); | ||
|
|
||
| return new EventsGet(message); | ||
| } | ||
|
|
||
| public static async create(options: EventsGetOptions): Promise<EventsGet> { | ||
| const descriptor: EventsGetDescriptor = { | ||
| interface : DwnInterfaceName.Events, | ||
| method : DwnMethodName.Get, | ||
| }; | ||
|
|
||
| if (options.watermark) { | ||
| descriptor.watermark = options.watermark; | ||
| } | ||
|
|
||
| const authorization = await Message.signAsAuthorization(descriptor, options.authorizationSignatureInput); | ||
| const message = { descriptor, authorization }; | ||
|
|
||
| Message.validateJsonSchema(message); | ||
|
|
||
| return new EventsGet(message); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import type { BaseMessage } from '../../core/types.js'; | ||
| import type { BaseMessageReply } from '../../core/message-reply.js'; | ||
| import type { Event } from '../../event-log/event-log.js'; | ||
| import type { DwnInterfaceName, DwnMethodName } from '../../core/message.js'; | ||
|
|
||
| export type EventsGetDescriptor = { | ||
| interface : DwnInterfaceName.Events; | ||
| method: DwnMethodName.Get; | ||
| watermark?: string; | ||
| }; | ||
|
|
||
| export type EventsGetMessage = BaseMessage & { | ||
| descriptor: EventsGetDescriptor; | ||
| }; | ||
|
|
||
| export type EventsGetReply = BaseMessageReply & { | ||
mistermoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| events?: Event[]; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.