@stripchatdev/ext-helper 0.3.2 → 0.5.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.
@@ -1,19 +1,19 @@
1
- const O = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_pubsub" && "version" in e && e.version === "1.0", I = (e) => e, P = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
1
+ const U = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_pubsub" && "version" in e && e.version === "1.0", _ = (e) => e, B = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
2
2
  var m;
3
3
  (function(e) {
4
4
  e.Base32IncorrectEncoding = "B32_ENC_INVALID", e.DecodeTimeInvalidCharacter = "DEC_TIME_CHAR", e.DecodeTimeValueMalformed = "DEC_TIME_MALFORMED", e.EncodeTimeNegative = "ENC_TIME_NEG", e.EncodeTimeSizeExceeded = "ENC_TIME_SIZE_EXCEED", e.EncodeTimeValueMalformed = "ENC_TIME_MALFORMED", e.PRNGDetectFailure = "PRNG_DETECT", e.ULIDInvalid = "ULID_INVALID", e.Unexpected = "UNEXPECTED", e.UUIDInvalid = "UUID_INVALID";
5
5
  })(m || (m = {}));
6
- class y extends Error {
6
+ class b extends Error {
7
7
  constructor(t, r) {
8
8
  super(`${r} (${t})`), this.name = "ULIDError", this.code = t;
9
9
  }
10
10
  }
11
- function A(e) {
11
+ function J(e) {
12
12
  const t = Math.floor(e() * 32) % 32;
13
- return P.charAt(t);
13
+ return B.charAt(t);
14
14
  }
15
- function x(e) {
16
- const t = D(), r = t && (t.crypto || t.msCrypto) || null;
15
+ function K(e) {
16
+ const t = Z(), r = t && (t.crypto || t.msCrypto) || null;
17
17
  if (typeof (r == null ? void 0 : r.getRandomValues) == "function")
18
18
  return () => {
19
19
  const n = new Uint8Array(1);
@@ -21,39 +21,39 @@ function x(e) {
21
21
  };
22
22
  if (typeof (r == null ? void 0 : r.randomBytes) == "function")
23
23
  return () => r.randomBytes(1).readUInt8() / 255;
24
- throw new y(m.PRNGDetectFailure, "Failed to find a reliable PRNG");
24
+ throw new b(m.PRNGDetectFailure, "Failed to find a reliable PRNG");
25
25
  }
26
- function D() {
27
- return j() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
26
+ function Z() {
27
+ return ee() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
28
28
  }
29
- function C(e, t) {
29
+ function Q(e, t) {
30
30
  let r = "";
31
31
  for (; e > 0; e--)
32
- r = A(t) + r;
32
+ r = J(t) + r;
33
33
  return r;
34
34
  }
35
- function F(e, t = 10) {
35
+ function Y(e, t = 10) {
36
36
  if (isNaN(e))
37
- throw new y(m.EncodeTimeValueMalformed, `Time must be a number: ${e}`);
37
+ throw new b(m.EncodeTimeValueMalformed, `Time must be a number: ${e}`);
38
38
  if (e > 281474976710655)
39
- throw new y(m.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${281474976710655}: ${e}`);
39
+ throw new b(m.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${281474976710655}: ${e}`);
40
40
  if (e < 0)
41
- throw new y(m.EncodeTimeNegative, `Time must be positive: ${e}`);
41
+ throw new b(m.EncodeTimeNegative, `Time must be positive: ${e}`);
42
42
  if (Number.isInteger(e) === !1)
43
- throw new y(m.EncodeTimeValueMalformed, `Time must be an integer: ${e}`);
43
+ throw new b(m.EncodeTimeValueMalformed, `Time must be an integer: ${e}`);
44
44
  let r, n = "";
45
45
  for (let s = t; s > 0; s--)
46
- r = e % 32, n = P.charAt(r) + n, e = (e - r) / 32;
46
+ r = e % 32, n = B.charAt(r) + n, e = (e - r) / 32;
47
47
  return n;
48
48
  }
49
- function j() {
49
+ function ee() {
50
50
  return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
51
51
  }
52
- function E(e, t) {
53
- const r = t || x(), n = !e || isNaN(e) ? Date.now() : e;
54
- return F(n, 10) + C(16, r);
52
+ function w(e, t) {
53
+ const r = t || K(), n = !e || isNaN(e) ? Date.now() : e;
54
+ return Y(n, 10) + Q(16, r);
55
55
  }
56
- const G = ({ seq: e, uniqId: t }) => (r) => ({
56
+ const te = ({ seq: e, uniqId: t }) => (r) => ({
57
57
  ...{
58
58
  protocol: "platform_pubsub",
59
59
  version: "1.0",
@@ -62,24 +62,24 @@ const G = ({ seq: e, uniqId: t }) => (r) => ({
62
62
  timestamp: Date.now()
63
63
  },
64
64
  ...r
65
- }), v = G({
66
- uniqId: () => E(),
67
- seq: () => E()
65
+ }), O = te({
66
+ uniqId: () => w(),
67
+ seq: () => w()
68
68
  });
69
- class z {
69
+ class re {
70
70
  constructor(t) {
71
71
  this.eventHandlerMap = /* @__PURE__ */ new Map(), this.transportMessageHandler = (s) => {
72
72
  const { data: o, senderId: a } = s;
73
- if (O(o)) {
73
+ if (U(o)) {
74
74
  if (o.type === "event") {
75
75
  const { eventName: i } = o, c = this.eventHandlerMap.get(i);
76
76
  if (!c)
77
77
  return;
78
- c.forEach((l) => {
78
+ c.forEach((d) => {
79
79
  try {
80
- l(o.data, a);
81
- } catch (f) {
82
- console.error("[PubSubSubscriber] transportMessageHandler: failed to handle income message", f);
80
+ d(o.data, a);
81
+ } catch (u) {
82
+ console.error("[PubSubSubscriber] transportMessageHandler: failed to handle income message", u);
83
83
  }
84
84
  });
85
85
  return;
@@ -91,20 +91,20 @@ class z {
91
91
  this.brokerId = r, this.transport = n, this.transport.onMessage(this.transportMessageHandler);
92
92
  }
93
93
  subscribe(t, r) {
94
- const n = I(t);
94
+ const n = _(t);
95
95
  let s = this.eventHandlerMap.get(n);
96
96
  s || (s = /* @__PURE__ */ new Set(), this.eventHandlerMap.set(n, s)), s.add(r);
97
- const o = v({
97
+ const o = O({
98
98
  type: "subscribe",
99
99
  eventName: t
100
100
  });
101
101
  this.transport.send(this.brokerId, o);
102
102
  }
103
103
  unsubscribe(t, r) {
104
- const n = I(t);
104
+ const n = _(t);
105
105
  let s = this.eventHandlerMap.get(n);
106
106
  if (s && (r ? (s.delete(r), s.size || this.eventHandlerMap.delete(n)) : this.eventHandlerMap.delete(n), !this.eventHandlerMap.has(n))) {
107
- const o = v({
107
+ const o = O({
108
108
  type: "unsubscribe",
109
109
  eventName: t
110
110
  });
@@ -112,19 +112,19 @@ class z {
112
112
  }
113
113
  }
114
114
  }
115
- const B = !!Error.captureStackTrace, V = "APP_ERROR";
116
- class b extends Error {
115
+ const ne = !!Error.captureStackTrace, se = "APP_ERROR";
116
+ class M extends Error {
117
117
  constructor(t, r) {
118
- super(t), this.name = new.target.name || V, this.cause = r, B && Error.captureStackTrace(this, this.constructor);
118
+ super(t), this.name = new.target.name || se, this.cause = r, ne && Error.captureStackTrace(this, this.constructor);
119
119
  }
120
120
  static serializeCause(t) {
121
- return t instanceof b ? t.toJSON() : t instanceof Error ? { name: t.name, message: t.message } : t !== null && typeof t == "object" ? t : String(t);
121
+ return t instanceof M ? t.toJSON() : t instanceof Error ? { name: t.name, message: t.message } : t !== null && typeof t == "object" ? t : String(t);
122
122
  }
123
123
  toJSON() {
124
124
  return {
125
125
  name: this.name,
126
126
  message: this.message,
127
- cause: this.cause ? b.serializeCause(this.cause) : void 0
127
+ cause: this.cause ? M.serializeCause(this.cause) : void 0
128
128
  };
129
129
  }
130
130
  toString() {
@@ -136,12 +136,12 @@ class b extends Error {
136
136
  }
137
137
  }
138
138
  }
139
- const X = {
139
+ const oe = {
140
140
  INTERNAL_ERROR: "INTERNAL_ERROR"
141
- }, W = "RPC_ERROR";
142
- class $ extends b {
141
+ }, ie = "RPC_ERROR";
142
+ class ae extends M {
143
143
  constructor(t) {
144
- super(t.message || "rpc error", t.cause), this.name = W, this.code = (t == null ? void 0 : t.code) || X.INTERNAL_ERROR, this.details = t.details, this.method = t.method, this.params = t.params;
144
+ super(t.message || "rpc error", t.cause), this.name = ie, this.code = (t == null ? void 0 : t.code) || oe.INTERNAL_ERROR, this.details = t.details, this.method = t.method, this.params = t.params;
145
145
  }
146
146
  toJSON() {
147
147
  return {
@@ -153,7 +153,7 @@ class $ extends b {
153
153
  };
154
154
  }
155
155
  }
156
- const U = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_rpc" && "version" in e && e.version === "1.0", J = ({ uniqId: e }) => (t) => ({
156
+ const ce = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_rpc" && "version" in e && e.version === "1.0", de = ({ uniqId: e }) => (t) => ({
157
157
  ...{
158
158
  requestId: e(),
159
159
  protocol: "platform_rpc",
@@ -161,14 +161,14 @@ const U = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol ==
161
161
  timestamp: Date.now()
162
162
  },
163
163
  ...t
164
- }), K = J({
165
- uniqId: () => E()
164
+ }), ue = de({
165
+ uniqId: () => w()
166
166
  });
167
- class Z {
167
+ class le {
168
168
  constructor(t) {
169
169
  this.pendingEntryMap = /* @__PURE__ */ new Map(), this.transportMessageHandler = (s) => {
170
170
  const { data: o } = s;
171
- if (U(o)) {
171
+ if (ce(o)) {
172
172
  if (o.type === "response" && o.status === "ok") {
173
173
  const a = this.pendingEntryMap.get(o.requestId);
174
174
  if (!a) {
@@ -184,7 +184,7 @@ class Z {
184
184
  console.error("[RpcClient] transportMessageHandler: got error response without pending request", o);
185
185
  return;
186
186
  }
187
- this.pendingEntryMap.delete(o.requestId), a.reject(new $(o.error));
187
+ this.pendingEntryMap.delete(o.requestId), a.reject(new ae(o.error));
188
188
  return;
189
189
  }
190
190
  console.error("[RpcClient] transportMessageHandler: invalid message schema", o);
@@ -194,7 +194,7 @@ class Z {
194
194
  this.serverId = r, this.transport = n, this.transport.onMessage(this.transportMessageHandler);
195
195
  }
196
196
  makeRequest(t, r) {
197
- const n = K({
197
+ const n = ue({
198
198
  type: "request",
199
199
  method: t,
200
200
  params: r
@@ -219,27 +219,27 @@ class Z {
219
219
  return s;
220
220
  }
221
221
  }
222
- const Q = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_transport" && "version" in e && e.version === "1.0", Y = ({ uniqId: e }) => (t) => ({
222
+ const pe = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_transport" && "version" in e && e.version === "1.0", he = ({ uniqId: e }) => (t) => ({
223
223
  messageId: e(),
224
224
  protocol: "platform_transport",
225
225
  version: "1.0",
226
226
  ...t
227
- }), S = Y({
228
- uniqId: E
227
+ }), A = he({
228
+ uniqId: w
229
229
  });
230
- class ee {
230
+ class fe {
231
231
  constructor(t) {
232
232
  this.peers = /* @__PURE__ */ new Map(), this.handlers = /* @__PURE__ */ new Set(), this.onMessage = (s) => {
233
233
  const o = (a) => {
234
- const { data: i, origin: c, source: l } = a;
235
- if (!l || !Q(i))
234
+ const { data: i, origin: c, source: d } = a;
235
+ if (!d || !pe(i))
236
236
  return;
237
- const { recipientId: f } = i;
238
- if (!(f !== this.transportId || !this.findPeer(l, c)))
237
+ const { recipientId: u } = i;
238
+ if (!(u !== this.transportId || !this.findPeer(d, c)))
239
239
  try {
240
240
  s(i);
241
- } catch (w) {
242
- console.error("[PostMessageTransport] onMessage: failed to call cb on message", w);
241
+ } catch (I) {
242
+ console.error("[PostMessageTransport] onMessage: failed to call cb on message", I);
243
243
  }
244
244
  };
245
245
  return this.localWindow.addEventListener("message", o), this.handlers.add(o), () => {
@@ -257,7 +257,7 @@ class ee {
257
257
  send(t, r) {
258
258
  const n = this.peers.get(t);
259
259
  if (n) {
260
- const s = S({
260
+ const s = A({
261
261
  data: r,
262
262
  senderId: this.transportId,
263
263
  recipientId: n.id
@@ -267,7 +267,7 @@ class ee {
267
267
  }
268
268
  broadcast(t) {
269
269
  this.peers.forEach((r) => {
270
- const n = S({
270
+ const n = A({
271
271
  data: t,
272
272
  senderId: this.transportId,
273
273
  recipientId: r.id
@@ -296,9 +296,9 @@ class ee {
296
296
  const g = {
297
297
  name: "unknownError",
298
298
  message: "unknown error"
299
- }, q = (e, t = 3, r = 0) => {
299
+ }, W = (e, t = 3, r = 0) => {
300
300
  if (e instanceof Error) {
301
- const n = r < t && e.cause ? q(e.cause, t, r + 1) : void 0;
301
+ const n = r < t && e.cause ? W(e.cause, t, r + 1) : void 0;
302
302
  return {
303
303
  name: e.name,
304
304
  message: e.message,
@@ -329,10 +329,10 @@ const g = {
329
329
  };
330
330
  }
331
331
  return g;
332
- }, L = (e) => {
332
+ }, V = (e) => {
333
333
  const t = [];
334
334
  if (e instanceof Error)
335
- t.push(e.message), "cause" in e && t.push(L(e.cause));
335
+ t.push(e.message), "cause" in e && t.push(V(e.cause));
336
336
  else
337
337
  try {
338
338
  const r = JSON.stringify(e);
@@ -341,7 +341,7 @@ const g = {
341
341
  t.push("failed to get chained error message: unserializable error object");
342
342
  }
343
343
  return t.join(":");
344
- }, te = [
344
+ }, me = [
345
345
  // browser internals — harmless noise
346
346
  /resizeObserver loop/ig,
347
347
  // cross-origin script errors with zero useful info
@@ -364,98 +364,98 @@ const g = {
364
364
  // generic network noise already captured by fetch/xhr integrations
365
365
  /networkError when attempting to fetch resource/ig,
366
366
  /load failed/ig
367
- ], re = (e) => te.some((t) => (t.lastIndex = 0, t.test(e))), ne = (e) => {
368
- const t = L(e.error), r = typeof e.data == "object" && "message" in e.data && typeof e.data.message == "string" ? e.data.message : "";
367
+ ], ge = (e) => me.some((t) => (t.lastIndex = 0, t.test(e))), ye = (e) => {
368
+ const t = V(e.error), r = typeof e.data == "object" && "message" in e.data && typeof e.data.message == "string" ? e.data.message : "";
369
369
  return [t, r].filter((n) => !!n).join(":");
370
- }, se = (e) => e.data && typeof e.data == "object" && "filename" in e.data ? String(e.data.filename ?? "") : "", oe = (e) => {
371
- const t = ne(e), r = se(e);
372
- return r && /^(chrome|moz|safari)-extension:\/\//.test(r) ? !0 : !!t && re(t);
373
- }, ae = "get", ie = (e, t) => {
370
+ }, be = (e) => e.data && typeof e.data == "object" && "filename" in e.data ? String(e.data.filename ?? "") : "", Ee = (e) => {
371
+ const t = ye(e), r = be(e);
372
+ return r && /^(chrome|moz|safari)-extension:\/\//.test(r) ? !0 : !!t && ge(t);
373
+ }, we = "get", Me = (e, t) => {
374
374
  var s;
375
375
  let r, n;
376
376
  return e instanceof Request ? (r = e.url, n = e.method) : e instanceof URL ? r = e.toString() : r = e, {
377
- method: n || ((s = t == null ? void 0 : t.method) == null ? void 0 : s.toString()) || ae,
377
+ method: n || ((s = t == null ? void 0 : t.method) == null ? void 0 : s.toString()) || we,
378
378
  url: r
379
379
  };
380
- }, ce = (e, t, r) => ({
380
+ }, ve = (e, t, r) => ({
381
381
  statusCode: r.status,
382
- ...ie(e, t)
383
- }), ue = (e) => {
382
+ ...Me(e, t)
383
+ }), Re = (e) => {
384
384
  const t = window.fetch;
385
385
  Object.defineProperty(window, "fetch", {
386
386
  value: async (n, s) => {
387
387
  try {
388
- const o = new Error("synthetic error"), a = await t(n, s), i = a.clone(), c = ce(n, s, i);
388
+ const o = new Error("synthetic error"), a = await t(n, s), i = a.clone(), c = ve(n, s, i);
389
389
  if (a.status >= 500) {
390
- const d = new Error("fetch response error");
391
- d.stack = o.stack, e.report({
390
+ const p = new Error("fetch response error");
391
+ p.stack = o.stack, e.report({
392
392
  kind: "fetchResponseError",
393
393
  type: "network",
394
394
  data: c,
395
- error: d
395
+ error: p
396
396
  });
397
397
  }
398
398
  const {
399
- arrayBuffer: l,
400
- blob: f,
401
- json: M,
402
- text: w
399
+ arrayBuffer: d,
400
+ blob: u,
401
+ json: q,
402
+ text: I
403
403
  } = a;
404
404
  return a.json = async function() {
405
405
  try {
406
- return await M.call(this);
407
- } catch (d) {
406
+ return await q.call(this);
407
+ } catch (p) {
408
408
  throw e.report({
409
409
  type: "network",
410
410
  kind: "fetchParseBodyError",
411
- error: d,
411
+ error: p,
412
412
  data: {
413
413
  parseType: "json",
414
414
  ...c
415
415
  }
416
- }), d;
416
+ }), p;
417
417
  }
418
418
  }, a.text = async function() {
419
419
  try {
420
- return await w.call(this);
421
- } catch (d) {
420
+ return await I.call(this);
421
+ } catch (p) {
422
422
  throw e.report({
423
423
  type: "network",
424
424
  kind: "fetchParseBodyError",
425
- error: d,
425
+ error: p,
426
426
  data: {
427
427
  parseType: "text",
428
428
  ...c
429
429
  }
430
- }), d;
430
+ }), p;
431
431
  }
432
432
  }, a.blob = async function() {
433
433
  try {
434
- return await f.call(this);
435
- } catch (d) {
434
+ return await u.call(this);
435
+ } catch (p) {
436
436
  throw e.report({
437
437
  type: "network",
438
438
  kind: "fetchParseBodyError",
439
- error: d,
439
+ error: p,
440
440
  data: {
441
441
  parseType: "blob",
442
442
  ...c
443
443
  }
444
- }), d;
444
+ }), p;
445
445
  }
446
446
  }, a.arrayBuffer = async function() {
447
447
  try {
448
- return await l.call(this);
449
- } catch (d) {
448
+ return await d.call(this);
449
+ } catch (p) {
450
450
  throw e.report({
451
451
  type: "network",
452
452
  kind: "fetchParseBodyError",
453
- error: d,
453
+ error: p,
454
454
  data: {
455
455
  parseType: "arrayBuffer",
456
456
  ...c
457
457
  }
458
- }), d;
458
+ }), p;
459
459
  }
460
460
  }, a;
461
461
  } catch (o) {
@@ -465,7 +465,7 @@ const g = {
465
465
  configurable: !0,
466
466
  writable: !0
467
467
  });
468
- }, de = (e) => {
468
+ }, Ie = (e) => {
469
469
  window.addEventListener("unhandledrejection", ({ reason: t }) => {
470
470
  e.report({
471
471
  type: "runtime",
@@ -485,23 +485,23 @@ const g = {
485
485
  }
486
486
  });
487
487
  });
488
- }, _ = Symbol("patchedXHLHttpRequest"), h = Symbol("requestInfo"), le = (e) => ({
488
+ }, z = Symbol("patchedXHLHttpRequest"), f = Symbol("requestInfo"), ke = (e) => ({
489
489
  statusCode: e.status,
490
- ...e[h]
491
- }), pe = (e) => (e[h] || (e[h] = {}), e[h]), he = (e) => {
492
- e[_] = !0;
493
- }, fe = (e) => e[_] === !0, me = (e) => {
490
+ ...e[f]
491
+ }), Te = (e) => (e[f] || (e[f] = {}), e[f]), Se = (e) => {
492
+ e[z] = !0;
493
+ }, Le = (e) => e[z] === !0, He = (e) => {
494
494
  const t = XMLHttpRequest.prototype.send, r = XMLHttpRequest.prototype.open, n = function(...o) {
495
495
  const [a, i] = o;
496
- this[h] = {
496
+ this[f] = {
497
497
  method: a,
498
498
  url: typeof i == "string" ? i : i.toString()
499
- }, fe(this) || (he(this), this.addEventListener("error", () => {
499
+ }, Le(this) || (Se(this), this.addEventListener("error", () => {
500
500
  const c = new Error("XMLHttpRequest network error");
501
501
  e.report({
502
502
  type: "network",
503
503
  kind: "xmlHttpRequestError",
504
- data: this[h],
504
+ data: this[f],
505
505
  error: c
506
506
  });
507
507
  }), this.addEventListener("timeout", () => {
@@ -509,7 +509,7 @@ const g = {
509
509
  e.report({
510
510
  type: "network",
511
511
  kind: "xmlHttpRequestTimeoutError",
512
- data: this[h],
512
+ data: this[f],
513
513
  error: c
514
514
  });
515
515
  }), this.addEventListener("load", () => {
@@ -518,7 +518,7 @@ const g = {
518
518
  e.report({
519
519
  type: "network",
520
520
  kind: "xmlHttpRequestLoadError",
521
- data: le(this),
521
+ data: ke(this),
522
522
  error: c
523
523
  });
524
524
  }
@@ -530,19 +530,19 @@ const g = {
530
530
  type: "network",
531
531
  kind: "xmlHttpRequestOpenError",
532
532
  error: c,
533
- data: this[h]
533
+ data: this[f]
534
534
  }), c;
535
535
  }
536
536
  }, s = function(o) {
537
537
  try {
538
- const a = pe(this), i = new Error("XMLHttpRequest request initiator");
538
+ const a = Te(this), i = new Error("XMLHttpRequest request initiator");
539
539
  a.requestStack = i.stack, t.call(this, o);
540
540
  } catch (a) {
541
541
  throw e.report({
542
542
  type: "network",
543
543
  kind: "xmlHttpRequestSendError",
544
544
  error: a,
545
- data: this[h]
545
+ data: this[f]
546
546
  }), a;
547
547
  }
548
548
  };
@@ -556,28 +556,148 @@ const g = {
556
556
  writable: !0
557
557
  });
558
558
  };
559
- let N;
560
- class ge {
559
+ let x;
560
+ class Ne {
561
561
  constructor(t) {
562
562
  this.onError = t;
563
563
  }
564
564
  report(t) {
565
- if (oe(t))
565
+ if (Ee(t))
566
566
  return;
567
567
  const { error: r, ...n } = t;
568
568
  this.onError({
569
569
  ...n,
570
- error: r ? q(r) : void 0
570
+ error: r ? W(r) : void 0
571
571
  });
572
572
  }
573
573
  init() {
574
574
  this.applyIntegrations();
575
575
  }
576
576
  applyIntegrations() {
577
- N || (N = !0, de(this), me(this), ue(this));
577
+ x || (x = !0, Ie(this), He(this), Re(this));
578
578
  }
579
579
  }
580
- class ye {
580
+ const y = (e, t, r) => {
581
+ var n;
582
+ try {
583
+ Object.defineProperty(e, t, {
584
+ configurable: !0,
585
+ enumerable: ((n = Object.getOwnPropertyDescriptor(e, t)) == null ? void 0 : n.enumerable) ?? !1,
586
+ value: r,
587
+ writable: !0
588
+ });
589
+ } catch {
590
+ }
591
+ }, k = /* @__PURE__ */ new WeakMap(), Pe = (e) => {
592
+ const t = window.setTimeout.bind(window), r = window.setInterval.bind(window), n = window.requestAnimationFrame, s = EventTarget.prototype.addEventListener, o = EventTarget.prototype.removeEventListener;
593
+ y(
594
+ window,
595
+ "setTimeout",
596
+ function(i, c, ...d) {
597
+ const u = typeof i == "function" ? e(i) : i;
598
+ return t(u, c, ...d);
599
+ }
600
+ ), y(
601
+ window,
602
+ "setInterval",
603
+ function(i, c, ...d) {
604
+ const u = typeof i == "function" ? e(i) : i;
605
+ return r(u, c, ...d);
606
+ }
607
+ ), y(
608
+ window,
609
+ "requestAnimationFrame",
610
+ function(i) {
611
+ return n.call(window, e(i));
612
+ }
613
+ ), y(
614
+ EventTarget.prototype,
615
+ "addEventListener",
616
+ function(i, c, d) {
617
+ if (typeof c != "function")
618
+ return s.call(this, i, c, d);
619
+ const u = k.get(c) ?? e(c);
620
+ return k.set(c, u), s.call(this, i, u, d);
621
+ }
622
+ ), y(
623
+ EventTarget.prototype,
624
+ "removeEventListener",
625
+ function(i, c, d) {
626
+ const u = typeof c == "function" ? k.get(c) : void 0;
627
+ return o.call(this, i, u ?? c, d);
628
+ }
629
+ );
630
+ };
631
+ let S = 0, L = 0, v = 0, H = 0, T = 0, C = !1, R = 0, E = 0, N = 0;
632
+ const qe = typeof window > "u" ? (() => 0) : window.setTimeout.bind(window), X = (e) => e < R, $ = (e) => {
633
+ E !== 0 && (N += Math.min(e, R) - E, E = X(e) ? e : 0);
634
+ }, _e = (e) => {
635
+ const t = performance.now();
636
+ $(t), E === 0 && (E = t), R = Math.max(R, t + e);
637
+ }, Oe = () => {
638
+ const e = performance.now();
639
+ $(e);
640
+ const t = {
641
+ activeMs: Math.round(N),
642
+ longestTaskMs: Math.round(v),
643
+ selfTimeMs: Math.round(S),
644
+ selfTimeWhileActiveMs: Math.round(L),
645
+ tasks: H
646
+ };
647
+ return S = 0, L = 0, v = 0, H = 0, N = 0, t;
648
+ }, Ae = (e) => function(...r) {
649
+ if (T > 0)
650
+ return e.apply(this, r);
651
+ T += 1;
652
+ const n = performance.now();
653
+ try {
654
+ return e.apply(this, r);
655
+ } finally {
656
+ const s = performance.now() - n;
657
+ T -= 1, H += 1, S += s, X(n) && (L += s), s > v && (v = s);
658
+ }
659
+ }, xe = () => {
660
+ C || typeof window > "u" || (C = !0, Pe(Ae));
661
+ }, D = 200, Ce = 50, De = 6e4;
662
+ class Fe {
663
+ constructor(t) {
664
+ this.timerId = null, this.windowStartMs = 0, this.expectedTickMs = 0, this.blocks = 0, this.blockedMs = 0, this.longestBlockMs = 0, this.ticks = 0, this.wasHidden = !1, this.handleVisibilityChange = () => {
665
+ document.hidden && (this.wasHidden = !0);
666
+ }, this.handleTick = () => {
667
+ const r = performance.now(), n = r - this.expectedTickMs;
668
+ this.ticks += 1, n > Ce && (this.blocks += 1, this.blockedMs += n, this.longestBlockMs = Math.max(this.longestBlockMs, n)), r - this.windowStartMs >= De && this.flush(r), this.scheduleTick();
669
+ }, this.onReport = t;
670
+ }
671
+ init() {
672
+ this.timerId === null && (this.startWindow(performance.now()), document.addEventListener("visibilitychange", this.handleVisibilityChange), this.scheduleTick());
673
+ }
674
+ stop() {
675
+ this.timerId !== null && (document.removeEventListener("visibilitychange", this.handleVisibilityChange), clearTimeout(this.timerId), this.timerId = null);
676
+ }
677
+ startWindow(t) {
678
+ this.windowStartMs = t, this.blocks = 0, this.blockedMs = 0, this.longestBlockMs = 0, this.ticks = 0, this.wasHidden = document.hidden;
679
+ }
680
+ scheduleTick() {
681
+ this.expectedTickMs = performance.now() + D, this.timerId = qe(this.handleTick, D);
682
+ }
683
+ flush(t) {
684
+ const { activeMs: r, longestTaskMs: n, selfTimeMs: s, selfTimeWhileActiveMs: o, tasks: a } = Oe(), i = {
685
+ blockedMs: Math.round(this.blockedMs),
686
+ blocks: this.blocks,
687
+ longestBlockMs: Math.round(this.longestBlockMs),
688
+ activeMs: r,
689
+ longestTaskMs: n,
690
+ selfTimeMs: s,
691
+ selfTimeWhileActiveMs: o,
692
+ tasks: a,
693
+ ticks: this.ticks,
694
+ wasHidden: this.wasHidden,
695
+ windowMs: Math.round(t - this.windowStartMs)
696
+ };
697
+ this.onReport(i), this.startWindow(t);
698
+ }
699
+ }
700
+ class je {
581
701
  constructor(t) {
582
702
  const {
583
703
  frameId: r,
@@ -590,17 +710,20 @@ class ye {
590
710
  id: s,
591
711
  origin: o,
592
712
  source: a
593
- }, l = new ee({
713
+ }, d = new fe({
594
714
  transportId: r
595
715
  });
596
- l.addPeer(c), this.rpcClient = new Z({
597
- transport: l,
716
+ d.addPeer(c), this.rpcClient = new le({
717
+ transport: d,
598
718
  serverId: s
599
- }), this.subscriber = new z({
600
- transport: l,
719
+ }), this.subscriber = new re({
720
+ transport: d,
601
721
  brokerId: c.id
602
- }), document.documentElement.dataset.theme = i, document.documentElement.lang = n, this.crashReporter = new ge((f) => {
603
- this.makeRequest("v1.system.report.crash", f);
722
+ }), document.documentElement.dataset.theme = i, document.documentElement.lang = n, this.crashReporter = new Ne((u) => {
723
+ this.makeRequest("v1.system.report.crash", u);
724
+ }), this.performanceReporter = new Fe((u) => {
725
+ this.makeRequest("v1.system.report.performance", u).catch(() => {
726
+ });
604
727
  });
605
728
  }
606
729
  makeRequest(t, r) {
@@ -613,6 +736,7 @@ class ye {
613
736
  return this.subscriber.unsubscribe(t, r);
614
737
  }
615
738
  bootstrap() {
739
+ this.subscribe("v1.ext.activity.granted", ({ durationMs: i }) => _e(i));
616
740
  let t = { height: 0, width: 0 };
617
741
  const r = () => {
618
742
  const i = document.body;
@@ -635,38 +759,38 @@ class ye {
635
759
  subtree: !0,
636
760
  attributes: !0,
637
761
  attributeFilter: ["style", "class", "hidden", "open"]
638
- }), this.crashReporter.init();
762
+ }), this.crashReporter.init(), this.performanceReporter.init();
639
763
  }
640
764
  }
641
- const Ee = HTMLElement.prototype.focus, be = SVGElement.prototype.focus;
642
- function T(e) {
765
+ const Ge = HTMLElement.prototype.focus, Be = SVGElement.prototype.focus;
766
+ function F(e) {
643
767
  const t = typeof e == "object" && e ? { ...e, preventScroll: !0 } : { preventScroll: !0 };
644
768
  if (this instanceof HTMLElement)
645
- return Ee.call(this, t);
769
+ return Ge.call(this, t);
646
770
  if (this instanceof SVGElement)
647
- return be.call(this, t);
771
+ return Be.call(this, t);
648
772
  }
649
- const we = HTMLFormElement.prototype.submit, Re = HTMLFormElement.prototype.requestSubmit, Me = /* @__PURE__ */ new Set(["_top", "_blank", "_parent"]), R = (e) => !!e && Me.has(e.toLowerCase());
650
- function Ie() {
773
+ const We = HTMLFormElement.prototype.submit, Ve = HTMLFormElement.prototype.requestSubmit, ze = /* @__PURE__ */ new Set(["_top", "_blank", "_parent"]), P = (e) => !!e && ze.has(e.toLowerCase());
774
+ function Xe() {
651
775
  const e = this.getAttribute("target");
652
- if (!R(e))
653
- return we.call(this);
776
+ if (!P(e))
777
+ return We.call(this);
654
778
  }
655
- function ve(e) {
779
+ function $e(e) {
656
780
  const t = (e == null ? void 0 : e.getAttribute("formtarget")) || this.getAttribute("target");
657
- if (!R(t))
658
- return Re.call(this, e);
781
+ if (!P(t))
782
+ return Ve.call(this, e);
659
783
  }
660
- function Se(e) {
784
+ function Ue(e) {
661
785
  var s;
662
786
  const t = e.target;
663
787
  if (!(t instanceof HTMLFormElement))
664
788
  return;
665
789
  const r = e instanceof SubmitEvent ? e.submitter : null, n = (r == null ? void 0 : r.getAttribute("formtarget")) || t.getAttribute("target") || ((s = document.querySelector("base[target]")) == null ? void 0 : s.getAttribute("target")) || "_self";
666
- R(n) && (e.preventDefault(), e.stopImmediatePropagation());
790
+ P(n) && (e.preventDefault(), e.stopImmediatePropagation());
667
791
  }
668
- const p = () => {
669
- }, u = (e, t, r) => {
792
+ const h = () => {
793
+ }, l = (e, t, r) => {
670
794
  const n = e;
671
795
  if (!n || typeof n[t] != "function")
672
796
  return;
@@ -681,27 +805,27 @@ const p = () => {
681
805
  });
682
806
  } catch {
683
807
  }
684
- }, Ne = () => {
685
- u(Window.prototype, "open", () => null), u(window, "open", () => null), u(Element.prototype, "scrollIntoView", p), u(
808
+ }, Je = () => {
809
+ l(Window.prototype, "open", () => null), l(window, "open", () => null), l(Element.prototype, "scrollIntoView", h), l(
686
810
  Element.prototype,
687
811
  "scrollIntoViewIfNeeded",
688
- p
689
- ), u(HTMLElement.prototype, "focus", T), u(SVGElement.prototype, "focus", T), u(History.prototype, "back", p), u(History.prototype, "forward", p), u(History.prototype, "go", p), u(History.prototype, "pushState", p), u(History.prototype, "replaceState", p), u(
812
+ h
813
+ ), l(HTMLElement.prototype, "focus", F), l(SVGElement.prototype, "focus", F), l(History.prototype, "back", h), l(History.prototype, "forward", h), l(History.prototype, "go", h), l(History.prototype, "pushState", h), l(History.prototype, "replaceState", h), l(
690
814
  HTMLVideoElement.prototype,
691
815
  "requestPictureInPicture",
692
816
  () => Promise.resolve({})
693
- ), u(HTMLFormElement.prototype, "submit", Ie), u(HTMLFormElement.prototype, "requestSubmit", ve), typeof Location < "u" && (u(Location.prototype, "assign", p), u(Location.prototype, "replace", p), u(Location.prototype, "reload", p)), document.addEventListener("submit", Se, !0);
694
- }, H = (e) => typeof e == "object" && e !== null && !Array.isArray(e), He = (e) => H(e) ? typeof e.code == "string" && typeof e.message == "string" && (e.details === void 0 || H(e.details)) : !1;
695
- let k = !1;
696
- const Te = "en";
697
- typeof window < "u" && typeof document < "u" && Ne();
698
- const ke = () => {
699
- if (k)
817
+ ), l(HTMLFormElement.prototype, "submit", Xe), l(HTMLFormElement.prototype, "requestSubmit", $e), typeof Location < "u" && (l(Location.prototype, "assign", h), l(Location.prototype, "replace", h), l(Location.prototype, "reload", h)), document.addEventListener("submit", Ue, !0);
818
+ }, j = (e) => typeof e == "object" && e !== null && !Array.isArray(e), Ze = (e) => j(e) ? typeof e.code == "string" && typeof e.message == "string" && (e.details === void 0 || j(e.details)) : !1;
819
+ let G = !1;
820
+ const Ke = "en";
821
+ typeof window < "u" && typeof document < "u" && (Je(), xe());
822
+ const Qe = () => {
823
+ if (G)
700
824
  throw new Error("ext helper already created, only one instance is allowed");
701
- const e = new URL(window.location.href), t = e.searchParams.get("origin") || "", r = e.searchParams.get("theme") || "dark", n = e.searchParams.get("lang") || Te, s = e.searchParams.get("frameId");
825
+ const e = new URL(window.location.href), t = e.searchParams.get("origin") || "", r = e.searchParams.get("theme") || "dark", n = e.searchParams.get("lang") || Ke, s = e.searchParams.get("frameId");
702
826
  if (!s)
703
827
  throw new Error("failed to create ext helper, frameId is empty");
704
- const o = new ye({
828
+ const o = new je({
705
829
  serverId: "server",
706
830
  serverOrigin: t || window.parent.origin,
707
831
  serverSource: window.parent,
@@ -709,9 +833,9 @@ const ke = () => {
709
833
  theme: r,
710
834
  lang: n
711
835
  });
712
- return o.bootstrap(), k = !0, o;
836
+ return o.bootstrap(), G = !0, o;
713
837
  };
714
838
  export {
715
- ke as createExtHelper,
716
- He as isExtensionError
839
+ Qe as createExtHelper,
840
+ Ze as isExtensionError
717
841
  };