Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@globaluy/notifications
Advanced tools
Notifications API is a notification module to handle email, push, sms and slack messages.
$ npm install @globaluy/notifications
Create notifications.config file in config folder of the root project:
//see configuration sample below.
export const notifications = () => ({
return {
enabled: env.SEND_EMAILS,
whitelist: env.EMAILS_WHITE_LIST?.split(','),
maxAttempts: 2,
sendLimit: 100,
account: {
port: Number(env.EMAIL_SMTP_PORT),
host: String(env.EMAIL_HOST),
username: String(env.EMAIL_USER),
password: String(env.EMAIL_PASSWORD),
alias: env.EMAIL_FROM,
},
from: String(env.EMAIL_FROM),
templates: String(env.EMAIL_TEMPLATES_PATH),
push: {
enabled: env.SEND_PUSH,
credentialJson: env.FIREBASE_CREDENTIAL_JSON,
parallelLimit: Number(env.FIREBASE_PARALLEL_LIMIT),
},
//configurada en Docker compose
stopCron: Boolean(+process.env.STOP_CRON),
slack: {
enabled: env.SEND_SLACK,
appToken: env.SLACK_APP_TOKEN,
},
twilio: {
enabled: env.SEND_TWILIO,
accountSid: env.TWILIO_ACCOUNT_SID,
authToken: env.TWILIO_AUTH_TOKEN,
from: env.TWILIO_FROM,
},
};
});
Add the module into the imports of the app moudle.
import { NotificationsModule } from 'src/common/notifications';
NotificationsModule.forRoot(notifications)
SEND_PUSH=1
FIREBASE_CREDENTIAL_JSON=<{Firebase credential json}>
FIREBASE_PARALLEL_LIMIT=3
SEND_EMAILS=1
EMAIL_HOST=<smtp host>
EMAIL_SMPT_PORT=<smtp port>
EMAIL_USER=<email use>
EMAIL_PASSWORD=<email password>
EMAIL_TEMPLATES_PATH='../../../templates/emails'
TWILIO_ACCOUNT_SID=<Twilio account sid>
TWILIO_AUTH_TOKEN=<Twilio auth token>
TWILIO_FROM=<Twilio from number>
SEND_TWILIO=1
SLACK_APP_TOKEN=<Slack app token>
SLACK_ALERTS_CHANNEL_ID=<Slack app channel id>
SEND_SLACK=1
Set the service as a module's provider
...
import {
NOTIFICATION_SERVICE_TOKEN,
NotificationsService,
} from '@globaluy/notifications';
@Module({
providers: [
...
{
provide: NOTIFICATION_SERVICE_TOKEN,
useClass: NotificationsService,
},
],
imports: [],
exports: [...],
})
export class Module {}
Import it
import { NotificationsService } from "@globaluy/notifications";
Inject NotificationsService dependency.
constructor(
private notificationsService: NotificationsService,
...
) {}
Create notification message and invoke create or createAndSendImmediately.
const notification = {
subject: this.options.mailNewUserSubject,
to: user.email,
template: this.options.mailNewUserTemplate,
context: JSON.stringify({
fullName: `${user.firstName} ${user.lastName}`,
email: user.email,
url,
currentYear: new Date().getFullYear(),
urlLogo: `${this.options.publicAssets}/${this.options.logoName}`,
}),
};
return this.notificationsService.createAndSendImmediately(notification);
package.json
"moduleNameMapper": {
"@globaluy/notifications": "<rootDir>/common/notifications/index.ts",
"src/notifications.module": "<rootDir>/common/notifications/src/notifications.module.ts",
"src/notifications.service": "<rootDir>/common/notifications/src/notifications.service.ts",
"src/(.*)": "<rootDir>/$1"
}
@globaluy/notifications
path is not really neccesary. It can be added in the tsconfig.json
file:
"paths": {
"@globaluy/notifications": ["src/common/notifications"],
},
const message = {
channelId: "<channel id>",
title: "Cars Database Appointment Service",
description: "esto es una prueba",
moreInfo: "y esto es mas info.",
type: NotificationAlertType.WARN,
values: {
Cause: "Cannot create appointment",
StatusCode: "BAD REQUEST",
},
};
A bot needs to be created, and from there we could get the token value The bot needs to be added to the channel we pretend to send messages to. We get channel id from the channel info modal in slack
export enum NotificationKind {
EMAIL = 'email',
PUSH = 'push',
PUSH_TOKEN = 'push-to-token',
SLACK = 'slack',
SMS = 'sms',
}
const mailNotificationToSend = {
to: "<destination email>",
subject: "test",
template: "default",
context: JSON.stringify({ body: "nuevo sms desde app" }),
};
const slackNotificationToSend = {
to: "<channel id>",
subject: "test",
template: "default",
kind: NotificationKind.SLACK,
context: JSON.stringify({
title: "nuevo slack desde app",
description: "description",
moreInfo: "y esto es mas info.",
type: NotificationAlertType.WARN,
values: {
Cause: "Cannot create appointment",
StatusCode: "BAD REQUEST",
},
}),
};
const smsNotificationToSend = {
to: "<phone number>",
kind: NotificationKind.SMS,
context: JSON.stringify({ body: "nuevo sms desde app" }),
};
export interface INotificationsService {
findOne(options: any): Promise<NotificationDto>;
findAll(options: any): Promise<NotificationDto[]>;
findAllAndCount(options: any): Promise<[NotificationDto[], number]>;
create(notification: DeepPartial<NotificationDto>): Promise<NotificationDto>;
createAndSendImmediately(
notification: DeepPartial<NotificationDto>,
): Promise<NotificationDto>;
update(id: number, notification: DeepPartial<NotificationDto>);
delete(id: number);
executeScheduler();
}
FAQs
Notifications API
We found that @globaluy/notifications demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.