@splash-tech/jackpot-sdk 1.0.6 → 1.0.8

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/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  import { SplashJackpotSDK } from './types';
2
- import { FooterWidgetParams } from './widgets/footerWidget/types/data';
3
- import { WonJackpotWidgetParams } from './widgets/wonJackpotWidget/types/data';
4
2
  export declare const splashJackpot: SplashJackpotSDK;
5
- export type { SplashJackpotSDK as SplashJackpot, FooterWidgetParams, WonJackpotWidgetParams, };
3
+ export type { SplashJackpotSDK as SplashJackpot };
package/dist/index.js CHANGED
@@ -7,8 +7,6 @@ export const splashJackpot = {
7
7
  isLaunched: () => footerWidget.isWidgetLaunched(),
8
8
  launch: (params) => footerWidget.launchFooter(params),
9
9
  updateData: (partialData) => footerWidget.updateData(partialData),
10
- showPopup: () => footerWidget.showPopup(),
11
- hidePopup: () => footerWidget.hidePopup(),
12
10
  destroy: () => footerWidget.destroyFooter(),
13
11
  addEventListener: (event, handler) => footerWidget.addEventListener(event, handler),
14
12
  removeEventListener: (event, handler) => footerWidget.removeEventListener(event, handler),
package/dist/types.d.ts CHANGED
@@ -2,14 +2,12 @@ import { FooterWidgetParams } from './widgets/footerWidget/types/data';
2
2
  import { FooterWidgetEvents } from './widgets/footerWidget/types/event';
3
3
  import { WidgetEventHandler } from './widgets/shared/types';
4
4
  import { WonJackpotWidgetParams } from './widgets/wonJackpotWidget/types/data';
5
- import { winWidgetWidgetEvents } from './widgets/wonJackpotWidget/types/event';
5
+ import { WinWidgetWidgetEvents } from './widgets/wonJackpotWidget/types/event';
6
6
  export interface SplashJackpotSDK {
7
7
  footer: {
8
8
  isLaunched: () => boolean;
9
9
  launch: (params: FooterWidgetParams) => void;
10
- updateData: (partialData: unknown) => void;
11
- showPopup: () => void;
12
- hidePopup: () => void;
10
+ updateData: (partialData: Partial<unknown>) => void;
13
11
  destroy: () => void;
14
12
  addEventListener(event: keyof FooterWidgetEvents, handler: WidgetEventHandler): void;
15
13
  removeEventListener(event: keyof FooterWidgetEvents, handler: WidgetEventHandler): void;
@@ -18,7 +16,7 @@ export interface SplashJackpotSDK {
18
16
  isLaunched: () => boolean;
19
17
  launch: (params: WonJackpotWidgetParams) => void;
20
18
  destroy: () => void;
21
- addEventListener(event: keyof winWidgetWidgetEvents, handler: WidgetEventHandler): void;
22
- removeEventListener(event: keyof winWidgetWidgetEvents, handler: WidgetEventHandler): void;
19
+ addEventListener(event: keyof WinWidgetWidgetEvents, handler: WidgetEventHandler): void;
20
+ removeEventListener(event: keyof WinWidgetWidgetEvents, handler: WidgetEventHandler): void;
23
21
  };
24
22
  }
@@ -1,15 +1,25 @@
1
- import { SDKMode, WidgetEventHandler } from './shared/types';
1
+ import { IframeOutgoingEvent, SDKMode, WidgetEventHandler, WidgetParams } from './shared/types';
2
+ interface ChildMessage {
3
+ type: IframeOutgoingEvent;
4
+ data: unknown;
5
+ }
2
6
  export declare abstract class BaseWidget {
3
7
  protected iframe: HTMLIFrameElement | null;
8
+ protected childAppOrigin: string | null;
4
9
  protected isLaunched: boolean;
10
+ protected data: unknown;
5
11
  private listeners;
6
12
  protected getBaseUrl(mode: SDKMode): string;
7
13
  protected createIframe(): HTMLIFrameElement;
8
14
  protected appendIframe(iframe: HTMLIFrameElement, container?: string): void;
9
15
  protected removeIframe(): void;
16
+ protected setParamsData(params: WidgetParams): void;
10
17
  protected setLaunched(launched: boolean): void;
11
18
  isWidgetLaunched(): boolean;
19
+ protected sendDataToChild(message: ChildMessage): void;
12
20
  addEventListener(event: string, handler: WidgetEventHandler): void;
13
21
  removeEventListener(event: string, handler: WidgetEventHandler): void;
14
22
  protected emit(event: string, payload?: unknown): void;
23
+ protected removeAllEventListeners(): void;
15
24
  }
25
+ export {};
@@ -1,6 +1,7 @@
1
1
  export class BaseWidget {
2
2
  constructor() {
3
3
  this.iframe = null;
4
+ this.childAppOrigin = null;
4
5
  this.isLaunched = false;
5
6
  this.listeners = new Map();
6
7
  }
@@ -41,11 +42,15 @@ export class BaseWidget {
41
42
  }
42
43
  }
43
44
  removeIframe() {
44
- if (this.iframe && this.iframe.parentNode) {
45
- this.iframe.parentNode.removeChild(this.iframe);
46
- this.iframe = null;
47
- this.isLaunched = false;
48
- }
45
+ var _a;
46
+ (_a = this.iframe) === null || _a === void 0 ? void 0 : _a.remove();
47
+ this.iframe = null;
48
+ this.isLaunched = false;
49
+ }
50
+ setParamsData(params) {
51
+ const { mode, data } = params;
52
+ this.childAppOrigin = this.getBaseUrl(mode !== null && mode !== void 0 ? mode : 'production');
53
+ this.data = data;
49
54
  }
50
55
  setLaunched(launched) {
51
56
  this.isLaunched = launched;
@@ -53,6 +58,17 @@ export class BaseWidget {
53
58
  isWidgetLaunched() {
54
59
  return this.isLaunched;
55
60
  }
61
+ sendDataToChild(message) {
62
+ var _a;
63
+ if (((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) &&
64
+ this.childAppOrigin &&
65
+ message.data !== undefined) {
66
+ this.iframe.contentWindow.postMessage({
67
+ type: message.type,
68
+ payload: message.data,
69
+ }, this.childAppOrigin);
70
+ }
71
+ }
56
72
  addEventListener(event, handler) {
57
73
  if (!this.listeners.has(event)) {
58
74
  this.listeners.set(event, []);
@@ -69,4 +85,7 @@ export class BaseWidget {
69
85
  const handlers = this.listeners.get(event);
70
86
  handlers === null || handlers === void 0 ? void 0 : handlers.forEach((handler) => handler());
71
87
  }
88
+ removeAllEventListeners() {
89
+ this.listeners.clear();
90
+ }
72
91
  }
@@ -2,15 +2,13 @@ import { BaseWidget } from '../BaseWidget';
2
2
  import { FooterWidgetParams } from './types/data';
3
3
  export declare class FooterWidget extends BaseWidget {
4
4
  private static instance;
5
- private childAppOrigin;
6
- private data;
7
5
  private constructor();
8
6
  static getInstance(): FooterWidget;
9
7
  private childMessageHandler;
10
- private sendDataToChild;
11
8
  launchFooter(params: FooterWidgetParams): void;
12
9
  updateData(partialData: unknown): void;
13
- showPopup(): void;
14
- hidePopup(): void;
10
+ private validateNonEmptyObject;
11
+ private showPopup;
12
+ private hidePopup;
15
13
  destroyFooter(): void;
16
14
  }
@@ -12,7 +12,10 @@ export class FooterWidget extends BaseWidget {
12
12
  return;
13
13
  switch ((_b = event.data) === null || _b === void 0 ? void 0 : _b.type) {
14
14
  case FooterIframeIncomingEvent.footerWidgetLoaded:
15
- this.sendDataToChild(FooterIframeOutgoingEvent.footerWidgetDataInitial, this.data);
15
+ this.sendDataToChild({
16
+ type: FooterIframeOutgoingEvent.footerWidgetDataInitial,
17
+ data: this.data,
18
+ });
16
19
  break;
17
20
  case FooterIframeIncomingEvent.showPopup: {
18
21
  this.emit('showPopup');
@@ -37,23 +40,12 @@ export class FooterWidget extends BaseWidget {
37
40
  }
38
41
  return FooterWidget.instance;
39
42
  }
40
- sendDataToChild(type, data) {
41
- var _a;
42
- if (((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) && data !== undefined) {
43
- this.iframe.contentWindow.postMessage({
44
- type,
45
- payload: data,
46
- }, this.childAppOrigin);
47
- }
48
- }
49
43
  launchFooter(params) {
50
- var _a;
51
44
  if (this.isWidgetLaunched()) {
52
45
  console.warn('Footer widget is already launched');
53
46
  return;
54
47
  }
55
- this.data = params.data;
56
- this.childAppOrigin = this.getBaseUrl((_a = params.mode) !== null && _a !== void 0 ? _a : 'production');
48
+ this.setParamsData(params);
57
49
  this.iframe = this.createIframe();
58
50
  this.iframe.style.bottom = '0';
59
51
  this.iframe.style.left = '0';
@@ -66,17 +58,23 @@ export class FooterWidget extends BaseWidget {
66
58
  window.addEventListener('message', this.childMessageHandler);
67
59
  }
68
60
  updateData(partialData) {
69
- // must be a non-null object
70
- if (!partialData || typeof partialData !== 'object') {
71
- console.error('FooterWidget.updateData: invalid payload', partialData);
61
+ if (!this.validateNonEmptyObject(partialData))
72
62
  return;
63
+ this.sendDataToChild({
64
+ type: FooterIframeOutgoingEvent.footerWidgetDataUpdated,
65
+ data: partialData,
66
+ });
67
+ }
68
+ validateNonEmptyObject(obj) {
69
+ if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
70
+ console.error('FooterWidget.updateData: Unable to update data. Invalid payload: ', obj);
71
+ return false;
73
72
  }
74
- // ignore empty object {}
75
- if (Object.keys(partialData).length === 0) {
76
- console.error('FooterWidget.updateData: empty object provided');
77
- return;
73
+ if (Object.keys(obj).length === 0) {
74
+ console.error('FooterWidget.updateData: Unable to update data. Empty object provided: ', obj);
75
+ return false;
78
76
  }
79
- this.sendDataToChild(FooterIframeOutgoingEvent.footerWidgetDataUpdated, partialData);
77
+ return true;
80
78
  }
81
79
  showPopup() {
82
80
  if (this.iframe) {
@@ -90,6 +88,7 @@ export class FooterWidget extends BaseWidget {
90
88
  }
91
89
  destroyFooter() {
92
90
  window.removeEventListener('message', this.childMessageHandler);
91
+ this.removeAllEventListeners();
93
92
  this.removeIframe();
94
93
  }
95
94
  }
@@ -4,151 +4,3 @@ export interface FooterWidgetParams {
4
4
  mode?: SDKMode;
5
5
  container?: string;
6
6
  }
7
- export interface FooterWidgetData {
8
- group: JackpotGroupResponse;
9
- newGroup: JackpotGroupResponseNew;
10
- theme: JackpotThemeResponse;
11
- participate: JackpotParticipation;
12
- }
13
- export interface JackpotGroup {
14
- uuid: string;
15
- name: string;
16
- brands: string[];
17
- tags: {
18
- tag: string;
19
- }[];
20
- deleted: boolean;
21
- }
22
- export interface JackpotGroupResponse {
23
- jackpotGroup: JackpotGroup | null;
24
- theme: Theme | null;
25
- jackpotLevels: JackpotLevel[];
26
- }
27
- export interface JackpotLevel {
28
- uuid: string;
29
- name: string;
30
- currency: string;
31
- values: {
32
- [key: string]: number;
33
- };
34
- won: boolean;
35
- paused: boolean;
36
- prizeLabel: string | null;
37
- iconAsset: Asset | null;
38
- }
39
- export interface JackpotLevelWithColor extends JackpotLevel {
40
- filter: string;
41
- background: string;
42
- }
43
- export interface WonJackpotLevel extends JackpotLevelWithColor {
44
- winAmount: number;
45
- }
46
- export interface JackpotSegment {
47
- icon: string;
48
- backgroundColor: string;
49
- label: string;
50
- index: number;
51
- isWon: boolean;
52
- filter: string;
53
- }
54
- export interface Theme extends BaseTheme {
55
- clientLogoAsset: Asset | null;
56
- jackpotLogoAsset: Asset | null;
57
- jackpotPopupImageAsset: Asset | null;
58
- lockingSymbolSoundAsset: Asset | null;
59
- resultNoPrizeSoundAsset: Asset | null;
60
- resultPrizeRevealSoundAsset: Asset | null;
61
- spinSoundAsset: Asset | null;
62
- }
63
- export interface JackpotGroupResponseNew {
64
- uuid: string;
65
- noOfWins: number;
66
- totalWinAmount: number;
67
- currentCounters: JackpotCounter[];
68
- }
69
- export interface JackpotCounter {
70
- uuid: string;
71
- name: string;
72
- currency: string;
73
- currentValue: number;
74
- totalUserLevelContributionPerSpin: number;
75
- }
76
- export interface JackpotThemeResponse {
77
- theme: Theme;
78
- }
79
- export interface JackpotParticipation {
80
- jackpotId: string;
81
- participate: boolean;
82
- tag: string | null;
83
- }
84
- export interface Asset {
85
- uuid: string;
86
- createdTs: string;
87
- name: string;
88
- label: string;
89
- comment: string;
90
- url: string;
91
- tags: string[];
92
- type: AssetType;
93
- sportType: SportType;
94
- }
95
- export declare enum AssetType {
96
- GAME = "GAME",
97
- REPORT = "REPORT",
98
- FONT = "FONT",
99
- CLIENT = "CLIENT",
100
- AUDIO = "AUDIO"
101
- }
102
- export declare enum SportType {
103
- SOCCER = "SOCCER",
104
- CRICKET = "CRICKET",
105
- BASKETBALL = "BASKETBALL",
106
- ICE_HOCKEY = "ICE HOCKEY",
107
- RUGBY = "RUGBY",
108
- MMA = "MMA",
109
- BOXING = "BOXING",
110
- BASEBALL = "BASEBALL",
111
- GOLF = "GOLF",
112
- TENNIS = "TENNIS",
113
- E_SPORTS = "E-SPORTS",
114
- FORMULA_1 = "FORMULA 1",
115
- OTHER = "OTHER",
116
- DARTS = "DARTS",
117
- OLYMPICS = "OLYMPICS",
118
- VOLLEYBALL = "VOLLEYBALL",
119
- AMERICAN_FOOTBALL = "AMERICAN FOOTBALL"
120
- }
121
- export interface BaseTheme {
122
- uuid: string;
123
- createdTs: string;
124
- updatedTs: string;
125
- name: string;
126
- cssVariables: ConfigValue[];
127
- primaryFontRegularAsset: Asset;
128
- primaryFontMediumAsset: Asset;
129
- primaryFontBoldAsset: Asset;
130
- jackpotFontAsset: Asset;
131
- darkMode: boolean;
132
- backgroundAnimation: BackgroundAnimationType | null;
133
- labels: ConfigValue[];
134
- cornerRadiusCta: number;
135
- termsAndConditions: string | null;
136
- rules: string | null;
137
- faq: string | null;
138
- secondaryCtaStyle: CTAStyles | null;
139
- }
140
- export declare enum CTAStyles {
141
- Outline = "OUTLINE",
142
- Solid = "SOLID"
143
- }
144
- export interface ConfigValue {
145
- uuid: string;
146
- key: string;
147
- description: string;
148
- value: string;
149
- hint: string;
150
- }
151
- export declare enum BackgroundAnimationType {
152
- SNOW = "SNOW",
153
- SPARKLE = "SPARKLE"
154
- }
@@ -1,2 +1,8 @@
1
+ import { FooterWidgetParams } from '../footerWidget/types/data';
2
+ import { FooterIframeOutgoingEvent } from '../footerWidget/types/event';
3
+ import { WonJackpotWidgetParams } from '../wonJackpotWidget/types/data';
4
+ import { WinWidgetIframeOutgoingEvent } from '../wonJackpotWidget/types/event';
1
5
  export type SDKMode = 'local' | 'dev' | 'staging' | 'production';
6
+ export type WidgetParams = FooterWidgetParams | WonJackpotWidgetParams;
7
+ export type IframeOutgoingEvent = FooterIframeOutgoingEvent | WinWidgetIframeOutgoingEvent;
2
8
  export type WidgetEventHandler = () => void;
@@ -2,12 +2,9 @@ import { BaseWidget } from '../BaseWidget';
2
2
  import { WonJackpotWidgetParams } from './types/data';
3
3
  export declare class WonJackpotWidget extends BaseWidget {
4
4
  private static instance;
5
- private childAppOrigin;
6
- private data;
7
5
  private constructor();
8
6
  static getInstance(): WonJackpotWidget;
9
7
  private childMessageHandler;
10
8
  launchWonJackpot(params: WonJackpotWidgetParams): void;
11
- private sendDataToChild;
12
9
  destroyWonJackpot(): void;
13
10
  }
@@ -1,5 +1,5 @@
1
1
  import { BaseWidget } from '../BaseWidget';
2
- import { winWidgetIframeIncomingEvent, winWidgetIframeOutgoingEvent, } from './types/event';
2
+ import { WinWidgetIframeIncomingEvent, WinWidgetIframeOutgoingEvent, } from './types/event';
3
3
  export class WonJackpotWidget extends BaseWidget {
4
4
  constructor() {
5
5
  super();
@@ -10,10 +10,13 @@ export class WonJackpotWidget extends BaseWidget {
10
10
  if (event.origin !== this.childAppOrigin)
11
11
  return;
12
12
  switch ((_b = event.data) === null || _b === void 0 ? void 0 : _b.type) {
13
- case winWidgetIframeIncomingEvent.winWidgetLoaded:
14
- this.sendDataToChild(winWidgetIframeOutgoingEvent.winWidgetDataIntitial, this.data);
13
+ case WinWidgetIframeIncomingEvent.winWidgetLoaded:
14
+ this.sendDataToChild({
15
+ type: WinWidgetIframeOutgoingEvent.winWidgetDataInitial,
16
+ data: this.data,
17
+ });
15
18
  break;
16
- case winWidgetIframeIncomingEvent.winWidgetClose:
19
+ case WinWidgetIframeIncomingEvent.winWidgetClose:
17
20
  this.emit('close');
18
21
  break;
19
22
  }
@@ -26,13 +29,11 @@ export class WonJackpotWidget extends BaseWidget {
26
29
  return WonJackpotWidget.instance;
27
30
  }
28
31
  launchWonJackpot(params) {
29
- var _a;
30
32
  if (this.isWidgetLaunched()) {
31
33
  console.warn('Won Jackpot widget is already launched');
32
34
  return;
33
35
  }
34
- this.data = params.data;
35
- this.childAppOrigin = this.getBaseUrl((_a = params.mode) !== null && _a !== void 0 ? _a : 'production');
36
+ this.setParamsData(params);
36
37
  this.iframe = this.createIframe();
37
38
  this.iframe.style.top = '0';
38
39
  this.iframe.style.left = '0';
@@ -45,17 +46,9 @@ export class WonJackpotWidget extends BaseWidget {
45
46
  this.setLaunched(true);
46
47
  window.addEventListener('message', this.childMessageHandler);
47
48
  }
48
- sendDataToChild(type, data) {
49
- var _a;
50
- if (((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) && data !== undefined) {
51
- this.iframe.contentWindow.postMessage({
52
- type,
53
- payload: data,
54
- }, this.childAppOrigin);
55
- }
56
- }
57
49
  destroyWonJackpot() {
58
50
  window.removeEventListener('message', this.childMessageHandler);
51
+ this.removeAllEventListeners();
59
52
  this.removeIframe();
60
53
  }
61
54
  }
@@ -1,10 +1,10 @@
1
- export declare enum winWidgetIframeIncomingEvent {
1
+ export declare enum WinWidgetIframeIncomingEvent {
2
2
  winWidgetLoaded = "jackpot-win-widget-loaded",
3
3
  winWidgetClose = "jackpot-win-widget-close"
4
4
  }
5
- export declare enum winWidgetIframeOutgoingEvent {
6
- winWidgetDataIntitial = "jackpot-win-widget-data-initial"
5
+ export declare enum WinWidgetIframeOutgoingEvent {
6
+ winWidgetDataInitial = "jackpot-win-widget-data-initial"
7
7
  }
8
- export type winWidgetWidgetEvents = {
8
+ export type WinWidgetWidgetEvents = {
9
9
  close: void;
10
10
  };
@@ -1,11 +1,11 @@
1
1
  // events emitted by app inside iframe to the SDK - Internal use
2
- export var winWidgetIframeIncomingEvent;
3
- (function (winWidgetIframeIncomingEvent) {
4
- winWidgetIframeIncomingEvent["winWidgetLoaded"] = "jackpot-win-widget-loaded";
5
- winWidgetIframeIncomingEvent["winWidgetClose"] = "jackpot-win-widget-close";
6
- })(winWidgetIframeIncomingEvent || (winWidgetIframeIncomingEvent = {}));
2
+ export var WinWidgetIframeIncomingEvent;
3
+ (function (WinWidgetIframeIncomingEvent) {
4
+ WinWidgetIframeIncomingEvent["winWidgetLoaded"] = "jackpot-win-widget-loaded";
5
+ WinWidgetIframeIncomingEvent["winWidgetClose"] = "jackpot-win-widget-close";
6
+ })(WinWidgetIframeIncomingEvent || (WinWidgetIframeIncomingEvent = {}));
7
7
  // events emitted by SDK to the app inside iframe - Internal use
8
- export var winWidgetIframeOutgoingEvent;
9
- (function (winWidgetIframeOutgoingEvent) {
10
- winWidgetIframeOutgoingEvent["winWidgetDataIntitial"] = "jackpot-win-widget-data-initial";
11
- })(winWidgetIframeOutgoingEvent || (winWidgetIframeOutgoingEvent = {}));
8
+ export var WinWidgetIframeOutgoingEvent;
9
+ (function (WinWidgetIframeOutgoingEvent) {
10
+ WinWidgetIframeOutgoingEvent["winWidgetDataInitial"] = "jackpot-win-widget-data-initial";
11
+ })(WinWidgetIframeOutgoingEvent || (WinWidgetIframeOutgoingEvent = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splash-tech/jackpot-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "SDK for managing jackpot widgets in iframes",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",