@insforge/sdk 1.3.0 → 1.3.2-razorpay.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/ssr.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as InsForgeConfig, I as InsForgeClient, m as AuthRefreshResponse, e as InsForgeError } from './client-CQfw9UsO.mjs';
1
+ import { a as InsForgeConfig, I as InsForgeClient, m as AuthRefreshResponse, e as InsForgeError } from './client-Co8KxT-n.mjs';
2
2
  import '@insforge/shared-schemas';
3
3
  import '@supabase/postgrest-js';
4
4
 
package/dist/ssr.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as InsForgeConfig, I as InsForgeClient, m as AuthRefreshResponse, e as InsForgeError } from './client-CQfw9UsO.js';
1
+ import { a as InsForgeConfig, I as InsForgeClient, m as AuthRefreshResponse, e as InsForgeError } from './client-Co8KxT-n.js';
2
2
  import '@insforge/shared-schemas';
3
3
  import '@supabase/postgrest-js';
4
4
 
package/dist/ssr.js CHANGED
@@ -1057,21 +1057,43 @@ var Auth = class {
1057
1057
  };
1058
1058
  }
1059
1059
  }
1060
- // ============================================================================
1061
- // OAuth Authentication
1062
- // ============================================================================
1063
- /**
1064
- * Sign in with OAuth provider using PKCE flow
1065
- */
1066
- async signInWithOAuth(options) {
1060
+ async signInWithOAuth(providerOrOptions, options) {
1067
1061
  try {
1068
- const { provider, redirectTo, skipBrowserRedirect } = options;
1062
+ let signInOptions;
1063
+ if (typeof providerOrOptions === "object") {
1064
+ signInOptions = providerOrOptions;
1065
+ } else if (options) {
1066
+ signInOptions = { provider: providerOrOptions, ...options };
1067
+ } else {
1068
+ return {
1069
+ data: {},
1070
+ error: new InsForgeError(
1071
+ "OAuth sign-in options are required",
1072
+ 400,
1073
+ import_shared_schemas.ERROR_CODES.INVALID_INPUT
1074
+ )
1075
+ };
1076
+ }
1077
+ if (!signInOptions || !signInOptions.redirectTo) {
1078
+ return {
1079
+ data: {},
1080
+ error: new InsForgeError(
1081
+ "Redirect URI is required",
1082
+ 400,
1083
+ import_shared_schemas.ERROR_CODES.INVALID_INPUT
1084
+ )
1085
+ };
1086
+ }
1087
+ const { provider } = signInOptions;
1069
1088
  const providerKey = encodeURIComponent(provider.toLowerCase());
1070
1089
  const codeVerifier = generateCodeVerifier();
1071
1090
  const codeChallenge = await generateCodeChallenge(codeVerifier);
1072
1091
  storePkceVerifier(codeVerifier);
1073
- const params = { code_challenge: codeChallenge };
1074
- if (redirectTo) params.redirect_uri = redirectTo;
1092
+ const params = {
1093
+ ...signInOptions.additionalParams ?? {},
1094
+ redirect_uri: signInOptions.redirectTo,
1095
+ code_challenge: codeChallenge
1096
+ };
1075
1097
  const isBuiltInProvider = import_shared_schemas.oAuthProvidersSchema.options.includes(
1076
1098
  providerKey
1077
1099
  );
@@ -1080,7 +1102,7 @@ var Auth = class {
1080
1102
  params,
1081
1103
  skipAuthRefresh: true
1082
1104
  });
1083
- if (!this.isServerMode() && typeof window !== "undefined" && !skipBrowserRedirect) {
1105
+ if (!this.isServerMode() && typeof window !== "undefined" && !signInOptions.skipBrowserRedirect) {
1084
1106
  window.location.href = response.authUrl;
1085
1107
  return { data: {}, error: null };
1086
1108
  }
@@ -2070,7 +2092,7 @@ var Images = class {
2070
2092
  * model: 'dall-e-3',
2071
2093
  * prompt: 'A sunset over mountains',
2072
2094
  * });
2073
- * console.log(response.images[0].url);
2095
+ * console.log(response.data[0].b64_json);
2074
2096
  *
2075
2097
  * // Image-to-image (with input images)
2076
2098
  * const response = await client.ai.images.generate({
@@ -2511,7 +2533,10 @@ var Emails = class {
2511
2533
  };
2512
2534
 
2513
2535
  // src/modules/payments.ts
2514
- var Payments = class {
2536
+ function providerEnvironmentPath(provider, environment) {
2537
+ return `/api/payments/${provider}/${encodeURIComponent(environment)}`;
2538
+ }
2539
+ var StripePayments = class {
2515
2540
  constructor(http) {
2516
2541
  this.http = http;
2517
2542
  }
@@ -2520,9 +2545,9 @@ var Payments = class {
2520
2545
  *
2521
2546
  * @example
2522
2547
  * ```typescript
2523
- * const { data, error } = await client.payments.createCheckoutSession('test', {
2548
+ * const { data, error } = await client.payments.stripe.createCheckoutSession('test', {
2524
2549
  * mode: 'payment',
2525
- * lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
2550
+ * lineItems: [{ priceId: 'price_123', quantity: 1 }],
2526
2551
  * successUrl: `${window.location.origin}/success`,
2527
2552
  * cancelUrl: `${window.location.origin}/pricing`
2528
2553
  * });
@@ -2535,7 +2560,7 @@ var Payments = class {
2535
2560
  async createCheckoutSession(environment, request) {
2536
2561
  try {
2537
2562
  const data = await this.http.post(
2538
- `/api/payments/${encodeURIComponent(environment)}/checkout-sessions`,
2563
+ `${providerEnvironmentPath("stripe", environment)}/checkout-sessions`,
2539
2564
  request,
2540
2565
  { idempotent: !!request.idempotencyKey }
2541
2566
  );
@@ -2543,7 +2568,7 @@ var Payments = class {
2543
2568
  } catch (error) {
2544
2569
  return wrapError(
2545
2570
  error,
2546
- "Checkout session creation failed"
2571
+ "Stripe checkout session creation failed"
2547
2572
  );
2548
2573
  }
2549
2574
  }
@@ -2553,17 +2578,132 @@ var Payments = class {
2553
2578
  async createCustomerPortalSession(environment, request) {
2554
2579
  try {
2555
2580
  const data = await this.http.post(
2556
- `/api/payments/${encodeURIComponent(environment)}/customer-portal-sessions`,
2581
+ `${providerEnvironmentPath("stripe", environment)}/customer-portal-sessions`,
2582
+ request
2583
+ );
2584
+ return { data, error: null };
2585
+ } catch (error) {
2586
+ return wrapError(
2587
+ error,
2588
+ "Stripe customer portal session creation failed"
2589
+ );
2590
+ }
2591
+ }
2592
+ };
2593
+ var RazorpayPayments = class {
2594
+ constructor(http) {
2595
+ this.http = http;
2596
+ }
2597
+ async createOrder(environment, request) {
2598
+ try {
2599
+ const data = await this.http.post(
2600
+ `${providerEnvironmentPath("razorpay", environment)}/orders`,
2601
+ request
2602
+ );
2603
+ return { data, error: null };
2604
+ } catch (error) {
2605
+ return wrapError(
2606
+ error,
2607
+ "Razorpay order creation failed"
2608
+ );
2609
+ }
2610
+ }
2611
+ async verifyOrder(environment, request) {
2612
+ try {
2613
+ const data = await this.http.post(
2614
+ `${providerEnvironmentPath("razorpay", environment)}/orders/verify`,
2557
2615
  request
2558
2616
  );
2559
2617
  return { data, error: null };
2560
2618
  } catch (error) {
2561
2619
  return wrapError(
2562
2620
  error,
2563
- "Customer portal session creation failed"
2621
+ "Razorpay order verification failed"
2564
2622
  );
2565
2623
  }
2566
2624
  }
2625
+ async createSubscription(environment, request) {
2626
+ try {
2627
+ const data = await this.http.post(
2628
+ `${providerEnvironmentPath("razorpay", environment)}/subscriptions`,
2629
+ request
2630
+ );
2631
+ return { data, error: null };
2632
+ } catch (error) {
2633
+ return wrapError(
2634
+ error,
2635
+ "Razorpay subscription creation failed"
2636
+ );
2637
+ }
2638
+ }
2639
+ async verifySubscription(environment, request) {
2640
+ try {
2641
+ const data = await this.http.post(
2642
+ `${providerEnvironmentPath("razorpay", environment)}/subscriptions/verify`,
2643
+ request
2644
+ );
2645
+ return { data, error: null };
2646
+ } catch (error) {
2647
+ return wrapError(
2648
+ error,
2649
+ "Razorpay subscription verification failed"
2650
+ );
2651
+ }
2652
+ }
2653
+ async cancelSubscription(environment, subscriptionId, request = {}) {
2654
+ try {
2655
+ const data = await this.http.post(
2656
+ `${providerEnvironmentPath("razorpay", environment)}/subscriptions/${encodeURIComponent(
2657
+ subscriptionId
2658
+ )}/cancel`,
2659
+ request
2660
+ );
2661
+ return { data, error: null };
2662
+ } catch (error) {
2663
+ return wrapError(
2664
+ error,
2665
+ "Razorpay subscription cancellation failed"
2666
+ );
2667
+ }
2668
+ }
2669
+ async pauseSubscription(environment, subscriptionId) {
2670
+ try {
2671
+ const data = await this.http.post(
2672
+ `${providerEnvironmentPath("razorpay", environment)}/subscriptions/${encodeURIComponent(
2673
+ subscriptionId
2674
+ )}/pause`,
2675
+ {}
2676
+ );
2677
+ return { data, error: null };
2678
+ } catch (error) {
2679
+ return wrapError(
2680
+ error,
2681
+ "Razorpay subscription pause failed"
2682
+ );
2683
+ }
2684
+ }
2685
+ async resumeSubscription(environment, subscriptionId) {
2686
+ try {
2687
+ const data = await this.http.post(
2688
+ `${providerEnvironmentPath("razorpay", environment)}/subscriptions/${encodeURIComponent(
2689
+ subscriptionId
2690
+ )}/resume`,
2691
+ {}
2692
+ );
2693
+ return { data, error: null };
2694
+ } catch (error) {
2695
+ return wrapError(
2696
+ error,
2697
+ "Razorpay subscription resume failed"
2698
+ );
2699
+ }
2700
+ }
2701
+ };
2702
+ var Payments = class {
2703
+ constructor(http) {
2704
+ this.stripe = new StripePayments(http);
2705
+ this.razorpay = new RazorpayPayments(http);
2706
+ }
2567
2707
  };
2568
2708
 
2569
2709
  // src/client.ts