@allanfsouza/aether-sdk 2.4.2 → 2.4.4
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/dist/auth.d.ts +51 -39
- package/dist/auth.js +70 -33
- package/dist/database.d.ts +35 -68
- package/dist/database.js +72 -78
- package/dist/index.d.ts +6 -15
- package/dist/index.js +12 -23
- package/dist/storage.d.ts +25 -14
- package/dist/storage.js +42 -20
- package/package.json +2 -2
- package/src/auth.ts +88 -44
- package/src/database.ts +80 -81
- package/src/index.ts +27 -46
- package/src/storage.ts +47 -20
package/dist/auth.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import type { AxiosInstance } from "axios";
|
|
2
2
|
import type { PlataformaClient } from "./index.js";
|
|
3
|
+
export interface User {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
email: string;
|
|
7
|
+
avatarUrl?: string;
|
|
8
|
+
role?: string;
|
|
9
|
+
aetherRole?: string;
|
|
10
|
+
planCode?: string;
|
|
11
|
+
emailVerified?: boolean;
|
|
12
|
+
}
|
|
3
13
|
export interface LoginResponse {
|
|
4
14
|
accessToken: string;
|
|
5
15
|
refreshToken: string;
|
|
6
|
-
user:
|
|
7
|
-
id: string;
|
|
8
|
-
name: string;
|
|
9
|
-
email: string;
|
|
10
|
-
avatarUrl?: string;
|
|
11
|
-
role?: string;
|
|
12
|
-
aetherRole?: string;
|
|
13
|
-
planCode?: string;
|
|
14
|
-
emailVerified?: boolean;
|
|
15
|
-
};
|
|
16
|
+
user: User;
|
|
16
17
|
}
|
|
17
18
|
export interface Session {
|
|
18
19
|
id: string;
|
|
@@ -25,55 +26,66 @@ export declare class AuthModule {
|
|
|
25
26
|
private client;
|
|
26
27
|
private http;
|
|
27
28
|
private refreshToken;
|
|
29
|
+
private currentUser;
|
|
28
30
|
constructor(client: PlataformaClient, http: AxiosInstance);
|
|
29
|
-
/**
|
|
30
|
-
* Login com email e senha
|
|
31
|
-
*/
|
|
32
31
|
login(email: string, password: string): Promise<LoginResponse>;
|
|
33
|
-
/**
|
|
34
|
-
* Registrar novo usuário
|
|
35
|
-
*/
|
|
36
32
|
register(credentials: {
|
|
37
33
|
name: string;
|
|
38
34
|
email: string;
|
|
39
35
|
password: string;
|
|
40
36
|
}): Promise<any>;
|
|
41
|
-
/**
|
|
42
|
-
* Renovar access token usando refresh token
|
|
43
|
-
*/
|
|
44
37
|
refresh(): Promise<{
|
|
45
38
|
accessToken: string;
|
|
46
39
|
}>;
|
|
47
|
-
/**
|
|
48
|
-
* Obter URL de autenticação do Google
|
|
49
|
-
*/
|
|
50
40
|
getGoogleAuthUrl(): string;
|
|
51
|
-
/**
|
|
52
|
-
* Logout da sessão atual
|
|
53
|
-
*/
|
|
54
41
|
logout(): Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* Logout de todas as sessões
|
|
57
|
-
*/
|
|
58
42
|
logoutAll(): Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Listar sessões ativas
|
|
61
|
-
*/
|
|
62
43
|
getSessions(): Promise<Session[]>;
|
|
44
|
+
forgotPassword(email: string): Promise<any>;
|
|
45
|
+
resetPassword(token: string, newPassword: string): Promise<any>;
|
|
46
|
+
getRefreshToken(): string | null;
|
|
47
|
+
setRefreshToken(token: string | null): void;
|
|
63
48
|
/**
|
|
64
|
-
*
|
|
49
|
+
* Alias para login, retornando { user, error } padrão do Showcase
|
|
65
50
|
*/
|
|
66
|
-
|
|
51
|
+
signInWithPassword(credentials: {
|
|
52
|
+
email: string;
|
|
53
|
+
password: string;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
user: User;
|
|
56
|
+
error: null;
|
|
57
|
+
} | {
|
|
58
|
+
user: null;
|
|
59
|
+
error: any;
|
|
60
|
+
}>;
|
|
67
61
|
/**
|
|
68
|
-
*
|
|
62
|
+
* Alias para register, retornando { user, error }
|
|
69
63
|
*/
|
|
70
|
-
|
|
64
|
+
signUp(credentials: {
|
|
65
|
+
email: string;
|
|
66
|
+
password: string;
|
|
67
|
+
data?: {
|
|
68
|
+
name: string;
|
|
69
|
+
};
|
|
70
|
+
}): Promise<{
|
|
71
|
+
user: any;
|
|
72
|
+
error: null;
|
|
73
|
+
} | {
|
|
74
|
+
user: null;
|
|
75
|
+
error: any;
|
|
76
|
+
}>;
|
|
71
77
|
/**
|
|
72
|
-
*
|
|
78
|
+
* Alias para logout
|
|
73
79
|
*/
|
|
74
|
-
|
|
80
|
+
signOut(): Promise<{
|
|
81
|
+
error: null;
|
|
82
|
+
}>;
|
|
75
83
|
/**
|
|
76
|
-
*
|
|
84
|
+
* Recupera a sessão atual (User + Token).
|
|
85
|
+
* Se não tiver logado, retorna null ou tenta validar o token.
|
|
77
86
|
*/
|
|
78
|
-
|
|
87
|
+
getSession(): Promise<{
|
|
88
|
+
user: User;
|
|
89
|
+
access_token: string;
|
|
90
|
+
} | null>;
|
|
79
91
|
}
|
package/dist/auth.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export class AuthModule {
|
|
2
2
|
constructor(client, http) {
|
|
3
3
|
this.refreshToken = null;
|
|
4
|
+
// Armazena o user localmente para acesso rápido via getSession
|
|
5
|
+
this.currentUser = null;
|
|
4
6
|
this.client = client;
|
|
5
7
|
this.http = http;
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
// =================================================================
|
|
10
|
+
// MÉTODOS ORIGINAIS (MANTIDOS)
|
|
11
|
+
// =================================================================
|
|
10
12
|
async login(email, password) {
|
|
11
13
|
try {
|
|
12
14
|
const { data } = await this.http.post("/auth/login", {
|
|
@@ -16,30 +18,31 @@ export class AuthModule {
|
|
|
16
18
|
if (data.accessToken) {
|
|
17
19
|
this.client.setToken(data.accessToken);
|
|
18
20
|
this.refreshToken = data.refreshToken;
|
|
21
|
+
this.currentUser = data.user;
|
|
19
22
|
}
|
|
20
23
|
return data;
|
|
21
24
|
}
|
|
22
25
|
catch (e) {
|
|
23
26
|
this.client.setToken(null);
|
|
24
27
|
this.refreshToken = null;
|
|
28
|
+
this.currentUser = null;
|
|
25
29
|
throw e;
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Registrar novo usuário
|
|
30
|
-
*/
|
|
31
32
|
async register(credentials) {
|
|
32
33
|
try {
|
|
33
34
|
const { data } = await this.http.post("/auth/register", credentials);
|
|
35
|
+
// Se o register já retornar token, configura:
|
|
36
|
+
if (data.accessToken) {
|
|
37
|
+
this.client.setToken(data.accessToken);
|
|
38
|
+
this.currentUser = data.user;
|
|
39
|
+
}
|
|
34
40
|
return data;
|
|
35
41
|
}
|
|
36
42
|
catch (e) {
|
|
37
43
|
throw e;
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Renovar access token usando refresh token
|
|
42
|
-
*/
|
|
43
46
|
async refresh() {
|
|
44
47
|
if (!this.refreshToken) {
|
|
45
48
|
throw new Error("Nenhum refresh token disponível");
|
|
@@ -59,15 +62,9 @@ export class AuthModule {
|
|
|
59
62
|
throw e;
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Obter URL de autenticação do Google
|
|
64
|
-
*/
|
|
65
65
|
getGoogleAuthUrl() {
|
|
66
66
|
return `${this.client.apiUrl}/v1/auth/google`;
|
|
67
67
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Logout da sessão atual
|
|
70
|
-
*/
|
|
71
68
|
async logout() {
|
|
72
69
|
if (this.refreshToken) {
|
|
73
70
|
try {
|
|
@@ -81,10 +78,8 @@ export class AuthModule {
|
|
|
81
78
|
}
|
|
82
79
|
this.client.setToken(null);
|
|
83
80
|
this.refreshToken = null;
|
|
81
|
+
this.currentUser = null;
|
|
84
82
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Logout de todas as sessões
|
|
87
|
-
*/
|
|
88
83
|
async logoutAll() {
|
|
89
84
|
try {
|
|
90
85
|
await this.http.post("/auth/logout-all");
|
|
@@ -92,25 +87,17 @@ export class AuthModule {
|
|
|
92
87
|
finally {
|
|
93
88
|
this.client.setToken(null);
|
|
94
89
|
this.refreshToken = null;
|
|
90
|
+
this.currentUser = null;
|
|
95
91
|
}
|
|
96
92
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Listar sessões ativas
|
|
99
|
-
*/
|
|
100
93
|
async getSessions() {
|
|
101
94
|
const { data } = await this.http.get("/auth/sessions");
|
|
102
95
|
return data.sessions;
|
|
103
96
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Esqueci minha senha
|
|
106
|
-
*/
|
|
107
97
|
async forgotPassword(email) {
|
|
108
98
|
const { data } = await this.http.post("/auth/forgot-password", { email });
|
|
109
99
|
return data;
|
|
110
100
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Redefinir senha
|
|
113
|
-
*/
|
|
114
101
|
async resetPassword(token, newPassword) {
|
|
115
102
|
const { data } = await this.http.post("/auth/reset-password", {
|
|
116
103
|
token,
|
|
@@ -118,16 +105,66 @@ export class AuthModule {
|
|
|
118
105
|
});
|
|
119
106
|
return data;
|
|
120
107
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Obter refresh token atual (para armazenamento)
|
|
123
|
-
*/
|
|
124
108
|
getRefreshToken() {
|
|
125
109
|
return this.refreshToken;
|
|
126
110
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Definir refresh token (para restaurar sessão)
|
|
129
|
-
*/
|
|
130
111
|
setRefreshToken(token) {
|
|
131
112
|
this.refreshToken = token;
|
|
132
113
|
}
|
|
114
|
+
// =================================================================
|
|
115
|
+
// NOVOS MÉTODOS (COMPATIBILIDADE COM SHOWCASE / SUPABASE STYLE)
|
|
116
|
+
// =================================================================
|
|
117
|
+
/**
|
|
118
|
+
* Alias para login, retornando { user, error } padrão do Showcase
|
|
119
|
+
*/
|
|
120
|
+
async signInWithPassword(credentials) {
|
|
121
|
+
try {
|
|
122
|
+
const data = await this.login(credentials.email, credentials.password);
|
|
123
|
+
return { user: data.user, error: null };
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
return { user: null, error: err.response?.data?.message || err.message };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Alias para register, retornando { user, error }
|
|
131
|
+
*/
|
|
132
|
+
async signUp(credentials) {
|
|
133
|
+
try {
|
|
134
|
+
const data = await this.register({
|
|
135
|
+
email: credentials.email,
|
|
136
|
+
password: credentials.password,
|
|
137
|
+
name: credentials.data?.name || credentials.email.split('@')[0],
|
|
138
|
+
});
|
|
139
|
+
return { user: data.user, error: null };
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
return { user: null, error: err.response?.data?.message || err.message };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Alias para logout
|
|
147
|
+
*/
|
|
148
|
+
async signOut() {
|
|
149
|
+
await this.logout();
|
|
150
|
+
return { error: null };
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Recupera a sessão atual (User + Token).
|
|
154
|
+
* Se não tiver logado, retorna null ou tenta validar o token.
|
|
155
|
+
*/
|
|
156
|
+
async getSession() {
|
|
157
|
+
const token = this.client.getToken();
|
|
158
|
+
if (!token)
|
|
159
|
+
return null;
|
|
160
|
+
// Se já temos o user em memória, retorna.
|
|
161
|
+
// O ideal seria validar o token no backend (/auth/me), mas vamos simplificar.
|
|
162
|
+
if (this.currentUser) {
|
|
163
|
+
return {
|
|
164
|
+
user: this.currentUser,
|
|
165
|
+
access_token: token
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
133
170
|
}
|
package/dist/database.d.ts
CHANGED
|
@@ -19,49 +19,16 @@ export declare class QueryBuilder<T> {
|
|
|
19
19
|
private limitVal?;
|
|
20
20
|
private offsetVal?;
|
|
21
21
|
constructor(collectionRef: CollectionReference<T>);
|
|
22
|
-
/**
|
|
23
|
-
* Adiciona um filtro de igualdade.
|
|
24
|
-
*/
|
|
25
22
|
eq(column: keyof T & string, value: any): this;
|
|
26
|
-
/**
|
|
27
|
-
* Adiciona um filtro de desigualdade ($ne).
|
|
28
|
-
*/
|
|
29
23
|
neq(column: keyof T & string, value: any): this;
|
|
30
|
-
/**
|
|
31
|
-
* Adiciona um filtro maior que ($gt).
|
|
32
|
-
*/
|
|
33
24
|
gt(column: keyof T & string, value: number | string): this;
|
|
34
|
-
/**
|
|
35
|
-
* Adiciona um filtro maior ou igual ($gte).
|
|
36
|
-
*/
|
|
37
25
|
gte(column: keyof T & string, value: number | string): this;
|
|
38
|
-
/**
|
|
39
|
-
* Adiciona um filtro menor que ($lt).
|
|
40
|
-
*/
|
|
41
26
|
lt(column: keyof T & string, value: number | string): this;
|
|
42
|
-
/**
|
|
43
|
-
* Adiciona um filtro menor ou igual ($lte).
|
|
44
|
-
*/
|
|
45
27
|
lte(column: keyof T & string, value: number | string): this;
|
|
46
|
-
/**
|
|
47
|
-
* Adiciona um filtro LIKE ($like).
|
|
48
|
-
*/
|
|
49
28
|
like(column: keyof T & string, value: string): this;
|
|
50
|
-
/**
|
|
51
|
-
* Define a ordenação.
|
|
52
|
-
*/
|
|
53
29
|
order(column: keyof T & string, direction?: "ASC" | "DESC"): this;
|
|
54
|
-
/**
|
|
55
|
-
* Define o limite de registros.
|
|
56
|
-
*/
|
|
57
30
|
limit(count: number): this;
|
|
58
|
-
/**
|
|
59
|
-
* Define o deslocamento (paginação).
|
|
60
|
-
*/
|
|
61
31
|
offset(count: number): this;
|
|
62
|
-
/**
|
|
63
|
-
* Executa a query e retorna os resultados.
|
|
64
|
-
*/
|
|
65
32
|
get(): Promise<T[]>;
|
|
66
33
|
}
|
|
67
34
|
/**
|
|
@@ -91,18 +58,50 @@ export declare class DatabaseModule {
|
|
|
91
58
|
/**
|
|
92
59
|
* Seleciona uma coleção de dados.
|
|
93
60
|
* [PREMIUM] Suporta Generics <T> para tipagem forte.
|
|
94
|
-
*
|
|
61
|
+
* @example client.db.collection<Product>('products')
|
|
95
62
|
*/
|
|
96
63
|
collection<T = any>(collectionName: string): CollectionReference<T>;
|
|
64
|
+
/**
|
|
65
|
+
* [NOVO] Método compatível com estilo 'Supabase/Drizzle'.
|
|
66
|
+
* É um alias para .collection() mas retorna interface compatível com o Showcase.
|
|
67
|
+
* @example client.db.from('posts').select('*')
|
|
68
|
+
*/
|
|
69
|
+
from<T = any>(tableName: string): {
|
|
70
|
+
select: (columns?: string) => Promise<{
|
|
71
|
+
data: T[];
|
|
72
|
+
error: null;
|
|
73
|
+
} | {
|
|
74
|
+
data: null;
|
|
75
|
+
error: any;
|
|
76
|
+
}>;
|
|
77
|
+
insert: (data: T) => Promise<{
|
|
78
|
+
data: Awaited<T>;
|
|
79
|
+
error: null;
|
|
80
|
+
} | {
|
|
81
|
+
data: null;
|
|
82
|
+
error: any;
|
|
83
|
+
}>;
|
|
84
|
+
update: (data: Partial<T> & {
|
|
85
|
+
id?: string;
|
|
86
|
+
}) => Promise<{
|
|
87
|
+
data: Awaited<T>;
|
|
88
|
+
error: null;
|
|
89
|
+
} | {
|
|
90
|
+
data: null;
|
|
91
|
+
error: any;
|
|
92
|
+
}>;
|
|
93
|
+
delete: () => Promise<{
|
|
94
|
+
data: null;
|
|
95
|
+
error: string;
|
|
96
|
+
}>;
|
|
97
|
+
};
|
|
97
98
|
/**
|
|
98
99
|
* Executa múltiplas operações em uma única transação.
|
|
99
|
-
* Se uma falhar, todas são revertidas.
|
|
100
100
|
*/
|
|
101
101
|
batch(operations: BatchOperation[]): Promise<any[]>;
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Referência a uma coleção específica.
|
|
105
|
-
* O <T> define o formato dos dados (ex: interface User).
|
|
106
105
|
*/
|
|
107
106
|
export declare class CollectionReference<T> {
|
|
108
107
|
private client;
|
|
@@ -110,45 +109,13 @@ export declare class CollectionReference<T> {
|
|
|
110
109
|
private collectionName;
|
|
111
110
|
private wsUrl;
|
|
112
111
|
constructor(client: PlataformaClient, http: AxiosInstance, name: string);
|
|
113
|
-
/**
|
|
114
|
-
* Inicia o QueryBuilder.
|
|
115
|
-
* Atalho para .eq()
|
|
116
|
-
*/
|
|
117
112
|
eq(column: keyof T & string, value: any): QueryBuilder<T>;
|
|
118
|
-
/**
|
|
119
|
-
* Inicia o QueryBuilder.
|
|
120
|
-
* Atalho para .gt()
|
|
121
|
-
*/
|
|
122
113
|
gt(column: keyof T & string, value: number | string): QueryBuilder<T>;
|
|
123
|
-
/**
|
|
124
|
-
* Retorna uma nova instância do QueryBuilder.
|
|
125
|
-
*/
|
|
126
114
|
query(): QueryBuilder<T>;
|
|
127
|
-
/**
|
|
128
|
-
* Lista documentos da coleção com filtros opcionais.
|
|
129
|
-
* @param options Filtros e Ordenação
|
|
130
|
-
*/
|
|
131
115
|
list(options?: ListOptions<T>): Promise<T[]>;
|
|
132
|
-
/**
|
|
133
|
-
* Busca um documento pelo ID.
|
|
134
|
-
*/
|
|
135
116
|
get(id: string): Promise<T>;
|
|
136
|
-
/**
|
|
137
|
-
* Cria um novo documento.
|
|
138
|
-
* O Partial<T> permite criar sem passar campos gerados (como id, createdAt).
|
|
139
|
-
*/
|
|
140
117
|
create(newData: Partial<T>): Promise<T>;
|
|
141
|
-
/**
|
|
142
|
-
* Atualiza um documento existente.
|
|
143
|
-
*/
|
|
144
118
|
update(id: string, updates: Partial<T>): Promise<T>;
|
|
145
|
-
/**
|
|
146
|
-
* Deleta um documento.
|
|
147
|
-
*/
|
|
148
119
|
delete(id: string): Promise<boolean>;
|
|
149
|
-
/**
|
|
150
|
-
* Inscreve-se para mudanças em tempo real.
|
|
151
|
-
* O callback recebe os dados já tipados como T.
|
|
152
|
-
*/
|
|
153
120
|
subscribe(callback: (action: "create" | "update" | "delete", data: T) => void): () => void;
|
|
154
121
|
}
|