Skip to content

Commit

Permalink
Merge pull request #270 from DFE-Digital/feature/gov-notify
Browse files Browse the repository at this point in the history
[DSI-7337, DSI-7302] Gov Notify Integration Foundations
  • Loading branch information
kruncher authored Nov 14, 2024
2 parents 599d9a6 + 251c840 commit 3307a4e
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 106 deletions.
27 changes: 21 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@
"ejs": "^3.1.7",
"express": "^4.17.3",
"jsonwebtoken": "^9.0.2",
"login.dfe.api.auth": "github:DFE-Digital/login.dfe.api.auth#v2.3.1",
"login.dfe.api.auth": "github:DFE-Digital/login.dfe.api.auth#v2.3.3",
"login.dfe.async-retry": "github:DFE-Digital/login.dfe.async-retry#v2.0.3",
"login.dfe.config.schema.common": "github:DFE-Digital/login.dfe.config.schema.common#v2.1.4",
"login.dfe.config.schema.common": "github:DFE-Digital/login.dfe.config.schema.common#v2.1.6",
"login.dfe.dao": "4.2.15",
"login.dfe.express-error-handling": "github:DFE-Digital/login.dfe.express-error-handling#v3.0.1",
"login.dfe.healthcheck": "github:DFE-Digital/login.dfe.healthcheck#v3.0.1",
"login.dfe.jwt-strategies": "github:DFE-Digital/login.dfe.jwt-strategies#v4.1.0",
"login.dfe.kue": "github:DFE-Digital/login.dfe.kue#v0.12.0",
"login.dfe.winston-appinsights": "github:DFE-Digital/login.dfe.winston-appinsights#v5.0.1",
"login.dfe.healthcheck": "github:DFE-Digital/login.dfe.healthcheck#v3.0.2",
"login.dfe.jwt-strategies": "github:DFE-Digital/login.dfe.jwt-strategies#v4.1.1",
"login.dfe.kue": "github:DFE-Digital/login.dfe.kue#v0.12.2",
"login.dfe.winston-appinsights": "github:DFE-Digital/login.dfe.winston-appinsights#v5.0.3",
"marked": "^12.0.2",
"morgan": "^1.10.0",
"node-cron": "^3.0.0",
"nodemon": "^3.0.1",
"notifications-node-client": "^8.2.1",
"pm2": "^5.2.0",
"sequelize": "^6.18.0",
"simpl-schema": "^3.4.1",
Expand Down
29 changes: 14 additions & 15 deletions src/handlers/notifications/changeProfile/verifyChangeEmailV1.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
const { getEmailAdapter } = require('../../../infrastructure/email');
const { getNotifyAdapter } = require('../../../infrastructure/notify');

const process = async (config, logger, data) => {
let returnUrl = `${config.notifications.profileUrl}/change-email/verify`;
if (data.uid) {
returnUrl = `${config.notifications.profileUrl}/change-email/${data.uid}/verify`;
}

const email = getEmailAdapter(config, logger);
await email.send(data.email, 'verify-change-email', {
firstName: data.firstName,
lastName: data.lastName,
email: data.email,
code: data.code,
returnUrl,
helpUrl: config.notifications.helpUrl,
}, 'Verify your new DfE Sign-in email address');
const notify = getNotifyAdapter(config);
await notify.sendEmail('verifyChangeEmailAddress', data.email, {
personalisation: {
firstName: data.firstName,
lastName: data.lastName,
email: data.email,
code: data.code,
returnUrl: !!data.uid
? `${config.notifications.profileUrl}/change-email/${data.uid}/verify`
: `${config.notifications.profileUrl}/change-email/verify`,
helpUrl: config.notifications.helpUrl,
},
});
};

