@insforge/sdk 1.2.5-dev.0 → 1.2.6-payments.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/README.md CHANGED
@@ -12,6 +12,7 @@ Official TypeScript/JavaScript SDK for [InsForge](https://github.com/InsForge/In
12
12
  - **Storage** - File upload and management with S3-compatible storage
13
13
  - **Edge Functions** - Serverless function invocation
14
14
  - **AI Integration** - Built-in AI capabilities
15
+ - **Payments** - Stripe Checkout and Billing Portal session helpers
15
16
  - **TypeScript** - Full TypeScript support with type definitions
16
17
  - **Automatic OAuth Handling** - Seamless OAuth callback detection
17
18
 
@@ -187,6 +188,49 @@ const { data, error } = await insforge.functions.invoke('my-function', {
187
188
  });
188
189
  ```
189
190
 
191
+ ### Payments
192
+
193
+ ```javascript
194
+ // Create and redirect to a Stripe Checkout Session
195
+ const { data, error } = await insforge.payments.createCheckoutSession({
196
+ environment: 'test',
197
+ mode: 'payment',
198
+ lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
199
+ successUrl: `${window.location.origin}/success`,
200
+ cancelUrl: `${window.location.origin}/pricing`,
201
+ idempotencyKey: 'cart_123'
202
+ });
203
+
204
+ if (!error && data?.checkoutSession.url) {
205
+ window.location.assign(data.checkoutSession.url);
206
+ }
207
+
208
+ // Create a subscription checkout for an app billing subject
209
+ const { data: subscriptionCheckout } = await insforge.payments.createCheckoutSession({
210
+ environment: 'test',
211
+ mode: 'subscription',
212
+ subject: { type: 'team', id: 'team_123' },
213
+ lineItems: [{ stripePriceId: 'price_monthly_123', quantity: 1 }],
214
+ successUrl: `${window.location.origin}/billing/success`,
215
+ cancelUrl: `${window.location.origin}/billing`
216
+ });
217
+
218
+ if (subscriptionCheckout?.checkoutSession.url) {
219
+ window.location.assign(subscriptionCheckout.checkoutSession.url);
220
+ }
221
+
222
+ // Let an authenticated customer manage their subscription in Stripe Billing Portal
223
+ const { data: portal } = await insforge.payments.createCustomerPortalSession({
224
+ environment: 'test',
225
+ subject: { type: 'team', id: 'team_123' },
226
+ returnUrl: `${window.location.origin}/billing`
227
+ });
228
+
229
+ if (portal?.customerPortalSession.url) {
230
+ window.location.assign(portal.customerPortalSession.url);
231
+ }
232
+ ```
233
+
190
234
  ### AI Integration
191
235
 
192
236
  ```javascript
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 } from '@insforge/shared-schemas';
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, CreateCheckoutSessionRequest, CreateCheckoutSessionResponse, CreateCustomerPortalSessionRequest, 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
 
@@ -974,6 +974,45 @@ declare class Emails {
974
974
  }>;
975
975
  }
976
976
 
