openxiangda 1.0.88 → 1.0.90

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.
@@ -34,7 +34,7 @@ var require_classnames = __commonJS({
34
34
  "use strict";
35
35
  (function() {
36
36
  "use strict";
37
- var hasOwn2 = {}.hasOwnProperty;
37
+ var hasOwn3 = {}.hasOwnProperty;
38
38
  function classNames80() {
39
39
  var classes = "";
40
40
  for (var i2 = 0; i2 < arguments.length; i2++) {
@@ -60,7 +60,7 @@ var require_classnames = __commonJS({
60
60
  }
61
61
  var classes = "";
62
62
  for (var key in arg) {
63
- if (hasOwn2.call(arg, key) && arg[key]) {
63
+ if (hasOwn3.call(arg, key) && arg[key]) {
64
64
  classes = appendClass(classes, key);
65
65
  }
66
66
  }
@@ -1007,18 +1007,39 @@ var normalizeDynamicOrder = (value) => {
1007
1007
  }
1008
1008
  return `${value.id}:${value.isAsc === "n" ? "-" : "+"}`;
1009
1009
  };
1010
+ var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
1011
+ var normalizeEnvelopeCode = (value) => {
1012
+ if (value === void 0 || value === null || value === "") {
1013
+ return 200;
1014
+ }
1015
+ const normalized = Number(value);
1016
+ return Number.isFinite(normalized) ? normalized : String(value);
1017
+ };
1018
+ var isSuccessCode = (value) => {
1019
+ if (value === void 0 || value === null || value === "") {
1020
+ return true;
1021
+ }
1022
+ const normalized = Number(value);
1023
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
1024
+ };
1025
+ var getEnvelopeCode = (rawResponse) => {
1026
+ if (isRecord(rawResponse) && hasOwn(rawResponse, "code")) {
1027
+ return rawResponse.code;
1028
+ }
1029
+ const nestedData = rawResponse?.data;
1030
+ if (isRecord(nestedData) && hasOwn(nestedData, "code")) {
1031
+ return nestedData.code;
1032
+ }
1033
+ return void 0;
1034
+ };
1010
1035
  var normalizeJsonResponse = (rawResponse) => {
1011
- const topLevelCode = Number(rawResponse?.code);
1012
- const nestedCode = Number(
1013
- rawResponse?.data?.code
1014
- );
1015
- const code = Number.isFinite(topLevelCode) ? topLevelCode : Number.isFinite(nestedCode) ? nestedCode : 200;
1036
+ const code = normalizeEnvelopeCode(getEnvelopeCode(rawResponse));
1016
1037
  const topLevelResult = isRecord(rawResponse) && "result" in rawResponse ? rawResponse.result : void 0;
1017
1038
  const nestedResult = isRecord(rawResponse?.data) && "result" in (rawResponse.data || {}) ? rawResponse.data?.result : void 0;
1018
1039
  const topLevelData = isRecord(rawResponse) && "data" in rawResponse ? rawResponse.data : void 0;
1019
1040
  const result = topLevelResult !== void 0 ? topLevelResult : nestedResult !== void 0 ? nestedResult : topLevelData !== void 0 ? topLevelData : isRecord(rawResponse) ? rawResponse : null;
1020
1041
  const nestedSuccess = typeof rawResponse?.data?.success === "boolean" ? rawResponse.data?.success : void 0;
1021
- const success = typeof rawResponse?.success === "boolean" ? Boolean(rawResponse.success) : typeof nestedSuccess === "boolean" ? Boolean(nestedSuccess) : code >= 200 && code < 300;
1042
+ const success = rawResponse?.success === false || nestedSuccess === false ? false : isSuccessCode(code);
1022
1043
  return {
1023
1044
  code,
1024
1045
  success,
@@ -1063,6 +1084,9 @@ var normalizeBinaryResponse = (rawResponse) => {
1063
1084
  };
1064
1085
  };
1065
1086
  var toSdkError = (input, payload) => {
1087
+ if (input instanceof Error && input.response) {
1088
+ return input;
1089
+ }
1066
1090
  const normalizedResponse = isRecord(input) ? normalizeJsonResponse(input) : void 0;
1067
1091
  const nextError = input instanceof Error ? input : new Error(
1068
1092
  normalizedResponse?.message || `\u8BF7\u6C42\u5931\u8D25: ${String(payload.method).toUpperCase()} ${payload.path}`
@@ -2202,7 +2226,8 @@ var createAuthClient = ({
2202
2226
  });
2203
2227
  const payload = await readPayload(response);
2204
2228
  const code = getRecordValue(payload, "code");
2205
- if (!response.ok || typeof code === "number" && code >= 400) {
2229
+ const success = getRecordValue(payload, "success");
2230
+ if (!response.ok || success === false || !isSuccessCode2(code)) {
2206
2231
  throw new AuthClientError(
2207
2232
  String(getRecordValue(payload, "message") || `Auth request failed: ${response.status}`),
2208
2233
  { status: response.status, code, payload }
@@ -2255,6 +2280,11 @@ var getRecordValue = (value, key) => {
2255
2280
  if (!value || typeof value !== "object") return void 0;
2256
2281
  return value[key];
2257
2282
  };
2283
+ var isSuccessCode2 = (code) => {
2284
+ if (code === void 0 || code === null || code === "") return true;
2285
+ const normalized = Number(code);
2286
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
2287
+ };
2258
2288
  var resolveLoginUrl = (appType, {
2259
2289
  callbackUrl = getCurrentHref2(),
2260
2290
  callbackParamName = "callback",
@@ -2326,7 +2356,8 @@ var createPublicAccessClient = ({
2326
2356
  );
2327
2357
  const payload = await readPayload2(response);
2328
2358
  const code = getRecordValue2(payload, "code");
2329
- if (!response.ok || typeof code === "number" && code >= 400) {
2359
+ const success = getRecordValue2(payload, "success");
2360
+ if (!response.ok || success === false || !isSuccessCode3(code)) {
2330
2361
  throw new PublicAccessClientError(
2331
2362
  String(
2332
2363
  getRecordValue2(payload, "message") || `Public access session failed: ${response.status}`
@@ -2364,6 +2395,11 @@ var getRecordValue2 = (value, key) => {
2364
2395
  if (!value || typeof value !== "object") return void 0;
2365
2396
  return value[key];
2366
2397
  };
2398
+ var isSuccessCode3 = (code) => {
2399
+ if (code === void 0 || code === null || code === "") return true;
2400
+ const normalized = Number(code);
2401
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
2402
+ };
2367
2403
  var getCurrentPathname = () => typeof window === "undefined" ? void 0 : window.location.pathname;
2368
2404
  var getCurrentDomain = () => typeof window === "undefined" ? void 0 : window.location.host;
2369
2405
  var getCurrentUserAgent = () => typeof navigator === "undefined" ? void 0 : navigator.userAgent;
@@ -3472,6 +3508,384 @@ import {
3472
3508
  useState as useState4
3473
3509
  } from "react";
3474
3510
 
3511
+ // packages/sdk/src/runtime/host/browserHost.ts
3512
+ var NAMESPACE_ROOT_CLASS2 = "sy-app-workspace";
3513
+ var defaultModuleLoader = (url2) => import(
3514
+ /* @vite-ignore */
3515
+ url2
3516
+ );
3517
+ var trimTrailingSlash = (value) => value.replace(/\/+$/, "");
3518
+ var getDefaultServicePrefix = () => typeof window !== "undefined" ? trimTrailingSlash(window.__OPENXIANGDA_SERVICE_PREFIX__ || "/service") : "/service";
3519
+ var joinServicePath = (servicePrefix, path) => {
3520
+ if (/^https?:\/\//i.test(path)) return path;
3521
+ const normalizedPrefix = trimTrailingSlash(servicePrefix || "/service");
3522
+ if (path.startsWith(normalizedPrefix)) return path;
3523
+ return `${normalizedPrefix}${path.startsWith("/") ? path : `/${path}`}`;
3524
+ };
3525
+ var appendQuery = (url2, query) => {
3526
+ if (!query) return url2;
3527
+ return `${url2}${url2.includes("?") ? "&" : "?"}${query}`;
3528
+ };
3529
+ var normalizeMethod2 = (method4) => {
3530
+ const value = String(method4 || "get").toUpperCase();
3531
+ return ["GET", "POST", "PUT", "DELETE", "PATCH"].includes(value) ? value : "GET";
3532
+ };
3533
+ var normalizeCssIsolation2 = (value) => {
3534
+ if (value === "namespace" || value === "shadow" || value === "none") {
3535
+ return value;
3536
+ }
3537
+ return "none";
3538
+ };
3539
+ var normalizeEnvelopeCode2 = (value, fallback) => {
3540
+ if (value === void 0 || value === null || value === "") return fallback;
3541
+ const normalized = Number(value);
3542
+ return Number.isFinite(normalized) ? normalized : String(value);
3543
+ };
3544
+ var isSuccessCode4 = (value) => {
3545
+ if (value === void 0 || value === null || value === "") return true;
3546
+ const normalized = Number(value);
3547
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
3548
+ };
3549
+ var parseJsonResponse = async (response) => {
3550
+ const payload = await response.json().catch(() => null);
3551
+ if (!response.ok) {
3552
+ const message7 = payload && typeof payload === "object" ? payload.message || payload.error || response.statusText : response.statusText;
3553
+ throw new Error(message7 || "\u8BF7\u6C42\u5931\u8D25");
3554
+ }
3555
+ if (payload && typeof payload === "object" && "code" in payload) {
3556
+ const code = normalizeEnvelopeCode2(payload.code, response.status);
3557
+ return {
3558
+ code,
3559
+ success: payload.success !== false && isSuccessCode4(code),
3560
+ message: payload.message,
3561
+ result: payload.result ?? payload.data ?? null,
3562
+ data: payload.data,
3563
+ raw: payload
3564
+ };
3565
+ }
3566
+ return {
3567
+ code: response.status,
3568
+ success: response.ok,
3569
+ message: response.statusText,
3570
+ result: payload,
3571
+ data: payload,
3572
+ raw: payload
3573
+ };
3574
+ };
3575
+ var createBrowserPageBridge = (options = {}) => {
3576
+ const servicePrefix = options.servicePrefix || getDefaultServicePrefix();
3577
+ const fetchImpl = createBoundFetch(options.fetchImpl);
3578
+ const request = async (payload) => {
3579
+ if (!payload?.path) {
3580
+ throw new Error("transport.request \u9700\u8981 path");
3581
+ }
3582
+ const url2 = appendQuery(joinServicePath(servicePrefix, payload.path), payload.query);
3583
+ const headers = new Headers(payload.headers);
3584
+ let body;
3585
+ if (payload.body !== void 0) {
3586
+ if (payload.body instanceof FormData) {
3587
+ body = payload.body;
3588
+ } else {
3589
+ headers.set("Content-Type", headers.get("Content-Type") || "application/json");
3590
+ body = JSON.stringify(payload.body);
3591
+ }
3592
+ }
3593
+ const response = await fetchImpl(url2, {
3594
+ method: normalizeMethod2(payload.method),
3595
+ headers,
3596
+ body,
3597
+ credentials: "include"
3598
+ });
3599
+ return parseJsonResponse(response);
3600
+ };
3601
+ const download = async (payload) => {
3602
+ if (!payload?.path) {
3603
+ throw new Error("transport.download \u9700\u8981 path");
3604
+ }
3605
+ const url2 = appendQuery(joinServicePath(servicePrefix, payload.path), payload.query);
3606
+ const headers = new Headers(payload.headers);
3607
+ let body;
3608
+ if (payload.body !== void 0) {
3609
+ if (payload.body instanceof FormData) {
3610
+ body = payload.body;
3611
+ } else {
3612
+ headers.set("Content-Type", headers.get("Content-Type") || "application/json");
3613
+ body = JSON.stringify(payload.body);
3614
+ }
3615
+ }
3616
+ const response = await fetchImpl(url2, {
3617
+ method: normalizeMethod2(payload.method),
3618
+ headers,
3619
+ body,
3620
+ credentials: "include"
3621
+ });
3622
+ if (!response.ok) {
3623
+ throw new Error(response.statusText || "\u4E0B\u8F7D\u5931\u8D25");
3624
+ }
3625
+ return {
3626
+ blob: await response.blob(),
3627
+ contentType: response.headers.get("content-type") || void 0,
3628
+ fileName: response.headers.get("content-disposition") || void 0,
3629
+ headers: Object.fromEntries(response.headers.entries())
3630
+ };
3631
+ };
3632
+ return {
3633
+ invoke: async (method4, payload) => {
3634
+ if (method4 === "transport.request") return await request(payload);
3635
+ if (method4 === "transport.download") return await download(payload);
3636
+ throw new Error(`\u4E0D\u652F\u6301\u7684 bridge \u65B9\u6CD5: ${method4}`);
3637
+ }
3638
+ };
3639
+ };
3640
+ var createBrowserPageContext = (bootstrap, options = {}) => {
3641
+ const route = {
3642
+ pathname: options.route?.pathname || (typeof window !== "undefined" ? window.location.pathname : ""),
3643
+ fullPath: options.route?.fullPath || (typeof window !== "undefined" ? `${window.location.pathname}${window.location.search}${window.location.hash}` : ""),
3644
+ params: options.route?.params || {},
3645
+ query: options.route?.query || {},
3646
+ hash: options.route?.hash || (typeof window !== "undefined" ? window.location.hash : "")
3647
+ };
3648
+ return {
3649
+ protocolVersion: bootstrap.asset?.protocolVersion || "1.0",
3650
+ app: bootstrap.app,
3651
+ page: {
3652
+ ...bootstrap.page,
3653
+ version: bootstrap.asset?.version || bootstrap.page.version,
3654
+ buildId: bootstrap.asset?.buildId || bootstrap.page.buildId
3655
+ },
3656
+ user: bootstrap.user,
3657
+ route,
3658
+ env: bootstrap.env || {},
3659
+ permissions: {
3660
+ canView: bootstrap.permissions?.canView !== false,
3661
+ hasFullAccess: bootstrap.permissions?.hasFullAccess === true,
3662
+ ...bootstrap.permissions || {}
3663
+ },
3664
+ capabilities: Array.from(
3665
+ /* @__PURE__ */ new Set([
3666
+ "navigation",
3667
+ "ui.message",
3668
+ "ui.modal",
3669
+ "transport.request",
3670
+ "transport.download",
3671
+ ...bootstrap.sdk?.supportedBridgeMethods || []
3672
+ ])
3673
+ ),
3674
+ ui: {
3675
+ message: {
3676
+ success: (text) => options.message?.success?.(text),
3677
+ error: (text) => options.message?.error?.(text),
3678
+ warning: (text) => options.message?.warning?.(text),
3679
+ info: (text) => options.message?.info?.(text),
3680
+ loading: (text) => options.message?.loading?.(text) || (() => void 0)
3681
+ },
3682
+ modal: {
3683
+ confirm: (input) => options.modal?.confirm?.(input) || Promise.resolve(false)
3684
+ }
3685
+ },
3686
+ navigation: {
3687
+ pushPage: (pageKey, query) => options.navigation?.pushPage?.(pageKey, query),
3688
+ replacePage: (pageKey, query) => options.navigation?.replacePage?.(pageKey, query),
3689
+ pushRoute: (routeValue, query) => options.navigation?.pushRoute?.(routeValue, query),
3690
+ replaceRoute: (routeValue, query) => options.navigation?.replaceRoute?.(routeValue, query),
3691
+ updateQuery: (query) => options.navigation?.updateQuery?.(query),
3692
+ setHash: (hash) => options.navigation?.setHash?.(hash),
3693
+ back: () => options.navigation?.back?.()
3694
+ },
3695
+ bridge: createBrowserPageBridge(options),
3696
+ sdk: {
3697
+ ...bootstrap.sdk,
3698
+ supportedBridgeMethods: ["transport.request", "transport.download"]
3699
+ }
3700
+ };
3701
+ };
3702
+ var resolveRuntimeAssets = async (bootstrap, fetchImpl = fetch) => {
3703
+ const boundFetch = createBoundFetch(fetchImpl);
3704
+ const fallback = {
3705
+ entryUrl: bootstrap.runtimeAssets?.entryUrl || bootstrap.asset?.entryUrl || "",
3706
+ cssUrls: bootstrap.runtimeAssets?.cssUrls || bootstrap.asset?.cssAssets || [],
3707
+ jsUrls: bootstrap.runtimeAssets?.jsUrls || bootstrap.asset?.jsAssets || [],
3708
+ cssIsolation: normalizeCssIsolation2(
3709
+ bootstrap.runtimeAssets?.cssIsolation || bootstrap.page.capabilities?.cssIsolation
3710
+ )
3711
+ };
3712
+ if (bootstrap.runtimeAssets?.entryUrl || !bootstrap.asset?.manifestUrl) {
3713
+ return fallback;
3714
+ }
3715
+ try {
3716
+ const response = await boundFetch(bootstrap.asset.manifestUrl, {
3717
+ credentials: "omit"
3718
+ });
3719
+ if (!response.ok) return fallback;
3720
+ const manifest = await response.json();
3721
+ const base = bootstrap.asset.manifestUrl;
3722
+ const resolveUrl = (value) => new URL(value, base).toString();
3723
+ return {
3724
+ entryUrl: manifest?.entry?.url ? resolveUrl(manifest.entry.url) : fallback.entryUrl,
3725
+ cssUrls: Array.isArray(manifest?.assets?.css) ? manifest.assets.css.map(resolveUrl) : fallback.cssUrls,
3726
+ jsUrls: Array.isArray(manifest?.assets?.js) ? manifest.assets.js.map(resolveUrl) : fallback.jsUrls,
3727
+ cssIsolation: normalizeCssIsolation2(
3728
+ manifest?.style?.isolation || fallback.cssIsolation
3729
+ )
3730
+ };
3731
+ } catch {
3732
+ return fallback;
3733
+ }
3734
+ };
3735
+ var fetchBrowserRuntimeBootstrap = async ({
3736
+ appType,
3737
+ bootstrapPath,
3738
+ fetchImpl = fetch,
3739
+ pageKey,
3740
+ servicePrefix
3741
+ }) => {
3742
+ if (!appType) {
3743
+ throw new Error("appType \u7F3A\u5931");
3744
+ }
3745
+ if (!pageKey) {
3746
+ throw new Error("pageKey \u7F3A\u5931");
3747
+ }
3748
+ const path = bootstrapPath || `/openxiangda-api/v1/apps/${encodeURIComponent(
3749
+ appType
3750
+ )}/pages/${encodeURIComponent(pageKey)}/bootstrap`;
3751
+ const boundFetch = createBoundFetch(fetchImpl);
3752
+ const response = await boundFetch(
3753
+ joinServicePath(servicePrefix || getDefaultServicePrefix(), path),
3754
+ {
3755
+ method: "GET",
3756
+ credentials: "include"
3757
+ }
3758
+ );
3759
+ const payload = await response.json().catch(() => null);
3760
+ if (!response.ok) {
3761
+ throw new Error(payload?.message || response.statusText || "\u83B7\u53D6\u9875\u9762\u8FD0\u884C\u65F6\u5931\u8D25");
3762
+ }
3763
+ if (payload && typeof payload === "object" && ("code" in payload || "success" in payload)) {
3764
+ if (payload.success === false || payload.code && Number(payload.code) !== 200) {
3765
+ throw new Error(payload.message || "\u83B7\u53D6\u9875\u9762\u8FD0\u884C\u65F6\u5931\u8D25");
3766
+ }
3767
+ return payload.data || {};
3768
+ }
3769
+ return payload || {};
3770
+ };
3771
+ var resolveBrowserRuntimeRoute = async ({
3772
+ appType,
3773
+ fetchImpl = fetch,
3774
+ path,
3775
+ resolvePath,
3776
+ search,
3777
+ servicePrefix
3778
+ }) => {
3779
+ if (!appType) {
3780
+ throw new Error("appType \u7F3A\u5931");
3781
+ }
3782
+ const currentPath = path || (typeof window !== "undefined" ? window.location.pathname : "/");
3783
+ const currentSearch = search !== void 0 ? search : typeof window !== "undefined" ? window.location.search : "";
3784
+ const endpoint = resolvePath || `/openxiangda-api/v1/apps/${encodeURIComponent(
3785
+ appType
3786
+ )}/runtime/routes/resolve`;
3787
+ const boundFetch = createBoundFetch(fetchImpl);
3788
+ const response = await boundFetch(
3789
+ joinServicePath(servicePrefix || getDefaultServicePrefix(), endpoint),
3790
+ {
3791
+ method: "POST",
3792
+ credentials: "include",
3793
+ headers: {
3794
+ "Content-Type": "application/json"
3795
+ },
3796
+ body: JSON.stringify({
3797
+ path: currentPath,
3798
+ search: currentSearch
3799
+ })
3800
+ }
3801
+ );
3802
+ const parsed = await parseJsonResponse(response);
3803
+ if (!parsed.success || !parsed.result) {
3804
+ throw new Error(parsed.message || "\u89E3\u6790\u8FD0\u884C\u65F6\u8DEF\u7531\u5931\u8D25");
3805
+ }
3806
+ return parsed.result;
3807
+ };
3808
+ var loadRuntimeScriptModules = async (jsUrls = [], moduleLoader = defaultModuleLoader) => {
3809
+ const urls = Array.from(
3810
+ new Set(jsUrls.map((url2) => String(url2 || "").trim()).filter(Boolean))
3811
+ );
3812
+ for (const url2 of urls) {
3813
+ await moduleLoader(url2);
3814
+ }
3815
+ };
3816
+ var loadCustomPageModule = async (entryUrl, moduleLoader = defaultModuleLoader, jsUrls = []) => {
3817
+ if (!entryUrl) {
3818
+ throw new Error("\u4EE3\u7801\u9875\u9762\u7F3A\u5C11 entryUrl");
3819
+ }
3820
+ await loadRuntimeScriptModules(
3821
+ jsUrls.filter((url2) => url2 && url2 !== entryUrl),
3822
+ moduleLoader
3823
+ );
3824
+ const loaded = await moduleLoader(entryUrl);
3825
+ return loaded?.default && (loaded.default.mount || loaded.default.unmount) ? { ...loaded.default, ...loaded } : loaded || {};
3826
+ };
3827
+ var mountCustomPageRuntime = async ({
3828
+ assets,
3829
+ container,
3830
+ context,
3831
+ module
3832
+ }) => {
3833
+ const cssIsolation = normalizeCssIsolation2(assets?.cssIsolation);
3834
+ const mountedLinks = [];
3835
+ container.innerHTML = "";
3836
+ container.classList.toggle(NAMESPACE_ROOT_CLASS2, cssIsolation === "namespace");
3837
+ (assets?.cssUrls || []).forEach((href) => {
3838
+ const link = document.createElement("link");
3839
+ link.rel = "stylesheet";
3840
+ link.href = href;
3841
+ link.setAttribute("data-openxiangda-runtime-style", href);
3842
+ document.head.appendChild(link);
3843
+ mountedLinks.push(link);
3844
+ });
3845
+ await module.mount?.(container, context);
3846
+ return async () => {
3847
+ await module.unmount?.(container, context);
3848
+ mountedLinks.forEach((link) => link.remove());
3849
+ container.classList.remove(NAMESPACE_ROOT_CLASS2);
3850
+ container.innerHTML = "";
3851
+ };
3852
+ };
3853
+ var mountBrowserPageRuntime = async (options) => {
3854
+ const bootstrap = await fetchBrowserRuntimeBootstrap({
3855
+ appType: options.appType,
3856
+ pageKey: options.pageKey,
3857
+ bootstrapPath: options.bootstrapPath,
3858
+ fetchImpl: options.fetchImpl,
3859
+ servicePrefix: options.servicePrefix
3860
+ });
3861
+ if (bootstrap.permissions?.canView === false) {
3862
+ throw new Error(String(bootstrap.permissions.message || "\u60A8\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u8BE5\u9875\u9762"));
3863
+ }
3864
+ const assets = await resolveRuntimeAssets(bootstrap, options.fetchImpl || fetch);
3865
+ if (!assets.entryUrl) {
3866
+ throw new Error("\u4EE3\u7801\u9875\u9762\u7F3A\u5C11 entryUrl");
3867
+ }
3868
+ const context = createBrowserPageContext(bootstrap, options);
3869
+ const module = await loadCustomPageModule(
3870
+ assets.entryUrl,
3871
+ options.moduleLoader,
3872
+ assets.jsUrls
3873
+ );
3874
+ const cleanup2 = await mountCustomPageRuntime({
3875
+ assets,
3876
+ container: options.container,
3877
+ context,
3878
+ module
3879
+ });
3880
+ return {
3881
+ bootstrap,
3882
+ assets,
3883
+ context,
3884
+ module,
3885
+ cleanup: cleanup2
3886
+ };
3887
+ };
3888
+
3475
3889
  // packages/sdk/src/runtime/react/auth.tsx
3476
3890
  import {
3477
3891
  useCallback as useCallback3,
@@ -4052,7 +4466,7 @@ var OpenXiangdaProvider = ({
4052
4466
  }
4053
4467
  );
4054
4468
  const payload = await readJsonPayload(response);
4055
- if (!response.ok || payload?.code >= 400) {
4469
+ if (isRuntimeEnvelopeFailure(response, payload)) {
4056
4470
  throw createRuntimeHttpError(
4057
4471
  response,
4058
4472
  payload,
@@ -4096,6 +4510,96 @@ var useOpenXiangda = () => {
4096
4510
  return context;
4097
4511
  };
4098
4512
  var useRuntimeBootstrap = () => useOpenXiangda();
4513
+ var OpenXiangdaPageProvider = ({
4514
+ children,
4515
+ page,
4516
+ route,
4517
+ env,
4518
+ message: message7,
4519
+ modal,
4520
+ navigation
4521
+ }) => {
4522
+ const runtime = useOpenXiangda();
4523
+ const context = useMemo5(() => {
4524
+ const bootstrap = runtime.data;
4525
+ const app = toRuntimeRecord(bootstrap?.app);
4526
+ const user = toRuntimeRecord(bootstrap?.user);
4527
+ const permissions = bootstrap?.permissions;
4528
+ const tenantId = toStringValue(getRecordValue3(app, "tenantId")) || toStringValue(getRecordValue3(user, "tenantId")) || toStringValue(getRecordValue3(app, "tenantCode")) || "";
4529
+ const appType = runtime.appType || bootstrap?.appType || toStringValue(getRecordValue3(app, "appType"));
4530
+ const routeInfo = buildBrowserRouteInfo(route);
4531
+ return createBrowserPageContext(
4532
+ {
4533
+ app: {
4534
+ ...app,
4535
+ appType,
4536
+ tenantId
4537
+ },
4538
+ page: {
4539
+ id: routeInfo.pathname || "react-spa",
4540
+ code: routeInfo.pathname || "react-spa",
4541
+ name: "OpenXiangda React SPA",
4542
+ type: "react-spa",
4543
+ rendererType: "react-spa",
4544
+ routeKey: routeInfo.pathname || "react-spa",
4545
+ status: "ACTIVE",
4546
+ props: {},
4547
+ route: {},
4548
+ dataSources: [],
4549
+ capabilities: {},
4550
+ buildId: toStringValue(
4551
+ getRecordValue3(bootstrap?.runtime, "activeBuildId")
4552
+ ),
4553
+ ...page
4554
+ },
4555
+ user: {
4556
+ ...user,
4557
+ id: toStringValue(getRecordValue3(user, "id")) || (user.isGuest ? "guest" : "current"),
4558
+ username: toStringValue(getRecordValue3(user, "username")) || toStringValue(getRecordValue3(user, "name")) || (user.isGuest ? "guest" : "current"),
4559
+ tenantId,
4560
+ isGuest: user.isGuest === true || user.userType === "guest" || Boolean(getRecordValue3(user, "publicAccess")),
4561
+ userType: user.userType === "guest" || user.isGuest === true ? "guest" : "normal"
4562
+ },
4563
+ env: {
4564
+ appType,
4565
+ servicePrefix: runtime.servicePrefix,
4566
+ runtimeMode: bootstrap?.runtime?.mode || "react-spa",
4567
+ ...env || {}
4568
+ },
4569
+ permissions: {
4570
+ canView: runtime.error?.type !== "forbidden",
4571
+ hasFullAccess: permissions?.hasFullAccess === true,
4572
+ ...permissions || {}
4573
+ },
4574
+ sdk: {
4575
+ packageName: "openxiangda",
4576
+ supportedBridgeMethods: ["transport.request", "transport.download"]
4577
+ }
4578
+ },
4579
+ {
4580
+ servicePrefix: runtime.servicePrefix,
4581
+ fetchImpl: runtime.fetchImpl,
4582
+ route: routeInfo,
4583
+ message: message7,
4584
+ modal,
4585
+ navigation
4586
+ }
4587
+ );
4588
+ }, [
4589
+ env,
4590
+ message7,
4591
+ modal,
4592
+ navigation,
4593
+ page,
4594
+ route,
4595
+ runtime.appType,
4596
+ runtime.data,
4597
+ runtime.error?.type,
4598
+ runtime.fetchImpl,
4599
+ runtime.servicePrefix
4600
+ ]);
4601
+ return /* @__PURE__ */ jsx4(PageProvider, { context, children });
4602
+ };
4099
4603
  var useAppMenus = () => {
4100
4604
  const runtime = useOpenXiangda();
4101
4605
  return {
@@ -4187,7 +4691,7 @@ var useCanAccessRoute = (input) => {
4187
4691
  payload
4188
4692
  };
4189
4693
  if (!disposed) {
4190
- const shouldTreatAsError = !response.ok || typeof code === "number" && code >= 500;
4694
+ const shouldTreatAsError = !response.ok || isServerErrorCode(code);
4191
4695
  setState({
4192
4696
  data,
4193
4697
  loading: false,
@@ -4319,7 +4823,7 @@ var useRuntimeAuth = () => {
4319
4823
  }
4320
4824
  );
4321
4825
  const payload = await readJsonPayload(response);
4322
- if (!response.ok || payload?.code >= 400) {
4826
+ if (isRuntimeEnvelopeFailure(response, payload)) {
4323
4827
  throw createRuntimeHttpError(
4324
4828
  response,
4325
4829
  payload,
@@ -4409,6 +4913,15 @@ var classifyRuntimeError = (status, code) => {
4409
4913
  const normalizedCode = typeof code === "string" ? Number(code) : code;
4410
4914
  if (status === 401 || normalizedCode === 401) return "unauthenticated";
4411
4915
  if (status === 403 || normalizedCode === 403) return "forbidden";
4916
+ if (typeof code === "string") {
4917
+ const normalizedText = code.toUpperCase();
4918
+ if (normalizedText.includes("DENIED") || normalizedText.includes("FORBIDDEN")) {
4919
+ return "forbidden";
4920
+ }
4921
+ if (normalizedText.includes("UNAUTH") || normalizedText.includes("LOGIN")) {
4922
+ return "unauthenticated";
4923
+ }
4924
+ }
4412
4925
  if (!status && !normalizedCode) return "network";
4413
4926
  return "unknown";
4414
4927
  };
@@ -4464,6 +4977,53 @@ var getRecordValue3 = (value, key) => {
4464
4977
  if (!value || typeof value !== "object") return void 0;
4465
4978
  return value[key];
4466
4979
  };
4980
+ var toRuntimeRecord = (value) => {
4981
+ return value && typeof value === "object" ? { ...value } : {};
4982
+ };
4983
+ var toStringValue = (value) => {
4984
+ if (value === void 0 || value === null) return "";
4985
+ return String(value);
4986
+ };
4987
+ var parseBrowserQuery = () => {
4988
+ if (typeof window === "undefined") return {};
4989
+ const query = {};
4990
+ const params = new URLSearchParams(window.location.search);
4991
+ params.forEach((value, key) => {
4992
+ const currentValue = query[key];
4993
+ if (currentValue === void 0) {
4994
+ query[key] = value;
4995
+ return;
4996
+ }
4997
+ query[key] = Array.isArray(currentValue) ? [...currentValue, value] : [currentValue, value];
4998
+ });
4999
+ return query;
5000
+ };
5001
+ var buildBrowserRouteInfo = (route) => {
5002
+ const pathname = route?.pathname || (typeof window !== "undefined" ? window.location.pathname : "");
5003
+ const search = typeof window !== "undefined" ? window.location.search : "";
5004
+ const hash = route?.hash || (typeof window !== "undefined" ? window.location.hash : "");
5005
+ return {
5006
+ pathname,
5007
+ fullPath: route?.fullPath || (typeof window !== "undefined" ? `${pathname}${search}${hash}` : pathname),
5008
+ params: route?.params || {},
5009
+ query: route?.query || parseBrowserQuery(),
5010
+ hash
5011
+ };
5012
+ };
5013
+ var isSuccessCode5 = (code) => {
5014
+ if (code === void 0 || code === null || code === "") return true;
5015
+ const normalized = Number(code);
5016
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
5017
+ };
5018
+ var isRuntimeEnvelopeFailure = (response, payload) => {
5019
+ const code = getRecordValue3(payload, "code");
5020
+ const success = getRecordValue3(payload, "success");
5021
+ return !response.ok || success === false || !isSuccessCode5(code);
5022
+ };
5023
+ var isServerErrorCode = (code) => {
5024
+ const normalized = Number(code);
5025
+ return Number.isFinite(normalized) && normalized >= 500;
5026
+ };
4467
5027
  var getRecordString = (value, key) => {
4468
5028
  const result = getRecordValue3(value, key);
4469
5029
  return typeof result === "string" ? result : void 0;
@@ -4568,373 +5128,6 @@ var readTicketFromLocation = () => {
4568
5128
  };
4569
5129
  var readPathFromLocation = () => typeof window === "undefined" ? void 0 : window.location.pathname;
4570
5130
 
4571
- // packages/sdk/src/runtime/host/browserHost.ts
4572
- var NAMESPACE_ROOT_CLASS2 = "sy-app-workspace";
4573
- var defaultModuleLoader = (url2) => import(
4574
- /* @vite-ignore */
4575
- url2
4576
- );
4577
- var trimTrailingSlash = (value) => value.replace(/\/+$/, "");
4578
- var getDefaultServicePrefix = () => typeof window !== "undefined" ? trimTrailingSlash(window.__OPENXIANGDA_SERVICE_PREFIX__ || "/service") : "/service";
4579
- var joinServicePath = (servicePrefix, path) => {
4580
- if (/^https?:\/\//i.test(path)) return path;
4581
- const normalizedPrefix = trimTrailingSlash(servicePrefix || "/service");
4582
- if (path.startsWith(normalizedPrefix)) return path;
4583
- return `${normalizedPrefix}${path.startsWith("/") ? path : `/${path}`}`;
4584
- };
4585
- var appendQuery = (url2, query) => {
4586
- if (!query) return url2;
4587
- return `${url2}${url2.includes("?") ? "&" : "?"}${query}`;
4588
- };
4589
- var normalizeMethod2 = (method4) => {
4590
- const value = String(method4 || "get").toUpperCase();
4591
- return ["GET", "POST", "PUT", "DELETE", "PATCH"].includes(value) ? value : "GET";
4592
- };
4593
- var normalizeCssIsolation2 = (value) => {
4594
- if (value === "namespace" || value === "shadow" || value === "none") {
4595
- return value;
4596
- }
4597
- return "none";
4598
- };
4599
- var parseJsonResponse = async (response) => {
4600
- const payload = await response.json().catch(() => null);
4601
- if (!response.ok) {
4602
- const message7 = payload && typeof payload === "object" ? payload.message || payload.error || response.statusText : response.statusText;
4603
- throw new Error(message7 || "\u8BF7\u6C42\u5931\u8D25");
4604
- }
4605
- if (payload && typeof payload === "object" && "code" in payload) {
4606
- return {
4607
- code: Number(payload.code || response.status),
4608
- success: payload.success === true || payload.code === 200,
4609
- message: payload.message,
4610
- result: payload.result ?? payload.data ?? null,
4611
- data: payload.data,
4612
- raw: payload
4613
- };
4614
- }
4615
- return {
4616
- code: response.status,
4617
- success: response.ok,
4618
- message: response.statusText,
4619
- result: payload,
4620
- data: payload,
4621
- raw: payload
4622
- };
4623
- };
4624
- var createBrowserPageBridge = (options = {}) => {
4625
- const servicePrefix = options.servicePrefix || getDefaultServicePrefix();
4626
- const fetchImpl = createBoundFetch(options.fetchImpl);
4627
- const request = async (payload) => {
4628
- if (!payload?.path) {
4629
- throw new Error("transport.request \u9700\u8981 path");
4630
- }
4631
- const url2 = appendQuery(joinServicePath(servicePrefix, payload.path), payload.query);
4632
- const headers = new Headers(payload.headers);
4633
- let body;
4634
- if (payload.body !== void 0) {
4635
- if (payload.body instanceof FormData) {
4636
- body = payload.body;
4637
- } else {
4638
- headers.set("Content-Type", headers.get("Content-Type") || "application/json");
4639
- body = JSON.stringify(payload.body);
4640
- }
4641
- }
4642
- const response = await fetchImpl(url2, {
4643
- method: normalizeMethod2(payload.method),
4644
- headers,
4645
- body,
4646
- credentials: "include"
4647
- });
4648
- return parseJsonResponse(response);
4649
- };
4650
- const download = async (payload) => {
4651
- if (!payload?.path) {
4652
- throw new Error("transport.download \u9700\u8981 path");
4653
- }
4654
- const url2 = appendQuery(joinServicePath(servicePrefix, payload.path), payload.query);
4655
- const headers = new Headers(payload.headers);
4656
- let body;
4657
- if (payload.body !== void 0) {
4658
- if (payload.body instanceof FormData) {
4659
- body = payload.body;
4660
- } else {
4661
- headers.set("Content-Type", headers.get("Content-Type") || "application/json");
4662
- body = JSON.stringify(payload.body);
4663
- }
4664
- }
4665
- const response = await fetchImpl(url2, {
4666
- method: normalizeMethod2(payload.method),
4667
- headers,
4668
- body,
4669
- credentials: "include"
4670
- });
4671
- if (!response.ok) {
4672
- throw new Error(response.statusText || "\u4E0B\u8F7D\u5931\u8D25");
4673
- }
4674
- return {
4675
- blob: await response.blob(),
4676
- contentType: response.headers.get("content-type") || void 0,
4677
- fileName: response.headers.get("content-disposition") || void 0,
4678
- headers: Object.fromEntries(response.headers.entries())
4679
- };
4680
- };
4681
- return {
4682
- invoke: async (method4, payload) => {
4683
- if (method4 === "transport.request") return await request(payload);
4684
- if (method4 === "transport.download") return await download(payload);
4685
- throw new Error(`\u4E0D\u652F\u6301\u7684 bridge \u65B9\u6CD5: ${method4}`);
4686
- }
4687
- };
4688
- };
4689
- var createBrowserPageContext = (bootstrap, options = {}) => {
4690
- const route = {
4691
- pathname: options.route?.pathname || (typeof window !== "undefined" ? window.location.pathname : ""),
4692
- fullPath: options.route?.fullPath || (typeof window !== "undefined" ? `${window.location.pathname}${window.location.search}${window.location.hash}` : ""),
4693
- params: options.route?.params || {},
4694
- query: options.route?.query || {},
4695
- hash: options.route?.hash || (typeof window !== "undefined" ? window.location.hash : "")
4696
- };
4697
- return {
4698
- protocolVersion: bootstrap.asset?.protocolVersion || "1.0",
4699
- app: bootstrap.app,
4700
- page: {
4701
- ...bootstrap.page,
4702
- version: bootstrap.asset?.version || bootstrap.page.version,
4703
- buildId: bootstrap.asset?.buildId || bootstrap.page.buildId
4704
- },
4705
- user: bootstrap.user,
4706
- route,
4707
- env: bootstrap.env || {},
4708
- permissions: {
4709
- canView: bootstrap.permissions?.canView !== false,
4710
- hasFullAccess: bootstrap.permissions?.hasFullAccess === true,
4711
- ...bootstrap.permissions || {}
4712
- },
4713
- capabilities: Array.from(
4714
- /* @__PURE__ */ new Set([
4715
- "navigation",
4716
- "ui.message",
4717
- "ui.modal",
4718
- "transport.request",
4719
- "transport.download",
4720
- ...bootstrap.sdk?.supportedBridgeMethods || []
4721
- ])
4722
- ),
4723
- ui: {
4724
- message: {
4725
- success: (text) => options.message?.success?.(text),
4726
- error: (text) => options.message?.error?.(text),
4727
- warning: (text) => options.message?.warning?.(text),
4728
- info: (text) => options.message?.info?.(text),
4729
- loading: (text) => options.message?.loading?.(text) || (() => void 0)
4730
- },
4731
- modal: {
4732
- confirm: (input) => options.modal?.confirm?.(input) || Promise.resolve(false)
4733
- }
4734
- },
4735
- navigation: {
4736
- pushPage: (pageKey, query) => options.navigation?.pushPage?.(pageKey, query),
4737
- replacePage: (pageKey, query) => options.navigation?.replacePage?.(pageKey, query),
4738
- pushRoute: (routeValue, query) => options.navigation?.pushRoute?.(routeValue, query),
4739
- replaceRoute: (routeValue, query) => options.navigation?.replaceRoute?.(routeValue, query),
4740
- updateQuery: (query) => options.navigation?.updateQuery?.(query),
4741
- setHash: (hash) => options.navigation?.setHash?.(hash),
4742
- back: () => options.navigation?.back?.()
4743
- },
4744
- bridge: createBrowserPageBridge(options),
4745
- sdk: {
4746
- ...bootstrap.sdk,
4747
- supportedBridgeMethods: ["transport.request", "transport.download"]
4748
- }
4749
- };
4750
- };
4751
- var resolveRuntimeAssets = async (bootstrap, fetchImpl = fetch) => {
4752
- const boundFetch = createBoundFetch(fetchImpl);
4753
- const fallback = {
4754
- entryUrl: bootstrap.runtimeAssets?.entryUrl || bootstrap.asset?.entryUrl || "",
4755
- cssUrls: bootstrap.runtimeAssets?.cssUrls || bootstrap.asset?.cssAssets || [],
4756
- jsUrls: bootstrap.runtimeAssets?.jsUrls || bootstrap.asset?.jsAssets || [],
4757
- cssIsolation: normalizeCssIsolation2(
4758
- bootstrap.runtimeAssets?.cssIsolation || bootstrap.page.capabilities?.cssIsolation
4759
- )
4760
- };
4761
- if (bootstrap.runtimeAssets?.entryUrl || !bootstrap.asset?.manifestUrl) {
4762
- return fallback;
4763
- }
4764
- try {
4765
- const response = await boundFetch(bootstrap.asset.manifestUrl, {
4766
- credentials: "omit"
4767
- });
4768
- if (!response.ok) return fallback;
4769
- const manifest = await response.json();
4770
- const base = bootstrap.asset.manifestUrl;
4771
- const resolveUrl = (value) => new URL(value, base).toString();
4772
- return {
4773
- entryUrl: manifest?.entry?.url ? resolveUrl(manifest.entry.url) : fallback.entryUrl,
4774
- cssUrls: Array.isArray(manifest?.assets?.css) ? manifest.assets.css.map(resolveUrl) : fallback.cssUrls,
4775
- jsUrls: Array.isArray(manifest?.assets?.js) ? manifest.assets.js.map(resolveUrl) : fallback.jsUrls,
4776
- cssIsolation: normalizeCssIsolation2(
4777
- manifest?.style?.isolation || fallback.cssIsolation
4778
- )
4779
- };
4780
- } catch {
4781
- return fallback;
4782
- }
4783
- };
4784
- var fetchBrowserRuntimeBootstrap = async ({
4785
- appType,
4786
- bootstrapPath,
4787
- fetchImpl = fetch,
4788
- pageKey,
4789
- servicePrefix
4790
- }) => {
4791
- if (!appType) {
4792
- throw new Error("appType \u7F3A\u5931");
4793
- }
4794
- if (!pageKey) {
4795
- throw new Error("pageKey \u7F3A\u5931");
4796
- }
4797
- const path = bootstrapPath || `/openxiangda-api/v1/apps/${encodeURIComponent(
4798
- appType
4799
- )}/pages/${encodeURIComponent(pageKey)}/bootstrap`;
4800
- const boundFetch = createBoundFetch(fetchImpl);
4801
- const response = await boundFetch(
4802
- joinServicePath(servicePrefix || getDefaultServicePrefix(), path),
4803
- {
4804
- method: "GET",
4805
- credentials: "include"
4806
- }
4807
- );
4808
- const payload = await response.json().catch(() => null);
4809
- if (!response.ok) {
4810
- throw new Error(payload?.message || response.statusText || "\u83B7\u53D6\u9875\u9762\u8FD0\u884C\u65F6\u5931\u8D25");
4811
- }
4812
- if (payload && typeof payload === "object" && ("code" in payload || "success" in payload)) {
4813
- if (payload.success === false || payload.code && Number(payload.code) !== 200) {
4814
- throw new Error(payload.message || "\u83B7\u53D6\u9875\u9762\u8FD0\u884C\u65F6\u5931\u8D25");
4815
- }
4816
- return payload.data || {};
4817
- }
4818
- return payload || {};
4819
- };
4820
- var resolveBrowserRuntimeRoute = async ({
4821
- appType,
4822
- fetchImpl = fetch,
4823
- path,
4824
- resolvePath,
4825
- search,
4826
- servicePrefix
4827
- }) => {
4828
- if (!appType) {
4829
- throw new Error("appType \u7F3A\u5931");
4830
- }
4831
- const currentPath = path || (typeof window !== "undefined" ? window.location.pathname : "/");
4832
- const currentSearch = search !== void 0 ? search : typeof window !== "undefined" ? window.location.search : "";
4833
- const endpoint = resolvePath || `/openxiangda-api/v1/apps/${encodeURIComponent(
4834
- appType
4835
- )}/runtime/routes/resolve`;
4836
- const boundFetch = createBoundFetch(fetchImpl);
4837
- const response = await boundFetch(
4838
- joinServicePath(servicePrefix || getDefaultServicePrefix(), endpoint),
4839
- {
4840
- method: "POST",
4841
- credentials: "include",
4842
- headers: {
4843
- "Content-Type": "application/json"
4844
- },
4845
- body: JSON.stringify({
4846
- path: currentPath,
4847
- search: currentSearch
4848
- })
4849
- }
4850
- );
4851
- const parsed = await parseJsonResponse(response);
4852
- if (!parsed.success || !parsed.result) {
4853
- throw new Error(parsed.message || "\u89E3\u6790\u8FD0\u884C\u65F6\u8DEF\u7531\u5931\u8D25");
4854
- }
4855
- return parsed.result;
4856
- };
4857
- var loadRuntimeScriptModules = async (jsUrls = [], moduleLoader = defaultModuleLoader) => {
4858
- const urls = Array.from(
4859
- new Set(jsUrls.map((url2) => String(url2 || "").trim()).filter(Boolean))
4860
- );
4861
- for (const url2 of urls) {
4862
- await moduleLoader(url2);
4863
- }
4864
- };
4865
- var loadCustomPageModule = async (entryUrl, moduleLoader = defaultModuleLoader, jsUrls = []) => {
4866
- if (!entryUrl) {
4867
- throw new Error("\u4EE3\u7801\u9875\u9762\u7F3A\u5C11 entryUrl");
4868
- }
4869
- await loadRuntimeScriptModules(
4870
- jsUrls.filter((url2) => url2 && url2 !== entryUrl),
4871
- moduleLoader
4872
- );
4873
- const loaded = await moduleLoader(entryUrl);
4874
- return loaded?.default && (loaded.default.mount || loaded.default.unmount) ? { ...loaded.default, ...loaded } : loaded || {};
4875
- };
4876
- var mountCustomPageRuntime = async ({
4877
- assets,
4878
- container,
4879
- context,
4880
- module
4881
- }) => {
4882
- const cssIsolation = normalizeCssIsolation2(assets?.cssIsolation);
4883
- const mountedLinks = [];
4884
- container.innerHTML = "";
4885
- container.classList.toggle(NAMESPACE_ROOT_CLASS2, cssIsolation === "namespace");
4886
- (assets?.cssUrls || []).forEach((href) => {
4887
- const link = document.createElement("link");
4888
- link.rel = "stylesheet";
4889
- link.href = href;
4890
- link.setAttribute("data-openxiangda-runtime-style", href);
4891
- document.head.appendChild(link);
4892
- mountedLinks.push(link);
4893
- });
4894
- await module.mount?.(container, context);
4895
- return async () => {
4896
- await module.unmount?.(container, context);
4897
- mountedLinks.forEach((link) => link.remove());
4898
- container.classList.remove(NAMESPACE_ROOT_CLASS2);
4899
- container.innerHTML = "";
4900
- };
4901
- };
4902
- var mountBrowserPageRuntime = async (options) => {
4903
- const bootstrap = await fetchBrowserRuntimeBootstrap({
4904
- appType: options.appType,
4905
- pageKey: options.pageKey,
4906
- bootstrapPath: options.bootstrapPath,
4907
- fetchImpl: options.fetchImpl,
4908
- servicePrefix: options.servicePrefix
4909
- });
4910
- if (bootstrap.permissions?.canView === false) {
4911
- throw new Error(String(bootstrap.permissions.message || "\u60A8\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u8BE5\u9875\u9762"));
4912
- }
4913
- const assets = await resolveRuntimeAssets(bootstrap, options.fetchImpl || fetch);
4914
- if (!assets.entryUrl) {
4915
- throw new Error("\u4EE3\u7801\u9875\u9762\u7F3A\u5C11 entryUrl");
4916
- }
4917
- const context = createBrowserPageContext(bootstrap, options);
4918
- const module = await loadCustomPageModule(
4919
- assets.entryUrl,
4920
- options.moduleLoader,
4921
- assets.jsUrls
4922
- );
4923
- const cleanup2 = await mountCustomPageRuntime({
4924
- assets,
4925
- container: options.container,
4926
- context,
4927
- module
4928
- });
4929
- return {
4930
- bootstrap,
4931
- assets,
4932
- context,
4933
- module,
4934
- cleanup: cleanup2
4935
- };
4936
- };
4937
-
4938
5131
  // packages/sdk/src/runtime/host/builtinRouteRenderer.tsx
4939
5132
  import { useCallback as useCallback39, useEffect as useEffect101, useMemo as useMemo67, useState as useState93 } from "react";
4940
5133
  import { Alert as Alert4, Button as Button17, Card as Card3, Empty as Empty9, Spin as Spin6, Typography as Typography3 } from "antd";
@@ -4971,6 +5164,11 @@ var joinUrl = (baseUrl, url2) => {
4971
5164
  if (/^https?:\/\//i.test(url2)) return url2;
4972
5165
  return `${trimTrailingSlash2(baseUrl)}${url2.startsWith("/") ? url2 : `/${url2}`}`;
4973
5166
  };
5167
+ var isSuccessCode6 = (value) => {
5168
+ if (value === void 0 || value === null || value === "") return true;
5169
+ const code = Number(value);
5170
+ return Number.isFinite(code) ? code === 0 || code >= 200 && code < 300 : false;
5171
+ };
4974
5172
  var normalizeRuntimeFileUrl = (baseUrl, value) => {
4975
5173
  if (typeof value !== "string" || !value) return value;
4976
5174
  if (/^(https?:)?\/\//i.test(value) || /^(blob|data):/i.test(value)) return value;
@@ -4997,6 +5195,12 @@ var parseResponse = async (response) => {
4997
5195
  const message7 = typeof payload === "object" && payload ? payload.message || payload.error || response.statusText : response.statusText;
4998
5196
  throw new Error(message7 || "\u8BF7\u6C42\u5931\u8D25");
4999
5197
  }
5198
+ if (typeof payload === "object" && payload) {
5199
+ const hasCode = Object.prototype.hasOwnProperty.call(payload, "code");
5200
+ if (payload.success === false || hasCode && !isSuccessCode6(payload.code)) {
5201
+ throw new Error(payload.message || payload.error || "\u8BF7\u6C42\u5931\u8D25");
5202
+ }
5203
+ }
5000
5204
  if (typeof payload === "object" && payload) {
5001
5205
  return payload;
5002
5206
  }
@@ -43427,20 +43631,20 @@ async function validateAndNotify(validateAllWithErrors) {
43427
43631
  import { useState as useState79, useEffect as useEffect91, useCallback as useCallback27, useRef as useRef87 } from "react";
43428
43632
 
43429
43633
  // packages/sdk/src/components/core/processApi.ts
43430
- var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
43431
- var isRuntimeEnvelope = (value) => !!value && typeof value === "object" && !Array.isArray(value) && (hasOwn(value, "code") || hasOwn(value, "success") || hasOwn(value, "data") || hasOwn(value, "result") || hasOwn(value, "message") || hasOwn(value, "error"));
43432
- var isSuccessCode = (code) => {
43634
+ var hasOwn2 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
43635
+ var isRuntimeEnvelope = (value) => !!value && typeof value === "object" && !Array.isArray(value) && (hasOwn2(value, "code") || hasOwn2(value, "success") || hasOwn2(value, "data") || hasOwn2(value, "result") || hasOwn2(value, "message") || hasOwn2(value, "error"));
43636
+ var isSuccessCode7 = (code) => {
43433
43637
  if (code === void 0 || code === null || code === "") return true;
43434
43638
  const normalized = Number(code);
43435
43639
  return Number.isFinite(normalized) ? normalized === 0 || normalized === 200 : false;
43436
43640
  };
43437
43641
  var unwrapRuntimeResponse = (response) => {
43438
43642
  if (!isRuntimeEnvelope(response)) return response;
43439
- if (response.success === false || !isSuccessCode(response.code)) {
43643
+ if (response.success === false || !isSuccessCode7(response.code)) {
43440
43644
  throw new Error(response.message || response.error || "\u8BF7\u6C42\u5931\u8D25");
43441
43645
  }
43442
- if (hasOwn(response, "data")) return response.data;
43443
- if (hasOwn(response, "result")) return response.result;
43646
+ if (hasOwn2(response, "data")) return response.data;
43647
+ if (hasOwn2(response, "result")) return response.result;
43444
43648
  return response;
43445
43649
  };
43446
43650
  var withInitiatorSelectedApprovers = (payload, initiatorSelectedApprovers) => {
@@ -50783,6 +50987,7 @@ export {
50783
50987
  AuthClientError,
50784
50988
  BuiltinRouteRenderer,
50785
50989
  LoginPage,
50990
+ OpenXiangdaPageProvider,
50786
50991
  OpenXiangdaProvider,
50787
50992
  PageProvider,
50788
50993
  PermissionBoundary,