@instant-messengers/vk-teams-bridge 2.3.7 → 2.3.8
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/cjs/index.js +26 -33
- package/dist/esm/index.js +167 -150
- package/dist/iife/index.min.js +1 -1
- package/dist/types/Bridge.d.ts +0 -1
- package/package.json +1 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,7 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
16
|
return to;
|
|
18
17
|
};
|
|
19
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
19
|
var __async = (__this, __arguments, generator) => {
|
|
22
20
|
return new Promise((resolve, reject) => {
|
|
23
21
|
var fulfilled = (value) => {
|
|
@@ -57,9 +55,7 @@ var BRIDGE_ERROR_TYPE = "BRIDGE_ERROR_TYPE";
|
|
|
57
55
|
var BridgeError = class extends Error {
|
|
58
56
|
constructor(code, reason) {
|
|
59
57
|
super(`${code}: ${reason}`);
|
|
60
|
-
|
|
61
|
-
__publicField(this, "code");
|
|
62
|
-
__publicField(this, "reason");
|
|
58
|
+
this._error_type_ = BRIDGE_ERROR_TYPE;
|
|
63
59
|
this.code = code;
|
|
64
60
|
this.reason = reason;
|
|
65
61
|
}
|
|
@@ -183,10 +179,10 @@ var TeamsSubscribeAction = /* @__PURE__ */ ((TeamsSubscribeAction2) => {
|
|
|
183
179
|
// src/Bridge.ts
|
|
184
180
|
var Bridge = class {
|
|
185
181
|
constructor() {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
182
|
+
this.subscriptions = {};
|
|
183
|
+
this.promises = {};
|
|
184
|
+
this.enableLog = true;
|
|
185
|
+
this.callBackHandlers = {
|
|
190
186
|
newEvent: (subscriptionId, eventAttributes) => {
|
|
191
187
|
const callback = this.subscriptions[subscriptionId];
|
|
192
188
|
if (!callback) {
|
|
@@ -195,8 +191,8 @@ var Bridge = class {
|
|
|
195
191
|
}
|
|
196
192
|
callback(eventAttributes);
|
|
197
193
|
}
|
|
198
|
-
}
|
|
199
|
-
|
|
194
|
+
};
|
|
195
|
+
this.callFunction = (name, ...args) => {
|
|
200
196
|
const reqId = getUniqueId();
|
|
201
197
|
const message = {
|
|
202
198
|
type: "functionCall",
|
|
@@ -210,13 +206,13 @@ var Bridge = class {
|
|
|
210
206
|
return new Promise((resolve, reject) => {
|
|
211
207
|
this.promises[reqId] = [resolve, reject];
|
|
212
208
|
});
|
|
213
|
-
}
|
|
209
|
+
};
|
|
214
210
|
/** Отправить событие в супер-апп */
|
|
215
|
-
|
|
211
|
+
this.send = (action, payload) => {
|
|
216
212
|
return this.callFunction("send", action, payload);
|
|
217
|
-
}
|
|
213
|
+
};
|
|
218
214
|
/** Подписаться на событие из супер-апп */
|
|
219
|
-
|
|
215
|
+
this.subscribe = (action, callback, params = null) => __async(this, null, function* () {
|
|
220
216
|
const { subscriptionId } = yield this.callFunction(
|
|
221
217
|
"subscribe",
|
|
222
218
|
action,
|
|
@@ -224,9 +220,9 @@ var Bridge = class {
|
|
|
224
220
|
);
|
|
225
221
|
this.subscriptions[subscriptionId] = callback;
|
|
226
222
|
return { unsubscribe: this.getUnsubscribe(subscriptionId) };
|
|
227
|
-
})
|
|
223
|
+
});
|
|
228
224
|
/** Переопределить методы console что бы они отправляли логи в супер-апп */
|
|
229
|
-
|
|
225
|
+
this.setupConsoleProxy = () => {
|
|
230
226
|
const consoleMethodsNames = ["log", "warn", "info", "error"];
|
|
231
227
|
const sendLog = this.sendLog.bind(this);
|
|
232
228
|
consoleMethodsNames.forEach((method) => {
|
|
@@ -240,9 +236,9 @@ var Bridge = class {
|
|
|
240
236
|
}
|
|
241
237
|
});
|
|
242
238
|
});
|
|
243
|
-
}
|
|
239
|
+
};
|
|
244
240
|
/** Функция отправки логов в супер-апп */
|
|
245
|
-
|
|
241
|
+
this.sendLog = ({ text, type }) => {
|
|
246
242
|
if (this.enableLog) {
|
|
247
243
|
const reqId = getUniqueId();
|
|
248
244
|
const message = {
|
|
@@ -255,20 +251,20 @@ var Bridge = class {
|
|
|
255
251
|
};
|
|
256
252
|
window.parent.postMessage(message, "*");
|
|
257
253
|
}
|
|
258
|
-
}
|
|
254
|
+
};
|
|
259
255
|
/** Изменяем включени/выключение отправки логов в супер-апп */
|
|
260
|
-
|
|
256
|
+
this.changeEnableLog = (_0) => __async(this, [_0], function* ({ enabled }) {
|
|
261
257
|
this.enableLog = enabled;
|
|
262
258
|
yield this.send("EnableLog" /* EnableLog */, {
|
|
263
259
|
active: enabled
|
|
264
260
|
});
|
|
265
|
-
})
|
|
266
|
-
|
|
261
|
+
});
|
|
262
|
+
this.getUnsubscribe = (subscriptionId) => () => {
|
|
267
263
|
if (subscriptionId in this.subscriptions) {
|
|
268
264
|
delete this.subscriptions[subscriptionId];
|
|
269
265
|
}
|
|
270
|
-
}
|
|
271
|
-
|
|
266
|
+
};
|
|
267
|
+
this.handleMessage = (event) => {
|
|
272
268
|
const eventData = event.data;
|
|
273
269
|
if (typeof eventData !== "object") {
|
|
274
270
|
return;
|
|
@@ -281,8 +277,8 @@ var Bridge = class {
|
|
|
281
277
|
this.handleCallBack(event, eventData.data);
|
|
282
278
|
break;
|
|
283
279
|
}
|
|
284
|
-
}
|
|
285
|
-
|
|
280
|
+
};
|
|
281
|
+
this.handleFunctionCallReply = (data) => {
|
|
286
282
|
const promise = this.promises[data.reqId];
|
|
287
283
|
if (promise) {
|
|
288
284
|
delete this.promises[data.reqId];
|
|
@@ -296,8 +292,8 @@ var Bridge = class {
|
|
|
296
292
|
} else {
|
|
297
293
|
logger.warn(`got reply to unknown function call with id ${data.reqId}`);
|
|
298
294
|
}
|
|
299
|
-
}
|
|
300
|
-
|
|
295
|
+
};
|
|
296
|
+
this.handleCallBack = (event, data) => {
|
|
301
297
|
const callBackReply = ({ ok, err }) => {
|
|
302
298
|
var _a;
|
|
303
299
|
if (ok === void 0 === (err === void 0)) {
|
|
@@ -341,13 +337,10 @@ var Bridge = class {
|
|
|
341
337
|
};
|
|
342
338
|
}
|
|
343
339
|
callBackReply(result);
|
|
344
|
-
}
|
|
340
|
+
};
|
|
345
341
|
window.addEventListener("message", this.handleMessage);
|
|
346
342
|
if (window.self !== window.parent) {
|
|
347
343
|
this.setupConsoleProxy();
|
|
348
344
|
}
|
|
349
345
|
}
|
|
350
|
-
sendNotification() {
|
|
351
|
-
new Notification("Hooray");
|
|
352
|
-
}
|
|
353
346
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,17 +1,36 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
1
22
|
// src/error.ts
|
|
2
23
|
var BRIDGE_ERROR_TYPE = "BRIDGE_ERROR_TYPE";
|
|
3
24
|
var BridgeError = class extends Error {
|
|
4
|
-
_error_type_ = BRIDGE_ERROR_TYPE;
|
|
5
|
-
code;
|
|
6
|
-
reason;
|
|
7
25
|
constructor(code, reason) {
|
|
8
26
|
super(`${code}: ${reason}`);
|
|
27
|
+
this._error_type_ = BRIDGE_ERROR_TYPE;
|
|
9
28
|
this.code = code;
|
|
10
29
|
this.reason = reason;
|
|
11
30
|
}
|
|
12
31
|
};
|
|
13
32
|
var isBridgeError = (err) => {
|
|
14
|
-
return err
|
|
33
|
+
return (err == null ? void 0 : err._error_type_) === BRIDGE_ERROR_TYPE;
|
|
15
34
|
};
|
|
16
35
|
|
|
17
36
|
// src/types.ts
|
|
@@ -128,172 +147,170 @@ var TeamsSubscribeAction = /* @__PURE__ */ ((TeamsSubscribeAction2) => {
|
|
|
128
147
|
|
|
129
148
|
// src/Bridge.ts
|
|
130
149
|
var Bridge = class {
|
|
131
|
-
subscriptions = {};
|
|
132
|
-
promises = {};
|
|
133
|
-
enableLog = true;
|
|
134
|
-
callBackHandlers = {
|
|
135
|
-
newEvent: (subscriptionId, eventAttributes) => {
|
|
136
|
-
const callback = this.subscriptions[subscriptionId];
|
|
137
|
-
if (!callback) {
|
|
138
|
-
logger.warn(`no subscription found with id ${subscriptionId}`);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
callback(eventAttributes);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
150
|
constructor() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
name,
|
|
157
|
-
args
|
|
151
|
+
this.subscriptions = {};
|
|
152
|
+
this.promises = {};
|
|
153
|
+
this.enableLog = true;
|
|
154
|
+
this.callBackHandlers = {
|
|
155
|
+
newEvent: (subscriptionId, eventAttributes) => {
|
|
156
|
+
const callback = this.subscriptions[subscriptionId];
|
|
157
|
+
if (!callback) {
|
|
158
|
+
logger.warn(`no subscription found with id ${subscriptionId}`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
callback(eventAttributes);
|
|
158
162
|
}
|
|
159
163
|
};
|
|
160
|
-
|
|
161
|
-
return new Promise((resolve, reject) => {
|
|
162
|
-
this.promises[reqId] = [resolve, reject];
|
|
163
|
-
});
|
|
164
|
-
};
|
|
165
|
-
/** Отправить событие в супер-апп */
|
|
166
|
-
send = (action, payload) => {
|
|
167
|
-
return this.callFunction("send", action, payload);
|
|
168
|
-
};
|
|
169
|
-
/** Подписаться на событие из супер-апп */
|
|
170
|
-
subscribe = async (action, callback, params = null) => {
|
|
171
|
-
const { subscriptionId } = await this.callFunction(
|
|
172
|
-
"subscribe",
|
|
173
|
-
action,
|
|
174
|
-
params
|
|
175
|
-
);
|
|
176
|
-
this.subscriptions[subscriptionId] = callback;
|
|
177
|
-
return { unsubscribe: this.getUnsubscribe(subscriptionId) };
|
|
178
|
-
};
|
|
179
|
-
/** Переопределить методы console что бы они отправляли логи в супер-апп */
|
|
180
|
-
setupConsoleProxy = () => {
|
|
181
|
-
const consoleMethodsNames = ["log", "warn", "info", "error"];
|
|
182
|
-
const sendLog = this.sendLog.bind(this);
|
|
183
|
-
consoleMethodsNames.forEach((method) => {
|
|
184
|
-
window.console[method] = new Proxy(console[method], {
|
|
185
|
-
apply(target, ctx, args) {
|
|
186
|
-
sendLog({
|
|
187
|
-
type: method,
|
|
188
|
-
text: getStringFromLogParams(args)
|
|
189
|
-
});
|
|
190
|
-
Reflect.apply(target, ctx, [...args]);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
/** Функция отправки логов в супер-апп */
|
|
196
|
-
sendLog = ({ text, type }) => {
|
|
197
|
-
if (this.enableLog) {
|
|
164
|
+
this.callFunction = (name, ...args) => {
|
|
198
165
|
const reqId = getUniqueId();
|
|
199
166
|
const message = {
|
|
200
|
-
type: "
|
|
167
|
+
type: "functionCall",
|
|
201
168
|
data: {
|
|
202
169
|
reqId,
|
|
203
|
-
name
|
|
204
|
-
|
|
170
|
+
name,
|
|
171
|
+
args
|
|
205
172
|
}
|
|
206
173
|
};
|
|
207
174
|
window.parent.postMessage(message, "*");
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
175
|
+
return new Promise((resolve, reject) => {
|
|
176
|
+
this.promises[reqId] = [resolve, reject];
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
/** Отправить событие в супер-апп */
|
|
180
|
+
this.send = (action, payload) => {
|
|
181
|
+
return this.callFunction("send", action, payload);
|
|
182
|
+
};
|
|
183
|
+
/** Подписаться на событие из супер-апп */
|
|
184
|
+
this.subscribe = (action, callback, params = null) => __async(this, null, function* () {
|
|
185
|
+
const { subscriptionId } = yield this.callFunction(
|
|
186
|
+
"subscribe",
|
|
187
|
+
action,
|
|
188
|
+
params
|
|
189
|
+
);
|
|
190
|
+
this.subscriptions[subscriptionId] = callback;
|
|
191
|
+
return { unsubscribe: this.getUnsubscribe(subscriptionId) };
|
|
215
192
|
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
case "functionCallReply":
|
|
229
|
-
this.handleFunctionCallReply(eventData.data);
|
|
230
|
-
break;
|
|
231
|
-
case "callBack":
|
|
232
|
-
this.handleCallBack(event, eventData.data);
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
handleFunctionCallReply = (data) => {
|
|
237
|
-
const promise = this.promises[data.reqId];
|
|
238
|
-
if (promise) {
|
|
239
|
-
delete this.promises[data.reqId];
|
|
240
|
-
const [resolve, reject] = promise;
|
|
241
|
-
if (data.ok !== void 0) {
|
|
242
|
-
resolve(data.ok);
|
|
243
|
-
} else {
|
|
244
|
-
logger.warn(`rejecting req ${data.reqId} promise: ${JSON.stringify(data.err)}`);
|
|
245
|
-
reject(data.err);
|
|
246
|
-
}
|
|
247
|
-
} else {
|
|
248
|
-
logger.warn(`got reply to unknown function call with id ${data.reqId}`);
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
handleCallBack = (event, data) => {
|
|
252
|
-
const callBackReply = ({ ok, err }) => {
|
|
253
|
-
if (ok === void 0 === (err === void 0)) {
|
|
254
|
-
return callBackReply({
|
|
255
|
-
reqId: data.reqId,
|
|
256
|
-
err: {
|
|
257
|
-
code: "INTERNAL_ERROR" /* INTERNAL_ERROR */,
|
|
258
|
-
reason: "callBack handler protocol violation"
|
|
193
|
+
/** Переопределить методы console что бы они отправляли логи в супер-апп */
|
|
194
|
+
this.setupConsoleProxy = () => {
|
|
195
|
+
const consoleMethodsNames = ["log", "warn", "info", "error"];
|
|
196
|
+
const sendLog = this.sendLog.bind(this);
|
|
197
|
+
consoleMethodsNames.forEach((method) => {
|
|
198
|
+
window.console[method] = new Proxy(console[method], {
|
|
199
|
+
apply(target, ctx, args) {
|
|
200
|
+
sendLog({
|
|
201
|
+
type: method,
|
|
202
|
+
text: getStringFromLogParams(args)
|
|
203
|
+
});
|
|
204
|
+
Reflect.apply(target, ctx, [...args]);
|
|
259
205
|
}
|
|
260
206
|
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
/** Функция отправки логов в супер-апп */
|
|
210
|
+
this.sendLog = ({ text, type }) => {
|
|
211
|
+
if (this.enableLog) {
|
|
212
|
+
const reqId = getUniqueId();
|
|
213
|
+
const message = {
|
|
214
|
+
type: "sendLog",
|
|
215
|
+
data: {
|
|
216
|
+
reqId,
|
|
217
|
+
name: "sendLog",
|
|
218
|
+
logData: { text, type }
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
window.parent.postMessage(message, "*");
|
|
261
222
|
}
|
|
262
|
-
const message = {
|
|
263
|
-
type: "callBackReply",
|
|
264
|
-
data: {
|
|
265
|
-
reqId: data.reqId,
|
|
266
|
-
ok,
|
|
267
|
-
err
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
event.source?.postMessage(message, event.origin);
|
|
271
223
|
};
|
|
272
|
-
|
|
273
|
-
|
|
224
|
+
/** Изменяем включени/выключение отправки логов в супер-апп */
|
|
225
|
+
this.changeEnableLog = (_0) => __async(this, [_0], function* ({ enabled }) {
|
|
226
|
+
this.enableLog = enabled;
|
|
227
|
+
yield this.send("EnableLog" /* EnableLog */, {
|
|
228
|
+
active: enabled
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
this.getUnsubscribe = (subscriptionId) => () => {
|
|
232
|
+
if (subscriptionId in this.subscriptions) {
|
|
233
|
+
delete this.subscriptions[subscriptionId];
|
|
234
|
+
}
|
|
274
235
|
};
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
236
|
+
this.handleMessage = (event) => {
|
|
237
|
+
const eventData = event.data;
|
|
238
|
+
if (typeof eventData !== "object") {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
switch (eventData.type) {
|
|
242
|
+
case "functionCallReply":
|
|
243
|
+
this.handleFunctionCallReply(eventData.data);
|
|
244
|
+
break;
|
|
245
|
+
case "callBack":
|
|
246
|
+
this.handleCallBack(event, eventData.data);
|
|
247
|
+
break;
|
|
281
248
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (
|
|
286
|
-
|
|
249
|
+
};
|
|
250
|
+
this.handleFunctionCallReply = (data) => {
|
|
251
|
+
const promise = this.promises[data.reqId];
|
|
252
|
+
if (promise) {
|
|
253
|
+
delete this.promises[data.reqId];
|
|
254
|
+
const [resolve, reject] = promise;
|
|
255
|
+
if (data.ok !== void 0) {
|
|
256
|
+
resolve(data.ok);
|
|
257
|
+
} else {
|
|
258
|
+
logger.warn(`rejecting req ${data.reqId} promise: ${JSON.stringify(data.err)}`);
|
|
259
|
+
reject(data.err);
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
logger.warn(`got reply to unknown function call with id ${data.reqId}`);
|
|
287
263
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
264
|
+
};
|
|
265
|
+
this.handleCallBack = (event, data) => {
|
|
266
|
+
const callBackReply = ({ ok, err }) => {
|
|
267
|
+
var _a;
|
|
268
|
+
if (ok === void 0 === (err === void 0)) {
|
|
269
|
+
return callBackReply({
|
|
270
|
+
reqId: data.reqId,
|
|
271
|
+
err: {
|
|
272
|
+
code: "INTERNAL_ERROR" /* INTERNAL_ERROR */,
|
|
273
|
+
reason: "callBack handler protocol violation"
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const message = {
|
|
278
|
+
type: "callBackReply",
|
|
279
|
+
data: {
|
|
280
|
+
reqId: data.reqId,
|
|
281
|
+
ok,
|
|
282
|
+
err
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
(_a = event.source) == null ? void 0 : _a.postMessage(message, event.origin);
|
|
286
|
+
};
|
|
287
|
+
const result = {
|
|
288
|
+
reqId: data.reqId
|
|
291
289
|
};
|
|
290
|
+
try {
|
|
291
|
+
const callback = this.callBackHandlers[data.name];
|
|
292
|
+
if (!callback) {
|
|
293
|
+
const reason = `got callBack request with unknown name "${data.name}"`;
|
|
294
|
+
logger.warn(reason);
|
|
295
|
+
throw new BridgeError("BAD_REQUEST" /* BAD_REQUEST */, reason);
|
|
296
|
+
}
|
|
297
|
+
result.ok = callback(...data.args) || null;
|
|
298
|
+
} catch (e) {
|
|
299
|
+
let reason = isBridgeError(e) ? e.reason : "callBack handler raised an exception";
|
|
300
|
+
if (e instanceof Error) {
|
|
301
|
+
reason += ` "${e.name}": "${e.message}"`;
|
|
302
|
+
}
|
|
303
|
+
result.err = {
|
|
304
|
+
code: isBridgeError(e) ? e.code : "INTERNAL_ERROR" /* INTERNAL_ERROR */,
|
|
305
|
+
reason
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
callBackReply(result);
|
|
309
|
+
};
|
|
310
|
+
window.addEventListener("message", this.handleMessage);
|
|
311
|
+
if (window.self !== window.parent) {
|
|
312
|
+
this.setupConsoleProxy();
|
|
292
313
|
}
|
|
293
|
-
callBackReply(result);
|
|
294
|
-
};
|
|
295
|
-
sendNotification() {
|
|
296
|
-
new Notification("Hooray");
|
|
297
314
|
}
|
|
298
315
|
};
|
|
299
316
|
export {
|
package/dist/iife/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var VKTBridge=(function(){var P=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var at=function(t,e){for(var o in e)P(t,o,{get:e[o],enumerable:!0})},it=function(t,e,o,r){if(e&&typeof e=="object"||typeof e=="function")for(var n=nt(e),a=0,u=n.length,c;a<u;a++)c=n[a],!ot.call(t,c)&&c!==o&&P(t,c,{get:function(f){return e[f]}.bind(null,c),enumerable:!(r=rt(e,c))||r.enumerable});return t};var ut=function(t){return it(P({},"__esModule",{value:!0}),t)};var st={};at(st,{instance:function(){return L},send:function(){return ct},subscribe:function(){return ft}});function U(t,e,o,r,n,a,u){try{var c=t[a](u),f=c.value}catch(i){o(i);return}c.done?e(f):Promise.resolve(f).then(r,n)}function N(t){return function(){var e=this,o=arguments;return new Promise(function(r,n){var a=t.apply(e,o);function u(f){U(a,r,n,u,c,"next",f)}function c(f){U(a,r,n,u,c,"throw",f)}u(void 0)})}}function y(t,e){return e!=null&&typeof Symbol!="undefined"&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](t):y(t,e)}function v(t,e){if(!y(t,e))throw new TypeError("Cannot call a class as a function")}function G(t,e){for(var o=0;o<e.length;o++){var r=e[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function F(t,e,o){return e&&G(t.prototype,e),o&&G(t,o),t}function s(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function M(t){if(Array.isArray(t))return t}function T(t,e){var o=t==null?null:typeof Symbol!="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(o!=null){var r=[],n=!0,a=!1,u,c;try{for(o=o.call(t);!(n=(u=o.next()).done)&&(r.push(u.value),!(e&&r.length===e));n=!0);}catch(f){a=!0,c=f}finally{try{!n&&o.return!=null&&o.return()}finally{if(a)throw c}}return r}}function B(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function m(t,e){(e==null||e>t.length)&&(e=t.length);for(var o=0,r=new Array(e);o<e;o++)r[o]=t[o];return r}function O(t,e){if(t){if(typeof t=="string")return m(t,e);var o=Object.prototype.toString.call(t).slice(8,-1);if(o==="Object"&&t.constructor&&(o=t.constructor.name),o==="Map"||o==="Set")return Array.from(o);if(o==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o))return m(t,e)}}function C(t,e){return M(t)||T(t,e)||O(t,e)||B()}function k(t){if(Array.isArray(t))return m(t)}function K(t){if(typeof Symbol!="undefined"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function q(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function h(t){return k(t)||K(t)||O(t)||q()}function d(t){"@swc/helpers - typeof";return t&&typeof Symbol!="undefined"&&t.constructor===Symbol?"symbol":typeof t}function E(t,e){var o={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,n,a,u=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return u.next=c(0),u.throw=c(1),u.return=c(2),typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function c(i){return function(_){return f([i,_])}}function f(i){if(r)throw new TypeError("Generator is already executing.");for(;u&&(u=0,i[0]&&(o=0)),o;)try{if(r=1,n&&(a=i[0]&2?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[i[0]&2,a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(a=o.trys,!(a=a.length>0&&a[a.length-1])&&(i[0]===6||i[0]===2)){o=0;continue}if(i[0]===3&&(!a||i[1]>a[0]&&i[1]<a[3])){o.label=i[1];break}if(i[0]===6&&o.label<a[1]){o.label=a[1],a=i;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(i);break}a[2]&&o.ops.pop(),o.trys.pop();continue}i=e.call(t,o)}catch(_){i=[6,_],n=0}finally{r=a=0}if(i[0]&5)throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}}function p(t){return p=Object.setPrototypeOf?Object.getPrototypeOf:function(o){return o.__proto__||Object.getPrototypeOf(o)},p(t)}function b(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(b=function(){return!!t})()}function V(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Y(t,e){return e&&(d(e)==="object"||typeof e=="function")?e:V(t)}function W(t,e,o){return e=p(e),Y(t,b()?Reflect.construct(e,o||[],p(t).constructor):e.apply(t,o))}function l(t,e){return l=Object.setPrototypeOf||function(r,n){return r.__proto__=n,r},l(t,e)}function H(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&l(t,e)}function w(t,e,o){return b()?w=Reflect.construct:w=function(n,a,u){var c=[null];c.push.apply(c,a);var f=Function.bind.apply(n,c),i=new f;return u&&l(i,u.prototype),i},w.apply(null,arguments)}function z(t){return Function.toString.call(t).indexOf("[native code]")!==-1}function x(t){var e=typeof Map=="function"?new Map:void 0;return x=function(r){if(r===null||!z(r))return r;if(typeof r!="function")throw new TypeError("Super expression must either be null or a function");if(typeof e!="undefined"){if(e.has(r))return e.get(r);e.set(r,n)}function n(){return w(r,arguments,p(this).constructor)}return n.prototype=Object.create(r.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),l(n,r)},x(t)}var Q="BRIDGE_ERROR_TYPE",$=function(t){"use strict";H(e,t);function e(o,r){v(this,e);var n;return n=W(this,e,["".concat(o,": ").concat(r)]),s(n,"_error_type_",Q),s(n,"code",void 0),s(n,"reason",void 0),n.code=o,n.reason=r,n}return e}(x(Error)),I=function(t){return(t==null?void 0:t._error_type_)===Q};var R=function(t){return t.BAD_REQUEST="BAD_REQUEST",t.NETWORK_ERROR="NETWORK_ERROR",t.INTERNAL_ERROR="INTERNAL_ERROR",t.UNKNOWN_SUBSCRIPTION_NAME="UNKNOWN_SUBSCRIPTION_NAME",t}({});function D(){if("crypto"in window&&window.crypto.randomUUID)return window.crypto.randomUUID();for(var t=new Date().getTime(),e=97,o=122,r="",n=0;n<30;n++){var a=Math.floor(Math.random()*(o-e+1))+e,u=String.fromCharCode(a);r+=u}return"".concat(t).concat(r)}var J=function(t){return"[Bridge]: ".concat(t)},g={log:function(t){for(var e=arguments.length,o=new Array(e>1?e-1:0),r=1;r<e;r++)o[r-1]=arguments[r];var n;(n=console).log.apply(n,[J(t)].concat(h(o)))},warn:function(t){for(var e=arguments.length,o=new Array(e>1?e-1:0),r=1;r<e;r++)o[r-1]=arguments[r];var n;(n=console).warn.apply(n,[J(t)].concat(h(o)))}};var X=function(t){return t.map(function(e){return(typeof e=="undefined"?"undefined":d(e))==="object"?JSON.stringify(e):String(e)}).join(" ")};var Z=function(t){return t.LoadingCompleted="LoadingCompleted",t.OpenProfile="OpenProfile",t.OpenDialog="OpenDialog",t.OpenThread="OpenThread",t.ForwardTask="ForwardTask",t.SetTitle="SetTitle",t.SetBadge="SetBadge",t.OpenLink="OpenLink",t.ShowToast="ShowToast",t.GetThemeSettings="GetThemeSettings",t.GetMiniAppShareLink="GetMiniAppShareLink",t.GetLanguage="GetLanguage",t.OpenPopUp="OpenPopUp",t.StoragePut="StoragePut",t.StorageGet="StorageGet",t.StorageDelete="StorageDelete",t.StorageClear="StorageClear",t.StartAudioCall="StartAudioCall",t.StartVideoCall="StartVideoCall",t.OpenAuthModal="OpenAuthModal",t.SetCanGoBack="SetCanGoBack",t.SetCanNotGoBack="SetCanNotGoBack",t.OpenContactSelectionDialog="OpenContactSelectionDialog",t.SetButtonGroup="SetButtonGroup",t.GetSelfId="GetSelfId",t.DownloadFile="DownloadFile",t.CreateChat="CreateChat",t.ForwardSurvey="ForwardSurvey",t.GetAuth="GetAuth",t.GetPlatformVersion="GetPlatformVersion",t.GetMiniappConfig="GetMiniappConfig",t.EnableLog="EnableLog",t.GetMiniappsSettings="GetMiniappsSettings",t}({});var tt=function(){"use strict";function t(){var e=this,o=this;v(this,t),s(this,"subscriptions",{}),s(this,"promises",{}),s(this,"enableLog",!0),s(this,"callBackHandlers",{newEvent:function(r,n){var a=e.subscriptions[r];if(!a){g.warn("no subscription found with id ".concat(r));return}a(n)}}),s(this,"callFunction",function(r){for(var n=arguments.length,a=new Array(n>1?n-1:0),u=1;u<n;u++)a[u-1]=arguments[u];var c=D(),f={type:"functionCall",data:{reqId:c,name:r,args:a}};return window.parent.postMessage(f,"*"),new Promise(function(i,_){o.promises[c]=[i,_]})}),s(this,"send",function(r,n){return e.callFunction("send",r,n)}),s(this,"subscribe",function(r,n){var a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null;return N(function(){var u;return E(this,function(c){switch(c.label){case 0:return[4,this.callFunction("subscribe",r,a)];case 1:return u=c.sent().subscriptionId,this.subscriptions[u]=n,[2,{unsubscribe:this.getUnsubscribe(u)}]}})}).call(o)}),s(this,"setupConsoleProxy",function(){var r=["log","warn","info","error"],n=e.sendLog.bind(e);r.forEach(function(a){window.console[a]=new Proxy(console[a],{apply:function(c,f,i){n({type:a,text:X(i)}),Reflect.apply(c,f,h(i))}})})}),s(this,"sendLog",function(r){var n=r.text,a=r.type;if(e.enableLog){var u=D(),c={type:"sendLog",data:{reqId:u,name:"sendLog",logData:{text:n,type:a}}};window.parent.postMessage(c,"*")}}),s(this,"changeEnableLog",function(r){var n=r.enabled;return N(function(){return E(this,function(a){switch(a.label){case 0:return this.enableLog=n,[4,this.send(Z.EnableLog,{active:n})];case 1:return a.sent(),[2]}})}).call(e)}),s(this,"getUnsubscribe",function(r){return function(){r in e.subscriptions&&delete e.subscriptions[r]}}),s(this,"handleMessage",function(r){var n=r.data;if((typeof n=="undefined"?"undefined":d(n))==="object")switch(n.type){case"functionCallReply":e.handleFunctionCallReply(n.data);break;case"callBack":e.handleCallBack(r,n.data);break}}),s(this,"handleFunctionCallReply",function(r){var n=e.promises[r.reqId];if(n){delete e.promises[r.reqId];var a=C(n,2),u=a[0],c=a[1];r.ok!==void 0?u(r.ok):(g.warn("rejecting req ".concat(r.reqId," promise: ").concat(JSON.stringify(r.err))),c(r.err))}else g.warn("got reply to unknown function call with id ".concat(r.reqId))}),s(this,"handleCallBack",function(r,n){var a=function(_){var j=_.ok,A=_.err,S;if(j===void 0==(A===void 0))return a({reqId:n.reqId,err:{code:R.INTERNAL_ERROR,reason:"callBack handler protocol violation"}});var et={type:"callBackReply",data:{reqId:n.reqId,ok:j,err:A}};(S=r.source)===null||S===void 0||S.postMessage(et,r.origin)},u={reqId:n.reqId};try{var c=e.callBackHandlers[n.name];if(!c){var f='got callBack request with unknown name "'.concat(n.name,'"');throw g.warn(f),new $(R.BAD_REQUEST,f)}u.ok=c.apply(void 0,h(n.args))||null}catch(_){var i=I(_)?_.reason:"callBack handler raised an exception";y(_,Error)&&(i+=' "'.concat(_.name,'": "').concat(_.message,'"')),u.err={code:I(_)?_.code:R.INTERNAL_ERROR,reason:i}}a(u)}),window.addEventListener("message",this.handleMessage),window.self!==window.parent&&this.setupConsoleProxy()}return F(t,[{key:"sendNotification",value:function(){new Notification("Hooray")}}]),t}();var L=new tt,ct=L.send,ft=L.subscribe;return ut(st);})();
|
|
1
|
+
"use strict";var VKTBridge=(function(){var I=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var at=Object.prototype.hasOwnProperty;var it=function(t,e){for(var o in e)I(t,o,{get:e[o],enumerable:!0})},ut=function(t,e,o,a){if(e&&typeof e=="object"||typeof e=="function")for(var r=ot(e),n=0,i=r.length,c;n<i;n++)c=r[n],!at.call(t,c)&&c!==o&&I(t,c,{get:function(f){return e[f]}.bind(null,c),enumerable:!(a=nt(e,c))||a.enumerable});return t};var ct=function(t){return ut(I({},"__esModule",{value:!0}),t)};var _t={};it(_t,{instance:function(){return A},send:function(){return ft},subscribe:function(){return st}});function F(t,e,o,a,r,n,i){try{var c=t[n](i),f=c.value}catch(u){o(u);return}c.done?e(f):Promise.resolve(f).then(a,r)}function N(t){return function(){var e=this,o=arguments;return new Promise(function(a,r){var n=t.apply(e,o);function i(f){F(n,a,r,i,c,"next",f)}function c(f){F(n,a,r,i,c,"throw",f)}i(void 0)})}}function d(t,e){return e!=null&&typeof Symbol!="undefined"&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](t):d(t,e)}function E(t,e){if(!d(t,e))throw new TypeError("Cannot call a class as a function")}function s(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function T(t){if(Array.isArray(t))return t}function M(t,e){var o=t==null?null:typeof Symbol!="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(o!=null){var a=[],r=!0,n=!1,i,c;try{for(o=o.call(t);!(r=(i=o.next()).done)&&(a.push(i.value),!(e&&a.length===e));r=!0);}catch(f){n=!0,c=f}finally{try{!r&&o.return!=null&&o.return()}finally{if(n)throw c}}return a}}function B(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function g(t,e){(e==null||e>t.length)&&(e=t.length);for(var o=0,a=new Array(e);o<e;o++)a[o]=t[o];return a}function x(t,e){if(t){if(typeof t=="string")return g(t,e);var o=Object.prototype.toString.call(t).slice(8,-1);if(o==="Object"&&t.constructor&&(o=t.constructor.name),o==="Map"||o==="Set")return Array.from(o);if(o==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o))return g(t,e)}}function C(t,e){return T(t)||M(t,e)||x(t,e)||B()}function k(t){if(Array.isArray(t))return g(t)}function q(t){if(typeof Symbol!="undefined"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function K(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function h(t){return k(t)||q(t)||x(t)||K()}function m(t){"@swc/helpers - typeof";return t&&typeof Symbol!="undefined"&&t.constructor===Symbol?"symbol":typeof t}function S(t,e){var o={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},a,r,n,i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function c(u){return function(_){return f([u,_])}}function f(u){if(a)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(o=0)),o;)try{if(a=1,r&&(n=u[0]&2?r.return:u[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,u[1])).done)return n;switch(r=0,n&&(u=[u[0]&2,n.value]),u[0]){case 0:case 1:n=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(n=o.trys,!(n=n.length>0&&n[n.length-1])&&(u[0]===6||u[0]===2)){o=0;continue}if(u[0]===3&&(!n||u[1]>n[0]&&u[1]<n[3])){o.label=u[1];break}if(u[0]===6&&o.label<n[1]){o.label=n[1],n=u;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(u);break}n[2]&&o.ops.pop(),o.trys.pop();continue}u=e.call(t,o)}catch(_){u=[6,_],r=0}finally{a=n=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function y(t){return y=Object.setPrototypeOf?Object.getPrototypeOf:function(o){return o.__proto__||Object.getPrototypeOf(o)},y(t)}function w(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(w=function(){return!!t})()}function V(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Y(t,e){return e&&(m(e)==="object"||typeof e=="function")?e:V(t)}function W(t,e,o){return e=y(e),Y(t,w()?Reflect.construct(e,o||[],y(t).constructor):e.apply(t,o))}function p(t,e){return p=Object.setPrototypeOf||function(a,r){return a.__proto__=r,a},p(t,e)}function H(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&p(t,e)}function O(t,e,o){return w()?O=Reflect.construct:O=function(r,n,i){var c=[null];c.push.apply(c,n);var f=Function.bind.apply(r,c),u=new f;return i&&p(u,i.prototype),u},O.apply(null,arguments)}function Q(t){return Function.toString.call(t).indexOf("[native code]")!==-1}function R(t){var e=typeof Map=="function"?new Map:void 0;return R=function(a){if(a===null||!Q(a))return a;if(typeof a!="function")throw new TypeError("Super expression must either be null or a function");if(typeof e!="undefined"){if(e.has(a))return e.get(a);e.set(a,r)}function r(){return O(a,arguments,y(this).constructor)}return r.prototype=Object.create(a.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),p(r,a)},R(t)}var z="BRIDGE_ERROR_TYPE",J=function(t){"use strict";H(e,t);function e(o,a){E(this,e);var r;return r=W(this,e,["".concat(o,": ").concat(a)]),s(r,"_error_type_",z),s(r,"code",void 0),s(r,"reason",void 0),r.code=o,r.reason=a,r}return e}(R(Error)),L=function(t){return(t==null?void 0:t._error_type_)===z};var b;(function(t){t.BAD_REQUEST="BAD_REQUEST",t.NETWORK_ERROR="NETWORK_ERROR",t.INTERNAL_ERROR="INTERNAL_ERROR",t.UNKNOWN_SUBSCRIPTION_NAME="UNKNOWN_SUBSCRIPTION_NAME"})(b||(b={}));function j(){if("crypto"in window&&window.crypto.randomUUID)return window.crypto.randomUUID();for(var t=new Date().getTime(),e=97,o=122,a="",r=0;r<30;r++){var n=Math.floor(Math.random()*(o-e+1))+e,i=String.fromCharCode(n);a+=i}return"".concat(t).concat(a)}var X=function(t){return"[Bridge]: ".concat(t)},v={log:function(t){for(var e=arguments.length,o=new Array(e>1?e-1:0),a=1;a<e;a++)o[a-1]=arguments[a];var r;(r=console).log.apply(r,[X(t)].concat(h(o)))},warn:function(t){for(var e=arguments.length,o=new Array(e>1?e-1:0),a=1;a<e;a++)o[a-1]=arguments[a];var r;(r=console).warn.apply(r,[X(t)].concat(h(o)))}};var Z=function(t){return t.map(function(e){return(typeof e=="undefined"?"undefined":m(e))==="object"?JSON.stringify(e):String(e)}).join(" ")};var P;(function(t){t.LoadingCompleted="LoadingCompleted",t.OpenProfile="OpenProfile",t.OpenDialog="OpenDialog",t.OpenThread="OpenThread",t.ForwardTask="ForwardTask",t.SetTitle="SetTitle",t.SetBadge="SetBadge",t.OpenLink="OpenLink",t.ShowToast="ShowToast",t.GetThemeSettings="GetThemeSettings",t.GetMiniAppShareLink="GetMiniAppShareLink",t.GetLanguage="GetLanguage",t.OpenPopUp="OpenPopUp",t.StoragePut="StoragePut",t.StorageGet="StorageGet",t.StorageDelete="StorageDelete",t.StorageClear="StorageClear",t.StartAudioCall="StartAudioCall",t.StartVideoCall="StartVideoCall",t.OpenAuthModal="OpenAuthModal",t.SetCanGoBack="SetCanGoBack",t.SetCanNotGoBack="SetCanNotGoBack",t.OpenContactSelectionDialog="OpenContactSelectionDialog",t.SetButtonGroup="SetButtonGroup",t.GetSelfId="GetSelfId",t.DownloadFile="DownloadFile",t.CreateChat="CreateChat",t.ForwardSurvey="ForwardSurvey",t.GetAuth="GetAuth",t.GetPlatformVersion="GetPlatformVersion",t.GetMiniappConfig="GetMiniappConfig",t.EnableLog="EnableLog",t.GetMiniappsSettings="GetMiniappsSettings"})(P||(P={}));var $;(function(t){t.ALREADY_CALLED="ALREADY_CALLED",t.PROFILE_NOT_FOUND="PROFILE_NOT_FOUND",t.DIALOG_NOT_FOUND="DIALOG_NOT_FOUND",t.THREAD_NOT_FOUND="THREAD_NOT_FOUND",t.POPUP_CLOSED="POPUP_CLOSED",t.KEY_IS_TOO_LARGE="KEY_IS_TOO_LARGE",t.VALUE_IS_TOO_LARGE="VALUE_IS_TOO_LARGE",t.TOTAL_LIMIT_EXCEEDED="TOTAL_LIMIT_EXCEEDED",t.INVALID_KEY="INVALID_KEY",t.INVALID_VALUE="INVALID_VALUE",t.KEY_NOT_FOUND="KEY_NOT_FOUND",t.USER_NOT_FOUND="USER_NOT_FOUND",t.MODAL_CLOSED="MODAL_CLOSED",t.UNKNOWN_GROUP="UNKNOWN_GROUP",t.UNKNOWN_ICON="UNKNOWN_ICON",t.CALLBACK_DATA_TOO_LARGE="CALLBACK_DATA_TOO_LARGE",t.TOO_MANY_BUTTONS="TOO_MANY_BUTTONS",t.CREATE_FAILED="CREATE_FAILED",t.UNAUTHTORIZED="401",t.FORBIDDEN="403",t.SERVER_ERROR="500"})($||($={}));var tt;(function(t){t.ThemeSettings="ThemeSettings",t.Language="Language",t.BackButtonPressed="BackButtonPressed",t.ButtonPressed="ButtonPressed",t.SettingChanged="SettingChanged"})(tt||(tt={}));var et=function t(){"use strict";var e=this,o=this;E(this,t);var a=this;s(this,"subscriptions",{}),s(this,"promises",{}),s(this,"enableLog",!0),s(this,"callBackHandlers",{newEvent:function(r,n){var i=e.subscriptions[r];if(!i){v.warn("no subscription found with id ".concat(r));return}i(n)}}),s(this,"callFunction",function(r){for(var n=arguments.length,i=new Array(n>1?n-1:0),c=1;c<n;c++)i[c-1]=arguments[c];var f=j(),u={type:"functionCall",data:{reqId:f,name:r,args:i}};return window.parent.postMessage(u,"*"),new Promise(function(_,l){o.promises[f]=[_,l]})}),s(this,"send",function(r,n){return e.callFunction("send",r,n)}),s(this,"subscribe",function(){var r=N(function(n,i){var c,f,u=arguments;return S(this,function(_){switch(_.label){case 0:return c=u.length>2&&u[2]!==void 0?u[2]:null,[4,a.callFunction("subscribe",n,c)];case 1:return f=_.sent().subscriptionId,a.subscriptions[f]=i,[2,{unsubscribe:a.getUnsubscribe(f)}]}})});return function(n,i){return r.apply(this,arguments)}}()),s(this,"setupConsoleProxy",function(){var r=["log","warn","info","error"],n=e.sendLog.bind(e);r.forEach(function(i){window.console[i]=new Proxy(console[i],{apply:function(f,u,_){n({type:i,text:Z(_)}),Reflect.apply(f,u,h(_))}})})}),s(this,"sendLog",function(r){var n=r.text,i=r.type;if(e.enableLog){var c=j(),f={type:"sendLog",data:{reqId:c,name:"sendLog",logData:{text:n,type:i}}};window.parent.postMessage(f,"*")}}),s(this,"changeEnableLog",function(){var r=N(function(n){var i;return S(this,function(c){switch(c.label){case 0:return i=n.enabled,a.enableLog=i,[4,a.send(P.EnableLog,{active:i})];case 1:return c.sent(),[2]}})});return function(n){return r.apply(this,arguments)}}()),s(this,"getUnsubscribe",function(r){return function(){r in e.subscriptions&&delete e.subscriptions[r]}}),s(this,"handleMessage",function(r){var n=r.data;if((typeof n=="undefined"?"undefined":m(n))==="object")switch(n.type){case"functionCallReply":e.handleFunctionCallReply(n.data);break;case"callBack":e.handleCallBack(r,n.data);break}}),s(this,"handleFunctionCallReply",function(r){var n=e.promises[r.reqId];if(n){delete e.promises[r.reqId];var i=C(n,2),c=i[0],f=i[1];r.ok!==void 0?c(r.ok):(v.warn("rejecting req ".concat(r.reqId," promise: ").concat(JSON.stringify(r.err))),f(r.err))}else v.warn("got reply to unknown function call with id ".concat(r.reqId))}),s(this,"handleCallBack",function(r,n){var i=function(l){var U=l.ok,G=l.err,D;if(U===void 0==(G===void 0))return i({reqId:n.reqId,err:{code:b.INTERNAL_ERROR,reason:"callBack handler protocol violation"}});var rt={type:"callBackReply",data:{reqId:n.reqId,ok:U,err:G}};(D=r.source)===null||D===void 0||D.postMessage(rt,r.origin)},c={reqId:n.reqId};try{var f=e.callBackHandlers[n.name];if(!f){var u='got callBack request with unknown name "'.concat(n.name,'"');throw v.warn(u),new J(b.BAD_REQUEST,u)}c.ok=f.apply(void 0,h(n.args))||null}catch(l){var _=L(l)?l.reason:"callBack handler raised an exception";d(l,Error)&&(_+=' "'.concat(l.name,'": "').concat(l.message,'"')),c.err={code:L(l)?l.code:b.INTERNAL_ERROR,reason:_}}i(c)}),window.addEventListener("message",this.handleMessage),window.self!==window.parent&&this.setupConsoleProxy()};var A=new et,ft=A.send,st=A.subscribe;return ct(_t);})();
|
package/dist/types/Bridge.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["../../src/bridge.ts","../../src/error.ts","../../src/index.ts","../../src/teamstypes.ts","../../src/types.ts","../../src/helpers/getuniqueid.ts","../../src/helpers/logger.ts","../../src/helpers/logsutils.ts"],"version":"5.8.3"}
|