@marcwelti/mw-core 0.2.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 +141 -0
- package/dist/context/index.d.mts +95 -0
- package/dist/context/index.d.ts +95 -0
- package/dist/context/index.js +280 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +276 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/firebase/index.d.mts +176 -0
- package/dist/firebase/index.d.ts +176 -0
- package/dist/firebase/index.js +393 -0
- package/dist/firebase/index.js.map +1 -0
- package/dist/firebase/index.mjs +318 -0
- package/dist/firebase/index.mjs.map +1 -0
- package/dist/hooks/index.d.mts +97 -0
- package/dist/hooks/index.d.ts +97 -0
- package/dist/hooks/index.js +618 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +611 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +922 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +843 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server/index.d.mts +216 -0
- package/dist/server/index.d.ts +216 -0
- package/dist/server/index.js +309 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +276 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/storage-BU_rfYCi.d.mts +43 -0
- package/dist/storage-BU_rfYCi.d.ts +43 -0
- package/dist/types/index.d.mts +108 -0
- package/dist/types/index.d.ts +108 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +3 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { getApps, getApp, initializeApp } from 'firebase/app';
|
|
2
|
+
import { getAuth, signInWithEmailAndPassword, createUserWithEmailAndPassword, updateProfile, signOut as signOut$1, sendPasswordResetEmail, sendEmailVerification, GoogleAuthProvider, signInWithPopup, signInWithRedirect, getRedirectResult, onAuthStateChanged } from 'firebase/auth';
|
|
3
|
+
import { getFirestore, doc, collection, getDoc, query, getDocs, addDoc, serverTimestamp, setDoc, updateDoc, deleteDoc, onSnapshot } from 'firebase/firestore';
|
|
4
|
+
export { Timestamp, limit, orderBy, query, serverTimestamp, startAfter, where } from 'firebase/firestore';
|
|
5
|
+
import { getStorage, ref, uploadBytes, getDownloadURL, uploadBytesResumable, deleteObject, listAll, getMetadata, updateMetadata } from 'firebase/storage';
|
|
6
|
+
import { isSupported, getAnalytics, logEvent } from 'firebase/analytics';
|
|
7
|
+
|
|
8
|
+
// src/firebase/config.ts
|
|
9
|
+
function getFirebaseConfig() {
|
|
10
|
+
const config = {
|
|
11
|
+
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || "",
|
|
12
|
+
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || "",
|
|
13
|
+
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || "",
|
|
14
|
+
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || "",
|
|
15
|
+
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || "",
|
|
16
|
+
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || "",
|
|
17
|
+
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
|
|
18
|
+
};
|
|
19
|
+
const requiredFields = [
|
|
20
|
+
"apiKey",
|
|
21
|
+
"authDomain",
|
|
22
|
+
"projectId",
|
|
23
|
+
"storageBucket",
|
|
24
|
+
"messagingSenderId",
|
|
25
|
+
"appId"
|
|
26
|
+
];
|
|
27
|
+
const missingFields = requiredFields.filter((field) => !config[field]);
|
|
28
|
+
if (missingFields.length > 0) {
|
|
29
|
+
console.warn(
|
|
30
|
+
`[mw-core] Missing Firebase config fields: ${missingFields.join(", ")}. Make sure to set NEXT_PUBLIC_FIREBASE_* environment variables.`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return config;
|
|
34
|
+
}
|
|
35
|
+
function initializeFirebase(config) {
|
|
36
|
+
if (getApps().length > 0) {
|
|
37
|
+
return getApp();
|
|
38
|
+
}
|
|
39
|
+
const firebaseConfig = config || getFirebaseConfig();
|
|
40
|
+
return initializeApp(firebaseConfig);
|
|
41
|
+
}
|
|
42
|
+
var _app = null;
|
|
43
|
+
var _auth = null;
|
|
44
|
+
var _db = null;
|
|
45
|
+
var _storage = null;
|
|
46
|
+
function getFirebaseApp() {
|
|
47
|
+
if (!_app) {
|
|
48
|
+
_app = initializeFirebase();
|
|
49
|
+
}
|
|
50
|
+
return _app;
|
|
51
|
+
}
|
|
52
|
+
function getFirebaseAuth() {
|
|
53
|
+
if (!_auth) {
|
|
54
|
+
_auth = getAuth(getFirebaseApp());
|
|
55
|
+
}
|
|
56
|
+
return _auth;
|
|
57
|
+
}
|
|
58
|
+
function getFirebaseFirestore() {
|
|
59
|
+
if (!_db) {
|
|
60
|
+
_db = getFirestore(getFirebaseApp());
|
|
61
|
+
}
|
|
62
|
+
return _db;
|
|
63
|
+
}
|
|
64
|
+
function getFirebaseStorage() {
|
|
65
|
+
if (!_storage) {
|
|
66
|
+
_storage = getStorage(getFirebaseApp());
|
|
67
|
+
}
|
|
68
|
+
return _storage;
|
|
69
|
+
}
|
|
70
|
+
var app = typeof window !== "undefined" ? getFirebaseApp() : null;
|
|
71
|
+
var auth = typeof window !== "undefined" ? getFirebaseAuth() : null;
|
|
72
|
+
var db = typeof window !== "undefined" ? getFirebaseFirestore() : null;
|
|
73
|
+
var storage = typeof window !== "undefined" ? getFirebaseStorage() : null;
|
|
74
|
+
async function signInWithEmail(email, password) {
|
|
75
|
+
const auth2 = getFirebaseAuth();
|
|
76
|
+
return signInWithEmailAndPassword(auth2, email, password);
|
|
77
|
+
}
|
|
78
|
+
async function signUpWithEmail(email, password, displayName) {
|
|
79
|
+
const auth2 = getFirebaseAuth();
|
|
80
|
+
const credential = await createUserWithEmailAndPassword(auth2, email, password);
|
|
81
|
+
if (displayName && credential.user) {
|
|
82
|
+
await updateProfile(credential.user, { displayName });
|
|
83
|
+
}
|
|
84
|
+
return credential;
|
|
85
|
+
}
|
|
86
|
+
async function signOut() {
|
|
87
|
+
const auth2 = getFirebaseAuth();
|
|
88
|
+
return signOut$1(auth2);
|
|
89
|
+
}
|
|
90
|
+
async function resetPassword(email) {
|
|
91
|
+
const auth2 = getFirebaseAuth();
|
|
92
|
+
return sendPasswordResetEmail(auth2, email);
|
|
93
|
+
}
|
|
94
|
+
async function sendVerificationEmail(user) {
|
|
95
|
+
return sendEmailVerification(user);
|
|
96
|
+
}
|
|
97
|
+
async function updateUserProfile(user, profile) {
|
|
98
|
+
return updateProfile(user, profile);
|
|
99
|
+
}
|
|
100
|
+
async function signInWithGoogle() {
|
|
101
|
+
const auth2 = getFirebaseAuth();
|
|
102
|
+
const provider = new GoogleAuthProvider();
|
|
103
|
+
provider.addScope("email");
|
|
104
|
+
provider.addScope("profile");
|
|
105
|
+
return signInWithPopup(auth2, provider);
|
|
106
|
+
}
|
|
107
|
+
async function signInWithGoogleRedirect() {
|
|
108
|
+
const auth2 = getFirebaseAuth();
|
|
109
|
+
const provider = new GoogleAuthProvider();
|
|
110
|
+
provider.addScope("email");
|
|
111
|
+
provider.addScope("profile");
|
|
112
|
+
return signInWithRedirect(auth2, provider);
|
|
113
|
+
}
|
|
114
|
+
async function getGoogleRedirectResult() {
|
|
115
|
+
const auth2 = getFirebaseAuth();
|
|
116
|
+
return getRedirectResult(auth2);
|
|
117
|
+
}
|
|
118
|
+
function subscribeToAuthState(callback) {
|
|
119
|
+
const auth2 = getFirebaseAuth();
|
|
120
|
+
return onAuthStateChanged(auth2, callback);
|
|
121
|
+
}
|
|
122
|
+
function getCurrentUser() {
|
|
123
|
+
const auth2 = getFirebaseAuth();
|
|
124
|
+
return auth2.currentUser;
|
|
125
|
+
}
|
|
126
|
+
function waitForAuthState() {
|
|
127
|
+
return new Promise((resolve) => {
|
|
128
|
+
const auth2 = getFirebaseAuth();
|
|
129
|
+
const unsubscribe = onAuthStateChanged(auth2, (user) => {
|
|
130
|
+
unsubscribe();
|
|
131
|
+
resolve(user);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function getDocRef(collectionPath, documentId) {
|
|
136
|
+
const db2 = getFirebaseFirestore();
|
|
137
|
+
return doc(db2, collectionPath, documentId);
|
|
138
|
+
}
|
|
139
|
+
function getCollectionRef(collectionPath) {
|
|
140
|
+
const db2 = getFirebaseFirestore();
|
|
141
|
+
return collection(db2, collectionPath);
|
|
142
|
+
}
|
|
143
|
+
async function getDocument(collectionPath, documentId) {
|
|
144
|
+
const docRef = getDocRef(collectionPath, documentId);
|
|
145
|
+
const docSnap = await getDoc(docRef);
|
|
146
|
+
if (docSnap.exists()) {
|
|
147
|
+
return { id: docSnap.id, ...docSnap.data() };
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
async function getCollection(collectionPath, constraints = []) {
|
|
152
|
+
const collectionRef = getCollectionRef(collectionPath);
|
|
153
|
+
const q = query(collectionRef, ...constraints);
|
|
154
|
+
const querySnapshot = await getDocs(q);
|
|
155
|
+
return querySnapshot.docs.map((doc2) => ({
|
|
156
|
+
id: doc2.id,
|
|
157
|
+
...doc2.data()
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
async function addDocument(collectionPath, data) {
|
|
161
|
+
const collectionRef = getCollectionRef(collectionPath);
|
|
162
|
+
const docRef = await addDoc(collectionRef, {
|
|
163
|
+
...data,
|
|
164
|
+
createdAt: serverTimestamp(),
|
|
165
|
+
updatedAt: serverTimestamp()
|
|
166
|
+
});
|
|
167
|
+
return docRef.id;
|
|
168
|
+
}
|
|
169
|
+
async function setDocument(collectionPath, documentId, data, merge = false) {
|
|
170
|
+
const docRef = getDocRef(collectionPath, documentId);
|
|
171
|
+
await setDoc(
|
|
172
|
+
docRef,
|
|
173
|
+
{
|
|
174
|
+
...data,
|
|
175
|
+
updatedAt: serverTimestamp(),
|
|
176
|
+
...merge ? {} : { createdAt: serverTimestamp() }
|
|
177
|
+
},
|
|
178
|
+
{ merge }
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
async function updateDocument(collectionPath, documentId, data) {
|
|
182
|
+
const docRef = getDocRef(collectionPath, documentId);
|
|
183
|
+
await updateDoc(docRef, {
|
|
184
|
+
...data,
|
|
185
|
+
updatedAt: serverTimestamp()
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async function deleteDocument(collectionPath, documentId) {
|
|
189
|
+
const docRef = getDocRef(collectionPath, documentId);
|
|
190
|
+
await deleteDoc(docRef);
|
|
191
|
+
}
|
|
192
|
+
function subscribeToDocument(collectionPath, documentId, callback) {
|
|
193
|
+
const docRef = getDocRef(collectionPath, documentId);
|
|
194
|
+
return onSnapshot(docRef, (docSnap) => {
|
|
195
|
+
if (docSnap.exists()) {
|
|
196
|
+
callback({ id: docSnap.id, ...docSnap.data() });
|
|
197
|
+
} else {
|
|
198
|
+
callback(null);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function subscribeToCollection(collectionPath, callback, constraints = []) {
|
|
203
|
+
const collectionRef = getCollectionRef(collectionPath);
|
|
204
|
+
const q = query(collectionRef, ...constraints);
|
|
205
|
+
return onSnapshot(q, (querySnapshot) => {
|
|
206
|
+
const data = querySnapshot.docs.map((doc2) => ({
|
|
207
|
+
id: doc2.id,
|
|
208
|
+
...doc2.data()
|
|
209
|
+
}));
|
|
210
|
+
callback(data);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
function getStorageRef(path) {
|
|
214
|
+
const storage2 = getFirebaseStorage();
|
|
215
|
+
return ref(storage2, path);
|
|
216
|
+
}
|
|
217
|
+
async function uploadFile(path, file, metadata) {
|
|
218
|
+
const storageRef = getStorageRef(path);
|
|
219
|
+
await uploadBytes(storageRef, file, metadata);
|
|
220
|
+
return getDownloadURL(storageRef);
|
|
221
|
+
}
|
|
222
|
+
function uploadFileWithProgress(path, file, onProgress, metadata) {
|
|
223
|
+
const storageRef = getStorageRef(path);
|
|
224
|
+
const task = uploadBytesResumable(storageRef, file, metadata);
|
|
225
|
+
if (onProgress) {
|
|
226
|
+
task.on("state_changed", (snapshot) => {
|
|
227
|
+
const progress = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
|
228
|
+
onProgress(progress);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
const promise = new Promise((resolve, reject) => {
|
|
232
|
+
task.on(
|
|
233
|
+
"state_changed",
|
|
234
|
+
null,
|
|
235
|
+
(error) => reject(error),
|
|
236
|
+
async () => {
|
|
237
|
+
const url = await getDownloadURL(task.snapshot.ref);
|
|
238
|
+
resolve(url);
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
return { task, promise };
|
|
243
|
+
}
|
|
244
|
+
async function getFileURL(path) {
|
|
245
|
+
const storageRef = getStorageRef(path);
|
|
246
|
+
return getDownloadURL(storageRef);
|
|
247
|
+
}
|
|
248
|
+
async function deleteFile(path) {
|
|
249
|
+
const storageRef = getStorageRef(path);
|
|
250
|
+
return deleteObject(storageRef);
|
|
251
|
+
}
|
|
252
|
+
async function listFiles(path) {
|
|
253
|
+
const storageRef = getStorageRef(path);
|
|
254
|
+
return listAll(storageRef);
|
|
255
|
+
}
|
|
256
|
+
async function getFileMetadata(path) {
|
|
257
|
+
const storageRef = getStorageRef(path);
|
|
258
|
+
return getMetadata(storageRef);
|
|
259
|
+
}
|
|
260
|
+
async function updateFileMetadata(path, metadata) {
|
|
261
|
+
const storageRef = getStorageRef(path);
|
|
262
|
+
return updateMetadata(storageRef, metadata);
|
|
263
|
+
}
|
|
264
|
+
function generateFilePath(folder, filename, userId) {
|
|
265
|
+
const timestamp = Date.now();
|
|
266
|
+
const extension = filename.split(".").pop() || "";
|
|
267
|
+
const baseName = filename.replace(/\.[^/.]+$/, "");
|
|
268
|
+
const sanitizedName = baseName.replace(/[^a-zA-Z0-9]/g, "_");
|
|
269
|
+
if (userId) {
|
|
270
|
+
return `${folder}/${userId}/${timestamp}_${sanitizedName}.${extension}`;
|
|
271
|
+
}
|
|
272
|
+
return `${folder}/${timestamp}_${sanitizedName}.${extension}`;
|
|
273
|
+
}
|
|
274
|
+
var _analytics = null;
|
|
275
|
+
async function getFirebaseAnalytics() {
|
|
276
|
+
if (typeof window === "undefined") {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
if (_analytics) {
|
|
280
|
+
return _analytics;
|
|
281
|
+
}
|
|
282
|
+
const supported = await isSupported();
|
|
283
|
+
if (!supported) {
|
|
284
|
+
console.warn("[mw-core] Firebase Analytics is not supported in this environment");
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
_analytics = getAnalytics(getFirebaseApp());
|
|
288
|
+
return _analytics;
|
|
289
|
+
}
|
|
290
|
+
async function trackEvent(eventName, eventParams) {
|
|
291
|
+
const analytics = await getFirebaseAnalytics();
|
|
292
|
+
if (analytics) {
|
|
293
|
+
logEvent(analytics, eventName, eventParams);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async function trackPageView(pagePath, pageTitle) {
|
|
297
|
+
await trackEvent("page_view", {
|
|
298
|
+
page_path: pagePath,
|
|
299
|
+
page_title: pageTitle
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
async function trackUserAction(action, category, label, value) {
|
|
303
|
+
await trackEvent(action, {
|
|
304
|
+
event_category: category,
|
|
305
|
+
event_label: label,
|
|
306
|
+
value
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async function trackSignUp(method) {
|
|
310
|
+
await trackEvent("sign_up", { method });
|
|
311
|
+
}
|
|
312
|
+
async function trackLogin(method) {
|
|
313
|
+
await trackEvent("login", { method });
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export { addDocument, app, auth, db, deleteDocument, deleteFile, generateFilePath, getCollection, getCollectionRef, getCurrentUser, getDocRef, getDocument, getFileMetadata, getFileURL, getFirebaseAnalytics, getFirebaseApp, getFirebaseAuth, getFirebaseConfig, getFirebaseFirestore, getFirebaseStorage, getGoogleRedirectResult, getStorageRef, initializeFirebase, listFiles, resetPassword, sendVerificationEmail, setDocument, signInWithEmail, signInWithGoogle, signInWithGoogleRedirect, signOut, signUpWithEmail, storage, subscribeToAuthState, subscribeToCollection, subscribeToDocument, trackEvent, trackLogin, trackPageView, trackSignUp, trackUserAction, updateDocument, updateFileMetadata, updateUserProfile, uploadFile, uploadFileWithProgress, waitForAuthState };
|
|
317
|
+
//# sourceMappingURL=index.mjs.map
|
|
318
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/firebase/config.ts","../../src/firebase/auth.ts","../../src/firebase/firestore.ts","../../src/firebase/storage.ts","../../src/firebase/analytics.ts"],"names":["auth","firebaseSignOut","db","doc","storage"],"mappings":";;;;;;;;AAuBO,SAAS,iBAAA,GAAoC;AAClD,EAAA,MAAM,MAAA,GAAyB;AAAA,IAC7B,MAAA,EAAQ,OAAA,CAAQ,GAAA,CAAI,4BAAA,IAAgC,EAAA;AAAA,IACpD,UAAA,EAAY,OAAA,CAAQ,GAAA,CAAI,gCAAA,IAAoC,EAAA;AAAA,IAC5D,SAAA,EAAW,OAAA,CAAQ,GAAA,CAAI,+BAAA,IAAmC,EAAA;AAAA,IAC1D,aAAA,EAAe,OAAA,CAAQ,GAAA,CAAI,mCAAA,IAAuC,EAAA;AAAA,IAClE,iBAAA,EAAmB,OAAA,CAAQ,GAAA,CAAI,wCAAA,IAA4C,EAAA;AAAA,IAC3E,KAAA,EAAO,OAAA,CAAQ,GAAA,CAAI,2BAAA,IAA+B,EAAA;AAAA,IAClD,aAAA,EAAe,QAAQ,GAAA,CAAI;AAAA,GAC7B;AAGA,EAAA,MAAM,cAAA,GAA2C;AAAA,IAC/C,Q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,SAAA,EAAW,WAAW,WAAW,CAAA;AAAA,EAC5C;AACF;AAKA,eAAsB,aAAA,CACpB,UACA,SAAA,EACe;AACf,EAAA,MAAM,WAAW,WAAA,EAAa;AAAA,IAC5B,SAAA,EAAW,QAAA;AAAA,IACX,UAAA,EAAY;AAAA,GACb,CAAA;AACH;AAKA,eAAsB,eAAA,CACpB,MAAA,EACA,QAAA,EACA,KAAA,EACA,KAAA,EACe;AACf,EAAA,MAAM,WAAW,MAAA,EAAQ;AAAA,IACvB,cAAA,EAAgB,QAAA;AAAA,IAChB,WAAA,EAAa,KAAA;AAAA,IACb;AAAA,GACD,CAAA;AACH;AAKA,eAAsB,YAAY,MAAA,EAA+B;AAC/D,EAAA,MAAM,UAAA,CAAW,SAAA,EAAW,EAAE,MAAA,EAAQ,CAAA;AACxC;AAKA,eAAsB,WAAW,MAAA,EAA+B;AAC9D,EAAA,MAAM,UAAA,CAAW,OAAA,EAAS,EAAE,MAAA,EAAQ,CAAA;AACtC","file":"index.mjs","sourcesContent":["import { initializeApp, getApps, getApp, FirebaseApp } from 'firebase/app';\nimport { getAuth, Auth } from 'firebase/auth';\nimport { getFirestore, Firestore } from 'firebase/firestore';\nimport { getStorage, FirebaseStorage } from 'firebase/storage';\n\n/**\n * Firebase configuration interface\n * All values should be provided via environment variables\n */\nexport interface FirebaseConfig {\n apiKey: string;\n authDomain: string;\n projectId: string;\n storageBucket: string;\n messagingSenderId: string;\n appId: string;\n measurementId?: string;\n}\n\n/**\n * Get Firebase configuration from environment variables\n * Works with Next.js NEXT_PUBLIC_ prefix\n */\nexport function getFirebaseConfig(): FirebaseConfig {\n const config: FirebaseConfig = {\n apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || '',\n authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || '',\n projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || '',\n storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || '',\n messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || '',\n appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || '',\n measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,\n };\n\n // Validate required fields\n const requiredFields: (keyof FirebaseConfig)[] = [\n 'apiKey',\n 'authDomain',\n 'projectId',\n 'storageBucket',\n 'messagingSenderId',\n 'appId',\n ];\n\n const missingFields = requiredFields.filter((field) => !config[field]);\n\n if (missingFields.length > 0) {\n console.warn(\n `[mw-core] Missing Firebase config fields: ${missingFields.join(', ')}. ` +\n `Make sure to set NEXT_PUBLIC_FIREBASE_* environment variables.`\n );\n }\n\n return config;\n}\n\n/**\n * Initialize Firebase app (singleton pattern)\n * Safe to call multiple times - returns existing instance if already initialized\n */\nexport function initializeFirebase(config?: FirebaseConfig): FirebaseApp {\n if (getApps().length > 0) {\n return getApp();\n }\n\n const firebaseConfig = config || getFirebaseConfig();\n return initializeApp(firebaseConfig);\n}\n\n// Lazy initialization singletons\nlet _app: FirebaseApp | null = null;\nlet _auth: Auth | null = null;\nlet _db: Firestore | null = null;\nlet _storage: FirebaseStorage | null = null;\n\n/**\n * Get the Firebase app instance\n */\nexport function getFirebaseApp(): FirebaseApp {\n if (!_app) {\n _app = initializeFirebase();\n }\n return _app;\n}\n\n/**\n * Get the Firebase Auth instance\n */\nexport function getFirebaseAuth(): Auth {\n if (!_auth) {\n _auth = getAuth(getFirebaseApp());\n }\n return _auth;\n}\n\n/**\n * Get the Firestore database instance\n */\nexport function getFirebaseFirestore(): Firestore {\n if (!_db) {\n _db = getFirestore(getFirebaseApp());\n }\n return _db;\n}\n\n/**\n * Get the Firebase Storage instance\n */\nexport function getFirebaseStorage(): FirebaseStorage {\n if (!_storage) {\n _storage = getStorage(getFirebaseApp());\n }\n return _storage;\n}\n\n// Convenience exports for direct access\nexport const app = typeof window !== 'undefined' ? getFirebaseApp() : null;\nexport const auth = typeof window !== 'undefined' ? getFirebaseAuth() : null;\nexport const db = typeof window !== 'undefined' ? getFirebaseFirestore() : null;\nexport const storage = typeof window !== 'undefined' ? getFirebaseStorage() : null;\n\n","import {\n signInWithEmailAndPassword,\n createUserWithEmailAndPassword,\n signOut as firebaseSignOut,\n sendPasswordResetEmail,\n sendEmailVerification,\n updateProfile,\n GoogleAuthProvider,\n signInWithPopup,\n signInWithRedirect,\n getRedirectResult,\n onAuthStateChanged,\n User,\n UserCredential,\n Auth,\n} from 'firebase/auth';\nimport { getFirebaseAuth } from './config';\n\n/**\n * Sign in with email and password\n */\nexport async function signInWithEmail(\n email: string,\n password: string\n): Promise<UserCredential> {\n const auth = getFirebaseAuth();\n return signInWithEmailAndPassword(auth, email, password);\n}\n\n/**\n * Create a new account with email and password\n */\nexport async function signUpWithEmail(\n email: string,\n password: string,\n displayName?: string\n): Promise<UserCredential> {\n const auth = getFirebaseAuth();\n const credential = await createUserWithEmailAndPassword(auth, email, password);\n \n if (displayName && credential.user) {\n await updateProfile(credential.user, { displayName });\n }\n \n return credential;\n}\n\n/**\n * Sign out the current user\n */\nexport async function signOut(): Promise<void> {\n const auth = getFirebaseAuth();\n return firebaseSignOut(auth);\n}\n\n/**\n * Send a password reset email\n */\nexport async function resetPassword(email: string): Promise<void> {\n const auth = getFirebaseAuth();\n return sendPasswordResetEmail(auth, email);\n}\n\n/**\n * Send email verification to the current user\n */\nexport async function sendVerificationEmail(user: User): Promise<void> {\n return sendEmailVerification(user);\n}\n\n/**\n * Update the current user's profile\n */\nexport async function updateUserProfile(\n user: User,\n profile: { displayName?: string; photoURL?: string }\n): Promise<void> {\n return updateProfile(user, profile);\n}\n\n/**\n * Sign in with Google using popup\n */\nexport async function signInWithGoogle(): Promise<UserCredential> {\n const auth = getFirebaseAuth();\n const provider = new GoogleAuthProvider();\n provider.addScope('email');\n provider.addScope('profile');\n return signInWithPopup(auth, provider);\n}\n\n/**\n * Sign in with Google using redirect (better for mobile)\n */\nexport async function signInWithGoogleRedirect(): Promise<void> {\n const auth = getFirebaseAuth();\n const provider = new GoogleAuthProvider();\n provider.addScope('email');\n provider.addScope('profile');\n return signInWithRedirect(auth, provider);\n}\n\n/**\n * Get the result of a redirect sign-in\n */\nexport async function getGoogleRedirectResult(): Promise<UserCredential | null> {\n const auth = getFirebaseAuth();\n return getRedirectResult(auth);\n}\n\n/**\n * Subscribe to auth state changes\n */\nexport function subscribeToAuthState(\n callback: (user: User | null) => void\n): () => void {\n const auth = getFirebaseAuth();\n return onAuthStateChanged(auth, callback);\n}\n\n/**\n * Get the current user (may be null if not authenticated)\n */\nexport function getCurrentUser(): User | null {\n const auth = getFirebaseAuth();\n return auth.currentUser;\n}\n\n/**\n * Wait for the auth state to be determined\n * Useful for SSR/initial load\n */\nexport function waitForAuthState(): Promise<User | null> {\n return new Promise((resolve) => {\n const auth = getFirebaseAuth();\n const unsubscribe = onAuthStateChanged(auth, (user) => {\n unsubscribe();\n resolve(user);\n });\n });\n}\n\n// Re-export useful types\nexport type { User, UserCredential, Auth };\n\n","import {\n collection,\n doc,\n getDoc,\n getDocs,\n setDoc,\n updateDoc,\n deleteDoc,\n addDoc,\n query,\n where,\n orderBy,\n limit,\n startAfter,\n onSnapshot,\n DocumentData,\n DocumentReference,\n CollectionReference,\n QueryConstraint,\n DocumentSnapshot,\n QuerySnapshot,\n Timestamp,\n serverTimestamp,\n FieldValue,\n WhereFilterOp,\n OrderByDirection,\n Unsubscribe,\n} from 'firebase/firestore';\nimport { getFirebaseFirestore } from './config';\n\n/**\n * Get a document reference\n */\nexport function getDocRef<T = DocumentData>(\n collectionPath: string,\n documentId: string\n): DocumentReference<T> {\n const db = getFirebaseFirestore();\n return doc(db, collectionPath, documentId) as DocumentReference<T>;\n}\n\n/**\n * Get a collection reference\n */\nexport function getCollectionRef<T = DocumentData>(\n collectionPath: string\n): CollectionReference<T> {\n const db = getFirebaseFirestore();\n return collection(db, collectionPath) as CollectionReference<T>;\n}\n\n/**\n * Get a single document by ID\n */\nexport async function getDocument<T = DocumentData>(\n collectionPath: string,\n documentId: string\n): Promise<T | null> {\n const docRef = getDocRef<T>(collectionPath, documentId);\n const docSnap = await getDoc(docRef);\n \n if (docSnap.exists()) {\n return { id: docSnap.id, ...docSnap.data() } as T;\n }\n \n return null;\n}\n\n/**\n * Get all documents in a collection\n */\nexport async function getCollection<T = DocumentData>(\n collectionPath: string,\n constraints: QueryConstraint[] = []\n): Promise<T[]> {\n const collectionRef = getCollectionRef<T>(collectionPath);\n const q = query(collectionRef, ...constraints);\n const querySnapshot = await getDocs(q);\n \n return querySnapshot.docs.map((doc) => ({\n id: doc.id,\n ...doc.data(),\n })) as T[];\n}\n\n/**\n * Add a new document with auto-generated ID\n */\nexport async function addDocument<T = DocumentData>(\n collectionPath: string,\n data: Omit<T, 'id'>\n): Promise<string> {\n const collectionRef = getCollectionRef(collectionPath);\n const docRef = await addDoc(collectionRef, {\n ...data,\n createdAt: serverTimestamp(),\n updatedAt: serverTimestamp(),\n });\n return docRef.id;\n}\n\n/**\n * Set/create a document with a specific ID\n */\nexport async function setDocument<T = DocumentData>(\n collectionPath: string,\n documentId: string,\n data: Omit<T, 'id'>,\n merge: boolean = false\n): Promise<void> {\n const docRef = getDocRef(collectionPath, documentId);\n await setDoc(\n docRef,\n {\n ...data,\n updatedAt: serverTimestamp(),\n ...(merge ? {} : { createdAt: serverTimestamp() }),\n },\n { merge }\n );\n}\n\n/**\n * Update specific fields in a document\n */\nexport async function updateDocument<T = DocumentData>(\n collectionPath: string,\n documentId: string,\n data: Partial<T>\n): Promise<void> {\n const docRef = getDocRef(collectionPath, documentId);\n await updateDoc(docRef, {\n ...data,\n updatedAt: serverTimestamp(),\n });\n}\n\n/**\n * Delete a document\n */\nexport async function deleteDocument(\n collectionPath: string,\n documentId: string\n): Promise<void> {\n const docRef = getDocRef(collectionPath, documentId);\n await deleteDoc(docRef);\n}\n\n/**\n * Subscribe to a single document\n */\nexport function subscribeToDocument<T = DocumentData>(\n collectionPath: string,\n documentId: string,\n callback: (data: T | null) => void\n): Unsubscribe {\n const docRef = getDocRef<T>(collectionPath, documentId);\n \n return onSnapshot(docRef, (docSnap) => {\n if (docSnap.exists()) {\n callback({ id: docSnap.id, ...docSnap.data() } as T);\n } else {\n callback(null);\n }\n });\n}\n\n/**\n * Subscribe to a collection\n */\nexport function subscribeToCollection<T = DocumentData>(\n collectionPath: string,\n callback: (data: T[]) => void,\n constraints: QueryConstraint[] = []\n): Unsubscribe {\n const collectionRef = getCollectionRef<T>(collectionPath);\n const q = query(collectionRef, ...constraints);\n \n return onSnapshot(q, (querySnapshot) => {\n const data = querySnapshot.docs.map((doc) => ({\n id: doc.id,\n ...doc.data(),\n })) as T[];\n callback(data);\n });\n}\n\n// Export query helpers for convenience\nexport {\n query,\n where,\n orderBy,\n limit,\n startAfter,\n Timestamp,\n serverTimestamp,\n};\n\n// Re-export types\nexport type {\n DocumentData,\n DocumentReference,\n CollectionReference,\n QueryConstraint,\n DocumentSnapshot,\n QuerySnapshot,\n FieldValue,\n WhereFilterOp,\n OrderByDirection,\n Unsubscribe,\n};\n\n","import {\n ref,\n uploadBytes,\n uploadBytesResumable,\n getDownloadURL,\n deleteObject,\n listAll,\n getMetadata,\n updateMetadata,\n StorageReference,\n UploadTask,\n UploadMetadata,\n FullMetadata,\n ListResult,\n} from 'firebase/storage';\nimport { getFirebaseStorage } from './config';\n\n/**\n * Get a reference to a storage location\n */\nexport function getStorageRef(path: string): StorageReference {\n const storage = getFirebaseStorage();\n return ref(storage, path);\n}\n\n/**\n * Upload a file to storage\n */\nexport async function uploadFile(\n path: string,\n file: Blob | Uint8Array | ArrayBuffer,\n metadata?: UploadMetadata\n): Promise<string> {\n const storageRef = getStorageRef(path);\n await uploadBytes(storageRef, file, metadata);\n return getDownloadURL(storageRef);\n}\n\n/**\n * Upload a file with progress tracking\n */\nexport function uploadFileWithProgress(\n path: string,\n file: Blob | Uint8Array | ArrayBuffer,\n onProgress?: (progress: number) => void,\n metadata?: UploadMetadata\n): { task: UploadTask; promise: Promise<string> } {\n const storageRef = getStorageRef(path);\n const task = uploadBytesResumable(storageRef, file, metadata);\n \n if (onProgress) {\n task.on('state_changed', (snapshot) => {\n const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;\n onProgress(progress);\n });\n }\n \n const promise = new Promise<string>((resolve, reject) => {\n task.on(\n 'state_changed',\n null,\n (error) => reject(error),\n async () => {\n const url = await getDownloadURL(task.snapshot.ref);\n resolve(url);\n }\n );\n });\n \n return { task, promise };\n}\n\n/**\n * Get the download URL for a file\n */\nexport async function getFileURL(path: string): Promise<string> {\n const storageRef = getStorageRef(path);\n return getDownloadURL(storageRef);\n}\n\n/**\n * Delete a file from storage\n */\nexport async function deleteFile(path: string): Promise<void> {\n const storageRef = getStorageRef(path);\n return deleteObject(storageRef);\n}\n\n/**\n * List all files in a directory\n */\nexport async function listFiles(path: string): Promise<ListResult> {\n const storageRef = getStorageRef(path);\n return listAll(storageRef);\n}\n\n/**\n * Get metadata for a file\n */\nexport async function getFileMetadata(path: string): Promise<FullMetadata> {\n const storageRef = getStorageRef(path);\n return getMetadata(storageRef);\n}\n\n/**\n * Update metadata for a file\n */\nexport async function updateFileMetadata(\n path: string,\n metadata: Partial<UploadMetadata>\n): Promise<FullMetadata> {\n const storageRef = getStorageRef(path);\n return updateMetadata(storageRef, metadata);\n}\n\n/**\n * Generate a unique file path with timestamp\n */\nexport function generateFilePath(\n folder: string,\n filename: string,\n userId?: string\n): string {\n const timestamp = Date.now();\n const extension = filename.split('.').pop() || '';\n const baseName = filename.replace(/\\.[^/.]+$/, '');\n const sanitizedName = baseName.replace(/[^a-zA-Z0-9]/g, '_');\n \n if (userId) {\n return `${folder}/${userId}/${timestamp}_${sanitizedName}.${extension}`;\n }\n \n return `${folder}/${timestamp}_${sanitizedName}.${extension}`;\n}\n\n// Re-export types\nexport type {\n StorageReference,\n UploadTask,\n UploadMetadata,\n FullMetadata,\n ListResult,\n};\n\n","import { getAnalytics, logEvent, Analytics, isSupported } from 'firebase/analytics';\nimport { getFirebaseApp } from './config';\n\nlet _analytics: Analytics | null = null;\n\n/**\n * Get the Firebase Analytics instance\n * Only works in browser environment\n */\nexport async function getFirebaseAnalytics(): Promise<Analytics | null> {\n if (typeof window === 'undefined') {\n return null;\n }\n\n if (_analytics) {\n return _analytics;\n }\n\n const supported = await isSupported();\n if (!supported) {\n console.warn('[mw-core] Firebase Analytics is not supported in this environment');\n return null;\n }\n\n _analytics = getAnalytics(getFirebaseApp());\n return _analytics;\n}\n\n/**\n * Log a custom event to Firebase Analytics\n */\nexport async function trackEvent(\n eventName: string,\n eventParams?: Record<string, unknown>\n): Promise<void> {\n const analytics = await getFirebaseAnalytics();\n if (analytics) {\n logEvent(analytics, eventName, eventParams);\n }\n}\n\n/**\n * Track a page view\n */\nexport async function trackPageView(\n pagePath: string,\n pageTitle?: string\n): Promise<void> {\n await trackEvent('page_view', {\n page_path: pagePath,\n page_title: pageTitle,\n });\n}\n\n/**\n * Track a user action\n */\nexport async function trackUserAction(\n action: string,\n category: string,\n label?: string,\n value?: number\n): Promise<void> {\n await trackEvent(action, {\n event_category: category,\n event_label: label,\n value,\n });\n}\n\n/**\n * Track sign up event\n */\nexport async function trackSignUp(method: string): Promise<void> {\n await trackEvent('sign_up', { method });\n}\n\n/**\n * Track login event\n */\nexport async function trackLogin(method: string): Promise<void> {\n await trackEvent('login', { method });\n}\n\n// Re-export types\nexport type { Analytics };\n\n"]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { User, UserCredential } from 'firebase/auth';
|
|
2
|
+
import { QueryConstraint } from 'firebase/firestore';
|
|
3
|
+
import { UploadMetadata } from 'firebase/storage';
|
|
4
|
+
export { g as generateFilePath } from '../storage-BU_rfYCi.mjs';
|
|
5
|
+
|
|
6
|
+
interface UseAuthReturn {
|
|
7
|
+
/** The current authenticated user, or null if not authenticated */
|
|
8
|
+
user: User | null;
|
|
9
|
+
/** Whether the auth state is still loading */
|
|
10
|
+
loading: boolean;
|
|
11
|
+
/** Any auth error that occurred */
|
|
12
|
+
error: Error | null;
|
|
13
|
+
/** Sign in with email and password */
|
|
14
|
+
signIn: (email: string, password: string) => Promise<UserCredential>;
|
|
15
|
+
/** Create a new account with email and password */
|
|
16
|
+
signUp: (email: string, password: string, displayName?: string) => Promise<UserCredential>;
|
|
17
|
+
/** Sign out the current user */
|
|
18
|
+
signOut: () => Promise<void>;
|
|
19
|
+
/** Sign in with Google */
|
|
20
|
+
signInWithGoogle: () => Promise<UserCredential>;
|
|
21
|
+
/** Send a password reset email */
|
|
22
|
+
resetPassword: (email: string) => Promise<void>;
|
|
23
|
+
/** Update the user's profile */
|
|
24
|
+
updateProfile: (profile: {
|
|
25
|
+
displayName?: string;
|
|
26
|
+
photoURL?: string;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
/** Send email verification */
|
|
29
|
+
sendEmailVerification: () => Promise<void>;
|
|
30
|
+
/** Clear any auth errors */
|
|
31
|
+
clearError: () => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* React hook for Firebase Authentication
|
|
35
|
+
* Provides auth state and authentication methods
|
|
36
|
+
*/
|
|
37
|
+
declare function useAuth(): UseAuthReturn;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Hook for fetching and subscribing to a single Firestore document
|
|
41
|
+
*/
|
|
42
|
+
declare function useDocument<T>(collectionPath: string, documentId: string | null | undefined, options?: {
|
|
43
|
+
subscribe?: boolean;
|
|
44
|
+
}): {
|
|
45
|
+
data: T | null;
|
|
46
|
+
loading: boolean;
|
|
47
|
+
error: Error | null;
|
|
48
|
+
refresh: () => Promise<void>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Hook for fetching and subscribing to a Firestore collection
|
|
52
|
+
*/
|
|
53
|
+
declare function useCollection<T>(collectionPath: string, constraints?: QueryConstraint[], options?: {
|
|
54
|
+
subscribe?: boolean;
|
|
55
|
+
}): {
|
|
56
|
+
data: T[];
|
|
57
|
+
loading: boolean;
|
|
58
|
+
error: Error | null;
|
|
59
|
+
refresh: () => Promise<void>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Hook providing Firestore mutation operations
|
|
63
|
+
*/
|
|
64
|
+
declare function useFirestoreMutation<T>(collectionPath: string): {
|
|
65
|
+
add: (data: Omit<T, "id">) => Promise<string>;
|
|
66
|
+
set: (documentId: string, data: Omit<T, "id">, merge?: boolean) => Promise<void>;
|
|
67
|
+
update: (documentId: string, data: Partial<T>) => Promise<void>;
|
|
68
|
+
remove: (documentId: string) => Promise<void>;
|
|
69
|
+
loading: boolean;
|
|
70
|
+
error: Error | null;
|
|
71
|
+
clearError: () => void;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
interface UseStorageReturn {
|
|
75
|
+
/** Upload a file */
|
|
76
|
+
upload: (path: string, file: Blob | File, metadata?: UploadMetadata) => Promise<string>;
|
|
77
|
+
/** Upload a file with progress tracking */
|
|
78
|
+
uploadWithProgress: (path: string, file: Blob | File, metadata?: UploadMetadata) => Promise<string>;
|
|
79
|
+
/** Delete a file */
|
|
80
|
+
remove: (path: string) => Promise<void>;
|
|
81
|
+
/** Get the download URL for a file */
|
|
82
|
+
getURL: (path: string) => Promise<string>;
|
|
83
|
+
/** Whether an upload is in progress */
|
|
84
|
+
uploading: boolean;
|
|
85
|
+
/** Upload progress (0-100) */
|
|
86
|
+
progress: number;
|
|
87
|
+
/** Any storage error */
|
|
88
|
+
error: Error | null;
|
|
89
|
+
/** Clear any errors */
|
|
90
|
+
clearError: () => void;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* React hook for Firebase Storage operations
|
|
94
|
+
*/
|
|
95
|
+
declare function useStorage(): UseStorageReturn;
|
|
96
|
+
|
|
97
|
+
export { type UseAuthReturn, type UseStorageReturn, useAuth, useCollection, useDocument, useFirestoreMutation, useStorage };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { User, UserCredential } from 'firebase/auth';
|
|
2
|
+
import { QueryConstraint } from 'firebase/firestore';
|
|
3
|
+
import { UploadMetadata } from 'firebase/storage';
|
|
4
|
+
export { g as generateFilePath } from '../storage-BU_rfYCi.js';
|
|
5
|
+
|
|
6
|
+
interface UseAuthReturn {
|
|
7
|
+
/** The current authenticated user, or null if not authenticated */
|
|
8
|
+
user: User | null;
|
|
9
|
+
/** Whether the auth state is still loading */
|
|
10
|
+
loading: boolean;
|
|
11
|
+
/** Any auth error that occurred */
|
|
12
|
+
error: Error | null;
|
|
13
|
+
/** Sign in with email and password */
|
|
14
|
+
signIn: (email: string, password: string) => Promise<UserCredential>;
|
|
15
|
+
/** Create a new account with email and password */
|
|
16
|
+
signUp: (email: string, password: string, displayName?: string) => Promise<UserCredential>;
|
|
17
|
+
/** Sign out the current user */
|
|
18
|
+
signOut: () => Promise<void>;
|
|
19
|
+
/** Sign in with Google */
|
|
20
|
+
signInWithGoogle: () => Promise<UserCredential>;
|
|
21
|
+
/** Send a password reset email */
|
|
22
|
+
resetPassword: (email: string) => Promise<void>;
|
|
23
|
+
/** Update the user's profile */
|
|
24
|
+
updateProfile: (profile: {
|
|
25
|
+
displayName?: string;
|
|
26
|
+
photoURL?: string;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
/** Send email verification */
|
|
29
|
+
sendEmailVerification: () => Promise<void>;
|
|
30
|
+
/** Clear any auth errors */
|
|
31
|
+
clearError: () => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* React hook for Firebase Authentication
|
|
35
|
+
* Provides auth state and authentication methods
|
|
36
|
+
*/
|
|
37
|
+
declare function useAuth(): UseAuthReturn;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Hook for fetching and subscribing to a single Firestore document
|
|
41
|
+
*/
|
|
42
|
+
declare function useDocument<T>(collectionPath: string, documentId: string | null | undefined, options?: {
|
|
43
|
+
subscribe?: boolean;
|
|
44
|
+
}): {
|
|
45
|
+
data: T | null;
|
|
46
|
+
loading: boolean;
|
|
47
|
+
error: Error | null;
|
|
48
|
+
refresh: () => Promise<void>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Hook for fetching and subscribing to a Firestore collection
|
|
52
|
+
*/
|
|
53
|
+
declare function useCollection<T>(collectionPath: string, constraints?: QueryConstraint[], options?: {
|
|
54
|
+
subscribe?: boolean;
|
|
55
|
+
}): {
|
|
56
|
+
data: T[];
|
|
57
|
+
loading: boolean;
|
|
58
|
+
error: Error | null;
|
|
59
|
+
refresh: () => Promise<void>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Hook providing Firestore mutation operations
|
|
63
|
+
*/
|
|
64
|
+
declare function useFirestoreMutation<T>(collectionPath: string): {
|
|
65
|
+
add: (data: Omit<T, "id">) => Promise<string>;
|
|
66
|
+
set: (documentId: string, data: Omit<T, "id">, merge?: boolean) => Promise<void>;
|
|
67
|
+
update: (documentId: string, data: Partial<T>) => Promise<void>;
|
|
68
|
+
remove: (documentId: string) => Promise<void>;
|
|
69
|
+
loading: boolean;
|
|
70
|
+
error: Error | null;
|
|
71
|
+
clearError: () => void;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
interface UseStorageReturn {
|
|
75
|
+
/** Upload a file */
|
|
76
|
+
upload: (path: string, file: Blob | File, metadata?: UploadMetadata) => Promise<string>;
|
|
77
|
+
/** Upload a file with progress tracking */
|
|
78
|
+
uploadWithProgress: (path: string, file: Blob | File, metadata?: UploadMetadata) => Promise<string>;
|
|
79
|
+
/** Delete a file */
|
|
80
|
+
remove: (path: string) => Promise<void>;
|
|
81
|
+
/** Get the download URL for a file */
|
|
82
|
+
getURL: (path: string) => Promise<string>;
|
|
83
|
+
/** Whether an upload is in progress */
|
|
84
|
+
uploading: boolean;
|
|
85
|
+
/** Upload progress (0-100) */
|
|
86
|
+
progress: number;
|
|
87
|
+
/** Any storage error */
|
|
88
|
+
error: Error | null;
|
|
89
|
+
/** Clear any errors */
|
|
90
|
+
clearError: () => void;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* React hook for Firebase Storage operations
|
|
94
|
+
*/
|
|
95
|
+
declare function useStorage(): UseStorageReturn;
|
|
96
|
+
|
|
97
|
+
export { type UseAuthReturn, type UseStorageReturn, useAuth, useCollection, useDocument, useFirestoreMutation, useStorage };
|