1.0.2 • Published 9 months ago

@thestartupfactory/open-snail v1.0.2

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

open-snail

This library offers some reusability around transactional email, with (basic) integrations to Sendgrid and Postmark. Using it with a local config {@link LocalConfig} allows you store emails locally during development and see the values that would be sent with the template in the console.

Example Usage With Sendgrid

    const config: LiveConfig<{ testing: { name: string } }> = {
      type: 'sendgrid',
      from: 'whoever@thestartupfactory.tech',
      apiKey: 'SG.asdfeasdfawefasdfawefasdfawefasdf'
      templateLookup: { testing: 'd-8d73df1f54484982b061908fe20e8e06' }, // <--- Map internal names to template IDs
    };

    const client = GetClient(config);
    await client.sendMail('testing', {
      to: 'unsuspectinguser@gmail.com',
      templateValues: { name: 'WORLD!' },
    })

Example usage with PostMark

const config: LiveConfig<{ testing: { name: string } }> = {
  type: 'postmark',
  from: 'rupertr@thestartupfactory.tech',
  apiKey: '7ec31028-34d2-4f12-b004-267ceedff957', // <--- Api key for your Postmark Server
  templateLookup: { testing: 'testing' }, // <--- A map of template names to template aliases on your Postmark server
};

const client = GetClient(config);
await client.sendMail('testing', {
  to: 'rupertr@thestartupfactory.tech',
  templateValues: { name: 'WORLD!' },
});

Building

Run nx build open-snail to build the library.

Running unit tests

Run nx test open-snail to execute the unit tests via Jest.