Skip to content

Commit

Permalink
Merge branch 'main' of github.com:dzangolab/fastify into multi-tenant…
Browse files Browse the repository at this point in the history
…/fix-invitation
  • Loading branch information
dipendraupreti committed Feb 23, 2024
2 parents 905a896 + 8165d98 commit eebc558
Show file tree
Hide file tree
Showing 104 changed files with 2,581 additions and 694 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
name: Use node ${{ matrix.node-version }}
Expand Down
103 changes: 103 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,106 @@
## [0.62.1](https://github.com/dzangolab/fastify/compare/v0.62.0...v0.62.1) (2024-02-19)


### Features

* return host in tenant all request ([#614](https://github.com/dzangolab/fastify/issues/614)) ([058308a](https://github.com/dzangolab/fastify/commit/058308a201615ee4e69a0a8a6f5b351103ae0aee))
* **user:** make invitations and user service configurable ([#511](https://github.com/dzangolab/fastify/issues/511)) ([3659f26](https://github.com/dzangolab/fastify/commit/3659f26c73007b8c99f391d0b95ddc5e2f9e2ae7))



# [0.62.0](https://github.com/dzangolab/fastify/compare/v0.61.1...v0.62.0) (2024-02-12)


### Features

* **user:** add support for custom third party provider ([#608](https://github.com/dzangolab/fastify/issues/608)) ([1a4ae53](https://github.com/dzangolab/fastify/commit/1a4ae53a8d3be37a56b0179a773e5fa77d72306d))



## [0.61.1](https://github.com/dzangolab/fastify/compare/v0.61.0...v0.61.1) (2024-02-12)


### Bug Fixes

* remove role check in user enable and disable graphql resolver ([#611](https://github.com/dzangolab/fastify/issues/611)) ([2d84f4b](https://github.com/dzangolab/fastify/commit/2d84f4b13b425b34d91683f7c63d59bfcd38b726))



# [0.61.0](https://github.com/dzangolab/fastify/compare/v0.60.0...v0.61.0) (2024-01-30)


### Features

* **multi-tenant:** add endpoint to get all tenants ([#604](https://github.com/dzangolab/fastify/issues/604)) ([70ed7bd](https://github.com/dzangolab/fastify/commit/70ed7bd3dec65f88b83332a1f7b331364beecdae))
* **user:** auto verify first admin user email when email verification is enabled ([#603](https://github.com/dzangolab/fastify/issues/603)) ([e9ccf84](https://github.com/dzangolab/fastify/commit/e9ccf844fb06940f67da41ac87f9712aa428e941))



# [0.60.0](https://github.com/dzangolab/fastify/compare/v0.59.0...v0.60.0) (2024-01-26)


### Features

* **user:** make accept invitation link path configurable ([#601](https://github.com/dzangolab/fastify/issues/601)) ([5d5aa1f](https://github.com/dzangolab/fastify/commit/5d5aa1fbd94aabf2d969a463cda4f750c3753d18))



# [0.59.0](https://github.com/dzangolab/fastify/compare/v0.58.0...v0.59.0) (2024-01-25)


### Bug Fixes

* **deps:** update dependency zod to v3.22.4 ([#591](https://github.com/dzangolab/fastify/issues/591)) ([b0b6b61](https://github.com/dzangolab/fastify/commit/b0b6b619e0c0bb0ac292d31752ad93c1f9e1fc0b))
* **user:** fix link in email verification for first admin sign up ([#598](https://github.com/dzangolab/fastify/issues/598)) ([f991df5](https://github.com/dzangolab/fastify/commit/f991df5f076d7526501f83e27c0f04a0446d2b51))


### Features

* **multi-tenant:** add tenant owner role on sign up from www app ([#586](https://github.com/dzangolab/fastify/issues/586)) ([49c341d](https://github.com/dzangolab/fastify/commit/49c341d0d474744b93d0581a5f6d19bfbbff940b))



# [0.58.0](https://github.com/dzangolab/fastify/compare/v0.57.1...v0.58.0) (2024-01-16)


### Bug Fixes

* **deps:** update dependency @types/busboy to v1.5.3 ([#559](https://github.com/dzangolab/fastify/issues/559)) ([da0cf54](https://github.com/dzangolab/fastify/commit/da0cf5454c5c3a18ebbbbadfe0f525573daa4ffa))
* **deps:** update dependency nodemailer to v6.9.8 ([#589](https://github.com/dzangolab/fastify/issues/589)) ([0dc1a7d](https://github.com/dzangolab/fastify/commit/0dc1a7d8a1e028a816ed1cbbecb08ad1f462f585))
* **deps:** update dependency uuid to v9.0.1 ([#590](https://github.com/dzangolab/fastify/issues/590)) ([3537316](https://github.com/dzangolab/fastify/commit/35373164f848a407ccd9241b976e1085c268bf02))


### Features

* **multi-tenant:** add owner information on creating tenant ([3ca2756](https://github.com/dzangolab/fastify/commit/3ca27560e820bd7953e579ab9195962cb43f630e))
* **multi-tenant:** As A tenant owner, I can only get tenants or a tenant created by me. ([#588](https://github.com/dzangolab/fastify/issues/588)) ([6c7bebb](https://github.com/dzangolab/fastify/commit/6c7bebbfbc4442c33506900468e46ea0527d6819))



## [0.57.1](https://github.com/dzangolab/fastify/compare/v0.57.0...v0.57.1) (2024-01-08)



# [0.57.0](https://github.com/dzangolab/fastify/compare/v0.56.0...v0.57.0) (2024-01-04)


### Features

* **user:** add role based access control (hasPermission middleware and directive to protect routes) ([#564](https://github.com/dzangolab/fastify/issues/564)) ([eca8909](https://github.com/dzangolab/fastify/commit/eca8909c8f5d23182531077ed8a9ee2fd5b8c5b6))
* **multi-tenant:** add tenant controller and resolver ([#574](https://github.com/dzangolab/fastify/issues/574)) ([95bb1f9](https://github.com/dzangolab/fastify/commit/95bb1f96ac1b4a3218047a6aa219eb00dfe67d89))



# [0.56.0](https://github.com/dzangolab/fastify/compare/v0.55.2...v0.56.0) (2023-12-25)


### Features

* add payload support in send notification route ([#581](https://github.com/dzangolab/fastify/issues/581)) ([68c3f9a](https://github.com/dzangolab/fastify/commit/68c3f9a3421083188096034b4cdf7af28f418bd6))
* **user:** fix create invitation issue when default role is not USER ([#565](https://github.com/dzangolab/fastify/issues/565)) ([7260f11](https://github.com/dzangolab/fastify/commit/7260f11c28164044094184f96f386a5259449bc5))



## [0.55.2](https://github.com/dzangolab/fastify/compare/v0.55.1...v0.55.2) (2023-12-20)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dzangolab/fastify",
"version": "0.55.2",
"version": "0.62.1",
"private": true,
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions packages/config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dzangolab/fastify-config",
"version": "0.55.2",
"version": "0.62.1",
"description": "Fastify config plugin",
"homepage": "https://github.com/dzangolab/fastify/tree/main/packages/config#readme",
"repository": {
Expand Down Expand Up @@ -35,12 +35,12 @@
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"@vitest/coverage-istanbul": "0.32.2",
"eslint": "8.43.0",
"eslint-config-custom": "0.55.2",
"eslint": "8.56.0",
"eslint-config-custom": "0.62.1",
"fastify": "4.10.2",
"fastify-plugin": "4.4.0",
"prettier": "2.8.8",
"tsconfig": "0.55.2",
"tsconfig": "0.62.1",
"typescript": "4.9.5",
"vite": "4.3.9",
"vitest": "0.32.0"
Expand Down
24 changes: 12 additions & 12 deletions packages/firebase/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dzangolab/fastify-firebase",
"version": "0.55.2",
"version": "0.62.1",
"description": "Fastify firebase plugin",
"homepage": "https://github.com/dzangolab/fastify/tree/main/packages/firebase#readme",
"repository": {
Expand Down Expand Up @@ -32,36 +32,36 @@
},
"dependencies": {
"firebase-admin": "12.0.0",
"zod": "3.22.3"
"zod": "3.22.4"
},
"devDependencies": {
"@dzangolab/fastify-config": "0.55.2",
"@dzangolab/fastify-slonik": "0.55.2",
"@dzangolab/fastify-mercurius": "0.55.2",
"@dzangolab/fastify-config": "0.62.1",
"@dzangolab/fastify-mercurius": "0.62.1",
"@dzangolab/fastify-slonik": "0.62.1",
"@types/node": "18.16.18",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"@vitest/coverage-istanbul": "0.32.2",
"eslint": "8.43.0",
"eslint-config-custom": "0.55.2",
"eslint": "8.56.0",
"eslint-config-custom": "0.62.1",
"fastify": "4.10.2",
"fastify-plugin": "4.4.0",
"mercurius": "12.2.0",
"prettier": "2.8.8",
"slonik": "37.2.0",
"supertokens-node": "14.1.3",
"tsconfig": "0.55.2",
"tsconfig": "0.62.1",
"typescript": "4.9.5",
"vite": "4.3.9",
"vitest": "0.32.0"
},
"peerDependencies": {
"@dzangolab/fastify-config": "0.55.2",
"@dzangolab/fastify-mercurius": "0.55.2",
"@dzangolab/fastify-slonik": "0.55.2",
"firebase-admin": "12.0.0",
"@dzangolab/fastify-config": "0.62.1",
"@dzangolab/fastify-mercurius": "0.62.1",
"@dzangolab/fastify-slonik": "0.62.1",
"fastify": ">=4.10.2",
"fastify-plugin": ">=4.4.0",
"firebase-admin": "12.0.0",
"mercurius": "12.2.0",
"slonik": ">=37.2.0",
"supertokens-node": ">=14.1.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/firebase/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ declare module "mercurius" {
declare module "@dzangolab/fastify-config" {
interface ApiConfig {
firebase: {
credentials: {
enabled?: boolean;
credentials?: {
projectId: string;
privateKey: string;
clientEmail: string;
Expand Down
36 changes: 23 additions & 13 deletions packages/firebase/src/lib/initializeFirebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ import { FastifyInstance } from "fastify";
import { initializeApp, credential, apps } from "firebase-admin";

const initializeFirebase = (config: ApiConfig, fastify: FastifyInstance) => {
if (apps.length === 0) {
try {
initializeApp({
credential: credential.cert({
projectId: config.firebase.credentials.projectId,
privateKey: config.firebase.credentials.privateKey,
clientEmail: config.firebase.credentials.clientEmail,
}),
});
} catch (error) {
fastify.log.error("Failed to initialize firebase");
fastify.log.error(error);
}
if (apps.length > 0) {
return;
}

if (config.firebase?.enabled !== false && !config.firebase.credentials) {
fastify.log.error("Firebase credentials are missing");
return;
}

try {
initializeApp({
credential: credential.cert({
projectId: config.firebase.credentials?.projectId,
privateKey: config.firebase.credentials?.privateKey.replace(
/\\n/g,
"\n"
),
clientEmail: config.firebase.credentials?.clientEmail,
}),
});
} catch (error) {
fastify.log.error("Failed to initialize firebase");
fastify.log.error(error);
}
};

Expand Down
11 changes: 3 additions & 8 deletions packages/firebase/src/lib/sendPushNotification.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { messaging } from "firebase-admin";
import { MulticastMessage } from "firebase-admin/lib/messaging/messaging-api";

import { Message } from "../types";

const sendPushNotification = async (message: Message) => {
await messaging().sendEachForMulticast({
tokens: message.tokens,
data: message.data,
notification: message.notification,
});
const sendPushNotification = async (message: MulticastMessage) => {
await messaging().sendEachForMulticast(message);
};

export default sendPushNotification;
10 changes: 10 additions & 0 deletions packages/firebase/src/middlewares/isFirebaseEnabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FastifyInstance } from "fastify";

const isFirebaseEnabled =
(fastify: FastifyInstance) => async (): Promise<void> => {
if (fastify.config.firebase.enabled === false) {
throw new Error("Firebase is not enabled");
}
};

export default isFirebaseEnabled;
3 changes: 2 additions & 1 deletion packages/firebase/src/model/notification/controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import handlers from "./handlers";
import { ROUTE_SEND_NOTIFICATION } from "../../constants";
import isFirebaseEnabled from "../../middlewares/isFirebaseEnabled";

import type { FastifyInstance } from "fastify";

Expand All @@ -15,7 +16,7 @@ const plugin = async (
fastify.post(
notificationConfig.test.path || ROUTE_SEND_NOTIFICATION,
{
preHandler: fastify.verifySession(),
preHandler: [fastify.verifySession(), isFirebaseEnabled(fastify)],
},
handlersConfig?.addUserDevice || handlers.sendNotification
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { FastifyReply } from "fastify";
import { MulticastMessage } from "firebase-admin/lib/messaging/messaging-api";
import { SessionRequest } from "supertokens-node/framework/fastify";

import { sendPushNotification } from "../../../lib";
import DeviceService from "../../userDevice/service";

import type { Message, TestNotificationInput } from "../../../types";
import type { TestNotificationInput } from "../../../types";

const testPushNotification = async (
request: SessionRequest,
Expand All @@ -21,6 +22,7 @@ const testPushNotification = async (
const {
body,
title,
data,
userId: receiverId,
} = request.body as TestNotificationInput;

Expand All @@ -46,12 +48,30 @@ const testPushNotification = async (

const tokens = receiverDevices.map((device) => device.deviceToken as string);

const message: Message = {
const message: MulticastMessage = {
android: {
priority: "high",
notification: {
sound: "default",
},
},
apns: {
payload: {
aps: {
sound: "default",
},
},
},
tokens,
notification: {
title,
body,
},
data: {
...data,
title,
body,
},
};

await sendPushNotification(message);
Expand Down
Loading

0 comments on commit eebc558

Please sign in to comment.