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(typeform): preserve fields when renaming forms
Rudy Celekli9909ae36bfd3
diff --git a/tests/typeform-update.test.cjs b/tests/typeform-update.test.cjsnew file mode 100644index 0000000..772a148--- /dev/null+++ b/tests/typeform-update.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/typeform.js')+function run(args, fetchSource = "throw new Error('Unexpected network request')") {+ const source = `global.fetch = async (url, options) => { ${fetchSource} }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ return spawnSync(process.execPath, ['-e', source], {+ encoding: 'utf8', env: { ...process.env, TYPEFORM_API_KEY: 'test-only-key' }+ })+}+test('renaming uses a title-only JSON patch, preserving fields and responses', () => {+ const result = run(['forms', 'update', '--id', 'form123', '--title', '新しい title'], `+ const form = { title: 'Old', fields: [{ id: 'field1', type: 'email' }], responses: ['existing'] };+ if (options.method === 'PUT') { form.fields = []; form.responses = []; }+ else if (options.method === 'PATCH') {+ const patches = JSON.parse(options.body);+ if (JSON.stringify(patches) !== JSON.stringify([{op: 'replace', path: '/title', value: '新しい title'}])) throw new Error('Invalid patch');+ form.title = patches[0].value;+ } else throw new Error('Unexpected method');+ return { status: 204, text: async () => JSON.stringify(form) };+ `)+ assert.equal(result.status, 0, result.stderr)+ const form = JSON.parse(result.stdout)+ assert.deepEqual(form.fields, [{ id: 'field1', type: 'email' }])+ assert.deepEqual(form.responses, ['existing'])+ assert.equal(form.title, '新しい title')+})+test('dry run shows exact patch with masked authorization and never fetches', () => {+ const result = run(['forms', 'update', '--id', 'form123', '--title', 'New', '--dry-run'])+ assert.equal(result.status, 0, result.stderr)+ const preview = JSON.parse(result.stdout)+ assert.equal(preview.method, 'PATCH')+ assert.deepEqual(preview.body, [{ op: 'replace', path: '/title', value: 'New' }])+ assert.equal(preview.headers.Authorization, '***')+})+test('missing title cannot send an empty replacement', () => {+ const result = run(['forms', 'update', '--id', 'form123'])+ assert.equal(JSON.parse(result.stdout).error, '--title required')+})diff --git a/tools/clis/typeform.js b/tools/clis/typeform.jsindex c3a7cbe..75d5ae3 100755--- a/tools/clis/typeform.js+++ b/tools/clis/typeform.js@@ -88,9 +88,12 @@ async function main() {case 'update': {const id = args.idif (!id) { result = { error: '--id required (form ID)' }; break }- const body = {}- if (args.title) body.title = args.title- result = await api('PUT', `/forms/${id}`, body)+ if (!args.title) { result = { error: '--title required' }; break }+ // PUT replaces the entire form, deleting omitted fields and their results.+ // Use Typeform's JSON Patch endpoint to rename without touching questions.+ result = await api('PATCH', `/forms/${id}`, [+ { op: 'replace', path: '/title', value: args.title },+ ])break}case 'delete': {diff --git a/tools/integrations/typeform.md b/tools/integrations/typeform.mdindex f9df034..f3dad62 100644--- a/tools/integrations/typeform.md+++ b/tools/integrations/typeform.md@@ -57,13 +57,15 @@ POST https://api.typeform.com/forms### Update a form```bash-PUT https://api.typeform.com/forms/{form_id}+PATCH https://api.typeform.com/forms/{form_id}-{- "title": "Updated Survey Title"-}+[+ { "op": "replace", "path": "/title", "value": "Updated Survey Title" }+]```+Use JSON Patch for a title-only change. `PUT` replaces the full form; omitted fields and their results are deleted. See [Typeform's partial-update contract](https://www.typeform.com/developers/create/reference/update-form-patch/).+### Delete a form```bash