caddy-mailout-handler
v0.5.3
Published
A frontend handler for Caddy's mailout plugin
Downloads
2
Readme
caddy-mailout-handler
A frontend handler for Caddy's mailout plugin
Usage
Simply import Mailout
. It is constructed with two arguments:
endpoint
which is the endpoint the plugin is atnotifier
which will be called with the result (akaMessage
) of trying to post the data
To send the actual data
to the endpoint, just call the send
method on the constructed Mailout.
Message
This object (passed to your notifier
) has the following structure:
class Message {
readonly code: string;
readonly mes: string;
hasMailed(): boolean;
}
These should be enough to update the UI as needed.
data
It should be an object having at least email
as key and others will also be handled:
interface IData {
email: string;
name?: string;
[propName: string]: any;
}
Example
import { Mailout, Message } from 'caddy-mailout-handler';
function notifier(m: Message): void {
if (m.hasMailed()) {
alert('Submitted successfully');
} else {
alert(`Submition failed: ${m.mes}`);
}
}
const mailout = new Mailout('https://site.com/mailout', notifier);
// Triggered by some event
mailout.send({email: '[email protected]', name: 'Joe', subscribe: true});