977
+ interface PaymentsResponse<T> {
978
+ data: T | null;
979
+ error: InsForgeError | null;
980
+ }
981
+ /**
982
+ * Payments client for runtime Stripe payment flows.
983
+ *
984
+ * These methods are safe to call from generated app frontends with the current
985
+ * user token or anon key. Admin-only Stripe key/catalog APIs are intentionally
986
+ * not exposed here.
987
+ */
988
+ declare class Payments {
989
+ private http;
990
+ constructor(http: HttpClient);
991
+ /**
992
+ * Create a Stripe Checkout Session through the InsForge backend.
993
+ *
994
+ * @example
995
+ * ```typescript
996
+ * const { data, error } = await client.payments.createCheckoutSession({
997
+ * environment: 'test',
998
+ * mode: 'payment',
999
+ * lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
1000
+ * successUrl: `${window.location.origin}/success`,
1001
+ * cancelUrl: `${window.location.origin}/pricing`
1002
+ * });
1003
+ *
1004
+ * if (!error && data.checkoutSession.url) {
1005
+ * window.location.assign(data.checkoutSession.url);
1006
+ * }
1007
+ * ```
1008
+ */
1009
+ createCheckoutSession(request: CreateCheckoutSessionRequest): Promise<PaymentsResponse<CreateCheckoutSessionResponse>>;
1010
+ /**
1011
+ * Create a Stripe Billing Portal Session for a mapped billing subject.
1012
+ */
1013
+ createCustomerPortalSession(request: CreateCustomerPortalSessionRequest): Promise<PaymentsResponse<CreateCustomerPortalSessionResponse>>;
1014
+ }
1015
+
977
1016
  /**
978
1017
  * Main InsForge SDK Client
979
1018
  *
@@ -1028,6 +1067,7 @@ declare class InsForgeClient {
1028
1067
  readonly functions: Functions;
1029
1068
  readonly realtime: Realtime;
1030
1069
  readonly emails: Emails;
1070
+ readonly payments: Payments;
1031
1071
  constructor(config?: InsForgeConfig);
1032
1072
  /**
1033
1073
  * Get the underlying HTTP client for custom requests
@@ -1049,4 +1089,4 @@ declare class InsForgeClient {
1049
1089
 
1050
1090
  declare function createClient(config: InsForgeConfig): InsForgeClient;
1051
1091
 
1052
- 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 };
1092
+ 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, Payments, type PaymentsResponse, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, createClient, InsForgeClient as default };
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 } from '@insforge/shared-schemas';
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, CreateCheckoutSessionRequest, CreateCheckoutSessionResponse, CreateCustomerPortalSessionRequest, 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
 
@@ -974,6 +974,45 @@ declare class Emails {
974
974
  }>;
975
975
  }
976
976
 
977
+ interface PaymentsResponse<T> {
978
+ data: T | null;
979
+ error: InsForgeError | null;
980
+ }
981
+ /**
982
+ * Payments client for runtime Stripe payment flows.
983
+ *
984
+ * These methods are safe to call from generated app frontends with the current
985
+ * user token or anon key. Admin-only Stripe key/catalog APIs are intentionally
986
+ * not exposed here.
987
+ */
988
+ declare class Payments {
989
+ private http;
990
+ constructor(http: HttpClient);
991
+ /**
992
+ * Create a Stripe Checkout Session through the InsForge backend.
993
+ *
994
+ * @example
995
+ * ```typescript
996
+ * const { data, error } = await client.payments.createCheckoutSession({
997
+ * environment: 'test',
998
+ * mode: 'payment',
999
+ * lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
1000
+ * successUrl: `${window.location.origin}/success`,
1001
+ * cancelUrl: `${window.location.origin}/pricing`
1002
+ * });
1003
+ *
1004
+ * if (!error && data.checkoutSession.url) {
1005
+ * window.location.assign(data.checkoutSession.url);
1006
+ * }
1007
+ * ```
1008
+ */
1009
+ createCheckoutSession(request: CreateCheckoutSessionRequest): Promise<PaymentsResponse<CreateCheckoutSessionResponse>>;
1010
+ /**
1011
+ * Create a Stripe Billing Portal Session for a mapped billing subject.
1012
+ */
1013
+ createCustomerPortalSession(request: CreateCustomerPortalSessionRequest): Promise<PaymentsResponse<CreateCustomerPortalSessionResponse>>;
1014
+ }
1015
+
977
1016
  /**
978
1017
  * Main InsForge SDK Client
979
1018
  *
@@ -1028,6 +1067,7 @@ declare class InsForgeClient {
1028
1067
  readonly functions: Functions;
1029
1068
  readonly realtime: Realtime;
1030
1069
  readonly emails: Emails;
1070
+ readonly payments: Payments;
1031
1071
  constructor(config?: InsForgeConfig);
1032
1072
  /**
1033
1073
  * Get the underlying HTTP client for custom requests
@@ -1049,4 +1089,4 @@ declare class InsForgeClient {
1049
1089
 
1050
1090
  declare function createClient(config: InsForgeConfig): InsForgeClient;
1051
1091
 
1052
- 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 };
1092
+ 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, Payments, type PaymentsResponse, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, createClient, InsForgeClient as default };
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ __export(index_exports, {
29
29
  InsForgeClient: () => InsForgeClient,
30
30
  InsForgeError: () => InsForgeError,
31
31
  Logger: () => Logger,
32
+ Payments: () => Payments,
32
33
  Realtime: () => Realtime,
33
34
  Storage: () => Storage,
34
35
  StorageBucket: () => StorageBucket,
@@ -2160,7 +2161,7 @@ var Realtime = class {
2160
2161
  */
