@stripchatdev/ext-helper 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,19 @@
1
- const 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";
2
- var f;
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
+ var m;
3
3
  (function(e) {
4
4
  e.Base32IncorrectEncoding = "B32_ENC_INVALID", e.DecodeTimeInvalidCharacter = "DEC_TIME_CHAR", e.DecodeTimeValueMalformed = "DEC_TIME_MALFORMED", e.EncodeTimeNegative = "ENC_TIME_NEG", e.EncodeTimeSizeExceeded = "ENC_TIME_SIZE_EXCEED", e.EncodeTimeValueMalformed = "ENC_TIME_MALFORMED", e.PRNGDetectFailure = "PRNG_DETECT", e.ULIDInvalid = "ULID_INVALID", e.Unexpected = "UNEXPECTED", e.UUIDInvalid = "UUID_INVALID";
5
- })(f || (f = {}));
5
+ })(m || (m = {}));
6
6
  class y extends Error {
7
7
  constructor(t, r) {
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 = D(), r = t && (t.crypto || t.msCrypto) || null;
17
17
  if (typeof (r == null ? void 0 : r.getRandomValues) == "function")
18
18
  return () => {
19
19
  const n = new Uint8Array(1);
@@ -21,39 +21,39 @@ function A(e) {
21
21
  };
22
22
  if (typeof (r == null ? void 0 : r.randomBytes) == "function")
23
23
  return () => r.randomBytes(1).readUInt8() / 255;
24
- throw new y(f.PRNGDetectFailure, "Failed to find a reliable PRNG");
24
+ throw new y(m.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 D() {
27
+ return j() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
28
28
  }
29
29
  function C(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
- throw new y(f.EncodeTimeValueMalformed, `Time must be a number: ${e}`);
37
+ throw new y(m.EncodeTimeValueMalformed, `Time must be a number: ${e}`);
38
38
  if (e > 281474976710655)
39
- throw new y(f.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${281474976710655}: ${e}`);
39
+ throw new y(m.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${281474976710655}: ${e}`);
40
40
  if (e < 0)
41
- throw new y(f.EncodeTimeNegative, `Time must be positive: ${e}`);
41
+ throw new y(m.EncodeTimeNegative, `Time must be positive: ${e}`);
42
42
  if (Number.isInteger(e) === !1)
43
- throw new y(f.EncodeTimeValueMalformed, `Time must be an integer: ${e}`);
43
+ throw new y(m.EncodeTimeValueMalformed, `Time must be an integer: ${e}`);
44
44
  let r, n = "";
45
45
  for (let s = t; s > 0; s--)
46
- r = e % 32, n = 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) + C(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,24 +62,24 @@ 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
72
  const { data: o, senderId: a } = s;
73
- if (L(o)) {
73
+ if (O(o)) {
74
74
  if (o.type === "event") {
75
75
  const { eventName: i } = o, c = this.eventHandlerMap.get(i);
76
76
  if (!c)
77
77
  return;
78
- c.forEach((h) => {
78
+ c.forEach((l) => {
79
79
  try {
80
- h(o.data, a);
81
- } catch (m) {
82
- console.error("[PubSubSubscriber] transportMessageHandler: failed to handle income message", m);
80
+ l(o.data, a);
81
+ } catch (f) {
82
+ console.error("[PubSubSubscriber] transportMessageHandler: failed to handle income message", f);
83
83
  }
84
84
  });
85
85
  return;
@@ -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,14 +161,14 @@ 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
173
  const a = this.pendingEntryMap.get(o.requestId);
173
174
  if (!a) {
@@ -183,7 +184,7 @@ class K {
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), a.reject(new $(o.error));
187
188
  return;
188
189
  }
189
190
  console.error("[RpcClient] transportMessageHandler: invalid message schema", o);
@@ -193,7 +194,7 @@ 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
@@ -218,23 +219,23 @@ class K {
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
233
  const o = (a) => {
233
- const { data: i, origin: c, source: h } = a;
234
- if (!h || !Z(i))
234
+ const { data: i, origin: c, source: l } = a;
235
+ if (!l || !Q(i))
235
236
  return;
236
- const { recipientId: m } = i;
237
- if (!(m !== this.transportId || !this.findPeer(h, c)))
237
+ const { recipientId: f } = i;
238
+ if (!(f !== this.transportId || !this.findPeer(l, c)))
238
239
  try {
239
240
  s(i);
240
241
  } catch (w) {
@@ -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
+ }, L = (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(L(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,28 +364,28 @@ 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 = L(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
+ }, ae = "get", ie = (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()) || ae,
377
378
  url: r
378
379
  };
379
- }, ie = (e, t, r) => ({
380
+ }, ce = (e, t, r) => ({
380
381
  statusCode: r.status,
381
- ...ae(e, t)
382
- }), ce = (e) => {
382
+ ...ie(e, t)
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
+ const o = new Error("synthetic error"), a = await t(n, s), i = a.clone(), c = ce(n, s, i);
388
389
  if (a.status >= 500) {
389
390
  const d = new Error("fetch response error");
390
391
  d.stack = o.stack, e.report({
@@ -395,8 +396,8 @@ const g = {
395
396
  });
396
397
  }
397
398
  const {
398
- arrayBuffer: h,
399
- blob: m,
399
+ arrayBuffer: l,
400
+ blob: f,
400
401
  json: M,
401
402
  text: w
402
403
  } = a;
@@ -430,7 +431,7 @@ const g = {
430
431
  }
431
432
  }, a.blob = async function() {
432
433
  try {
433
- return await m.call(this);
434
+ return await f.call(this);
434
435
  } catch (d) {
435
436
  throw e.report({
436
437
  type: "network",
@@ -444,7 +445,7 @@ const g = {
444
445
  }
445
446
  }, a.arrayBuffer = async function() {
446
447
  try {
447
- return await h.call(this);
448
+ return await l.call(this);
448
449
  } catch (d) {
449
450
  throw e.report({
450
451
  type: "network",
@@ -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,23 +485,23 @@ const g = {
484
485
  }
485
486
  });
486
487
  });
487
- }, _ = Symbol("patchedXHLHttpRequest"), p = Symbol("requestInfo"), de = (e) => ({
488
+ }, _ = Symbol("patchedXHLHttpRequest"), h = Symbol("requestInfo"), le = (e) => ({
488
489
  statusCode: e.status,
489
- ...e[p]
490
- }), le = (e) => (e[p] || (e[p] = {}), e[p]), pe = (e) => {
490
+ ...e[h]
491
+ }), pe = (e) => (e[h] || (e[h] = {}), e[h]), he = (e) => {
491
492
  e[_] = !0;
492
- }, he = (e) => e[_] === !0, fe = (e) => {
493
+ }, fe = (e) => e[_] === !0, me = (e) => {
493
494
  const t = XMLHttpRequest.prototype.send, r = XMLHttpRequest.prototype.open, n = function(...o) {
494
495
  const [a, i] = o;
495
- this[p] = {
496
+ this[h] = {
496
497
  method: a,
497
498
  url: typeof i == "string" ? i : i.toString()
498
- }, he(this) || (pe(this), this.addEventListener("error", () => {
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",
502
503
  kind: "xmlHttpRequestError",
503
- data: this[p],
504
+ data: this[h],
504
505
  error: c
505
506
  });
506
507
  }), this.addEventListener("timeout", () => {
@@ -508,7 +509,7 @@ const g = {
508
509
  e.report({
509
510
  type: "network",
510
511
  kind: "xmlHttpRequestTimeoutError",
511
- data: this[p],
512
+ data: this[h],
512
513
  error: c
513
514
  });
514
515
  }), this.addEventListener("load", () => {
@@ -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
  }
@@ -529,19 +530,19 @@ const g = {
529
530
  type: "network",
530
531
  kind: "xmlHttpRequestOpenError",
531
532
  error: c,
532
- data: this[p]
533
+ data: this[h]
533
534
  }), c;
534
535
  }
535
536
  }, s = function(o) {
536
537
  try {
537
- const a = le(this), i = new Error("XMLHttpRequest request initiator");
538
+ const a = pe(this), i = new Error("XMLHttpRequest request initiator");
538
539
  a.requestStack = i.stack, t.call(this, o);
539
540
  } catch (a) {
540
541
  throw e.report({
541
542
  type: "network",
542
543
  kind: "xmlHttpRequestSendError",
543
544
  error: a,
544
- data: this[p]
545
+ data: this[h]
545
546
  }), a;
546
547
  }
547
548
  };
@@ -556,49 +557,50 @@ 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
- serverId: n,
584
- serverOrigin: s,
585
- serverSource: o,
586
- theme: a
587
- } = t, i = {
588
- id: n,
589
- origin: s,
590
- source: o
591
- }, c = new Y({
584
+ lang: n,
585
+ serverId: s,
586
+ serverOrigin: o,
587
+ serverSource: a,
588
+ theme: i
589
+ } = t, c = {
590
+ id: s,
591
+ origin: o,
592
+ source: a
593
+ }, l = new ee({
592
594
  transportId: r
593
595
  });
594
- c.addPeer(i), this.rpcClient = new K({
595
- transport: c,
596
- serverId: n
597
- }), this.subscriber = new G({
598
- transport: c,
599
- brokerId: i.id
600
- }), document.documentElement.dataset.theme = a, this.crashReporter = new me((h) => {
601
- this.makeRequest("v1.system.report.crash", h);
596
+ l.addPeer(c), this.rpcClient = new Z({
597
+ transport: l,
598
+ serverId: s
599
+ }), this.subscriber = new z({
600
+ transport: l,
601
+ brokerId: c.id
602
+ }), document.documentElement.dataset.theme = i, document.documentElement.lang = n, this.crashReporter = new ge((f) => {
603
+ this.makeRequest("v1.system.report.crash", f);
602
604
  });
603
605
  }
604
606
  makeRequest(t, r) {
@@ -636,26 +638,26 @@ class ge {
636
638
  }), this.crashReporter.init();
637
639
  }
638
640
  }
639
- const ye = HTMLElement.prototype.focus, Ee = SVGElement.prototype.focus;
641
+ const Ee = HTMLElement.prototype.focus, be = SVGElement.prototype.focus;
640
642
  function T(e) {
641
643
  const t = typeof e == "object" && e ? { ...e, preventScroll: !0 } : { preventScroll: !0 };
642
644
  if (this instanceof HTMLElement)
643
- return ye.call(this, t);
644
- if (this instanceof SVGElement)
645
645
  return Ee.call(this, t);
646
+ if (this instanceof SVGElement)
647
+ return be.call(this, t);
646
648
  }
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() {
649
+ const we = HTMLFormElement.prototype.submit, Re = HTMLFormElement.prototype.requestSubmit, Me = /* @__PURE__ */ new Set(["_top", "_blank", "_parent"]), R = (e) => !!e && Me.has(e.toLowerCase());
650
+ function Ie() {
649
651
  const e = this.getAttribute("target");
650
652
  if (!R(e))
651
- return be.call(this);
653
+ return we.call(this);
652
654
  }
653
- function Ie(e) {
655
+ function ve(e) {
654
656
  const t = (e == null ? void 0 : e.getAttribute("formtarget")) || this.getAttribute("target");
655
657
  if (!R(t))
656
- return we.call(this, e);
658
+ return Re.call(this, e);
657
659
  }
658
- function ve(e) {
660
+ function Se(e) {
659
661
  var s;
660
662
  const t = e.target;
661
663
  if (!(t instanceof HTMLFormElement))
@@ -663,7 +665,7 @@ function ve(e) {
663
665
  const r = e instanceof SubmitEvent ? e.submitter : null, n = (r == null ? void 0 : r.getAttribute("formtarget")) || t.getAttribute("target") || ((s = document.querySelector("base[target]")) == null ? void 0 : s.getAttribute("target")) || "_self";
664
666
  R(n) && (e.preventDefault(), e.stopImmediatePropagation());
665
667
  }
666
- const l = () => {
668
+ const p = () => {
667
669
  }, u = (e, t, r) => {
668
670
  const n = e;
669
671
  if (!n || typeof n[t] != "function")
@@ -679,34 +681,37 @@ const l = () => {
679
681
  });
680
682
  } catch {
681
683
  }
682
- }, Se = () => {
683
- u(Window.prototype, "open", () => null), u(window, "open", () => null), u(Element.prototype, "scrollIntoView", l), u(
684
+ }, Ne = () => {
685
+ u(Window.prototype, "open", () => null), u(window, "open", () => null), u(Element.prototype, "scrollIntoView", p), u(
684
686
  Element.prototype,
685
687
  "scrollIntoViewIfNeeded",
686
- l
687
- ), u(HTMLElement.prototype, "focus", T), u(SVGElement.prototype, "focus", T), u(History.prototype, "back", l), u(History.prototype, "forward", l), u(History.prototype, "go", l), u(History.prototype, "pushState", l), u(History.prototype, "replaceState", l), u(
688
+ p
689
+ ), u(HTMLElement.prototype, "focus", T), u(SVGElement.prototype, "focus", T), u(History.prototype, "back", p), u(History.prototype, "forward", p), u(History.prototype, "go", p), u(History.prototype, "pushState", p), u(History.prototype, "replaceState", p), u(
688
690
  HTMLVideoElement.prototype,
689
691
  "requestPictureInPicture",
690
692
  () => 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)
693
+ ), u(HTMLFormElement.prototype, "submit", Ie), u(HTMLFormElement.prototype, "requestSubmit", ve), typeof Location < "u" && (u(Location.prototype, "assign", p), u(Location.prototype, "replace", p), u(Location.prototype, "reload", p)), document.addEventListener("submit", Se, !0);
694
+ }, H = (e) => typeof e == "object" && e !== null && !Array.isArray(e), He = (e) => H(e) ? typeof e.code == "string" && typeof e.message == "string" && (e.details === void 0 || H(e.details)) : !1;
695
+ let k = !1;
696
+ const Te = "en";
697
+ typeof window < "u" && typeof document < "u" && Ne();
698
+ const ke = () => {
699
+ if (k)
697
700
  throw new Error("ext helper already created, only one instance is allowed");
698
- const e = new URL(window.location.href), t = e.searchParams.get("origin") || "", r = e.searchParams.get("theme") || "dark", n = e.searchParams.get("frameId");
699
- if (!n)
701
+ const e = new URL(window.location.href), t = e.searchParams.get("origin") || "", r = e.searchParams.get("theme") || "dark", n = e.searchParams.get("lang") || Te, s = e.searchParams.get("frameId");
702
+ if (!s)
700
703
  throw new Error("failed to create ext helper, frameId is empty");
701
- const s = new ge({
704
+ const o = new ye({
702
705
  serverId: "server",
703
706
  serverOrigin: t || window.parent.origin,
704
707
  serverSource: window.parent,
705
- frameId: n,
706
- theme: r
708
+ frameId: s,
709
+ theme: r,
710
+ lang: n
707
711
  });
708
- return s.bootstrap(), H = !0, s;
712
+ return o.bootstrap(), k = !0, o;
709
713
  };
710
714
  export {
711
- Ne as createExtHelper
715
+ ke as createExtHelper,
716
+ He as isExtensionError
712
717
  };
@@ -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']>;
@@ -51,6 +57,7 @@ declare type TExtHelper = {
51
57
 
52
58
  declare type TExtHelperProps = {
53
59
  frameId: string;
60
+ lang: string;
54
61
  serverId: string;
55
62
  serverOrigin: string;
56
63
  serverSource: Window;
@@ -196,6 +203,12 @@ export declare type TV1ExtContext = {
196
203
  user?: TV1ExtUser;
197
204
  };
198
205
 
206
+ export declare type TV1ExtensionError<TCode extends string = string, TDetails extends Record<string, unknown> = Record<string, unknown>> = {
207
+ code: TCode;
208
+ details?: TDetails;
209
+ message: string;
210
+ };
211
+
199
212
  declare type TV1ExtEvents = {
200
213
  'v1.ext.activity.available': null;
201
214
  'v1.ext.activity.busy': null;
@@ -458,6 +471,11 @@ declare type TV1GoalMethods = {
458
471
  };
459
472
  };
460
473
 
474
+ export declare type TV1MethodErrors = {
475
+ 'v1.storage.string.append': TV1StorageStringAppendError;
476
+ 'v1.storage.string.set': TV1StorageStringSetError;
477
+ };
478
+
461
479
  export declare type TV1Methods = TV1ExtMethods & TV1SystemMethods & TV1PaymentMethods & TV1ModelMethods & TV1ChatMethods & TV1PrivateMethods & TV1MonitoringMethods & TV1SessionMethods & TV1StorageMethods & TV1TipMethods & TV1GoalMethods & TV1FanClubMethods;
462
480
 
463
481
  declare type TV1ModelEvents = {
@@ -799,6 +817,10 @@ declare type TV1StorageMethods = {
799
817
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
800
818
  /** @format int64 */
801
819
  ttl?: string;
820
+ /**
821
+ * Append payload (at most 50000 UTF-8 bytes). Resulting stored value must also fit within 50000 bytes.
822
+ * @maxLength 50000
823
+ */
802
824
  value: string;
803
825
  };
804
826
  result: {
@@ -841,6 +863,10 @@ declare type TV1StorageMethods = {
841
863
  /** Auto-delete the key after this many seconds. Omit or 0 = no expiry. */
842
864
  /** @format int64 */
843
865
  ttl?: string;
866
+ /**
867
+ * Value (at most 50000 UTF-8 bytes).
868
+ * @maxLength 50000
869
+ */
844
870
  value: string;
845
871
  };
846
872
  result: {
@@ -903,6 +929,14 @@ declare type TV1StorageMethods = {
903
929
  };
904
930
  };
905
931
 
932
+ export declare type TV1StorageStringAppendError = TV1ExtensionError<TV1StorageStringAppendErrorCode>;
933
+
934
+ export declare type TV1StorageStringAppendErrorCode = TV1StorageStringSetErrorCode;
935
+
936
+ export declare type TV1StorageStringSetError = TV1ExtensionError<TV1StorageStringSetErrorCode>;
937
+
938
+ export declare type TV1StorageStringSetErrorCode = 'ERR_CODE_UNSPECIFIED' | 'ERR_STORAGE_VALUE_SIZE_LIMIT_EXCEEDED';
939
+
906
940
  declare type TV1SystemMethods = {
907
941
  'v1.system.report.crash': {
908
942
  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.1",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "module": "./dist/ext-helper.js",