Emarsys v1.5 connector (v3 OIDC)#3782
Open
xc0n42 wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates the Emarsys cloud destination from legacy v2 X-WSSE auth to v3 OIDC (client credentials), while keeping legacy credentials as an option for backwards compatibility.
Changes:
- Adds OIDC token acquisition + caching and updates request construction to use per-request auth headers and configurable base URLs.
- Updates Emarsys destination authentication fields +
testAuthenticationto support both legacy and OIDC modes. - Refactors and updates unit/snapshot tests to mock token retrieval and new API base URLs.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/destination-actions/src/destinations/emarsys/index.ts | Adds OIDC auth settings, legacy compatibility logic, and updates extendRequest/testAuthentication. |
| packages/destination-actions/src/destinations/emarsys/generated-types.ts | Makes legacy credentials optional and adds new OIDC-related settings to Settings. |
| packages/destination-actions/src/destinations/emarsys/emarsys-helper.ts | Introduces token cache + helpers (getAuthHeader, getApiBaseUrl, legacy detection) and updates dynamic field fetchers to use them. |
| packages/destination-actions/src/destinations/emarsys/auth.ts | Implements client-credentials token retrieval. |
| packages/destination-actions/src/destinations/emarsys/constants.ts | Adds Emarsys-specific User-Agent constant. |
| packages/destination-actions/src/destinations/emarsys/addToContactList/index.ts | Switches to getAuthHeader + configurable API base URL for requests/batching. |
| packages/destination-actions/src/destinations/emarsys/addToContactList/tests/index.test.ts | Updates tests to mock OIDC token and v3 base path. |
| packages/destination-actions/src/destinations/emarsys/addToContactList/tests/snapshot.test.ts | Updates snapshot test harness for OIDC + new request selection logic. |
| packages/destination-actions/src/destinations/emarsys/addToContactList/tests/snapshots/snapshot.test.ts.snap | Updates snapshots for new request flow. |
| packages/destination-actions/src/destinations/emarsys/removeFromContactList/index.ts | Switches to getAuthHeader + configurable API base URL for requests/batching. |
| packages/destination-actions/src/destinations/emarsys/removeFromContactList/tests/index.test.ts | Updates tests to mock OIDC token and v3 base path. |
| packages/destination-actions/src/destinations/emarsys/removeFromContactList/tests/snapshot.test.ts | Updates snapshot test harness for OIDC + new request selection logic. |
| packages/destination-actions/src/destinations/emarsys/removeFromContactList/tests/snapshots/snapshot.test.ts.snap | Updates snapshots for new request flow. |
| packages/destination-actions/src/destinations/emarsys/triggerEvent/index.ts | Switches to getAuthHeader + configurable API base URL; updates one error message. |
| packages/destination-actions/src/destinations/emarsys/triggerEvent/tests/index.test.ts | Updates tests to mock OIDC token and v3 base path. |
| packages/destination-actions/src/destinations/emarsys/triggerEvent/tests/snapshot.test.ts | Updates snapshot test harness for OIDC + new request selection logic. |
| packages/destination-actions/src/destinations/emarsys/triggerEvent/tests/snapshots/snapshot.test.ts.snap | Updates snapshots for new request flow. |
| packages/destination-actions/src/destinations/emarsys/upsertContact/index.ts | Switches to getAuthHeader + configurable API base URL for requests/batching and dynamic fields. |
| packages/destination-actions/src/destinations/emarsys/upsertContact/tests/index.test.ts | Updates tests to mock OIDC token and v3 base path. |
| packages/destination-actions/src/destinations/emarsys/upsertContact/tests/snapshot.test.ts | Updates snapshot test harness for OIDC + new request selection logic. |
| packages/destination-actions/src/destinations/emarsys/upsertContact/tests/snapshots/snapshot.test.ts.snap | Updates snapshots for new request flow. |
| packages/destination-actions/src/destinations/emarsys/tests/index.test.ts | Updates destination testAuthentication test to validate OIDC settings/token retrieval. |
| packages/destination-actions/src/destinations/emarsys/tests/snapshot.test.ts | Updates destination-wide snapshots to mock OIDC + new request selection logic. |
| packages/destination-actions/src/destinations/emarsys/tests/snapshots/snapshot.test.ts.snap | Updates snapshots for new request flow. |
Comments suppressed due to low confidence (3)
packages/destination-actions/src/destinations/emarsys/triggerEvent/tests/index.test.ts:36
- These tests use the global
tokenCachebut don't clear it between test cases. If a token is cached, subsequent tests may not call the mocked auth endpoint, making the tests order-dependent and reducing coverage of the auth flow. CleartokenCacheinbeforeEach(as done in the snapshot tests) to keep tests isolated and deterministic.
beforeEach(() => {
nock.cleanAll()
})
packages/destination-actions/src/destinations/emarsys/addToContactList/tests/index.test.ts:33
- These tests rely on the global
tokenCacheintroduced for OIDC but don't clear it between test cases. A cached token can cause the auth request not to be made, which can mask auth-related regressions and make tests order-dependent. CleartokenCacheinbeforeEach(consistent with other Emarsys tests).
beforeEach(() => {
nock.cleanAll()
})
packages/destination-actions/src/destinations/emarsys/removeFromContactList/tests/index.test.ts:33
- These tests rely on the global
tokenCacheintroduced for OIDC but don't clear it between test cases. A cached token can cause the auth request not to be made, which can mask auth-related regressions and make tests order-dependent. CleartokenCacheinbeforeEach(consistent with other Emarsys tests).
beforeEach(() => {
nock.cleanAll()
})
Comment on lines
+66
to
+75
| if (!settings.apiAuthEndpoint) { | ||
| throw new IntegrationError('Auth endpoint is required', 'MISSING_AUTH_ENDPOINT', 400) | ||
| } | ||
|
|
||
| const { accessToken, expiresIn } = await getAccessToken( | ||
| request, | ||
| settings.apiAuthEndpoint.replace(/\/$/, ''), | ||
| settings.apiClientId as string, | ||
| settings.apiClientSecret as string | ||
| ) |
Comment on lines
+16
to
+21
| export const tokenCache = new Map<string, CachedToken>() | ||
| const TOKEN_EXPIRY_BUFFER_MS = 60 * 1000 // 60 seconds | ||
|
|
||
| function getCacheKey(settings: Settings): string { | ||
| return `${settings.apiAuthEndpoint}::${settings.apiClientId}` | ||
| } |
| try { | ||
| data = await request(`${getApiBaseUrl(settings)}field/translate/en`, { headers: authHeader }) | ||
| } catch (err) { | ||
| return { choices: [] } |
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.
Migrate Emarsys Segment.io connector to use OIDC (v3 API) (keeping v2 backward compability)
Testing
Security Review
type: 'password'