mezon-js 2.9.93 → 2.9.95
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 +9 -6
- package/client.ts +15 -13
- package/dist/api.gen.d.ts +2 -1
- package/dist/client.d.ts +1 -1
- package/dist/mezon-js.cjs.js +43 -21
- package/dist/mezon-js.esm.mjs +43 -21
- package/dist/utils.d.ts +1 -0
- package/package.json +1 -1
- package/socket.ts +7 -6
- package/utils.ts +23 -0
- package/web_socket_adapter.ts +2 -1
package/api.gen.ts
CHANGED
@@ -2416,6 +2416,8 @@ export interface ApiWalletLedger {
|
|
2416
2416
|
//
|
2417
2417
|
id?: string;
|
2418
2418
|
//
|
2419
|
+
transaction_id?: string;
|
2420
|
+
//
|
2419
2421
|
user_id?: string;
|
2420
2422
|
//
|
2421
2423
|
value?: number;
|
@@ -9682,16 +9684,17 @@ pushPubKey(bearerToken: string,
|
|
9682
9684
|
}
|
9683
9685
|
|
9684
9686
|
/** Get user status */
|
9685
|
-
listWalletLedger(
|
9686
|
-
|
9687
|
-
|
9688
|
-
|
9689
|
-
|
9690
|
-
|
9687
|
+
listWalletLedger(bearerToken: string,
|
9688
|
+
limit?:number,
|
9689
|
+
cursor?:string,
|
9690
|
+
transactionId?:string,
|
9691
|
+
options: any = {}): Promise<ApiWalletLedgerList> {
|
9692
|
+
|
9691
9693
|
const urlPath = "/v2/walletledger";
|
9692
9694
|
const queryParams = new Map<string, any>();
|
9693
9695
|
queryParams.set("limit", limit);
|
9694
9696
|
queryParams.set("cursor", cursor);
|
9697
|
+
queryParams.set("transaction_id", transactionId);
|
9695
9698
|
|
9696
9699
|
let bodyJson: string = "";
|
9697
9700
|
|
package/client.ts
CHANGED
@@ -160,6 +160,7 @@ import {
|
|
160
160
|
|
161
161
|
import { Session } from "./session";
|
162
162
|
import { DefaultSocket, Socket } from "./socket";
|
163
|
+
import { safeJSONParse } from "./utils";
|
163
164
|
import { WebSocketAdapter, WebSocketAdapterText } from "./web_socket_adapter";
|
164
165
|
|
165
166
|
const DEFAULT_HOST = "127.0.0.1";
|
@@ -1346,7 +1347,7 @@ export class Client {
|
|
1346
1347
|
timezone: u.timezone,
|
1347
1348
|
update_time: u.update_time,
|
1348
1349
|
username: u.username,
|
1349
|
-
metadata: u.metadata ?
|
1350
|
+
metadata: u.metadata ? safeJSONParse(u.metadata) : undefined,
|
1350
1351
|
});
|
1351
1352
|
});
|
1352
1353
|
return Promise.resolve(result);
|
@@ -1434,27 +1435,27 @@ export class Client {
|
|
1434
1435
|
response.messages!.forEach((m) => {
|
1435
1436
|
var content, reactions, mentions, attachments, references;
|
1436
1437
|
try {
|
1437
|
-
content =
|
1438
|
+
content = safeJSONParse(m.content);
|
1438
1439
|
} catch (e) {
|
1439
1440
|
console.log("error parse content", e);
|
1440
1441
|
}
|
1441
1442
|
try {
|
1442
|
-
reactions =
|
1443
|
+
reactions = safeJSONParse(m.reactions || "[]");
|
1443
1444
|
} catch (e) {
|
1444
1445
|
console.log("error parse reactions", e);
|
1445
1446
|
}
|
1446
1447
|
try {
|
1447
|
-
mentions =
|
1448
|
+
mentions = safeJSONParse(m.mentions || "[]");
|
1448
1449
|
} catch (e) {
|
1449
1450
|
console.log("error parse mentions", e);
|
1450
1451
|
}
|
1451
1452
|
try {
|
1452
|
-
attachments =
|
1453
|
+
attachments = safeJSONParse(m.attachments || "[]");
|
1453
1454
|
} catch (e) {
|
1454
1455
|
console.log("error parse attachments", e);
|
1455
1456
|
}
|
1456
1457
|
try {
|
1457
|
-
references =
|
1458
|
+
references = safeJSONParse(m.references || "[]");
|
1458
1459
|
} catch (e) {
|
1459
1460
|
console.log("error parse references", e);
|
1460
1461
|
}
|
@@ -1689,7 +1690,7 @@ export class Client {
|
|
1689
1690
|
update_time: gu.user!.update_time,
|
1690
1691
|
username: gu.user!.username,
|
1691
1692
|
metadata: gu.user!.metadata
|
1692
|
-
?
|
1693
|
+
? safeJSONParse(gu.user!.metadata!)
|
1693
1694
|
: undefined,
|
1694
1695
|
},
|
1695
1696
|
role_id: gu!.role_id,
|
@@ -2208,7 +2209,7 @@ export class Client {
|
|
2208
2209
|
username: f.user!.username,
|
2209
2210
|
is_mobile: f.user?.is_mobile,
|
2210
2211
|
metadata: f.user!.metadata
|
2211
|
-
?
|
2212
|
+
? safeJSONParse(f.user!.metadata!)
|
2212
2213
|
: undefined,
|
2213
2214
|
},
|
2214
2215
|
state: f.state,
|
@@ -2253,7 +2254,7 @@ export class Client {
|
|
2253
2254
|
persistent: n.persistent,
|
2254
2255
|
sender_id: n.sender_id,
|
2255
2256
|
subject: n.subject,
|
2256
|
-
content: n.content ?
|
2257
|
+
content: n.content ? safeJSONParse(n.content) : undefined,
|
2257
2258
|
});
|
2258
2259
|
});
|
2259
2260
|
return Promise.resolve(result);
|
@@ -2287,7 +2288,7 @@ export class Client {
|
|
2287
2288
|
.then((response: ApiRpc) => {
|
2288
2289
|
return Promise.resolve({
|
2289
2290
|
id: response.id,
|
2290
|
-
payload: !response.payload ? undefined :
|
2291
|
+
payload: !response.payload ? undefined : safeJSONParse(response.payload),
|
2291
2292
|
});
|
2292
2293
|
});
|
2293
2294
|
}
|
@@ -2303,7 +2304,7 @@ export class Client {
|
|
2303
2304
|
.then((response: ApiRpc) => {
|
2304
2305
|
return Promise.resolve({
|
2305
2306
|
id: response.id,
|
2306
|
-
payload: !response.payload ? undefined :
|
2307
|
+
payload: !response.payload ? undefined : safeJSONParse(response.payload),
|
2307
2308
|
});
|
2308
2309
|
})
|
2309
2310
|
.catch((err: any) => {
|
@@ -4795,7 +4796,8 @@ export class Client {
|
|
4795
4796
|
async listWalletLedger(
|
4796
4797
|
session: Session,
|
4797
4798
|
limit?: number,
|
4798
|
-
cursor?: string
|
4799
|
+
cursor?: string,
|
4800
|
+
transactionId?: string
|
4799
4801
|
): Promise<ApiWalletLedgerList> {
|
4800
4802
|
if (
|
4801
4803
|
this.autoRefreshSession &&
|
@@ -4806,7 +4808,7 @@ export class Client {
|
|
4806
4808
|
}
|
4807
4809
|
|
4808
4810
|
return this.apiClient
|
4809
|
-
.listWalletLedger(session.token, limit, cursor)
|
4811
|
+
.listWalletLedger(session.token, limit, cursor, transactionId)
|
4810
4812
|
.then((response: ApiWalletLedgerList) => {
|
4811
4813
|
return Promise.resolve(response);
|
4812
4814
|
});
|
package/dist/api.gen.d.ts
CHANGED
@@ -1404,6 +1404,7 @@ export interface ApiVoiceChannelUserList {
|
|
1404
1404
|
export interface ApiWalletLedger {
|
1405
1405
|
create_time?: string;
|
1406
1406
|
id?: string;
|
1407
|
+
transaction_id?: string;
|
1407
1408
|
user_id?: string;
|
1408
1409
|
value?: number;
|
1409
1410
|
}
|
@@ -1931,7 +1932,7 @@ export declare class MezonApi {
|
|
1931
1932
|
/** Update user status */
|
1932
1933
|
updateUserStatus(bearerToken: string, body: ApiUserStatusUpdate, options?: any): Promise<any>;
|
1933
1934
|
/** Get user status */
|
1934
|
-
listWalletLedger(bearerToken: string, limit?: number, cursor?: string, options?: any): Promise<ApiWalletLedgerList>;
|
1935
|
+
listWalletLedger(bearerToken: string, limit?: number, cursor?: string, transactionId?: string, options?: any): Promise<ApiWalletLedgerList>;
|
1935
1936
|
/** create webhook */
|
1936
1937
|
generateWebhook(bearerToken: string, body: ApiWebhookCreateRequest, options?: any): Promise<any>;
|
1937
1938
|
/** update webhook name by id */
|
package/dist/client.d.ts
CHANGED
@@ -631,5 +631,5 @@ export declare class Client {
|
|
631
631
|
listPTTChannelUsers(session: Session, clanId: string, channelId: string, channelType: number, state?: number, limit?: number, cursor?: string): Promise<ApiPTTChannelUserList>;
|
632
632
|
getCustomDisplay(session: Session): Promise<ApiCustomDisplay>;
|
633
633
|
updateCustomDisplay(session: Session, request: ApiCustomDisplay): Promise<boolean>;
|
634
|
-
listWalletLedger(session: Session, limit?: number, cursor?: string): Promise<ApiWalletLedgerList>;
|
634
|
+
listWalletLedger(session: Session, limit?: number, cursor?: string, transactionId?: string): Promise<ApiWalletLedgerList>;
|
635
635
|
}
|
package/dist/mezon-js.cjs.js
CHANGED
@@ -680,6 +680,27 @@ function buildFetchOptions(method, options, bodyJson) {
|
|
680
680
|
}
|
681
681
|
return fetchOptions;
|
682
682
|
}
|
683
|
+
function safeJSONParse(jsonString) {
|
684
|
+
try {
|
685
|
+
const unescapedJSON = jsonString.replace(/\\./g, (match) => {
|
686
|
+
switch (match) {
|
687
|
+
case '\\"':
|
688
|
+
return '"';
|
689
|
+
case "\\n":
|
690
|
+
return "\n";
|
691
|
+
case "\\t":
|
692
|
+
return " ";
|
693
|
+
default:
|
694
|
+
return match[1];
|
695
|
+
}
|
696
|
+
});
|
697
|
+
const parsedData = JSON.parse(unescapedJSON);
|
698
|
+
return parsedData;
|
699
|
+
} catch (error) {
|
700
|
+
console.error("Error parsing JSON:", error);
|
701
|
+
return null;
|
702
|
+
}
|
703
|
+
}
|
683
704
|
|
684
705
|
// api.gen.ts
|
685
706
|
var MezonApi = class {
|
@@ -6145,11 +6166,12 @@ var MezonApi = class {
|
|
6145
6166
|
]);
|
6146
6167
|
}
|
6147
6168
|
/** Get user status */
|
6148
|
-
listWalletLedger(bearerToken, limit, cursor, options = {}) {
|
6169
|
+
listWalletLedger(bearerToken, limit, cursor, transactionId, options = {}) {
|
6149
6170
|
const urlPath = "/v2/walletledger";
|
6150
6171
|
const queryParams = /* @__PURE__ */ new Map();
|
6151
6172
|
queryParams.set("limit", limit);
|
6152
6173
|
queryParams.set("cursor", cursor);
|
6174
|
+
queryParams.set("transaction_id", transactionId);
|
6153
6175
|
let bodyJson = "";
|
6154
6176
|
const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
6155
6177
|
const fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
@@ -6882,7 +6904,7 @@ var WebSocketAdapterText = class {
|
|
6882
6904
|
set onMessage(value) {
|
6883
6905
|
if (value) {
|
6884
6906
|
this._socket.onmessage = (evt) => {
|
6885
|
-
const message =
|
6907
|
+
const message = safeJSONParse(evt.data);
|
6886
6908
|
if (message.party_data && message.party_data.data) {
|
6887
6909
|
message.party_data.data = new Uint8Array(
|
6888
6910
|
decode2(message.party_data.data)
|
@@ -6989,7 +7011,7 @@ var _DefaultSocket = class _DefaultSocket {
|
|
6989
7011
|
if (!message.cid) {
|
6990
7012
|
if (message.notifications) {
|
6991
7013
|
message.notifications.notifications.forEach((n) => {
|
6992
|
-
n.content = n.content ?
|
7014
|
+
n.content = n.content ? safeJSONParse(n.content) : void 0;
|
6993
7015
|
this.onnotification(n);
|
6994
7016
|
});
|
6995
7017
|
} else if (message.voice_started_event) {
|
@@ -7037,27 +7059,27 @@ var _DefaultSocket = class _DefaultSocket {
|
|
7037
7059
|
} else if (message.channel_message) {
|
7038
7060
|
var content, reactions, mentions, attachments, references;
|
7039
7061
|
try {
|
7040
|
-
content =
|
7062
|
+
content = safeJSONParse(message.channel_message.content);
|
7041
7063
|
} catch (e2) {
|
7042
7064
|
console.log("content is invalid", e2);
|
7043
7065
|
}
|
7044
7066
|
try {
|
7045
|
-
reactions =
|
7067
|
+
reactions = safeJSONParse(message.channel_message.reactions);
|
7046
7068
|
} catch (e2) {
|
7047
7069
|
console.log("reactions is invalid", e2);
|
7048
7070
|
}
|
7049
7071
|
try {
|
7050
|
-
mentions =
|
7072
|
+
mentions = safeJSONParse(message.channel_message.mentions);
|
7051
7073
|
} catch (e2) {
|
7052
7074
|
console.log("mentions is invalid", e2);
|
7053
7075
|
}
|
7054
7076
|
try {
|
7055
|
-
attachments =
|
7077
|
+
attachments = safeJSONParse(message.channel_message.attachments);
|
7056
7078
|
} catch (e2) {
|
7057
7079
|
console.log("attachments is invalid", e2);
|
7058
7080
|
}
|
7059
7081
|
try {
|
7060
|
-
references =
|
7082
|
+
references = safeJSONParse(message.channel_message.references);
|
7061
7083
|
} catch (e2) {
|
7062
7084
|
console.log("references is invalid", e2);
|
7063
7085
|
}
|
@@ -8382,7 +8404,7 @@ var Client = class {
|
|
8382
8404
|
timezone: u.timezone,
|
8383
8405
|
update_time: u.update_time,
|
8384
8406
|
username: u.username,
|
8385
|
-
metadata: u.metadata ?
|
8407
|
+
metadata: u.metadata ? safeJSONParse(u.metadata) : void 0
|
8386
8408
|
});
|
8387
8409
|
});
|
8388
8410
|
return Promise.resolve(result);
|
@@ -8436,27 +8458,27 @@ var Client = class {
|
|
8436
8458
|
response.messages.forEach((m) => {
|
8437
8459
|
var content, reactions, mentions, attachments, references;
|
8438
8460
|
try {
|
8439
|
-
content =
|
8461
|
+
content = safeJSONParse(m.content);
|
8440
8462
|
} catch (e) {
|
8441
8463
|
console.log("error parse content", e);
|
8442
8464
|
}
|
8443
8465
|
try {
|
8444
|
-
reactions =
|
8466
|
+
reactions = safeJSONParse(m.reactions || "[]");
|
8445
8467
|
} catch (e) {
|
8446
8468
|
console.log("error parse reactions", e);
|
8447
8469
|
}
|
8448
8470
|
try {
|
8449
|
-
mentions =
|
8471
|
+
mentions = safeJSONParse(m.mentions || "[]");
|
8450
8472
|
} catch (e) {
|
8451
8473
|
console.log("error parse mentions", e);
|
8452
8474
|
}
|
8453
8475
|
try {
|
8454
|
-
attachments =
|
8476
|
+
attachments = safeJSONParse(m.attachments || "[]");
|
8455
8477
|
} catch (e) {
|
8456
8478
|
console.log("error parse attachments", e);
|
8457
8479
|
}
|
8458
8480
|
try {
|
8459
|
-
references =
|
8481
|
+
references = safeJSONParse(m.references || "[]");
|
8460
8482
|
} catch (e) {
|
8461
8483
|
console.log("error parse references", e);
|
8462
8484
|
}
|
@@ -8632,7 +8654,7 @@ var Client = class {
|
|
8632
8654
|
timezone: gu.user.timezone,
|
8633
8655
|
update_time: gu.user.update_time,
|
8634
8656
|
username: gu.user.username,
|
8635
|
-
metadata: gu.user.metadata ?
|
8657
|
+
metadata: gu.user.metadata ? safeJSONParse(gu.user.metadata) : void 0
|
8636
8658
|
},
|
8637
8659
|
role_id: gu.role_id,
|
8638
8660
|
clan_nick: gu.clan_nick,
|
@@ -8937,7 +8959,7 @@ var Client = class {
|
|
8937
8959
|
update_time: f.user.update_time,
|
8938
8960
|
username: f.user.username,
|
8939
8961
|
is_mobile: (_a = f.user) == null ? void 0 : _a.is_mobile,
|
8940
|
-
metadata: f.user.metadata ?
|
8962
|
+
metadata: f.user.metadata ? safeJSONParse(f.user.metadata) : void 0
|
8941
8963
|
},
|
8942
8964
|
state: f.state
|
8943
8965
|
});
|
@@ -8968,7 +8990,7 @@ var Client = class {
|
|
8968
8990
|
persistent: n.persistent,
|
8969
8991
|
sender_id: n.sender_id,
|
8970
8992
|
subject: n.subject,
|
8971
|
-
content: n.content ?
|
8993
|
+
content: n.content ? safeJSONParse(n.content) : void 0
|
8972
8994
|
});
|
8973
8995
|
});
|
8974
8996
|
return Promise.resolve(result);
|
@@ -8990,7 +9012,7 @@ var Client = class {
|
|
8990
9012
|
).then((response) => {
|
8991
9013
|
return Promise.resolve({
|
8992
9014
|
id: response.id,
|
8993
|
-
payload: !response.payload ? void 0 :
|
9015
|
+
payload: !response.payload ? void 0 : safeJSONParse(response.payload)
|
8994
9016
|
});
|
8995
9017
|
});
|
8996
9018
|
});
|
@@ -9001,7 +9023,7 @@ var Client = class {
|
|
9001
9023
|
return this.apiClient.rpcFunc2("", id, input && JSON.stringify(input) || "", httpKey).then((response) => {
|
9002
9024
|
return Promise.resolve({
|
9003
9025
|
id: response.id,
|
9004
|
-
payload: !response.payload ? void 0 :
|
9026
|
+
payload: !response.payload ? void 0 : safeJSONParse(response.payload)
|
9005
9027
|
});
|
9006
9028
|
}).catch((err) => {
|
9007
9029
|
throw err;
|
@@ -10415,12 +10437,12 @@ var Client = class {
|
|
10415
10437
|
});
|
10416
10438
|
}
|
10417
10439
|
//**list wallet ledger */
|
10418
|
-
listWalletLedger(session, limit, cursor) {
|
10440
|
+
listWalletLedger(session, limit, cursor, transactionId) {
|
10419
10441
|
return __async(this, null, function* () {
|
10420
10442
|
if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
|
10421
10443
|
yield this.sessionRefresh(session);
|
10422
10444
|
}
|
10423
|
-
return this.apiClient.listWalletLedger(session.token, limit, cursor).then((response) => {
|
10445
|
+
return this.apiClient.listWalletLedger(session.token, limit, cursor, transactionId).then((response) => {
|
10424
10446
|
return Promise.resolve(response);
|
10425
10447
|
});
|
10426
10448
|
});
|
package/dist/mezon-js.esm.mjs
CHANGED
@@ -650,6 +650,27 @@ function buildFetchOptions(method, options, bodyJson) {
|
|
650
650
|
}
|
651
651
|
return fetchOptions;
|
652
652
|
}
|
653
|
+
function safeJSONParse(jsonString) {
|
654
|
+
try {
|
655
|
+
const unescapedJSON = jsonString.replace(/\\./g, (match) => {
|
656
|
+
switch (match) {
|
657
|
+
case '\\"':
|
658
|
+
return '"';
|
659
|
+
case "\\n":
|
660
|
+
return "\n";
|
661
|
+
case "\\t":
|
662
|
+
return " ";
|
663
|
+
default:
|
664
|
+
return match[1];
|
665
|
+
}
|
666
|
+
});
|
667
|
+
const parsedData = JSON.parse(unescapedJSON);
|
668
|
+
return parsedData;
|
669
|
+
} catch (error) {
|
670
|
+
console.error("Error parsing JSON:", error);
|
671
|
+
return null;
|
672
|
+
}
|
673
|
+
}
|
653
674
|
|
654
675
|
// api.gen.ts
|
655
676
|
var MezonApi = class {
|
@@ -6115,11 +6136,12 @@ var MezonApi = class {
|
|
6115
6136
|
]);
|
6116
6137
|
}
|
6117
6138
|
/** Get user status */
|
6118
|
-
listWalletLedger(bearerToken, limit, cursor, options = {}) {
|
6139
|
+
listWalletLedger(bearerToken, limit, cursor, transactionId, options = {}) {
|
6119
6140
|
const urlPath = "/v2/walletledger";
|
6120
6141
|
const queryParams = /* @__PURE__ */ new Map();
|
6121
6142
|
queryParams.set("limit", limit);
|
6122
6143
|
queryParams.set("cursor", cursor);
|
6144
|
+
queryParams.set("transaction_id", transactionId);
|
6123
6145
|
let bodyJson = "";
|
6124
6146
|
const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
6125
6147
|
const fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
@@ -6852,7 +6874,7 @@ var WebSocketAdapterText = class {
|
|
6852
6874
|
set onMessage(value) {
|
6853
6875
|
if (value) {
|
6854
6876
|
this._socket.onmessage = (evt) => {
|
6855
|
-
const message =
|
6877
|
+
const message = safeJSONParse(evt.data);
|
6856
6878
|
if (message.party_data && message.party_data.data) {
|
6857
6879
|
message.party_data.data = new Uint8Array(
|
6858
6880
|
decode2(message.party_data.data)
|
@@ -6959,7 +6981,7 @@ var _DefaultSocket = class _DefaultSocket {
|
|
6959
6981
|
if (!message.cid) {
|
6960
6982
|
if (message.notifications) {
|
6961
6983
|
message.notifications.notifications.forEach((n) => {
|
6962
|
-
n.content = n.content ?
|
6984
|
+
n.content = n.content ? safeJSONParse(n.content) : void 0;
|
6963
6985
|
this.onnotification(n);
|
6964
6986
|
});
|
6965
6987
|
} else if (message.voice_started_event) {
|
@@ -7007,27 +7029,27 @@ var _DefaultSocket = class _DefaultSocket {
|
|
7007
7029
|
} else if (message.channel_message) {
|
7008
7030
|
var content, reactions, mentions, attachments, references;
|
7009
7031
|
try {
|
7010
|
-
content =
|
7032
|
+
content = safeJSONParse(message.channel_message.content);
|
7011
7033
|
} catch (e2) {
|
7012
7034
|
console.log("content is invalid", e2);
|
7013
7035
|
}
|
7014
7036
|
try {
|
7015
|
-
reactions =
|
7037
|
+
reactions = safeJSONParse(message.channel_message.reactions);
|
7016
7038
|
} catch (e2) {
|
7017
7039
|
console.log("reactions is invalid", e2);
|
7018
7040
|
}
|
7019
7041
|
try {
|
7020
|
-
mentions =
|
7042
|
+
mentions = safeJSONParse(message.channel_message.mentions);
|
7021
7043
|
} catch (e2) {
|
7022
7044
|
console.log("mentions is invalid", e2);
|
7023
7045
|
}
|
7024
7046
|
try {
|
7025
|
-
attachments =
|
7047
|
+
attachments = safeJSONParse(message.channel_message.attachments);
|
7026
7048
|
} catch (e2) {
|
7027
7049
|
console.log("attachments is invalid", e2);
|
7028
7050
|
}
|
7029
7051
|
try {
|
7030
|
-
references =
|
7052
|
+
references = safeJSONParse(message.channel_message.references);
|
7031
7053
|
} catch (e2) {
|
7032
7054
|
console.log("references is invalid", e2);
|
7033
7055
|
}
|
@@ -8352,7 +8374,7 @@ var Client = class {
|
|
8352
8374
|
timezone: u.timezone,
|
8353
8375
|
update_time: u.update_time,
|
8354
8376
|
username: u.username,
|
8355
|
-
metadata: u.metadata ?
|
8377
|
+
metadata: u.metadata ? safeJSONParse(u.metadata) : void 0
|
8356
8378
|
});
|
8357
8379
|
});
|
8358
8380
|
return Promise.resolve(result);
|
@@ -8406,27 +8428,27 @@ var Client = class {
|
|
8406
8428
|
response.messages.forEach((m) => {
|
8407
8429
|
var content, reactions, mentions, attachments, references;
|
8408
8430
|
try {
|
8409
|
-
content =
|
8431
|
+
content = safeJSONParse(m.content);
|
8410
8432
|
} catch (e) {
|
8411
8433
|
console.log("error parse content", e);
|
8412
8434
|
}
|
8413
8435
|
try {
|
8414
|
-
reactions =
|
8436
|
+
reactions = safeJSONParse(m.reactions || "[]");
|
8415
8437
|
} catch (e) {
|
8416
8438
|
console.log("error parse reactions", e);
|
8417
8439
|
}
|
8418
8440
|
try {
|
8419
|
-
mentions =
|
8441
|
+
mentions = safeJSONParse(m.mentions || "[]");
|
8420
8442
|
} catch (e) {
|
8421
8443
|
console.log("error parse mentions", e);
|
8422
8444
|
}
|
8423
8445
|
try {
|
8424
|
-
attachments =
|
8446
|
+
attachments = safeJSONParse(m.attachments || "[]");
|
8425
8447
|
} catch (e) {
|
8426
8448
|
console.log("error parse attachments", e);
|
8427
8449
|
}
|
8428
8450
|
try {
|
8429
|
-
references =
|
8451
|
+
references = safeJSONParse(m.references || "[]");
|
8430
8452
|
} catch (e) {
|
8431
8453
|
console.log("error parse references", e);
|
8432
8454
|
}
|
@@ -8602,7 +8624,7 @@ var Client = class {
|
|
8602
8624
|
timezone: gu.user.timezone,
|
8603
8625
|
update_time: gu.user.update_time,
|
8604
8626
|
username: gu.user.username,
|
8605
|
-
metadata: gu.user.metadata ?
|
8627
|
+
metadata: gu.user.metadata ? safeJSONParse(gu.user.metadata) : void 0
|
8606
8628
|
},
|
8607
8629
|
role_id: gu.role_id,
|
8608
8630
|
clan_nick: gu.clan_nick,
|
@@ -8907,7 +8929,7 @@ var Client = class {
|
|
8907
8929
|
update_time: f.user.update_time,
|
8908
8930
|
username: f.user.username,
|
8909
8931
|
is_mobile: (_a = f.user) == null ? void 0 : _a.is_mobile,
|
8910
|
-
metadata: f.user.metadata ?
|
8932
|
+
metadata: f.user.metadata ? safeJSONParse(f.user.metadata) : void 0
|
8911
8933
|
},
|
8912
8934
|
state: f.state
|
8913
8935
|
});
|
@@ -8938,7 +8960,7 @@ var Client = class {
|
|
8938
8960
|
persistent: n.persistent,
|
8939
8961
|
sender_id: n.sender_id,
|
8940
8962
|
subject: n.subject,
|
8941
|
-
content: n.content ?
|
8963
|
+
content: n.content ? safeJSONParse(n.content) : void 0
|
8942
8964
|
});
|
8943
8965
|
});
|
8944
8966
|
return Promise.resolve(result);
|
@@ -8960,7 +8982,7 @@ var Client = class {
|
|
8960
8982
|
).then((response) => {
|
8961
8983
|
return Promise.resolve({
|
8962
8984
|
id: response.id,
|
8963
|
-
payload: !response.payload ? void 0 :
|
8985
|
+
payload: !response.payload ? void 0 : safeJSONParse(response.payload)
|
8964
8986
|
});
|
8965
8987
|
});
|
8966
8988
|
});
|
@@ -8971,7 +8993,7 @@ var Client = class {
|
|
8971
8993
|
return this.apiClient.rpcFunc2("", id, input && JSON.stringify(input) || "", httpKey).then((response) => {
|
8972
8994
|
return Promise.resolve({
|
8973
8995
|
id: response.id,
|
8974
|
-
payload: !response.payload ? void 0 :
|
8996
|
+
payload: !response.payload ? void 0 : safeJSONParse(response.payload)
|
8975
8997
|
});
|
8976
8998
|
}).catch((err) => {
|
8977
8999
|
throw err;
|
@@ -10385,12 +10407,12 @@ var Client = class {
|
|
10385
10407
|
});
|
10386
10408
|
}
|
10387
10409
|
//**list wallet ledger */
|
10388
|
-
listWalletLedger(session, limit, cursor) {
|
10410
|
+
listWalletLedger(session, limit, cursor, transactionId) {
|
10389
10411
|
return __async(this, null, function* () {
|
10390
10412
|
if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
|
10391
10413
|
yield this.sessionRefresh(session);
|
10392
10414
|
}
|
10393
|
-
return this.apiClient.listWalletLedger(session.token, limit, cursor).then((response) => {
|
10415
|
+
return this.apiClient.listWalletLedger(session.token, limit, cursor, transactionId).then((response) => {
|
10394
10416
|
return Promise.resolve(response);
|
10395
10417
|
});
|
10396
10418
|
});
|
package/dist/utils.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
1
|
export declare function buildFetchOptions(method: string, options: any, bodyJson: string): any;
|
2
2
|
export declare function b64EncodeUnicode(str: string): string;
|
3
3
|
export declare function b64DecodeUnicode(str: string): string;
|
4
|
+
export declare function safeJSONParse(jsonString: string): any;
|
package/package.json
CHANGED
package/socket.ts
CHANGED
@@ -32,6 +32,7 @@ import {
|
|
32
32
|
import { Session } from "./session";
|
33
33
|
import { ChannelMessage, Notification } from "./client";
|
34
34
|
import { WebSocketAdapter, WebSocketAdapterText } from "./web_socket_adapter";
|
35
|
+
import { safeJSONParse } from "./utils";
|
35
36
|
|
36
37
|
/** Stores function references for resolve/reject with a DOM Promise. */
|
37
38
|
interface PromiseExecutor {
|
@@ -1364,7 +1365,7 @@ export class DefaultSocket implements Socket {
|
|
1364
1365
|
if (!message.cid) {
|
1365
1366
|
if (message.notifications) {
|
1366
1367
|
message.notifications.notifications.forEach((n: ApiNotification) => {
|
1367
|
-
n.content = n.content ?
|
1368
|
+
n.content = n.content ? safeJSONParse(n.content) : undefined;
|
1368
1369
|
this.onnotification(n);
|
1369
1370
|
});
|
1370
1371
|
} else if (message.voice_started_event) {
|
@@ -1412,27 +1413,27 @@ export class DefaultSocket implements Socket {
|
|
1412
1413
|
} else if (message.channel_message) {
|
1413
1414
|
var content, reactions, mentions, attachments, references;
|
1414
1415
|
try {
|
1415
|
-
content =
|
1416
|
+
content = safeJSONParse(message.channel_message.content);
|
1416
1417
|
} catch (e) {
|
1417
1418
|
console.log("content is invalid", e);
|
1418
1419
|
}
|
1419
1420
|
try {
|
1420
|
-
reactions =
|
1421
|
+
reactions = safeJSONParse(message.channel_message.reactions);
|
1421
1422
|
} catch (e) {
|
1422
1423
|
console.log("reactions is invalid", e);
|
1423
1424
|
}
|
1424
1425
|
try {
|
1425
|
-
mentions =
|
1426
|
+
mentions = safeJSONParse(message.channel_message.mentions);
|
1426
1427
|
} catch (e) {
|
1427
1428
|
console.log("mentions is invalid", e);
|
1428
1429
|
}
|
1429
1430
|
try {
|
1430
|
-
attachments =
|
1431
|
+
attachments = safeJSONParse(message.channel_message.attachments);
|
1431
1432
|
} catch (e) {
|
1432
1433
|
console.log("attachments is invalid", e);
|
1433
1434
|
}
|
1434
1435
|
try {
|
1435
|
-
references =
|
1436
|
+
references = safeJSONParse(message.channel_message.references);
|
1436
1437
|
} catch (e) {
|
1437
1438
|
console.log("references is invalid", e);
|
1438
1439
|
}
|
package/utils.ts
CHANGED
@@ -47,3 +47,26 @@ export function b64DecodeUnicode(str: string) {
|
|
47
47
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
48
48
|
}).join(''));
|
49
49
|
}
|
50
|
+
|
51
|
+
export function safeJSONParse(jsonString: string) {
|
52
|
+
try {
|
53
|
+
// Step 1: Unescape JSON strings to handle double-escaped characters
|
54
|
+
const unescapedJSON = jsonString.replace(/\\./g, (match) => {
|
55
|
+
switch (match) {
|
56
|
+
case '\\"': return '"';
|
57
|
+
case '\\n': return '\n';
|
58
|
+
case '\\t': return '\t';
|
59
|
+
// Add more escape sequences as needed
|
60
|
+
default: return match[1]; // Remove the backslash
|
61
|
+
}
|
62
|
+
});
|
63
|
+
|
64
|
+
// Step 2: Parse the unescaped JSON
|
65
|
+
const parsedData = JSON.parse(unescapedJSON);
|
66
|
+
|
67
|
+
return parsedData;
|
68
|
+
} catch (error) {
|
69
|
+
console.error('Error parsing JSON:', error);
|
70
|
+
return null; // Handle the error gracefully or throw an exception if necessary
|
71
|
+
}
|
72
|
+
}
|
package/web_socket_adapter.ts
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
|
17
17
|
import { decode, encode } from "base64-arraybuffer";
|
18
18
|
import { btoa } from "js-base64";
|
19
|
+
import { safeJSONParse } from "./utils";
|
19
20
|
|
20
21
|
/**
|
21
22
|
* An interface used by Mezon's web socket to determine the payload protocol.
|
@@ -114,7 +115,7 @@ export class WebSocketAdapterText implements WebSocketAdapter {
|
|
114
115
|
set onMessage(value: SocketMessageHandler | null) {
|
115
116
|
if (value) {
|
116
117
|
this._socket!.onmessage = (evt: MessageEvent) => {
|
117
|
-
const message: any =
|
118
|
+
const message: any = safeJSONParse(evt.data);
|
118
119
|
if (message.party_data && message.party_data.data) {
|
119
120
|
message.party_data.data = new Uint8Array(
|
120
121
|
decode(message.party_data.data)
|