svelte-firekit 0.0.25 → 0.1.1

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.
Files changed (95) hide show
  1. package/README.md +445 -213
  2. package/dist/components/Collection.svelte +150 -0
  3. package/dist/components/Collection.svelte.d.ts +27 -0
  4. package/dist/components/Ddoc.svelte +131 -0
  5. package/dist/components/Ddoc.svelte.d.ts +28 -0
  6. package/dist/components/Node.svelte +97 -0
  7. package/dist/components/Node.svelte.d.ts +23 -0
  8. package/dist/components/auth-guard.svelte +89 -0
  9. package/dist/components/auth-guard.svelte.d.ts +26 -0
  10. package/dist/components/custom-guard.svelte +122 -0
  11. package/dist/components/custom-guard.svelte.d.ts +31 -0
  12. package/dist/components/download-url.svelte +92 -0
  13. package/dist/components/download-url.svelte.d.ts +19 -0
  14. package/dist/components/firebase-app.svelte +30 -0
  15. package/dist/components/firebase-app.svelte.d.ts +7 -0
  16. package/dist/components/node-list.svelte +102 -0
  17. package/dist/components/node-list.svelte.d.ts +27 -0
  18. package/dist/components/signed-in.svelte +42 -0
  19. package/dist/components/signed-in.svelte.d.ts +11 -0
  20. package/dist/components/signed-out.svelte +42 -0
  21. package/dist/components/signed-out.svelte.d.ts +11 -0
  22. package/dist/components/storage-list.svelte +97 -0
  23. package/dist/components/storage-list.svelte.d.ts +26 -0
  24. package/dist/components/upload-task.svelte +108 -0
  25. package/dist/components/upload-task.svelte.d.ts +24 -0
  26. package/dist/config.js +17 -39
  27. package/dist/firebase.d.ts +43 -21
  28. package/dist/firebase.js +121 -35
  29. package/dist/index.d.ts +21 -13
  30. package/dist/index.js +27 -15
  31. package/dist/services/auth.d.ts +397 -0
  32. package/dist/services/auth.js +882 -0
  33. package/dist/services/collection.svelte.d.ts +286 -0
  34. package/dist/services/collection.svelte.js +871 -0
  35. package/dist/services/document.svelte.d.ts +288 -0
  36. package/dist/services/document.svelte.js +555 -0
  37. package/dist/services/mutations.d.ts +336 -0
  38. package/dist/services/mutations.js +1079 -0
  39. package/dist/services/presence.svelte.d.ts +141 -0
  40. package/dist/services/presence.svelte.js +727 -0
  41. package/dist/{realtime → services}/realtime.svelte.d.ts +3 -1
  42. package/dist/{realtime → services}/realtime.svelte.js +13 -7
  43. package/dist/services/storage.svelte.d.ts +257 -0
  44. package/dist/services/storage.svelte.js +374 -0
  45. package/dist/services/user.svelte.d.ts +296 -0
  46. package/dist/services/user.svelte.js +609 -0
  47. package/dist/types/auth.d.ts +158 -0
  48. package/dist/types/auth.js +106 -0
  49. package/dist/types/collection.d.ts +360 -0
  50. package/dist/types/collection.js +167 -0
  51. package/dist/types/document.d.ts +342 -0
  52. package/dist/types/document.js +148 -0
  53. package/dist/types/firebase.d.ts +44 -0
  54. package/dist/types/firebase.js +33 -0
  55. package/dist/types/index.d.ts +6 -0
  56. package/dist/types/index.js +4 -0
  57. package/dist/types/mutations.d.ts +387 -0
  58. package/dist/types/mutations.js +205 -0
  59. package/dist/types/presence.d.ts +282 -0
  60. package/dist/types/presence.js +80 -0
  61. package/dist/utils/errors.d.ts +21 -0
  62. package/dist/utils/errors.js +35 -0
  63. package/dist/utils/firestore.d.ts +9 -0
  64. package/dist/utils/firestore.js +33 -0
  65. package/dist/utils/index.d.ts +4 -0
  66. package/dist/utils/index.js +8 -0
  67. package/dist/utils/providers.d.ts +16 -0
  68. package/dist/utils/providers.js +30 -0
  69. package/dist/utils/user.d.ts +8 -0
  70. package/dist/utils/user.js +29 -0
  71. package/package.json +64 -64
  72. package/dist/auth/auth.d.ts +0 -117
  73. package/dist/auth/auth.js +0 -194
  74. package/dist/auth/presence.svelte.d.ts +0 -139
  75. package/dist/auth/presence.svelte.js +0 -373
  76. package/dist/auth/user.svelte.d.ts +0 -112
  77. package/dist/auth/user.svelte.js +0 -155
  78. package/dist/firestore/awaitable-doc.svelte.d.ts +0 -141
  79. package/dist/firestore/awaitable-doc.svelte.js +0 -183
  80. package/dist/firestore/batch-mutations.svelte.d.ts +0 -140
  81. package/dist/firestore/batch-mutations.svelte.js +0 -218
  82. package/dist/firestore/collection-group.svelte.d.ts +0 -78
  83. package/dist/firestore/collection-group.svelte.js +0 -120
  84. package/dist/firestore/collection.svelte.d.ts +0 -96
  85. package/dist/firestore/collection.svelte.js +0 -137
  86. package/dist/firestore/doc.svelte.d.ts +0 -90
  87. package/dist/firestore/doc.svelte.js +0 -131
  88. package/dist/firestore/document-mutations.svelte.d.ts +0 -164
  89. package/dist/firestore/document-mutations.svelte.js +0 -273
  90. package/dist/storage/download-url.svelte.d.ts +0 -83
  91. package/dist/storage/download-url.svelte.js +0 -114
  92. package/dist/storage/storage-list.svelte.d.ts +0 -89
  93. package/dist/storage/storage-list.svelte.js +0 -123
  94. package/dist/storage/upload-task.svelte.d.ts +0 -94
  95. package/dist/storage/upload-task.svelte.js +0 -138
