nestjs-firebase-admin 0.4.5 → 0.5.6
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 +22 -127
- package/art/logo.png +0 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/modules/admin/admin.module.js +36 -6
- package/dist/modules/admin/{admin.service.d.ts → services/admin.service.d.ts} +1 -1
- package/dist/modules/admin/{admin.service.js → services/admin.service.js} +1 -1
- package/dist/modules/admin/services/auth.service.d.ts +32 -0
- package/dist/modules/admin/services/auth.service.js +87 -0
- package/dist/modules/admin/{database.service.d.ts → services/database.service.d.ts} +1 -1
- package/dist/modules/admin/{database.service.js → services/database.service.js} +1 -1
- package/dist/modules/admin/services/firestore.service.d.ts +18 -0
- package/dist/modules/admin/services/firestore.service.js +94 -0
- package/dist/modules/admin/{messaging.service.js → services/messaging.service.js} +1 -1
- package/docs/_sidebar.md +10 -0
- package/docs/getting-started.md +82 -0
- package/docs/services/admin-service.md +99 -0
- package/docs/services/auth-service.md +123 -0
- package/docs/services/database-service.md +65 -0
- package/docs/services/firestore-service.md +69 -0
- package/docs/services/messaging-service.md +87 -0
- package/docs/testing.md +67 -0
- package/index.html +60 -0
- package/package.json +4 -4
- package/dist/modules/admin/admin.service.spec.d.ts +0 -1
- package/dist/modules/admin/admin.service.spec.js +0 -228
- package/dist/modules/admin/database.service.spec.d.ts +0 -1
- package/dist/modules/admin/database.service.spec.js +0 -235
- package/dist/modules/admin/messaging.service.spec.d.ts +0 -1
- package/dist/modules/admin/messaging.service.spec.js +0 -148
- /package/dist/modules/admin/{admin.constants.d.ts → constants/admin.constants.d.ts} +0 -0
- /package/dist/modules/admin/{admin.constants.js → constants/admin.constants.js} +0 -0
- /package/dist/modules/admin/{messaging.service.d.ts → services/messaging.service.d.ts} +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Admin Service
|
|
2
|
+
|
|
3
|
+
The `AdminService` is the core service that manages the Firebase Admin SDK initialization and configuration. This service is automatically injected when you import the `AdminModule`.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Firebase Admin SDK initialization
|
|
8
|
+
- Multiple app instances support
|
|
9
|
+
- Credential management
|
|
10
|
+
- App lifecycle management
|
|
11
|
+
- TypeScript type support
|
|
12
|
+
|
|
13
|
+
## Usage Example
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Injectable } from '@nestjs/common';
|
|
17
|
+
import { AdminService } from 'nestjs-firebase-admin';
|
|
18
|
+
|
|
19
|
+
@Injectable()
|
|
20
|
+
export class FirebaseService {
|
|
21
|
+
constructor(private readonly adminService: AdminService) {}
|
|
22
|
+
|
|
23
|
+
// Get the default app instance
|
|
24
|
+
getApp() {
|
|
25
|
+
return this.adminService.getApp;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Get all initialized apps
|
|
29
|
+
getApps() {
|
|
30
|
+
return this.adminService.getApps;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Delete an app instance
|
|
34
|
+
async deleteApp(app) {
|
|
35
|
+
await this.adminService.deleteApp(app);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Get default credentials
|
|
39
|
+
getDefaultCredentials() {
|
|
40
|
+
return this.adminService.applicationDefault();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Get the Firebase Admin SDK instance
|
|
44
|
+
getAdmin() {
|
|
45
|
+
return this.adminService.admin();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Available Methods
|
|
51
|
+
|
|
52
|
+
| Method | Description | Documentation |
|
|
53
|
+
|--------|-------------|---------------|
|
|
54
|
+
| `getApp` | Gets the default Firebase app instance | [Get App](https://firebase.google.com/docs/reference/admin/node/firebase-admin.app#getapp) |
|
|
55
|
+
| `getApps` | Gets all initialized Firebase apps | [Get Apps](https://firebase.google.com/docs/reference/admin/node/firebase-admin.app#getapps) |
|
|
56
|
+
| `deleteApp(app)` | Deletes a Firebase app instance | [Delete App](https://firebase.google.com/docs/reference/admin/node/firebase-admin.app#deleteapp) |
|
|
57
|
+
| `applicationDefault(httpAgent?)` | Gets default credentials | [Application Default](https://firebase.google.com/docs/reference/admin/node/firebase-admin.credential#applicationdefault) |
|
|
58
|
+
| `admin()` | Gets the Firebase Admin SDK instance | [Admin SDK](https://firebase.google.com/docs/admin/setup) |
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
The service can be configured through the `AdminModule` using either synchronous or asynchronous registration:
|
|
63
|
+
|
|
64
|
+
### Synchronous Registration
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
AdminModule.register({
|
|
68
|
+
credential: {
|
|
69
|
+
projectId: 'my-project-id',
|
|
70
|
+
clientEmail: 'my-client-email',
|
|
71
|
+
privateKey: 'my-private-key',
|
|
72
|
+
},
|
|
73
|
+
databaseURL: 'https://my-project-id.firebaseio.com',
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Asynchronous Registration
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
AdminModule.registerAsync({
|
|
81
|
+
useFactory: async () => ({
|
|
82
|
+
credential: {
|
|
83
|
+
projectId: 'my-project-id',
|
|
84
|
+
clientEmail: 'my-client-email',
|
|
85
|
+
privateKey: 'my-private-key',
|
|
86
|
+
},
|
|
87
|
+
databaseURL: 'https://my-project-id.firebaseio.com',
|
|
88
|
+
}),
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## App Lifecycle
|
|
93
|
+
|
|
94
|
+
The service manages the lifecycle of Firebase app instances:
|
|
95
|
+
|
|
96
|
+
1. **Initialization**: Apps are initialized when the module is registered
|
|
97
|
+
2. **Access**: Apps can be accessed through `getApp` or `getApps`
|
|
98
|
+
3. **Cleanup**: Apps can be deleted using `deleteApp`
|
|
99
|
+
4. **Multiple Instances**: Multiple app instances can be managed simultaneously
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Auth Service
|
|
2
|
+
|
|
3
|
+
The `AuthService` provides a clean and type-safe interface for managing Firebase Authentication. This service is automatically injected when you import the `AdminModule`.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- User management (create, read, update, delete)
|
|
8
|
+
- Custom token generation
|
|
9
|
+
- ID token verification
|
|
10
|
+
- Custom claims management
|
|
11
|
+
- User listing and pagination
|
|
12
|
+
- Email and phone number authentication
|
|
13
|
+
- TypeScript type support
|
|
14
|
+
|
|
15
|
+
## Usage Example
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Injectable } from '@nestjs/common';
|
|
19
|
+
import { AuthService } from 'nestjs-firebase-admin';
|
|
20
|
+
|
|
21
|
+
@Injectable()
|
|
22
|
+
export class UsersService {
|
|
23
|
+
constructor(private readonly authService: AuthService) {}
|
|
24
|
+
|
|
25
|
+
// Create a new user
|
|
26
|
+
async createUser(email: string, password: string) {
|
|
27
|
+
return this.authService.createUser({
|
|
28
|
+
email,
|
|
29
|
+
password,
|
|
30
|
+
emailVerified: false,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Get user by UID
|
|
35
|
+
async getUser(uid: string) {
|
|
36
|
+
return this.authService.getUser(uid);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Update user profile
|
|
40
|
+
async updateProfile(uid: string, displayName: string, photoURL: string) {
|
|
41
|
+
return this.authService.updateUser(uid, {
|
|
42
|
+
displayName,
|
|
43
|
+
photoURL,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Set custom claims
|
|
48
|
+
async setUserRole(uid: string, role: string) {
|
|
49
|
+
return this.authService.setCustomUserClaims(uid, { role });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Verify ID token
|
|
53
|
+
async verifyToken(idToken: string) {
|
|
54
|
+
return this.authService.verifyIdToken(idToken);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// List users with pagination
|
|
58
|
+
async listUsers(pageSize: number = 100) {
|
|
59
|
+
return this.authService.listUsers(pageSize);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Available Methods
|
|
65
|
+
|
|
66
|
+
| Method | Description | Documentation |
|
|
67
|
+
|--------|-------------|---------------|
|
|
68
|
+
| `createUser(properties)` | Creates a new user | [Create User](https://firebase.google.com/docs/auth/admin/manage-users#create_a_user) |
|
|
69
|
+
| `getUser(uid)` | Gets a user by UID | [Get User](https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data) |
|
|
70
|
+
| `getUserByEmail(email)` | Gets a user by email | [Get User by Email](https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data) |
|
|
71
|
+
| `getUserByPhoneNumber(phoneNumber)` | Gets a user by phone number | [Get User by Phone](https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data) |
|
|
72
|
+
| `updateUser(uid, properties)` | Updates a user's properties | [Update User](https://firebase.google.com/docs/auth/admin/manage-users#update_a_user) |
|
|
73
|
+
| `deleteUser(uid)` | Deletes a user | [Delete User](https://firebase.google.com/docs/auth/admin/manage-users#delete_a_user) |
|
|
74
|
+
| `createCustomToken(uid, claims?)` | Creates a custom token | [Custom Tokens](https://firebase.google.com/docs/auth/admin/create-custom-tokens) |
|
|
75
|
+
| `verifyIdToken(idToken)` | Verifies an ID token | [Verify ID Token](https://firebase.google.com/docs/auth/admin/verify-id-tokens) |
|
|
76
|
+
| `setCustomUserClaims(uid, claims)` | Sets custom claims | [Custom Claims](https://firebase.google.com/docs/auth/admin/custom-claims) |
|
|
77
|
+
| `listUsers(maxResults?, pageToken?)` | Lists users with pagination | [List Users](https://firebase.google.com/docs/auth/admin/manage-users#list_all_users) |
|
|
78
|
+
|
|
79
|
+
## User Properties
|
|
80
|
+
|
|
81
|
+
When creating or updating a user, you can specify the following properties:
|
|
82
|
+
|
|
83
|
+
| Property | Type | Description |
|
|
84
|
+
|----------|------|-------------|
|
|
85
|
+
| `email` | string | The user's email address |
|
|
86
|
+
| `emailVerified` | boolean | Whether the email is verified |
|
|
87
|
+
| `phoneNumber` | string | The user's phone number |
|
|
88
|
+
| `password` | string | The user's password |
|
|
89
|
+
| `displayName` | string | The user's display name |
|
|
90
|
+
| `photoURL` | string | The user's profile photo URL |
|
|
91
|
+
| `disabled` | boolean | Whether the user account is disabled |
|
|
92
|
+
|
|
93
|
+
## Custom Claims
|
|
94
|
+
|
|
95
|
+
Custom claims can be used to define user roles and permissions. They are included in the ID token and can be accessed on the client side.
|
|
96
|
+
|
|
97
|
+
Example:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
// Set admin role
|
|
101
|
+
await authService.setCustomUserClaims(uid, { role: 'admin' });
|
|
102
|
+
|
|
103
|
+
// Set multiple roles
|
|
104
|
+
await authService.setCustomUserClaims(uid, {
|
|
105
|
+
roles: ['admin', 'editor'],
|
|
106
|
+
premium: true
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Token Verification
|
|
111
|
+
|
|
112
|
+
The service provides methods for token verification and custom token generation:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
// Verify ID token
|
|
116
|
+
const decodedToken = await authService.verifyIdToken(idToken);
|
|
117
|
+
console.log(decodedToken.uid);
|
|
118
|
+
|
|
119
|
+
// Create custom token
|
|
120
|
+
const customToken = await authService.createCustomToken(uid, {
|
|
121
|
+
role: 'admin'
|
|
122
|
+
});
|
|
123
|
+
```
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Database Service
|
|
2
|
+
|
|
3
|
+
The `DatabaseService` provides a clean and type-safe interface for interacting with the Firebase Realtime Database. This service is automatically injected when you import the `AdminModule`.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Full CRUD operations (Create, Read, Update, Delete)
|
|
8
|
+
- TypeScript type support
|
|
9
|
+
- Asynchronous methods with Promises
|
|
10
|
+
- Database reference handling
|
|
11
|
+
- List operations with unique keys
|
|
12
|
+
|
|
13
|
+
## Usage Example
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Injectable } from '@nestjs/common';
|
|
17
|
+
import { DatabaseService } from 'nestjs-firebase-admin';
|
|
18
|
+
|
|
19
|
+
@Injectable()
|
|
20
|
+
export class UsersService {
|
|
21
|
+
constructor(private readonly databaseService: DatabaseService) {}
|
|
22
|
+
|
|
23
|
+
// Get data from a path
|
|
24
|
+
async getUser(userId: string) {
|
|
25
|
+
return this.databaseService.get<User>(`users/${userId}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Set data at a path
|
|
29
|
+
async createUser(userId: string, userData: User) {
|
|
30
|
+
await this.databaseService.set(`users/${userId}`, userData);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Update specific fields
|
|
34
|
+
async updateUser(userId: string, updates: Partial<User>) {
|
|
35
|
+
await this.databaseService.update(`users/${userId}`, updates);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Remove data
|
|
39
|
+
async deleteUser(userId: string) {
|
|
40
|
+
await this.databaseService.remove(`users/${userId}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Add to a list
|
|
44
|
+
async addUser(userData: User) {
|
|
45
|
+
const newKey = await this.databaseService.push('users', userData);
|
|
46
|
+
return newKey;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Get a database reference
|
|
50
|
+
async getUsersRef() {
|
|
51
|
+
return this.databaseService.ref('users');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Available Methods
|
|
57
|
+
|
|
58
|
+
| Method | Description | Documentation |
|
|
59
|
+
|--------|-------------|---------------|
|
|
60
|
+
| `ref(path)` | Gets a reference to a specific path | [Firebase Ref](https://firebase.google.com/docs/database/admin/retrieve-data#section-queries) |
|
|
61
|
+
| `get<T>(path)` | Retrieves data from a specific path | [Read Data](https://firebase.google.com/docs/database/admin/retrieve-data#section-read-once) |
|
|
62
|
+
| `set<T>(path, data)` | Sets data at a specific path | [Set Data](https://firebase.google.com/docs/database/admin/save-data#section-set) |
|
|
63
|
+
| `update<T>(path, data)` | Updates specific fields at a path | [Update Data](https://firebase.google.com/docs/database/admin/save-data#section-update) |
|
|
64
|
+
| `remove(path)` | Removes data from a specific path | [Delete Data](https://firebase.google.com/docs/database/admin/save-data#section-delete) |
|
|
65
|
+
| `push<T>(path, data)` | Adds data to a list | [Push Data](https://firebase.google.com/docs/database/admin/save-data#section-push) |
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Firestore Service
|
|
2
|
+
|
|
3
|
+
The `FirestoreService` provides a clean and type-safe interface for interacting with Cloud Firestore. This service is automatically injected when you import the `AdminModule`.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Full CRUD operations (Create, Read, Update, Delete)
|
|
8
|
+
- TypeScript type support
|
|
9
|
+
- Collection and document management
|
|
10
|
+
- Query support
|
|
11
|
+
- Batch operations
|
|
12
|
+
- Transaction support
|
|
13
|
+
|
|
14
|
+
## Usage Example
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { Injectable } from '@nestjs/common';
|
|
18
|
+
import { FirestoreService } from 'nestjs-firebase-admin';
|
|
19
|
+
|
|
20
|
+
@Injectable()
|
|
21
|
+
export class UsersService {
|
|
22
|
+
constructor(private readonly firestoreService: FirestoreService) {}
|
|
23
|
+
|
|
24
|
+
// Get a document
|
|
25
|
+
async getUser(userId: string) {
|
|
26
|
+
return this.firestoreService.get<User>(`users/${userId}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Create or update a document
|
|
30
|
+
async createUser(userId: string, userData: User) {
|
|
31
|
+
await this.firestoreService.set(`users/${userId}`, userData);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Update specific fields
|
|
35
|
+
async updateUser(userId: string, updates: Partial<User>) {
|
|
36
|
+
await this.firestoreService.update(`users/${userId}`, updates);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Delete a document
|
|
40
|
+
async deleteUser(userId: string) {
|
|
41
|
+
await this.firestoreService.delete(`users/${userId}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Add a document with auto-generated ID
|
|
45
|
+
async addUser(userData: User) {
|
|
46
|
+
return this.firestoreService.add('users', userData);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Query documents
|
|
50
|
+
async getActiveUsers() {
|
|
51
|
+
return this.firestoreService.query<User>('users',
|
|
52
|
+
(q) => q.where('status', '==', 'active')
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Available Methods
|
|
59
|
+
|
|
60
|
+
| Method | Description | Documentation |
|
|
61
|
+
|--------|-------------|---------------|
|
|
62
|
+
| `collection<T>(path)` | Gets a reference to a collection | [Firestore Collections](https://firebase.google.com/docs/firestore/manage-data/structure-data) |
|
|
63
|
+
| `doc<T>(path)` | Gets a reference to a document | [Firestore Documents](https://firebase.google.com/docs/firestore/manage-data/structure-data) |
|
|
64
|
+
| `get<T>(path)` | Retrieves a document's data | [Read Data](https://firebase.google.com/docs/firestore/query-data/get-data) |
|
|
65
|
+
| `set<T>(path, data, options?)` | Sets a document's data | [Set Data](https://firebase.google.com/docs/firestore/manage-data/add-data) |
|
|
66
|
+
| `update<T>(path, data)` | Updates specific fields | [Update Data](https://firebase.google.com/docs/firestore/manage-data/add-data#update-data) |
|
|
67
|
+
| `delete(path)` | Deletes a document | [Delete Data](https://firebase.google.com/docs/firestore/manage-data/delete-data) |
|
|
68
|
+
| `add<T>(path, data)` | Adds a document with auto-generated ID | [Add Data](https://firebase.google.com/docs/firestore/manage-data/add-data) |
|
|
69
|
+
| `query<T>(path, ...constraints)` | Queries a collection | [Query Data](https://firebase.google.com/docs/firestore/query-data/queries) |
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Messaging Service
|
|
2
|
+
|
|
3
|
+
The `MessagingService` provides a clean and type-safe interface for sending messages through Firebase Cloud Messaging (FCM). This service is automatically injected when you import the `AdminModule`.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Send messages to individual devices
|
|
8
|
+
- Send multicast messages to multiple devices
|
|
9
|
+
- Topic messaging
|
|
10
|
+
- Conditional messaging
|
|
11
|
+
- Message customization
|
|
12
|
+
- TypeScript type support
|
|
13
|
+
|
|
14
|
+
## Usage Example
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { Injectable } from '@nestjs/common';
|
|
18
|
+
import { MessagingService } from 'nestjs-firebase-admin';
|
|
19
|
+
|
|
20
|
+
@Injectable()
|
|
21
|
+
export class NotificationService {
|
|
22
|
+
constructor(private readonly messagingService: MessagingService) {}
|
|
23
|
+
|
|
24
|
+
// Send a message to a single device
|
|
25
|
+
async sendToDevice(deviceToken: string, title: string, body: string) {
|
|
26
|
+
await this.messagingService.send({
|
|
27
|
+
token: deviceToken,
|
|
28
|
+
notification: {
|
|
29
|
+
title,
|
|
30
|
+
body,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Send a message to multiple devices
|
|
36
|
+
async sendToDevices(deviceTokens: string[], title: string, body: string) {
|
|
37
|
+
await this.messagingService.sendMulticast({
|
|
38
|
+
tokens: deviceTokens,
|
|
39
|
+
notification: {
|
|
40
|
+
title,
|
|
41
|
+
body,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Send a message to a topic
|
|
47
|
+
async sendToTopic(topic: string, title: string, body: string) {
|
|
48
|
+
await this.messagingService.send({
|
|
49
|
+
topic,
|
|
50
|
+
notification: {
|
|
51
|
+
title,
|
|
52
|
+
body,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Subscribe devices to a topic
|
|
58
|
+
async subscribeToTopic(topic: string, deviceTokens: string[]) {
|
|
59
|
+
await this.messagingService.subscribeToTopic(deviceTokens, topic);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Unsubscribe devices from a topic
|
|
63
|
+
async unsubscribeFromTopic(topic: string, deviceTokens: string[]) {
|
|
64
|
+
await this.messagingService.unsubscribeFromTopic(deviceTokens, topic);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Available Methods
|
|
70
|
+
|
|
71
|
+
| Method | Description | Documentation |
|
|
72
|
+
|--------|-------------|---------------|
|
|
73
|
+
| `send(message)` | Sends a message to a device or topic | [Send Messages](https://firebase.google.com/docs/cloud-messaging/send-message) |
|
|
74
|
+
| `sendMulticast(message)` | Sends a message to multiple devices | [Send Multicast](https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-multiple-devices) |
|
|
75
|
+
| `subscribeToTopic(tokens, topic)` | Subscribes devices to a topic | [Topic Management](https://firebase.google.com/docs/cloud-messaging/manage-topics) |
|
|
76
|
+
| `unsubscribeFromTopic(tokens, topic)` | Unsubscribes devices from a topic | [Topic Management](https://firebase.google.com/docs/cloud-messaging/manage-topics) |
|
|
77
|
+
|
|
78
|
+
## Message Types
|
|
79
|
+
|
|
80
|
+
The service supports various message types:
|
|
81
|
+
|
|
82
|
+
- **Notification Messages**: Simple messages with title and body
|
|
83
|
+
- **Data Messages**: Custom key-value pairs
|
|
84
|
+
- **Combined Messages**: Both notification and data
|
|
85
|
+
- **Android Messages**: Android-specific configurations
|
|
86
|
+
- **APNS Messages**: iOS-specific configurations
|
|
87
|
+
- **Webpush Messages**: Web-specific configurations
|
package/docs/testing.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Testing
|
|
2
|
+
|
|
3
|
+
This document provides instructions on how to run tests for the `nestjs-firebase-admin` project.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Ensure you have the following installed:
|
|
8
|
+
|
|
9
|
+
- **Node.js**: >= 20
|
|
10
|
+
- **NPM**: >= 10
|
|
11
|
+
|
|
12
|
+
Install the dependencies:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Running Tests
|
|
19
|
+
|
|
20
|
+
### Unit Tests
|
|
21
|
+
|
|
22
|
+
To run unit tests, use the following command:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm test
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Coverage Tests
|
|
29
|
+
|
|
30
|
+
To generate a code coverage report, run:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm run test:cov
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The coverage report will be available in the `coverage/` directory.
|
|
37
|
+
|
|
38
|
+
### Watch Mode Tests
|
|
39
|
+
|
|
40
|
+
To run tests in watch mode, use:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm run test:watch
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Debug Tests
|
|
47
|
+
|
|
48
|
+
To debug tests, use:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm run test:debug
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Testing Tools
|
|
55
|
+
|
|
56
|
+
This project uses the following tools for testing:
|
|
57
|
+
|
|
58
|
+
- **Jest**: A JavaScript testing framework.
|
|
59
|
+
- **@nestjs/testing**: Utilities for testing NestJS applications.
|
|
60
|
+
|
|
61
|
+
## Mocking
|
|
62
|
+
|
|
63
|
+
Mock implementations are provided for Firebase services to ensure tests do not make actual calls to Firebase. These mocks are located in the `lib/tests/mocks/` directory.
|
|
64
|
+
|
|
65
|
+
## Continuous Integration
|
|
66
|
+
|
|
67
|
+
Tests are automatically run in CI pipelines using GitHub Actions and CircleCI. Refer to the respective configuration files for more details.
|
package/index.html
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>NestJS Firebase Admin</title>
|
|
7
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
|
|
9
|
+
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
|
|
10
|
+
<link rel="icon" type="image/png"
|
|
11
|
+
href="https://raw.githubusercontent.com/hebertcisco/nestjs-firebase-admin/refs/heads/main/art/logo.png" />
|
|
12
|
+
<meta name="description"
|
|
13
|
+
content="NestJS Firebase Admin is a NestJS module that provides a simple and efficient way to integrate Firebase Admin SDK into your NestJS applications.">
|
|
14
|
+
<meta name="keywords" content="NestJS, Firebase, Admin SDK, Module, Integration">
|
|
15
|
+
<meta name="author" content="Hebert Cisco">
|
|
16
|
+
<meta name="theme-color" content="#1E2830">
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<div id="app"></div>
|
|
21
|
+
<script>
|
|
22
|
+
window.$docsify = {
|
|
23
|
+
name: 'NestJS Firebase Admin',
|
|
24
|
+
repo: 'hebertcisco/nestjs-firebase-admin',
|
|
25
|
+
subMaxLevel: 3,
|
|
26
|
+
loadSidebar: 'docs/_sidebar.md',
|
|
27
|
+
auto2top: true,
|
|
28
|
+
subMaxLevel: 3,
|
|
29
|
+
maxLevel: 3,
|
|
30
|
+
themeColor: '#1E2830',
|
|
31
|
+
noCompileLinks: ['benchmarks/.*'],
|
|
32
|
+
search: {
|
|
33
|
+
placeholder: 'Search documentation...',
|
|
34
|
+
maxAge: 86400000,
|
|
35
|
+
paths: 'auto',
|
|
36
|
+
placeholder: 'Search',
|
|
37
|
+
noData: 'No results found!',
|
|
38
|
+
depth: 6
|
|
39
|
+
},
|
|
40
|
+
pagination: {
|
|
41
|
+
previousText: 'Previous',
|
|
42
|
+
nextText: 'Next',
|
|
43
|
+
crossChapter: true,
|
|
44
|
+
crossChapterText: true
|
|
45
|
+
},
|
|
46
|
+
plugins: [
|
|
47
|
+
function (hook, vm) {
|
|
48
|
+
hook.beforeEach(function (content) {
|
|
49
|
+
return content + '\n\n---\n\nLast updated: {docsify-updated}';
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
</script>
|
|
55
|
+
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
|
|
56
|
+
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script>
|
|
57
|
+
<script src="//cdn.jsdelivr.net/npm/docsify-pagination/dist/docsify-pagination.min.js"></script>
|
|
58
|
+
</body>
|
|
59
|
+
|
|
60
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestjs-firebase-admin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "Firebase Admin SDK for Nestjs",
|
|
5
5
|
"author": "Hebert Cisco",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"postversion": "git push && git push --tags"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@nestjs/common": "10.
|
|
34
|
+
"@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.2.1 || ^10.2.1",
|
|
35
35
|
"@nestjs/core": "10.4.13",
|
|
36
|
-
"@nestjs/platform-express": "10.4.
|
|
36
|
+
"@nestjs/platform-express": "^10.4.17",
|
|
37
37
|
"firebase-admin": "12.7.0",
|
|
38
38
|
"nest-shared": "^5.0.6"
|
|
39
39
|
},
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"lint-staged": "15.2.10",
|
|
61
61
|
"prettier": "^3.4.2",
|
|
62
62
|
"reflect-metadata": "0.2.2",
|
|
63
|
-
"release-it": "
|
|
63
|
+
"release-it": "^19.0.2",
|
|
64
64
|
"rimraf": "5.0.10",
|
|
65
65
|
"rxjs": "7.8.1",
|
|
66
66
|
"supertest": "^7.1.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|