diff --git a/.claude/skills/build-plugin/SKILL.md b/.claude/skills/build-plugin/SKILL.md index d508a63..07ba681 100644 --- a/.claude/skills/build-plugin/SKILL.md +++ b/.claude/skills/build-plugin/SKILL.md @@ -188,6 +188,8 @@ my-plugin/ myStream.json scripts/ myScript.js + errorHandling/ + myStream.js # errorHandling scripts referenced by path, like postRequestScript defaultContent/ manifest.json scopes.json diff --git a/.claude/skills/build-plugin/references/data-streams.md b/.claude/skills/build-plugin/references/data-streams.md index 8c220cd..e94a2a9 100644 --- a/.claude/skills/build-plugin/references/data-streams.md +++ b/.claude/skills/build-plugin/references/data-streams.md @@ -476,7 +476,19 @@ The `paging` block in `config` controls how SquaredUp fetches multiple pages. "errorHandling": { "type": "path", "realm": "payload", "path": "error.message" } // Custom script — access response (.status, .body) and data -"errorHandling": { "type": "script", "script": "result = response.status + ': ' + data.error;" } +"errorHandling": { "type": "script", "script": "errorHandling/incidents.js" } +``` + +### Script files + +Reference the script as a file — the same mechanism [`postRequestScript`](#post-request-scripts) uses. Place the file in `dataStreams/scripts/errorHandling/`, named after the stream's `name` field, and set `script` to its path relative to `dataStreams/scripts/` — **the `.js` extension is required** (a bare `.js` path with no newline is what marks the value as a file reference; deploy inlines the file's source, and an unresolvable reference is a validation error). + +Script file (`dataStreams/scripts/errorHandling/incidents.js`) — `{{ ... }}` expressions work in script files too: + +```javascript +const apiMsg = data && (data.message || data.error); + +result = apiMsg || ('Request failed with HTTP ' + response.status); ``` --- @@ -736,7 +748,7 @@ Scripts run after the HTTP response is received. Input is `data` (parsed JSON bo ### Wiring a script to a stream -Set `postRequestScript` inside `config` to the script's filename — **the `.js` extension is required**. Name the file after the stream's `name` field and place it in `dataStreams/scripts/`. +Set `postRequestScript` inside `config` to the script's filename — **the `.js` extension is required**. Name the file after the stream's `name` field and place it in `dataStreams/scripts/`. ([errorHandling scripts](#errorhandling) use the same file-reference mechanism, from the `errorHandling/` sub-folder.) Stream JSON (`dataStreams/incidents.json`):