@insforge/sdk 1.2.0-dev.1 → 1.2.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.
- package/dist/index.d.mts +145 -2
- package/dist/index.d.ts +145 -2
- package/dist/index.js +367 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +366 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -45,6 +45,35 @@ interface InsForgeConfig {
|
|
|
45
45
|
* Custom headers to include with every request
|
|
46
46
|
*/
|
|
47
47
|
headers?: Record<string, string>;
|
|
48
|
+
/**
|
|
49
|
+
* Enable debug logging for HTTP requests and responses.
|
|
50
|
+
* When true, request/response details are logged to the console.
|
|
51
|
+
* Can also be a custom log function for advanced use cases.
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
debug?: boolean | ((message: string, ...args: any[]) => void);
|
|
55
|
+
/**
|
|
56
|
+
* Request timeout in milliseconds.
|
|
57
|
+
* Requests that exceed this duration will be aborted.
|
|
58
|
+
* Set to 0 to disable timeout.
|
|
59
|
+
* @default 30000
|
|
60
|
+
*/
|
|
61
|
+
timeout?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum number of retry attempts for failed requests.
|
|
64
|
+
* Retries are triggered on network errors and server errors (5xx).
|
|
65
|
+
* Client errors (4xx) are never retried.
|
|
66
|
+
* Set to 0 to disable retries.
|
|
67
|
+
* @default 3
|
|
68
|
+
*/
|
|
69
|
+
retryCount?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Initial delay in milliseconds before the first retry.
|
|
72
|
+
* The delay doubles with each subsequent attempt (exponential backoff)
|
|
73
|
+
* with ±15% jitter to prevent thundering herd.
|
|
74
|
+
* @default 500
|
|
75
|
+
*/
|
|
76
|
+
retryDelay?: number;
|
|
48
77
|
}
|
|
49
78
|
interface AuthSession {
|
|
50
79
|
user: UserSchema;
|
|
@@ -65,24 +94,132 @@ declare class InsForgeError extends Error {
|
|
|
65
94
|
static fromApiError(apiError: ApiError): InsForgeError;
|
|
66
95
|
}
|
|
67
96
|
|
|
97
|
+
type LogFunction = (message: string, ...args: any[]) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Debug logger for the InsForge SDK.
|
|
100
|
+
* Logs HTTP request/response details with automatic redaction of sensitive data.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // Enable via SDK config
|
|
105
|
+
* const client = new InsForgeClient({ debug: true });
|
|
106
|
+
*
|
|
107
|
+
* // Or with a custom log function
|
|
108
|
+
* const client = new InsForgeClient({
|
|
109
|
+
* debug: (msg) => myLogger.info(msg)
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare class Logger {
|
|
114
|
+
/** Whether debug logging is currently enabled */
|
|
115
|
+
enabled: boolean;
|
|
116
|
+
private customLog;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new Logger instance.
|
|
119
|
+
* @param debug - Set to true to enable console logging, or pass a custom log function
|
|
120
|
+
*/
|
|
121
|
+
constructor(debug?: boolean | LogFunction);
|
|
122
|
+
/**
|
|
123
|
+
* Logs a debug message at the info level.
|
|
124
|
+
* @param message - The message to log
|
|
125
|
+
* @param args - Additional arguments to pass to the log function
|
|
126
|
+
*/
|
|
127
|
+
log(message: string, ...args: any[]): void;
|
|
128
|
+
/**
|
|
129
|
+
* Logs a debug message at the warning level.
|
|
130
|
+
* @param message - The message to log
|
|
131
|
+
* @param args - Additional arguments to pass to the log function
|
|
132
|
+
*/
|
|
133
|
+
warn(message: string, ...args: any[]): void;
|
|
134
|
+
/**
|
|
135
|
+
* Logs a debug message at the error level.
|
|
136
|
+
* @param message - The message to log
|
|
137
|
+
* @param args - Additional arguments to pass to the log function
|
|
138
|
+
*/
|
|
139
|
+
error(message: string, ...args: any[]): void;
|
|
140
|
+
/**
|
|
141
|
+
* Logs an outgoing HTTP request with method, URL, headers, and body.
|
|
142
|
+
* Sensitive headers and body fields are automatically redacted.
|
|
143
|
+
* @param method - HTTP method (GET, POST, etc.)
|
|
144
|
+
* @param url - The full request URL
|
|
145
|
+
* @param headers - Request headers (sensitive values will be redacted)
|
|
146
|
+
* @param body - Request body (sensitive fields will be masked)
|
|
147
|
+
*/
|
|
148
|
+
logRequest(method: string, url: string, headers?: Record<string, string>, body?: any): void;
|
|
149
|
+
/**
|
|
150
|
+
* Logs an incoming HTTP response with method, URL, status, duration, and body.
|
|
151
|
+
* Error responses (4xx/5xx) are logged at the error level.
|
|
152
|
+
* @param method - HTTP method (GET, POST, etc.)
|
|
153
|
+
* @param url - The full request URL
|
|
154
|
+
* @param status - HTTP response status code
|
|
155
|
+
* @param durationMs - Request duration in milliseconds
|
|
156
|
+
* @param body - Response body (sensitive fields will be masked, large bodies truncated)
|
|
157
|
+
*/
|
|
158
|
+
logResponse(method: string, url: string, status: number, durationMs: number, body?: any): void;
|
|
159
|
+
}
|
|
160
|
+
|
|
68
161
|
interface RequestOptions extends RequestInit {
|
|
69
162
|
params?: Record<string, string>;
|
|
163
|
+
/** Allow retrying non-idempotent requests (POST, PATCH). Off by default to prevent duplicate writes. */
|
|
164
|
+
idempotent?: boolean;
|
|
70
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* HTTP client with built-in retry, timeout, and exponential backoff support.
|
|
168
|
+
* Handles authentication, request serialization, and error normalization.
|
|
169
|
+
*/
|
|
71
170
|
declare class HttpClient {
|
|
72
171
|
readonly baseUrl: string;
|
|
73
172
|
readonly fetch: typeof fetch;
|
|
74
173
|
private defaultHeaders;
|
|
75
174
|
private anonKey;
|
|
76
175
|
private userToken;
|
|
77
|
-
|
|
176
|
+
private logger;
|
|
177
|
+
private timeout;
|
|
178
|
+
private retryCount;
|
|
179
|
+
private retryDelay;
|
|
180
|
+
/**
|
|
181
|
+
* Creates a new HttpClient instance.
|
|
182
|
+
* @param config - SDK configuration including baseUrl, timeout, retry settings, and fetch implementation.
|
|
183
|
+
* @param logger - Optional logger instance for request/response debugging.
|
|
184
|
+
*/
|
|
185
|
+
constructor(config: InsForgeConfig, logger?: Logger);
|
|
186
|
+
/**
|
|
187
|
+
* Builds a full URL from a path and optional query parameters.
|
|
188
|
+
* Normalizes PostgREST select parameters for proper syntax.
|
|
189
|
+
*/
|
|
78
190
|
private buildUrl;
|
|
191
|
+
/** Checks if an HTTP status code is eligible for retry (5xx server errors). */
|
|
192
|
+
private isRetryableStatus;
|
|
193
|
+
/**
|
|
194
|
+
* Computes the delay before the next retry using exponential backoff with jitter.
|
|
195
|
+
* @param attempt - The current retry attempt number (1-based).
|
|
196
|
+
* @returns Delay in milliseconds.
|
|
197
|
+
*/
|
|
198
|
+
private computeRetryDelay;
|
|
199
|
+
/**
|
|
200
|
+
* Performs an HTTP request with automatic retry and timeout handling.
|
|
201
|
+
* Retries on network errors and 5xx server errors with exponential backoff.
|
|
202
|
+
* Client errors (4xx) and timeouts are thrown immediately without retry.
|
|
203
|
+
* @param method - HTTP method (GET, POST, PUT, PATCH, DELETE).
|
|
204
|
+
* @param path - API path relative to the base URL.
|
|
205
|
+
* @param options - Optional request configuration including headers, body, and query params.
|
|
206
|
+
* @returns Parsed response data.
|
|
207
|
+
* @throws {InsForgeError} On timeout, network failure, or HTTP error responses.
|
|
208
|
+
*/
|
|
79
209
|
request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
|
|
210
|
+
/** Performs a GET request. */
|
|
80
211
|
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
212
|
+
/** Performs a POST request with an optional JSON body. */
|
|
81
213
|
post<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
214
|
+
/** Performs a PUT request with an optional JSON body. */
|
|
82
215
|
put<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
216
|
+
/** Performs a PATCH request with an optional JSON body. */
|
|
83
217
|
patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
218
|
+
/** Performs a DELETE request. */
|
|
84
219
|
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
220
|
+
/** Sets or clears the user authentication token for subsequent requests. */
|
|
85
221
|
setAuthToken(token: string | null): void;
|
|
222
|
+
/** Returns the current default headers including the authorization header if set. */
|
|
86
223
|
getHeaders(): Record<string, string>;
|
|
87
224
|
}
|
|
88
225
|
|
|
@@ -870,6 +1007,12 @@ declare class Emails {
|
|
|
870
1007
|
* const { data, error } = await client.functions.invoke('my-function', {
|
|
871
1008
|
* body: { message: 'Hello from SDK' }
|
|
872
1009
|
* });
|
|
1010
|
+
*
|
|
1011
|
+
* // Enable debug logging
|
|
1012
|
+
* const debugClient = new InsForgeClient({
|
|
1013
|
+
* baseUrl: 'http://localhost:7130',
|
|
1014
|
+
* debug: true
|
|
1015
|
+
* });
|
|
873
1016
|
* ```
|
|
874
1017
|
*/
|
|
875
1018
|
declare class InsForgeClient {
|
|
@@ -903,4 +1046,4 @@ declare class InsForgeClient {
|
|
|
903
1046
|
|
|
904
1047
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
905
1048
|
|
|
906
|
-
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, Emails, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, createClient, InsForgeClient as default };
|
|
1049
|
+
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, Emails, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Logger, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, createClient, InsForgeClient as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -45,6 +45,35 @@ interface InsForgeConfig {
|
|
|
45
45
|
* Custom headers to include with every request
|
|
46
46
|
*/
|
|
47
47
|
headers?: Record<string, string>;
|
|
48
|
+
/**
|
|
49
|
+
* Enable debug logging for HTTP requests and responses.
|
|
50
|
+
* When true, request/response details are logged to the console.
|
|
51
|
+
* Can also be a custom log function for advanced use cases.
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
debug?: boolean | ((message: string, ...args: any[]) => void);
|
|
55
|
+
/**
|
|
56
|
+
* Request timeout in milliseconds.
|
|
57
|
+
* Requests that exceed this duration will be aborted.
|
|
58
|
+
* Set to 0 to disable timeout.
|
|
59
|
+
* @default 30000
|
|
60
|
+
*/
|
|
61
|
+
timeout?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum number of retry attempts for failed requests.
|
|
64
|
+
* Retries are triggered on network errors and server errors (5xx).
|
|
65
|
+
* Client errors (4xx) are never retried.
|
|
66
|
+
* Set to 0 to disable retries.
|
|
67
|
+
* @default 3
|
|
68
|
+
*/
|
|
69
|
+
retryCount?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Initial delay in milliseconds before the first retry.
|
|
72
|
+
* The delay doubles with each subsequent attempt (exponential backoff)
|
|
73
|
+
* with ±15% jitter to prevent thundering herd.
|
|
74
|
+
* @default 500
|
|
75
|
+
*/
|
|
76
|
+
retryDelay?: number;
|
|
48
77
|
}
|
|
49
78
|
interface AuthSession {
|
|
50
79
|
user: UserSchema;
|
|
@@ -65,24 +94,132 @@ declare class InsForgeError extends Error {
|
|
|
65
94
|
static fromApiError(apiError: ApiError): InsForgeError;
|
|
66
95
|
}
|
|
67
96
|
|
|
97
|
+
type LogFunction = (message: string, ...args: any[]) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Debug logger for the InsForge SDK.
|
|
100
|
+
* Logs HTTP request/response details with automatic redaction of sensitive data.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // Enable via SDK config
|
|
105
|
+
* const client = new InsForgeClient({ debug: true });
|
|
106
|
+
*
|
|
107
|
+
* // Or with a custom log function
|
|
108
|
+
* const client = new InsForgeClient({
|
|
109
|
+
* debug: (msg) => myLogger.info(msg)
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare class Logger {
|
|
114
|
+
/** Whether debug logging is currently enabled */
|
|
115
|
+
enabled: boolean;
|
|
116
|
+
private customLog;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new Logger instance.
|
|
119
|
+
* @param debug - Set to true to enable console logging, or pass a custom log function
|
|
120
|
+
*/
|
|
121
|
+
constructor(debug?: boolean | LogFunction);
|
|
122
|
+
/**
|
|
123
|
+
* Logs a debug message at the info level.
|
|
124
|
+
* @param message - The message to log
|
|
125
|
+
* @param args - Additional arguments to pass to the log function
|
|
126
|
+
*/
|
|
127
|
+
log(message: string, ...args: any[]): void;
|
|
128
|
+
/**
|
|
129
|
+
* Logs a debug message at the warning level.
|
|
130
|
+
* @param message - The message to log
|
|
131
|
+
* @param args - Additional arguments to pass to the log function
|
|
132
|
+
*/
|
|
133
|
+
warn(message: string, ...args: any[]): void;
|
|
134
|
+
/**
|
|
135
|
+
* Logs a debug message at the error level.
|
|
136
|
+
* @param message - The message to log
|
|
137
|
+
* @param args - Additional arguments to pass to the log function
|
|
138
|
+
*/
|
|
139
|
+
error(message: string, ...args: any[]): void;
|
|
140
|
+
/**
|
|
141
|
+
* Logs an outgoing HTTP request with method, URL, headers, and body.
|
|
142
|
+
* Sensitive headers and body fields are automatically redacted.
|
|
143
|
+
* @param method - HTTP method (GET, POST, etc.)
|
|
144
|
+
* @param url - The full request URL
|
|
145
|
+
* @param headers - Request headers (sensitive values will be redacted)
|
|
146
|
+
* @param body - Request body (sensitive fields will be masked)
|
|
147
|
+
*/
|
|
148
|
+
logRequest(method: string, url: string, headers?: Record<string, string>, body?: any): void;
|
|
149
|
+
/**
|
|
150
|
+
* Logs an incoming HTTP response with method, URL, status, duration, and body.
|
|
151
|
+
* Error responses (4xx/5xx) are logged at the error level.
|
|
152
|
+
* @param method - HTTP method (GET, POST, etc.)
|
|
153
|
+
* @param url - The full request URL
|
|
154
|
+
* @param status - HTTP response status code
|
|
155
|
+
* @param durationMs - Request duration in milliseconds
|
|
156
|
+
* @param body - Response body (sensitive fields will be masked, large bodies truncated)
|
|
157
|
+
*/
|
|
158
|
+
logResponse(method: string, url: string, status: number, durationMs: number, body?: any): void;
|
|
159
|
+
}
|
|
160
|
+
|
|
68
161
|
interface RequestOptions extends RequestInit {
|
|
69
162
|
params?: Record<string, string>;
|
|
163
|
+
/** Allow retrying non-idempotent requests (POST, PATCH). Off by default to prevent duplicate writes. */
|
|
164
|
+
idempotent?: boolean;
|
|
70
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* HTTP client with built-in retry, timeout, and exponential backoff support.
|
|
168
|
+
* Handles authentication, request serialization, and error normalization.
|
|
169
|
+
*/
|
|
71
170
|
declare class HttpClient {
|
|
72
171
|
readonly baseUrl: string;
|
|
73
172
|
readonly fetch: typeof fetch;
|
|
74
173
|
private defaultHeaders;
|
|
75
174
|
private anonKey;
|
|
76
175
|
private userToken;
|
|
77
|
-
|
|
176
|
+
private logger;
|
|
177
|
+
private timeout;
|
|
178
|
+
private retryCount;
|
|
179
|
+
private retryDelay;
|
|
180
|
+
/**
|
|
181
|
+
* Creates a new HttpClient instance.
|
|
182
|
+
* @param config - SDK configuration including baseUrl, timeout, retry settings, and fetch implementation.
|
|
183
|
+
* @param logger - Optional logger instance for request/response debugging.
|
|
184
|
+
*/
|
|
185
|
+
constructor(config: InsForgeConfig, logger?: Logger);
|
|
186
|
+
/**
|
|
187
|
+
* Builds a full URL from a path and optional query parameters.
|
|
188
|
+
* Normalizes PostgREST select parameters for proper syntax.
|
|
189
|
+
*/
|
|
78
190
|
private buildUrl;
|
|
191
|
+
/** Checks if an HTTP status code is eligible for retry (5xx server errors). */
|
|
192
|
+
private isRetryableStatus;
|
|
193
|
+
/**
|
|
194
|
+
* Computes the delay before the next retry using exponential backoff with jitter.
|
|
195
|
+
* @param attempt - The current retry attempt number (1-based).
|
|
196
|
+
* @returns Delay in milliseconds.
|
|
197
|
+
*/
|
|
198
|
+
private computeRetryDelay;
|
|
199
|
+
/**
|
|
200
|
+
* Performs an HTTP request with automatic retry and timeout handling.
|
|
201
|
+
* Retries on network errors and 5xx server errors with exponential backoff.
|
|
202
|
+
* Client errors (4xx) and timeouts are thrown immediately without retry.
|
|
203
|
+
* @param method - HTTP method (GET, POST, PUT, PATCH, DELETE).
|
|
204
|
+
* @param path - API path relative to the base URL.
|
|
205
|
+
* @param options - Optional request configuration including headers, body, and query params.
|
|
206
|
+
* @returns Parsed response data.
|
|
207
|
+
* @throws {InsForgeError} On timeout, network failure, or HTTP error responses.
|
|
208
|
+
*/
|
|
79
209
|
request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
|
|
210
|
+
/** Performs a GET request. */
|
|
80
211
|
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
212
|
+
/** Performs a POST request with an optional JSON body. */
|
|
81
213
|
post<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
214
|
+
/** Performs a PUT request with an optional JSON body. */
|
|
82
215
|
put<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
216
|
+
/** Performs a PATCH request with an optional JSON body. */
|
|
83
217
|
patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
218
|
+
/** Performs a DELETE request. */
|
|
84
219
|
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
220
|
+
/** Sets or clears the user authentication token for subsequent requests. */
|
|
85
221
|
setAuthToken(token: string | null): void;
|
|
222
|
+
/** Returns the current default headers including the authorization header if set. */
|
|
86
223
|
getHeaders(): Record<string, string>;
|
|
87
224
|
}
|
|
88
225
|
|
|
@@ -870,6 +1007,12 @@ declare class Emails {
|
|
|
870
1007
|
* const { data, error } = await client.functions.invoke('my-function', {
|
|
871
1008
|
* body: { message: 'Hello from SDK' }
|
|
872
1009
|
* });
|
|
1010
|
+
*
|
|
1011
|
+
* // Enable debug logging
|
|
1012
|
+
* const debugClient = new InsForgeClient({
|
|
1013
|
+
* baseUrl: 'http://localhost:7130',
|
|
1014
|
+
* debug: true
|
|
1015
|
+
* });
|
|
873
1016
|
* ```
|
|
874
1017
|
*/
|
|
875
1018
|
declare class InsForgeClient {
|
|
@@ -903,4 +1046,4 @@ declare class InsForgeClient {
|
|
|
903
1046
|
|
|
904
1047
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
905
1048
|
|
|
906
|
-
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, Emails, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, createClient, InsForgeClient as default };
|
|
1049
|
+
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, Emails, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Logger, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, createClient, InsForgeClient as default };
|