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
package/README.md
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="art/logo.png" alt="nestjs-firebase-admin logo" width="200">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://codecov.io/gh/hebertcisco/nestjs-firebase-admin">
|
|
7
|
+
<img src="https://codecov.io/gh/hebertcisco/nestjs-firebase-admin/branch/main/graph/badge.svg?token=N0IW1UNNIP" alt="codecov">
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://dl.circleci.com/status-badge/redirect/gh/hebertcisco/nestjs-firebase-admin/tree/main">
|
|
10
|
+
<img src="https://dl.circleci.com/status-badge/img/gh/hebertcisco/nestjs-firebase-admin/tree/main.svg?style=svg" alt="CircleCI">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://github.com/hebertcisco/nestjs-firebase-admin/actions/workflows/npm-publish.yml">
|
|
13
|
+
<img src="https://github.com/hebertcisco/nestjs-firebase-admin/actions/workflows/npm-publish.yml/badge.svg" alt="Node.js build and publish package">
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://github.com/hebertcisco/nestjs-firebase-admin/actions/workflows/coverage.yml">
|
|
16
|
+
<img src="https://github.com/hebertcisco/nestjs-firebase-admin/actions/workflows/coverage.yml/badge.svg" alt="Running Code Coverage">
|
|
17
|
+
</a>
|
|
18
|
+
<img src="https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white" alt="TypeScript">
|
|
19
|
+
<img src="https://img.shields.io/badge/Nestjs-ea2845?style=flat&logo=nestjs&logoColor=white" alt="Nestjs">
|
|
20
|
+
<img src="https://img.shields.io/badge/VS_Code-0078D4?style=flat&logo=visual%20studio%20code&logoColor=white" alt="VS Code">
|
|
21
|
+
<img src="https://img.shields.io/badge/github%20actions-%232671E5.svg?style=flat&logo=githubactions&logoColor=white" alt="GitHub Actions">
|
|
22
|
+
</p>
|
|
13
23
|
|
|
14
24
|
> Firebase Admin SDK for NestJS :fire:
|
|
15
25
|
|
|
@@ -38,121 +48,6 @@ npm i nestjs-firebase-admin --save
|
|
|
38
48
|
pnpm add nestjs-firebase-admin --save
|
|
39
49
|
```
|
|
40
50
|
|
|
41
|
-
## Usage Example
|
|
42
|
-
|
|
43
|
-
Here is an example of how to configure the `AdminModule` in NestJS:
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
// common.module.ts
|
|
47
|
-
import { Module } from '@nestjs/common';
|
|
48
|
-
import { AdminModule } from 'nestjs-firebase-admin';
|
|
49
|
-
|
|
50
|
-
@Module({
|
|
51
|
-
imports: [
|
|
52
|
-
AdminModule.register({
|
|
53
|
-
credential: {
|
|
54
|
-
projectId: 'my-project-id',
|
|
55
|
-
clientEmail: 'my-client-email',
|
|
56
|
-
privateKey: 'my-private-key',
|
|
57
|
-
},
|
|
58
|
-
databaseURL: 'https://my-project-id.firebaseio.com',
|
|
59
|
-
}),
|
|
60
|
-
],
|
|
61
|
-
})
|
|
62
|
-
export class CommonModule {}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Asynchronous Registration
|
|
66
|
-
|
|
67
|
-
If you need asynchronous configuration, use the `registerAsync` method:
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import { Module } from '@nestjs/common';
|
|
71
|
-
import { AdminModule } from 'nestjs-firebase-admin';
|
|
72
|
-
|
|
73
|
-
@Module({
|
|
74
|
-
imports: [
|
|
75
|
-
AdminModule.registerAsync({
|
|
76
|
-
useFactory: async () => ({
|
|
77
|
-
credential: {
|
|
78
|
-
projectId: 'my-project-id',
|
|
79
|
-
clientEmail: 'my-client-email',
|
|
80
|
-
privateKey: 'my-private-key',
|
|
81
|
-
},
|
|
82
|
-
databaseURL: 'https://my-project-id.firebaseio.com',
|
|
83
|
-
}),
|
|
84
|
-
}),
|
|
85
|
-
],
|
|
86
|
-
})
|
|
87
|
-
export class AppModule {}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## DatabaseService
|
|
91
|
-
|
|
92
|
-
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`.
|
|
93
|
-
|
|
94
|
-
### Features
|
|
95
|
-
|
|
96
|
-
- Full CRUD operations (Create, Read, Update, Delete)
|
|
97
|
-
- TypeScript type support
|
|
98
|
-
- Asynchronous methods with Promises
|
|
99
|
-
- Database reference handling
|
|
100
|
-
- List operations with unique keys
|
|
101
|
-
|
|
102
|
-
### Usage Example
|
|
103
|
-
|
|
104
|
-
```ts
|
|
105
|
-
import { Injectable } from '@nestjs/common';
|
|
106
|
-
import { DatabaseService } from 'nestjs-firebase-admin';
|
|
107
|
-
|
|
108
|
-
@Injectable()
|
|
109
|
-
export class UsersService {
|
|
110
|
-
constructor(private readonly databaseService: DatabaseService) {}
|
|
111
|
-
|
|
112
|
-
// Get data from a path
|
|
113
|
-
async getUser(userId: string) {
|
|
114
|
-
return this.databaseService.get<User>(`users/${userId}`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Set data at a path
|
|
118
|
-
async createUser(userId: string, userData: User) {
|
|
119
|
-
await this.databaseService.set(`users/${userId}`, userData);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Update specific fields
|
|
123
|
-
async updateUser(userId: string, updates: Partial<User>) {
|
|
124
|
-
await this.databaseService.update(`users/${userId}`, updates);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Remove data
|
|
128
|
-
async deleteUser(userId: string) {
|
|
129
|
-
await this.databaseService.remove(`users/${userId}`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Add to a list
|
|
133
|
-
async addUser(userData: User) {
|
|
134
|
-
const newKey = await this.databaseService.push('users', userData);
|
|
135
|
-
return newKey;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Get a database reference
|
|
139
|
-
async getUsersRef() {
|
|
140
|
-
return this.databaseService.ref('users');
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### Available Methods
|
|
146
|
-
|
|
147
|
-
| Method | Description | Documentation |
|
|
148
|
-
|--------|-------------|---------------|
|
|
149
|
-
| `ref(path)` | Gets a reference to a specific path | [Firebase Ref](https://firebase.google.com/docs/database/admin/retrieve-data#section-queries) |
|
|
150
|
-
| `get<T>(path)` | Retrieves data from a specific path | [Read Data](https://firebase.google.com/docs/database/admin/retrieve-data#section-read-once) |
|
|
151
|
-
| `set<T>(path, data)` | Sets data at a specific path | [Set Data](https://firebase.google.com/docs/database/admin/save-data#section-set) |
|
|
152
|
-
| `update<T>(path, data)` | Updates specific fields at a path | [Update Data](https://firebase.google.com/docs/database/admin/save-data#section-update) |
|
|
153
|
-
| `remove(path)` | Removes data from a specific path | [Delete Data](https://firebase.google.com/docs/database/admin/save-data#section-delete) |
|
|
154
|
-
| `push<T>(path, data)` | Adds data to a list | [Push Data](https://firebase.google.com/docs/database/admin/save-data#section-push) |
|
|
155
|
-
|
|
156
51
|
## Testing
|
|
157
52
|
|
|
158
53
|
To run tests, use the following commands:
|
package/art/logo.png
ADDED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './modules/admin/admin.module';
|
|
2
|
-
export * from './modules/admin/admin.service';
|
|
3
|
-
export * from './modules/admin/database.service';
|
|
4
|
-
export * from './modules/admin/messaging.service';
|
|
2
|
+
export * from './modules/admin/services/admin.service';
|
|
3
|
+
export * from './modules/admin/services/database.service';
|
|
4
|
+
export * from './modules/admin/services/messaging.service';
|
|
5
|
+
export * from './modules/admin/services/firestore.service';
|
|
5
6
|
export * from './modules/admin/interfaces';
|
|
6
7
|
export * from './modules/admin/types';
|
package/dist/index.js
CHANGED
|
@@ -15,8 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./modules/admin/admin.module"), exports);
|
|
18
|
-
__exportStar(require("./modules/admin/admin.service"), exports);
|
|
19
|
-
__exportStar(require("./modules/admin/database.service"), exports);
|
|
20
|
-
__exportStar(require("./modules/admin/messaging.service"), exports);
|
|
18
|
+
__exportStar(require("./modules/admin/services/admin.service"), exports);
|
|
19
|
+
__exportStar(require("./modules/admin/services/database.service"), exports);
|
|
20
|
+
__exportStar(require("./modules/admin/services/messaging.service"), exports);
|
|
21
|
+
__exportStar(require("./modules/admin/services/firestore.service"), exports);
|
|
21
22
|
__exportStar(require("./modules/admin/interfaces"), exports);
|
|
22
23
|
__exportStar(require("./modules/admin/types"), exports);
|
|
@@ -23,19 +23,27 @@ exports.AdminModule = void 0;
|
|
|
23
23
|
const common_1 = require("@nestjs/common");
|
|
24
24
|
const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
|
|
25
25
|
const firebase_admin_1 = __importDefault(require("firebase-admin"));
|
|
26
|
-
const admin_constants_1 = require("./admin.constants");
|
|
27
|
-
const admin_service_1 = require("./admin.service");
|
|
28
|
-
const database_service_1 = require("./database.service");
|
|
29
|
-
const messaging_service_1 = require("./messaging.service");
|
|
26
|
+
const admin_constants_1 = require("./constants/admin.constants");
|
|
27
|
+
const admin_service_1 = require("./services/admin.service");
|
|
28
|
+
const database_service_1 = require("./services/database.service");
|
|
29
|
+
const messaging_service_1 = require("./services/messaging.service");
|
|
30
|
+
const firestore_service_1 = require("./services/firestore.service");
|
|
31
|
+
const auth_service_1 = require("./services/auth.service");
|
|
30
32
|
let AdminModule = AdminModule_1 = class AdminModule {
|
|
31
33
|
static register(options) {
|
|
32
34
|
const firebaseApp = firebase_admin_1.default.initializeApp(Object.assign(Object.assign({}, options), { credential: firebase_admin_1.default.credential.cert(options.credential) }));
|
|
33
35
|
return {
|
|
34
36
|
module: AdminModule_1,
|
|
35
37
|
providers: [
|
|
38
|
+
{
|
|
39
|
+
provide: admin_constants_1.ADMIN_MODULE_OPTIONS,
|
|
40
|
+
useValue: options,
|
|
41
|
+
},
|
|
36
42
|
admin_service_1.AdminService,
|
|
37
43
|
database_service_1.DatabaseService,
|
|
38
44
|
messaging_service_1.MessagingService,
|
|
45
|
+
firestore_service_1.FirestoreService,
|
|
46
|
+
auth_service_1.AuthService,
|
|
39
47
|
{
|
|
40
48
|
provide: admin_constants_1.FIREBASE_ADMIN_INSTANCE_TOKEN,
|
|
41
49
|
useValue: options,
|
|
@@ -53,16 +61,28 @@ let AdminModule = AdminModule_1 = class AdminModule {
|
|
|
53
61
|
admin_service_1.AdminService,
|
|
54
62
|
database_service_1.DatabaseService,
|
|
55
63
|
messaging_service_1.MessagingService,
|
|
64
|
+
firestore_service_1.FirestoreService,
|
|
65
|
+
auth_service_1.AuthService,
|
|
56
66
|
admin_constants_1.FIREBASE_ADMIN_INSTANCE_TOKEN,
|
|
57
67
|
admin_constants_1.FIREBASE_ADMIN_APP,
|
|
58
68
|
],
|
|
59
69
|
};
|
|
60
70
|
}
|
|
61
71
|
static registerAsync(options) {
|
|
72
|
+
if (!options.useFactory) {
|
|
73
|
+
throw new Error('useFactory is required in registerAsync options');
|
|
74
|
+
}
|
|
62
75
|
const providers = [
|
|
76
|
+
{
|
|
77
|
+
provide: admin_constants_1.ADMIN_MODULE_OPTIONS,
|
|
78
|
+
useFactory: options.useFactory,
|
|
79
|
+
inject: options.inject || [],
|
|
80
|
+
},
|
|
63
81
|
admin_service_1.AdminService,
|
|
64
82
|
database_service_1.DatabaseService,
|
|
65
83
|
messaging_service_1.MessagingService,
|
|
84
|
+
firestore_service_1.FirestoreService,
|
|
85
|
+
auth_service_1.AuthService,
|
|
66
86
|
{
|
|
67
87
|
provide: admin_constants_1.ADMIN_MODULE_ID,
|
|
68
88
|
useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
|
|
@@ -129,12 +149,14 @@ let AdminModule = AdminModule_1 = class AdminModule {
|
|
|
129
149
|
}
|
|
130
150
|
return {
|
|
131
151
|
module: AdminModule_1,
|
|
132
|
-
imports: options.imports,
|
|
152
|
+
imports: options.imports || [],
|
|
133
153
|
providers,
|
|
134
154
|
exports: [
|
|
135
155
|
admin_service_1.AdminService,
|
|
136
156
|
database_service_1.DatabaseService,
|
|
137
157
|
messaging_service_1.MessagingService,
|
|
158
|
+
firestore_service_1.FirestoreService,
|
|
159
|
+
auth_service_1.AuthService,
|
|
138
160
|
admin_constants_1.FIREBASE_ADMIN_INSTANCE_TOKEN,
|
|
139
161
|
admin_constants_1.FIREBASE_ADMIN_APP,
|
|
140
162
|
],
|
|
@@ -148,11 +170,19 @@ exports.AdminModule = AdminModule = AdminModule_1 = __decorate([
|
|
|
148
170
|
admin_service_1.AdminService,
|
|
149
171
|
database_service_1.DatabaseService,
|
|
150
172
|
messaging_service_1.MessagingService,
|
|
173
|
+
firestore_service_1.FirestoreService,
|
|
174
|
+
auth_service_1.AuthService,
|
|
151
175
|
{
|
|
152
176
|
provide: admin_constants_1.ADMIN_MODULE_ID,
|
|
153
177
|
useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
|
|
154
178
|
},
|
|
155
179
|
],
|
|
156
|
-
exports: [
|
|
180
|
+
exports: [
|
|
181
|
+
admin_service_1.AdminService,
|
|
182
|
+
database_service_1.DatabaseService,
|
|
183
|
+
messaging_service_1.MessagingService,
|
|
184
|
+
firestore_service_1.FirestoreService,
|
|
185
|
+
auth_service_1.AuthService,
|
|
186
|
+
],
|
|
157
187
|
})
|
|
158
188
|
], AdminModule);
|
|
@@ -2,7 +2,7 @@ import { Observable } from 'rxjs';
|
|
|
2
2
|
import Admin from 'firebase-admin';
|
|
3
3
|
import type { App } from 'firebase-admin/app';
|
|
4
4
|
import type { Agent } from 'node:http';
|
|
5
|
-
import type { AdminModuleOptions } from '
|
|
5
|
+
import type { AdminModuleOptions } from '../types';
|
|
6
6
|
export declare class AdminService {
|
|
7
7
|
protected readonly options: AdminModuleOptions;
|
|
8
8
|
private readonly firebaseApp;
|
|
@@ -20,7 +20,7 @@ const common_1 = require("@nestjs/common");
|
|
|
20
20
|
const rxjs_1 = require("rxjs");
|
|
21
21
|
const app_1 = require("firebase-admin/app");
|
|
22
22
|
const firebase_admin_1 = __importDefault(require("firebase-admin"));
|
|
23
|
-
const admin_constants_1 = require("
|
|
23
|
+
const admin_constants_1 = require("../constants/admin.constants");
|
|
24
24
|
let AdminService = class AdminService {
|
|
25
25
|
constructor(options, firebaseApp) {
|
|
26
26
|
this.options = options;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AdminService } from './admin.service';
|
|
2
|
+
export declare class AuthService {
|
|
3
|
+
private readonly adminService;
|
|
4
|
+
constructor(adminService: AdminService);
|
|
5
|
+
get auth(): import("firebase-admin/auth").Auth;
|
|
6
|
+
createUser(properties: {
|
|
7
|
+
email?: string;
|
|
8
|
+
emailVerified?: boolean;
|
|
9
|
+
phoneNumber?: string;
|
|
10
|
+
password?: string;
|
|
11
|
+
displayName?: string;
|
|
12
|
+
photoURL?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}): Promise<import("firebase-admin/auth").UserRecord>;
|
|
15
|
+
getUser(uid: string): Promise<import("firebase-admin/auth").UserRecord>;
|
|
16
|
+
getUserByEmail(email: string): Promise<import("firebase-admin/auth").UserRecord>;
|
|
17
|
+
getUserByPhoneNumber(phoneNumber: string): Promise<import("firebase-admin/auth").UserRecord>;
|
|
18
|
+
updateUser(uid: string, properties: {
|
|
19
|
+
email?: string;
|
|
20
|
+
emailVerified?: boolean;
|
|
21
|
+
phoneNumber?: string;
|
|
22
|
+
password?: string;
|
|
23
|
+
displayName?: string;
|
|
24
|
+
photoURL?: string;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
}): Promise<import("firebase-admin/auth").UserRecord>;
|
|
27
|
+
deleteUser(uid: string): Promise<void>;
|
|
28
|
+
createCustomToken(uid: string, claims?: object): Promise<string>;
|
|
29
|
+
verifyIdToken(idToken: string): Promise<import("firebase-admin/auth").DecodedIdToken>;
|
|
30
|
+
setCustomUserClaims(uid: string, claims: object): Promise<void>;
|
|
31
|
+
listUsers(maxResults?: number, pageToken?: string): Promise<import("firebase-admin/auth").ListUsersResult>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.AuthService = void 0;
|
|
22
|
+
const common_1 = require("@nestjs/common");
|
|
23
|
+
const auth_1 = require("firebase-admin/auth");
|
|
24
|
+
const admin_service_1 = require("./admin.service");
|
|
25
|
+
let AuthService = class AuthService {
|
|
26
|
+
constructor(adminService) {
|
|
27
|
+
this.adminService = adminService;
|
|
28
|
+
}
|
|
29
|
+
get auth() {
|
|
30
|
+
return (0, auth_1.getAuth)(this.adminService.appRef);
|
|
31
|
+
}
|
|
32
|
+
createUser(properties) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return this.auth.createUser(properties);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getUser(uid) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
return this.auth.getUser(uid);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getUserByEmail(email) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
return this.auth.getUserByEmail(email);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
getUserByPhoneNumber(phoneNumber) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return this.auth.getUserByPhoneNumber(phoneNumber);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
updateUser(uid, properties) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
return this.auth.updateUser(uid, properties);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
deleteUser(uid) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return this.auth.deleteUser(uid);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
createCustomToken(uid, claims) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
return this.auth.createCustomToken(uid, claims);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
verifyIdToken(idToken) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
return this.auth.verifyIdToken(idToken);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
setCustomUserClaims(uid, claims) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
return this.auth.setCustomUserClaims(uid, claims);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
listUsers(maxResults, pageToken) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
return this.auth.listUsers(maxResults, pageToken);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.AuthService = AuthService;
|
|
84
|
+
exports.AuthService = AuthService = __decorate([
|
|
85
|
+
(0, common_1.Injectable)(),
|
|
86
|
+
__metadata("design:paramtypes", [admin_service_1.AdminService])
|
|
87
|
+
], AuthService);
|
|
@@ -24,7 +24,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
24
24
|
exports.DatabaseService = void 0;
|
|
25
25
|
const common_1 = require("@nestjs/common");
|
|
26
26
|
const database_1 = require("firebase-admin/database");
|
|
27
|
-
const admin_constants_1 = require("
|
|
27
|
+
const admin_constants_1 = require("../constants/admin.constants");
|
|
28
28
|
let DatabaseService = class DatabaseService {
|
|
29
29
|
constructor(options, firebaseApp) {
|
|
30
30
|
this.options = options;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CollectionReference, DocumentReference, DocumentData, SetOptions, WithFieldValue } from 'firebase-admin/firestore';
|
|
2
|
+
import type { AdminModuleOptions } from '../types';
|
|
3
|
+
import { App } from 'firebase-admin/app';
|
|
4
|
+
export declare class FirestoreService {
|
|
5
|
+
protected readonly options: AdminModuleOptions;
|
|
6
|
+
private readonly firebaseApp;
|
|
7
|
+
private app;
|
|
8
|
+
private firestore;
|
|
9
|
+
constructor(options: AdminModuleOptions, firebaseApp: App);
|
|
10
|
+
collection<T = DocumentData>(path: string): CollectionReference<T>;
|
|
11
|
+
doc<T = DocumentData>(path: string): DocumentReference<T>;
|
|
12
|
+
get<T = DocumentData>(path: string): Promise<T | null>;
|
|
13
|
+
set<T = DocumentData>(path: string, data: WithFieldValue<T>, options?: SetOptions): Promise<void>;
|
|
14
|
+
update<T = DocumentData>(path: string, data: Record<string, any>): Promise<void>;
|
|
15
|
+
delete(path: string): Promise<void>;
|
|
16
|
+
add<T = DocumentData>(collectionPath: string, data: WithFieldValue<T>): Promise<DocumentReference<T>>;
|
|
17
|
+
query<T = DocumentData>(collectionPath: string, ...constraints: any[]): Promise<T[]>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.FirestoreService = void 0;
|
|
25
|
+
const common_1 = require("@nestjs/common");
|
|
26
|
+
const firestore_1 = require("firebase-admin/firestore");
|
|
27
|
+
const admin_constants_1 = require("../constants/admin.constants");
|
|
28
|
+
let FirestoreService = class FirestoreService {
|
|
29
|
+
constructor(options, firebaseApp) {
|
|
30
|
+
this.options = options;
|
|
31
|
+
this.firebaseApp = firebaseApp;
|
|
32
|
+
this.app = firebaseApp;
|
|
33
|
+
this.firestore = (0, firestore_1.getFirestore)();
|
|
34
|
+
}
|
|
35
|
+
collection(path) {
|
|
36
|
+
return this.firestore.collection(path);
|
|
37
|
+
}
|
|
38
|
+
doc(path) {
|
|
39
|
+
return this.firestore.doc(path);
|
|
40
|
+
}
|
|
41
|
+
get(path) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const docSnap = yield this.doc(path).get();
|
|
44
|
+
return docSnap.exists ? docSnap.data() : null;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
set(path, data, options) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (options) {
|
|
50
|
+
yield this.doc(path).set(data, options);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
yield this.doc(path).set(data);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
update(path, data) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
if (!data || typeof data !== 'object') {
|
|
60
|
+
throw new Error('Update data must be a non-null object');
|
|
61
|
+
}
|
|
62
|
+
yield this.doc(path).update(data);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
delete(path) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
yield this.doc(path).delete();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
add(collectionPath, data) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return yield this.collection(collectionPath).add(data);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
query(collectionPath, ...constraints) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
let q = this.collection(collectionPath);
|
|
78
|
+
if (constraints.length) {
|
|
79
|
+
for (const constraint of constraints) {
|
|
80
|
+
q = constraint(q);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const snap = yield q.get();
|
|
84
|
+
return snap.docs.map(doc => doc.data());
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
exports.FirestoreService = FirestoreService;
|
|
89
|
+
exports.FirestoreService = FirestoreService = __decorate([
|
|
90
|
+
(0, common_1.Injectable)(),
|
|
91
|
+
__param(0, (0, common_1.Inject)(admin_constants_1.FIREBASE_ADMIN_INSTANCE_TOKEN)),
|
|
92
|
+
__param(1, (0, common_1.Inject)('FIREBASE_ADMIN_APP')),
|
|
93
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
94
|
+
], FirestoreService);
|
|
@@ -23,7 +23,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.MessagingService = void 0;
|
|
25
25
|
const common_1 = require("@nestjs/common");
|
|
26
|
-
const admin_constants_1 = require("
|
|
26
|
+
const admin_constants_1 = require("../constants/admin.constants");
|
|
27
27
|
let MessagingService = class MessagingService {
|
|
28
28
|
constructor(app) {
|
|
29
29
|
this.app = app;
|
package/docs/_sidebar.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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)
|
|
@@ -0,0 +1,82 @@
|
|
|
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 { AdminModule } from 'nestjs-firebase-admin';
|
|
59
|
+
|
|
60
|
+
@Module({
|
|
61
|
+
imports: [
|
|
62
|
+
AdminModule.registerAsync({
|
|
63
|
+
useFactory: async () => ({
|
|
64
|
+
credential: {
|
|
65
|
+
projectId: 'my-project-id',
|
|
66
|
+
clientEmail: 'my-client-email',
|
|
67
|
+
privateKey: 'my-private-key',
|
|
68
|
+
},
|
|
69
|
+
databaseURL: 'https://my-project-id.firebaseio.com',
|
|
70
|
+
}),
|
|
71
|
+
}),
|
|
72
|
+
],
|
|
73
|
+
})
|
|
74
|
+
export class AppModule {}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Next Steps
|
|
78
|
+
|
|
79
|
+
- Learn about the [Admin Service](services/admin-service.md)
|
|
80
|
+
- Explore the [Database Service](services/database-service.md)
|
|
81
|
+
- Check out the [Firestore Service](services/firestore-service.md)
|
|
82
|
+
- Discover the [Messaging Service](services/messaging-service.md)
|