eny-ai 1.0.0 → 2.0.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.
@@ -0,0 +1,296 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/firebase/index.ts
31
+ var firebase_exports = {};
32
+ __export(firebase_exports, {
33
+ ENYFirebase: () => ENYFirebase,
34
+ firebase: () => firebase,
35
+ useAuth: () => useAuth,
36
+ useFirebase: () => useFirebase,
37
+ useRealtimeData: () => useRealtimeData
38
+ });
39
+ module.exports = __toCommonJS(firebase_exports);
40
+ var import_app = require("firebase/app");
41
+ var import_auth = require("firebase/auth");
42
+ var import_database = require("firebase/database");
43
+ var import_react = __toESM(require("react"), 1);
44
+ var ENYFirebase = class {
45
+ constructor() {
46
+ this.app = null;
47
+ this.auth = null;
48
+ this.db = null;
49
+ }
50
+ /**
51
+ * ⚙️ - Inicializar Firebase
52
+ */
53
+ initialize(config) {
54
+ this.app = (0, import_app.initializeApp)(config);
55
+ this.auth = (0, import_auth.getAuth)(this.app);
56
+ this.db = (0, import_database.getDatabase)(this.app);
57
+ console.log("\u2705 Firebase inicializado");
58
+ }
59
+ // ═════════════════════════════════════════════════════════════════════════════
60
+ // MÉTODOS AUTENTICAÇÃO
61
+ // ═════════════════════════════════════════════════════════════════════════════
62
+ /**
63
+ * signin - Login com email/senha
64
+ * signin(email, password)
65
+ * Alias: 🔑(email, password)
66
+ */
67
+ async signin(email, password) {
68
+ if (!this.auth) throw new Error("Firebase not initialized");
69
+ try {
70
+ const credential = await (0, import_auth.signInWithEmailAndPassword)(this.auth, email, password);
71
+ console.log("\u2705 Login bem-sucedido:", email);
72
+ return {
73
+ user: credential.user,
74
+ success: true
75
+ };
76
+ } catch (error) {
77
+ console.error("\u274C Erro login:", error);
78
+ throw error;
79
+ }
80
+ }
81
+ /**
82
+ * signup - Criar conta
83
+ * signup(email, password)
84
+ * Alias: 📝(email, password)
85
+ */
86
+ async signup(email, password) {
87
+ if (!this.auth) throw new Error("Firebase not initialized");
88
+ try {
89
+ const credential = await (0, import_auth.createUserWithEmailAndPassword)(this.auth, email, password);
90
+ console.log("\u2705 Conta criada:", email);
91
+ return {
92
+ user: credential.user,
93
+ success: true
94
+ };
95
+ } catch (error) {
96
+ console.error("\u274C Erro criar conta:", error);
97
+ throw error;
98
+ }
99
+ }
100
+ /**
101
+ * signout - Logout
102
+ * signout()
103
+ * Alias: 🚪()
104
+ */
105
+ async signout() {
106
+ if (!this.auth) throw new Error("Firebase not initialized");
107
+ try {
108
+ await (0, import_auth.signOut)(this.auth);
109
+ console.log("\u{1F44B} Desconectado");
110
+ return { success: true };
111
+ } catch (error) {
112
+ console.error("\u274C Erro logout:", error);
113
+ throw error;
114
+ }
115
+ }
116
+ /**
117
+ * currentUser - Obter usuário atual
118
+ * Alias: 👤
119
+ */
120
+ get currentUser() {
121
+ return this.auth?.currentUser || null;
122
+ }
123
+ /**
124
+ * onAuthStateChange - Observar estado autenticação
125
+ * onAuthStateChange((user) => {...})
126
+ * Alias: 👁((user) => {...})
127
+ */
128
+ onAuthStateChange(callback) {
129
+ if (!this.auth) throw new Error("Firebase not initialized");
130
+ return (0, import_auth.onAuthStateChanged)(this.auth, callback);
131
+ }
132
+ // ═════════════════════════════════════════════════════════════════════════════
133
+ // MÉTODOS DATABASE
134
+ // ═════════════════════════════════════════════════════════════════════════════
135
+ /**
136
+ * write - Escrever dados
137
+ * write('users/123', { name: 'João' })
138
+ * Alias: 📊(path, data)
139
+ */
140
+ async write(path, data) {
141
+ if (!this.db) throw new Error("Firebase not initialized");
142
+ try {
143
+ const dbRef = (0, import_database.ref)(this.db, path);
144
+ await (0, import_database.set)(dbRef, data);
145
+ console.log("\u2705 Dados salvos:", path);
146
+ return { success: true };
147
+ } catch (error) {
148
+ console.error("\u274C Erro salvar:", error);
149
+ throw error;
150
+ }
151
+ }
152
+ /**
153
+ * read - Ler dados (uma vez)
154
+ * read('users/123')
155
+ * Alias: 🔍('users/123')
156
+ */
157
+ async read(path) {
158
+ if (!this.db) throw new Error("Firebase not initialized");
159
+ try {
160
+ const dbRef = (0, import_database.ref)(this.db, path);
161
+ const snapshot = await (0, import_database.get)(dbRef);
162
+ console.log("\u2705 Dados lidos:", path);
163
+ return snapshot.val();
164
+ } catch (error) {
165
+ console.error("\u274C Erro ler:", error);
166
+ throw error;
167
+ }
168
+ }
169
+ /**
170
+ * watch - Observar dados em tempo real
171
+ * watch('users/123', (data) => {...})
172
+ * Alias: 📡('users/123', (data) => {...})
173
+ */
174
+ watch(path, callback) {
175
+ if (!this.db) throw new Error("Firebase not initialized");
176
+ const dbRef = (0, import_database.ref)(this.db, path);
177
+ return (0, import_database.onValue)(dbRef, (snapshot) => {
178
+ callback(snapshot.val());
179
+ });
180
+ }
181
+ /**
182
+ * update - Atualizar dados específicos
183
+ * update('users/123', { name: 'João Silva' })
184
+ * Alias: ✏️('users/123', { name: 'João Silva' })
185
+ */
186
+ async updateData(path, data) {
187
+ if (!this.db) throw new Error("Firebase not initialized");
188
+ try {
189
+ const dbRef = (0, import_database.ref)(this.db, path);
190
+ await (0, import_database.update)(dbRef, data);
191
+ console.log("\u2705 Dados atualizados:", path);
192
+ return { success: true };
193
+ } catch (error) {
194
+ console.error("\u274C Erro atualizar:", error);
195
+ throw error;
196
+ }
197
+ }
198
+ /**
199
+ * delete - Deletar dados
200
+ * delete('users/123')
201
+ * Alias: 🗑️('users/123')
202
+ */
203
+ async delete(path) {
204
+ if (!this.db) throw new Error("Firebase not initialized");
205
+ try {
206
+ const dbRef = (0, import_database.ref)(this.db, path);
207
+ await (0, import_database.remove)(dbRef);
208
+ console.log("\u2705 Dados deletados:", path);
209
+ return { success: true };
210
+ } catch (error) {
211
+ console.error("\u274C Erro deletar:", error);
212
+ throw error;
213
+ }
214
+ }
215
+ /**
216
+ * query - Query com ordem/limite
217
+ * query('users', 'age', 10)
218
+ * Alias: 🔗('users', 'age', 10)
219
+ */
220
+ async queryData(path, orderBy = "", limit = 0) {
221
+ if (!this.db) throw new Error("Firebase not initialized");
222
+ try {
223
+ const dbRef = (0, import_database.ref)(this.db, path);
224
+ let q = dbRef;
225
+ if (orderBy) {
226
+ q = (0, import_database.query)(dbRef, (0, import_database.orderByChild)(orderBy));
227
+ }
228
+ if (limit) {
229
+ q = (0, import_database.query)(dbRef, (0, import_database.limitToFirst)(limit));
230
+ }
231
+ const snapshot = await (0, import_database.get)(q);
232
+ return snapshot.val();
233
+ } catch (error) {
234
+ console.error("\u274C Erro query:", error);
235
+ throw error;
236
+ }
237
+ }
238
+ // ═════════════════════════════════════════════════════════════════════════════
239
+ // HELPERS
240
+ // ═════════════════════════════════════════════════════════════════════════════
241
+ /**
242
+ * 🔐 - Contexto de autenticação
243
+ */
244
+ getAuth() {
245
+ return this.auth;
246
+ }
247
+ /**
248
+ * 📂 - Contexto de database
249
+ */
250
+ getDatabase() {
251
+ return this.db;
252
+ }
253
+ /**
254
+ * Verificar se está autenticado
255
+ */
256
+ isAuthenticated() {
257
+ return this.currentUser !== null;
258
+ }
259
+ };
260
+ var firebase = new ENYFirebase();
261
+ function useFirebase() {
262
+ return firebase;
263
+ }
264
+ function useAuth(callback) {
265
+ const [user, setUser] = import_react.default.useState(null);
266
+ const [loading, setLoading] = import_react.default.useState(true);
267
+ import_react.default.useEffect(() => {
268
+ const unsubscribe = firebase.onAuthStateChange((u) => {
269
+ setUser(u);
270
+ setLoading(false);
271
+ callback?.(u);
272
+ });
273
+ return () => unsubscribe();
274
+ }, [callback]);
275
+ return { user, loading };
276
+ }
277
+ function useRealtimeData(path) {
278
+ const [data, setData] = import_react.default.useState(null);
279
+ const [loading, setLoading] = import_react.default.useState(true);
280
+ import_react.default.useEffect(() => {
281
+ const unsubscribe = firebase.watch(path, (d) => {
282
+ setData(d);
283
+ setLoading(false);
284
+ });
285
+ return () => unsubscribe();
286
+ }, [path]);
287
+ return { data, loading };
288
+ }
289
+ // Annotate the CommonJS export names for ESM import in node:
290
+ 0 && (module.exports = {
291
+ ENYFirebase,
292
+ firebase,
293
+ useAuth,
294
+ useFirebase,
295
+ useRealtimeData
296
+ });
@@ -0,0 +1,136 @@
1
+ import { User } from 'firebase/auth';
2
+
3
+ /**
4
+ * 🧠 ENY-AI FIREBASE - Auth e Database 90% Simbólicos
5
+ * Firebase is an optional peer dependency
6
+ */
7
+
8
+ interface FirebaseConfig {
9
+ apiKey: string;
10
+ authDomain: string;
11
+ projectId: string;
12
+ storageBucket?: string;
13
+ messagingSenderId?: string;
14
+ appId: string;
15
+ }
16
+ declare class ENYFirebase {
17
+ private app;
18
+ private auth;
19
+ private db;
20
+ /**
21
+ * ⚙️ - Inicializar Firebase
22
+ */
23
+ initialize(config: FirebaseConfig): void;
24
+ /**
25
+ * signin - Login com email/senha
26
+ * signin(email, password)
27
+ * Alias: 🔑(email, password)
28
+ */
29
+ signin(email: string, password: string): Promise<{
30
+ user: any;
31
+ success: boolean;
32
+ }>;
33
+ /**
34
+ * signup - Criar conta
35
+ * signup(email, password)
36
+ * Alias: 📝(email, password)
37
+ */
38
+ signup(email: string, password: string): Promise<{
39
+ user: any;
40
+ success: boolean;
41
+ }>;
42
+ /**
43
+ * signout - Logout
44
+ * signout()
45
+ * Alias: 🚪()
46
+ */
47
+ signout(): Promise<{
48
+ success: boolean;
49
+ }>;
50
+ /**
51
+ * currentUser - Obter usuário atual
52
+ * Alias: 👤
53
+ */
54
+ get currentUser(): User | null;
55
+ /**
56
+ * onAuthStateChange - Observar estado autenticação
57
+ * onAuthStateChange((user) => {...})
58
+ * Alias: 👁((user) => {...})
59
+ */
60
+ onAuthStateChange(callback: (user: User | null) => void): any;
61
+ /**
62
+ * write - Escrever dados
63
+ * write('users/123', { name: 'João' })
64
+ * Alias: 📊(path, data)
65
+ */
66
+ write(path: string, data: any): Promise<{
67
+ success: boolean;
68
+ }>;
69
+ /**
70
+ * read - Ler dados (uma vez)
71
+ * read('users/123')
72
+ * Alias: 🔍('users/123')
73
+ */
74
+ read(path: string): Promise<any>;
75
+ /**
76
+ * watch - Observar dados em tempo real
77
+ * watch('users/123', (data) => {...})
78
+ * Alias: 📡('users/123', (data) => {...})
79
+ */
80
+ watch(path: string, callback: (data: any) => void): any;
81
+ /**
82
+ * update - Atualizar dados específicos
83
+ * update('users/123', { name: 'João Silva' })
84
+ * Alias: ✏️('users/123', { name: 'João Silva' })
85
+ */
86
+ updateData(path: string, data: any): Promise<{
87
+ success: boolean;
88
+ }>;
89
+ /**
90
+ * delete - Deletar dados
91
+ * delete('users/123')
92
+ * Alias: 🗑️('users/123')
93
+ */
94
+ delete(path: string): Promise<{
95
+ success: boolean;
96
+ }>;
97
+ /**
98
+ * query - Query com ordem/limite
99
+ * query('users', 'age', 10)
100
+ * Alias: 🔗('users', 'age', 10)
101
+ */
102
+ queryData(path: string, orderBy?: string, limit?: number): Promise<any>;
103
+ /**
104
+ * 🔐 - Contexto de autenticação
105
+ */
106
+ getAuth(): any;
107
+ /**
108
+ * 📂 - Contexto de database
109
+ */
110
+ getDatabase(): any;
111
+ /**
112
+ * Verificar se está autenticado
113
+ */
114
+ isAuthenticated(): boolean;
115
+ }
116
+ declare const firebase: ENYFirebase;
117
+ /**
118
+ * Hook React para Firebase
119
+ */
120
+ declare function useFirebase(): ENYFirebase;
121
+ /**
122
+ * Hook para observar autenticação
123
+ */
124
+ declare function useAuth(callback?: (user: User | null) => void): {
125
+ user: any;
126
+ loading: boolean;
127
+ };
128
+ /**
129
+ * Hook para dados em tempo real
130
+ */
131
+ declare function useRealtimeData(path: string): {
132
+ data: null;
133
+ loading: boolean;
134
+ };
135
+
136
+ export { ENYFirebase, firebase, useAuth, useFirebase, useRealtimeData };
@@ -0,0 +1,136 @@
1
+ import { User } from 'firebase/auth';
2
+
3
+ /**
4
+ * 🧠 ENY-AI FIREBASE - Auth e Database 90% Simbólicos
5
+ * Firebase is an optional peer dependency
6
+ */
7
+
8
+ interface FirebaseConfig {
9
+ apiKey: string;
10
+ authDomain: string;
11
+ projectId: string;
12
+ storageBucket?: string;
13
+ messagingSenderId?: string;
14
+ appId: string;
15
+ }
16
+ declare class ENYFirebase {
17
+ private app;
18
+ private auth;
19
+ private db;
20
+ /**
21
+ * ⚙️ - Inicializar Firebase
22
+ */
23
+ initialize(config: FirebaseConfig): void;
24
+ /**
25
+ * signin - Login com email/senha
26
+ * signin(email, password)
27
+ * Alias: 🔑(email, password)
28
+ */
29
+ signin(email: string, password: string): Promise<{
30
+ user: any;
31
+ success: boolean;
32
+ }>;
33
+ /**
34
+ * signup - Criar conta
35
+ * signup(email, password)
36
+ * Alias: 📝(email, password)
37
+ */
38
+ signup(email: string, password: string): Promise<{
39
+ user: any;
40
+ success: boolean;
41
+ }>;
42
+ /**
43
+ * signout - Logout
44
+ * signout()
45
+ * Alias: 🚪()
46
+ */
47
+ signout(): Promise<{
48
+ success: boolean;
49
+ }>;
50
+ /**
51
+ * currentUser - Obter usuário atual
52
+ * Alias: 👤
53
+ */
54
+ get currentUser(): User | null;
55
+ /**
56
+ * onAuthStateChange - Observar estado autenticação
57
+ * onAuthStateChange((user) => {...})
58
+ * Alias: 👁((user) => {...})
59
+ */
60
+ onAuthStateChange(callback: (user: User | null) => void): any;
61
+ /**
62
+ * write - Escrever dados
63
+ * write('users/123', { name: 'João' })
64
+ * Alias: 📊(path, data)
65
+ */
66
+ write(path: string, data: any): Promise<{
67
+ success: boolean;
68
+ }>;
69
+ /**
70
+ * read - Ler dados (uma vez)
71
+ * read('users/123')
72
+ * Alias: 🔍('users/123')
73
+ */
74
+ read(path: string): Promise<any>;
75
+ /**
76
+ * watch - Observar dados em tempo real
77
+ * watch('users/123', (data) => {...})
78
+ * Alias: 📡('users/123', (data) => {...})
79
+ */
80
+ watch(path: string, callback: (data: any) => void): any;
81
+ /**
82
+ * update - Atualizar dados específicos
83
+ * update('users/123', { name: 'João Silva' })
84
+ * Alias: ✏️('users/123', { name: 'João Silva' })
85
+ */
86
+ updateData(path: string, data: any): Promise<{
87
+ success: boolean;
88
+ }>;
89
+ /**
90
+ * delete - Deletar dados
91
+ * delete('users/123')
92
+ * Alias: 🗑️('users/123')
93
+ */
94
+ delete(path: string): Promise<{
95
+ success: boolean;
96
+ }>;
97
+ /**
98
+ * query - Query com ordem/limite
99
+ * query('users', 'age', 10)
100
+ * Alias: 🔗('users', 'age', 10)
101
+ */
102
+ queryData(path: string, orderBy?: string, limit?: number): Promise<any>;
103
+ /**
104
+ * 🔐 - Contexto de autenticação
105
+ */
106
+ getAuth(): any;
107
+ /**
108
+ * 📂 - Contexto de database
109
+ */
110
+ getDatabase(): any;
111
+ /**
112
+ * Verificar se está autenticado
113
+ */
114
+ isAuthenticated(): boolean;
115
+ }
116
+ declare const firebase: ENYFirebase;
117
+ /**
118
+ * Hook React para Firebase
119
+ */
120
+ declare function useFirebase(): ENYFirebase;
121
+ /**
122
+ * Hook para observar autenticação
123
+ */
124
+ declare function useAuth(callback?: (user: User | null) => void): {
125
+ user: any;
126
+ loading: boolean;
127
+ };
128
+ /**
129
+ * Hook para dados em tempo real
130
+ */
131
+ declare function useRealtimeData(path: string): {
132
+ data: null;
133
+ loading: boolean;
134
+ };
135
+
136
+ export { ENYFirebase, firebase, useAuth, useFirebase, useRealtimeData };
@@ -0,0 +1,17 @@
1
+ import {
2
+ ENYFirebase,
3
+ firebase,
4
+ init_firebase,
5
+ useAuth,
6
+ useFirebase,
7
+ useRealtimeData
8
+ } from "./chunk-5KPALVCK.js";
9
+ import "./chunk-MXA7TAAG.js";
10
+ init_firebase();
11
+ export {
12
+ ENYFirebase,
13
+ firebase,
14
+ useAuth,
15
+ useFirebase,
16
+ useRealtimeData
17
+ };