@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/dist/index.mjs CHANGED
@@ -2261,8 +2261,7 @@ var Payments = class {
2261
2261
  *
2262
2262
  * @example
2263
2263
  * ```typescript
2264
- * const { data, error } = await client.payments.createCheckoutSession({
2265
- * environment: 'test',
2264
+ * const { data, error } = await client.payments.createCheckoutSession('test', {
2266
2265
  * mode: 'payment',
2267
2266
  * lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
2268
2267
  * successUrl: `${window.location.origin}/success`,
@@ -2274,10 +2273,10 @@ var Payments = class {
2274
2273
  * }
2275
2274
  * ```
2276
2275
  */
2277
- async createCheckoutSession(request) {
2276
+ async createCheckoutSession(environment, request) {
2278
2277
  try {
2279
2278
  const data = await this.http.post(
2280
- "/api/payments/checkout-sessions",
2279
+ `/api/payments/${encodeURIComponent(environment)}/checkout-sessions`,
2281
2280
  request,
2282
2281
  { idempotent: !!request.idempotencyKey }
2283
2282
  );
@@ -2292,10 +2291,10 @@ var Payments = class {
2292
2291
  /**
2293
2292
  * Create a Stripe Billing Portal Session for a mapped billing subject.
2294
2293
  */
2295
- async createCustomerPortalSession(request) {
2294
+ async createCustomerPortalSession(environment, request) {
2296
2295
  try {
2297
2296
  const data = await this.http.post(
2298
- "/api/payments/customer-portal-sessions",
2297
+ `/api/payments/${encodeURIComponent(environment)}/customer-portal-sessions`,
2299
2298
  request
2300
2299
  );
2301
2300
  return { data, error: null };
@@ -2345,6 +2344,37 @@ var InsForgeClient = class {
2345
2344
  getHttpClient() {
2346
2345
  return this.http;
2347
2346
  }
2347
+ /**
2348
+ * Set the access token used by every SDK surface. Updates both the HTTP
2349
+ * client (database / storage / functions / AI / emails) and the realtime
2350
+ * token manager (which fires `onTokenChange` to reconnect the WebSocket
2351
+ * with the new bearer). Pass `null` to clear.
2352
+ *
2353
+ * Use this when an external auth provider (Better Auth, Clerk, Auth0,
2354
+ * WorkOS, Kinde, Stytch, …) issues the JWT and you need to keep the
2355
+ * long-lived InsForge client in sync. Without this, you'd have to call
2356
+ * `client.getHttpClient().setAuthToken(token)` AND reach into the private
2357
+ * `client.realtime.tokenManager.setAccessToken(token)` separately —
2358
+ * forgetting the second one silently breaks realtime auth.
2359
+ *
2360
+ * @example
2361
+ * ```typescript
2362
+ * // Refresh a third-party-issued JWT periodically
2363
+ * const { token } = await fetch('/api/insforge-token').then((r) => r.json());
2364
+ * client.setAccessToken(token);
2365
+ *
2366
+ * // Sign-out
2367
+ * client.setAccessToken(null);
2368
+ * ```
2369
+ */
2370
+ setAccessToken(token) {
2371
+ this.http.setAuthToken(token);
2372
+ if (token === null) {
2373
+ this.tokenManager.clearSession();
2374
+ } else {
2375
+ this.tokenManager.setAccessToken(token);
2376
+ }
2377
+ }
2348
2378
  /**
2349
2379
  * Future modules will be added here:
2350
2380
  * - database: Database operations