nestjs-firebase-admin 0.3.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.
Files changed (31) hide show
  1. package/README.md +22 -127
  2. package/art/logo.png +0 -0
  3. package/dist/index.d.ts +4 -2
  4. package/dist/index.js +4 -2
  5. package/dist/modules/admin/admin.module.js +75 -12
  6. package/dist/modules/admin/{admin.constants.d.ts → constants/admin.constants.d.ts} +1 -0
  7. package/dist/modules/admin/{admin.constants.js → constants/admin.constants.js} +2 -1
  8. package/dist/modules/admin/{admin.service.d.ts → services/admin.service.d.ts} +1 -1
  9. package/dist/modules/admin/{admin.service.js → services/admin.service.js} +1 -1
  10. package/dist/modules/admin/services/auth.service.d.ts +32 -0
  11. package/dist/modules/admin/services/auth.service.js +87 -0
  12. package/dist/modules/admin/{database.service.d.ts → services/database.service.d.ts} +1 -1
  13. package/dist/modules/admin/{database.service.js → services/database.service.js} +1 -1
  14. package/dist/modules/admin/services/firestore.service.d.ts +18 -0
  15. package/dist/modules/admin/services/firestore.service.js +94 -0
  16. package/dist/modules/admin/services/messaging.service.d.ts +105 -0
  17. package/dist/modules/admin/services/messaging.service.js +71 -0
  18. package/docs/_sidebar.md +10 -0
  19. package/docs/getting-started.md +82 -0
  20. package/docs/services/admin-service.md +99 -0
  21. package/docs/services/auth-service.md +123 -0
  22. package/docs/services/database-service.md +65 -0
  23. package/docs/services/firestore-service.md +69 -0
  24. package/docs/services/messaging-service.md +87 -0
  25. package/docs/testing.md +67 -0
  26. package/index.html +60 -0
  27. package/package.json +4 -4
  28. package/dist/modules/admin/admin.service.spec.d.ts +0 -1
  29. package/dist/modules/admin/admin.service.spec.js +0 -228
  30. package/dist/modules/admin/database.service.spec.d.ts +0 -1
  31. package/dist/modules/admin/database.service.spec.js +0 -235
