Skip to content

Commit

Permalink
Start decoding notification input
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Dec 4, 2023
1 parent fa0f3a9 commit 5f4b584
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "module",
"dependencies": {
"@effect/platform-node": "^0.33.5",
"@effect/schema": "^0.51.3",
"effect": "^2.0.0-next.58"
},
"devDependencies": {
Expand Down
9 changes: 9 additions & 0 deletions src/CoarNotify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Schema } from '@effect/schema'

export const ReviewActionSchema = Schema.struct({
'@context': Schema.tuple(
Schema.literal('https://www.w3.org/ns/activitystreams'),
Schema.literal('https://purl.org/coar/notify'),
),
id: Schema.string,
})
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { HttpServer, Runtime } from '@effect/platform-node'
import { Effect, Layer } from 'effect'
import { createServer } from 'node:http'
import * as CoarNotify from './CoarNotify.js'

const serve = HttpServer.router.empty.pipe(
HttpServer.router.get('/health', HttpServer.response.json({ status: 'ok' })),
HttpServer.router.post('/inbox', HttpServer.response.empty({ status: 503 })),
HttpServer.router.post(
'/inbox',
Effect.gen(function* (_) {
yield* _(HttpServer.request.schemaBodyJson(CoarNotify.ReviewActionSchema))

return yield* _(HttpServer.response.empty({ status: 503 }))
}).pipe(
Effect.catchTags({
ParseError: () => HttpServer.response.empty({ status: 400 }),
RequestError: () => HttpServer.response.empty({ status: 400 }),
}),
),
),
Effect.catchTag('RouteNotFound', () => HttpServer.response.empty({ status: 404 })),
HttpServer.server.serve(HttpServer.middleware.logger),
)
Expand Down
25 changes: 25 additions & 0 deletions test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"id": "10.1111/234567",
"updated": "2023-08-09T17:01:32.340000",
"@context": ["https://www.w3.org/ns/activitystreams", "https://purl.org/coar/notify"],
"type": ["Offer", "coar-notify:ReviewAction"],
"origin": {
"id": "https://www.repo.org",
"inbox": "https://api.repo.org/inbox",
"type": "Service"
},
"target": {
"id": "https://www.review-service.org",
"inbox": "https://api.review-service.org/inbox",
"type": "Service"
},
"object": {
"id": "10.1101/234567",
"ietf:cite-as": "https://doi.org/10.1101/234567"
},
"actor": {
"id": "mailto:[email protected]",
"type": "Person",
"name": "Chris Wilkinson"
}
}

0 comments on commit 5f4b584

Please sign in to comment.