AnyMux

Middleware API reference

Exports of @anymux/middleware. Back to the module

Classes

MemoryTokenStore

class
class MemoryTokenStore

get

method
get(key: string): Promise<TokenData | undefined>

set

method
set(key: string, token: TokenData): Promise<void>

delete

method
delete(key: string): Promise<boolean>

clear

method
clear(): Promise<void>

DatabaseTokenStore

class
class DatabaseTokenStore

constructor

constructor
constructor(db: KeyValueDB, prefix?: string): DatabaseTokenStore

get

method
get(key: string): Promise<TokenData | undefined>

set

method
set(key: string, token: TokenData): Promise<void>

delete

method
delete(key: string): Promise<boolean>

clear

method
clear(): Promise<void>

Functions

createOAuthMiddleware

function
createOAuthMiddleware(config: OAuthConfig, store: TokenStore): Hono<import("/home/andrew/gits/github/AnyFileSystem/AnyFsMnoorepo-sf-phase3-npmf/node_modules/.pnpm/hono@4.12.5/node_modules/hono/dist/types/types").BlankEnv, import("/home/andrew/gits/github/AnyFileSystem/AnyFsMnoorepo-sf-phase3-npmf/node_modules/.pnpm/hono@4.12.5/node_modules/hono/dist/types/types").BlankSchema, "/">

createCorsProxy

function
createCorsProxy(config: CorsConfig): MiddlewareHandler

createTokenRefresh

function
createTokenRefresh(config: TokenRefreshConfig): MiddlewareHandler

toExpressMiddleware

function
toExpressMiddleware(honoApp: Hono): (req: IncomingMessage, res: ServerResponse, next: () => void) => Promise<void>

toNextHandler

function
toNextHandler(honoApp: Hono): { GET: (req: Request) => Promise<Response>; POST: (req: Request) => Promise<Response>; PUT: (req: Request) => Promise<Response>; DELETE: (req: Request) => Promise<Response>; PATCH: (req: Request) => Promise<Response>; OPTIONS: (req: Request) => Promise<Response>; HEAD: (req: Request) => Promise<Response>; }

Types

OAuthConfig

type
type OAuthConfig = { clientId?: string; clientSecret?: string; authorizationUrl?: string; tokenUrl?: string; callbackUrl?: string; scopes?: string[]; state?: string; }

CorsConfig

type
type CorsConfig = { allowedOrigins?: string[]; allowedMethods?: string[]; allowedHeaders?: string[]; credentials?: boolean; maxAge?: number; }

Interfaces

TokenData

interface
interface TokenData

accessToken

property
accessToken: string

refreshToken

property
refreshToken: string

expiresAt

property
expiresAt: number

tokenType

property
tokenType: string

scope

property
scope: string

TokenStore

interface
interface TokenStore

get

method
get(key: string): Promise<TokenData | undefined>

set

method
set(key: string, token: TokenData): Promise<void>

delete

method
delete(key: string): Promise<boolean>

clear

method
clear(): Promise<void>

KeyValueDB

interface
interface KeyValueDB

get

method
get(key: string): Promise<string | undefined>

set

method
set(key: string, value: string): Promise<void>

delete

method
delete(key: string): Promise<boolean>

keys

method
keys(): Promise<string[]>

TokenRefreshConfig

interface
interface TokenRefreshConfig

tokenUrl

property
tokenUrl: string

clientId

property
clientId: string

clientSecret

property
clientSecret: string

store

property
store: TokenStore

Constants

OAuthConfigSchema

const
const OAuthConfigSchema: z.ZodObject<{ clientId: z.ZodString; clientSecret: z.ZodString; authorizationUrl: z.ZodString; tokenUrl: z.ZodString; callbackUrl: z.ZodString; scopes: z.ZodArray<z.ZodString, "many">; state: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { clientId?: string; clientSecret?: string; authorizationUrl?: string; tokenUrl?: string; callbackUrl?: string; scopes?: string[]; state?: string; }, { clientId?: string; clientSecret?: string; authorizationUrl?: string; tokenUrl?: string; callbackUrl?: string; scopes?: string[]; state?: string; }>

CorsConfigSchema

const
const CorsConfigSchema: z.ZodObject<{ allowedOrigins: z.ZodArray<z.ZodString, "many">; allowedMethods: z.ZodDefault<z.ZodArray<z.ZodString, "many">>; allowedHeaders: z.ZodDefault<z.ZodArray<z.ZodString, "many">>; credentials: z.ZodDefault<z.ZodBoolean>; maxAge: z.ZodDefault<z.ZodNumber>; }, "strip", z.ZodTypeAny, { allowedOrigins?: string[]; allowedMethods?: string[]; allowedHeaders?: string[]; credentials?: boolean; maxAge?: number; }, { allowedOrigins?: string[]; allowedMethods?: string[]; allowedHeaders?: string[]; credentials?: boolean; maxAge?: number; }>