2161
2162
  async subscribe(channel) {
2162
2163
  if (this.subscribedChannels.has(channel)) {
2163
- return { ok: true, channel };
2164
+ return { ok: true, channel, presence: { members: [] } };
2164
2165
  }
2165
2166
  if (!this.socket?.connected) {
2166
2167
  try {
@@ -2291,6 +2292,63 @@ var Emails = class {
2291
2292
  }
2292
2293
  };
2293
2294
 
2295
+ // src/modules/payments.ts
2296
+ var Payments = class {
2297
+ constructor(http) {
2298
+ this.http = http;
2299
+ }
2300
+ /**
2301
+ * Create a Stripe Checkout Session through the InsForge backend.
2302
+ *
2303
+ * @example
2304
+ * ```typescript
2305
+ * const { data, error } = await client.payments.createCheckoutSession({
2306
+ * environment: 'test',
2307
+ * mode: 'payment',
2308
+ * lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
2309
+ * successUrl: `${window.location.origin}/success`,
2310
+ * cancelUrl: `${window.location.origin}/pricing`
2311
+ * });
2312
+ *
2313
+ * if (!error && data.checkoutSession.url) {
2314
+ * window.location.assign(data.checkoutSession.url);
2315
+ * }
2316
+ * ```
2317
+ */
2318
+ async createCheckoutSession(request) {
2319
+ try {
2320
+ const data = await this.http.post(
2321
+ "/api/payments/checkout-sessions",
2322
+ request,
2323
+ { idempotent: !!request.idempotencyKey }
2324
+ );
2325
+ return { data, error: null };
2326
+ } catch (error) {
2327
+ return wrapError(
2328
+ error,
2329
+ "Checkout session creation failed"
2330
+ );
2331
+ }
2332
+ }
2333
+ /**
2334
+ * Create a Stripe Billing Portal Session for a mapped billing subject.
2335
+ */
2336
+ async createCustomerPortalSession(request) {
2337
+ try {
2338
+ const data = await this.http.post(
2339
+ "/api/payments/customer-portal-sessions",
2340
+ request
2341
+ );
2342
+ return { data, error: null };
2343
+ } catch (error) {
2344
+ return wrapError(
2345
+ error,
2346
+ "Customer portal session creation failed"
2347
+ );
2348
+ }
2349
+ }
2350
+ };
2351
+
2294
2352
  // src/client.ts
2295
2353
  var InsForgeClient = class {
2296
2354
  constructor(config = {}) {
@@ -2302,7 +2360,7 @@ var InsForgeClient = class {
2302
2360
  this.tokenManager.setAccessToken(config.edgeFunctionToken);
2303
2361
  }
2304
2362
  this.auth = new Auth(this.http, this.tokenManager, {
2305
- isServerMode: config.isServerMode ?? false
2363
+ isServerMode: config.isServerMode ?? !!config.edgeFunctionToken
2306
2364
  });
2307
2365
  this.database = new Database(this.http, this.tokenManager);
2308
2366
  this.storage = new Storage(this.http);
@@ -2314,6 +2372,7 @@ var InsForgeClient = class {
2314
2372
  config.anonKey
2315
2373
  );
2316
2374
  this.emails = new Emails(this.http);
2375
+ this.payments = new Payments(this.http);
2317
2376
  }
2318
2377
  /**
2319
2378
  * Get the underlying HTTP client for custom requests
@@ -2353,6 +2412,7 @@ var index_default = InsForgeClient;
2353
2412
  InsForgeClient,
2354
2413
  InsForgeError,
2355
2414
  Logger,
2415
+ Payments,
2356
2416
  Realtime,
2357
2417
  Storage,
2358
2418
  StorageBucket,