com-angel-authorization 1.0.0 → 1.0.1
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.
- package/README.md +87 -0
- package/dist/index.cjs +295 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +126 -1
- package/dist/index.d.ts +126 -1
- package/dist/index.js +280 -1
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +482 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +135 -1
- package/dist/react/index.d.ts +135 -1
- package/dist/react/index.js +488 -0
- package/dist/react/index.js.map +1 -1
- package/dist/vue/index.cjs +594 -0
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.cts +162 -1
- package/dist/vue/index.d.ts +162 -1
- package/dist/vue/index.js +602 -0
- package/dist/vue/index.js.map +1 -1
- package/package.json +6 -1
package/dist/react/index.d.cts
CHANGED
|
@@ -116,4 +116,138 @@ interface CanProps {
|
|
|
116
116
|
*/
|
|
117
117
|
declare function Can({ permission, role, mode, combine, children, fallback, }: CanProps): react.JSX.Element;
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
type PageDirection = 'previous' | 'current' | 'next';
|
|
120
|
+
type ListPaginationParams = {
|
|
121
|
+
pageToken?: string;
|
|
122
|
+
pageSize?: string;
|
|
123
|
+
pageDirection?: PageDirection;
|
|
124
|
+
};
|
|
125
|
+
type ListPaginationResult = {
|
|
126
|
+
pageToken: string;
|
|
127
|
+
hasPreviousPage: boolean;
|
|
128
|
+
hasNextPage: boolean;
|
|
129
|
+
};
|
|
130
|
+
/** 权限点状态:1 启用,0 禁用 */
|
|
131
|
+
type ResourceStatus = 0 | 1;
|
|
132
|
+
type AuthorizationResource = {
|
|
133
|
+
resourceId: string;
|
|
134
|
+
type: 'api';
|
|
135
|
+
name: string;
|
|
136
|
+
identification: string;
|
|
137
|
+
status: ResourceStatus;
|
|
138
|
+
private: boolean;
|
|
139
|
+
description: string;
|
|
140
|
+
};
|
|
141
|
+
type AuthorizationResourceFormValues = {
|
|
142
|
+
name: string;
|
|
143
|
+
identification: string;
|
|
144
|
+
status: ResourceStatus;
|
|
145
|
+
private: boolean;
|
|
146
|
+
description: string;
|
|
147
|
+
};
|
|
148
|
+
type CreateAuthorizationResourceBody = AuthorizationResourceFormValues & {
|
|
149
|
+
resourceId: string;
|
|
150
|
+
type: 'api';
|
|
151
|
+
};
|
|
152
|
+
type UpdateAuthorizationResourceBody = Partial<AuthorizationResourceFormValues> & {
|
|
153
|
+
type?: 'api';
|
|
154
|
+
};
|
|
155
|
+
type FetchAuthorizationResourcesParams = {
|
|
156
|
+
pagination?: ListPaginationParams;
|
|
157
|
+
};
|
|
158
|
+
type AuthorizationResourceListResult = {
|
|
159
|
+
records: AuthorizationResource[];
|
|
160
|
+
pageToken: string;
|
|
161
|
+
hasPreviousPage: boolean;
|
|
162
|
+
hasNextPage: boolean;
|
|
163
|
+
};
|
|
164
|
+
declare const RESOURCE_TYPE_API: "api";
|
|
165
|
+
declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
|
|
166
|
+
declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
|
|
167
|
+
declare const RESOURCE_STATUS_OPTIONS: {
|
|
168
|
+
label: string;
|
|
169
|
+
value: ResourceStatus;
|
|
170
|
+
}[];
|
|
171
|
+
declare const RESOURCE_PRIVATE_OPTIONS: {
|
|
172
|
+
label: string;
|
|
173
|
+
value: boolean;
|
|
174
|
+
}[];
|
|
175
|
+
|
|
176
|
+
type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
177
|
+
type ResourceRequestOptions = {
|
|
178
|
+
method: HttpMethod;
|
|
179
|
+
url: string;
|
|
180
|
+
body?: unknown;
|
|
181
|
+
signal?: AbortSignal;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* 由宿主应用注入的请求函数(可对接 Angel_HGAMS 的 apiGetJson / apiPostJson 等)。
|
|
185
|
+
*/
|
|
186
|
+
type ResourceHttpRequest = <T = unknown>(options: ResourceRequestOptions) => Promise<T>;
|
|
187
|
+
type AuthorizationResourceApi = {
|
|
188
|
+
list: (params?: FetchAuthorizationResourcesParams, signal?: AbortSignal) => Promise<AuthorizationResourceListResult>;
|
|
189
|
+
create: (values: AuthorizationResourceFormValues, signal?: AbortSignal) => Promise<unknown>;
|
|
190
|
+
update: (resourceId: string, values: AuthorizationResourceFormValues, signal?: AbortSignal) => Promise<unknown>;
|
|
191
|
+
remove: (resourceId: string, signal?: AbortSignal) => Promise<unknown>;
|
|
192
|
+
};
|
|
193
|
+
declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
|
|
194
|
+
declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
|
|
195
|
+
declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
|
|
196
|
+
declare function createAuthorizationResourceApi(request: ResourceHttpRequest): AuthorizationResourceApi;
|
|
197
|
+
type CreateDefaultResourceRequestOptions = {
|
|
198
|
+
/** API 前缀,如 `/api` 或完整域名 */
|
|
199
|
+
baseUrl?: string;
|
|
200
|
+
/** 追加请求头(如 Authorization) */
|
|
201
|
+
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
202
|
+
credentials?: RequestCredentials;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* 基于 fetch 的默认请求实现,便于快速接入。
|
|
206
|
+
* 生产环境建议注入宿主应用已有的 request 封装。
|
|
207
|
+
*/
|
|
208
|
+
declare function createDefaultResourceRequest(options?: CreateDefaultResourceRequestOptions): ResourceHttpRequest;
|
|
209
|
+
|
|
210
|
+
declare function appendQueryParam(parts: string[], key: string, value: string): void;
|
|
211
|
+
declare function extractPagination(payload: unknown): ListPaginationResult;
|
|
212
|
+
declare function extractRecords(payload: unknown): unknown[];
|
|
213
|
+
|
|
214
|
+
type ResourceManagerProps = {
|
|
215
|
+
api: AuthorizationResourceApi;
|
|
216
|
+
title?: string;
|
|
217
|
+
pageSize?: string;
|
|
218
|
+
/** 自定义顶部右侧操作区 */
|
|
219
|
+
toolbarExtra?: ReactNode;
|
|
220
|
+
};
|
|
221
|
+
declare function ResourceManager({ api, title, pageSize: initialPageSize, toolbarExtra, }: ResourceManagerProps): react.JSX.Element;
|
|
222
|
+
|
|
223
|
+
interface SnowyflakeOptions {
|
|
224
|
+
epoch?: bigint;
|
|
225
|
+
workerId?: bigint;
|
|
226
|
+
processId?: bigint;
|
|
227
|
+
workerIdBits?: number;
|
|
228
|
+
processIdBits?: number;
|
|
229
|
+
sequenceBits?: number;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* snowyflake 2.0.1 仅支持固定 5+5+12 位布局,此处按相同 nextId 算法实现可配置位数版本。
|
|
233
|
+
*/
|
|
234
|
+
declare class ConfigurableSnowflake {
|
|
235
|
+
readonly epoch: bigint;
|
|
236
|
+
readonly workerId: bigint;
|
|
237
|
+
readonly processId: bigint;
|
|
238
|
+
private readonly sequenceMask;
|
|
239
|
+
private readonly timestampLeftShift;
|
|
240
|
+
private readonly workerIdShift;
|
|
241
|
+
private readonly processIdShift;
|
|
242
|
+
private sequence;
|
|
243
|
+
private latestTimestamp;
|
|
244
|
+
constructor({ epoch, workerId, processId, workerIdBits, processIdBits, sequenceBits, }?: SnowyflakeOptions);
|
|
245
|
+
nextId(): bigint;
|
|
246
|
+
}
|
|
247
|
+
/** 应用级单例,模块加载时只初始化一次(不受 React StrictMode 重复 mount 影响) */
|
|
248
|
+
declare const snowyflake: ConfigurableSnowflake;
|
|
249
|
+
/** 生成雪花 ID 字符串(reportId、detailId、resourceId 等) */
|
|
250
|
+
declare function getAppClientId(): string;
|
|
251
|
+
declare function getDeviceWorkerId(): string;
|
|
252
|
+
|
|
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 };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -116,4 +116,138 @@ interface CanProps {
|
|
|
116
116
|
*/
|
|
117
117
|
declare function Can({ permission, role, mode, combine, children, fallback, }: CanProps): react.JSX.Element;
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
type PageDirection = 'previous' | 'current' | 'next';
|
|
120
|
+
type ListPaginationParams = {
|
|
121
|
+
pageToken?: string;
|
|
122
|
+
pageSize?: string;
|
|
123
|
+
pageDirection?: PageDirection;
|
|
124
|
+
};
|
|
125
|
+
type ListPaginationResult = {
|
|
126
|
+
pageToken: string;
|
|
127
|
+
hasPreviousPage: boolean;
|
|
128
|
+
hasNextPage: boolean;
|
|
129
|
+
};
|
|
130
|
+
/** 权限点状态:1 启用,0 禁用 */
|
|
131
|
+
type ResourceStatus = 0 | 1;
|
|
132
|
+
type AuthorizationResource = {
|
|
133
|
+
resourceId: string;
|
|
134
|
+
type: 'api';
|
|
135
|
+
name: string;
|
|
136
|
+
identification: string;
|
|
137
|
+
status: ResourceStatus;
|
|
138
|
+
private: boolean;
|
|
139
|
+
description: string;
|
|
140
|
+
};
|
|
141
|
+
type AuthorizationResourceFormValues = {
|
|
142
|
+
name: string;
|
|
143
|
+
identification: string;
|
|
144
|
+
status: ResourceStatus;
|
|
145
|
+
private: boolean;
|
|
146
|
+
description: string;
|
|
147
|
+
};
|
|
148
|
+
type CreateAuthorizationResourceBody = AuthorizationResourceFormValues & {
|
|
149
|
+
resourceId: string;
|
|
150
|
+
type: 'api';
|
|
151
|
+
};
|
|
152
|
+
type UpdateAuthorizationResourceBody = Partial<AuthorizationResourceFormValues> & {
|
|
153
|
+
type?: 'api';
|
|
154
|
+
};
|
|
155
|
+
type FetchAuthorizationResourcesParams = {
|
|
156
|
+
pagination?: ListPaginationParams;
|
|
157
|
+
};
|
|
158
|
+
type AuthorizationResourceListResult = {
|
|
159
|
+
records: AuthorizationResource[];
|
|
160
|
+
pageToken: string;
|
|
161
|
+
hasPreviousPage: boolean;
|
|
162
|
+
hasNextPage: boolean;
|
|
163
|
+
};
|
|
164
|
+
declare const RESOURCE_TYPE_API: "api";
|
|
165
|
+
declare const RESOURCE_STATUS_ENABLED: ResourceStatus;
|
|
166
|
+
declare const RESOURCE_STATUS_DISABLED: ResourceStatus;
|
|
167
|
+
declare const RESOURCE_STATUS_OPTIONS: {
|
|
168
|
+
label: string;
|
|
169
|
+
value: ResourceStatus;
|
|
170
|
+
}[];
|
|
171
|
+
declare const RESOURCE_PRIVATE_OPTIONS: {
|
|
172
|
+
label: string;
|
|
173
|
+
value: boolean;
|
|
174
|
+
}[];
|
|
175
|
+
|
|
176
|
+
type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
177
|
+
type ResourceRequestOptions = {
|
|
178
|
+
method: HttpMethod;
|
|
179
|
+
url: string;
|
|
180
|
+
body?: unknown;
|
|
181
|
+
signal?: AbortSignal;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* 由宿主应用注入的请求函数(可对接 Angel_HGAMS 的 apiGetJson / apiPostJson 等)。
|
|
185
|
+
*/
|
|
186
|
+
type ResourceHttpRequest = <T = unknown>(options: ResourceRequestOptions) => Promise<T>;
|
|
187
|
+
type AuthorizationResourceApi = {
|
|
188
|
+
list: (params?: FetchAuthorizationResourcesParams, signal?: AbortSignal) => Promise<AuthorizationResourceListResult>;
|
|
189
|
+
create: (values: AuthorizationResourceFormValues, signal?: AbortSignal) => Promise<unknown>;
|
|
190
|
+
update: (resourceId: string, values: AuthorizationResourceFormValues, signal?: AbortSignal) => Promise<unknown>;
|
|
191
|
+
remove: (resourceId: string, signal?: AbortSignal) => Promise<unknown>;
|
|
192
|
+
};
|
|
193
|
+
declare function mapAuthorizationResource(item: unknown): AuthorizationResource | null;
|
|
194
|
+
declare function buildCreateBody(values: AuthorizationResourceFormValues, resourceId?: string): CreateAuthorizationResourceBody;
|
|
195
|
+
declare function buildUpdateBody(values: AuthorizationResourceFormValues): UpdateAuthorizationResourceBody;
|
|
196
|
+
declare function createAuthorizationResourceApi(request: ResourceHttpRequest): AuthorizationResourceApi;
|
|
197
|
+
type CreateDefaultResourceRequestOptions = {
|
|
198
|
+
/** API 前缀,如 `/api` 或完整域名 */
|
|
199
|
+
baseUrl?: string;
|
|
200
|
+
/** 追加请求头(如 Authorization) */
|
|
201
|
+
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
202
|
+
credentials?: RequestCredentials;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* 基于 fetch 的默认请求实现,便于快速接入。
|
|
206
|
+
* 生产环境建议注入宿主应用已有的 request 封装。
|
|
207
|
+
*/
|
|
208
|
+
declare function createDefaultResourceRequest(options?: CreateDefaultResourceRequestOptions): ResourceHttpRequest;
|
|
209
|
+
|
|
210
|
+
declare function appendQueryParam(parts: string[], key: string, value: string): void;
|
|
211
|
+
declare function extractPagination(payload: unknown): ListPaginationResult;
|
|
212
|
+
declare function extractRecords(payload: unknown): unknown[];
|
|
213
|
+
|
|
214
|
+
type ResourceManagerProps = {
|
|
215
|
+
api: AuthorizationResourceApi;
|
|
216
|
+
title?: string;
|
|
217
|
+
pageSize?: string;
|
|
218
|
+
/** 自定义顶部右侧操作区 */
|
|
219
|
+
toolbarExtra?: ReactNode;
|
|
220
|
+
};
|
|
221
|
+
declare function ResourceManager({ api, title, pageSize: initialPageSize, toolbarExtra, }: ResourceManagerProps): react.JSX.Element;
|
|
222
|
+
|
|
223
|
+
interface SnowyflakeOptions {
|
|
224
|
+
epoch?: bigint;
|
|
225
|
+
workerId?: bigint;
|
|
226
|
+
processId?: bigint;
|
|
227
|
+
workerIdBits?: number;
|
|
228
|
+
processIdBits?: number;
|
|
229
|
+
sequenceBits?: number;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* snowyflake 2.0.1 仅支持固定 5+5+12 位布局,此处按相同 nextId 算法实现可配置位数版本。
|
|
233
|
+
*/
|
|
234
|
+
declare class ConfigurableSnowflake {
|
|
235
|
+
readonly epoch: bigint;
|
|
236
|
+
readonly workerId: bigint;
|
|
237
|
+
readonly processId: bigint;
|
|
238
|
+
private readonly sequenceMask;
|
|
239
|
+
private readonly timestampLeftShift;
|
|
240
|
+
private readonly workerIdShift;
|
|
241
|
+
private readonly processIdShift;
|
|
242
|
+
private sequence;
|
|
243
|
+
private latestTimestamp;
|
|
244
|
+
constructor({ epoch, workerId, processId, workerIdBits, processIdBits, sequenceBits, }?: SnowyflakeOptions);
|
|
245
|
+
nextId(): bigint;
|
|
246
|
+
}
|
|
247
|
+
/** 应用级单例,模块加载时只初始化一次(不受 React StrictMode 重复 mount 影响) */
|
|
248
|
+
declare const snowyflake: ConfigurableSnowflake;
|
|
249
|
+
/** 生成雪花 ID 字符串(reportId、detailId、resourceId 等) */
|
|
250
|
+
declare function getAppClientId(): string;
|
|
251
|
+
declare function getDeviceWorkerId(): string;
|
|
252
|
+
|
|
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 };
|