service-worker-staging.php
245 lines
| 1 | "use strict"; |
| 2 | |
| 3 | function _classCallCheck(t, e) { |
| 4 | if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function") |
| 5 | } |
| 6 | |
| 7 | function _defineProperties(t, e) { |
| 8 | for (var n = 0; n < e.length; n++) { |
| 9 | var i = e[n]; |
| 10 | i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(t, i.key, i) |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | function _createClass(t, e, n) { |
| 15 | return e && _defineProperties(t.prototype, e), n && _defineProperties(t, n), Object.defineProperty(t, "prototype", { |
| 16 | writable: !1 |
| 17 | }), t |
| 18 | } |
| 19 | self.PUSHOWL_SERVICE_WORKER_VERSION = "2.2"; |
| 20 | var ErrorHelper = function() { |
| 21 | var e = "https://sentry.io/api/1891871/store/?sentry_version=7&sentry_key=0df575aa94e3419782416c33a46d9dd7"; |
| 22 | |
| 23 | function i(t) { |
| 24 | (t = t || {}).poServiceWorkerVersion = self.PUSHOWL_SERVICE_WORKER_VERSION; |
| 25 | var e = (new Date).toISOString().split(".")[0]; |
| 26 | return { |
| 27 | event_id: "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, function(t) { |
| 28 | var e = 16 * Math.random() | 0; |
| 29 | return ("x" === t ? e : 3 & e | 8).toString(16) |
| 30 | }), |
| 31 | logger: "cdn-service-worker", |
| 32 | platform: "javascript", |
| 33 | timestamp: e, |
| 34 | extra: t, |
| 35 | release: "abc815b" |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | function r(t) { |
| 40 | return fetch(e, { |
| 41 | method: "post", |
| 42 | mode: "no-cors", |
| 43 | headers: { |
| 44 | "Content-Type": "application/json" |
| 45 | }, |
| 46 | body: JSON.stringify(t) |
| 47 | }) |
| 48 | } |
| 49 | |
| 50 | function a(t, e) { |
| 51 | (e = e || {}).errorDump = { |
| 52 | str: String(t), |
| 53 | stack: t && t.stack |
| 54 | }; |
| 55 | var n = i(e); |
| 56 | return n.exception = ((t = ((e = t).stack || "").split("\n").map(function(t) { |
| 57 | return t.trim() |
| 58 | }).filter(function(t) { |
| 59 | return t.startsWith("at") |
| 60 | }).map(function(t) { |
| 61 | var e = "", |
| 62 | n = 0, |
| 63 | i = 0, |
| 64 | r = "", |
| 65 | t = t.split(/[ ]+/); |
| 66 | return "at" === t[0].trim() && 1 < t.length && (1 < (t = (2 < t.length ? (e = t[1], t[2]) : t[1]).replace("(", "").replace(")", "").split(":")).length && (n = t[t.length - 1], i = t[t.length - 2], r = t.slice(0, t.length - 2).join(":"))), { |
| 67 | in_app: !0, |
| 68 | function: e, |
| 69 | colno: Number(n) || n, |
| 70 | lineno: Number(i) || i, |
| 71 | filename: r |
| 72 | } |
| 73 | })).reverse(), { |
| 74 | values: [{ |
| 75 | type: e.name || "Error", |
| 76 | value: e.message || String(e), |
| 77 | stacktrace: { |
| 78 | frames: t |
| 79 | } |
| 80 | }] |
| 81 | }), r(n) |
| 82 | } |
| 83 | return { |
| 84 | log: function(t, e) { |
| 85 | return (e = i(e)).message = t, r(e) |
| 86 | }, |
| 87 | logException: a, |
| 88 | withErrorReporting: function(t) { |
| 89 | return function(e) { |
| 90 | if (!e || !e.waitUntil) throw new Error("withErrorReporting should only be used for handlers that receive ExtendableEvent"); |
| 91 | try { |
| 92 | return t(e) |
| 93 | } catch (t) { |
| 94 | var n = a(t, { |
| 95 | eventData: e && e.data && e.data.json() |
| 96 | }); |
| 97 | e.waitUntil(n) |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | }(); |
| 103 | ! function() { |
| 104 | var e = console, |
| 105 | o = new(function() { |
| 106 | function e(t) { |
| 107 | t = t.maxNetworkRetries; |
| 108 | _classCallCheck(this, e), this.maxNetworkRetries = t |
| 109 | } |
| 110 | return _createClass(e, [{ |
| 111 | key: "payloadTransformation", |
| 112 | value: function(e) { |
| 113 | var t = e.title, |
| 114 | n = [], |
| 115 | i = e.actions; |
| 116 | if (i) |
| 117 | for (var r = 0; r < i.length; r++) { |
| 118 | var a = { |
| 119 | action: "action" + r, |
| 120 | title: i[r].title |
| 121 | }; |
| 122 | n.push(a) |
| 123 | } |
| 124 | var o = !("require_interaction" in e) || e.require_interaction, |
| 125 | c = { |
| 126 | body: e.description || "", |
| 127 | tag: e.tag || e.id, |
| 128 | actions: n, |
| 129 | requireInteraction: o, |
| 130 | data: e |
| 131 | }; |
| 132 | return ["icon", "badge", "image"].forEach(function(t) { |
| 133 | e[t] && (c[t] = e[t]) |
| 134 | }), { |
| 135 | title: t, |
| 136 | config: c |
| 137 | } |
| 138 | } |
| 139 | }, { |
| 140 | key: "processPush", |
| 141 | value: function(t) { |
| 142 | if (this.payload = t.data.json().data, !this.payload || "pushowl" !== this.payload.app) return Promise.resolve(); |
| 143 | var e = this.payloadTransformation(this.payload), |
| 144 | t = e.title, |
| 145 | e = e.config, |
| 146 | t = this.displayNotification(t, e), |
| 147 | e = this.payload.delivery_acknowledgement_url, |
| 148 | e = this.update(e); |
| 149 | return Promise.all([e, t]) |
| 150 | } |
| 151 | }, { |
| 152 | key: "displayNotification", |
| 153 | value: function(t, e) { |
| 154 | return self.registration.showNotification(t, e) |
| 155 | } |
| 156 | }, { |
| 157 | key: "update", |
| 158 | value: function(t) { |
| 159 | var r = this, |
| 160 | a = 1; |
| 161 | return new Promise(function(i, e) { |
| 162 | (function n() { |
| 163 | fetch(t, { |
| 164 | method: "POST", |
| 165 | headers: { |
| 166 | "Content-Type": "text/plain" |
| 167 | } |
| 168 | }).then(function(t) { |
| 169 | var e = Math.min(8e3, 1e3 * Math.pow(2, a)); |
| 170 | 429 === t.status && a++ <= r.maxNetworkRetries ? setTimeout(n, e) : i(t) |
| 171 | }).catch(function(t) { |
| 172 | return e(t) |
| 173 | }) |
| 174 | })() |
| 175 | }) |
| 176 | } |
| 177 | }, { |
| 178 | key: "openLink", |
| 179 | value: function(i) { |
| 180 | i && clients.matchAll({ |
| 181 | type: "window" |
| 182 | }).then(function(t) { |
| 183 | for (var e = 0; e < t.length; e++) { |
| 184 | var n = t[e]; |
| 185 | if (n.url === i && "focus" in n) return n.focus() |
| 186 | } |
| 187 | if (clients.openWindow) return clients.openWindow(i) |
| 188 | }) |
| 189 | } |
| 190 | }], [{ |
| 191 | key: "version", |
| 192 | get: function() { |
| 193 | return self.PUSHOWL_SERVICE_WORKER_VERSION |
| 194 | } |
| 195 | }]), e |
| 196 | }())({ |
| 197 | maxNetworkRetries: 5 |
| 198 | }); |
| 199 | self.addEventListener("install", function(t) { |
| 200 | t.waitUntil(self.skipWaiting()) |
| 201 | }), self.addEventListener("activate", function(t) { |
| 202 | t.waitUntil(self.clients.claim()) |
| 203 | }), self.addEventListener("push", ErrorHelper.withErrorReporting(function(t) { |
| 204 | if (self.Notification && "granted" === self.Notification.permission) { |
| 205 | if (!t.data) throw new Error("Empty event data."); |
| 206 | var e = o.processPush(t); |
| 207 | t.waitUntil(e) |
| 208 | } |
| 209 | })), self.addEventListener("notificationclick", function(n) { |
| 210 | var i, t, e = n.notification, |
| 211 | r = e.data; |
| 212 | try { |
| 213 | i = r.redirect_url, a = r.click_acknowledgement_url, t = "body", n.action && (n.action.includes("action0") ? (i = r.actions[0].redirect_url, t = "cta1") : n.action.includes("action1") && (i = r.actions[1].redirect_url, t = "cta2")) |
| 214 | } catch (t) { |
| 215 | ErrorHelper.logException(t, e ? { |
| 216 | notification: { |
| 217 | title: e.title, |
| 218 | data: e.data, |
| 219 | actions: e.actions |
| 220 | } |
| 221 | } : void 0) |
| 222 | } |
| 223 | e = new Promise(function(t, e) { |
| 224 | n.notification.close(), o.openLink(i), t() |
| 225 | }); |
| 226 | a += "&clicked_component=" + t; |
| 227 | var a = Promise.all([e, o.update(a)]); |
| 228 | n.waitUntil(a) |
| 229 | }), self.addEventListener("message", function(t) { |
| 230 | var e = o.payloadTransformation(t.data), |
| 231 | n = e.title, |
| 232 | e = e.config; |
| 233 | n && t.waitUntil(o.displayNotification(n, e)) |
| 234 | }), self.addEventListener("notificationclose", function(i) { |
| 235 | i.waitUntil(new Promise(function(t, e) { |
| 236 | var n = i.notification.data.close_acknowledgement_url; |
| 237 | o.update(n).then(function() { |
| 238 | t() |
| 239 | }).catch(function() {}) |
| 240 | })) |
| 241 | }), self.addEventListener("error", function(t) { |
| 242 | ErrorHelper.logException(t.error), e.error(t.filename, t.lineno, t.colno, t.message) |
| 243 | }) |
| 244 | }(); |
| 245 |