openxiangda 1.0.37 → 1.0.38

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.
@@ -742,6 +742,15 @@ interface ConnectorInvokeResult<TResult = unknown> {
742
742
  }
743
743
  interface ConnectorCallParams<TBody = unknown> extends Omit<ConnectorInvokeParams<TBody>, "connector" | "api"> {
744
744
  }
745
+ interface AuthLogoutRedirectOptions {
746
+ loginUrl?: string;
747
+ callbackUrl?: string;
748
+ callbackParamName?: string;
749
+ replace?: boolean;
750
+ continueOnLogoutError?: boolean;
751
+ fallback?: "reload" | "none";
752
+ redirect?: (url: string) => void;
753
+ }
745
754
  interface PageSdk {
746
755
  context: PageContext;
747
756
  request<TResult = unknown, TRaw = TResult>(options: PageRequestOptions): Promise<PageApiResponse<TResult, TRaw>>;
@@ -750,6 +759,10 @@ interface PageSdk {
750
759
  request<TResult = unknown, TRaw = TResult>(options: PageRequestOptions): Promise<PageApiResponse<TResult, TRaw>>;
751
760
  download(options: PageRequestOptions): Promise<PageBinaryResponse>;
752
761
  };
762
+ auth: {
763
+ logout<T = boolean>(): Promise<PageApiResponse<T>>;
764
+ logoutAndRedirect<T = boolean>(options?: AuthLogoutRedirectOptions): Promise<PageApiResponse<T> | null>;
765
+ };
753
766
  connector: {
754
767
  invoke<TResult = unknown, TBody = unknown>(params: ConnectorInvokeParams<TBody>): Promise<PageApiResponse<ConnectorInvokeResult<TResult>>>;
755
768
  call<TResult = unknown, TBody = unknown>(name: string, params?: ConnectorCallParams<TBody>): Promise<PageApiResponse<ConnectorInvokeResult<TResult>>>;
@@ -948,4 +961,4 @@ declare const usePageRoute: () => PageRouteInfo;
948
961
 
949
962
  declare const usePageSdk: () => PageSdk;
950
963
 
951
- export { type ApiPermissionListParams, type ApproveTaskParams, type AssignPermissionsParams, type AssignRolesParams, type BatchAddUsersToRoleParams, type BatchSendNotificationByTypeParams, type ChangeUserRoleParams, type ConnectorCallParams, type ConnectorInvokeParams, type ConnectorInvokeResult, type ConnectorRequestBodyType, type ConnectorResponseType, type CreateApiPermissionParams, type CreateFormPermissionGroupDto, type CreatePagePermissionGroupDto, type CreateRoleParams, type CreateUiPermissionParams, type CreateUserParams, type CurrentUserDepartmentParents, type CustomPageEntryConfig, type CustomPageEntryMode, type DataManagementConfigParams, type DataManagementFilterState, type DataPermissionConditionDto, type DataPermissionDto, type DataPermissionRuleDto, type DataViewQueryParams, type DataViewQueryResult, type FieldPermissionDto, type FindNotificationConfigParams, type FormAdvancedSearchParams, type FormChangeRecordParams, type FormCreateParams, type FormExportParams, type FormGetDetailParams, type FormImportParams, type FormPermissionGroup, type FormRemoveParams, type FormSearchParams, type FormUpdateParams, type GetParentDepartmentsOptions, type GetProcessInstanceParams, type GetUserRolesParams, type ImportExportRecordDownloadParams, type ImportExportRecordQuery, type InstanceStatus, type NotificationChannel, type NotificationChannelConfig, type NotificationChannelsConfig, type NotificationConfigLevel, type NotificationMessageRecord, type NotificationTemplate, type NotificationTemplatePreview, type NotificationTypeConfig, type PageApiPermissionRecord, type PageApiResponse, type PageAppInfo, type PageBinaryResponse, type PageBridgeApi, type PageContext, type PageDataManagementConfig, type PageDataSourceDescriptor, type PageDepartmentInfo, type PageDepartmentRecord, type PageHttpMethod, type PageInfo, type PageListResult, type PageMessageApi, type PageModalApi, type PageNavigationApi, type PageOffsetListResult, type PagePermissionGroup, type PagePermissionInfo, PageProvider, type PageQueryValue, type PageRequestOptions, type PageRoleRecord, type PageRouteInfo, type PageScope, type PageSdk, type PageSdkError, type PageSdkMeta, type PageTransportDownloadPayload, type PageTransportRequestPayload, type PageUiPermissionRecord, type PageUiPermissionType, type PageUserInfo, type PageUserRecord, type PageUserType, type PreviewNotificationTemplateParams, type ProcessApproveAction, type QueryFormPermissionGroupDto, type QueryPagePermissionGroupDto, type RoleListParams, type RoleUsersParams, type SaveDataManagementConfigParams, type SearchComponentName, type SearchExpression, type SearchFieldKey, type SearchGroup, type SearchLogic, type SearchOperator, type SearchRule, type SearchSortItem, type SearchSystemField, type SendNotificationByTypeParams, type SendNotificationResult, type SubFormRule, type SwitchAppRoleParams, type SwitchPlatformRoleParams, type TerminateProcessInstanceParams, type TriggerCallbackTaskParams, type UiPermissionListParams, type UpdateApiPermissionParams, type UpdateFormPermissionGroupDto, type UpdatePagePermissionGroupDto, type UpdateRoleParams, type UpdateUiPermissionParams, type UpdateUserParams, type UserListParams, type UserMenuPermissionsResponse, type ValidateUserParams, type ViewFieldPermissionValue, type ViewOperationPermission, type ViewPermissionSummary, createPageSdk, createReactPage, useCurrentUser, useDataSource, useFormViewPermissions, useMessage, useModal, useNavigation, usePageContext, usePageProps, usePageRoute, usePageSdk };
964
+ export { type ApiPermissionListParams, type ApproveTaskParams, type AssignPermissionsParams, type AssignRolesParams, type AuthLogoutRedirectOptions, type BatchAddUsersToRoleParams, type BatchSendNotificationByTypeParams, type ChangeUserRoleParams, type ConnectorCallParams, type ConnectorInvokeParams, type ConnectorInvokeResult, type ConnectorRequestBodyType, type ConnectorResponseType, type CreateApiPermissionParams, type CreateFormPermissionGroupDto, type CreatePagePermissionGroupDto, type CreateRoleParams, type CreateUiPermissionParams, type CreateUserParams, type CurrentUserDepartmentParents, type CustomPageEntryConfig, type CustomPageEntryMode, type DataManagementConfigParams, type DataManagementFilterState, type DataPermissionConditionDto, type DataPermissionDto, type DataPermissionRuleDto, type DataViewQueryParams, type DataViewQueryResult, type FieldPermissionDto, type FindNotificationConfigParams, type FormAdvancedSearchParams, type FormChangeRecordParams, type FormCreateParams, type FormExportParams, type FormGetDetailParams, type FormImportParams, type FormPermissionGroup, type FormRemoveParams, type FormSearchParams, type FormUpdateParams, type GetParentDepartmentsOptions, type GetProcessInstanceParams, type GetUserRolesParams, type ImportExportRecordDownloadParams, type ImportExportRecordQuery, type InstanceStatus, type NotificationChannel, type NotificationChannelConfig, type NotificationChannelsConfig, type NotificationConfigLevel, type NotificationMessageRecord, type NotificationTemplate, type NotificationTemplatePreview, type NotificationTypeConfig, type PageApiPermissionRecord, type PageApiResponse, type PageAppInfo, type PageBinaryResponse, type PageBridgeApi, type PageContext, type PageDataManagementConfig, type PageDataSourceDescriptor, type PageDepartmentInfo, type PageDepartmentRecord, type PageHttpMethod, type PageInfo, type PageListResult, type PageMessageApi, type PageModalApi, type PageNavigationApi, type PageOffsetListResult, type PagePermissionGroup, type PagePermissionInfo, PageProvider, type PageQueryValue, type PageRequestOptions, type PageRoleRecord, type PageRouteInfo, type PageScope, type PageSdk, type PageSdkError, type PageSdkMeta, type PageTransportDownloadPayload, type PageTransportRequestPayload, type PageUiPermissionRecord, type PageUiPermissionType, type PageUserInfo, type PageUserRecord, type PageUserType, type PreviewNotificationTemplateParams, type ProcessApproveAction, type QueryFormPermissionGroupDto, type QueryPagePermissionGroupDto, type RoleListParams, type RoleUsersParams, type SaveDataManagementConfigParams, type SearchComponentName, type SearchExpression, type SearchFieldKey, type SearchGroup, type SearchLogic, type SearchOperator, type SearchRule, type SearchSortItem, type SearchSystemField, type SendNotificationByTypeParams, type SendNotificationResult, type SubFormRule, type SwitchAppRoleParams, type SwitchPlatformRoleParams, type TerminateProcessInstanceParams, type TriggerCallbackTaskParams, type UiPermissionListParams, type UpdateApiPermissionParams, type UpdateFormPermissionGroupDto, type UpdatePagePermissionGroupDto, type UpdateRoleParams, type UpdateUiPermissionParams, type UpdateUserParams, type UserListParams, type UserMenuPermissionsResponse, type ValidateUserParams, type ViewFieldPermissionValue, type ViewOperationPermission, type ViewPermissionSummary, createPageSdk, createReactPage, useCurrentUser, useDataSource, useFormViewPermissions, useMessage, useModal, useNavigation, usePageContext, usePageProps, usePageRoute, usePageSdk };
@@ -313,6 +313,99 @@ var withDefaultAppType = (context, params) => {
313
313
  }
314
314
  return params;
315
315
  };
316
+ var AUTH_LOGIN_URL_ENV_KEYS = [
317
+ "loginUrl",
318
+ "authLoginUrl",
319
+ "bathAuthUrl",
320
+ "REACT_APP_VITE_BATH_AUTH_URL",
321
+ "VITE_BATH_AUTH_URL",
322
+ "BATH_AUTH_URL"
323
+ ];
324
+ var normalizeOptionalString = (value) => {
325
+ const text = typeof value === "string" ? value.trim() : "";
326
+ return text || void 0;
327
+ };
328
+ var getCurrentHref = () => {
329
+ if (typeof window === "undefined") {
330
+ return "";
331
+ }
332
+ return window.location?.href || "";
333
+ };
334
+ var resolveAuthLoginUrl = (context, options) => {
335
+ const explicitLoginUrl = normalizeOptionalString(options.loginUrl);
336
+ if (explicitLoginUrl) {
337
+ return explicitLoginUrl;
338
+ }
339
+ for (const key of AUTH_LOGIN_URL_ENV_KEYS) {
340
+ const loginUrl = normalizeOptionalString(context.env?.[key]);
341
+ if (loginUrl) {
342
+ return loginUrl;
343
+ }
344
+ }
345
+ return void 0;
346
+ };
347
+ var buildAuthRedirectUrl = (loginUrl, callbackUrl, callbackParamName) => {
348
+ const paramName = normalizeOptionalString(callbackParamName) || "callback";
349
+ const normalizedCallbackUrl = normalizeOptionalString(callbackUrl);
350
+ if (!normalizedCallbackUrl) {
351
+ return loginUrl;
352
+ }
353
+ const baseHref = getCurrentHref() || "http://localhost/";
354
+ const isAbsoluteUrl = /^[a-z][a-z\d+.-]*:/i.test(loginUrl);
355
+ const isProtocolRelativeUrl = loginUrl.startsWith("//");
356
+ const isRootRelativeUrl = loginUrl.startsWith("/");
357
+ try {
358
+ const url = new URL(loginUrl, baseHref);
359
+ url.searchParams.set(paramName, normalizedCallbackUrl);
360
+ if (isAbsoluteUrl || isProtocolRelativeUrl) {
361
+ return url.toString();
362
+ }
363
+ const path = `${url.pathname}${url.search}${url.hash}`;
364
+ return isRootRelativeUrl ? path : path.replace(/^\//, "");
365
+ } catch {
366
+ const hashIndex = loginUrl.indexOf("#");
367
+ const pathAndQuery = hashIndex >= 0 ? loginUrl.slice(0, hashIndex) : loginUrl;
368
+ const hash = hashIndex >= 0 ? loginUrl.slice(hashIndex) : "";
369
+ const separator = pathAndQuery.includes("?") ? "&" : "?";
370
+ return `${pathAndQuery}${separator}${encodeURIComponent(
371
+ paramName
372
+ )}=${encodeURIComponent(normalizedCallbackUrl)}${hash}`;
373
+ }
374
+ };
375
+ var performRedirect = (url, options) => {
376
+ if (options.redirect) {
377
+ options.redirect(url);
378
+ return;
379
+ }
380
+ if (typeof window === "undefined" || !window.location) {
381
+ return;
382
+ }
383
+ if (options.replace && typeof window.location.replace === "function") {
384
+ window.location.replace(url);
385
+ return;
386
+ }
387
+ window.location.href = url;
388
+ };
389
+ var reloadCurrentPage = () => {
390
+ if (typeof window === "undefined" || !window.location || typeof window.location.reload !== "function") {
391
+ return;
392
+ }
393
+ window.location.reload();
394
+ };
395
+ var redirectAfterLogout = (context, options) => {
396
+ const loginUrl = resolveAuthLoginUrl(context, options);
397
+ const callbackUrl = normalizeOptionalString(options.callbackUrl) || getCurrentHref();
398
+ if (loginUrl) {
399
+ performRedirect(
400
+ buildAuthRedirectUrl(loginUrl, callbackUrl, options.callbackParamName),
401
+ options
402
+ );
403
+ return;
404
+ }
405
+ if (options.fallback !== "none") {
406
+ reloadCurrentPage();
407
+ }
408
+ };
316
409
  var createPageSdk = (context) => {
317
410
  const request = async (options) => {
318
411
  const payload = {
@@ -353,6 +446,26 @@ var createPageSdk = (context) => {
353
446
  throw toSdkError(error, payload);
354
447
  }
355
448
  };
449
+ const logout = () => request({
450
+ path: "/api/auth/logout",
451
+ method: "post"
452
+ });
453
+ const auth = {
454
+ logout,
455
+ logoutAndRedirect: async (options = {}) => {
456
+ try {
457
+ const response = await logout();
458
+ redirectAfterLogout(context, options);
459
+ return response;
460
+ } catch (error) {
461
+ if (options.continueOnLogoutError === false) {
462
+ throw error;
463
+ }
464
+ redirectAfterLogout(context, options);
465
+ return null;
466
+ }
467
+ }
468
+ };
356
469
  const connector = {
357
470
  invoke: (params) => request({
358
471
  path: buildAppPath(
@@ -1110,6 +1223,7 @@ var createPageSdk = (context) => {
1110
1223
  request,
1111
1224
  download
1112
1225
  },
1226
+ auth,
1113
1227
  connector,
1114
1228
  form,
1115
1229
  user,