@allanfsouza/aether-sdk 2.4.11 → 2.5.0
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 +293 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/package.json +1 -1
- package/src/index.ts +16 -1
package/README.md
CHANGED
|
@@ -1,9 +1,299 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🚀 Aether SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
SDK oficial JavaScript/TypeScript para a plataforma **Aether BaaS**.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@allanfsouza/aether-sdk)
|
|
4
6
|
|
|
5
7
|
## Instalação
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
|
-
npm install @
|
|
10
|
+
npm install @allanfsouza/aether-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Inicialização
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { PlataformaClient } from '@allanfsouza/aether-sdk';
|
|
17
|
+
|
|
18
|
+
const aether = new PlataformaClient({
|
|
19
|
+
baseUrl: 'https://sua-api.aether.com',
|
|
20
|
+
apiKey: 'seu-project-id',
|
|
21
|
+
persistSession: true // Salva sessão no localStorage (padrão: true)
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 📦 Database
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
const users = aether.db.collection('users');
|
|
31
|
+
|
|
32
|
+
// Listar
|
|
33
|
+
const list = await users.list({ limit: 10 });
|
|
34
|
+
|
|
35
|
+
// Buscar por ID
|
|
36
|
+
const user = await users.get('user-id');
|
|
37
|
+
|
|
38
|
+
// Criar
|
|
39
|
+
const newUser = await users.create({ name: 'João', email: 'joao@email.com' });
|
|
40
|
+
|
|
41
|
+
// Atualizar
|
|
42
|
+
await users.update('user-id', { name: 'Novo Nome' });
|
|
43
|
+
|
|
44
|
+
// Deletar
|
|
45
|
+
await users.delete('user-id');
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Query Builder
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const adults = await aether.db.collection('users')
|
|
52
|
+
.query()
|
|
53
|
+
.eq('status', 'active')
|
|
54
|
+
.gt('age', 18)
|
|
55
|
+
.order('name', 'ASC')
|
|
56
|
+
.limit(50)
|
|
57
|
+
.get();
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 🔐 Autenticação
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// Login
|
|
66
|
+
const { accessToken, user } = await aether.auth.login('email@test.com', 'senha');
|
|
67
|
+
|
|
68
|
+
// Registro
|
|
69
|
+
await aether.auth.register({ name: 'João', email: 'joao@email.com', password: 'senha' });
|
|
70
|
+
|
|
71
|
+
// Logout
|
|
72
|
+
await aether.auth.logout();
|
|
73
|
+
|
|
74
|
+
// Sessão
|
|
75
|
+
const user = aether.auth.getCurrentUser();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 📁 Storage
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// Upload
|
|
84
|
+
const { data } = await aether.storage.upload(file, 'avatar.png', 'image/png');
|
|
85
|
+
console.log(data.downloadUrl);
|
|
86
|
+
|
|
87
|
+
// Listar
|
|
88
|
+
const files = await aether.storage.list('folder');
|
|
89
|
+
|
|
90
|
+
// Deletar
|
|
91
|
+
await aether.storage.delete('file-id');
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## ⚡ Functions
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
// Invocar função
|
|
100
|
+
const result = await aether.functions.invoke('send-email', {
|
|
101
|
+
to: 'user@email.com',
|
|
102
|
+
subject: 'Olá!',
|
|
103
|
+
body: 'Bem-vindo!'
|
|
104
|
+
});
|
|
9
105
|
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 📱 Push Notifications
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// Registrar dispositivo
|
|
113
|
+
await aether.push.registerDevice({
|
|
114
|
+
token: 'fcm-token',
|
|
115
|
+
platform: 'android',
|
|
116
|
+
environment: 'prod'
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Enviar para usuário
|
|
120
|
+
await aether.push.sendToUser({
|
|
121
|
+
userId: 'user-id',
|
|
122
|
+
title: 'Olá!',
|
|
123
|
+
body: 'Nova mensagem'
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 🤖 AI (Inteligência Artificial)
|
|
130
|
+
|
|
131
|
+
O módulo de IA permite adicionar capacidades de linguagem natural aos seus apps.
|
|
132
|
+
|
|
133
|
+
### Chat Simples
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// Pergunta simples (aguarda resposta completa)
|
|
137
|
+
const { text, conversationId } = await aether.ai.ask("Quais produtos estão em promoção?");
|
|
138
|
+
console.log(text);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Chat com Streaming
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// Resposta em tempo real (chunk por chunk)
|
|
145
|
+
await aether.ai.chat("Explique como funciona o sistema de pagamentos", {
|
|
146
|
+
conversationId: 'conv-id-opcional', // Mantém contexto
|
|
147
|
+
onChunk: (chunk) => {
|
|
148
|
+
// Atualiza UI em tempo real
|
|
149
|
+
setResponse(prev => prev + chunk);
|
|
150
|
+
},
|
|
151
|
+
onComplete: (fullResponse, meta) => {
|
|
152
|
+
console.log("Conversa:", meta.conversationId);
|
|
153
|
+
},
|
|
154
|
+
onError: (error) => {
|
|
155
|
+
console.error(error);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Busca Semântica
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// Encontra documentos similares usando embeddings
|
|
164
|
+
const results = await aether.ai.search("tênis confortável para corrida", {
|
|
165
|
+
collection: "products", // Opcional: filtrar por collection
|
|
166
|
+
limit: 10,
|
|
167
|
+
minScore: 0.7
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
results.forEach(r => console.log(r.content, r.similarity));
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Geração de Conteúdo
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
// Gera texto baseado em dados e prompt
|
|
177
|
+
const descricao = await aether.ai.generate(
|
|
178
|
+
"Escreva uma descrição para o produto",
|
|
179
|
+
{ name: "iPhone 15", price: 5999, features: ["5G", "48MP"] },
|
|
180
|
+
{ tone: 'friendly', length: 'medium', language: 'pt-BR' }
|
|
181
|
+
);
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Análise de Dados
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
// Analisa dados e retorna insights em linguagem natural
|
|
188
|
+
const { insights, data } = await aether.ai.analyze("orders", {
|
|
189
|
+
question: "Como foram as vendas essa semana?",
|
|
190
|
+
period: "7d"
|
|
191
|
+
});
|
|
192
|
+
console.log(insights);
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Conversão de Linguagem Natural para Query
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
// Converte texto em filtros estruturados
|
|
199
|
+
const query = await aether.ai.parseQuery(
|
|
200
|
+
"produtos vermelhos acima de 100 reais ordenados por preço"
|
|
201
|
+
);
|
|
202
|
+
// Retorna: { filter: { color: 'vermelho', price: { $gt: 100 } }, sort: { price: 'ASC' } }
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Gerenciar Conversas
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// Listar conversas
|
|
209
|
+
const conversas = await aether.ai.conversations.list();
|
|
210
|
+
|
|
211
|
+
// Histórico de mensagens
|
|
212
|
+
const mensagens = await aether.ai.conversations.getMessages(conversationId);
|
|
213
|
+
|
|
214
|
+
// Renomear conversa
|
|
215
|
+
await aether.ai.conversations.rename(conversationId, "Suporte Técnico");
|
|
216
|
+
|
|
217
|
+
// Deletar conversa
|
|
218
|
+
await aether.ai.conversations.delete(conversationId);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Feedback
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
// Enviar feedback sobre resposta
|
|
225
|
+
await aether.ai.feedback(messageId, 'thumbs_up');
|
|
226
|
+
await aether.ai.feedback(messageId, 'thumbs_down', 'Resposta incorreta');
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Funções Administrativas
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
// Reindexar dados para RAG
|
|
233
|
+
await aether.ai.admin.reindex();
|
|
234
|
+
|
|
235
|
+
// Estatísticas de uso
|
|
236
|
+
const stats = await aether.ai.admin.stats();
|
|
237
|
+
console.log(stats.totalConversations, stats.totalMessages);
|
|
238
|
+
|
|
239
|
+
// Configurar collections indexadas
|
|
240
|
+
await aether.ai.admin.setIndexedCollections(['products', 'articles', 'faq']);
|
|
241
|
+
|
|
242
|
+
// Limpar embeddings (CUIDADO!)
|
|
243
|
+
await aether.ai.admin.clear();
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## 👥 Tenant Auth
|
|
249
|
+
|
|
250
|
+
Para apps que precisam de sistema de login para usuários finais:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
// Registro de usuário no projeto
|
|
254
|
+
const { user } = await aether.tenantAuth.signUp('project-id', {
|
|
255
|
+
email: 'usuario@app.com',
|
|
256
|
+
password: 'senha123',
|
|
257
|
+
name: 'Nome'
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// Login
|
|
261
|
+
const { accessToken, user } = await aether.tenantAuth.signIn('project-id', {
|
|
262
|
+
email: 'usuario@app.com',
|
|
263
|
+
password: 'senha123'
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// Perfil
|
|
267
|
+
const profile = await aether.tenantAuth.getProfile();
|
|
268
|
+
|
|
269
|
+
// Logout
|
|
270
|
+
aether.tenantAuth.signOut();
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## 📖 Tipos Exportados
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
import type {
|
|
279
|
+
// Auth
|
|
280
|
+
LoginResponse, Session, User,
|
|
281
|
+
// Database
|
|
282
|
+
ListOptions,
|
|
283
|
+
// Push
|
|
284
|
+
PushDevice, PushStatus, PushStats,
|
|
285
|
+
// Tenant
|
|
286
|
+
TenantUser, TenantLoginResponse,
|
|
287
|
+
// AI
|
|
288
|
+
ChatOptions, ChatMetadata, AskResponse,
|
|
289
|
+
Conversation, Message, FeedbackType,
|
|
290
|
+
SemanticSearchOptions, SemanticSearchResult,
|
|
291
|
+
GenerateOptions, RetrievedSource
|
|
292
|
+
} from '@allanfsouza/aether-sdk';
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## 📝 Licença
|
|
298
|
+
|
|
299
|
+
MIT © Allan Felipe de Souza
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { StorageModule } from "./storage.js";
|
|
|
5
5
|
import { FunctionsModule } from "./functions.js";
|
|
6
6
|
import { PushModule } from "./push.js";
|
|
7
7
|
import { TenantAuthModule } from "./tenant-auth.js";
|
|
8
|
+
import { AIModule } from "./ai.js";
|
|
8
9
|
/**
|
|
9
10
|
* Configuração usada para criar o cliente principal da plataforma.
|
|
10
11
|
*/
|
|
@@ -31,6 +32,7 @@ export declare class PlataformaClient {
|
|
|
31
32
|
functions: FunctionsModule;
|
|
32
33
|
push: PushModule;
|
|
33
34
|
tenantAuth: TenantAuthModule;
|
|
35
|
+
ai: AIModule;
|
|
34
36
|
database: DatabaseModule;
|
|
35
37
|
apiUrl: string;
|
|
36
38
|
projectId: string;
|
|
@@ -85,3 +87,4 @@ export type { LoginResponse, Session, User } from "./auth.js";
|
|
|
85
87
|
export type { ListOptions } from "./database.js";
|
|
86
88
|
export type { PushPlatform, PushEnvironment, PushDevice, RegisterDeviceParams, SendPushResponse, PushStatus, PushLogEntry, ListPushLogsOptions, PushStats, } from "./push.js";
|
|
87
89
|
export type { TenantUser, TenantLoginResponse, TenantRegisterCredentials, TenantLoginCredentials, } from "./tenant-auth.js";
|
|
90
|
+
export type { ChatOptions, ChatMetadata, AskResponse, Conversation, Message, FeedbackType, SemanticSearchOptions, SemanticSearchResult, GenerateOptions, RetrievedSource, } from "./ai.js";
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { StorageModule } from "./storage.js";
|
|
|
5
5
|
import { FunctionsModule } from "./functions.js";
|
|
6
6
|
import { PushModule } from "./push.js";
|
|
7
7
|
import { TenantAuthModule } from "./tenant-auth.js";
|
|
8
|
+
import { AIModule } from "./ai.js";
|
|
8
9
|
// =============================================================================
|
|
9
10
|
// CONSTANTES DE STORAGE
|
|
10
11
|
// Chaves padronizadas para localStorage - evita conflito com outros SDKs
|
|
@@ -48,6 +49,7 @@ export class PlataformaClient {
|
|
|
48
49
|
this.functions = new FunctionsModule(this, this.http);
|
|
49
50
|
this.push = new PushModule(this, this.http);
|
|
50
51
|
this.tenantAuth = new TenantAuthModule(this, this.http);
|
|
52
|
+
this.ai = new AIModule(this, this.http);
|
|
51
53
|
// Cria o alias que o Showcase App espera
|
|
52
54
|
this.database = this.db;
|
|
53
55
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { StorageModule } from "./storage.js";
|
|
|
7
7
|
import { FunctionsModule } from "./functions.js";
|
|
8
8
|
import { PushModule } from "./push.js";
|
|
9
9
|
import { TenantAuthModule, TenantUser, TenantLoginResponse, TenantRegisterCredentials, TenantLoginCredentials } from "./tenant-auth.js";
|
|
10
|
+
import { AIModule } from "./ai.js";
|
|
10
11
|
|
|
11
12
|
// =============================================================================
|
|
12
13
|
// CONSTANTES DE STORAGE
|
|
@@ -59,6 +60,7 @@ export class PlataformaClient {
|
|
|
59
60
|
public functions: FunctionsModule;
|
|
60
61
|
public push: PushModule;
|
|
61
62
|
public tenantAuth: TenantAuthModule;
|
|
63
|
+
public ai: AIModule;
|
|
62
64
|
|
|
63
65
|
// Alias para 'db' que o showcase tenta usar como 'database'
|
|
64
66
|
public database: DatabaseModule;
|
|
@@ -101,6 +103,7 @@ export class PlataformaClient {
|
|
|
101
103
|
this.functions = new FunctionsModule(this, this.http);
|
|
102
104
|
this.push = new PushModule(this, this.http);
|
|
103
105
|
this.tenantAuth = new TenantAuthModule(this, this.http);
|
|
106
|
+
this.ai = new AIModule(this, this.http);
|
|
104
107
|
|
|
105
108
|
// Cria o alias que o Showcase App espera
|
|
106
109
|
this.database = this.db;
|
|
@@ -258,4 +261,16 @@ export type {
|
|
|
258
261
|
TenantLoginResponse,
|
|
259
262
|
TenantRegisterCredentials,
|
|
260
263
|
TenantLoginCredentials,
|
|
261
|
-
} from "./tenant-auth.js";
|
|
264
|
+
} from "./tenant-auth.js";
|
|
265
|
+
export type {
|
|
266
|
+
ChatOptions,
|
|
267
|
+
ChatMetadata,
|
|
268
|
+
AskResponse,
|
|
269
|
+
Conversation,
|
|
270
|
+
Message,
|
|
271
|
+
FeedbackType,
|
|
272
|
+
SemanticSearchOptions,
|
|
273
|
+
SemanticSearchResult,
|
|
274
|
+
GenerateOptions,
|
|
275
|
+
RetrievedSource,
|
|
276
|
+
} from "./ai.js";
|