const getHandler = (config, logger) => {
Expand Down
42 changes: 21 additions & 21 deletions src/handlers/notifications/index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
const accessRequest = require('./accessRequest');
const changeProfile = require('./changeProfile');
const changeUserPermission = require('./userPermissions');
const invite = require('./invite');
const newServiceAdded = require('./serviceAdded');
const passwordReset = require('./passwordReset');
const support = require('./support');
const registration = require('./registration');
const changeProfile = require('./changeProfile');
const accessRequest = require('./accessRequest');
const newServiceAdded = require('./serviceAdded');
const userOrganisation = require('./userOrganisation');
const changeUserPermission = require('./userPermissions');
const serviceRemoved = require('./serviceRemoved');
const serviceRequested = require('./serviceRequested');
const serviceRequestRejected = require('./serviceRequestRejected');
const subServiceRequested = require('./subServiceRequested');
const subServiceRequestActioned = require('./subServiceRequestActioned');
const subServiceRequested = require('./subServiceRequested');
const support = require('./support');
const userOrganisation = require('./userOrganisation');

const register = (config, logger) => {
const accessRequestHandler = accessRequest.register(config, logger);
const changeProfileHandlers = changeProfile.register(config, logger);
const changeUserPermissionHandler = changeUserPermission.register(config, logger);
const inviteHandlers = invite.register(config, logger);
const newServiceAddedHandler = newServiceAdded.register(config, logger);
const passwordResetHandlers = passwordReset.register(config, logger);
const supportHandlers = support.register(config, logger);
const registrationHandlers = registration.register(config, logger);
const changeProfileHandlers = changeProfile.register(config, logger);
const accessRequestHandler = accessRequest.register(config, logger);
const newServiceAddedHandler = newServiceAdded.register(config, logger);
const userOrganisationHandler = userOrganisation.register(config, logger);
const changeUserPermissionHandler = changeUserPermission.register(config, logger);
const serviceRemovedHandler = serviceRemoved.register(config, logger);
const serviceRequestedHandler = serviceRequested.register(config, logger);
const serviceRequestRejectedHandler = serviceRequestRejected.register(config, logger);
const subServiceRequestedHandler = subServiceRequested.register(config, logger);
const subServiceRequestActionedHandler = subServiceRequestActioned.register(config, logger);
const subServiceRequestedHandler = subServiceRequested.register(config, logger);
const supportHandlers = support.register(config, logger);
const userOrganisationHandler = userOrganisation.register(config, logger);

return [
...accessRequestHandler,
...changeProfileHandlers,
...changeUserPermissionHandler,
...inviteHandlers,
...newServiceAddedHandler,
...passwordResetHandlers,
...supportHandlers,
...registrationHandlers,
...changeProfileHandlers,
...accessRequestHandler,
...newServiceAddedHandler,
...userOrganisationHandler,
...changeUserPermissionHandler,
...serviceRemovedHandler,
...serviceRequestedHandler,
...serviceRequestRejectedHandler,
...subServiceRequestedHandler,
...subServiceRequestActionedHandler,
...subServiceRequestedHandler,
...supportHandlers,
...userOrganisationHandler,
];
};

Expand Down
14 changes: 7 additions & 7 deletions src/handlers/serviceNotifications/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const users = require('./users');
const roles = require('./roles');
const organisations = require('./organisations');
const { v4:uuid } = require('uuid');
const organisations = require('./organisations');
const roles = require('./roles');
const users = require('./users');

const register = async (config, logger) => {
const correlationId = `register-${uuid()}`;
const userHandlers = await users.register(config, logger, correlationId);
const roleHandlers = await roles.register(config, logger, correlationId);
const organisationHandlers = await organisations.register(config, logger, correlationId);
const roleHandlers = await roles.register(config, logger, correlationId);
const userHandlers = await users.register(config, logger, correlationId);

return [
...userHandlers,
...roleHandlers,
...organisationHandlers,
...roleHandlers,
...userHandlers,
];
};

Expand Down
14 changes: 14 additions & 0 deletions src/infrastructure/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ const adapterSchema = new SimpleSchema({
},
});

const govNotifyEmailTemplatesSchema = new SimpleSchema({
verifyChangeEmailAddress: String,
});

const govNotifyTemplatesSchema = new SimpleSchema({
email: govNotifyEmailTemplatesSchema,
});

const govNotifySchema = new SimpleSchema({
apiKey: String,
templates: govNotifyTemplatesSchema,
});

const notificationsSchema = new SimpleSchema({
interactionsUrl: patterns.url,
profileUrl: patterns.url,
Expand All @@ -41,6 +54,7 @@ const notificationsSchema = new SimpleSchema({
type: Object,
blackbox: true,
},
govNotify: govNotifySchema,
slackWebHookUrl: String,
envName: String
});
Expand Down
20 changes: 20 additions & 0 deletions src/infrastructure/notify/GovNotifyAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { NotifyClient } = require('notifications-node-client');

class GovNotifyAdapter {
constructor(config) {
const { govNotify } = config.notifications;

this.client = new NotifyClient(govNotify.apiKey);
this.templateMappings = govNotify.templates;
}

async sendEmail(templateName, emailAddress, options) {
const templateId = this.templateMappings.email[templateName];
if (!templateId) {
throw new Error(`Invalid notify email template name '${templateName}'.`);
}
return await this.client.sendEmail(templateId, emailAddress, options);
}
}

module.exports = GovNotifyAdapter;
9 changes: 9 additions & 0 deletions src/infrastructure/notify/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const GovNotifyAdapter = require('./GovNotifyAdapter');

function getNotifyAdapter(config) {
return new GovNotifyAdapter(config);
}

module.exports = {
getNotifyAdapter,
};
Loading

0 comments on commit 3307a4e

Please sign in to comment.