nestjs-firebase-admin 0.6.1 → 0.6.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-firebase-admin",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Firebase Admin SDK for Nestjs",
5
5
  "author": "hebertcisco <hebertcisco@outlook.com>",
6
6
  "license": "MIT",
@@ -22,9 +22,14 @@
22
22
  ],
23
23
  "main": "./dist/index.js",
24
24
  "types": "./dist/index.d.ts",
25
+ "files": [
26
+ "dist",
27
+ "LICENSE",
28
+ "README.md"
29
+ ],
25
30
  "scripts": {
26
31
  "start:debug": "nest start --debug --watch",
27
- "build": "npx tsc",
32
+ "build": "npx tsc -p tsconfig.build.json",
28
33
  "prebuild": "rimraf dist",
29
34
  "format": "npx prettier --write \"{lib,test}/**/*.ts\"",
30
35
  "lint": "npx eslint \"lib/**/*.ts\" --fix",
@@ -54,24 +59,24 @@
54
59
  },
55
60
  "devDependencies": {
56
61
  "@nestjs/testing": "^7.0.0 || ^8.0.0 || ^9.2.1 || ^10.2.1 || ^11.0.0",
57
- "@types/jest": "29.5.14",
58
- "@types/node": "20.17.9",
59
- "@types/supertest": "^2.0.16",
60
- "@typescript-eslint/eslint-plugin": "^8.56.1",
61
- "@typescript-eslint/parser": "^8.56.1",
62
- "eslint": "8.57.1",
63
- "eslint-config-prettier": "9.1.0",
64
- "eslint-plugin-import": "2.31.0",
65
- "eslint-plugin-jest": "^28.8.0",
66
- "eslint-plugin-prettier": "^5.2.1",
67
- "jest": "29.7.0",
68
- "prettier": "^3.4.2",
62
+ "@types/jest": "^29.5.14",
63
+ "@types/node": "^22.19.17",
64
+ "@types/supertest": "^7.2.0",
65
+ "@typescript-eslint/eslint-plugin": "^8.58.1",
66
+ "@typescript-eslint/parser": "^8.58.1",
67
+ "eslint": "^8.57.1",
68
+ "eslint-config-prettier": "^10.1.8",
69
+ "eslint-plugin-import": "^2.32.0",
70
+ "eslint-plugin-jest": "^28.14.0",
71
+ "eslint-plugin-prettier": "^5.5.5",
72
+ "jest": "^29.7.0",
73
+ "prettier": "^3.8.1",
69
74
  "reflect-metadata": "^0.2.2",
70
- "rimraf": "5.0.10",
71
- "rxjs": "7.8.1",
72
- "supertest": "^7.1.0",
73
- "ts-jest": "29.2.5",
74
- "typescript": "5.7.2"
75
+ "rimraf": "^5.0.10",
76
+ "rxjs": "^7.8.2",
77
+ "supertest": "^7.2.2",
78
+ "ts-jest": "^29.4.9",
79
+ "typescript": "^5.9.3"
75
80
  },
