Fix: countryCode rename, X-Restli header, and null safety for auth#2
Open
desaip wants to merge 5 commits into
Open
Fix: countryCode rename, X-Restli header, and null safety for auth#2desaip wants to merge 5 commits into
desaip wants to merge 5 commits into
Conversation
- 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>
Coverage Report for CI Build 28140327424Coverage increased (+0.4%) to 60.266%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - 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>
- 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>
… 2 Secret Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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.countrytouser_data.countryCodein the action schema and updates the combobox field ID accordingly. - Adds the required
X-Restli-Protocol-Version: 2.0.0header to conversion event requests. - Improves null-safety around
getExtensionSettings()/getSettings()and adds a clearer error whenaccessTokenis 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' | ||
| }) | ||
| }) | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
countrytocountryCodeinextension.jsonuser_dataschemauserDataComboboxFields.jsxfield id from'country'to'countryCode'X-Restli-Protocol-Version: 2.0.0header to LinkedIn API requestsgetExtensionSettings(),authentication, andgetSettings()delete settings.authenticationwith cleaner destructuring patternaccessTokenis missinggetExtensionSettings()Related Issue
N/A
Motivation and Context
countryCode— usingcountrysilently dropped the field.X-Restli-Protocol-Version: 2.0.0— missing header causes failures.getExtensionSettings()can returnundefinedin 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
Checklist:
Testing Done
npm test)getExtensionSettings()🤖 Generated with GitHub Copilot CLI