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/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: AuthProvider[];
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