@goodgamestudios/cxf-announcements
Advanced tools
Comparing version 0.19.4-qa.0 to 0.19.4-qa.1
@@ -1,2 +0,1104 @@ | ||
!function(){function t(t){return t&&t.__esModule?t.default:t}var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},n={},r={},o=e.parcelRequire3fb7;function a(t,e,n,r,o,a,i){try{var c=t[a](i),u=c.value}catch(t){return void n(t)}c.done?e(u):Promise.resolve(u).then(r,o)}function i(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var i=t.apply(e,n);function c(t){a(i,r,o,c,u,"next",t)}function u(t){a(i,r,o,c,u,"throw",t)}c(void 0)}))}}function c(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter((function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable})))),r.forEach((function(e){c(t,e,n[e])}))}return t}function s(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function l(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||s(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}null==o&&((o=function(t){if(t in n)return n[t].exports;if(t in r){var e=r[t];delete r[t];var o={id:t,exports:{}};return n[t]=o,e.call(o.exports,o,o.exports),o.exports}var a=new Error("Cannot find module '"+t+"'");throw a.code="MODULE_NOT_FOUND",a}).register=function(t,e){r[t]=e},e.parcelRequire3fb7=o),o.register("jvuiF",(function(t,e){t.exports={getPlayerInfo:function(t){var e=JSON.parse(t[1]);return{playername:e.gpi.PN,level:e.gxp.LVL}},getLevel:function(t){return JSON.parse(t[1]).LVL},lastTutorialLevel:5,loginCmd:"gbd",levelUpCmd:"gxp"}})),o.register("7y43J",(function(t,e){t.exports={getPlayerInfo:function(t){return{playername:t.playerIdentity.name,level:t.xp.level}},getLevel:function(t){return t.newLevel},lastTutorialLevel:1,loginCmd:"LOGIN_BASIC_DATA",levelUpCmd:"LEVEL_UP"}})),o.register("5uSe0",(function(t,e){t.exports={getPlayerInfo:function(t){var e=JSON.parse(t[1]);return{playername:e.gpi.PN,level:e.gxp.LVL}},getLevel:function(t){return JSON.parse(t[1]).LVL},lastTutorialLevel:5,loginCmd:"gbd",levelUpCmd:"gxp",logoutCmd:"LOGOUT"}})),o.register("4y3pw",(function(e,n){var r=o("5mFHf");o("6RIYV");var a=o("2lV2D").acronym,c=f.appendLoginParameters,l=f.ANNOUNCEMENTS_LOCALSTORAGE_KEY,h=f.hashCode,g=f.getHashKey,d=f.logger,p=y.getDoNotShowMessages,m=_.CXF_DIALOG_OPEN,v=N.GAME_CALLBACK,w=C.tracking,E=C.OPEN_ANNOUNCEMENTS,A=C.ANNOUNCEMENT_READY,S=function(t){var e=t.game,n=t.playername,r=t.network,o=t.instance,a=g(e,n,r,o);return p(a)},O=function(t){return function(e){return e.filter((function(e){return!t.includes(h(e.title+e.message))}))}},L=function(t){return t&&t.Count>0||!1},b=function(t,e){return function(n,r){var o=r.network,a=r.instance,i=r.lang,c=r.playername,s=e.game;if(L(n)){var f=S({game:s,playername:c,network:o,instance:a}),h=O(f)(n.Items);d.info("Received ".concat(h.length>0?h.length:0," valid announcements"));var p=h.map((function(t){return u({},t,{body:t.message})}));localStorage.setItem(l,JSON.stringify(p));var y=g(s,c,o,a),v=new URLSearchParams({game:s,lang:i,network:o,instance:a,hash:y}),w="".concat(t,"/").concat(s,"_announcement.html?").concat(v.toString());e.emit(m,w)}}},T=function(t){return{level:t.level}};function x(t,e,n){return I.apply(this,arguments)}function I(){return(I=i(t(r).mark((function e(n,o,a){var i;return t(r).wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=T(a),n=c(n,a,i),t.abrupt("return",fetch(n).then((function(t){return t.json()})).then((function(t){if(0!==Object.keys(t).length&&0!==t.Count)return o(t,a);d.info("".concat(n," shows empty response"))})).catch((function(t){return d.log("failed loading ".concat(n,": ").concat(t))})));case 3:case"end":return t.stop()}}),e)})))).apply(this,arguments)}var P=function(t,e){(!t||!Array.isArray(t)||t.length<4)&&d.error("Received invalid payload from game - ".concat(t," \n the valid payload is [userdata, lang, network, instance]"));var n,r=function(t){if(Array.isArray(t))return t}(n=t)||s(n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}(),o=r[0],a=r[1],i=r[2],c=r[3];return{userdata:e.getPlayerInfo(o),lang:a,network:i,instance:c}};e.exports=function(e,n){var o,c=b("https://community-announcement-template-staging.ggs-stp.com",e),u=a(e.game)||"",s=function(t){!function(t){x("https://bcybh10xrg.execute-api.eu-west-1.amazonaws.com/staging/messages/"+u,c,t)}(t)},l={},f=function(t){if(t||0!==Object.keys(l).length){if(t){var r=P(t,n);Object.assign(l,{lang:r.lang,network:r.network,instance:r.instance,game:e.game,playername:r.userdata.playername,level:r.userdata.level})}}else d.warn(" saveLoginData - the user data has not been set/initialized ".concat(l))},h=function(t){f(t),d.log("[getNewAnnouncements] - ".concat(JSON.stringify(l,null,4)));return x("https://bcybh10xrg.execute-api.eu-west-1.amazonaws.com/staging/messages/"+u,(function(t){var e=0;return L(t)&&(e=function(t,e){return O(S(t))(e).length}(l,t.Items),o=t),d.log(" Has announcements: ",e>0),e}),l)},g=function(a){return i(t(r).mark((function i(c){var u;return t(r).wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return d.log(" onGetMessageStatus - ".concat(a),c),t.next=3,h(c);case 3:u=t.sent,e.gameApi.invokeFn(v.UNREAD_ANNOUNCEMENTS,u),a===n.loginCmd&&u&&w(A,o),d.log(" call ".concat(v.UNREAD_ANNOUNCEMENTS," - ").concat(u));case 7:case"end":return t.stop()}}),i)})))};return{onLogin:function(t){return d.info(" onLogin",t),f(t),s(l)},onLogout:function(){e.once(n.loginCmd,g(n.loginCmd))},placeholder:function(){},onGetMessageStatus:g,onOpenAnnouncements:function(){0!==Object.keys(l).length?(s(l),d.info("onOpenAnnouncement handler for user ".concat(l)),w(E,o)):d.info(" onOpenAnnouncement handler - the user data has not been set/initialized ".concat(l))}}},e.exports.__internals={loadCurrentMessages:x,handleAnnouncementMessage:b,getHashKey:g,hashCode:h,getRootGamePayload:P,hasAnnouncements:L}})),o.register("5mFHf",(function(t,e){var n=function(t){var e,n=function(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]},r=function(t,e,n,r){var o=e&&e.prototype instanceof a?e:a,i=Object.create(o.prototype),c=new g(r||[]);return i._invoke=l(t,n,c),i},o=function(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}},a=function(){},i=function(){},c=function(){},u=function(t){["next","throw","return"].forEach((function(e){n(t,e,(function(t){return this._invoke(e,t)}))}))},s=function(t,e){function n(r,a,i,c){var u=o(t[r],t,a);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&y.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(l).then((function(t){s.value=t,i(s)}),(function(t){return n("throw",t,i,c)}))}c(u.arg)}var r;this._invoke=function(t,o){function a(){return new e((function(e,r){n(t,o,e,r)}))}return r=r?r.then(a,a):a()}},l=function(t,e,n){var r=A;return function(a,i){if(r===S)throw new Error("Generator is already running");if(r===O){if("throw"===a)throw i;return p()}for(n.method=a,n.arg=i;;){var c=n.delegate;if(c){var u=I(c,n);if(u){if(u===L)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===A)throw r=O,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=S;var s=o(t,e,n);if("normal"===s.type){if(r=n.done?O:N,s.arg===L)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(r=O,n.method="throw",n.arg=s.arg)}}},f=function(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)},h=function(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e},g=function(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(f,this),this.reset(!0)},d=function(t){if(t){var n=t[w];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function n(){for(;++r<t.length;)if(y.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=e,n.done=!0,n};return o.next=o}}return{next:p}},p=function(){return{value:e,done:!0}},m=Object.prototype,y=m.hasOwnProperty,v="function"==typeof Symbol?Symbol:{},w=v.iterator||"@@iterator",E=v.asyncIterator||"@@asyncIterator",_=v.toStringTag||"@@toStringTag";try{n({},"")}catch(t){n=function(t,e,n){return t[e]=n}}t.wrap=r;var A="suspendedStart",N="suspendedYield",S="executing",O="completed",L={},b={};b[w]=function(){return this};var C=Object.getPrototypeOf,T=C&&C(C(d([])));T&&T!==m&&y.call(T,w)&&(b=T);var x=c.prototype=a.prototype=Object.create(b);function I(t,n){var r=t.iterator[n.method];if(r===e){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=e,I(t,n),"throw"===n.method))return L;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return L}var a=o(r,t.iterator,n.arg);if("throw"===a.type)return n.method="throw",n.arg=a.arg,n.delegate=null,L;var i=a.arg;return i?i.done?(n[t.resultName]=i.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,L):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,L)}return i.prototype=x.constructor=c,c.constructor=i,i.displayName=n(c,_,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===i||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,c):(t.__proto__=c,n(t,_,"GeneratorFunction")),t.prototype=Object.create(x),t},t.awrap=function(t){return{__await:t}},u(s.prototype),s.prototype[E]=function(){return this},t.AsyncIterator=s,t.async=function(e,n,o,a,i){void 0===i&&(i=Promise);var c=new s(r(e,n,o,a),i);return t.isGeneratorFunction(n)?c:c.next().then((function(t){return t.done?t.value:c.next()}))},u(x),n(x,_,"Generator"),x[w]=function(){return this},x.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=d,g.prototype={constructor:g,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(h),!t)for(var n in this)"t"===n.charAt(0)&&y.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){var n=function(n,o){return i.type="throw",i.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o};if(this.done)throw t;for(var r=this,o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=y.call(a,"catchLoc"),u=y.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&y.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,L):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),L},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),h(n),L}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;h(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:d(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),L}},t}(t.exports);try{regeneratorRuntime=n}catch(t){Function("r","regeneratorRuntime = r")(n)}})),o.register("6RIYV",(function(t,n){ | ||
// modules are defined as an array | ||
// [ module function, map of requires ] | ||
// | ||
// map of requires is short require name -> numeric require | ||
// | ||
// anything defined in a previous bundle is accessed via the | ||
// orig method which is the require for previous bundles | ||
(function (modules, entry, mainEntry, parcelRequireName, globalName) { | ||
/* eslint-disable no-undef */ | ||
var globalObject = | ||
typeof globalThis !== 'undefined' | ||
? globalThis | ||
: typeof self !== 'undefined' | ||
? self | ||
: typeof window !== 'undefined' | ||
? window | ||
: typeof global !== 'undefined' | ||
? global | ||
: {}; | ||
/* eslint-enable no-undef */ | ||
// Save the require from previous bundle to this closure if any | ||
var previousRequire = | ||
typeof globalObject[parcelRequireName] === 'function' && | ||
globalObject[parcelRequireName]; | ||
var cache = previousRequire.cache || {}; | ||
// Do not use `require` to prevent Webpack from trying to bundle this call | ||
var nodeRequire = | ||
typeof module !== 'undefined' && | ||
typeof module.require === 'function' && | ||
module.require.bind(module); | ||
function newRequire(name, jumped) { | ||
if (!cache[name]) { | ||
if (!modules[name]) { | ||
// if we cannot find the module within our internal map or | ||
// cache jump to the current global require ie. the last bundle | ||
// that was added to the page. | ||
var currentRequire = | ||
typeof globalObject[parcelRequireName] === 'function' && | ||
globalObject[parcelRequireName]; | ||
if (!jumped && currentRequire) { | ||
return currentRequire(name, true); | ||
} | ||
// If there are other bundles on this page the require from the | ||
// previous one is saved to 'previousRequire'. Repeat this as | ||
// many times as there are bundles until the module is found or | ||
// we exhaust the require chain. | ||
if (previousRequire) { | ||
return previousRequire(name, true); | ||
} | ||
// Try the node require function if it exists. | ||
if (nodeRequire && typeof name === 'string') { | ||
return nodeRequire(name); | ||
} | ||
var err = new Error("Cannot find module '" + name + "'"); | ||
err.code = 'MODULE_NOT_FOUND'; | ||
throw err; | ||
} | ||
localRequire.resolve = resolve; | ||
localRequire.cache = {}; | ||
var module = (cache[name] = new newRequire.Module(name)); | ||
modules[name][0].call( | ||
module.exports, | ||
localRequire, | ||
module, | ||
module.exports, | ||
this | ||
); | ||
} | ||
return cache[name].exports; | ||
function localRequire(x) { | ||
var res = localRequire.resolve(x); | ||
return res === false ? {} : newRequire(res); | ||
} | ||
function resolve(x) { | ||
var id = modules[name][1][x]; | ||
return id != null ? id : x; | ||
} | ||
} | ||
function Module(moduleName) { | ||
this.id = moduleName; | ||
this.bundle = newRequire; | ||
this.exports = {}; | ||
} | ||
newRequire.isParcelRequire = true; | ||
newRequire.Module = Module; | ||
newRequire.modules = modules; | ||
newRequire.cache = cache; | ||
newRequire.parent = previousRequire; | ||
newRequire.register = function (id, exports) { | ||
modules[id] = [ | ||
function (require, module) { | ||
module.exports = exports; | ||
}, | ||
{}, | ||
]; | ||
}; | ||
Object.defineProperty(newRequire, 'root', { | ||
get: function () { | ||
return globalObject[parcelRequireName]; | ||
}, | ||
}); | ||
globalObject[parcelRequireName] = newRequire; | ||
for (var i = 0; i < entry.length; i++) { | ||
newRequire(entry[i]); | ||
} | ||
if (mainEntry) { | ||
// Expose entry point to Node, AMD or browser globals | ||
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js | ||
var mainExports = newRequire(mainEntry); | ||
// CommonJS | ||
if (typeof exports === 'object' && typeof module !== 'undefined') { | ||
module.exports = mainExports; | ||
// RequireJS | ||
} else if (typeof define === 'function' && define.amd) { | ||
define(function () { | ||
return mainExports; | ||
}); | ||
// <script> | ||
} else if (globalName) { | ||
this[globalName] = mainExports; | ||
} | ||
} | ||
})({"f0MWR":[function(require,module,exports) { | ||
"use strict"; | ||
var global = arguments[3]; | ||
var HMR_HOST = null; | ||
var HMR_PORT = null; | ||
var HMR_SECURE = false; | ||
var HMR_ENV_HASH = "d6ea1d42532a7575"; | ||
module.bundle.HMR_BUNDLE_ID = "f826857471f7fe43"; | ||
/* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, chrome, browser, globalThis, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope */ /*:: | ||
import type { | ||
HMRAsset, | ||
HMRMessage, | ||
} from '@parcel/reporter-dev-server/src/HMRServer.js'; | ||
interface ParcelRequire { | ||
(string): mixed; | ||
cache: {|[string]: ParcelModule|}; | ||
hotData: mixed; | ||
Module: any; | ||
parent: ?ParcelRequire; | ||
isParcelRequire: true; | ||
modules: {|[string]: [Function, {|[string]: string|}]|}; | ||
HMR_BUNDLE_ID: string; | ||
root: ParcelRequire; | ||
} | ||
interface ParcelModule { | ||
hot: {| | ||
data: mixed, | ||
accept(cb: (Function) => void): void, | ||
dispose(cb: (mixed) => void): void, | ||
// accept(deps: Array<string> | string, cb: (Function) => void): void, | ||
// decline(): void, | ||
_acceptCallbacks: Array<(Function) => void>, | ||
_disposeCallbacks: Array<(mixed) => void>, | ||
|}; | ||
} | ||
interface ExtensionContext { | ||
runtime: {| | ||
reload(): void, | ||
getURL(url: string): string; | ||
getManifest(): {manifest_version: number, ...}; | ||
|}; | ||
} | ||
declare var module: {bundle: ParcelRequire, ...}; | ||
declare var HMR_HOST: string; | ||
declare var HMR_PORT: string; | ||
declare var HMR_ENV_HASH: string; | ||
declare var HMR_SECURE: boolean; | ||
declare var chrome: ExtensionContext; | ||
declare var browser: ExtensionContext; | ||
declare var __parcel__import__: (string) => Promise<void>; | ||
declare var __parcel__importScripts__: (string) => Promise<void>; | ||
declare var globalThis: typeof self; | ||
declare var ServiceWorkerGlobalScope: Object; | ||
*/ var OVERLAY_ID = "__parcel__error__overlay__"; | ||
var OldModule = module.bundle.Module; | ||
function Module(moduleName) { | ||
OldModule.call(this, moduleName); | ||
this.hot = { | ||
data: module.bundle.hotData, | ||
_acceptCallbacks: [], | ||
_disposeCallbacks: [], | ||
accept: function(fn) { | ||
this._acceptCallbacks.push(fn || function() {}); | ||
}, | ||
dispose: function(fn) { | ||
this._disposeCallbacks.push(fn); | ||
} | ||
}; | ||
module.bundle.hotData = undefined; | ||
} | ||
module.bundle.Module = Module; | ||
var checkedAssets, acceptedAssets, assetsToAccept /*: Array<[ParcelRequire, string]> */ ; | ||
function getHostname() { | ||
return HMR_HOST || (location.protocol.indexOf("http") === 0 ? location.hostname : "localhost"); | ||
} | ||
function getPort() { | ||
return HMR_PORT || location.port; | ||
} // eslint-disable-next-line no-redeclare | ||
var parent = module.bundle.parent; | ||
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== "undefined") { | ||
var hostname = getHostname(); | ||
var port = getPort(); | ||
var protocol = HMR_SECURE || location.protocol == "https:" && !/localhost|127.0.0.1|0.0.0.0/.test(hostname) ? "wss" : "ws"; | ||
var ws = new WebSocket(protocol + "://" + hostname + (port ? ":" + port : "") + "/"); // Web extension context | ||
var extCtx = typeof chrome === "undefined" ? typeof browser === "undefined" ? null : browser : chrome; // Safari doesn't support sourceURL in error stacks. | ||
// eval may also be disabled via CSP, so do a quick check. | ||
var supportsSourceURL = false; | ||
try { | ||
(0, eval)('throw new Error("test"); //# sourceURL=test.js'); | ||
} catch (err) { | ||
supportsSourceURL = err.stack.includes("test.js"); | ||
} // $FlowFixMe | ||
ws.onmessage = async function(event) { | ||
checkedAssets = {} /*: {|[string]: boolean|} */ ; | ||
acceptedAssets = {} /*: {|[string]: boolean|} */ ; | ||
assetsToAccept = []; | ||
var data = JSON.parse(event.data); | ||
if (data.type === "update") { | ||
// Remove error overlay if there is one | ||
if (typeof document !== "undefined") removeErrorOverlay(); | ||
let assets = data.assets.filter((asset)=>asset.envHash === HMR_ENV_HASH); // Handle HMR Update | ||
let handled = assets.every((asset)=>{ | ||
return asset.type === "css" || asset.type === "js" && hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle); | ||
}); | ||
if (handled) { | ||
console.clear(); // Dispatch custom event so other runtimes (e.g React Refresh) are aware. | ||
if (typeof window !== "undefined" && typeof CustomEvent !== "undefined") window.dispatchEvent(new CustomEvent("parcelhmraccept")); | ||
await hmrApplyUpdates(assets); | ||
for(var i = 0; i < assetsToAccept.length; i++){ | ||
var id = assetsToAccept[i][1]; | ||
if (!acceptedAssets[id]) hmrAcceptRun(assetsToAccept[i][0], id); | ||
} | ||
} else fullReload(); | ||
} | ||
if (data.type === "error") { | ||
// Log parcel errors to console | ||
for (let ansiDiagnostic of data.diagnostics.ansi){ | ||
let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack; | ||
console.error("\uD83D\uDEA8 [parcel]: " + ansiDiagnostic.message + "\n" + stack + "\n\n" + ansiDiagnostic.hints.join("\n")); | ||
} | ||
if (typeof document !== "undefined") { | ||
// Render the fancy html overlay | ||
removeErrorOverlay(); | ||
var overlay = createErrorOverlay(data.diagnostics.html); // $FlowFixMe | ||
document.body.appendChild(overlay); | ||
} | ||
} | ||
}; | ||
ws.onerror = function(e) { | ||
console.error(e.message); | ||
}; | ||
ws.onclose = function() { | ||
console.warn("[parcel] \uD83D\uDEA8 Connection to the HMR server was lost"); | ||
}; | ||
} | ||
function removeErrorOverlay() { | ||
var overlay = document.getElementById(OVERLAY_ID); | ||
if (overlay) { | ||
overlay.remove(); | ||
console.log("[parcel] ✨ Error resolved"); | ||
} | ||
} | ||
function createErrorOverlay(diagnostics) { | ||
var overlay = document.createElement("div"); | ||
overlay.id = OVERLAY_ID; | ||
let errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">'; | ||
for (let diagnostic of diagnostics){ | ||
let stack = diagnostic.frames.length ? diagnostic.frames.reduce((p, frame)=>{ | ||
return `${p} | ||
<a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a> | ||
${frame.code}`; | ||
}, "") : diagnostic.stack; | ||
errorHTML += ` | ||
<div> | ||
<div style="font-size: 18px; font-weight: bold; margin-top: 20px;"> | ||
🚨 ${diagnostic.message} | ||
</div> | ||
<pre>${stack}</pre> | ||
<div> | ||
${diagnostic.hints.map((hint)=>"<div>\uD83D\uDCA1 " + hint + "</div>").join("")} | ||
</div> | ||
${diagnostic.documentation ? `<div>📝 <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>` : ""} | ||
</div> | ||
`; | ||
} | ||
errorHTML += "</div>"; | ||
overlay.innerHTML = errorHTML; | ||
return overlay; | ||
} | ||
function fullReload() { | ||
if ("reload" in location) location.reload(); | ||
else if (extCtx && extCtx.runtime && extCtx.runtime.reload) extCtx.runtime.reload(); | ||
} | ||
function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ { | ||
var modules = bundle.modules; | ||
if (!modules) return []; | ||
var parents = []; | ||
var k, d, dep; | ||
for(k in modules)for(d in modules[k][1]){ | ||
dep = modules[k][1][d]; | ||
if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) parents.push([ | ||
bundle, | ||
k | ||
]); | ||
} | ||
if (bundle.parent) parents = parents.concat(getParents(bundle.parent, id)); | ||
return parents; | ||
} | ||
function updateLink(link) { | ||
var newLink = link.cloneNode(); | ||
newLink.onload = function() { | ||
if (link.parentNode !== null) // $FlowFixMe | ||
link.parentNode.removeChild(link); | ||
}; | ||
newLink.setAttribute("href", link.getAttribute("href").split("?")[0] + "?" + Date.now()); // $FlowFixMe | ||
link.parentNode.insertBefore(newLink, link.nextSibling); | ||
} | ||
var cssTimeout = null; | ||
function reloadCSS() { | ||
if (cssTimeout) return; | ||
cssTimeout = setTimeout(function() { | ||
var links = document.querySelectorAll('link[rel="stylesheet"]'); | ||
for(var i = 0; i < links.length; i++){ | ||
// $FlowFixMe[incompatible-type] | ||
var href = links[i].getAttribute("href"); | ||
var hostname = getHostname(); | ||
var servedFromHMRServer = hostname === "localhost" ? new RegExp("^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):" + getPort()).test(href) : href.indexOf(hostname + ":" + getPort()); | ||
var absolute = /^https?:\/\//i.test(href) && href.indexOf(location.origin) !== 0 && !servedFromHMRServer; | ||
if (!absolute) updateLink(links[i]); | ||
} | ||
cssTimeout = null; | ||
}, 50); | ||
} | ||
function hmrDownload(asset) { | ||
if (asset.type === "js") { | ||
if (typeof document !== "undefined") { | ||
let script = document.createElement("script"); | ||
script.src = asset.url + "?t=" + Date.now(); | ||
if (asset.outputFormat === "esmodule") script.type = "module"; | ||
return new Promise((resolve, reject)=>{ | ||
var _document$head; | ||
script.onload = ()=>resolve(script); | ||
script.onerror = reject; | ||
(_document$head = document.head) === null || _document$head === void 0 || _document$head.appendChild(script); | ||
}); | ||
} else if (typeof importScripts === "function") { | ||
// Worker scripts | ||
if (asset.outputFormat === "esmodule") return import(asset.url + "?t=" + Date.now()); | ||
else return new Promise((resolve, reject)=>{ | ||
try { | ||
importScripts(asset.url + "?t=" + Date.now()); | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
async function hmrApplyUpdates(assets) { | ||
global.parcelHotUpdate = Object.create(null); | ||
let scriptsToRemove; | ||
try { | ||
// If sourceURL comments aren't supported in eval, we need to load | ||
// the update from the dev server over HTTP so that stack traces | ||
// are correct in errors/logs. This is much slower than eval, so | ||
// we only do it if needed (currently just Safari). | ||
// https://bugs.webkit.org/show_bug.cgi?id=137297 | ||
// This path is also taken if a CSP disallows eval. | ||
if (!supportsSourceURL) { | ||
let promises = assets.map((asset)=>{ | ||
var _hmrDownload; | ||
return (_hmrDownload = hmrDownload(asset)) === null || _hmrDownload === void 0 ? void 0 : _hmrDownload.catch((err)=>{ | ||
// Web extension bugfix for Chromium | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=1255412#c12 | ||
if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3) { | ||
if (typeof ServiceWorkerGlobalScope != "undefined" && global instanceof ServiceWorkerGlobalScope) { | ||
extCtx.runtime.reload(); | ||
return; | ||
} | ||
asset.url = extCtx.runtime.getURL("/__parcel_hmr_proxy__?url=" + encodeURIComponent(asset.url + "?t=" + Date.now())); | ||
return hmrDownload(asset); | ||
} | ||
throw err; | ||
}); | ||
}); | ||
scriptsToRemove = await Promise.all(promises); | ||
} | ||
assets.forEach(function(asset) { | ||
hmrApply(module.bundle.root, asset); | ||
}); | ||
} finally{ | ||
delete global.parcelHotUpdate; | ||
if (scriptsToRemove) scriptsToRemove.forEach((script)=>{ | ||
if (script) { | ||
var _document$head2; | ||
(_document$head2 = document.head) === null || _document$head2 === void 0 || _document$head2.removeChild(script); | ||
} | ||
}); | ||
} | ||
} | ||
function hmrApply(bundle, asset) { | ||
var modules = bundle.modules; | ||
if (!modules) return; | ||
if (asset.type === "css") reloadCSS(); | ||
else if (asset.type === "js") { | ||
let deps = asset.depsByBundle[bundle.HMR_BUNDLE_ID]; | ||
if (deps) { | ||
if (modules[asset.id]) { | ||
// Remove dependencies that are removed and will become orphaned. | ||
// This is necessary so that if the asset is added back again, the cache is gone, and we prevent a full page reload. | ||
let oldDeps = modules[asset.id][1]; | ||
for(let dep in oldDeps)if (!deps[dep] || deps[dep] !== oldDeps[dep]) { | ||
let id = oldDeps[dep]; | ||
let parents = getParents(module.bundle.root, id); | ||
if (parents.length === 1) hmrDelete(module.bundle.root, id); | ||
} | ||
} | ||
if (supportsSourceURL) // Global eval. We would use `new Function` here but browser | ||
// support for source maps is better with eval. | ||
(0, eval)(asset.output); | ||
// $FlowFixMe | ||
let fn = global.parcelHotUpdate[asset.id]; | ||
modules[asset.id] = [ | ||
fn, | ||
deps | ||
]; | ||
} else if (bundle.parent) hmrApply(bundle.parent, asset); | ||
} | ||
} | ||
function hmrDelete(bundle, id) { | ||
let modules = bundle.modules; | ||
if (!modules) return; | ||
if (modules[id]) { | ||
// Collect dependencies that will become orphaned when this module is deleted. | ||
let deps = modules[id][1]; | ||
let orphans = []; | ||
for(let dep in deps){ | ||
let parents = getParents(module.bundle.root, deps[dep]); | ||
if (parents.length === 1) orphans.push(deps[dep]); | ||
} // Delete the module. This must be done before deleting dependencies in case of circular dependencies. | ||
delete modules[id]; | ||
delete bundle.cache[id]; // Now delete the orphans. | ||
orphans.forEach((id)=>{ | ||
hmrDelete(module.bundle.root, id); | ||
}); | ||
} else if (bundle.parent) hmrDelete(bundle.parent, id); | ||
} | ||
function hmrAcceptCheck(bundle, id, depsByBundle) { | ||
if (hmrAcceptCheckOne(bundle, id, depsByBundle)) return true; | ||
// Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload. | ||
let parents = getParents(module.bundle.root, id); | ||
let accepted = false; | ||
while(parents.length > 0){ | ||
let v = parents.shift(); | ||
let a = hmrAcceptCheckOne(v[0], v[1], null); | ||
if (a) // If this parent accepts, stop traversing upward, but still consider siblings. | ||
accepted = true; | ||
else { | ||
// Otherwise, queue the parents in the next level upward. | ||
let p = getParents(module.bundle.root, v[1]); | ||
if (p.length === 0) { | ||
// If there are no parents, then we've reached an entry without accepting. Reload. | ||
accepted = false; | ||
break; | ||
} | ||
parents.push(...p); | ||
} | ||
} | ||
return accepted; | ||
} | ||
function hmrAcceptCheckOne(bundle, id, depsByBundle) { | ||
var modules = bundle.modules; | ||
if (!modules) return; | ||
if (depsByBundle && !depsByBundle[bundle.HMR_BUNDLE_ID]) { | ||
// If we reached the root bundle without finding where the asset should go, | ||
// there's nothing to do. Mark as "accepted" so we don't reload the page. | ||
if (!bundle.parent) return true; | ||
return hmrAcceptCheck(bundle.parent, id, depsByBundle); | ||
} | ||
if (checkedAssets[id]) return true; | ||
checkedAssets[id] = true; | ||
var cached = bundle.cache[id]; | ||
assetsToAccept.push([ | ||
bundle, | ||
id | ||
]); | ||
if (!cached || cached.hot && cached.hot._acceptCallbacks.length) return true; | ||
} | ||
function hmrAcceptRun(bundle, id) { | ||
var cached = bundle.cache[id]; | ||
bundle.hotData = {}; | ||
if (cached && cached.hot) cached.hot.data = bundle.hotData; | ||
if (cached && cached.hot && cached.hot._disposeCallbacks.length) cached.hot._disposeCallbacks.forEach(function(cb) { | ||
cb(bundle.hotData); | ||
}); | ||
delete bundle.cache[id]; | ||
bundle(id); | ||
cached = bundle.cache[id]; | ||
if (cached && cached.hot && cached.hot._acceptCallbacks.length) cached.hot._acceptCallbacks.forEach(function(cb) { | ||
var assetsToAlsoAccept = cb(function() { | ||
return getParents(module.bundle.root, id); | ||
}); | ||
if (assetsToAlsoAccept && assetsToAccept.length) // $FlowFixMe[method-unbinding] | ||
assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept); | ||
}); | ||
acceptedAssets[id] = true; | ||
} | ||
},{}],"2rNzt":[function(require,module,exports) { | ||
const { addWindowListeners } = require("./window-handlers"); | ||
const { logger } = require("./utils"); | ||
const { GAME } = require("./constants"); | ||
const ADAPTERS = { | ||
[GAME.EMPIRE]: require("./game-adapters/empire"), | ||
[GAME.BIG_FARM]: require("./game-adapters/bigfarm"), | ||
[GAME.E4K]: require("./game-adapters/empirefourkingdoms") | ||
}; | ||
const { OPEN , GET } = require("./constants"); | ||
const { init: initTracking } = require("./tracking"); | ||
function init(context) { | ||
logger.log(" initialized successfully - waiting for player login", context.game); | ||
initTracking(context); | ||
const adapter = ADAPTERS[context.game]; | ||
const logic = require("./announcement-events")(context, adapter); | ||
addWindowListeners(context); | ||
if (adapter.logoutCmd) context.on(adapter.logoutCmd, logic.onLogout); | ||
// TODO STP-367 BF protobufController emits events with message_name but CXFClient registers events with msgId therefore we need to subscribe with both ( when Stp-367 is merged we can just use String) | ||
context.once(3, ()=>{}); | ||
context.once(24, ()=>{}); | ||
context.once(adapter.loginCmd, logic.onLogin); | ||
context.on(GET, logic.onGetMessageStatus(GET)); | ||
context.on(OPEN, logic.onOpenAnnouncements); | ||
} | ||
init(window.CXF); | ||
module.exports.__internals = { | ||
ADAPTERS | ||
}; | ||
},{"./window-handlers":"kLkRK","./utils":"en4he","./constants":"3huJa","./game-adapters/empire":"eKfN2","./game-adapters/bigfarm":"iU3KV","./game-adapters/empirefourkingdoms":"KVWeT","./tracking":"8Ey6b","./announcement-events":"6HmS4"}],"kLkRK":[function(require,module,exports) { | ||
const { subtractArray } = require("./utils"); | ||
const { sharedCommands , ANNOUNCEMENTS_LOCALSTORAGE_KEY } = require("./utils"); | ||
const { CXF_DIALOG_CLOSE } = require("./cxf-event-constants"); | ||
const { GET , GAME_CALLBACK } = require("./constants"); | ||
const { tracking , CLOSE_CROSS , CLOSE_REGULAR , DONT_SHOW_AGAIN_ACTIVATE , DONT_SHOW_AGAIN_DEACTIVATE , SCROLL , LOADED } = require("./tracking"); | ||
let allActiveAnnouncements; | ||
function markAsRead({ hash , wasRead }) { | ||
const doNotShowMessages = getDoNotShowMessages(hash.key); | ||
const eventName = wasRead ? DONT_SHOW_AGAIN_ACTIVATE : DONT_SHOW_AGAIN_DEACTIVATE; | ||
for (const announcement of allActiveAnnouncements)tracking(eventName, announcement); | ||
const hiddenMessages = wasRead ? doNotShowMessages.concat(hash.hashList) : subtractArray(doNotShowMessages, hash.hashList); | ||
if (hiddenMessages.length === 0) localStorage.removeItem(hash.key); | ||
else localStorage.setItem(hash.key, JSON.stringify(hiddenMessages)); | ||
} | ||
function closeFrame(context) { | ||
localStorage.removeItem(ANNOUNCEMENTS_LOCALSTORAGE_KEY); | ||
allActiveAnnouncements = undefined; | ||
context.emit(CXF_DIALOG_CLOSE); | ||
} | ||
function getDoNotShowMessages(key) { | ||
const doNotShowMessages = localStorage.getItem(key) || "[]"; | ||
return JSON.parse(doNotShowMessages); | ||
} | ||
function getMessages() { | ||
const messagesJSON = localStorage.getItem(ANNOUNCEMENTS_LOCALSTORAGE_KEY) || "[]"; | ||
return JSON.parse(messagesJSON); | ||
} | ||
const sortByStartDate = (a, b)=>b.start_date - a.start_date; | ||
function showAllMessages({ frameId }) { | ||
const messages = getMessages().sort(sortByStartDate); | ||
if (messages && messages.length > 0) { | ||
// eslint-disable-next-line unicorn/prefer-query-selector | ||
const iframe = document.getElementById(frameId).contentWindow; | ||
allActiveAnnouncements = messages; | ||
const triggeredTimestamp = Date.now(); | ||
iframe.postMessage({ | ||
messages, | ||
triggeredTimestamp | ||
}, "*"); | ||
localStorage.setItem(ANNOUNCEMENTS_LOCALSTORAGE_KEY, JSON.stringify([])); | ||
} | ||
} | ||
const MAP_BTN_NAME_TO_TRACKING_EVENT = new Map([ | ||
[ | ||
`okBtn`, | ||
CLOSE_REGULAR | ||
], | ||
[ | ||
`crossBtn`, | ||
CLOSE_CROSS | ||
], | ||
[ | ||
`scrolled`, | ||
SCROLL | ||
], | ||
[ | ||
`loaded`, | ||
LOADED | ||
] | ||
]); | ||
function addWindowListeners(context) { | ||
window.addEventListener("message", (evt)=>{ | ||
if (evt.data && evt.data.name) switch(evt.data.name){ | ||
case sharedCommands.MARK_AS_READ: | ||
markAsRead(evt.data); | ||
context.emit(GET); | ||
break; | ||
case sharedCommands.CLOSE_POPUP: | ||
closeFrame(context); | ||
break; | ||
case sharedCommands.SHOW_ANNOUNCEMENTS: | ||
showAllMessages(evt.data); | ||
break; | ||
case sharedCommands.TRACKING: | ||
// tracking of this actions (loaded,crossBtn,okBtn,scrolled) | ||
for (const announcement of allActiveAnnouncements)if (evt.data.action === "scrolled") { | ||
const scrolledAnnouncements = evt.data.params.scrolledAnnouncements; | ||
if (scrolledAnnouncements.includes(announcement.id)) tracking(MAP_BTN_NAME_TO_TRACKING_EVENT.get(evt.data.action), announcement, evt.data.params); | ||
} else tracking(MAP_BTN_NAME_TO_TRACKING_EVENT.get(evt.data.action), announcement, evt.data.params); | ||
break; | ||
case sharedCommands.LINK_CLICKED: | ||
context.gameApi.invokeFn(GAME_CALLBACK.PAGE_LOAD_STARTING, evt.data.href); | ||
break; | ||
default: | ||
} | ||
}, false); | ||
} | ||
module.exports = { | ||
addWindowListeners, | ||
getDoNotShowMessages | ||
}; | ||
module.exports.__internals = { | ||
markAsRead, | ||
getDoNotShowMessages, | ||
getMessages, | ||
closeFrame, | ||
showAllMessages, | ||
setAllActiveAnnouncements: (values)=>{ | ||
allActiveAnnouncements = values; | ||
} | ||
}; | ||
},{"./utils":"en4he","./cxf-event-constants":"3B2HD","./constants":"3huJa","./tracking":"8Ey6b"}],"en4he":[function(require,module,exports) { | ||
/* eslint-disable no-extend-native, no-eq-null, eqeqeq, no-new-object */ // https://tc39.github.io/ecma262/#sec-array.prototype.find | ||
if (!Array.prototype.find) Object.defineProperty(Array.prototype, "find", { | ||
value (predicate) { | ||
// 1. Let O be ? ToObject(this value). | ||
if (this == null) throw new TypeError('"this" is null or not defined'); | ||
const o = new Object(this); | ||
// 2. Let len be ? ToLength(? Get(O, "length")). | ||
const length_ = o.length >>> 0; | ||
// 3. If IsCallable(predicate) is false, throw a TypeError exception. | ||
if (typeof predicate !== "function") throw new TypeError("predicate must be a function"); | ||
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined. | ||
const thisArg = arguments[1]; | ||
// 5. Let k be 0. | ||
let k = 0; | ||
// 6. Repeat, while k < len | ||
while(k < length_){ | ||
// A. Let Pk be ! ToString(k). | ||
// b. Let kValue be ? Get(O, Pk). | ||
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). | ||
// d. If testResult is true, return kValue. | ||
const kValue = o[k]; | ||
if (predicate.call(thisArg, kValue, k, o)) return kValue; | ||
// E. Increase k by 1. | ||
k++; | ||
} | ||
// 7. Return undefined. | ||
return undefined; | ||
}, | ||
configurable: true, | ||
writable: true | ||
}); | ||
/* eslint-enable */ const containsInstance = (networks, network, instance)=>{ | ||
let found = networks.find((n)=>n.id === network); | ||
if (!found) return false; | ||
found = found.instances.find((i)=>i === instance); | ||
return Boolean(found); | ||
}; | ||
const appendLoginParameters = (path, pathParameters, queryParameters = {})=>{ | ||
const { network , instance , lang } = pathParameters; | ||
const endpoint = `${path}/${network}/${instance}/${lang}`; | ||
const finalEndpoint = appendQueryParameters(endpoint, queryParameters); | ||
return finalEndpoint; | ||
}; | ||
const appendQueryParameters = (endpoint, queryObject)=>{ | ||
endpoint = new URL(endpoint); | ||
for (const key of Object.keys(queryObject))endpoint.searchParams.append(key, queryObject[key]); | ||
return endpoint.toString(); | ||
}; | ||
const sharedCommands = { | ||
CLOSE_POPUP: "cxf.announcements.closePopup", | ||
MARK_AS_READ: "cxf.announcements.markAsRead", | ||
SHOW_ANNOUNCEMENTS: "cxf.announcements.getAllAnnouncements", | ||
TRACKING: "cxf.announcements.tracking", | ||
LINK_CLICKED: "cxf.announcements.hrefClicked" | ||
}; | ||
const ANNOUNCEMENTS_LOCALSTORAGE_KEY = "ggs.cxf.announcements.fetchedAnnouncements"; | ||
const getHashKey = (game, playername, network, instance)=>{ | ||
const k = [ | ||
game, | ||
playername, | ||
network, | ||
instance | ||
].join("_"); | ||
return `ggs.cxf.announcements.${k}.messageHash`; | ||
}; | ||
// Generate random hash from title+body | ||
// https://stackoverflow.com/a/34842797 | ||
const hashCode = (string)=>{ | ||
let h = 0; | ||
for(let i = 0; i < string.length; i++)// eslint-disable-next-line unicorn/prefer-math-trunc | ||
h = Math.imul(31, h) + string.charCodeAt(i) | 0; | ||
return h; | ||
}; | ||
const PLUGIN_PREFIX = `CXF-ANNOUNCEMENT`; | ||
const logger = { | ||
info: (...args)=>{ | ||
console.info(`%c ${PLUGIN_PREFIX} ->`, "background: green; color: yellow", ...args); | ||
}, | ||
log: (...args)=>{ | ||
console.info(`%c ${PLUGIN_PREFIX} ->`, "background: green; color: yellow", ...args); | ||
}, | ||
warn: (...args)=>{ | ||
console.warn(`%c ${PLUGIN_PREFIX} ->`, "background: orange; color: yellow", ...args); | ||
}, | ||
error: (...args)=>{ | ||
console.error(`%c ${PLUGIN_PREFIX} ->`, "background: red; color: yellow", ...args); | ||
} | ||
}; | ||
const subtractArray = (array1, array2)=>array1.filter((item)=>!array2.includes(item)); | ||
module.exports = { | ||
containsInstance, | ||
sharedCommands, | ||
appendLoginParameters, | ||
appendQueryParameters, | ||
ANNOUNCEMENTS_LOCALSTORAGE_KEY, | ||
hashCode, | ||
getHashKey, | ||
logger, | ||
subtractArray | ||
}; | ||
},{}],"3B2HD":[function(require,module,exports) { | ||
module.exports = { | ||
CXF_DIALOG_OPEN: "cxf.dialog.open", | ||
CXF_DIALOG_CLOSE: "cxf.dialog.close" | ||
}; | ||
},{}],"3huJa":[function(require,module,exports) { | ||
const GAME_CALLBACK = { | ||
UNREAD_ANNOUNCEMENTS: `setCapToolNotifications`, | ||
PAGE_LOAD_STARTING: `pageLoadStarting` | ||
}; | ||
const GAME = { | ||
BIG_FARM: "bigfarm", | ||
EMPIRE: "empire", | ||
E4K: "empirefourkingdoms" | ||
}; | ||
const GAME_BUTTON_CLICKED_PREFIX = "game.button.clicked."; | ||
const GAME_ANNOUNCEMENTS_EVENT = { | ||
GET_ANNOUNCEMENTS: `${GAME_BUTTON_CLICKED_PREFIX}getAnnouncements`, | ||
OPEN_ANNOUNCEMENTS: `${GAME_BUTTON_CLICKED_PREFIX}openAnnouncements` | ||
}; | ||
module.exports = { | ||
GAME_CALLBACK, | ||
GAME, | ||
GAME_BUTTON_CLICKED_PREFIX, | ||
GAME_ANNOUNCEMENTS_EVENT, | ||
OPEN: GAME_ANNOUNCEMENTS_EVENT.OPEN_ANNOUNCEMENTS, | ||
GET: GAME_ANNOUNCEMENTS_EVENT.GET_ANNOUNCEMENTS | ||
}; | ||
},{}],"8Ey6b":[function(require,module,exports) { | ||
const { logger } = require("./utils"); | ||
let context; | ||
const TED = 1236 // Tracking-Event Definitions | ||
; | ||
const CXF_TRACK_MSG = "cxf.tracking.message"; | ||
const ANNOUNCEMENT_READY = `announcement_ready`; | ||
const OPEN_ANNOUNCEMENTS = `click`; | ||
const DONT_SHOW_AGAIN_ACTIVATE = `dont_show_again_activate`; | ||
const DONT_SHOW_AGAIN_DEACTIVATE = `dont_show_again_deactivate`; | ||
const CLOSE_CROSS = `close_cross`; | ||
const CLOSE_REGULAR = `close_regular`; | ||
const SCROLL = `scroll`; | ||
const LOADED = `loaded`; | ||
const init = (contextInst)=>{ | ||
logger.log("tracking has been initialized", contextInst); | ||
context = contextInst; | ||
}; | ||
const getAnnouncement = (announcements)=>{ | ||
let result; | ||
if (announcements) result = Array.isArray(announcements.Items) ? announcements.Items[0] : announcements; | ||
return result; | ||
}; | ||
const tracking = (actionType, announcements, parameters)=>{ | ||
const announcementData = getAnnouncement(announcements); | ||
let payload = { | ||
eventId: TED, | ||
gameId: Number.parseInt(context.gameId, 10), | ||
networkId: Number.parseInt(context.networkId, 10), | ||
instanceId: context.instanceId, | ||
playerId: context.playerId, | ||
language: context.countryCode, | ||
date: new Date().toUTCString(), | ||
zoneId: context.zoneId, | ||
actionType | ||
}; | ||
const { id , start_date: startDate , end_date: endDate , title: name } = announcementData; | ||
payload = { | ||
...payload, | ||
...parameters | ||
}; | ||
payload.id = id; | ||
payload.scheduleStart = new Date(startDate).toUTCString(); | ||
payload.scheduleEnd = new Date(endDate).toUTCString(); | ||
payload.name = name; | ||
logger.log(CXF_TRACK_MSG, JSON.stringify(payload, null, 4)); | ||
context.emit(CXF_TRACK_MSG, payload); | ||
}; | ||
module.exports = { | ||
init, | ||
tracking, | ||
OPEN_ANNOUNCEMENTS, | ||
ANNOUNCEMENT_READY, | ||
CLOSE_CROSS, | ||
CLOSE_REGULAR, | ||
DONT_SHOW_AGAIN_ACTIVATE, | ||
DONT_SHOW_AGAIN_DEACTIVATE, | ||
SCROLL, | ||
LOADED | ||
}; | ||
},{"./utils":"en4he"}],"eKfN2":[function(require,module,exports) { | ||
module.exports = { | ||
getPlayerInfo: (json)=>{ | ||
const p = JSON.parse(json[1]); | ||
return { | ||
playername: p.gpi.PN, | ||
level: p.gxp.LVL | ||
}; | ||
}, | ||
getLevel: (resp)=>JSON.parse(resp[1]).LVL, | ||
lastTutorialLevel: 5, | ||
loginCmd: "gbd", | ||
levelUpCmd: "gxp" | ||
}; | ||
},{}],"iU3KV":[function(require,module,exports) { | ||
module.exports = { | ||
getPlayerInfo: (p)=>({ | ||
playername: p.playerIdentity.name, | ||
level: p.xp.level | ||
}), | ||
getLevel: ({ newLevel })=>newLevel, | ||
lastTutorialLevel: 1, | ||
loginCmd: "LOGIN_BASIC_DATA", | ||
levelUpCmd: "LEVEL_UP" | ||
}; | ||
},{}],"KVWeT":[function(require,module,exports) { | ||
module.exports = { | ||
getPlayerInfo: (json)=>{ | ||
const p = JSON.parse(json[1]); | ||
return { | ||
playername: p.gpi.PN, | ||
level: p.gxp.LVL | ||
}; | ||
}, | ||
getLevel: (resp)=>JSON.parse(resp[1]).LVL, | ||
lastTutorialLevel: 5, | ||
loginCmd: "gbd", | ||
levelUpCmd: "gxp", | ||
logoutCmd: "LOGOUT" | ||
}; | ||
},{}],"6HmS4":[function(require,module,exports) { | ||
const { logger } = require("./utils"); | ||
const { GAME_CALLBACK } = require(`./constants`); | ||
const { tracking , OPEN_ANNOUNCEMENTS , ANNOUNCEMENT_READY } = require("./tracking"); | ||
const { getNewAnnouncements , getAnnouncementsCache , setLoginData , getLoginData , loadMessages , loadLoginMessages } = require("./announcement-utils"); | ||
module.exports = (context, adapter)=>{ | ||
const onLogin = (data)=>{ | ||
logger.info("Login event triggered", data); | ||
setLoginData(context, adapter)(data); | ||
const loginData = getLoginData(); | ||
onGetMessageStatus(adapter.loginCmd)(loginData); | ||
return loadLoginMessages(context)(loginData); | ||
}; | ||
const onLogout = ()=>{ | ||
context.once(adapter.loginCmd, onGetMessageStatus(adapter.loginCmd)); | ||
}; | ||
const onGetMessageStatus = (eventName)=>async (data)=>{ | ||
setLoginData(context, adapter)(data); | ||
const loginData = getLoginData(); | ||
logger.log(` onGetMessageStatus - ${eventName}`, loginData); | ||
const countOfActiveAnnouncements = await getNewAnnouncements(loginData); | ||
context.gameApi.invokeFn(GAME_CALLBACK.UNREAD_ANNOUNCEMENTS, countOfActiveAnnouncements); | ||
// tracking - announcements are ready | ||
if (eventName === adapter.loginCmd && countOfActiveAnnouncements) tracking(ANNOUNCEMENT_READY, getAnnouncementsCache()); | ||
logger.log(` call ${GAME_CALLBACK.UNREAD_ANNOUNCEMENTS} - ${countOfActiveAnnouncements}`); | ||
}; | ||
const onOpenAnnouncements = ()=>{ | ||
const loginData = getLoginData(); | ||
if (!loginData) return; | ||
loadMessages(context)(loginData); | ||
logger.info("onOpenAnnouncement handler for user %O", loginData); | ||
tracking(OPEN_ANNOUNCEMENTS, getAnnouncementsCache()); | ||
}; | ||
return { | ||
onLogin, | ||
onLogout, | ||
onGetMessageStatus, | ||
onOpenAnnouncements | ||
}; | ||
}; | ||
},{"./utils":"en4he","./constants":"3huJa","./tracking":"8Ey6b","./announcement-utils":"dplRs"}],"dplRs":[function(require,module,exports) { | ||
require("url-search-params-polyfill") // eslint-disable-line import/no-unassigned-import | ||
; | ||
const { acronym } = require("@goodgamestudios/game-alias"); | ||
const { getDoNotShowMessages } = require("./window-handlers"); | ||
const { CXF_DIALOG_OPEN } = require("./cxf-event-constants"); | ||
const { appendLoginParameters , ANNOUNCEMENTS_LOCALSTORAGE_KEY , hashCode , getHashKey , logger } = require("./utils"); | ||
const alreadyShown = (loginData)=>{ | ||
const { game , playername , network , instance } = loginData; | ||
const hash = getHashKey(game, playername, network, instance); | ||
return getDoNotShowMessages(hash); | ||
}; | ||
const filterUnreadForceOpen = (alreadyShown, forceOpenMessages = false)=>(msgs)=>{ | ||
return msgs.filter((message)=>!alreadyShown.includes(hashCode(message.title + message.message))).filter((message)=>Boolean(message.force_open) === forceOpenMessages); | ||
}; | ||
const hasAnnouncements = (dtoJSON)=>{ | ||
return dtoJSON && dtoJSON.Count > 0 || false; | ||
}; | ||
const handleAnnouncementMessage = (basepath, context, forceOpenMessages = false)=>(json, { network , instance , lang , playername })=>{ | ||
const { game } = context; | ||
if (!hasAnnouncements(json)) return; | ||
const alreadyShownAnnouncements = alreadyShown({ | ||
game, | ||
playername, | ||
network, | ||
instance | ||
}); | ||
const announcements = filterUnreadForceOpen(alreadyShownAnnouncements, forceOpenMessages)(json.Items); | ||
logger.info(`Received ${announcements.length > 0 ? announcements.length : 0} valid announcements`); | ||
const formattedAnnouncements = announcements.map((a)=>({ | ||
...a, | ||
body: a.message | ||
})); | ||
localStorage.setItem(ANNOUNCEMENTS_LOCALSTORAGE_KEY, JSON.stringify(formattedAnnouncements)); | ||
const hash = getHashKey(game, playername, network, instance); | ||
const parameters = { | ||
game, | ||
lang, | ||
network, | ||
instance, | ||
hash | ||
}; | ||
const URLparams = new URLSearchParams(parameters); | ||
const templateUrl = `${basepath}/${game}_announcement.html?${URLparams.toString()}`; | ||
// logger.info(`templateUrl - ${templateUrl}`) | ||
context.emit(CXF_DIALOG_OPEN, templateUrl); | ||
}; | ||
// Conditions that we can filter the display of announcements based on the player data | ||
const getAnnouncementFilters = (loginData)=>{ | ||
return { | ||
level: loginData.level | ||
}; | ||
}; | ||
const loadCurrentMessages = async (path, handler, loginData)=>{ | ||
const filters = getAnnouncementFilters(loginData); | ||
path = appendLoginParameters(path, loginData, filters); | ||
return fetch(path).then((r)=>r.json()).then((data)=>{ | ||
if (Object.keys(data).length === 0 || data.Count === 0) { | ||
logger.info(`${path} shows empty response`); | ||
return; | ||
} | ||
return handler(data, loginData); | ||
}).catch((error)=>logger.log(`failed loading ${path}: ${error}`)); | ||
}; | ||
const getRootGamePayload = (data, adapter)=>{ | ||
if (!data || !Array.isArray(data) || data.length < 4) { | ||
logger.error("Received invalid payload from game - %O \n the valid payload is [userdata, lang, network, instance]", data); | ||
return; | ||
} | ||
const [userdata, lang, network, instance] = data; | ||
return { | ||
userdata: adapter.getPlayerInfo(userdata), | ||
lang, | ||
network, | ||
instance | ||
}; | ||
}; | ||
const countUnread = (loginData, announcements)=>{ | ||
const filteredAnnouncements = filterUnreadForceOpen(alreadyShown(loginData))(announcements); | ||
return filteredAnnouncements.length; | ||
}; | ||
const getNewAnnouncements = (loginData)=>{ | ||
logger.log("getNewAnnouncements - loginData: %O", loginData); | ||
const countUnreadAnnouncements = (announcements)=>{ | ||
let announcementCount = 0; | ||
if (hasAnnouncements(announcements)) { | ||
announcementCount = countUnread(loginData, announcements.Items); | ||
setAnnouncementsCache(announcements); | ||
} | ||
logger.log(` Has announcements: `, announcementCount > 0); | ||
return announcementCount; | ||
}; | ||
return loadCurrentMessages("https://7vjlctgjad.execute-api.eu-west-1.amazonaws.com/dev/messages/" + loginData.gameAcronym, countUnreadAnnouncements, loginData); | ||
}; | ||
const loadMessages = (context)=>(loginData, forceOpenMessages = false)=>{ | ||
const handleMessages = handleAnnouncementMessage("http://localhost:4002/", context, forceOpenMessages); | ||
return loadCurrentMessages("https://7vjlctgjad.execute-api.eu-west-1.amazonaws.com/dev/messages/" + loginData.gameAcronym, handleMessages, loginData); | ||
}; | ||
const loadLoginMessages = (context)=>(loginData)=>{ | ||
const forceOpenMessages = true; | ||
return loadMessages(context)(loginData, forceOpenMessages); | ||
}; | ||
// ========= Announcements and login data cache section ========= | ||
let cachedAnnouncements; | ||
const setAnnouncementsCache = (annoucement)=>{ | ||
cachedAnnouncements = annoucement; | ||
}; | ||
const getAnnouncementsCache = ()=>{ | ||
if (!cachedAnnouncements || Object.keys(cachedAnnouncements).length === 0) { | ||
logger.warn("getAnnouncementsCache - annoucement data has not been set yet", cachedAnnouncements); | ||
return; | ||
} | ||
return cachedAnnouncements; | ||
}; | ||
const preservedLoginData = {}; | ||
const setLoginData = (context, adapter)=>(loginData)=>{ | ||
if (!loginData && Object.keys(preservedLoginData).length === 0) { | ||
logger.warn("saveLoginData - the user data has not been set/initialized %O", preservedLoginData); | ||
return; | ||
} | ||
const gamePayload = getRootGamePayload(loginData, adapter); | ||
if (loginData && gamePayload) Object.assign(preservedLoginData, { | ||
lang: gamePayload.lang, | ||
network: gamePayload.network, | ||
instance: gamePayload.instance, | ||
game: context.game, | ||
gameAcronym: acronym(context.game), | ||
playername: gamePayload.userdata.playername, | ||
level: gamePayload.userdata.level | ||
}); | ||
}; | ||
const getLoginData = ()=>{ | ||
if (!preservedLoginData || Object.keys(preservedLoginData).length === 0) { | ||
logger.warn("getLoginData - login data has not been set yet", preservedLoginData); | ||
return; | ||
} | ||
return preservedLoginData; | ||
}; | ||
module.exports = { | ||
getNewAnnouncements, | ||
getAnnouncementsCache, | ||
setLoginData, | ||
getLoginData, | ||
loadMessages, | ||
loadLoginMessages | ||
}; | ||
module.exports.__internals = { | ||
alreadyShown, | ||
countUnread, | ||
filterUnread: filterUnreadForceOpen, | ||
getAnnouncementFilters, | ||
getRootGamePayload, | ||
handleAnnouncementMessage, | ||
hasAnnouncements, | ||
loadCurrentMessages, | ||
setAnnouncementsCache | ||
}; | ||
},{"url-search-params-polyfill":"5fp49","@goodgamestudios/game-alias":"iUC5C","./window-handlers":"kLkRK","./cxf-event-constants":"3B2HD","./utils":"en4he"}],"5fp49":[function(require,module,exports) { | ||
var global = arguments[3]; | ||
/** | ||
@@ -8,4 +1110,336 @@ * | ||
* | ||
*/ | ||
!function(t){var e,n=function(t){var e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(t).replace(/[!'\(\)~]|%20|%00/g,(function(t){return e[t]}))},r=function(t){return t.replace(/[ +]/g,"%20").replace(/(%[a-f0-9]{2})+/gi,(function(t){return decodeURIComponent(t)}))},o=function(e){var n={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return d&&(n[t.Symbol.iterator]=function(){return n}),n},a=function(t){var e={};if("object"==typeof t)if(c(t))for(var n=0;n<t.length;n++){var o=t[n];if(!c(o)||2!==o.length)throw new TypeError("Failed to construct 'URLSearchParams': Sequence initializer must only contain pair elements");i(e,o[0],o[1])}else for(var a in t)t.hasOwnProperty(a)&&i(e,a,t[a]);else{0===t.indexOf("?")&&(t=t.slice(1));for(var u=t.split("&"),s=0;s<u.length;s++){var l=u[s],f=l.indexOf("=");-1<f?i(e,r(l.slice(0,f)),r(l.slice(f+1))):l&&i(e,r(l),"")}}return e},i=function(t,e,n){var r="string"==typeof n?n:null!=n&&"function"==typeof n.toString?n.toString():JSON.stringify(n);u(t,e)?t[e].push(r):t[e]=[r]},c=function(t){return!!t&&"[object Array]"===Object.prototype.toString.call(t)},u=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s=function(){try{if(t.URLSearchParams&&"bar"===new t.URLSearchParams("foo=bar").get("foo"))return t.URLSearchParams}catch(t){}return null}(),l=s&&"a=1"===new s({a:1}).toString(),f=s&&"+"===new s("s=%2B").get("s"),h=!s||((e=new s).append("s"," &"),"s=+%26"===e.toString()),g=y.prototype,d=!(!t.Symbol||!t.Symbol.iterator);if(!(s&&l&&f&&h)){var p;g.append=function(t,e){i(this.__URLSearchParams__,t,e)},g.delete=function(t){delete this.__URLSearchParams__[t]},g.get=function(t){var e=this.__URLSearchParams__;return this.has(t)?e[t][0]:null},g.getAll=function(t){var e=this.__URLSearchParams__;return this.has(t)?e[t].slice(0):[]},g.has=function(t){return u(this.__URLSearchParams__,t)},g.set=function(t,e){this.__URLSearchParams__[t]=[""+e]},g.toString=function(){var t,e,r,o,a=this.__URLSearchParams__,i=[];for(e in a)for(r=n(e),t=0,o=a[e];t<o.length;t++)i.push(r+"="+n(o[t]));return i.join("&")},!!f&&s&&!l&&t.Proxy?(p=new Proxy(s,{construct:function(t,e){return new t(new y(e[0]).toString())}})).toString=Function.prototype.toString.bind(y):p=y,Object.defineProperty(t,"URLSearchParams",{value:p});var m=t.URLSearchParams.prototype;m.polyfill=!0,m.forEach=m.forEach||function(t,e){var n=a(this.toString());Object.getOwnPropertyNames(n).forEach((function(r){n[r].forEach((function(n){t.call(e,n,r,this)}),this)}),this)},m.sort=m.sort||function(){var t,e,n,r=a(this.toString()),o=[];for(t in r)o.push(t);for(o.sort(),e=0;e<o.length;e++)this.delete(o[e]);for(e=0;e<o.length;e++){var i=o[e],c=r[i];for(n=0;n<c.length;n++)this.append(i,c[n])}},m.keys=m.keys||function(){var t=[];return this.forEach((function(e,n){t.push(n)})),o(t)},m.values=m.values||function(){var t=[];return this.forEach((function(e){t.push(e)})),o(t)},m.entries=m.entries||function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),o(t)},d&&(m[t.Symbol.iterator]=m[t.Symbol.iterator]||m.entries)}function y(t){((t=t||"")instanceof URLSearchParams||t instanceof y)&&(t=t.toString()),this.__URLSearchParams__=a(t)}}(void 0!==e?e:"undefined"!=typeof window?window:t.exports)})),o.register("2lV2D",(function(t,e){var n,r,o,a,i,c,u,s,l,f,h;r=function(t,e){return i(t)||a(t,e)||o()},o=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")},a=function(t,e){var n=[],r=!0,o=!1,a=void 0;try{for(var i,c=t[Symbol.iterator]();!(r=(i=c.next()).done)&&(n.push(i.value),!e||n.length!==e);r=!0);}catch(t){o=!0,a=t}finally{try{r||null==c.return||c.return()}finally{if(o)throw a}}return n},i=function(t){if(Array.isArray(t))return t},c={1:["poker","poker2","poker"],12:["empire","castle","em"],15:["bigfarm","ranch","bf"],16:["empirefourkingdoms","fourkingdoms","e4k"],23:["legendsofhonor",void 0,"loh"],41:["empiremillenniumwars",void 0,"emmw"]},u=Object.entries(c).reduce((function(t,e){var n=r(e,2),o=n[0],a=n[1];return o=parseInt(o,10),t[o]=o,a.forEach((function(e){t[e]=o})),t}),{}),l=(s=function(t,e){return(e=u[e])&&c[e][t]}).bind(null,0),f=s.bind(null,1),h=s.bind(null,2),n={id:function(t){t=t.toString().toLowerCase();var e=u[t];return e&&0|e},name:l,codename:f,acronym:h},"object"==typeof t.exports?t.exports=n:"function"==typeof define&&define.amd&&define((function(){return n}))}));var f={};Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=new Object(this),n=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var r=arguments[1],o=0;o<n;){var a=e[o];if(t.call(r,a,o,e))return a;o++}},configurable:!0,writable:!0});var h=function(t,e){t=new URL(t);var n=!0,r=!1,o=void 0;try{for(var a,i=Object.keys(e)[Symbol.iterator]();!(n=(a=i.next()).done);n=!0){var c=a.value;t.searchParams.append(c,e[c])}}catch(t){r=!0,o=t}finally{try{n||null==i.return||i.return()}finally{if(r)throw o}}return t.toString()},g="CXF-ANNOUNCEMENT",d={info:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r;(r=console).info.apply(r,["%c ".concat(g," ->"),"background: green; color: yellow"].concat(l(e)))},log:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r;(r=console).info.apply(r,["%c ".concat(g," ->"),"background: green; color: yellow"].concat(l(e)))},warn:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r;(r=console).warn.apply(r,["%c ".concat(g," ->"),"background: orange; color: yellow"].concat(l(e)))},error:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r;(r=console).error.apply(r,["%c ".concat(g," ->"),"background: red; color: yellow"].concat(l(e)))}};f={containsInstance:function(t,e,n){var r=t.find((function(t){return t.id===e}));return!!r&&(r=r.instances.find((function(t){return t===n})),Boolean(r))},sharedCommands:{CLOSE_POPUP:"cxf.announcements.closePopup",MARK_AS_READ:"cxf.announcements.markAsRead",SHOW_ANNOUNCEMENTS:"cxf.announcements.getAllAnnouncements",TRACKING:"cxf.announcements.tracking",LINK_CLICKED:"cxf.announcements.hrefClicked"},appendLoginParameters:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=e.network,o=e.instance,a=e.lang,i="".concat(t,"/").concat(r,"/").concat(o,"/").concat(a),c=h(i,n);return c},appendQueryParameters:h,ANNOUNCEMENTS_LOCALSTORAGE_KEY:"ggs.cxf.announcements.fetchedAnnouncements",hashCode:function(t){for(var e=0,n=0;n<t.length;n++)e=Math.imul(31,e)+t.charCodeAt(n)|0;return e},getHashKey:function(t,e,n,r){var o=[t,e,n,r].join("_");return"ggs.cxf.announcements.".concat(o,".messageHash")},logger:d,subtractArray:function(t,e){return t.filter((function(t){return!e.includes(t)}))}};var p,m,y={},v=f.subtractArray,w=f.sharedCommands,E=f.ANNOUNCEMENTS_LOCALSTORAGE_KEY,_={},A=(_={CXF_DIALOG_OPEN:"cxf.dialog.open",CXF_DIALOG_CLOSE:"cxf.dialog.close"}).CXF_DIALOG_CLOSE,N={},S="game.button.clicked.",O={GET_ANNOUNCEMENTS:"".concat(S,"getAnnouncements"),OPEN_ANNOUNCEMENTS:"".concat(S,"openAnnouncements")},L=(N={GAME_CALLBACK:{UNREAD_ANNOUNCEMENTS:"setCapToolNotifications",PAGE_LOAD_STARTING:"pageLoadStarting"},GAME:{BIG_FARM:"bigfarm",EMPIRE:"empire",E4K:"empirefourkingdoms"},GAME_BUTTON_CLICKED_PREFIX:S,GAME_ANNOUNCEMENTS_EVENT:O,OPEN:O.OPEN_ANNOUNCEMENTS,GET:O.GET_ANNOUNCEMENTS}).GET,b=N.GAME_CALLBACK,C={},T=f.logger,x="cxf.tracking.message",I=(C={init:function(t){T.log("tracking has been initialized",t),p=t},tracking:function(t,e,n){var r=function(t){var e;return t&&(e=Array.isArray(t.Items)?t.Items[0]:t),e}(e),o={eventId:1236,gameId:Number.parseInt(p.gameId,10),networkId:Number.parseInt(p.networkId,10),instanceId:p.instanceId,playerId:p.playerId,language:p.countryCode,date:(new Date).toUTCString(),zoneId:p.zoneId,actionType:t},a=r.id,i=r.start_date,c=r.end_date,s=r.title;(o=u({},o,n)).id=a,o.scheduleStart=new Date(i).toUTCString(),o.scheduleEnd=new Date(c).toUTCString(),o.name=s,T.log(x,JSON.stringify(o,null,4)),p.emit(x,o)},OPEN_ANNOUNCEMENTS:"click",ANNOUNCEMENT_READY:"announcement_ready",CLOSE_CROSS:"close_cross",CLOSE_REGULAR:"close_regular",DONT_SHOW_AGAIN_ACTIVATE:"dont_show_again_activate",DONT_SHOW_AGAIN_DEACTIVATE:"dont_show_again_deactivate",SCROLL:"scroll",LOADED:"loaded"}).tracking,P=C.CLOSE_CROSS,k=C.CLOSE_REGULAR,R=C.DONT_SHOW_AGAIN_ACTIVATE,U=C.DONT_SHOW_AGAIN_DEACTIVATE,G=C.SCROLL,M=C.LOADED;function D(t){var e=t.hash,n=t.wasRead,r=F(e.key),o=n?R:U,a=!0,i=!1,c=void 0;try{for(var u,s=m[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var l=u.value;I(o,l)}}catch(t){i=!0,c=t}finally{try{a||null==s.return||s.return()}finally{if(i)throw c}}var f=n?r.concat(e.hashList):v(r,e.hashList);0===f.length?localStorage.removeItem(e.key):localStorage.setItem(e.key,JSON.stringify(f))}function j(t){localStorage.removeItem(E),m=void 0,t.emit(A)}function F(t){var e=localStorage.getItem(t)||"[]";return JSON.parse(e)}function K(){var t=localStorage.getItem(E)||"[]";return JSON.parse(t)}var J=function(t,e){return e.start_date-t.start_date};function V(t){var e=t.frameId,n=K().sort(J);if(n&&n.length>0){var r=document.getElementById(e).contentWindow;m=n;var o=Date.now();r.postMessage({messages:n,triggeredTimestamp:o},"*"),localStorage.setItem(E,JSON.stringify([]))}}var H=new Map([["okBtn",k],["crossBtn",P],["scrolled",G],["loaded",M]]);(y={addWindowListeners:function(t){window.addEventListener("message",(function(e){if(e.data&&e.data.name)switch(e.data.name){case w.MARK_AS_READ:D(e.data),t.emit(L);break;case w.CLOSE_POPUP:j(t);break;case w.SHOW_ANNOUNCEMENTS:V(e.data);break;case w.TRACKING:var n=!0,r=!1,o=void 0;try{for(var a,i=m[Symbol.iterator]();!(n=(a=i.next()).done);n=!0){var c=a.value;if("scrolled"===e.data.action)e.data.params.scrolledAnnouncements.includes(c.id)&&I(H.get(e.data.action),c,e.data.params);else I(H.get(e.data.action),c,e.data.params)}}catch(t){r=!0,o=t}finally{try{n||null==i.return||i.return()}finally{if(r)throw o}}break;case w.LINK_CLICKED:t.gameApi.invokeFn(b.PAGE_LOAD_STARTING,e.data.href)}}),!1)},getDoNotShowMessages:F}).__internals={markAsRead:D,getDoNotShowMessages:F,getMessages:K,closeFrame:j,showAllMessages:V,setAllActiveAnnouncements:function(t){m=t}};var B,z=y.addWindowListeners,W=f.logger,Y=N.GAME,X=(c(B={},Y.EMPIRE,o("jvuiF")),c(B,Y.BIG_FARM,o("7y43J")),c(B,Y.E4K,o("5uSe0")),B),q=N.OPEN,Q=N.GET,Z=C.init;!function(t){W.log(" initialized successfully - waiting for player login",t.game),Z(t);var e=X[t.game],n=o("4y3pw")(t,e);z(t),e.logoutCmd&&t.on(e.logoutCmd,n.onLogout),t.once(3,n.placeholder),t.once(24,n.placeholder),t.on(Q,n.onGetMessageStatus(Q)),t.once(e.loginCmd,n.onGetMessageStatus(e.loginCmd)),t.on(q,n.onOpenAnnouncements)}(window.CXF)}(); | ||
//# sourceMappingURL=announcements.js.map | ||
*/ (function(self) { | ||
"use strict"; | ||
var nativeURLSearchParams = function() { | ||
// #41 Fix issue in RN | ||
try { | ||
if (self.URLSearchParams && new self.URLSearchParams("foo=bar").get("foo") === "bar") return self.URLSearchParams; | ||
} catch (e) {} | ||
return null; | ||
}(), isSupportObjectConstructor = nativeURLSearchParams && new nativeURLSearchParams({ | ||
a: 1 | ||
}).toString() === "a=1", // There is a bug in safari 10.1 (and earlier) that incorrectly decodes `%2B` as an empty space and not a plus. | ||
decodesPlusesCorrectly = nativeURLSearchParams && new nativeURLSearchParams("s=%2B").get("s") === "+", __URLSearchParams__ = "__URLSearchParams__", // Fix bug in Edge which cannot encode ' &' correctly | ||
encodesAmpersandsCorrectly = nativeURLSearchParams ? function() { | ||
var ampersandTest = new nativeURLSearchParams(); | ||
ampersandTest.append("s", " &"); | ||
return ampersandTest.toString() === "s=+%26"; | ||
}() : true, prototype = URLSearchParamsPolyfill.prototype, iterable = !!(self.Symbol && self.Symbol.iterator); | ||
if (nativeURLSearchParams && isSupportObjectConstructor && decodesPlusesCorrectly && encodesAmpersandsCorrectly) return; | ||
/** | ||
* Make a URLSearchParams instance | ||
* | ||
* @param {object|string|URLSearchParams} search | ||
* @constructor | ||
*/ function URLSearchParamsPolyfill(search) { | ||
search = search || ""; | ||
// support construct object with another URLSearchParams instance | ||
if (search instanceof URLSearchParams || search instanceof URLSearchParamsPolyfill) search = search.toString(); | ||
this[__URLSearchParams__] = parseToDict(search); | ||
} | ||
/** | ||
* Appends a specified key/value pair as a new search parameter. | ||
* | ||
* @param {string} name | ||
* @param {string} value | ||
*/ prototype.append = function(name, value) { | ||
appendTo(this[__URLSearchParams__], name, value); | ||
}; | ||
/** | ||
* Deletes the given search parameter, and its associated value, | ||
* from the list of all search parameters. | ||
* | ||
* @param {string} name | ||
*/ prototype["delete"] = function(name) { | ||
delete this[__URLSearchParams__][name]; | ||
}; | ||
/** | ||
* Returns the first value associated to the given search parameter. | ||
* | ||
* @param {string} name | ||
* @returns {string|null} | ||
*/ prototype.get = function(name) { | ||
var dict = this[__URLSearchParams__]; | ||
return this.has(name) ? dict[name][0] : null; | ||
}; | ||
/** | ||
* Returns all the values association with a given search parameter. | ||
* | ||
* @param {string} name | ||
* @returns {Array} | ||
*/ prototype.getAll = function(name) { | ||
var dict = this[__URLSearchParams__]; | ||
return this.has(name) ? dict[name].slice(0) : []; | ||
}; | ||
/** | ||
* Returns a Boolean indicating if such a search parameter exists. | ||
* | ||
* @param {string} name | ||
* @returns {boolean} | ||
*/ prototype.has = function(name) { | ||
return hasOwnProperty(this[__URLSearchParams__], name); | ||
}; | ||
/** | ||
* Sets the value associated to a given search parameter to | ||
* the given value. If there were several values, delete the | ||
* others. | ||
* | ||
* @param {string} name | ||
* @param {string} value | ||
*/ prototype.set = function set(name, value) { | ||
this[__URLSearchParams__][name] = [ | ||
"" + value | ||
]; | ||
}; | ||
/** | ||
* Returns a string containg a query string suitable for use in a URL. | ||
* | ||
* @returns {string} | ||
*/ prototype.toString = function() { | ||
var dict = this[__URLSearchParams__], query = [], i, key, name, value; | ||
for(key in dict){ | ||
name = encode(key); | ||
for(i = 0, value = dict[key]; i < value.length; i++)query.push(name + "=" + encode(value[i])); | ||
} | ||
return query.join("&"); | ||
}; | ||
// There is a bug in Safari 10.1 and `Proxy`ing it is not enough. | ||
var forSureUsePolyfill = !decodesPlusesCorrectly; | ||
var useProxy = !forSureUsePolyfill && nativeURLSearchParams && !isSupportObjectConstructor && self.Proxy; | ||
var propValue; | ||
if (useProxy) { | ||
// Safari 10.0 doesn't support Proxy, so it won't extend URLSearchParams on safari 10.0 | ||
propValue = new Proxy(nativeURLSearchParams, { | ||
construct: function(target, args) { | ||
return new target(new URLSearchParamsPolyfill(args[0]).toString()); | ||
} | ||
}); | ||
// Chrome <=60 .toString() on a function proxy got error "Function.prototype.toString is not generic" | ||
propValue.toString = Function.prototype.toString.bind(URLSearchParamsPolyfill); | ||
} else propValue = URLSearchParamsPolyfill; | ||
/* | ||
* Apply polifill to global object and append other prototype into it | ||
*/ Object.defineProperty(self, "URLSearchParams", { | ||
value: propValue | ||
}); | ||
var USPProto = self.URLSearchParams.prototype; | ||
USPProto.polyfill = true; | ||
/** | ||
* | ||
* @param {function} callback | ||
* @param {object} thisArg | ||
*/ USPProto.forEach = USPProto.forEach || function(callback, thisArg) { | ||
var dict = parseToDict(this.toString()); | ||
Object.getOwnPropertyNames(dict).forEach(function(name) { | ||
dict[name].forEach(function(value) { | ||
callback.call(thisArg, value, name, this); | ||
}, this); | ||
}, this); | ||
}; | ||
/** | ||
* Sort all name-value pairs | ||
*/ USPProto.sort = USPProto.sort || function() { | ||
var dict = parseToDict(this.toString()), keys = [], k, i, j; | ||
for(k in dict)keys.push(k); | ||
keys.sort(); | ||
for(i = 0; i < keys.length; i++)this["delete"](keys[i]); | ||
for(i = 0; i < keys.length; i++){ | ||
var key = keys[i], values = dict[key]; | ||
for(j = 0; j < values.length; j++)this.append(key, values[j]); | ||
} | ||
}; | ||
/** | ||
* Returns an iterator allowing to go through all keys of | ||
* the key/value pairs contained in this object. | ||
* | ||
* @returns {function} | ||
*/ USPProto.keys = USPProto.keys || function() { | ||
var items = []; | ||
this.forEach(function(item, name) { | ||
items.push(name); | ||
}); | ||
return makeIterator(items); | ||
}; | ||
/** | ||
* Returns an iterator allowing to go through all values of | ||
* the key/value pairs contained in this object. | ||
* | ||
* @returns {function} | ||
*/ USPProto.values = USPProto.values || function() { | ||
var items = []; | ||
this.forEach(function(item) { | ||
items.push(item); | ||
}); | ||
return makeIterator(items); | ||
}; | ||
/** | ||
* Returns an iterator allowing to go through all key/value | ||
* pairs contained in this object. | ||
* | ||
* @returns {function} | ||
*/ USPProto.entries = USPProto.entries || function() { | ||
var items = []; | ||
this.forEach(function(item, name) { | ||
items.push([ | ||
name, | ||
item | ||
]); | ||
}); | ||
return makeIterator(items); | ||
}; | ||
if (iterable) USPProto[self.Symbol.iterator] = USPProto[self.Symbol.iterator] || USPProto.entries; | ||
function encode(str) { | ||
var replace = { | ||
"!": "%21", | ||
"'": "%27", | ||
"(": "%28", | ||
")": "%29", | ||
"~": "%7E", | ||
"%20": "+", | ||
"%00": "\0" | ||
}; | ||
return encodeURIComponent(str).replace(/[!'\(\)~]|%20|%00/g, function(match) { | ||
return replace[match]; | ||
}); | ||
} | ||
function decode(str) { | ||
return str.replace(/[ +]/g, "%20").replace(/(%[a-f0-9]{2})+/ig, function(match) { | ||
return decodeURIComponent(match); | ||
}); | ||
} | ||
function makeIterator(arr) { | ||
var iterator = { | ||
next: function() { | ||
var value = arr.shift(); | ||
return { | ||
done: value === undefined, | ||
value: value | ||
}; | ||
} | ||
}; | ||
if (iterable) iterator[self.Symbol.iterator] = function() { | ||
return iterator; | ||
}; | ||
return iterator; | ||
} | ||
function parseToDict(search) { | ||
var dict = {}; | ||
if (typeof search === "object") { | ||
// if `search` is an array, treat it as a sequence | ||
if (isArray(search)) for(var i = 0; i < search.length; i++){ | ||
var item = search[i]; | ||
if (isArray(item) && item.length === 2) appendTo(dict, item[0], item[1]); | ||
else throw new TypeError("Failed to construct 'URLSearchParams': Sequence initializer must only contain pair elements"); | ||
} | ||
else { | ||
for(var key in search)if (search.hasOwnProperty(key)) appendTo(dict, key, search[key]); | ||
} | ||
} else { | ||
// remove first '?' | ||
if (search.indexOf("?") === 0) search = search.slice(1); | ||
var pairs = search.split("&"); | ||
for(var j = 0; j < pairs.length; j++){ | ||
var value = pairs[j], index = value.indexOf("="); | ||
if (-1 < index) appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1))); | ||
else if (value) appendTo(dict, decode(value), ""); | ||
} | ||
} | ||
return dict; | ||
} | ||
function appendTo(dict, name, value) { | ||
var val = typeof value === "string" ? value : value !== null && value !== undefined && typeof value.toString === "function" ? value.toString() : JSON.stringify(value); | ||
// #47 Prevent using `hasOwnProperty` as a property name | ||
if (hasOwnProperty(dict, name)) dict[name].push(val); | ||
else dict[name] = [ | ||
val | ||
]; | ||
} | ||
function isArray(val) { | ||
return !!val && "[object Array]" === Object.prototype.toString.call(val); | ||
} | ||
function hasOwnProperty(obj, prop) { | ||
return Object.prototype.hasOwnProperty.call(obj, prop); | ||
} | ||
})(typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : this); | ||
},{}],"iUC5C":[function(require,module,exports) { | ||
(function() { | ||
var b = {}; | ||
function f(r, $) { | ||
return h(r) || g(r, $) || e(); | ||
} | ||
function e() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
function g(r, $) { | ||
var a = [], o = !0, e = !1, n = void 0; | ||
try { | ||
for(var c, i = r[Symbol.iterator](); !(o = (c = i.next()).done) && (a.push(c.value), !$ || a.length !== $); o = !0); | ||
} catch (m) { | ||
e = !0, n = m; | ||
} finally{ | ||
try { | ||
o || null == i.return || i.return(); | ||
} finally{ | ||
if (e) throw n; | ||
} | ||
} | ||
return a; | ||
} | ||
function h(r) { | ||
if (Array.isArray(r)) return r; | ||
} | ||
var i = 0, j = 1, k = 2, c = { | ||
1: [ | ||
"poker", | ||
"poker2", | ||
"poker" | ||
], | ||
12: [ | ||
"empire", | ||
"castle", | ||
"em" | ||
], | ||
15: [ | ||
"bigfarm", | ||
"ranch", | ||
"bf" | ||
], | ||
16: [ | ||
"empirefourkingdoms", | ||
"fourkingdoms", | ||
"e4k" | ||
], | ||
23: [ | ||
"legendsofhonor", | ||
void 0, | ||
"loh" | ||
], | ||
41: [ | ||
"empiremillenniumwars", | ||
void 0, | ||
"emmw" | ||
] | ||
}, d = Object.entries(c).reduce(function(r, $) { | ||
var a = f($, 2), o = a[0], e = a[1]; | ||
return o = parseInt(o, 10), r[o] = o, e.forEach(function($) { | ||
r[$] = o; | ||
}), r; | ||
}, {}), l = function(r) { | ||
r = r.toString().toLowerCase(); | ||
var $ = d[r]; | ||
return $ && 0 | $; | ||
}, a = function(r, $) { | ||
return ($ = d[$]) && c[$][r]; | ||
}, m = a.bind(null, i), n = a.bind(null, j), o = a.bind(null, k); | ||
b = { | ||
id: l, | ||
name: m, | ||
codename: n, | ||
acronym: o | ||
}; | ||
module.exports = b; | ||
})(); | ||
},{}]},["f0MWR","2rNzt"], "2rNzt", "parcelRequire3fb7") | ||
{ | ||
"name": "@goodgamestudios/cxf-announcements", | ||
"version": "0.19.4-qa.0", | ||
"version": "0.19.4-qa.1", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "serve:locally": "http-server dist --port 4002", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2907300
80
11617
3
21