@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/dist/index.mjs CHANGED
@@ -2120,7 +2120,7 @@ var Realtime = class {
2120
2120
  */
2121
2121
  async subscribe(channel) {
2122
2122
  if (this.subscribedChannels.has(channel)) {
2123
- return { ok: true, channel };
2123
+ return { ok: true, channel, presence: { members: [] } };
2124
2124
  }
2125
2125
  if (!this.socket?.connected) {
2126
2126
  try {
@@ -2251,6 +2251,63 @@ var Emails = class {
2251
2251
  }
2252
2252
  };
2253
2253
 
2254
+ // src/modules/payments.ts
2255
+ var Payments = class {
2256
+ constructor(http) {
2257
+ this.http = http;
2258
+ }
2259
+ /**
2260
+ * Create a Stripe Checkout Session through the InsForge backend.
2261
+ *
2262
+ * @example
2263
+ * ```typescript
2264
+ * const { data, error } = await client.payments.createCheckoutSession({
2265
+ * environment: 'test',
2266
+ * mode: 'payment',
2267
+ * lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
2268
+ * successUrl: `${window.location.origin}/success`,
2269
+ * cancelUrl: `${window.location.origin}/pricing`
2270
+ * });
2271
+ *
2272
+ * if (!error && data.checkoutSession.url) {
2273
+ * window.location.assign(data.checkoutSession.url);
2274
+ * }
2275
+ * ```
2276
+ */
2277
+ async createCheckoutSession(request) {
2278
+ try {
2279
+ const data = await this.http.post(
2280
+ "/api/payments/checkout-sessions",
2281
+ request,
2282
+ { idempotent: !!request.idempotencyKey }
2283
+ );
2284
+ return { data, error: null };
2285
+ } catch (error) {
2286
+ return wrapError(
2287
+ error,
2288
+ "Checkout session creation failed"
2289
+ );
2290
+ }
2291
+ }
2292
+ /**
2293
+ * Create a Stripe Billing Portal Session for a mapped billing subject.
2294
+ */
2295
+ async createCustomerPortalSession(request) {
2296
+ try {
2297
+ const data = await this.http.post(
2298
+ "/api/payments/customer-portal-sessions",
2299
+ request
2300
+ );
2301
+ return { data, error: null };
2302
+ } catch (error) {
2303
+ return wrapError(
2304
+ error,
2305
+ "Customer portal session creation failed"
2306
+ );
2307
+ }
2308
+ }
2309
+ };
2310
+
2254
2311
  // src/client.ts
2255
2312
  var InsForgeClient = class {
2256
2313
  constructor(config = {}) {
@@ -2262,7 +2319,7 @@ var InsForgeClient = class {
2262
2319
  this.tokenManager.setAccessToken(config.edgeFunctionToken);
2263
2320
  }
2264
2321
  this.auth = new Auth(this.http, this.tokenManager, {
2265
- isServerMode: config.isServerMode ?? false
2322
+ isServerMode: config.isServerMode ?? !!config.edgeFunctionToken
2266
2323
  });
2267
2324
  this.database = new Database(this.http, this.tokenManager);
2268
2325
  this.storage = new Storage(this.http);
@@ -2274,6 +2331,7 @@ var InsForgeClient = class {
2274
2331
  config.anonKey
2275
2332
  );
2276
2333
  this.emails = new Emails(this.http);
2334
+ this.payments = new Payments(this.http);
2277
2335
  }
2278
2336
  /**
2279
2337
  * Get the underlying HTTP client for custom requests
@@ -2312,6 +2370,7 @@ export {
2312
2370
  InsForgeClient,
2313
2371
  InsForgeError,
2314
2372
  Logger,
2373
+ Payments,
2315
2374
  Realtime,
2316
2375
  Storage,
2317
2376
  StorageBucket,