@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.mjs CHANGED
@@ -1009,21 +1009,43 @@ var Auth = class {
1009
1009
  };
1010
1010
  }
1011
1011
  }
1012
- // ============================================================================
1013
- // OAuth Authentication
1014
- // ============================================================================
1015
- /**
1016
- * Sign in with OAuth provider using PKCE flow
1017
- */
1018
- async signInWithOAuth(options) {
1012
+ async signInWithOAuth(providerOrOptions, options) {
1019
1013
  try {
1020
- const { provider, redirectTo, skipBrowserRedirect } = options;
1014
+ let signInOptions;
1015
+ if (typeof providerOrOptions === "object") {
1016
+ signInOptions = providerOrOptions;
1017
+ } else if (options) {
1018
+ signInOptions = { provider: providerOrOptions, ...options };
1019
+ } else {
1020
+ return {
1021
+ data: {},
1022
+ error: new InsForgeError(
1023
+ "OAuth sign-in options are required",
1024
+ 400,
1025
+ ERROR_CODES.INVALID_INPUT
1026
+ )
1027
+ };
1028
+ }
1029
+ if (!signInOptions || !signInOptions.redirectTo) {
1030
+ return {
1031
+ data: {},
1032
+ error: new InsForgeError(
1033
+ "Redirect URI is required",
1034
+ 400,
1035
+ ERROR_CODES.INVALID_INPUT
1036
+ )
1037
+ };
1038
+ }
1039
+ const { provider } = signInOptions;
1021
1040
  const providerKey = encodeURIComponent(provider.toLowerCase());
1022
1041
  const codeVerifier = generateCodeVerifier();
1023
1042
  const codeChallenge = await generateCodeChallenge(codeVerifier);
1024
1043
  storePkceVerifier(codeVerifier);
1025
- const params = { code_challenge: codeChallenge };
1026
- if (redirectTo) params.redirect_uri = redirectTo;
1044
+ const params = {
1045
+ ...signInOptions.additionalParams ?? {},
1046
+ redirect_uri: signInOptions.redirectTo,
1047
+ code_challenge: codeChallenge
1048
+ };
1027
1049
  const isBuiltInProvider = oAuthProvidersSchema.options.includes(
1028
1050
  providerKey
1029
1051
  );
@@ -1032,7 +1054,7 @@ var Auth = class {
1032
1054
  params,
1033
1055
  skipAuthRefresh: true
1034
1056
  });
1035
- if (!this.isServerMode() && typeof window !== "undefined" && !skipBrowserRedirect) {
1057
+ if (!this.isServerMode() && typeof window !== "undefined" && !signInOptions.skipBrowserRedirect) {
1036
1058
  window.location.href = response.authUrl;
1037
1059
  return { data: {}, error: null };
1038
1060
  }
@@ -2022,7 +2044,7 @@ var Images = class {
2022
2044
  * model: 'dall-e-3',
2023
2045
  * prompt: 'A sunset over mountains',
2024
2046
  * });
2025
- * console.log(response.images[0].url);
2047
+ * console.log(response.data[0].b64_json);
2026
2048
  *
2027
2049
  * // Image-to-image (with input images)
2028
2050
  * const response = await client.ai.images.generate({
@@ -2463,7 +2485,10 @@ var Emails = class {
2463
2485
  };
2464
2486
 
2465
2487
  // src/modules/payments.ts
2466
- var Payments = class {
2488
+ function providerEnvironmentPath(provider, environment) {
2489
+ return `/api/payments/${provider}/${encodeURIComponent(environment)}`;
2490
+ }
2491
+ var StripePayments = class {
2467
2492
  constructor(http) {
2468
2493
  this.http = http;
2469
2494
  }
@@ -2472,9 +2497,9 @@ var Payments = class {
2472
2497
  *
2473
2498
  * @example
2474
2499
  * ```typescript
2475
- * const { data, error } = await client.payments.createCheckoutSession('test', {
2500
+ * const { data, error } = await client.payments.stripe.createCheckoutSession('test', {
2476
2501
  * mode: 'payment',
2477
- * lineItems: [{ stripePriceId: 'price_123', quantity: 1 }],
2502
+ * lineItems: [{ priceId: 'price_123', quantity: 1 }],
2478
2503
  * successUrl: `${window.location.origin}/success`,
2479
2504
  * cancelUrl: `${window.location.origin}/pricing`
2480
2505
  * });
@@ -2487,7 +2512,7 @@ var Payments = class {
2487
2512
  async createCheckoutSession(environment, request) {
2488
2513
  try {
2489
2514
  const data = await this.http.post(
2490
- `/api/payments/${encodeURIComponent(environment)}/checkout-sessions`,
2515
+ `${providerEnvironmentPath("stripe", environment)}/checkout-sessions`,
2491
2516
  request,
2492
2517
  { idempotent: !!request.idempotencyKey }
2493
2518
  );
@@ -2495,7 +2520,7 @@ var Payments = class {
2495
2520
  } catch (error) {
2496
2521
  return wrapError(
2497
2522
  error,
2498
- "Checkout session creation failed"
2523
+ "Stripe checkout session creation failed"
2499
2524
  );
2500
2525
  }
2501
2526
  }
@@ -2505,17 +2530,132 @@ var Payments = class {
2505
2530
  async createCustomerPortalSession(environment, request) {
2506
2531
  try {
2507
2532
  const data = await this.http.post(
2508
- `/api/payments/${encodeURIComponent(environment)}/customer-portal-sessions`,
2533
+ `${providerEnvironmentPath("stripe", environment)}/customer-portal-sessions`,
2534
+ request
2535
+ );
2536
+ return { data, error: null };
2537
+ } catch (error) {
2538
+ return wrapError(
2539
+ error,
2540
+ "Stripe customer portal session creation failed"
2541
+ );
2542
+ }
2543
+ }
2544
+ };
2545
+ var RazorpayPayments = class {
2546
+ constructor(http) {
2547
+ this.http = http;
2548
+ }
2549
+ async createOrder(environment, request) {
2550
+ try {
2551
+ const data = await this.http.post(
2552
+ `${providerEnvironmentPath("razorpay", environment)}/orders`,
2553
+ request
2554
+ );
2555
+ return { data, error: null };
2556
+ } catch (error) {
2557
+ return wrapError(
2558
+ error,
2559
+ "Razorpay order creation failed"
2560
+ );
2561
+ }
2562
+ }
2563
+ async verifyOrder(environment, request) {
2564
+ try {
2565
+ const data = await this.http.post(
2566
+ `${providerEnvironmentPath("razorpay", environment)}/orders/verify`,
2509
2567
  request
2510
2568
  );
2511
2569
  return { data, error: null };
2512
2570
  } catch (error) {
2513
2571
  return wrapError(
2514
2572
  error,
2515
- "Customer portal session creation failed"
2573
+ "Razorpay order verification failed"
2516
2574
  );
2517
2575
  }
2518
2576
  }
2577
+ async createSubscription(environment, request) {
2578
+ try {
2579
+ const data = await this.http.post(
2580
+ `${providerEnvironmentPath("razorpay", environment)}/subscriptions`,
2581
+ request
2582
+ );
2583
+ return { data, error: null };
2584
+ } catch (error) {
2585
+ return wrapError(
2586
+ error,
2587
+ "Razorpay subscription creation failed"
2588
+ );
2589
+ }
2590
+ }
2591
+ async verifySubscription(environment, request) {
2592
+ try {
2593
+ const data = await this.http.post(
2594
+ `${providerEnvironmentPath("razorpay", environment)}/subscriptions/verify`,
2595
+ request
2596
+ );
2597
+ return { data, error: null };
2598
+ } catch (error) {
2599
+ return wrapError(
2600
+ error,
2601
+ "Razorpay subscription verification failed"
2602
+ );
2603
+ }
2604
+ }
2605
+ async cancelSubscription(environment, subscriptionId, request = {}) {
2606
+ try {
2607
+ const data = await this.http.post(
2608
+ `${providerEnvironmentPath("razorpay", environment)}/subscriptions/${encodeURIComponent(
2609
+ subscriptionId
2610
+ )}/cancel`,
2611
+ request
2612
+ );
2613
+ return { data, error: null };
2614
+ } catch (error) {
2615
+ return wrapError(
2616
+ error,
2617
+ "Razorpay subscription cancellation failed"
2618
+ );
2619
+ }
2620
+ }
2621
+ async pauseSubscription(environment, subscriptionId) {
2622
+ try {
2623
+ const data = await this.http.post(
2624
+ `${providerEnvironmentPath("razorpay", environment)}/subscriptions/${encodeURIComponent(
2625
+ subscriptionId
2626
+ )}/pause`,
2627
+ {}
2628
+ );
2629
+ return { data, error: null };
2630
+ } catch (error) {
2631
+ return wrapError(
2632
+ error,
2633
+ "Razorpay subscription pause failed"
2634
+ );
2635
+ }
2636
+ }
2637
+ async resumeSubscription(environment, subscriptionId) {
2638
+ try {
2639
+ const data = await this.http.post(
2640
+ `${providerEnvironmentPath("razorpay", environment)}/subscriptions/${encodeURIComponent(
2641
+ subscriptionId
2642
+ )}/resume`,
2643
+ {}
2644
+ );
2645
+ return { data, error: null };
2646
+ } catch (error) {
2647
+ return wrapError(
2648
+ error,
2649
+ "Razorpay subscription resume failed"
2650
+ );
2651
+ }
2652
+ }
2653
+ };
2654
+ var Payments = class {
2655
+ constructor(http) {
2656
+ this.stripe = new StripePayments(http);
2657
+ this.razorpay = new RazorpayPayments(http);
2658
+ }
2519
2659
  };
2520
2660
 
2521
2661
  // src/client.ts