openxiangda 1.0.55 → 1.0.57

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.
@@ -3219,6 +3219,14 @@ import {
3219
3219
  useMemo as useMemo4,
3220
3220
  useState as useState3
3221
3221
  } from "react";
3222
+
3223
+ // packages/sdk/src/runtime/core/fetch.ts
3224
+ var createBoundFetch = (fetchImpl) => {
3225
+ const baseFetch = fetchImpl || globalThis.fetch;
3226
+ return ((input, init) => baseFetch.call(globalThis, input, init));
3227
+ };
3228
+
3229
+ // packages/sdk/src/runtime/react/openxiangdaProvider.tsx
3222
3230
  import { Fragment as Fragment2, jsx as jsx3 } from "react/jsx-runtime";
3223
3231
  var OpenXiangdaRuntimeContext = createContext2(null);
3224
3232
  var OpenXiangdaProvider = ({
@@ -3227,7 +3235,7 @@ var OpenXiangdaProvider = ({
3227
3235
  fetchImpl,
3228
3236
  children
3229
3237
  }) => {
3230
- const resolvedFetch = fetchImpl || fetch;
3238
+ const resolvedFetch = useMemo4(() => createBoundFetch(fetchImpl), [fetchImpl]);
3231
3239
  const resolvedAppType = useMemo4(
3232
3240
  () => appType || resolveAppTypeFromLocation(),
3233
3241
  [appType]
@@ -3478,7 +3486,7 @@ var parseJsonResponse = async (response) => {
3478
3486
  };
3479
3487
  var createBrowserPageBridge = (options = {}) => {
3480
3488
  const servicePrefix = options.servicePrefix || getDefaultServicePrefix();
3481
- const fetchImpl = options.fetchImpl || fetch;
3489
+ const fetchImpl = createBoundFetch(options.fetchImpl);
3482
3490
  const request = async (payload) => {
3483
3491
  if (!payload?.path) {
3484
3492
  throw new Error("transport.request \u9700\u8981 path");
@@ -3604,6 +3612,7 @@ var createBrowserPageContext = (bootstrap, options = {}) => {
3604
3612
  };
3605
3613
  };
3606
3614
  var resolveRuntimeAssets = async (bootstrap, fetchImpl = fetch) => {
3615
+ const boundFetch = createBoundFetch(fetchImpl);
3607
3616
  const fallback = {
3608
3617
  entryUrl: bootstrap.runtimeAssets?.entryUrl || bootstrap.asset?.entryUrl || "",
3609
3618
  cssUrls: bootstrap.runtimeAssets?.cssUrls || bootstrap.asset?.cssAssets || [],
@@ -3616,7 +3625,7 @@ var resolveRuntimeAssets = async (bootstrap, fetchImpl = fetch) => {
3616
3625
  return fallback;
3617
3626
  }
3618
3627
  try {
3619
- const response = await fetchImpl(bootstrap.asset.manifestUrl, {
3628
+ const response = await boundFetch(bootstrap.asset.manifestUrl, {
3620
3629
  credentials: "omit"
3621
3630
  });
3622
3631
  if (!response.ok) return fallback;
@@ -3651,7 +3660,8 @@ var fetchBrowserRuntimeBootstrap = async ({
3651
3660
  const path = bootstrapPath || `/openxiangda-api/v1/apps/${encodeURIComponent(
3652
3661
  appType
3653
3662
  )}/pages/${encodeURIComponent(pageKey)}/bootstrap`;
3654
- const response = await fetchImpl(
3663
+ const boundFetch = createBoundFetch(fetchImpl);
3664
+ const response = await boundFetch(
3655
3665
  joinServicePath(servicePrefix || getDefaultServicePrefix(), path),
3656
3666
  {
3657
3667
  method: "GET",
@@ -3686,7 +3696,8 @@ var resolveBrowserRuntimeRoute = async ({
3686
3696
  const endpoint = resolvePath || `/openxiangda-api/v1/apps/${encodeURIComponent(
3687
3697
  appType
3688
3698
  )}/runtime/routes/resolve`;
3689
- const response = await fetchImpl(
3699
+ const boundFetch = createBoundFetch(fetchImpl);
3700
+ const response = await boundFetch(
3690
3701
  joinServicePath(servicePrefix || getDefaultServicePrefix(), endpoint),
3691
3702
  {
3692
3703
  method: "POST",
@@ -49226,6 +49237,7 @@ var parseRuntimeResponse = async (response) => {
49226
49237
  return await response.json();
49227
49238
  };
49228
49239
  var createBuiltinRouteRequest = (servicePrefix = DEFAULT_SERVICE_PREFIX, fetchImpl = fetch) => async (config3) => {
49240
+ const boundFetch = createBoundFetch(fetchImpl);
49229
49241
  const headers = new Headers(config3.headers);
49230
49242
  let body;
49231
49243
  if (config3.data !== void 0) {
@@ -49236,7 +49248,7 @@ var createBuiltinRouteRequest = (servicePrefix = DEFAULT_SERVICE_PREFIX, fetchIm
49236
49248
  body = JSON.stringify(config3.data);
49237
49249
  }
49238
49250
  }
49239
- const response = await fetchImpl(appendQuery3(joinServicePath2(servicePrefix, config3.url), config3.params), {
49251
+ const response = await boundFetch(appendQuery3(joinServicePath2(servicePrefix, config3.url), config3.params), {
49240
49252
  method: normalizeMethod3(config3.method),
49241
49253
  headers,
49242
49254
  body,