Skip to content

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

fix(pendo): wrap report pipelines in aggregation requests

RudyCelekli7c8e740fcb8a
diff --git a/tests/clis/pendo-pipeline-envelope.test.cjs b/tests/clis/pendo-pipeline-envelope.test.cjs
new file mode 100644
index 0000000..317029c
--- /dev/null
+++ b/tests/clis/pendo-pipeline-envelope.test.cjs
@@ -0,0 +1,55 @@
+const assert = require('node:assert/strict')
+const { spawnSync } = require('node:child_process')
+const fs = require('node:fs')
+const os = require('node:os')
+const path = require('node:path')
+const { test } = require('node:test')
+const cli = path.resolve(__dirname, '../../tools/clis/pendo.js')
+function run(argv, env = {}, response = "throw new Error('unexpected network request')") {
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'marketing-contract-'))
+ const mock = path.join(tmp, 'fetch.cjs')
+ fs.writeFileSync(mock, `const assert = require('node:assert/strict'); global.fetch = async (url, opts) => { ${response} };`)
+ const childEnv = { ...process.env, ...env }
+ for (const [key, val] of Object.entries(env)) if (val === undefined) delete childEnv[key]
+ try {
+ return spawnSync(process.execPath, ['--require', mock, cli, ...argv], { env: childEnv, encoding: 'utf8', timeout: 10000 })
+ } finally { fs.rmSync(tmp, { recursive: true, force: true }) }
+}
+function value(result) {
+ assert.equal(result.status, 0, result.stderr)
+ return JSON.parse(result.stdout)
+}
+
+const env = { PENDO_INTEGRATION_KEY: 'fixture-key' }
+const pipeline = [{source:{visitors:null}},{limit:10}]
+const argv = ['reports','funnel','--pipeline']
+test('pipeline array is wrapped in the documented aggregation envelope', () => {
+ const result = run([...argv, JSON.stringify(pipeline)], env, `
+ assert.equal(url,'https://app.pendo.io/api/v1/aggregation'); assert.equal(opts.method,'POST');
+ assert.equal(opts.headers['x-pendo-integration-key'],'fixture-key');
+ assert.deepEqual(JSON.parse(opts.body), {response:{mimeType:'application/json'}, request:{pipeline:${JSON.stringify(pipeline)}}});
+ return new Response('{"results":[]}');`)
+ assert.deepEqual(value(result), {results:[]})
+})
+test('full aggregation envelopes remain supported without dropping request settings', () => {
+ const body = {response:{mimeType:'application/json'}, request:{requestId:'fixture-report',pipeline}}
+ const result = value(run([...argv, JSON.stringify(body), '--dry-run'], env))
+ assert.deepEqual(result.body, body)
+})
+test('dry-run shows the wrapped pipeline without requesting data', () => {
+ const result = value(run([...argv, JSON.stringify(pipeline), '--dry-run'], env))
+ assert.equal(result._dry_run,true)
+ assert.deepEqual(result.body.request.pipeline,pipeline)
+ assert.equal(result.headers['x-pendo-integration-key'],'***')
+})
+for (const input of ['null','42','{}','{"request":{"pipeline":{}}}','{"request":{"pipeline":null}}']) {
+ test(`invalid pipeline input ${input} fails before fetch`, () => {
+ const result = run([...argv,input],env)
+ assert.equal(result.status,1)
+ assert.match(result.stderr,/pipeline.*array|array.*pipeline/)
+ })
+}
+test('visitor searches still pass through full query bodies', () => {
+ const body={response:{mimeType:'application/json'}, request:{pipeline}}
+ assert.deepEqual(value(run(['visitors','search','--query',JSON.stringify(body),'--dry-run'],env)).body,body)
+})
diff --git a/tools/clis/pendo.js b/tools/clis/pendo.js
index 533512a..1962852 100755
--- a/tools/clis/pendo.js
+++ b/tools/clis/pendo.js
@@ -158,6 +158,11 @@ async function main() {
if (!pipeline) { result = { error: '--pipeline <json> required' }; break }
let body
try { body = JSON.parse(pipeline) } catch { result = { error: 'Invalid JSON in --pipeline' }; break }
+ if (Array.isArray(body)) {
+ body = { response: { mimeType: 'application/json' }, request: { pipeline: body } }
+ } else if (!body || typeof body !== 'object' || !Array.isArray(body.request?.pipeline)) {
+ throw new Error('--pipeline must be a pipeline array or an aggregation object with request.pipeline as an array')
+ }
result = await api('POST', '/aggregation', body)
break
}
@@ -204,7 +209,7 @@ async function main() {
search: 'accounts search --query <json>',
},
reports: {
- funnel: 'reports funnel --pipeline <json>',
+ funnel: 'reports funnel --pipeline <JSON array|aggregation object>',
},
metadata: {
list: 'metadata list --kind <visitor|account|parentAccount>',
diff --git a/tools/integrations/pendo.md b/tools/integrations/pendo.md
index 4c15741..52befc3 100644
--- a/tools/integrations/pendo.md
+++ b/tools/integrations/pendo.md
@@ -117,6 +117,17 @@ POST https://app.pendo.io/api/v1/aggregation
}
```
+`reports funnel --pipeline` accepts a JSON array of aggregation steps and wraps it
+in `response.mimeType` and `request.pipeline`, as described in Pendo's
+[aggregation guide](https://www.pendo.io/pendo-blog/pendo-aggs-writing-your-first-aggregation/).
+Existing full aggregation objects are also accepted, preserving request settings.
+The supplied steps determine the report; the CLI does not construct funnel logic.
+
+```bash
+node tools/clis/pendo.js reports funnel \
+ --pipeline '[{"source":{"visitors":null}},{"limit":10}]' --dry-run
+```
+
### List Metadata Fields
```bash