@stripchatdev/ext-helper 0.1.31 → 0.1.33

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,130 +1,130 @@
1
- const S = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "iframe_pubsub" && "version" in e && e.version === "1.0", b = (e, t) => e, w = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
2
- var l;
1
+ const q = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_pubsub" && "version" in e && e.version === "1.0", R = (e) => e, N = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
2
+ var h;
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
- })(l || (l = {}));
6
- class f extends Error {
5
+ })(h || (h = {}));
6
+ class m extends Error {
7
7
  constructor(t, r) {
8
8
  super(`${r} (${t})`), this.name = "ULIDError", this.code = t;
9
9
  }
10
10
  }
11
11
  function T(e) {
12
12
  const t = Math.floor(e() * 32) % 32;
13
- return w.charAt(t);
13
+ return N.charAt(t);
14
14
  }
15
- function _(e) {
16
- const t = O(), r = t && (t.crypto || t.msCrypto) || null;
15
+ function O(e) {
16
+ const t = P(), r = t && (t.crypto || t.msCrypto) || null;
17
17
  if (typeof (r == null ? void 0 : r.getRandomValues) == "function")
18
18
  return () => {
19
- const n = new Uint8Array(1);
20
- return r.getRandomValues(n), n[0] / 255;
19
+ const s = new Uint8Array(1);
20
+ return r.getRandomValues(s), s[0] / 255;
21
21
  };
22
22
  if (typeof (r == null ? void 0 : r.randomBytes) == "function")
23
23
  return () => r.randomBytes(1).readUInt8() / 255;
24
- throw new f(l.PRNGDetectFailure, "Failed to find a reliable PRNG");
24
+ throw new m(h.PRNGDetectFailure, "Failed to find a reliable PRNG");
25
25
  }
26
- function O() {
27
- return q() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
26
+ function P() {
27
+ return x() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
28
28
  }
29
- function P(e, t) {
29
+ function H(e, t) {
30
30
  let r = "";
31
31
  for (; e > 0; e--)
32
32
  r = T(t) + r;
33
33
  return r;
34
34
  }
35
- function H(e, t = 10) {
35
+ function L(e, t = 10) {
36
36
  if (isNaN(e))
37
- throw new f(l.EncodeTimeValueMalformed, `Time must be a number: ${e}`);
37
+ throw new m(h.EncodeTimeValueMalformed, `Time must be a number: ${e}`);
38
38
  if (e > 281474976710655)
39
- throw new f(l.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${281474976710655}: ${e}`);
39
+ throw new m(h.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${281474976710655}: ${e}`);
40
40
  if (e < 0)
41
- throw new f(l.EncodeTimeNegative, `Time must be positive: ${e}`);
41
+ throw new m(h.EncodeTimeNegative, `Time must be positive: ${e}`);
42
42
  if (Number.isInteger(e) === !1)
43
- throw new f(l.EncodeTimeValueMalformed, `Time must be an integer: ${e}`);
44
- let r, n = "";
45
- for (let s = t; s > 0; s--)
46
- r = e % 32, n = w.charAt(r) + n, e = (e - r) / 32;
47
- return n;
43
+ throw new m(h.EncodeTimeValueMalformed, `Time must be an integer: ${e}`);
44
+ let r, s = "";
45
+ for (let o = t; o > 0; o--)
46
+ r = e % 32, s = N.charAt(r) + s, e = (e - r) / 32;
47
+ return s;
48
48
  }
49
- function q() {
49
+ function x() {
50
50
  return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
51
51
  }
52
- function E(e, t) {
53
- const r = _(), n = Date.now();
54
- return H(n, 10) + P(16, r);
52
+ function g(e, t) {
53
+ const r = t || O(), s = !e || isNaN(e) ? Date.now() : e;
54
+ return L(s, 10) + H(16, r);
55
55
  }
56
- const L = ({ seq: e, uniqId: t }) => (r) => ({
56
+ const A = ({ seq: e, uniqId: t }) => (r) => ({
57
57
  ...{
58
- protocol: "iframe_pubsub",
58
+ protocol: "platform_pubsub",
59
59
  version: "1.0",
60
60
  id: t(),
61
61
  seq: e(),
62
62
  timestamp: Date.now()
63
63
  },
64
64
  ...r
65
- }), y = L({
66
- uniqId: () => E(),
67
- seq: () => E()
65
+ }), w = A({
66
+ uniqId: () => g(),
67
+ seq: () => g()
68
68
  });
69
- class A {
69
+ class C {
70
70
  constructor(t) {
71
- this.eventHandlerMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (s, o) => {
72
- if (S(s)) {
73
- if (s.type === "event") {
74
- const { eventName: i } = s, a = this.eventHandlerMap.get(i);
75
- if (!a)
71
+ this.eventHandlerMap = /* @__PURE__ */ new Map(), this.transportMessageHandler = (o) => {
72
+ const { data: n, senderId: a } = o;
73
+ if (q(n)) {
74
+ if (n.type === "event") {
75
+ const { eventName: i } = n, c = this.eventHandlerMap.get(i);
76
+ if (!c)
76
77
  return;
77
- a.forEach((c) => {
78
+ c.forEach((l) => {
78
79
  try {
79
- c(s.data, o.id);
80
- } catch (h) {
81
- console.error("[PubSubSubscriber] globalMessageHandler: failed to handle income message", h);
80
+ l(n.data, a);
81
+ } catch (p) {
82
+ console.error("[PubSubSubscriber] transportMessageHandler: failed to handle income message", p);
82
83
  }
83
84
  });
84
85
  return;
85
86
  }
86
- console.error("[PubSubSubscriber] globalMessageHandler: unhandled message", s);
87
+ console.error("[PubSubSubscriber] transportMessageHandler: unhandled message", n);
87
88
  }
88
89
  };
89
- const { brokerId: r, transport: n } = t;
90
- this.brokerId = r, this.transport = n, this.transport.onMessage(this.globalMessageHandler);
90
+ const { brokerId: r, transport: s } = t;
91
+ this.brokerId = r, this.transport = s, this.transport.onMessage(this.transportMessageHandler);
91
92
  }
92
93
  subscribe(t, r) {
93
- const n = b(t);
94
- let s = this.eventHandlerMap.get(n);
95
- s || (s = /* @__PURE__ */ new Set(), this.eventHandlerMap.set(n, s)), s.add(r);
96
- const o = y({
94
+ const s = R(t);
95
+ let o = this.eventHandlerMap.get(s);
96
+ o || (o = /* @__PURE__ */ new Set(), this.eventHandlerMap.set(s, o)), o.add(r);
97
+ const n = w({
97
98
  type: "subscribe",
98
99
  eventName: t
99
100
  });
100
- this.transport.send(this.brokerId, o);
101
+ this.transport.send(this.brokerId, n);
101
102
  }
102
103
  unsubscribe(t, r) {
103
- const n = b(t);
104
- let s = this.eventHandlerMap.get(n);
105
- if (!s)
106
- return;
107
- r ? s.delete(r) : this.eventHandlerMap.delete(n);
108
- const o = y({
109
- type: "unsubscribe",
110
- eventName: t
111
- });
112
- this.transport.send(this.brokerId, o);
104
+ const s = R(t);
105
+ let o = this.eventHandlerMap.get(s);
106
+ if (o && (r ? (o.delete(r), o.size || this.eventHandlerMap.delete(s)) : this.eventHandlerMap.delete(s), !this.eventHandlerMap.has(s))) {
107
+ const n = w({
108
+ type: "unsubscribe",
109
+ eventName: t
110
+ });
111
+ this.transport.send(this.brokerId, n);
112
+ }
113
113
  }
114
114
  }
115
- const x = !!Error.captureStackTrace, C = "APP_ERROR";
116
- class g extends Error {
115
+ const D = !!Error.captureStackTrace, j = "APP_ERROR";
116
+ class E extends Error {
117
117
  constructor(t, r) {
118
- super(t), this.name = new.target.name || C, this.cause = r, x && Error.captureStackTrace(this, this.constructor);
118
+ super(t), this.name = new.target.name || j, this.cause = r, D && Error.captureStackTrace(this, this.constructor);
119
119
  }
120
120
  static serializeCause(t) {
121
- return t instanceof g ? t.toJSON() : t instanceof Error ? { name: t.name, message: t.message } : t !== null && typeof t == "object" ? t : String(t);
121
+ return t instanceof E ? 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 ? g.serializeCause(this.cause) : void 0
127
+ cause: this.cause ? E.serializeCause(this.cause) : void 0
128
128
  };
129
129
  }
130
130
  toString() {
@@ -136,12 +136,12 @@ class g extends Error {
136
136
  }
137
137
  }
138
138
  }
139
- const D = {
139
+ const F = {
140
140
  INTERNAL_ERROR: "INTERNAL_ERROR"
141
- }, j = "RPC_ERROR";
142
- class G extends g {
141
+ }, G = "RPC_ERROR";
142
+ class z extends E {
143
143
  constructor(t) {
144
- super(t.message || "rpc error", t.cause), this.name = j, this.code = (t == null ? void 0 : t.code) || D.INTERNAL_ERROR, this.method = t.method, this.params = t.params;
144
+ super(t.message || "rpc error", t.cause), this.name = G, this.code = (t == null ? void 0 : t.code) || F.INTERNAL_ERROR, this.method = t.method, this.params = t.params;
145
145
  }
146
146
  toJSON() {
147
147
  return {
@@ -152,92 +152,101 @@ class G extends g {
152
152
  };
153
153
  }
154
154
  }
155
- const F = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "iframe_rpc" && "version" in e && e.version === "1.0", B = ({ uniqId: e }) => (t) => ({
155
+ const B = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_rpc" && "version" in e && e.version === "1.0", X = ({ uniqId: e }) => (t) => ({
156
156
  ...{
157
- protocol: "iframe_rpc",
157
+ requestId: e(),
158
+ protocol: "platform_rpc",
158
159
  version: "1.0",
159
- id: e(),
160
160
  timestamp: Date.now()
161
161
  },
162
162
  ...t
163
- }), z = B({
164
- uniqId: () => E()
163
+ }), $ = X({
164
+ uniqId: () => g()
165
165
  });
166
- class X {
166
+ class W {
167
167
  constructor(t) {
168
- this.pendingEntryMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (s) => {
169
- if (F(s)) {
170
- if (s.type === "response" && s.status === "ok") {
171
- const o = s.id, i = this.pendingEntryMap.get(o);
172
- if (!i) {
173
- console.error("[RpcClient] globalMessageHandler: got success response without pending request", s);
168
+ this.pendingEntryMap = /* @__PURE__ */ new Map(), this.transportMessageHandler = (o) => {
169
+ const { data: n } = o;
170
+ if (B(n)) {
171
+ if (n.type === "response" && n.status === "ok") {
172
+ const a = this.pendingEntryMap.get(n.requestId);
173
+ if (!a) {
174
+ console.error("[RpcClient] transportMessageHandler: got success response without pending request", n);
174
175
  return;
175
176
  }
176
- this.pendingEntryMap.delete(o), i.resolve(s.result);
177
+ this.pendingEntryMap.delete(n.requestId), a.resolve(n.result);
177
178
  return;
178
179
  }
179
- if (s.type === "response" && s.status === "error") {
180
- const o = s.id, i = this.pendingEntryMap.get(o);
181
- if (!i) {
182
- console.error("[RpcClient] globalMessageHandler: got error response without pending request", s);
180
+ if (n.type === "response" && n.status === "error") {
181
+ const a = this.pendingEntryMap.get(n.requestId);
182
+ if (!a) {
183
+ console.error("[RpcClient] transportMessageHandler: got error response without pending request", n);
183
184
  return;
184
185
  }
185
- this.pendingEntryMap.delete(o), i.reject(new G(s.error));
186
+ this.pendingEntryMap.delete(n.requestId), a.reject(new z(n.error));
186
187
  return;
187
188
  }
188
- console.error("[RpcClient] globalMessageHandler: invalid message schema", s);
189
+ console.error("[RpcClient] transportMessageHandler: invalid message schema", n);
189
190
  }
190
191
  };
191
- const { serverId: r, transport: n } = t;
192
- this.serverId = r, this.transport = n, this.transport.onMessage(this.globalMessageHandler);
192
+ const { serverId: r, transport: s } = t;
193
+ this.serverId = r, this.transport = s, this.transport.onMessage(this.transportMessageHandler);
193
194
  }
194
195
  makeRequest(t, r) {
195
- const n = z({
196
+ const s = $({
196
197
  type: "request",
197
198
  method: t,
198
199
  params: r
199
- }), s = new Promise((o, i) => {
200
- this.pendingEntryMap.set(n.id, {
200
+ }), o = new Promise((n, a) => {
201
+ this.pendingEntryMap.set(s.requestId, {
201
202
  method: t,
202
- resolve: (a) => {
203
- o(a);
203
+ resolve: (i) => {
204
+ n(i);
204
205
  },
205
- reject: (a) => {
206
- i(a);
206
+ reject: (i) => {
207
+ a(i);
207
208
  }
208
209
  });
209
210
  });
210
211
  try {
211
- this.transport.send(this.serverId, n);
212
- } catch (o) {
213
- console.error("[RpcClient] makeRequest: failed to send rpc message", o);
214
- const i = this.pendingEntryMap.get(n.id);
215
- i && (this.pendingEntryMap.delete(n.id), i.reject(o));
212
+ this.transport.send(this.serverId, s);
213
+ } catch (n) {
214
+ console.error("[RpcClient] makeRequest: failed to send rpc message", n);
215
+ const a = this.pendingEntryMap.get(s.requestId);
216
+ a && (this.pendingEntryMap.delete(s.requestId), a.reject(n));
216
217
  }
217
- return s;
218
+ return o;
218
219
  }
219
220
  }
220
- class W {
221
+ const J = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_transport" && "version" in e && e.version === "1.0", V = ({ uniqId: e }) => (t) => ({
222
+ messageId: e(),
223
+ protocol: "platform_transport",
224
+ version: "1.0",
225
+ ...t
226
+ }), I = V({
227
+ uniqId: g
228
+ });
229
+ class U {
221
230
  constructor(t) {
222
- this.peers = /* @__PURE__ */ new Map(), this.handlers = /* @__PURE__ */ new Set(), this.onMessage = (n) => {
223
- const s = (o) => {
224
- const { data: i, origin: a, source: c } = o;
225
- if (!c)
231
+ this.peers = /* @__PURE__ */ new Map(), this.handlers = /* @__PURE__ */ new Set(), this.onMessage = (o) => {
232
+ const n = (a) => {
233
+ const { data: i, origin: c, source: l } = a;
234
+ if (!l || !J(i))
226
235
  return;
227
- const h = this.findPeer(c, a);
228
- if (h)
236
+ const { recipientId: p } = i;
237
+ if (!(p !== this.transportId || !this.findPeer(l, c)))
229
238
  try {
230
- n(i, h);
231
- } catch (m) {
232
- console.error("[PostMessageTransport] onMessage: failed to call cb on message", m);
239
+ o(i);
240
+ } catch (y) {
241
+ console.error("[PostMessageTransport] onMessage: failed to call cb on message", y);
233
242
  }
234
243
  };
235
- return this.localWindow.addEventListener("message", s), this.handlers.add(s), () => {
236
- this.localWindow.removeEventListener("message", s), this.handlers.delete(s);
244
+ return this.localWindow.addEventListener("message", n), this.handlers.add(n), () => {
245
+ this.localWindow.removeEventListener("message", n), this.handlers.delete(n);
237
246
  };
238
247
  };
239
- const { localWindow: r } = t;
240
- this.localWindow = r || window;
248
+ const { localWindow: r, transportId: s } = t;
249
+ this.transportId = s, this.localWindow = r || window;
241
250
  }
242
251
  destroy() {
243
252
  this.handlers.forEach((t) => {
@@ -245,17 +254,29 @@ class W {
245
254
  });
246
255
  }
247
256
  send(t, r) {
248
- const n = this.peers.get(t);
249
- n && n.source.postMessage(r, n.origin);
257
+ const s = this.peers.get(t);
258
+ if (s) {
259
+ const o = I({
260
+ data: r,
261
+ senderId: this.transportId,
262
+ recipientId: s.id
263
+ });
264
+ s.source.postMessage(o, s.origin);
265
+ }
250
266
  }
251
267
  broadcast(t) {
252
268
  this.peers.forEach((r) => {
253
- r.source.postMessage(t, r.origin);
269
+ const s = I({
270
+ data: t,
271
+ senderId: this.transportId,
272
+ recipientId: r.id
273
+ });
274
+ r.source.postMessage(s, r.origin);
254
275
  });
255
276
  }
256
277
  broadcastGroup(t, r) {
257
- t.forEach((n) => {
258
- this.send(n, r);
278
+ t.forEach((s) => {
279
+ this.send(s, r);
259
280
  });
260
281
  }
261
282
  addPeer(t) {
@@ -265,52 +286,52 @@ class W {
265
286
  this.peers.delete(t);
266
287
  }
267
288
  findPeer(t, r) {
268
- for (const [n, s] of this.peers)
269
- if (s.source === t && s.origin === r)
270
- return s;
289
+ for (const [s, o] of this.peers)
290
+ if (o.source === t && o.origin === r)
291
+ return o;
271
292
  return null;
272
293
  }
273
294
  }
274
- const p = {
295
+ const f = {
275
296
  name: "unknownError",
276
297
  message: "unknown error"
277
- }, M = (e, t = 3, r = 0) => {
298
+ }, k = (e, t = 3, r = 0) => {
278
299
  if (e instanceof Error) {
279
- const n = r < t && e.cause ? M(e.cause, t, r + 1) : void 0;
300
+ const s = r < t && e.cause ? k(e.cause, t, r + 1) : void 0;
280
301
  return {
281
302
  name: e.name,
282
303
  message: e.message,
283
304
  stack: e.stack,
284
- cause: n
305
+ cause: s
285
306
  };
286
307
  }
287
308
  if (typeof e == "string")
288
309
  return {
289
- name: p.name,
310
+ name: f.name,
290
311
  message: e
291
312
  };
292
313
  if (typeof e == "number" || typeof e == "bigint" || typeof e == "boolean")
293
314
  return {
294
- name: p.name,
315
+ name: f.name,
295
316
  message: String(e)
296
317
  };
297
318
  if (e && typeof e == "object")
298
319
  try {
299
320
  return {
300
- name: p.name,
321
+ name: f.name,
301
322
  message: "message" in e && typeof e.message == "string" && e.message !== "" ? e.message : JSON.stringify(e)
302
323
  };
303
324
  } catch {
304
325
  return {
305
- name: p.name,
326
+ name: f.name,
306
327
  message: "failed to serialize error: unserializable error object"
307
328
  };
308
329
  }
309
- return p;
310
- }, I = (e) => {
330
+ return f;
331
+ }, S = (e) => {
311
332
  const t = [];
312
333
  if (e instanceof Error)
313
- t.push(e.message), "cause" in e && t.push(I(e.cause));
334
+ t.push(e.message), "cause" in e && t.push(S(e.cause));
314
335
  else
315
336
  try {
316
337
  const r = JSON.stringify(e);
@@ -319,7 +340,7 @@ const p = {
319
340
  t.push("failed to get chained error message: unserializable error object");
320
341
  }
321
342
  return t.join(":");
322
- }, $ = [
343
+ }, K = [
323
344
  // browser internals — harmless noise
324
345
  /resizeObserver loop/ig,
325
346
  // cross-origin script errors with zero useful info
@@ -342,31 +363,31 @@ const p = {
342
363
  // generic network noise already captured by fetch/xhr integrations
343
364
  /networkError when attempting to fetch resource/ig,
344
365
  /load failed/ig
345
- ], J = (e) => $.some((t) => (t.lastIndex = 0, t.test(e))), V = (e) => {
346
- const t = I(e.error), r = typeof e.data == "object" && "message" in e.data && typeof e.data.message == "string" ? e.data.message : "";
347
- return [t, r].filter((n) => !!n).join(":");
348
- }, U = (e) => e.data && typeof e.data == "object" && "filename" in e.data ? String(e.data.filename ?? "") : "", K = (e) => {
349
- const t = V(e), r = U(e);
350
- return r && /^(chrome|moz|safari)-extension:\/\//.test(r) ? !0 : !!t && J(t);
351
- }, Z = "get", Q = (e, t) => {
352
- var s;
353
- let r, n;
354
- return e instanceof Request ? (r = e.url, n = e.method) : e instanceof URL ? r = e.toString() : r = e, {
355
- method: n || ((s = t == null ? void 0 : t.method) == null ? void 0 : s.toString()) || Z,
366
+ ], Z = (e) => K.some((t) => (t.lastIndex = 0, t.test(e))), Q = (e) => {
367
+ const t = S(e.error), r = typeof e.data == "object" && "message" in e.data && typeof e.data.message == "string" ? e.data.message : "";
368
+ return [t, r].filter((s) => !!s).join(":");
369
+ }, Y = (e) => e.data && typeof e.data == "object" && "filename" in e.data ? String(e.data.filename ?? "") : "", ee = (e) => {
370
+ const t = Q(e), r = Y(e);
371
+ return r && /^(chrome|moz|safari)-extension:\/\//.test(r) ? !0 : !!t && Z(t);
372
+ }, te = "get", re = (e, t) => {
373
+ var o;
374
+ let r, s;
375
+ return e instanceof Request ? (r = e.url, s = e.method) : e instanceof URL ? r = e.toString() : r = e, {
376
+ method: s || ((o = t == null ? void 0 : t.method) == null ? void 0 : o.toString()) || te,
356
377
  url: r
357
378
  };
358
- }, Y = (e, t, r) => ({
379
+ }, se = (e, t, r) => ({
359
380
  statusCode: r.status,
360
- ...Q(e, t)
361
- }), ee = (e) => {
381
+ ...re(e, t)
382
+ }), ne = (e) => {
362
383
  const t = window.fetch;
363
384
  Object.defineProperty(window, "fetch", {
364
- value: async (n, s) => {
385
+ value: async (s, o) => {
365
386
  try {
366
- const o = new Error("synthetic error"), i = await t(n, s), a = i.clone(), c = Y(n, s, a);
367
- if (i.status >= 500) {
387
+ const n = new Error("synthetic error"), a = await t(s, o), i = a.clone(), c = se(s, o, i);
388
+ if (a.status >= 500) {
368
389
  const d = new Error("fetch response error");
369
- d.stack = o.stack, e.report({
390
+ d.stack = n.stack, e.report({
370
391
  kind: "fetchResponseError",
371
392
  type: "network",
372
393
  data: c,
@@ -374,14 +395,14 @@ const p = {
374
395
  });
375
396
  }
376
397
  const {
377
- arrayBuffer: h,
378
- blob: m,
379
- json: N,
380
- text: k
381
- } = i;
382
- return i.json = async function() {
398
+ arrayBuffer: l,
399
+ blob: p,
400
+ json: b,
401
+ text: y
402
+ } = a;
403
+ return a.json = async function() {
383
404
  try {
384
- return await N.call(this);
405
+ return await b.call(this);
385
406
  } catch (d) {
386
407
  throw e.report({
387
408
  type: "network",
@@ -393,9 +414,9 @@ const p = {
393
414
  }
394
415
  }), d;
395
416
  }
396
- }, i.text = async function() {
417
+ }, a.text = async function() {
397
418
  try {
398
- return await k.call(this);
419
+ return await y.call(this);
399
420
  } catch (d) {
400
421
  throw e.report({
401
422
  type: "network",
@@ -407,9 +428,9 @@ const p = {
407
428
  }
408
429
  }), d;
409
430
  }
410
- }, i.blob = async function() {
431
+ }, a.blob = async function() {
411
432
  try {
412
- return await m.call(this);
433
+ return await p.call(this);
413
434
  } catch (d) {
414
435
  throw e.report({
415
436
  type: "network",
@@ -421,9 +442,9 @@ const p = {
421
442
  }
422
443
  }), d;
423
444
  }
424
- }, i.arrayBuffer = async function() {
445
+ }, a.arrayBuffer = async function() {
425
446
  try {
426
- return await h.call(this);
447
+ return await l.call(this);
427
448
  } catch (d) {
428
449
  throw e.report({
429
450
  type: "network",
@@ -435,46 +456,46 @@ const p = {
435
456
  }
436
457
  }), d;
437
458
  }
438
- }, i;
439
- } catch (o) {
440
- throw o instanceof Error && o.name === "AbortError", o;
459
+ }, a;
460
+ } catch (n) {
461
+ throw n instanceof Error && n.name === "AbortError", n;
441
462
  }
442
463
  },
443
464
  configurable: !0,
444
465
  writable: !0
445
466
  });
446
- }, te = (e) => {
467
+ }, oe = (e) => {
447
468
  window.addEventListener("unhandledrejection", ({ reason: t }) => {
448
469
  e.report({
449
470
  type: "runtime",
450
471
  kind: "unhandledRejection",
451
472
  error: t
452
473
  });
453
- }), window.addEventListener("error", ({ colno: t, error: r, filename: n, lineno: s, message: o }) => {
474
+ }), window.addEventListener("error", ({ colno: t, error: r, filename: s, lineno: o, message: n }) => {
454
475
  e.report({
455
476
  type: "runtime",
456
477
  kind: "uncaughtError",
457
478
  error: r,
458
479
  data: {
459
- lineno: s,
480
+ lineno: o,
460
481
  colno: t,
461
- message: o,
462
- filename: n
482
+ message: n,
483
+ filename: s
463
484
  }
464
485
  });
465
486
  });
466
- }, v = Symbol("patchedXHLHttpRequest"), u = Symbol("requestInfo"), re = (e) => ({
487
+ }, _ = Symbol("patchedXHLHttpRequest"), u = Symbol("requestInfo"), ae = (e) => ({
467
488
  statusCode: e.status,
468
489
  ...e[u]
469
- }), ne = (e) => (e[u] || (e[u] = {}), e[u]), se = (e) => {
470
- e[v] = !0;
471
- }, oe = (e) => e[v] === !0, ie = (e) => {
472
- const t = XMLHttpRequest.prototype.send, r = XMLHttpRequest.prototype.open, n = function(...o) {
473
- const [i, a] = o;
490
+ }), ie = (e) => (e[u] || (e[u] = {}), e[u]), ce = (e) => {
491
+ e[_] = !0;
492
+ }, de = (e) => e[_] === !0, ue = (e) => {
493
+ const t = XMLHttpRequest.prototype.send, r = XMLHttpRequest.prototype.open, s = function(...n) {
494
+ const [a, i] = n;
474
495
  this[u] = {
475
- method: i,
476
- url: typeof a == "string" ? a : a.toString()
477
- }, oe(this) || (se(this), this.addEventListener("error", () => {
496
+ method: a,
497
+ url: typeof i == "string" ? i : i.toString()
498
+ }, de(this) || (ce(this), this.addEventListener("error", () => {
478
499
  const c = new Error("XMLHttpRequest network error");
479
500
  e.report({
480
501
  type: "network",
@@ -496,13 +517,13 @@ const p = {
496
517
  e.report({
497
518
  type: "network",
498
519
  kind: "xmlHttpRequestLoadError",
499
- data: re(this),
520
+ data: ae(this),
500
521
  error: c
501
522
  });
502
523
  }
503
524
  }));
504
525
  try {
505
- r.apply(this, o);
526
+ r.apply(this, n);
506
527
  } catch (c) {
507
528
  throw e.report({
508
529
  type: "network",
@@ -511,70 +532,73 @@ const p = {
511
532
  data: this[u]
512
533
  }), c;
513
534
  }
514
- }, s = function(o) {
535
+ }, o = function(n) {
515
536
  try {
516
- const i = ne(this), a = new Error("XMLHttpRequest request initiator");
517
- i.requestStack = a.stack, t.call(this, o);
518
- } catch (i) {
537
+ const a = ie(this), i = new Error("XMLHttpRequest request initiator");
538
+ a.requestStack = i.stack, t.call(this, n);
539
+ } catch (a) {
519
540
  throw e.report({
520
541
  type: "network",
521
542
  kind: "xmlHttpRequestSendError",
522
- error: i,
543
+ error: a,
523
544
  data: this[u]
524
- }), i;
545
+ }), a;
525
546
  }
526
547
  };
527
548
  Object.defineProperty(XMLHttpRequest.prototype, "open", {
528
- value: n,
549
+ value: s,
529
550
  configurable: !0,
530
551
  writable: !0
531
552
  }), Object.defineProperty(XMLHttpRequest.prototype, "send", {
532
- value: s,
553
+ value: o,
533
554
  configurable: !0,
534
555
  writable: !0
535
556
  });
536
557
  };
537
- let R;
538
- class ae {
558
+ let M;
559
+ class le {
539
560
  constructor(t) {
540
561
  this.onError = t;
541
562
  }
542
563
  report(t) {
543
- if (K(t))
564
+ if (ee(t))
544
565
  return;
545
- const { error: r, ...n } = t;
566
+ const { error: r, ...s } = t;
546
567
  this.onError({
547
- ...n,
548
- error: r ? M(r) : void 0
568
+ ...s,
569
+ error: r ? k(r) : void 0
549
570
  });
550
571
  }
551
572
  init() {
552
573
  this.applyIntegrations();
553
574
  }
554
575
  applyIntegrations() {
555
- R || (R = !0, te(this), ie(this), ee(this));
576
+ M || (M = !0, oe(this), ue(this), ne(this));
556
577
  }
557
578
  }
558
- class ce {
579
+ class he {
559
580
  constructor(t) {
560
581
  const {
561
- serverId: r,
562
- serverOrigin: n,
563
- serverSource: s,
564
- theme: o
582
+ frameId: r,
583
+ serverId: s,
584
+ serverOrigin: o,
585
+ serverSource: n,
586
+ theme: a
565
587
  } = t, i = {
566
- id: r,
567
- origin: n,
568
- source: s
569
- }, a = new W({});
570
- a.addPeer(i), this.rpcClient = new X({
571
- transport: a,
572
- serverId: r
573
- }), this.subscriber = new A({
574
- transport: a,
588
+ id: s,
589
+ origin: o,
590
+ source: n
591
+ }, c = new U({
592
+ transportId: r
593
+ });
594
+ c.addPeer(i), this.rpcClient = new W({
595
+ transport: c,
596
+ serverId: s
597
+ }), this.subscriber = new C({
598
+ transport: c,
575
599
  brokerId: i.id
576
- }), document.documentElement.dataset.theme = o, this.crashReporter = new ae((c) => {
577
- this.makeRequest("v1.system.report.crash", c);
600
+ }), document.documentElement.dataset.theme = a, this.crashReporter = new le((l) => {
601
+ this.makeRequest("v1.system.report.crash", l);
578
602
  });
579
603
  }
580
604
  makeRequest(t, r) {
@@ -589,22 +613,22 @@ class ce {
589
613
  bootstrap() {
590
614
  let t = { height: 0, width: 0 };
591
615
  const r = () => {
592
- const a = document.body;
616
+ const i = document.body;
593
617
  return Math.max(
594
- a.offsetHeight,
595
- a.scrollHeight
618
+ i.offsetHeight,
619
+ i.scrollHeight
596
620
  );
597
- }, n = () => {
598
- const a = document.body;
621
+ }, s = () => {
622
+ const i = document.body;
599
623
  return Math.max(
600
- a.offsetWidth,
601
- a.scrollWidth
624
+ i.offsetWidth,
625
+ i.scrollWidth
602
626
  );
603
- }, s = () => {
604
- const a = n(), c = r();
605
- (t.height !== c || t.width !== a) && (t = { height: c, width: a }, this.makeRequest("v1.system.resize.notify", { height: c, width: a }));
627
+ }, o = () => {
628
+ const i = s(), c = r();
629
+ (t.height !== c || t.width !== i) && (t = { height: c, width: i }, this.makeRequest("v1.system.resize.notify", { height: c, width: i }));
606
630
  };
607
- s(), new ResizeObserver(s).observe(document.body), new MutationObserver(s).observe(document.body, {
631
+ o(), new ResizeObserver(o).observe(document.body), new MutationObserver(o).observe(document.body, {
608
632
  childList: !0,
609
633
  subtree: !0,
610
634
  attributes: !0,
@@ -612,15 +636,22 @@ class ce {
612
636
  }), this.crashReporter.init();
613
637
  }
614
638
  }
615
- const de = () => {
616
- const e = new URL(window.location.href), t = e.searchParams.get("origin") || "", r = e.searchParams.get("theme") || "dark", n = new ce({
639
+ let v = !1;
640
+ const pe = () => {
641
+ if (v)
642
+ throw new Error("ext helper already created, only one instance is allowed");
643
+ const e = new URL(window.location.href), t = e.searchParams.get("origin") || "", r = e.searchParams.get("theme") || "dark", s = e.searchParams.get("frameId");
644
+ if (!s)
645
+ throw new Error("failed to create ext helper, frameId is empty");
646
+ const o = new he({
617
647
  serverId: "server",
618
648
  serverOrigin: t || window.parent.origin,
619
649
  serverSource: window.parent,
650
+ frameId: s,
620
651
  theme: r
621
652
  });
622
- return n.bootstrap(), n;
653
+ return o.bootstrap(), v = !0, o;
623
654
  };
624
655
  export {
625
- de as createExtHelper
656
+ pe as createExtHelper
626
657
  };
package/dist/index.d.ts CHANGED
@@ -43,6 +43,7 @@ export declare type TEvents = TV1Events;
43
43
  export declare type TExtensionId = string;
44
44
 
45
45
  declare type TExtHelperProps = {
46
+ frameId: string;
46
47
  serverId: string;
47
48
  serverOrigin: string;
48
49
  serverSource: Window;
@@ -116,9 +117,29 @@ declare type TV1ChatEvents = {
116
117
  };
117
118
 
118
119
  declare type TV1ChatMethods = {
120
+ /**
121
+ * Renders a message in the chat locally for each user. The message is not sent to the server
122
+ * and is not broadcast — each user sees it injected into their own local chat feed.
123
+ *
124
+ * Because the message is local only, it is **not persisted**: it will disappear from the chat
125
+ * history after the page is reloaded.
126
+ *
127
+ * **Note:** A clickable link to the extension is always appended at the end of every message sent via this method.
128
+ * Clicking it opens the extension that sent the message.
129
+ * This behavior is mandatory and cannot be disabled.
130
+ */
119
131
  'v1.chat.message.send': {
120
132
  params: {
121
133
  isAnonymous: boolean;
134
+ /**
135
+ * Chat message text.
136
+ *
137
+ * Supports inline markup tags:
138
+ * - `{#accent}…{/accent}` — highlights text with an accent color.
139
+ * - `{#fade}…{/fade}` — renders text in a dimmed/secondary style.
140
+ *
141
+ * Example: `'won {#accent}Alice{/accent} in'`
142
+ */
122
143
  message: string;
123
144
  user: TV1ExtUser | null;
124
145
  };
@@ -201,7 +222,13 @@ export declare type TV1ExtLoggedInUser = {
201
222
  isKing: boolean;
202
223
  /** User is a knight of the model. */
203
224
  isKnight: boolean;
204
- /** Current user is a model. */
225
+ /**
226
+ * User has a model account.
227
+ *
228
+ * This can be true for another model visiting the stream. To check whether the
229
+ * current user is the broadcaster, compare `context.user.id`
230
+ * and `context.model.id`.
231
+ */
205
232
  isModel: boolean;
206
233
  /**
207
234
  * Current show/session state for this user.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stripchatdev/ext-helper",
3
3
  "private": false,
4
- "version": "0.1.31",
4
+ "version": "0.1.33",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "module": "./dist/ext-helper.js",