662 piano destination#672
Conversation
|
Important Review skippedToo many files! This PR contains 212 files, which is 62 over the limit of 150. To get a review, narrow the scope: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (212)
You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR introduces the Piano Analytics web destination for walkerOS, enabling forwarding of processed events to Piano's ChangesPiano Analytics Web Destination
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/web/destinations/piano/src/index.ts (1)
49-54: ⚡ Quick winConsider guarding against duplicate script injection.
The
addScriptfunction doesn't check whether the Piano script is already present in the DOM. While destinationinitis typically called only once, adding a guard would make the code more resilient to repeated initialization.🔍 Proposed defensive check
function addScript(src = SCRIPT_SRC) { if (typeof document === 'undefined') return; + if (document.querySelector(`script[src="${src}"]`)) return; const script = document.createElement('script'); script.src = src; document.head.appendChild(script); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/web/destinations/piano/src/index.ts` around lines 49 - 54, The addScript function can append duplicate Piano script tags; modify addScript (and reference SCRIPT_SRC) to first search the document (e.g., document.querySelector or getElementsByTagName) for an existing script whose src matches the provided src (or a unique id attribute) and if found return that existing element instead of creating/appending a new one; only create and append a script element when no matching script is present to prevent duplicate injections on repeated init calls.packages/web/destinations/piano/src/__tests__/stepExamples.test.ts (1)
23-29: 💤 Low valueConsider strengthening type guards for Config and Rule.
The type guards
isConfigandisRuleonly verify that the value is an object, without validating any specific properties. This means any object (including{}) would pass validation. While the current usage has safe fallbacks, more robust guards would improve type safety and catch malformed example data earlier.♻️ Suggested refinement
function isConfig(value: unknown): value is Config { - return isObject(value); + return ( + isObject(value) && + (value.settings === undefined || isObject(value.settings)) && + (value.mapping === undefined || isObject(value.mapping)) + ); } function isRule(value: unknown): value is Rule { - return isObject(value); + return ( + isObject(value) && + (value.name === undefined || typeof value.name === 'string') + ); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/web/destinations/piano/src/__tests__/stepExamples.test.ts` around lines 23 - 29, The current type guards isConfig and isRule only check for an object shape and should be strengthened to validate required properties: update isConfig(value) to verify expected Config properties (e.g., presence and types of keys like client, apiKey, or whatever fields Config defines) and update isRule(value) to verify required Rule properties (e.g., id, match, actions or the actual properties in your Rule type). Modify the guards to first ensure isObject(value) then check typeof/Array.isArray checks for those specific fields so malformed objects (like {}) are rejected; keep the functions named isConfig and isRule so callers (e.g., tests in stepExamples.test.ts) continue to use them unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/web/destinations/piano/src/__tests__/stepExamples.test.ts`:
- Around line 23-29: The current type guards isConfig and isRule only check for
an object shape and should be strengthened to validate required properties:
update isConfig(value) to verify expected Config properties (e.g., presence and
types of keys like client, apiKey, or whatever fields Config defines) and update
isRule(value) to verify required Rule properties (e.g., id, match, actions or
the actual properties in your Rule type). Modify the guards to first ensure
isObject(value) then check typeof/Array.isArray checks for those specific fields
so malformed objects (like {}) are rejected; keep the functions named isConfig
and isRule so callers (e.g., tests in stepExamples.test.ts) continue to use them
unchanged.
In `@packages/web/destinations/piano/src/index.ts`:
- Around line 49-54: The addScript function can append duplicate Piano script
tags; modify addScript (and reference SCRIPT_SRC) to first search the document
(e.g., document.querySelector or getElementsByTagName) for an existing script
whose src matches the provided src (or a unique id attribute) and if found
return that existing element instead of creating/appending a new one; only
create and append a script element when no matching script is present to prevent
duplicate injections on repeated init calls.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 74e40f13-7f98-4003-8c47-b20d072ca3c8
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (20)
.changeset/piano-web-destination.mdpackages/web/destinations/piano/LICENSEpackages/web/destinations/piano/README.mdpackages/web/destinations/piano/jest.config.mjspackages/web/destinations/piano/package.jsonpackages/web/destinations/piano/src/__tests__/stepExamples.test.tspackages/web/destinations/piano/src/dev.tspackages/web/destinations/piano/src/examples/env.tspackages/web/destinations/piano/src/examples/index.tspackages/web/destinations/piano/src/examples/step.tspackages/web/destinations/piano/src/index.test.tspackages/web/destinations/piano/src/index.tspackages/web/destinations/piano/src/schemas/index.tspackages/web/destinations/piano/src/schemas/mapping.tspackages/web/destinations/piano/src/schemas/settings.tspackages/web/destinations/piano/src/types/index.tspackages/web/destinations/piano/tsconfig.jsonpackages/web/destinations/piano/tsup.config.tsskills/walkeros-create-transformer/templates/validation/index.test.tswebsite/docs/destinations/web/piano.mdx
Summary by CodeRabbit
Release Notes
New Features
paSDKloadScriptoptionDocumentation