@splash-tech/jackpot-sdk 2.0.2 → 3.0.1

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
@@ -0,0 +1,18 @@
1
+ import { BaseWidget } from './BaseWidget';
2
+ import { FooterWidgetBaseConfig, WidgetLaunchParams } from './types';
3
+ export declare abstract class FooterWidgetBase<TConfig extends FooterWidgetBaseConfig, TEvents> extends BaseWidget<TConfig, TEvents> {
4
+ protected abstract readonly route: string;
5
+ protected abstract readonly height: string;
6
+ protected container: string;
7
+ protected position: "top" | "bottom";
8
+ protected maxWidth: string;
9
+ protected abstract sendInitialData(): void;
10
+ protected abstract sendDataUpdate(partialData: object): void;
11
+ launch(params: WidgetLaunchParams<TConfig>): void;
12
+ updateData(partialData: object): void;
13
+ destroy(): void;
14
+ protected styleIframe(iframe: HTMLIFrameElement): HTMLIFrameElement;
15
+ protected expandIframe(): void;
16
+ protected collapseIframe(): void;
17
+ private setIframeHeight;
18
+ }
@@ -0,0 +1,71 @@
1
+ import { validateNonEmptyObject } from '../shared/validation';
2
+ import { BaseWidget } from './BaseWidget';
3
+ const defaults = {
4
+ container: '',
5
+ position: 'bottom',
6
+ maxWidth: '1300px',
7
+ };
8
+ export class FooterWidgetBase extends BaseWidget {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.container = defaults.container;
12
+ this.position = defaults.position;
13
+ this.maxWidth = defaults.maxWidth;
14
+ }
15
+ launch(params) {
16
+ var _a, _b, _c, _d;
17
+ if (this.isLaunched()) {
18
+ console.warn('Footer widget is already launched');
19
+ return;
20
+ }
21
+ this.config = (_a = params.config) !== null && _a !== void 0 ? _a : {};
22
+ this.data = params.data;
23
+ this.container = (_b = this.config.container) !== null && _b !== void 0 ? _b : defaults.container;
24
+ this.position = (_c = this.config.position) !== null && _c !== void 0 ? _c : defaults.position;
25
+ this.maxWidth = (_d = this.config.maxWidth) !== null && _d !== void 0 ? _d : defaults.maxWidth;
26
+ this.iframe = this.createIframe();
27
+ this.iframe = this.styleIframe(this.iframe);
28
+ this.iframe.src = `${this.childAppOrigin}${this.route}`;
29
+ this.appendIframe(this.iframe, this.container);
30
+ this.setLaunched(true);
31
+ this.startListening();
32
+ }
33
+ updateData(partialData) {
34
+ if (!validateNonEmptyObject(partialData, 'footerWidget.updateData'))
35
+ return;
36
+ this.sendDataUpdate(partialData);
37
+ }
38
+ destroy() {
39
+ this.container = defaults.container;
40
+ this.position = defaults.position;
41
+ this.maxWidth = defaults.maxWidth;
42
+ this.stopListening();
43
+ this.removeIframe();
44
+ }
45
+ styleIframe(iframe) {
46
+ iframe.style.left = '0';
47
+ iframe.style.width = '100%';
48
+ iframe.style.height = this.height;
49
+ iframe.style.zIndex = '999999'; // 6
50
+ if (this.position === 'top') {
51
+ iframe.style.top = '0';
52
+ iframe.style.bottom = '';
53
+ }
54
+ else {
55
+ iframe.style.bottom = '0';
56
+ iframe.style.top = '';
57
+ }
58
+ return iframe;
59
+ }
60
+ expandIframe() {
61
+ this.setIframeHeight('100%');
62
+ }
63
+ collapseIframe() {
64
+ this.setIframeHeight(this.height);
65
+ }
66
+ setIframeHeight(height) {
67
+ if (this.iframe) {
68
+ this.iframe.style.height = height;
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,12 @@
1
+ import { BaseWidget } from './BaseWidget';
2
+ import { WidgetLaunchParams, WinWidgetBaseConfig } from './types';
3
+ export declare abstract class WinWidgetBase<TConfig extends WinWidgetBaseConfig, TEvents> extends BaseWidget<TConfig, TEvents> {
4
+ protected abstract readonly route: string;
5
+ protected container: string;
6
+ protected abstract sendInitialData(): void;
7
+ launch(params: WidgetLaunchParams<TConfig>): void;
8
+ destroy(): void;
9
+ protected applyLaunchAnimation(iframe: HTMLIFrameElement): void;
10
+ protected cleanupLaunchAnimation(): void;
11
+ protected styleIframe(iframe: HTMLIFrameElement): HTMLIFrameElement;
12
+ }
@@ -0,0 +1,47 @@
1
+ import { BaseWidget } from './BaseWidget';
2
+ const defaults = {
3
+ container: '',
4
+ };
5
+ export class WinWidgetBase extends BaseWidget {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.container = defaults.container;
9
+ }
10
+ launch(params) {
11
+ var _a, _b;
12
+ if (this.isLaunched()) {
13
+ console.warn('Win widget is already launched');
14
+ return;
15
+ }
16
+ this.config = (_a = params.config) !== null && _a !== void 0 ? _a : {};
17
+ this.data = params.data;
18
+ this.container = (_b = this.config.container) !== null && _b !== void 0 ? _b : defaults.container;
19
+ this.iframe = this.createIframe();
20
+ this.iframe = this.styleIframe(this.iframe);
21
+ this.iframe.src = `${this.childAppOrigin}${this.route}`;
22
+ this.applyLaunchAnimation(this.iframe);
23
+ this.startListening();
24
+ }
25
+ destroy() {
26
+ this.cleanupLaunchAnimation();
27
+ this.container = defaults.container;
28
+ this.stopListening();
29
+ this.removeIframe();
30
+ }
31
+ // append the iframe with no enter animation.
32
+ // override in child for custom animation
33
+ applyLaunchAnimation(iframe) {
34
+ this.appendIframe(iframe, this.container);
35
+ this.setLaunched(true);
36
+ }
37
+ cleanupLaunchAnimation() { }
38
+ styleIframe(iframe) {
39
+ iframe.style.top = '0';
40
+ iframe.style.left = '0';
41
+ iframe.style.width = '100%';
42
+ iframe.style.height = '100%';
43
+ iframe.style.zIndex = '9999999'; // 7
44
+ iframe.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
45
+ return iframe;
46
+ }
47
+ }
@@ -0,0 +1,21 @@
1
+ export type SDKEnv = 'local' | 'dev' | 'staging' | 'production';
2
+ export interface WidgetLaunchParams<TConfig> {
3
+ config?: TConfig;
4
+ data: unknown;
5
+ }
6
+ export interface FooterWidgetBaseConfig {
7
+ container?: string;
8
+ position?: 'top' | 'bottom';
9
+ maxWidth?: string;
10
+ }
11
+ export interface WinWidgetBaseConfig {
12
+ container?: string;
13
+ }
14
+ export interface ChildMessage {
15
+ type: string;
16
+ data: unknown;
17
+ }
18
+ export interface InitialChildMessage<TConfig> extends ChildMessage {
19
+ config: TConfig;
20
+ }
21
+ export type WidgetEventHandler = () => void;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { SplashJackpotSDK } from './types';
2
- declare const splashJackpot: SplashJackpotSDK;
3
- export { splashJackpot };
1
+ import { ClientId } from './clients/registry';
2
+ import { SplashJackpotInitOptions, SplashJackpotSDK } from './types';
3
+ export declare function createSplashJackpot<C extends ClientId>(options: SplashJackpotInitOptions<C>): SplashJackpotSDK<C>;
package/dist/index.js CHANGED
@@ -1,25 +1,11 @@
1
- import { FooterWidget } from './widgets/footerWidget/FooterWidget';
2
- import { WinWidget } from './widgets/winWidget/WinWidget';
3
- const footerWidget = FooterWidget.getInstance();
4
- const winWidget = WinWidget.getInstance();
5
- const splashJackpot = {
6
- footerWidget: {
7
- isLaunched: () => footerWidget.isWidgetLaunched(),
8
- launch: (params) => footerWidget.launch(params),
9
- updateData: (partialData) => footerWidget.updateData(partialData),
10
- destroy: () => footerWidget.destroy(),
11
- addEventListener: (event, handler) => footerWidget.addEventListener(event, handler),
12
- removeEventListener: (event, handler) => footerWidget.removeEventListener(event, handler),
13
- removeAllEventListeners: () => footerWidget.removeAllEventListeners(),
14
- },
15
- winWidget: {
16
- isLaunched: () => winWidget.isWidgetLaunched(),
17
- launch: (params) => winWidget.launch(params),
18
- destroy: () => winWidget.destroy(),
19
- addEventListener: (event, handler) => winWidget.addEventListener(event, handler),
20
- removeEventListener: (event, handler) => winWidget.removeEventListener(event, handler),
21
- removeAllEventListeners: () => winWidget.removeAllEventListeners(),
22
- },
23
- };
24
- // export
25
- export { splashJackpot };
1
+ import { clientRegistry } from './clients/registry';
2
+ export function createSplashJackpot(options) {
3
+ var _a;
4
+ const client = clientRegistry[options.client];
5
+ if (!client) {
6
+ throw new Error(`createSplashJackpot: unknown client "${options.client}".`);
7
+ }
8
+ const env = (_a = options.env) !== null && _a !== void 0 ? _a : 'production';
9
+ const childAppOrigin = client.baseUrls[env];
10
+ return client.createWidgets(childAppOrigin);
11
+ }
@@ -0,0 +1 @@
1
+ export declare function validateNonEmptyObject(obj: unknown, label: string): boolean;
@@ -0,0 +1,11 @@
1
+ export function validateNonEmptyObject(obj, label) {
2
+ if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
3
+ console.error(`${label}: invalid payload: `, obj);
4
+ return false;
5
+ }
6
+ if (Object.keys(obj).length === 0) {
7
+ console.error(`${label}: empty object provided: `, obj);
8
+ return false;
9
+ }
10
+ return true;
11
+ }
package/dist/types.d.ts CHANGED
@@ -1,24 +1,7 @@
1
- import { FooterWidgetParams } from './widgets/footerWidget/types/data';
2
- import { FooterWidgetEvents } from './widgets/footerWidget/types/events';
3
- import { WidgetEventHandler } from './widgets/shared/types';
4
- import { WinWidgetParams } from './widgets/winWidget/types/data';
5
- import { WinWidgetWidgetEvents } from './widgets/winWidget/types/events';
6
- export interface SplashJackpotSDK {
7
- footerWidget: {
8
- isLaunched: () => boolean;
9
- launch: (params: FooterWidgetParams) => void;
10
- updateData: (partialData: Partial<unknown>) => void;
11
- destroy: () => void;
12
- addEventListener(event: keyof FooterWidgetEvents, handler: WidgetEventHandler): void;
13
- removeEventListener(event: keyof FooterWidgetEvents, handler: WidgetEventHandler): void;
14
- removeAllEventListeners(): void;
15
- };
16
- winWidget: {
17
- isLaunched: () => boolean;
18
- launch: (params: WinWidgetParams) => void;
19
- destroy: () => void;
20
- addEventListener(event: keyof WinWidgetWidgetEvents, handler: WidgetEventHandler): void;
21
- removeEventListener(event: keyof WinWidgetWidgetEvents, handler: WidgetEventHandler): void;
22
- removeAllEventListeners(): void;
23
- };
1
+ import { ClientId, ClientWidgets } from './clients/registry';
2
+ import { SDKEnv } from './core/types';
3
+ export interface SplashJackpotInitOptions<C extends ClientId> {
4
+ client: C;
5
+ env?: SDKEnv;
24
6
  }
7
+ export type SplashJackpotSDK<C extends ClientId> = ClientWidgets[C];
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "@splash-tech/jackpot-sdk",
3
- "version": "2.0.2",
3
+ "version": "3.0.1",
4
4
  "description": "SDK for managing jackpot widgets in iframes",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
7
14
  "files": [
8
15
  "dist",
9
16
  "README.md"
@@ -11,6 +18,7 @@
11
18
  "scripts": {
12
19
  "clean": "rm -rf dist",
13
20
  "build": "npm run clean && tsc",
21
+ "build:watch": "npm run clean && tsc --watch",
14
22
  "publish:npm": "npm run build && npm publish --access public",
15
23
  "test": "echo \"Error: no test specified\" && exit 1"
16
24
  },
@@ -1,28 +0,0 @@
1
- import { FooterWidgetParams } from './footerWidget/types/data';
2
- import { ChildMessage, SDKMode, WidgetEventHandler, WidgetParams } from './shared/types';
3
- import { WinWidgetParams } from './winWidget/types/data';
4
- export declare abstract class BaseWidget {
5
- protected iframe: HTMLIFrameElement | null;
6
- protected childAppOrigin: string | null;
7
- protected isLaunched: boolean;
8
- protected data: unknown;
9
- protected position: FooterWidgetParams['position'];
10
- protected maxWidth: string;
11
- protected animation: WinWidgetParams['animation'];
12
- protected jackpotId: string | null;
13
- protected tag: string | null;
14
- protected brand: string | null;
15
- private listeners;
16
- protected getBaseUrl(mode: SDKMode): string;
17
- protected createIframe(): HTMLIFrameElement;
18
- protected appendIframe(iframe: HTMLIFrameElement, container?: string): void;
19
- protected removeIframe(): void;
20
- protected setParamsData(params: WidgetParams): void;
21
- protected setLaunched(launched: boolean): void;
22
- isWidgetLaunched(): boolean;
23
- protected sendDataToChild(message: ChildMessage): void;
24
- addEventListener(event: string, handler: WidgetEventHandler): void;
25
- removeEventListener(event: string, handler: WidgetEventHandler): void;
26
- protected emit(event: string): void;
27
- protected removeAllEventListeners(): void;
28
- }
@@ -1,104 +0,0 @@
1
- export class BaseWidget {
2
- constructor() {
3
- this.iframe = null;
4
- this.childAppOrigin = null;
5
- this.isLaunched = false;
6
- this.position = 'bottom';
7
- this.maxWidth = '1300px';
8
- this.animation = 'wheel';
9
- this.jackpotId = null;
10
- this.tag = null;
11
- this.brand = null;
12
- this.listeners = new Map();
13
- }
14
- getBaseUrl(mode) {
15
- switch (mode) {
16
- case 'local':
17
- return 'http://localhost:4207';
18
- case 'dev':
19
- return 'https://jackpot-widget-dev.splash.tech';
20
- case 'staging':
21
- return 'https://jackpot-widget-staging.splash.tech';
22
- case 'production':
23
- default:
24
- return 'https://jackpot-widget.splash.tech';
25
- }
26
- }
27
- createIframe() {
28
- const iframe = document.createElement('iframe');
29
- iframe.style.border = 'none';
30
- iframe.style.position = 'fixed';
31
- iframe.style.zIndex = '999999';
32
- return iframe;
33
- }
34
- appendIframe(iframe, container) {
35
- const targetContainer = container
36
- ? document.querySelector(container)
37
- : document.body;
38
- if (!targetContainer) {
39
- console.error(`Container "${container}" not found`);
40
- document.body.appendChild(iframe);
41
- }
42
- else {
43
- if (container) {
44
- iframe.style.position = 'absolute';
45
- targetContainer.style.position = 'relative';
46
- }
47
- targetContainer.appendChild(iframe);
48
- }
49
- }
50
- removeIframe() {
51
- var _a;
52
- (_a = this.iframe) === null || _a === void 0 ? void 0 : _a.remove();
53
- this.iframe = null;
54
- this.isLaunched = false;
55
- }
56
- setParamsData(params) {
57
- const { mode, data, jackpotId, tag, brand, position, animation, maxWidth } = params;
58
- this.childAppOrigin = this.getBaseUrl(mode !== null && mode !== void 0 ? mode : 'production');
59
- this.data = data;
60
- this.jackpotId = jackpotId !== null && jackpotId !== void 0 ? jackpotId : null;
61
- this.tag = tag !== null && tag !== void 0 ? tag : null;
62
- this.brand = brand !== null && brand !== void 0 ? brand : null;
63
- this.position = position !== null && position !== void 0 ? position : this.position;
64
- this.animation = animation !== null && animation !== void 0 ? animation : this.animation;
65
- this.maxWidth = maxWidth !== null && maxWidth !== void 0 ? maxWidth : this.maxWidth;
66
- }
67
- setLaunched(launched) {
68
- this.isLaunched = launched;
69
- }
70
- isWidgetLaunched() {
71
- return this.isLaunched;
72
- }
73
- sendDataToChild(message) {
74
- var _a;
75
- if (((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) &&
76
- this.childAppOrigin &&
77
- message.data !== undefined) {
78
- const { data, jackpotId, tag, brand, position, maxWidth } = message;
79
- this.iframe.contentWindow.postMessage({
80
- type: message.type,
81
- payload: { data, jackpotId, tag, brand, position, maxWidth },
82
- }, this.childAppOrigin);
83
- }
84
- }
85
- addEventListener(event, handler) {
86
- if (!this.listeners.has(event)) {
87
- this.listeners.set(event, []);
88
- }
89
- this.listeners.get(event).push(handler);
90
- }
91
- removeEventListener(event, handler) {
92
- const handlers = this.listeners.get(event);
93
- if (!handlers)
94
- return;
95
- this.listeners.set(event, handlers.filter((h) => h !== handler));
96
- }
97
- emit(event) {
98
- const handlers = this.listeners.get(event);
99
- handlers === null || handlers === void 0 ? void 0 : handlers.forEach((handler) => handler());
100
- }
101
- removeAllEventListeners() {
102
- this.listeners.clear();
103
- }
104
- }
@@ -1,16 +0,0 @@
1
- import { BaseWidget } from '../BaseWidget';
2
- import { FooterWidgetParams } from './types/data';
3
- export declare class FooterWidget extends BaseWidget {
4
- private static instance;
5
- private constructor();
6
- static getInstance(): FooterWidget;
7
- private childMessageHandler;
8
- launch(params: FooterWidgetParams): void;
9
- private setIframeStyles;
10
- updateData(partialData: unknown): void;
11
- private validateNonEmptyObject;
12
- private showPopup;
13
- private hidePopup;
14
- removeAllEventListeners(): void;
15
- destroy(): void;
16
- }
@@ -1,110 +0,0 @@
1
- import { BaseWidget } from '../BaseWidget';
2
- import { FooterIframeIncomingEvent, FooterIframeOutgoingEvent, } from './types/events';
3
- export class FooterWidget extends BaseWidget {
4
- constructor() {
5
- super();
6
- // listen for messages of an app that is inside iframe
7
- this.childMessageHandler = (event) => {
8
- var _a, _b;
9
- if (!((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.src))
10
- return;
11
- if (event.origin !== this.childAppOrigin)
12
- return;
13
- switch ((_b = event.data) === null || _b === void 0 ? void 0 : _b.type) {
14
- case FooterIframeIncomingEvent.footerWidgetLoaded:
15
- this.sendDataToChild({
16
- type: FooterIframeOutgoingEvent.footerWidgetDataInitial,
17
- data: this.data,
18
- jackpotId: this.jackpotId,
19
- tag: this.tag,
20
- brand: this.brand,
21
- position: this.position,
22
- maxWidth: this.maxWidth,
23
- });
24
- break;
25
- case FooterIframeIncomingEvent.showPopup: {
26
- this.emit('showPopup');
27
- this.showPopup();
28
- break;
29
- }
30
- case FooterIframeIncomingEvent.hidePopup: {
31
- this.emit('hidePopup');
32
- this.hidePopup();
33
- break;
34
- }
35
- case FooterIframeIncomingEvent.participateChange: {
36
- this.emit('participateChange');
37
- break;
38
- }
39
- }
40
- };
41
- }
42
- static getInstance() {
43
- if (!FooterWidget.instance) {
44
- FooterWidget.instance = new FooterWidget();
45
- }
46
- return FooterWidget.instance;
47
- }
48
- launch(params) {
49
- if (this.isWidgetLaunched()) {
50
- console.warn('Footer widget is already launched');
51
- return;
52
- }
53
- this.setParamsData(params);
54
- this.iframe = this.createIframe();
55
- this.iframe = this.setIframeStyles(this.iframe);
56
- this.iframe.src = `${this.childAppOrigin}/footer-widget`;
57
- this.appendIframe(this.iframe, params.container);
58
- this.setLaunched(true);
59
- window.addEventListener('message', this.childMessageHandler);
60
- }
61
- setIframeStyles(iframe) {
62
- iframe.style.left = '0';
63
- iframe.style.width = '100%';
64
- iframe.style.height = '50px';
65
- iframe.style.zIndex = '999999'; // 6
66
- if (this.position === 'bottom') {
67
- iframe.style.bottom = '0';
68
- }
69
- else {
70
- iframe.style.top = '0';
71
- }
72
- return iframe;
73
- }
74
- updateData(partialData) {
75
- if (!this.validateNonEmptyObject(partialData))
76
- return;
77
- this.sendDataToChild({
78
- type: FooterIframeOutgoingEvent.footerWidgetDataUpdated,
79
- data: partialData,
80
- });
81
- }
82
- validateNonEmptyObject(obj) {
83
- if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
84
- console.error('FooterWidget.updateData: Unable to update data. Invalid payload: ', obj);
85
- return false;
86
- }
87
- if (Object.keys(obj).length === 0) {
88
- console.error('FooterWidget.updateData: Unable to update data. Empty object provided: ', obj);
89
- return false;
90
- }
91
- return true;
92
- }
93
- showPopup() {
94
- if (this.iframe) {
95
- this.iframe.style.height = '100%';
96
- }
97
- }
98
- hidePopup() {
99
- if (this.iframe) {
100
- this.iframe.style.height = '50px';
101
- }
102
- }
103
- removeAllEventListeners() {
104
- super.removeAllEventListeners();
105
- }
106
- destroy() {
107
- window.removeEventListener('message', this.childMessageHandler);
108
- this.removeIframe();
109
- }
110
- }
@@ -1,12 +0,0 @@
1
- import { SDKMode } from 'src/widgets/shared/types';
2
- export interface FooterWidgetParams {
3
- data: unknown;
4
- mode?: SDKMode;
5
- position?: 'top' | 'bottom';
6
- animation?: 'wheel' | 'airplane';
7
- maxWidth?: string;
8
- container?: string;
9
- jackpotId?: string;
10
- tag?: string;
11
- brand?: string;
12
- }
@@ -1,15 +0,0 @@
1
- export declare enum FooterIframeIncomingEvent {
2
- footerWidgetLoaded = "jackpot-footer-widget-loaded",
3
- participateChange = "jackpot-footer-widget-participate-change",
4
- showPopup = "jackpot-footer-widget-popup-show",
5
- hidePopup = "jackpot-footer-widget-popup-hide"
6
- }
7
- export declare enum FooterIframeOutgoingEvent {
8
- footerWidgetDataInitial = "jackpot-footer-widget-data-initial",
9
- footerWidgetDataUpdated = "jackpot-footer-widget-data-updated"
10
- }
11
- export type FooterWidgetEvents = {
12
- participateChange: void;
13
- showPopup: void;
14
- hidePopup: void;
15
- };
@@ -1,14 +0,0 @@
1
- // events emitted by app inside iframe to the SDK - Internal use
2
- export var FooterIframeIncomingEvent;
3
- (function (FooterIframeIncomingEvent) {
4
- FooterIframeIncomingEvent["footerWidgetLoaded"] = "jackpot-footer-widget-loaded";
5
- FooterIframeIncomingEvent["participateChange"] = "jackpot-footer-widget-participate-change";
6
- FooterIframeIncomingEvent["showPopup"] = "jackpot-footer-widget-popup-show";
7
- FooterIframeIncomingEvent["hidePopup"] = "jackpot-footer-widget-popup-hide";
8
- })(FooterIframeIncomingEvent || (FooterIframeIncomingEvent = {}));
9
- // events emitted by SDK to the app inside iframe - Internal use
10
- export var FooterIframeOutgoingEvent;
11
- (function (FooterIframeOutgoingEvent) {
12
- FooterIframeOutgoingEvent["footerWidgetDataInitial"] = "jackpot-footer-widget-data-initial";
13
- FooterIframeOutgoingEvent["footerWidgetDataUpdated"] = "jackpot-footer-widget-data-updated";
14
- })(FooterIframeOutgoingEvent || (FooterIframeOutgoingEvent = {}));
@@ -1,18 +0,0 @@
1
- import { FooterWidgetParams } from '../footerWidget/types/data';
2
- import { FooterIframeOutgoingEvent } from '../footerWidget/types/events';
3
- import { WinWidgetParams } from '../winWidget/types/data';
4
- import { WinWidgetIframeOutgoingEvent } from '../winWidget/types/events';
5
- export type SDKMode = 'local' | 'dev' | 'staging' | 'production';
6
- export type WidgetParams = FooterWidgetParams | WinWidgetParams;
7
- export type IframeOutgoingEvent = FooterIframeOutgoingEvent | WinWidgetIframeOutgoingEvent;
8
- export type WidgetEventHandler = () => void;
9
- export interface ChildMessage {
10
- type: IframeOutgoingEvent;
11
- data: unknown;
12
- position?: FooterWidgetParams['position'];
13
- animation?: WinWidgetParams['animation'];
14
- maxWidth?: string;
15
- jackpotId?: string | null;
16
- tag?: string | null;
17
- brand?: string | null;
18
- }
@@ -1,13 +0,0 @@
1
- import { BaseWidget } from '../BaseWidget';
2
- import { WinWidgetParams } from './types/data';
3
- export declare class WinWidget extends BaseWidget {
4
- private static instance;
5
- private constructor();
6
- static getInstance(): WinWidget;
7
- private childMessageHandler;
8
- launch(params: WinWidgetParams): void;
9
- private animateEnter;
10
- private cleanupAnimation;
11
- removeAllEventListeners(): void;
12
- destroy(): void;
13
- }