@splash-tech/jackpot-sdk 1.0.3 → 1.0.4

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,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.environment = void 0;
4
- exports.environment = {
1
+ export const environment = {
5
2
  production: true,
6
3
  jackpotWidgetUrl: 'https://jackpot-widget.splash.tech',
7
4
  };
package/dist/index.js CHANGED
@@ -1,36 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.splashJackpot = void 0;
4
- var FooterWidget_1 = require("./widgets/footerWidget/FooterWidget");
5
- var WonJackpotWidget_1 = require("./widgets/wonJackpotWidget/WonJackpotWidget");
6
- var footerWidget = FooterWidget_1.FooterWidget.getInstance();
7
- var wonJackpotWidget = WonJackpotWidget_1.WonJackpotWidget.getInstance();
8
- exports.splashJackpot = {
1
+ import { FooterWidget } from './widgets/footerWidget/FooterWidget';
2
+ import { WonJackpotWidget } from './widgets/wonJackpotWidget/WonJackpotWidget';
3
+ const footerWidget = FooterWidget.getInstance();
4
+ const wonJackpotWidget = WonJackpotWidget.getInstance();
5
+ export const splashJackpot = {
9
6
  footer: {
10
- isLaunched: function () { return footerWidget.isWidgetLaunched(); },
11
- launch: function (params) { return footerWidget.launchFooter(params); },
12
- updateData: function (partialData) { return footerWidget.updateData(partialData); },
13
- showPopup: function () { return footerWidget.showPopup(); },
14
- hidePopup: function () { return footerWidget.hidePopup(); },
15
- destroy: function () { return footerWidget.destroyFooter(); },
16
- addEventListener: function (event, handler) {
17
- return footerWidget.addEventListener(event, handler);
18
- },
19
- removeEventListener: function (event, handler) {
20
- return footerWidget.removeEventListener(event, handler);
21
- },
7
+ isLaunched: () => footerWidget.isWidgetLaunched(),
8
+ launch: (params) => footerWidget.launchFooter(params),
9
+ updateData: (partialData) => footerWidget.updateData(partialData),
10
+ showPopup: () => footerWidget.showPopup(),
11
+ hidePopup: () => footerWidget.hidePopup(),
12
+ destroy: () => footerWidget.destroyFooter(),
13
+ addEventListener: (event, handler) => footerWidget.addEventListener(event, handler),
14
+ removeEventListener: (event, handler) => footerWidget.removeEventListener(event, handler),
22
15
  },
23
16
  wonJackpot: {
24
- isLaunched: function () { return wonJackpotWidget.isWidgetLaunched(); },
25
- launch: function (params) {
26
- return wonJackpotWidget.launchWonJackpot(params);
27
- },
28
- destroy: function () { return wonJackpotWidget.destroyWonJackpot(); },
29
- addEventListener: function (event, handler) {
30
- return wonJackpotWidget.addEventListener(event, handler);
31
- },
32
- removeEventListener: function (event, handler) {
33
- return wonJackpotWidget.removeEventListener(event, handler);
34
- },
17
+ isLaunched: () => wonJackpotWidget.isWidgetLaunched(),
18
+ launch: (params) => wonJackpotWidget.launchWonJackpot(params),
19
+ destroy: () => wonJackpotWidget.destroyWonJackpot(),
20
+ addEventListener: (event, handler) => wonJackpotWidget.addEventListener(event, handler),
21
+ removeEventListener: (event, handler) => wonJackpotWidget.removeEventListener(event, handler),
35
22
  },
36
23
  };
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,41 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseWidget = void 0;
4
- var BaseWidget = /** @class */ (function () {
5
- function BaseWidget() {
1
+ export class BaseWidget {
2
+ constructor() {
6
3
  this.iframe = null;
7
4
  this.isLaunched = false;
8
5
  this.listeners = new Map();
9
6
  }
10
- BaseWidget.prototype.emit = function (event, payload) {
11
- var handlers = this.listeners.get(event);
12
- handlers === null || handlers === void 0 ? void 0 : handlers.forEach(function (handler) { return handler(); });
13
- };
14
- BaseWidget.prototype.addEventListener = function (event, handler) {
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) {
15
12
  if (!this.listeners.has(event)) {
16
13
  this.listeners.set(event, []);
17
14
  }
18
15
  this.listeners.get(event).push(handler);
19
- };
20
- BaseWidget.prototype.removeEventListener = function (event, handler) {
21
- var handlers = this.listeners.get(event);
16
+ }
17
+ removeEventListener(event, handler) {
18
+ const handlers = this.listeners.get(event);
22
19
  if (!handlers)
23
20
  return;
24
- this.listeners.set(event, handlers.filter(function (h) { return h !== handler; }));
25
- };
26
- BaseWidget.prototype.createIframe = function () {
27
- var iframe = document.createElement('iframe');
21
+ this.listeners.set(event, handlers.filter((h) => h !== handler));
22
+ }
23
+ createIframe() {
24
+ const iframe = document.createElement('iframe');
28
25
  iframe.style.border = 'none';
29
26
  iframe.style.position = 'fixed';
30
27
  iframe.style.zIndex = '999999';
31
28
  return iframe;
32
- };
33
- BaseWidget.prototype.appendIframe = function (iframe, container) {
34
- var targetContainer = container
29
+ }
30
+ appendIframe(iframe, container) {
31
+ const targetContainer = container
35
32
  ? document.querySelector(container)
36
33
  : document.body;
37
34
  if (!targetContainer) {
38
- console.error("Container \"".concat(container, "\" not found"));
35
+ console.error(`Container "${container}" not found`);
39
36
  document.body.appendChild(iframe);
40
37
  }
41
38
  else {
@@ -45,20 +42,18 @@ var BaseWidget = /** @class */ (function () {
45
42
  }
46
43
  targetContainer.appendChild(iframe);
47
44
  }
48
- };
49
- BaseWidget.prototype.removeIframe = function () {
45
+ }
46
+ removeIframe() {
50
47
  if (this.iframe && this.iframe.parentNode) {
51
48
  this.iframe.parentNode.removeChild(this.iframe);
52
49
  this.iframe = null;
53
50
  this.isLaunched = false;
54
51
  }
55
- };
56
- BaseWidget.prototype.setLaunched = function (launched) {
52
+ }
53
+ setLaunched(launched) {
57
54
  this.isLaunched = launched;
58
- };
59
- BaseWidget.prototype.isWidgetLaunched = function () {
55
+ }
56
+ isWidgetLaunched() {
60
57
  return this.isLaunched;
61
- };
62
- return BaseWidget;
63
- }());
64
- exports.BaseWidget = BaseWidget;
58
+ }
59
+ }
@@ -1,74 +1,54 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.FooterWidget = void 0;
19
- var BaseWidget_1 = require("../BaseWidget");
20
- var _environment_1 = require("../../environments/environment.prod.js");
21
- var event_1 = require("./types/event");
22
- var FooterWidget = /** @class */ (function (_super) {
23
- __extends(FooterWidget, _super);
24
- function FooterWidget() {
25
- var _this = _super.call(this) || this;
26
- _this.childAppOrigin = _environment_1.environment.jackpotWidgetUrl;
1
+ import { BaseWidget } from '../BaseWidget';
2
+ import { environment } from '../../environments/environment.prod.js';
3
+ import { FooterIframeIncomingEvent, FooterIframeOutgoingEvent, } from './types/event';
4
+ export class FooterWidget extends BaseWidget {
5
+ constructor() {
6
+ super();
7
+ this.childAppOrigin = environment.jackpotWidgetUrl;
27
8
  // listen for messages of an app that is inside iframe
28
- _this.childMessageHandler = function (event) {
9
+ this.childMessageHandler = (event) => {
29
10
  var _a, _b;
30
- if (!((_a = _this.iframe) === null || _a === void 0 ? void 0 : _a.src))
11
+ if (!((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.src))
31
12
  return;
32
- if (event.origin !== _this.childAppOrigin)
13
+ if (event.origin !== this.childAppOrigin)
33
14
  return;
34
15
  switch ((_b = event.data) === null || _b === void 0 ? void 0 : _b.type) {
35
- case event_1.FooterIframeIncomingEvent.footerWidgetLoaded:
36
- _this.sendDataToChild(event_1.FooterIframeOutgoingEvent.footerWidgetDataInitial, _this.data);
16
+ case FooterIframeIncomingEvent.footerWidgetLoaded:
17
+ this.sendDataToChild(FooterIframeOutgoingEvent.footerWidgetDataInitial, this.data);
37
18
  break;
38
- case event_1.FooterIframeIncomingEvent.showPopup: {
39
- _this.emit('showPopup');
40
- _this.showPopup();
19
+ case FooterIframeIncomingEvent.showPopup: {
20
+ this.emit('showPopup');
21
+ this.showPopup();
41
22
  break;
42
23
  }
43
- case event_1.FooterIframeIncomingEvent.hidePopup: {
44
- _this.emit('hidePopup');
45
- _this.hidePopup();
24
+ case FooterIframeIncomingEvent.hidePopup: {
25
+ this.emit('hidePopup');
26
+ this.hidePopup();
46
27
  break;
47
28
  }
48
- case event_1.FooterIframeIncomingEvent.participateChange: {
49
- _this.emit('participateChange');
29
+ case FooterIframeIncomingEvent.participateChange: {
30
+ this.emit('participateChange');
50
31
  break;
51
32
  }
52
33
  }
53
34
  };
54
- return _this;
55
35
  }
56
- FooterWidget.getInstance = function () {
36
+ static getInstance() {
57
37
  if (!FooterWidget.instance) {
58
38
  FooterWidget.instance = new FooterWidget();
59
39
  }
60
40
  return FooterWidget.instance;
61
- };
62
- FooterWidget.prototype.sendDataToChild = function (type, data) {
41
+ }
42
+ sendDataToChild(type, data) {
63
43
  var _a;
64
44
  if (((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) && data !== undefined) {
65
45
  this.iframe.contentWindow.postMessage({
66
- type: type,
46
+ type,
67
47
  payload: data,
68
48
  }, this.childAppOrigin);
69
49
  }
70
- };
71
- FooterWidget.prototype.launchFooter = function (params) {
50
+ }
51
+ launchFooter(params) {
72
52
  if (this.isWidgetLaunched()) {
73
53
  console.warn('Footer widget is already launched');
74
54
  return;
@@ -80,12 +60,12 @@ var FooterWidget = /** @class */ (function (_super) {
80
60
  this.iframe.style.width = '100%';
81
61
  this.iframe.style.height = '50px';
82
62
  this.iframe.style.zIndex = '999999'; // 6
83
- this.iframe.src = "".concat(_environment_1.environment.jackpotWidgetUrl, "/footer-widget");
63
+ this.iframe.src = `${environment.jackpotWidgetUrl}/footer-widget`;
84
64
  this.appendIframe(this.iframe, params.container);
85
65
  this.setLaunched(true);
86
66
  window.addEventListener('message', this.childMessageHandler);
87
- };
88
- FooterWidget.prototype.updateData = function (partialData) {
67
+ }
68
+ updateData(partialData) {
89
69
  // must be a non-null object
90
70
  if (!partialData || typeof partialData !== 'object') {
91
71
  console.error('FooterWidget.updateData: invalid payload', partialData);
@@ -96,22 +76,20 @@ var FooterWidget = /** @class */ (function (_super) {
96
76
  console.error('FooterWidget.updateData: empty object provided');
97
77
  return;
98
78
  }
99
- this.sendDataToChild(event_1.FooterIframeOutgoingEvent.footerWidgetDataUpdated, partialData);
100
- };
101
- FooterWidget.prototype.showPopup = function () {
79
+ this.sendDataToChild(FooterIframeOutgoingEvent.footerWidgetDataUpdated, partialData);
80
+ }
81
+ showPopup() {
102
82
  if (this.iframe) {
103
83
  this.iframe.style.height = '100%';
104
84
  }
105
- };
106
- FooterWidget.prototype.hidePopup = function () {
85
+ }
86
+ hidePopup() {
107
87
  if (this.iframe) {
108
88
  this.iframe.style.height = '50px';
109
89
  }
110
- };
111
- FooterWidget.prototype.destroyFooter = function () {
90
+ }
91
+ destroyFooter() {
112
92
  window.removeEventListener('message', this.childMessageHandler);
113
93
  this.removeIframe();
114
- };
115
- return FooterWidget;
116
- }(BaseWidget_1.BaseWidget));
117
- exports.FooterWidget = FooterWidget;
94
+ }
95
+ }
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FooterIframeOutgoingEvent = exports.FooterIframeIncomingEvent = void 0;
4
1
  // events emitted by app inside iframe to the SDK - Internal use
5
- var FooterIframeIncomingEvent;
2
+ export var FooterIframeIncomingEvent;
6
3
  (function (FooterIframeIncomingEvent) {
7
4
  FooterIframeIncomingEvent["footerWidgetLoaded"] = "jackpot-footer-widget-loaded";
8
5
  FooterIframeIncomingEvent["participateChange"] = "jackpot-footer-widget-participate-change";
9
6
  FooterIframeIncomingEvent["showPopup"] = "jackpot-footer-widget-popup-show";
10
7
  FooterIframeIncomingEvent["hidePopup"] = "jackpot-footer-widget-popup-hide";
11
- })(FooterIframeIncomingEvent || (exports.FooterIframeIncomingEvent = FooterIframeIncomingEvent = {}));
8
+ })(FooterIframeIncomingEvent || (FooterIframeIncomingEvent = {}));
12
9
  // events emitted by SDK to the app inside iframe- Internal use
13
- var FooterIframeOutgoingEvent;
10
+ export var FooterIframeOutgoingEvent;
14
11
  (function (FooterIframeOutgoingEvent) {
15
12
  FooterIframeOutgoingEvent["footerWidgetDataInitial"] = "jackpot-footer-widget-data-initial";
16
13
  FooterIframeOutgoingEvent["footerWidgetDataUpdated"] = "jackpot-footer-widget-data-updated";
17
- })(FooterIframeOutgoingEvent || (exports.FooterIframeOutgoingEvent = FooterIframeOutgoingEvent = {}));
14
+ })(FooterIframeOutgoingEvent || (FooterIframeOutgoingEvent = {}));
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,50 +1,30 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.WonJackpotWidget = void 0;
19
- var BaseWidget_1 = require("../BaseWidget");
20
- var _environment_1 = require("../../environments/environment.prod.js");
21
- var event_1 = require("./types/event");
22
- var WonJackpotWidget = /** @class */ (function (_super) {
23
- __extends(WonJackpotWidget, _super);
24
- function WonJackpotWidget() {
25
- var _this = _super.call(this) || this;
26
- _this.childAppOrigin = _environment_1.environment.jackpotWidgetUrl;
27
- _this.childMessageHandler = function (event) {
1
+ import { BaseWidget } from '../BaseWidget';
2
+ import { environment } from '../../environments/environment.prod.js';
3
+ import { WonJackpotIframeIncomingEvent } from './types/event';
4
+ export class WonJackpotWidget extends BaseWidget {
5
+ constructor() {
6
+ super();
7
+ this.childAppOrigin = environment.jackpotWidgetUrl;
8
+ this.childMessageHandler = (event) => {
28
9
  var _a, _b;
29
- if (!((_a = _this.iframe) === null || _a === void 0 ? void 0 : _a.src))
10
+ if (!((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.src))
30
11
  return;
31
- if (event.origin !== _this.childAppOrigin)
12
+ if (event.origin !== this.childAppOrigin)
32
13
  return;
33
14
  switch ((_b = event.data) === null || _b === void 0 ? void 0 : _b.type) {
34
- case event_1.WonJackpotIframeIncomingEvent.jackpotWinClose:
35
- _this.emit('close');
15
+ case WonJackpotIframeIncomingEvent.jackpotWinClose:
16
+ this.emit('close');
36
17
  break;
37
18
  }
38
19
  };
39
- return _this;
40
20
  }
41
- WonJackpotWidget.getInstance = function () {
21
+ static getInstance() {
42
22
  if (!WonJackpotWidget.instance) {
43
23
  WonJackpotWidget.instance = new WonJackpotWidget();
44
24
  }
45
25
  return WonJackpotWidget.instance;
46
- };
47
- WonJackpotWidget.prototype.launchWonJackpot = function (params) {
26
+ }
27
+ launchWonJackpot(params) {
48
28
  if (this.isWidgetLaunched()) {
49
29
  console.warn('Won Jackpot widget is already launched');
50
30
  return;
@@ -56,15 +36,13 @@ var WonJackpotWidget = /** @class */ (function (_super) {
56
36
  this.iframe.style.height = '100%';
57
37
  this.iframe.style.zIndex = '9999999'; // 7
58
38
  this.iframe.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
59
- this.iframe.src = "".concat(_environment_1.environment.jackpotWidgetUrl, "/win-animation-widget");
39
+ this.iframe.src = `${environment.jackpotWidgetUrl}/win-animation-widget`;
60
40
  this.appendIframe(this.iframe, params.container);
61
41
  this.setLaunched(true);
62
42
  window.addEventListener('message', this.childMessageHandler);
63
- };
64
- WonJackpotWidget.prototype.destroyWonJackpot = function () {
43
+ }
44
+ destroyWonJackpot() {
65
45
  window.removeEventListener('message', this.childMessageHandler);
66
46
  this.removeIframe();
67
- };
68
- return WonJackpotWidget;
69
- }(BaseWidget_1.BaseWidget));
70
- exports.WonJackpotWidget = WonJackpotWidget;
47
+ }
48
+ }
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WonJackpotIframeIncomingEvent = void 0;
4
1
  // events emitted by app inside iframe to the SDK - Internal use
5
- var WonJackpotIframeIncomingEvent;
2
+ export var WonJackpotIframeIncomingEvent;
6
3
  (function (WonJackpotIframeIncomingEvent) {
7
4
  WonJackpotIframeIncomingEvent["footerWidgetLoaded"] = "jackpot-footer-widget-loaded";
8
5
  WonJackpotIframeIncomingEvent["participateChange"] = "jackpot-footer-widget-participate-change";
9
6
  WonJackpotIframeIncomingEvent["showPopup"] = "jackpot-footer-widget-popup-show";
10
7
  WonJackpotIframeIncomingEvent["jackpotWinClose"] = "jackpot-win-close";
11
- })(WonJackpotIframeIncomingEvent || (exports.WonJackpotIframeIncomingEvent = WonJackpotIframeIncomingEvent = {}));
8
+ })(WonJackpotIframeIncomingEvent || (WonJackpotIframeIncomingEvent = {}));
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@splash-tech/jackpot-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "SDK for managing jackpot widgets in iframes",
5
- "type": "module",
6
5
  "main": "dist/index.js",
7
6
  "types": "dist/index.d.ts",
8
7
  "files": [