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
fix(partnerstack): send supported creation request contracts
Rudy Celekli68a11cdb7835
diff --git a/tests/clis/partnerstack-actions.test.cjs b/tests/clis/partnerstack-actions.test.cjsnew file mode 100644index 0000000..a853e31--- /dev/null+++ b/tests/clis/partnerstack-actions.test.cjs@@ -0,0 +1,49 @@+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/partnerstack.js')+function run(args, network = false) {+ const source = `global.fetch = async (url, options) => {+ if (!${network}) throw new Error('Unexpected network request');+ const body = options.body ? JSON.parse(options.body) : undefined;+ const valid = options.method === 'GET' || (body.target_key && body.target_type === 'customer'+ && body.type && Number.isInteger(body.value) && body.value >= 1);+ return { ok: !!valid, status: valid ? 200 : 400, text: async () => JSON.stringify(valid+ ? { url, method: options.method, body }+ : { error: 'target_key, target_type, type and positive integer value are required' }) };+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ const result = spawnSync(process.execPath, ['-e', source], {+ encoding: 'utf8', timeout: 5000,+ env: { ...process.env, PARTNERSTACK_PUBLIC_KEY: 'owned-public', PARTNERSTACK_SECRET_KEY: 'owned-secret' },+ })+ assert.equal(result.status, 0, result.stderr)+ return JSON.parse(result.stdout)+}++const create = ['actions', 'create', '--customer-key', 'cust_owned', '--action-key', 'signup_completed']+test('customer action flags produce the documented target and action type', () => {+ assert.deepEqual(run([...create, '--value', '3'], true), {+ url: 'https://api.partnerstack.com/api/v2/actions', method: 'POST',+ body: { target_key: 'cust_owned', target_type: 'customer', type: 'signup_completed', value: 3 },+ })+})+test('an action without an explicit count records one occurrence', () => {+ assert.equal(run(create, true).body.value, 1)+})+test('action counts must be positive integers before fetching', () => {+ for (const value of ['0', '-1', '1.5', 'many']) {+ assert.match(run([...create, '--value', value]).error, /--value must be a positive integer/)+ }+})+test('dry run shows the supported action payload without sending it', () => {+ const result = run([...create, '--dry-run'])+ assert.deepEqual(result.body, { target_key: 'cust_owned', target_type: 'customer', type: 'signup_completed', value: 1 })+ assert.equal(result.headers.Authorization, '***')+})+test('action listing keeps its cursor request and no body', () => {+ assert.deepEqual(run(['actions', 'list', '--after', 'act_owned'], true), {+ url: 'https://api.partnerstack.com/api/v2/actions?starting_after=act_owned', method: 'GET',+ })+})diff --git a/tests/clis/partnerstack-transactions.test.cjs b/tests/clis/partnerstack-transactions.test.cjsnew file mode 100644index 0000000..3dca010--- /dev/null+++ b/tests/clis/partnerstack-transactions.test.cjs@@ -0,0 +1,40 @@+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/partnerstack.js')+function run(args, network = false) {+ const source = `global.fetch = async (url, options) => {+ if (!${network}) throw new Error('Unexpected network request');+ return { ok: true, status: 200, text: async () => JSON.stringify({ url,+ method: options.method, body: JSON.parse(options.body) }) };+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ const result = spawnSync(process.execPath, ['-e', source], {+ encoding: 'utf8', timeout: 5000,+ env: { ...process.env, PARTNERSTACK_PUBLIC_KEY: 'owned-public', PARTNERSTACK_SECRET_KEY: 'owned-secret' },+ })+ assert.equal(result.status, 0, result.stderr)+ return JSON.parse(result.stdout)+}++const create = ['transactions', 'create', '--customer-key', 'cust_owned', '--amount', '9900']+test('transaction category uses the commission category key field', () => {+ const result = run([...create, '--currency', 'USD', '--category', 'subscription'], true)+ assert.deepEqual(result.body, { customer_key: 'cust_owned', amount: 9900, currency: 'USD', category_key: 'subscription' })+ assert.equal(result.url, 'https://api.partnerstack.com/api/v2/transactions')+ assert.equal(result.method, 'POST')+})+test('transaction creation requires its currency before fetching', () => {+ assert.match(run(create).error, /--currency required/)+})+test('transaction product selection remains unchanged without a category', () => {+ assert.deepEqual(run([...create, '--currency', 'EUR', '--product-key', 'pro_plan'], true).body,+ { customer_key: 'cust_owned', amount: 9900, currency: 'EUR', product_key: 'pro_plan' })+})+test('transaction preview includes the selected category without sending it', () => {+ const result = run([...create, '--currency', 'USD', '--category', 'subscription', '--dry-run'])+ assert.equal(result.body.category_key, 'subscription')+ assert.equal(Object.hasOwn(result.body, 'category'), false)+ assert.equal(result.headers.Authorization, '***')+})diff --git a/tests/clis/partnerstack-webhooks.test.cjs b/tests/clis/partnerstack-webhooks.test.cjsnew file mode 100644index 0000000..91a98f8--- /dev/null+++ b/tests/clis/partnerstack-webhooks.test.cjs@@ -0,0 +1,44 @@+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/partnerstack.js')+function run(args, network = false) {+ const source = `global.fetch = async (url, options) => {+ if (!${network}) throw new Error('Unexpected network request');+ const body = JSON.parse(options.body);+ const valid = typeof body.target_url === 'string' && Array.isArray(body.events) && body.events.length > 0;+ return { ok: valid, status: valid ? 200 : 400, text: async () => JSON.stringify(valid+ ? { data: { key: 'hook_owned', ...body }, request: { url, method: options.method } }+ : { error: 'target_url and events are required' }) };+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ const result = spawnSync(process.execPath, ['-e', source], {+ encoding: 'utf8', timeout: 5000,+ env: { ...process.env, PARTNERSTACK_PUBLIC_KEY: 'owned-public', PARTNERSTACK_SECRET_KEY: 'owned-secret' },+ })+ assert.equal(result.status, 0, result.stderr)+ return JSON.parse(result.stdout)+}++const create = ['webhooks', 'create', '--target', 'https://example.com/partnerstack']+test('webhook creation sends the documented destination and event list', () => {+ const result = run([...create, '--events', 'customer.created,transaction.created'], true)+ assert.deepEqual(result.data, {+ key: 'hook_owned', target_url: 'https://example.com/partnerstack',+ events: ['customer.created', 'transaction.created'],+ })+ assert.deepEqual(result.request, { url: 'https://api.partnerstack.com/api/v2/webhooks', method: 'POST' })+})+test('webhook creation requires events before making a request', () => {+ assert.match(run(create).error, /--events required/)+})+test('webhook creation still requires a destination', () => {+ assert.match(run(['webhooks', 'create', '--events', 'customer.created']).error, /--target required/)+})+test('dry run previews the same webhook payload without credentials or a request', () => {+ const result = run([...create, '--events', 'customer.created', '--dry-run'])+ assert.deepEqual(result.body, { target_url: 'https://example.com/partnerstack', events: ['customer.created'] })+ assert.equal(result.headers.Authorization, '***')+ assert.equal(JSON.stringify(result).includes('owned-secret'), false)+})diff --git a/tools/clis/partnerstack.js b/tools/clis/partnerstack.jsindex de60ac7..f2a5c0a 100755--- a/tools/clis/partnerstack.js+++ b/tools/clis/partnerstack.js@@ -166,12 +166,13 @@ async function main() {const amount = args.amountif (!customerKey) { result = { error: '--customer-key required' }; break }if (!amount) { result = { error: '--amount required (in cents)' }; break }+ if (!args.currency) { result = { error: '--currency required (three-letter currency code)' }; break }const body = {customer_key: customerKey,amount: Number(amount),+ currency: args.currency,}- if (args.currency) body.currency = args.currency- if (args.category) body.category = args.category+ if (args.category) body.category_key = args.categoryif (args['product-key']) body.product_key = args['product-key']result = await api('POST', '/transactions', body)break@@ -242,11 +243,14 @@ async function main() {const actionKey = args['action-key']if (!customerKey) { result = { error: '--customer-key required' }; break }if (!actionKey) { result = { error: '--action-key required' }; break }+ const value = args.value === undefined ? 1 : Number(args.value)+ if (!Number.isSafeInteger(value) || value < 1) { result = { error: '--value must be a positive integer' }; break }const body = {- customer_key: customerKey,- key: actionKey,+ target_key: customerKey,+ target_type: 'customer',+ type: actionKey,+ value,}- if (args.value) body.value = Number(args.value)result = await api('POST', '/actions', body)break}@@ -340,8 +344,8 @@ async function main() {case 'create': {const target = args.targetif (!target) { result = { error: '--target required (webhook URL)' }; break }- const body = { target }- if (args.events) body.events = args.events.split(',')+ if (!args.events) { result = { error: '--events required (comma-separated event names)' }; break }+ const body = { target_url: target, events: args.events.split(',') }result = await api('POST', '/webhooks', body)break}@@ -362,13 +366,13 @@ async function main() {usage: {partnerships: 'partnerships [list | get --key <key> | create --email <email> --group <group-key> | update --key <key>]',customers: 'customers [list | get --key <key> | create --email <email> --partner-key <key> | update --key <key> | delete --key <key>]',- transactions: 'transactions [list | get --key <key> | create --customer-key <key> --amount <cents> | delete --key <key>]',+ transactions: 'transactions [list | get --key <key> | create --customer-key <key> --amount <cents> --currency <code> [--category <category-key>] | delete --key <key>]',deals: 'deals [list | get --key <key> | create --partner-key <key> --name <name> | update --key <key> | archive --key <key>]',- actions: 'actions [list | create --customer-key <key> --action-key <key> [--value <n>]]',+ actions: 'actions [list | create --customer-key <key> --action-key <action-type> [--value <count, default: 1>]]',rewards: 'rewards [list | create --partner-key <key> --amount <cents>]',leads: 'leads [list | get --key <key> | create --partner-key <key> --email <email> | update --key <key>]',groups: 'groups [list]',- webhooks: 'webhooks [list | get --key <key> | create --target <url> [--events <evt1,evt2>] | delete --key <key>]',+ webhooks: 'webhooks [list | get --key <key> | create --target <url> --events <evt1,evt2> | delete --key <key>]',options: '--limit <n> --after <cursor> --before <cursor> --order-by <field>',}}diff --git a/tools/integrations/partnerstack.md b/tools/integrations/partnerstack.mdindex f4dcd13..7dbc48b 100644--- a/tools/integrations/partnerstack.md+++ b/tools/integrations/partnerstack.md@@ -93,12 +93,16 @@ POST https://api.partnerstack.com/api/v2/deals### Record an action (event-based rewards)+The CLI maps `--customer-key` to the customer target and `--action-key` to+the action `type`. `--value` is the number of occurrences, defaulting to one.+```bashPOST https://api.partnerstack.com/api/v2/actions{- "customer_key": "cust_abc123",- "key": "signup_completed",+ "target_key": "cust_abc123",+ "target_type": "customer",+ "type": "signup_completed","value": 1}```@@ -142,11 +146,14 @@ GET https://api.partnerstack.com/api/v2/groups### Manage webhooks+Both the destination URL and a nonempty event list are required when creating+a webhook (`--target` and `--events` in the CLI).+```bashPOST https://api.partnerstack.com/api/v2/webhooks{- "target": "https://example.com/webhooks/partnerstack",+ "target_url": "https://example.com/webhooks/partnerstack","events": ["deal.created", "transaction.created", "customer.created"]}```