| 1 | import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { RelayManagedEndpoint } from "@t3tools/contracts/relay"; |
| 3 | import * as Context from "effect/Context"; |
| 4 | import type * as Effect from "effect/Effect"; |
| 5 | import * as Layer from "effect/Layer"; |
| 6 | import type * as Option from "effect/Option"; |
| 7 | import * as Schema from "effect/Schema"; |
| 8 | |
| 9 | import type { ConnectionAttemptError } from "../connection/model.ts"; |
| 10 | |
| 11 | export class RemoteDpopAccessToken extends Schema.Class<RemoteDpopAccessToken>( |
| 12 | "@t3tools/client-runtime/authorization/RemoteDpopAccessToken", |
| 13 | )({ |
| 14 | environmentId: EnvironmentId, |
| 15 | accountId: Schema.optionalKey(Schema.String), |
| 16 | label: Schema.String, |
| 17 | endpoint: RelayManagedEndpoint, |
| 18 | accessToken: Schema.String, |
| 19 | expiresAtEpochMs: Schema.Number, |
| 20 | dpopThumbprint: Schema.String, |
| 21 | }) {} |
| 22 | |
| 23 | export class RemoteDpopAccessTokenStore extends Context.Service< |
| 24 | RemoteDpopAccessTokenStore, |
| 25 | { |
| 26 | readonly get: ( |
| 27 | environmentId: EnvironmentId, |
| 28 | ) => Effect.Effect<Option.Option<RemoteDpopAccessToken>, ConnectionAttemptError>; |
| 29 | readonly put: (token: RemoteDpopAccessToken) => Effect.Effect<void, ConnectionAttemptError>; |
| 30 | readonly remove: (environmentId: EnvironmentId) => Effect.Effect<void, ConnectionAttemptError>; |
| 31 | } |
| 32 | >()("@t3tools/client-runtime/authorization/tokenStore/RemoteDpopAccessTokenStore") {} |
| 33 | |
| 34 | export const make = (service: RemoteDpopAccessTokenStore["Service"]) => |
| 35 | RemoteDpopAccessTokenStore.of(service); |
| 36 | |
| 37 | export const layer = (service: RemoteDpopAccessTokenStore["Service"]) => |
| 38 | Layer.succeed(RemoteDpopAccessTokenStore, make(service)); |