Files
plexjs/src/hooks/types.ts

75 lines
2.3 KiB
TypeScript

/*
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
*/
import { HTTPClient } from "../lib/http";
export type HookContext = {
operationID: string;
oAuth2Scopes?: string[];
securitySource?: any | (() => Promise<any>);
};
export type Awaitable<T> = T | Promise<T>;
export type SDKInitOptions = {
baseURL: URL | null;
client: HTTPClient;
};
export type BeforeRequestContext = HookContext & {};
export type AfterSuccessContext = HookContext & {};
export type AfterErrorContext = HookContext & {};
/**
* SDKInitHook is called when the SDK is initializing. The
* hook can return a new baseURL and HTTP client to be used by the SDK.
*/
export interface SDKInitHook {
sdkInit: (opts: SDKInitOptions) => SDKInitOptions;
}
/**
* BeforeRequestHook is called before the SDK sends a request. The hook can
* modify the request before it is sent or throw an error to stop the request
* from being sent.
*/
export interface BeforeRequestHook {
beforeRequest: (hookCtx: BeforeRequestContext, request: Request) => Awaitable<Request>;
}
/**
* AfterSuccessHook is called after the SDK receives a response. The hook can
* modify the response before it is handled or throw an error to stop the
* response from being handled.
*/
export interface AfterSuccessHook {
afterSuccess: (hookCtx: AfterSuccessContext, response: Response) => Awaitable<Response>;
}
/**
* AfterErrorHook is called after the SDK encounters an error, or a
* non-successful response. The hook can modify the response if available
* otherwise modify the error.
*/
export interface AfterErrorHook {
afterError: (
hookCtx: AfterErrorContext,
response: Response | null,
error: unknown
) => Awaitable<{
response: Response | null;
error: unknown;
}>;
}
export interface Hooks {
/** Registers a hook to be used by the SDK for initialization event. */
registerSDKInitHook(hook: SDKInitHook): void;
/** Registers a hook to be used by the SDK for the before request event. */
registerBeforeRequestHook(hook: BeforeRequestHook): void;
/** Registers a hook to be used by the SDK for the after success event. */
registerAfterSuccessHook(hook: AfterSuccessHook): void;
/** Registers a hook to be used by the SDK for the after error event. */
registerAfterErrorHook(hook: AfterErrorHook): void;
}