mailmessagequeue v1.0.3
mailMessageQueue-npm
An NPM to abstract the Mail Message Queue functionality. It allows us to send mail messages retrieved by the essp_getMailMessageQueue stored procedure, and to push new mail messages and message values into the Mail Message Queue.
Two objects are exported: queueMessage and sendMessage.
sendMessage
In order to use sendMessage, it must be first configured using the init method:
const dependencies = { dbConfig, logger, sqlServer, slack, smtpConfig };
sendMessage.init(dependencies);
Sending a mail message from the mail message queue
To send a mail message, call the send method with one of the objects retrieved by the essp_getMailMessageQueue stored procedure as argument; this method returns a promise with two boolean properties: sent and updated, the former indicates if the message was sent and the later indicates if the message was marked as sent in the mailMessageQueue table.
const messageStatusPromise = sendMailQueue.send(mailMessage);
queueMessage
To queue a mail message, call the queueMailMessage method with a mailMessage object, a mailMessageValues object ,and logger and sqlServer wrapped in a dependencies object. It returns a promise that is resolved or rejected to one of the following options:
- rejects with an error as a reason, if any of the fields of the mail message object has an invalid data type.
- resolve to undefined, if an error occurs while the mail message or its values are queued.
- resolve to an integer specifying the mailMessageQueueID of the mail message, if the mail message and its values are queued successfully.
mailMessage object
Field | Data type |
---|---|
sender | string |
recipient | string |
accountID | integer |
divert | boolean |
holdDate | Date |
mailMessageComment | string |
mailMessageTemplate | integer |
The mailMessageValues object must be an array composed of objects with two properties: name and value. Example:
mailMessageValues object
const mailMessageValues = [
{
name: 'some string',
value: 'abc',
},
{
name: 'some id',
value: 100,
},
];
dependencies
const dependencies = {
sqlServer,
logger,
};
Example:
const dependencies = {
sqlServer,
logger,
};
const mailMessage = {
sender: 'sender@example.com',
recipient: 'recipient@example.com',
accountID: 1,
divert: false,
holdDate: null,
mailMessageComment: 'comment',
mailMessageTemplate: 1,
};
const mailMessageValues = [
{
name: 'SEID',
value: 10,
},
{
name: 'alias',
value: 'dea@spamex.com',
},
];
const mailMessageQueueID = await queueMessage
.queueMailMessage(mailMessage, mailMessageValues, dependencies);
## Deploying:
### merging to development
-- must pass circleci tests. lint, unit, coverage and (eventally) integration
-- If using private NPMs there must be an NPM_TOKEN environment variable set in circleci for the project in order to pull the private NPMs
## merging to master
-- set a version in package.json
-- PR developemnt into master
## deploying
-- git tag vx.y.z with the same version as is in package.json. This should release it in GIT (abbreviated release) and push to NPM.