-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
322 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
RELEASE 1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Contributing | ||
|
||
1. [Fork it](https://help.github.com/articles/fork-a-repo/) | ||
2. Install dependencies (`npm install`) | ||
3. Create your feature branch (`git checkout -b my-new-feature`) | ||
4. Commit your changes (`git commit -am 'Added some feature'`) | ||
5. Push to the branch (`git push origin my-new-feature`) | ||
6. [Create new Pull Request](https://help.github.com/articles/creating-a-pull-request/) | ||
|
||
## Code Style | ||
|
||
We use [Prettier](https://prettier.io/) and tslint to maintain code style and best practices. | ||
Please make sure your PR adheres to the guides by running: | ||
|
||
```bash | ||
npm run format | ||
``` | ||
|
||
and | ||
|
||
```bash | ||
npm run lint | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,60 @@ | ||
# nestjs-firebase-admin | ||
NestJS Module for Firebase Admin SDK | ||
<h1 align="center"></h1> | ||
|
||
<div align="center"> | ||
<a href="http://nestjs.com/" target="_blank"> | ||
<img src="https://nestjs.com/img/logo_text.svg" width="150" alt="Nest Logo" /> | ||
</a> | ||
</div> | ||
|
||
<h3 align="center">NestJS Module for Firebase Admin SDK</h3> | ||
|
||
<div align="center"> | ||
<a href="https://nestjs.com" target="_blank"> | ||
<img src="https://img.shields.io/badge/built%20with-NestJs-red.svg" alt="Built with NestJS"> | ||
</a> | ||
</div> | ||
|
||
# Installation | ||
|
||
```bash | ||
npm install @tfarras/nestjs-firebase-admin | ||
``` | ||
|
||
## Import module | ||
|
||
```typescript | ||
import { Module } from '@nestjs/common'; | ||
import { FirebaseAdminModule } from '@tfarras/nestjs-firebase-admin' | ||
import * as admin from 'firebase-admin' | ||
|
||
@Module({ | ||
imports: [ | ||
FirebaseAdminModule.forRootAsync({ | ||
useFactory: () => ({ | ||
credential: admin.credential.applicationDefault() | ||
}) | ||
}), | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
# Example | ||
|
||
## Inject FirebaseAdminSDK | ||
|
||
```typescript | ||
import { Injectable, Inject } from '@nestjs/common'; | ||
import { FIREBASE_ADMIN_INJECT, FirebaseAdminSDK } from '@tfarras/nestjs-firebase-admin'; | ||
|
||
@Injectable() | ||
export class AppService { | ||
constructor( | ||
@Inject(FIREBASE_ADMIN_INJECT) private firebaseAdmin: FirebaseAdminSDK, | ||
) {} | ||
|
||
getUsers() { | ||
return this.firebaseAdmin.auth().listUsers(); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"language": "ts", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"name": "@tfarras/nestjs-firebase-admin", | ||
"version": "1.0.0", | ||
"description": "NestJS Module for Firebase Admin SDK", | ||
"author": "Taimoor Farras <[email protected]>", | ||
"readmeFilename": "README.md", | ||
"main": "dist/index.js", | ||
"license": "MIT", | ||
"files": [ | ||
"dist/**/*", | ||
"*.md" | ||
], | ||
"scripts": { | ||
"start:dev": "tsc -w", | ||
"build": "tsc", | ||
"prepare": "npm run build", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
"lint": "tslint -p tsconfig.json -c tslint.json", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:cov": "jest --coverage", | ||
"test:e2e": "jest --config ./test/jest-e2e.json" | ||
}, | ||
"keywords": [ | ||
"nestjs", | ||
"firebase", | ||
"firebase-admin", | ||
"sdk" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/tfarras/nestjs-firebase-admin-sdk.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/tfarras/nestjs-firebase-admin-sdk/issues" | ||
}, | ||
"homepage": "https://github.com/tfarras/nestjs-firebase-admin-sdk#readme", | ||
"peerDependencies": { | ||
"@nestjs/common": "^6.0.0", | ||
"firebase-admin": "^8.10.0" | ||
}, | ||
"dependencies": { | ||
"firebase-admin": "^8.10.0" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/common": "^6.0.0", | ||
"@nestjs/core": "^6.0.0", | ||
"@nestjs/platform-express": "^6.0.0", | ||
"@nestjs/testing": "6.1.1", | ||
"@types/express": "4.16.1", | ||
"@types/jest": "24.0.11", | ||
"@types/node": "11.13.4", | ||
"@types/supertest": "2.0.7", | ||
"rxjs": "^6.5.4", | ||
"jest": "24.7.1", | ||
"prettier": "1.17.0", | ||
"supertest": "4.0.2", | ||
"ts-jest": "24.0.2", | ||
"ts-node": "8.1.0", | ||
"tsc-watch": "2.2.1", | ||
"tsconfig-paths": "3.8.0", | ||
"tslint": "5.16.0", | ||
"typescript": "3.7.2" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"ts" | ||
], | ||
"rootDir": "src", | ||
"testRegex": ".spec.ts$", | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"coverageDirectory": "../coverage", | ||
"testEnvironment": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as admin from 'firebase-admin'; | ||
|
||
export type FirebaseAdminSDK = admin.app.App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const FIREBASE_ADMIN_MODULE_OPTIONS = 'FIREBASE_ADMIN_MODULE_OPTIONS'; | ||
export const FIREBASE_ADMIN_NAME = 'FIREBASE_ADMIN_NAME'; | ||
export const FIREBASE_ADMIN_INJECT = 'FIREBASE_ADMIN_INJECT'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as admin from 'firebase-admin'; | ||
import { ModuleMetadata } from '@nestjs/common/interfaces'; | ||
|
||
export type FirebaseUser = admin.auth.DecodedIdToken; | ||
|
||
export interface FirebaseAdminModuleAsyncOptions | ||
extends Pick<ModuleMetadata, 'imports'> { | ||
name?: string; | ||
useFactory?: ( | ||
...args: any[] | ||
) => Promise<admin.AppOptions> | admin.AppOptions; | ||
inject?: any[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Global, Module, DynamicModule } from '@nestjs/common'; | ||
import { FirebaseAdminModuleAsyncOptions } from './firebase-admin.interface'; | ||
import { FIREBASE_ADMIN_MODULE_OPTIONS, FIREBASE_ADMIN_INJECT } from './firebase-admin.constant'; | ||
import * as admin from 'firebase-admin'; | ||
|
||
@Global() | ||
@Module({}) | ||
export class FirebaseAdminCoreModule { | ||
static forRoot(options: admin.AppOptions): DynamicModule { | ||
const firebaseAdminModuleOptions = { | ||
provide: FIREBASE_ADMIN_MODULE_OPTIONS, | ||
useValue: options, | ||
}; | ||
|
||
const app = admin.apps.length === 0 ? admin.initializeApp(options) : admin.apps[0]; | ||
|
||
const firebaseAuthencationProvider = { | ||
provide: FIREBASE_ADMIN_INJECT, | ||
useValue: app, | ||
}; | ||
|
||
return { | ||
module: FirebaseAdminCoreModule, | ||
providers: [firebaseAdminModuleOptions, firebaseAuthencationProvider], | ||
exports: [firebaseAdminModuleOptions, firebaseAuthencationProvider], | ||
}; | ||
} | ||
|
||
static forRootAsync(options: FirebaseAdminModuleAsyncOptions): DynamicModule { | ||
const firebaseAdminModuleOptions = { | ||
provide: FIREBASE_ADMIN_MODULE_OPTIONS, | ||
useFactory: options.useFactory, | ||
inject: options.inject || [], | ||
}; | ||
|
||
const firebaseAuthencationProvider = { | ||
provide: FIREBASE_ADMIN_INJECT, | ||
useFactory: (opt: admin.AppOptions) => { | ||
const app = admin.apps.length === 0 ? admin.initializeApp(opt) : admin.apps[0]; | ||
|
||
return app; | ||
}, | ||
inject: [FIREBASE_ADMIN_MODULE_OPTIONS], | ||
}; | ||
|
||
return { | ||
module: FirebaseAdminCoreModule, | ||
imports: options.imports, | ||
providers: [firebaseAdminModuleOptions, firebaseAuthencationProvider], | ||
exports: [firebaseAdminModuleOptions, firebaseAuthencationProvider], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './firebase-admin-sdk.type'; | ||
export * from './firebase-admin.constant'; | ||
export * from './firebase-admin.interface'; | ||
export * from './firebase-admin.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"declaration": true, | ||
"removeComments": true, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"target": "es6", | ||
"sourceMap": false, | ||
"outDir": "./dist", | ||
"rootDir": "./src", | ||
"baseUrl": "./", | ||
"noLib": false | ||
}, | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"extends": ["tslint:recommended"], | ||
"jsRules": { | ||
"no-unused-expression": true | ||
}, | ||
"rules": { | ||
"quotemark": [true, "single"], | ||
"member-access": [false], | ||
"ordered-imports": [false], | ||
"max-line-length": [true, 150], | ||
"member-ordering": [false], | ||
"interface-name": [false], | ||
"arrow-parens": false, | ||
"object-literal-sort-keys": false | ||
}, | ||
"rulesDirectory": [] | ||
} |