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