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.
- package/README.md +445 -213
- package/dist/components/Collection.svelte +150 -0
- package/dist/components/Collection.svelte.d.ts +27 -0
- package/dist/components/Ddoc.svelte +131 -0
- package/dist/components/Ddoc.svelte.d.ts +28 -0
- package/dist/components/Node.svelte +97 -0
- package/dist/components/Node.svelte.d.ts +23 -0
- package/dist/components/auth-guard.svelte +89 -0
- package/dist/components/auth-guard.svelte.d.ts +26 -0
- package/dist/components/custom-guard.svelte +122 -0
- package/dist/components/custom-guard.svelte.d.ts +31 -0
- package/dist/components/download-url.svelte +92 -0
- package/dist/components/download-url.svelte.d.ts +19 -0
- package/dist/components/firebase-app.svelte +30 -0
- package/dist/components/firebase-app.svelte.d.ts +7 -0
- package/dist/components/node-list.svelte +102 -0
- package/dist/components/node-list.svelte.d.ts +27 -0
- package/dist/components/signed-in.svelte +42 -0
- package/dist/components/signed-in.svelte.d.ts +11 -0
- package/dist/components/signed-out.svelte +42 -0
- package/dist/components/signed-out.svelte.d.ts +11 -0
- package/dist/components/storage-list.svelte +97 -0
- package/dist/components/storage-list.svelte.d.ts +26 -0
- package/dist/components/upload-task.svelte +108 -0
- package/dist/components/upload-task.svelte.d.ts +24 -0
- package/dist/config.js +17 -39
- package/dist/firebase.d.ts +43 -21
- package/dist/firebase.js +121 -35
- package/dist/index.d.ts +21 -13
- package/dist/index.js +27 -15
- package/dist/services/auth.d.ts +397 -0
- package/dist/services/auth.js +882 -0
- package/dist/services/collection.svelte.d.ts +286 -0
- package/dist/services/collection.svelte.js +871 -0
- package/dist/services/document.svelte.d.ts +288 -0
- package/dist/services/document.svelte.js +555 -0
- package/dist/services/mutations.d.ts +336 -0
- package/dist/services/mutations.js +1079 -0
- package/dist/services/presence.svelte.d.ts +141 -0
- package/dist/services/presence.svelte.js +727 -0
- package/dist/{realtime → services}/realtime.svelte.d.ts +3 -1
- package/dist/{realtime → services}/realtime.svelte.js +13 -7
- package/dist/services/storage.svelte.d.ts +257 -0
- package/dist/services/storage.svelte.js +374 -0
- package/dist/services/user.svelte.d.ts +296 -0
- package/dist/services/user.svelte.js +609 -0
- package/dist/types/auth.d.ts +158 -0
- package/dist/types/auth.js +106 -0
- package/dist/types/collection.d.ts +360 -0
- package/dist/types/collection.js +167 -0
- package/dist/types/document.d.ts +342 -0
- package/dist/types/document.js +148 -0
- package/dist/types/firebase.d.ts +44 -0
- package/dist/types/firebase.js +33 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +4 -0
- package/dist/types/mutations.d.ts +387 -0
- package/dist/types/mutations.js +205 -0
- package/dist/types/presence.d.ts +282 -0
- package/dist/types/presence.js +80 -0
- package/dist/utils/errors.d.ts +21 -0
- package/dist/utils/errors.js +35 -0
- package/dist/utils/firestore.d.ts +9 -0
- package/dist/utils/firestore.js +33 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/providers.d.ts +16 -0
- package/dist/utils/providers.js +30 -0
- package/dist/utils/user.d.ts +8 -0
- package/dist/utils/user.js +29 -0
- package/package.json +64 -64
- package/dist/auth/auth.d.ts +0 -117
- package/dist/auth/auth.js +0 -194
- package/dist/auth/presence.svelte.d.ts +0 -139
- package/dist/auth/presence.svelte.js +0 -373
- package/dist/auth/user.svelte.d.ts +0 -112
- package/dist/auth/user.svelte.js +0 -155
- package/dist/firestore/awaitable-doc.svelte.d.ts +0 -141
- package/dist/firestore/awaitable-doc.svelte.js +0 -183
- package/dist/firestore/batch-mutations.svelte.d.ts +0 -140
- package/dist/firestore/batch-mutations.svelte.js +0 -218
- package/dist/firestore/collection-group.svelte.d.ts +0 -78
- package/dist/firestore/collection-group.svelte.js +0 -120
- package/dist/firestore/collection.svelte.d.ts +0 -96
- package/dist/firestore/collection.svelte.js +0 -137
- package/dist/firestore/doc.svelte.d.ts +0 -90
- package/dist/firestore/doc.svelte.js +0 -131
- package/dist/firestore/document-mutations.svelte.d.ts +0 -164
- package/dist/firestore/document-mutations.svelte.js +0 -273
- package/dist/storage/download-url.svelte.d.ts +0 -83
- package/dist/storage/download-url.svelte.js +0 -114
- package/dist/storage/storage-list.svelte.d.ts +0 -89
- package/dist/storage/storage-list.svelte.js +0 -123
- package/dist/storage/upload-task.svelte.d.ts +0 -94
- package/dist/storage/upload-task.svelte.js +0 -138
package/package.json
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "svelte-firekit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"dev": "vite dev",
|
|
7
|
-
"build": "vite build && npm run
|
|
8
|
-
"preview": "vite preview",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
12
|
-
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
13
|
-
"format": "prettier --write .",
|
|
14
|
-
"lint": "prettier --check ."
|
|
15
|
-
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "https://github.com/code-gio/svelte-firekit.git"
|
|
19
|
-
},
|
|
20
|
-
"description": "A Svelte library for Firebase integration",
|
|
21
|
-
"keywords": [
|
|
22
|
-
"svelte",
|
|
23
|
-
"firebase",
|
|
24
|
-
"library",
|
|
25
|
-
"frontend"
|
|
26
|
-
],
|
|
27
|
-
"author": "Giovani Rodriguez",
|
|
28
|
-
"files": [
|
|
29
|
-
"dist",
|
|
30
|
-
"!dist/**/*.test.*",
|
|
31
|
-
"!dist/**/*.spec.*"
|
|
32
|
-
],
|
|
33
|
-
"sideEffects": [
|
|
34
|
-
"**/*.css"
|
|
35
|
-
],
|
|
36
|
-
"svelte": "./dist/index.js",
|
|
37
|
-
"types": "./dist/index.d.ts",
|
|
38
|
-
"type": "module",
|
|
39
|
-
"exports": {
|
|
40
|
-
".": {
|
|
41
|
-
"types": "./dist/index.d.ts",
|
|
42
|
-
"svelte": "./dist/index.js"
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
"peerDependencies": {
|
|
46
|
-
"firebase": "^11.
|
|
47
|
-
"svelte": "^5.0.0"
|
|
48
|
-
},
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@sveltejs/adapter-auto": "^
|
|
51
|
-
"@sveltejs/kit": "^2.
|
|
52
|
-
"@sveltejs/package": "^2.0.0",
|
|
53
|
-
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
|
54
|
-
"prettier": "^3.
|
|
55
|
-
"prettier-plugin-svelte": "^3.
|
|
56
|
-
"publint": "^0.2
|
|
57
|
-
"svelte": "^5.0.0",
|
|
58
|
-
"svelte-check": "^4.0.0",
|
|
59
|
-
"typescript": "^5.0.0",
|
|
60
|
-
"vite": "^6.
|
|
61
|
-
},
|
|
62
|
-
"dependencies": {
|
|
63
|
-
"firebase": "^11.
|
|
64
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "svelte-firekit",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite dev",
|
|
7
|
+
"build": "vite build && npm run prepack",
|
|
8
|
+
"preview": "vite preview",
|
|
9
|
+
"prepare": "svelte-kit sync || echo ''",
|
|
10
|
+
"prepack": "svelte-kit sync && svelte-package && publint",
|
|
11
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
12
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
13
|
+
"format": "prettier --write .",
|
|
14
|
+
"lint": "prettier --check ."
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/code-gio/svelte-firekit.git"
|
|
19
|
+
},
|
|
20
|
+
"description": "A Svelte library for Firebase integration",
|
|
21
|
+
"keywords": [
|
|
22
|
+
"svelte",
|
|
23
|
+
"firebase",
|
|
24
|
+
"library",
|
|
25
|
+
"frontend"
|
|
26
|
+
],
|
|
27
|
+
"author": "Giovani Rodriguez",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"!dist/**/*.test.*",
|
|
31
|
+
"!dist/**/*.spec.*"
|
|
32
|
+
],
|
|
33
|
+
"sideEffects": [
|
|
34
|
+
"**/*.css"
|
|
35
|
+
],
|
|
36
|
+
"svelte": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"type": "module",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"svelte": "./dist/index.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"firebase": "^11.9.1",
|
|
47
|
+
"svelte": "^5.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@sveltejs/adapter-auto": "^6.0.0",
|
|
51
|
+
"@sveltejs/kit": "^2.16.0",
|
|
52
|
+
"@sveltejs/package": "^2.0.0",
|
|
53
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
|
54
|
+
"prettier": "^3.4.2",
|
|
55
|
+
"prettier-plugin-svelte": "^3.3.3",
|
|
56
|
+
"publint": "^0.3.2",
|
|
57
|
+
"svelte": "^5.0.0",
|
|
58
|
+
"svelte-check": "^4.0.0",
|
|
59
|
+
"typescript": "^5.0.0",
|
|
60
|
+
"vite": "^6.2.6"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"firebase": "^11.9.1"
|
|
64
|
+
}
|
|
65
65
|
}
|
package/dist/auth/auth.d.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module FirekitAuth
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Manages Firebase authentication operations including sign-in, registration, and profile management.
|
|
6
|
-
* @class
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // Sign in with Google
|
|
10
|
-
* await firekitAuth.signInWithGoogle();
|
|
11
|
-
*
|
|
12
|
-
* // Register new user
|
|
13
|
-
* await firekitAuth.registerWithEmail("user@example.com", "password123", "John Doe");
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
declare class FirekitAuth {
|
|
17
|
-
private static instance;
|
|
18
|
-
private auth;
|
|
19
|
-
private firestore;
|
|
20
|
-
private constructor();
|
|
21
|
-
/**
|
|
22
|
-
* Gets singleton instance of FirekitAuth
|
|
23
|
-
* @returns {FirekitAuth} The FirekitAuth instance
|
|
24
|
-
*/
|
|
25
|
-
static getInstance(): FirekitAuth;
|
|
26
|
-
/**
|
|
27
|
-
* Initiates Google sign-in popup and updates user data in Firestore
|
|
28
|
-
* @throws {Error} If sign-in fails
|
|
29
|
-
*/
|
|
30
|
-
signInWithGoogle(): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Signs in user with email and password
|
|
33
|
-
* @param {string} email User's email
|
|
34
|
-
* @param {string} password User's password
|
|
35
|
-
* @throws {Error} If sign-in fails
|
|
36
|
-
*/
|
|
37
|
-
signInWithEmail(email: string, password: string): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Registers new user with email and password
|
|
40
|
-
* @param {string} email User's email
|
|
41
|
-
* @param {string} password User's password
|
|
42
|
-
* @param {string} displayName User's display name
|
|
43
|
-
* @throws {Error} If registration fails
|
|
44
|
-
*/
|
|
45
|
-
registerWithEmail(email: string, password: string, displayName: string): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Updates user data in Firestore
|
|
48
|
-
* @param {User} user Firebase user object
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
private updateUserInFirestore;
|
|
52
|
-
/**
|
|
53
|
-
* Signs out current user
|
|
54
|
-
* @throws {Error} If sign-out fails
|
|
55
|
-
*/
|
|
56
|
-
logOut(): Promise<void>;
|
|
57
|
-
/**
|
|
58
|
-
* Sends password reset email
|
|
59
|
-
* @param {string} email User's email
|
|
60
|
-
* @throws {Error} If sending reset email fails
|
|
61
|
-
*/
|
|
62
|
-
sendPasswordReset(email: string): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Sends email verification to current user
|
|
65
|
-
* @throws {Error} If sending verification fails
|
|
66
|
-
*/
|
|
67
|
-
sendEmailVerificationToUser(): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Updates user profile data
|
|
70
|
-
* @param {Object} profile Profile update data
|
|
71
|
-
* @param {string} [profile.displayName] New display name
|
|
72
|
-
* @param {string} [profile.photoURL] New photo URL
|
|
73
|
-
* @throws {Error} If update fails
|
|
74
|
-
*/
|
|
75
|
-
updateUserProfile(profile: {
|
|
76
|
-
displayName?: string;
|
|
77
|
-
photoURL?: string;
|
|
78
|
-
}): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Updates user password with reauthentication
|
|
81
|
-
* @param {string} newPassword New password
|
|
82
|
-
* @param {string} currentPassword Current password for reauthentication
|
|
83
|
-
* @returns {Promise<{success: boolean, message: string, code?: string}>} Update result
|
|
84
|
-
*/
|
|
85
|
-
updateUserPassword(newPassword: string, currentPassword: string): Promise<{
|
|
86
|
-
success: boolean;
|
|
87
|
-
message: string;
|
|
88
|
-
code?: undefined;
|
|
89
|
-
} | {
|
|
90
|
-
success: boolean;
|
|
91
|
-
code: any;
|
|
92
|
-
message: string;
|
|
93
|
-
}>;
|
|
94
|
-
/**
|
|
95
|
-
* Reauthenticates current user
|
|
96
|
-
* @param {string} currentPassword Current password
|
|
97
|
-
* @throws {Error} If reauthentication fails
|
|
98
|
-
* @private
|
|
99
|
-
*/
|
|
100
|
-
private reauthenticateUser;
|
|
101
|
-
/**
|
|
102
|
-
* Deletes user account and associated data
|
|
103
|
-
* @returns {Promise<{success: boolean, message: string}>} Deletion result
|
|
104
|
-
* @throws {Error} If deletion fails
|
|
105
|
-
*/
|
|
106
|
-
deleteUserAccount(): Promise<{
|
|
107
|
-
success: boolean;
|
|
108
|
-
message: string;
|
|
109
|
-
}>;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Pre-initialized singleton instance of FirekitAuth
|
|
113
|
-
* @const
|
|
114
|
-
* @type {FirekitAuth}
|
|
115
|
-
*/
|
|
116
|
-
export declare const firekitAuth: FirekitAuth;
|
|
117
|
-
export {};
|
package/dist/auth/auth.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module FirekitAuth
|
|
3
|
-
*/
|
|
4
|
-
import { GoogleAuthProvider, sendPasswordResetEmail, signInWithEmailAndPassword, signInWithPopup, signOut, createUserWithEmailAndPassword, sendEmailVerification, updateProfile, updatePassword, EmailAuthProvider, reauthenticateWithCredential, } from 'firebase/auth';
|
|
5
|
-
import { doc, setDoc } from 'firebase/firestore';
|
|
6
|
-
import { firebaseService } from '../firebase.js';
|
|
7
|
-
import { firekitDocMutations } from '../firestore/document-mutations.svelte.js';
|
|
8
|
-
/**
|
|
9
|
-
* Manages Firebase authentication operations including sign-in, registration, and profile management.
|
|
10
|
-
* @class
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* // Sign in with Google
|
|
14
|
-
* await firekitAuth.signInWithGoogle();
|
|
15
|
-
*
|
|
16
|
-
* // Register new user
|
|
17
|
-
* await firekitAuth.registerWithEmail("user@example.com", "password123", "John Doe");
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
class FirekitAuth {
|
|
21
|
-
static instance;
|
|
22
|
-
auth = firebaseService.getAuthInstance();
|
|
23
|
-
firestore = firebaseService.getDbInstance();
|
|
24
|
-
constructor() { }
|
|
25
|
-
/**
|
|
26
|
-
* Gets singleton instance of FirekitAuth
|
|
27
|
-
* @returns {FirekitAuth} The FirekitAuth instance
|
|
28
|
-
*/
|
|
29
|
-
static getInstance() {
|
|
30
|
-
if (!FirekitAuth.instance) {
|
|
31
|
-
FirekitAuth.instance = new FirekitAuth();
|
|
32
|
-
}
|
|
33
|
-
return FirekitAuth.instance;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Initiates Google sign-in popup and updates user data in Firestore
|
|
37
|
-
* @throws {Error} If sign-in fails
|
|
38
|
-
*/
|
|
39
|
-
async signInWithGoogle() {
|
|
40
|
-
const provider = new GoogleAuthProvider();
|
|
41
|
-
const result = await signInWithPopup(this.auth, provider);
|
|
42
|
-
await this.updateUserInFirestore(result.user);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Signs in user with email and password
|
|
46
|
-
* @param {string} email User's email
|
|
47
|
-
* @param {string} password User's password
|
|
48
|
-
* @throws {Error} If sign-in fails
|
|
49
|
-
*/
|
|
50
|
-
async signInWithEmail(email, password) {
|
|
51
|
-
const result = await signInWithEmailAndPassword(this.auth, email, password);
|
|
52
|
-
await this.updateUserInFirestore(result.user);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Registers new user with email and password
|
|
56
|
-
* @param {string} email User's email
|
|
57
|
-
* @param {string} password User's password
|
|
58
|
-
* @param {string} displayName User's display name
|
|
59
|
-
* @throws {Error} If registration fails
|
|
60
|
-
*/
|
|
61
|
-
async registerWithEmail(email, password, displayName) {
|
|
62
|
-
const result = await createUserWithEmailAndPassword(this.auth, email, password);
|
|
63
|
-
const user = result.user;
|
|
64
|
-
if (user) {
|
|
65
|
-
await updateProfile(user, { displayName });
|
|
66
|
-
await this.updateUserInFirestore(user);
|
|
67
|
-
await sendEmailVerification(user);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Updates user data in Firestore
|
|
72
|
-
* @param {User} user Firebase user object
|
|
73
|
-
* @private
|
|
74
|
-
*/
|
|
75
|
-
async updateUserInFirestore(user) {
|
|
76
|
-
const ref = doc(this.firestore, 'users', user.uid);
|
|
77
|
-
const userData = {
|
|
78
|
-
uid: user.uid,
|
|
79
|
-
email: user.email,
|
|
80
|
-
emailVerified: user.emailVerified,
|
|
81
|
-
displayName: user.displayName,
|
|
82
|
-
photoURL: user.photoURL,
|
|
83
|
-
isAnonymous: user.isAnonymous,
|
|
84
|
-
providerId: user.providerId,
|
|
85
|
-
providerData: user.providerData,
|
|
86
|
-
};
|
|
87
|
-
await setDoc(ref, userData, { merge: true });
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Signs out current user
|
|
91
|
-
* @throws {Error} If sign-out fails
|
|
92
|
-
*/
|
|
93
|
-
async logOut() {
|
|
94
|
-
await signOut(this.auth);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Sends password reset email
|
|
98
|
-
* @param {string} email User's email
|
|
99
|
-
* @throws {Error} If sending reset email fails
|
|
100
|
-
*/
|
|
101
|
-
async sendPasswordReset(email) {
|
|
102
|
-
await sendPasswordResetEmail(this.auth, email);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Sends email verification to current user
|
|
106
|
-
* @throws {Error} If sending verification fails
|
|
107
|
-
*/
|
|
108
|
-
async sendEmailVerificationToUser() {
|
|
109
|
-
if (this.auth.currentUser) {
|
|
110
|
-
await sendEmailVerification(this.auth.currentUser);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Updates user profile data
|
|
115
|
-
* @param {Object} profile Profile update data
|
|
116
|
-
* @param {string} [profile.displayName] New display name
|
|
117
|
-
* @param {string} [profile.photoURL] New photo URL
|
|
118
|
-
* @throws {Error} If update fails
|
|
119
|
-
*/
|
|
120
|
-
async updateUserProfile(profile) {
|
|
121
|
-
if (this.auth.currentUser) {
|
|
122
|
-
await updateProfile(this.auth.currentUser, profile);
|
|
123
|
-
await this.updateUserInFirestore(this.auth.currentUser);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Updates user password with reauthentication
|
|
128
|
-
* @param {string} newPassword New password
|
|
129
|
-
* @param {string} currentPassword Current password for reauthentication
|
|
130
|
-
* @returns {Promise<{success: boolean, message: string, code?: string}>} Update result
|
|
131
|
-
*/
|
|
132
|
-
async updateUserPassword(newPassword, currentPassword) {
|
|
133
|
-
if (!this.auth.currentUser) {
|
|
134
|
-
throw new Error('No authenticated user found.');
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
await this.reauthenticateUser(currentPassword);
|
|
138
|
-
await updatePassword(this.auth.currentUser, newPassword);
|
|
139
|
-
return { success: true, message: 'Password successfully updated.' };
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
if (error.code === 'auth/wrong-password') {
|
|
143
|
-
return { success: false, code: error.code, message: 'Reauthentication failed: incorrect password.' };
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
success: false,
|
|
147
|
-
code: error.code || 'unknown_error',
|
|
148
|
-
message: `Failed to update password: ${error.message || 'Unknown error occurred.'}`
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Reauthenticates current user
|
|
154
|
-
* @param {string} currentPassword Current password
|
|
155
|
-
* @throws {Error} If reauthentication fails
|
|
156
|
-
* @private
|
|
157
|
-
*/
|
|
158
|
-
async reauthenticateUser(currentPassword) {
|
|
159
|
-
if (!this.auth.currentUser || !this.auth.currentUser.email) {
|
|
160
|
-
throw new Error('No authenticated user or email unavailable.');
|
|
161
|
-
}
|
|
162
|
-
const credential = EmailAuthProvider.credential(this.auth.currentUser.email, currentPassword);
|
|
163
|
-
try {
|
|
164
|
-
await reauthenticateWithCredential(this.auth.currentUser, credential);
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
throw new Error(`Reauthentication failed: ${error.message || 'Unknown error occurred.'}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Deletes user account and associated data
|
|
172
|
-
* @returns {Promise<{success: boolean, message: string}>} Deletion result
|
|
173
|
-
* @throws {Error} If deletion fails
|
|
174
|
-
*/
|
|
175
|
-
async deleteUserAccount() {
|
|
176
|
-
if (!this.auth.currentUser) {
|
|
177
|
-
throw new Error('No authenticated user found.');
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
firekitDocMutations.delete(`users/${this.auth.currentUser.uid}`);
|
|
181
|
-
await this.auth.currentUser.delete();
|
|
182
|
-
return { success: true, message: 'Account successfully deleted.' };
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
throw new Error(error.message);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Pre-initialized singleton instance of FirekitAuth
|
|
191
|
-
* @const
|
|
192
|
-
* @type {FirekitAuth}
|
|
193
|
-
*/
|
|
194
|
-
export const firekitAuth = FirekitAuth.getInstance();
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Geolocation configuration options
|
|
3
|
-
*/
|
|
4
|
-
interface GeolocationConfig {
|
|
5
|
-
/** Whether geolocation tracking is enabled */
|
|
6
|
-
enabled: boolean;
|
|
7
|
-
/** Type of geolocation service to use */
|
|
8
|
-
type: 'browser' | 'ip' | 'custom';
|
|
9
|
-
/** Custom function for retrieving geolocation */
|
|
10
|
-
customGeolocationFn?: () => Promise<{
|
|
11
|
-
latitude: number;
|
|
12
|
-
longitude: number;
|
|
13
|
-
}>;
|
|
14
|
-
/** URL for IP-based geolocation service */
|
|
15
|
-
ipServiceUrl?: string;
|
|
16
|
-
/** Whether user consent is required for location tracking */
|
|
17
|
-
requireConsent?: boolean;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Presence service configuration options
|
|
21
|
-
*/
|
|
22
|
-
interface PresenceConfig {
|
|
23
|
-
/** Geolocation settings */
|
|
24
|
-
geolocation?: GeolocationConfig;
|
|
25
|
-
/** Session timeout in milliseconds */
|
|
26
|
-
sessionTTL?: number;
|
|
27
|
-
/** Presence update interval in milliseconds */
|
|
28
|
-
updateInterval?: number;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Location data structure
|
|
32
|
-
*/
|
|
33
|
-
interface Location {
|
|
34
|
-
latitude: number | null;
|
|
35
|
-
longitude: number | null;
|
|
36
|
-
lastUpdated: string | null;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Session data structure
|
|
40
|
-
*/
|
|
41
|
-
interface SessionData {
|
|
42
|
-
uid: string;
|
|
43
|
-
userId: string;
|
|
44
|
-
deviceId: string;
|
|
45
|
-
status: 'online' | 'offline' | 'away';
|
|
46
|
-
createdAt: string;
|
|
47
|
-
lastSeen: string;
|
|
48
|
-
location?: Location;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Presence event structure
|
|
52
|
-
*/
|
|
53
|
-
type PresenceEvent = {
|
|
54
|
-
type: 'status_change' | 'error' | 'init' | 'disconnect' | 'location_update';
|
|
55
|
-
data?: any;
|
|
56
|
-
error?: Error;
|
|
57
|
-
timestamp: number;
|
|
58
|
-
};
|
|
59
|
-
type PresenceEventCallback = (event: PresenceEvent) => void;
|
|
60
|
-
/**
|
|
61
|
-
* Manages real-time user presence tracking with optional geolocation support
|
|
62
|
-
* @class
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* // Initialize presence tracking
|
|
66
|
-
* await presenceService.initialize(currentUser, {
|
|
67
|
-
* geolocation: { enabled: true, type: 'browser' },
|
|
68
|
-
* sessionTTL: 30 * 60 * 1000
|
|
69
|
-
* });
|
|
70
|
-
*
|
|
71
|
-
* // Listen for presence events
|
|
72
|
-
* presenceService.addEventListener((event) => {
|
|
73
|
-
* console.log(event.type, event.data);
|
|
74
|
-
* });
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
declare class PresenceService {
|
|
78
|
-
private static instance;
|
|
79
|
-
private connectedListener;
|
|
80
|
-
private locationWatcher;
|
|
81
|
-
private currentUser;
|
|
82
|
-
private eventListeners;
|
|
83
|
-
private config;
|
|
84
|
-
private initialized;
|
|
85
|
-
private locationConsent;
|
|
86
|
-
private _currentSession;
|
|
87
|
-
private _sessions;
|
|
88
|
-
private _status;
|
|
89
|
-
private _loading;
|
|
90
|
-
private _error;
|
|
91
|
-
private constructor();
|
|
92
|
-
static getInstance(): PresenceService;
|
|
93
|
-
/** Get current session data */
|
|
94
|
-
get currentSession(): SessionData | null;
|
|
95
|
-
/** Get all active sessions */
|
|
96
|
-
get sessions(): SessionData[];
|
|
97
|
-
/** Get current presence status */
|
|
98
|
-
get status(): "online" | "offline" | "away";
|
|
99
|
-
/** Get loading state */
|
|
100
|
-
get loading(): boolean;
|
|
101
|
-
/** Get error state */
|
|
102
|
-
get error(): Error | null;
|
|
103
|
-
/** Check if service is initialized */
|
|
104
|
-
get isInitialized(): boolean;
|
|
105
|
-
/** Check if location consent is granted */
|
|
106
|
-
get hasLocationConsent(): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Initialize presence tracking
|
|
109
|
-
* @param {any} user Current user object
|
|
110
|
-
* @param {PresenceConfig} config Optional configuration
|
|
111
|
-
* @throws {Error} If initialization fails
|
|
112
|
-
*/
|
|
113
|
-
private initializePresence;
|
|
114
|
-
private setupVisibilityListener;
|
|
115
|
-
private getDeviceInfo;
|
|
116
|
-
/**
|
|
117
|
-
* Request location tracking consent
|
|
118
|
-
* @returns {Promise<boolean>} Whether consent was granted
|
|
119
|
-
*/
|
|
120
|
-
requestLocationConsent(): Promise<boolean>;
|
|
121
|
-
private getLocation;
|
|
122
|
-
initialize(user: any, config?: PresenceConfig): Promise<void>;
|
|
123
|
-
private setPresence;
|
|
124
|
-
private startLocationWatcher;
|
|
125
|
-
private stopLocationWatcher;
|
|
126
|
-
/**
|
|
127
|
-
* Add presence event listener
|
|
128
|
-
* @param {Function} callback Event callback function
|
|
129
|
-
* @returns {Function} Cleanup function to remove listener
|
|
130
|
-
*/
|
|
131
|
-
addEventListener(callback: PresenceEventCallback): () => boolean;
|
|
132
|
-
private emitEvent;
|
|
133
|
-
/**
|
|
134
|
-
* Cleanup presence tracking
|
|
135
|
-
*/
|
|
136
|
-
dispose(): void;
|
|
137
|
-
}
|
|
138
|
-
export declare const presenceService: PresenceService;
|
|
139
|
-
export {};
|