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