@splash-tech/jackpot-sdk 2.0.2 → 3.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.
Files changed (42) hide show
  1. package/README.md +123 -21
  2. package/dist/clients/b2tech/B2TechFooterWidget.d.ts +11 -0
  3. package/dist/clients/b2tech/B2TechFooterWidget.js +74 -0
  4. package/dist/clients/b2tech/types.d.ts +6 -0
  5. package/dist/clients/defaultClient/DefaultClientFooterWidget.d.ts +9 -0
  6. package/dist/clients/defaultClient/DefaultClientFooterWidget.js +53 -0
  7. package/dist/clients/defaultClient/DefaultClientWinWidget.d.ts +9 -0
  8. package/dist/clients/defaultClient/DefaultClientWinWidget.js +95 -0
  9. package/dist/clients/defaultClient/types.d.ts +14 -0
  10. package/dist/clients/registry.d.ts +24 -0
  11. package/dist/clients/registry.js +28 -0
  12. package/dist/core/BaseWidget.d.ts +24 -0
  13. package/dist/core/BaseWidget.js +96 -0
  14. package/dist/core/FooterWidgetBase.d.ts +18 -0
  15. package/dist/core/FooterWidgetBase.js +71 -0
  16. package/dist/core/WinWidgetBase.d.ts +12 -0
  17. package/dist/core/WinWidgetBase.js +47 -0
  18. package/dist/core/types.d.ts +21 -0
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +11 -25
  21. package/dist/shared/validation.d.ts +1 -0
  22. package/dist/shared/validation.js +11 -0
  23. package/dist/types.d.ts +6 -23
  24. package/package.json +9 -1
  25. package/dist/widgets/BaseWidget.d.ts +0 -28
  26. package/dist/widgets/BaseWidget.js +0 -104
  27. package/dist/widgets/footerWidget/FooterWidget.d.ts +0 -16
  28. package/dist/widgets/footerWidget/FooterWidget.js +0 -110
  29. package/dist/widgets/footerWidget/types/data.d.ts +0 -12
  30. package/dist/widgets/footerWidget/types/events.d.ts +0 -15
  31. package/dist/widgets/footerWidget/types/events.js +0 -14
  32. package/dist/widgets/shared/types.d.ts +0 -18
  33. package/dist/widgets/winWidget/WinWidget copy.d.ts +0 -13
  34. package/dist/widgets/winWidget/WinWidget copy.js +0 -131
  35. package/dist/widgets/winWidget/WinWidget.d.ts +0 -14
  36. package/dist/widgets/winWidget/WinWidget.js +0 -134
  37. package/dist/widgets/winWidget/types/data.d.ts +0 -12
  38. package/dist/widgets/winWidget/types/events.d.ts +0 -10
  39. package/dist/widgets/winWidget/types/events.js +0 -11
  40. /package/dist/{widgets/shared → clients/b2tech}/types.js +0 -0
  41. /package/dist/{widgets/footerWidget/types/data.js → clients/defaultClient/types.js} +0 -0
  42. /package/dist/{widgets/winWidget/types/data.js → core/types.js} +0 -0
package/README.md CHANGED
@@ -22,23 +22,28 @@ npm install @splash-tech/jackpot-sdk
22
22
 
23
23
  # Quick Start
24
24
 
25
- ## Launch Footer Widget
25
+ The SDK is initialized once with your **clientId**. The clientId determines which widget app is loaded, which launch options are available, and which events are emitted — all fully typed.
26
26
 
27
27
  ```ts
28
- import { splashJackpot } from '@splash-tech/jackpot-sdk';
28
+ import { createSplashJackpot } from '@splash-tech/jackpot-sdk';
29
+
30
+ const splashJackpot = createSplashJackpot({
31
+ client: 'defaultClient',
32
+ env: 'production',
33
+ });
34
+ ```
35
+
36
+ ## Launch Footer Widget
29
37
 
38
+ ```ts
30
39
  splashJackpot.footerWidget.launch({
31
40
  data: widgetData,
32
41
  });
33
42
  ```
34
43
 
35
- ---
36
-
37
44
  ## Launch Win Widget
