// Test-side helpers: load the seed artifact and build SDK clients against prod. import { RudderClient } from '../../../src/client/RudderClient.js'; import type { TokenStore } from '../../../src/token/TokenStore.js'; import { readArtifact } from './artifact.js'; import type { SeedArtifact } from './types.js'; /** Loads the seed artifact; RUDDER_E2E_* env vars override file values. */ export function loadArtifact(): SeedArtifact { const file = readArtifact(); if (!file) { throw new Error( 'No seed artifact (.e2e-prod.local.json). Run `npm run test:e2e-prod` (globalSetup seeds automatically).', ); } return { ...file, baseUrl: process.env.RUDDER_E2E_BASE_URL ?? file.baseUrl, projectKey: process.env.RUDDER_E2E_PROJECT_KEY ?? file.projectKey, }; } export function createInMemoryTokenStore(): TokenStore { let access: string | null = null; let refresh: string | null = null; return { getAccessToken: () => access, getRefreshToken: () => refresh, saveTokens: (a, r) => { access = a; refresh = r; }, clear: () => { access = null; refresh = null; }, }; } /** A client with no auth yet (in-memory tokens). */ export function makeProdClient( artifact: SeedArtifact = loadArtifact(), ): RudderClient { return new RudderClient({ baseUrl: artifact.baseUrl, projectKey: artifact.projectKey, tokenStore: createInMemoryTokenStore(), }); } /** A device-authenticated client. In Node each call mints a fresh player (ephemeral device id). */ export async function freshPlayer( artifact: SeedArtifact = loadArtifact(), ): Promise { const client = makeProdClient(artifact); await client.auth.loginWithDevice({ region: 'en', language: 'en' }); return client; }