openxiangda 1.0.123 → 1.0.124
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/package.json +1 -1
- package/packages/sdk/dist/runtime/index.cjs +89 -10
- package/packages/sdk/dist/runtime/index.cjs.map +1 -1
- package/packages/sdk/dist/runtime/index.mjs +137 -58
- package/packages/sdk/dist/runtime/index.mjs.map +1 -1
- package/packages/sdk/dist/runtime/react.cjs +91 -12
- package/packages/sdk/dist/runtime/react.cjs.map +1 -1
- package/packages/sdk/dist/runtime/react.d.mts +9 -3
- package/packages/sdk/dist/runtime/react.d.ts +9 -3
- package/packages/sdk/dist/runtime/react.mjs +92 -13
- package/packages/sdk/dist/runtime/react.mjs.map +1 -1
package/package.json
CHANGED
|
@@ -35356,10 +35356,18 @@ var OpenXiangdaProvider = ({
|
|
|
35356
35356
|
const [accessToken, setAccessTokenState] = (0, import_react216.useState)(null);
|
|
35357
35357
|
const accessTokenRef = (0, import_react216.useRef)(null);
|
|
35358
35358
|
const setAccessToken = (0, import_react216.useCallback)(
|
|
35359
|
-
(nextAccessToken) => {
|
|
35359
|
+
(nextAccessToken, options = {}) => {
|
|
35360
|
+
if (!nextAccessToken && options.clearIfToken && accessTokenRef.current?.token !== options.clearIfToken) {
|
|
35361
|
+
return;
|
|
35362
|
+
}
|
|
35360
35363
|
const normalizedAccessToken = nextAccessToken || null;
|
|
35361
|
-
|
|
35362
|
-
|
|
35364
|
+
const nextState = normalizedAccessToken ? {
|
|
35365
|
+
token: normalizedAccessToken,
|
|
35366
|
+
scope: options.scope || "default",
|
|
35367
|
+
path: options.path || null
|
|
35368
|
+
} : null;
|
|
35369
|
+
accessTokenRef.current = nextState;
|
|
35370
|
+
setAccessTokenState(nextState);
|
|
35363
35371
|
},
|
|
35364
35372
|
[]
|
|
35365
35373
|
);
|
|
@@ -35385,7 +35393,13 @@ var OpenXiangdaProvider = ({
|
|
|
35385
35393
|
return;
|
|
35386
35394
|
}
|
|
35387
35395
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
35388
|
-
const requestFetch = options.accessToken !== void 0 ? createAuthorizedFetch(
|
|
35396
|
+
const requestFetch = options.accessToken !== void 0 ? createAuthorizedFetch(
|
|
35397
|
+
resolvedFetch,
|
|
35398
|
+
createAccessTokenState(
|
|
35399
|
+
options.accessToken || null,
|
|
35400
|
+
options.accessTokenOptions
|
|
35401
|
+
)
|
|
35402
|
+
) : createAuthorizedFetch(resolvedFetch, accessTokenRef.current);
|
|
35389
35403
|
try {
|
|
35390
35404
|
const response = await requestFetch(
|
|
35391
35405
|
buildServiceUrl3(
|
|
@@ -35795,9 +35809,11 @@ var buildServiceUrl3 = (servicePrefix, path) => {
|
|
|
35795
35809
|
var createAuthorizedFetch = (baseFetch, accessToken) => {
|
|
35796
35810
|
if (!accessToken) return baseFetch;
|
|
35797
35811
|
return ((input, init = {}) => {
|
|
35812
|
+
const token = resolveAccessTokenForCurrentRoute(accessToken);
|
|
35813
|
+
if (!token) return baseFetch(input, init);
|
|
35798
35814
|
const headers = new Headers(init.headers || {});
|
|
35799
35815
|
if (!headers.has("authorization")) {
|
|
35800
|
-
headers.set("authorization", `Bearer ${
|
|
35816
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
35801
35817
|
}
|
|
35802
35818
|
return baseFetch(input, {
|
|
35803
35819
|
...init,
|
|
@@ -35805,6 +35821,34 @@ var createAuthorizedFetch = (baseFetch, accessToken) => {
|
|
|
35805
35821
|
});
|
|
35806
35822
|
});
|
|
35807
35823
|
};
|
|
35824
|
+
var createAccessTokenState = (accessToken, options = {}) => accessToken ? {
|
|
35825
|
+
token: accessToken,
|
|
35826
|
+
scope: options.scope || "default",
|
|
35827
|
+
path: options.path || null
|
|
35828
|
+
} : null;
|
|
35829
|
+
var resolveAccessTokenForCurrentRoute = (accessToken) => {
|
|
35830
|
+
if (accessToken.scope !== "public") return accessToken.token;
|
|
35831
|
+
const scopedPath = normalizeRoutePath(accessToken.path);
|
|
35832
|
+
const currentPath = normalizeRoutePath(getCurrentPathname2());
|
|
35833
|
+
if (!scopedPath) {
|
|
35834
|
+
return isPublicRoutePath(currentPath) ? accessToken.token : null;
|
|
35835
|
+
}
|
|
35836
|
+
if (currentPath === scopedPath || isPublicRoutePath(currentPath) && currentPath.startsWith(`${scopedPath}/`)) {
|
|
35837
|
+
return accessToken.token;
|
|
35838
|
+
}
|
|
35839
|
+
return null;
|
|
35840
|
+
};
|
|
35841
|
+
var normalizeRoutePath = (path) => {
|
|
35842
|
+
const text = String(path || "").trim();
|
|
35843
|
+
if (!text) return "";
|
|
35844
|
+
try {
|
|
35845
|
+
const base = typeof window !== "undefined" ? window.location.origin : "http://localhost";
|
|
35846
|
+
return new URL(text, base).pathname.replace(/\/+$/, "") || "/";
|
|
35847
|
+
} catch {
|
|
35848
|
+
return text.split(/[?#]/, 1)[0].replace(/\/+$/, "") || "/";
|
|
35849
|
+
}
|
|
35850
|
+
};
|
|
35851
|
+
var isPublicRoutePath = (path) => /\/public(?:\/|$)/.test(path);
|
|
35808
35852
|
var readJsonPayload = async (response) => {
|
|
35809
35853
|
try {
|
|
35810
35854
|
return await response.json();
|
|
@@ -35905,6 +35949,7 @@ var attachCallback = (loginUrl, callback) => {
|
|
|
35905
35949
|
}
|
|
35906
35950
|
};
|
|
35907
35951
|
var getCurrentHref4 = () => typeof window === "undefined" ? "" : window.location.href;
|
|
35952
|
+
var getCurrentPathname2 = () => typeof window === "undefined" ? "" : window.location.pathname;
|
|
35908
35953
|
var getCurrentHostname2 = () => typeof window === "undefined" ? "" : window.location.hostname;
|
|
35909
35954
|
var getRuntimeEnv = (key) => {
|
|
35910
35955
|
const env = typeof process !== "undefined" ? process.env : void 0;
|
|
@@ -35997,6 +36042,8 @@ var usePublicAccess = (options = {}) => {
|
|
|
35997
36042
|
const [session, setSession] = (0, import_react217.useState)(null);
|
|
35998
36043
|
const [error, setError] = (0, import_react217.useState)(null);
|
|
35999
36044
|
const [loading, setLoading] = (0, import_react217.useState)(Boolean(autoStart));
|
|
36045
|
+
const activeSessionRef = (0, import_react217.useRef)(null);
|
|
36046
|
+
const mountedRef = (0, import_react217.useRef)(true);
|
|
36000
36047
|
const sessionInputKey = JSON.stringify(sessionInput);
|
|
36001
36048
|
const stableSessionInput = (0, import_react217.useMemo)(() => sessionInput, [sessionInputKey]);
|
|
36002
36049
|
const client = (0, import_react217.useMemo)(
|
|
@@ -36012,15 +36059,31 @@ var usePublicAccess = (options = {}) => {
|
|
|
36012
36059
|
setLoading(true);
|
|
36013
36060
|
setError(null);
|
|
36014
36061
|
try {
|
|
36062
|
+
const resolvedPath = input.path || stableSessionInput.path || readPathFromLocation();
|
|
36015
36063
|
const data = await client.startSession({
|
|
36016
36064
|
...stableSessionInput,
|
|
36017
36065
|
...input,
|
|
36018
36066
|
ticket: input.ticket || stableSessionInput.ticket || readTicketFromLocation(),
|
|
36019
|
-
path:
|
|
36067
|
+
path: resolvedPath
|
|
36020
36068
|
});
|
|
36069
|
+
if (!mountedRef.current) return data;
|
|
36070
|
+
activeSessionRef.current = {
|
|
36071
|
+
accessToken: data.accessToken,
|
|
36072
|
+
path: resolvedPath
|
|
36073
|
+
};
|
|
36021
36074
|
setSession(data);
|
|
36022
|
-
setAccessToken(data.accessToken
|
|
36023
|
-
|
|
36075
|
+
setAccessToken(data.accessToken, {
|
|
36076
|
+
scope: "public",
|
|
36077
|
+
path: resolvedPath
|
|
36078
|
+
});
|
|
36079
|
+
await reloadRuntime({
|
|
36080
|
+
accessToken: data.accessToken,
|
|
36081
|
+
accessTokenOptions: {
|
|
36082
|
+
scope: "public",
|
|
36083
|
+
path: resolvedPath
|
|
36084
|
+
}
|
|
36085
|
+
});
|
|
36086
|
+
if (!mountedRef.current) return data;
|
|
36024
36087
|
setLoading(false);
|
|
36025
36088
|
return data;
|
|
36026
36089
|
} catch (caught) {
|
|
@@ -36028,8 +36091,10 @@ var usePublicAccess = (options = {}) => {
|
|
|
36028
36091
|
caught instanceof Error ? caught.message : "\u516C\u5F00\u8BBF\u95EE\u4F1A\u8BDD\u521B\u5EFA\u5931\u8D25",
|
|
36029
36092
|
{ payload: caught }
|
|
36030
36093
|
);
|
|
36031
|
-
|
|
36032
|
-
|
|
36094
|
+
if (mountedRef.current) {
|
|
36095
|
+
setError(nextError);
|
|
36096
|
+
setLoading(false);
|
|
36097
|
+
}
|
|
36033
36098
|
throw nextError;
|
|
36034
36099
|
}
|
|
36035
36100
|
},
|
|
@@ -36039,6 +36104,20 @@ var usePublicAccess = (options = {}) => {
|
|
|
36039
36104
|
if (!autoStart) return;
|
|
36040
36105
|
void startSession().catch(() => void 0);
|
|
36041
36106
|
}, [autoStart, startSession]);
|
|
36107
|
+
(0, import_react217.useEffect)(
|
|
36108
|
+
() => {
|
|
36109
|
+
mountedRef.current = true;
|
|
36110
|
+
return () => {
|
|
36111
|
+
mountedRef.current = false;
|
|
36112
|
+
const activeSession = activeSessionRef.current;
|
|
36113
|
+
if (!activeSession) return;
|
|
36114
|
+
activeSessionRef.current = null;
|
|
36115
|
+
setAccessToken(null, { clearIfToken: activeSession.accessToken });
|
|
36116
|
+
void reloadRuntime({ accessToken: null });
|
|
36117
|
+
};
|
|
36118
|
+
},
|
|
36119
|
+
[reloadRuntime, setAccessToken]
|
|
36120
|
+
);
|
|
36042
36121
|
return {
|
|
36043
36122
|
loading,
|
|
36044
36123
|
error,
|