@stripchatdev/ext-helper 0.2.3 → 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
  };
@@ -829,6 +829,10 @@ declare type TV1StorageMethods = {
829
829
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
830
830
  /** @format int64 */
831
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
+ */
832
836
  value: string;
833
837
  };
834
838
  result: {
@@ -871,6 +875,10 @@ declare type TV1StorageMethods = {
871
875
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
872
876
  /** @format int64 */
873
877
  ttl?: string;
878
+ /**
879
+ * Value (at most 50000 UTF-8 bytes).
880
+ * @maxLength 50000
881
+ */
874
882
  value: string;
875
883
  };
876
884
  result: {
@@ -763,6 +763,10 @@ declare type TV1StorageMethods = {
763
763
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
764
764
  /** @format int64 */
765
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
+ */
766
770
  value: string;
767
771
  };
768
772
  result: {
@@ -805,6 +809,10 @@ declare type TV1StorageMethods = {
805
809
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
806
810
  /** @format int64 */
807
811
  ttl?: string;
812
+ /**
813
+ * Value (at most 50000 UTF-8 bytes).
814
+ * @maxLength 50000
815
+ */
808
816
  value: string;
809
817
  };
810
818
  result: {
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']>;
@@ -196,6 +202,12 @@ export declare type TV1ExtContext = {
196
202
  user?: TV1ExtUser;
197
203
  };
198
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
+
199
211
  declare type TV1ExtEvents = {
200
212
  'v1.ext.activity.available': null;
201
213
  'v1.ext.activity.busy': null;
@@ -458,6 +470,11 @@ declare type TV1GoalMethods = {
458
470
  };
459
471
  };
460
472
 
473
+ export declare type TV1MethodErrors = {
474
+ 'v1.storage.string.append': TV1StorageStringAppendError;
475
+ 'v1.storage.string.set': TV1StorageStringSetError;
476
+ };
477
+
461
478
  export declare type TV1Methods = TV1ExtMethods & TV1SystemMethods & TV1PaymentMethods & TV1ModelMethods & TV1ChatMethods & TV1PrivateMethods & TV1MonitoringMethods & TV1SessionMethods & TV1StorageMethods & TV1TipMethods & TV1GoalMethods & TV1FanClubMethods;
462
479
 
463
480
  declare type TV1ModelEvents = {
@@ -799,6 +816,10 @@ declare type TV1StorageMethods = {
799
816
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
800
817
  /** @format int64 */
801
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
+ */
802
823
  value: string;
803
824
  };
804
825
  result: {
@@ -841,6 +862,10 @@ declare type TV1StorageMethods = {
841
862
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
842
863
  /** @format int64 */
843
864
  ttl?: string;
865
+ /**
866
+ * Value (at most 50000 UTF-8 bytes).
867
+ * @maxLength 50000
868
+ */
844
869
  value: string;
845
870
  };
846
871
  result: {
@@ -903,6 +928,14 @@ declare type TV1StorageMethods = {
903
928
  };
904
929
  };
905
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
+
906
939
  declare type TV1SystemMethods = {
907
940
  'v1.system.report.crash': {
908
941
  params: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stripchatdev/ext-helper",
3
3
  "private": false,
4
- "version": "0.2.3",
4
+ "version": "0.3.0",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "module": "./dist/ext-helper.js",