@umituz/web-firebase 3.2.3 → 3.2.5
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/package.json +5 -2
- package/src/application/use-cases/auth/sign-in-with-google.use-case.ts +13 -11
- package/src/domain/interfaces/file.repository.interface.ts +28 -3
- package/src/domain/interfaces/user.repository.interface.ts +12 -40
- package/src/infrastructure/firebase/auth.adapter.ts +2 -2
- package/src/infrastructure/firebase/client.ts +7 -7
- package/src/presentation/hooks/useAuth.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-firebase",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.5",
|
|
4
4
|
"description": "Comprehensive Firebase integration with domain-based architecture for web applications",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -21,7 +21,10 @@
|
|
|
21
21
|
"src"
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
|
-
"
|
|
24
|
+
"build": "npm run clean && tsc",
|
|
25
|
+
"clean": "rm -rf dist",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
25
28
|
},
|
|
26
29
|
"keywords": [
|
|
27
30
|
"firebase",
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import type { UserCredential } from 'firebase/auth'
|
|
7
7
|
import type { IAuthRepository } from '../../../domain/interfaces/auth.repository.interface'
|
|
8
8
|
import type { IUserRepository } from '../../../domain/interfaces/user.repository.interface'
|
|
9
|
-
import type { CreateUserDTO } from '../../dto/user.dto'
|
|
10
9
|
import { createAuthError, AuthErrorCode } from '../../../domain/errors/auth.errors'
|
|
11
10
|
|
|
12
11
|
export class SignInWithGoogleUseCase {
|
|
@@ -27,16 +26,19 @@ export class SignInWithGoogleUseCase {
|
|
|
27
26
|
const existingUser = await this.userRepository.getUser(result.user.uid)
|
|
28
27
|
if (!existingUser) {
|
|
29
28
|
// New user - create user document
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
await this.userRepository.createUser(result.user.uid, {
|
|
30
|
+
profile: {
|
|
31
|
+
id: result.user.uid,
|
|
32
|
+
email: result.user.email || '',
|
|
33
|
+
displayName: result.user.displayName || '',
|
|
34
|
+
photoURL: result.user.photoURL || undefined,
|
|
35
|
+
phoneNumber: result.user.phoneNumber || undefined,
|
|
36
|
+
emailVerified: result.user.emailVerified,
|
|
37
|
+
createdAt: Date.now(),
|
|
38
|
+
updatedAt: Date.now(),
|
|
39
|
+
lastLoginAt: Date.now(),
|
|
40
|
+
}
|
|
41
|
+
} as any)
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
return result
|
|
@@ -3,21 +3,33 @@
|
|
|
3
3
|
* @description Generic contract for file storage operations
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import type { UploadResult, UploadOptions } from '../entities/file.entity'
|
|
7
|
+
|
|
6
8
|
export interface IFileRepository {
|
|
7
9
|
/**
|
|
8
10
|
* Upload file to storage
|
|
9
11
|
*/
|
|
10
|
-
uploadFile(userId: string, path: string, file: File | Blob, options?:
|
|
12
|
+
uploadFile(userId: string, path: string, file: File | Blob, options?: UploadOptions): Promise<UploadResult>
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Upload image with automatic categorization
|
|
14
16
|
*/
|
|
15
|
-
uploadImage(userId: string, file: File, filename?: string): Promise<
|
|
17
|
+
uploadImage(userId: string, file: File, filename?: string): Promise<UploadResult>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Upload video with automatic categorization
|
|
21
|
+
*/
|
|
22
|
+
uploadVideo(userId: string, file: File, filename?: string): Promise<UploadResult>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Upload document with automatic categorization
|
|
26
|
+
*/
|
|
27
|
+
uploadDocument(userId: string, file: File, filename?: string): Promise<UploadResult>
|
|
16
28
|
|
|
17
29
|
/**
|
|
18
30
|
* Upload profile picture
|
|
19
31
|
*/
|
|
20
|
-
uploadProfilePicture(userId: string, file: File): Promise<
|
|
32
|
+
uploadProfilePicture(userId: string, file: File): Promise<UploadResult>
|
|
21
33
|
|
|
22
34
|
/**
|
|
23
35
|
* Get download URL for a file
|
|
@@ -34,11 +46,24 @@ export interface IFileRepository {
|
|
|
34
46
|
*/
|
|
35
47
|
deleteUserFiles(userId: string): Promise<void>
|
|
36
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Delete specific media types
|
|
51
|
+
*/
|
|
52
|
+
deleteImage(userId: string, filename: string): Promise<void>
|
|
53
|
+
deleteVideo(userId: string, filename: string): Promise<void>
|
|
54
|
+
deleteProfilePicture(userId: string, filename: string): Promise<void>
|
|
55
|
+
|
|
37
56
|
/**
|
|
38
57
|
* List user files
|
|
39
58
|
*/
|
|
40
59
|
listUserFiles(userId: string, path?: string): Promise<string[]>
|
|
41
60
|
|
|
61
|
+
/**
|
|
62
|
+
* List specific media types
|
|
63
|
+
*/
|
|
64
|
+
listUserImages(userId: string): Promise<string[]>
|
|
65
|
+
listUserVideos(userId: string): Promise<string[]>
|
|
66
|
+
|
|
42
67
|
/**
|
|
43
68
|
* Validate file before upload
|
|
44
69
|
*/
|
|
@@ -3,46 +3,18 @@
|
|
|
3
3
|
* @description Generic contract for user data operations
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type {
|
|
6
|
+
import type { User } from '../entities/user.entity'
|
|
7
7
|
|
|
8
8
|
export interface IUserRepository {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* Create document
|
|
21
|
-
*/
|
|
22
|
-
create(userId: string, data: any): Promise<void>
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Update document
|
|
26
|
-
*/
|
|
27
|
-
update(userId: string, data: any, options?: { merge?: boolean }): Promise<void>
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Delete document
|
|
31
|
-
*/
|
|
32
|
-
delete(userId: string): Promise<void>
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Query collection with constraints
|
|
36
|
-
*/
|
|
37
|
-
query<T>(collectionPath: string, constraints: QueryConstraint[]): Promise<T[]>
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Subscribe to document changes
|
|
41
|
-
*/
|
|
42
|
-
subscribeToDoc<T>(docPath: string, callback: (data: T | null) => void): () => void
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Subscribe to collection changes
|
|
46
|
-
*/
|
|
47
|
-
subscribeToCollection<T>(collectionPath: string, callback: (data: T[]) => void, constraints?: QueryConstraint[]): () => void
|
|
9
|
+
getUser(userId: string): Promise<User | null>
|
|
10
|
+
getUserByEmail(email: string): Promise<User | null>
|
|
11
|
+
createUser(userId: string, data: Partial<User>): Promise<void>
|
|
12
|
+
updateUser(userId: string, data: Partial<User>): Promise<void>
|
|
13
|
+
deleteUser(userId: string): Promise<void>
|
|
14
|
+
updateProfile(userId: string, updates: Partial<Pick<User['profile'], 'displayName' | 'photoURL' | 'phoneNumber'>>): Promise<void>
|
|
15
|
+
updateSettings(userId: string, settings: Partial<User['settings']>): Promise<void>
|
|
16
|
+
updateSubscription(userId: string, subscription: Partial<User['subscription']>): Promise<void>
|
|
17
|
+
updateLastLogin(userId: string): Promise<void>
|
|
18
|
+
queryUsers(constraints: any[]): Promise<User[]>
|
|
19
|
+
subscribeToUser(userId: string, callback: (user: User | null) => void, onError?: (error: Error) => void): () => void
|
|
48
20
|
}
|
|
@@ -320,8 +320,8 @@ export class AuthAdapter implements IAuthRepository {
|
|
|
320
320
|
return this.auth.currentUser
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
-
onAuthStateChanged(callback: (user: FirebaseUser | null) => void) {
|
|
324
|
-
return this.auth.onAuthStateChanged(callback)
|
|
323
|
+
onAuthStateChanged(callback: (user: FirebaseUser | null) => void, onError?: (error: Error) => void) {
|
|
324
|
+
return this.auth.onAuthStateChanged(callback, onError)
|
|
325
325
|
}
|
|
326
326
|
|
|
327
327
|
// ==================== Token Management ====================
|
|
@@ -12,13 +12,13 @@ import { getAnalytics, Analytics } from 'firebase/analytics'
|
|
|
12
12
|
import { getFunctions, Functions } from 'firebase/functions'
|
|
13
13
|
|
|
14
14
|
const firebaseConfig = {
|
|
15
|
-
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
|
|
16
|
-
authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
|
|
17
|
-
projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
|
|
18
|
-
storageBucket: import.meta.env.VITE_FIREBASE_STORAGE_BUCKET,
|
|
19
|
-
messagingSenderId: import.meta.env.VITE_FIREBASE_MESSAGING_SENDER_ID,
|
|
20
|
-
appId: import.meta.env.VITE_FIREBASE_APP_ID,
|
|
21
|
-
measurementId: import.meta.env.VITE_FIREBASE_MEASUREMENT_ID,
|
|
15
|
+
apiKey: (import.meta as any).env.VITE_FIREBASE_API_KEY,
|
|
16
|
+
authDomain: (import.meta as any).env.VITE_FIREBASE_AUTH_DOMAIN,
|
|
17
|
+
projectId: (import.meta as any).env.VITE_FIREBASE_PROJECT_ID,
|
|
18
|
+
storageBucket: (import.meta as any).env.VITE_FIREBASE_STORAGE_BUCKET,
|
|
19
|
+
messagingSenderId: (import.meta as any).env.VITE_FIREBASE_MESSAGING_SENDER_ID,
|
|
20
|
+
appId: (import.meta as any).env.VITE_FIREBASE_APP_ID,
|
|
21
|
+
measurementId: (import.meta as any).env.VITE_FIREBASE_MEASUREMENT_ID,
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// Singleton instances
|
|
@@ -152,7 +152,7 @@ export function useAuth(): UseAuthResult {
|
|
|
152
152
|
id: result.user.uid,
|
|
153
153
|
email: result.user.email ?? '',
|
|
154
154
|
displayName: result.user.displayName ?? '',
|
|
155
|
-
photoURL: result.user.photoURL,
|
|
155
|
+
photoURL: result.user.photoURL || undefined,
|
|
156
156
|
createdAt: now,
|
|
157
157
|
updatedAt: now,
|
|
158
158
|
lastLoginAt: now,
|
|
@@ -207,7 +207,7 @@ export function useAuth(): UseAuthResult {
|
|
|
207
207
|
id: result.user.uid,
|
|
208
208
|
email: result.user.email ?? '',
|
|
209
209
|
displayName: result.user.displayName ?? '',
|
|
210
|
-
photoURL: result.user.photoURL,
|
|
210
|
+
photoURL: result.user.photoURL || undefined,
|
|
211
211
|
createdAt: now,
|
|
212
212
|
updatedAt: now,
|
|
213
213
|
lastLoginAt: now,
|