Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/audience/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ export const SESSION_COOKIE = '_imtbl_sid';
export const COOKIE_MAX_AGE_SECONDS = 365 * 24 * 60 * 60 * 2; // 2 years
export const SESSION_MAX_AGE = 30 * 60; // 30 minutes in seconds

export const SESSION_START = 'session_start';
export const SESSION_END = 'session_end';

export const getBaseUrl = (environment: Environment): string => BASE_URLS[environment];
3 changes: 2 additions & 1 deletion packages/audience/core/src/consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export function createConsentManager(
// Purge all queued messages
queue.purge(() => true);
} else if (next === 'anonymous') {
// Strip userId from queued messages
// Remove identify/alias messages and strip userId from the rest
queue.purge((msg: Message) => msg.type === 'identify' || msg.type === 'alias');
queue.transform((msg: Message) => {
if ('userId' in msg) {
const { userId, ...rest } = msg;
Expand Down
2 changes: 2 additions & 0 deletions packages/audience/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export {
COOKIE_NAME,
SESSION_COOKIE,
SESSION_MAX_AGE,
SESSION_START,
SESSION_END,
} from './config';

export { generateId, getTimestamp, isBrowser } from './utils';
Expand Down
4 changes: 2 additions & 2 deletions packages/audience/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@imtbl/audience-sdk",
"description": "Immutable Audience SDK — consent-aware event tracking and identity management",
"name": "@imtbl/audience",
"description": "Immutable Audience — consent-aware event tracking and identity management",
"version": "0.0.0",
"author": "Immutable",
"bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
Expand Down
10 changes: 8 additions & 2 deletions packages/audience/sdk/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// SDK-specific constants.
// Backend endpoints and base URLs come from @imtbl/audience-core.

export const LIBRARY_NAME = '@imtbl/audience-sdk';
// Replaced at build time by esbuild replace plugin
export const LIBRARY_NAME = '@imtbl/audience';
/** Replaced at build time by esbuild replace plugin. */
export const LIBRARY_VERSION = '__SDK_VERSION__';

/** Log prefix for console messages from this package. */
export const LOG_PREFIX = '[audience]';

/** Default consent source when consentSource is not provided in config. */
export const DEFAULT_CONSENT_SOURCE = 'WebSDK';
11 changes: 0 additions & 11 deletions packages/audience/sdk/src/context.test.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/audience/sdk/src/context.ts

This file was deleted.

13 changes: 7 additions & 6 deletions packages/audience/sdk/src/debug.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Message } from '@imtbl/audience-core';
import { DebugLogger } from './debug';
import { LOG_PREFIX } from './config';

describe('DebugLogger', () => {
let logSpy: jest.SpyInstance;
Expand All @@ -22,7 +23,7 @@ describe('DebugLogger', () => {
anonymousId: 'anon-1',
surface: 'web',
context: { library: 'test', libraryVersion: '0.0.0' },
event: 'click',
eventName: 'click',
properties: {},
};

Expand All @@ -42,7 +43,7 @@ describe('DebugLogger', () => {
logger.logEvent('track', stubMessage);

expect(logSpy).toHaveBeenCalledWith(
'[Immutable Audience] track',
`${LOG_PREFIX} track`,
stubMessage,
);
});
Expand All @@ -52,12 +53,12 @@ describe('DebugLogger', () => {

logger.logFlush(true, 5);
expect(logSpy).toHaveBeenCalledWith(
'[Immutable Audience] flush ok (5 messages)',
`${LOG_PREFIX} flush ok (5 messages)`,
);

logger.logFlush(false, 3);
expect(logSpy).toHaveBeenCalledWith(
'[Immutable Audience] flush failed (3 messages)',
`${LOG_PREFIX} flush failed (3 messages)`,
);
});

Expand All @@ -66,7 +67,7 @@ describe('DebugLogger', () => {
logger.logConsent('none', 'full');

expect(logSpy).toHaveBeenCalledWith(
'[Immutable Audience] consent none full',
`${LOG_PREFIX} consent none \u2192 full`,
);
});

Expand All @@ -75,7 +76,7 @@ describe('DebugLogger', () => {
logger.logWarning('something went wrong');

expect(warnSpy).toHaveBeenCalledWith(
'[Immutable Audience] something went wrong',
`${LOG_PREFIX} something went wrong`,
);
});
});
11 changes: 5 additions & 6 deletions packages/audience/sdk/src/debug.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ConsentLevel, Message } from '@imtbl/audience-core';

const PREFIX = '[Immutable Audience]';
import { LOG_PREFIX } from './config';

export class DebugLogger {
private enabled: boolean;
Expand All @@ -12,24 +11,24 @@ export class DebugLogger {
logEvent(method: string, message: Message): void {
if (!this.enabled) return;
// eslint-disable-next-line no-console
console.log(`${PREFIX} ${method}`, message);
console.log(`${LOG_PREFIX} ${method}`, message);
}

logFlush(ok: boolean, count: number): void {
if (!this.enabled) return;
// eslint-disable-next-line no-console
console.log(`${PREFIX} flush ${ok ? 'ok' : 'failed'} (${count} messages)`);
console.log(`${LOG_PREFIX} flush ${ok ? 'ok' : 'failed'} (${count} messages)`);
}

logConsent(from: ConsentLevel, to: ConsentLevel): void {
if (!this.enabled) return;
// eslint-disable-next-line no-console
console.log(`${PREFIX} consent ${from} → ${to}`);
console.log(`${LOG_PREFIX} consent ${from} → ${to}`);
}

logWarning(msg: string): void {
if (!this.enabled) return;
// eslint-disable-next-line no-console
console.warn(`${PREFIX} ${msg}`);
console.warn(`${LOG_PREFIX} ${msg}`);
}
}
6 changes: 3 additions & 3 deletions packages/audience/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type { AudienceSDKConfig } from './types';
export { DebugLogger } from './debug';
export { collectContext } from './context';
export { Audience } from './sdk';
export type { AudienceConfig } from './types';
export type { Environment, ConsentLevel, UserTraits } from '@imtbl/audience-core';
Loading
Loading