Skip to content

Commit

Permalink
Allow the script to point at a different ORCID
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Jan 30, 2024
1 parent ff51f05 commit e7aa59e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ORCID_URL=https://api.sandbox.orcid.org
REDIS_URL=redis://localhost:6379
ZENODO_URL=https://sandbox.zenodo.org
9 changes: 9 additions & 0 deletions src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { Config, Layer } from 'effect'
import { OrcidConfig } from './Orcid.js'
import { RedisConfig } from './Redis.js'
import { ZenodoConfig } from './Zenodo.js'

const orcidConfig: Config.Config<OrcidConfig> = Config.nested(
Config.all({
url: Config.mapAttempt(Config.string('URL'), url => new URL(url)),
}),
'ORCID',
)

const redisConfig: Config.Config<RedisConfig> = Config.nested(
Config.all({
url: Config.mapAttempt(Config.string('URL'), url => new URL(url)),
Expand All @@ -17,6 +25,7 @@ const zenodoConfig: Config.Config<ZenodoConfig> = Config.nested(
)

export const ConfigLive = Layer.mergeAll(
Layer.effect(OrcidConfig, orcidConfig),
Layer.effect(RedisConfig, redisConfig),
Layer.effect(ZenodoConfig, zenodoConfig),
)
23 changes: 19 additions & 4 deletions src/Orcid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ type GetPeerReviewsForOrcidIdError = HttpClient.error.HttpClientError | ParseRes
type AddPeerReviewToOrcidIdError = HttpClient.error.HttpClientError | HttpClient.body.BodyError
type DeletePeerReviewError = HttpClient.error.HttpClientError

export interface OrcidConfig {
readonly url: URL
}

export const OrcidConfig = Context.Tag<OrcidConfig>()

export const getPeerReviewsForOrcidId = (
id: OrcidId,
): Effect.Effect<HttpClient.client.Client.Default | OrcidAccessToken, GetPeerReviewsForOrcidIdError, PeerReviews> =>
): Effect.Effect<
OrcidConfig | HttpClient.client.Client.Default | OrcidAccessToken,
GetPeerReviewsForOrcidIdError,
PeerReviews
> =>
Effect.gen(function* (_) {
const client = yield* _(orcidClient)

Expand All @@ -40,7 +50,11 @@ export const addPeerReviewToOrcidId = ({
}: {
id: OrcidId
peerReview: NewPeerReview
}): Effect.Effect<HttpClient.client.Client.Default | OrcidAccessToken, AddPeerReviewToOrcidIdError, void> =>
}): Effect.Effect<
OrcidConfig | HttpClient.client.Client.Default | OrcidAccessToken,
AddPeerReviewToOrcidIdError,
void
> =>
Effect.gen(function* (_) {
const client = yield* _(orcidClient)

Expand All @@ -57,7 +71,7 @@ export const deletePeerReview = ({
}: {
orcid: OrcidId
id: number
}): Effect.Effect<HttpClient.client.Client.Default | OrcidAccessToken, DeletePeerReviewError, void> =>
}): Effect.Effect<OrcidConfig | HttpClient.client.Client.Default | OrcidAccessToken, DeletePeerReviewError, void> =>
Effect.gen(function* (_) {
const client = yield* _(orcidClient)

Expand Down Expand Up @@ -137,13 +151,14 @@ const NewPeerReviewSchema = Schema.struct({
})

const orcidClient = Effect.gen(function* (_) {
const config = yield* _(OrcidConfig)
const httpClient = yield* _(HttpClient.client.Client)
const { token } = yield* _(OrcidAccessToken)

return httpClient.pipe(
HttpClient.client.filterStatusOk,
HttpClient.client.mapRequest(HttpClient.request.accept('application/vnd.orcid+json')),
HttpClient.client.mapRequest(HttpClient.request.prependUrl('https://api.sandbox.orcid.org/v3.0/')),
HttpClient.client.mapRequest(HttpClient.request.prependUrl(new URL('/v3.0/', config.url).href)),
HttpClient.client.mapRequest(HttpClient.request.bearerToken(token)),
)
})

0 comments on commit e7aa59e

Please sign in to comment.