@insforge/sdk 1.1.1 → 1.1.2-edge.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/LICENSE +201 -201
- package/README.md +259 -259
- package/dist/index.d.mts +48 -2
- package/dist/index.d.ts +48 -2
- package/dist/index.js +156 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +156 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +68 -68
package/README.md
CHANGED
|
@@ -1,259 +1,259 @@
|
|
|
1
|
-
# insforge-sdk-js
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@insforge/sdk)
|
|
4
|
-
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
|
-
|
|
6
|
-
Official TypeScript/JavaScript SDK for [InsForge](https://github.com/InsForge/InsForge) - A powerful, open-source Backend-as-a-Service (BaaS) platform.
|
|
7
|
-
|
|
8
|
-
## Features
|
|
9
|
-
|
|
10
|
-
- **Authentication** - Email/password, OAuth (Google, GitHub), session management
|
|
11
|
-
- **Database** - Full PostgreSQL database access with PostgREST
|
|
12
|
-
- **Storage** - File upload and management with S3-compatible storage
|
|
13
|
-
- **Edge Functions** - Serverless function invocation
|
|
14
|
-
- **AI Integration** - Built-in AI capabilities
|
|
15
|
-
- **TypeScript** - Full TypeScript support with type definitions
|
|
16
|
-
- **Automatic OAuth Handling** - Seamless OAuth callback detection
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install @insforge/sdk
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Or with yarn:
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
yarn add @insforge/sdk
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Quick Start
|
|
31
|
-
|
|
32
|
-
### Initialize the Client
|
|
33
|
-
|
|
34
|
-
```javascript
|
|
35
|
-
import { createClient } from '@insforge/sdk';
|
|
36
|
-
|
|
37
|
-
const insforge = createClient({
|
|
38
|
-
baseUrl: 'http://localhost:7130' // Your InsForge backend URL
|
|
39
|
-
});
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Authentication
|
|
43
|
-
|
|
44
|
-
```javascript
|
|
45
|
-
// Sign up a new user
|
|
46
|
-
const { data, error } = await insforge.auth.signUp({
|
|
47
|
-
email: 'user@example.com',
|
|
48
|
-
password: 'securePassword123',
|
|
49
|
-
name: 'John Doe' // optional
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Sign in with email/password
|
|
53
|
-
const { data, error } = await insforge.auth.signInWithPassword({
|
|
54
|
-
email: 'user@example.com',
|
|
55
|
-
password: 'securePassword123'
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// OAuth authentication (Google, GitHub)
|
|
59
|
-
await insforge.auth.signInWithOAuth({
|
|
60
|
-
provider: 'google',
|
|
61
|
-
redirectTo: 'http://localhost:3000/dashboard'
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Get current user
|
|
65
|
-
const { data: user } = await insforge.auth.getCurrentUser();
|
|
66
|
-
|
|
67
|
-
// Get any user's profile by ID (public endpoint)
|
|
68
|
-
const { data: profile, error } = await insforge.auth.getProfile('user-id-here');
|
|
69
|
-
|
|
70
|
-
// Update current user's profile (requires authentication)
|
|
71
|
-
const { data: updatedProfile, error } = await insforge.auth.setProfile({
|
|
72
|
-
displayName: 'John Doe',
|
|
73
|
-
bio: 'Software developer',
|
|
74
|
-
avatarUrl: 'https://example.com/avatar.jpg'
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Sign out
|
|
78
|
-
await insforge.auth.signOut();
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Database Operations
|
|
82
|
-
|
|
83
|
-
```javascript
|
|
84
|
-
// Insert data
|
|
85
|
-
const { data, error } = await insforge.database
|
|
86
|
-
.from('posts')
|
|
87
|
-
.insert([
|
|
88
|
-
{ title: 'My First Post', content: 'Hello World!' }
|
|
89
|
-
]);
|
|
90
|
-
|
|
91
|
-
// Query data
|
|
92
|
-
const { data, error } = await insforge.database
|
|
93
|
-
.from('posts')
|
|
94
|
-
.select('*')
|
|
95
|
-
.eq('author_id', userId);
|
|
96
|
-
|
|
97
|
-
// Update data
|
|
98
|
-
const { data, error } = await insforge.database
|
|
99
|
-
.from('posts')
|
|
100
|
-
.update({ title: 'Updated Title' })
|
|
101
|
-
.eq('id', postId);
|
|
102
|
-
|
|
103
|
-
// Delete data
|
|
104
|
-
const { data, error } = await insforge.database
|
|
105
|
-
.from('posts')
|
|
106
|
-
.delete()
|
|
107
|
-
.eq('id', postId);
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### File Storage
|
|
111
|
-
|
|
112
|
-
```javascript
|
|
113
|
-
// Upload a file
|
|
114
|
-
const file = document.querySelector('input[type="file"]').files[0];
|
|
115
|
-
const { data, error } = await insforge.storage
|
|
116
|
-
.from('avatars')
|
|
117
|
-
.upload(file);
|
|
118
|
-
|
|
119
|
-
// Download a file
|
|
120
|
-
const { data, error } = await insforge.storage
|
|
121
|
-
.from('avatars')
|
|
122
|
-
.download('user-avatar.png');
|
|
123
|
-
|
|
124
|
-
// Delete a file
|
|
125
|
-
const { data, error } = await insforge.storage
|
|
126
|
-
.from('avatars')
|
|
127
|
-
.remove(['user-avatar.png']);
|
|
128
|
-
|
|
129
|
-
// List files
|
|
130
|
-
const { data, error } = await insforge.storage
|
|
131
|
-
.from('avatars')
|
|
132
|
-
.list();
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Edge Functions
|
|
136
|
-
|
|
137
|
-
```javascript
|
|
138
|
-
// Invoke an edge function
|
|
139
|
-
const { data, error } = await insforge.functions.invoke('my-function', {
|
|
140
|
-
body: { key: 'value' }
|
|
141
|
-
});
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### AI Integration
|
|
145
|
-
|
|
146
|
-
```javascript
|
|
147
|
-
// Generate text completion
|
|
148
|
-
const { data, error } = await insforge.ai.completion({
|
|
149
|
-
model: 'gpt-3.5-turbo',
|
|
150
|
-
prompt: 'Write a hello world program'
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
// Analyze an image
|
|
154
|
-
const { data, error } = await insforge.ai.vision({
|
|
155
|
-
imageUrl: 'https://example.com/image.jpg',
|
|
156
|
-
prompt: 'Describe this image'
|
|
157
|
-
});
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
## Documentation
|
|
161
|
-
|
|
162
|
-
For complete API reference and advanced usage, see:
|
|
163
|
-
|
|
164
|
-
- **[SDK Reference](./SDK-REFERENCE.md)** - Complete API documentation
|
|
165
|
-
- **[InsForge Main Repository](https://github.com/InsForge/InsForge)** - Backend platform and setup guides
|
|
166
|
-
|
|
167
|
-
## Configuration
|
|
168
|
-
|
|
169
|
-
The SDK supports the following configuration options:
|
|
170
|
-
|
|
171
|
-
```javascript
|
|
172
|
-
const insforge = createClient({
|
|
173
|
-
baseUrl: 'http://localhost:7130', // Required: Your InsForge backend URL
|
|
174
|
-
storageStrategy: 'localStorage' // Optional: 'localStorage' or 'memory' (default: 'localStorage')
|
|
175
|
-
});
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## TypeScript Support
|
|
179
|
-
|
|
180
|
-
The SDK is written in TypeScript and provides full type definitions:
|
|
181
|
-
|
|
182
|
-
```typescript
|
|
183
|
-
import { createClient, InsForgeClient, User, Session } from '@insforge/sdk';
|
|
184
|
-
|
|
185
|
-
const insforge: InsForgeClient = createClient({
|
|
186
|
-
baseUrl: 'http://localhost:7130'
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// Type-safe API calls
|
|
190
|
-
const response: { data: User | null; error: Error | null } =
|
|
191
|
-
await insforge.auth.getCurrentUser();
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
## Error Handling
|
|
195
|
-
|
|
196
|
-
All SDK methods return a consistent response format:
|
|
197
|
-
|
|
198
|
-
```javascript
|
|
199
|
-
const { data, error } = await insforge.auth.signUp({...});
|
|
200
|
-
|
|
201
|
-
if (error) {
|
|
202
|
-
console.error('Error:', error.message);
|
|
203
|
-
console.error('Status:', error.statusCode);
|
|
204
|
-
} else {
|
|
205
|
-
console.log('Success:', data);
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
## Browser Support
|
|
210
|
-
|
|
211
|
-
The SDK works in all modern browsers that support:
|
|
212
|
-
- ES6+ features
|
|
213
|
-
- Fetch API
|
|
214
|
-
- LocalStorage (for session management)
|
|
215
|
-
|
|
216
|
-
For Node.js environments, ensure you're using Node.js 18 or higher.
|
|
217
|
-
|
|
218
|
-
## Contributing
|
|
219
|
-
|
|
220
|
-
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
|
|
221
|
-
|
|
222
|
-
### Development Setup
|
|
223
|
-
|
|
224
|
-
```bash
|
|
225
|
-
# Clone the repository
|
|
226
|
-
git clone https://github.com/InsForge/insforge-sdk-js.git
|
|
227
|
-
cd insforge-sdk-js
|
|
228
|
-
|
|
229
|
-
# Install dependencies
|
|
230
|
-
npm install
|
|
231
|
-
|
|
232
|
-
# Build the SDK
|
|
233
|
-
npm run build
|
|
234
|
-
|
|
235
|
-
# Run tests
|
|
236
|
-
npm test
|
|
237
|
-
|
|
238
|
-
# Run integration tests
|
|
239
|
-
npm run test:integration
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
## License
|
|
243
|
-
|
|
244
|
-
This project is licensed under the Apache License 2.0 - see the [LICENSE](./LICENSE) file for details.
|
|
245
|
-
|
|
246
|
-
## Community & Support
|
|
247
|
-
|
|
248
|
-
- **GitHub Issues**: [Report bugs or request features](https://github.com/InsForge/insforge-sdk-js/issues)
|
|
249
|
-
- **Documentation**: [https://docs.insforge.com](https://docs.insforge.com)
|
|
250
|
-
- **Main Repository**: [InsForge Backend Platform](https://github.com/InsForge/InsForge)
|
|
251
|
-
|
|
252
|
-
## Related Projects
|
|
253
|
-
|
|
254
|
-
- **[InsForge](https://github.com/InsForge/InsForge)** - The main InsForge backend platform
|
|
255
|
-
- **[InsForge MCP](https://github.com/InsForge/insforge-mcp)** - Model Context Protocol server for InsForge
|
|
256
|
-
|
|
257
|
-
---
|
|
258
|
-
|
|
259
|
-
Built with ❤️ by the InsForge team
|
|
1
|
+
# insforge-sdk-js
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@insforge/sdk)
|
|
4
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
|
+
|
|
6
|
+
Official TypeScript/JavaScript SDK for [InsForge](https://github.com/InsForge/InsForge) - A powerful, open-source Backend-as-a-Service (BaaS) platform.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **Authentication** - Email/password, OAuth (Google, GitHub), session management
|
|
11
|
+
- **Database** - Full PostgreSQL database access with PostgREST
|
|
12
|
+
- **Storage** - File upload and management with S3-compatible storage
|
|
13
|
+
- **Edge Functions** - Serverless function invocation
|
|
14
|
+
- **AI Integration** - Built-in AI capabilities
|
|
15
|
+
- **TypeScript** - Full TypeScript support with type definitions
|
|
16
|
+
- **Automatic OAuth Handling** - Seamless OAuth callback detection
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @insforge/sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or with yarn:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn add @insforge/sdk
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Initialize the Client
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
import { createClient } from '@insforge/sdk';
|
|
36
|
+
|
|
37
|
+
const insforge = createClient({
|
|
38
|
+
baseUrl: 'http://localhost:7130' // Your InsForge backend URL
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Authentication
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
// Sign up a new user
|
|
46
|
+
const { data, error } = await insforge.auth.signUp({
|
|
47
|
+
email: 'user@example.com',
|
|
48
|
+
password: 'securePassword123',
|
|
49
|
+
name: 'John Doe' // optional
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Sign in with email/password
|
|
53
|
+
const { data, error } = await insforge.auth.signInWithPassword({
|
|
54
|
+
email: 'user@example.com',
|
|
55
|
+
password: 'securePassword123'
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// OAuth authentication (Google, GitHub)
|
|
59
|
+
await insforge.auth.signInWithOAuth({
|
|
60
|
+
provider: 'google',
|
|
61
|
+
redirectTo: 'http://localhost:3000/dashboard'
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Get current user
|
|
65
|
+
const { data: user } = await insforge.auth.getCurrentUser();
|
|
66
|
+
|
|
67
|
+
// Get any user's profile by ID (public endpoint)
|
|
68
|
+
const { data: profile, error } = await insforge.auth.getProfile('user-id-here');
|
|
69
|
+
|
|
70
|
+
// Update current user's profile (requires authentication)
|
|
71
|
+
const { data: updatedProfile, error } = await insforge.auth.setProfile({
|
|
72
|
+
displayName: 'John Doe',
|
|
73
|
+
bio: 'Software developer',
|
|
74
|
+
avatarUrl: 'https://example.com/avatar.jpg'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Sign out
|
|
78
|
+
await insforge.auth.signOut();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Database Operations
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
// Insert data
|
|
85
|
+
const { data, error } = await insforge.database
|
|
86
|
+
.from('posts')
|
|
87
|
+
.insert([
|
|
88
|
+
{ title: 'My First Post', content: 'Hello World!' }
|
|
89
|
+
]);
|
|
90
|
+
|
|
91
|
+
// Query data
|
|
92
|
+
const { data, error } = await insforge.database
|
|
93
|
+
.from('posts')
|
|
94
|
+
.select('*')
|
|
95
|
+
.eq('author_id', userId);
|
|
96
|
+
|
|
97
|
+
// Update data
|
|
98
|
+
const { data, error } = await insforge.database
|
|
99
|
+
.from('posts')
|
|
100
|
+
.update({ title: 'Updated Title' })
|
|
101
|
+
.eq('id', postId);
|
|
102
|
+
|
|
103
|
+
// Delete data
|
|
104
|
+
const { data, error } = await insforge.database
|
|
105
|
+
.from('posts')
|
|
106
|
+
.delete()
|
|
107
|
+
.eq('id', postId);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### File Storage
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
// Upload a file
|
|
114
|
+
const file = document.querySelector('input[type="file"]').files[0];
|
|
115
|
+
const { data, error } = await insforge.storage
|
|
116
|
+
.from('avatars')
|
|
117
|
+
.upload(file);
|
|
118
|
+
|
|
119
|
+
// Download a file
|
|
120
|
+
const { data, error } = await insforge.storage
|
|
121
|
+
.from('avatars')
|
|
122
|
+
.download('user-avatar.png');
|
|
123
|
+
|
|
124
|
+
// Delete a file
|
|
125
|
+
const { data, error } = await insforge.storage
|
|
126
|
+
.from('avatars')
|
|
127
|
+
.remove(['user-avatar.png']);
|
|
128
|
+
|
|
129
|
+
// List files
|
|
130
|
+
const { data, error } = await insforge.storage
|
|
131
|
+
.from('avatars')
|
|
132
|
+
.list();
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Edge Functions
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
// Invoke an edge function
|
|
139
|
+
const { data, error } = await insforge.functions.invoke('my-function', {
|
|
140
|
+
body: { key: 'value' }
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### AI Integration
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
// Generate text completion
|
|
148
|
+
const { data, error } = await insforge.ai.completion({
|
|
149
|
+
model: 'gpt-3.5-turbo',
|
|
150
|
+
prompt: 'Write a hello world program'
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Analyze an image
|
|
154
|
+
const { data, error } = await insforge.ai.vision({
|
|
155
|
+
imageUrl: 'https://example.com/image.jpg',
|
|
156
|
+
prompt: 'Describe this image'
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Documentation
|
|
161
|
+
|
|
162
|
+
For complete API reference and advanced usage, see:
|
|
163
|
+
|
|
164
|
+
- **[SDK Reference](./SDK-REFERENCE.md)** - Complete API documentation
|
|
165
|
+
- **[InsForge Main Repository](https://github.com/InsForge/InsForge)** - Backend platform and setup guides
|
|
166
|
+
|
|
167
|
+
## Configuration
|
|
168
|
+
|
|
169
|
+
The SDK supports the following configuration options:
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
const insforge = createClient({
|
|
173
|
+
baseUrl: 'http://localhost:7130', // Required: Your InsForge backend URL
|
|
174
|
+
storageStrategy: 'localStorage' // Optional: 'localStorage' or 'memory' (default: 'localStorage')
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## TypeScript Support
|
|
179
|
+
|
|
180
|
+
The SDK is written in TypeScript and provides full type definitions:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { createClient, InsForgeClient, User, Session } from '@insforge/sdk';
|
|
184
|
+
|
|
185
|
+
const insforge: InsForgeClient = createClient({
|
|
186
|
+
baseUrl: 'http://localhost:7130'
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// Type-safe API calls
|
|
190
|
+
const response: { data: User | null; error: Error | null } =
|
|
191
|
+
await insforge.auth.getCurrentUser();
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Error Handling
|
|
195
|
+
|
|
196
|
+
All SDK methods return a consistent response format:
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
const { data, error } = await insforge.auth.signUp({...});
|
|
200
|
+
|
|
201
|
+
if (error) {
|
|
202
|
+
console.error('Error:', error.message);
|
|
203
|
+
console.error('Status:', error.statusCode);
|
|
204
|
+
} else {
|
|
205
|
+
console.log('Success:', data);
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Browser Support
|
|
210
|
+
|
|
211
|
+
The SDK works in all modern browsers that support:
|
|
212
|
+
- ES6+ features
|
|
213
|
+
- Fetch API
|
|
214
|
+
- LocalStorage (for session management)
|
|
215
|
+
|
|
216
|
+
For Node.js environments, ensure you're using Node.js 18 or higher.
|
|
217
|
+
|
|
218
|
+
## Contributing
|
|
219
|
+
|
|
220
|
+
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
|
|
221
|
+
|
|
222
|
+
### Development Setup
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# Clone the repository
|
|
226
|
+
git clone https://github.com/InsForge/insforge-sdk-js.git
|
|
227
|
+
cd insforge-sdk-js
|
|
228
|
+
|
|
229
|
+
# Install dependencies
|
|
230
|
+
npm install
|
|
231
|
+
|
|
232
|
+
# Build the SDK
|
|
233
|
+
npm run build
|
|
234
|
+
|
|
235
|
+
# Run tests
|
|
236
|
+
npm test
|
|
237
|
+
|
|
238
|
+
# Run integration tests
|
|
239
|
+
npm run test:integration
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](./LICENSE) file for details.
|
|
245
|
+
|
|
246
|
+
## Community & Support
|
|
247
|
+
|
|
248
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/InsForge/insforge-sdk-js/issues)
|
|
249
|
+
- **Documentation**: [https://docs.insforge.com](https://docs.insforge.com)
|
|
250
|
+
- **Main Repository**: [InsForge Backend Platform](https://github.com/InsForge/InsForge)
|
|
251
|
+
|
|
252
|
+
## Related Projects
|
|
253
|
+
|
|
254
|
+
- **[InsForge](https://github.com/InsForge/InsForge)** - The main InsForge backend platform
|
|
255
|
+
- **[InsForge MCP](https://github.com/InsForge/insforge-mcp)** - Model Context Protocol server for InsForge
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
Built with ❤️ by the InsForge team
|
package/dist/index.d.mts
CHANGED
|
@@ -53,7 +53,7 @@ interface TokenStorage {
|
|
|
53
53
|
removeItem(key: string): void | Promise<void>;
|
|
54
54
|
}
|
|
55
55
|
interface AuthSession {
|
|
56
|
-
user: UserSchema;
|
|
56
|
+
user: UserSchema | null;
|
|
57
57
|
accessToken: string;
|
|
58
58
|
expiresAt?: Date;
|
|
59
59
|
}
|
|
@@ -166,11 +166,19 @@ declare class TokenManager {
|
|
|
166
166
|
declare class Auth {
|
|
167
167
|
private http;
|
|
168
168
|
private tokenManager;
|
|
169
|
+
/**
|
|
170
|
+
* Promise that resolves when OAuth callback handling is complete.
|
|
171
|
+
* Resolves immediately if no OAuth callback is detected in the URL.
|
|
172
|
+
*/
|
|
173
|
+
private authCallbackHandled;
|
|
169
174
|
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
170
175
|
/**
|
|
171
176
|
* Automatically detect and handle OAuth callback parameters in the URL
|
|
172
177
|
* This runs after initialization to seamlessly complete the OAuth flow
|
|
173
|
-
*
|
|
178
|
+
*
|
|
179
|
+
* Supports two flows:
|
|
180
|
+
* - PKCE flow (new): Backend returns `insforge_code` param, exchanged for tokens
|
|
181
|
+
* - Legacy flow: Backend returns tokens directly in URL (backward compatible)
|
|
174
182
|
*/
|
|
175
183
|
private detectAuthCallback;
|
|
176
184
|
/**
|
|
@@ -189,6 +197,7 @@ declare class Auth {
|
|
|
189
197
|
}>;
|
|
190
198
|
/**
|
|
191
199
|
* Sign in with OAuth provider
|
|
200
|
+
* Uses PKCE (Proof Key for Code Exchange) for enhanced security
|
|
192
201
|
*/
|
|
193
202
|
signInWithOAuth(options: {
|
|
194
203
|
provider: OAuthProvidersSchema;
|
|
@@ -198,9 +207,45 @@ declare class Auth {
|
|
|
198
207
|
data: {
|
|
199
208
|
url?: string;
|
|
200
209
|
provider?: string;
|
|
210
|
+
codeVerifier?: string;
|
|
201
211
|
};
|
|
202
212
|
error: InsForgeError | null;
|
|
203
213
|
}>;
|
|
214
|
+
/**
|
|
215
|
+
* Exchange OAuth authorization code for tokens (PKCE flow)
|
|
216
|
+
*
|
|
217
|
+
* After OAuth callback redirects with an `insforge_code` parameter, call this method
|
|
218
|
+
* to exchange it for access tokens. The code verifier is automatically
|
|
219
|
+
* retrieved from sessionStorage if available.
|
|
220
|
+
*
|
|
221
|
+
* Note: This is called automatically by the SDK on initialization. You typically
|
|
222
|
+
* don't need to call this directly unless using `skipBrowserRedirect: true`.
|
|
223
|
+
*
|
|
224
|
+
* @param code - The authorization code from OAuth callback URL
|
|
225
|
+
* @param codeVerifier - Optional code verifier (auto-retrieved from sessionStorage if not provided)
|
|
226
|
+
* @returns Session data with access token and user info
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* // Automatic verifier retrieval (recommended for browser)
|
|
231
|
+
* const params = new URLSearchParams(window.location.search);
|
|
232
|
+
* const code = params.get('insforge_code');
|
|
233
|
+
* if (code) {
|
|
234
|
+
* const { data, error } = await insforge.auth.exchangeOAuthCode(code);
|
|
235
|
+
* }
|
|
236
|
+
*
|
|
237
|
+
* // Manual verifier (for custom flows)
|
|
238
|
+
* const { data, error } = await insforge.auth.exchangeOAuthCode(code, codeVerifier);
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
exchangeOAuthCode(code: string, codeVerifier?: string): Promise<{
|
|
242
|
+
data: {
|
|
243
|
+
accessToken: string;
|
|
244
|
+
user: UserSchema;
|
|
245
|
+
redirectTo?: string;
|
|
246
|
+
} | null;
|
|
247
|
+
error: InsForgeError | null;
|
|
248
|
+
}>;
|
|
204
249
|
/**
|
|
205
250
|
* Sign out the current user
|
|
206
251
|
*/
|
|
@@ -238,6 +283,7 @@ declare class Auth {
|
|
|
238
283
|
/**
|
|
239
284
|
* Get the current session (only session data, no API call)
|
|
240
285
|
* Returns the stored JWT token and basic user info from local storage
|
|
286
|
+
* Automatically waits for any pending OAuth callback to complete first
|
|
241
287
|
*/
|
|
242
288
|
getCurrentSession(): Promise<{
|
|
243
289
|
data: {
|