Skip to content
Draft
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: 1 addition & 2 deletions crates/js/lib/src/core/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Global configuration storage for the tsjs runtime (mode, logging, etc.).
import { log, LogLevel } from './log';
import type { Config, GamConfig } from './types';
import { RequestMode } from './types';

let CONFIG: Config = { mode: RequestMode.FirstParty };
let CONFIG: Config = { mode: 'render' };

// Lazy import to avoid circular dependencies - GAM integration may not be present
let setGamConfigFn: ((cfg: GamConfig) => void) | null | undefined = undefined;
Expand Down
4 changes: 3 additions & 1 deletion crates/js/lib/src/core/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import type { TsjsApi } from './types';
declare global {
interface Window {
tsjs?: TsjsApi;
pbjs?: TsjsApi;
// pbjs is Prebid.js which has its own types
// eslint-disable-next-line @typescript-eslint/no-explicit-any
pbjs?: any;
}
}

Expand Down
43 changes: 3 additions & 40 deletions crates/js/lib/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// Public tsjs core bundle: sets up the global API, queue, and default methods.
export type { AdUnit, TsjsApi } from './types';
// Public tsjs core bundle: sets up the global API.
export type { TsjsApi } from './types';
import type { TsjsApi } from './types';
import { addAdUnits } from './registry';
import { renderAdUnit, renderAllAdUnits } from './render';
import { log } from './log';
import { setConfig, getConfig } from './config';
import { requestAds } from './request';
import { installQueue } from './queue';

const VERSION = '0.1.0';

Expand All @@ -15,45 +11,12 @@ const w: Window & { tsjs?: TsjsApi } =
tsjs?: TsjsApi;
}) || ({} as Window & { tsjs?: TsjsApi });

// Collect existing tsjs queued fns before we overwrite
const pending: Array<() => void> = Array.isArray(w.tsjs?.que) ? [...w.tsjs.que] : [];

// Create API and attach methods
const api: TsjsApi = (w.tsjs ??= {} as TsjsApi);
api.version = VERSION;
api.addAdUnits = addAdUnits;
api.renderAdUnit = renderAdUnit;
api.renderAllAdUnits = () => renderAllAdUnits();
api.log = log;
api.setConfig = setConfig;
api.getConfig = getConfig;
// Provide core requestAds API
api.requestAds = requestAds;
// Point global tsjs
w.tsjs = api;

// Single shared queue
installQueue(api, w);

// Flush prior queued callbacks
for (const fn of pending) {
try {
if (typeof fn === 'function') {
fn.call(api);
log.debug('queue: flushed callback');
}
} catch {
/* ignore queued callback error */
}
}

log.info('tsjs initialized', {
methods: [
'setConfig',
'getConfig',
'requestAds',
'addAdUnits',
'renderAdUnit',
'renderAllAdUnits',
],
});
log.info('tsjs initialized', { version: VERSION });
23 changes: 0 additions & 23 deletions crates/js/lib/src/core/queue.ts

This file was deleted.

36 changes: 0 additions & 36 deletions crates/js/lib/src/core/registry.ts

This file was deleted.

181 changes: 0 additions & 181 deletions crates/js/lib/src/core/render.ts

This file was deleted.

Loading