38
45
 
39
46
  ```ts
40
- import { splashJackpot } from '@splash-tech/jackpot-sdk';
41
-
42
47
  splashJackpot.winWidget.launch({
43
48
  data: winData,
44
49
  });
@@ -46,23 +51,53 @@ splashJackpot.winWidget.launch({
46
51
 
47
52
  ---
48
53
 
54
+ # Initialization Options
55
+
56
+ | Option | Type | Default | Description |
57
+ | ------ | ------ | ---------- | ---------------------------------------------------------- |
58
+ | client | string | (required) | Client integration to use (`defaultClient`, `b2tech`) |
59
+ | env | string | production | SDK environment (`local`, `dev`, `staging`, `production`) |
60
+
61
+ An unknown `client` throws at initialization.
62
+
63
+ ---
64
+
49
65
  # Widget Launch Parameters
50
66
 
51
- | Parameter | Type | Default | Description |
52
- | --------- | ------ | ------------- | --------------------------------------------------------- |
53
- | data | object | null | Widget data from Splash backend |
54
- | container | string | document.body | CSS selector where widget will be injected |
55
- | mode | string | production | SDK environment (`local`, `dev`, `staging`, `production`) |
56
- | maxWidth | string | '1300px' | Maximum width of the footer widget |
67
+ Both widgets accept the same base parameters. Presentation options are grouped under `config`, and the available `config` fields depend on the clientId chosen at initialization.
68
+
69
+ | Parameter | Type | Default | Description |
70
+ | --------- | ------ | ------- | ------------------------------------------ |
71
+ | data | object | null | Widget data from Splash backend |
72
+ | config | object | — | Client-specific presentation options below |
73
+
74
+ ## Footer Widget `config`
75
+
76
+ | Field | Type | Default | Description |
77
+ | --------- | ----------------- | ------------- | ------------------------------------------ |
78
+ | position | 'top' \| 'bottom' | per client | Where the footer bar is docked |
79
+ | maxWidth | string | per client | Maximum width of the footer widget |
80
+ | container | string | document.body | CSS selector where widget will be injected |
81
+
82
+ ## Win Widget `config`
83
+
84
+ | Field | Type | Default | Description |
85
+ | --------- | --------------------- | ------------- | ------------------------------------------------------- |
86
+ | animation | 'wheel' \| 'airplane' | 'wheel' | Win animation to play (`defaultClient` only) |
87
+ | container | string | document.body | CSS selector where widget will be injected |
88
+
89
+ Clients may have additional `config` fields; TypeScript only offers the fields valid for your clientId.
57
90
 
58
91
  Example:
59
92
 
60
93
  ```ts
61
94
  splashJackpot.footerWidget.launch({
62
95
  data: widgetData,
63
- container: '#game-container',
64
- mode: 'production',
65
- maxWidth: '100%',
96
+ config: {
97
+ position: 'bottom',
98
+ maxWidth: '100%',
99
+ container: '#game-container',
100
+ },
66
101
  });
67
102
  ```
68
103
 
@@ -70,7 +105,9 @@ splashJackpot.footerWidget.launch({
70
105
 
71
106
  # Widget API
72
107
 
73
- ## Footer Widget
108
+ Every client gets the core API. On top of it, a client may have extra methods defined by the SDK for that clientId — TypeScript only offers the methods valid for your clientId, and integrators cannot add methods of their own.
109
+
110
+ ## Footer Widget (core, all clients)
74
111
 
75
112
  - `launch()` – launch widget
76
113
  - `updateData()` – update jackpot values
@@ -80,7 +117,11 @@ splashJackpot.footerWidget.launch({
80
117
  - `removeAllEventListeners()` – remove all listeners
81
118
  - `destroy()` – remove widget from DOM
82
119
 
83
- ## Win Widget
120
+ ## Footer Widget (`b2tech` client)
121
+
122
+ - `helloWorld()` – placeholder client-specific method
123
+
124
+ ## Win Widget (core, all clients)
84
125
 
85
126
  - `launch()`
86
127
  - `isLaunched()`
@@ -93,7 +134,9 @@ splashJackpot.footerWidget.launch({
93
134
 
94
135
  # Events
95
136
 
96
- ## Footer Widget
137
+ Events are client-specific; TypeScript only offers the event names valid for your clientId.
138
+
139
+ ## Footer Widget (`defaultClient`)
97
140
 
98
141
  | Event | Description |
99
142
  | ----------------- | ---------------------------------- |
@@ -101,6 +144,14 @@ splashJackpot.footerWidget.launch({
101
144
  | hidePopup | Footer popup closed |
102
145
  | participateChange | User toggled jackpot participation |
103
146
 
147
+ ## Footer Widget (`b2tech` client)
148
+
149
+ | Event | Description |
150
+ | ------------------ | ------------------------------- |
151
+ | panelOpen | Footer panel opened |
152
+ | panelClose | Footer panel closed |
153
+ | subscriptionChange | User toggled their subscription |
154
+
104
155
  Example:
105
156
 
106
157
  ```ts
