Skip to content

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

fix(livestorm): use API token auth and registration field pairs

Rudy Celeklic698dcbb3194
diff --git a/tests/clis/livestorm-registration.test.cjs b/tests/clis/livestorm-registration.test.cjs
new file mode 100644
index 0000000..aaf6598
--- /dev/null
+++ b/tests/clis/livestorm-registration.test.cjs
@@ -0,0 +1,54 @@
+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/livestorm.js')
+function run(args, oracle = '') {
+ const code = `global.fetch = async (url, options) => {
+ const assert = require('node:assert/strict');
+ const parsed = new URL(url);
+ const body = options.body ? JSON.parse(options.body) : null;
+ ${oracle}
+ return new Response(JSON.stringify({accepted:true, url, body}), {status:200});
+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`
+ return spawnSync(process.execPath, ['-e', code], {
+ encoding: 'utf8', timeout: 10000,
+ env: { ...process.env, LIVESTORM_API_TOKEN: 'fixture-token' },
+ })
+}
+function result(r) { assert.equal(r.status, 0, r.stderr); return JSON.parse(r.stdout) }
+
+test('registration sends an array of field IDs and values using the API token header', () => {
+ assert.equal(result(run(['sessions','register','--id','session_123','--email','[email protected]','--first-name','Jane','--last-name','Doe'], `
+ assert.equal(options.method, 'POST');
+ assert.equal(parsed.pathname, '/v1/sessions/session_123/people');
+ assert.equal(options.headers.Authorization, 'fixture-token');
+ assert.deepEqual(body, {data:{type:'people',attributes:{fields:[
+ {id:'email',value:'[email protected]'},
+ {id:'first_name',value:'Jane'},
+ {id:'last_name',value:'Doe'}
+ ]}}});
+ `)).accepted, true)
+})
+test('email-only registration omits optional name fields', () => {
+ result(run(['sessions','register','--id','session_123','--email','[email protected]'], `
+ assert.deepEqual(body.data.attributes.fields, [{id:'email',value:'[email protected]'}]);
+ `))
+})
+test('registration preview preserves the field array and masks the token', () => {
+ const p = result(run(['sessions','register','--id','session_123','--email','[email protected]','--dry-run'], "throw new Error('unexpected fetch')"))
+ assert.deepEqual(p.body.data.attributes.fields, [{id:'email',value:'[email protected]'}])
+ assert.equal(p.headers.Authorization, '***')
+ assert.equal(JSON.stringify(p).includes('fixture-token'), false)
+})
+test('read requests use the same raw API token authentication', () => {
+ result(run(['ping'], `
+ assert.equal(options.method, 'GET');
+ assert.equal(parsed.pathname, '/v1/ping');
+ assert.equal(options.headers.Authorization, 'fixture-token');
+ assert.equal(options.body, undefined);
+ `))
+})
+test('missing registration email remains rejected without a request', () => {
+ assert.match(result(run(['sessions','register','--id','session_123'], "throw new Error('unexpected fetch')")).error, /--email required/)
+})
diff --git a/tools/clis/livestorm.js b/tools/clis/livestorm.js
index 84304b2..6acfed2 100755
--- a/tools/clis/livestorm.js
+++ b/tools/clis/livestorm.js
@@ -11,7 +11,7 @@ if ((!API_TOKEN) && rawArgs.length > 0) {
async function api(method, path, body) {
const headers = {
- 'Authorization': `Bearer ${API_TOKEN}`,
+ 'Authorization': API_TOKEN,
'Content-Type': 'application/vnd.api+json',
'Accept': 'application/vnd.api+json',
}
@@ -170,9 +170,9 @@ async function main() {
if (!id) { result = { error: '--id (session id) required' }; break }
const email = args.email
if (!email) { result = { error: '--email required' }; break }
- const fields = { email }
- if (args['first-name']) fields.first_name = args['first-name']
- if (args['last-name']) fields.last_name = args['last-name']
+ const fields = [{ id: 'email', value: email }]
+ if (args['first-name']) fields.push({ id: 'first_name', value: args['first-name'] })
+ if (args['last-name']) fields.push({ id: 'last_name', value: args['last-name'] })
result = await api('POST', `/sessions/${id}/people`, {
data: {
type: 'people',
diff --git a/tools/integrations/livestorm.md b/tools/integrations/livestorm.md
index faabfc3..eeedc59 100644
--- a/tools/integrations/livestorm.md
+++ b/tools/integrations/livestorm.md
@@ -136,16 +136,21 @@ Headers:
"data": {
"type": "people",
"attributes": {
- "fields": {
- "email": "[email protected]",
- "first_name": "Jane",
- "last_name": "Doe"
- }
+ "fields": [
+ { "id": "email", "value": "[email protected]" },
+ { "id": "first_name", "value": "Jane" },
+ { "id": "last_name", "value": "Doe" }
+ ]
}
}
}
```
+Registration fields are an array of `id`/`value` pairs, including the required
+email field. See the official [registration contract](https://developers.livestorm.co/reference/post_sessions-id-people).
+Private API tokens are sent directly in `Authorization`, as described in
+[API token authentication](https://developers.livestorm.co/docs/api-token-authentication).
+
### List session participants
```bash