openxiangda 1.0.87 → 1.0.88

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.
@@ -1292,6 +1292,9 @@ interface RuntimeRequestState<T> {
1292
1292
  loading: boolean;
1293
1293
  error: RuntimeRequestError | null;
1294
1294
  }
1295
+ interface RuntimeReloadOptions {
1296
+ accessToken?: string | null;
1297
+ }
1295
1298
  interface OpenXiangdaProviderProps {
1296
1299
  appType?: string;
1297
1300
  servicePrefix?: string;
@@ -1302,7 +1305,8 @@ interface OpenXiangdaRuntimeStore extends RuntimeRequestState<RuntimeBootstrap>
1302
1305
  appType: string;
1303
1306
  servicePrefix: string;
1304
1307
  fetchImpl: typeof fetch;
1305
- reload: () => Promise<void>;
1308
+ reload: (options?: RuntimeReloadOptions) => Promise<void>;
1309
+ setAccessToken: (accessToken?: string | null) => void;
1306
1310
  }
1307
1311
  declare const OpenXiangdaProvider: React__default.FC<OpenXiangdaProviderProps>;
1308
1312
  declare const useOpenXiangda: () => OpenXiangdaRuntimeStore;
@@ -1312,7 +1316,8 @@ declare const useAppMenus: () => {
1312
1316
  appType: string;
1313
1317
  servicePrefix: string;
1314
1318
  fetchImpl: typeof fetch;
1315
- reload: () => Promise<void>;
1319
+ reload: (options?: RuntimeReloadOptions) => Promise<void>;
1320
+ setAccessToken: (accessToken?: string | null) => void;
1316
1321
  loading: boolean;
1317
1322
  error: RuntimeRequestError | null;
1318
1323
  };
@@ -1321,7 +1326,8 @@ declare const usePermission: () => {
1321
1326
  appType: string;
1322
1327
  servicePrefix: string;
1323
1328
  fetchImpl: typeof fetch;
1324
- reload: () => Promise<void>;
1329
+ reload: (options?: RuntimeReloadOptions) => Promise<void>;
1330
+ setAccessToken: (accessToken?: string | null) => void;
1325
1331
  loading: boolean;
1326
1332
  error: RuntimeRequestError | null;
1327
1333
  };
@@ -1292,6 +1292,9 @@ interface RuntimeRequestState<T> {
1292
1292
  loading: boolean;
1293
1293
  error: RuntimeRequestError | null;
1294
1294
  }
1295
+ interface RuntimeReloadOptions {
1296
+ accessToken?: string | null;
1297
+ }
1295
1298
  interface OpenXiangdaProviderProps {
1296
1299
  appType?: string;
1297
1300
  servicePrefix?: string;
@@ -1302,7 +1305,8 @@ interface OpenXiangdaRuntimeStore extends RuntimeRequestState<RuntimeBootstrap>
1302
1305
  appType: string;
1303
1306
  servicePrefix: string;
1304
1307
  fetchImpl: typeof fetch;
1305
- reload: () => Promise<void>;
1308
+ reload: (options?: RuntimeReloadOptions) => Promise<void>;
1309
+ setAccessToken: (accessToken?: string | null) => void;
1306
1310
  }
1307
1311
  declare const OpenXiangdaProvider: React__default.FC<OpenXiangdaProviderProps>;
1308
1312
  declare const useOpenXiangda: () => OpenXiangdaRuntimeStore;
@@ -1312,7 +1316,8 @@ declare const useAppMenus: () => {
1312
1316
  appType: string;
1313
1317
  servicePrefix: string;
1314
1318
  fetchImpl: typeof fetch;
1315
- reload: () => Promise<void>;
1319
+ reload: (options?: RuntimeReloadOptions) => Promise<void>;
1320
+ setAccessToken: (accessToken?: string | null) => void;
1316
1321
  loading: boolean;
1317
1322
  error: RuntimeRequestError | null;
1318
1323
  };
@@ -1321,7 +1326,8 @@ declare const usePermission: () => {
1321
1326
  appType: string;
1322
1327
  servicePrefix: string;
1323
1328
  fetchImpl: typeof fetch;
1324
- reload: () => Promise<void>;
1329
+ reload: (options?: RuntimeReloadOptions) => Promise<void>;
1330
+ setAccessToken: (accessToken?: string | null) => void;
1325
1331
  loading: boolean;
1326
1332
  error: RuntimeRequestError | null;
1327
1333
  };
