@splash-tech/jackpot-sdk 1.0.2 → 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.
@@ -0,0 +1,4 @@
1
+ export const environment = {
2
+ production: true,
3
+ jackpotWidgetUrl: 'https://jackpot-widget.splash.tech',
4
+ };
package/dist/index.js CHANGED
@@ -1 +1,23 @@
1
- var e={283(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.environment=void 0,t.environment={production:!0,jackpotWidgetUrl:"https://jackpot-widget.splash.tech"}},529(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.BaseWidget=void 0;var o=function(){function e(){this.iframe=null,this.isLaunched=!1,this.listeners=new Map}return e.prototype.emit=function(e,t){var o=this.listeners.get(e);null==o||o.forEach(function(e){return e()})},e.prototype.addEventListener=function(e,t){this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t)},e.prototype.removeEventListener=function(e,t){var o=this.listeners.get(e);o&&this.listeners.set(e,o.filter(function(e){return e!==t}))},e.prototype.createIframe=function(){var e=document.createElement("iframe");return e.style.border="none",e.style.position="fixed",e.style.zIndex="999999",e},e.prototype.appendIframe=function(e,t){var o=t?document.querySelector(t):document.body;o?(t&&(e.style.position="absolute",o.style.position="relative"),o.appendChild(e)):(console.error('Container "'.concat(t,'" not found')),document.body.appendChild(e))},e.prototype.removeIframe=function(){this.iframe&&this.iframe.parentNode&&(this.iframe.parentNode.removeChild(this.iframe),this.iframe=null,this.isLaunched=!1)},e.prototype.setLaunched=function(e){this.isLaunched=e},e.prototype.isWidgetLaunched=function(){return this.isLaunched},e}();t.BaseWidget=o},489(e,t,o){var n,i=this&&this.__extends||(n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)});Object.defineProperty(t,"__esModule",{value:!0}),t.FooterWidget=void 0;var r=o(529),a=o(283),s=o(978),c=function(e){function t(){var t=e.call(this)||this;return t.childAppOrigin=a.environment.jackpotWidgetUrl,t.childMessageHandler=function(e){var o,n;if((null===(o=t.iframe)||void 0===o?void 0:o.src)&&e.origin===t.childAppOrigin)switch(null===(n=e.data)||void 0===n?void 0:n.type){case s.FooterIframeIncomingEvent.footerWidgetLoaded:t.sendDataToChild(s.FooterIframeOutgoingEvent.footerWidgetDataInitial,t.data);break;case s.FooterIframeIncomingEvent.showPopup:t.emit("showPopup"),t.showPopup();break;case s.FooterIframeIncomingEvent.hidePopup:t.emit("hidePopup"),t.hidePopup();break;case s.FooterIframeIncomingEvent.participateChange:t.emit("participateChange")}},t}return i(t,e),t.getInstance=function(){return t.instance||(t.instance=new t),t.instance},t.prototype.sendDataToChild=function(e,t){var o;(null===(o=this.iframe)||void 0===o?void 0:o.contentWindow)&&void 0!==t&&this.iframe.contentWindow.postMessage({type:e,payload:t},this.childAppOrigin)},t.prototype.launchFooter=function(e){this.isWidgetLaunched()?console.warn("Footer widget is already launched"):(this.data=e.data,this.iframe=this.createIframe(),this.iframe.style.bottom="0",this.iframe.style.left="0",this.iframe.style.width="100%",this.iframe.style.height="50px",this.iframe.style.zIndex="999999",this.iframe.src="".concat(a.environment.jackpotWidgetUrl,"/footer-widget"),this.appendIframe(this.iframe,e.container),this.setLaunched(!0),window.addEventListener("message",this.childMessageHandler))},t.prototype.updateData=function(e){e&&"object"==typeof e?0!==Object.keys(e).length?this.sendDataToChild(s.FooterIframeOutgoingEvent.footerWidgetDataUpdated,e):console.error("FooterWidget.updateData: empty object provided"):console.error("FooterWidget.updateData: invalid payload",e)},t.prototype.showPopup=function(){this.iframe&&(this.iframe.style.height="100%")},t.prototype.hidePopup=function(){this.iframe&&(this.iframe.style.height="50px")},t.prototype.destroyFooter=function(){window.removeEventListener("message",this.childMessageHandler),this.removeIframe()},t}(r.BaseWidget);t.FooterWidget=c},978(e,t){var o,n;Object.defineProperty(t,"__esModule",{value:!0}),t.FooterIframeOutgoingEvent=t.FooterIframeIncomingEvent=void 0,function(e){e.footerWidgetLoaded="jackpot-footer-widget-loaded",e.participateChange="jackpot-footer-widget-participate-change",e.showPopup="jackpot-footer-widget-popup-show",e.hidePopup="jackpot-footer-widget-popup-hide"}(o||(t.FooterIframeIncomingEvent=o={})),function(e){e.footerWidgetDataInitial="jackpot-footer-widget-data-initial",e.footerWidgetDataUpdated="jackpot-footer-widget-data-updated"}(n||(t.FooterIframeOutgoingEvent=n={}))},79(e,t,o){var n,i=this&&this.__extends||(n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)});Object.defineProperty(t,"__esModule",{value:!0}),t.WonJackpotWidget=void 0;var r=o(529),a=o(283),s=o(95),c=function(e){function t(){var t=e.call(this)||this;return t.childAppOrigin=a.environment.jackpotWidgetUrl,t.childMessageHandler=function(e){var o,n;(null===(o=t.iframe)||void 0===o?void 0:o.src)&&e.origin===t.childAppOrigin&&(null===(n=e.data)||void 0===n?void 0:n.type)===s.WonJackpotIframeIncomingEvent.jackpotWinClose&&t.emit("close")},t}return i(t,e),t.getInstance=function(){return t.instance||(t.instance=new t),t.instance},t.prototype.launchWonJackpot=function(e){this.isWidgetLaunched()?console.warn("Won Jackpot widget is already launched"):(this.iframe=this.createIframe(),this.iframe.style.top="0",this.iframe.style.left="0",this.iframe.style.width="100%",this.iframe.style.height="100%",this.iframe.style.zIndex="9999999",this.iframe.style.backgroundColor="rgba(0, 0, 0, 0.5)",this.iframe.src="".concat(a.environment.jackpotWidgetUrl,"/win-animation-widget"),this.appendIframe(this.iframe,e.container),this.setLaunched(!0),window.addEventListener("message",this.childMessageHandler))},t.prototype.destroyWonJackpot=function(){window.removeEventListener("message",this.childMessageHandler),this.removeIframe()},t}(r.BaseWidget);t.WonJackpotWidget=c},95(e,t){var o;Object.defineProperty(t,"__esModule",{value:!0}),t.WonJackpotIframeIncomingEvent=void 0,function(e){e.footerWidgetLoaded="jackpot-footer-widget-loaded",e.participateChange="jackpot-footer-widget-participate-change",e.showPopup="jackpot-footer-widget-popup-show",e.jackpotWinClose="jackpot-win-close"}(o||(t.WonJackpotIframeIncomingEvent=o={}))}},t={};function o(n){var i=t[n];if(void 0!==i)return i.exports;var r=t[n]={exports:{}};return e[n].call(r.exports,r,r.exports,o),r.exports}var n={};(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.splashJackpot=void 0;var t=o(489),i=o(79),r=t.FooterWidget.getInstance(),a=i.WonJackpotWidget.getInstance();e.splashJackpot={footer:{isLaunched:function(){return r.isWidgetLaunched()},launch:function(e){return r.launchFooter(e)},updateData:function(e){return r.updateData(e)},showPopup:function(){return r.showPopup()},hidePopup:function(){return r.hidePopup()},destroy:function(){return r.destroyFooter()},addEventListener:function(e,t){return r.addEventListener(e,t)},removeEventListener:function(e,t){return r.removeEventListener(e,t)}},wonJackpot:{isLaunched:function(){return a.isWidgetLaunched()},launch:function(e){return a.launchWonJackpot(e)},destroy:function(){return a.destroyWonJackpot()},addEventListener:function(e,t){return a.addEventListener(e,t)},removeEventListener:function(e,t){return a.removeEventListener(e,t)}}}})();const i=n.__esModule,r=n.splashJackpot;export{i as __esModule,r as splashJackpot,n as default};
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 = {
6
+ footer: {
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),
15
+ },
16
+ wonJackpot: {
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),
22
+ },
23
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ export class BaseWidget {
2
+ constructor() {
3
+ this.iframe = null;
4
+ this.isLaunched = false;
5
+ this.listeners = new Map();
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, []);
14
+ }
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
+ }
23
+ createIframe() {
24
+ const iframe = document.createElement('iframe');
25
+ iframe.style.border = 'none';
26
+ iframe.style.position = 'fixed';
27
+ iframe.style.zIndex = '999999';
28
+ return iframe;
29
+ }
30
+ appendIframe(iframe, container) {
31
+ const targetContainer = container
32
+ ? document.querySelector(container)
33
+ : document.body;
34
+ if (!targetContainer) {
35
+ console.error(`Container "${container}" not found`);
36
+ document.body.appendChild(iframe);
37
+ }
38
+ else {
39
+ if (container) {
40
+ iframe.style.position = 'absolute';
41
+ targetContainer.style.position = 'relative';
42
+ }
43
+ targetContainer.appendChild(iframe);
44
+ }
45
+ }
46
+ removeIframe() {
47
+ if (this.iframe && this.iframe.parentNode) {
48
+ this.iframe.parentNode.removeChild(this.iframe);
49
+ this.iframe = null;
50
+ this.isLaunched = false;
51
+ }
52
+ }
53
+ setLaunched(launched) {
54
+ this.isLaunched = launched;
55
+ }
56
+ isWidgetLaunched() {
57
+ return this.isLaunched;
58
+ }
59
+ }
@@ -0,0 +1,95 @@
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;
8
+ // listen for messages of an app that is inside iframe
9
+ this.childMessageHandler = (event) => {
10
+ var _a, _b;
11
+ if (!((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.src))
12
+ return;
13
+ if (event.origin !== this.childAppOrigin)
14
+ return;
15
+ switch ((_b = event.data) === null || _b === void 0 ? void 0 : _b.type) {
16
+ case FooterIframeIncomingEvent.footerWidgetLoaded:
17
+ this.sendDataToChild(FooterIframeOutgoingEvent.footerWidgetDataInitial, this.data);
18
+ break;
19
+ case FooterIframeIncomingEvent.showPopup: {
20
+ this.emit('showPopup');
21
+ this.showPopup();
22
+ break;
23
+ }
24
+ case FooterIframeIncomingEvent.hidePopup: {
25
+ this.emit('hidePopup');
26
+ this.hidePopup();
27
+ break;
28
+ }
29
+ case FooterIframeIncomingEvent.participateChange: {
30
+ this.emit('participateChange');
31
+ break;
32
+ }
33
+ }
34
+ };
35
+ }
36
+ static getInstance() {
37
+ if (!FooterWidget.instance) {
38
+ FooterWidget.instance = new FooterWidget();
39
+ }
40
+ return FooterWidget.instance;
41
+ }
42
+ sendDataToChild(type, data) {
43
+ var _a;
44
+ if (((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) && data !== undefined) {
45
+ this.iframe.contentWindow.postMessage({
46
+ type,
47
+ payload: data,
48
+ }, this.childAppOrigin);
49
+ }
50
+ }
51
+ launchFooter(params) {
52
+ if (this.isWidgetLaunched()) {
53
+ console.warn('Footer widget is already launched');
54
+ return;
55
+ }
56
+ this.data = params.data;
57
+ this.iframe = this.createIframe();
58
+ this.iframe.style.bottom = '0';
59
+ this.iframe.style.left = '0';
60
+ this.iframe.style.width = '100%';
61
+ this.iframe.style.height = '50px';
62
+ this.iframe.style.zIndex = '999999'; // 6
63
+ this.iframe.src = `${environment.jackpotWidgetUrl}/footer-widget`;
64
+ this.appendIframe(this.iframe, params.container);
65
+ this.setLaunched(true);
66
+ window.addEventListener('message', this.childMessageHandler);
67
+ }
68
+ updateData(partialData) {
69
+ // must be a non-null object
70
+ if (!partialData || typeof partialData !== 'object') {
71
+ console.error('FooterWidget.updateData: invalid payload', partialData);
72
+ return;
73
+ }
74
+ // ignore empty object {}
75
+ if (Object.keys(partialData).length === 0) {
76
+ console.error('FooterWidget.updateData: empty object provided');
77
+ return;
78
+ }
79
+ this.sendDataToChild(FooterIframeOutgoingEvent.footerWidgetDataUpdated, partialData);
80
+ }
81
+ showPopup() {
82
+ if (this.iframe) {
83
+ this.iframe.style.height = '100%';
84
+ }
85
+ }
86
+ hidePopup() {
87
+ if (this.iframe) {
88
+ this.iframe.style.height = '50px';
89
+ }
90
+ }
91
+ destroyFooter() {
92
+ window.removeEventListener('message', this.childMessageHandler);
93
+ this.removeIframe();
94
+ }
95
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
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 = {}));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
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) => {
9
+ var _a, _b;
10
+ if (!((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.src))
11
+ return;
12
+ if (event.origin !== this.childAppOrigin)
13
+ return;
14
+ switch ((_b = event.data) === null || _b === void 0 ? void 0 : _b.type) {
15
+ case WonJackpotIframeIncomingEvent.jackpotWinClose:
16
+ this.emit('close');
17
+ break;
18
+ }
19
+ };
20
+ }
21
+ static getInstance() {
22
+ if (!WonJackpotWidget.instance) {
23
+ WonJackpotWidget.instance = new WonJackpotWidget();
24
+ }
25
+ return WonJackpotWidget.instance;
26
+ }
27
+ launchWonJackpot(params) {
28
+ if (this.isWidgetLaunched()) {
29
+ console.warn('Won Jackpot widget is already launched');
30
+ return;
31
+ }
32
+ this.iframe = this.createIframe();
33
+ this.iframe.style.top = '0';
34
+ this.iframe.style.left = '0';
35
+ this.iframe.style.width = '100%';
36
+ this.iframe.style.height = '100%';
37
+ this.iframe.style.zIndex = '9999999'; // 7
38
+ this.iframe.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
39
+ this.iframe.src = `${environment.jackpotWidgetUrl}/win-animation-widget`;
40
+ this.appendIframe(this.iframe, params.container);
41
+ this.setLaunched(true);
42
+ window.addEventListener('message', this.childMessageHandler);
43
+ }
44
+ destroyWonJackpot() {
45
+ window.removeEventListener('message', this.childMessageHandler);
46
+ this.removeIframe();
47
+ }
48
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
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 = {}));
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@splash-tech/jackpot-sdk",
3
- "version": "1.0.2",
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": [
@@ -10,14 +9,11 @@
10
9
  "README.md"
11
10
  ],
12
11
  "scripts": {
13
- "build": "webpack --env local --mode development",
14
- "build:dev": "webpack --env dev --mode development",
15
- "build:staging": "webpack --env staging --mode production",
16
- "build:prod": "webpack --env production --mode production",
17
- "serve": "webpack serve --env local --mode development",
18
- "serve:dev": "webpack serve --env dev --mode development",
19
- "serve:staging": "webpack serve --env staging --mode production",
20
- "serve:prod": "webpack serve --env production --mode production",
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",
21
17
  "prepublishOnly": "npm run build:prod",
22
18
  "test": "echo \"Error: no test specified\" && exit 1"
23
19
  },
@@ -1,4 +0,0 @@
1
- export declare const environment: {
2
- production: boolean;
3
- jackpotWidgetUrl: string;
4
- };