feat(types): add connect fields to callback ServerData#44
Conversation
- Add optional payload-level metadata for `connectPluginVersion` and `connectState` so callback flows can carry Connect context even when the action itself has no server object. - Before this change, the callback envelope only preserved `actions`, `sender`, and `type`, which meant Connect sign-in/sign-out style callbacks had no shared place to send plugin version or runtime state. - That made it awkward to support newer Connect-aware flows without overloading unrelated action shapes or requiring server payloads where none exist. - This change threads a new `CallbackPayloadMetadata` object through client and server `send`/`generateUrl` helpers, includes it in encryption/serialization, and exposes the fields on parsed payload types. - Add round-trip tests and README examples, then rebuild `dist/` so published artifacts stay aligned with the source API.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #44 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 109 109
Branches 30 30
=========================================
Hits 109 109 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
README.md (1)
31-44: Consider documenting the parameter order or using an options object.The example shows multiple
undefinedplaceholders (undefined, 'forUpc', undefined, { ... }) which can be confusing for users. The current signature has 6 positional parameters, making it easy to misorder arguments.Consider either:
- Adding inline comments in the example showing what each parameter is
- Noting this in a future refactor to use an options object pattern
For now, a clearer example might help:
callback.send( 'https://example.com/callback', [{ type: 'signIn', apiKey: 'your-api-key', user: { /* user info */ } }], undefined, // redirectType (optional) 'forUpc', // sendType undefined, // sender (uses window.location.href by default) { // metadata connectPluginVersion: '2024.05.06.1049', connectState: { connectionStatus: 'CONNECTED' }, } );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@README.md` around lines 31 - 44, The README example for callback.send is confusing due to multiple positional undefineds; update the example call to callback.send by adding inline comments showing each positional parameter name and which are optional (e.g., redirectType, sendType, sender, metadata) so readers can map the undefined placeholders to meanings; also add a short note suggesting a future refactor to an options object pattern for callback.send to avoid positional confusion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@README.md`:
- Around line 31-44: The README example for callback.send is confusing due to
multiple positional undefineds; update the example call to callback.send by
adding inline comments showing each positional parameter name and which are
optional (e.g., redirectType, sendType, sender, metadata) so readers can map the
undefined placeholders to meanings; also add a short note suggesting a future
refactor to an options object pattern for callback.send to avoid positional
confusion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e8053c06-dd5c-4451-94d4-3386e8e7f132
⛔ Files ignored due to path filters (7)
dist/client.d.tsis excluded by!**/dist/**dist/client.jsis excluded by!**/dist/**dist/core.d.tsis excluded by!**/dist/**dist/index.jsis excluded by!**/dist/**dist/server.d.tsis excluded by!**/dist/**dist/server.jsis excluded by!**/dist/**dist/types.d.tsis excluded by!**/dist/**
📒 Files selected for processing (7)
README.mdsrc/__tests__/server.test.tssrc/__tests__/useSharedCallback.test.tssrc/client.tssrc/core.tssrc/server.tssrc/types.ts
- Model `connectPluginVersion` and `connectState` on `ServerData` so callback actions keep Connect details inside the existing `server` payload used by the web app. - The previous change added a trailing metadata argument to `send()` and `generateUrl()`, which would have diverged from real callers and implied a second callback data channel outside the server action payload. - In `../api/web`, account and purchase callbacks already send a `server` object, so the extra API surface was the wrong fit and risked pushing usage away from established call patterns. - Remove the added metadata parameter and payload-envelope fields, restore the original helper signatures, and cover the new fields through round-trip tests on server-backed callback actions instead. - Rebuild `dist/` and keep README examples aligned with the unchanged public helper API.
- Replace the loose `connectState` JSON value with a typed string union covering the existing Connect minigraph states: `PRE_INIT`, `CONNECTING`, `CONNECTED`, `PING_FAILURE`, and `ERROR_RETRYING`. - Leaving the field as untyped JSON made the callback contract too permissive and would have let unrelated shapes slip into server callback state without type help. - The Connect codebase already has a clear set of status strings, so this change aligns shared-callbacks with the existing source of truth instead of inventing a looser parallel model. - Update the round-trip tests to send the string form and re-export the new `ConnectState` type from the client and server entrypoints. - Rebuild `dist/` so the generated declarations and runtime bundles match the narrowed public type surface.
Summary
connectPluginVersionand a typedconnectStatetoServerDatasend()andgenerateUrl()signatures unchanged so existing callback callers do not need to changeconnectStateas the known Connect minigraph status strings:PRE_INIT,CONNECTING,CONNECTED,PING_FAILURE, andERROR_RETRYINGdist/Why
The real callback call sites in
../api/webalready send server-backed actions like{ type, server }for account and purchase flows.connectPluginVersionandconnectStatebelong to that existing server state payload, not to a separate top-level metadata argument.Keeping
connectStateas untyped JSON would make the callback contract too loose. The Connect codebase already has an established set of state strings, so this PR narrows the field to that existing source of truth.Testing
pnpm testpnpm buildSummary by CodeRabbit
New Features
Enhancements
Tests