@@ -3112,12 +3112,23 @@ var OpenXiangdaProvider = ({
3112
3112
  () => appType || resolveAppTypeFromLocation(),
3113
3113
  [appType]
3114
3114
  );
3115
+ const [accessToken, setAccessTokenState] = useState4(null);
3116
+ const setAccessToken = useCallback4(
3117
+ (nextAccessToken) => {
3118
+ setAccessTokenState(nextAccessToken || null);
3119
+ },
3120
+ []
3121
+ );
3122
+ const authorizedFetch = useMemo5(
3123
+ () => createAuthorizedFetch(resolvedFetch, accessToken),
3124
+ [accessToken, resolvedFetch]
3125
+ );
3115
3126
  const [state, setState] = useState4({
3116
3127
  data: null,
3117
3128
  loading: true,
3118
3129
  error: null
3119
3130
  });
3120
- const reload = useCallback4(async () => {
3131
+ const reload = useCallback4(async (options = {}) => {
3121
3132
  if (!resolvedAppType) {
3122
3133
  setState({
3123
3134
  data: null,
@@ -3130,8 +3141,9 @@ var OpenXiangdaProvider = ({
3130
3141
  return;
3131
3142
  }
3132
3143
  setState((prev) => ({ ...prev, loading: true, error: null }));
3144
+ const requestFetch = options.accessToken !== void 0 ? createAuthorizedFetch(resolvedFetch, options.accessToken || null) : authorizedFetch;
3133
3145
  try {
3134
- const response = await resolvedFetch(
3146
+ const response = await requestFetch(
3135
3147
  buildServiceUrl2(
3136
3148
  servicePrefix,
3137
3149
  `/openxiangda-api/v1/apps/${encodeURIComponent(
@@ -3163,7 +3175,7 @@ var OpenXiangdaProvider = ({
3163
3175
  error: normalizeRuntimeError(error)
3164
3176
  });
3165
3177
  }
3166
- }, [resolvedAppType, resolvedFetch, servicePrefix]);
3178
+ }, [authorizedFetch, resolvedAppType, resolvedFetch, servicePrefix]);
3167
3179
  useEffect4(() => {
3168
3180
  void reload();
3169
3181
  }, [reload]);
@@ -3172,10 +3184,11 @@ var OpenXiangdaProvider = ({
3172
3184
  ...state,
3173
3185
  appType: resolvedAppType,
3174
3186
  servicePrefix,
3175
- fetchImpl: resolvedFetch,
3176
- reload
3187
+ fetchImpl: authorizedFetch,
3188
+ reload,
3189
+ setAccessToken
3177
3190
  }),
3178
- [reload, resolvedAppType, resolvedFetch, servicePrefix, state]
3191
+ [authorizedFetch, reload, resolvedAppType, servicePrefix, state]
3179
3192
  );
3180
3193
  return /* @__PURE__ */ jsx4(OpenXiangdaRuntimeContext.Provider, { value, children });
3181
3194
  };
@@ -3442,6 +3455,19 @@ var buildServiceUrl2 = (servicePrefix, path) => {
3442
3455
  const suffix = path.startsWith("/") ? path : `/${path}`;
3443
3456
  return `${prefix}${suffix}`;
3444
3457
  };
3458
+ var createAuthorizedFetch = (baseFetch, accessToken) => {
3459
+ if (!accessToken) return baseFetch;
3460
+ return ((input, init = {}) => {
3461
+ const headers = new Headers(init.headers || {});
3462
+ if (!headers.has("authorization")) {
3463
+ headers.set("authorization", `Bearer ${accessToken}`);
3464
+ }
3465
+ return baseFetch(input, {
3466
+ ...init,
3467
+ headers
3468
+ });
3469
+ });
3470
+ };
3445
3471
  var readJsonPayload = async (response) => {
3446
3472
  try {
3447
3473
  return await response.json();
@@ -3673,7 +3699,8 @@ var usePublicAccess = (options = {}) => {
3673
3699
  appType: runtimeAppType,
3674
3700
  servicePrefix: runtimeServicePrefix,
3675
3701
  fetchImpl: runtimeFetchImpl,
3676
- reload: reloadRuntime
3702
+ reload: reloadRuntime,
3703
+ setAccessToken
3677
3704
  } = runtime;
3678
3705
  const {
3679
3706
  appType = runtimeAppType,
@@ -3707,7 +3734,8 @@ var usePublicAccess = (options = {}) => {
3707
3734
  path: input.path || stableSessionInput.path || readPathFromLocation()
3708
3735
  });
3709
3736
  setSession(data);
3710
- await reloadRuntime();
3737
+ setAccessToken(data.accessToken);
3738
+ await reloadRuntime({ accessToken: data.accessToken });
3711
3739
  setLoading(false);
3712
3740
  return data;
3713
3741
  } catch (caught) {
@@ -3720,7 +3748,7 @@ var usePublicAccess = (options = {}) => {
3720
3748
  throw nextError;
3721
3749
  }
3722
3750
  },
3723
- [client, reloadRuntime, stableSessionInput]
3751
+ [client, reloadRuntime, setAccessToken, stableSessionInput]
3724
3752
  );
3725
3753
  useEffect5(() => {
3726
3754
  if (!autoStart) return;