hightjs 0.1.1 → 0.2.2
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 +147 -9
- package/dist/api/http.js +5 -3
- package/dist/auth/client.d.ts +11 -1
- package/dist/auth/client.js +78 -0
- package/dist/auth/core.d.ts +21 -4
- package/dist/auth/core.js +66 -17
- package/dist/auth/example.d.ts +40 -0
- package/dist/auth/example.js +104 -0
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +2 -1
- package/dist/auth/providers/credentials.d.ts +68 -0
- package/dist/auth/providers/credentials.js +132 -0
- package/dist/auth/providers/discord.d.ts +67 -0
- package/dist/auth/providers/discord.js +198 -0
- package/dist/auth/providers/index.d.ts +2 -0
- package/dist/auth/providers/index.js +19 -0
- package/dist/auth/providers.d.ts +2 -5
- package/dist/auth/providers.js +6 -12
- package/dist/auth/react.js +20 -13
- package/dist/auth/routes.d.ts +2 -2
- package/dist/auth/routes.js +45 -13
- package/dist/auth/types.d.ts +36 -21
- package/dist/router.js +9 -1
- package/package.json +1 -1
- package/src/api/http.ts +6 -2
- package/src/auth/client.ts +84 -3
- package/src/auth/core.ts +75 -19
- package/src/auth/example.ts +115 -0
- package/src/auth/index.ts +2 -1
- package/src/auth/providers/credentials.ts +158 -0
- package/src/auth/providers/discord.ts +231 -0
- package/src/auth/providers/index.ts +4 -0
- package/src/auth/providers.ts +3 -12
- package/src/auth/react.tsx +21 -13
- package/src/auth/routes.ts +51 -18
- package/src/auth/types.ts +49 -26
- package/src/router.ts +9 -1
package/src/auth/types.ts
CHANGED
|
@@ -7,8 +7,55 @@ export interface Session {
|
|
|
7
7
|
accessToken?: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
// Client-side types
|
|
11
|
+
export interface SignInOptions {
|
|
12
|
+
redirect?: boolean;
|
|
13
|
+
callbackUrl?: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface SignInResult {
|
|
18
|
+
error?: string;
|
|
19
|
+
status?: number;
|
|
20
|
+
ok?: boolean;
|
|
21
|
+
url?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface SessionContextType {
|
|
25
|
+
data: Session | null;
|
|
26
|
+
status: 'loading' | 'authenticated' | 'unauthenticated';
|
|
27
|
+
signIn: (provider?: string, options?: SignInOptions) => Promise<SignInResult | undefined>;
|
|
28
|
+
signOut: (options?: { callbackUrl?: string }) => Promise<void>;
|
|
29
|
+
update: () => Promise<Session | null>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AuthRoute {
|
|
33
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
34
|
+
path: string;
|
|
35
|
+
handler: (req: any, params: any) => Promise<any>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface AuthProviderClass {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
type: string;
|
|
42
|
+
|
|
43
|
+
// Para providers OAuth - retorna URL de redirecionamento
|
|
44
|
+
handleOauth?(credentials: Record<string, string>): Promise<string> | string;
|
|
45
|
+
|
|
46
|
+
// Métodos principais
|
|
47
|
+
handleSignIn(credentials: Record<string, string>): Promise<User | string | null>;
|
|
48
|
+
handleSignOut?(): Promise<void>;
|
|
49
|
+
|
|
50
|
+
// Rotas adicionais que o provider pode ter
|
|
51
|
+
additionalRoutes?: AuthRoute[];
|
|
52
|
+
|
|
53
|
+
// Configurações específicas do provider
|
|
54
|
+
getConfig?(): any;
|
|
55
|
+
}
|
|
56
|
+
|
|
10
57
|
export interface AuthConfig {
|
|
11
|
-
providers:
|
|
58
|
+
providers: AuthProviderClass[];
|
|
12
59
|
pages?: {
|
|
13
60
|
signIn?: string;
|
|
14
61
|
signOut?: string;
|
|
@@ -28,6 +75,7 @@ export interface AuthConfig {
|
|
|
28
75
|
debug?: boolean;
|
|
29
76
|
}
|
|
30
77
|
|
|
78
|
+
// Interface legada para compatibilidade
|
|
31
79
|
export interface AuthProvider {
|
|
32
80
|
id: string;
|
|
33
81
|
name: string;
|
|
@@ -35,27 +83,6 @@ export interface AuthProvider {
|
|
|
35
83
|
authorize?: (credentials: Record<string, string>) => Promise<User | null> | User | null;
|
|
36
84
|
}
|
|
37
85
|
|
|
38
|
-
export interface SignInOptions {
|
|
39
|
-
redirect?: boolean;
|
|
40
|
-
callbackUrl?: string;
|
|
41
|
-
[key: string]: any;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface SignInResult {
|
|
45
|
-
error?: string;
|
|
46
|
-
status?: number;
|
|
47
|
-
ok?: boolean;
|
|
48
|
-
url?: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface SessionContextType {
|
|
52
|
-
data: Session | null;
|
|
53
|
-
status: 'loading' | 'authenticated' | 'unauthenticated';
|
|
54
|
-
signIn: (provider?: string, options?: SignInOptions) => Promise<SignInResult | undefined>;
|
|
55
|
-
signOut: (options?: { callbackUrl?: string }) => Promise<void>;
|
|
56
|
-
update: () => Promise<Session | null>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
86
|
// Provider para credenciais
|
|
60
87
|
export interface CredentialsConfig {
|
|
61
88
|
id?: string;
|
|
@@ -67,7 +94,3 @@ export interface CredentialsConfig {
|
|
|
67
94
|
}>;
|
|
68
95
|
authorize: (credentials: Record<string, string>) => Promise<User | null> | User | null;
|
|
69
96
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
package/src/router.ts
CHANGED
|
@@ -341,8 +341,16 @@ export function findMatchingBackendRoute(pathname: string, method: string) {
|
|
|
341
341
|
for (const route of allBackendRoutes) {
|
|
342
342
|
// Verifica se a rota tem um handler para o método HTTP atual
|
|
343
343
|
if (!route.pattern || !route[method.toUpperCase() as keyof BackendRouteConfig]) continue;
|
|
344
|
+
const regexPattern = route.pattern
|
|
345
|
+
// [[...param]] → opcional catch-all
|
|
346
|
+
.replace(/\[\[\.\.\.(\w+)\]\]/g, '(?<$1>.+)?')
|
|
347
|
+
// [...param] → obrigatório catch-all
|
|
348
|
+
.replace(/\[\.\.\.(\w+)\]/g, '(?<$1>.+)')
|
|
349
|
+
// [[param]] → segmento opcional
|
|
350
|
+
.replace(/\[\[(\w+)\]\]/g, '(?<$1>[^/]+)?')
|
|
351
|
+
// [param] → segmento obrigatório
|
|
352
|
+
.replace(/\[(\w+)\]/g, '(?<$1>[^/]+)');
|
|
344
353
|
|
|
345
|
-
const regexPattern = route.pattern.replace(/\[(\w+)\]/g, '(?<$1>[^/]+)');
|
|
346
354
|
const regex = new RegExp(`^${regexPattern}/?$`);
|
|
347
355
|
const match = pathname.match(regex);
|
|
348
356
|
|