@splash-tech/jackpot-sdk 1.0.4 → 1.0.6

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/types.d.ts CHANGED
@@ -2,7 +2,7 @@ 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 { WonJackpotWidgetEvents } 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;
@@ -18,7 +18,7 @@ export interface SplashJackpotSDK {
18
18
  isLaunched: () => boolean;
19
19
  launch: (params: WonJackpotWidgetParams) => void;
20
20
  destroy: () => void;
21
- addEventListener(event: keyof WonJackpotWidgetEvents, handler: WidgetEventHandler): void;
22
- removeEventListener(event: keyof WonJackpotWidgetEvents, handler: WidgetEventHandler): void;
21
+ addEventListener(event: keyof winWidgetWidgetEvents, handler: WidgetEventHandler): void;
22
+ removeEventListener(event: keyof winWidgetWidgetEvents, handler: WidgetEventHandler): void;
23
23
  };
24
24
  }
@@ -1,14 +1,15 @@
1
- import { WidgetEventHandler } from './shared/types';
1
+ import { SDKMode, WidgetEventHandler } from './shared/types';
2
2
  export declare abstract class BaseWidget {
3
3
  protected iframe: HTMLIFrameElement | null;
4
4
  protected isLaunched: boolean;
5
5
  private listeners;
6
- protected emit(event: string, payload?: unknown): void;
7
- addEventListener(event: string, handler: WidgetEventHandler): void;
8
- removeEventListener(event: string, handler: WidgetEventHandler): void;
6
+ protected getBaseUrl(mode: SDKMode): string;
9
7
  protected createIframe(): HTMLIFrameElement;
10
8
  protected appendIframe(iframe: HTMLIFrameElement, container?: string): void;
11
9
  protected removeIframe(): void;
12
10
  protected setLaunched(launched: boolean): void;
13
11
  isWidgetLaunched(): boolean;
12
+ addEventListener(event: string, handler: WidgetEventHandler): void;
13
+ removeEventListener(event: string, handler: WidgetEventHandler): void;
14
+ protected emit(event: string, payload?: unknown): void;
14
15
  }
@@ -4,21 +4,18 @@ export class BaseWidget {
4
4
  this.isLaunched = false;
5
5
  this.listeners = new Map();
6
6
  }
