@insforge/sdk 1.4.0 → 1.4.1
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/README.md +17 -1
- package/SDK-REFERENCE.md +5 -1
- package/dist/{client-CqfpCc8Z.d.mts → client-DoWwzWnh.d.ts} +52 -112
- package/dist/{client-CqfpCc8Z.d.ts → client-hYdj36T6.d.mts} +52 -112
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +105 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -11
- package/dist/index.mjs.map +1 -1
- package/dist/middleware-BxJ0PzUT.d.mts +67 -0
- package/dist/middleware-DLZiheYP.d.ts +67 -0
- package/dist/ssr/middleware.d.mts +3 -0
- package/dist/ssr/middleware.d.ts +3 -0
- package/dist/ssr/middleware.js +461 -0
- package/dist/ssr/middleware.js.map +1 -0
- package/dist/ssr/middleware.mjs +428 -0
- package/dist/ssr/middleware.mjs.map +1 -0
- package/dist/ssr.d.mts +8 -69
- package/dist/ssr.d.ts +8 -69
- package/dist/ssr.js +107 -10
- package/dist/ssr.js.map +1 -1
- package/dist/ssr.mjs +107 -10
- package/dist/ssr.mjs.map +1 -1
- package/dist/types-NjykhyRq.d.mts +118 -0
- package/dist/types-NjykhyRq.d.ts +118 -0
- package/package.json +6 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { UserSchema, ErrorCode } from '@insforge/shared-schemas';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* InsForge SDK Types - only SDK-specific types here
|
|
5
|
+
* Use @insforge/shared-schemas directly for API types
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type InsForgeErrorCode = ErrorCode | (string & {});
|
|
9
|
+
interface InsForgeConfig {
|
|
10
|
+
/**
|
|
11
|
+
* The base URL of the InsForge backend API
|
|
12
|
+
* @default "http://localhost:7130"
|
|
13
|
+
*/
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Anonymous API key (optional)
|
|
17
|
+
* Used for public/unauthenticated requests when no user token is set
|
|
18
|
+
*/
|
|
19
|
+
anonKey?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Static access token (optional)
|
|
22
|
+
* Seeds the client with a fixed bearer token used for all authenticated
|
|
23
|
+
* requests — e.g. a user JWT inside an edge function, or a server-signed
|
|
24
|
+
* JWT from an external auth provider. Disables automatic token refresh
|
|
25
|
+
* and implies server mode unless `isServerMode` is set explicitly.
|
|
26
|
+
*/
|
|
27
|
+
accessToken?: string;
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use `accessToken` instead. Same behavior; `accessToken`
|
|
30
|
+
* takes precedence when both are provided.
|
|
31
|
+
*/
|
|
32
|
+
edgeFunctionToken?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Direct URL to Deno Subhosting functions (optional)
|
|
35
|
+
* When provided, SDK will try this URL first for function invocations.
|
|
36
|
+
* Falls back to proxy URL if subhosting returns 404.
|
|
37
|
+
* @example "https://{appKey}.functions.insforge.app"
|
|
38
|
+
*/
|
|
39
|
+
functionsUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Custom fetch implementation (useful for Node.js environments)
|
|
42
|
+
*/
|
|
43
|
+
fetch?: typeof fetch;
|
|
44
|
+
/**
|
|
45
|
+
* Enable server-side auth mode (SSR/Node runtime)
|
|
46
|
+
* In this mode auth endpoints use `client_type=mobile` and refresh_token body flow.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated Use `createServerClient()`, `createBrowserClient()`, and
|
|
49
|
+
* `updateSession()` from `@insforge/sdk/ssr` for SSR apps.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
isServerMode?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Custom headers to include with every request
|
|
55
|
+
*/
|
|
56
|
+
headers?: Record<string, string>;
|
|
57
|
+
/**
|
|
58
|
+
* Enable debug logging for HTTP requests and responses.
|
|
59
|
+
* When true, request/response details are logged to the console.
|
|
60
|
+
* Can also be a custom log function for advanced use cases.
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
debug?: boolean | ((message: string, ...args: any[]) => void);
|
|
64
|
+
/**
|
|
65
|
+
* Request timeout in milliseconds.
|
|
66
|
+
* Requests that exceed this duration will be aborted.
|
|
67
|
+
* Set to 0 to disable timeout.
|
|
68
|
+
* @default 30000
|
|
69
|
+
*/
|
|
70
|
+
timeout?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Maximum number of retry attempts for failed requests.
|
|
73
|
+
* Retries are triggered on network errors and server errors (5xx).
|
|
74
|
+
* Client errors (4xx) are never retried.
|
|
75
|
+
* Set to 0 to disable retries.
|
|
76
|
+
* @default 3
|
|
77
|
+
*/
|
|
78
|
+
retryCount?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Initial delay in milliseconds before the first retry.
|
|
81
|
+
* The delay doubles with each subsequent attempt (exponential backoff)
|
|
82
|
+
* with ±15% jitter to prevent thundering herd.
|
|
83
|
+
* @default 500
|
|
84
|
+
*/
|
|
85
|
+
retryDelay?: number;
|
|
86
|
+
}
|
|
87
|
+
type InsForgeAdminConfig = Omit<InsForgeConfig, 'anonKey' | 'accessToken' | 'edgeFunctionToken' | 'isServerMode'> & {
|
|
88
|
+
/**
|
|
89
|
+
* Project admin API key. Keep this server-side only.
|
|
90
|
+
*/
|
|
91
|
+
apiKey: string;
|
|
92
|
+
};
|
|
93
|
+
interface AuthSession {
|
|
94
|
+
user: UserSchema;
|
|
95
|
+
accessToken: string;
|
|
96
|
+
expiresAt?: Date;
|
|
97
|
+
}
|
|
98
|
+
interface AuthRefreshResponse {
|
|
99
|
+
user: UserSchema;
|
|
100
|
+
accessToken: string;
|
|
101
|
+
csrfToken?: string;
|
|
102
|
+
refreshToken?: string;
|
|
103
|
+
}
|
|
104
|
+
interface ApiError {
|
|
105
|
+
error: InsForgeErrorCode;
|
|
106
|
+
message: string;
|
|
107
|
+
statusCode: number;
|
|
108
|
+
nextActions?: string;
|
|
109
|
+
}
|
|
110
|
+
declare class InsForgeError extends Error {
|
|
111
|
+
statusCode: number;
|
|
112
|
+
error: InsForgeErrorCode;
|
|
113
|
+
nextActions?: string;
|
|
114
|
+
constructor(message: string, statusCode: number, error: InsForgeErrorCode, nextActions?: string);
|
|
115
|
+
static fromApiError(apiError: ApiError): InsForgeError;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { type AuthSession as A, type InsForgeConfig as I, type InsForgeAdminConfig as a, type ApiError as b, type InsForgeErrorCode as c, InsForgeError as d, type AuthRefreshResponse as e };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { UserSchema, ErrorCode } from '@insforge/shared-schemas';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* InsForge SDK Types - only SDK-specific types here
|
|
5
|
+
* Use @insforge/shared-schemas directly for API types
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type InsForgeErrorCode = ErrorCode | (string & {});
|
|
9
|
+
interface InsForgeConfig {
|
|
10
|
+
/**
|
|
11
|
+
* The base URL of the InsForge backend API
|
|
12
|
+
* @default "http://localhost:7130"
|
|
13
|
+
*/
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Anonymous API key (optional)
|
|
17
|
+
* Used for public/unauthenticated requests when no user token is set
|
|
18
|
+
*/
|
|
19
|
+
anonKey?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Static access token (optional)
|
|
22
|
+
* Seeds the client with a fixed bearer token used for all authenticated
|
|
23
|
+
* requests — e.g. a user JWT inside an edge function, or a server-signed
|
|
24
|
+
* JWT from an external auth provider. Disables automatic token refresh
|
|
25
|
+
* and implies server mode unless `isServerMode` is set explicitly.
|
|
26
|
+
*/
|
|
27
|
+
accessToken?: string;
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use `accessToken` instead. Same behavior; `accessToken`
|
|
30
|
+
* takes precedence when both are provided.
|
|
31
|
+
*/
|
|
32
|
+
edgeFunctionToken?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Direct URL to Deno Subhosting functions (optional)
|
|
35
|
+
* When provided, SDK will try this URL first for function invocations.
|
|
36
|
+
* Falls back to proxy URL if subhosting returns 404.
|
|
37
|
+
* @example "https://{appKey}.functions.insforge.app"
|
|
38
|
+
*/
|
|
39
|
+
functionsUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Custom fetch implementation (useful for Node.js environments)
|
|
42
|
+
*/
|
|
43
|
+
fetch?: typeof fetch;
|
|
44
|
+
/**
|
|
45
|
+
* Enable server-side auth mode (SSR/Node runtime)
|
|
46
|
+
* In this mode auth endpoints use `client_type=mobile` and refresh_token body flow.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated Use `createServerClient()`, `createBrowserClient()`, and
|
|
49
|
+
* `updateSession()` from `@insforge/sdk/ssr` for SSR apps.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
isServerMode?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Custom headers to include with every request
|
|
55
|
+
*/
|
|
56
|
+
headers?: Record<string, string>;
|
|
57
|
+
/**
|
|
58
|
+
* Enable debug logging for HTTP requests and responses.
|
|
59
|
+
* When true, request/response details are logged to the console.
|
|
60
|
+
* Can also be a custom log function for advanced use cases.
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
debug?: boolean | ((message: string, ...args: any[]) => void);
|
|
64
|
+
/**
|
|
65
|
+
* Request timeout in milliseconds.
|
|
66
|
+
* Requests that exceed this duration will be aborted.
|
|
67
|
+
* Set to 0 to disable timeout.
|
|
68
|
+
* @default 30000
|
|
69
|
+
*/
|
|
70
|
+
timeout?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Maximum number of retry attempts for failed requests.
|
|
73
|
+
* Retries are triggered on network errors and server errors (5xx).
|
|
74
|
+
* Client errors (4xx) are never retried.
|
|
75
|
+
* Set to 0 to disable retries.
|
|
76
|
+
* @default 3
|
|
77
|
+
*/
|
|
78
|
+
retryCount?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Initial delay in milliseconds before the first retry.
|
|
81
|
+
* The delay doubles with each subsequent attempt (exponential backoff)
|
|
82
|
+
* with ±15% jitter to prevent thundering herd.
|
|
83
|
+
* @default 500
|
|
84
|
+
*/
|
|
85
|
+
retryDelay?: number;
|
|
86
|
+
}
|
|
87
|
+
type InsForgeAdminConfig = Omit<InsForgeConfig, 'anonKey' | 'accessToken' | 'edgeFunctionToken' | 'isServerMode'> & {
|
|
88
|
+
/**
|
|
89
|
+
* Project admin API key. Keep this server-side only.
|
|
90
|
+
*/
|
|
91
|
+
apiKey: string;
|
|
92
|
+
};
|
|
93
|
+
interface AuthSession {
|
|
94
|
+
user: UserSchema;
|
|
95
|
+
accessToken: string;
|
|
96
|
+
expiresAt?: Date;
|
|
97
|
+
}
|
|
98
|
+
interface AuthRefreshResponse {
|
|
99
|
+
user: UserSchema;
|
|
100
|
+
accessToken: string;
|
|
101
|
+
csrfToken?: string;
|
|
102
|
+
refreshToken?: string;
|
|
103
|
+
}
|
|
104
|
+
interface ApiError {
|
|
105
|
+
error: InsForgeErrorCode;
|
|
106
|
+
message: string;
|
|
107
|
+
statusCode: number;
|
|
108
|
+
nextActions?: string;
|
|
109
|
+
}
|
|
110
|
+
declare class InsForgeError extends Error {
|
|
111
|
+
statusCode: number;
|
|
112
|
+
error: InsForgeErrorCode;
|
|
113
|
+
nextActions?: string;
|
|
114
|
+
constructor(message: string, statusCode: number, error: InsForgeErrorCode, nextActions?: string);
|
|
115
|
+
static fromApiError(apiError: ApiError): InsForgeError;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { type AuthSession as A, type InsForgeConfig as I, type InsForgeAdminConfig as a, type ApiError as b, type InsForgeErrorCode as c, InsForgeError as d, type AuthRefreshResponse as e };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insforge/sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Official JavaScript/TypeScript client for InsForge Backend-as-a-Service platform",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
"types": "./dist/ssr.d.ts",
|
|
16
16
|
"import": "./dist/ssr.mjs",
|
|
17
17
|
"require": "./dist/ssr.js"
|
|
18
|
+
},
|
|
19
|
+
"./ssr/middleware": {
|
|
20
|
+
"types": "./dist/ssr/middleware.d.ts",
|
|
21
|
+
"import": "./dist/ssr/middleware.mjs",
|
|
22
|
+
"require": "./dist/ssr/middleware.js"
|
|
18
23
|
}
|
|
19
24
|
},
|
|
20
25
|
"files": [
|