@@ -109,14 +160,18 @@ splashJackpot.footerWidget.addEventListener('showPopup', () => {
109
160
  });
110
161
  ```
111
162
 
112
- ---
113
-
114
- ## Win Widget
163
+ ## Win Widget (`defaultClient`)
115
164
 
116
165
  | Event | Description |
117
166
  | ----- | ----------------- |
118
167
  | close | Win widget closed |
119
168
 
169
+ ## Win Widget (`b2tech` client)
170
+
171
+ | Event | Description |
172
+ | --------- | -------------------- |
173
+ | dismissed | Win widget dismissed |
174
+
120
175
  ---
121
176
 
122
177
  # Cleanup
@@ -130,6 +185,53 @@ splashJackpot.footerWidget.destroy();
130
185
 
131
186
  ---
132
187
 
188
+ # Migrating from 2.x
189
+
190
+ ```ts
191
+ // 2.x
192
+ import { splashJackpot } from '@splash-tech/jackpot-sdk';
193
+
194
+ splashJackpot.footerWidget.launch({
195
+ data: widgetData,
196
+ mode: 'production',
197
+ position: 'bottom',
198
+ maxWidth: '100%',
199
+ container: '#game-container',
200
+ });
201
+
202
+ // 3.x
203
+ import { createSplashJackpot } from '@splash-tech/jackpot-sdk';
204
+
205
+ const splashJackpot = createSplashJackpot({
206
+ client: 'defaultClient',
207
+ env: 'production',
208
+ });
209
+
210
+ splashJackpot.footerWidget.launch({
211
+ data: widgetData,
212
+ config: {
213
+ position: 'bottom',
214
+ maxWidth: '100%',
215
+ container: '#game-container',
216
+ },
217
+ });
218
+ ```
219
+
220
+ - `client` and `env` moved from `launch()` to `createSplashJackpot()`.
221
+ - Presentation options (`position`, `maxWidth`, `animation`, `container`) moved under `config`.
222
+ - Everything else (`updateData`, events, `destroy`) is unchanged.
223
+
224
+ ---
225
+
226
+ # Adding a New Client (SDK maintainers)
227
+
228
+ 1. Create `src/clients/<name>/` with `client.ts`, `FooterWidgetProtocol.ts`, `WinWidgetProtocol.ts`, and `types.ts` (launch `config` shapes, event maps, and host-facing method interfaces — empty interfaces if the client has none).
229
+ 2. Implement the client's extra host-facing methods in each protocol's `createMethods(ctx)` factory. `ctx` is a controller exposing `sendToChild`, `expandIframe`/`collapseIframe` (footer), `emit`, `destroy`, and `isLaunched`. Keep the return type annotation on `createMethods` so methods outside the declared interface fail compilation. Core behavior (`launch`, `updateData`, events, `destroy`) lives in the widgets and is not client-definable.
230
+ 3. For the win widget, optionally provide `presentation` (`applyLaunchPresentation`/`cleanupPresentation`) on the protocol for a custom enter/exit animation; omit it for a plain iframe.
231
+ 4. Register it in `src/clients/registry.ts`: add the id to `ClientId`, the config to `clientRegistry`, and the types to the six type maps. Missing entries fail compilation.
232
+
233
+ ---
234
+
133
235
  # Documentation
134
236
 
135
237
  For full integration instructions, backend communication flow, and advanced usage, refer to the complete [documentation](https://www.notion.so/Jackpot-Widgets-320975a6f2ab80118284e6165d569843?pvs=25#325975a6f2ab8096be15dfc7eda06028).
@@ -0,0 +1,11 @@
1
+ import { FooterWidgetBase } from '../../core/FooterWidgetBase';
2
+ import { B2TechFooterWidgetConfig, B2TechFooterWidgetEvents } from './types';
3
+ export declare class B2TechFooterWidget extends FooterWidgetBase<B2TechFooterWidgetConfig, B2TechFooterWidgetEvents> {
4
+ protected readonly route = "/footer-widget";
5
+ protected readonly height = "64px";
6
+ protected sendInitialData(): void;
7
+ protected sendDataUpdate(partialData: object): void;
8
+ protected handleChildMessage(type: string | undefined): boolean;
9
+ showWinPopup(data: unknown): void;
10
+ hideWinPopup(): void;
11
+ }
@@ -0,0 +1,74 @@
1
+ import { FooterWidgetBase } from '../../core/FooterWidgetBase';
2
+ var IncomingEvent;
3
+ (function (IncomingEvent) {
4
+ IncomingEvent["footerWidgetLoaded"] = "jackpot-b2tech-footer-widget-loaded";
5
+ IncomingEvent["showPopup"] = "jackpot-b2tech-footer-widget-popup-show";
6
+ IncomingEvent["hidePopup"] = "jackpot-b2tech-footer-widget-popup-hide";
7
+ IncomingEvent["winPopupClosed"] = "jackpot-b2tech-footer-widget-win-popup-closed";
8
+ })(IncomingEvent || (IncomingEvent = {}));
9
+ var OutgoingEvent;
10
+ (function (OutgoingEvent) {
11
+ OutgoingEvent["footerWidgetDataInitial"] = "jackpot-b2tech-footer-widget-data-initial";
12
+ OutgoingEvent["footerWidgetDataUpdated"] = "jackpot-b2tech-footer-widget-data-updated";
13
+ OutgoingEvent["winPopupShow"] = "jackpot-b2tech-footer-widget-win-popup-show";
14
+ OutgoingEvent["winPopupHide"] = "jackpot-b2tech-footer-widget-win-popup-hide";
15
+ })(OutgoingEvent || (OutgoingEvent = {}));
16
+ export class B2TechFooterWidget extends FooterWidgetBase {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.route = '/footer-widget';
20
+ this.height = '64px';
21
+ }
22
+ sendInitialData() {
23
+ this.sendToChild({
24
+ type: OutgoingEvent.footerWidgetDataInitial,
25
+ data: this.data,
26
+ config: this.config,
27
+ });
28
+ }
29
+ sendDataUpdate(partialData) {
30
+ this.sendToChild({
31
+ type: OutgoingEvent.footerWidgetDataUpdated,
32
+ data: partialData,
33
+ });
34
+ }
35
+ handleChildMessage(type) {
36
+ switch (type) {
37
+ case IncomingEvent.footerWidgetLoaded:
38
+ this.sendInitialData();
39
+ return true;
40
+ case IncomingEvent.showPopup:
41
+ this.expandIframe();
42
+ return true;
43
+ case IncomingEvent.hidePopup:
44
+ this.collapseIframe();
45
+ return true;
46
+ case IncomingEvent.winPopupClosed:
47
+ this.collapseIframe();
48
+ this.emit('winPopupClosed');
49
+ return true;
50
+ default:
51
+ return false;
52
+ }
53
+ }
54
+ showWinPopup(data) {
55
+ if (!this.isLaunched()) {
56
+ console.warn('Footer widget must be launched before showWinPopup');
57
+ return;
58
+ }
59
+ this.sendToChild({
60
+ type: OutgoingEvent.winPopupShow,
61
+ data,
62
+ });
63
+ this.expandIframe();
64
+ }
65
+ hideWinPopup() {
66
+ if (!this.isLaunched())
67
+ return;
68
+ this.sendToChild({
69
+ type: OutgoingEvent.winPopupHide,
70
+ data: null,
71
+ });
72
+ this.collapseIframe();
73
+ }
74
+ }
@@ -0,0 +1,6 @@
1
+ import { FooterWidgetBaseConfig } from '../../core/types';
2
+ export interface B2TechFooterWidgetConfig extends FooterWidgetBaseConfig {
3
+ }
4
+ export interface B2TechFooterWidgetEvents {
5
+ winPopupClosed: void;
6
+ }
@@ -0,0 +1,9 @@
1
+ import { FooterWidgetBase } from '../../core/FooterWidgetBase';
2
+ import { DefaultClientFooterWidgetConfig, DefaultClientFooterWidgetEvents } from './types';
3
+ export declare class DefaultClientFooterWidget extends FooterWidgetBase<DefaultClientFooterWidgetConfig, DefaultClientFooterWidgetEvents> {
4
+ protected readonly route = "/footer-widget";
5
+ protected readonly height = "50px";
6
+ protected sendInitialData(): void;
7
+ protected sendDataUpdate(partialData: object): void;
8
+ protected handleChildMessage(type: string | undefined): boolean;
9
+ }
@@ -0,0 +1,53 @@
1
+ import { FooterWidgetBase } from '../../core/FooterWidgetBase';
2
+ var IncomingEvent;
3
+ (function (IncomingEvent) {
4
+ IncomingEvent["footerWidgetLoaded"] = "jackpot-default-footer-widget-loaded";
5
+ IncomingEvent["participateChange"] = "jackpot-default-footer-widget-participate-change";
6
+ IncomingEvent["showPopup"] = "jackpot-default-footer-widget-popup-show";
7
+ IncomingEvent["hidePopup"] = "jackpot-default-footer-widget-popup-hide";
8
+ })(IncomingEvent || (IncomingEvent = {}));
9
+ var OutgoingEvent;
10
+ (function (OutgoingEvent) {
11
+ OutgoingEvent["footerWidgetDataInitial"] = "jackpot-default-footer-widget-data-initial";
12
+ OutgoingEvent["footerWidgetDataUpdated"] = "jackpot-default-footer-widget-data-updated";
13
+ })(OutgoingEvent || (OutgoingEvent = {}));
14
+ export class DefaultClientFooterWidget extends FooterWidgetBase {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.route = '/footer-widget';
18
+ this.height = '50px';
19
+ }
20
+ sendInitialData() {
21
+ this.sendToChild({
22
+ type: OutgoingEvent.footerWidgetDataInitial,
23
+ data: this.data,
24
+ config: this.config,
25
+ });
26
+ }
27
+ sendDataUpdate(partialData) {
28
+ this.sendToChild({
29
+ type: OutgoingEvent.footerWidgetDataUpdated,
30
+ data: partialData,
31
+ });
32
+ }
33
+ handleChildMessage(type) {
34
+ switch (type) {
35
+ case IncomingEvent.footerWidgetLoaded:
36
+ this.sendInitialData();
37
+ return true;
38
+ case IncomingEvent.showPopup:
39
+ this.emit('showPopup');
40
+ this.expandIframe();
41
+ return true;
42
+ case IncomingEvent.hidePopup:
43
+ this.emit('hidePopup');
44
+ this.collapseIframe();
45
+ return true;
46
+ case IncomingEvent.participateChange:
47
+ this.emit('participateChange');
48
+ return true;
49
+ default:
50
+ return false;
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,9 @@
1
+ import { WinWidgetBase } from '../../core/WinWidgetBase';
2
+ import { DefaultClientWinWidgetConfig, DefaultClientWinWidgetEvents } from './types';
3
+ export declare class DefaultClientWinWidget extends WinWidgetBase<DefaultClientWinWidgetConfig, DefaultClientWinWidgetEvents> {
4
+ protected get route(): string;
5
+ protected sendInitialData(): void;
6
+ protected handleChildMessage(type: string | undefined): boolean;
7
+ protected applyLaunchAnimation(iframe: HTMLIFrameElement): void;
8
+ protected cleanupLaunchAnimation(): void;
9
+ }
@@ -0,0 +1,95 @@
1
+ import { WinWidgetBase } from '../../core/WinWidgetBase';
2
+ var IncomingEvent;
3
+ (function (IncomingEvent) {
4
+ IncomingEvent["winWidgetLoaded"] = "jackpot-default-win-widget-loaded";
5
+ IncomingEvent["winWidgetClose"] = "jackpot-default-win-widget-close";
6
+ })(IncomingEvent || (IncomingEvent = {}));
7
+ var OutgoingEvent;
8
+ (function (OutgoingEvent) {
9
+ OutgoingEvent["winWidgetDataInitial"] = "jackpot-default-win-widget-data-initial";
10
+ })(OutgoingEvent || (OutgoingEvent = {}));
11
+ export class DefaultClientWinWidget extends WinWidgetBase {
12
+ get route() {
13
+ var _a;
14
+ return `/win-animation-widget?animation=${(_a = this.config.animation) !== null && _a !== void 0 ? _a : 'wheel'}`;
15
+ }
16
+ sendInitialData() {
17
+ this.sendToChild({
18
+ type: OutgoingEvent.winWidgetDataInitial,
19
+ data: this.data,
20
+ config: this.config,
21
+ });
22
+ }
23
+ handleChildMessage(type) {
24
+ switch (type) {
25
+ case IncomingEvent.winWidgetLoaded:
26
+ this.sendInitialData();
27
+ return true;
28
+ case IncomingEvent.winWidgetClose:
29
+ this.destroy();
30
+ this.emit('close');
31
+ return true;
32
+ default:
33
+ return false;
34
+ }
35
+ }
36
+ applyLaunchAnimation(iframe) {
37
+ const targetContainer = this.container
38
+ ? document.querySelector(this.container)
39
+ : document.body;
40
+ if (!targetContainer) {
41
+ console.error(`Failed to show win widget. Container "${this.container}" not found`);
42
+ return;
43
+ }
44
+ const isCustomContainer = !!this.container;
45
+ if (isCustomContainer) {
46
+ const style = window.getComputedStyle(targetContainer);
47
+ if (style.position === 'static') {
48
+ targetContainer.style.position = 'relative';
49
+ }
50
+ }
51
+ const container = document.createElement('div');
52
+ container.dataset.winWidget = 'container';
53
+ Object.assign(container.style, {
54
+ position: isCustomContainer ? 'absolute' : 'fixed',
55
+ inset: '0',
56
+ width: '100%',
57
+ height: '100%',
58
+ overflow: 'hidden',
59
+ zIndex: '99999999', // 8
60
+ clipPath: 'circle(0% at 50% 50%)',
61
+ transition: 'clip-path 1.2s cubic-bezier(0.22, 1, 0.36, 1)',
62
+ });
63
+ targetContainer.appendChild(container);
64
+ container.appendChild(iframe);
65
+ const overlay = document.createElement('div');
66
+ overlay.dataset.winWidget = 'overlay';
67
+ Object.assign(overlay.style, {
68
+ position: isCustomContainer ? 'absolute' : 'fixed',
69
+ inset: '0',
70
+ width: '100%',
71
+ height: '100%',
72
+ background: 'rgba(0,0,0,0)',
73
+ zIndex: '9999999', // 7
74
+ backdropFilter: 'blur(0px)',
75
+ transition: 'background 0.8s ease, backdrop-filter 0.8s ease',
76
+ });
77
+ targetContainer.appendChild(overlay);
78
+ setTimeout(() => {
79
+ overlay.style.background = 'rgba(0,0,0,0.4)';
80
+ overlay.style.backdropFilter = 'blur(8px)';
81
+ }, 200);
82
+ setTimeout(() => {
83
+ container.style.clipPath = 'circle(150% at 50% 50%)';
84
+ }, 1000);
85
+ this.setLaunched(true);
86
+ }
87
+ cleanupLaunchAnimation() {
88
+ var _a, _b;
89
+ const root = this.container
90
+ ? document.querySelector(this.container) || document
91
+ : document;
92
+ (_a = root.querySelector('[data-win-widget="overlay"]')) === null || _a === void 0 ? void 0 : _a.remove();
93
+ (_b = root.querySelector('[data-win-widget="container"]')) === null || _b === void 0 ? void 0 : _b.remove();
94
+ }
95
+ }
@@ -0,0 +1,14 @@
1
+ import { FooterWidgetBaseConfig, WinWidgetBaseConfig } from '../../core/types';
2
+ export interface DefaultClientFooterWidgetConfig extends FooterWidgetBaseConfig {
3
+ }
4
+ export interface DefaultClientWinWidgetConfig extends WinWidgetBaseConfig {
5
+ animation?: 'wheel' | 'airplane';
6
+ }
7
+ export interface DefaultClientFooterWidgetEvents {
8
+ participateChange: void;
9
+ showPopup: void;
10
+ hidePopup: void;
11
+ }
12
+ export interface DefaultClientWinWidgetEvents {
13
+ close: void;
14
+ }
@@ -0,0 +1,24 @@
1
+ import { SDKEnv } from '../core/types';
2
+ import { B2TechFooterWidget } from './b2tech/B2TechFooterWidget';
3
+ import { DefaultClientFooterWidget } from './defaultClient/DefaultClientFooterWidget';
4
+ import { DefaultClientWinWidget } from './defaultClient/DefaultClientWinWidget';
5
+ export type ClientId = 'defaultClient' | 'b2tech';
6
+ export interface DefaultClientWidgets {
7
+ footerWidget: DefaultClientFooterWidget;
8
+ winWidget: DefaultClientWinWidget;
9
+ }
10
+ export interface B2TechWidgets {
11
+ footerWidget: B2TechFooterWidget;
12
+ }
13
+ export interface ClientWidgets {
14
+ defaultClient: DefaultClientWidgets;
15
+ b2tech: B2TechWidgets;
16
+ }
17
+ interface ClientDefinition<C extends ClientId> {
18
+ baseUrls: Record<SDKEnv, string>;
19
+ createWidgets: (origin: string) => ClientWidgets[C];
20
+ }
21
+ export declare const clientRegistry: {
22
+ [K in ClientId]: ClientDefinition<K>;
23
+ };
24
+ export {};
@@ -0,0 +1,28 @@
1
+ import { B2TechFooterWidget } from './b2tech/B2TechFooterWidget';
2
+ import { DefaultClientFooterWidget } from './defaultClient/DefaultClientFooterWidget';
3
+ import { DefaultClientWinWidget } from './defaultClient/DefaultClientWinWidget';
4
+ export const clientRegistry = {
5
+ defaultClient: {
6
+ baseUrls: {
7
+ local: 'http://localhost:4741',
8
+ dev: 'https://jackpot-widget-dev.splash.tech',
9
+ staging: 'https://jackpot-widget-staging.splash.tech',
10
+ production: 'https://jackpot-widget.splash.tech',
11
+ },
12
+ createWidgets: (origin) => ({
13
+ footerWidget: new DefaultClientFooterWidget(origin),
14
+ winWidget: new DefaultClientWinWidget(origin),
15
+ }),
16
+ },
17
+ b2tech: {
18
+ baseUrls: {
19
+ local: 'http://localhost:4742',
20
+ dev: 'https://jackpot-widget-b2tech-dev.splash.tech',
21
+ staging: 'https://jackpot-widget-b2tech-staging.splash.tech',
22
+ production: 'https://jackpot-widget-b2tech.splash.tech',
23
+ },
24
+ createWidgets: (origin) => ({
25
+ footerWidget: new B2TechFooterWidget(origin),
26
+ }),
27
+ },
28
+ };
@@ -0,0 +1,24 @@
1
+ import { ChildMessage, InitialChildMessage, WidgetEventHandler } from './types';
2
+ export declare abstract class BaseWidget<TConfig, TEvents> {
3
+ protected readonly childAppOrigin: string;
4
+ protected iframe: HTMLIFrameElement | null;
5
+ protected config: TConfig;
6
+ protected data: unknown;
7
+ private launched;
8
+ private listeners;
9
+ constructor(childAppOrigin: string);
10
+ protected abstract handleChildMessage(type: string | undefined): boolean;
11
+ isLaunched(): boolean;
12
+ addEventListener(event: keyof TEvents & string, handler: WidgetEventHandler): void;
13
+ removeEventListener(event: keyof TEvents & string, handler: WidgetEventHandler): void;
14
+ removeAllEventListeners(): void;
15
+ protected emit(event: keyof TEvents & string): void;
16
+ protected setLaunched(launched: boolean): void;
17
+ protected createIframe(): HTMLIFrameElement;
18
+ protected appendIframe(iframe: HTMLIFrameElement, container?: string): void;
19
+ protected removeIframe(): void;
20
+ protected sendToChild(message: ChildMessage | InitialChildMessage<TConfig>): void;
21
+ protected startListening(): void;
22
+ protected stopListening(): void;
23
+ private childMessageHandler;
24
+ }
@@ -0,0 +1,96 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ export class BaseWidget {
13
+ constructor(childAppOrigin) {
14
+ this.childAppOrigin = childAppOrigin;
15
+ this.iframe = null;
16
+ this.config = {};
17
+ this.launched = false;
18
+ this.listeners = new Map();
19
+ this.childMessageHandler = (event) => {
20
+ var _a, _b;
21
+ if (!((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.src))
22
+ return;
23
+ if (event.origin !== this.childAppOrigin)
24
+ return;
25
+ this.handleChildMessage((_b = event.data) === null || _b === void 0 ? void 0 : _b.type);
26
+ };
27
+ }
28
+ isLaunched() {
29
+ return this.launched;
30
+ }
31
+ addEventListener(event, handler) {
32
+ if (!this.listeners.has(event)) {
33
+ this.listeners.set(event, []);
34
+ }
35
+ this.listeners.get(event).push(handler);
36
+ }
37
+ removeEventListener(event, handler) {
38
+ const handlers = this.listeners.get(event);
39
+ if (!handlers)
40
+ return;
41
+ this.listeners.set(event, handlers.filter((h) => h !== handler));
42
+ }
43
+ removeAllEventListeners() {
44
+ this.listeners.clear();
45
+ }
46
+ emit(event) {
47
+ const handlers = this.listeners.get(event);
48
+ handlers === null || handlers === void 0 ? void 0 : handlers.forEach((handler) => handler());
49
+ }
50
+ setLaunched(launched) {
51
+ this.launched = launched;
52
+ }
53
+ createIframe() {
54
+ const iframe = document.createElement('iframe');
55
+ iframe.style.border = 'none';
56
+ iframe.style.position = 'fixed';
57
+ iframe.style.zIndex = '999999'; // 6
58
+ return iframe;
59
+ }
60
+ appendIframe(iframe, container) {
61
+ const targetContainer = container
62
+ ? document.querySelector(container)
63
+ : document.body;
64
+ if (!targetContainer) {
65
+ console.error(`Container "${container}" not found`);
66
+ document.body.appendChild(iframe);
67
+ }
68
+ else {
69
+ if (container) {
70
+ iframe.style.position = 'absolute';
71
+ targetContainer.style.position = 'relative';
72
+ }
73
+ targetContainer.appendChild(iframe);
74
+ }
75
+ }
76
+ removeIframe() {
77
+ var _a;
78
+ (_a = this.iframe) === null || _a === void 0 ? void 0 : _a.remove();
79
+ this.iframe = null;
80
+ this.launched = false;
81
+ this.config = {};
82
+ }
83
+ sendToChild(message) {
84
+ var _a;
85
+ if (((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) && message.data !== undefined) {
86
+ const { type } = message, payload = __rest(message, ["type"]);
87
+ this.iframe.contentWindow.postMessage({ type, payload }, this.childAppOrigin);
88
+ }
89
+ }
90
+ startListening() {
91
+ window.addEventListener('message', this.childMessageHandler);
92
+ }
93
+ stopListening() {
94
+ window.removeEventListener('message', this.childMessageHandler);
95
+ }
96
+ }