@insforge/sdk 1.2.6 → 1.2.7
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 +74 -78
- package/dist/index.d.mts +28 -5
- package/dist/index.d.ts +28 -5
- package/dist/index.js +36 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,10 +33,10 @@ yarn add @insforge/sdk
|
|
|
33
33
|
### Initialize the Client
|
|
34
34
|
|
|
35
35
|
```javascript
|
|
36
|
-
import { createClient } from
|
|
36
|
+
import { createClient } from "@insforge/sdk";
|
|
37
37
|
|
|
38
38
|
const insforge = createClient({
|
|
39
|
-
baseUrl:
|
|
39
|
+
baseUrl: "http://localhost:7130", // Your InsForge backend URL
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
42
|
|
|
@@ -45,35 +45,35 @@ const insforge = createClient({
|
|
|
45
45
|
```javascript
|
|
46
46
|
// Sign up a new user
|
|
47
47
|
const { data, error } = await insforge.auth.signUp({
|
|
48
|
-
email:
|
|
49
|
-
password:
|
|
50
|
-
name:
|
|
51
|
-
redirectTo:
|
|
48
|
+
email: "user@example.com",
|
|
49
|
+
password: "securePassword123",
|
|
50
|
+
name: "John Doe", // optional
|
|
51
|
+
redirectTo: "http://localhost:3000/sign-in", // optional, recommended for link-based verification
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
// Sign in with email/password
|
|
55
55
|
const { data, error } = await insforge.auth.signInWithPassword({
|
|
56
|
-
email:
|
|
57
|
-
password:
|
|
56
|
+
email: "user@example.com",
|
|
57
|
+
password: "securePassword123",
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
// OAuth authentication (built-in or custom provider key)
|
|
61
61
|
await insforge.auth.signInWithOAuth({
|
|
62
|
-
provider:
|
|
63
|
-
redirectTo:
|
|
62
|
+
provider: "google", // e.g. built-in: "google", custom: "auth0-acme"
|
|
63
|
+
redirectTo: "http://localhost:3000/dashboard",
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
// Get current user (call this during browser app startup)
|
|
67
67
|
const { data: currentUser } = await insforge.auth.getCurrentUser();
|
|
68
68
|
|
|
69
69
|
// Get any user's profile by ID (public endpoint)
|
|
70
|
-
const { data: profile, error } = await insforge.auth.getProfile(
|
|
70
|
+
const { data: profile, error } = await insforge.auth.getProfile("user-id-here");
|
|
71
71
|
|
|
72
72
|
// Update current user's profile (requires authentication)
|
|
73
73
|
const { data: updatedProfile, error } = await insforge.auth.setProfile({
|
|
74
|
-
displayName:
|
|
75
|
-
bio:
|
|
76
|
-
avatarUrl:
|
|
74
|
+
displayName: "John Doe",
|
|
75
|
+
bio: "Software developer",
|
|
76
|
+
avatarUrl: "https://example.com/avatar.jpg",
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
// Sign out
|
|
@@ -85,37 +85,38 @@ await insforge.auth.signOut();
|
|
|
85
85
|
```javascript
|
|
86
86
|
// Resend a verification email
|
|
87
87
|
await insforge.auth.resendVerificationEmail({
|
|
88
|
-
email:
|
|
89
|
-
redirectTo:
|
|
88
|
+
email: "user@example.com",
|
|
89
|
+
redirectTo: "http://localhost:3000/sign-in", // optional, recommended for link-based verification
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
// Verify email with a 6-digit code
|
|
93
93
|
await insforge.auth.verifyEmail({
|
|
94
|
-
email:
|
|
95
|
-
otp:
|
|
94
|
+
email: "user@example.com",
|
|
95
|
+
otp: "123456",
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
// Send password reset email
|
|
99
99
|
await insforge.auth.sendResetPasswordEmail({
|
|
100
|
-
email:
|
|
101
|
-
redirectTo:
|
|
100
|
+
email: "user@example.com",
|
|
101
|
+
redirectTo: "http://localhost:3000/reset-password", // optional, recommended for link-based reset
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
// Code-based reset flow: exchange the code, then reset the password
|
|
105
105
|
const { data: resetToken } = await insforge.auth.exchangeResetPasswordToken({
|
|
106
|
-
email:
|
|
107
|
-
code:
|
|
106
|
+
email: "user@example.com",
|
|
107
|
+
code: "123456",
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
if (resetToken) {
|
|
111
111
|
await insforge.auth.resetPassword({
|
|
112
|
-
newPassword:
|
|
113
|
-
otp: resetToken.token
|
|
112
|
+
newPassword: "newSecurePassword123",
|
|
113
|
+
otp: resetToken.token,
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
For link-based verification and password reset, users click the emailed browser links:
|
|
119
|
+
|
|
119
120
|
- `GET /api/auth/email/verify-link`
|
|
120
121
|
- `GET /api/auth/email/reset-password-link`
|
|
121
122
|
|
|
@@ -130,28 +131,26 @@ Those backend endpoints validate the token first, then redirect the browser to y
|
|
|
130
131
|
```javascript
|
|
131
132
|
// Insert data
|
|
132
133
|
const { data, error } = await insforge.database
|
|
133
|
-
.from(
|
|
134
|
-
.insert([
|
|
135
|
-
{ title: 'My First Post', content: 'Hello World!' }
|
|
136
|
-
]);
|
|
134
|
+
.from("posts")
|
|
135
|
+
.insert([{ title: "My First Post", content: "Hello World!" }]);
|
|
137
136
|
|
|
138
137
|
// Query data
|
|
139
138
|
const { data, error } = await insforge.database
|
|
140
|
-
.from(
|
|
141
|
-
.select(
|
|
142
|
-
.eq(
|
|
139
|
+
.from("posts")
|
|
140
|
+
.select("*")
|
|
141
|
+
.eq("author_id", userId);
|
|
143
142
|
|
|
144
143
|
// Update data
|
|
145
144
|
const { data, error } = await insforge.database
|
|
146
|
-
.from(
|
|
147
|
-
.update({ title:
|
|
148
|
-
.eq(
|
|
145
|
+
.from("posts")
|
|
146
|
+
.update({ title: "Updated Title" })
|
|
147
|
+
.eq("id", postId);
|
|
149
148
|
|
|
150
149
|
// Delete data
|
|
151
150
|
const { data, error } = await insforge.database
|
|
152
|
-
.from(
|
|
151
|
+
.from("posts")
|
|
153
152
|
.delete()
|
|
154
|
-
.eq(
|
|
153
|
+
.eq("id", postId);
|
|
155
154
|
```
|
|
156
155
|
|
|
157
156
|
### File Storage
|
|
@@ -159,32 +158,28 @@ const { data, error } = await insforge.database
|
|
|
159
158
|
```javascript
|
|
160
159
|
// Upload a file
|
|
161
160
|
const file = document.querySelector('input[type="file"]').files[0];
|
|
162
|
-
const { data, error } = await insforge.storage
|
|
163
|
-
.from('avatars')
|
|
164
|
-
.upload(file);
|
|
161
|
+
const { data, error } = await insforge.storage.from("avatars").upload(file);
|
|
165
162
|
|
|
166
163
|
// Download a file
|
|
167
164
|
const { data, error } = await insforge.storage
|
|
168
|
-
.from(
|
|
169
|
-
.download(
|
|
165
|
+
.from("avatars")
|
|
166
|
+
.download("user-avatar.png");
|
|
170
167
|
|
|
171
168
|
// Delete a file
|
|
172
169
|
const { data, error } = await insforge.storage
|
|
173
|
-
.from(
|
|
174
|
-
.remove([
|
|
170
|
+
.from("avatars")
|
|
171
|
+
.remove(["user-avatar.png"]);
|
|
175
172
|
|
|
176
173
|
// List files
|
|
177
|
-
const { data, error } = await insforge.storage
|
|
178
|
-
.from('avatars')
|
|
179
|
-
.list();
|
|
174
|
+
const { data, error } = await insforge.storage.from("avatars").list();
|
|
180
175
|
```
|
|
181
176
|
|
|
182
177
|
### Edge Functions
|
|
183
178
|
|
|
184
179
|
```javascript
|
|
185
180
|
// Invoke an edge function
|
|
186
|
-
const { data, error } = await insforge.functions.invoke(
|
|
187
|
-
body: { key:
|
|
181
|
+
const { data, error } = await insforge.functions.invoke("my-function", {
|
|
182
|
+
body: { key: "value" },
|
|
188
183
|
});
|
|
189
184
|
```
|
|
190
185
|
|
|
@@ -192,13 +187,12 @@ const { data, error } = await insforge.functions.invoke('my-function', {
|
|
|
192
187
|
|
|
193
188
|
```javascript
|
|
194
189
|
// Create and redirect to a Stripe Checkout Session
|
|
195
|
-
const { data, error } = await insforge.payments.createCheckoutSession({
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
|
|
190
|
+
const { data, error } = await insforge.payments.createCheckoutSession("test", {
|
|
191
|
+
mode: "payment",
|
|
192
|
+
lineItems: [{ stripePriceId: "price_123", quantity: 1 }],
|
|
199
193
|
successUrl: `${window.location.origin}/success`,
|
|
200
194
|
cancelUrl: `${window.location.origin}/pricing`,
|
|
201
|
-
idempotencyKey:
|
|
195
|
+
idempotencyKey: "cart_123",
|
|
202
196
|
});
|
|
203
197
|
|
|
204
198
|
if (!error && data?.checkoutSession.url) {
|
|
@@ -206,25 +200,27 @@ if (!error && data?.checkoutSession.url) {
|
|
|
206
200
|
}
|
|
207
201
|
|
|
208
202
|
// Create a subscription checkout for an app billing subject
|
|
209
|
-
const { data: subscriptionCheckout } =
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
});
|
|
203
|
+
const { data: subscriptionCheckout } =
|
|
204
|
+
await insforge.payments.createCheckoutSession("test", {
|
|
205
|
+
mode: "subscription",
|
|
206
|
+
subject: { type: "team", id: "team_123" },
|
|
207
|
+
lineItems: [{ stripePriceId: "price_monthly_123", quantity: 1 }],
|
|
208
|
+
successUrl: `${window.location.origin}/billing/success`,
|
|
209
|
+
cancelUrl: `${window.location.origin}/billing`,
|
|
210
|
+
});
|
|
217
211
|
|
|
218
212
|
if (subscriptionCheckout?.checkoutSession.url) {
|
|
219
213
|
window.location.assign(subscriptionCheckout.checkoutSession.url);
|
|
220
214
|
}
|
|
221
215
|
|
|
222
216
|
// Let an authenticated customer manage their subscription in Stripe Billing Portal
|
|
223
|
-
const { data: portal } = await insforge.payments.createCustomerPortalSession(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
217
|
+
const { data: portal } = await insforge.payments.createCustomerPortalSession(
|
|
218
|
+
"test",
|
|
219
|
+
{
|
|
220
|
+
subject: { type: "team", id: "team_123" },
|
|
221
|
+
returnUrl: `${window.location.origin}/billing`,
|
|
222
|
+
},
|
|
223
|
+
);
|
|
228
224
|
|
|
229
225
|
if (portal?.customerPortalSession.url) {
|
|
230
226
|
window.location.assign(portal.customerPortalSession.url);
|
|
@@ -236,14 +232,14 @@ if (portal?.customerPortalSession.url) {
|
|
|
236
232
|
```javascript
|
|
237
233
|
// Generate text completion
|
|
238
234
|
const { data, error } = await insforge.ai.completion({
|
|
239
|
-
model:
|
|
240
|
-
prompt:
|
|
235
|
+
model: "gpt-3.5-turbo",
|
|
236
|
+
prompt: "Write a hello world program",
|
|
241
237
|
});
|
|
242
238
|
|
|
243
239
|
// Analyze an image
|
|
244
240
|
const { data, error } = await insforge.ai.vision({
|
|
245
|
-
imageUrl:
|
|
246
|
-
prompt:
|
|
241
|
+
imageUrl: "https://example.com/image.jpg",
|
|
242
|
+
prompt: "Describe this image",
|
|
247
243
|
});
|
|
248
244
|
```
|
|
249
245
|
|
|
@@ -260,9 +256,9 @@ The SDK supports the following configuration options:
|
|
|
260
256
|
|
|
261
257
|
```javascript
|
|
262
258
|
const insforge = createClient({
|
|
263
|
-
baseUrl:
|
|
264
|
-
anonKey:
|
|
265
|
-
isServerMode: false
|
|
259
|
+
baseUrl: "http://localhost:7130", // Your InsForge backend URL
|
|
260
|
+
anonKey: "your-anon-key", // Optional
|
|
261
|
+
isServerMode: false, // Optional (set true in SSR/server runtime)
|
|
266
262
|
});
|
|
267
263
|
```
|
|
268
264
|
|
|
@@ -276,7 +272,7 @@ Read your access token from cookies in Next.js and pass it as `edgeFunctionToken
|
|
|
276
272
|
Your app should write/update cookies itself after login/refresh.
|
|
277
273
|
|
|
278
274
|
```typescript
|
|
279
|
-
import { createClient } from
|
|
275
|
+
import { createClient } from "@insforge/sdk";
|
|
280
276
|
const accessToken = /* read access token from request cookies */ null;
|
|
281
277
|
|
|
282
278
|
const insforge = createClient({
|
|
@@ -291,15 +287,14 @@ const insforge = createClient({
|
|
|
291
287
|
The SDK is written in TypeScript and provides full type definitions:
|
|
292
288
|
|
|
293
289
|
```typescript
|
|
294
|
-
import { createClient, InsForgeClient } from
|
|
290
|
+
import { createClient, InsForgeClient } from "@insforge/sdk";
|
|
295
291
|
|
|
296
292
|
const insforge: InsForgeClient = createClient({
|
|
297
|
-
baseUrl:
|
|
293
|
+
baseUrl: "http://localhost:7130",
|
|
298
294
|
});
|
|
299
295
|
|
|
300
296
|
// Type-safe API calls
|
|
301
|
-
const response =
|
|
302
|
-
await insforge.auth.getCurrentUser();
|
|
297
|
+
const response = await insforge.auth.getCurrentUser();
|
|
303
298
|
```
|
|
304
299
|
|
|
305
300
|
## Error Handling
|
|
@@ -320,6 +315,7 @@ if (error) {
|
|
|
320
315
|
## Browser Support
|
|
321
316
|
|
|
322
317
|
The SDK works in all modern browsers that support:
|
|
318
|
+
|
|
323
319
|
- ES6+ features
|
|
324
320
|
- Fetch API
|
|
325
321
|
- Cookies (for refresh token flow)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, RefreshSessionResponse, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, ExchangeResetPasswordTokenResponse, ResetPasswordResponse, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse,
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, RefreshSessionResponse, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, ExchangeResetPasswordTokenResponse, ResetPasswordResponse, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse, StripeEnvironment, CreateCheckoutSessionBody, CreateCheckoutSessionResponse, CreateCustomerPortalSessionBody, CreateCustomerPortalSessionResponse } from '@insforge/shared-schemas';
|
|
2
2
|
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SendRawEmailRequest as SendEmailOptions, SendEmailResponse, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
|
|
3
3
|
import * as _supabase_postgrest_js from '@supabase/postgrest-js';
|
|
4
4
|
|
|
@@ -993,8 +993,7 @@ declare class Payments {
|
|
|
993
993
|
*
|
|
994
994
|
* @example
|
|
995
995
|
* ```typescript
|
|
996
|
-
* const { data, error } = await client.payments.createCheckoutSession({
|
|
997
|
-
* environment: 'test',
|
|
996
|
+
* const { data, error } = await client.payments.createCheckoutSession('test', {
|
|
998
997
|
* mode: 'payment',
|
|
999
998
|
* lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
|
|
1000
999
|
* successUrl: `${window.location.origin}/success`,
|
|
@@ -1006,11 +1005,11 @@ declare class Payments {
|
|
|
1006
1005
|
* }
|
|
1007
1006
|
* ```
|
|
1008
1007
|
*/
|
|
1009
|
-
createCheckoutSession(request:
|
|
1008
|
+
createCheckoutSession(environment: StripeEnvironment, request: CreateCheckoutSessionBody): Promise<PaymentsResponse<CreateCheckoutSessionResponse>>;
|
|
1010
1009
|
/**
|
|
1011
1010
|
* Create a Stripe Billing Portal Session for a mapped billing subject.
|
|
1012
1011
|
*/
|
|
1013
|
-
createCustomerPortalSession(request:
|
|
1012
|
+
createCustomerPortalSession(environment: StripeEnvironment, request: CreateCustomerPortalSessionBody): Promise<PaymentsResponse<CreateCustomerPortalSessionResponse>>;
|
|
1014
1013
|
}
|
|
1015
1014
|
|
|
1016
1015
|
/**
|
|
@@ -1079,6 +1078,30 @@ declare class InsForgeClient {
|
|
|
1079
1078
|
* ```
|
|
1080
1079
|
*/
|
|
1081
1080
|
getHttpClient(): HttpClient;
|
|
1081
|
+
/**
|
|
1082
|
+
* Set the access token used by every SDK surface. Updates both the HTTP
|
|
1083
|
+
* client (database / storage / functions / AI / emails) and the realtime
|
|
1084
|
+
* token manager (which fires `onTokenChange` to reconnect the WebSocket
|
|
1085
|
+
* with the new bearer). Pass `null` to clear.
|
|
1086
|
+
*
|
|
1087
|
+
* Use this when an external auth provider (Better Auth, Clerk, Auth0,
|
|
1088
|
+
* WorkOS, Kinde, Stytch, …) issues the JWT and you need to keep the
|
|
1089
|
+
* long-lived InsForge client in sync. Without this, you'd have to call
|
|
1090
|
+
* `client.getHttpClient().setAuthToken(token)` AND reach into the private
|
|
1091
|
+
* `client.realtime.tokenManager.setAccessToken(token)` separately —
|
|
1092
|
+
* forgetting the second one silently breaks realtime auth.
|
|
1093
|
+
*
|
|
1094
|
+
* @example
|
|
1095
|
+
* ```typescript
|
|
1096
|
+
* // Refresh a third-party-issued JWT periodically
|
|
1097
|
+
* const { token } = await fetch('/api/insforge-token').then((r) => r.json());
|
|
1098
|
+
* client.setAccessToken(token);
|
|
1099
|
+
*
|
|
1100
|
+
* // Sign-out
|
|
1101
|
+
* client.setAccessToken(null);
|
|
1102
|
+
* ```
|
|
1103
|
+
*/
|
|
1104
|
+
setAccessToken(token: string | null): void;
|
|
1082
1105
|
}
|
|
1083
1106
|
|
|
1084
1107
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, RefreshSessionResponse, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, ExchangeResetPasswordTokenResponse, ResetPasswordResponse, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse,
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, RefreshSessionResponse, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, ExchangeResetPasswordTokenResponse, ResetPasswordResponse, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse, StripeEnvironment, CreateCheckoutSessionBody, CreateCheckoutSessionResponse, CreateCustomerPortalSessionBody, CreateCustomerPortalSessionResponse } from '@insforge/shared-schemas';
|
|
2
2
|
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SendRawEmailRequest as SendEmailOptions, SendEmailResponse, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
|
|
3
3
|
import * as _supabase_postgrest_js from '@supabase/postgrest-js';
|
|
4
4
|
|
|
@@ -993,8 +993,7 @@ declare class Payments {
|
|
|
993
993
|
*
|
|
994
994
|
* @example
|
|
995
995
|
* ```typescript
|
|
996
|
-
* const { data, error } = await client.payments.createCheckoutSession({
|
|
997
|
-
* environment: 'test',
|
|
996
|
+
* const { data, error } = await client.payments.createCheckoutSession('test', {
|
|
998
997
|
* mode: 'payment',
|
|
999
998
|
* lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
|
|
1000
999
|
* successUrl: `${window.location.origin}/success`,
|
|
@@ -1006,11 +1005,11 @@ declare class Payments {
|
|
|
1006
1005
|
* }
|
|
1007
1006
|
* ```
|
|
1008
1007
|
*/
|
|
1009
|
-
createCheckoutSession(request:
|
|
1008
|
+
createCheckoutSession(environment: StripeEnvironment, request: CreateCheckoutSessionBody): Promise<PaymentsResponse<CreateCheckoutSessionResponse>>;
|
|
1010
1009
|
/**
|
|
1011
1010
|
* Create a Stripe Billing Portal Session for a mapped billing subject.
|
|
1012
1011
|
*/
|
|
1013
|
-
createCustomerPortalSession(request:
|
|
1012
|
+
createCustomerPortalSession(environment: StripeEnvironment, request: CreateCustomerPortalSessionBody): Promise<PaymentsResponse<CreateCustomerPortalSessionResponse>>;
|
|
1014
1013
|
}
|
|
1015
1014
|
|
|
1016
1015
|
/**
|
|
@@ -1079,6 +1078,30 @@ declare class InsForgeClient {
|
|
|
1079
1078
|
* ```
|
|
1080
1079
|
*/
|
|
1081
1080
|
getHttpClient(): HttpClient;
|
|
1081
|
+
/**
|
|
1082
|
+
* Set the access token used by every SDK surface. Updates both the HTTP
|
|
1083
|
+
* client (database / storage / functions / AI / emails) and the realtime
|
|
1084
|
+
* token manager (which fires `onTokenChange` to reconnect the WebSocket
|
|
1085
|
+
* with the new bearer). Pass `null` to clear.
|
|
1086
|
+
*
|
|
1087
|
+
* Use this when an external auth provider (Better Auth, Clerk, Auth0,
|
|
1088
|
+
* WorkOS, Kinde, Stytch, …) issues the JWT and you need to keep the
|
|
1089
|
+
* long-lived InsForge client in sync. Without this, you'd have to call
|
|
1090
|
+
* `client.getHttpClient().setAuthToken(token)` AND reach into the private
|
|
1091
|
+
* `client.realtime.tokenManager.setAccessToken(token)` separately —
|
|
1092
|
+
* forgetting the second one silently breaks realtime auth.
|
|
1093
|
+
*
|
|
1094
|
+
* @example
|
|
1095
|
+
* ```typescript
|
|
1096
|
+
* // Refresh a third-party-issued JWT periodically
|
|
1097
|
+
* const { token } = await fetch('/api/insforge-token').then((r) => r.json());
|
|
1098
|
+
* client.setAccessToken(token);
|
|
1099
|
+
*
|
|
1100
|
+
* // Sign-out
|
|
1101
|
+
* client.setAccessToken(null);
|
|
1102
|
+
* ```
|
|
1103
|
+
*/
|
|
1104
|
+
setAccessToken(token: string | null): void;
|
|
1082
1105
|
}
|
|
1083
1106
|
|
|
1084
1107
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2302,8 +2302,7 @@ var Payments = class {
|
|
|
2302
2302
|
*
|
|
2303
2303
|
* @example
|
|
2304
2304
|
* ```typescript
|
|
2305
|
-
* const { data, error } = await client.payments.createCheckoutSession({
|
|
2306
|
-
* environment: 'test',
|
|
2305
|
+
* const { data, error } = await client.payments.createCheckoutSession('test', {
|
|
2307
2306
|
* mode: 'payment',
|
|
2308
2307
|
* lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
|
|
2309
2308
|
* successUrl: `${window.location.origin}/success`,
|
|
@@ -2315,10 +2314,10 @@ var Payments = class {
|
|
|
2315
2314
|
* }
|
|
2316
2315
|
* ```
|
|
2317
2316
|
*/
|
|
2318
|
-
async createCheckoutSession(request) {
|
|
2317
|
+
async createCheckoutSession(environment, request) {
|
|
2319
2318
|
try {
|
|
2320
2319
|
const data = await this.http.post(
|
|
2321
|
-
|
|
2320
|
+
`/api/payments/${encodeURIComponent(environment)}/checkout-sessions`,
|
|
2322
2321
|
request,
|
|
2323
2322
|
{ idempotent: !!request.idempotencyKey }
|
|
2324
2323
|
);
|
|
@@ -2333,10 +2332,10 @@ var Payments = class {
|
|
|
2333
2332
|
/**
|
|
2334
2333
|
* Create a Stripe Billing Portal Session for a mapped billing subject.
|
|
2335
2334
|
*/
|
|
2336
|
-
async createCustomerPortalSession(request) {
|
|
2335
|
+
async createCustomerPortalSession(environment, request) {
|
|
2337
2336
|
try {
|
|
2338
2337
|
const data = await this.http.post(
|
|
2339
|
-
|
|
2338
|
+
`/api/payments/${encodeURIComponent(environment)}/customer-portal-sessions`,
|
|
2340
2339
|
request
|
|
2341
2340
|
);
|
|
2342
2341
|
return { data, error: null };
|
|
@@ -2386,6 +2385,37 @@ var InsForgeClient = class {
|
|
|
2386
2385
|
getHttpClient() {
|
|
2387
2386
|
return this.http;
|
|
2388
2387
|
}
|
|
2388
|
+
/**
|
|
2389
|
+
* Set the access token used by every SDK surface. Updates both the HTTP
|
|
2390
|
+
* client (database / storage / functions / AI / emails) and the realtime
|
|
2391
|
+
* token manager (which fires `onTokenChange` to reconnect the WebSocket
|
|
2392
|
+
* with the new bearer). Pass `null` to clear.
|
|
2393
|
+
*
|
|
2394
|
+
* Use this when an external auth provider (Better Auth, Clerk, Auth0,
|
|
2395
|
+
* WorkOS, Kinde, Stytch, …) issues the JWT and you need to keep the
|
|
2396
|
+
* long-lived InsForge client in sync. Without this, you'd have to call
|
|
2397
|
+
* `client.getHttpClient().setAuthToken(token)` AND reach into the private
|
|
2398
|
+
* `client.realtime.tokenManager.setAccessToken(token)` separately —
|
|
2399
|
+
* forgetting the second one silently breaks realtime auth.
|
|
2400
|
+
*
|
|
2401
|
+
* @example
|
|
2402
|
+
* ```typescript
|
|
2403
|
+
* // Refresh a third-party-issued JWT periodically
|
|
2404
|
+
* const { token } = await fetch('/api/insforge-token').then((r) => r.json());
|
|
2405
|
+
* client.setAccessToken(token);
|
|
2406
|
+
*
|
|
2407
|
+
* // Sign-out
|
|
2408
|
+
* client.setAccessToken(null);
|
|
2409
|
+
* ```
|
|
2410
|
+
*/
|
|
2411
|
+
setAccessToken(token) {
|
|
2412
|
+
this.http.setAuthToken(token);
|
|
2413
|
+
if (token === null) {
|
|
2414
|
+
this.tokenManager.clearSession();
|
|
2415
|
+
} else {
|
|
2416
|
+
this.tokenManager.setAccessToken(token);
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2389
2419
|
/**
|
|
2390
2420
|
* Future modules will be added here:
|
|
2391
2421
|
* - database: Database operations
|