vg-x07df 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/.azure-pipelines/publish-public.yml +37 -0
  2. package/.azure-pipelines/publish.yml +39 -0
  3. package/.changeset/README.md +8 -0
  4. package/.changeset/config.json +11 -0
  5. package/AUTO_JOIN_GUIDE.md +411 -0
  6. package/README.md +215 -0
  7. package/Screenshot 2025-09-24 at 14.34.48.png +0 -0
  8. package/Screenshot 2025-10-04 at 12.58.54.png +0 -0
  9. package/biome.json +48 -0
  10. package/examples/demo/.env.example +19 -0
  11. package/examples/demo/CHANGELOG.md +22 -0
  12. package/examples/demo/README.md +72 -0
  13. package/examples/demo/eslint.config.js +23 -0
  14. package/examples/demo/index.html +13 -0
  15. package/examples/demo/package.json +34 -0
  16. package/examples/demo/pnpm-lock.yaml +2098 -0
  17. package/examples/demo/pnpm-workspace.yaml +1 -0
  18. package/examples/demo/public/vite.svg +1 -0
  19. package/examples/demo/src/App.css +52 -0
  20. package/examples/demo/src/App.tsx +176 -0
  21. package/examples/demo/src/assets/react.svg +1 -0
  22. package/examples/demo/src/components/auth/LoginForm.css +144 -0
  23. package/examples/demo/src/components/auth/LoginForm.tsx +80 -0
  24. package/examples/demo/src/components/calling/AutoJoinSettings.tsx +213 -0
  25. package/examples/demo/src/components/calling/AutoJoinStatus.tsx +72 -0
  26. package/examples/demo/src/components/calling/CallInitiator.css +258 -0
  27. package/examples/demo/src/components/calling/CallInitiator.tsx +142 -0
  28. package/examples/demo/src/components/calling/CallNotifications.css +119 -0
  29. package/examples/demo/src/components/calling/CallNotifications.tsx +108 -0
  30. package/examples/demo/src/components/calling/IncomingCallModal.css +192 -0
  31. package/examples/demo/src/components/calling/IncomingCallModal.tsx +78 -0
  32. package/examples/demo/src/components/calling/MinimizedCall.css +156 -0
  33. package/examples/demo/src/components/calling/MinimizedCall.tsx +78 -0
  34. package/examples/demo/src/components/conference/ConferenceHeader.css +265 -0
  35. package/examples/demo/src/components/conference/ConferenceHeader.tsx +78 -0
  36. package/examples/demo/src/components/conference/EnhancedControlBar.css +356 -0
  37. package/examples/demo/src/components/conference/EnhancedControlBar.tsx +262 -0
  38. package/examples/demo/src/components/conference/PaginationControls.css +67 -0
  39. package/examples/demo/src/components/conference/PaginationControls.tsx +64 -0
  40. package/examples/demo/src/components/conference/ParticipantGrid.css +153 -0
  41. package/examples/demo/src/components/conference/ParticipantGrid.tsx +87 -0
  42. package/examples/demo/src/components/conference/ParticipantTile.css +210 -0
  43. package/examples/demo/src/components/conference/ParticipantTile.tsx +114 -0
  44. package/examples/demo/src/components/conference/VideoConference.css +214 -0
  45. package/examples/demo/src/components/conference/VideoConference.tsx +93 -0
  46. package/examples/demo/src/contexts/AuthContext.tsx +105 -0
  47. package/examples/demo/src/hooks/useAuth.ts +5 -0
  48. package/examples/demo/src/hooks/useCallTimer.ts +42 -0
  49. package/examples/demo/src/index.css +68 -0
  50. package/examples/demo/src/main.tsx +10 -0
  51. package/examples/demo/src/services/auth.service.ts +153 -0
  52. package/examples/demo/src/types/auth.types.ts +31 -0
  53. package/examples/demo/tsconfig.app.json +28 -0
  54. package/examples/demo/tsconfig.json +7 -0
  55. package/examples/demo/tsconfig.node.json +26 -0
  56. package/examples/demo/vite.config.ts +15 -0
  57. package/images/callpad-without-ai.png +0 -0
  58. package/package.json +28 -0
  59. package/packages/sdk/CHANGELOG.md +33 -0
  60. package/packages/sdk/LICENSE +21 -0
  61. package/packages/sdk/README.md +97 -0
  62. package/packages/sdk/documentation.md +1132 -0
  63. package/packages/sdk/openapi-ts.config.ts +7 -0
  64. package/packages/sdk/package.json +88 -0
  65. package/packages/sdk/src/core/auth.manager.ts +52 -0
  66. package/packages/sdk/src/core/events/event-bus.ts +301 -0
  67. package/packages/sdk/src/core/events/index.ts +8 -0
  68. package/packages/sdk/src/core/events/types.ts +165 -0
  69. package/packages/sdk/src/core/index.ts +3 -0
  70. package/packages/sdk/src/core/signal/api.config.ts +49 -0
  71. package/packages/sdk/src/core/signal/index.ts +16 -0
  72. package/packages/sdk/src/core/signal/signal.client.ts +101 -0
  73. package/packages/sdk/src/core/signal/types.ts +110 -0
  74. package/packages/sdk/src/core/socketio/handlers/base.handler.ts +212 -0
  75. package/packages/sdk/src/core/socketio/handlers/call-accepted.handler.ts +34 -0
  76. package/packages/sdk/src/core/socketio/handlers/call-canceled.handler.ts +34 -0
  77. package/packages/sdk/src/core/socketio/handlers/call-declined.handler.ts +29 -0
  78. package/packages/sdk/src/core/socketio/handlers/call-ended.handler.ts +40 -0
  79. package/packages/sdk/src/core/socketio/handlers/call-incoming.handler.ts +72 -0
  80. package/packages/sdk/src/core/socketio/handlers/call-join-info.handler.ts +181 -0
  81. package/packages/sdk/src/core/socketio/handlers/call-participant-joined.handler.ts +42 -0
  82. package/packages/sdk/src/core/socketio/handlers/call-participant-joining.handler.ts +42 -0
  83. package/packages/sdk/src/core/socketio/handlers/call-timeout.handler.ts +31 -0
  84. package/packages/sdk/src/core/socketio/handlers/handler.registry.ts +62 -0
  85. package/packages/sdk/src/core/socketio/handlers/index.ts +21 -0
  86. package/packages/sdk/src/core/socketio/handlers/participant-left.handler.ts +37 -0
  87. package/packages/sdk/src/core/socketio/handlers/schema.ts +130 -0
  88. package/packages/sdk/src/core/socketio/index.ts +5 -0
  89. package/packages/sdk/src/core/socketio/socket.manager.ts +187 -0
  90. package/packages/sdk/src/core/socketio/types.ts +14 -0
  91. package/packages/sdk/src/core/types.ts +23 -0
  92. package/packages/sdk/src/generated/api/core/ApiError.ts +21 -0
  93. package/packages/sdk/src/generated/api/core/ApiRequestOptions.ts +13 -0
  94. package/packages/sdk/src/generated/api/core/ApiResult.ts +7 -0
  95. package/packages/sdk/src/generated/api/core/CancelablePromise.ts +126 -0
  96. package/packages/sdk/src/generated/api/core/OpenAPI.ts +55 -0
  97. package/packages/sdk/src/generated/api/core/request.ts +339 -0
  98. package/packages/sdk/src/generated/api/index.ts +5 -0
  99. package/packages/sdk/src/generated/api/models.ts +219 -0
  100. package/packages/sdk/src/generated/api/services.ts +225 -0
  101. package/packages/sdk/src/hooks/index.ts +21 -0
  102. package/packages/sdk/src/hooks/useAutoJoin.ts +66 -0
  103. package/packages/sdk/src/hooks/useCallActions.ts +28 -0
  104. package/packages/sdk/src/hooks/useCallQuality.ts +416 -0
  105. package/packages/sdk/src/hooks/useCallState.ts +23 -0
  106. package/packages/sdk/src/hooks/useConnection.ts +15 -0
  107. package/packages/sdk/src/hooks/useDevices.ts +296 -0
  108. package/packages/sdk/src/hooks/useErrorRecovery.ts +299 -0
  109. package/packages/sdk/src/hooks/useErrors.ts +84 -0
  110. package/packages/sdk/src/hooks/useEvent.ts +188 -0
  111. package/packages/sdk/src/hooks/useMediaControls.ts +215 -0
  112. package/packages/sdk/src/hooks/useParticipantStatus.ts +318 -0
  113. package/packages/sdk/src/hooks/useParticipants.ts +111 -0
  114. package/packages/sdk/src/index.ts +66 -0
  115. package/packages/sdk/src/livekit/constants.ts +76 -0
  116. package/packages/sdk/src/livekit/device.manager.ts +172 -0
  117. package/packages/sdk/src/livekit/error-classifier.ts +155 -0
  118. package/packages/sdk/src/livekit/events/eventBridge.ts +371 -0
  119. package/packages/sdk/src/livekit/events/trackRegistry.ts +114 -0
  120. package/packages/sdk/src/livekit/index.ts +49 -0
  121. package/packages/sdk/src/livekit/livekit.service.ts +110 -0
  122. package/packages/sdk/src/livekit/media.controls.ts +315 -0
  123. package/packages/sdk/src/livekit/room.manager.ts +79 -0
  124. package/packages/sdk/src/livekit/track.utils.ts +230 -0
  125. package/packages/sdk/src/livekit/types.ts +135 -0
  126. package/packages/sdk/src/provider/RtcProvider.tsx +78 -0
  127. package/packages/sdk/src/services/call-actions.ts +260 -0
  128. package/packages/sdk/src/services/error-recovery.ts +461 -0
  129. package/packages/sdk/src/services/index.ts +2 -0
  130. package/packages/sdk/src/services/sdk-builder.ts +104 -0
  131. package/packages/sdk/src/state/errors.ts +163 -0
  132. package/packages/sdk/src/state/selectors.ts +28 -0
  133. package/packages/sdk/src/state/store.ts +36 -0
  134. package/packages/sdk/src/state/types.ts +151 -0
  135. package/packages/sdk/src/utils/logger.ts +183 -0
  136. package/packages/sdk/tsconfig.json +49 -0
  137. package/packages/sdk/tsup.config.ts +51 -0
  138. package/pnpm-workspace.yaml +4 -0
  139. package/tsconfig.base.json +19 -0
  140. package/turbo.json +34 -0
