@stripchatdev/ext-helper 0.1.1 → 0.1.2
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 +455 -207
- package/dist/index.d.ts +44 -7
- package/package.json +1 -1
package/dist/ext-helper.js
CHANGED
|
@@ -1,323 +1,571 @@
|
|
|
1
|
-
const
|
|
2
|
-
var
|
|
3
|
-
(function(
|
|
4
|
-
|
|
5
|
-
})(
|
|
6
|
-
class
|
|
7
|
-
constructor(
|
|
8
|
-
super(`${
|
|
1
|
+
const T = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "iframe_pubsub" && "version" in e && e.version === "1.0", y = (e, t) => e, w = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
2
|
+
var l;
|
|
3
|
+
(function(e) {
|
|
4
|
+
e.Base32IncorrectEncoding = "B32_ENC_INVALID", e.DecodeTimeInvalidCharacter = "DEC_TIME_CHAR", e.DecodeTimeValueMalformed = "DEC_TIME_MALFORMED", e.EncodeTimeNegative = "ENC_TIME_NEG", e.EncodeTimeSizeExceeded = "ENC_TIME_SIZE_EXCEED", e.EncodeTimeValueMalformed = "ENC_TIME_MALFORMED", e.PRNGDetectFailure = "PRNG_DETECT", e.ULIDInvalid = "ULID_INVALID", e.Unexpected = "UNEXPECTED", e.UUIDInvalid = "UUID_INVALID";
|
|
5
|
+
})(l || (l = {}));
|
|
6
|
+
class f extends Error {
|
|
7
|
+
constructor(t, r) {
|
|
8
|
+
super(`${r} (${t})`), this.name = "ULIDError", this.code = t;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
const
|
|
13
|
-
return
|
|
11
|
+
function P(e) {
|
|
12
|
+
const t = Math.floor(e() * 32) % 32;
|
|
13
|
+
return w.charAt(t);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
if (typeof (
|
|
15
|
+
function _(e) {
|
|
16
|
+
const t = H(), r = t && (t.crypto || t.msCrypto) || null;
|
|
17
|
+
if (typeof (r == null ? void 0 : r.getRandomValues) == "function")
|
|
18
18
|
return () => {
|
|
19
|
-
const
|
|
20
|
-
return
|
|
19
|
+
const s = new Uint8Array(1);
|
|
20
|
+
return r.getRandomValues(s), s[0] / 255;
|
|
21
21
|
};
|
|
22
|
-
if (typeof (
|
|
23
|
-
return () =>
|
|
24
|
-
throw new
|
|
22
|
+
if (typeof (r == null ? void 0 : r.randomBytes) == "function")
|
|
23
|
+
return () => r.randomBytes(1).readUInt8() / 255;
|
|
24
|
+
throw new f(l.PRNGDetectFailure, "Failed to find a reliable PRNG");
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
return
|
|
26
|
+
function H() {
|
|
27
|
+
return O() ? self : typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : null;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
let
|
|
31
|
-
for (;
|
|
32
|
-
|
|
33
|
-
return
|
|
29
|
+
function q(e, t) {
|
|
30
|
+
let r = "";
|
|
31
|
+
for (; e > 0; e--)
|
|
32
|
+
r = P(t) + r;
|
|
33
|
+
return r;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
if (isNaN(
|
|
37
|
-
throw new
|
|
38
|
-
if (
|
|
39
|
-
throw new
|
|
40
|
-
if (
|
|
41
|
-
throw new
|
|
42
|
-
if (Number.isInteger(
|
|
43
|
-
throw new
|
|
44
|
-
let
|
|
45
|
-
for (let
|
|
46
|
-
|
|
47
|
-
return
|
|
35
|
+
function L(e, t = 10) {
|
|
36
|
+
if (isNaN(e))
|
|
37
|
+
throw new f(l.EncodeTimeValueMalformed, `Time must be a number: ${e}`);
|
|
38
|
+
if (e > 281474976710655)
|
|
39
|
+
throw new f(l.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${281474976710655}: ${e}`);
|
|
40
|
+
if (e < 0)
|
|
41
|
+
throw new f(l.EncodeTimeNegative, `Time must be positive: ${e}`);
|
|
42
|
+
if (Number.isInteger(e) === !1)
|
|
43
|
+
throw new f(l.EncodeTimeValueMalformed, `Time must be an integer: ${e}`);
|
|
44
|
+
let r, s = "";
|
|
45
|
+
for (let n = t; n > 0; n--)
|
|
46
|
+
r = e % 32, s = w.charAt(r) + s, e = (e - r) / 32;
|
|
47
|
+
return s;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function O() {
|
|
50
50
|
return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
const
|
|
54
|
-
return
|
|
52
|
+
function g(e, t) {
|
|
53
|
+
const r = _(), s = Date.now();
|
|
54
|
+
return L(s, 10) + q(16, r);
|
|
55
55
|
}
|
|
56
|
-
const
|
|
56
|
+
const S = ({ seq: e, uniqId: t }) => (r) => ({
|
|
57
57
|
...{
|
|
58
58
|
protocol: "iframe_pubsub",
|
|
59
59
|
version: "1.0",
|
|
60
|
-
id:
|
|
61
|
-
seq:
|
|
60
|
+
id: t(),
|
|
61
|
+
seq: e(),
|
|
62
62
|
timestamp: Date.now()
|
|
63
63
|
},
|
|
64
|
-
...
|
|
65
|
-
}),
|
|
66
|
-
uniqId: () =>
|
|
67
|
-
seq: () =>
|
|
64
|
+
...r
|
|
65
|
+
}), m = S({
|
|
66
|
+
uniqId: () => g(),
|
|
67
|
+
seq: () => g()
|
|
68
68
|
});
|
|
69
|
-
class
|
|
70
|
-
constructor(
|
|
71
|
-
this.eventHandlerMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (
|
|
72
|
-
if (
|
|
73
|
-
if (
|
|
74
|
-
const { eventName:
|
|
75
|
-
if (!
|
|
69
|
+
class C {
|
|
70
|
+
constructor(t) {
|
|
71
|
+
this.eventHandlerMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (n, o) => {
|
|
72
|
+
if (T(n)) {
|
|
73
|
+
if (n.type === "event") {
|
|
74
|
+
const { eventName: i } = n, a = this.eventHandlerMap.get(i);
|
|
75
|
+
if (!a)
|
|
76
76
|
return;
|
|
77
|
-
|
|
77
|
+
a.forEach((c) => {
|
|
78
78
|
try {
|
|
79
|
-
c(
|
|
80
|
-
} catch (
|
|
81
|
-
console.error("[PubSubSubscriber] globalMessageHandler: failed to handle income message",
|
|
79
|
+
c(n.data, o.id);
|
|
80
|
+
} catch (p) {
|
|
81
|
+
console.error("[PubSubSubscriber] globalMessageHandler: failed to handle income message", p);
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
console.error("[PubSubSubscriber] globalMessageHandler: unhandled message",
|
|
86
|
+
console.error("[PubSubSubscriber] globalMessageHandler: unhandled message", n);
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
|
-
const { brokerId:
|
|
90
|
-
this.brokerId =
|
|
89
|
+
const { brokerId: r, transport: s } = t;
|
|
90
|
+
this.brokerId = r, this.transport = s, this.transport.onMessage(this.globalMessageHandler);
|
|
91
91
|
}
|
|
92
|
-
subscribe(
|
|
93
|
-
const
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
const
|
|
92
|
+
subscribe(t, r) {
|
|
93
|
+
const s = y(t);
|
|
94
|
+
let n = this.eventHandlerMap.get(s);
|
|
95
|
+
n || (n = /* @__PURE__ */ new Set(), this.eventHandlerMap.set(s, n)), n.add(r);
|
|
96
|
+
const o = m({
|
|
97
97
|
type: "subscribe",
|
|
98
|
-
eventName:
|
|
98
|
+
eventName: t
|
|
99
99
|
});
|
|
100
|
-
this.transport.send(this.brokerId,
|
|
100
|
+
this.transport.send(this.brokerId, o);
|
|
101
101
|
}
|
|
102
|
-
unsubscribe(
|
|
103
|
-
const
|
|
104
|
-
let
|
|
105
|
-
if (!
|
|
102
|
+
unsubscribe(t, r) {
|
|
103
|
+
const s = y(t);
|
|
104
|
+
let n = this.eventHandlerMap.get(s);
|
|
105
|
+
if (!n)
|
|
106
106
|
return;
|
|
107
|
-
|
|
108
|
-
const
|
|
107
|
+
r ? n.delete(r) : this.eventHandlerMap.delete(s);
|
|
108
|
+
const o = m({
|
|
109
109
|
type: "unsubscribe",
|
|
110
|
-
eventName:
|
|
110
|
+
eventName: t
|
|
111
111
|
});
|
|
112
|
-
this.transport.send(this.brokerId,
|
|
112
|
+
this.transport.send(this.brokerId, o);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
const
|
|
116
|
-
class
|
|
117
|
-
constructor(
|
|
118
|
-
super(
|
|
115
|
+
const A = !!Error.captureStackTrace, D = "APP_ERROR";
|
|
116
|
+
class E extends Error {
|
|
117
|
+
constructor(t, r) {
|
|
118
|
+
super(t), this.name = new.target.name || D, this.cause = r, A && Error.captureStackTrace(this, this.constructor);
|
|
119
119
|
}
|
|
120
|
-
static getChainedMessage(
|
|
121
|
-
let { message:
|
|
122
|
-
return
|
|
123
|
-
Caused by: ${
|
|
120
|
+
static getChainedMessage(t) {
|
|
121
|
+
let { message: r } = t;
|
|
122
|
+
return t instanceof E && t.cause && (r += `
|
|
123
|
+
Caused by: ${E.getChainedMessage(t.cause)}`), r;
|
|
124
124
|
}
|
|
125
125
|
toJSON() {
|
|
126
126
|
return {
|
|
127
127
|
name: this.name,
|
|
128
128
|
message: this.message,
|
|
129
|
-
cause: this.cause ?
|
|
129
|
+
cause: this.cause ? E.getChainedMessage(this.cause) : void 0
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
const
|
|
133
|
+
const x = {
|
|
134
134
|
INTERNAL_ERROR: "INTERNAL_ERROR"
|
|
135
|
-
},
|
|
136
|
-
class
|
|
137
|
-
constructor(
|
|
138
|
-
super(
|
|
135
|
+
}, G = "RPC_ERROR";
|
|
136
|
+
class F extends E {
|
|
137
|
+
constructor(t) {
|
|
138
|
+
super(t.message || "unknown rpc error"), this.name = G, this.code = (t == null ? void 0 : t.code) || x.INTERNAL_ERROR;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
const
|
|
141
|
+
const j = (e) => !!e && typeof e == "object" && "protocol" in e && e.protocol === "iframe_rpc" && "version" in e && e.version === "1.0", B = ({ uniqId: e }) => (t) => ({
|
|
142
142
|
...{
|
|
143
143
|
protocol: "iframe_rpc",
|
|
144
144
|
version: "1.0",
|
|
145
|
-
id:
|
|
145
|
+
id: e(),
|
|
146
146
|
timestamp: Date.now()
|
|
147
147
|
},
|
|
148
|
-
...
|
|
149
|
-
}),
|
|
150
|
-
uniqId: () =>
|
|
148
|
+
...t
|
|
149
|
+
}), X = B({
|
|
150
|
+
uniqId: () => g()
|
|
151
151
|
});
|
|
152
|
-
class
|
|
153
|
-
constructor(
|
|
154
|
-
this.pendingEntryMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (
|
|
155
|
-
if (
|
|
156
|
-
if (
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
159
|
-
console.error("[RpcClient] globalMessageHandler: got success response without pending request",
|
|
152
|
+
class U {
|
|
153
|
+
constructor(t) {
|
|
154
|
+
this.pendingEntryMap = /* @__PURE__ */ new Map(), this.globalMessageHandler = (n) => {
|
|
155
|
+
if (j(n)) {
|
|
156
|
+
if (n.type === "response" && n.status === "ok") {
|
|
157
|
+
const o = n.id, i = this.pendingEntryMap.get(o);
|
|
158
|
+
if (!i) {
|
|
159
|
+
console.error("[RpcClient] globalMessageHandler: got success response without pending request", n);
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
|
-
this.pendingEntryMap.delete(
|
|
162
|
+
this.pendingEntryMap.delete(o), i.resolve(n.result);
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
|
-
if (
|
|
166
|
-
const
|
|
167
|
-
if (!
|
|
168
|
-
console.error("[RpcClient] globalMessageHandler: got error response without pending request",
|
|
165
|
+
if (n.type === "response" && n.status === "error") {
|
|
166
|
+
const o = n.id, i = this.pendingEntryMap.get(o);
|
|
167
|
+
if (!i) {
|
|
168
|
+
console.error("[RpcClient] globalMessageHandler: got error response without pending request", n);
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
|
-
this.pendingEntryMap.delete(
|
|
171
|
+
this.pendingEntryMap.delete(o), i.reject(new F(n.error));
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
|
-
console.error("[RpcClient] globalMessageHandler: invalid message schema",
|
|
174
|
+
console.error("[RpcClient] globalMessageHandler: invalid message schema", n);
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
|
-
const { serverId:
|
|
178
|
-
this.serverId =
|
|
177
|
+
const { serverId: r, transport: s } = t;
|
|
178
|
+
this.serverId = r, this.transport = s, this.transport.onMessage(this.globalMessageHandler);
|
|
179
179
|
}
|
|
180
|
-
makeRequest(
|
|
181
|
-
const
|
|
180
|
+
makeRequest(t, r) {
|
|
181
|
+
const s = X({
|
|
182
182
|
type: "request",
|
|
183
|
-
method:
|
|
184
|
-
params:
|
|
185
|
-
}),
|
|
186
|
-
this.pendingEntryMap.set(
|
|
187
|
-
method:
|
|
188
|
-
resolve: (
|
|
189
|
-
|
|
183
|
+
method: t,
|
|
184
|
+
params: r
|
|
185
|
+
}), n = new Promise((o, i) => {
|
|
186
|
+
this.pendingEntryMap.set(s.id, {
|
|
187
|
+
method: t,
|
|
188
|
+
resolve: (a) => {
|
|
189
|
+
o(a);
|
|
190
190
|
},
|
|
191
|
-
reject: (
|
|
192
|
-
a
|
|
191
|
+
reject: (a) => {
|
|
192
|
+
i(a);
|
|
193
193
|
}
|
|
194
194
|
});
|
|
195
195
|
});
|
|
196
196
|
try {
|
|
197
|
-
this.transport.send(this.serverId,
|
|
198
|
-
} catch (
|
|
199
|
-
console.error("[RpcClient] makeRequest: failed to send rpc message",
|
|
200
|
-
const
|
|
201
|
-
|
|
197
|
+
this.transport.send(this.serverId, s);
|
|
198
|
+
} catch (o) {
|
|
199
|
+
console.error("[RpcClient] makeRequest: failed to send rpc message", o);
|
|
200
|
+
const i = this.pendingEntryMap.get(s.id);
|
|
201
|
+
i && (this.pendingEntryMap.delete(s.id), i.reject(o));
|
|
202
202
|
}
|
|
203
|
-
return
|
|
203
|
+
return n;
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
|
-
class
|
|
207
|
-
constructor(
|
|
208
|
-
this.peers = /* @__PURE__ */ new Map(), this.onMessage = (
|
|
209
|
-
const
|
|
210
|
-
const { data:
|
|
206
|
+
class W {
|
|
207
|
+
constructor(t) {
|
|
208
|
+
this.peers = /* @__PURE__ */ new Map(), this.onMessage = (s) => {
|
|
209
|
+
const n = (o) => {
|
|
210
|
+
const { data: i, origin: a, source: c } = o;
|
|
211
211
|
if (!c) {
|
|
212
212
|
console.error("[PostMessageTransport] onMessage: source could not be empty");
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
215
|
+
const p = this.findPeer(c, a);
|
|
216
|
+
if (p)
|
|
217
217
|
try {
|
|
218
|
-
|
|
219
|
-
} catch (
|
|
220
|
-
console.error("[PostMessageTransport] onMessage: failed to call cb on message",
|
|
218
|
+
s(i, p);
|
|
219
|
+
} catch (b) {
|
|
220
|
+
console.error("[PostMessageTransport] onMessage: failed to call cb on message", b);
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
|
-
return this.localWindow.addEventListener("message",
|
|
224
|
-
this.localWindow.removeEventListener("message",
|
|
223
|
+
return this.localWindow.addEventListener("message", n), () => {
|
|
224
|
+
this.localWindow.removeEventListener("message", n);
|
|
225
225
|
};
|
|
226
226
|
};
|
|
227
|
-
const { localWindow:
|
|
228
|
-
this.localWindow =
|
|
227
|
+
const { localWindow: r } = t;
|
|
228
|
+
this.localWindow = r || window;
|
|
229
229
|
}
|
|
230
|
-
send(
|
|
231
|
-
const
|
|
232
|
-
|
|
230
|
+
send(t, r) {
|
|
231
|
+
const s = this.peers.get(t);
|
|
232
|
+
s && s.source.postMessage(r, s.origin);
|
|
233
233
|
}
|
|
234
|
-
broadcast(
|
|
235
|
-
this.peers.forEach((
|
|
236
|
-
|
|
234
|
+
broadcast(t) {
|
|
235
|
+
this.peers.forEach((r) => {
|
|
236
|
+
r.source.postMessage(t, r.origin);
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
|
-
broadcastGroup(
|
|
240
|
-
|
|
241
|
-
this.send(
|
|
239
|
+
broadcastGroup(t, r) {
|
|
240
|
+
t.forEach((s) => {
|
|
241
|
+
this.send(s, r);
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
|
-
addPeer(
|
|
245
|
-
this.peers.set(
|
|
244
|
+
addPeer(t) {
|
|
245
|
+
this.peers.set(t.id, t);
|
|
246
246
|
}
|
|
247
|
-
removePeer(
|
|
248
|
-
this.peers.delete(
|
|
247
|
+
removePeer(t) {
|
|
248
|
+
this.peers.delete(t);
|
|
249
249
|
}
|
|
250
|
-
findPeer(
|
|
251
|
-
for (const [
|
|
252
|
-
if (
|
|
253
|
-
return
|
|
250
|
+
findPeer(t, r) {
|
|
251
|
+
for (const [s, n] of this.peers)
|
|
252
|
+
if (n.source === t && n.origin === r)
|
|
253
|
+
return n;
|
|
254
254
|
return null;
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
const h = {
|
|
258
|
+
name: "UnknownError",
|
|
259
|
+
message: "Unknown error"
|
|
260
|
+
}, M = (e, t = 3, r = 0) => {
|
|
261
|
+
if (e instanceof Error) {
|
|
262
|
+
const s = r < t && e.cause ? M(e.cause, t, r + 1) : void 0;
|
|
263
|
+
return {
|
|
264
|
+
name: e.name,
|
|
265
|
+
message: e.message,
|
|
266
|
+
stack: e.stack,
|
|
267
|
+
cause: s
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
if (typeof e == "string")
|
|
271
|
+
return {
|
|
272
|
+
name: h.name,
|
|
273
|
+
message: e
|
|
274
|
+
};
|
|
275
|
+
if (typeof e == "number" || typeof e == "bigint" || typeof e == "boolean")
|
|
276
|
+
return {
|
|
277
|
+
name: h.name,
|
|
278
|
+
message: String(e)
|
|
279
|
+
};
|
|
280
|
+
if (e && typeof e == "object")
|
|
281
|
+
try {
|
|
282
|
+
return {
|
|
283
|
+
name: h.name,
|
|
284
|
+
message: "message" in e && typeof e.message == "string" && e.message !== "" ? e.message : JSON.stringify(e)
|
|
285
|
+
};
|
|
286
|
+
} catch {
|
|
287
|
+
return {
|
|
288
|
+
name: h.name,
|
|
289
|
+
message: "Unserializable error object"
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return h;
|
|
293
|
+
}, $ = "get", I = (e, t) => {
|
|
294
|
+
var n;
|
|
295
|
+
let r, s;
|
|
296
|
+
return e instanceof Request ? (r = e.url, s = e.method) : e instanceof URL ? r = e.toString() : r = e, {
|
|
297
|
+
method: s || ((n = t == null ? void 0 : t.method) == null ? void 0 : n.toString()) || $,
|
|
298
|
+
url: r
|
|
299
|
+
};
|
|
300
|
+
}, V = (e, t, r) => ({
|
|
301
|
+
statusCode: r.status,
|
|
302
|
+
...I(e, t)
|
|
303
|
+
}), z = (e) => {
|
|
304
|
+
const t = window.fetch;
|
|
305
|
+
Object.defineProperty(window, "fetch", {
|
|
306
|
+
value: async (s, n) => {
|
|
307
|
+
try {
|
|
308
|
+
const o = new Error("synthetic error"), i = await t(s, n), a = i.clone(), c = V(s, n, a);
|
|
309
|
+
if (i.status >= 500) {
|
|
310
|
+
const u = new Error("fetch response error");
|
|
311
|
+
u.stack = o.stack, e.report({
|
|
312
|
+
kind: "fetchResponseError",
|
|
313
|
+
type: "network",
|
|
314
|
+
data: c,
|
|
315
|
+
error: u
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
const {
|
|
319
|
+
arrayBuffer: p,
|
|
320
|
+
blob: b,
|
|
321
|
+
json: k,
|
|
322
|
+
text: N
|
|
323
|
+
} = i;
|
|
324
|
+
return i.json = async function() {
|
|
325
|
+
try {
|
|
326
|
+
return await k.call(this);
|
|
327
|
+
} catch (u) {
|
|
328
|
+
throw e.report({
|
|
329
|
+
type: "network",
|
|
330
|
+
kind: "fetchParseBodyError",
|
|
331
|
+
error: u,
|
|
332
|
+
data: {
|
|
333
|
+
parseType: "json",
|
|
334
|
+
...c
|
|
335
|
+
}
|
|
336
|
+
}), u;
|
|
337
|
+
}
|
|
338
|
+
}, i.text = async function() {
|
|
339
|
+
try {
|
|
340
|
+
return await N.call(this);
|
|
341
|
+
} catch (u) {
|
|
342
|
+
throw e.report({
|
|
343
|
+
type: "network",
|
|
344
|
+
kind: "fetchParseBodyError",
|
|
345
|
+
error: u,
|
|
346
|
+
data: {
|
|
347
|
+
parseType: "text",
|
|
348
|
+
...c
|
|
349
|
+
}
|
|
350
|
+
}), u;
|
|
351
|
+
}
|
|
352
|
+
}, i.blob = async function() {
|
|
353
|
+
try {
|
|
354
|
+
return await b.call(this);
|
|
355
|
+
} catch (u) {
|
|
356
|
+
throw e.report({
|
|
357
|
+
type: "network",
|
|
358
|
+
kind: "fetchParseBodyError",
|
|
359
|
+
error: u,
|
|
360
|
+
data: {
|
|
361
|
+
parseType: "blob",
|
|
362
|
+
...c
|
|
363
|
+
}
|
|
364
|
+
}), u;
|
|
365
|
+
}
|
|
366
|
+
}, i.arrayBuffer = async function() {
|
|
367
|
+
try {
|
|
368
|
+
return await p.call(this);
|
|
369
|
+
} catch (u) {
|
|
370
|
+
throw e.report({
|
|
371
|
+
type: "network",
|
|
372
|
+
kind: "fetchParseBodyError",
|
|
373
|
+
error: u,
|
|
374
|
+
data: {
|
|
375
|
+
parseType: "arrayBuffer",
|
|
376
|
+
...c
|
|
377
|
+
}
|
|
378
|
+
}), u;
|
|
379
|
+
}
|
|
380
|
+
}, i;
|
|
381
|
+
} catch (o) {
|
|
382
|
+
throw o instanceof Error && o.name === "AbortError" || e.report({
|
|
383
|
+
type: "network",
|
|
384
|
+
kind: "fetchRequestError",
|
|
385
|
+
error: o,
|
|
386
|
+
data: I(s, n)
|
|
387
|
+
}), o;
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
configurable: !1,
|
|
391
|
+
writable: !1
|
|
392
|
+
});
|
|
393
|
+
}, K = (e) => {
|
|
394
|
+
window.addEventListener("unhandledrejection", ({ reason: t }) => {
|
|
395
|
+
e.report({
|
|
396
|
+
type: "runtime",
|
|
397
|
+
kind: "unhandledRejection",
|
|
398
|
+
error: t
|
|
399
|
+
});
|
|
400
|
+
}), window.addEventListener("error", ({ colno: t, error: r, filename: s, lineno: n, message: o }) => {
|
|
401
|
+
e.report({
|
|
402
|
+
type: "runtime",
|
|
403
|
+
kind: "uncaughtError",
|
|
404
|
+
error: r,
|
|
405
|
+
data: {
|
|
406
|
+
lineno: n,
|
|
407
|
+
colno: t,
|
|
408
|
+
message: o,
|
|
409
|
+
filename: s
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
}, v = Symbol("patchedXHLHttpRequest"), d = Symbol("requestInfo"), J = (e) => ({
|
|
414
|
+
statusCode: e.status,
|
|
415
|
+
...e[d]
|
|
416
|
+
}), Z = (e) => (e[d] || (e[d] = {}), e[d]), Q = (e) => {
|
|
417
|
+
e[v] = !0;
|
|
418
|
+
}, Y = (e) => e[v] === !0, ee = (e) => {
|
|
419
|
+
const t = XMLHttpRequest.prototype.send, r = XMLHttpRequest.prototype.open, s = function(...o) {
|
|
420
|
+
const [i, a] = o;
|
|
421
|
+
this[d] = {
|
|
422
|
+
method: i,
|
|
423
|
+
url: typeof a == "string" ? a : a.toString()
|
|
424
|
+
}, Y(this) || (Q(this), this.addEventListener("error", () => {
|
|
425
|
+
const c = new Error("XMLHttpRequest network error");
|
|
426
|
+
e.report({
|
|
427
|
+
type: "network",
|
|
428
|
+
kind: "xmlHttpRequestError",
|
|
429
|
+
data: this[d],
|
|
430
|
+
error: c
|
|
431
|
+
});
|
|
432
|
+
}), this.addEventListener("timeout", () => {
|
|
433
|
+
const c = new Error("XMLHttpRequest timeout error");
|
|
434
|
+
e.report({
|
|
435
|
+
type: "network",
|
|
436
|
+
kind: "xmlHttpRequestTimeoutError",
|
|
437
|
+
data: this[d],
|
|
438
|
+
error: c
|
|
439
|
+
});
|
|
440
|
+
}), this.addEventListener("load", () => {
|
|
441
|
+
if (this.status >= 500) {
|
|
442
|
+
const c = new Error("XMLHttpRequest response error");
|
|
443
|
+
e.report({
|
|
444
|
+
type: "network",
|
|
445
|
+
kind: "xmlHttpRequestLoadError",
|
|
446
|
+
data: J(this),
|
|
447
|
+
error: c
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}));
|
|
451
|
+
try {
|
|
452
|
+
r.apply(this, o);
|
|
453
|
+
} catch (c) {
|
|
454
|
+
throw e.report({
|
|
455
|
+
type: "network",
|
|
456
|
+
kind: "xmlHttpRequestOpenError",
|
|
457
|
+
error: c,
|
|
458
|
+
data: this[d]
|
|
459
|
+
}), c;
|
|
460
|
+
}
|
|
461
|
+
}, n = function(o) {
|
|
462
|
+
try {
|
|
463
|
+
const i = Z(this), a = new Error("XMLHttpRequest request initiator");
|
|
464
|
+
i.requestStack = a.stack, t.call(this, o);
|
|
465
|
+
} catch (i) {
|
|
466
|
+
throw e.report({
|
|
467
|
+
type: "network",
|
|
468
|
+
kind: "xmlHttpRequestSendError",
|
|
469
|
+
error: i,
|
|
470
|
+
data: this[d]
|
|
471
|
+
}), i;
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
Object.defineProperty(XMLHttpRequest.prototype, "open", {
|
|
475
|
+
value: s,
|
|
476
|
+
configurable: !1,
|
|
477
|
+
writable: !1
|
|
478
|
+
}), Object.defineProperty(XMLHttpRequest.prototype, "send", {
|
|
479
|
+
value: n,
|
|
480
|
+
configurable: !1,
|
|
481
|
+
writable: !1
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
let R;
|
|
485
|
+
class te {
|
|
486
|
+
constructor(t) {
|
|
487
|
+
this.onError = t;
|
|
488
|
+
}
|
|
489
|
+
report(t) {
|
|
490
|
+
const { error: r, ...s } = t;
|
|
491
|
+
this.onError({
|
|
492
|
+
...s,
|
|
493
|
+
error: r ? M(r) : void 0
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
init() {
|
|
497
|
+
this.applyIntegrations();
|
|
498
|
+
}
|
|
499
|
+
applyIntegrations() {
|
|
500
|
+
R || (R = !0, K(this), ee(this), z(this));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
class re {
|
|
504
|
+
constructor(t) {
|
|
259
505
|
const {
|
|
260
|
-
serverId:
|
|
261
|
-
serverOrigin:
|
|
262
|
-
serverSource:
|
|
263
|
-
theme:
|
|
264
|
-
} =
|
|
265
|
-
id:
|
|
266
|
-
origin:
|
|
267
|
-
source:
|
|
268
|
-
},
|
|
269
|
-
|
|
270
|
-
transport:
|
|
271
|
-
serverId:
|
|
272
|
-
}), this.subscriber = new
|
|
273
|
-
transport:
|
|
274
|
-
brokerId:
|
|
275
|
-
}), document.documentElement.dataset.theme =
|
|
506
|
+
serverId: r,
|
|
507
|
+
serverOrigin: s,
|
|
508
|
+
serverSource: n,
|
|
509
|
+
theme: o
|
|
510
|
+
} = t, i = {
|
|
511
|
+
id: r,
|
|
512
|
+
origin: s,
|
|
513
|
+
source: n
|
|
514
|
+
}, a = new W({});
|
|
515
|
+
a.addPeer(i), this.rpcClient = new U({
|
|
516
|
+
transport: a,
|
|
517
|
+
serverId: r
|
|
518
|
+
}), this.subscriber = new C({
|
|
519
|
+
transport: a,
|
|
520
|
+
brokerId: i.id
|
|
521
|
+
}), document.documentElement.dataset.theme = o, this.crashReporter = new te((c) => {
|
|
522
|
+
this.makeRequest("v1.system.report.crash", c);
|
|
523
|
+
});
|
|
276
524
|
}
|
|
277
|
-
makeRequest(
|
|
278
|
-
return this.rpcClient.makeRequest(
|
|
525
|
+
makeRequest(t, r) {
|
|
526
|
+
return this.rpcClient.makeRequest(t, r);
|
|
279
527
|
}
|
|
280
|
-
subscribe(
|
|
281
|
-
return this.subscriber.subscribe(
|
|
528
|
+
subscribe(t, r) {
|
|
529
|
+
return this.subscriber.subscribe(t, r);
|
|
282
530
|
}
|
|
283
|
-
unsubscribe(
|
|
284
|
-
return this.subscriber.unsubscribe(
|
|
531
|
+
unsubscribe(t, r) {
|
|
532
|
+
return this.subscriber.unsubscribe(t, r);
|
|
285
533
|
}
|
|
286
534
|
bootstrap() {
|
|
287
|
-
let
|
|
288
|
-
const
|
|
289
|
-
const
|
|
535
|
+
let t = { height: 0, width: 0 };
|
|
536
|
+
const r = () => {
|
|
537
|
+
const a = document.body;
|
|
290
538
|
return Math.max(
|
|
291
|
-
|
|
292
|
-
|
|
539
|
+
a.offsetHeight,
|
|
540
|
+
a.scrollHeight
|
|
293
541
|
);
|
|
294
|
-
},
|
|
295
|
-
const
|
|
542
|
+
}, s = () => {
|
|
543
|
+
const a = document.body;
|
|
296
544
|
return Math.max(
|
|
297
|
-
|
|
298
|
-
|
|
545
|
+
a.offsetWidth,
|
|
546
|
+
a.scrollWidth
|
|
299
547
|
);
|
|
300
|
-
},
|
|
301
|
-
const
|
|
302
|
-
(
|
|
548
|
+
}, n = () => {
|
|
549
|
+
const a = s(), c = r();
|
|
550
|
+
(t.height !== c || t.width !== a) && (t = { height: c, width: a }, this.makeRequest("v1.system.resize.notify", { height: c, width: a }));
|
|
303
551
|
};
|
|
304
|
-
|
|
552
|
+
n(), new ResizeObserver(n).observe(document.body), new MutationObserver(n).observe(document.body, {
|
|
305
553
|
childList: !0,
|
|
306
554
|
subtree: !0,
|
|
307
555
|
attributes: !0,
|
|
308
556
|
attributeFilter: ["style", "class", "hidden", "open"]
|
|
309
|
-
});
|
|
557
|
+
}), this.crashReporter.init();
|
|
310
558
|
}
|
|
311
559
|
}
|
|
312
|
-
const
|
|
313
|
-
const
|
|
560
|
+
const se = () => {
|
|
561
|
+
const e = new URL(window.location.href), t = e.searchParams.get("origin") || "", r = e.searchParams.get("theme") || "dark", s = new re({
|
|
314
562
|
serverId: "server",
|
|
315
|
-
serverOrigin:
|
|
563
|
+
serverOrigin: t || window.parent.origin,
|
|
316
564
|
serverSource: window.parent,
|
|
317
|
-
theme:
|
|
565
|
+
theme: r
|
|
318
566
|
});
|
|
319
|
-
return
|
|
567
|
+
return s.bootstrap(), s;
|
|
320
568
|
};
|
|
321
569
|
export {
|
|
322
|
-
|
|
570
|
+
se as createExtHelper
|
|
323
571
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare const createExtHelper: () => ExtHelper;
|
|
|
3
3
|
declare class ExtHelper {
|
|
4
4
|
private rpcClient;
|
|
5
5
|
private subscriber;
|
|
6
|
+
private crashReporter;
|
|
6
7
|
constructor(props: TExtHelperProps);
|
|
7
8
|
makeRequest<M extends Extract<keyof TApiContract['methods'], string>>(method: M, params: TApiContract['methods'][M]['params']): Promise<TV1Methods[M]["result"]>;
|
|
8
9
|
subscribe<E extends Extract<keyof TApiContract['events'], string>>(eventName: E, handler: TAnyPubSubHandler<TApiContract['events'][E]>): void;
|
|
@@ -226,17 +227,12 @@ export declare type TV1ExtUser = {
|
|
|
226
227
|
/** User username. */
|
|
227
228
|
username: string;
|
|
228
229
|
/** User activity ranking data when available. */
|
|
229
|
-
userRanking?:
|
|
230
|
-
/** League representation of the user's activity level. Could be `grey`, `bronze`, `silver`, `gold`, `diamond`, `royal` or `legend`. */
|
|
231
|
-
league: TV1UserLeague;
|
|
232
|
-
/** Activity level from 1 to 100. */
|
|
233
|
-
level: number;
|
|
234
|
-
};
|
|
230
|
+
userRanking?: TV1UserRanking;
|
|
235
231
|
};
|
|
236
232
|
|
|
237
233
|
export declare type TV1Genders = 'male' | 'female' | 'group' | 'tranny';
|
|
238
234
|
|
|
239
|
-
export declare type TV1Methods = TV1ExtMethods & TV1SystemMethods & TV1PaymentMethods & TV1ModelMethods & TV1ChatMethods & TV1PrivateMethods;
|
|
235
|
+
export declare type TV1Methods = TV1ExtMethods & TV1SystemMethods & TV1PaymentMethods & TV1ModelMethods & TV1ChatMethods & TV1PrivateMethods & TV1MonitoringMethods;
|
|
240
236
|
|
|
241
237
|
declare type TV1ModelEvents = {
|
|
242
238
|
'v1.model.ext.settings.set.requested': null;
|
|
@@ -260,6 +256,23 @@ declare type TV1ModelMethods = {
|
|
|
260
256
|
|
|
261
257
|
export declare type TV1ModelStatus = Exclude<(typeof V1_SHOW_STATUSES)[keyof typeof V1_SHOW_STATUSES], 'spy'>;
|
|
262
258
|
|
|
259
|
+
declare type TV1MonitoringMethods = {
|
|
260
|
+
'v1.monitoring.report.error': {
|
|
261
|
+
params: {
|
|
262
|
+
data: unknown;
|
|
263
|
+
message: string;
|
|
264
|
+
};
|
|
265
|
+
result: null;
|
|
266
|
+
};
|
|
267
|
+
'v1.monitoring.report.log': {
|
|
268
|
+
params: {
|
|
269
|
+
data: unknown;
|
|
270
|
+
message: string;
|
|
271
|
+
};
|
|
272
|
+
result: null;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
|
|
263
276
|
declare type TV1PaymentEvents = {
|
|
264
277
|
'v1.payment.tokens.spend.succeeded': {
|
|
265
278
|
isAnonymous: boolean;
|
|
@@ -285,7 +298,23 @@ declare type TV1PrivateMethods = {
|
|
|
285
298
|
};
|
|
286
299
|
};
|
|
287
300
|
|
|
301
|
+
declare type TV1SerializedError = {
|
|
302
|
+
cause?: TV1SerializedError;
|
|
303
|
+
message: string;
|
|
304
|
+
name: string;
|
|
305
|
+
stack?: string;
|
|
306
|
+
};
|
|
307
|
+
|
|
288
308
|
declare type TV1SystemMethods = {
|
|
309
|
+
'v1.system.report.crash': {
|
|
310
|
+
params: {
|
|
311
|
+
data?: Record<string, unknown>;
|
|
312
|
+
error?: TV1SerializedError;
|
|
313
|
+
kind: string;
|
|
314
|
+
type: 'network' | 'runtime';
|
|
315
|
+
};
|
|
316
|
+
result: null;
|
|
317
|
+
};
|
|
289
318
|
'v1.system.resize.notify': {
|
|
290
319
|
params: {
|
|
291
320
|
height: number;
|
|
@@ -309,6 +338,14 @@ export declare type TV1TokenSpendData = TUnknownDictionary;
|
|
|
309
338
|
*/
|
|
310
339
|
declare type TV1UserLeague = 'grey' | 'bronze' | 'silver' | 'gold' | 'diamond' | 'royal' | 'legend';
|
|
311
340
|
|
|
341
|
+
/** User activity ranking system */
|
|
342
|
+
export declare type TV1UserRanking = {
|
|
343
|
+
/** League representation of the user's activity level. Could be `grey`, `bronze`, `silver`, `gold`, `diamond`, `royal` or `legend`. */
|
|
344
|
+
league: TV1UserLeague;
|
|
345
|
+
/** Activity level from 1 to 100. */
|
|
346
|
+
level: number;
|
|
347
|
+
};
|
|
348
|
+
|
|
312
349
|
export declare type TV1UserStatus = Exclude<(typeof V1_SHOW_STATUSES)[keyof typeof V1_SHOW_STATUSES], 'idle'>;
|
|
313
350
|
|
|
314
351
|
export declare type TV1WhisperData = TUnknownDictionary;
|