Skip to content

Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.

fix(postmark): omit forbidden subjects from layout templates

Rudy Celekli16565bd1a246
diff --git a/tests/postmark-layout-template.test.cjs b/tests/postmark-layout-template.test.cjs
new file mode 100644
index 0000000..f31272d
--- /dev/null
+++ b/tests/postmark-layout-template.test.cjs
@@ -0,0 +1,42 @@
+const { test } = require('node:test')
+const assert = require('node:assert/strict')
+const { spawnSync } = require('node:child_process')
+const path = require('node:path')
+function run(vendor, args, fetch = true) {
+ const cli = path.resolve(__dirname, `../tools/clis/${vendor}.js`)
+ const source = `global.fetch = async (url, options) => {
+ if (!${fetch}) throw new Error('Unexpected network request');
+ return { status: 200, text: async () => JSON.stringify({ url, method: options.method, body: options.body ? JSON.parse(options.body) : null }) };
+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`
+ return spawnSync(process.execPath, ['-e', source], { encoding: 'utf8', timeout: 5000, env: {
+ ...process.env, REWARDFUL_API_KEY: 'fake-key', RESEND_API_KEY: 'fake-key', POSTMARK_API_KEY: 'fake-key', BEEHIIV_API_KEY: 'fake-key', KLAVIYO_API_KEY: 'fake-key',
+ } })
+}
+function output(result) { assert.equal(result.status, 0, result.stderr); return JSON.parse(result.stdout) }
+
+test('a layout creation request omits the API-forbidden Subject field', () => {
+ const result = output(run('postmark', ['templates', 'create', '--name', 'Layout', '--type', 'Layout', '--html', '<div>{{{ @content }}}</div>']))
+ assert.equal(result.method, 'POST')
+ assert.equal(result.url, 'https://api.postmarkapp.com/templates')
+ assert.equal(result.body.TemplateType, 'Layout')
+ assert.equal(Object.hasOwn(result.body, 'Subject'), false)
+ assert.equal(result.body.HtmlBody, '<div>{{{ @content }}}</div>')
+})
+test('a subject for a layout stops before the provider rejects it', () => {
+ assert.match(output(run('postmark', ['templates', 'create', '--name', 'Layout', '--type', 'Layout', '--subject', 'Invalid', '--html', '{{{ @content }}}'], false)).error, /subject.*Layout/i)
+})
+test('standard templates retain their required Subject and explicit type', () => {
+ const result = output(run('postmark', ['templates', 'create', '--name', 'Standard', '--type', 'Standard', '--subject', 'Receipt', '--text', 'Hello']))
+ assert.equal(result.body.Subject, 'Receipt')
+ assert.equal(result.body.TemplateType, 'Standard')
+})
+test('the default standard template request remains compatible', () => {
+ const result = output(run('postmark', ['templates', 'create', '--name', 'Standard', '--subject', 'Receipt', '--text', 'Hello']))
+ assert.equal(result.body.Subject, 'Receipt')
+ assert.equal(Object.hasOwn(result.body, 'TemplateType'), false)
+})
+test('layout dry run reflects the provider contract and masks the server token', () => {
+ const result = output(run('postmark', ['templates', 'create', '--name', 'Layout', '--type', 'Layout', '--text', '{{{ @content }}}', '--dry-run'], false))
+ assert.equal(Object.hasOwn(result.body, 'Subject'), false)
+ assert.equal(result.headers['X-Postmark-Server-Token'], '***')
+})
diff --git a/tools/clis/postmark.js b/tools/clis/postmark.js
index e66ca08..e81b0c0 100755
--- a/tools/clis/postmark.js
+++ b/tools/clis/postmark.js
@@ -168,10 +168,11 @@ async function main() {
case 'create': {
const name = args.name
if (!name) { result = { error: '--name required' }; break }
- const body = {
- Name: name,
- Subject: args.subject || '',
+ if (args.type === 'Layout' && args.subject) {
+ result = { error: '--subject is not allowed for Layout templates' }; break
}
+ const body = { Name: name }
+ if (args.type !== 'Layout') body.Subject = args.subject || ''
if (args.html) body.HtmlBody = args.html
if (args.text) body.TextBody = args.text
if (args.alias) body.Alias = args.alias
@@ -355,7 +356,7 @@ async function main() {
error: 'Unknown command',
usage: {
email: 'email [send --from <from> --to <to> --subject <subj> | send-template --from <from> --to <to> --template <id> | send-batch --from <from> --to <to1,to2> --subject <subj>]',
- templates: 'templates [list | get --id <id> | create --name <name> | delete --id <id>]',
+ templates: 'templates [list | get --id <id> | create --name <name> [--type Standard|Layout] [--subject <subject> (Standard only)] | delete --id <id>]',
bounces: 'bounces [list | get --id <id> | stats | activate --id <id>]',
messages: 'messages [outbound | inbound | get --id <id>]',
stats: 'stats [overview | sends | bounces | opens | clicks | spam]',