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(wistia): authenticate with the documented Bearer token
Rudy Celekli8d1e82beba1a
diff --git a/tests/clis/wistia-auth.test.cjs b/tests/clis/wistia-auth.test.cjsnew file mode 100644index 0000000..6dc7d23--- /dev/null+++ b/tests/clis/wistia-auth.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/wistia.js')+const token = 'fixture-token-with:colon'+function run(args, env = { WISTIA_API_KEY: token }) {+ const script = `global.fetch = async (url, options) => {+ if (options.headers.Authorization !== ${JSON.stringify('Bearer ' + token)}) {+ throw new Error('Wistia v1 requires Bearer authorization')+ }+ return new Response(JSON.stringify({ accepted: true, url, method: options.method }), { status: 200 })+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)})`+ return spawnSync(process.execPath, ['-e', script], { encoding: 'utf8', timeout: 10000, env: { ...process.env, WISTIA_API_KEY: '', ...env } })+}+for (const args of [['projects', 'list'], ['medias', 'get', '--id', 'abc123'], ['projects', 'create', '--name', 'Campaign']]) {+ test(`${args.slice(0, 2).join(' ')} uses the documented Bearer token`, () => {+ const result = run(args)+ assert.equal(result.status, 0, result.stderr)+ assert.equal(JSON.parse(result.stdout).accepted, true)+ })+}+test('dry-run masks the Bearer header and does not fetch', () => {+ const result = run(['projects', 'list', '--dry-run'])+ assert.equal(result.status, 0, result.stderr)+ const preview = JSON.parse(result.stdout)+ assert.equal(preview._dry_run, true)+ assert.equal(preview.headers.Authorization, 'Bearer ***')+ assert.equal(result.stdout.includes(token), false)+})+test('no arguments still shows usage without a credential', () => {+ const result = run([], {})+ assert.equal(result.status, 0, result.stderr)+ assert.ok(JSON.parse(result.stdout).usage)+})+test('a request without a credential fails before fetch', () => {+ const result = run(['projects', 'list'], {})+ assert.equal(result.status, 1)+ assert.match(result.stderr, /WISTIA_API_KEY/)+})diff --git a/tools/clis/wistia.js b/tools/clis/wistia.jsindex 3ebd13b..e35ed1e 100755--- a/tools/clis/wistia.js+++ b/tools/clis/wistia.js@@ -10,9 +10,9 @@ if ((!API_KEY) && rawArgs.length > 0) {}async function api(method, path, body) {- const auth = 'Basic ' + Buffer.from(`${API_KEY}:`).toString('base64')+ const auth = `Bearer ${API_KEY}`if (args['dry-run']) {- return { _dry_run: true, method, url: `${BASE_URL}${path}`, headers: { 'Authorization': '***', 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: body || undefined }+ return { _dry_run: true, method, url: `${BASE_URL}${path}`, headers: { 'Authorization': 'Bearer ***', 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: body || undefined }}const res = await fetch(`${BASE_URL}${path}`, {method,