Skip to content

Fix: countryCode rename, X-Restli header, and null safety for auth#2

Open
desaip wants to merge 5 commits into
mainfrom
pradesai/fix-countrycode-field
Open

Fix: countryCode rename, X-Restli header, and null safety for auth#2
desaip wants to merge 5 commits into
mainfrom
pradesai/fix-countrycode-field

Conversation

@desaip

@desaip desaip commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

  • Renamed country to countryCode in extension.json user_data schema
  • Updated userDataComboboxFields.jsx field id from 'country' to 'countryCode'
  • Added missing X-Restli-Protocol-Version: 2.0.0 header to LinkedIn API requests
  • Added null safety for getExtensionSettings(), authentication, and getSettings()
  • Replaced delete settings.authentication with cleaner destructuring pattern
  • Added explicit actionable error when accessToken is missing
  • Added 2 new tests covering missing token and undefined getExtensionSettings()

Related Issue

N/A

Motivation and Context

  1. LinkedIn CAPI expects countryCode — using country silently dropped the field.
  2. LinkedIn REST API (Rest.li framework) requires X-Restli-Protocol-Version: 2.0.0 — missing header causes failures.
  3. getExtensionSettings() can return undefined in unconfigured environments — destructuring directly crashes with a cryptic error. Now falls back gracefully with a clear actionable message.

All three fixes mirror the linkedin-sandbox reference implementation (PRs #9 and #12).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have signed the Adobe Open Source CLA or I'm an Adobe employee.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have made any necessary test changes and all tests pass.

Testing Done

  • Local code review completed
  • All 62 tests pass (npm test)
  • Lint passes clean
  • Added tests for missing token and undefined getExtensionSettings()
  • Cross-referenced with sandbox PRs #9 and #12

🤖 Generated with GitHub Copilot CLI

- Rename 'country' to 'countryCode' in extension.json user_data schema
- Update userDataComboboxFields.jsx field id from 'country' to 'countryCode'

Aligns with the LinkedIn Conversion API's expected field name and matches
the linkedin-sandbox reference implementation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coveralls

coveralls commented Jun 25, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28140327424

Coverage increased (+0.4%) to 60.266%

Details

  • Coverage increased (+0.4%) from the base build.
  • Patch coverage: 7 of 7 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 389
Covered Lines: 263
Line Coverage: 67.61%
Relevant Branches: 288
Covered Branches: 145
Branch Coverage: 50.35%
Branches in Coverage %: Yes
Coverage Strength: 17.44 hits per line

💛 - Coveralls

LinkedIn's REST API is built on the Rest.li framework and requires
the X-Restli-Protocol-Version: 2.0.0 header for proper request handling.
Without it, API calls can fail or return unexpected response formats.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@desaip desaip changed the title Fix: rename 'country' to 'countryCode' to match LinkedIn CAPI schema Fix: rename 'country' to 'countryCode' and add missing X-Restli-Protocol-Version header Jun 25, 2026
- Guard getExtensionSettings() against undefined with || {}
- Guard authentication property against undefined with || {}
- Guard getSettings() against undefined with || {}
- Use destructuring instead of delete to extract settings auth
- Throw explicit error when accessToken is missing with actionable message
- Add tests for missing token and undefined getExtensionSettings()

Mirrors linkedin-sandbox/linkedin-adobe-capi-extension#12

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@desaip desaip changed the title Fix: rename 'country' to 'countryCode' and add missing X-Restli-Protocol-Version header Fix: countryCode rename, X-Restli header, and null safety for auth Jun 25, 2026
desaip and others added 2 commits June 24, 2026 18:12
… 2 Secret

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the LinkedIn Edge extension to align with LinkedIn API expectations (countryCode field + required Rest.li protocol header) and improves robustness around settings/authentication retrieval to avoid cryptic runtime crashes.

Changes:

  • Renames user_data.country to user_data.countryCode in the action schema and updates the combobox field ID accordingly.
  • Adds the required X-Restli-Protocol-Version: 2.0.0 header to conversion event requests.
  • Improves null-safety around getExtensionSettings()/getSettings() and adds a clearer error when accessToken is missing, with new tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
extension.json Renames user_data.country schema property to countryCode.
src/view/actions/userIdentificationSection/userDataComboboxFields.jsx Updates user-data combobox field ID from country to countryCode.
src/lib/actions/sendConversion.js Adds Rest.li protocol header and refactors settings/auth handling + clearer missing-token error.
src/lib/actions/tests/sendConversion.test.js Adds tests for missing token and undefined getExtensionSettings().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 13 to +17
{ id: 'title', name: 'Title' },
{ id: 'companyName', name: 'Company Name' },
{ id: 'lastName', name: 'Last Name' },
{ id: 'firstName', name: 'First Name' },
{ id: 'country', name: 'Country' }
{ id: 'countryCode', name: 'Country' }
Comment on lines 46 to 50
headers: {
'Content-Type': 'application/json',
'LinkedIn-Version': version,
'X-Restli-Protocol-Version': '2.0.0',
Authorization: `Bearer ${accessToken}`
Comment on lines +65 to 71
if (!authentication.accessToken) {
throw new Error(
'LinkedIn access token is required. Create an access token by configuring a Secret ' +
'in Event Forwarding with the LinkedIn OAuth 2 type, then reference it in the ' +
'extension or action settings.'
);
}
Comment on lines +271 to +280
await expect(sendWebConversion({ arc, utils })).resolves.toBeDefined();
expect(fetch).toHaveBeenCalledWith(
'https://api.linkedin.com/rest/conversionEvents',
expect.objectContaining({
headers: expect.objectContaining({
Authorization: 'Bearer token-from-settings'
})
})
);
});
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.

3 participants