Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const preview = (serverToken: string, args: TemplatePreviewArguments) => {
const { port, templatesdirectory } = args
log(`${title} Starting template preview server...`)
// Start server
const app = express()
const server = require('http').createServer(app)
const io = require('socket.io')(server)
// Cache manifest and Postmark server
const client = new ServerClient(serverToken)
let manifest = createManifest(templatesdirectory)
// Static assets
app.use(express.static(`${previewPath}assets`))
const updateEvent = () => {
// Generate new manifest
manifest = createManifest(templatesdirectory)
// Trigger reload on client
log(`${title} File changed. Reloading browser...`)
io.emit('change')
}
// Watch for file changes
createMonitor(untildify(templatesdirectory), { interval: 2 }, monitor => {
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import PurchaseIncludingDownload from './email-templates/purchase-incl-download';
import PurchaseJustPhysicalPrint from './email-templates/purchase-just-physical';
import ShippingNotification from './email-templates/shipping-notification';
const postmark = require('postmark');
const SEND_IN_DEV = false;
// Send an email:
var client = new postmark.ServerClient('b79d4a35-93f3-49b3-ab72-8278293863f6');
export const sendArtVectorEmail = (
name,
email,
format,
orderId,
svgUrl,
pngUrlTransparent,
pngUrlOpaque
) => {
// Don't send email in development
if (!SEND_IN_DEV && process.env.NODE_ENV !== 'production') {
return;
}
const Component =
export const deleteTemplateData = async () => {
const client = new postmark.ServerClient(serverToken);
const templates = await client.getTemplates({count: 50});
for (const template of templates.Templates) {
if (template.Name.includes(templatePrefix)) {
await client.deleteTemplate(template.TemplateId);
}
}
}
const fetchTemplateList = (options: TemplateListOptions) => {
const { sourceServer, outputDir, requestHost } = options
const spinner = ora('Pulling templates from Postmark...').start()
const client = new ServerClient(sourceServer)
if (requestHost !== undefined && requestHost !== '') {
client.clientOptions.requestHost = requestHost
}
client
.getTemplates()
.then(response => {
if (response.TotalCount === 0) {
spinner.stop()
log('There are no templates on this server.', { error: true })
process.exit(1)
} else {
processTemplates({
spinner,
client,
outputDir: outputDir,
const sendCommand = (serverToken: string, args: RawEmailArguments): void => {
const { from, to, subject, html, text, requestHost } = args
const command: CommandResponse = new CommandResponse()
command.initResponse('Sending an email')
const client = new ServerClient(serverToken)
if (requestHost !== undefined && requestHost !== '') {
client.clientOptions.requestHost = requestHost
}
sendEmail(client, from, to, subject, html, text)
.then(response => {
command.response(JSON.stringify(response))
})
.catch(error => {
command.errorResponse(error)
})
}
const sendCommand = (serverToken: string, args: TemplatedEmailArguments) => {
const { id, alias, from, to, model, requestHost } = args
const command: CommandResponse = new CommandResponse()
command.initResponse('Sending an email')
const client = new ServerClient(serverToken)
if (requestHost !== undefined && requestHost !== '') {
client.clientOptions.requestHost = requestHost
}
sendEmailWithTemplate(client, id, alias, from, to, model)
.then((response: any) => {
command.response(JSON.stringify(response))
})
.catch((error: any) => {
command.errorResponse(error)
})
}