import { Config, Effect, Redacted, Schema } from "effect";
import { HttpClient } from "effect/http";
declare const SignInRequired_base: new = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
readonly _tag: "SignInRequired";
} & Readonly;
/**
* No sign-in to `resource` can give a token: none is kept, or the issuer refused to refresh it.
* Only the owner can mend it, by running `command`, which `message` names.
*/
export declare class SignInRequired extends SignInRequired_base<{
readonly resource: string;
/** The command that signs in again, such as `clankerauth login https://notes.example/`. */
readonly command: string;
readonly message: string;
}> {
}
declare const TokenUnavailable_base: new = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
readonly _tag: "TokenUnavailable";
} & Readonly;
/**
* The sign-in file could not be read, written or locked, or the issuer could not be reached or
* answered something unusable: `message` says which, for a person.
*/
export declare class TokenUnavailable extends TokenUnavailable_base<{
readonly message: string;
}> {
readonly cause?: unknown;
constructor(options: {
readonly message: string;
readonly cause?: unknown;
});
}
declare const SignInFailed_base: new = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
readonly _tag: "SignInFailed";
} & Readonly;
/**
* A sign-in did not finish: the application, its issuer or the owner's approval failed, as
* `message` says, for a person.
*/
export declare class SignInFailed extends SignInFailed_base<{
readonly message: string;
}> {
}
/**
* The owner's authorization for one resource, with all a refresh needs: the issuer, and the
* client the sign-in registered there. The access token lasts fifteen minutes and the refresh
* token rotates on every use, so the file is rewritten whenever one is refreshed.
*/
export declare const SignIn: Schema.Struct<{
/** The token audience: a resource identifier, such as `https://notes.home.example/`. */
readonly resource: Schema.String;
/** The issuer's origin, `CLANKERAUTH_BASE_URL`: where `/api/owner/` is served. */
readonly url: Schema.String;
readonly server: Schema.Struct<{
readonly issuer: Schema.String;
readonly authorization_endpoint: Schema.String;
readonly token_endpoint: Schema.String;
readonly registration_endpoint: Schema.String;
readonly revocation_endpoint: Schema.String;
}>;
readonly clientId: Schema.String;
/** The scopes granted, `offline_access` among them. */
readonly scope: Schema.String;
readonly accessToken: Schema.String;
readonly refreshToken: Schema.String;
/** When the access token expires, as an ISO instant. */
readonly expiresAt: Schema.String;
}>;
export type SignIn = typeof SignIn.Type;
/** The file's path, read from the environment on every call. */
export declare const path: () => string;
/** Every sign-in kept; none when there is no file, or one no version of it can be read from. */
export declare const list: Effect.Effect<{
readonly resource: string;
readonly url: string;
readonly server: {
readonly issuer: string;
readonly authorization_endpoint: string;
readonly token_endpoint: string;
readonly registration_endpoint: string;
readonly revocation_endpoint: string;
};
readonly clientId: string;
readonly scope: string;
readonly accessToken: string;
readonly refreshToken: string;
readonly expiresAt: string;
}[], TokenUnavailable, never>;
export interface TokenOptions {
/**
* Where the program calls the application, or any address under its resource: the sign-in
* used is the one whose resource holds this URL, the most specific when several do.
*/
readonly url: string | URL;
/**
* A bearer token the environment may give, an API key or an access token, returned instead
* of any sign-in when it is set: `Config.Redacted("NOTES_TOKEN")`.
*/
readonly token?: Config.Config;
}
/**
* A program's bearer token for the application at `options.url`: the environment's when it
* gives one, so the program runs unattended, and otherwise the owner's sign-in whose resource
* holds the URL, which `clankerauth login ` keeps and this refreshes. Ask again for each
* call, or each run: a token is never within a minute of expiring.
*/
export declare const token: (options: TokenOptions) => Effect.Effect, SignInRequired | TokenUnavailable, never>;
/**
* A client sending the bearer token `token` gives for `options` with each request, so a long run
* is refreshed as it goes: an effect-actions client's `transformClient`, whose methods then fail
* with `SignInRequired` and `TokenUnavailable` too.
*
* ```ts
* const notes = yield* ActionHttp.client(NotesHttp, {
* baseUrl: "https://notes.home.example",
* transformClient: Credentials.authorizing({ url: "https://notes.home.example/" }),
* });
* ```
*/
export declare const authorizing: (options: TokenOptions) => (client: HttpClient.HttpClient) => HttpClient.HttpClient.With;
export interface SignInOptions {
/** The scopes to ask for, space-separated; every scope the resource publishes when left out. */
readonly scope?: string | undefined;
/**
* Show the owner the issuer's approval page, such as by printing its URL. The sign-in then
* waits up to five minutes for the approval.
*/
readonly approve: (page: URL) => Effect.Effect;
}
/**
* Sign in as the issuer's owner to the resource `url` identifies, read from its
* `/.well-known/oauth-protected-resource`, and keep the sign-in, replacing and revoking any to
* that resource. The issuer is the one the resource names; the sign-in registers a native OAuth
* client there, asks for `offline_access` beside the scopes, and listens for the redirect on a
* loopback port.
*/
export declare const signIn: (url: string, options: SignInOptions) => Effect.Effect<{
url: string;
resource: string;
scope: string;
}, SignInFailed | TokenUnavailable, never>;
/**
* Forget the sign-in whose resource holds `url`, or every one, holding the file's lock so a
* refresh never slips between, then revoke it. A sign-in is forgotten even when the issuer does
* not answer its revocation.
*/
export declare const signOut: (url?: string | URL | undefined) => Effect.Effect<{
signedOut: boolean;
}, TokenUnavailable, never>;
export {};