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.
@@ -47,7 +47,7 @@ var require_classnames = __commonJS({
47
47
  init_cjs_shims();
48
48
  (function() {
49
49
  "use strict";
50
- var hasOwn2 = {}.hasOwnProperty;
50
+ var hasOwn3 = {}.hasOwnProperty;
51
51
  function classNames80() {
52
52
  var classes = "";
53
53
  for (var i2 = 0; i2 < arguments.length; i2++) {
@@ -73,7 +73,7 @@ var require_classnames = __commonJS({
73
73
  }
74
74
  var classes = "";
75
75
  for (var key in arg) {
76
- if (hasOwn2.call(arg, key) && arg[key]) {
76
+ if (hasOwn3.call(arg, key) && arg[key]) {
77
77
  classes = appendClass(classes, key);
78
78
  }
79
79
  }
@@ -827,6 +827,7 @@ __export(runtime_exports, {
827
827
  AuthClientError: () => AuthClientError,
828
828
  BuiltinRouteRenderer: () => BuiltinRouteRenderer,
829
829
  LoginPage: () => LoginPage,
830
+ OpenXiangdaPageProvider: () => OpenXiangdaPageProvider,
830
831
  OpenXiangdaProvider: () => OpenXiangdaProvider,
831
832
  PageProvider: () => PageProvider,
832
833
  PermissionBoundary: () => PermissionBoundary,
@@ -1093,18 +1094,39 @@ var normalizeDynamicOrder = (value) => {
1093
1094
  }
1094
1095
  return `${value.id}:${value.isAsc === "n" ? "-" : "+"}`;
1095
1096
  };
1097
+ var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
1098
+ var normalizeEnvelopeCode = (value) => {
1099
+ if (value === void 0 || value === null || value === "") {
1100
+ return 200;
1101
+ }
1102
+ const normalized = Number(value);
1103
+ return Number.isFinite(normalized) ? normalized : String(value);
1104
+ };
1105
+ var isSuccessCode = (value) => {
1106
+ if (value === void 0 || value === null || value === "") {
1107
+ return true;
1108
+ }
1109
+ const normalized = Number(value);
1110
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
1111
+ };
1112
+ var getEnvelopeCode = (rawResponse) => {
1113
+ if (isRecord(rawResponse) && hasOwn(rawResponse, "code")) {
1114
+ return rawResponse.code;
1115
+ }
1116
+ const nestedData = rawResponse?.data;
1117
+ if (isRecord(nestedData) && hasOwn(nestedData, "code")) {
1118
+ return nestedData.code;
1119
+ }
1120
+ return void 0;
1121
+ };
1096
1122
  var normalizeJsonResponse = (rawResponse) => {
1097
- const topLevelCode = Number(rawResponse?.code);
1098
- const nestedCode = Number(
1099
- rawResponse?.data?.code
1100
- );
1101
- const code = Number.isFinite(topLevelCode) ? topLevelCode : Number.isFinite(nestedCode) ? nestedCode : 200;
1123
+ const code = normalizeEnvelopeCode(getEnvelopeCode(rawResponse));
1102
1124
  const topLevelResult = isRecord(rawResponse) && "result" in rawResponse ? rawResponse.result : void 0;
1103
1125
  const nestedResult = isRecord(rawResponse?.data) && "result" in (rawResponse.data || {}) ? rawResponse.data?.result : void 0;
1104
1126
  const topLevelData = isRecord(rawResponse) && "data" in rawResponse ? rawResponse.data : void 0;
1105
1127
  const result = topLevelResult !== void 0 ? topLevelResult : nestedResult !== void 0 ? nestedResult : topLevelData !== void 0 ? topLevelData : isRecord(rawResponse) ? rawResponse : null;
1106
1128
  const nestedSuccess = typeof rawResponse?.data?.success === "boolean" ? rawResponse.data?.success : void 0;
1107
- const success = typeof rawResponse?.success === "boolean" ? Boolean(rawResponse.success) : typeof nestedSuccess === "boolean" ? Boolean(nestedSuccess) : code >= 200 && code < 300;
1129
+ const success = rawResponse?.success === false || nestedSuccess === false ? false : isSuccessCode(code);
1108
1130
  return {
1109
1131
  code,
1110
1132
  success,
@@ -1149,6 +1171,9 @@ var normalizeBinaryResponse = (rawResponse) => {
1149
1171
  };
1150
1172
  };
1151
1173
  var toSdkError = (input, payload) => {
1174
+ if (input instanceof Error && input.response) {
1175
+ return input;
1176
+ }
1152
1177
  const normalizedResponse = isRecord(input) ? normalizeJsonResponse(input) : void 0;
1153
1178
  const nextError = input instanceof Error ? input : new Error(
1154
1179
  normalizedResponse?.message || `\u8BF7\u6C42\u5931\u8D25: ${String(payload.method).toUpperCase()} ${payload.path}`
@@ -2295,7 +2320,8 @@ var createAuthClient = ({
2295
2320
  });
2296
2321
  const payload = await readPayload(response);
2297
2322
  const code = getRecordValue(payload, "code");
2298
- if (!response.ok || typeof code === "number" && code >= 400) {
2323
+ const success = getRecordValue(payload, "success");
2324
+ if (!response.ok || success === false || !isSuccessCode2(code)) {
2299
2325
  throw new AuthClientError(
2300
2326
  String(getRecordValue(payload, "message") || `Auth request failed: ${response.status}`),
2301
2327
  { status: response.status, code, payload }
@@ -2348,6 +2374,11 @@ var getRecordValue = (value, key) => {
2348
2374
  if (!value || typeof value !== "object") return void 0;
2349
2375
  return value[key];
2350
2376
  };
2377
+ var isSuccessCode2 = (code) => {
2378
+ if (code === void 0 || code === null || code === "") return true;
2379
+ const normalized = Number(code);
2380
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
2381
+ };
2351
2382
  var resolveLoginUrl = (appType, {
2352
2383
  callbackUrl = getCurrentHref2(),
2353
2384
  callbackParamName = "callback",
@@ -2420,7 +2451,8 @@ var createPublicAccessClient = ({
2420
2451
  );
2421
2452
  const payload = await readPayload2(response);
2422
2453
  const code = getRecordValue2(payload, "code");
2423
- if (!response.ok || typeof code === "number" && code >= 400) {
2454
+ const success = getRecordValue2(payload, "success");
2455
+ if (!response.ok || success === false || !isSuccessCode3(code)) {
2424
2456
  throw new PublicAccessClientError(
2425
2457
  String(
2426
2458
  getRecordValue2(payload, "message") || `Public access session failed: ${response.status}`
@@ -2458,6 +2490,11 @@ var getRecordValue2 = (value, key) => {
2458
2490
  if (!value || typeof value !== "object") return void 0;
2459
2491
  return value[key];
2460
2492
  };
2493
+ var isSuccessCode3 = (code) => {
2494
+ if (code === void 0 || code === null || code === "") return true;
2495
+ const normalized = Number(code);
2496
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
2497
+ };
2461
2498
  var getCurrentPathname = () => typeof window === "undefined" ? void 0 : window.location.pathname;
2462
2499
  var getCurrentDomain = () => typeof window === "undefined" ? void 0 : window.location.host;
2463
2500
  var getCurrentUserAgent = () => typeof navigator === "undefined" ? void 0 : navigator.userAgent;
@@ -3586,6 +3623,385 @@ var usePageRoute = () => {
3586
3623
  init_cjs_shims();
3587
3624
  var import_react8 = require("react");
3588
3625
 
3626
+ // packages/sdk/src/runtime/host/browserHost.ts
3627
+ init_cjs_shims();
3628
+ var NAMESPACE_ROOT_CLASS2 = "sy-app-workspace";
3629
+ var defaultModuleLoader = (url2) => import(
3630
+ /* @vite-ignore */
3631
+ url2
3632
+ );
3633
+ var trimTrailingSlash = (value) => value.replace(/\/+$/, "");
3634
+ var getDefaultServicePrefix = () => typeof window !== "undefined" ? trimTrailingSlash(window.__OPENXIANGDA_SERVICE_PREFIX__ || "/service") : "/service";
3635
+ var joinServicePath = (servicePrefix, path) => {
3636
+ if (/^https?:\/\//i.test(path)) return path;
3637
+ const normalizedPrefix = trimTrailingSlash(servicePrefix || "/service");
3638
+ if (path.startsWith(normalizedPrefix)) return path;
3639
+ return `${normalizedPrefix}${path.startsWith("/") ? path : `/${path}`}`;
3640
+ };
3641
+ var appendQuery = (url2, query) => {
3642
+ if (!query) return url2;
3643
+ return `${url2}${url2.includes("?") ? "&" : "?"}${query}`;
3644
+ };
3645
+ var normalizeMethod2 = (method4) => {
3646
+ const value = String(method4 || "get").toUpperCase();
3647
+ return ["GET", "POST", "PUT", "DELETE", "PATCH"].includes(value) ? value : "GET";
3648
+ };
3649
+ var normalizeCssIsolation2 = (value) => {
3650
+ if (value === "namespace" || value === "shadow" || value === "none") {
3651
+ return value;
3652
+ }
3653
+ return "none";
3654
+ };
3655
+ var normalizeEnvelopeCode2 = (value, fallback) => {
3656
+ if (value === void 0 || value === null || value === "") return fallback;
3657
+ const normalized = Number(value);
3658
+ return Number.isFinite(normalized) ? normalized : String(value);
3659
+ };
3660
+ var isSuccessCode4 = (value) => {
3661
+ if (value === void 0 || value === null || value === "") return true;
3662
+ const normalized = Number(value);
3663
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
3664
+ };
3665
+ var parseJsonResponse = async (response) => {
3666
+ const payload = await response.json().catch(() => null);
3667
+ if (!response.ok) {
3668
+ const message7 = payload && typeof payload === "object" ? payload.message || payload.error || response.statusText : response.statusText;
3669
+ throw new Error(message7 || "\u8BF7\u6C42\u5931\u8D25");
3670
+ }
3671
+ if (payload && typeof payload === "object" && "code" in payload) {
3672
+ const code = normalizeEnvelopeCode2(payload.code, response.status);
3673
+ return {
3674
+ code,
3675
+ success: payload.success !== false && isSuccessCode4(code),
3676
+ message: payload.message,
3677
+ result: payload.result ?? payload.data ?? null,
3678
+ data: payload.data,
3679
+ raw: payload
3680
+ };
3681
+ }
3682
+ return {
3683
+ code: response.status,
3684
+ success: response.ok,
3685
+ message: response.statusText,
3686
+ result: payload,
3687
+ data: payload,
3688
+ raw: payload
3689
+ };
3690
+ };
3691
+ var createBrowserPageBridge = (options = {}) => {
3692
+ const servicePrefix = options.servicePrefix || getDefaultServicePrefix();
3693
+ const fetchImpl = createBoundFetch(options.fetchImpl);
3694
+ const request = async (payload) => {
3695
+ if (!payload?.path) {
3696
+ throw new Error("transport.request \u9700\u8981 path");
3697
+ }
3698
+ const url2 = appendQuery(joinServicePath(servicePrefix, payload.path), payload.query);
3699
+ const headers = new Headers(payload.headers);
3700
+ let body;
3701
+ if (payload.body !== void 0) {
3702
+ if (payload.body instanceof FormData) {
3703
+ body = payload.body;
3704
+ } else {
3705
+ headers.set("Content-Type", headers.get("Content-Type") || "application/json");
3706
+ body = JSON.stringify(payload.body);
3707
+ }
3708
+ }
3709
+ const response = await fetchImpl(url2, {
3710
+ method: normalizeMethod2(payload.method),
3711
+ headers,
3712
+ body,
3713
+ credentials: "include"
3714
+ });
3715
+ return parseJsonResponse(response);
3716
+ };
3717
+ const download = async (payload) => {
3718
+ if (!payload?.path) {
3719
+ throw new Error("transport.download \u9700\u8981 path");
3720
+ }
3721
+ const url2 = appendQuery(joinServicePath(servicePrefix, payload.path), payload.query);
3722
+ const headers = new Headers(payload.headers);
3723
+ let body;
3724
+ if (payload.body !== void 0) {
3725
+ if (payload.body instanceof FormData) {
3726
+ body = payload.body;
3727
+ } else {
3728
+ headers.set("Content-Type", headers.get("Content-Type") || "application/json");
3729
+ body = JSON.stringify(payload.body);
3730
+ }
3731
+ }
3732
+ const response = await fetchImpl(url2, {
3733
+ method: normalizeMethod2(payload.method),
3734
+ headers,
3735
+ body,
3736
+ credentials: "include"
3737
+ });
3738
+ if (!response.ok) {
3739
+ throw new Error(response.statusText || "\u4E0B\u8F7D\u5931\u8D25");
3740
+ }
3741
+ return {
3742
+ blob: await response.blob(),
3743
+ contentType: response.headers.get("content-type") || void 0,
3744
+ fileName: response.headers.get("content-disposition") || void 0,
3745
+ headers: Object.fromEntries(response.headers.entries())
3746
+ };
3747
+ };
3748
+ return {
3749
+ invoke: async (method4, payload) => {
3750
+ if (method4 === "transport.request") return await request(payload);
3751
+ if (method4 === "transport.download") return await download(payload);
3752
+ throw new Error(`\u4E0D\u652F\u6301\u7684 bridge \u65B9\u6CD5: ${method4}`);
3753
+ }
3754
+ };
3755
+ };
3756
+ var createBrowserPageContext = (bootstrap, options = {}) => {
3757
+ const route = {
3758
+ pathname: options.route?.pathname || (typeof window !== "undefined" ? window.location.pathname : ""),
3759
+ fullPath: options.route?.fullPath || (typeof window !== "undefined" ? `${window.location.pathname}${window.location.search}${window.location.hash}` : ""),
3760
+ params: options.route?.params || {},
3761
+ query: options.route?.query || {},
3762
+ hash: options.route?.hash || (typeof window !== "undefined" ? window.location.hash : "")
3763
+ };
3764
+ return {
3765
+ protocolVersion: bootstrap.asset?.protocolVersion || "1.0",
3766
+ app: bootstrap.app,
3767
+ page: {
3768
+ ...bootstrap.page,
3769
+ version: bootstrap.asset?.version || bootstrap.page.version,
3770
+ buildId: bootstrap.asset?.buildId || bootstrap.page.buildId
3771
+ },
3772
+ user: bootstrap.user,
3773
+ route,
3774
+ env: bootstrap.env || {},
3775
+ permissions: {
3776
+ canView: bootstrap.permissions?.canView !== false,
3777
+ hasFullAccess: bootstrap.permissions?.hasFullAccess === true,
3778
+ ...bootstrap.permissions || {}
3779
+ },
3780
+ capabilities: Array.from(
3781
+ /* @__PURE__ */ new Set([
3782
+ "navigation",
3783
+ "ui.message",
3784
+ "ui.modal",
3785
+ "transport.request",
3786
+ "transport.download",
3787
+ ...bootstrap.sdk?.supportedBridgeMethods || []
3788
+ ])
3789
+ ),
3790
+ ui: {
3791
+ message: {
3792
+ success: (text) => options.message?.success?.(text),
3793
+ error: (text) => options.message?.error?.(text),
3794
+ warning: (text) => options.message?.warning?.(text),
3795
+ info: (text) => options.message?.info?.(text),
3796
+ loading: (text) => options.message?.loading?.(text) || (() => void 0)
3797
+ },
3798
+ modal: {
3799
+ confirm: (input) => options.modal?.confirm?.(input) || Promise.resolve(false)
3800
+ }
3801
+ },
3802
+ navigation: {
3803
+ pushPage: (pageKey, query) => options.navigation?.pushPage?.(pageKey, query),
3804
+ replacePage: (pageKey, query) => options.navigation?.replacePage?.(pageKey, query),
3805
+ pushRoute: (routeValue, query) => options.navigation?.pushRoute?.(routeValue, query),
3806
+ replaceRoute: (routeValue, query) => options.navigation?.replaceRoute?.(routeValue, query),
3807
+ updateQuery: (query) => options.navigation?.updateQuery?.(query),
3808
+ setHash: (hash) => options.navigation?.setHash?.(hash),
3809
+ back: () => options.navigation?.back?.()
3810
+ },
3811
+ bridge: createBrowserPageBridge(options),
3812
+ sdk: {
3813
+ ...bootstrap.sdk,
3814
+ supportedBridgeMethods: ["transport.request", "transport.download"]
3815
+ }
3816
+ };
3817
+ };
3818
+ var resolveRuntimeAssets = async (bootstrap, fetchImpl = fetch) => {
3819
+ const boundFetch = createBoundFetch(fetchImpl);
3820
+ const fallback = {
3821
+ entryUrl: bootstrap.runtimeAssets?.entryUrl || bootstrap.asset?.entryUrl || "",
3822
+ cssUrls: bootstrap.runtimeAssets?.cssUrls || bootstrap.asset?.cssAssets || [],
3823
+ jsUrls: bootstrap.runtimeAssets?.jsUrls || bootstrap.asset?.jsAssets || [],
3824
+ cssIsolation: normalizeCssIsolation2(
3825
+ bootstrap.runtimeAssets?.cssIsolation || bootstrap.page.capabilities?.cssIsolation
3826
+ )
3827
+ };
3828
+ if (bootstrap.runtimeAssets?.entryUrl || !bootstrap.asset?.manifestUrl) {
3829
+ return fallback;
3830
+ }
3831
+ try {
3832
+ const response = await boundFetch(bootstrap.asset.manifestUrl, {
3833
+ credentials: "omit"
3834
+ });
3835
+ if (!response.ok) return fallback;
3836
+ const manifest = await response.json();
3837
+ const base = bootstrap.asset.manifestUrl;
3838
+ const resolveUrl = (value) => new URL(value, base).toString();
3839
+ return {
3840
+ entryUrl: manifest?.entry?.url ? resolveUrl(manifest.entry.url) : fallback.entryUrl,
3841
+ cssUrls: Array.isArray(manifest?.assets?.css) ? manifest.assets.css.map(resolveUrl) : fallback.cssUrls,
3842
+ jsUrls: Array.isArray(manifest?.assets?.js) ? manifest.assets.js.map(resolveUrl) : fallback.jsUrls,
3843
+ cssIsolation: normalizeCssIsolation2(
3844
+ manifest?.style?.isolation || fallback.cssIsolation
3845
+ )
3846
+ };
3847
+ } catch {
3848
+ return fallback;
3849
+ }
3850
+ };
3851
+ var fetchBrowserRuntimeBootstrap = async ({
3852
+ appType,
3853
+ bootstrapPath,
3854
+ fetchImpl = fetch,
3855
+ pageKey,
3856
+ servicePrefix
3857
+ }) => {
3858
+ if (!appType) {
3859
+ throw new Error("appType \u7F3A\u5931");
3860
+ }
3861
+ if (!pageKey) {
3862
+ throw new Error("pageKey \u7F3A\u5931");
3863
+ }
3864
+ const path = bootstrapPath || `/openxiangda-api/v1/apps/${encodeURIComponent(
3865
+ appType
3866
+ )}/pages/${encodeURIComponent(pageKey)}/bootstrap`;
3867
+ const boundFetch = createBoundFetch(fetchImpl);
3868
+ const response = await boundFetch(
3869
+ joinServicePath(servicePrefix || getDefaultServicePrefix(), path),
3870
+ {
3871
+ method: "GET",
3872
+ credentials: "include"
3873
+ }
3874
+ );
3875
+ const payload = await response.json().catch(() => null);
3876
+ if (!response.ok) {
3877
+ throw new Error(payload?.message || response.statusText || "\u83B7\u53D6\u9875\u9762\u8FD0\u884C\u65F6\u5931\u8D25");
3878
+ }
3879
+ if (payload && typeof payload === "object" && ("code" in payload || "success" in payload)) {
3880
+ if (payload.success === false || payload.code && Number(payload.code) !== 200) {
3881
+ throw new Error(payload.message || "\u83B7\u53D6\u9875\u9762\u8FD0\u884C\u65F6\u5931\u8D25");
3882
+ }
3883
+ return payload.data || {};
3884
+ }
3885
+ return payload || {};
3886
+ };
3887
+ var resolveBrowserRuntimeRoute = async ({
3888
+ appType,
3889
+ fetchImpl = fetch,
3890
+ path,
3891
+ resolvePath,
3892
+ search,
3893
+ servicePrefix
3894
+ }) => {
3895
+ if (!appType) {
3896
+ throw new Error("appType \u7F3A\u5931");
3897
+ }
3898
+ const currentPath = path || (typeof window !== "undefined" ? window.location.pathname : "/");
3899
+ const currentSearch = search !== void 0 ? search : typeof window !== "undefined" ? window.location.search : "";
3900
+ const endpoint = resolvePath || `/openxiangda-api/v1/apps/${encodeURIComponent(
3901
+ appType
3902
+ )}/runtime/routes/resolve`;
3903
+ const boundFetch = createBoundFetch(fetchImpl);
3904
+ const response = await boundFetch(
3905
+ joinServicePath(servicePrefix || getDefaultServicePrefix(), endpoint),
3906
+ {
3907
+ method: "POST",
3908
+ credentials: "include",
3909
+ headers: {
3910
+ "Content-Type": "application/json"
3911
+ },
3912
+ body: JSON.stringify({
3913
+ path: currentPath,
3914
+ search: currentSearch
3915
+ })
3916
+ }
3917
+ );
3918
+ const parsed = await parseJsonResponse(response);
3919
+ if (!parsed.success || !parsed.result) {
3920
+ throw new Error(parsed.message || "\u89E3\u6790\u8FD0\u884C\u65F6\u8DEF\u7531\u5931\u8D25");
3921
+ }
3922
+ return parsed.result;
3923
+ };
3924
+ var loadRuntimeScriptModules = async (jsUrls = [], moduleLoader = defaultModuleLoader) => {
3925
+ const urls = Array.from(
3926
+ new Set(jsUrls.map((url2) => String(url2 || "").trim()).filter(Boolean))
3927
+ );
3928
+ for (const url2 of urls) {
3929
+ await moduleLoader(url2);
3930
+ }
3931
+ };
3932
+ var loadCustomPageModule = async (entryUrl, moduleLoader = defaultModuleLoader, jsUrls = []) => {
3933
+ if (!entryUrl) {
3934
+ throw new Error("\u4EE3\u7801\u9875\u9762\u7F3A\u5C11 entryUrl");
3935
+ }
3936
+ await loadRuntimeScriptModules(
3937
+ jsUrls.filter((url2) => url2 && url2 !== entryUrl),
3938
+ moduleLoader
3939
+ );
3940
+ const loaded = await moduleLoader(entryUrl);
3941
+ return loaded?.default && (loaded.default.mount || loaded.default.unmount) ? { ...loaded.default, ...loaded } : loaded || {};
3942
+ };
3943
+ var mountCustomPageRuntime = async ({
3944
+ assets,
3945
+ container,
3946
+ context,
3947
+ module: module2
3948
+ }) => {
3949
+ const cssIsolation = normalizeCssIsolation2(assets?.cssIsolation);
3950
+ const mountedLinks = [];
3951
+ container.innerHTML = "";
3952
+ container.classList.toggle(NAMESPACE_ROOT_CLASS2, cssIsolation === "namespace");
3953
+ (assets?.cssUrls || []).forEach((href) => {
3954
+ const link = document.createElement("link");
3955
+ link.rel = "stylesheet";
3956
+ link.href = href;
3957
+ link.setAttribute("data-openxiangda-runtime-style", href);
3958
+ document.head.appendChild(link);
3959
+ mountedLinks.push(link);
3960
+ });
3961
+ await module2.mount?.(container, context);
3962
+ return async () => {
3963
+ await module2.unmount?.(container, context);
3964
+ mountedLinks.forEach((link) => link.remove());
3965
+ container.classList.remove(NAMESPACE_ROOT_CLASS2);
3966
+ container.innerHTML = "";
3967
+ };
3968
+ };
3969
+ var mountBrowserPageRuntime = async (options) => {
3970
+ const bootstrap = await fetchBrowserRuntimeBootstrap({
3971
+ appType: options.appType,
3972
+ pageKey: options.pageKey,
3973
+ bootstrapPath: options.bootstrapPath,
3974
+ fetchImpl: options.fetchImpl,
3975
+ servicePrefix: options.servicePrefix
3976
+ });
3977
+ if (bootstrap.permissions?.canView === false) {
3978
+ throw new Error(String(bootstrap.permissions.message || "\u60A8\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u8BE5\u9875\u9762"));
3979
+ }
3980
+ const assets = await resolveRuntimeAssets(bootstrap, options.fetchImpl || fetch);
3981
+ if (!assets.entryUrl) {
3982
+ throw new Error("\u4EE3\u7801\u9875\u9762\u7F3A\u5C11 entryUrl");
3983
+ }
3984
+ const context = createBrowserPageContext(bootstrap, options);
3985
+ const module2 = await loadCustomPageModule(
3986
+ assets.entryUrl,
3987
+ options.moduleLoader,
3988
+ assets.jsUrls
3989
+ );
3990
+ const cleanup2 = await mountCustomPageRuntime({
3991
+ assets,
3992
+ container: options.container,
3993
+ context,
3994
+ module: module2
3995
+ });
3996
+ return {
3997
+ bootstrap,
3998
+ assets,
3999
+ context,
4000
+ module: module2,
4001
+ cleanup: cleanup2
4002
+ };
4003
+ };
4004
+
3589
4005
  // packages/sdk/src/runtime/react/auth.tsx
3590
4006
  init_cjs_shims();
3591
4007
  var import_react7 = require("react");
@@ -4146,7 +4562,7 @@ var OpenXiangdaProvider = ({
4146
4562
  }
4147
4563
  );
4148
4564
  const payload = await readJsonPayload(response);
4149
- if (!response.ok || payload?.code >= 400) {
4565
+ if (isRuntimeEnvelopeFailure(response, payload)) {
4150
4566
  throw createRuntimeHttpError(
4151
4567
  response,
4152
4568
  payload,
@@ -4190,6 +4606,96 @@ var useOpenXiangda = () => {
4190
4606
  return context;
4191
4607
  };
4192
4608
  var useRuntimeBootstrap = () => useOpenXiangda();
4609
+ var OpenXiangdaPageProvider = ({
4610
+ children,
4611
+ page,
4612
+ route,
4613
+ env,
4614
+ message: message7,
4615
+ modal,
4616
+ navigation
4617
+ }) => {
4618
+ const runtime = useOpenXiangda();
4619
+ const context = (0, import_react8.useMemo)(() => {
4620
+ const bootstrap = runtime.data;
4621
+ const app = toRuntimeRecord(bootstrap?.app);
4622
+ const user = toRuntimeRecord(bootstrap?.user);
4623
+ const permissions = bootstrap?.permissions;
4624
+ const tenantId = toStringValue(getRecordValue3(app, "tenantId")) || toStringValue(getRecordValue3(user, "tenantId")) || toStringValue(getRecordValue3(app, "tenantCode")) || "";
4625
+ const appType = runtime.appType || bootstrap?.appType || toStringValue(getRecordValue3(app, "appType"));
4626
+ const routeInfo = buildBrowserRouteInfo(route);
4627
+ return createBrowserPageContext(
4628
+ {
4629
+ app: {
4630
+ ...app,
4631
+ appType,
4632
+ tenantId
4633
+ },
4634
+ page: {
4635
+ id: routeInfo.pathname || "react-spa",
4636
+ code: routeInfo.pathname || "react-spa",
4637
+ name: "OpenXiangda React SPA",
4638
+ type: "react-spa",
4639
+ rendererType: "react-spa",
4640
+ routeKey: routeInfo.pathname || "react-spa",
4641
+ status: "ACTIVE",
4642
+ props: {},
4643
+ route: {},
4644
+ dataSources: [],
4645
+ capabilities: {},
4646
+ buildId: toStringValue(
4647
+ getRecordValue3(bootstrap?.runtime, "activeBuildId")
4648
+ ),
4649
+ ...page
4650
+ },
4651
+ user: {
4652
+ ...user,
4653
+ id: toStringValue(getRecordValue3(user, "id")) || (user.isGuest ? "guest" : "current"),
4654
+ username: toStringValue(getRecordValue3(user, "username")) || toStringValue(getRecordValue3(user, "name")) || (user.isGuest ? "guest" : "current"),
4655
+ tenantId,
4656
+ isGuest: user.isGuest === true || user.userType === "guest" || Boolean(getRecordValue3(user, "publicAccess")),
4657
+ userType: user.userType === "guest" || user.isGuest === true ? "guest" : "normal"
4658
+ },
4659
+ env: {
4660
+ appType,
4661
+ servicePrefix: runtime.servicePrefix,
4662
+ runtimeMode: bootstrap?.runtime?.mode || "react-spa",
4663
+ ...env || {}
4664
+ },
4665
+ permissions: {
4666
+ canView: runtime.error?.type !== "forbidden",
4667
+ hasFullAccess: permissions?.hasFullAccess === true,
4668
+ ...permissions || {}
4669
+ },
4670
+ sdk: {
4671
+ packageName: "openxiangda",
4672
+ supportedBridgeMethods: ["transport.request", "transport.download"]
4673
+ }
4674
+ },
4675
+ {
4676
+ servicePrefix: runtime.servicePrefix,
4677
+ fetchImpl: runtime.fetchImpl,
4678
+ route: routeInfo,
4679
+ message: message7,
4680
+ modal,
4681
+ navigation
4682
+ }
4683
+ );
4684
+ }, [
4685
+ env,
4686
+ message7,
4687
+ modal,
4688
+ navigation,
4689
+ page,
4690
+ route,
4691
+ runtime.appType,
4692
+ runtime.data,
4693
+ runtime.error?.type,
4694
+ runtime.fetchImpl,
4695
+ runtime.servicePrefix
4696
+ ]);
4697
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PageProvider, { context, children });
4698
+ };
4193
4699
  var useAppMenus = () => {
4194
4700
  const runtime = useOpenXiangda();
4195
4701
  return {
@@ -4281,7 +4787,7 @@ var useCanAccessRoute = (input) => {
4281
4787
  payload
4282
4788
  };
4283
4789
  if (!disposed) {
4284
- const shouldTreatAsError = !response.ok || typeof code === "number" && code >= 500;
4790
+ const shouldTreatAsError = !response.ok || isServerErrorCode(code);
4285
4791
  setState({
4286
4792
  data,
4287
4793
  loading: false,
@@ -4413,7 +4919,7 @@ var useRuntimeAuth = () => {
4413
4919
  }
4414
4920
  );
4415
4921
  const payload = await readJsonPayload(response);
4416
- if (!response.ok || payload?.code >= 400) {
4922
+ if (isRuntimeEnvelopeFailure(response, payload)) {
4417
4923
  throw createRuntimeHttpError(
4418
4924
  response,
4419
4925
  payload,
@@ -4503,6 +5009,15 @@ var classifyRuntimeError = (status, code) => {
4503
5009
  const normalizedCode = typeof code === "string" ? Number(code) : code;
4504
5010
  if (status === 401 || normalizedCode === 401) return "unauthenticated";
4505
5011
  if (status === 403 || normalizedCode === 403) return "forbidden";
5012
+ if (typeof code === "string") {
5013
+ const normalizedText = code.toUpperCase();
5014
+ if (normalizedText.includes("DENIED") || normalizedText.includes("FORBIDDEN")) {
5015
+ return "forbidden";
5016
+ }
5017
+ if (normalizedText.includes("UNAUTH") || normalizedText.includes("LOGIN")) {
5018
+ return "unauthenticated";
5019
+ }
5020
+ }
4506
5021
  if (!status && !normalizedCode) return "network";
4507
5022
  return "unknown";
4508
5023
  };
@@ -4558,6 +5073,53 @@ var getRecordValue3 = (value, key) => {
4558
5073
  if (!value || typeof value !== "object") return void 0;
4559
5074
  return value[key];
4560
5075
  };
5076
+ var toRuntimeRecord = (value) => {
5077
+ return value && typeof value === "object" ? { ...value } : {};
5078
+ };
5079
+ var toStringValue = (value) => {
5080
+ if (value === void 0 || value === null) return "";
5081
+ return String(value);
5082
+ };
5083
+ var parseBrowserQuery = () => {
5084
+ if (typeof window === "undefined") return {};
5085
+ const query = {};
5086
+ const params = new URLSearchParams(window.location.search);
5087
+ params.forEach((value, key) => {
5088
+ const currentValue = query[key];
5089
+ if (currentValue === void 0) {
5090
+ query[key] = value;
5091
+ return;
5092
+ }
5093
+ query[key] = Array.isArray(currentValue) ? [...currentValue, value] : [currentValue, value];
5094
+ });
5095
+ return query;
5096
+ };
5097
+ var buildBrowserRouteInfo = (route) => {
5098
+ const pathname = route?.pathname || (typeof window !== "undefined" ? window.location.pathname : "");
5099
+ const search = typeof window !== "undefined" ? window.location.search : "";
5100
+ const hash = route?.hash || (typeof window !== "undefined" ? window.location.hash : "");
5101
+ return {
5102
+ pathname,
5103
+ fullPath: route?.fullPath || (typeof window !== "undefined" ? `${pathname}${search}${hash}` : pathname),
5104
+ params: route?.params || {},
5105
+ query: route?.query || parseBrowserQuery(),
5106
+ hash
5107
+ };
5108
+ };
5109
+ var isSuccessCode5 = (code) => {
5110
+ if (code === void 0 || code === null || code === "") return true;
5111
+ const normalized = Number(code);
5112
+ return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
5113
+ };
5114
+ var isRuntimeEnvelopeFailure = (response, payload) => {
5115
+ const code = getRecordValue3(payload, "code");
5116
+ const success = getRecordValue3(payload, "success");
5117
+ return !response.ok || success === false || !isSuccessCode5(code);
5118
+ };
5119
+ var isServerErrorCode = (code) => {
5120
+ const normalized = Number(code);
5121
+ return Number.isFinite(normalized) && normalized >= 500;
5122
+ };
4561
5123
  var getRecordString = (value, key) => {
4562
5124
  const result = getRecordValue3(value, key);
4563
5125
  return typeof result === "string" ? result : void 0;
@@ -4666,374 +5228,6 @@ var readPathFromLocation = () => typeof window === "undefined" ? void 0 : window
4666
5228
  // packages/sdk/src/runtime/host/index.ts
4667
5229
  init_cjs_shims();
4668
5230
 
4669
- // packages/sdk/src/runtime/host/browserHost.ts
4670
- init_cjs_shims();
4671
- var NAMESPACE_ROOT_CLASS2 = "sy-app-workspace";
4672
- var defaultModuleLoader = (url2) => import(
4673
- /* @vite-ignore */
4674
- url2
4675
- );
4676
- var trimTrailingSlash = (value) => value.replace(/\/+$/, "");
4677
- var getDefaultServicePrefix = () => typeof window !== "undefined" ? trimTrailingSlash(window.__OPENXIANGDA_SERVICE_PREFIX__ || "/service") : "/service";
4678
- var joinServicePath = (servicePrefix, path) => {
4679
- if (/^https?:\/\//i.test(path)) return path;
4680
- const normalizedPrefix = trimTrailingSlash(servicePrefix || "/service");
4681
- if (path.startsWith(normalizedPrefix)) return path;
4682
- return `${normalizedPrefix}${path.startsWith("/") ? path : `/${path}`}`;
4683
- };
4684
- var appendQuery = (url2, query) => {
4685
- if (!query) return url2;
4686
- return `${url2}${url2.includes("?") ? "&" : "?"}${query}`;
4687
- };
4688
- var normalizeMethod2 = (method4) => {
4689
- const value = String(method4 || "get").toUpperCase();
4690
- return ["GET", "POST", "PUT", "DELETE", "PATCH"].includes(value) ? value : "GET";
4691
- };
4692
- var normalizeCssIsolation2 = (value) => {
4693
- if (value === "namespace" || value === "shadow" || value === "none") {
4694
- return value;
4695
- }
4696
- return "none";
4697
- };
4698
- var parseJsonResponse = async (response) => {
4699
- const payload = await response.json().catch(() => null);
4700
- if (!response.ok) {
4701
- const message7 = payload && typeof payload === "object" ? payload.message || payload.error || response.statusText : response.statusText;
4702
- throw new Error(message7 || "\u8BF7\u6C42\u5931\u8D25");
4703
- }
4704
- if (payload && typeof payload === "object" && "code" in payload) {
4705
- return {
4706
- code: Number(payload.code || response.status),
4707
- success: payload.success === true || payload.code === 200,
4708
- message: payload.message,
4709
- result: payload.result ?? payload.data ?? null,
4710
- data: payload.data,
4711
- raw: payload
4712
- };
4713
- }
4714
- return {
4715
- code: response.status,
4716
- success: response.ok,
4717
- message: response.statusText,
4718
- result: payload,
4719
- data: payload,
4720
- raw: payload
4721
- };
4722
- };
4723
- var createBrowserPageBridge = (options = {}) => {
4724
- const servicePrefix = options.servicePrefix || getDefaultServicePrefix();
4725
- const fetchImpl = createBoundFetch(options.fetchImpl);
4726
- const request = async (payload) => {
4727
- if (!payload?.path) {
4728
- throw new Error("transport.request \u9700\u8981 path");
4729
- }
4730
- const url2 = appendQuery(joinServicePath(servicePrefix, payload.path), payload.query);
4731
- const headers = new Headers(payload.headers);
4732
- let body;
4733
- if (payload.body !== void 0) {
4734
- if (payload.body instanceof FormData) {
4735
- body = payload.body;
4736
- } else {
4737
- headers.set("Content-Type", headers.get("Content-Type") || "application/json");
4738
- body = JSON.stringify(payload.body);
4739
- }
4740
- }
4741
- const response = await fetchImpl(url2, {
4742
- method: normalizeMethod2(payload.method),
4743
- headers,
4744
- body,
4745
- credentials: "include"
4746
- });
4747
- return parseJsonResponse(response);
4748
- };
4749
- const download = async (payload) => {
4750
- if (!payload?.path) {
4751
- throw new Error("transport.download \u9700\u8981 path");
4752
- }
4753
- const url2 = appendQuery(joinServicePath(servicePrefix, payload.path), payload.query);
4754
- const headers = new Headers(payload.headers);
4755
- let body;
4756
- if (payload.body !== void 0) {
4757
- if (payload.body instanceof FormData) {
4758
- body = payload.body;
4759
- } else {
4760
- headers.set("Content-Type", headers.get("Content-Type") || "application/json");
4761
- body = JSON.stringify(payload.body);
4762
- }
4763
- }
4764
- const response = await fetchImpl(url2, {
4765
- method: normalizeMethod2(payload.method),
4766
- headers,
4767
- body,
4768
- credentials: "include"
4769
- });
4770
- if (!response.ok) {
4771
- throw new Error(response.statusText || "\u4E0B\u8F7D\u5931\u8D25");
4772
- }
4773
- return {
4774
- blob: await response.blob(),
4775
- contentType: response.headers.get("content-type") || void 0,
4776
- fileName: response.headers.get("content-disposition") || void 0,
4777
- headers: Object.fromEntries(response.headers.entries())
4778
- };
4779
- };
4780
- return {
4781
- invoke: async (method4, payload) => {
4782
- if (method4 === "transport.request") return await request(payload);
4783
- if (method4 === "transport.download") return await download(payload);
4784
- throw new Error(`\u4E0D\u652F\u6301\u7684 bridge \u65B9\u6CD5: ${method4}`);
4785
- }
4786
- };
4787
- };
4788
- var createBrowserPageContext = (bootstrap, options = {}) => {
4789
- const route = {
4790
- pathname: options.route?.pathname || (typeof window !== "undefined" ? window.location.pathname : ""),
4791
- fullPath: options.route?.fullPath || (typeof window !== "undefined" ? `${window.location.pathname}${window.location.search}${window.location.hash}` : ""),
4792
- params: options.route?.params || {},
4793
- query: options.route?.query || {},
4794
- hash: options.route?.hash || (typeof window !== "undefined" ? window.location.hash : "")
4795
- };
4796
- return {
4797
- protocolVersion: bootstrap.asset?.protocolVersion || "1.0",
4798
- app: bootstrap.app,
4799
- page: {
4800
- ...bootstrap.page,
4801
- version: bootstrap.asset?.version || bootstrap.page.version,
4802
- buildId: bootstrap.asset?.buildId || bootstrap.page.buildId
4803
- },
4804
- user: bootstrap.user,
4805
- route,
4806
- env: bootstrap.env || {},
4807
- permissions: {
4808
- canView: bootstrap.permissions?.canView !== false,
4809
- hasFullAccess: bootstrap.permissions?.hasFullAccess === true,
4810
- ...bootstrap.permissions || {}
4811
- },
4812
- capabilities: Array.from(
4813
- /* @__PURE__ */ new Set([
4814
- "navigation",
4815
- "ui.message",
4816
- "ui.modal",
4817
- "transport.request",
4818
- "transport.download",
4819
- ...bootstrap.sdk?.supportedBridgeMethods || []
4820
- ])
4821
- ),
4822
- ui: {
4823
- message: {
4824
- success: (text) => options.message?.success?.(text),
4825
- error: (text) => options.message?.error?.(text),
4826
- warning: (text) => options.message?.warning?.(text),
4827
- info: (text) => options.message?.info?.(text),
4828
- loading: (text) => options.message?.loading?.(text) || (() => void 0)
4829
- },
4830
- modal: {
4831
- confirm: (input) => options.modal?.confirm?.(input) || Promise.resolve(false)
4832
- }
4833
- },
4834
- navigation: {
4835
- pushPage: (pageKey, query) => options.navigation?.pushPage?.(pageKey, query),
4836
- replacePage: (pageKey, query) => options.navigation?.replacePage?.(pageKey, query),
4837
- pushRoute: (routeValue, query) => options.navigation?.pushRoute?.(routeValue, query),
4838
- replaceRoute: (routeValue, query) => options.navigation?.replaceRoute?.(routeValue, query),
4839
- updateQuery: (query) => options.navigation?.updateQuery?.(query),
4840
- setHash: (hash) => options.navigation?.setHash?.(hash),
4841
- back: () => options.navigation?.back?.()
4842
- },
4843
- bridge: createBrowserPageBridge(options),
4844
- sdk: {
4845
- ...bootstrap.sdk,
4846
- supportedBridgeMethods: ["transport.request", "transport.download"]
4847
- }
4848
- };
4849
- };
4850
- var resolveRuntimeAssets = async (bootstrap, fetchImpl = fetch) => {
4851
- const boundFetch = createBoundFetch(fetchImpl);
4852
- const fallback = {
4853
- entryUrl: bootstrap.runtimeAssets?.entryUrl || bootstrap.asset?.entryUrl || "",
4854
- cssUrls: bootstrap.runtimeAssets?.cssUrls || bootstrap.asset?.cssAssets || [],
4855
- jsUrls: bootstrap.runtimeAssets?.jsUrls || bootstrap.asset?.jsAssets || [],
4856
- cssIsolation: normalizeCssIsolation2(
4857
- bootstrap.runtimeAssets?.cssIsolation || bootstrap.page.capabilities?.cssIsolation
4858
- )
4859
- };
4860
- if (bootstrap.runtimeAssets?.entryUrl || !bootstrap.asset?.manifestUrl) {
4861
- return fallback;
4862
- }
4863
- try {
4864
- const response = await boundFetch(bootstrap.asset.manifestUrl, {
4865
- credentials: "omit"
4866
- });
4867
- if (!response.ok) return fallback;
4868
- const manifest = await response.json();
4869
- const base = bootstrap.asset.manifestUrl;
4870
- const resolveUrl = (value) => new URL(value, base).toString();
4871
- return {
4872
- entryUrl: manifest?.entry?.url ? resolveUrl(manifest.entry.url) : fallback.entryUrl,
4873
- cssUrls: Array.isArray(manifest?.assets?.css) ? manifest.assets.css.map(resolveUrl) : fallback.cssUrls,
4874
- jsUrls: Array.isArray(manifest?.assets?.js) ? manifest.assets.js.map(resolveUrl) : fallback.jsUrls,
4875
- cssIsolation: normalizeCssIsolation2(
4876
- manifest?.style?.isolation || fallback.cssIsolation
4877
- )
4878
- };
4879
- } catch {
4880
- return fallback;
4881
- }
4882
- };
4883
- var fetchBrowserRuntimeBootstrap = async ({
4884
- appType,
4885
- bootstrapPath,
4886
- fetchImpl = fetch,
4887
- pageKey,
4888
- servicePrefix
4889
- }) => {
4890
- if (!appType) {
4891
- throw new Error("appType \u7F3A\u5931");
4892
- }
4893
- if (!pageKey) {
4894
- throw new Error("pageKey \u7F3A\u5931");
4895
- }
4896
- const path = bootstrapPath || `/openxiangda-api/v1/apps/${encodeURIComponent(
4897
- appType
4898
- )}/pages/${encodeURIComponent(pageKey)}/bootstrap`;
4899
- const boundFetch = createBoundFetch(fetchImpl);
4900
- const response = await boundFetch(
4901
- joinServicePath(servicePrefix || getDefaultServicePrefix(), path),
4902
- {
4903
- method: "GET",
4904
- credentials: "include"
4905
- }
4906
- );
4907
- const payload = await response.json().catch(() => null);
4908
- if (!response.ok) {
4909
- throw new Error(payload?.message || response.statusText || "\u83B7\u53D6\u9875\u9762\u8FD0\u884C\u65F6\u5931\u8D25");
4910
- }
4911
- if (payload && typeof payload === "object" && ("code" in payload || "success" in payload)) {
4912
- if (payload.success === false || payload.code && Number(payload.code) !== 200) {
4913
- throw new Error(payload.message || "\u83B7\u53D6\u9875\u9762\u8FD0\u884C\u65F6\u5931\u8D25");
4914
- }
4915
- return payload.data || {};
4916
- }
4917
- return payload || {};
4918
- };
4919
- var resolveBrowserRuntimeRoute = async ({
4920
- appType,
4921
- fetchImpl = fetch,
4922
- path,
4923
- resolvePath,
4924
- search,
4925
- servicePrefix
4926
- }) => {
4927
- if (!appType) {
4928
- throw new Error("appType \u7F3A\u5931");
4929
- }
4930
- const currentPath = path || (typeof window !== "undefined" ? window.location.pathname : "/");
4931
- const currentSearch = search !== void 0 ? search : typeof window !== "undefined" ? window.location.search : "";
4932
- const endpoint = resolvePath || `/openxiangda-api/v1/apps/${encodeURIComponent(
4933
- appType
4934
- )}/runtime/routes/resolve`;
4935
- const boundFetch = createBoundFetch(fetchImpl);
4936
- const response = await boundFetch(
4937
- joinServicePath(servicePrefix || getDefaultServicePrefix(), endpoint),
4938
- {
4939
- method: "POST",
4940
- credentials: "include",
4941
- headers: {
4942
- "Content-Type": "application/json"
4943
- },
4944
- body: JSON.stringify({
4945
- path: currentPath,
4946
- search: currentSearch
4947
- })
4948
- }
4949
- );
4950
- const parsed = await parseJsonResponse(response);
4951
- if (!parsed.success || !parsed.result) {
4952
- throw new Error(parsed.message || "\u89E3\u6790\u8FD0\u884C\u65F6\u8DEF\u7531\u5931\u8D25");
4953
- }
4954
- return parsed.result;
4955
- };
4956
- var loadRuntimeScriptModules = async (jsUrls = [], moduleLoader = defaultModuleLoader) => {
4957
- const urls = Array.from(
4958
- new Set(jsUrls.map((url2) => String(url2 || "").trim()).filter(Boolean))
4959
- );
4960
- for (const url2 of urls) {
4961
- await moduleLoader(url2);
4962
- }
4963
- };
4964
- var loadCustomPageModule = async (entryUrl, moduleLoader = defaultModuleLoader, jsUrls = []) => {
4965
- if (!entryUrl) {
4966
- throw new Error("\u4EE3\u7801\u9875\u9762\u7F3A\u5C11 entryUrl");
4967
- }
4968
- await loadRuntimeScriptModules(
4969
- jsUrls.filter((url2) => url2 && url2 !== entryUrl),
4970
- moduleLoader
4971
- );
4972
- const loaded = await moduleLoader(entryUrl);
4973
- return loaded?.default && (loaded.default.mount || loaded.default.unmount) ? { ...loaded.default, ...loaded } : loaded || {};
4974
- };
4975
- var mountCustomPageRuntime = async ({
4976
- assets,
4977
- container,
4978
- context,
4979
- module: module2
4980
- }) => {
4981
- const cssIsolation = normalizeCssIsolation2(assets?.cssIsolation);
4982
- const mountedLinks = [];
4983
- container.innerHTML = "";
4984
- container.classList.toggle(NAMESPACE_ROOT_CLASS2, cssIsolation === "namespace");
4985
- (assets?.cssUrls || []).forEach((href) => {
4986
- const link = document.createElement("link");
4987
- link.rel = "stylesheet";
4988
- link.href = href;
4989
- link.setAttribute("data-openxiangda-runtime-style", href);
4990
- document.head.appendChild(link);
4991
- mountedLinks.push(link);
4992
- });
4993
- await module2.mount?.(container, context);
4994
- return async () => {
4995
- await module2.unmount?.(container, context);
4996
- mountedLinks.forEach((link) => link.remove());
4997
- container.classList.remove(NAMESPACE_ROOT_CLASS2);
4998
- container.innerHTML = "";
4999
- };
5000
- };
5001
- var mountBrowserPageRuntime = async (options) => {
5002
- const bootstrap = await fetchBrowserRuntimeBootstrap({
5003
- appType: options.appType,
5004
- pageKey: options.pageKey,
5005
- bootstrapPath: options.bootstrapPath,
5006
- fetchImpl: options.fetchImpl,
5007
- servicePrefix: options.servicePrefix
5008
- });
5009
- if (bootstrap.permissions?.canView === false) {
5010
- throw new Error(String(bootstrap.permissions.message || "\u60A8\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u8BE5\u9875\u9762"));
5011
- }
5012
- const assets = await resolveRuntimeAssets(bootstrap, options.fetchImpl || fetch);
5013
- if (!assets.entryUrl) {
5014
- throw new Error("\u4EE3\u7801\u9875\u9762\u7F3A\u5C11 entryUrl");
5015
- }
5016
- const context = createBrowserPageContext(bootstrap, options);
5017
- const module2 = await loadCustomPageModule(
5018
- assets.entryUrl,
5019
- options.moduleLoader,
5020
- assets.jsUrls
5021
- );
5022
- const cleanup2 = await mountCustomPageRuntime({
5023
- assets,
5024
- container: options.container,
5025
- context,
5026
- module: module2
5027
- });
5028
- return {
5029
- bootstrap,
5030
- assets,
5031
- context,
5032
- module: module2,
5033
- cleanup: cleanup2
5034
- };
5035
- };
5036
-
5037
5231
  // packages/sdk/src/runtime/host/builtinRouteRenderer.tsx
5038
5232
  init_cjs_shims();
5039
5233
  var import_react284 = require("react");
@@ -5072,6 +5266,11 @@ var joinUrl = (baseUrl, url2) => {
5072
5266
  if (/^https?:\/\//i.test(url2)) return url2;
5073
5267
  return `${trimTrailingSlash2(baseUrl)}${url2.startsWith("/") ? url2 : `/${url2}`}`;
5074
5268
  };
5269
+ var isSuccessCode6 = (value) => {
5270
+ if (value === void 0 || value === null || value === "") return true;
5271
+ const code = Number(value);
5272
+ return Number.isFinite(code) ? code === 0 || code >= 200 && code < 300 : false;
5273
+ };
5075
5274
  var normalizeRuntimeFileUrl = (baseUrl, value) => {
5076
5275
  if (typeof value !== "string" || !value) return value;
5077
5276
  if (/^(https?:)?\/\//i.test(value) || /^(blob|data):/i.test(value)) return value;
@@ -5098,6 +5297,12 @@ var parseResponse = async (response) => {
5098
5297
  const message7 = typeof payload === "object" && payload ? payload.message || payload.error || response.statusText : response.statusText;
5099
5298
  throw new Error(message7 || "\u8BF7\u6C42\u5931\u8D25");
5100
5299
  }
5300
+ if (typeof payload === "object" && payload) {
5301
+ const hasCode = Object.prototype.hasOwnProperty.call(payload, "code");
5302
+ if (payload.success === false || hasCode && !isSuccessCode6(payload.code)) {
5303
+ throw new Error(payload.message || payload.error || "\u8BF7\u6C42\u5931\u8D25");
5304
+ }
5305
+ }
5101
5306
  if (typeof payload === "object" && payload) {
5102
5307
  return payload;
5103
5308
  }
@@ -44324,20 +44529,20 @@ var import_react267 = require("react");
44324
44529
 
44325
44530
  // packages/sdk/src/components/core/processApi.ts
44326
44531
  init_cjs_shims();
44327
- var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
44328
- 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"));
44329
- var isSuccessCode = (code) => {
44532
+ var hasOwn2 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
44533
+ 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"));
44534
+ var isSuccessCode7 = (code) => {
44330
44535
  if (code === void 0 || code === null || code === "") return true;
44331
44536
  const normalized = Number(code);
44332
44537
  return Number.isFinite(normalized) ? normalized === 0 || normalized === 200 : false;
44333
44538
  };
44334
44539
  var unwrapRuntimeResponse = (response) => {
44335
44540
  if (!isRuntimeEnvelope(response)) return response;
44336
- if (response.success === false || !isSuccessCode(response.code)) {
44541
+ if (response.success === false || !isSuccessCode7(response.code)) {
44337
44542
  throw new Error(response.message || response.error || "\u8BF7\u6C42\u5931\u8D25");
44338
44543
  }
44339
- if (hasOwn(response, "data")) return response.data;
44340
- if (hasOwn(response, "result")) return response.result;
44544
+ if (hasOwn2(response, "data")) return response.data;
44545
+ if (hasOwn2(response, "result")) return response.result;
44341
44546
  return response;
44342
44547
  };
44343
44548
  var withInitiatorSelectedApprovers = (payload, initiatorSelectedApprovers) => {