Skip to content

feat(types): add connect fields to callback ServerData#44

Merged
elibosley merged 4 commits intomainfrom
codex/add-connect-callback-metadata
Mar 24, 2026
Merged

feat(types): add connect fields to callback ServerData#44
elibosley merged 4 commits intomainfrom
codex/add-connect-callback-metadata

Conversation

@elibosley
Copy link
Member

@elibosley elibosley commented Mar 24, 2026

Summary

  • add connectPluginVersion and a typed connectState to ServerData
  • keep send() and generateUrl() signatures unchanged so existing callback callers do not need to change
  • define connectState as the known Connect minigraph status strings: PRE_INIT, CONNECTING, CONNECTED, PING_FAILURE, and ERROR_RETRYING
  • cover the new fields with round-trip tests on server-backed callback actions and rebuild dist/

Why

The real callback call sites in ../api/web already send server-backed actions like { type, server } for account and purchase flows. connectPluginVersion and connectState belong to that existing server state payload, not to a separate top-level metadata argument.

Keeping connectState as 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 test
  • pnpm build

Summary by CodeRabbit

  • New Features

    • Added a connection status type for tracking connection states.
  • Enhancements

    • Server data now includes optional plugin version and connection state fields for improved status reporting.
  • Tests

    • Updated tests to use richer server payloads and added a case verifying URL generation/parsing when sender is absent.

- 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.
@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8801726a-12d2-427c-92a4-10c5692d2d28

📥 Commits

Reviewing files that changed from the base of the PR and between 591458c and 80391ea.

📒 Files selected for processing (1)
  • src/__tests__/server.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tests/server.test.ts

📝 Walkthrough

Walkthrough

Added a new ConnectState union and two optional fields (connectPluginVersion, connectState) to ServerData; exported ConnectState from client and server entrypoints; updated tests to use ServerPayload[] (a signIn action with nested server data) for encryption/decryption and URL parsing assertions.

Changes

Cohort / File(s) Summary
Types
src/types.ts
Added `export type ConnectState = "PRE_INIT"
Public surface (re-exports)
src/client.ts, src/server.ts
Added ConnectState to the list of re-exported types so the new union is exposed from both client and server entry points.
Tests
src/__tests__/server.test.ts, src/__tests__/useSharedCallback.test.ts
Replaced simple ExternalSignOut[] test payloads with ServerPayload[] containing a signIn action and nested server object (includes fields like connectPluginVersion, connectState, guid, registered, state); adjusted assertions and added a test for generateUrl when sender is omitted.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped in to tuck a new ConnectState,
a tiny field tucked in the server's crate,
tests sniffed the packet, then twitched their nose,
round-trips still hum where the encrypted data goes,
nibbling bytes, I left a carrot-shaped state.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title follows conventional commit format with 'feat:' prefix and clearly describes the main change: adding connect-related fields to ServerData.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/add-connect-callback-metadata
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/add-connect-callback-metadata

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1c9d571) to head (80391ea).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
README.md (1)

31-44: Consider documenting the parameter order or using an options object.

The example shows multiple undefined placeholders (undefined, 'forUpc', undefined, { ... }) which can be confusing for users. The current signature has 6 positional parameters, making it easy to misorder arguments.

Consider either:

  1. Adding inline comments in the example showing what each parameter is
  2. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1c9d571 and 035eb20.

⛔ Files ignored due to path filters (7)
  • dist/client.d.ts is excluded by !**/dist/**
  • dist/client.js is excluded by !**/dist/**
  • dist/core.d.ts is excluded by !**/dist/**
  • dist/index.js is excluded by !**/dist/**
  • dist/server.d.ts is excluded by !**/dist/**
  • dist/server.js is excluded by !**/dist/**
  • dist/types.d.ts is excluded by !**/dist/**
📒 Files selected for processing (7)
  • README.md
  • src/__tests__/server.test.ts
  • src/__tests__/useSharedCallback.test.ts
  • src/client.ts
  • src/core.ts
  • src/server.ts
  • src/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.
@elibosley elibosley changed the title feat(callbacks): add connect metadata to callback payloads feat(types): add connect fields to callback ServerData Mar 24, 2026
- 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.
@elibosley elibosley merged commit 1f5724f into main Mar 24, 2026
5 checks passed
@elibosley elibosley deleted the codex/add-connect-callback-metadata branch March 24, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant