@goodgamestudios/cxf-webshop 7.0.0-qa.8 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1499 @@
1
+ "use strict";
2
+ (() => {
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __esm = (fn, res) => function __init() {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ };
12
+ var __commonJS = (cb, mod) => function __require() {
13
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+
32
+ // <define:process>
33
+ var define_process_default;
34
+ var init_define_process = __esm({
35
+ "<define:process>"() {
36
+ define_process_default = { env: { BASE_URL: "http://localhost:1101", CANVAS_AGENT_URL: "https://app-dev.canvas.stillfront.com/agent.js", CANVAS_APP_ID_BY_GAME: { "12": "dae760ab-b773-4c1a-ae99-7633f12ec7d5", "15": "d57bb239-6e02-4e17-8148-0a10c4dd75f6", "16": "18f5521d-7df2-4bb3-88a3-c162ba072d73" }, CUSTOMIZATION_URL_TEMPLATE: "https://cdn.jsdelivr.net/npm/@lemonstand.org/config-goodgamestudios@{1}/dist/goodgamestudios-{0}.json", CUSTOMIZATION_URL: "https://cdn.jsdelivr.net/npm/@lemonstand.org/config-goodgamestudios@qa/dist/goodgamestudios-{0}.json" } };
37
+ }
38
+ });
39
+
40
+ // node_modules/debug/node_modules/ms/index.js
41
+ var require_ms = __commonJS({
42
+ "node_modules/debug/node_modules/ms/index.js"(exports, module) {
43
+ init_define_process();
44
+ var s = 1e3;
45
+ var m = s * 60;
46
+ var h = m * 60;
47
+ var d = h * 24;
48
+ var w = d * 7;
49
+ var y = d * 365.25;
50
+ module.exports = function(val, options) {
51
+ options = options || {};
52
+ var type = typeof val;
53
+ if (type === "string" && val.length > 0) {
54
+ return parse(val);
55
+ } else if (type === "number" && isFinite(val)) {
56
+ return options.long ? fmtLong(val) : fmtShort(val);
57
+ }
58
+ throw new Error(
59
+ "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
60
+ );
61
+ };
62
+ function parse(str) {
63
+ str = String(str);
64
+ if (str.length > 100) {
65
+ return;
66
+ }
67
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
68
+ str
69
+ );
70
+ if (!match) {
71
+ return;
72
+ }
73
+ var n = parseFloat(match[1]);
74
+ var type = (match[2] || "ms").toLowerCase();
75
+ switch (type) {
76
+ case "years":
77
+ case "year":
78
+ case "yrs":
79
+ case "yr":
80
+ case "y":
81
+ return n * y;
82
+ case "weeks":
83
+ case "week":
84
+ case "w":
85
+ return n * w;
86
+ case "days":
87
+ case "day":
88
+ case "d":
89
+ return n * d;
90
+ case "hours":
91
+ case "hour":
92
+ case "hrs":
93
+ case "hr":
94
+ case "h":
95
+ return n * h;
96
+ case "minutes":
97
+ case "minute":
98
+ case "mins":
99
+ case "min":
100
+ case "m":
101
+ return n * m;
102
+ case "seconds":
103
+ case "second":
104
+ case "secs":
105
+ case "sec":
106
+ case "s":
107
+ return n * s;
108
+ case "milliseconds":
109
+ case "millisecond":
110
+ case "msecs":
111
+ case "msec":
112
+ case "ms":
113
+ return n;
114
+ default:
115
+ return void 0;
116
+ }
117
+ }
118
+ function fmtShort(ms) {
119
+ var msAbs = Math.abs(ms);
120
+ if (msAbs >= d) {
121
+ return Math.round(ms / d) + "d";
122
+ }
123
+ if (msAbs >= h) {
124
+ return Math.round(ms / h) + "h";
125
+ }
126
+ if (msAbs >= m) {
127
+ return Math.round(ms / m) + "m";
128
+ }
129
+ if (msAbs >= s) {
130
+ return Math.round(ms / s) + "s";
131
+ }
132
+ return ms + "ms";
133
+ }
134
+ function fmtLong(ms) {
135
+ var msAbs = Math.abs(ms);
136
+ if (msAbs >= d) {
137
+ return plural(ms, msAbs, d, "day");
138
+ }
139
+ if (msAbs >= h) {
140
+ return plural(ms, msAbs, h, "hour");
141
+ }
142
+ if (msAbs >= m) {
143
+ return plural(ms, msAbs, m, "minute");
144
+ }
145
+ if (msAbs >= s) {
146
+ return plural(ms, msAbs, s, "second");
147
+ }
148
+ return ms + " ms";
149
+ }
150
+ function plural(ms, msAbs, n, name) {
151
+ var isPlural = msAbs >= n * 1.5;
152
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
153
+ }
154
+ }
155
+ });
156
+
157
+ // node_modules/debug/src/common.js
158
+ var require_common = __commonJS({
159
+ "node_modules/debug/src/common.js"(exports, module) {
160
+ init_define_process();
161
+ function setup(env) {
162
+ createDebug.debug = createDebug;
163
+ createDebug.default = createDebug;
164
+ createDebug.coerce = coerce;
165
+ createDebug.disable = disable;
166
+ createDebug.enable = enable;
167
+ createDebug.enabled = enabled;
168
+ createDebug.humanize = require_ms();
169
+ createDebug.destroy = destroy;
170
+ Object.keys(env).forEach((key) => {
171
+ createDebug[key] = env[key];
172
+ });
173
+ createDebug.names = [];
174
+ createDebug.skips = [];
175
+ createDebug.formatters = {};
176
+ function selectColor(namespace) {
177
+ let hash = 0;
178
+ for (let i = 0; i < namespace.length; i++) {
179
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
180
+ hash |= 0;
181
+ }
182
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
183
+ }
184
+ createDebug.selectColor = selectColor;
185
+ function createDebug(namespace) {
186
+ let prevTime;
187
+ let enableOverride = null;
188
+ let namespacesCache;
189
+ let enabledCache;
190
+ function debug2(...args) {
191
+ if (!debug2.enabled) {
192
+ return;
193
+ }
194
+ const self = debug2;
195
+ const curr = Number(/* @__PURE__ */ new Date());
196
+ const ms = curr - (prevTime || curr);
197
+ self.diff = ms;
198
+ self.prev = prevTime;
199
+ self.curr = curr;
200
+ prevTime = curr;
201
+ args[0] = createDebug.coerce(args[0]);
202
+ if (typeof args[0] !== "string") {
203
+ args.unshift("%O");
204
+ }
205
+ let index = 0;
206
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
207
+ if (match === "%%") {
208
+ return "%";
209
+ }
210
+ index++;
211
+ const formatter = createDebug.formatters[format];
212
+ if (typeof formatter === "function") {
213
+ const val = args[index];
214
+ match = formatter.call(self, val);
215
+ args.splice(index, 1);
216
+ index--;
217
+ }
218
+ return match;
219
+ });
220
+ createDebug.formatArgs.call(self, args);
221
+ const logFn = self.log || createDebug.log;
222
+ logFn.apply(self, args);
223
+ }
224
+ debug2.namespace = namespace;
225
+ debug2.useColors = createDebug.useColors();
226
+ debug2.color = createDebug.selectColor(namespace);
227
+ debug2.extend = extend;
228
+ debug2.destroy = createDebug.destroy;
229
+ Object.defineProperty(debug2, "enabled", {
230
+ enumerable: true,
231
+ configurable: false,
232
+ get: () => {
233
+ if (enableOverride !== null) {
234
+ return enableOverride;
235
+ }
236
+ if (namespacesCache !== createDebug.namespaces) {
237
+ namespacesCache = createDebug.namespaces;
238
+ enabledCache = createDebug.enabled(namespace);
239
+ }
240
+ return enabledCache;
241
+ },
242
+ set: (v) => {
243
+ enableOverride = v;
244
+ }
245
+ });
246
+ if (typeof createDebug.init === "function") {
247
+ createDebug.init(debug2);
248
+ }
249
+ return debug2;
250
+ }
251
+ function extend(namespace, delimiter) {
252
+ const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
253
+ newDebug.log = this.log;
254
+ return newDebug;
255
+ }
256
+ function enable(namespaces) {
257
+ createDebug.save(namespaces);
258
+ createDebug.namespaces = namespaces;
259
+ createDebug.names = [];
260
+ createDebug.skips = [];
261
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
262
+ for (const ns of split) {
263
+ if (ns[0] === "-") {
264
+ createDebug.skips.push(ns.slice(1));
265
+ } else {
266
+ createDebug.names.push(ns);
267
+ }
268
+ }
269
+ }
270
+ function matchesTemplate(search, template) {
271
+ let searchIndex = 0;
272
+ let templateIndex = 0;
273
+ let starIndex = -1;
274
+ let matchIndex = 0;
275
+ while (searchIndex < search.length) {
276
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
277
+ if (template[templateIndex] === "*") {
278
+ starIndex = templateIndex;
279
+ matchIndex = searchIndex;
280
+ templateIndex++;
281
+ } else {
282
+ searchIndex++;
283
+ templateIndex++;
284
+ }
285
+ } else if (starIndex !== -1) {
286
+ templateIndex = starIndex + 1;
287
+ matchIndex++;
288
+ searchIndex = matchIndex;
289
+ } else {
290
+ return false;
291
+ }
292
+ }
293
+ while (templateIndex < template.length && template[templateIndex] === "*") {
294
+ templateIndex++;
295
+ }
296
+ return templateIndex === template.length;
297
+ }
298
+ function disable() {
299
+ const namespaces = [
300
+ ...createDebug.names,
301
+ ...createDebug.skips.map((namespace) => "-" + namespace)
302
+ ].join(",");
303
+ createDebug.enable("");
304
+ return namespaces;
305
+ }
306
+ function enabled(name) {
307
+ for (const skip of createDebug.skips) {
308
+ if (matchesTemplate(name, skip)) {
309
+ return false;
310
+ }
311
+ }
312
+ for (const ns of createDebug.names) {
313
+ if (matchesTemplate(name, ns)) {
314
+ return true;
315
+ }
316
+ }
317
+ return false;
318
+ }
319
+ function coerce(val) {
320
+ if (val instanceof Error) {
321
+ return val.stack || val.message;
322
+ }
323
+ return val;
324
+ }
325
+ function destroy() {
326
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
327
+ }
328
+ createDebug.enable(createDebug.load());
329
+ return createDebug;
330
+ }
331
+ module.exports = setup;
332
+ }
333
+ });
334
+
335
+ // node_modules/debug/src/browser.js
336
+ var require_browser = __commonJS({
337
+ "node_modules/debug/src/browser.js"(exports, module) {
338
+ init_define_process();
339
+ exports.formatArgs = formatArgs;
340
+ exports.save = save;
341
+ exports.load = load;
342
+ exports.useColors = useColors;
343
+ exports.storage = localstorage();
344
+ exports.destroy = /* @__PURE__ */ (() => {
345
+ let warned = false;
346
+ return () => {
347
+ if (!warned) {
348
+ warned = true;
349
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
350
+ }
351
+ };
352
+ })();
353
+ exports.colors = [
354
+ "#0000CC",
355
+ "#0000FF",
356
+ "#0033CC",
357
+ "#0033FF",
358
+ "#0066CC",
359
+ "#0066FF",
360
+ "#0099CC",
361
+ "#0099FF",
362
+ "#00CC00",
363
+ "#00CC33",
364
+ "#00CC66",
365
+ "#00CC99",
366
+ "#00CCCC",
367
+ "#00CCFF",
368
+ "#3300CC",
369
+ "#3300FF",
370
+ "#3333CC",
371
+ "#3333FF",
372
+ "#3366CC",
373
+ "#3366FF",
374
+ "#3399CC",
375
+ "#3399FF",
376
+ "#33CC00",
377
+ "#33CC33",
378
+ "#33CC66",
379
+ "#33CC99",
380
+ "#33CCCC",
381
+ "#33CCFF",
382
+ "#6600CC",
383
+ "#6600FF",
384
+ "#6633CC",
385
+ "#6633FF",
386
+ "#66CC00",
387
+ "#66CC33",
388
+ "#9900CC",
389
+ "#9900FF",
390
+ "#9933CC",
391
+ "#9933FF",
392
+ "#99CC00",
393
+ "#99CC33",
394
+ "#CC0000",
395
+ "#CC0033",
396
+ "#CC0066",
397
+ "#CC0099",
398
+ "#CC00CC",
399
+ "#CC00FF",
400
+ "#CC3300",
401
+ "#CC3333",
402
+ "#CC3366",
403
+ "#CC3399",
404
+ "#CC33CC",
405
+ "#CC33FF",
406
+ "#CC6600",
407
+ "#CC6633",
408
+ "#CC9900",
409
+ "#CC9933",
410
+ "#CCCC00",
411
+ "#CCCC33",
412
+ "#FF0000",
413
+ "#FF0033",
414
+ "#FF0066",
415
+ "#FF0099",
416
+ "#FF00CC",
417
+ "#FF00FF",
418
+ "#FF3300",
419
+ "#FF3333",
420
+ "#FF3366",
421
+ "#FF3399",
422
+ "#FF33CC",
423
+ "#FF33FF",
424
+ "#FF6600",
425
+ "#FF6633",
426
+ "#FF9900",
427
+ "#FF9933",
428
+ "#FFCC00",
429
+ "#FFCC33"
430
+ ];
431
+ function useColors() {
432
+ if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
433
+ return true;
434
+ }
435
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
436
+ return false;
437
+ }
438
+ let m;
439
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
440
+ typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
441
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
442
+ typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
443
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
444
+ }
445
+ function formatArgs(args) {
446
+ args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
447
+ if (!this.useColors) {
448
+ return;
449
+ }
450
+ const c = "color: " + this.color;
451
+ args.splice(1, 0, c, "color: inherit");
452
+ let index = 0;
453
+ let lastC = 0;
454
+ args[0].replace(/%[a-zA-Z%]/g, (match) => {
455
+ if (match === "%%") {
456
+ return;
457
+ }
458
+ index++;
459
+ if (match === "%c") {
460
+ lastC = index;
461
+ }
462
+ });
463
+ args.splice(lastC, 0, c);
464
+ }
465
+ exports.log = console.debug || console.log || (() => {
466
+ });
467
+ function save(namespaces) {
468
+ try {
469
+ if (namespaces) {
470
+ exports.storage.setItem("debug", namespaces);
471
+ } else {
472
+ exports.storage.removeItem("debug");
473
+ }
474
+ } catch (error) {
475
+ }
476
+ }
477
+ function load() {
478
+ let r;
479
+ try {
480
+ r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
481
+ } catch (error) {
482
+ }
483
+ if (!r && typeof define_process_default !== "undefined" && "env" in define_process_default) {
484
+ r = define_process_default.env.DEBUG;
485
+ }
486
+ return r;
487
+ }
488
+ function localstorage() {
489
+ try {
490
+ return localStorage;
491
+ } catch (error) {
492
+ }
493
+ }
494
+ module.exports = require_common()(exports);
495
+ var { formatters } = module.exports;
496
+ formatters.j = function(v) {
497
+ try {
498
+ return JSON.stringify(v);
499
+ } catch (error) {
500
+ return "[UnexpectedJSONParseError]: " + error.message;
501
+ }
502
+ };
503
+ }
504
+ });
505
+
506
+ // node_modules/@goodgamestudios/cxf-ready/dist/index.js
507
+ var require_dist = __commonJS({
508
+ "node_modules/@goodgamestudios/cxf-ready/dist/index.js"(exports, module) {
509
+ "use strict";
510
+ init_define_process();
511
+ var cxf = window && window.CXF;
512
+ module.exports = new Promise(function(resolve, reject) {
513
+ if (!window) {
514
+ reject();
515
+ }
516
+ if (cxf) {
517
+ return resolve(cxf);
518
+ }
519
+ window.addEventListener("cxf.initialized", function(event) {
520
+ cxf = event.cxf;
521
+ resolve(cxf);
522
+ }, {
523
+ capture: true,
524
+ once: true,
525
+ passive: true
526
+ });
527
+ });
528
+ }
529
+ });
530
+
531
+ // node_modules/@goodgamestudios/game-alias/dist/index.js
532
+ var require_dist2 = __commonJS({
533
+ "node_modules/@goodgamestudios/game-alias/dist/index.js"(exports, module) {
534
+ init_define_process();
535
+ (function() {
536
+ var b = {};
537
+ function f(r, $) {
538
+ return h(r) || g(r, $) || e();
539
+ }
540
+ function e() {
541
+ throw new TypeError("Invalid attempt to destructure non-iterable instance");
542
+ }
543
+ function g(r, $) {
544
+ var a2 = [], o2 = true, e2 = false, n2 = void 0;
545
+ try {
546
+ for (var c2, i2 = r[Symbol.iterator](); !(o2 = (c2 = i2.next()).done) && (a2.push(c2.value), !$ || a2.length !== $); o2 = true) ;
547
+ } catch (m2) {
548
+ e2 = true, n2 = m2;
549
+ } finally {
550
+ try {
551
+ o2 || null == i2.return || i2.return();
552
+ } finally {
553
+ if (e2) throw n2;
554
+ }
555
+ }
556
+ return a2;
557
+ }
558
+ function h(r) {
559
+ if (Array.isArray(r)) return r;
560
+ }
561
+ 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, $) {
562
+ var a2 = f($, 2), o2 = a2[0], e2 = a2[1];
563
+ return o2 = parseInt(o2, 10), r[o2] = o2, e2.forEach(function($2) {
564
+ r[$2] = o2;
565
+ }), r;
566
+ }, {}), l = function(r) {
567
+ r = r.toString().toLowerCase();
568
+ var $ = d[r];
569
+ return $ && 0 | $;
570
+ }, a = function(r, $) {
571
+ return ($ = d[$]) && c[$][r];
572
+ }, m = a.bind(null, i), n = a.bind(null, j), o = a.bind(null, k);
573
+ b = { id: l, name: m, codename: n, acronym: o };
574
+ if (typeof exports === "object" && typeof module !== "undefined") {
575
+ module.exports = b;
576
+ } else if (typeof define === "function" && define.amd) {
577
+ define(function() {
578
+ return b;
579
+ });
580
+ }
581
+ })();
582
+ }
583
+ });
584
+
585
+ // node_modules/@goodgamestudios/cxf-events/dist/typings.js
586
+ var require_typings = __commonJS({
587
+ "node_modules/@goodgamestudios/cxf-events/dist/typings.js"(exports) {
588
+ "use strict";
589
+ init_define_process();
590
+ Object.defineProperty(exports, "__esModule", { value: true });
591
+ exports.CxfEvents = void 0;
592
+ var CxfEvents3;
593
+ (function(CxfEvents4) {
594
+ CxfEvents4["Token"] = "cxf.token";
595
+ CxfEvents4["Login"] = "cxf.login";
596
+ CxfEvents4["Signup"] = "cxf.signup";
597
+ CxfEvents4["GameEventUpdate"] = "cxf.gameEvent.update";
598
+ CxfEvents4["GameEventAdd"] = "cxf.gameEvent.add";
599
+ CxfEvents4["GameEventRemove"] = "cxf.gameEvent.remove";
600
+ CxfEvents4["XpChanged"] = "cxf.xp.changed";
601
+ CxfEvents4["LevelChanged"] = "cxf.level.changed";
602
+ CxfEvents4["LegendLevelChanged"] = "cxf.legendLevel.changed";
603
+ CxfEvents4["Push"] = "cxf.push";
604
+ CxfEvents4["OpenIGS"] = "cxf.igs.open";
605
+ CxfEvents4["JoinTempServer"] = "cxf.join.temp.server";
606
+ CxfEvents4["Subscription"] = "cxf.subscription";
607
+ CxfEvents4["RewardedAdStart"] = "cxf.rewardedad.start";
608
+ CxfEvents4["RewardedAdDone"] = "cxf.rewardedad.done";
609
+ })(CxfEvents3 = exports.CxfEvents || (exports.CxfEvents = {}));
610
+ }
611
+ });
612
+
613
+ // src/index.ts
614
+ init_define_process();
615
+
616
+ // src/app.ts
617
+ init_define_process();
618
+
619
+ // src/globalState.ts
620
+ init_define_process();
621
+
622
+ // src/fetch.ts
623
+ init_define_process();
624
+
625
+ // src/helpers.ts
626
+ init_define_process();
627
+
628
+ // node_modules/@lukeed/uuid/dist/index.mjs
629
+ init_define_process();
630
+ var IDX = 256;
631
+ var HEX = [];
632
+ var BUFFER;
633
+ while (IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1);
634
+ function v4() {
635
+ var i = 0, num, out = "";
636
+ if (!BUFFER || IDX + 16 > 256) {
637
+ BUFFER = Array(i = 256);
638
+ while (i--) BUFFER[i] = 256 * Math.random() | 0;
639
+ i = IDX = 0;
640
+ }
641
+ for (; i < 16; i++) {
642
+ num = BUFFER[IDX + i];
643
+ if (i == 6) out += HEX[num & 15 | 64];
644
+ else if (i == 8) out += HEX[num & 63 | 128];
645
+ else out += HEX[num];
646
+ if (i & 1 && i > 1 && i < 11) out += "-";
647
+ }
648
+ IDX++;
649
+ return out;
650
+ }
651
+
652
+ // src/helpers.ts
653
+ var import_debug = __toESM(require_browser());
654
+
655
+ // src/ArgumentNullError.ts
656
+ init_define_process();
657
+ var ArgumentNullError = class extends Error {
658
+ constructor(parameterName, parameterValue) {
659
+ super(`${parameterName} has null value: ${parameterValue}`);
660
+ this.name = "ArgumentNullError";
661
+ }
662
+ };
663
+
664
+ // src/types/models.ts
665
+ init_define_process();
666
+ function encodeGnip({ gameId, networkId, instanceId, playerId }) {
667
+ return [gameId, networkId, instanceId, playerId].join("-");
668
+ }
669
+
670
+ // src/utils.ts
671
+ init_define_process();
672
+ var startTimer = (function_, time) => {
673
+ const id = setTimeout(function_, time);
674
+ return () => clearTimeout(id);
675
+ };
676
+ var timeout = (function_, time) => (a) => {
677
+ return new Promise((resolve, reject) => {
678
+ const stopTimer = startTimer(() => {
679
+ reject(new Error(`Timeout has exceeded ${time}`));
680
+ }, time);
681
+ function_(a).then((value) => {
682
+ resolve(value);
683
+ stopTimer();
684
+ }).catch(reject);
685
+ });
686
+ };
687
+ var validateForNull = (properties) => {
688
+ for (const key of Object.keys(properties)) {
689
+ const value = properties[key];
690
+ if (value === void 0 || value === null || Number.isNaN(value)) {
691
+ throw new ArgumentNullError(key, value);
692
+ }
693
+ }
694
+ };
695
+ function msToSec(value) {
696
+ return Math.floor(value / 1e3);
697
+ }
698
+ var parentDomain = (referrer) => {
699
+ const matches = referrer.match(/^https?:\/\/([^#/?]+)(?:[#/?]|$)/i);
700
+ if (!matches || !matches[1]) {
701
+ return;
702
+ }
703
+ const result = matches[1].match(/[^.]+\.[^.]+$/);
704
+ if (!result) {
705
+ return;
706
+ }
707
+ return result[0];
708
+ };
709
+
710
+ // src/helpers.ts
711
+ var detectPlatform = (defaultPlatform = "stillpay") => {
712
+ const nativePlatform = navigator.userAgent.match(
713
+ /(itunes)|(googleplay)|(Android)|(amazonmobile)|(facebook)|(samsung)|(huawei)/g
714
+ );
715
+ if (!nativePlatform) return defaultPlatform;
716
+ const activePlatform = nativePlatform[0];
717
+ const distribPlatforms = {
718
+ itunes: "apple",
719
+ Android: "google",
720
+ googleplay: "google",
721
+ amazonmobile: "amazon",
722
+ facebook: "facebook",
723
+ samsung: "samsung",
724
+ huawei: "huawei"
725
+ };
726
+ return Object.prototype.hasOwnProperty.call(distribPlatforms, activePlatform) ? distribPlatforms[activePlatform] : defaultPlatform;
727
+ };
728
+ function formatQueryString(object) {
729
+ return Object.entries(object).filter(([key, value]) => value !== null && value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&");
730
+ }
731
+ var getTokenAndLanguage = (store) => {
732
+ const { playerId, token, zoneId, language } = store;
733
+ if (!playerId) {
734
+ throw new ArgumentNullError("playerId", playerId);
735
+ }
736
+ return {
737
+ token,
738
+ zoneId,
739
+ locale: language,
740
+ ping: encodeGnip({ ...store, playerId })
741
+ };
742
+ };
743
+ var loadScript = (src) => new Promise((resolve, reject) => {
744
+ const script = document.createElement("script");
745
+ script.type = "text/javascript";
746
+ script.type = "module";
747
+ script.async = true;
748
+ script.src = src;
749
+ script.addEventListener("load", resolve);
750
+ script.addEventListener("error", reject);
751
+ document.body.append(script);
752
+ });
753
+ var tryCatch = (fn) => (...args) => {
754
+ try {
755
+ return fn(...args);
756
+ } catch (error) {
757
+ logError(error);
758
+ throwCxfError(error);
759
+ }
760
+ };
761
+ var throwCxfError = (e) => {
762
+ const config = globalState.getConfig();
763
+ const cxf = globalState.getCxf();
764
+ cxf.emit(config.CXF_ERROR, e);
765
+ };
766
+ var loadCxf = timeout(() => require_dist(), 1e4);
767
+ var logger = (0, import_debug.default)("CXF-WEBSHOP");
768
+ var log = (argument0, ...rest) => logger(argument0, ...rest);
769
+ var logError = (...arguments_) => (
770
+ // tslint:disable-next-line:no-console
771
+ console.error("%c CXF-WEBSHOP ->", "background: #ff0000; color: #fff", ...arguments_)
772
+ );
773
+ var createSessionId = () => v4();
774
+ var getDomain = (referrer) => {
775
+ return parentDomain(referrer);
776
+ };
777
+ var ggsGetQueryParams = () => {
778
+ return ggsGetQueryParameters();
779
+ };
780
+ var ggsGetReferrerValue = () => {
781
+ return ggsGetReferrer();
782
+ };
783
+ var transformPaymentContractIdsToNativePriceEvent = (ids) => (
784
+ // eslint-disable-next-line unicorn/no-array-reduce
785
+ ids.reduce(
786
+ (prev, cur, idx) => {
787
+ prev.offers.push({
788
+ id: cur,
789
+ tier: 0,
790
+ productIds: {
791
+ googleplay: cur
792
+ }
793
+ });
794
+ return prev;
795
+ },
796
+ {
797
+ category: "all",
798
+ offers: [],
799
+ eventName: "lemonstand.nativePrice",
800
+ eventType: "bubble"
801
+ }
802
+ )
803
+ );
804
+
805
+ // src/store.ts
806
+ init_define_process();
807
+ function initializeStore(cxf) {
808
+ return {
809
+ isCanvas: false,
810
+ playerId: cxf.playerId,
811
+ instanceId: cxf.instanceId,
812
+ networkId: cxf.networkId,
813
+ gameId: cxf.gameId,
814
+ gameApi: cxf.gameApi,
815
+ language: cxf.language,
816
+ token: cxf.token,
817
+ zoneId: cxf.zoneId,
818
+ gameEvents: [],
819
+ xp: 0,
820
+ level: 0,
821
+ legendLevel: void 0,
822
+ countryCode: "",
823
+ lastPurchaseTab: "",
824
+ subscriptionDisabled: false,
825
+ isTempServer: false,
826
+ customizationSuffix: "",
827
+ resolvedCustomizationUrl: "",
828
+ sourceId: "unknown",
829
+ unreadOfferNotifsCountUrl: ""
830
+ };
831
+ }
832
+ function criteriaSelector({ legendLevel, level }) {
833
+ return {
834
+ legendLevel,
835
+ level
836
+ };
837
+ }
838
+
839
+ // src/fetch.ts
840
+ var fetchUnreadOfferNotificationsCount = async () => {
841
+ const config = globalState.getConfig();
842
+ const store = globalState.getStore();
843
+ if (config.LEGEND_LEVEL_IS_USED && store.legendLevel === void 0) {
844
+ log("Skip fetchUnreadOfferNotificationsCount due to legendLevel is undefined");
845
+ return;
846
+ }
847
+ if (!store.isCanvas && store.token && store.unreadOfferNotifsCountUrl) {
848
+ log("fetchUnreadOfferNotificationsCount");
849
+ let unreadCount = 0;
850
+ const headers = {
851
+ Authorization: `Bearer ${store.token}`
852
+ };
853
+ const url = store.unreadOfferNotifsCountUrl.replace("{locale}", store.language || "").replace("{zoneId}", store.zoneId || "").replace("{criteria}", encodeURIComponent(JSON.stringify(criteriaSelector(store))));
854
+ try {
855
+ log("fetch", url);
856
+ const resp = await fetch(url, {
857
+ headers
858
+ });
859
+ if (resp.ok) {
860
+ const data = await resp.json();
861
+ unreadCount = Number(data?.notifCount);
862
+ }
863
+ } catch (error) {
864
+ logError(`cannot fetch ${url}`, error);
865
+ }
866
+ log("setUnseenOffersCounter", unreadCount);
867
+ store.gameApi.invokeFn("setUnseenOffersCounter", unreadCount).catch((error) => {
868
+ logError("setUnseenOffersCounter error:", error);
869
+ });
870
+ }
871
+ };
872
+
873
+ // src/messages/ShopMessageBus.ts
874
+ init_define_process();
875
+ var ShopMessageBus = class {
876
+ post(message) {
877
+ const element = document.querySelector("#dialog");
878
+ if (element && element.tagName.toLocaleLowerCase() === "iframe") {
879
+ element.contentWindow?.postMessage(message, "*");
880
+ }
881
+ }
882
+ };
883
+
884
+ // src/preFetch.ts
885
+ init_define_process();
886
+
887
+ // src/url.ts
888
+ init_define_process();
889
+ var import_game_alias = __toESM(require_dist2());
890
+ var createIframeUrl = ({ page, route, sid, config: igsConfig = {} }) => {
891
+ const config = globalState.getConfig();
892
+ const store = globalState.getStore();
893
+ const { token, zoneId, locale } = getTokenAndLanguage(store);
894
+ const parameters = {
895
+ token,
896
+ zoneId,
897
+ locale,
898
+ sid: sid || createSessionId()
899
+ };
900
+ if (Object.keys(igsConfig).length > 0) {
901
+ parameters.config = JSON.stringify(igsConfig);
902
+ }
903
+ validateForNull(parameters);
904
+ const urlParameters = new URLSearchParams(ggsGetQueryParams());
905
+ const queryParameters = {
906
+ ...parameters,
907
+ "lemonstand.customization.url": store.resolvedCustomizationUrl || createCustomizationUrl(),
908
+ domain: getDomain(ggsGetReferrerValue()),
909
+ websiteId: urlParameters.get("w"),
910
+ criteria: JSON.stringify(criteriaSelector(store)),
911
+ level: store.level
912
+ };
913
+ const network = urlParameters.get("network");
914
+ if (urlParameters.get("usekeybaselogin") === "false" && Number(network) > 0) {
915
+ queryParameters.network = network;
916
+ }
917
+ if (store.adStatus?.areBannersAvailable) {
918
+ queryParameters.ads = true;
919
+ }
920
+ return `${config.BASE_URL}/?${formatQueryString(queryParameters)}${page ? `#${page}` : ""}${route ? `--${route}--${Date.now()}` : ""}`;
921
+ };
922
+ var createCustomizationUrl = () => {
923
+ const config = globalState.getConfig();
924
+ const store = globalState.getStore();
925
+ const cxf = globalState.getCxf();
926
+ const configBase = (0, import_game_alias.acronym)(store.gameId);
927
+ const configVariance = store.customizationSuffix ? `-${store.customizationSuffix}` : "";
928
+ const configBranch = `${configBase}${configVariance}`;
929
+ if (cxf.env === "test") {
930
+ const configVersion = new URLSearchParams(window.location.search).get("configGGS");
931
+ if (configVersion !== null) {
932
+ return config.CUSTOMIZATION_URL_TEMPLATE.replace("{0}", configBranch).replace("{1}", configVersion);
933
+ }
934
+ }
935
+ return config.CUSTOMIZATION_URL.replace("{0}", configBranch);
936
+ };
937
+
938
+ // src/preFetch.ts
939
+ var preResolveConfig = () => {
940
+ if (typeof fetch !== "function") {
941
+ return;
942
+ }
943
+ const originalCustomUrl = createCustomizationUrl();
944
+ let resolvedUrl = "";
945
+ fetch(originalCustomUrl).then((resp) => {
946
+ const currentCustomUrl = createCustomizationUrl();
947
+ if (currentCustomUrl === originalCustomUrl) {
948
+ resolvedUrl = resp.url;
949
+ log("parsed customization url is " + resolvedUrl);
950
+ globalState.updateStore({
951
+ resolvedCustomizationUrl: resolvedUrl
952
+ });
953
+ return resp.json();
954
+ }
955
+ }).then((config) => {
956
+ if (config) {
957
+ globalState.updateStore({
958
+ unreadOfferNotifsCountUrl: config.unreadOfferNotifsCountUrl || ""
959
+ });
960
+ }
961
+ });
962
+ };
963
+
964
+ // src/types/store.ts
965
+ init_define_process();
966
+ var entityProvider = (initial) => {
967
+ let element = initial;
968
+ return {
969
+ get: () => element,
970
+ set: (value) => {
971
+ element = value;
972
+ }
973
+ };
974
+ };
975
+
976
+ // src/globalState.ts
977
+ var GlobalState = class {
978
+ constructor() {
979
+ this.config = void 0;
980
+ this.cxfProvider = entityProvider();
981
+ this.dialogProvider = entityProvider();
982
+ this.storeProvider = entityProvider();
983
+ this.shopMessageBus = new ShopMessageBus();
984
+ this.fetchUnreadOfferNotificationsCount = fetchUnreadOfferNotificationsCount;
985
+ this.preResolveConfig = preResolveConfig;
986
+ }
987
+ setConfig(config) {
988
+ this.config = config;
989
+ }
990
+ getConfig() {
991
+ if (this.config === void 0) {
992
+ throw new Error("Config is not initialized");
993
+ }
994
+ return this.config;
995
+ }
996
+ setCxf(cxf) {
997
+ this.cxfProvider.set(cxf);
998
+ }
999
+ getCxf() {
1000
+ const cxf = this.cxfProvider.get();
1001
+ if (!cxf) {
1002
+ throw new Error("CXF is not loaded");
1003
+ }
1004
+ return cxf;
1005
+ }
1006
+ setStore(store) {
1007
+ this.storeProvider.set(store);
1008
+ }
1009
+ getStore() {
1010
+ const store = this.storeProvider.get();
1011
+ if (!store) {
1012
+ throw new Error("Store is not initialized");
1013
+ }
1014
+ return store;
1015
+ }
1016
+ updateStore(data) {
1017
+ const currentStore = this.getStore();
1018
+ this.setStore({
1019
+ ...currentStore,
1020
+ ...data
1021
+ });
1022
+ }
1023
+ };
1024
+ var globalState = new GlobalState();
1025
+
1026
+ // src/handlers/cxfEventHandlers.ts
1027
+ init_define_process();
1028
+ var import_cxf_events = __toESM(require_typings());
1029
+
1030
+ // src/dialog.ts
1031
+ init_define_process();
1032
+ var createDialog = (url) => {
1033
+ const config = globalState.getConfig();
1034
+ const cxf = globalState.getCxf();
1035
+ cxf.emit(config.CXF_DIALOG_OPEN, url);
1036
+ };
1037
+
1038
+ // src/track.ts
1039
+ init_define_process();
1040
+ var trackOpenAction = (sid) => {
1041
+ const config = globalState.getConfig();
1042
+ const store = globalState.getStore();
1043
+ const now = Date.now();
1044
+ const parameters = getTokenAndLanguage(store);
1045
+ const { zoneId } = parameters;
1046
+ const sessionId = sid;
1047
+ const { playerId, gameId, networkId, instanceId, sourceId } = store;
1048
+ trackAction({
1049
+ eventId: config.WEB_SHOP_CALL_TRACK_ID,
1050
+ date: msToSec(now),
1051
+ unixtimeMS: now,
1052
+ sessionId,
1053
+ zoneId: zoneId ? Number.parseInt(zoneId, 10) : void 0,
1054
+ playerId: Number.parseInt(playerId, 10),
1055
+ gameId: Number.parseInt(gameId, 10),
1056
+ networkId: Number.parseInt(networkId, 10),
1057
+ instanceId: Number.parseInt(instanceId, 10),
1058
+ sourceId
1059
+ });
1060
+ };
1061
+ var trackAction = (payload) => {
1062
+ const config = globalState.getConfig();
1063
+ const cxf = globalState.getCxf();
1064
+ cxf.emit(config.CXF_TRACK_MSG, payload);
1065
+ };
1066
+
1067
+ // src/types/index.ts
1068
+ init_define_process();
1069
+
1070
+ // src/types/config.ts
1071
+ init_define_process();
1072
+
1073
+ // src/whitelist.ts
1074
+ init_define_process();
1075
+ var whitelistedZones = /* @__PURE__ */ new Set([
1076
+ // 264, Poland
1077
+ 316,
1078
+ 318,
1079
+ 460,
1080
+ 461,
1081
+ 767,
1082
+ 768,
1083
+ 802,
1084
+ 814,
1085
+ 830,
1086
+ 877
1087
+ ]);
1088
+
1089
+ // src/handlers/pushHandlers.ts
1090
+ init_define_process();
1091
+ var onReward = (payload) => {
1092
+ log("OnReward: payload", payload);
1093
+ const { isCanvas } = globalState.getStore();
1094
+ if (isCanvas) {
1095
+ window.CanvasAgent?.instance?.hide();
1096
+ window.CanvasAgent?.instance?.navigate();
1097
+ return;
1098
+ }
1099
+ const url = createIframeUrl({
1100
+ route: encodeURIComponent(payload.successUrl),
1101
+ ...payload
1102
+ });
1103
+ globalState.updateStore({
1104
+ lastPurchaseTab: payload.page,
1105
+ sourceId: "successfulPayoutReward"
1106
+ });
1107
+ trackOpenAction(payload.sid);
1108
+ createDialog(url);
1109
+ };
1110
+ var onLemonstandCategoryUpdate = ({ target, action, data }) => {
1111
+ globalState.shopMessageBus.post({
1112
+ eventName: "lemonstand.category.update" /* LEMONSTAND_CATEGORY_UPDATE */,
1113
+ target,
1114
+ data: { action, data }
1115
+ });
1116
+ };
1117
+ var onLemonstandNotificationsCreated = ({ notifCount }) => {
1118
+ log("onLemonstandNotificationsCreated -> notifCount:", notifCount);
1119
+ const store = globalState.getStore();
1120
+ if (notifCount > 0) {
1121
+ const randomDelayMs = Math.floor(Math.random() * (Number(store.networkId) < 250 ? 12e4 : 15e3));
1122
+ setTimeout(() => {
1123
+ fetchUnreadOfferNotificationsCount();
1124
+ }, randomDelayMs);
1125
+ } else {
1126
+ store.gameApi.invokeFn("setUnseenOffersCounter", 0).catch((error) => {
1127
+ logError("setUnseenOffersCounter error:", error);
1128
+ });
1129
+ }
1130
+ };
1131
+ var createPushHandlers = () => {
1132
+ return {
1133
+ reward: onReward,
1134
+ reward_received: onReward,
1135
+ ["lemonstand.category.update" /* LEMONSTAND_CATEGORY_UPDATE */]: onLemonstandCategoryUpdate,
1136
+ ["lemonstand.notifs.created" /* LEMONSTAND_NOTIFICATIONS_CREATED */]: onLemonstandNotificationsCreated
1137
+ };
1138
+ };
1139
+
1140
+ // src/handlers/cxfEventHandlers.ts
1141
+ var isWindowMessageListenerAttached = false;
1142
+ var eventListener = (event) => {
1143
+ log(`Canvas event "${event.eventType}" received:`, event);
1144
+ switch (event.eventType) {
1145
+ case "native_catalog_request" /* NATIVE_CATALOG_REQUEST */: {
1146
+ if (event?.paymentContractIds?.length > 0) {
1147
+ if (!isWindowMessageListenerAttached) {
1148
+ window.addEventListener("message", ({ data }) => {
1149
+ if (data?.eventName === "lemonstand.category.update" /* LEMONSTAND_CATEGORY_UPDATE */ && data?.data?.action === "nativePriceUpdate") {
1150
+ log(`${"lemonstand.category.update" /* LEMONSTAND_CATEGORY_UPDATE */} event`, data.data);
1151
+ if (!data.data.data) return;
1152
+ const nativeCatalog = {};
1153
+ for (const key in data.data.data) {
1154
+ const { priceString, ...rest } = data.data.data[key];
1155
+ nativeCatalog[key] = rest;
1156
+ }
1157
+ log("nativeCatalog:", nativeCatalog);
1158
+ window.CanvasAgent?.instance?.setNativeCatalog(nativeCatalog);
1159
+ }
1160
+ });
1161
+ isWindowMessageListenerAttached = true;
1162
+ }
1163
+ const msg = transformPaymentContractIdsToNativePriceEvent(event.paymentContractIds);
1164
+ window.postMessage(msg, "*");
1165
+ log("Event `lemonstand.nativePrice` sent");
1166
+ }
1167
+ break;
1168
+ }
1169
+ case "native_checkout_request" /* NATIVE_CHECKOUT_REQUEST */: {
1170
+ const { paymentContract, sessionId, collectionAlias, offerId } = event;
1171
+ const { zoneId } = globalState.getStore();
1172
+ window.postMessage(
1173
+ {
1174
+ eventName: "lemonstand.nativePay",
1175
+ eventType: "bubble",
1176
+ nativePayInfo: {
1177
+ pkg: {
1178
+ price: paymentContract?.price?.amount,
1179
+ productIdMS: "",
1180
+ productIds: { googleplay: paymentContract?.id },
1181
+ tier: Number(paymentContract?.id?.split("_")?.at(-1))
1182
+ },
1183
+ // !sid || !type || !zoneId || !offerId || !successUrl || !criteria
1184
+ meta: {
1185
+ criteria: JSON.stringify({}),
1186
+ lemonstand: true,
1187
+ offerId,
1188
+ sid: sessionId,
1189
+ type: collectionAlias,
1190
+ zoneId,
1191
+ successUrl: window.location.href
1192
+ }
1193
+ }
1194
+ },
1195
+ "*"
1196
+ );
1197
+ log("Event `lemonstand.nativePay` sent");
1198
+ break;
1199
+ }
1200
+ default: {
1201
+ break;
1202
+ }
1203
+ }
1204
+ };
1205
+ var onOpen = (payload = {}) => {
1206
+ log(import_cxf_events.CxfEvents.OpenIGS, "payload:", payload);
1207
+ if (payload.sourceId) {
1208
+ globalState.updateStore({
1209
+ sourceId: payload.sourceId
1210
+ });
1211
+ }
1212
+ const { isCanvas, lastPurchaseTab, gameApi } = globalState.getStore();
1213
+ if (isCanvas) {
1214
+ if (payload.page) {
1215
+ window.CanvasAgent?.instance?.navigate(payload.page);
1216
+ }
1217
+ window.CanvasAgent?.instance?.show();
1218
+ return;
1219
+ }
1220
+ const sid = createSessionId();
1221
+ trackOpenAction(sid);
1222
+ const url = createIframeUrl({
1223
+ sid,
1224
+ page: lastPurchaseTab,
1225
+ ...payload
1226
+ });
1227
+ createDialog(url);
1228
+ setTimeout(() => {
1229
+ gameApi.invokeFn("setUnseenOffersCounter", 0);
1230
+ }, 1e3);
1231
+ };
1232
+ var subscribeToCommonCxfEvents = (cxf) => {
1233
+ const pushHandlers = createPushHandlers();
1234
+ cxf.on(import_cxf_events.CxfEvents.OpenIGS, tryCatch(onOpen));
1235
+ cxf.on(
1236
+ import_cxf_events.CxfEvents.Push,
1237
+ tryCatch(({ id, payload }) => {
1238
+ log(import_cxf_events.CxfEvents.Push, id, payload);
1239
+ const handler = pushHandlers[id];
1240
+ handler && handler(payload);
1241
+ })
1242
+ );
1243
+ };
1244
+ var subscribeToGameEvents = (cxf) => {
1245
+ cxf.on(import_cxf_events.CxfEvents.Login, (e) => {
1246
+ const { gameEvents: eventsInLogin, language, token, zoneId } = e;
1247
+ if (whitelistedZones.has(Number(zoneId)) && (Number(zoneId) > 300 || localStorage.getItem("cxf_canvas") === "enabled")) {
1248
+ globalState.updateStore({
1249
+ isCanvas: true
1250
+ });
1251
+ }
1252
+ const { gameEvents, isCanvas } = globalState.getStore();
1253
+ const eventNotExistPredicateGenerator = (existingEvents) => (event) => !existingEvents.map((event_) => event_.type).includes(event.type);
1254
+ globalState.updateStore({
1255
+ ...e,
1256
+ gameEvents: [...gameEvents.filter(eventNotExistPredicateGenerator(eventsInLogin)), ...eventsInLogin]
1257
+ });
1258
+ log(import_cxf_events.CxfEvents.Login, globalState.getStore());
1259
+ if (!isCanvas) {
1260
+ globalState.fetchUnreadOfferNotificationsCount();
1261
+ return;
1262
+ }
1263
+ if (typeof window.CanvasAgent?.create === "function") {
1264
+ const { CANVAS_APP_ID_BY_GAME } = globalState.getConfig();
1265
+ const platform = detectPlatform();
1266
+ const canvasApps = CANVAS_APP_ID_BY_GAME[cxf.gameId];
1267
+ const canvasAppId = typeof canvasApps === "string" ? canvasApps : canvasApps?.[platform];
1268
+ window.CanvasAgent.create({
1269
+ authClientId: "lemonstand",
1270
+ canvasAppId,
1271
+ eventListener,
1272
+ locale: language,
1273
+ token
1274
+ }).then((res) => {
1275
+ window.CanvasAgent.instance = res;
1276
+ log(import_cxf_events.CxfEvents.Login, "Canvas created");
1277
+ }).catch((error) => {
1278
+ logError("Cannot create instance of Canvas", error);
1279
+ });
1280
+ }
1281
+ });
1282
+ cxf.on(import_cxf_events.CxfEvents.GameEventUpdate, (e) => {
1283
+ log(import_cxf_events.CxfEvents.GameEventUpdate, e);
1284
+ const { gameEvents, isCanvas } = globalState.getStore();
1285
+ const updatedEventTypes = new Set(e.map((event) => event.type));
1286
+ globalState.updateStore({
1287
+ gameEvents: [...gameEvents.filter((event) => !updatedEventTypes.has(event.type)), ...e]
1288
+ });
1289
+ if (isCanvas) {
1290
+ window.CanvasAgent?.instance?.refresh();
1291
+ }
1292
+ log(import_cxf_events.CxfEvents.GameEventUpdate, "reducer", globalState.getStore());
1293
+ });
1294
+ cxf.on(import_cxf_events.CxfEvents.GameEventAdd, (e) => {
1295
+ log(import_cxf_events.CxfEvents.GameEventAdd, e);
1296
+ const { gameEvents, isCanvas } = globalState.getStore();
1297
+ globalState.updateStore({
1298
+ gameEvents: [...gameEvents, e]
1299
+ });
1300
+ if (isCanvas) {
1301
+ window.CanvasAgent?.instance?.refresh();
1302
+ }
1303
+ log(import_cxf_events.CxfEvents.GameEventAdd, "reducer", globalState.getStore());
1304
+ });
1305
+ cxf.on(import_cxf_events.CxfEvents.GameEventRemove, (e) => {
1306
+ log(import_cxf_events.CxfEvents.GameEventRemove, e);
1307
+ const { gameEvents, isCanvas } = globalState.getStore();
1308
+ globalState.updateStore({
1309
+ gameEvents: gameEvents.filter(({ type }) => type !== e)
1310
+ });
1311
+ if (isCanvas) {
1312
+ window.CanvasAgent?.instance?.refresh();
1313
+ }
1314
+ log(import_cxf_events.CxfEvents.GameEventRemove, "reducer", globalState.getStore());
1315
+ });
1316
+ cxf.on(import_cxf_events.CxfEvents.LevelChanged, (level) => {
1317
+ log(import_cxf_events.CxfEvents.LevelChanged, level);
1318
+ const { isCanvas } = globalState.getStore();
1319
+ globalState.updateStore({
1320
+ level
1321
+ });
1322
+ log(import_cxf_events.CxfEvents.LevelChanged, "reducer", globalState.getStore());
1323
+ if (isCanvas) {
1324
+ window.CanvasAgent?.instance?.refresh();
1325
+ } else {
1326
+ globalState.fetchUnreadOfferNotificationsCount();
1327
+ }
1328
+ });
1329
+ cxf.on(import_cxf_events.CxfEvents.LegendLevelChanged, (legendLevel) => {
1330
+ log(import_cxf_events.CxfEvents.LegendLevelChanged, `legendLevel: ${legendLevel}`);
1331
+ globalState.updateStore({
1332
+ legendLevel
1333
+ });
1334
+ const store = globalState.getStore();
1335
+ log(import_cxf_events.CxfEvents.LegendLevelChanged, "reducer", store);
1336
+ globalState.fetchUnreadOfferNotificationsCount();
1337
+ });
1338
+ };
1339
+ var subscribeToNativeSubscriptionEnable = (cxf) => {
1340
+ cxf.on("cxf.native.subscription.enable" /* CXF_NATIVE_SUBSCRIPTION_ENABLE */, (enabled) => {
1341
+ globalState.updateStore({
1342
+ subscriptionDisabled: enabled === 0,
1343
+ customizationSuffix: enabled === 0 ? "no-subscription" : ""
1344
+ });
1345
+ globalState.preResolveConfig();
1346
+ });
1347
+ };
1348
+ var subscribeToCustomizationSuffix = (cxf) => {
1349
+ cxf.on("cxf.set.customization.surfix" /* CXF_SET_CUSTOMIZATION_SUFFIX */, (suffix) => {
1350
+ const { customizationSuffix } = globalState.getStore();
1351
+ if (suffix === customizationSuffix) {
1352
+ return;
1353
+ }
1354
+ globalState.updateStore({
1355
+ customizationSuffix: suffix || ""
1356
+ });
1357
+ globalState.preResolveConfig();
1358
+ });
1359
+ };
1360
+ var subscribeToAdStatus = (cxf) => {
1361
+ const config = globalState.getConfig();
1362
+ cxf.on(config.CXF_AD_STATUS, ({ areBannersAvailable, bannersDetails }) => {
1363
+ globalState.updateStore({
1364
+ adStatus: {
1365
+ areBannersAvailable,
1366
+ bannersDetails
1367
+ }
1368
+ });
1369
+ });
1370
+ };
1371
+ var subscribeToTempServerContext = (cxf) => {
1372
+ cxf.on("cxf.join.temp.server" /* CXF_JOIN_TEMP_SERVER */, (isTemp) => {
1373
+ const store = globalState.getStore();
1374
+ globalState.updateStore({
1375
+ isTempServer: Boolean(isTemp)
1376
+ });
1377
+ if (store.customizationSuffix === "" || store.customizationSuffix === "temp") {
1378
+ globalState.updateStore({
1379
+ customizationSuffix: isTemp ? "temp" : ""
1380
+ });
1381
+ globalState.preResolveConfig();
1382
+ }
1383
+ });
1384
+ };
1385
+ var createCxfEventHandlers = () => {
1386
+ return [
1387
+ subscribeToCommonCxfEvents,
1388
+ subscribeToGameEvents,
1389
+ subscribeToAdStatus,
1390
+ subscribeToTempServerContext,
1391
+ subscribeToNativeSubscriptionEnable,
1392
+ subscribeToCustomizationSuffix
1393
+ ];
1394
+ };
1395
+
1396
+ // src/handlers/postMessageHandlers.ts
1397
+ init_define_process();
1398
+ var onSalesPageOpen = () => {
1399
+ log("OnOpenSalesOffersPage");
1400
+ const { isCanvas } = globalState.getStore();
1401
+ if (isCanvas) {
1402
+ window.CanvasAgent?.instance?.navigate("supersale");
1403
+ return;
1404
+ }
1405
+ const sid = createSessionId();
1406
+ const url = createIframeUrl({
1407
+ page: "sale-offers",
1408
+ sid
1409
+ });
1410
+ createDialog(url);
1411
+ };
1412
+ var onLemonstandClose = () => {
1413
+ const store = globalState.getStore();
1414
+ log("onLemonstandClose", store);
1415
+ fetchUnreadOfferNotificationsCount();
1416
+ };
1417
+ var createPostMessageHandlers = () => {
1418
+ return {
1419
+ ["cxf.webshop.sales.open" /* CXF_OPEN_SALES_MSG */]: onSalesPageOpen,
1420
+ ["cxf.dialog.close" /* CXF_DIALOG_CLOSE */]: onLemonstandClose
1421
+ };
1422
+ };
1423
+
1424
+ // src/app.ts
1425
+ var app = (cxf) => {
1426
+ const postMessageHandlers = createPostMessageHandlers();
1427
+ const subscribeCxf = createCxfEventHandlers();
1428
+ window.addEventListener(
1429
+ "message",
1430
+ tryCatch(({ data }) => {
1431
+ if (data) {
1432
+ const handler = postMessageHandlers[data.name];
1433
+ if (handler) {
1434
+ log("POST MESSAGE", data);
1435
+ handler(data.payload);
1436
+ }
1437
+ }
1438
+ })
1439
+ );
1440
+ for (const handler of subscribeCxf) {
1441
+ handler(cxf);
1442
+ }
1443
+ globalState.preResolveConfig();
1444
+ log("App has started");
1445
+ };
1446
+
1447
+ // src/config.ts
1448
+ init_define_process();
1449
+ var import_cxf_events2 = __toESM(require_typings());
1450
+ var COMMON_CONFIG = {
1451
+ CANVAS_AGENT_URL: define_process_default.env.CANVAS_AGENT_URL,
1452
+ CANVAS_APP_ID_BY_GAME: define_process_default.env.CANVAS_APP_ID_BY_GAME,
1453
+ CUSTOMIZATION_URL: define_process_default.env.CUSTOMIZATION_URL,
1454
+ CUSTOMIZATION_URL_TEMPLATE: define_process_default.env.CUSTOMIZATION_URL_TEMPLATE,
1455
+ BASE_URL: define_process_default.env.BASE_URL,
1456
+ CXF_DIALOG_OPEN: "cxf.dialog.open",
1457
+ CXF_DIALOG_CLOSE: "cxf.dialog.close",
1458
+ CXF_TRACK_MSG: "cxf.tracking.message",
1459
+ CXF_BTN_CLICK_MSG: import_cxf_events2.CxfEvents.OpenIGS,
1460
+ CXF_OPEN_SALES_MSG: "cxf.webshop.sales.open" /* CXF_OPEN_SALES_MSG */,
1461
+ WEB_SHOP_CALL_TRACK_ID: 1181,
1462
+ CXF_ERROR: "cxf.error",
1463
+ CXF_PUSH: "cxf.push",
1464
+ CXF_AD_STATUS: "cxf.adBanner.status"
1465
+ };
1466
+ var GAME_SPECIFIC_CONFIG = {
1467
+ 12: {
1468
+ LEGEND_LEVEL_IS_USED: true
1469
+ },
1470
+ 15: {
1471
+ LEGEND_LEVEL_IS_USED: false
1472
+ },
1473
+ 16: {
1474
+ LEGEND_LEVEL_IS_USED: true
1475
+ }
1476
+ };
1477
+ var createConfig = (gameId) => {
1478
+ return {
1479
+ ...COMMON_CONFIG,
1480
+ ...GAME_SPECIFIC_CONFIG[gameId]
1481
+ };
1482
+ };
1483
+
1484
+ // src/index.ts
1485
+ require_dist().then((cxf) => {
1486
+ const config = createConfig(cxf.gameId);
1487
+ globalState.setConfig(config);
1488
+ globalState.setCxf(cxf);
1489
+ const store = initializeStore(cxf);
1490
+ globalState.setStore(store);
1491
+ loadScript(config.CANVAS_AGENT_URL).then(() => {
1492
+ log(`Canvas agent loaded: ${config.CANVAS_AGENT_URL}`);
1493
+ }).catch((error) => {
1494
+ logError("Canvas agent load error", error);
1495
+ });
1496
+ app(cxf);
1497
+ });
1498
+ })();
1499
+ //# sourceMappingURL=webshop-cxf.js.map