@stripchatdev/ext-helper 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,323 +1,571 @@
1
- const M = (r) => !!r && typeof r == "object" && "protocol" in r && r.protocol === "iframe_pubsub" && "version" in r && r.version === "1.0", f = (r, e) => r, E = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
2
- var u;
3
- (function(r) {
4
- r.Base32IncorrectEncoding = "B32_ENC_INVALID", r.DecodeTimeInvalidCharacter = "DEC_TIME_CHAR", r.DecodeTimeValueMalformed = "DEC_TIME_MALFORMED", r.EncodeTimeNegative = "ENC_TIME_NEG", r.EncodeTimeSizeExceeded = "ENC_TIME_SIZE_EXCEED", r.EncodeTimeValueMalformed = "ENC_TIME_MALFORMED", r.PRNGDetectFailure = "PRNG_DETECT", r.ULIDInvalid = "ULID_INVALID", r.Unexpected = "UNEXPECTED", r.UUIDInvalid = "UUID_INVALID";
5
- })(u || (u = {}));
6
- class d extends Error {
7
- constructor(e, t) {
8
- super(`${t} (${e})`), this.name = "ULIDError", this.code = e;
1
+ const T = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "iframe_pubsub" && "version" in e && e.version === "1.0", y = (e, t) => e, w = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
2
+ var l;
3
+ (function(e) {
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
+ })(l || (l = {}));
6
+ class f extends Error {
7
+ constructor(t, r) {
8
+ super(`${r} (${t})`), this.name = "ULIDError", this.code = t;
9
9
  }
10
10
  }
11
- function m(r) {
12
- const e = Math.floor(r() * 32) % 32;
13
- return E.charAt(e);
11
+ function P(e) {
12
+ const t = Math.floor(e() * 32) % 32;
13
+ return w.charAt(t);
14
14
  }
15
- function R(r) {
16
- const e = y(), t = e && (e.crypto || e.msCrypto) || null;
17
- if (typeof (t == null ? void 0 : t.getRandomValues) == "function")
15
+ function _(e) {
16
+ const t = H(), r = t && (t.crypto || t.msCrypto) || null;
17
+ if (typeof (r == null ? void 0 : r.getRandomValues) == "function")
18
18
  return () => {
19
- const n = new Uint8Array(1);
20
- return t.getRandomValues(n), n[0] / 255;
19
+ const s = new Uint8Array(1);
20
+ return r.getRandomValues(s), s[0] / 255;
21
21
  };
22
- if (typeof (t == null ? void 0 : t.randomBytes) == "function")
23
- return () => t.randomBytes(1).readUInt8() / 255;
24
- throw new d(u.PRNGDetectFailure, "Failed to find a reliable PRNG");
22
+ if (typeof (r == null ? void 0 : r.randomBytes) == "function")
23
+ return () => r.randomBytes(1).readUInt8() / 255;
24
+ throw new f(l.PRNGDetectFailure, "Failed to find a reliable PRNG");
25
25
  }
26
- function y() {
27
- return I() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
26
+ function H() {
27
+ return O() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
28
28
  }
29
- function N(r, e) {
30
- let t = "";
31
- for (; r > 0; r--)
32
- t = m(e) + t;
33
- return t;
29
+ function q(e, t) {
30
+ let r = "";
31
+ for (; e > 0; e--)
32
+ r = P(t) + r;
33
+ return r;
34
34
  }
35
- function v(r, e = 10) {
36
- if (isNaN(r))
37
- throw new d(u.EncodeTimeValueMalformed, `Time must be a number: ${r}`);
38
- if (r > 281474976710655)
39
- throw new d(u.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${281474976710655}: ${r}`);
40
- if (r < 0)
41
- throw new d(u.EncodeTimeNegative, `Time must be positive: ${r}`);
42
- if (Number.isInteger(r) === !1)
43
- throw new d(u.EncodeTimeValueMalformed, `Time must be an integer: ${r}`);
44
- let t, n = "";
45
- for (let s = e; s > 0; s--)
46
- t = r % 32, n = E.charAt(t) + n, r = (r - t) / 32;
47
- return n;
35
+ function L(e, t = 10) {
36
+ if (isNaN(e))
37
+ throw new f(l.EncodeTimeValueMalformed, `Time must be a number: ${e}`);
38
+ if (e > 281474976710655)
39
+ throw new f(l.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${281474976710655}: ${e}`);
40
+ if (e < 0)
41
+ throw new f(l.EncodeTimeNegative, `Time must be positive: ${e}`);
42
+ if (Number.isInteger(e) === !1)
43
+ throw new f(l.EncodeTimeValueMalformed, `Time must be an integer: ${e}`);
44
+ let r, s = "";
45
+ for (let n = t; n > 0; n--)
46
+ r = e % 32, s = w.charAt(r) + s, e = (e - r) / 32;
47
+ return s;
48
48
  }
49
- function I() {
49
+ function O() {
50
50
  return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
51
51
  }
52
- function p(r, e) {
53
- const t = R(), n = Date.now();
54
- return v(n, 10) + N(16, t);
52
+ function g(e, t) {
53
+ const r = _(), s = Date.now();
54
+ return L(s, 10) + q(16, r);
55
55
  }
56
- const _ = ({ seq: r, uniqId: e }) => (t) => ({
56
+ const S = ({ seq: e, uniqId: t }) => (r) => ({
57
57
  ...{
58
58
  protocol: "iframe_pubsub",
59
59
  version: "1.0",
60
- id: e(),
61
- seq: r(),
60
+ id: t(),
61
+ seq: e(),
62
62
  timestamp: Date.now()
63
63
  },
64
- ...t
65
- }), b = _({
66
- uniqId: () => p(),
67
- seq: () => p()
64
+ ...r
65
+ }), m = S({
66
+ uniqId: () => g(),
67
+ seq: () => g()
68
68
  });
69
- class T {
70
- constructor(e) {
71
- this.eventHandlerMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (s, i) => {
72
- if (M(s)) {
73
- if (s.type === "event") {
74
- const { eventName: a } = s, o = this.eventHandlerMap.get(a);
75
- if (!o)
69
+ class C {
70
+ constructor(t) {
71
+ this.eventHandlerMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (n, o) => {
72
+ if (T(n)) {
73
+ if (n.type === "event") {
74
+ const { eventName: i } = n, a = this.eventHandlerMap.get(i);
75
+ if (!a)
76
76
  return;
77
- o.forEach((c) => {
77
+ a.forEach((c) => {
78
78
  try {
79
- c(s.data, i.id);
80
- } catch (h) {
81
- console.error("[PubSubSubscriber] globalMessageHandler: failed to handle income message", h);
79
+ c(n.data, o.id);
80
+ } catch (p) {
81
+ console.error("[PubSubSubscriber] globalMessageHandler: failed to handle income message", p);
82
82
  }
83
83
  });
84
84
  return;
85
85
  }
86
- console.error("[PubSubSubscriber] globalMessageHandler: unhandled message", s);
86
+ console.error("[PubSubSubscriber] globalMessageHandler: unhandled message", n);
87
87
  }
88
88
  };
89
- const { brokerId: t, transport: n } = e;
90
- this.brokerId = t, this.transport = n, this.transport.onMessage(this.globalMessageHandler);
89
+ const { brokerId: r, transport: s } = t;
90
+ this.brokerId = r, this.transport = s, this.transport.onMessage(this.globalMessageHandler);
91
91
  }
92
- subscribe(e, t) {
93
- const n = f(e);
94
- let s = this.eventHandlerMap.get(n);
95
- s || (s = /* @__PURE__ */ new Set(), this.eventHandlerMap.set(n, s)), s.add(t);
96
- const i = b({
92
+ subscribe(t, r) {
93
+ const s = y(t);
94
+ let n = this.eventHandlerMap.get(s);
95
+ n || (n = /* @__PURE__ */ new Set(), this.eventHandlerMap.set(s, n)), n.add(r);
96
+ const o = m({
97
97
  type: "subscribe",
98
- eventName: e
98
+ eventName: t
99
99
  });
100
- this.transport.send(this.brokerId, i);
100
+ this.transport.send(this.brokerId, o);
101
101
  }
102
- unsubscribe(e, t) {
103
- const n = f(e);
104
- let s = this.eventHandlerMap.get(n);
105
- if (!s)
102
+ unsubscribe(t, r) {
103
+ const s = y(t);
104
+ let n = this.eventHandlerMap.get(s);
105
+ if (!n)
106
106
  return;
107
- t ? s.delete(t) : this.eventHandlerMap.delete(n);
108
- const i = b({
107
+ r ? n.delete(r) : this.eventHandlerMap.delete(s);
108
+ const o = m({
109
109
  type: "unsubscribe",
110
- eventName: e
110
+ eventName: t
111
111
  });
112
- this.transport.send(this.brokerId, i);
112
+ this.transport.send(this.brokerId, o);
113
113
  }
114
114
  }
115
- const w = !!Error.captureStackTrace, P = "APP_ERROR";
116
- class l extends Error {
117
- constructor(e, t) {
118
- super(e), this.name = new.target.name || P, this.cause = t, w && Error.captureStackTrace(this, this.constructor);
115
+ const A = !!Error.captureStackTrace, D = "APP_ERROR";
116
+ class E extends Error {
117
+ constructor(t, r) {
118
+ super(t), this.name = new.target.name || D, this.cause = r, A && Error.captureStackTrace(this, this.constructor);
119
119
  }
120
- static getChainedMessage(e) {
121
- let { message: t } = e;
122
- return e instanceof l && e.cause && (t += `
123
- Caused by: ${l.getChainedMessage(e.cause)}`), t;
120
+ static getChainedMessage(t) {
121
+ let { message: r } = t;
122
+ return t instanceof E && t.cause && (r += `
123
+ Caused by: ${E.getChainedMessage(t.cause)}`), r;
124
124
  }
125
125
  toJSON() {
126
126
  return {
127
127
  name: this.name,
128
128
  message: this.message,
129
- cause: this.cause ? l.getChainedMessage(this.cause) : void 0
129
+ cause: this.cause ? E.getChainedMessage(this.cause) : void 0
130
130
  };
131
131
  }
132
132
  }
133
- const O = {
133
+ const x = {
134
134
  INTERNAL_ERROR: "INTERNAL_ERROR"
135
- }, C = "RPC_ERROR";
136
- class D extends l {
137
- constructor(e) {
138
- super(e.message || "unknown rpc error"), this.name = C, this.code = (e == null ? void 0 : e.code) || O.INTERNAL_ERROR;
135
+ }, G = "RPC_ERROR";
136
+ class F extends E {
137
+ constructor(t) {
138
+ super(t.message || "unknown rpc error"), this.name = G, this.code = (t == null ? void 0 : t.code) || x.INTERNAL_ERROR;
139
139
  }
140
140
  }
141
- const A = (r) => !!r && typeof r == "object" && "protocol" in r && r.protocol === "iframe_rpc" && "version" in r && r.version === "1.0", H = ({ uniqId: r }) => (e) => ({
141
+ const j = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "iframe_rpc" && "version" in e && e.version === "1.0", B = ({ uniqId: e }) => (t) => ({
142
142
  ...{
143
143
  protocol: "iframe_rpc",
144
144
  version: "1.0",
145
- id: r(),
145
+ id: e(),
146
146
  timestamp: Date.now()
147
147
  },
148
- ...e
149
- }), S = H({
150
- uniqId: () => p()
148
+ ...t
149
+ }), X = B({
150
+ uniqId: () => g()
151
151
  });
152
- class L {
153
- constructor(e) {
154
- this.pendingEntryMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (s) => {
155
- if (A(s)) {
156
- if (s.type === "response" && s.status === "ok") {
157
- const i = s.id, a = this.pendingEntryMap.get(i);
158
- if (!a) {
159
- console.error("[RpcClient] globalMessageHandler: got success response without pending request", s);
152
+ class U {
153
+ constructor(t) {
154
+ this.pendingEntryMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (n) => {
155
+ if (j(n)) {
156
+ if (n.type === "response" && n.status === "ok") {
157
+ const o = n.id, i = this.pendingEntryMap.get(o);
158
+ if (!i) {
159
+ console.error("[RpcClient] globalMessageHandler: got success response without pending request", n);
160
160
  return;
161
161
  }
162
- this.pendingEntryMap.delete(i), a.resolve(s.result);
162
+ this.pendingEntryMap.delete(o), i.resolve(n.result);
163
163
  return;
164
164
  }
165
- if (s.type === "response" && s.status === "error") {
166
- const i = s.id, a = this.pendingEntryMap.get(i);
167
- if (!a) {
168
- console.error("[RpcClient] globalMessageHandler: got error response without pending request", s);
165
+ if (n.type === "response" && n.status === "error") {
166
+ const o = n.id, i = this.pendingEntryMap.get(o);
167
+ if (!i) {
168
+ console.error("[RpcClient] globalMessageHandler: got error response without pending request", n);
169
169
  return;
170
170
  }
171
- this.pendingEntryMap.delete(i), a.reject(new D(s.error));
171
+ this.pendingEntryMap.delete(o), i.reject(new F(n.error));
172
172
  return;
173
173
  }
174
- console.error("[RpcClient] globalMessageHandler: invalid message schema", s);
174
+ console.error("[RpcClient] globalMessageHandler: invalid message schema", n);
175
175
  }
176
176
  };
177
- const { serverId: t, transport: n } = e;
178
- this.serverId = t, this.transport = n, this.transport.onMessage(this.globalMessageHandler);
177
+ const { serverId: r, transport: s } = t;
178
+ this.serverId = r, this.transport = s, this.transport.onMessage(this.globalMessageHandler);
179
179
  }
180
- makeRequest(e, t) {
181
- const n = S({
180
+ makeRequest(t, r) {
181
+ const s = X({
182
182
  type: "request",
183
- method: e,
184
- params: t
185
- }), s = new Promise((i, a) => {
186
- this.pendingEntryMap.set(n.id, {
187
- method: e,
188
- resolve: (o) => {
189
- i(o);
183
+ method: t,
184
+ params: r
185
+ }), n = new Promise((o, i) => {
186
+ this.pendingEntryMap.set(s.id, {
187
+ method: t,
188
+ resolve: (a) => {
189
+ o(a);
190
190
  },
191
- reject: (o) => {
192
- a(o);
191
+ reject: (a) => {
192
+ i(a);
193
193
  }
194
194
  });
195
195
  });
196
196
  try {
197
- this.transport.send(this.serverId, n);
198
- } catch (i) {
199
- console.error("[RpcClient] makeRequest: failed to send rpc message", i);
200
- const a = this.pendingEntryMap.get(n.id);
201
- a && (this.pendingEntryMap.delete(n.id), a.reject(i));
197
+ this.transport.send(this.serverId, s);
198
+ } catch (o) {
199
+ console.error("[RpcClient] makeRequest: failed to send rpc message", o);
200
+ const i = this.pendingEntryMap.get(s.id);
201
+ i && (this.pendingEntryMap.delete(s.id), i.reject(o));
202
202
  }
203
- return s;
203
+ return n;
204
204
  }
205
205
  }
206
- class k {
207
- constructor(e) {
208
- this.peers = /* @__PURE__ */ new Map(), this.onMessage = (n) => {
209
- const s = (i) => {
210
- const { data: a, origin: o, source: c } = i;
206
+ class W {
207
+ constructor(t) {
208
+ this.peers = /* @__PURE__ */ new Map(), this.onMessage = (s) => {
209
+ const n = (o) => {
210
+ const { data: i, origin: a, source: c } = o;
211
211
  if (!c) {
212
212
  console.error("[PostMessageTransport] onMessage: source could not be empty");
213
213
  return;
214
214
  }
215
- const h = this.findPeer(c, o);
216
- if (h)
215
+ const p = this.findPeer(c, a);
216
+ if (p)
217
217
  try {
218
- n(a, h);
219
- } catch (g) {
220
- console.error("[PostMessageTransport] onMessage: failed to call cb on message", g);
218
+ s(i, p);
219
+ } catch (b) {
220
+ console.error("[PostMessageTransport] onMessage: failed to call cb on message", b);
221
221
  }
222
222
  };
223
- return this.localWindow.addEventListener("message", s), () => {
224
- this.localWindow.removeEventListener("message", s);
223
+ return this.localWindow.addEventListener("message", n), () => {
224
+ this.localWindow.removeEventListener("message", n);
225
225
  };
226
226
  };
227
- const { localWindow: t } = e;
228
- this.localWindow = t || window;
227
+ const { localWindow: r } = t;
228
+ this.localWindow = r || window;
229
229
  }
230
- send(e, t) {
231
- const n = this.peers.get(e);
232
- n && n.source.postMessage(t, n.origin);
230
+ send(t, r) {
231
+ const s = this.peers.get(t);
232
+ s && s.source.postMessage(r, s.origin);
233
233
  }
234
- broadcast(e) {
235
- this.peers.forEach((t) => {
236
- t.source.postMessage(e, t.origin);
234
+ broadcast(t) {
235
+ this.peers.forEach((r) => {
236
+ r.source.postMessage(t, r.origin);
237
237
  });
238
238
  }
239
- broadcastGroup(e, t) {
240
- e.forEach((n) => {
241
- this.send(n, t);
239
+ broadcastGroup(t, r) {
240
+ t.forEach((s) => {
241
+ this.send(s, r);
242
242
  });
243
243
  }
244
- addPeer(e) {
245
- this.peers.set(e.id, e);
244
+ addPeer(t) {
245
+ this.peers.set(t.id, t);
246
246
  }
247
- removePeer(e) {
248
- this.peers.delete(e);
247
+ removePeer(t) {
248
+ this.peers.delete(t);
249
249
  }
250
- findPeer(e, t) {
251
- for (const [n, s] of this.peers)
252
- if (s.source === e && s.origin === t)
253
- return s;
250
+ findPeer(t, r) {
251
+ for (const [s, n] of this.peers)
252
+ if (n.source === t && n.origin === r)
253
+ return n;
254
254
  return null;
255
255
  }
256
256
  }
257
- class G {
258
- constructor(e) {
257
+ const h = {
258
+ name: "UnknownError",
259
+ message: "Unknown error"
260
+ }, M = (e, t = 3, r = 0) => {
261
+ if (e instanceof Error) {
262
+ const s = r < t && e.cause ? M(e.cause, t, r + 1) : void 0;
263
+ return {
264
+ name: e.name,
265
+ message: e.message,
266
+ stack: e.stack,
267
+ cause: s
268
+ };
269
+ }
270
+ if (typeof e == "string")
271
+ return {
272
+ name: h.name,
273
+ message: e
274
+ };
275
+ if (typeof e == "number" || typeof e == "bigint" || typeof e == "boolean")
276
+ return {
277
+ name: h.name,
278
+ message: String(e)
279
+ };
280
+ if (e && typeof e == "object")
281
+ try {
282
+ return {
283
+ name: h.name,
284
+ message: "message" in e && typeof e.message == "string" && e.message !== "" ? e.message : JSON.stringify(e)
285
+ };
286
+ } catch {
287
+ return {
288
+ name: h.name,
289
+ message: "Unserializable error object"
290
+ };
291
+ }
292
+ return h;
293
+ }, $ = "get", I = (e, t) => {
294
+ var n;
295
+ let r, s;
296
+ return e instanceof Request ? (r = e.url, s = e.method) : e instanceof URL ? r = e.toString() : r = e, {
297
+ method: s || ((n = t == null ? void 0 : t.method) == null ? void 0 : n.toString()) || $,
298
+ url: r
299
+ };
300
+ }, V = (e, t, r) => ({
301
+ statusCode: r.status,
302
+ ...I(e, t)
303
+ }), z = (e) => {
304
+ const t = window.fetch;
305
+ Object.defineProperty(window, "fetch", {
306
+ value: async (s, n) => {
307
+ try {
308
+ const o = new Error("synthetic error"), i = await t(s, n), a = i.clone(), c = V(s, n, a);
309
+ if (i.status >= 500) {
310
+ const u = new Error("fetch response error");
311
+ u.stack = o.stack, e.report({
312
+ kind: "fetchResponseError",
313
+ type: "network",
314
+ data: c,
315
+ error: u
316
+ });
317
+ }
318
+ const {
319
+ arrayBuffer: p,
320
+ blob: b,
321
+ json: k,
322
+ text: N
323
+ } = i;
324
+ return i.json = async function() {
325
+ try {
326
+ return await k.call(this);
327
+ } catch (u) {
328
+ throw e.report({
329
+ type: "network",
330
+ kind: "fetchParseBodyError",
331
+ error: u,
332
+ data: {
333
+ parseType: "json",
334
+ ...c
335
+ }
336
+ }), u;
337
+ }
338
+ }, i.text = async function() {
339
+ try {
340
+ return await N.call(this);
341
+ } catch (u) {
342
+ throw e.report({
343
+ type: "network",
344
+ kind: "fetchParseBodyError",
345
+ error: u,
346
+ data: {
347
+ parseType: "text",
348
+ ...c
349
+ }
350
+ }), u;
351
+ }
352
+ }, i.blob = async function() {
353
+ try {
354
+ return await b.call(this);
355
+ } catch (u) {
356
+ throw e.report({
357
+ type: "network",
358
+ kind: "fetchParseBodyError",
359
+ error: u,
360
+ data: {
361
+ parseType: "blob",
362
+ ...c
363
+ }
364
+ }), u;
365
+ }
366
+ }, i.arrayBuffer = async function() {
367
+ try {
368
+ return await p.call(this);
369
+ } catch (u) {
370
+ throw e.report({
371
+ type: "network",
372
+ kind: "fetchParseBodyError",
373
+ error: u,
374
+ data: {
375
+ parseType: "arrayBuffer",
376
+ ...c
377
+ }
378
+ }), u;
379
+ }
380
+ }, i;
381
+ } catch (o) {
382
+ throw o instanceof Error && o.name === "AbortError" || e.report({
383
+ type: "network",
384
+ kind: "fetchRequestError",
385
+ error: o,
386
+ data: I(s, n)
387
+ }), o;
388
+ }
389
+ },
390
+ configurable: !1,
391
+ writable: !1
392
+ });
393
+ }, K = (e) => {
394
+ window.addEventListener("unhandledrejection", ({ reason: t }) => {
395
+ e.report({
396
+ type: "runtime",
397
+ kind: "unhandledRejection",
398
+ error: t
399
+ });
400
+ }), window.addEventListener("error", ({ colno: t, error: r, filename: s, lineno: n, message: o }) => {
401
+ e.report({
402
+ type: "runtime",
403
+ kind: "uncaughtError",
404
+ error: r,
405
+ data: {
406
+ lineno: n,
407
+ colno: t,
408
+ message: o,
409
+ filename: s
410
+ }
411
+ });
412
+ });
413
+ }, v = Symbol("patchedXHLHttpRequest"), d = Symbol("requestInfo"), J = (e) => ({
414
+ statusCode: e.status,
415
+ ...e[d]
416
+ }), Z = (e) => (e[d] || (e[d] = {}), e[d]), Q = (e) => {
417
+ e[v] = !0;
418
+ }, Y = (e) => e[v] === !0, ee = (e) => {
419
+ const t = XMLHttpRequest.prototype.send, r = XMLHttpRequest.prototype.open, s = function(...o) {
420
+ const [i, a] = o;
421
+ this[d] = {
422
+ method: i,
423
+ url: typeof a == "string" ? a : a.toString()
424
+ }, Y(this) || (Q(this), this.addEventListener("error", () => {
425
+ const c = new Error("XMLHttpRequest network error");
426
+ e.report({
427
+ type: "network",
428
+ kind: "xmlHttpRequestError",
429
+ data: this[d],
430
+ error: c
431
+ });
432
+ }), this.addEventListener("timeout", () => {
433
+ const c = new Error("XMLHttpRequest timeout error");
434
+ e.report({
435
+ type: "network",
436
+ kind: "xmlHttpRequestTimeoutError",
437
+ data: this[d],
438
+ error: c
439
+ });
440
+ }), this.addEventListener("load", () => {
441
+ if (this.status >= 500) {
442
+ const c = new Error("XMLHttpRequest response error");
443
+ e.report({
444
+ type: "network",
445
+ kind: "xmlHttpRequestLoadError",
446
+ data: J(this),
447
+ error: c
448
+ });
449
+ }
450
+ }));
451
+ try {
452
+ r.apply(this, o);
453
+ } catch (c) {
454
+ throw e.report({
455
+ type: "network",
456
+ kind: "xmlHttpRequestOpenError",
457
+ error: c,
458
+ data: this[d]
459
+ }), c;
460
+ }
461
+ }, n = function(o) {
462
+ try {
463
+ const i = Z(this), a = new Error("XMLHttpRequest request initiator");
464
+ i.requestStack = a.stack, t.call(this, o);
465
+ } catch (i) {
466
+ throw e.report({
467
+ type: "network",
468
+ kind: "xmlHttpRequestSendError",
469
+ error: i,
470
+ data: this[d]
471
+ }), i;
472
+ }
473
+ };
474
+ Object.defineProperty(XMLHttpRequest.prototype, "open", {
475
+ value: s,
476
+ configurable: !1,
477
+ writable: !1
478
+ }), Object.defineProperty(XMLHttpRequest.prototype, "send", {
479
+ value: n,
480
+ configurable: !1,
481
+ writable: !1
482
+ });
483
+ };
484
+ let R;
485
+ class te {
486
+ constructor(t) {
487
+ this.onError = t;
488
+ }
489
+ report(t) {
490
+ const { error: r, ...s } = t;
491
+ this.onError({
492
+ ...s,
493
+ error: r ? M(r) : void 0
494
+ });
495
+ }
496
+ init() {
497
+ this.applyIntegrations();
498
+ }
499
+ applyIntegrations() {
500
+ R || (R = !0, K(this), ee(this), z(this));
501
+ }
502
+ }
503
+ class re {
504
+ constructor(t) {
259
505
  const {
260
- serverId: t,
261
- serverOrigin: n,
262
- serverSource: s,
263
- theme: i
264
- } = e, a = {
265
- id: t,
266
- origin: n,
267
- source: s
268
- }, o = new k({});
269
- o.addPeer(a), this.rpcClient = new L({
270
- transport: o,
271
- serverId: t
272
- }), this.subscriber = new T({
273
- transport: o,
274
- brokerId: a.id
275
- }), document.documentElement.dataset.theme = i;
506
+ serverId: r,
507
+ serverOrigin: s,
508
+ serverSource: n,
509
+ theme: o
510
+ } = t, i = {
511
+ id: r,
512
+ origin: s,
513
+ source: n
514
+ }, a = new W({});
515
+ a.addPeer(i), this.rpcClient = new U({
516
+ transport: a,
517
+ serverId: r
518
+ }), this.subscriber = new C({
519
+ transport: a,
520
+ brokerId: i.id
521
+ }), document.documentElement.dataset.theme = o, this.crashReporter = new te((c) => {
522
+ this.makeRequest("v1.system.report.crash", c);
523
+ });
276
524
  }
277
- makeRequest(e, t) {
278
- return this.rpcClient.makeRequest(e, t);
525
+ makeRequest(t, r) {
526
+ return this.rpcClient.makeRequest(t, r);
279
527
  }
280
- subscribe(e, t) {
281
- return this.subscriber.subscribe(e, t);
528
+ subscribe(t, r) {
529
+ return this.subscriber.subscribe(t, r);
282
530
  }
283
- unsubscribe(e, t) {
284
- return this.subscriber.unsubscribe(e, t);
531
+ unsubscribe(t, r) {
532
+ return this.subscriber.unsubscribe(t, r);
285
533
  }
286
534
  bootstrap() {
287
- let e = { height: 0, width: 0 };
288
- const t = () => {
289
- const o = document.body;
535
+ let t = { height: 0, width: 0 };
536
+ const r = () => {
537
+ const a = document.body;
290
538
  return Math.max(
291
- o.offsetHeight,
292
- o.scrollHeight
539
+ a.offsetHeight,
540
+ a.scrollHeight
293
541
  );
294
- }, n = () => {
295
- const o = document.body;
542
+ }, s = () => {
543
+ const a = document.body;
296
544
  return Math.max(
297
- o.offsetWidth,
298
- o.scrollWidth
545
+ a.offsetWidth,
546
+ a.scrollWidth
299
547
  );
300
- }, s = () => {
301
- const o = n(), c = t();
302
- (e.height !== c || e.width !== o) && (e = { height: c, width: o }, this.makeRequest("v1.system.resize.notify", { height: c, width: o }));
548
+ }, n = () => {
549
+ const a = s(), c = r();
550
+ (t.height !== c || t.width !== a) && (t = { height: c, width: a }, this.makeRequest("v1.system.resize.notify", { height: c, width: a }));
303
551
  };
304
- s(), new ResizeObserver(s).observe(document.body), new MutationObserver(s).observe(document.body, {
552
+ n(), new ResizeObserver(n).observe(document.body), new MutationObserver(n).observe(document.body, {
305
553
  childList: !0,
306
554
  subtree: !0,
307
555
  attributes: !0,
308
556
  attributeFilter: ["style", "class", "hidden", "open"]
309
- });
557
+ }), this.crashReporter.init();
310
558
  }
311
559
  }
312
- const x = () => {
313
- const r = new URL(window.location.href), e = r.searchParams.get("origin") || "", t = r.searchParams.get("theme") || "dark", n = new G({
560
+ const se = () => {
561
+ const e = new URL(window.location.href), t = e.searchParams.get("origin") || "", r = e.searchParams.get("theme") || "dark", s = new re({
314
562
  serverId: "server",
315
- serverOrigin: e || window.parent.origin,
563
+ serverOrigin: t || window.parent.origin,
316
564
  serverSource: window.parent,
317
- theme: t
565
+ theme: r
318
566
  });
319
- return n.bootstrap(), n;
567
+ return s.bootstrap(), s;
320
568
  };
321
569
  export {
322
- x as createExtHelper
570
+ se as createExtHelper
323
571
  };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export declare const createExtHelper: () => ExtHelper;
3
3
  declare class ExtHelper {
4
4
  private rpcClient;
5
5
  private subscriber;
6
+ private crashReporter;
6
7
  constructor(props: TExtHelperProps);
7
8
  makeRequest<M extends Extract<keyof TApiContract['methods'], string>>(method: M, params: TApiContract['methods'][M]['params']): Promise<TV1Methods[M]["result"]>;
8
9
  subscribe<E extends Extract<keyof TApiContract['events'], string>>(eventName: E, handler: TAnyPubSubHandler<TApiContract['events'][E]>): void;
@@ -99,7 +100,7 @@ declare type TV1ChatMethods = {
99
100
  };
100
101
  };
101
102
 
102
- export declare type TV1Events = TV1ExtEvents & TV1PaymentEvents & TV1ModelEvents;
103
+ export declare type TV1Events = TV1ExtEvents & TV1PaymentEvents & TV1ModelEvents & TV1TipEvents;
103
104
 
104
105
  export declare type TV1ExtContext = {
105
106
  model?: TV1ExtModel;
@@ -226,17 +227,12 @@ export declare type TV1ExtUser = {
226
227
  /** User username. */
227
228
  username: string;
228
229
  /** User activity ranking data when available. */
229
- userRanking?: {
230
- /** League representation of the user's activity level. Could be `grey`, `bronze`, `silver`, `gold`, `diamond`, `royal` or `legend`. */
231
- league: TV1UserLeague;
232
- /** Activity level from 1 to 100. */
233
- level: number;
234
- };
230
+ userRanking?: TV1UserRanking;
235
231
  };
236
232
 
237
233
  export declare type TV1Genders = 'male' | 'female' | 'group' | 'tranny';
238
234
 
239
- export declare type TV1Methods = TV1ExtMethods & TV1SystemMethods & TV1PaymentMethods & TV1ModelMethods & TV1ChatMethods & TV1PrivateMethods;
235
+ export declare type TV1Methods = TV1ExtMethods & TV1SystemMethods & TV1PaymentMethods & TV1ModelMethods & TV1ChatMethods & TV1PrivateMethods & TV1MonitoringMethods;
240
236
 
241
237
  declare type TV1ModelEvents = {
242
238
  'v1.model.ext.settings.set.requested': null;
@@ -260,6 +256,23 @@ declare type TV1ModelMethods = {
260
256
 
261
257
  export declare type TV1ModelStatus = Exclude<(typeof V1_SHOW_STATUSES)[keyof typeof V1_SHOW_STATUSES], 'spy'>;
262
258
 
259
+ declare type TV1MonitoringMethods = {
260
+ 'v1.monitoring.report.error': {
261
+ params: {
262
+ data: unknown;
263
+ message: string;
264
+ };
265
+ result: null;
266
+ };
267
+ 'v1.monitoring.report.log': {
268
+ params: {
269
+ data: unknown;
270
+ message: string;
271
+ };
272
+ result: null;
273
+ };
274
+ };
275
+
263
276
  declare type TV1PaymentEvents = {
264
277
  'v1.payment.tokens.spend.succeeded': {
265
278
  isAnonymous: boolean;
@@ -285,7 +298,23 @@ declare type TV1PrivateMethods = {
285
298
  };
286
299
  };
287
300
 
301
+ declare type TV1SerializedError = {
302
+ cause?: TV1SerializedError;
303
+ message: string;
304
+ name: string;
305
+ stack?: string;
306
+ };
307
+
288
308
  declare type TV1SystemMethods = {
309
+ 'v1.system.report.crash': {
310
+ params: {
311
+ data?: Record<string, unknown>;
312
+ error?: TV1SerializedError;
313
+ kind: string;
314
+ type: 'network' | 'runtime';
315
+ };
316
+ result: null;
317
+ };
289
318
  'v1.system.resize.notify': {
290
319
  params: {
291
320
  height: number;
@@ -295,6 +324,61 @@ declare type TV1SystemMethods = {
295
324
  };
296
325
  };
297
326
 
327
+ export declare type TV1TipData = {
328
+ /** Amount of tokens spent */
329
+ amount: number;
330
+ /** Is anonymous tip or not */
331
+ isAnonymous: boolean;
332
+ /** Is tip sent from the current user or not */
333
+ isFromTheCurrentUser: boolean;
334
+ /** Is tip sent from the current extension or not */
335
+ isOriginalSource: boolean;
336
+ /** Message that was sent with the tip. Empty string if no message was sent */
337
+ message?: string;
338
+ /** Source of the tip. Could be one of the following:
339
+ *
340
+ * `console` - tip was sent using / command
341
+ * `tipMenu` - tip was sent using tip menu
342
+ * `goal` - tip was sent via goal button
343
+ * `epicGoal` - tip was sent to epic goal
344
+ * `fullscreen` - tip was sent from the fullscreen view
345
+ * `interactiveToy` - tip was sent from the interactive toy
346
+ * `privateChat` - tip was sent from the private chat, in any type of show
347
+ * `publicChat` - tip was sent using publich chat, either in public or group show.
348
+ * `extension` - tip was sent from one of the extensions
349
+ * `sendTipButton` - tip was sent using send tip button
350
+ * `feed` - tip was sent from the feed
351
+ * */
352
+ source: TV1TipSource;
353
+ /** Determins whether tip was sent in public or private chat */
354
+ type: 'private' | 'public';
355
+ /** User who sent the tip. Can be null in case of anonymous tip */
356
+ user?: TV1ExtUser | null;
357
+ };
358
+
359
+ declare type TV1TipEvents = {
360
+ /** Fired on every tip in chat for both model and user. Doesn't fire on private tips during public shows */
361
+ 'v1.tokens.spent': {
362
+ tipData: TV1TipData;
363
+ };
364
+ };
365
+
366
+ /** Source of the tip. Could be one of the following:
367
+ *
368
+ * `console` - tip was sent using / command
369
+ * `tipMenu` - tip was sent using tip menu
370
+ * `goal` - tip was sent via goal button
371
+ * `epicGoal` - tip was sent to epic goal
372
+ * `fullscreen` - tip was sent from the fullscreen view
373
+ * `interactiveToy` - tip was sent from the interactive toy
374
+ * `privateChat` - tip was sent from the private chat, in any type of show
375
+ * `publicChat` - tip was sent using publich chat, either in public or group show.
376
+ * `extension` - tip was sent from one of the extensions
377
+ * `sendTipButton` - tip was sent using send tip button
378
+ * `feed` - tip was sent from the feed
379
+ */
380
+ declare type TV1TipSource = 'console' | 'tipMenu' | 'goal' | 'epicGoal' | 'fullscreen' | 'interactiveToy' | 'publicChat' | 'privateChat' | 'extension' | 'sendTipButton' | 'feed';
381
+
298
382
  export declare type TV1TokenSpendData = TUnknownDictionary;
299
383
 
300
384
  /**
@@ -309,6 +393,14 @@ export declare type TV1TokenSpendData = TUnknownDictionary;
309
393
  */
310
394
  declare type TV1UserLeague = 'grey' | 'bronze' | 'silver' | 'gold' | 'diamond' | 'royal' | 'legend';
311
395
 
396
+ /** User activity ranking system */
397
+ export declare type TV1UserRanking = {
398
+ /** League representation of the user's activity level. Could be `grey`, `bronze`, `silver`, `gold`, `diamond`, `royal` or `legend`. */
399
+ league: TV1UserLeague;
400
+ /** Activity level from 1 to 100. */
401
+ level: number;
402
+ };
403
+
312
404
  export declare type TV1UserStatus = Exclude<(typeof V1_SHOW_STATUSES)[keyof typeof V1_SHOW_STATUSES], 'idle'>;
313
405
 
314
406
  export declare type TV1WhisperData = TUnknownDictionary;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stripchatdev/ext-helper",
3
3
  "private": false,
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "type": "module",
6
6
  "module": "./dist/ext-helper.js",
7
7
  "types": "./dist/index.d.ts",