2026-09-17 14:15:37 +03:00
|
|
|
// Test-side helpers: load the seed artifact and build SDK clients against prod.
|
2026-08-12 14:02:25 +03:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-17 12:08:03 +03:00
|
|
|
/** A client with no auth yet (in-memory tokens). */
|
|
|
|
|
export function makeProdClient(
|
2026-08-12 14:02:25 +03:00
|
|
|
artifact: SeedArtifact = loadArtifact(),
|
2026-09-17 12:08:03 +03:00
|
|
|
): RudderClient {
|
|
|
|
|
return new RudderClient({
|
2026-08-12 14:02:25 +03:00
|
|
|
baseUrl: artifact.baseUrl,
|
|
|
|
|
projectKey: artifact.projectKey,
|
|
|
|
|
tokenStore: createInMemoryTokenStore(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A device-authenticated client. In Node each call mints a fresh player (ephemeral device id). */
|
2026-09-17 12:08:03 +03:00
|
|
|
export async function freshPlayer(
|
2026-08-12 14:02:25 +03:00
|
|
|
artifact: SeedArtifact = loadArtifact(),
|
2026-09-17 12:08:03 +03:00
|
|
|
): Promise<RudderClient> {
|
|
|
|
|
const client = makeProdClient(artifact);
|
2026-08-12 14:02:25 +03:00
|
|
|
await client.auth.loginWithDevice({ region: 'en', language: 'en' });
|
|
|
|
|
return client;
|
|
|
|
|
}
|