package/README.md CHANGED
@@ -1,15 +1,25 @@
1
- [![codecov](https://codecov.io/gh/hebertcisco/nestjs-firebase-admin/branch/main/graph/badge.svg?token=N0IW1UNNIP)](https://codecov.io/gh/hebertcisco/nestjs-firebase-admin)
2
-
3
- [![CircleCI](https://dl.circleci.com/status-badge/img/gh/hebertcisco/nestjs-firebase-admin/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/hebertcisco/nestjs-firebase-admin/tree/main)
4
-
5
- [![Node.js build and publish package](https://github.com/hebertcisco/nestjs-firebase-admin/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/hebertcisco/nestjs-firebase-admin/actions/workflows/npm-publish.yml)
6
-
7
- [![Running Code Coverage](https://github.com/hebertcisco/nestjs-firebase-admin/actions/workflows/coverage.yml/badge.svg)](https://github.com/hebertcisco/nestjs-firebase-admin/actions/workflows/coverage.yml)
8
-
9
- [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
10
- [![Nestjs](https://img.shields.io/badge/Nestjs-ea2845?style=flat&logo=nestjs&logoColor=white)](https://nestjs.com/)
11
- [![Free. Built on open source. Runs everywhere.](https://img.shields.io/badge/VS_Code-0078D4?style=flat&logo=visual%20studio%20code&logoColor=white)](https://code.visualstudio.com/)
12
- [![GitHub Actions](https://img.shields.io/badge/github%20actions-%232671E5.svg?style=flat&logo=githubactions&logoColor=white)](https://github.com/hebertcisco/nestjs-firebase-admin/actions)
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,5 +1,7 @@
1
1
  export * from './modules/admin/admin.module';
2
- export * from './modules/admin/admin.service';
3
- export * from './modules/admin/database.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';
4
6
  export * from './modules/admin/interfaces';
5
7
  export * from './modules/admin/types';
package/dist/index.js CHANGED
@@ -15,7 +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);
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);
20
22
  __exportStar(require("./modules/admin/interfaces"), exports);
21
23
  __exportStar(require("./modules/admin/types"), exports);
@@ -23,21 +23,33 @@ 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");
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");
29
32
  let AdminModule = AdminModule_1 = class AdminModule {
30
33
  static register(options) {
31
34
  const firebaseApp = firebase_admin_1.default.initializeApp(Object.assign(Object.assign({}, options), { credential: firebase_admin_1.default.credential.cert(options.credential) }));
32
35
  return {
33
36
  module: AdminModule_1,
34
37
  providers: [
38
+ {
39
+ provide: admin_constants_1.ADMIN_MODULE_OPTIONS,
40
+ useValue: options,
41
+ },
42
+ admin_service_1.AdminService,
43
+ database_service_1.DatabaseService,
44
+ messaging_service_1.MessagingService,
45
+ firestore_service_1.FirestoreService,
46
+ auth_service_1.AuthService,
35
47
  {
36
48
  provide: admin_constants_1.FIREBASE_ADMIN_INSTANCE_TOKEN,
37
49
  useValue: options,
38
50
  },
39
51
  {
40
- provide: 'FIREBASE_ADMIN_APP',
52
+ provide: admin_constants_1.FIREBASE_ADMIN_APP,
41
53
  useValue: firebaseApp,
42
54
  },
43
55
  {
@@ -45,10 +57,37 @@ let AdminModule = AdminModule_1 = class AdminModule {
45
57
  useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
46
58
  },
47
59
  ],
60
+ exports: [
61
+ admin_service_1.AdminService,
62
+ database_service_1.DatabaseService,
63
+ messaging_service_1.MessagingService,
64
+ firestore_service_1.FirestoreService,
65
+ auth_service_1.AuthService,
66
+ admin_constants_1.FIREBASE_ADMIN_INSTANCE_TOKEN,
67
+ admin_constants_1.FIREBASE_ADMIN_APP,
68
+ ],
48
69
  };
49
70
  }
50
71
  static registerAsync(options) {
51
- const providers = [];
72
+ if (!options.useFactory) {
73
+ throw new Error('useFactory is required in registerAsync options');
74
+ }
75
+ const providers = [
76
+ {
77
+ provide: admin_constants_1.ADMIN_MODULE_OPTIONS,
78
+ useFactory: options.useFactory,
79
+ inject: options.inject || [],
80
+ },
81
+ admin_service_1.AdminService,
82
+ database_service_1.DatabaseService,
83
+ messaging_service_1.MessagingService,
84
+ firestore_service_1.FirestoreService,
85
+ auth_service_1.AuthService,
86
+ {
87
+ provide: admin_constants_1.ADMIN_MODULE_ID,
88
+ useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
89
+ },
90
+ ];
52
91
  if (options.useFactory) {
53
92
  const factory = options.useFactory;
54
93
  providers.push({
@@ -57,7 +96,7 @@ let AdminModule = AdminModule_1 = class AdminModule {
57
96
  inject: options.inject || [],
58
97
  });
59
98
  providers.push({
60
- provide: 'FIREBASE_ADMIN_APP',
99
+ provide: admin_constants_1.FIREBASE_ADMIN_APP,
61
100
  useFactory: (...args) => __awaiter(this, void 0, void 0, function* () {
62
101
  const config = yield factory(...args);
63
102
  return firebase_admin_1.default.initializeApp(Object.assign(Object.assign({}, config), { credential: firebase_admin_1.default.credential.cert(config.credential) }));
@@ -75,7 +114,7 @@ let AdminModule = AdminModule_1 = class AdminModule {
75
114
  inject: [options.useExisting],
76
115
  });
77
116
  providers.push({
78
- provide: 'FIREBASE_ADMIN_APP',
117
+ provide: admin_constants_1.FIREBASE_ADMIN_APP,
79
118
  useFactory: (optionsFactory) => __awaiter(this, void 0, void 0, function* () {
80
119
  const config = yield optionsFactory.createAdminOptions();
81
120
  return firebase_admin_1.default.initializeApp(Object.assign(Object.assign({}, config), { credential: firebase_admin_1.default.credential.cert(config.credential) }));
@@ -97,7 +136,7 @@ let AdminModule = AdminModule_1 = class AdminModule {
97
136
  inject: [options.useClass],
98
137
  });
99
138
  providers.push({
100
- provide: 'FIREBASE_ADMIN_APP',
139
+ provide: admin_constants_1.FIREBASE_ADMIN_APP,
101
140
  useFactory: (optionsFactory) => __awaiter(this, void 0, void 0, function* () {
102
141
  const config = yield optionsFactory.createAdminOptions();
103
142
  return firebase_admin_1.default.initializeApp(Object.assign(Object.assign({}, config), { credential: firebase_admin_1.default.credential.cert(config.credential) }));
@@ -110,16 +149,40 @@ let AdminModule = AdminModule_1 = class AdminModule {
110
149
  }
111
150
  return {
112
151
  module: AdminModule_1,
113
- imports: options.imports,
152
+ imports: options.imports || [],
114
153
  providers,
115
- exports: [admin_service_1.AdminService],
154
+ exports: [
155
+ admin_service_1.AdminService,
156
+ database_service_1.DatabaseService,
157
+ messaging_service_1.MessagingService,
158
+ firestore_service_1.FirestoreService,
159
+ auth_service_1.AuthService,
160
+ admin_constants_1.FIREBASE_ADMIN_INSTANCE_TOKEN,
161
+ admin_constants_1.FIREBASE_ADMIN_APP,
162
+ ],
116
163
  };
117
164
  }
118
165
  };
119
166
  exports.AdminModule = AdminModule;
120
167
  exports.AdminModule = AdminModule = AdminModule_1 = __decorate([
121
168
  (0, common_1.Module)({
122
- providers: [admin_service_1.AdminService, database_service_1.DatabaseService],
123
- exports: [admin_service_1.AdminService, database_service_1.DatabaseService],
169
+ providers: [
170
+ admin_service_1.AdminService,
171
+ database_service_1.DatabaseService,
172
+ messaging_service_1.MessagingService,
173
+ firestore_service_1.FirestoreService,
174
+ auth_service_1.AuthService,
175
+ {
176
+ provide: admin_constants_1.ADMIN_MODULE_ID,
177
+ useValue: (0, random_string_generator_util_1.randomStringGenerator)(),
178
+ },
179
+ ],
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
+ ],
124
187
  })
125
188
  ], AdminModule);
@@ -1,3 +1,4 @@
1
1
  export declare const FIREBASE_ADMIN_INSTANCE_TOKEN = "FIREBASE_ADMIN_INSTANCE_TOKEN";
2
+ export declare const FIREBASE_ADMIN_APP = "FIREBASE_ADMIN_APP";
2
3
  export declare const ADMIN_MODULE_ID = "ADMIN_MODULE_ID";
3
4
  export declare const ADMIN_MODULE_OPTIONS = "ADMIN_MODULE_OPTIONS";
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ADMIN_MODULE_OPTIONS = exports.ADMIN_MODULE_ID = exports.FIREBASE_ADMIN_INSTANCE_TOKEN = void 0;
3
+ exports.ADMIN_MODULE_OPTIONS = exports.ADMIN_MODULE_ID = exports.FIREBASE_ADMIN_APP = exports.FIREBASE_ADMIN_INSTANCE_TOKEN = void 0;
4
4
  exports.FIREBASE_ADMIN_INSTANCE_TOKEN = 'FIREBASE_ADMIN_INSTANCE_TOKEN';
5
+ exports.FIREBASE_ADMIN_APP = 'FIREBASE_ADMIN_APP';
5
6
  exports.ADMIN_MODULE_ID = 'ADMIN_MODULE_ID';
6
7
  exports.ADMIN_MODULE_OPTIONS = 'ADMIN_MODULE_OPTIONS';
@@ -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 './types';
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("./admin.constants");
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);
@@ -1,4 +1,4 @@
1
- import type { AdminModuleOptions } from './types';
1
+ import type { AdminModuleOptions } from '../types';
2
2
  import { App } from 'firebase-admin/app';
3
3
  export declare class DatabaseService {
4
4
  protected readonly options: AdminModuleOptions;
@@ -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("./admin.constants");
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);