@stripchatdev/ext-helper 0.2.2 → 0.3.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,4 +1,4 @@
1
- const L = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_pubsub" && "version" in e && e.version === "1.0", I = (e) => e, k = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
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";
2
2
  var f;
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";
@@ -8,12 +8,12 @@ class y extends Error {
8
8
  super(`${r} (${t})`), this.name = "ULIDError", this.code = t;
9
9
  }
10
10
  }
11
- function O(e) {
11
+ function A(e) {
12
12
  const t = Math.floor(e() * 32) % 32;
13
- return k.charAt(t);
13
+ return P.charAt(t);
14
14
  }
15
- function A(e) {
16
- const t = x(), r = t && (t.crypto || t.msCrypto) || null;
15
+ function x(e) {
16
+ const t = C(), 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);
@@ -23,16 +23,16 @@ function A(e) {
23
23
  return () => r.randomBytes(1).readUInt8() / 255;
24
24
  throw new y(f.PRNGDetectFailure, "Failed to find a reliable PRNG");
25
25
  }
26
- function x() {
27
- return F() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
26
+ function C() {
27
+ return j() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
28
28
  }
29
- function C(e, t) {
29
+ function D(e, t) {
30
30
  let r = "";
31
31
  for (; e > 0; e--)
32
- r = O(t) + r;
32
+ r = A(t) + r;
33
33
  return r;
34
34
  }
35
- function D(e, t = 10) {
35
+ function F(e, t = 10) {
36
36
  if (isNaN(e))
37
37
  throw new y(f.EncodeTimeValueMalformed, `Time must be a number: ${e}`);
38
38
  if (e > 281474976710655)
@@ -43,17 +43,17 @@ function D(e, t = 10) {
43
43
  throw new y(f.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 = k.charAt(r) + n, e = (e - r) / 32;
46
+ r = e % 32, n = P.charAt(r) + n, e = (e - r) / 32;
47
47
  return n;
48
48
  }
49
- function F() {
49
+ function j() {
50
50
  return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
51
51
  }
52
52
  function E(e, t) {
53
- const r = t || A(), n = !e || isNaN(e) ? Date.now() : e;
54
- return D(n, 10) + C(16, r);
53
+ const r = t || x(), n = !e || isNaN(e) ? Date.now() : e;
54
+ return F(n, 10) + D(16, r);
55
55
  }
56
- const j = ({ seq: e, uniqId: t }) => (r) => ({
56
+ const G = ({ seq: e, uniqId: t }) => (r) => ({
57
57
  ...{
58
58
  protocol: "platform_pubsub",
59
59
  version: "1.0",
@@ -62,22 +62,22 @@ const j = ({ seq: e, uniqId: t }) => (r) => ({
62
62
  timestamp: Date.now()
63
63
  },
64
64
  ...r
65
- }), v = j({
65
+ }), v = G({
66
66
  uniqId: () => E(),
67
67
  seq: () => E()
68
68
  });
69
- class G {
69
+ class z {
70
70
  constructor(t) {
71
71
  this.eventHandlerMap = /* @__PURE__ */ new Map(), this.transportMessageHandler = (s) => {
72
- const { data: o, senderId: a } = s;
73
- if (L(o)) {
72
+ const { data: o, senderId: i } = s;
73
+ if (O(o)) {
74
74
  if (o.type === "event") {
75
- const { eventName: i } = o, c = this.eventHandlerMap.get(i);
75
+ const { eventName: a } = o, c = this.eventHandlerMap.get(a);
76
76
  if (!c)
77
77
  return;
78
78
  c.forEach((h) => {
79
79
  try {
80
- h(o.data, a);
80
+ h(o.data, i);
81
81
  } catch (m) {
82
82
  console.error("[PubSubSubscriber] transportMessageHandler: failed to handle income message", m);
83
83
  }
@@ -112,10 +112,10 @@ class G {
112
112
  }
113
113
  }
114
114
  }
115
- const z = !!Error.captureStackTrace, B = "APP_ERROR";
115
+ const B = !!Error.captureStackTrace, V = "APP_ERROR";
116
116
  class b extends Error {
117
117
  constructor(t, r) {
118
- super(t), this.name = new.target.name || B, this.cause = r, z && Error.captureStackTrace(this, this.constructor);
118
+ super(t), this.name = new.target.name || V, this.cause = r, B && Error.captureStackTrace(this, this.constructor);
119
119
  }
120
120
  static serializeCause(t) {
121
121
  return t instanceof b ? t.toJSON() : t instanceof Error ? { name: t.name, message: t.message } : t !== null && typeof t == "object" ? t : String(t);
@@ -136,23 +136,24 @@ class b extends Error {
136
136
  }
137
137
  }
138
138
  }
139
- const V = {
139
+ const X = {
140
140
  INTERNAL_ERROR: "INTERNAL_ERROR"
141
- }, X = "RPC_ERROR";
142
- class W extends b {
141
+ }, W = "RPC_ERROR";
142
+ class $ extends b {
143
143
  constructor(t) {
144
- super(t.message || "rpc error", t.cause), this.name = X, this.code = (t == null ? void 0 : t.code) || V.INTERNAL_ERROR, this.method = t.method, this.params = t.params;
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;
145
145
  }
146
146
  toJSON() {
147
147
  return {
148
148
  ...super.toJSON(),
149
149
  code: this.code,
150
+ details: this.details,
150
151
  method: this.method,
151
152
  params: this.params
152
153
  };
153
154
  }
154
155
  }
155
- const $ = (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 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
157
  ...{
157
158
  requestId: e(),
158
159
  protocol: "platform_rpc",
@@ -160,30 +161,30 @@ const $ = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol ==
160
161
  timestamp: Date.now()
161
162
  },
162
163
  ...t
163
- }), U = J({
164
+ }), K = J({
164
165
  uniqId: () => E()
165
166
  });
166
- class K {
167
+ class Z {
167
168
  constructor(t) {
168
169
  this.pendingEntryMap = /* @__PURE__ */ new Map(), this.transportMessageHandler = (s) => {
169
170
  const { data: o } = s;
170
- if ($(o)) {
171
+ if (U(o)) {
171
172
  if (o.type === "response" && o.status === "ok") {
172
- const a = this.pendingEntryMap.get(o.requestId);
173
- if (!a) {
173
+ const i = this.pendingEntryMap.get(o.requestId);
174
+ if (!i) {
174
175
  console.error("[RpcClient] transportMessageHandler: got success response without pending request", o);
175
176
  return;
176
177
  }
177
- this.pendingEntryMap.delete(o.requestId), a.resolve(o.result);
178
+ this.pendingEntryMap.delete(o.requestId), i.resolve(o.result);
178
179
  return;
179
180
  }
180
181
  if (o.type === "response" && o.status === "error") {
181
- const a = this.pendingEntryMap.get(o.requestId);
182
- if (!a) {
182
+ const i = this.pendingEntryMap.get(o.requestId);
183
+ if (!i) {
183
184
  console.error("[RpcClient] transportMessageHandler: got error response without pending request", o);
184
185
  return;
185
186
  }
186
- this.pendingEntryMap.delete(o.requestId), a.reject(new W(o.error));
187
+ this.pendingEntryMap.delete(o.requestId), i.reject(new $(o.error));
187
188
  return;
188
189
  }
189
190
  console.error("[RpcClient] transportMessageHandler: invalid message schema", o);
@@ -193,18 +194,18 @@ class K {
193
194
  this.serverId = r, this.transport = n, this.transport.onMessage(this.transportMessageHandler);
194
195
  }
195
196
  makeRequest(t, r) {
196
- const n = U({
197
+ const n = K({
197
198
  type: "request",
198
199
  method: t,
199
200
  params: r
200
- }), s = new Promise((o, a) => {
201
+ }), s = new Promise((o, i) => {
201
202
  this.pendingEntryMap.set(n.requestId, {
202
203
  method: t,
203
- resolve: (i) => {
204
- o(i);
204
+ resolve: (a) => {
205
+ o(a);
205
206
  },
206
- reject: (i) => {
207
- a(i);
207
+ reject: (a) => {
208
+ i(a);
208
209
  }
209
210
  });
210
211
  });
@@ -212,31 +213,31 @@ class K {
212
213
  this.transport.send(this.serverId, n);
213
214
  } catch (o) {
214
215
  console.error("[RpcClient] makeRequest: failed to send rpc message", o);
215
- const a = this.pendingEntryMap.get(n.requestId);
216
- a && (this.pendingEntryMap.delete(n.requestId), a.reject(o));
216
+ const i = this.pendingEntryMap.get(n.requestId);
217
+ i && (this.pendingEntryMap.delete(n.requestId), i.reject(o));
217
218
  }
218
219
  return s;
219
220
  }
220
221
  }
221
- const Z = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "platform_transport" && "version" in e && e.version === "1.0", Q = ({ uniqId: e }) => (t) => ({
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
223
  messageId: e(),
223
224
  protocol: "platform_transport",
224
225
  version: "1.0",
225
226
  ...t
226
- }), S = Q({
227
+ }), S = Y({
227
228
  uniqId: E
228
229
  });
229
- class Y {
230
+ class ee {
230
231
  constructor(t) {
231
232
  this.peers = /* @__PURE__ */ new Map(), this.handlers = /* @__PURE__ */ new Set(), this.onMessage = (s) => {
232
- const o = (a) => {
233
- const { data: i, origin: c, source: h } = a;
234
- if (!h || !Z(i))
233
+ const o = (i) => {
234
+ const { data: a, origin: c, source: h } = i;
235
+ if (!h || !Q(a))
235
236
  return;
236
- const { recipientId: m } = i;
237
+ const { recipientId: m } = a;
237
238
  if (!(m !== this.transportId || !this.findPeer(h, c)))
238
239
  try {
239
- s(i);
240
+ s(a);
240
241
  } catch (w) {
241
242
  console.error("[PostMessageTransport] onMessage: failed to call cb on message", w);
242
243
  }
@@ -295,9 +296,9 @@ class Y {
295
296
  const g = {
296
297
  name: "unknownError",
297
298
  message: "unknown error"
298
- }, P = (e, t = 3, r = 0) => {
299
+ }, q = (e, t = 3, r = 0) => {
299
300
  if (e instanceof Error) {
300
- const n = r < t && e.cause ? P(e.cause, t, r + 1) : void 0;
301
+ const n = r < t && e.cause ? q(e.cause, t, r + 1) : void 0;
301
302
  return {
302
303
  name: e.name,
303
304
  message: e.message,
@@ -328,10 +329,10 @@ const g = {
328
329
  };
329
330
  }
330
331
  return g;
331
- }, q = (e) => {
332
+ }, _ = (e) => {
332
333
  const t = [];
333
334
  if (e instanceof Error)
334
- t.push(e.message), "cause" in e && t.push(q(e.cause));
335
+ t.push(e.message), "cause" in e && t.push(_(e.cause));
335
336
  else
336
337
  try {
337
338
  const r = JSON.stringify(e);
@@ -340,7 +341,7 @@ const g = {
340
341
  t.push("failed to get chained error message: unserializable error object");
341
342
  }
342
343
  return t.join(":");
343
- }, ee = [
344
+ }, te = [
344
345
  // browser internals — harmless noise
345
346
  /resizeObserver loop/ig,
346
347
  // cross-origin script errors with zero useful info
@@ -363,29 +364,29 @@ const g = {
363
364
  // generic network noise already captured by fetch/xhr integrations
364
365
  /networkError when attempting to fetch resource/ig,
365
366
  /load failed/ig
366
- ], te = (e) => ee.some((t) => (t.lastIndex = 0, t.test(e))), re = (e) => {
367
- const t = q(e.error), r = typeof e.data == "object" && "message" in e.data && typeof e.data.message == "string" ? e.data.message : "";
367
+ ], re = (e) => te.some((t) => (t.lastIndex = 0, t.test(e))), ne = (e) => {
368
+ const t = _(e.error), r = typeof e.data == "object" && "message" in e.data && typeof e.data.message == "string" ? e.data.message : "";
368
369
  return [t, r].filter((n) => !!n).join(":");
369
- }, ne = (e) => e.data && typeof e.data == "object" && "filename" in e.data ? String(e.data.filename ?? "") : "", se = (e) => {
370
- const t = re(e), r = ne(e);
371
- return r && /^(chrome|moz|safari)-extension:\/\//.test(r) ? !0 : !!t && te(t);
372
- }, oe = "get", ae = (e, t) => {
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
+ }, ie = "get", ae = (e, t) => {
373
374
  var s;
374
375
  let r, n;
375
376
  return e instanceof Request ? (r = e.url, n = e.method) : e instanceof URL ? r = e.toString() : r = e, {
376
- method: n || ((s = t == null ? void 0 : t.method) == null ? void 0 : s.toString()) || oe,
377
+ method: n || ((s = t == null ? void 0 : t.method) == null ? void 0 : s.toString()) || ie,
377
378
  url: r
378
379
  };
379
- }, ie = (e, t, r) => ({
380
+ }, ce = (e, t, r) => ({
380
381
  statusCode: r.status,
381
382
  ...ae(e, t)
382
- }), ce = (e) => {
383
+ }), ue = (e) => {
383
384
  const t = window.fetch;
384
385
  Object.defineProperty(window, "fetch", {
385
386
  value: async (n, s) => {
386
387
  try {
387
- const o = new Error("synthetic error"), a = await t(n, s), i = a.clone(), c = ie(n, s, i);
388
- if (a.status >= 500) {
388
+ const o = new Error("synthetic error"), i = await t(n, s), a = i.clone(), c = ce(n, s, a);
389
+ if (i.status >= 500) {
389
390
  const d = new Error("fetch response error");
390
391
  d.stack = o.stack, e.report({
391
392
  kind: "fetchResponseError",
@@ -399,8 +400,8 @@ const g = {
399
400
  blob: m,
400
401
  json: M,
401
402
  text: w
402
- } = a;
403
- return a.json = async function() {
403
+ } = i;
404
+ return i.json = async function() {
404
405
  try {
405
406
  return await M.call(this);
406
407
  } catch (d) {
@@ -414,7 +415,7 @@ const g = {
414
415
  }
415
416
  }), d;
416
417
  }
417
- }, a.text = async function() {
418
+ }, i.text = async function() {
418
419
  try {
419
420
  return await w.call(this);
420
421
  } catch (d) {
@@ -428,7 +429,7 @@ const g = {
428
429
  }
429
430
  }), d;
430
431
  }
431
- }, a.blob = async function() {
432
+ }, i.blob = async function() {
432
433
  try {
433
434
  return await m.call(this);
434
435
  } catch (d) {
@@ -442,7 +443,7 @@ const g = {
442
443
  }
443
444
  }), d;
444
445
  }
445
- }, a.arrayBuffer = async function() {
446
+ }, i.arrayBuffer = async function() {
446
447
  try {
447
448
  return await h.call(this);
448
449
  } catch (d) {
@@ -456,7 +457,7 @@ const g = {
456
457
  }
457
458
  }), d;
458
459
  }
459
- }, a;
460
+ }, i;
460
461
  } catch (o) {
461
462
  throw o instanceof Error && o.name === "AbortError", o;
462
463
  }
@@ -464,7 +465,7 @@ const g = {
464
465
  configurable: !0,
465
466
  writable: !0
466
467
  });
467
- }, ue = (e) => {
468
+ }, de = (e) => {
468
469
  window.addEventListener("unhandledrejection", ({ reason: t }) => {
469
470
  e.report({
470
471
  type: "runtime",
@@ -484,18 +485,18 @@ const g = {
484
485
  }
485
486
  });
486
487
  });
487
- }, _ = Symbol("patchedXHLHttpRequest"), p = Symbol("requestInfo"), de = (e) => ({
488
+ }, L = Symbol("patchedXHLHttpRequest"), p = Symbol("requestInfo"), le = (e) => ({
488
489
  statusCode: e.status,
489
490
  ...e[p]
490
- }), le = (e) => (e[p] || (e[p] = {}), e[p]), pe = (e) => {
491
- e[_] = !0;
492
- }, he = (e) => e[_] === !0, fe = (e) => {
491
+ }), pe = (e) => (e[p] || (e[p] = {}), e[p]), he = (e) => {
492
+ e[L] = !0;
493
+ }, fe = (e) => e[L] === !0, me = (e) => {
493
494
  const t = XMLHttpRequest.prototype.send, r = XMLHttpRequest.prototype.open, n = function(...o) {
494
- const [a, i] = o;
495
+ const [i, a] = o;
495
496
  this[p] = {
496
- method: a,
497
- url: typeof i == "string" ? i : i.toString()
498
- }, he(this) || (pe(this), this.addEventListener("error", () => {
497
+ method: i,
498
+ url: typeof a == "string" ? a : a.toString()
499
+ }, fe(this) || (he(this), this.addEventListener("error", () => {
499
500
  const c = new Error("XMLHttpRequest network error");
500
501
  e.report({
501
502
  type: "network",
@@ -517,7 +518,7 @@ const g = {
517
518
  e.report({
518
519
  type: "network",
519
520
  kind: "xmlHttpRequestLoadError",
520
- data: de(this),
521
+ data: le(this),
521
522
  error: c
522
523
  });
523
524
  }
@@ -534,15 +535,15 @@ const g = {
534
535
  }
535
536
  }, s = function(o) {
536
537
  try {
537
- const a = le(this), i = new Error("XMLHttpRequest request initiator");
538
- a.requestStack = i.stack, t.call(this, o);
539
- } catch (a) {
538
+ const i = pe(this), a = new Error("XMLHttpRequest request initiator");
539
+ i.requestStack = a.stack, t.call(this, o);
540
+ } catch (i) {
540
541
  throw e.report({
541
542
  type: "network",
542
543
  kind: "xmlHttpRequestSendError",
543
- error: a,
544
+ error: i,
544
545
  data: this[p]
545
- }), a;
546
+ }), i;
546
547
  }
547
548
  };
548
549
  Object.defineProperty(XMLHttpRequest.prototype, "open", {
@@ -556,48 +557,48 @@ const g = {
556
557
  });
557
558
  };
558
559
  let N;
559
- class me {
560
+ class ge {
560
561
  constructor(t) {
561
562
  this.onError = t;
562
563
  }
563
564
  report(t) {
564
- if (se(t))
565
+ if (oe(t))
565
566
  return;
566
567
  const { error: r, ...n } = t;
567
568
  this.onError({
568
569
  ...n,
569
- error: r ? P(r) : void 0
570
+ error: r ? q(r) : void 0
570
571
  });
571
572
  }
572
573
  init() {
573
574
  this.applyIntegrations();
574
575
  }
575
576
  applyIntegrations() {
576
- N || (N = !0, ue(this), fe(this), ce(this));
577
+ N || (N = !0, de(this), me(this), ue(this));
577
578
  }
578
579
  }
579
- class ge {
580
+ class ye {
580
581
  constructor(t) {
581
582
  const {
582
583
  frameId: r,
583
584
  serverId: n,
584
585
  serverOrigin: s,
585
586
  serverSource: o,
586
- theme: a
587
- } = t, i = {
587
+ theme: i
588
+ } = t, a = {
588
589
  id: n,
589
590
  origin: s,
590
591
  source: o
591
- }, c = new Y({
592
+ }, c = new ee({
592
593
  transportId: r
593
594
  });
594
- c.addPeer(i), this.rpcClient = new K({
595
+ c.addPeer(a), this.rpcClient = new Z({
595
596
  transport: c,
596
597
  serverId: n
597
- }), this.subscriber = new G({
598
+ }), this.subscriber = new z({
598
599
  transport: c,
599
- brokerId: i.id
600
- }), document.documentElement.dataset.theme = a, this.crashReporter = new me((h) => {
600
+ brokerId: a.id
601
+ }), document.documentElement.dataset.theme = i, this.crashReporter = new ge((h) => {
601
602
  this.makeRequest("v1.system.report.crash", h);
602
603
  });
603
604
  }
@@ -613,20 +614,20 @@ class ge {
613
614
  bootstrap() {
614
615
  let t = { height: 0, width: 0 };
615
616
  const r = () => {
616
- const i = document.body;
617
+ const a = document.body;
617
618
  return Math.max(
618
- i.offsetHeight,
619
- i.scrollHeight
619
+ a.offsetHeight,
620
+ a.scrollHeight
620
621
  );
621
622
  }, n = () => {
622
- const i = document.body;
623
+ const a = document.body;
623
624
  return Math.max(
624
- i.offsetWidth,
625
- i.scrollWidth
625
+ a.offsetWidth,
626
+ a.scrollWidth
626
627
  );
627
628
  }, s = () => {
628
- const i = n(), c = r();
629
- (t.height !== c || t.width !== i) && (t = { height: c, width: i }, this.makeRequest("v1.system.resize.notify", { height: c, width: i }));
629
+ const a = n(), c = r();
630
+ (t.height !== c || t.width !== a) && (t = { height: c, width: a }, this.makeRequest("v1.system.resize.notify", { height: c, width: a }));
630
631
  };
631
632
  s(), new ResizeObserver(s).observe(document.body), new MutationObserver(s).observe(document.body, {
632
633
  childList: !0,
@@ -636,26 +637,26 @@ class ge {
636
637
  }), this.crashReporter.init();
637
638
  }
638
639
  }
639
- const ye = HTMLElement.prototype.focus, Ee = SVGElement.prototype.focus;
640
+ const Ee = HTMLElement.prototype.focus, be = SVGElement.prototype.focus;
640
641
  function T(e) {
641
642
  const t = typeof e == "object" && e ? { ...e, preventScroll: !0 } : { preventScroll: !0 };
642
643
  if (this instanceof HTMLElement)
643
- return ye.call(this, t);
644
- if (this instanceof SVGElement)
645
644
  return Ee.call(this, t);
645
+ if (this instanceof SVGElement)
646
+ return be.call(this, t);
646
647
  }
647
- const be = HTMLFormElement.prototype.submit, we = HTMLFormElement.prototype.requestSubmit, Re = /* @__PURE__ */ new Set(["_top", "_blank", "_parent"]), R = (e) => !!e && Re.has(e.toLowerCase());
648
- function Me() {
648
+ const we = HTMLFormElement.prototype.submit, Re = HTMLFormElement.prototype.requestSubmit, Me = /* @__PURE__ */ new Set(["_top", "_blank", "_parent"]), R = (e) => !!e && Me.has(e.toLowerCase());
649
+ function Ie() {
649
650
  const e = this.getAttribute("target");
650
651
  if (!R(e))
651
- return be.call(this);
652
+ return we.call(this);
652
653
  }
653
- function Ie(e) {
654
+ function ve(e) {
654
655
  const t = (e == null ? void 0 : e.getAttribute("formtarget")) || this.getAttribute("target");
655
656
  if (!R(t))
656
- return we.call(this, e);
657
+ return Re.call(this, e);
657
658
  }
658
- function ve(e) {
659
+ function Se(e) {
659
660
  var s;
660
661
  const t = e.target;
661
662
  if (!(t instanceof HTMLFormElement))
@@ -679,7 +680,7 @@ const l = () => {
679
680
  });
680
681
  } catch {
681
682
  }
682
- }, Se = () => {
683
+ }, Ne = () => {
683
684
  u(Window.prototype, "open", () => null), u(window, "open", () => null), u(Element.prototype, "scrollIntoView", l), u(
684
685
  Element.prototype,
685
686
  "scrollIntoViewIfNeeded",
@@ -688,25 +689,26 @@ const l = () => {
688
689
  HTMLVideoElement.prototype,
689
690
  "requestPictureInPicture",
690
691
  () => Promise.resolve({})
691
- ), u(HTMLFormElement.prototype, "submit", Me), u(HTMLFormElement.prototype, "requestSubmit", Ie), typeof Location < "u" && (u(Location.prototype, "assign", l), u(Location.prototype, "replace", l), u(Location.prototype, "reload", l)), document.addEventListener("submit", ve, !0);
692
- };
693
- let H = !1;
694
- typeof window < "u" && typeof document < "u" && Se();
695
- const Ne = () => {
696
- if (H)
692
+ ), u(HTMLFormElement.prototype, "submit", Ie), u(HTMLFormElement.prototype, "requestSubmit", ve), typeof Location < "u" && (u(Location.prototype, "assign", l), u(Location.prototype, "replace", l), u(Location.prototype, "reload", l)), document.addEventListener("submit", Se, !0);
693
+ }, H = (e) => typeof e == "object" && e !== null && !Array.isArray(e), Te = (e) => H(e) ? typeof e.code == "string" && typeof e.message == "string" && (e.details === void 0 || H(e.details)) : !1;
694
+ let k = !1;
695
+ typeof window < "u" && typeof document < "u" && Ne();
696
+ const He = () => {
697
+ if (k)
697
698
  throw new Error("ext helper already created, only one instance is allowed");
698
699
  const e = new URL(window.location.href), t = e.searchParams.get("origin") || "", r = e.searchParams.get("theme") || "dark", n = e.searchParams.get("frameId");
699
700
  if (!n)
700
701
  throw new Error("failed to create ext helper, frameId is empty");
701
- const s = new ge({
702
+ const s = new ye({
702
703
  serverId: "server",
703
704
  serverOrigin: t || window.parent.origin,
704
705
  serverSource: window.parent,
705
706
  frameId: n,
706
707
  theme: r
707
708
  });
708
- return s.bootstrap(), H = !0, s;
709
+ return s.bootstrap(), k = !0, s;
709
710
  };
710
711
  export {
711
- Ne as createExtHelper
712
+ He as createExtHelper,
713
+ Te as isExtensionError
712
714
  };
@@ -146,6 +146,10 @@ declare type TV1ActionResult = {
146
146
  declare type TV1ChatEvents = {
147
147
  /** Triggered on every new message in a chat */
148
148
  'v1.chat.message.received': {
149
+ /** Unique event id */
150
+ eventId: string;
151
+ /** Unique id of the message */
152
+ messageId: string;
149
153
  /** Text of the message */
150
154
  messageText: string;
151
155
  /** User who sent the message **/
@@ -469,6 +473,7 @@ declare type TV1GoalData = {
469
473
  declare type TV1GoalEvents = {
470
474
  /** Fired when any field of the active goal changes (description, isCompleted, tokensTarget, or tokensCollected), or the active goal is removed. */
471
475
  'v1.goal.updated': {
476
+ eventId: string;
472
477
  goal: TV1GoalData | null;
473
478
  };
474
479
  };
@@ -750,6 +755,12 @@ declare type TV1StorageMethods = {
750
755
  params: {
751
756
  /** Amount to add (may be negative). Must not be zero. */
752
757
  delta: string;
758
+ /**
759
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
760
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
761
+ * Use the same stable value across tabs and devices.
762
+ */
763
+ idempotencyKey?: string;
753
764
  key: string;
754
765
  /** Opaque payload forwarded to server-side payment/policy validation. */
755
766
  paymentContext?: string;
@@ -764,6 +775,12 @@ declare type TV1StorageMethods = {
764
775
  /** Reset an integer counter to 0. */
765
776
  'v1.storage.int.reset': {
766
777
  params: {
778
+ /**
779
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
780
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
781
+ * Use the same stable value across tabs and devices.
782
+ */
783
+ idempotencyKey?: string;
767
784
  key: string;
768
785
  };
769
786
  result: {
@@ -802,14 +819,25 @@ declare type TV1StorageMethods = {
802
819
  };
803
820
  'v1.storage.string.append': {
804
821
  params: {
822
+ /**
823
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
824
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
825
+ * Use the same stable value across tabs and devices.
826
+ */
827
+ idempotencyKey?: string;
805
828
  key: string;
806
829
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
807
830
  /** @format int64 */
808
831
  ttl?: string;
832
+ /**
833
+ * Append payload (at most 50000 UTF-8 bytes). Resulting stored value must also fit within 50000 bytes.
834
+ * @maxLength 50000
835
+ */
809
836
  value: string;
810
837
  };
811
838
  result: {
812
839
  success: boolean;
840
+ value: string;
813
841
  };
814
842
  };
815
843
  'v1.storage.string.get': {
@@ -837,14 +865,25 @@ declare type TV1StorageMethods = {
837
865
  };
838
866
  'v1.storage.string.set': {
839
867
  params: {
868
+ /**
869
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
870
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
871
+ * Use the same stable value across tabs and devices.
872
+ */
873
+ idempotencyKey?: string;
840
874
  key: string;
841
875
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
842
876
  /** @format int64 */
843
877
  ttl?: string;
878
+ /**
879
+ * Value (at most 50000 UTF-8 bytes).
880
+ * @maxLength 50000
881
+ */
844
882
  value: string;
845
883
  };
846
884
  result: {
847
885
  success: boolean;
886
+ value: string;
848
887
  };
849
888
  };
850
889
  /**
@@ -959,11 +998,15 @@ declare type TV1TipData = {
959
998
  declare type TV1TipEvents = {
960
999
  /** Fired when the tip menu has been updated.*/
961
1000
  'v1.tipMenu.updated': {
1001
+ /** Unique event id */
1002
+ eventId: string;
962
1003
  /** The current tip menu data. */
963
1004
  tipMenu: TV1TipMenu;
964
1005
  };
965
1006
  /** Fired on every tip in chat for both model and user. Doesn't fire on private tips during public shows */
966
1007
  'v1.tokens.spent': {
1008
+ /** Unique event id */
1009
+ eventId: string;
967
1010
  tipData: TV1TipData;
968
1011
  };
969
1012
  };
@@ -80,6 +80,10 @@ declare type TV1ActionResult = {
80
80
  declare type TV1ChatEvents = {
81
81
  /** Triggered on every new message in a chat */
82
82
  'v1.chat.message.received': {
83
+ /** Unique event id */
84
+ eventId: string;
85
+ /** Unique id of the message */
86
+ messageId: string;
83
87
  /** Text of the message */
84
88
  messageText: string;
85
89
  /** User who sent the message **/
@@ -403,6 +407,7 @@ declare type TV1GoalData = {
403
407
  declare type TV1GoalEvents = {
404
408
  /** Fired when any field of the active goal changes (description, isCompleted, tokensTarget, or tokensCollected), or the active goal is removed. */
405
409
  'v1.goal.updated': {
410
+ eventId: string;
406
411
  goal: TV1GoalData | null;
407
412
  };
408
413
  };
@@ -684,6 +689,12 @@ declare type TV1StorageMethods = {
684
689
  params: {
685
690
  /** Amount to add (may be negative). Must not be zero. */
686
691
  delta: string;
692
+ /**
693
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
694
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
695
+ * Use the same stable value across tabs and devices.
696
+ */
697
+ idempotencyKey?: string;
687
698
  key: string;
688
699
  /** Opaque payload forwarded to server-side payment/policy validation. */
689
700
  paymentContext?: string;
@@ -698,6 +709,12 @@ declare type TV1StorageMethods = {
698
709
  /** Reset an integer counter to 0. */
699
710
  'v1.storage.int.reset': {
700
711
  params: {
712
+ /**
713
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
714
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
715
+ * Use the same stable value across tabs and devices.
716
+ */
717
+ idempotencyKey?: string;
701
718
  key: string;
702
719
  };
703
720
  result: {
@@ -736,14 +753,25 @@ declare type TV1StorageMethods = {
736
753
  };
737
754
  'v1.storage.string.append': {
738
755
  params: {
756
+ /**
757
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
758
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
759
+ * Use the same stable value across tabs and devices.
760
+ */
761
+ idempotencyKey?: string;
739
762
  key: string;
740
763
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
741
764
  /** @format int64 */
742
765
  ttl?: string;
766
+ /**
767
+ * Append payload (at most 50000 UTF-8 bytes). Resulting stored value must also fit within 50000 bytes.
768
+ * @maxLength 50000
769
+ */
743
770
  value: string;
744
771
  };
745
772
  result: {
746
773
  success: boolean;
774
+ value: string;
747
775
  };
748
776
  };
749
777
  'v1.storage.string.get': {
@@ -771,14 +799,25 @@ declare type TV1StorageMethods = {
771
799
  };
772
800
  'v1.storage.string.set': {
773
801
  params: {
802
+ /**
803
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
804
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
805
+ * Use the same stable value across tabs and devices.
806
+ */
807
+ idempotencyKey?: string;
774
808
  key: string;
775
809
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
776
810
  /** @format int64 */
777
811
  ttl?: string;
812
+ /**
813
+ * Value (at most 50000 UTF-8 bytes).
814
+ * @maxLength 50000
815
+ */
778
816
  value: string;
779
817
  };
780
818
  result: {
781
819
  success: boolean;
820
+ value: string;
782
821
  };
783
822
  };
784
823
  /**
@@ -893,11 +932,15 @@ declare type TV1TipData = {
893
932
  declare type TV1TipEvents = {
894
933
  /** Fired when the tip menu has been updated.*/
895
934
  'v1.tipMenu.updated': {
935
+ /** Unique event id */
936
+ eventId: string;
896
937
  /** The current tip menu data. */
897
938
  tipMenu: TV1TipMenu;
898
939
  };
899
940
  /** Fired on every tip in chat for both model and user. Doesn't fire on private tips during public shows */
900
941
  'v1.tokens.spent': {
942
+ /** Unique event id */
943
+ eventId: string;
901
944
  tipData: TV1TipData;
902
945
  };
903
946
  };
package/dist/index.d.ts CHANGED
@@ -11,6 +11,8 @@ declare class ExtHelper implements TExtHelper {
11
11
  bootstrap(): void;
12
12
  }
13
13
 
14
+ export declare const isExtensionError: <TMethod extends TExtensionMethodName | undefined = undefined>(error: unknown) => error is TExtensionError<TMethod>;
15
+
14
16
  export declare type IV1IntIncrementFailureReason = 'INT_INCREMENT_FAILURE_REASON_UNSPECIFIED' | 'INT_INCREMENT_FAILURE_REASON_NONE' | 'INT_INCREMENT_FAILURE_REASON_VALIDATION_DENIED';
15
17
 
16
18
  export declare type IV1ResolveSlotPage = (slotType: string, context: TV1ExtContext, extSettings: TV1ExtSettings) => void;
@@ -39,9 +41,13 @@ export declare type TApiSchema = TAnyApiSchema<TEvents, TMethods>;
39
41
 
40
42
  export declare type TEvents = TV1Events;
41
43
 
44
+ declare type TExtensionError<TMethod extends TExtensionMethodName | undefined = undefined> = TMethod extends keyof TV1MethodErrors ? TV1MethodErrors[TMethod] : TV1ExtensionError;
45
+
42
46
  /** UUID */
43
47
  export declare type TExtensionId = string;
44
48
 
49
+ declare type TExtensionMethodName = Extract<keyof TApiSchema['methods'], string>;
50
+
45
51
  declare type TExtHelper = {
46
52
  bootstrap(): void;
47
53
  makeRequest<M extends Extract<keyof TApiContract['methods'], string>>(method: M, params: TApiContract['methods'][M]['params']): Promise<TApiContract['methods'][M]['result']>;
@@ -116,6 +122,10 @@ export declare type TV1ActionResult = {
116
122
  declare type TV1ChatEvents = {
117
123
  /** Triggered on every new message in a chat */
118
124
  'v1.chat.message.received': {
125
+ /** Unique event id */
126
+ eventId: string;
127
+ /** Unique id of the message */
128
+ messageId: string;
119
129
  /** Text of the message */
120
130
  messageText: string;
121
131
  /** User who sent the message **/
@@ -192,6 +202,12 @@ export declare type TV1ExtContext = {
192
202
  user?: TV1ExtUser;
193
203
  };
194
204
 
205
+ export declare type TV1ExtensionError<TCode extends string = string, TDetails extends Record<string, unknown> = Record<string, unknown>> = {
206
+ code: TCode;
207
+ details?: TDetails;
208
+ message: string;
209
+ };
210
+
195
211
  declare type TV1ExtEvents = {
196
212
  'v1.ext.activity.available': null;
197
213
  'v1.ext.activity.busy': null;
@@ -439,6 +455,7 @@ export declare type TV1GoalData = {
439
455
  declare type TV1GoalEvents = {
440
456
  /** Fired when any field of the active goal changes (description, isCompleted, tokensTarget, or tokensCollected), or the active goal is removed. */
441
457
  'v1.goal.updated': {
458
+ eventId: string;
442
459
  goal: TV1GoalData | null;
443
460
  };
444
461
  };
@@ -453,6 +470,11 @@ declare type TV1GoalMethods = {
453
470
  };
454
471
  };
455
472
 
473
+ export declare type TV1MethodErrors = {
474
+ 'v1.storage.string.append': TV1StorageStringAppendError;
475
+ 'v1.storage.string.set': TV1StorageStringSetError;
476
+ };
477
+
456
478
  export declare type TV1Methods = TV1ExtMethods & TV1SystemMethods & TV1PaymentMethods & TV1ModelMethods & TV1ChatMethods & TV1PrivateMethods & TV1MonitoringMethods & TV1SessionMethods & TV1StorageMethods & TV1TipMethods & TV1GoalMethods & TV1FanClubMethods;
457
479
 
458
480
  declare type TV1ModelEvents = {
@@ -720,6 +742,12 @@ declare type TV1StorageMethods = {
720
742
  params: {
721
743
  /** Amount to add (may be negative). Must not be zero. */
722
744
  delta: string;
745
+ /**
746
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
747
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
748
+ * Use the same stable value across tabs and devices.
749
+ */
750
+ idempotencyKey?: string;
723
751
  key: string;
724
752
  /** Opaque payload forwarded to server-side payment/policy validation. */
725
753
  paymentContext?: string;
@@ -734,6 +762,12 @@ declare type TV1StorageMethods = {
734
762
  /** Reset an integer counter to 0. */
735
763
  'v1.storage.int.reset': {
736
764
  params: {
765
+ /**
766
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
767
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
768
+ * Use the same stable value across tabs and devices.
769
+ */
770
+ idempotencyKey?: string;
737
771
  key: string;
738
772
  };
739
773
  result: {
@@ -772,14 +806,25 @@ declare type TV1StorageMethods = {
772
806
  };
773
807
  'v1.storage.string.append': {
774
808
  params: {
809
+ /**
810
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
811
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
812
+ * Use the same stable value across tabs and devices.
813
+ */
814
+ idempotencyKey?: string;
775
815
  key: string;
776
816
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
777
817
  /** @format int64 */
778
818
  ttl?: string;
819
+ /**
820
+ * Append payload (at most 50000 UTF-8 bytes). Resulting stored value must also fit within 50000 bytes.
821
+ * @maxLength 50000
822
+ */
779
823
  value: string;
780
824
  };
781
825
  result: {
782
826
  success: boolean;
827
+ value: string;
783
828
  };
784
829
  };
785
830
  'v1.storage.string.get': {
@@ -807,14 +852,25 @@ declare type TV1StorageMethods = {
807
852
  };
808
853
  'v1.storage.string.set': {
809
854
  params: {
855
+ /**
856
+ * Unique key for idempotent storage writes, such as an eventId, messageId, or transactionId.
857
+ * Warning: Do not use unstable frontend-generated values because they may differ across tabs.
858
+ * Use the same stable value across tabs and devices.
859
+ */
860
+ idempotencyKey?: string;
810
861
  key: string;
811
862
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
812
863
  /** @format int64 */
813
864
  ttl?: string;
865
+ /**
866
+ * Value (at most 50000 UTF-8 bytes).
867
+ * @maxLength 50000
868
+ */
814
869
  value: string;
815
870
  };
816
871
  result: {
817
872
  success: boolean;
873
+ value: string;
818
874
  };
819
875
  };
820
876
  /**
@@ -872,6 +928,14 @@ declare type TV1StorageMethods = {
872
928
  };
873
929
  };
874
930
 
931
+ export declare type TV1StorageStringAppendError = TV1ExtensionError<TV1StorageStringAppendErrorCode>;
932
+
933
+ export declare type TV1StorageStringAppendErrorCode = TV1StorageStringSetErrorCode;
934
+
935
+ export declare type TV1StorageStringSetError = TV1ExtensionError<TV1StorageStringSetErrorCode>;
936
+
937
+ export declare type TV1StorageStringSetErrorCode = 'ERR_CODE_UNSPECIFIED' | 'ERR_STORAGE_VALUE_SIZE_LIMIT_EXCEEDED';
938
+
875
939
  declare type TV1SystemMethods = {
876
940
  'v1.system.report.crash': {
877
941
  params: {
@@ -929,11 +993,15 @@ export declare type TV1TipData = {
929
993
  declare type TV1TipEvents = {
930
994
  /** Fired when the tip menu has been updated.*/
931
995
  'v1.tipMenu.updated': {
996
+ /** Unique event id */
997
+ eventId: string;
932
998
  /** The current tip menu data. */
933
999
  tipMenu: TV1TipMenu;
934
1000
  };
935
1001
  /** Fired on every tip in chat for both model and user. Doesn't fire on private tips during public shows */
936
1002
  'v1.tokens.spent': {
1003
+ /** Unique event id */
1004
+ eventId: string;
937
1005
  tipData: TV1TipData;
938
1006
  };
939
1007
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stripchatdev/ext-helper",
3
3
  "private": false,
4
- "version": "0.2.2",
4
+ "version": "0.3.0",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "module": "./dist/ext-helper.js",