@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,393 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var app$1 = require('firebase/app');
|
|
4
|
+
var auth$1 = require('firebase/auth');
|
|
5
|
+
var firestore = require('firebase/firestore');
|
|
6
|
+
var storage$1 = require('firebase/storage');
|
|
7
|
+
var analytics = require('firebase/analytics');
|
|
8
|
+
|
|
9
|
+
// src/firebase/config.ts
|
|
10
|
+
function getFirebaseConfig() {
|
|
11
|
+
const config = {
|
|
12
|
+
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY || "",
|
|
13
|
+
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN || "",
|
|
14
|
+
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID || "",
|
|
15
|
+
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET || "",
|
|
16
|
+
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID || "",
|
|
17
|
+
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID || "",
|
|
18
|
+
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
|
|
19
|
+
};
|
|
20
|
+
const requiredFields = [
|
|
21
|
+
"apiKey",
|
|
22
|
+
"authDomain",
|
|
23
|
+
"projectId",
|
|
24
|
+
"storageBucket",
|
|
25
|
+
"messagingSenderId",
|
|
26
|
+
"appId"
|
|
27
|
+
];
|
|
28
|
+
const missingFields = requiredFields.filter((field) => !config[field]);
|
|
29
|
+
if (missingFields.length > 0) {
|
|
30
|
+
console.warn(
|
|
31
|
+
`[mw-core] Missing Firebase config fields: ${missingFields.join(", ")}. Make sure to set NEXT_PUBLIC_FIREBASE_* environment variables.`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return config;
|
|
35
|
+
}
|
|
36
|
+
function initializeFirebase(config) {
|
|
37
|
+
if (app$1.getApps().length > 0) {
|
|
38
|
+
return app$1.getApp();
|
|
39
|
+
}
|
|
40
|
+
const firebaseConfig = config || getFirebaseConfig();
|
|
41
|
+
return app$1.initializeApp(firebaseConfig);
|
|
42
|
+
}
|
|
43
|
+
var _app = null;
|
|
44
|
+
var _auth = null;
|
|
45
|
+
var _db = null;
|
|
46
|
+
var _storage = null;
|
|
47
|
+
function getFirebaseApp() {
|
|
48
|
+
if (!_app) {
|
|
49
|
+
_app = initializeFirebase();
|
|
50
|
+
}
|
|
51
|
+
return _app;
|
|
52
|
+
}
|
|
53
|
+
function getFirebaseAuth() {
|
|
54
|
+
if (!_auth) {
|
|
55
|
+
_auth = auth$1.getAuth(getFirebaseApp());
|
|
56
|
+
}
|
|
57
|
+
return _auth;
|
|
58
|
+
}
|
|
59
|
+
function getFirebaseFirestore() {
|
|
60
|
+
if (!_db) {
|
|
61
|
+
_db = firestore.getFirestore(getFirebaseApp());
|
|
62
|
+
}
|
|
63
|
+
return _db;
|
|
64
|
+
}
|
|
65
|
+
function getFirebaseStorage() {
|
|
66
|
+
if (!_storage) {
|
|
67
|
+
_storage = storage$1.getStorage(getFirebaseApp());
|
|
68
|
+
}
|
|
69
|
+
return _storage;
|
|
70
|
+
}
|
|
71
|
+
var app = typeof window !== "undefined" ? getFirebaseApp() : null;
|
|
72
|
+
var auth = typeof window !== "undefined" ? getFirebaseAuth() : null;
|
|
73
|
+
var db = typeof window !== "undefined" ? getFirebaseFirestore() : null;
|
|
74
|
+
var storage = typeof window !== "undefined" ? getFirebaseStorage() : null;
|
|
75
|
+
async function signInWithEmail(email, password) {
|
|
76
|
+
const auth2 = getFirebaseAuth();
|
|
77
|
+
return auth$1.signInWithEmailAndPassword(auth2, email, password);
|
|
78
|
+
}
|
|
79
|
+
async function signUpWithEmail(email, password, displayName) {
|
|
80
|
+
const auth2 = getFirebaseAuth();
|
|
81
|
+
const credential = await auth$1.createUserWithEmailAndPassword(auth2, email, password);
|
|
82
|
+
if (displayName && credential.user) {
|
|
83
|
+
await auth$1.updateProfile(credential.user, { displayName });
|
|
84
|
+
}
|
|
85
|
+
return credential;
|
|
86
|
+
}
|
|
87
|
+
async function signOut() {
|
|
88
|
+
const auth2 = getFirebaseAuth();
|
|
89
|
+
return auth$1.signOut(auth2);
|
|
90
|
+
}
|
|
91
|
+
async function resetPassword(email) {
|
|
92
|
+
const auth2 = getFirebaseAuth();
|
|
93
|
+
return auth$1.sendPasswordResetEmail(auth2, email);
|
|
94
|
+
}
|
|
95
|
+
async function sendVerificationEmail(user) {
|
|
96
|
+
return auth$1.sendEmailVerification(user);
|
|
97
|
+
}
|
|
98
|
+
async function updateUserProfile(user, profile) {
|
|
99
|
+
return auth$1.updateProfile(user, profile);
|
|
100
|
+
}
|
|
101
|
+
async function signInWithGoogle() {
|
|
102
|
+
const auth2 = getFirebaseAuth();
|
|
103
|
+
const provider = new auth$1.GoogleAuthProvider();
|
|
104
|
+
provider.addScope("email");
|
|
105
|
+
provider.addScope("profile");
|
|
106
|
+
return auth$1.signInWithPopup(auth2, provider);
|
|
107
|
+
}
|
|
108
|
+
async function signInWithGoogleRedirect() {
|
|
109
|
+
const auth2 = getFirebaseAuth();
|
|
110
|
+
const provider = new auth$1.GoogleAuthProvider();
|
|
111
|
+
provider.addScope("email");
|
|
112
|
+
provider.addScope("profile");
|
|
113
|
+
return auth$1.signInWithRedirect(auth2, provider);
|
|
114
|
+
}
|
|
115
|
+
async function getGoogleRedirectResult() {
|
|
116
|
+
const auth2 = getFirebaseAuth();
|
|
117
|
+
return auth$1.getRedirectResult(auth2);
|
|
118
|
+
}
|
|
119
|
+
function subscribeToAuthState(callback) {
|
|
120
|
+
const auth2 = getFirebaseAuth();
|
|
121
|
+
return auth$1.onAuthStateChanged(auth2, callback);
|
|
122
|
+
}
|
|
123
|
+
function getCurrentUser() {
|
|
124
|
+
const auth2 = getFirebaseAuth();
|
|
125
|
+
return auth2.currentUser;
|
|
126
|
+
}
|
|
127
|
+
function waitForAuthState() {
|
|
128
|
+
return new Promise((resolve) => {
|
|
129
|
+
const auth2 = getFirebaseAuth();
|
|
130
|
+
const unsubscribe = auth$1.onAuthStateChanged(auth2, (user) => {
|
|
131
|
+
unsubscribe();
|
|
132
|
+
resolve(user);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function getDocRef(collectionPath, documentId) {
|
|
137
|
+
const db2 = getFirebaseFirestore();
|
|
138
|
+
return firestore.doc(db2, collectionPath, documentId);
|
|
139
|
+
}
|
|
140
|
+
function getCollectionRef(collectionPath) {
|
|
141
|
+
const db2 = getFirebaseFirestore();
|
|
142
|
+
return firestore.collection(db2, collectionPath);
|
|
143
|
+
}
|
|
144
|
+
async function getDocument(collectionPath, documentId) {
|
|
145
|
+
const docRef = getDocRef(collectionPath, documentId);
|
|
146
|
+
const docSnap = await firestore.getDoc(docRef);
|
|
147
|
+
if (docSnap.exists()) {
|
|
148
|
+
return { id: docSnap.id, ...docSnap.data() };
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
async function getCollection(collectionPath, constraints = []) {
|
|
153
|
+
const collectionRef = getCollectionRef(collectionPath);
|
|
154
|
+
const q = firestore.query(collectionRef, ...constraints);
|
|
155
|
+
const querySnapshot = await firestore.getDocs(q);
|
|
156
|
+
return querySnapshot.docs.map((doc2) => ({
|
|
157
|
+
id: doc2.id,
|
|
158
|
+
...doc2.data()
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
async function addDocument(collectionPath, data) {
|
|
162
|
+
const collectionRef = getCollectionRef(collectionPath);
|
|
163
|
+
const docRef = await firestore.addDoc(collectionRef, {
|
|
164
|
+
...data,
|
|
165
|
+
createdAt: firestore.serverTimestamp(),
|
|
166
|
+
updatedAt: firestore.serverTimestamp()
|
|
167
|
+
});
|
|
168
|
+
return docRef.id;
|
|
169
|
+
}
|
|
170
|
+
async function setDocument(collectionPath, documentId, data, merge = false) {
|
|
171
|
+
const docRef = getDocRef(collectionPath, documentId);
|
|
172
|
+
await firestore.setDoc(
|
|
173
|
+
docRef,
|
|
174
|
+
{
|
|
175
|
+
...data,
|
|
176
|
+
updatedAt: firestore.serverTimestamp(),
|
|
177
|
+
...merge ? {} : { createdAt: firestore.serverTimestamp() }
|
|
178
|
+
},
|
|
179
|
+
{ merge }
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
async function updateDocument(collectionPath, documentId, data) {
|
|
183
|
+
const docRef = getDocRef(collectionPath, documentId);
|
|
184
|
+
await firestore.updateDoc(docRef, {
|
|
185
|
+
...data,
|
|
186
|
+
updatedAt: firestore.serverTimestamp()
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
async function deleteDocument(collectionPath, documentId) {
|
|
190
|
+
const docRef = getDocRef(collectionPath, documentId);
|
|
191
|
+
await firestore.deleteDoc(docRef);
|
|
192
|
+
}
|
|
193
|
+
function subscribeToDocument(collectionPath, documentId, callback) {
|
|
194
|
+
const docRef = getDocRef(collectionPath, documentId);
|
|
195
|
+
return firestore.onSnapshot(docRef, (docSnap) => {
|
|
196
|
+
if (docSnap.exists()) {
|
|
197
|
+
callback({ id: docSnap.id, ...docSnap.data() });
|
|
198
|
+
} else {
|
|
199
|
+
callback(null);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function subscribeToCollection(collectionPath, callback, constraints = []) {
|
|
204
|
+
const collectionRef = getCollectionRef(collectionPath);
|
|
205
|
+
const q = firestore.query(collectionRef, ...constraints);
|
|
206
|
+
return firestore.onSnapshot(q, (querySnapshot) => {
|
|
207
|
+
const data = querySnapshot.docs.map((doc2) => ({
|
|
208
|
+
id: doc2.id,
|
|
209
|
+
...doc2.data()
|
|
210
|
+
}));
|
|
211
|
+
callback(data);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function getStorageRef(path) {
|
|
215
|
+
const storage2 = getFirebaseStorage();
|
|
216
|
+
return storage$1.ref(storage2, path);
|
|
217
|
+
}
|
|
218
|
+
async function uploadFile(path, file, metadata) {
|
|
219
|
+
const storageRef = getStorageRef(path);
|
|
220
|
+
await storage$1.uploadBytes(storageRef, file, metadata);
|
|
221
|
+
return storage$1.getDownloadURL(storageRef);
|
|
222
|
+
}
|
|
223
|
+
function uploadFileWithProgress(path, file, onProgress, metadata) {
|
|
224
|
+
const storageRef = getStorageRef(path);
|
|
225
|
+
const task = storage$1.uploadBytesResumable(storageRef, file, metadata);
|
|
226
|
+
if (onProgress) {
|
|
227
|
+
task.on("state_changed", (snapshot) => {
|
|
228
|
+
const progress = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
|
229
|
+
onProgress(progress);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
const promise = new Promise((resolve, reject) => {
|
|
233
|
+
task.on(
|
|
234
|
+
"state_changed",
|
|
235
|
+
null,
|
|
236
|
+
(error) => reject(error),
|
|
237
|
+
async () => {
|
|
238
|
+
const url = await storage$1.getDownloadURL(task.snapshot.ref);
|
|
239
|
+
resolve(url);
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
return { task, promise };
|
|
244
|
+
}
|
|
245
|
+
async function getFileURL(path) {
|
|
246
|
+
const storageRef = getStorageRef(path);
|
|
247
|
+
return storage$1.getDownloadURL(storageRef);
|
|
248
|
+
}
|
|
249
|
+
async function deleteFile(path) {
|
|
250
|
+
const storageRef = getStorageRef(path);
|
|
251
|
+
return storage$1.deleteObject(storageRef);
|
|
252
|
+
}
|
|
253
|
+
async function listFiles(path) {
|
|
254
|
+
const storageRef = getStorageRef(path);
|
|
255
|
+
return storage$1.listAll(storageRef);
|
|
256
|
+
}
|
|
257
|
+
async function getFileMetadata(path) {
|
|
258
|
+
const storageRef = getStorageRef(path);
|
|
259
|
+
return storage$1.getMetadata(storageRef);
|
|
260
|
+
}
|
|
261
|
+
async function updateFileMetadata(path, metadata) {
|
|
262
|
+
const storageRef = getStorageRef(path);
|
|
263
|
+
return storage$1.updateMetadata(storageRef, metadata);
|
|
264
|
+
}
|
|
265
|
+
function generateFilePath(folder, filename, userId) {
|
|
266
|
+
const timestamp = Date.now();
|
|
267
|
+
const extension = filename.split(".").pop() || "";
|
|
268
|
+
const baseName = filename.replace(/\.[^/.]+$/, "");
|
|
269
|
+
const sanitizedName = baseName.replace(/[^a-zA-Z0-9]/g, "_");
|
|
270
|
+
if (userId) {
|
|
271
|
+
return `${folder}/${userId}/${timestamp}_${sanitizedName}.${extension}`;
|
|
272
|
+
}
|
|
273
|
+
return `${folder}/${timestamp}_${sanitizedName}.${extension}`;
|
|
274
|
+
}
|
|
275
|
+
var _analytics = null;
|
|
276
|
+
async function getFirebaseAnalytics() {
|
|
277
|
+
if (typeof window === "undefined") {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
if (_analytics) {
|
|
281
|
+
return _analytics;
|
|
282
|
+
}
|
|
283
|
+
const supported = await analytics.isSupported();
|
|
284
|
+
if (!supported) {
|
|
285
|
+
console.warn("[mw-core] Firebase Analytics is not supported in this environment");
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
_analytics = analytics.getAnalytics(getFirebaseApp());
|
|
289
|
+
return _analytics;
|
|
290
|
+
}
|
|
291
|
+
async function trackEvent(eventName, eventParams) {
|
|
292
|
+
const analytics$1 = await getFirebaseAnalytics();
|
|
293
|
+
if (analytics$1) {
|
|
294
|
+
analytics.logEvent(analytics$1, eventName, eventParams);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
async function trackPageView(pagePath, pageTitle) {
|
|
298
|
+
await trackEvent("page_view", {
|
|
299
|
+
page_path: pagePath,
|
|
300
|
+
page_title: pageTitle
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
async function trackUserAction(action, category, label, value) {
|
|
304
|
+
await trackEvent(action, {
|
|
305
|
+
event_category: category,
|
|
306
|
+
event_label: label,
|
|
307
|
+
value
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
async function trackSignUp(method) {
|
|
311
|
+
await trackEvent("sign_up", { method });
|
|
312
|
+
}
|
|
313
|
+
async function trackLogin(method) {
|
|
314
|
+
await trackEvent("login", { method });
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
Object.defineProperty(exports, "Timestamp", {
|
|
318
|
+
enumerable: true,
|
|
319
|
+
get: function () { return firestore.Timestamp; }
|
|
320
|
+
});
|
|
321
|
+
Object.defineProperty(exports, "limit", {
|
|
322
|
+
enumerable: true,
|
|
323
|
+
get: function () { return firestore.limit; }
|
|
324
|
+
});
|
|
325
|
+
Object.defineProperty(exports, "orderBy", {
|
|
326
|
+
enumerable: true,
|
|
327
|
+
get: function () { return firestore.orderBy; }
|
|
328
|
+
});
|
|
329
|
+
Object.defineProperty(exports, "query", {
|
|
330
|
+
enumerable: true,
|
|
331
|
+
get: function () { return firestore.query; }
|
|
332
|
+
});
|
|
333
|
+
Object.defineProperty(exports, "serverTimestamp", {
|
|
334
|
+
enumerable: true,
|
|
335
|
+
get: function () { return firestore.serverTimestamp; }
|
|
336
|
+
});
|
|
337
|
+
Object.defineProperty(exports, "startAfter", {
|
|
338
|
+
enumerable: true,
|
|
339
|
+
get: function () { return firestore.startAfter; }
|
|
340
|
+
});
|
|
341
|
+
Object.defineProperty(exports, "where", {
|
|
342
|
+
enumerable: true,
|
|
343
|
+
get: function () { return firestore.where; }
|
|
344
|
+
});
|
|
345
|
+
exports.addDocument = addDocument;
|
|
346
|
+
exports.app = app;
|
|
347
|
+
exports.auth = auth;
|
|
348
|
+
exports.db = db;
|
|
349
|
+
exports.deleteDocument = deleteDocument;
|
|
350
|
+
exports.deleteFile = deleteFile;
|
|
351
|
+
exports.generateFilePath = generateFilePath;
|
|
352
|
+
exports.getCollection = getCollection;
|
|
353
|
+
exports.getCollectionRef = getCollectionRef;
|
|
354
|
+
exports.getCurrentUser = getCurrentUser;
|
|
355
|
+
exports.getDocRef = getDocRef;
|
|
356
|
+
exports.getDocument = getDocument;
|
|
357
|
+
exports.getFileMetadata = getFileMetadata;
|
|
358
|
+
exports.getFileURL = getFileURL;
|
|
359
|
+
exports.getFirebaseAnalytics = getFirebaseAnalytics;
|
|
360
|
+
exports.getFirebaseApp = getFirebaseApp;
|
|
361
|
+
exports.getFirebaseAuth = getFirebaseAuth;
|
|
362
|
+
exports.getFirebaseConfig = getFirebaseConfig;
|
|
363
|
+
exports.getFirebaseFirestore = getFirebaseFirestore;
|
|
364
|
+
exports.getFirebaseStorage = getFirebaseStorage;
|
|
365
|
+
exports.getGoogleRedirectResult = getGoogleRedirectResult;
|
|
366
|
+
exports.getStorageRef = getStorageRef;
|
|
367
|
+
exports.initializeFirebase = initializeFirebase;
|
|
368
|
+
exports.listFiles = listFiles;
|
|
369
|
+
exports.resetPassword = resetPassword;
|
|
370
|
+
exports.sendVerificationEmail = sendVerificationEmail;
|
|
371
|
+
exports.setDocument = setDocument;
|
|
372
|
+
exports.signInWithEmail = signInWithEmail;
|
|
373
|
+
exports.signInWithGoogle = signInWithGoogle;
|
|
374
|
+
exports.signInWithGoogleRedirect = signInWithGoogleRedirect;
|
|
375
|
+
exports.signOut = signOut;
|
|
376
|
+
exports.signUpWithEmail = signUpWithEmail;
|
|
377
|
+
exports.storage = storage;
|
|
378
|
+
exports.subscribeToAuthState = subscribeToAuthState;
|
|
379
|
+
exports.subscribeToCollection = subscribeToCollection;
|
|
380
|
+
exports.subscribeToDocument = subscribeToDocument;
|
|
381
|
+
exports.trackEvent = trackEvent;
|
|
382
|
+
exports.trackLogin = trackLogin;
|
|
383
|
+
exports.trackPageView = trackPageView;
|
|
384
|
+
exports.trackSignUp = trackSignUp;
|
|
385
|
+
exports.trackUserAction = trackUserAction;
|
|
386
|
+
exports.updateDocument = updateDocument;
|
|
387
|
+
exports.updateFileMetadata = updateFileMetadata;
|
|
388
|
+
exports.updateUserProfile = updateUserProfile;
|
|
389
|
+
exports.uploadFile = uploadFile;
|
|
390
|
+
exports.uploadFileWithProgress = uploadFileWithProgress;
|
|
391
|
+
exports.waitForAuthState = waitForAuthState;
|
|
392
|
+
//# sourceMappingURL=index.js.map
|
|
393
|
+
//# sourceMappingURL=index.js.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":["getApps","getApp","initializeApp","getAuth","getFirestore","getStorage","auth","signInWithEmailAndPassword","createUserWithEmailAndPassword","updateProfile","firebaseSignOut","sendPasswordResetEmail","sendEmailVerification","GoogleAuthProvider","signInWithPopup","signInWithRedirect","getRedirectResult","onAuthStateChanged","db","doc","collection","getDoc","query","getDocs","addDoc","serverTimestamp","setDoc","updateDoc","deleteDoc","onSnapshot","storage","ref","uploadBytes","getDownloadURL","uploadBytesResumable","deleteObject","listAll","getMetadata","updateMetadata","isSupported","getAnalytics","analytics","logEvent"],"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,QAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,eAAA;AAAA,IACA,mBAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,MAAM,aAAA,GAAgB,eAAe,MAAA,CAAO,CAAC,UAAU,CAAC,MAAA,CAAO,KAAK,CAAC,CAAA;AAErE,EAAA,IAAI,aAAA,CAAc,SAAS,CAAA,EAAG;AAC5B,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN,CAAA,0CAAA,EAA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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.js","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"]}
|