7
- emit(event, payload) {
8
- const handlers = this.listeners.get(event);
9
- handlers === null || handlers === void 0 ? void 0 : handlers.forEach((handler) => handler());
10
- }
11
- addEventListener(event, handler) {
12
- if (!this.listeners.has(event)) {
13
- this.listeners.set(event, []);
7
+ getBaseUrl(mode) {
8
+ switch (mode) {
9
+ case 'local':
10
+ return 'http://localhost:4207';
11
+ case 'dev':
12
+ return 'https://jackpot-widget-dev.splash.tech';
13
+ case 'staging':
14
+ return 'https://jackpot-widget-staging.splash.tech';
15
+ case 'production':
16
+ default:
17
+ return 'https://jackpot-widget.splash.tech';
14
18
  }
15
- this.listeners.get(event).push(handler);
16
- }
17
- removeEventListener(event, handler) {
18
- const handlers = this.listeners.get(event);
19
- if (!handlers)
20
- return;
21
- this.listeners.set(event, handlers.filter((h) => h !== handler));
22
19
  }
23
20
  createIframe() {
24
21
  const iframe = document.createElement('iframe');
@@ -56,4 +53,20 @@ export class BaseWidget {
56
53
  isWidgetLaunched() {
57
54
  return this.isLaunched;
58
55
  }
56
+ addEventListener(event, handler) {
57
+ if (!this.listeners.has(event)) {
58
+ this.listeners.set(event, []);
59
+ }
60
+ this.listeners.get(event).push(handler);
61
+ }
62
+ removeEventListener(event, handler) {
63
+ const handlers = this.listeners.get(event);
64
+ if (!handlers)
65
+ return;
66
+ this.listeners.set(event, handlers.filter((h) => h !== handler));
67
+ }
68
+ emit(event, payload) {
69
+ const handlers = this.listeners.get(event);
70
+ handlers === null || handlers === void 0 ? void 0 : handlers.forEach((handler) => handler());
71
+ }
59
72
  }
@@ -1,10 +1,8 @@
1
1
  import { BaseWidget } from '../BaseWidget';
2
- import { environment } from '../../environments/environment.prod.js';
3
2
  import { FooterIframeIncomingEvent, FooterIframeOutgoingEvent, } from './types/event';
4
3
  export class FooterWidget extends BaseWidget {
5
4
  constructor() {
6
5
  super();
7
- this.childAppOrigin = environment.jackpotWidgetUrl;
8
6
  // listen for messages of an app that is inside iframe
9
7
  this.childMessageHandler = (event) => {
10
8
  var _a, _b;
@@ -49,18 +47,20 @@ export class FooterWidget extends BaseWidget {
49
47
  }
50
48
  }
51
49
  launchFooter(params) {
50
+ var _a;
52
51
  if (this.isWidgetLaunched()) {
53
52
  console.warn('Footer widget is already launched');
54
53
  return;
55
54
  }
56
55
  this.data = params.data;
56
+ this.childAppOrigin = this.getBaseUrl((_a = params.mode) !== null && _a !== void 0 ? _a : 'production');
57
57
  this.iframe = this.createIframe();
58
58
  this.iframe.style.bottom = '0';
59
59
  this.iframe.style.left = '0';
60
60
  this.iframe.style.width = '100%';
61
61
  this.iframe.style.height = '50px';
62
62
  this.iframe.style.zIndex = '999999'; // 6
63
- this.iframe.src = `${environment.jackpotWidgetUrl}/footer-widget`;
63
+ this.iframe.src = `${this.childAppOrigin}/footer-widget`;
64
64
  this.appendIframe(this.iframe, params.container);
65
65
  this.setLaunched(true);
66
66
  window.addEventListener('message', this.childMessageHandler);
@@ -1,6 +1,8 @@
1
+ import { SDKMode } from 'src/widgets/shared/types';
1
2
  export interface FooterWidgetParams {
2
- container?: string;
3
3
  data: unknown;
4
+ mode?: SDKMode;
5
+ container?: string;
4
6
  }
5
7
  export interface FooterWidgetData {
6
8
  group: JackpotGroupResponse;
@@ -6,7 +6,7 @@ export var FooterIframeIncomingEvent;
6
6
  FooterIframeIncomingEvent["showPopup"] = "jackpot-footer-widget-popup-show";
7
7
  FooterIframeIncomingEvent["hidePopup"] = "jackpot-footer-widget-popup-hide";
8
8
  })(FooterIframeIncomingEvent || (FooterIframeIncomingEvent = {}));
9
- // events emitted by SDK to the app inside iframe- Internal use
9
+ // events emitted by SDK to the app inside iframe - Internal use
10
10
  export var FooterIframeOutgoingEvent;
11
11
  (function (FooterIframeOutgoingEvent) {
12
12
  FooterIframeOutgoingEvent["footerWidgetDataInitial"] = "jackpot-footer-widget-data-initial";
@@ -1 +1,2 @@
1
+ export type SDKMode = 'local' | 'dev' | 'staging' | 'production';
1
2
  export type WidgetEventHandler = () => void;
@@ -3,9 +3,11 @@ import { WonJackpotWidgetParams } from './types/data';
3
3
  export declare class WonJackpotWidget extends BaseWidget {
4
4
  private static instance;
5
5
  private childAppOrigin;
6
+ private data;
6
7
  private constructor();
7
8
  static getInstance(): WonJackpotWidget;
8
9
  private childMessageHandler;
9
10
  launchWonJackpot(params: WonJackpotWidgetParams): void;
11
+ private sendDataToChild;
10
12
  destroyWonJackpot(): void;
11
13
  }
@@ -1,10 +1,8 @@
1
1
  import { BaseWidget } from '../BaseWidget';
2
- import { environment } from '../../environments/environment.prod.js';
3
- import { WonJackpotIframeIncomingEvent } from './types/event';
2
+ import { winWidgetIframeIncomingEvent, winWidgetIframeOutgoingEvent, } from './types/event';
4
3
  export class WonJackpotWidget extends BaseWidget {
5
4
  constructor() {
6
5
  super();
7
- this.childAppOrigin = environment.jackpotWidgetUrl;
8
6
  this.childMessageHandler = (event) => {
9
7
  var _a, _b;
10
8
  if (!((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.src))
@@ -12,7 +10,10 @@ export class WonJackpotWidget extends BaseWidget {
12
10
  if (event.origin !== this.childAppOrigin)
13
11
  return;
14
12
  switch ((_b = event.data) === null || _b === void 0 ? void 0 : _b.type) {
15
- case WonJackpotIframeIncomingEvent.jackpotWinClose:
13
+ case winWidgetIframeIncomingEvent.winWidgetLoaded:
14
+ this.sendDataToChild(winWidgetIframeOutgoingEvent.winWidgetDataIntitial, this.data);
15
+ break;
16
+ case winWidgetIframeIncomingEvent.winWidgetClose:
16
17
  this.emit('close');
17
18
  break;
18
19
  }
@@ -25,10 +26,13 @@ export class WonJackpotWidget extends BaseWidget {
25
26
  return WonJackpotWidget.instance;
26
27
  }
27
28
  launchWonJackpot(params) {
29
+ var _a;
28
30
  if (this.isWidgetLaunched()) {
29
31
  console.warn('Won Jackpot widget is already launched');
30
32
  return;
31
33
  }
34
+ this.data = params.data;
35
+ this.childAppOrigin = this.getBaseUrl((_a = params.mode) !== null && _a !== void 0 ? _a : 'production');
32
36
  this.iframe = this.createIframe();
33
37
  this.iframe.style.top = '0';
34
38
  this.iframe.style.left = '0';
@@ -36,11 +40,20 @@ export class WonJackpotWidget extends BaseWidget {
36
40
  this.iframe.style.height = '100%';
37
41
  this.iframe.style.zIndex = '9999999'; // 7
38
42
  this.iframe.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
39
- this.iframe.src = `${environment.jackpotWidgetUrl}/win-animation-widget`;
43
+ this.iframe.src = `${this.childAppOrigin}/win-animation-widget`;
40
44
  this.appendIframe(this.iframe, params.container);
41
45
  this.setLaunched(true);
42
46
  window.addEventListener('message', this.childMessageHandler);
43
47
  }
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
+ }
44
57
  destroyWonJackpot() {
45
58
  window.removeEventListener('message', this.childMessageHandler);
46
59
  this.removeIframe();
@@ -1,4 +1,6 @@
1
+ import { SDKMode } from 'src/widgets/shared/types';
1
2
  export interface WonJackpotWidgetParams {
2
- container?: string;
3
3
  data: unknown;
4
+ mode?: SDKMode;
5
+ container?: string;
4
6
  }
@@ -1,9 +1,10 @@
1
- export declare enum WonJackpotIframeIncomingEvent {
2
- footerWidgetLoaded = "jackpot-footer-widget-loaded",
3
- participateChange = "jackpot-footer-widget-participate-change",
4
- showPopup = "jackpot-footer-widget-popup-show",
5
- jackpotWinClose = "jackpot-win-close"
1
+ export declare enum winWidgetIframeIncomingEvent {
2
+ winWidgetLoaded = "jackpot-win-widget-loaded",
3
+ winWidgetClose = "jackpot-win-widget-close"
6
4
  }
7
- export type WonJackpotWidgetEvents = {
5
+ export declare enum winWidgetIframeOutgoingEvent {
6
+ winWidgetDataIntitial = "jackpot-win-widget-data-initial"
7
+ }
8
+ export type winWidgetWidgetEvents = {
8
9
  close: void;
9
10
  };
@@ -1,8 +1,11 @@
1
1
  // events emitted by app inside iframe to the SDK - Internal use
2
- export var WonJackpotIframeIncomingEvent;
3
- (function (WonJackpotIframeIncomingEvent) {
4
- WonJackpotIframeIncomingEvent["footerWidgetLoaded"] = "jackpot-footer-widget-loaded";
5
- WonJackpotIframeIncomingEvent["participateChange"] = "jackpot-footer-widget-participate-change";
6
- WonJackpotIframeIncomingEvent["showPopup"] = "jackpot-footer-widget-popup-show";
7
- WonJackpotIframeIncomingEvent["jackpotWinClose"] = "jackpot-win-close";
8
- })(WonJackpotIframeIncomingEvent || (WonJackpotIframeIncomingEvent = {}));
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
+ // 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 = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splash-tech/jackpot-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "SDK for managing jackpot widgets in iframes",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,10 +10,10 @@
10
10
  ],
11
11
  "scripts": {
12
12
  "clean": "rm -rf dist",
13
- "build:local": "npm run clean && tsc -p tsconfig.build.local.json && npx tsc-alias -p tsconfig.build.local.json",
14
- "build:dev": "npm run clean && tsc -p tsconfig.build.dev.json && npx tsc-alias -p tsconfig.build.dev.json",
15
- "build:staging": "npm run clean && tsc -p tsconfig.build.staging.json && npx tsc-alias -p tsconfig.build.staging.json",
16
- "build:prod": "npm run clean && tsc -p tsconfig.build.prod.json && npx tsc-alias -p tsconfig.build.prod.json",
13
+ "build:local": "npm run clean && tsc",
14
+ "build:dev": "npm run clean && tsc",
15
+ "build:staging": "npm run clean && tsc",
16
+ "build:prod": "npm run clean && tsc",
17
17
  "prepublishOnly": "npm run build:prod",
18
18
  "test": "echo \"Error: no test specified\" && exit 1"
19
19
  },
@@ -27,10 +27,6 @@
27
27
  "license": "MIT",
28
28
  "devDependencies": {
29
29
  "@types/node": "^20.11.19",
30
- "ts-loader": "^9.5.4",
31
- "tsc-alias": "^1.8.16",
32
- "typescript": "^5.8.2",
33
- "webpack": "^5.105.3",
34
- "webpack-cli": "^6.0.1"
30
+ "typescript": "^5.8.2"
35
31
  }
36
32
  }
@@ -1,4 +0,0 @@
1
- export declare const environment: {
2
- production: boolean;
3
- jackpotWidgetUrl: string;
4
- };
@@ -1,4 +0,0 @@
1
- export const environment = {
2
- production: true,
3
- jackpotWidgetUrl: 'https://jackpot-widget.splash.tech',
4
- };