@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/CONTRIBUTING.md +27 -0
- package/README.md +5 -2
- package/SDK-REFERENCE.md +842 -0
- package/dist/{client-CQfw9UsO.d.mts → client-DTNmGqHB.d.mts} +20 -5
- package/dist/{client-CQfw9UsO.d.ts → client-DTNmGqHB.d.ts} +20 -5
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +36 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -13
- package/dist/index.mjs.map +1 -1
- package/dist/ssr.d.mts +1 -1
- package/dist/ssr.d.ts +1 -1
- package/dist/ssr.js +46 -15
- package/dist/ssr.js.map +1 -1
- package/dist/ssr.mjs +46 -15
- package/dist/ssr.mjs.map +1 -1
- package/package.json +5 -3
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
|
-
|
|
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 = {
|
|
1026
|
-
|
|
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
|
}
|
|
@@ -2622,8 +2644,9 @@ function getJwtExpiration(token) {
|
|
|
2622
2644
|
}
|
|
2623
2645
|
}
|
|
2624
2646
|
function isJwtExpiredOrExpiring(token, leewaySeconds = 60) {
|
|
2647
|
+
if (!token) return false;
|
|
2625
2648
|
const expires = getJwtExpiration(token);
|
|
2626
|
-
if (!expires) return
|
|
2649
|
+
if (!expires) return true;
|
|
2627
2650
|
return expires.getTime() <= Date.now() + leewaySeconds * 1e3;
|
|
2628
2651
|
}
|
|
2629
2652
|
|
|
@@ -2690,11 +2713,12 @@ function refreshTokenCookieOptions(token, overrides) {
|
|
|
2690
2713
|
};
|
|
2691
2714
|
}
|
|
2692
2715
|
function expiredCookieOptions(overrides) {
|
|
2716
|
+
const { expires: _expires, maxAge: _maxAge, ...safeOverrides } = overrides ?? {};
|
|
2693
2717
|
return {
|
|
2694
2718
|
...defaultCookieOptions(),
|
|
2719
|
+
...safeOverrides,
|
|
2695
2720
|
expires: EXPIRED_DATE,
|
|
2696
|
-
maxAge: 0
|
|
2697
|
-
...overrides
|
|
2721
|
+
maxAge: 0
|
|
2698
2722
|
};
|
|
2699
2723
|
}
|
|
2700
2724
|
function setCookie(cookies, name, value, options) {
|
|
@@ -2835,6 +2859,13 @@ function withAuthHeader(init, token) {
|
|
|
2835
2859
|
headers
|
|
2836
2860
|
};
|
|
2837
2861
|
}
|
|
2862
|
+
function getRequestUrl(input) {
|
|
2863
|
+
if (typeof input === "string") return input;
|
|
2864
|
+
if (typeof Request !== "undefined" && input instanceof Request) {
|
|
2865
|
+
return input.url;
|
|
2866
|
+
}
|
|
2867
|
+
return input.toString();
|
|
2868
|
+
}
|
|
2838
2869
|
function createBrowserClient(options = {}) {
|
|
2839
2870
|
let { baseUrl, anonKey } = options;
|
|
2840
2871
|
try {
|
|
@@ -2891,7 +2922,7 @@ function createBrowserClient(options = {}) {
|
|
|
2891
2922
|
return refreshPromise;
|
|
2892
2923
|
};
|
|
2893
2924
|
const shouldSkipRefresh = (input) => {
|
|
2894
|
-
const url =
|
|
2925
|
+
const url = getRequestUrl(input);
|
|
2895
2926
|
return url === refreshUrl || url.endsWith(refreshUrl);
|
|
2896
2927
|
};
|
|
2897
2928
|
const ssrFetch = async (input, init) => {
|