openxiangda 1.0.122 → 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/openxiangda-skills/references/notifications.md +21 -0
- package/package.json +1 -1
- package/packages/sdk/dist/runtime/index.cjs +128 -10
- package/packages/sdk/dist/runtime/index.cjs.map +1 -1
- package/packages/sdk/dist/runtime/index.d.mts +1 -1
- package/packages/sdk/dist/runtime/index.d.ts +1 -1
- package/packages/sdk/dist/runtime/index.mjs +176 -58
- package/packages/sdk/dist/runtime/index.mjs.map +1 -1
- package/packages/sdk/dist/runtime/react.cjs +130 -12
- package/packages/sdk/dist/runtime/react.cjs.map +1 -1
- package/packages/sdk/dist/runtime/react.d.mts +64 -4
- package/packages/sdk/dist/runtime/react.d.ts +64 -4
- package/packages/sdk/dist/runtime/react.mjs +131 -13
- package/packages/sdk/dist/runtime/react.mjs.map +1 -1
|
@@ -3006,6 +3006,45 @@ var createPageSdk = (context) => {
|
|
|
3006
3006
|
...params,
|
|
3007
3007
|
appType: resolveAppType(context, params.appType)
|
|
3008
3008
|
}
|
|
3009
|
+
}),
|
|
3010
|
+
listInbox: (params = {}) => request({
|
|
3011
|
+
path: buildOpenXiangdaAppPath(
|
|
3012
|
+
context,
|
|
3013
|
+
params.appType,
|
|
3014
|
+
"/notifications/inbox"
|
|
3015
|
+
),
|
|
3016
|
+
method: "get",
|
|
3017
|
+
query: {
|
|
3018
|
+
page: params.page,
|
|
3019
|
+
limit: params.limit,
|
|
3020
|
+
readStatus: params.readStatus,
|
|
3021
|
+
keyword: params.keyword,
|
|
3022
|
+
templateCode: params.templateCode
|
|
3023
|
+
}
|
|
3024
|
+
}),
|
|
3025
|
+
getUnreadCount: (params = {}) => request({
|
|
3026
|
+
path: buildOpenXiangdaAppPath(
|
|
3027
|
+
context,
|
|
3028
|
+
params.appType,
|
|
3029
|
+
"/notifications/inbox/unread-count"
|
|
3030
|
+
),
|
|
3031
|
+
method: "get"
|
|
3032
|
+
}),
|
|
3033
|
+
markRead: (messageId, params = {}) => request({
|
|
3034
|
+
path: buildOpenXiangdaAppPath(
|
|
3035
|
+
context,
|
|
3036
|
+
params.appType,
|
|
3037
|
+
`/notifications/inbox/${encodePathSegment(messageId)}/read`
|
|
3038
|
+
),
|
|
3039
|
+
method: "post"
|
|
3040
|
+
}),
|
|
3041
|
+
markAllRead: (params = {}) => request({
|
|
3042
|
+
path: buildOpenXiangdaAppPath(
|
|
3043
|
+
context,
|
|
3044
|
+
params.appType,
|
|
3045
|
+
"/notifications/inbox/read-all"
|
|
3046
|
+
),
|
|
3047
|
+
method: "post"
|
|
3009
3048
|
})
|
|
3010
3049
|
};
|
|
3011
3050
|
const sdk = {
|
|
@@ -34523,10 +34562,18 @@ var OpenXiangdaProvider = ({
|
|
|
34523
34562
|
const [accessToken, setAccessTokenState] = (0, import_react216.useState)(null);
|
|
34524
34563
|
const accessTokenRef = (0, import_react216.useRef)(null);
|
|
34525
34564
|
const setAccessToken = (0, import_react216.useCallback)(
|
|
34526
|
-
(nextAccessToken) => {
|
|
34565
|
+
(nextAccessToken, options = {}) => {
|
|
34566
|
+
if (!nextAccessToken && options.clearIfToken && accessTokenRef.current?.token !== options.clearIfToken) {
|
|
34567
|
+
return;
|
|
34568
|
+
}
|
|
34527
34569
|
const normalizedAccessToken = nextAccessToken || null;
|
|
34528
|
-
|
|
34529
|
-
|
|
34570
|
+
const nextState = normalizedAccessToken ? {
|
|
34571
|
+
token: normalizedAccessToken,
|
|
34572
|
+
scope: options.scope || "default",
|
|
34573
|
+
path: options.path || null
|
|
34574
|
+
} : null;
|
|
34575
|
+
accessTokenRef.current = nextState;
|
|
34576
|
+
setAccessTokenState(nextState);
|
|
34530
34577
|
},
|
|
34531
34578
|
[]
|
|
34532
34579
|
);
|
|
@@ -34552,7 +34599,13 @@ var OpenXiangdaProvider = ({
|
|
|
34552
34599
|
return;
|
|
34553
34600
|
}
|
|
34554
34601
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
34555
|
-
const requestFetch = options.accessToken !== void 0 ? createAuthorizedFetch(
|
|
34602
|
+
const requestFetch = options.accessToken !== void 0 ? createAuthorizedFetch(
|
|
34603
|
+
resolvedFetch,
|
|
34604
|
+
createAccessTokenState(
|
|
34605
|
+
options.accessToken || null,
|
|
34606
|
+
options.accessTokenOptions
|
|
34607
|
+
)
|
|
34608
|
+
) : createAuthorizedFetch(resolvedFetch, accessTokenRef.current);
|
|
34556
34609
|
try {
|
|
34557
34610
|
const response = await requestFetch(
|
|
34558
34611
|
buildServiceUrl2(
|
|
@@ -34962,9 +35015,11 @@ var buildServiceUrl2 = (servicePrefix, path) => {
|
|
|
34962
35015
|
var createAuthorizedFetch = (baseFetch, accessToken) => {
|
|
34963
35016
|
if (!accessToken) return baseFetch;
|
|
34964
35017
|
return ((input, init = {}) => {
|
|
35018
|
+
const token = resolveAccessTokenForCurrentRoute(accessToken);
|
|
35019
|
+
if (!token) return baseFetch(input, init);
|
|
34965
35020
|
const headers = new Headers(init.headers || {});
|
|
34966
35021
|
if (!headers.has("authorization")) {
|
|
34967
|
-
headers.set("authorization", `Bearer ${
|
|
35022
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
34968
35023
|
}
|
|
34969
35024
|
return baseFetch(input, {
|
|
34970
35025
|
...init,
|
|
@@ -34972,6 +35027,34 @@ var createAuthorizedFetch = (baseFetch, accessToken) => {
|
|
|
34972
35027
|
});
|
|
34973
35028
|
});
|
|
34974
35029
|
};
|
|
35030
|
+
var createAccessTokenState = (accessToken, options = {}) => accessToken ? {
|
|
35031
|
+
token: accessToken,
|
|
35032
|
+
scope: options.scope || "default",
|
|
35033
|
+
path: options.path || null
|
|
35034
|
+
} : null;
|
|
35035
|
+
var resolveAccessTokenForCurrentRoute = (accessToken) => {
|
|
35036
|
+
if (accessToken.scope !== "public") return accessToken.token;
|
|
35037
|
+
const scopedPath = normalizeRoutePath(accessToken.path);
|
|
35038
|
+
const currentPath = normalizeRoutePath(getCurrentPathname());
|
|
35039
|
+
if (!scopedPath) {
|
|
35040
|
+
return isPublicRoutePath(currentPath) ? accessToken.token : null;
|
|
35041
|
+
}
|
|
35042
|
+
if (currentPath === scopedPath || isPublicRoutePath(currentPath) && currentPath.startsWith(`${scopedPath}/`)) {
|
|
35043
|
+
return accessToken.token;
|
|
35044
|
+
}
|
|
35045
|
+
return null;
|
|
35046
|
+
};
|
|
35047
|
+
var normalizeRoutePath = (path) => {
|
|
35048
|
+
const text = String(path || "").trim();
|
|
35049
|
+
if (!text) return "";
|
|
35050
|
+
try {
|
|
35051
|
+
const base = typeof window !== "undefined" ? window.location.origin : "http://localhost";
|
|
35052
|
+
return new URL(text, base).pathname.replace(/\/+$/, "") || "/";
|
|
35053
|
+
} catch {
|
|
35054
|
+
return text.split(/[?#]/, 1)[0].replace(/\/+$/, "") || "/";
|
|
35055
|
+
}
|
|
35056
|
+
};
|
|
35057
|
+
var isPublicRoutePath = (path) => /\/public(?:\/|$)/.test(path);
|
|
34975
35058
|
var readJsonPayload = async (response) => {
|
|
34976
35059
|
try {
|
|
34977
35060
|
return await response.json();
|
|
@@ -35072,6 +35155,7 @@ var attachCallback = (loginUrl, callback) => {
|
|
|
35072
35155
|
}
|
|
35073
35156
|
};
|
|
35074
35157
|
var getCurrentHref4 = () => typeof window === "undefined" ? "" : window.location.href;
|
|
35158
|
+
var getCurrentPathname = () => typeof window === "undefined" ? "" : window.location.pathname;
|
|
35075
35159
|
var getCurrentHostname2 = () => typeof window === "undefined" ? "" : window.location.hostname;
|
|
35076
35160
|
var getRuntimeEnv = (key) => {
|
|
35077
35161
|
const env = typeof process !== "undefined" ? process.env : void 0;
|
|
@@ -35169,7 +35253,7 @@ var createPublicAccessClient = ({
|
|
|
35169
35253
|
const request = async (input = {}) => {
|
|
35170
35254
|
const body = {
|
|
35171
35255
|
...input,
|
|
35172
|
-
path: input.path ||
|
|
35256
|
+
path: input.path || getCurrentPathname2(),
|
|
35173
35257
|
domain: input.domain || getCurrentDomain(),
|
|
35174
35258
|
userAgent: input.userAgent || getCurrentUserAgent(),
|
|
35175
35259
|
guestIdentifier: input.guestIdentifier || getOrCreatePublicGuestIdentifier(normalizedAppType)
|
|
@@ -35237,7 +35321,7 @@ var isSuccessCode6 = (code) => {
|
|
|
35237
35321
|
const normalized = Number(code);
|
|
35238
35322
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
35239
35323
|
};
|
|
35240
|
-
var
|
|
35324
|
+
var getCurrentPathname2 = () => typeof window === "undefined" ? void 0 : window.location.pathname;
|
|
35241
35325
|
var getCurrentDomain = () => typeof window === "undefined" ? void 0 : window.location.host;
|
|
35242
35326
|
var getCurrentUserAgent = () => typeof navigator === "undefined" ? void 0 : navigator.userAgent;
|
|
35243
35327
|
var getOrCreatePublicGuestIdentifier = (appType) => {
|
|
@@ -35280,6 +35364,8 @@ var usePublicAccess = (options = {}) => {
|
|
|
35280
35364
|
const [session, setSession] = (0, import_react217.useState)(null);
|
|
35281
35365
|
const [error, setError] = (0, import_react217.useState)(null);
|
|
35282
35366
|
const [loading, setLoading] = (0, import_react217.useState)(Boolean(autoStart));
|
|
35367
|
+
const activeSessionRef = (0, import_react217.useRef)(null);
|
|
35368
|
+
const mountedRef = (0, import_react217.useRef)(true);
|
|
35283
35369
|
const sessionInputKey = JSON.stringify(sessionInput);
|
|
35284
35370
|
const stableSessionInput = (0, import_react217.useMemo)(() => sessionInput, [sessionInputKey]);
|
|
35285
35371
|
const client = (0, import_react217.useMemo)(
|
|
@@ -35295,15 +35381,31 @@ var usePublicAccess = (options = {}) => {
|
|
|
35295
35381
|
setLoading(true);
|
|
35296
35382
|
setError(null);
|
|
35297
35383
|
try {
|
|
35384
|
+
const resolvedPath = input.path || stableSessionInput.path || readPathFromLocation();
|
|
35298
35385
|
const data = await client.startSession({
|
|
35299
35386
|
...stableSessionInput,
|
|
35300
35387
|
...input,
|
|
35301
35388
|
ticket: input.ticket || stableSessionInput.ticket || readTicketFromLocation(),
|
|
35302
|
-
path:
|
|
35389
|
+
path: resolvedPath
|
|
35303
35390
|
});
|
|
35391
|
+
if (!mountedRef.current) return data;
|
|
35392
|
+
activeSessionRef.current = {
|
|
35393
|
+
accessToken: data.accessToken,
|
|
35394
|
+
path: resolvedPath
|
|
35395
|
+
};
|
|
35304
35396
|
setSession(data);
|
|
35305
|
-
setAccessToken(data.accessToken
|
|
35306
|
-
|
|
35397
|
+
setAccessToken(data.accessToken, {
|
|
35398
|
+
scope: "public",
|
|
35399
|
+
path: resolvedPath
|
|
35400
|
+
});
|
|
35401
|
+
await reloadRuntime({
|
|
35402
|
+
accessToken: data.accessToken,
|
|
35403
|
+
accessTokenOptions: {
|
|
35404
|
+
scope: "public",
|
|
35405
|
+
path: resolvedPath
|
|
35406
|
+
}
|
|
35407
|
+
});
|
|
35408
|
+
if (!mountedRef.current) return data;
|
|
35307
35409
|
setLoading(false);
|
|
35308
35410
|
return data;
|
|
35309
35411
|
} catch (caught) {
|
|
@@ -35311,8 +35413,10 @@ var usePublicAccess = (options = {}) => {
|
|
|
35311
35413
|
caught instanceof Error ? caught.message : "\u516C\u5F00\u8BBF\u95EE\u4F1A\u8BDD\u521B\u5EFA\u5931\u8D25",
|
|
35312
35414
|
{ payload: caught }
|
|
35313
35415
|
);
|
|
35314
|
-
|
|
35315
|
-
|
|
35416
|
+
if (mountedRef.current) {
|
|
35417
|
+
setError(nextError);
|
|
35418
|
+
setLoading(false);
|
|
35419
|
+
}
|
|
35316
35420
|
throw nextError;
|
|
35317
35421
|
}
|
|
35318
35422
|
},
|
|
@@ -35322,6 +35426,20 @@ var usePublicAccess = (options = {}) => {
|
|
|
35322
35426
|
if (!autoStart) return;
|
|
35323
35427
|
void startSession().catch(() => void 0);
|
|
35324
35428
|
}, [autoStart, startSession]);
|
|
35429
|
+
(0, import_react217.useEffect)(
|
|
35430
|
+
() => {
|
|
35431
|
+
mountedRef.current = true;
|
|
35432
|
+
return () => {
|
|
35433
|
+
mountedRef.current = false;
|
|
35434
|
+
const activeSession = activeSessionRef.current;
|
|
35435
|
+
if (!activeSession) return;
|
|
35436
|
+
activeSessionRef.current = null;
|
|
35437
|
+
setAccessToken(null, { clearIfToken: activeSession.accessToken });
|
|
35438
|
+
void reloadRuntime({ accessToken: null });
|
|
35439
|
+
};
|
|
35440
|
+
},
|
|
35441
|
+
[reloadRuntime, setAccessToken]
|
|
35442
|
+
);
|
|
35325
35443
|
return {
|
|
35326
35444
|
loading,
|
|
35327
35445
|
error,
|