76
81
  "peerDependencies": {
77
82
  "@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.2.1 || ^10.2.1 || ^11.0.0",
@@ -1,28 +0,0 @@
1
- {
2
- "extends": ["@commitlint/config-angular"],
3
- "rules": {
4
- "subject-case": [
5
- 2,
6
- "always",
7
- ["sentence-case", "start-case", "pascal-case", "upper-case", "lower-case"]
8
- ],
9
- "type-enum": [
10
- 2,
11
- "always",
12
- [
13
- "build",
14
- "chore",
15
- "ci",
16
- "docs",
17
- "feat",
18
- "fix",
19
- "perf",
20
- "refactor",
21
- "revert",
22
- "style",
23
- "test",
24
- "sample"
25
- ]
26
- ]
27
- }
28
- }
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- src/**/*.test.ts
2
- src/**/files/**
3
- test/**
package/.eslintrc DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "root": true,
3
- "parser": "@typescript-eslint/parser",
4
- "plugins": [
5
- "@typescript-eslint",
6
- "jest"
7
- ],
8
- "extends": [
9
- "eslint:recommended",
10
- "plugin:@typescript-eslint/recommended",
11
- "plugin:jest/recommended"
12
- ],
13
- "rules": {
14
- "@typescript-eslint/no-explicit-any": "off",
15
- "@typescript-eslint/no-unused-vars": "off",
16
- "jest/no-export": "off",
17
- "jest/no-disabled-tests": "off",
18
- "jest/expect-expect": "off",
19
- "jest/valid-title": "off"
20
- }
21
- }
package/.gitpod.yml DELETED
@@ -1,10 +0,0 @@
1
- # This configuration file was automatically generated by Gitpod.
2
- # Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
3
- # and commit this file to your remote git repository to share the goodness with others.
4
-
5
- # Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart
6
-
7
- tasks:
8
- - init: npm install && npm run build
9
-
10
-
package/.nojekyll DELETED
File without changes
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- lts/jod
package/.release-it.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "git": {
3
- "commitMessage": "chore(): release v${version}"
4
- },
5
- "github": {
6
- "release": true
7
- }
8
- }
package/_coverpage.md DELETED
@@ -1,13 +0,0 @@
1
- ![logo](art/logo.png ':size=120')
2
-
3
- # nestjs-firebase-admin
4
-
5
- > Firebase Admin SDK module for NestJS
6
-
7
- - Injectable services for Auth, Firestore, Database, and Messaging
8
- - Sync and async module registration
9
- - TypeScript-first with full type support
10
- - Compatible with NestJS 7 through 11
11
-
12
- [Get Started](docs/getting-started.md)
13
- [GitHub](https://github.com/hebertcisco/nestjs-firebase-admin)
package/art/logo.png DELETED
Binary file
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- describe('AdminModuleOptionsFactory', () => {
13
- it('should define a method to create admin options', () => {
14
- class TestFactory {
15
- createAdminOptions() {
16
- return { credential: { projectId: 'test' } };
17
- }
18
- }
19
- const factory = new TestFactory();
20
- expect(factory.createAdminOptions()).toEqual({
21
- credential: { projectId: 'test' },
22
- });
23
- });
24
- });
25
- describe('AdminModuleAsyncOptions', () => {
26
- it('should allow useExisting, useClass, or useFactory for async options', () => {
27
- const asyncOptions = {
28
- useFactory: () => __awaiter(void 0, void 0, void 0, function* () { return ({ credential: { projectId: 'test' } }); }),
29
- inject: [],
30
- };
31
- expect(asyncOptions.useFactory).toBeDefined();
32
- expect(asyncOptions.inject).toEqual([]);
33
- });
34
- it('should support extraProviders', () => {
35
- const extraProvider = { provide: 'TEST', useValue: 'value' };
36
- const asyncOptions = {
37
- useFactory: () => __awaiter(void 0, void 0, void 0, function* () { return ({ credential: { projectId: 'test' } }); }),
38
- inject: [],
39
- extraProviders: [extraProvider],
40
- };
41
- expect(asyncOptions.extraProviders).toContain(extraProvider);
42
- });
43
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- describe('Admin Types', () => {
4
- it('should define AdminConfig with required and optional properties', () => {
5
- const config = {
6
- credential: {
7
- projectId: 'test-project',
8
- clientEmail: 'test@example.com',
9
- privateKey: 'test-key',
10
- },
11
- databaseURL: 'https://test.firebaseio.com',
12
- storageBucket: 'test-bucket',
13
- projectId: 'test-project-id',
14
- httpAgent: undefined,
15
- };
16
- expect(config.credential.projectId).toBe('test-project');
17
- expect(config.databaseURL).toBe('https://test.firebaseio.com');
18
- expect(config.storageBucket).toBe('test-bucket');
19
- expect(config.projectId).toBe('test-project-id');
20
- expect(config.httpAgent).toBeUndefined();
21
- });
22
- it('should define AdminModuleOptions as an alias for AdminConfig', () => {
23
- const options = {
24
- credential: {
25
- projectId: 'test-project',
26
- clientEmail: 'test@example.com',
27
- privateKey: 'test-key',
28
- },
29
- };
30
- expect(options.credential.projectId).toBe('test-project');
31
- expect(options.credential.clientEmail).toBe('test@example.com');
32
- expect(options.credential.privateKey).toBe('test-key');
33
- });
34
- });
package/docs/_sidebar.md DELETED
@@ -1,10 +0,0 @@
1
- * [Home](/)
2
- * [Getting Started](docs/getting-started.md)
3
- * Services
4
- * [Admin Service](docs/services/admin-service.md)
5
- * [Auth Service](docs/services/auth-service.md)
6
- * [Database Service](docs/services/database-service.md)
7
- * [Firestore Service](docs/services/firestore-service.md)
8
- * [Messaging Service](docs/services/messaging-service.md)
9
- * [Testing](docs/testing.md)
10
- * [Contributing](docs/contributing.md)
@@ -1,93 +0,0 @@
1
- # Getting Started
2
-
3
- ## Requirements
4
-
5
- - **Node.js**: >= 20
6
- - **NPM**: >= 10
7
- - **NestJS**: >= 7.0.0
8
-
9
- ## Installation
10
-
11
- Install the package using `yarn`, `npm`, or `pnpm`:
12
-
13
- ```bash
14
- # yarn
15
- yarn add nestjs-firebase-admin
16
- ```
17
-
18
- ```bash
19
- # npm
20
- npm i nestjs-firebase-admin --save
21
- ```
22
-
23
- ```bash
24
- # pnpm
25
- pnpm add nestjs-firebase-admin --save
26
- ```
27
-
28
- ## Basic Usage
29
-
30
- Here is an example of how to configure the `AdminModule` in NestJS:
31
-
32
- ```ts
33
- // common.module.ts
34
- import { Module } from '@nestjs/common';
35
- import { AdminModule } from 'nestjs-firebase-admin';
36
-
37
- @Module({
38
- imports: [
39
- AdminModule.register({
40
- credential: {
41
- projectId: 'my-project-id',
42
- clientEmail: 'my-client-email',
43
- privateKey: 'my-private-key',
44
- },
45
- databaseURL: 'https://my-project-id.firebaseio.com',
46
- }),
47
- ],
48
- })
49
- export class CommonModule {}
50
- ```
51
-
52
- ### Asynchronous Registration
53
-
54
- If you need asynchronous configuration, use the `registerAsync` method:
55
-
56
- ```ts
57
- import { Module } from '@nestjs/common';
58
- import { ConfigService } from '@nestjs/config';
59
- import { AdminModule } from 'nestjs-firebase-admin';
60
-
61
- @Module({
62
- imports: [
63
- AdminModule.registerAsync({
64
- inject: [ConfigService],
65
- useFactory: async (config: ConfigService) => ({
66
- credential: {
67
- projectId: config.get('FIREBASE_PROJECT_ID'),
68
- clientEmail: config.get('FIREBASE_CLIENT_EMAIL'),
69
- privateKey: config.get('FIREBASE_PRIVATE_KEY'),
70
- },
71
- databaseURL: config.get('FIREBASE_DATABASE_URL'),
72
- }),
73
- }),
74
- ],
75
- })
76
- export class AppModule {}
77
- ```
78
-
79
- You can also use `useClass` or `useExisting` for more advanced scenarios:
80
-
81
- ```ts
82
- AdminModule.registerAsync({
83
- useClass: FirebaseConfigService,
84
- })
85
- ```
86
-
87
- ## Next Steps
88
-
89
- - Learn about the [Admin Service](services/admin-service.md)
90
- - Manage users with the [Auth Service](services/auth-service.md)
91
- - Explore the [Database Service](services/database-service.md)
92
- - Check out the [Firestore Service](services/firestore-service.md)
93
- - Discover the [Messaging Service](services/messaging-service.md)
@@ -1,102 +0,0 @@
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
- | `appRef` | Gets the initialized app instance reference | [Initialize App](https://firebase.google.com/docs/reference/admin/node/firebase-admin.app#initializeapp) |
60
- | `initializeApp()` | Returns the initialized app instance | [Initialize App](https://firebase.google.com/docs/reference/admin/node/firebase-admin.app#initializeapp) |
61
- | `initializeAppObservable()` | Creates an Observable that emits the app instance | [Initialize App](https://firebase.google.com/docs/reference/admin/node/firebase-admin.app#initializeapp) |
62
-
63
- ## Configuration
64
-
65
- The service can be configured through the `AdminModule` using either synchronous or asynchronous registration:
66
-
67
- ### Synchronous Registration
68
-
69
- ```ts
70
- AdminModule.register({
71
- credential: {
72
- projectId: 'my-project-id',
73
- clientEmail: 'my-client-email',
74
- privateKey: 'my-private-key',
75
- },
76
- databaseURL: 'https://my-project-id.firebaseio.com',
77
- })
78
- ```
79
-
80
- ### Asynchronous Registration
81
-
82
- ```ts
83
- AdminModule.registerAsync({
84
- useFactory: async () => ({
85
- credential: {
86
- projectId: 'my-project-id',
87
- clientEmail: 'my-client-email',
88
- privateKey: 'my-private-key',
89
- },
90
- databaseURL: 'https://my-project-id.firebaseio.com',
91
- }),
92
- })
93
- ```
94
-
95
- ## App Lifecycle
96
-
97
- The service manages the lifecycle of Firebase app instances:
98
-
99
- 1. **Initialization**: Apps are initialized when the module is registered
100
- 2. **Access**: Apps can be accessed through `getApp` or `getApps`
101
- 3. **Cleanup**: Apps can be deleted using `deleteApp`
102
- 4. **Multiple Instances**: Multiple app instances can be managed simultaneously
@@ -1,123 +0,0 @@
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
- ```
@@ -1,65 +0,0 @@
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) |
@@ -1,69 +0,0 @@
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) |
@@ -1,84 +0,0 @@
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 messages to multiple devices
9
- - Topic messaging and subscription management
10
- - Message customization per platform (Android, iOS, Web)
11
- - TypeScript type support
12
-
13
- ## Usage Example
14
-
15
- ```ts
16
- import { Injectable } from '@nestjs/common';
17
- import { MessagingService } from 'nestjs-firebase-admin';
18
-
19
- @Injectable()
20
- export class NotificationService {
21
- constructor(private readonly messagingService: MessagingService) {}
22
-
23
- // Send a message to a single device
24
- async sendToDevice(deviceToken: string, title: string, body: string) {
25
- return this.messagingService.sendToDevice(deviceToken, {
26
- notification: {
27
- title,
28
- body,
29
- },
30
- });
31
- }
32
-
33
- // Send a message to multiple devices
34
- async sendToDevices(deviceTokens: string[], title: string, body: string) {
35
- return this.messagingService.sendToDevices(deviceTokens, {
36
- notification: {
37
- title,
38
- body,
39
- },
40
- });
41
- }
42
-
43
- // Send a message to a topic
44
- async sendToTopic(topic: string, title: string, body: string) {
45
- return this.messagingService.sendToTopic(topic, {
46
- notification: {
47
- title,
48
- body,
49
- },
50
- });
51
- }
52
-
53
- // Subscribe devices to a topic
54
- async subscribeToTopic(topic: string, deviceTokens: string[]) {
55
- return this.messagingService.subscribeToTopic(deviceTokens, topic);
56
- }
57
-
58
- // Unsubscribe devices from a topic
59
- async unsubscribeFromTopic(topic: string, deviceTokens: string[]) {
60
- return this.messagingService.unsubscribeFromTopic(deviceTokens, topic);
61
- }
62
- }
63
- ```
64
-
65
- ## Available Methods
66
-
67
- | Method | Description | Documentation |
68
- |--------|-------------|---------------|
69
- | `sendToDevice(token, payload)` | Sends a message to a single device | [Send Messages](https://firebase.google.com/docs/cloud-messaging/send-message) |
70
- | `sendToDevices(tokens, payload)` | Sends a message to multiple devices | [Send Multicast](https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-multiple-devices) |
71
- | `sendToTopic(topic, payload)` | Sends a message to a topic | [Topic Messaging](https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-topics) |
72
- | `subscribeToTopic(tokens, topic)` | Subscribes devices to a topic | [Topic Management](https://firebase.google.com/docs/cloud-messaging/manage-topics) |
73
- | `unsubscribeFromTopic(tokens, topic)` | Unsubscribes devices from a topic | [Topic Management](https://firebase.google.com/docs/cloud-messaging/manage-topics) |
74
-
75
- ## Message Types
76
-
77
- The service supports various message types:
78
-
79
- - **Notification Messages**: Simple messages with title and body
80
- - **Data Messages**: Custom key-value pairs
81
- - **Combined Messages**: Both notification and data
82
- - **Android Messages**: Android-specific configurations (priority, TTL, channel)
83
- - **APNS Messages**: iOS-specific configurations (sound, badge, alert)
84
- - **Webpush Messages**: Web-specific configurations (headers, icons, actions)
package/docs/testing.md DELETED
@@ -1,67 +0,0 @@
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. Refer to the respective configuration files for more details.
package/index.html DELETED
@@ -1,107 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8">
6
- <title>NestJS Firebase Admin — Firebase Admin SDK module for NestJS</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
-
10
- <!-- SEO -->
11
- <meta name="description"
12
- content="NestJS Firebase Admin is a NestJS module that wraps the Firebase Admin SDK, providing injectable services for Auth, Firestore, Realtime Database, and Cloud Messaging in your NestJS applications.">
13
- <meta name="keywords"
14
- content="NestJS, Firebase, Admin SDK, NestJS module, Firebase Auth, Firestore, Realtime Database, Cloud Messaging, FCM, TypeScript, Node.js, serverless, backend, nestjs-firebase-admin">
15
- <meta name="author" content="Hebert Cisco">
16
- <meta name="robots" content="index, follow">
17
- <link rel="canonical" href="https://hebertcisco.github.io/nestjs-firebase-admin/" />
18
-
19
- <!-- Open Graph -->
20
- <meta property="og:type" content="website" />
21
- <meta property="og:title" content="NestJS Firebase Admin — Firebase Admin SDK module for NestJS" />
22
- <meta property="og:description"
23
- content="Injectable NestJS services for Firebase Auth, Firestore, Realtime Database, and Cloud Messaging. TypeScript-first with sync and async module registration." />
24
- <meta property="og:url" content="https://hebertcisco.github.io/nestjs-firebase-admin/" />
25
- <meta property="og:image"
26
- content="https://raw.githubusercontent.com/hebertcisco/nestjs-firebase-admin/refs/heads/main/art/logo.png" />
27
- <meta property="og:site_name" content="nestjs-firebase-admin" />
28
-
29
- <!-- Twitter Card -->
30
- <meta name="twitter:card" content="summary" />
31
- <meta name="twitter:title" content="NestJS Firebase Admin — Firebase Admin SDK module for NestJS" />
32
- <meta name="twitter:description"
33
- content="Injectable NestJS services for Firebase Auth, Firestore, Realtime Database, and Cloud Messaging." />
34
- <meta name="twitter:image"
35
- content="https://raw.githubusercontent.com/hebertcisco/nestjs-firebase-admin/refs/heads/main/art/logo.png" />
36
-
37
- <!-- Theme -->
38
- <meta name="theme-color" content="#1E2830">
39
- <link rel="icon" type="image/png"
40
- href="https://raw.githubusercontent.com/hebertcisco/nestjs-firebase-admin/refs/heads/main/art/logo.png" />
41
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
42
-
43
- <!-- Structured Data (JSON-LD) -->
44
- <script type="application/ld+json">
45
- {
46
- "@context": "https://schema.org",
47
- "@type": "SoftwareSourceCode",
48
- "name": "nestjs-firebase-admin",
49
- "description": "NestJS module that wraps the Firebase Admin SDK, providing injectable services for Auth, Firestore, Realtime Database, and Cloud Messaging.",
50
- "url": "https://hebertcisco.github.io/nestjs-firebase-admin/",
51
- "codeRepository": "https://github.com/hebertcisco/nestjs-firebase-admin",
52
- "programmingLanguage": "TypeScript",
53
- "runtimePlatform": "Node.js",
54
- "license": "https://opensource.org/licenses/MIT",
55
- "author": {
56
- "@type": "Person",
57
- "name": "Hebert Cisco",
58
- "url": "https://github.com/hebertcisco"
59
- },
60
- "keywords": ["NestJS", "Firebase", "Admin SDK", "Firestore", "Auth", "Cloud Messaging", "TypeScript"]
61
- }
62
- </script>
63
- </head>
64
-
65
- <body>
66
- <div id="app"></div>
67
- <script>
68
- window.$docsify = {
69
- name: 'NestJS Firebase Admin',
70
- nameLink: '/',
71
- repo: 'hebertcisco/nestjs-firebase-admin',
72
- coverpage: '_coverpage.md',
73
- loadSidebar: 'docs/_sidebar.md',
74
- auto2top: true,
75
- subMaxLevel: 3,
76
- maxLevel: 3,
77
- themeColor: '#1E2830',
78
- noCompileLinks: ['benchmarks/.*'],
79
- externalLinkTarget: '_blank',
80
- search: {
81
- placeholder: 'Search documentation...',
82
- maxAge: 86400000,
83
- paths: 'auto',
84
- noData: 'No results found!',
85
- depth: 6
86
- },
87
- pagination: {
88
- previousText: 'Previous',
89
- nextText: 'Next',
90
- crossChapter: true,
91
- crossChapterText: true
92
- },
93
- plugins: [
94
- function (hook, vm) {
95
- hook.beforeEach(function (content) {
96
- return content + '\n\n---\n\nLast updated: {docsify-updated}';
97
- });
98
- }
99
- ]
100
- }
101
- </script>
102
- <script src="https://cdn.jsdelivr.net/npm/docsify@4"></script>
103
- <script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script>
104
- <script src="https://cdn.jsdelivr.net/npm/docsify-pagination/dist/docsify-pagination.min.js"></script>
105
- </body>
106
-
107
- </html>
package/llms.txt DELETED
@@ -1,68 +0,0 @@
1
- # nestjs-firebase-admin
2
-
3
- > Firebase Admin SDK module for NestJS
4
-
5
- nestjs-firebase-admin is a NestJS module that wraps the Firebase Admin SDK into injectable, testable services. It supports NestJS 7-11 and Firebase Admin 13+.
6
-
7
- ## Install
8
-
9
- ```bash
10
- npm i nestjs-firebase-admin --save
11
- ```
12
-
13
- ## Quick start
14
-
15
- ```ts
16
- import { Module } from '@nestjs/common';
17
- import { AdminModule } from 'nestjs-firebase-admin';
18
-
19
- @Module({
20
- imports: [
21
- AdminModule.register({
22
- credential: {
23
- projectId: 'my-project-id',
24
- clientEmail: 'my-client-email',
25
- privateKey: 'my-private-key',
26
- },
27
- databaseURL: 'https://my-project-id.firebaseio.com',
28
- }),
29
- ],
30
- })
31
- export class AppModule {}
32
- ```
33
-
34
- Use `AdminModule.registerAsync()` with `useFactory`, `useClass`, or `useExisting` for dynamic configuration (e.g. from `ConfigService`).
35
-
36
- ## Services
37
-
38
- After importing `AdminModule`, inject any of these services:
39
-
40
- - **AdminService** — Firebase app initialization, lifecycle management, credential access.
41
- - **AuthService** — User management: create, update, delete, verify ID tokens, manage custom claims.
42
- - **DatabaseService** — Firebase Realtime Database: read, write, push, update, remove, and listen to refs.
43
- - **FirestoreService** — Cloud Firestore: typed CRUD, collection queries, batch writes, transactions.
44
- - **MessagingService** — Firebase Cloud Messaging: send to device tokens, topics, conditions; manage topic subscriptions.
45
-
46
- ## Requirements
47
-
48
- - Node.js >= 20
49
- - NestJS >= 7.0.0
50
- - firebase-admin >= 13.0.0
51
-
52
- ## Links
53
-
54
- - Docs: https://hebertcisco.github.io/nestjs-firebase-admin/
55
- - Repository: https://github.com/hebertcisco/nestjs-firebase-admin
56
- - npm: https://www.npmjs.com/package/nestjs-firebase-admin
57
- - Issues: https://github.com/hebertcisco/nestjs-firebase-admin/issues
58
-
59
- ## Detailed docs
60
-
61
- - [Getting started](https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/getting-started)
62
- - [Admin Service](https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/services/admin-service)
63
- - [Auth Service](https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/services/auth-service)
64
- - [Database Service](https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/services/database-service)
65
- - [Firestore Service](https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/services/firestore-service)
66
- - [Messaging Service](https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/services/messaging-service)
67
- - [Testing](https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/testing)
68
- - [Contributing](https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/contributing)
package/robots.txt DELETED
@@ -1,4 +0,0 @@
1
- User-agent: *
2
- Allow: /
3
-
4
- Sitemap: https://hebertcisco.github.io/nestjs-firebase-admin/sitemap.xml
package/sitemap.xml DELETED
@@ -1,48 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
- <url>
4
- <loc>https://hebertcisco.github.io/nestjs-firebase-admin/</loc>
5
- <changefreq>weekly</changefreq>
6
- <priority>1.0</priority>
7
- </url>
8
- <url>
9
- <loc>https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/getting-started</loc>
10
- <changefreq>weekly</changefreq>
11
- <priority>0.9</priority>
12
- </url>
13
- <url>
14
- <loc>https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/services/admin-service</loc>
15
- <changefreq>monthly</changefreq>
16
- <priority>0.8</priority>
17
- </url>
18
- <url>
19
- <loc>https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/services/auth-service</loc>
20
- <changefreq>monthly</changefreq>
21
- <priority>0.8</priority>
22
- </url>
23
- <url>
24
- <loc>https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/services/database-service</loc>
25
- <changefreq>monthly</changefreq>
26
- <priority>0.8</priority>
27
- </url>
28
- <url>
29
- <loc>https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/services/firestore-service</loc>
30
- <changefreq>monthly</changefreq>
31
- <priority>0.8</priority>
32
- </url>
33
- <url>
34
- <loc>https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/services/messaging-service</loc>
35
- <changefreq>monthly</changefreq>
36
- <priority>0.8</priority>
37
- </url>
38
- <url>
39
- <loc>https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/testing</loc>
40
- <changefreq>monthly</changefreq>
41
- <priority>0.6</priority>
42
- </url>
43
- <url>
44
- <loc>https://hebertcisco.github.io/nestjs-firebase-admin/#/docs/contributing</loc>
45
- <changefreq>monthly</changefreq>
46
- <priority>0.5</priority>
47
- </url>
48
- </urlset>
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["node_modules", "__tests__", "dist", "**/*spec.ts"]
4
- }