@@ -0,0 +1,397 @@
1
+ /**
2
+ * @fileoverview FirekitAuth - Complete Firebase Authentication Service for Svelte
3
+ * @module FirekitAuth
4
+ * @version 1.0.0
5
+ */
6
+ import { type User } from 'firebase/auth';
7
+ import { type UserProfile, type AuthState, type PasswordUpdateResult, type AccountDeletionResult, type PhoneVerificationResult } from '../types/auth.js';
8
+ /**
9
+ * Comprehensive Firebase Authentication service for Svelte applications.
10
+ * Provides a complete authentication solution with automatic Firestore integration,
11
+ * error handling, and support for all major authentication methods.
12
+ *
13
+ * @class FirekitAuth
14
+ * @example
15
+ * ```typescript
16
+ * import { firekitAuth } from 'svelte-firekit';
17
+ *
18
+ * // Sign in with Google
19
+ * await firekitAuth.signInWithGoogle();
20
+ *
21
+ * // Register new user
22
+ * await firekitAuth.registerWithEmail("user@example.com", "password123", "John Doe");
23
+ *
24
+ * // Listen to auth state changes
25
+ * const unsubscribe = firekitAuth.onAuthStateChanged((user) => {
26
+ * console.log('User:', user);
27
+ * });
28
+ * ```
29
+ */
30
+ declare class FirekitAuth {
31
+ private static instance;
32
+ private auth;
33
+ private firestore;
34
+ private _servicesInitialized;
35
+ private authState;
36
+ private stateListeners;
37
+ private recaptchaVerifiers;
38
+ private constructor();
39
+ /**
40
+ * Gets singleton instance of FirekitAuth
41
+ * @returns {FirekitAuth} The FirekitAuth instance
42
+ */
43
+ static getInstance(): FirekitAuth;
44
+ /**
45
+ * Initializes Firebase services and auth state listener
46
+ * @private
47
+ */
48
+ private initializeServices;
49
+ /**
50
+ * Initializes the authentication state listener
51
+ * @private
52
+ */
53
+ private initializeAuthStateListener;
54
+ /**
55
+ * Notifies all state listeners of auth state changes
56
+ * @private
57
+ */
58
+ private notifyStateListeners;
59
+ /**
60
+ * Maps Firebase User to UserProfile interface
61
+ * @private
62
+ */
63
+ private mapFirebaseUserToProfile;
64
+ /**
65
+ * Updates user data in Firestore with comprehensive profile information
66
+ * @private
67
+ */
68
+ private updateUserInFirestore;
69
+ /**
70
+ * Handles Firebase authentication errors and throws FirekitAuthError
71
+ * @private
72
+ */
73
+ private handleAuthError;
74
+ /**
75
+ * Gets the current authentication state
76
+ * @returns {AuthState} Current authentication state
77
+ */
78
+ getState(): AuthState;
79
+ /**
80
+ * Gets the current authenticated user
81
+ * @returns {User | null} Current Firebase user or null
82
+ */
83
+ getCurrentUser(): User | null;
84
+ /**
85
+ * Gets the current user profile
86
+ * @returns {UserProfile | null} Current user profile or null
87
+ */
88
+ getCurrentUserProfile(): UserProfile | null;
89
+ /**
90
+ * Waits for auth initialization to complete
91
+ * @returns {Promise<UserProfile | null>} Promise that resolves when auth is initialized
92
+ */
93
+ waitForAuth(): Promise<UserProfile | null>;
94
+ /**
95
+ * Subscribes to authentication state changes
96
+ * @param {Function} callback Callback function to handle state changes
97
+ * @returns {Function} Unsubscribe function
98
+ */
99
+ onAuthStateChanged(callback: (state: AuthState) => void): () => void;
100
+ /**
101
+ * Signs in user with email and password
102
+ * @param {string} email User's email address
103
+ * @param {string} password User's password
104
+ * @returns {Promise<UserProfile>} Promise resolving to user profile
105
+ * @throws {FirekitAuthError} If sign-in fails
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * try {
110
+ * const user = await firekitAuth.signInWithEmail("user@example.com", "password123");
111
+ * console.log("Signed in:", user.displayName);
112
+ * } catch (error) {
113
+ * console.error("Sign-in failed:", error.message);
114
+ * }
115
+ * ```
116
+ */
117
+ signInWithEmail(email: string, password: string): Promise<UserProfile>;
118
+ /**
119
+ * Signs in user with Google popup
120
+ * @returns {Promise<UserProfile>} Promise resolving to user profile
121
+ * @throws {FirekitAuthError} If sign-in fails
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * try {
126
+ * const user = await firekitAuth.signInWithGoogle();
127
+ * console.log("Signed in with Google:", user.email);
128
+ * } catch (error) {
129
+ * if (error.code === 'auth/popup-closed-by-user') {
130
+ * console.log("User cancelled sign-in");
131
+ * }
132
+ * }
133
+ * ```
134
+ */
135
+ signInWithGoogle(): Promise<UserProfile>;
136
+ /**
137
+ * Signs in user with Facebook popup
138
+ * @returns {Promise<UserProfile>} Promise resolving to user profile
139
+ * @throws {FirekitAuthError} If sign-in fails
140
+ */
141
+ signInWithFacebook(): Promise<UserProfile>;
142
+ /**
143
+ * Signs in user with Apple popup
144
+ * @returns {Promise<UserProfile>} Promise resolving to user profile
145
+ * @throws {FirekitAuthError} If sign-in fails
146
+ */
147
+ signInWithApple(): Promise<UserProfile>;
148
+ /**
149
+ * Signs in user anonymously
150
+ * @returns {Promise<UserProfile>} Promise resolving to user profile
151
+ * @throws {FirekitAuthError} If sign-in fails
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const user = await firekitAuth.signInAnonymously();
156
+ * console.log("Anonymous user:", user.uid);
157
+ * ```
158
+ */
159
+ signInAnonymously(): Promise<UserProfile>;
160
+ /**
161
+ * Initiates phone number sign-in process
162
+ * @param {string} phoneNumber Phone number in international format
163
+ * @param {string} recaptchaContainerId ID of the reCAPTCHA container element
164
+ * @returns {Promise<PhoneVerificationResult>} Promise resolving to verification result
165
+ * @throws {FirekitAuthError} If verification initiation fails
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const verification = await firekitAuth.signInWithPhoneNumber("+1234567890", "recaptcha-container");
170
+ * const user = await verification.confirm("123456");
171
+ * ```
172
+ */
173
+ signInWithPhoneNumber(phoneNumber: string, recaptchaContainerId: string): Promise<PhoneVerificationResult>;
174
+ /**
175
+ * Registers new user with email and password
176
+ * @param {string} email User's email address
177
+ * @param {string} password User's password
178
+ * @param {string} [displayName] User's display name
179
+ * @param {boolean} [sendVerification=true] Whether to send email verification
180
+ * @returns {Promise<UserProfile>} Promise resolving to user profile
181
+ * @throws {FirekitAuthError} If registration fails
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const user = await firekitAuth.registerWithEmail(
186
+ * "user@example.com",
187
+ * "password123",
188
+ * "John Doe"
189
+ * );
190
+ * console.log("Registered:", user.displayName);
191
+ * ```
192
+ */
193
+ registerWithEmail(email: string, password: string, displayName?: string, sendVerification?: boolean): Promise<UserProfile>;
194
+ /**
195
+ * Sends password reset email
196
+ * @param {string} email User's email address
197
+ * @returns {Promise<void>} Promise that resolves when email is sent
198
+ * @throws {FirekitAuthError} If sending fails
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * await firekitAuth.sendPasswordReset("user@example.com");
203
+ * console.log("Password reset email sent");
204
+ * ```
205
+ */
206
+ sendPasswordReset(email: string): Promise<void>;
207
+ /**
208
+ * Confirms password reset with code
209
+ * @param {string} code Password reset code from email
210
+ * @param {string} newPassword New password
211
+ * @returns {Promise<void>} Promise that resolves when password is reset
212
+ * @throws {FirekitAuthError} If reset fails
213
+ */
214
+ confirmPasswordReset(code: string, newPassword: string): Promise<void>;
215
+ /**
216
+ * Updates user password with reauthentication
217
+ * @param {string} newPassword New password
218
+ * @param {string} currentPassword Current password for reauthentication
219
+ * @returns {Promise<PasswordUpdateResult>} Promise resolving to update result
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * const result = await firekitAuth.updatePassword("newPassword123", "oldPassword123");
224
+ * if (result.success) {
225
+ * console.log("Password updated successfully");
226
+ * } else {
227
+ * console.error("Update failed:", result.message);
228
+ * }
229
+ * ```
230
+ */
231
+ updatePassword(newPassword: string, currentPassword: string): Promise<PasswordUpdateResult>;
232
+ /**
233
+ * Updates user profile
234
+ * @param {Object} profile Profile update data
235
+ * @param {string} [profile.displayName] New display name
236
+ * @param {string} [profile.photoURL] New photo URL
237
+ * @returns {Promise<void>} Promise that resolves when profile is updated
238
+ * @throws {FirekitAuthError} If update fails
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * await firekitAuth.updateUserProfile({
243
+ * displayName: "John Smith",
244
+ * photoURL: "https://example.com/photo.jpg"
245
+ * });
246
+ * ```
247
+ */
248
+ updateUserProfile(profile: {
249
+ displayName?: string;
250
+ photoURL?: string;
251
+ }): Promise<void>;
252
+ /**
253
+ * Updates user email address
254
+ * @param {string} newEmail New email address
255
+ * @returns {Promise<void>} Promise that resolves when email is updated
256
+ * @throws {FirekitAuthError} If update fails
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * await firekitAuth.updateEmail("newemail@example.com");
261
+ * ```
262
+ */
263
+ updateEmail(newEmail: string): Promise<void>;
264
+ /**
265
+ * Sends email verification to current user
266
+ * @returns {Promise<void>} Promise that resolves when verification email is sent
267
+ * @throws {FirekitAuthError} If sending fails
268
+ *
269
+ * @example
270
+ * ```typescript
271
+ * await firekitAuth.sendEmailVerification();
272
+ * ```
273
+ */
274
+ sendEmailVerification(): Promise<void>;
275
+ /**
276
+ * Reloads user to get updated data
277
+ * @returns {Promise<void>} Promise that resolves when user is reloaded
278
+ * @throws {FirekitAuthError} If reload fails
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * await firekitAuth.reloadUser();
283
+ * ```
284
+ */
285
+ reloadUser(): Promise<void>;
286
+ /**
287
+ * Gets the current user's ID token
288
+ * @param {boolean} [forceRefresh=false] Whether to force token refresh
289
+ * @returns {Promise<string>} Promise resolving to ID token
290
+ * @throws {FirekitAuthError} If getting token fails
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * const token = await firekitAuth.getIdToken();
295
+ * ```
296
+ */
297
+ getIdToken(forceRefresh?: boolean): Promise<string>;
298
+ /**
299
+ * Reauthenticates user with current password
300
+ * @private
301
+ */
302
+ private reauthenticateUser;
303
+ /**
304
+ * Deletes user account
305
+ * @param {string} [currentPassword] Current password for reauthentication
306
+ * @returns {Promise<AccountDeletionResult>} Promise resolving to deletion result
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * const result = await firekitAuth.deleteAccount("currentPassword123");
311
+ * if (result.success) {
312
+ * console.log("Account deleted successfully");
313
+ * } else {
314
+ * console.error("Deletion failed:", result.message);
315
+ * }
316
+ * ```
317
+ */
318
+ deleteAccount(currentPassword?: string): Promise<AccountDeletionResult>;
319
+ /**
320
+ * Signs out the current user
321
+ * @returns {Promise<void>} Promise that resolves when sign-out completes
322
+ * @throws {FirekitAuthError} If sign-out fails
323
+ *
324
+ * @example
325
+ * ```typescript
326
+ * await firekitAuth.signOut();
327
+ * console.log("User signed out");
328
+ * ```
329
+ */
330
+ signOut(): Promise<void>;
331
+ /**
332
+ * Checks if user is authenticated
333
+ * @returns {boolean} True if user is authenticated
334
+ */
335
+ isAuthenticated(): boolean;
336
+ /**
337
+ * Checks if user is anonymous
338
+ * @returns {boolean} True if user is anonymous
339
+ */
340
+ isAnonymous(): boolean;
341
+ /**
342
+ * Checks if user's email is verified
343
+ * @returns {boolean} True if email is verified
344
+ */
345
+ isEmailVerified(): boolean;
346
+ /**
347
+ * Gets user's email address
348
+ * @returns {string | null} User's email or null
349
+ */
350
+ getUserEmail(): string | null;
351
+ /**
352
+ * Gets user's display name
353
+ * @returns {string | null} User's display name or null
354
+ */
355
+ getUserDisplayName(): string | null;
356
+ /**
357
+ * Gets user's photo URL
358
+ * @returns {string | null} User's photo URL or null
359
+ */
360
+ getUserPhotoURL(): string | null;
361
+ /**
362
+ * Gets user's unique ID
363
+ * @returns {string | null} User's UID or null
364
+ */
365
+ getUserId(): string | null;
366
+ /**
367
+ * Cleans up resources and listeners
368
+ * @returns {Promise<void>} Promise that resolves when cleanup completes
369
+ */
370
+ cleanup(): Promise<void>;
371
+ }
372
+ /**
373
+ * Pre-initialized singleton instance of FirekitAuth.
374
+ * This is the main export that should be used throughout your application.
375
+ *
376
+ * @example
377
+ * ```typescript
378
+ * import { firekitAuth } from 'svelte-firekit';
379
+ *
380
+ * // Sign in with email
381
+ * await firekitAuth.signInWithEmail("user@example.com", "password");
382
+ *
383
+ * // Listen to auth state
384
+ * const unsubscribe = firekitAuth.onAuthStateChanged((state) => {
385
+ * if (state.user) {
386
+ * console.log("User is signed in:", state.user.email);
387
+ * } else {
388
+ * console.log("User is signed out");
389
+ * }
390
+ * });
391
+ *
392
+ * // Clean up listener
393
+ * unsubscribe();
394
+ * ```
395
+ */
396
+ export declare const firekitAuth: FirekitAuth;
397
+ export {};