/** * @since 1.0.0 */ import * as Context from "effect/Context" import { dual } from "effect/Function" import { type Pipeable, pipeArguments } from "effect/Pipeable" import type { Redacted } from "effect/Redacted" import type { Covariant } from "effect/Types" /** * @since 1.0.0 * @category type ids */ export const TypeId: unique symbol = Symbol.for("@effect/platform/HttpApiSecurity") /** * @since 1.0.0 * @category type ids */ export type TypeId = typeof TypeId /** * @since 1.0.0 * @category models */ export type HttpApiSecurity = Bearer | ApiKey | Basic /** * @since 1.0.0 * @category models */ export declare namespace HttpApiSecurity { /** * @since 1.0.0 * @category models */ export interface Proto extends Pipeable { readonly [TypeId]: { readonly _A: Covariant } readonly annotations: Context.Context } /** * @since 1.0.0 * @category models */ export type Type = A extends Proto ? Out : never } /** * @since 1.0.0 * @category models */ export interface Bearer extends HttpApiSecurity.Proto { readonly _tag: "Bearer" } /** * @since 1.0.0 * @category models */ export interface ApiKey extends HttpApiSecurity.Proto { readonly _tag: "ApiKey" readonly in: "header" | "query" | "cookie" readonly key: string } /** * @since 1.0.0 * @category models */ export interface Basic extends HttpApiSecurity.Proto { readonly _tag: "Basic" } /** * @since 1.0.0 * @category models */ export interface Credentials { readonly username: string readonly password: Redacted } const Proto = { [TypeId]: TypeId, pipe() { return pipeArguments(this, arguments) } } /** * Create an Bearer token security scheme. * * You can implement some api middleware for this security scheme using * `HttpApiBuilder.middlewareSecurity`. * * @since 1.0.0 * @category constructors */ export const bearer: Bearer = Object.assign(Object.create(Proto), { _tag: "Bearer", annotations: Context.empty() }) /** * Create an API key security scheme. * * You can implement some api middleware for this security scheme using * `HttpApiBuilder.middlewareSecurity`. * * To set the correct cookie in a handler, you can use * `HttpApiBuilder.securitySetCookie`. * * The default value for `in` is "header". * * @since 1.0.0 * @category constructors */ export const apiKey = (options: { readonly key: string readonly in?: "header" | "query" | "cookie" | undefined }): ApiKey => Object.assign(Object.create(Proto), { _tag: "ApiKey", key: options.key, in: options.in ?? "header", annotations: Context.empty() }) /** * @since 1.0.0 * @category constructors */ export const basic: Basic = Object.assign(Object.create(Proto), { _tag: "Basic", annotations: Context.empty() }) /** * @since 1.0.0 * @category annotations */ export const annotateContext: { /** * @since 1.0.0 * @category annotations */ (context: Context.Context): (self: A) => A /** * @since 1.0.0 * @category annotations */ (self: A, context: Context.Context): A } = dual( 2, (self: A, context: Context.Context): A => Object.assign(Object.create(Proto), { ...self, annotations: Context.merge(self.annotations, context) }) ) /** * @since 1.0.0 * @category annotations */ export const annotate: { /** * @since 1.0.0 * @category annotations */ (tag: Context.Tag, value: S): (self: A) => A /** * @since 1.0.0 * @category annotations */ (self: A, tag: Context.Tag, value: S): A } = dual( 3, (self: A, tag: Context.Tag, value: S): A => Object.assign(Object.create(Proto), { ...self, annotations: Context.add(self.annotations, tag, value) }) )