@trillboards/ads-sdk 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@trillboards/ads-sdk` will be documented in this file.
4
+
5
+ ## [2.0.0] - 2026-02-14
6
+
7
+ ### Breaking Changes
8
+ - Singleton pattern via `TrillboardsAds.create()` factory -- `init()` is now private
9
+ - All events require typed listeners matching `EventMap`
10
+
11
+ ### Features
12
+ - **Circuit breaker**: Automatic failure detection with configurable thresholds and half-open recovery
13
+ - **Waterfall engine**: Three modes -- `programmatic_only`, `programmatic_then_direct`, `direct_only`
14
+ - **Telemetry**: Real-time fill rate, no-fill, timeout, and error rate tracking
15
+ - **React bindings**: `TrillboardsProvider`, `TrillboardsAdSlot`, `useTrillboardsAds`, `useAdEvents`
16
+ - **React Native bindings**: `TrillboardsWebView` with ref handle, `useTrillboardsNative` hook
17
+ - **Server bindings**: `PartnerClient` with `AudienceClient`, `AnalyticsClient`, `AuctionClient`, `CreativeClient`, `VastTagBuilder`, `TrackingBatch`
18
+ - **NativeBridge**: 10 platform types -- Android, Android-alt, iOS, React Native, Flutter, CTV, Electron, Tauri, postMessage, custom
19
+ - **IndexedDB caching**: Offline ad storage with automatic eviction
20
+ - **IIFE build**: Direct `<script>` tag support via `trillboards-ads.iife.js`
21
+ - **`createAuthenticatedFetch`**: Reusable authenticated HTTP client factory
22
+ - **`once()` on EventEmitter**: One-shot event listener support
23
+
24
+ ### Fixes
25
+ - Double-callback guard in impression tracking
26
+ - React Strict Mode compatibility (proper cleanup in useEffect)
27
+ - WebView XSS prevention in NativeBridge message handling
28
+ - Memory leak in event listeners on destroy
29
+ - `isOffline` state getting stuck after reconnection
30
+ - BidCollector CPM normalization for multi-source auctions
31
+ - Half-open circuit breaker state transition logic
32
+
33
+ ## [1.0.0] - 2026-01-15
34
+
35
+ ### Features
36
+ - Initial release
37
+ - Core ad player with VAST support
38
+ - Basic impression tracking
39
+ - IndexedDB offline caching
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # @trillboards/ads-sdk
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@trillboards/ads-sdk.svg)](https://www.npmjs.com/package/@trillboards/ads-sdk)
4
+ [![license](https://img.shields.io/npm/l/@trillboards/ads-sdk.svg)](https://opensource.org/licenses/MIT)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.3+-blue.svg)](https://www.typescriptlang.org/)
6
+
7
+ Programmatic infrastructure as a service for digital signage -- client, React, React Native, and server bindings.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @trillboards/ads-sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ### Browser (core)
18
+
19
+ ```typescript
20
+ import { TrillboardsAds } from '@trillboards/ads-sdk';
21
+
22
+ const sdk = await TrillboardsAds.create({ deviceId: 'your-device-id' });
23
+ sdk.on('ad_started', (data) => console.log('Ad playing:', data.id));
24
+ sdk.show();
25
+ ```
26
+
27
+ ### React
28
+
29
+ ```tsx
30
+ import { TrillboardsProvider, TrillboardsAdSlot, useTrillboardsAds } from '@trillboards/ads-sdk/react';
31
+
32
+ function App() {
33
+ return (
34
+ <TrillboardsProvider config={{ deviceId: 'your-device-id' }}>
35
+ <TrillboardsAdSlot style={{ width: '100%', height: '100%' }} />
36
+ </TrillboardsProvider>
37
+ );
38
+ }
39
+ ```
40
+
41
+ ### React Native
42
+
43
+ ```tsx
44
+ import { TrillboardsWebView, useTrillboardsNative } from '@trillboards/ads-sdk/react-native';
45
+
46
+ function AdScreen() {
47
+ return <TrillboardsWebView config={{ deviceId: 'your-device-id' }} />;
48
+ }
49
+ ```
50
+
51
+ ### Server (Node.js)
52
+
53
+ ```typescript
54
+ import { PartnerClient } from '@trillboards/ads-sdk/server';
55
+
56
+ const client = new PartnerClient({ apiKey: 'trb_partner_xxx' });
57
+ const audience = await client.audience.getLive('screen-id');
58
+ const analytics = await client.analytics.getScreenDaily('screen-id', {
59
+ startDate: '2026-02-01',
60
+ endDate: '2026-02-14',
61
+ });
62
+ ```
63
+
64
+ ## Configuration
65
+
66
+ The `TrillboardsConfig` interface accepts the following options:
67
+
68
+ | Option | Type | Default | Description |
69
+ |--------|------|---------|-------------|
70
+ | `deviceId` | `string` | required | Device fingerprint |
71
+ | `apiBase` | `string` | `https://api.trillboards.com/v1/partner` | API base URL |
72
+ | `cdnBase` | `string` | `https://cdn.trillboards.com` | CDN base URL |
73
+ | `waterfall` | `WaterfallMode` | `'programmatic_only'` | Ad source priority |
74
+ | `autoStart` | `boolean` | `true` | Start playing on init |
75
+ | `refreshInterval` | `number` | `120000` | Ad refresh interval (ms) |
76
+ | `cacheSize` | `number` | `10` | Max cached ads |
77
+
78
+ ## Events
79
+
80
+ The SDK emits typed events via the `EventMap` interface. Subscribe with `sdk.on(event, listener)` or `sdk.once(event, listener)`.
81
+
82
+ | Event | Description |
83
+ |-------|-------------|
84
+ | `initialized` | SDK has completed initialization |
85
+ | `ads_refreshed` | New ads fetched and ready |
86
+ | `ad_started` | An ad has started playing |
87
+ | `ad_ended` | An ad has finished playing |
88
+ | `ad_error` | An error occurred during ad playback |
89
+ | `programmatic_started` | A programmatic ad has started |
90
+ | `programmatic_ended` | A programmatic ad has ended |
91
+ | `impression_tracked` | An impression was successfully reported |
92
+ | `state_changed` | The SDK state machine transitioned |
93
+ | `offline` | Network connectivity lost |
94
+ | `online` | Network connectivity restored |
95
+
96
+ ## Architecture
97
+
98
+ The SDK is organized around four entry points, each targeting a different runtime:
99
+
100
+ - **Core browser** (`@trillboards/ads-sdk`) -- Full ad player with VAST support, waterfall engine, and telemetry. Works in any browser environment.
101
+ - **React** (`@trillboards/ads-sdk/react`) -- Context provider, ad slot component, and hooks (`useTrillboardsAds`, `useAdEvents`) for React 17+ applications.
102
+ - **React Native** (`@trillboards/ads-sdk/react-native`) -- WebView-based player with native bridge communication and a `useTrillboardsNative` hook.
103
+ - **Server** (`@trillboards/ads-sdk/server`) -- Node.js `PartnerClient` for audience data, analytics, auctions, creatives, VAST tag building, and batch tracking.
104
+
105
+ ### Key internals
106
+
107
+ - **IIFE build**: A `trillboards-ads.iife.js` bundle is produced for direct `<script>` tag usage without a bundler.
108
+ - **Waterfall engine**: Three modes control ad source priority -- `programmatic_only`, `programmatic_then_direct`, and `direct_only`.
109
+ - **Circuit breaker**: Automatic failure detection with configurable thresholds and half-open recovery to avoid hammering failing endpoints.
110
+ - **Telemetry**: Real-time tracking of fill rate, no-fill, timeout, and error rates reported back to the platform.
111
+ - **IndexedDB caching**: Ads are cached offline in IndexedDB with automatic eviction based on `cacheSize`.
112
+ - **NativeBridge**: Supports 10 platform types -- Android, Android-alt, iOS, React Native, Flutter, CTV, Electron, Tauri, postMessage, and custom.
113
+
114
+ ## Server Sub-Clients
115
+
116
+ The `PartnerClient` exposes domain-specific sub-clients:
117
+
118
+ | Sub-client | Description |
119
+ |------------|-------------|
120
+ | `client.audience` | Live audience data, predictions, lookalike screens |
121
+ | `client.analytics` | Daily screen analytics, earnings data |
122
+ | `client.auctions` | Programmatic auction results |
123
+ | `client.creatives` | Creative review, moderation stats |
124
+ | `client.createVastTagBuilder()` | Build VAST tags with targeting parameters |
125
+ | `client.createTrackingBatch()` | Batch impression reporting |
126
+
127
+ ### Example: VAST tag builder
128
+
129
+ ```typescript
130
+ const vastBuilder = client.createVastTagBuilder();
131
+ const tag = await vastBuilder.buildTag({
132
+ deviceId: 'device-001',
133
+ width: 1920,
134
+ height: 1080,
135
+ orientation: 'landscape',
136
+ });
137
+ console.log('VAST URL:', tag.url);
138
+ ```
139
+
140
+ ### Example: Batch tracking
141
+
142
+ ```typescript
143
+ const tracker = client.createTrackingBatch();
144
+ const result = await tracker.report([
145
+ { adId: 'ad-1', impressionId: 'imp-1', deviceId: 'dev-1', duration: 15, completed: true, timestamp: new Date().toISOString() },
146
+ { adId: 'ad-2', impressionId: 'imp-2', deviceId: 'dev-1', duration: 30, completed: true, timestamp: new Date().toISOString() },
147
+ ]);
148
+ console.log('Tracked:', result.tracked);
149
+ ```
150
+
151
+ ## Links
152
+
153
+ - [Developer documentation](https://trillboards.com/developers/partner-sdk)
154
+ - [API reference](https://api.trillboards.com/docs/partner)
155
+
156
+ ## License
157
+
158
+ MIT