@@ -0,0 +1,187 @@
1
+ import { type Socket, io } from "socket.io-client";
2
+ import { createLogger } from "../../utils/logger";
3
+ import type { AuthManager } from "../auth.manager";
4
+ import type { AutoJoinConfig, Nullable } from "../types";
5
+ import { SocketHandlerRegistry } from "./handlers";
6
+ import type { SocketHandlerOptions } from "./handlers/base.handler";
7
+ import type { ConnectionConfig, ConnectionState } from "./types";
8
+
9
+ export class SocketManager {
10
+ private static instance: Nullable<SocketManager> = null;
11
+ private logger = createLogger("socket");
12
+
13
+ private socket: Nullable<Socket> = null;
14
+ private connectionState: ConnectionState = "DISCONNECTED";
15
+ private livekit: any = null;
16
+ private autoJoinConfig: Nullable<AutoJoinConfig> = null;
17
+ private handlerRegistry: Nullable<SocketHandlerRegistry> = null;
18
+ private authManager: Nullable<AuthManager> = null;
19
+
20
+ private constructor() {}
21
+
22
+ static getInstance(): SocketManager {
23
+ if (!SocketManager.instance) {
24
+ SocketManager.instance = new SocketManager();
25
+ }
26
+ return SocketManager.instance;
27
+ }
28
+
29
+ async initialize(
30
+ baseUrl: string,
31
+ authManager: AuthManager,
32
+ config: ConnectionConfig = {},
33
+ livekit?: any,
34
+ autoJoinConfig?: AutoJoinConfig
35
+ ): Promise<void> {
36
+ this.livekit = livekit;
37
+ this.autoJoinConfig = autoJoinConfig || null;
38
+ this.authManager = authManager;
39
+ if (this.socket?.connected) {
40
+ return;
41
+ }
42
+
43
+ this.updateConnectionState("CONNECTING");
44
+ const token = authManager.getCurrentToken();
45
+ if (!token) {
46
+ throw new Error("No authentication token available");
47
+ }
48
+
49
+ try {
50
+ this.socket = io(baseUrl, {
51
+ auth: { token },
52
+ autoConnect: false,
53
+ reconnection: true,
54
+ reconnectionAttempts: config.reconnectAttempts ?? 5,
55
+ reconnectionDelay: config.reconnectDelay ?? 1000,
56
+ reconnectionDelayMax: config.reconnectDelayMax ?? 30000,
57
+ timeout: config.timeout ?? 10000,
58
+ forceNew: true,
59
+ path: "/signal/socket.io",
60
+ transports: ["websocket"],
61
+ withCredentials: false,
62
+ });
63
+
64
+ this.setupConnectionHandlers(authManager);
65
+ this.setupEventHandlers();
66
+ this.socket.connect();
67
+ } catch (error) {
68
+ this.updateConnectionState("ERROR");
69
+ throw error;
70
+ }
71
+ }
72
+
73
+ private setupConnectionHandlers(authManager: AuthManager): void {
74
+ if (!this.socket) return;
75
+
76
+ this.socket.on("connect", () => {
77
+ this.updateConnectionState("CONNECTED");
78
+ this.logger.info("Connected to server");
79
+ });
80
+
81
+ this.socket.on("disconnect", (reason: string) => {
82
+ this.updateConnectionState("DISCONNECTED");
83
+ this.logger.info("Disconnected", { reason });
84
+ });
85
+
86
+ this.socket.on("connect_error", (error: Error) => {
87
+ this.updateConnectionState("ERROR");
88
+ this.logger.error("Connection error", { error: error.message });
89
+ });
90
+
91
+ this.socket.io.on("reconnect_attempt", () => {
92
+ this.updateConnectionState("RECONNECTING");
93
+ const freshToken = authManager.getCurrentToken();
94
+ if (freshToken && this.socket) {
95
+ this.logger.debug("Refreshing auth token for reconnection");
96
+ this.socket.auth = { token: freshToken };
97
+ }
98
+ });
99
+
100
+ this.socket.io.on("reconnect", (attemptNumber: number) => {
101
+ this.logger.info("Reconnected successfully", { attemptNumber });
102
+ });
103
+
104
+ this.socket.io.on("reconnect_error", (error: Error) => {
105
+ this.logger.error("Reconnection error", { error: error.message });
106
+ if (this.isAuthError(error)) {
107
+ this.updateConnectionState("FAILED");
108
+ }
109
+ });
110
+
111
+ this.socket.io.on("reconnect_failed", () => {
112
+ this.updateConnectionState("FAILED");
113
+ this.logger.error("All reconnection attempts failed");
114
+ });
115
+ }
116
+
117
+ private setupEventHandlers(): void {
118
+ if (!this.socket) {
119
+ return;
120
+ }
121
+
122
+ this.logger.debug("Setting up event handlers via registry");
123
+
124
+ console.log("[SOCKET_MANAGER] Setting up event handlers", {
125
+ socketId: this.socket.id,
126
+ connected: this.socket.connected,
127
+ });
128
+
129
+ // Clean up existing handlers to prevent duplicate registrations
130
+ if (this.handlerRegistry) {
131
+ this.handlerRegistry.removeEventListeners(this.socket);
132
+ this.handlerRegistry.destroy();
133
+ }
134
+
135
+ const options: SocketHandlerOptions = {
136
+ livekit: this.livekit,
137
+ autoJoinConfig: this.autoJoinConfig,
138
+ };
139
+
140
+ if (this.authManager) {
141
+ options.authManager = this.authManager;
142
+ }
143
+
144
+ this.handlerRegistry = new SocketHandlerRegistry(options);
145
+
146
+ this.handlerRegistry.registerEventListeners(this.socket);
147
+
148
+ console.log("[SOCKET_MANAGER] Event handlers registered successfully");
149
+ }
150
+
151
+ private isAuthError(error: Error): boolean {
152
+ const authErrorIndicators = [
153
+ "unauthorized",
154
+ "authentication",
155
+ "token",
156
+ "401",
157
+ "403",
158
+ ];
159
+ const errorMessage = error.message.toLowerCase();
160
+ return authErrorIndicators.some((indicator) =>
161
+ errorMessage.includes(indicator)
162
+ );
163
+ }
164
+
165
+ private updateConnectionState(newState: ConnectionState): void {
166
+ if (this.connectionState !== newState) {
167
+ this.connectionState = newState;
168
+ this.logger.debug("Connection state changed", { newState });
169
+ }
170
+ }
171
+
172
+ destroy(): void {
173
+ if (this.socket) {
174
+ if (this.handlerRegistry) {
175
+ this.handlerRegistry.removeEventListeners(this.socket);
176
+ this.handlerRegistry.destroy();
177
+ this.handlerRegistry = null;
178
+ }
179
+ this.socket.removeAllListeners();
180
+ this.socket.disconnect();
181
+ this.socket = null;
182
+ }
183
+ this.connectionState = "DISCONNECTED";
184
+ SocketManager.instance = null;
185
+ this.logger.debug("Destroyed and cleaned up");
186
+ }
187
+ }
@@ -0,0 +1,14 @@
1
+ export interface ConnectionConfig {
2
+ reconnectAttempts?: number;
3
+ reconnectDelay?: number;
4
+ reconnectDelayMax?: number;
5
+ timeout?: number;
6
+ }
7
+
8
+ export type ConnectionState =
9
+ | "DISCONNECTED"
10
+ | "CONNECTING"
11
+ | "CONNECTED"
12
+ | "RECONNECTING"
13
+ | "ERROR"
14
+ | "FAILED";
@@ -0,0 +1,23 @@
1
+ export type AuthProvider = () => string | null;
2
+
3
+ export interface TokenInfo {
4
+ token: string;
5
+ isExpired: boolean;
6
+ expiresAt?: number | undefined;
7
+ }
8
+
9
+ export interface JWTPayload {
10
+ exp?: number;
11
+ iat?: number;
12
+ sub?: string;
13
+ [key: string]: any;
14
+ }
15
+
16
+ export type Nullable<T> = T | null;
17
+
18
+ // Auto-join configuration types
19
+ export interface AutoJoinConfig {
20
+ enabled: boolean;
21
+ retryOnFailure: boolean;
22
+ maxRetries: number;
23
+ }
@@ -0,0 +1,21 @@
1
+ import type { ApiRequestOptions } from './ApiRequestOptions';
2
+ import type { ApiResult } from './ApiResult';
3
+
4
+ export class ApiError extends Error {
5
+ public readonly url: string;
6
+ public readonly status: number;
7
+ public readonly statusText: string;
8
+ public readonly body: unknown;
9
+ public readonly request: ApiRequestOptions;
10
+
11
+ constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
12
+ super(message);
13
+
14
+ this.name = 'ApiError';
15
+ this.url = response.url;
16
+ this.status = response.status;
17
+ this.statusText = response.statusText;
18
+ this.body = response.body;
19
+ this.request = request;
20
+ }
21
+ }
@@ -0,0 +1,13 @@
1
+ export type ApiRequestOptions = {
2
+ readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
3
+ readonly url: string;
4
+ readonly path?: Record<string, unknown>;
5
+ readonly cookies?: Record<string, unknown>;
6
+ readonly headers?: Record<string, unknown>;
7
+ readonly query?: Record<string, unknown>;
8
+ readonly formData?: Record<string, unknown>;
9
+ readonly body?: any;
10
+ readonly mediaType?: string;
11
+ readonly responseHeader?: string;
12
+ readonly errors?: Record<number, string>;
13
+ };
@@ -0,0 +1,7 @@
1
+ export type ApiResult<TData = any> = {
2
+ readonly body: TData;
3
+ readonly ok: boolean;
4
+ readonly status: number;
5
+ readonly statusText: string;
6
+ readonly url: string;
7
+ };
@@ -0,0 +1,126 @@
1
+ export class CancelError extends Error {
2
+ constructor(message: string) {
3
+ super(message);
4
+ this.name = 'CancelError';
5
+ }
6
+
7
+ public get isCancelled(): boolean {
8
+ return true;
9
+ }
10
+ }
11
+
12
+ export interface OnCancel {
13
+ readonly isResolved: boolean;
14
+ readonly isRejected: boolean;
15
+ readonly isCancelled: boolean;
16
+
17
+ (cancelHandler: () => void): void;
18
+ }
19
+
20
+ export class CancelablePromise<T> implements Promise<T> {
21
+ private _isResolved: boolean;
22
+ private _isRejected: boolean;
23
+ private _isCancelled: boolean;
24
+ readonly cancelHandlers: (() => void)[];
25
+ readonly promise: Promise<T>;
26
+ private _resolve?: (value: T | PromiseLike<T>) => void;
27
+ private _reject?: (reason?: unknown) => void;
28
+
29
+ constructor(
30
+ executor: (
31
+ resolve: (value: T | PromiseLike<T>) => void,
32
+ reject: (reason?: unknown) => void,
33
+ onCancel: OnCancel
34
+ ) => void
35
+ ) {
36
+ this._isResolved = false;
37
+ this._isRejected = false;
38
+ this._isCancelled = false;
39
+ this.cancelHandlers = [];
40
+ this.promise = new Promise<T>((resolve, reject) => {
41
+ this._resolve = resolve;
42
+ this._reject = reject;
43
+
44
+ const onResolve = (value: T | PromiseLike<T>): void => {
45
+ if (this._isResolved || this._isRejected || this._isCancelled) {
46
+ return;
47
+ }
48
+ this._isResolved = true;
49
+ if (this._resolve) this._resolve(value);
50
+ };
51
+
52
+ const onReject = (reason?: unknown): void => {
53
+ if (this._isResolved || this._isRejected || this._isCancelled) {
54
+ return;
55
+ }
56
+ this._isRejected = true;
57
+ if (this._reject) this._reject(reason);
58
+ };
59
+
60
+ const onCancel = (cancelHandler: () => void): void => {
61
+ if (this._isResolved || this._isRejected || this._isCancelled) {
62
+ return;
63
+ }
64
+ this.cancelHandlers.push(cancelHandler);
65
+ };
66
+
67
+ Object.defineProperty(onCancel, 'isResolved', {
68
+ get: (): boolean => this._isResolved,
69
+ });
70
+
71
+ Object.defineProperty(onCancel, 'isRejected', {
72
+ get: (): boolean => this._isRejected,
73
+ });
74
+
75
+ Object.defineProperty(onCancel, 'isCancelled', {
76
+ get: (): boolean => this._isCancelled,
77
+ });
78
+
79
+ return executor(onResolve, onReject, onCancel as OnCancel);
80
+ });
81
+ }
82
+
83
+ get [Symbol.toStringTag]() {
84
+ return "Cancellable Promise";
85
+ }
86
+
87
+ public then<TResult1 = T, TResult2 = never>(
88
+ onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
89
+ onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null
90
+ ): Promise<TResult1 | TResult2> {
91
+ return this.promise.then(onFulfilled, onRejected);
92
+ }
93
+
94
+ public catch<TResult = never>(
95
+ onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null
96
+ ): Promise<T | TResult> {
97
+ return this.promise.catch(onRejected);
98
+ }
99
+
100
+ public finally(onFinally?: (() => void) | null): Promise<T> {
101
+ return this.promise.finally(onFinally);
102
+ }
103
+
104
+ public cancel(): void {
105
+ if (this._isResolved || this._isRejected || this._isCancelled) {
106
+ return;
107
+ }
108
+ this._isCancelled = true;
109
+ if (this.cancelHandlers.length) {
110
+ try {
111
+ for (const cancelHandler of this.cancelHandlers) {
112
+ cancelHandler();
113
+ }
114
+ } catch (error) {
115
+ // Silently ignore cancellation errors
116
+ return;
117
+ }
118
+ }
119
+ this.cancelHandlers.length = 0;
120
+ if (this._reject) this._reject(new CancelError('Request aborted'));
121
+ }
122
+
123
+ public get isCancelled(): boolean {
124
+ return this._isCancelled;
125
+ }
126
+ }
@@ -0,0 +1,55 @@
1
+ import type { ApiRequestOptions } from './ApiRequestOptions';
2
+
3
+ type Headers = Record<string, string>;
4
+ type Middleware<T> = (value: T) => T | Promise<T>;
5
+ type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
6
+
7
+ export class Interceptors<T> {
8
+ _fns: Middleware<T>[];
9
+
10
+ constructor() {
11
+ this._fns = [];
12
+ }
13
+
14
+ eject(fn: Middleware<T>) {
15
+ const index = this._fns.indexOf(fn);
16
+ if (index !== -1) {
17
+ this._fns = [
18
+ ...this._fns.slice(0, index),
19
+ ...this._fns.slice(index + 1),
20
+ ];
21
+ }
22
+ }
23
+
24
+ use(fn: Middleware<T>) {
25
+ this._fns = [...this._fns, fn];
26
+ }
27
+ }
28
+
29
+ export type OpenAPIConfig = {
30
+ BASE: string;
31
+ CREDENTIALS: 'include' | 'omit' | 'same-origin';
32
+ ENCODE_PATH?: ((path: string) => string) | undefined;
33
+ HEADERS?: Headers | Resolver<Headers> | undefined;
34
+ PASSWORD?: string | Resolver<string> | undefined;
35
+ TOKEN?: string | Resolver<string> | undefined;
36
+ USERNAME?: string | Resolver<string> | undefined;
37
+ VERSION: string;
38
+ WITH_CREDENTIALS: boolean;
39
+ interceptors: {request: Interceptors<RequestInit>;
40
+ response: Interceptors<Response>;};
41
+ };
42
+
43
+ export const OpenAPI: OpenAPIConfig = {
44
+ BASE: '',
45
+ CREDENTIALS: 'include',
46
+ ENCODE_PATH: undefined,
47
+ HEADERS: undefined,
48
+ PASSWORD: undefined,
49
+ TOKEN: undefined,
50
+ USERNAME: undefined,
51
+ VERSION: '0.0.1',
52
+ WITH_CREDENTIALS: false,
53
+ interceptors: {request: new Interceptors(),response: new Interceptors(),
54
+ },
55
+ };