Skip to content

Emarsys v1.5 connector (v3 OIDC)#3782

Open
xc0n42 wants to merge 2 commits into
segmentio:mainfrom
xc0n42:emarsys_v_1_5
Open

Emarsys v1.5 connector (v3 OIDC)#3782
xc0n42 wants to merge 2 commits into
segmentio:mainfrom
xc0n42:emarsys_v_1_5

Conversation

@xc0n42
Copy link
Copy Markdown
Contributor

@xc0n42 xc0n42 commented May 8, 2026

Migrate Emarsys Segment.io connector to use OIDC (v3 API) (keeping v2 backward compability)

Testing

  • Added [unit tests] for new functionality
  • Tested end-to-end using the [local server]
  • [If destination is already live] Tested for backward compatibility of destination. Note: New required fields are a breaking change.
  • [Segmenters] Tested in the staging environment
  • [Segmenters] [If applicable for this change] Tested for regression with Hadron.

Security Review

  • Reviewed all field definitions for sensitive data (API keys, tokens, passwords, client secrets) and confirmed they use type: 'password'

Copilot AI review requested due to automatic review settings May 8, 2026 12:34
@xc0n42 xc0n42 requested a review from a team as a code owner May 8, 2026 12:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 + testAuthentication to 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 tokenCache but 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. Clear tokenCache in beforeEach (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 tokenCache introduced 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. Clear tokenCache in beforeEach (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 tokenCache introduced 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. Clear tokenCache in beforeEach (consistent with other Emarsys tests).
beforeEach(() => {
  nock.cleanAll()
})

Comment thread packages/destination-actions/src/destinations/emarsys/index.ts
Comment thread packages/destination-actions/src/destinations/emarsys/index.ts
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: [] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants