diff --git a/src/data/users.json.ts b/src/data/users.json.ts new file mode 100644 index 0000000..804df82 --- /dev/null +++ b/src/data/users.json.ts @@ -0,0 +1,27 @@ +import { HttpClient, HttpClientRequest, HttpClientResponse, Terminal } from '@effect/platform' +import { NodeTerminal } from '@effect/platform-node' +import { Schema } from '@effect/schema' +import { Config, Effect, Redacted } from 'effect' + +const Users = Schema.Array(Schema.Struct({})) + +const program = Effect.gen(function* () { + const terminal = yield* Terminal.Terminal + const token = yield* Config.redacted('PREREVIEW_REVIEWS_DATA_TOKEN') + + const request = HttpClientRequest.bearerToken( + HttpClientRequest.get('https://prereview.org/users-data'), + Redacted.value(token), + ) + + const data = yield* HttpClient.fetchOk(request).pipe( + Effect.andThen(HttpClientResponse.schemaBodyJson(Users)), + Effect.scoped, + ) + + const encoded = yield* Schema.encode(Schema.parseJson(Users))(data) + + yield* terminal.display(encoded) +}) + +await Effect.runPromise(program.pipe(Effect.provide(NodeTerminal.layer))) diff --git a/src/index.md b/src/index.md index e6aef30..b6d92b1 100644 --- a/src/index.md +++ b/src/index.md @@ -9,6 +9,7 @@ toc: false ```js const requests = FileAttachment('./data/requests.json').json() const reviews = FileAttachment('./data/reviews.json').json() +const users = FileAttachment('./data/users.json').json() ```