openxiangda 1.0.84 → 1.0.86

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.
@@ -0,0 +1,328 @@
1
+ import React__default, { CSSProperties } from 'react';
2
+
3
+ type AuthMethodType = "password" | "dingtalk" | "sso" | "guest" | "phone_code" | string;
4
+ interface AuthMethod {
5
+ type: AuthMethodType;
6
+ enabled?: boolean;
7
+ label?: string;
8
+ protocol?: string;
9
+ [key: string]: unknown;
10
+ }
11
+ interface LoginMethodsResult {
12
+ appType: string;
13
+ configCode?: string;
14
+ methods: AuthMethod[];
15
+ registration?: {
16
+ mode?: string;
17
+ [key: string]: unknown;
18
+ };
19
+ security?: {
20
+ hideFailureReason?: boolean;
21
+ [key: string]: unknown;
22
+ };
23
+ defaultRedirectUrl?: string;
24
+ }
25
+ interface AuthUser {
26
+ id: string;
27
+ username?: string;
28
+ name?: string;
29
+ phone?: string | null;
30
+ email?: string | null;
31
+ avatar?: string | null;
32
+ jobNumber?: string | null;
33
+ departments?: Array<Record<string, unknown>>;
34
+ affiliatedDepartmentId?: string | null;
35
+ affiliatedDepartment?: Record<string, unknown> | null;
36
+ [key: string]: unknown;
37
+ }
38
+ interface AuthTokenData {
39
+ accessToken: string;
40
+ refreshToken: string;
41
+ token?: string;
42
+ accessTokenExpiresAt?: number;
43
+ refreshTokenExpiresAt?: number;
44
+ user?: AuthUser;
45
+ guestUser?: AuthUser;
46
+ [key: string]: unknown;
47
+ }
48
+ interface PhoneCodeSendResult {
49
+ challengeId: string;
50
+ expiresAt?: string | Date;
51
+ ttlSeconds?: number;
52
+ message?: string;
53
+ }
54
+ interface SsoLoginUrlResult {
55
+ loginUrl: string;
56
+ protocol?: string;
57
+ }
58
+ interface AuthClientOptions {
59
+ appType: string;
60
+ servicePrefix?: string;
61
+ fetchImpl?: typeof fetch;
62
+ }
63
+ interface PasswordLoginInput {
64
+ username: string;
65
+ password: string;
66
+ clientFingerprint?: string;
67
+ challengeId?: string;
68
+ challengeAnswer?: string;
69
+ }
70
+ interface DingTalkLoginInput {
71
+ code: string;
72
+ corpId?: string;
73
+ }
74
+ interface GuestLoginInput {
75
+ guestIdentifier?: string;
76
+ domain?: string;
77
+ ipAddress?: string;
78
+ userAgent?: string;
79
+ formUuid?: string;
80
+ }
81
+ interface PhoneCodeInput {
82
+ phone: string;
83
+ purpose?: "login" | "register" | string;
84
+ }
85
+ interface PhoneCodeLoginInput {
86
+ phone: string;
87
+ code: string;
88
+ challengeId?: string;
89
+ }
90
+ interface PhoneCodeRegisterInput extends PhoneCodeLoginInput {
91
+ name?: string;
92
+ email?: string;
93
+ }
94
+ interface SsoLoginUrlInput {
95
+ protocol?: string;
96
+ redirectUri?: string;
97
+ }
98
+ interface RefreshInput {
99
+ refreshToken?: string;
100
+ }
101
+ interface ResolveLoginUrlInput {
102
+ callbackUrl?: string;
103
+ callbackParamName?: string;
104
+ loginUrl?: string;
105
+ }
106
+ interface AppAuthClient {
107
+ appType: string;
108
+ servicePrefix: string;
109
+ getMethods: () => Promise<LoginMethodsResult>;
110
+ passwordLogin: (input: PasswordLoginInput) => Promise<AuthTokenData>;
111
+ dingtalkLogin: (input: DingTalkLoginInput) => Promise<AuthTokenData>;
112
+ guestLogin: (input?: GuestLoginInput) => Promise<AuthTokenData>;
113
+ sendPhoneCode: (input: PhoneCodeInput) => Promise<PhoneCodeSendResult>;
114
+ phoneCodeLogin: (input: PhoneCodeLoginInput) => Promise<AuthTokenData>;
115
+ registerWithPhoneCode: (input: PhoneCodeRegisterInput) => Promise<AuthTokenData>;
116
+ getSsoLoginUrl: (input?: SsoLoginUrlInput) => Promise<SsoLoginUrlResult>;
117
+ refresh: (input?: RefreshInput) => Promise<AuthTokenData>;
118
+ logout: () => Promise<void>;
119
+ resolveLoginUrl: (input?: ResolveLoginUrlInput) => string;
120
+ }
121
+ declare class AuthClientError extends Error {
122
+ status?: number;
123
+ code?: number | string;
124
+ payload?: unknown;
125
+ constructor(message: string, options?: {
126
+ status?: number;
127
+ code?: number | string;
128
+ payload?: unknown;
129
+ });
130
+ }
131
+ declare const createAuthClient: ({ appType, servicePrefix, fetchImpl, }: AuthClientOptions) => AppAuthClient;
132
+
133
+ interface UseAuthOptions extends Partial<AuthClientOptions> {
134
+ }
135
+ interface UseLoginMethodsState {
136
+ data: LoginMethodsResult | null;
137
+ methods: AuthMethod[];
138
+ loading: boolean;
139
+ error: Error | null;
140
+ reload: () => Promise<void>;
141
+ }
142
+ interface LoginPageProps extends UseAuthOptions {
143
+ title?: React__default.ReactNode;
144
+ subtitle?: React__default.ReactNode;
145
+ className?: string;
146
+ style?: CSSProperties;
147
+ defaultMethod?: "password" | "phone_code";
148
+ redirectUrl?: string;
149
+ redirectOnSuccess?: boolean;
150
+ onSuccess?: (data: AuthTokenData) => void | Promise<void>;
151
+ }
152
+ declare const useAuth: (options?: UseAuthOptions) => {
153
+ client: AppAuthClient;
154
+ getMethods: () => Promise<LoginMethodsResult>;
155
+ passwordLogin: (input: PasswordLoginInput) => Promise<AuthTokenData>;
156
+ dingtalkLogin: (input: DingTalkLoginInput) => Promise<AuthTokenData>;
157
+ guestLogin: (input?: GuestLoginInput) => Promise<AuthTokenData>;
158
+ sendPhoneCode: (input: PhoneCodeInput) => Promise<PhoneCodeSendResult>;
159
+ phoneCodeLogin: (input: PhoneCodeLoginInput) => Promise<AuthTokenData>;
160
+ registerWithPhoneCode: (input: PhoneCodeRegisterInput) => Promise<AuthTokenData>;
161
+ getSsoLoginUrl: (input?: SsoLoginUrlInput) => Promise<SsoLoginUrlResult>;
162
+ refresh: (input?: RefreshInput) => Promise<AuthTokenData>;
163
+ logout: () => Promise<void>;
164
+ resolveLoginUrl: (input?: ResolveLoginUrlInput) => string;
165
+ };
166
+ declare const useLoginMethods: (options?: UseAuthOptions) => UseLoginMethodsState;
167
+ declare const LoginPage: React__default.FC<LoginPageProps>;
168
+
169
+ type RuntimeErrorType = "unauthenticated" | "forbidden" | "network" | "unknown";
170
+ type RuntimeRequestError = Error & {
171
+ type?: RuntimeErrorType;
172
+ status?: number;
173
+ code?: number | string;
174
+ payload?: unknown;
175
+ };
176
+ interface RuntimeErrorSnapshot {
177
+ type: RuntimeErrorType;
178
+ status?: number;
179
+ code?: number | string;
180
+ message: string;
181
+ payload?: unknown;
182
+ }
183
+ declare class RuntimeHttpError extends Error {
184
+ type: RuntimeErrorType;
185
+ status?: number;
186
+ code?: number | string;
187
+ payload?: unknown;
188
+ constructor(snapshot: RuntimeErrorSnapshot);
189
+ }
190
+ interface RuntimeMenuItem {
191
+ id: string;
192
+ name: string;
193
+ resourceCode?: string | null;
194
+ routeCode?: string | null;
195
+ path?: string | null;
196
+ type?: string;
197
+ formUuid?: string | null;
198
+ pageId?: string | null;
199
+ parentId?: string | null;
200
+ sortOrder?: number;
201
+ isHidden?: boolean;
202
+ icon?: string | null;
203
+ children?: RuntimeMenuItem[];
204
+ [key: string]: unknown;
205
+ }
206
+ interface RuntimePagePermissions {
207
+ appType: string;
208
+ hasFullAccess: boolean;
209
+ roleCodes: string[];
210
+ roleSource?: string;
211
+ menuFormUuids: string[];
212
+ menuCodes: string[];
213
+ routeCodes: string[];
214
+ pathPatterns: string[];
215
+ }
216
+ interface RuntimeBootstrap {
217
+ appType: string;
218
+ app?: Record<string, unknown> | null;
219
+ user?: Record<string, unknown> | null;
220
+ runtime?: {
221
+ mode?: "legacy" | "react-spa" | string;
222
+ settings?: Record<string, unknown>;
223
+ activeReleaseId?: string | null;
224
+ activeBuildId?: string | null;
225
+ indexUrl?: string | null;
226
+ assetBaseUrl?: string | null;
227
+ };
228
+ permissions?: RuntimePagePermissions;
229
+ menus?: RuntimeMenuItem[];
230
+ servicePrefix?: string;
231
+ }
232
+ interface RouteAccessResult {
233
+ appType: string;
234
+ canAccess: boolean;
235
+ routeCode?: string;
236
+ menuCode?: string;
237
+ path?: string;
238
+ status?: number;
239
+ code?: number | string;
240
+ message?: string;
241
+ errorType?: RuntimeErrorType;
242
+ payload?: unknown;
243
+ permissions?: RuntimePagePermissions;
244
+ }
245
+ interface RuntimeRequestState<T> {
246
+ data: T | null;
247
+ loading: boolean;
248
+ error: RuntimeRequestError | null;
249
+ }
250
+ interface OpenXiangdaProviderProps {
251
+ appType?: string;
252
+ servicePrefix?: string;
253
+ fetchImpl?: typeof fetch;
254
+ children: React__default.ReactNode;
255
+ }
256
+ interface OpenXiangdaRuntimeStore extends RuntimeRequestState<RuntimeBootstrap> {
257
+ appType: string;
258
+ servicePrefix: string;
259
+ fetchImpl: typeof fetch;
260
+ reload: () => Promise<void>;
261
+ }
262
+ declare const OpenXiangdaProvider: React__default.FC<OpenXiangdaProviderProps>;
263
+ declare const useOpenXiangda: () => OpenXiangdaRuntimeStore;
264
+ declare const useRuntimeBootstrap: () => OpenXiangdaRuntimeStore;
265
+ declare const useAppMenus: () => {
266
+ data: RuntimeMenuItem[];
267
+ appType: string;
268
+ servicePrefix: string;
269
+ fetchImpl: typeof fetch;
270
+ reload: () => Promise<void>;
271
+ loading: boolean;
272
+ error: RuntimeRequestError | null;
273
+ };
274
+ declare const usePermission: () => {
275
+ data: RuntimePagePermissions | null;
276
+ appType: string;
277
+ servicePrefix: string;
278
+ fetchImpl: typeof fetch;
279
+ reload: () => Promise<void>;
280
+ loading: boolean;
281
+ error: RuntimeRequestError | null;
282
+ };
283
+ interface UseCanAccessRouteInput {
284
+ routeCode?: string;
285
+ menuCode?: string;
286
+ path?: string;
287
+ }
288
+ declare const useCanAccessRoute: (input: UseCanAccessRouteInput) => {
289
+ canAccess: boolean;
290
+ data: RouteAccessResult | null;
291
+ loading: boolean;
292
+ error: RuntimeRequestError | null;
293
+ };
294
+ interface PermissionBoundaryProps extends UseCanAccessRouteInput {
295
+ children: React__default.ReactNode;
296
+ fallback?: React__default.ReactNode | PermissionBoundaryFallback;
297
+ loadingFallback?: React__default.ReactNode | PermissionBoundaryFallback;
298
+ }
299
+ interface PermissionBoundaryFallbackState {
300
+ access: ReturnType<typeof useCanAccessRoute>;
301
+ runtime: ReturnType<typeof useOpenXiangda>;
302
+ error: RuntimeRequestError | null;
303
+ errorType: RuntimeErrorType;
304
+ status?: number;
305
+ code?: number | string;
306
+ message: string;
307
+ }
308
+ type PermissionBoundaryFallback = (state: PermissionBoundaryFallbackState) => React__default.ReactNode;
309
+ declare const PermissionBoundary: React__default.FC<PermissionBoundaryProps>;
310
+ interface RuntimeResolveLoginOptions {
311
+ redirectUri?: string;
312
+ loginUrl?: string;
313
+ domain?: string;
314
+ }
315
+ interface RuntimeRedirectLoginOptions extends RuntimeResolveLoginOptions {
316
+ replace?: boolean;
317
+ }
318
+ interface RuntimeLogoutOptions extends RuntimeRedirectLoginOptions {
319
+ continueOnError?: boolean;
320
+ }
321
+ declare const useRuntimeAuth: () => {
322
+ logout: () => Promise<any>;
323
+ logoutAndRedirect: (options?: RuntimeLogoutOptions) => Promise<string>;
324
+ redirectToLogin: (options?: RuntimeRedirectLoginOptions) => Promise<string>;
325
+ resolveLoginUrl: (options?: RuntimeResolveLoginOptions) => Promise<string>;
326
+ };
327
+
328
+ export { type AppAuthClient as A, type RuntimeRedirectLoginOptions as B, type RuntimeRequestError as C, type DingTalkLoginInput as D, type RuntimeRequestState as E, type RuntimeResolveLoginOptions as F, type GuestLoginInput as G, type SsoLoginUrlResult as H, type UseCanAccessRouteInput as I, type UseLoginMethodsState as J, createAuthClient as K, type LoginMethodsResult as L, useAppMenus as M, useAuth as N, OpenXiangdaProvider as O, type PasswordLoginInput as P, useCanAccessRoute as Q, type RefreshInput as R, type SsoLoginUrlInput as S, useLoginMethods as T, type UseAuthOptions as U, useOpenXiangda as V, usePermission as W, useRuntimeAuth as X, useRuntimeBootstrap as Y, AuthClientError as a, type AuthClientOptions as b, type AuthMethod as c, type AuthMethodType as d, type AuthTokenData as e, type AuthUser as f, LoginPage as g, type LoginPageProps as h, type OpenXiangdaProviderProps as i, PermissionBoundary as j, type PermissionBoundaryFallback as k, type PermissionBoundaryFallbackState as l, type PermissionBoundaryProps as m, type PhoneCodeInput as n, type PhoneCodeLoginInput as o, type PhoneCodeRegisterInput as p, type PhoneCodeSendResult as q, type ResolveLoginUrlInput as r, type RouteAccessResult as s, type RuntimeBootstrap as t, type RuntimeErrorSnapshot as u, type RuntimeErrorType as v, RuntimeHttpError as w, type RuntimeLogoutOptions as x, type RuntimeMenuItem as y, type RuntimePagePermissions as z };