@insforge/sdk 1.3.0-ssr.3 → 1.3.1

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-DTNmGqHB.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-DTNmGqHB.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
  }
@@ -2670,8 +2692,9 @@ function getJwtExpiration(token) {
2670
2692
  }
2671
2693
  }
2672
2694
  function isJwtExpiredOrExpiring(token, leewaySeconds = 60) {
2695
+ if (!token) return false;
2673
2696
  const expires = getJwtExpiration(token);
2674
- if (!expires) return false;
2697
+ if (!expires) return true;
2675
2698
  return expires.getTime() <= Date.now() + leewaySeconds * 1e3;
2676
2699
  }
2677
2700
 
@@ -2738,11 +2761,12 @@ function refreshTokenCookieOptions(token, overrides) {
2738
2761
  };
2739
2762
  }
2740
2763
  function expiredCookieOptions(overrides) {
2764
+ const { expires: _expires, maxAge: _maxAge, ...safeOverrides } = overrides ?? {};
2741
2765
  return {
2742
2766
  ...defaultCookieOptions(),
2767
+ ...safeOverrides,
2743
2768
  expires: EXPIRED_DATE,
2744
- maxAge: 0,
2745
- ...overrides
2769
+ maxAge: 0
2746
2770
  };
2747
2771
  }
2748
2772
  function setCookie(cookies, name, value, options) {
@@ -2883,6 +2907,13 @@ function withAuthHeader(init, token) {
2883
2907
  headers
2884
2908
  };
2885
2909
  }
2910
+ function getRequestUrl(input) {
2911
+ if (typeof input === "string") return input;
2912
+ if (typeof Request !== "undefined" && input instanceof Request) {
2913
+ return input.url;
2914
+ }
2915
+ return input.toString();
2916
+ }
2886
2917
  function createBrowserClient(options = {}) {
2887
2918
  let { baseUrl, anonKey } = options;
2888
2919
  try {
@@ -2939,7 +2970,7 @@ function createBrowserClient(options = {}) {
2939
2970
  return refreshPromise;
2940
2971
  };
2941
2972
  const shouldSkipRefresh = (input) => {
2942
- const url = typeof input === "string" ? input : input.toString();
2973
+ const url = getRequestUrl(input);
2943
2974
  return url === refreshUrl || url.endsWith(refreshUrl);
2944
2975
  };
2945
2976
  const ssrFetch = async (input, init) => {