-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.ts
98 lines (87 loc) · 3.14 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import { HTTPClient, RequestInput } from "../lib/http.js";
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 BeforeCreateRequestContext = HookContext & {};
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;
}
export interface BeforeCreateRequestHook {
/**
* A hook that is called before the SDK creates a `Request` object. The hook
* can modify how a request is constructed since certain modifications, like
* changing the request URL, cannot be done on a request object directly.
*/
beforeCreateRequest: (
hookCtx: BeforeCreateRequestContext,
input: RequestInput,
) => RequestInput;
}
export interface BeforeRequestHook {
/**
* A hook that is called before the SDK sends a request. The hook can
* introduce instrumentation code such as logging, tracing and metrics or
* replace the request before it is sent or throw an error to stop the
* request from being sent.
*/
beforeRequest: (
hookCtx: BeforeRequestContext,
request: Request,
) => Awaitable<Request>;
}
export interface AfterSuccessHook {
/**
* A hook that is called after the SDK receives a response. The hook can
* introduce instrumentation code such as logging, tracing and metrics or
* modify the response before it is handled or throw an error to stop the
* response from being handled.
*/
afterSuccess: (
hookCtx: AfterSuccessContext,
response: Response,
) => Awaitable<Response>;
}
export interface AfterErrorHook {
/**
* A hook that is called after the SDK encounters an error, or a
* non-successful response. The hook can introduce instrumentation code such
* as logging, tracing and metrics or modify the response or error values.
*/
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 to modify `Request` construction. */
registerBeforeCreateRequestHook(hook: BeforeCreateRequestHook): 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;
}