Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.
JavaScript agent-skillsai-agentsai-seoclaudeclaude-codeclaude-code-pluginclaude-skillscodexcontent-marketingconversion-rate-optimizationcopywritingcursoremail-marketinggenerative-engine-optimizationgrowth-marketingmarketingmarketing-automationsaas-marketingseoskill-md
feat(postmark): preserve structured template model inputs
Rudy Celekli214dc8571025
diff --git a/tests/clis/postmark-model-json.test.cjs b/tests/clis/postmark-model-json.test.cjsnew file mode 100644index 0000000..0bb731e--- /dev/null+++ b/tests/clis/postmark-model-json.test.cjs@@ -0,0 +1,39 @@+const { test } = require('node:test')+const assert = require('node:assert/strict')+const { spawnSync } = require('node:child_process')+const path = require('node:path')+const cli = path.resolve(__dirname, '../../tools/clis/postmark.js')+function run(extra) {+ const args = ['email', 'send-template', '--from', '[email protected]', '--to', '[email protected]', '--template', 'receipt', ...extra]+ const code = `global.fetch=async(url,options)=>({status:200,text:async()=>JSON.stringify({url,body:JSON.parse(options.body)})});process.argv=['node',${JSON.stringify(cli)},...${JSON.stringify(args)}];require(${JSON.stringify(cli)});`+ return spawnSync(process.execPath, ['-e', code], { encoding: 'utf8', env: { ...process.env, POSTMARK_API_KEY: 'fixture-only' } })+}+const model = { customer: { name: 'Growth, Inc.' }, items: [{ title: 'Service: priority', quantity: 2 }], paid: true, total: 29.5 }+test('structured template models retain nested arrays and numeric/boolean values in the actual request', () => {+ const r = run(['--model-json', JSON.stringify(model)])+ assert.equal(r.status, 0, r.stderr)+ const out = JSON.parse(r.stdout)+ assert.equal(out.url, 'https://api.postmarkapp.com/email/withTemplate')+ assert.deepEqual(out.body.TemplateModel, model)+ assert.equal(out.body.TemplateAlias, 'receipt')+})+test('legacy shorthand remains intact and previews preserve model types without exposing credentials', () => {+ const legacy = run(['--model', 'name:Rudy,url:https://example.com'])+ assert.equal(legacy.status, 0, legacy.stderr)+ assert.deepEqual(JSON.parse(legacy.stdout).body.TemplateModel, { name: 'Rudy', url: 'https://example.com' })+ const preview = run(['--model-json', JSON.stringify(model), '--dry-run'])+ assert.equal(preview.status, 0, preview.stderr)+ const out = JSON.parse(preview.stdout)+ assert.deepEqual(out.body.TemplateModel, model)+ assert.equal(out.headers['X-Postmark-Server-Token'], '***')+})+for (const value of ['null', '[]', '"text"', 'true', '{bad']) test(`invalid object model ${value} fails before delivery`, () => {+ const r = run(['--model-json', value])+ assert.notEqual(r.status, 0)+ assert.match(JSON.parse(r.stderr).error, /model-json/)+})+test('ambiguous legacy and JSON model inputs fail before delivery', () => {+ const r = run(['--model', 'name:old', '--model-json', '{}'])+ assert.notEqual(r.status, 0)+ assert.match(JSON.parse(r.stderr).error, /not both/)+})diff --git a/tools/clis/postmark.js b/tools/clis/postmark.jsindex 5fee027..d029a64 100755--- a/tools/clis/postmark.js+++ b/tools/clis/postmark.js@@ -120,6 +120,13 @@ async function main() {} else {body.TemplateAlias = template}+ if (args['model-json'] !== undefined) {+ if (args.model !== undefined) throw new Error('Use --model or --model-json, not both')+ let model+ try { model = JSON.parse(args['model-json']) } catch { throw new Error('--model-json must be a valid JSON object') }+ if (model === null || typeof model !== 'object' || Array.isArray(model)) throw new Error('--model-json must be a JSON object')+ body.TemplateModel = model+ }if (args.model) {const pairs = args.model.split(',')for (const pair of pairs) {@@ -364,7 +371,7 @@ async function main() {result = {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>]',+ email: 'email [send --from <from> --to <to> --subject <subj> | send-template --from <from> --to <to> --template <id> [--model <pairs> | --model-json <object>] | send-batch --from <from> --to <to1,to2> --subject <subj>]',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>]',diff --git a/tools/integrations/postmark.md b/tools/integrations/postmark.mdindex c3ef1bf..34b30f9 100644--- a/tools/integrations/postmark.md+++ b/tools/integrations/postmark.md@@ -232,3 +232,13 @@ Postmark uses simple REST endpoints with PascalCase field names in request/respo- transactional-email- email-deliverability- onboarding-email++### Structured template models++Use `--model-json` for nested template data, line-item arrays, numbers and booleans. The existing `--model key:value,...` shorthand remains available for simple strings; choose one input format per invocation.++```bash+node tools/clis/postmark.js email send-template --from [email protected] --to [email protected] --template receipt --model-json '{"customer":{"name":"Growth, Inc."},"items":[{"title":"Service: priority","quantity":2}],"paid":true}' --dry-run+```++The CLI requires a JSON object and preserves its nested value types in `TemplateModel`. Preview first; removing `--dry-run` sends the message. See the [Postmark Templates API](https://postmarkapp.com/developer/api/templates-api).