@splash-tech/jackpot-sdk 1.0.4 → 1.0.5

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.
@@ -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;
@@ -1 +1,2 @@
1
+ export type SDKMode = 'local' | 'dev' | 'staging' | 'production';
1
2
  export type WidgetEventHandler = () => void;
@@ -1,10 +1,8 @@
1
1
  import { BaseWidget } from '../BaseWidget';
2
- import { environment } from '../../environments/environment.prod.js';
3
2
  import { WonJackpotIframeIncomingEvent } 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))
@@ -25,10 +23,12 @@ export class WonJackpotWidget extends BaseWidget {
25
23
  return WonJackpotWidget.instance;
26
24
  }
27
25
  launchWonJackpot(params) {
26
+ var _a;
28
27
  if (this.isWidgetLaunched()) {
29
28
  console.warn('Won Jackpot widget is already launched');
30
29
  return;
31
30
  }
31
+ this.childAppOrigin = this.getBaseUrl((_a = params.mode) !== null && _a !== void 0 ? _a : 'production');
32
32
  this.iframe = this.createIframe();
33
33
  this.iframe.style.top = '0';
34
34
  this.iframe.style.left = '0';
@@ -36,7 +36,7 @@ export class WonJackpotWidget extends BaseWidget {
36
36
  this.iframe.style.height = '100%';
37
37
  this.iframe.style.zIndex = '9999999'; // 7
38
38
  this.iframe.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
39
- this.iframe.src = `${environment.jackpotWidgetUrl}/win-animation-widget`;
39
+ this.iframe.src = `${this.childAppOrigin}/win-animation-widget`;
40
40
  this.appendIframe(this.iframe, params.container);
41
41
  this.setLaunched(true);
42
42
  window.addEventListener('message', this.childMessageHandler);
@@ -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
  }
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.5",
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
- };