mezon-js 2.7.50 → 2.7.52
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/api.gen.ts +80 -35
- package/client.ts +13 -0
- package/dist/api.gen.d.ts +9 -2
- package/dist/client.d.ts +3 -1
- package/dist/mezon-js.cjs.js +86 -164
- package/dist/mezon-js.esm.mjs +86 -164
- package/dist/socket.d.ts +17 -222
- package/package.json +1 -1
- package/socket.ts +36 -374
package/dist/mezon-js.esm.mjs
CHANGED
@@ -577,19 +577,6 @@ var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
577
577
|
var utob = (u) => u.replace(re_utob, cb_utob);
|
578
578
|
var _encode = _hasBuffer ? (s) => Buffer.from(s, "utf8").toString("base64") : _TE ? (s) => _fromUint8Array(_TE.encode(s)) : (s) => _btoa(utob(s));
|
579
579
|
var encode = (src, urlsafe = false) => urlsafe ? _mkUriSafe(_encode(src)) : _encode(src);
|
580
|
-
var re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
|
581
|
-
var cb_btou = (cccc) => {
|
582
|
-
switch (cccc.length) {
|
583
|
-
case 4:
|
584
|
-
var cp = (7 & cccc.charCodeAt(0)) << 18 | (63 & cccc.charCodeAt(1)) << 12 | (63 & cccc.charCodeAt(2)) << 6 | 63 & cccc.charCodeAt(3), offset = cp - 65536;
|
585
|
-
return _fromCC((offset >>> 10) + 55296) + _fromCC((offset & 1023) + 56320);
|
586
|
-
case 3:
|
587
|
-
return _fromCC((15 & cccc.charCodeAt(0)) << 12 | (63 & cccc.charCodeAt(1)) << 6 | 63 & cccc.charCodeAt(2));
|
588
|
-
default:
|
589
|
-
return _fromCC((31 & cccc.charCodeAt(0)) << 6 | 63 & cccc.charCodeAt(1));
|
590
|
-
}
|
591
|
-
};
|
592
|
-
var btou = (b) => b.replace(re_btou, cb_btou);
|
593
580
|
var atobPolyfill = (asc) => {
|
594
581
|
asc = asc.replace(/\s+/g, "");
|
595
582
|
if (!b64re.test(asc))
|
@@ -603,10 +590,6 @@ var atobPolyfill = (asc) => {
|
|
603
590
|
return bin;
|
604
591
|
};
|
605
592
|
var _atob = _hasatob ? (asc) => atob(_tidyB64(asc)) : _hasBuffer ? (asc) => Buffer.from(asc, "base64").toString("binary") : atobPolyfill;
|
606
|
-
var _toUint8Array = _hasBuffer ? (a) => _U8Afrom(Buffer.from(a, "base64")) : (a) => _U8Afrom(_atob(a), (c) => c.charCodeAt(0));
|
607
|
-
var _decode = _hasBuffer ? (a) => Buffer.from(a, "base64").toString("utf8") : _TD ? (a) => _TD.decode(_toUint8Array(a)) : (a) => btou(_atob(a));
|
608
|
-
var _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == "-" ? "+" : "/"));
|
609
|
-
var decode2 = (src) => _decode(_unURI(src));
|
610
593
|
|
611
594
|
// utils.ts
|
612
595
|
function buildFetchOptions(method, options, bodyJson) {
|
@@ -2234,17 +2217,16 @@ var MezonApi = class {
|
|
2234
2217
|
)
|
2235
2218
|
]);
|
2236
2219
|
}
|
2237
|
-
/**
|
2238
|
-
|
2239
|
-
|
2240
|
-
throw new Error("'body' is a required parameter but is null or undefined.");
|
2241
|
-
}
|
2242
|
-
const urlPath = "/v2/direct/open";
|
2220
|
+
/** regist fcm device token */
|
2221
|
+
registFCMDeviceToken(bearerToken, token, deviceId, platform, options = {}) {
|
2222
|
+
const urlPath = "/v2/devicetoken";
|
2243
2223
|
const queryParams = /* @__PURE__ */ new Map();
|
2224
|
+
queryParams.set("token", token);
|
2225
|
+
queryParams.set("device_id", deviceId);
|
2226
|
+
queryParams.set("platform", platform);
|
2244
2227
|
let bodyJson = "";
|
2245
|
-
bodyJson = JSON.stringify(body || {});
|
2246
2228
|
const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
2247
|
-
const fetchOptions = buildFetchOptions("
|
2229
|
+
const fetchOptions = buildFetchOptions("POST", options, bodyJson);
|
2248
2230
|
if (bearerToken) {
|
2249
2231
|
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
2250
2232
|
}
|
@@ -2263,16 +2245,17 @@ var MezonApi = class {
|
|
2263
2245
|
)
|
2264
2246
|
]);
|
2265
2247
|
}
|
2266
|
-
/**
|
2267
|
-
|
2268
|
-
|
2248
|
+
/** close direct message. */
|
2249
|
+
closeDirectMess(bearerToken, body, options = {}) {
|
2250
|
+
if (body === null || body === void 0) {
|
2251
|
+
throw new Error("'body' is a required parameter but is null or undefined.");
|
2252
|
+
}
|
2253
|
+
const urlPath = "/v2/direct/close";
|
2269
2254
|
const queryParams = /* @__PURE__ */ new Map();
|
2270
|
-
queryParams.set("token", token);
|
2271
|
-
queryParams.set("device_id", deviceId);
|
2272
|
-
queryParams.set("platform", platform);
|
2273
2255
|
let bodyJson = "";
|
2256
|
+
bodyJson = JSON.stringify(body || {});
|
2274
2257
|
const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
2275
|
-
const fetchOptions = buildFetchOptions("
|
2258
|
+
const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
|
2276
2259
|
if (bearerToken) {
|
2277
2260
|
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
2278
2261
|
}
|
@@ -2291,12 +2274,12 @@ var MezonApi = class {
|
|
2291
2274
|
)
|
2292
2275
|
]);
|
2293
2276
|
}
|
2294
|
-
/**
|
2295
|
-
|
2277
|
+
/** open direct message. */
|
2278
|
+
openDirectMess(bearerToken, body, options = {}) {
|
2296
2279
|
if (body === null || body === void 0) {
|
2297
2280
|
throw new Error("'body' is a required parameter but is null or undefined.");
|
2298
2281
|
}
|
2299
|
-
const urlPath = "/v2/direct/
|
2282
|
+
const urlPath = "/v2/direct/open";
|
2300
2283
|
const queryParams = /* @__PURE__ */ new Map();
|
2301
2284
|
let bodyJson = "";
|
2302
2285
|
bodyJson = JSON.stringify(body || {});
|
@@ -3889,6 +3872,35 @@ var MezonApi = class {
|
|
3889
3872
|
)
|
3890
3873
|
]);
|
3891
3874
|
}
|
3875
|
+
/** Update channel private. */
|
3876
|
+
updateChannelPrivate(bearerToken, body, options = {}) {
|
3877
|
+
if (body === null || body === void 0) {
|
3878
|
+
throw new Error("'body' is a required parameter but is null or undefined.");
|
3879
|
+
}
|
3880
|
+
const urlPath = "/v2/updatechannelprivate";
|
3881
|
+
const queryParams = /* @__PURE__ */ new Map();
|
3882
|
+
let bodyJson = "";
|
3883
|
+
bodyJson = JSON.stringify(body || {});
|
3884
|
+
const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
3885
|
+
const fetchOptions = buildFetchOptions("PUT", options, bodyJson);
|
3886
|
+
if (bearerToken) {
|
3887
|
+
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
3888
|
+
}
|
3889
|
+
return Promise.race([
|
3890
|
+
fetch(fullUrl, fetchOptions).then((response) => {
|
3891
|
+
if (response.status == 204) {
|
3892
|
+
return response;
|
3893
|
+
} else if (response.status >= 200 && response.status < 300) {
|
3894
|
+
return response.json();
|
3895
|
+
} else {
|
3896
|
+
throw response;
|
3897
|
+
}
|
3898
|
+
}),
|
3899
|
+
new Promise(
|
3900
|
+
(_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
|
3901
|
+
)
|
3902
|
+
]);
|
3903
|
+
}
|
3892
3904
|
/** */
|
3893
3905
|
updateUserProfileByClan(bearerToken, clanId, body, options = {}) {
|
3894
3906
|
if (clanId === null || clanId === void 0) {
|
@@ -4118,7 +4130,7 @@ var encode2 = function(arraybuffer) {
|
|
4118
4130
|
}
|
4119
4131
|
return base64;
|
4120
4132
|
};
|
4121
|
-
var
|
4133
|
+
var decode2 = function(base64) {
|
4122
4134
|
var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
|
4123
4135
|
if (base64[base64.length - 1] === "=") {
|
4124
4136
|
bufferLength--;
|
@@ -4161,7 +4173,7 @@ var WebSocketAdapterText = class {
|
|
4161
4173
|
this._socket.onmessage = (evt) => {
|
4162
4174
|
const message = JSON.parse(evt.data);
|
4163
4175
|
if (message.party_data && message.party_data.data) {
|
4164
|
-
message.party_data.data = new Uint8Array(
|
4176
|
+
message.party_data.data = new Uint8Array(decode2(message.party_data.data));
|
4165
4177
|
}
|
4166
4178
|
value(message);
|
4167
4179
|
};
|
@@ -4298,19 +4310,6 @@ var _DefaultSocket = class _DefaultSocket {
|
|
4298
4310
|
this.onmessagereaction(message.message_reaction_event);
|
4299
4311
|
} else if (message.channel_presence_event) {
|
4300
4312
|
this.onchannelpresence(message.channel_presence_event);
|
4301
|
-
} else if (message.party_data) {
|
4302
|
-
message.party_data.op_code = parseInt(message.party_data.op_code);
|
4303
|
-
this.onpartydata(message.party_data);
|
4304
|
-
} else if (message.party_close) {
|
4305
|
-
this.onpartyclose(message.party_close);
|
4306
|
-
} else if (message.party_join_request) {
|
4307
|
-
this.onpartyjoinrequest(message.party_join_request);
|
4308
|
-
} else if (message.party_leader) {
|
4309
|
-
this.onpartyleader(message.party_leader);
|
4310
|
-
} else if (message.party_presence_event) {
|
4311
|
-
this.onpartypresence(message.party_presence_event);
|
4312
|
-
} else if (message.party) {
|
4313
|
-
this.onparty(message.party);
|
4314
4313
|
} else {
|
4315
4314
|
if (this.verbose && window && window.console) {
|
4316
4315
|
console.log("Unrecognized message received: %o", message);
|
@@ -4398,41 +4397,6 @@ var _DefaultSocket = class _DefaultSocket {
|
|
4398
4397
|
console.log(notification);
|
4399
4398
|
}
|
4400
4399
|
}
|
4401
|
-
onparty(party) {
|
4402
|
-
if (this.verbose && window && window.console) {
|
4403
|
-
console.log(party);
|
4404
|
-
}
|
4405
|
-
}
|
4406
|
-
onpartyclose(close) {
|
4407
|
-
if (this.verbose && window && window.console) {
|
4408
|
-
console.log("Party closed: " + close);
|
4409
|
-
}
|
4410
|
-
}
|
4411
|
-
onpartyjoinrequest(partyJoinRequest) {
|
4412
|
-
if (this.verbose && window && window.console) {
|
4413
|
-
console.log(partyJoinRequest);
|
4414
|
-
}
|
4415
|
-
}
|
4416
|
-
onpartydata(partyData) {
|
4417
|
-
if (this.verbose && window && window.console) {
|
4418
|
-
console.log(partyData);
|
4419
|
-
}
|
4420
|
-
}
|
4421
|
-
onpartyleader(partyLeader) {
|
4422
|
-
if (this.verbose && window && window.console) {
|
4423
|
-
console.log(partyLeader);
|
4424
|
-
}
|
4425
|
-
}
|
4426
|
-
onpartymatchmakerticket(partyMatched) {
|
4427
|
-
if (this.verbose && window && window.console) {
|
4428
|
-
console.log(partyMatched);
|
4429
|
-
}
|
4430
|
-
}
|
4431
|
-
onpartypresence(partyPresence) {
|
4432
|
-
if (this.verbose && window && window.console) {
|
4433
|
-
console.log(partyPresence);
|
4434
|
-
}
|
4435
|
-
}
|
4436
4400
|
onstatuspresence(statusPresence) {
|
4437
4401
|
if (this.verbose && window && window.console) {
|
4438
4402
|
console.log(statusPresence);
|
@@ -4494,47 +4458,19 @@ var _DefaultSocket = class _DefaultSocket {
|
|
4494
4458
|
if (!this.adapter.isOpen()) {
|
4495
4459
|
reject("Socket connection has not been established yet.");
|
4496
4460
|
} else {
|
4497
|
-
if (untypedMessage.
|
4498
|
-
|
4499
|
-
|
4500
|
-
|
4501
|
-
|
4502
|
-
|
4503
|
-
|
4504
|
-
|
4505
|
-
|
4506
|
-
|
4507
|
-
|
4508
|
-
|
4509
|
-
reject("The socket timed out while waiting for a response.");
|
4510
|
-
}, sendTimeout);
|
4511
|
-
untypedMessage.cid = cid;
|
4512
|
-
this.adapter.send(untypedMessage);
|
4513
|
-
}
|
4461
|
+
if (untypedMessage.channel_message_send) {
|
4462
|
+
untypedMessage.channel_message_send.content = JSON.stringify(untypedMessage.channel_message_send.content);
|
4463
|
+
} else if (untypedMessage.channel_message_update) {
|
4464
|
+
untypedMessage.channel_message_update.content = JSON.stringify(untypedMessage.channel_message_update.content);
|
4465
|
+
}
|
4466
|
+
const cid = this.generatecid();
|
4467
|
+
this.cIds[cid] = { resolve, reject };
|
4468
|
+
setTimeout(() => {
|
4469
|
+
reject("The socket timed out while waiting for a response.");
|
4470
|
+
}, sendTimeout);
|
4471
|
+
untypedMessage.cid = cid;
|
4472
|
+
this.adapter.send(untypedMessage);
|
4514
4473
|
}
|
4515
|
-
if (this.verbose && window && window.console) {
|
4516
|
-
const loggedMessage = __spreadValues({}, untypedMessage);
|
4517
|
-
if (loggedMessage.match_data_send && loggedMessage.match_data_send.data) {
|
4518
|
-
loggedMessage.match_data_send.data = decode2(loggedMessage.match_data_send.data);
|
4519
|
-
} else if (loggedMessage.party_data_send && loggedMessage.party_data_send.data) {
|
4520
|
-
loggedMessage.party_data_send.data = decode2(loggedMessage.party_data_send.data);
|
4521
|
-
}
|
4522
|
-
console.log("Sent message: %o", JSON.stringify(loggedMessage));
|
4523
|
-
}
|
4524
|
-
});
|
4525
|
-
}
|
4526
|
-
acceptPartyMember(party_id, presence) {
|
4527
|
-
return this.send({ party_accept: { party_id, presence } });
|
4528
|
-
}
|
4529
|
-
closeParty(party_id) {
|
4530
|
-
return __async(this, null, function* () {
|
4531
|
-
return yield this.send({ party_close: { party_id } });
|
4532
|
-
});
|
4533
|
-
}
|
4534
|
-
createParty(open, max_size) {
|
4535
|
-
return __async(this, null, function* () {
|
4536
|
-
const response = yield this.send({ party_create: { open, max_size } });
|
4537
|
-
return response.party;
|
4538
4474
|
});
|
4539
4475
|
}
|
4540
4476
|
followUsers(userIds) {
|
@@ -4553,13 +4489,12 @@ var _DefaultSocket = class _DefaultSocket {
|
|
4553
4489
|
return response.clan_join;
|
4554
4490
|
});
|
4555
4491
|
}
|
4556
|
-
joinChat(channel_id,
|
4492
|
+
joinChat(channel_id, mode, type, persistence, hidden) {
|
4557
4493
|
return __async(this, null, function* () {
|
4558
4494
|
const response = yield this.send(
|
4559
4495
|
{
|
4560
4496
|
channel_join: {
|
4561
4497
|
channel_id,
|
4562
|
-
channel_label,
|
4563
4498
|
mode,
|
4564
4499
|
type,
|
4565
4500
|
persistence,
|
@@ -4570,39 +4505,15 @@ var _DefaultSocket = class _DefaultSocket {
|
|
4570
4505
|
return response.channel;
|
4571
4506
|
});
|
4572
4507
|
}
|
4573
|
-
|
4574
|
-
return
|
4575
|
-
return yield this.send({ party_join: { party_id } });
|
4576
|
-
});
|
4577
|
-
}
|
4578
|
-
leaveChat(channel_id, channel_label, mode) {
|
4579
|
-
return this.send({ channel_leave: { channel_id, channel_label, mode } });
|
4580
|
-
}
|
4581
|
-
leaveMatch(matchId) {
|
4582
|
-
return this.send({ match_leave: { match_id: matchId } });
|
4583
|
-
}
|
4584
|
-
leaveParty(party_id) {
|
4585
|
-
return this.send({ party_leave: { party_id } });
|
4508
|
+
leaveChat(channel_id, mode) {
|
4509
|
+
return this.send({ channel_leave: { channel_id, mode } });
|
4586
4510
|
}
|
4587
|
-
|
4588
|
-
return __async(this, null, function* () {
|
4589
|
-
const response = yield this.send({ party_join_request_list: { party_id } });
|
4590
|
-
return response.party_join_request;
|
4591
|
-
});
|
4592
|
-
}
|
4593
|
-
promotePartyMember(party_id, party_member) {
|
4594
|
-
return __async(this, null, function* () {
|
4595
|
-
const response = yield this.send({ party_promote: { party_id, presence: party_member } });
|
4596
|
-
return response.party_leader;
|
4597
|
-
});
|
4598
|
-
}
|
4599
|
-
removeChatMessage(channel_id, channel_label, mode, message_id) {
|
4511
|
+
removeChatMessage(channel_id, mode, message_id) {
|
4600
4512
|
return __async(this, null, function* () {
|
4601
4513
|
const response = yield this.send(
|
4602
4514
|
{
|
4603
4515
|
channel_message_remove: {
|
4604
4516
|
channel_id,
|
4605
|
-
channel_label,
|
4606
4517
|
mode,
|
4607
4518
|
message_id
|
4608
4519
|
}
|
@@ -4639,36 +4550,36 @@ var _DefaultSocket = class _DefaultSocket {
|
|
4639
4550
|
unfollowUsers(user_ids) {
|
4640
4551
|
return this.send({ status_unfollow: { user_ids } });
|
4641
4552
|
}
|
4642
|
-
updateChatMessage(channel_id,
|
4553
|
+
updateChatMessage(channel_id, mode, message_id, content) {
|
4643
4554
|
return __async(this, null, function* () {
|
4644
|
-
const response = yield this.send({ channel_message_update: { channel_id,
|
4555
|
+
const response = yield this.send({ channel_message_update: { channel_id, message_id, content, mode } });
|
4645
4556
|
return response.channel_message_ack;
|
4646
4557
|
});
|
4647
4558
|
}
|
4648
4559
|
updateStatus(status) {
|
4649
4560
|
return this.send({ status_update: { status } });
|
4650
4561
|
}
|
4651
|
-
writeChatMessage(clan_id, channel_id,
|
4562
|
+
writeChatMessage(clan_id, channel_id, mode, content, mentions, attachments, references, anonymous_message, mention_everyone, notifi_content) {
|
4652
4563
|
return __async(this, null, function* () {
|
4653
|
-
const response = yield this.send({ channel_message_send: { clan_id, channel_id,
|
4564
|
+
const response = yield this.send({ channel_message_send: { clan_id, channel_id, mode, content, mentions, attachments, references, anonymous_message, mention_everyone, notifi_content } });
|
4654
4565
|
return response.channel_message_ack;
|
4655
4566
|
});
|
4656
4567
|
}
|
4657
|
-
writeMessageReaction(id, channel_id,
|
4568
|
+
writeMessageReaction(id, channel_id, mode, message_id, emoji, count, message_sender_id, action_delete) {
|
4658
4569
|
return __async(this, null, function* () {
|
4659
|
-
const response = yield this.send({ message_reaction_event: { id, channel_id,
|
4570
|
+
const response = yield this.send({ message_reaction_event: { id, channel_id, mode, message_id, emoji, count, message_sender_id, action: action_delete } });
|
4660
4571
|
return response.message_reaction_event;
|
4661
4572
|
});
|
4662
4573
|
}
|
4663
|
-
writeMessageTyping(channel_id,
|
4574
|
+
writeMessageTyping(channel_id, mode) {
|
4664
4575
|
return __async(this, null, function* () {
|
4665
|
-
const response = yield this.send({ message_typing_event: { channel_id,
|
4576
|
+
const response = yield this.send({ message_typing_event: { channel_id, mode } });
|
4666
4577
|
return response.message_typing_event;
|
4667
4578
|
});
|
4668
4579
|
}
|
4669
|
-
writeLastSeenMessage(channel_id,
|
4580
|
+
writeLastSeenMessage(channel_id, mode, message_id, timestamp) {
|
4670
4581
|
return __async(this, null, function* () {
|
4671
|
-
const response = yield this.send({ last_seen_message_event: { channel_id,
|
4582
|
+
const response = yield this.send({ last_seen_message_event: { channel_id, mode, message_id, timestamp } });
|
4672
4583
|
return response.last_seen_message_event;
|
4673
4584
|
});
|
4674
4585
|
}
|
@@ -6150,6 +6061,17 @@ var Client = class {
|
|
6150
6061
|
});
|
6151
6062
|
});
|
6152
6063
|
}
|
6064
|
+
/** update channel private*/
|
6065
|
+
updateChannelPrivate(session, request) {
|
6066
|
+
return __async(this, null, function* () {
|
6067
|
+
if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
|
6068
|
+
yield this.sessionRefresh(session);
|
6069
|
+
}
|
6070
|
+
return this.apiClient.updateChannelPrivate(session.token, request).then((response) => {
|
6071
|
+
return response !== void 0;
|
6072
|
+
});
|
6073
|
+
});
|
6074
|
+
}
|
6153
6075
|
/** get default notification clan */
|
6154
6076
|
getNotificationChannel(session, channelId) {
|
6155
6077
|
return __async(this, null, function* () {
|