com-angel-authorization 1.0.4 → 1.0.6

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.
@@ -127,11 +127,16 @@ type ListPaginationResult = {
127
127
  hasPreviousPage: boolean;
128
128
  hasNextPage: boolean;
129
129
  };
130
- /** 权限点状态:1 启用,0 禁用 */
130
+ /** 通用状态:权限点 1 启用 / 0 禁用;菜单 1 显示 / 0 隐藏 */
131
131
  type ResourceStatus = 0 | 1;
132
+ /** 权限点类型 */
133
+ type ApiResourceType = 'api';
134
+ /** 菜单资源类型 */
135
+ type MenuResourceType = 'page' | 'menu' | 'button';
136
+ type ResourceType = ApiResourceType | MenuResourceType;
132
137
  type AuthorizationResource = {
133
138
  resourceId: string;
134
- type: 'api';
139
+ type: ApiResourceType;
135
140
  name: string;
136
141
  identification: string;
137
142
  status: ResourceStatus;
@@ -147,10 +152,10 @@ type AuthorizationResourceFormValues = {
147
152
  };
148
153
  type CreateAuthorizationResourceBody = AuthorizationResourceFormValues & {
149
154
  resourceId: string;
150
- type: 'api';
155
+ type: ApiResourceType;
151
156
  };
152
157
  type UpdateAuthorizationResourceBody = Partial<AuthorizationResourceFormValues> & {
153
- type?: 'api';
158
+ type?: ApiResourceType;
154
159
  };
155
160
  type FetchAuthorizationResourcesParams = {
156
161
  pagination?: ListPaginationParams;
@@ -161,17 +166,65 @@ type AuthorizationResourceListResult = {
161
166
  hasPreviousPage: boolean;
162
167
  hasNextPage: boolean;
163
168
  };
164
- declare const RESOURCE_TYPE_API: "api";
169
+ type MenuResource = {
170
+ resourceId: string;
171
+ parentId: string;
172
+ type: MenuResourceType;
173
+ name: string;
174
+ identification: string;
175
+ permissionPointIds: string[];
176
+ /** 关联权限点名称(列表展示用,后端可能返回) */
177
+ permissionPointNames?: string[];
178
+ status: ResourceStatus;
179
+ };
180
+ type MenuResourceFormValues = {
181
+ parentId: string;
182
+ type: MenuResourceType;
183
+ name: string;
184
+ identification: string;
185
+ permissionPointIds: string[];
186
+ status: ResourceStatus;
187
+ };
188
+ type CreateMenuResourceBody = MenuResourceFormValues & {
189
+ resourceId: string;
190
+ };
191
+ type UpdateMenuResourceBody = Partial<MenuResourceFormValues>;
192
+ type FetchMenuResourcesParams = {
193
+ pagination?: ListPaginationParams;
194
+ };
195
+ type MenuResourceListResult = {
196
+ records: MenuResource[];
197
+ pageToken: string;
198
+ hasPreviousPage: boolean;
199
+ hasNextPage: boolean;
200
+ };
201
+ declare const RESOURCE_TYPE_API: ApiResourceType;
202
+ declare const MENU_TYPE_PAGE: MenuResourceType;
203
+ declare const MENU_TYPE_MENU: MenuResourceType;
204
+ declare const MENU_TYPE_BUTTON: MenuResourceType;
205
+ /** 菜单列表查询 type 参数 */
206
+ declare const MENU_LIST_TYPE_PARAM = "page,menu,button";
207
+ declare const ROOT_PARENT_ID = "0";
165
208
  declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
166
209
  declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
167
210
  declare const RESOURCE_STATUS_OPTIONS: {
168
211
  label: string;
169
212
  value: ResourceStatus;
170
213
  }[];
214
+ /** 菜单可见性 */
215
+ declare const MENU_VISIBILITY_OPTIONS: {
216
+ label: string;
217
+ value: ResourceStatus;
218
+ }[];
171
219
  declare const RESOURCE_PRIVATE_OPTIONS: {
172
220
  label: string;
173
221
  value: boolean;
174
222
  }[];
223
+ declare const MENU_TYPE_OPTIONS: {
224
+ label: string;
225
+ value: MenuResourceType;
226
+ }[];
227
+ declare const MENU_TYPE_LABEL: Record<MenuResourceType, string>;
175
228
 
176
229
  type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE';
177
230
  type ResourceRequestOptions = {
@@ -190,10 +243,22 @@ type AuthorizationResourceApi = {
190
243
  update: (resourceId: string, values: AuthorizationResourceFormValues, signal?: AbortSignal) => Promise<unknown>;
191
244
  remove: (resourceId: string, signal?: AbortSignal) => Promise<unknown>;
192
245
  };
246
+ type MenuResourceApi = {
247
+ list: (params?: FetchMenuResourcesParams, signal?: AbortSignal) => Promise<MenuResourceListResult>;
248
+ /** 拉取权限点(type=api),供菜单表单多选 */
249
+ listPermissionPoints: (params?: FetchAuthorizationResourcesParams, signal?: AbortSignal) => Promise<AuthorizationResourceListResult>;
250
+ create: (values: MenuResourceFormValues, signal?: AbortSignal) => Promise<unknown>;
251
+ update: (resourceId: string, values: MenuResourceFormValues, signal?: AbortSignal) => Promise<unknown>;
252
+ remove: (resourceId: string, signal?: AbortSignal) => Promise<unknown>;
253
+ };
193
254
  declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
255
+ declare function mapMenuResource(item: unknown): MenuResource | null;
194
256
  declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
195
257
  declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
258
+ declare function buildCreateMenuBody(values: MenuResourceFormValues, resourceId?: string): CreateMenuResourceBody;
259
+ declare function buildUpdateMenuBody(values: MenuResourceFormValues): UpdateMenuResourceBody;
196
260
  declare function createAuthorizationResourceApi(request: ResourceHttpRequest): AuthorizationResourceApi;
261
+ declare function createMenuResourceApi(request: ResourceHttpRequest): MenuResourceApi;
197
262
  type CreateDefaultResourceRequestOptions = {
198
263
  /** API 前缀,如 `/api` 或完整域名 */
199
264
  baseUrl?: string;
@@ -220,6 +285,14 @@ type ResourceManagerProps = {
220
285
  };
221
286
  declare function ResourceManager({ api, title, pageSize: initialPageSize, toolbarExtra, }: ResourceManagerProps): react.JSX.Element;
222
287
 
288
+ type MenuManagerProps = {
289
+ api: MenuResourceApi;
290
+ title?: string;
291
+ pageSize?: string;
292
+ toolbarExtra?: ReactNode;
293
+ };
294
+ declare function MenuManager({ api, title, pageSize: initialPageSize, toolbarExtra, }: MenuManagerProps): react.JSX.Element;
295
+
223
296
  interface SnowyflakeOptions {
224
297
  epoch?: bigint;
225
298
  workerId?: bigint;
@@ -250,4 +323,4 @@ declare const snowyflake: ConfigurableSnowflake;
250
323
  declare function getAppClientId(): string;
251
324
  declare function getDeviceWorkerId(): string;
252
325
 
253
- export { type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, type CanProps, type CheckOptions, type CreateAuthorizationResourceBody, type CreateDefaultResourceRequestOptions, type FetchAuthorizationResourcesParams, type HttpMethod, type ListPaginationParams, type ListPaginationResult, type MatchMode, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionListener, PermissionProvider, type PermissionProviderProps, type PermissionState, PermissionStore, RESOURCE_PRIVATE_OPTIONS, RESOURCE_STATUS_DISABLED, RESOURCE_STATUS_ENABLED, RESOURCE_STATUS_OPTIONS, RESOURCE_TYPE_API, type ResourceHttpRequest, ResourceManager, type ResourceManagerProps, type ResourceRequestOptions, type ResourceStatus, type RoleCode, type UpdateAuthorizationResourceBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildUpdateBody, createAuthorizationResourceApi, createDefaultResourceRequest, createPermissionStore, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, mapAuthorizationResource, snowyflake, useHasPermission, useHasRole, usePermission };
326
+ export { type ApiResourceType, type AuthorizationResource, type AuthorizationResourceApi, type AuthorizationResourceFormValues, type AuthorizationResourceListResult, Can, type CanProps, type CheckOptions, type CreateAuthorizationResourceBody, type CreateDefaultResourceRequestOptions, type CreateMenuResourceBody, type FetchAuthorizationResourcesParams, type FetchMenuResourcesParams, type HttpMethod, type ListPaginationParams, type ListPaginationResult, MENU_LIST_TYPE_PARAM, MENU_TYPE_BUTTON, MENU_TYPE_LABEL, MENU_TYPE_MENU, MENU_TYPE_OPTIONS, MENU_TYPE_PAGE, MENU_VISIBILITY_OPTIONS, type MatchMode, MenuManager, type MenuManagerProps, type MenuResource, type MenuResourceApi, type MenuResourceFormValues, type MenuResourceListResult, type MenuResourceType, type PageDirection, type PermissionChecker, type PermissionCode, type PermissionListener, PermissionProvider, type PermissionProviderProps, type PermissionState, PermissionStore, RESOURCE_PRIVATE_OPTIONS, RESOURCE_STATUS_DISABLED, RESOURCE_STATUS_ENABLED, RESOURCE_STATUS_OPTIONS, RESOURCE_TYPE_API, ROOT_PARENT_ID, type ResourceHttpRequest, ResourceManager, type ResourceManagerProps, type ResourceRequestOptions, type ResourceStatus, type ResourceType, type RoleCode, type UpdateAuthorizationResourceBody, type UpdateMenuResourceBody, type UsePermissionResult, appendQueryParam, buildCreateBody, buildCreateMenuBody, buildUpdateBody, buildUpdateMenuBody, createAuthorizationResourceApi, createDefaultResourceRequest, createMenuResourceApi, createPermissionStore, extractPagination, extractRecords, getAppClientId, getDeviceWorkerId, mapAuthorizationResource, mapMenuResource, snowyflake, useHasPermission, useHasRole, usePermission };