mezon-js 2.10.98 → 2.11.1
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/client.ts +32 -7
- package/dist/client.d.ts +3 -1
- package/dist/mezon-js.cjs.js +30 -8
- package/dist/mezon-js.esm.mjs +30 -8
- package/package.json +1 -1
package/client.ts
CHANGED
@@ -561,6 +561,9 @@ export class Client {
|
|
561
561
|
/** The low level API client for Mezon server. */
|
562
562
|
private readonly apiClient: MezonApi;
|
563
563
|
|
564
|
+
/** thre refreshTokenPromise */
|
565
|
+
private refreshTokenPromise: Promise<Session> | null = null;
|
566
|
+
|
564
567
|
constructor(
|
565
568
|
readonly serverkey = DEFAULT_SERVER_KEY,
|
566
569
|
readonly host = DEFAULT_HOST,
|
@@ -2404,12 +2407,34 @@ export class Client {
|
|
2404
2407
|
);
|
2405
2408
|
}
|
2406
2409
|
|
2407
|
-
|
2408
|
-
|
2409
|
-
|
2410
|
+
if (this.refreshTokenPromise) {
|
2411
|
+
return this.refreshTokenPromise; // Reuse existing promise
|
2412
|
+
}
|
2413
|
+
|
2414
|
+
this.refreshTokenPromise = new Promise<Session>(async (resolve, reject) => {
|
2415
|
+
try {
|
2416
|
+
const apiSession = await this.apiClient.sessionRefresh(
|
2417
|
+
this.serverkey,
|
2418
|
+
"",
|
2419
|
+
{
|
2420
|
+
token: session.refresh_token,
|
2421
|
+
vars: vars,
|
2422
|
+
}
|
2423
|
+
);
|
2424
|
+
session.update(apiSession.token!, apiSession.refresh_token!);
|
2425
|
+
resolve(session);
|
2426
|
+
} catch (error) {
|
2427
|
+
console.error("Session refresh failed:", error);
|
2428
|
+
reject(error);
|
2429
|
+
} finally {
|
2430
|
+
const refreshTokenPromiseTimeoutId = setTimeout(() => {
|
2431
|
+
this.refreshTokenPromise = null;
|
2432
|
+
clearInterval(refreshTokenPromiseTimeoutId);
|
2433
|
+
}, 1000);
|
2434
|
+
}
|
2410
2435
|
});
|
2411
|
-
|
2412
|
-
return
|
2436
|
+
|
2437
|
+
return this.refreshTokenPromise;
|
2413
2438
|
}
|
2414
2439
|
|
2415
2440
|
/** Remove the Apple ID from the social profiles on the current user's account. */
|
@@ -4134,7 +4159,7 @@ export class Client {
|
|
4134
4159
|
type?: number,
|
4135
4160
|
limit?: number,
|
4136
4161
|
page?: number,
|
4137
|
-
|
4162
|
+
channelLabel?: string
|
4138
4163
|
): Promise<ApiChannelSettingListResponse> {
|
4139
4164
|
if (
|
4140
4165
|
this.autoRefreshSession &&
|
@@ -4156,7 +4181,7 @@ export class Client {
|
|
4156
4181
|
type,
|
4157
4182
|
limit,
|
4158
4183
|
page,
|
4159
|
-
|
4184
|
+
channelLabel
|
4160
4185
|
)
|
4161
4186
|
.then((response: any) => {
|
4162
4187
|
return Promise.resolve(response);
|
package/dist/client.d.ts
CHANGED
@@ -347,6 +347,8 @@ export declare class Client {
|
|
347
347
|
expiredTimespanMs: number;
|
348
348
|
/** The low level API client for Mezon server. */
|
349
349
|
private readonly apiClient;
|
350
|
+
/** thre refreshTokenPromise */
|
351
|
+
private refreshTokenPromise;
|
350
352
|
constructor(serverkey?: string, host?: string, port?: string, useSSL?: boolean, timeout?: number, autoRefreshSession?: boolean);
|
351
353
|
/** Add users to a channel, or accept their join requests. */
|
352
354
|
addChannelUsers(session: Session, channelId: string, ids?: Array<string>): Promise<boolean>;
|
@@ -600,7 +602,7 @@ export declare class Client {
|
|
600
602
|
/** List Threads. */
|
601
603
|
listThreadDescs(session: Session, channelId: string, limit?: number, state?: number, clanId?: string, threadId?: string, page?: number): Promise<ApiChannelDescList>;
|
602
604
|
leaveThread(session: Session, channelId: string): Promise<any>;
|
603
|
-
getChannelSettingInClan(session: Session, clanId: string, parentId?: string, categoryId?: string, privateChannel?: number, active?: number, status?: number, type?: number, limit?: number, page?: number,
|
605
|
+
getChannelSettingInClan(session: Session, clanId: string, parentId?: string, categoryId?: string, privateChannel?: number, active?: number, status?: number, type?: number, limit?: number, page?: number, channelLabel?: string): Promise<ApiChannelSettingListResponse>;
|
604
606
|
getChannelCanvasList(session: Session, channelId: string, clanId?: string, limit?: number, page?: number): Promise<ApiChannelCanvasListResponse>;
|
605
607
|
getChannelCanvasDetail(session: Session, id: string, clanId?: string, channelId?: string): Promise<any>;
|
606
608
|
editChannelCanvases(session: Session, request: ApiEditChannelCanvasRequest): Promise<any>;
|
package/dist/mezon-js.cjs.js
CHANGED
@@ -8352,6 +8352,8 @@ var Client = class {
|
|
8352
8352
|
this.autoRefreshSession = autoRefreshSession;
|
8353
8353
|
/** The expired timespan used to check session lifetime. */
|
8354
8354
|
this.expiredTimespanMs = DEFAULT_EXPIRED_TIMESPAN_MS;
|
8355
|
+
/** thre refreshTokenPromise */
|
8356
|
+
this.refreshTokenPromise = null;
|
8355
8357
|
const scheme = useSSL ? "https://" : "http://";
|
8356
8358
|
const basePath = `${scheme}${host}:${port}`;
|
8357
8359
|
this.apiClient = new MezonApi(serverkey, basePath, timeout);
|
@@ -9506,12 +9508,32 @@ var Client = class {
|
|
9506
9508
|
"Session refresh lifetime too short, please set '--session.refresh_token_expiry_sec' option. See the documentation for more info: https://mezon.vn/docs/mezon/getting-started/configuration/#session"
|
9507
9509
|
);
|
9508
9510
|
}
|
9509
|
-
|
9510
|
-
|
9511
|
-
|
9512
|
-
|
9513
|
-
|
9514
|
-
|
9511
|
+
if (this.refreshTokenPromise) {
|
9512
|
+
return this.refreshTokenPromise;
|
9513
|
+
}
|
9514
|
+
this.refreshTokenPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
9515
|
+
try {
|
9516
|
+
const apiSession = yield this.apiClient.sessionRefresh(
|
9517
|
+
this.serverkey,
|
9518
|
+
"",
|
9519
|
+
{
|
9520
|
+
token: session.refresh_token,
|
9521
|
+
vars
|
9522
|
+
}
|
9523
|
+
);
|
9524
|
+
session.update(apiSession.token, apiSession.refresh_token);
|
9525
|
+
resolve(session);
|
9526
|
+
} catch (error) {
|
9527
|
+
console.error("Session refresh failed:", error);
|
9528
|
+
reject(error);
|
9529
|
+
} finally {
|
9530
|
+
const refreshTokenPromiseTimeoutId = setTimeout(() => {
|
9531
|
+
this.refreshTokenPromise = null;
|
9532
|
+
clearInterval(refreshTokenPromiseTimeoutId);
|
9533
|
+
}, 1e3);
|
9534
|
+
}
|
9535
|
+
}));
|
9536
|
+
return this.refreshTokenPromise;
|
9515
9537
|
});
|
9516
9538
|
}
|
9517
9539
|
/** Remove the Apple ID from the social profiles on the current user's account. */
|
@@ -10469,7 +10491,7 @@ var Client = class {
|
|
10469
10491
|
});
|
10470
10492
|
});
|
10471
10493
|
}
|
10472
|
-
getChannelSettingInClan(session, clanId, parentId, categoryId, privateChannel, active, status, type, limit, page,
|
10494
|
+
getChannelSettingInClan(session, clanId, parentId, categoryId, privateChannel, active, status, type, limit, page, channelLabel) {
|
10473
10495
|
return __async(this, null, function* () {
|
10474
10496
|
if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
|
10475
10497
|
yield this.sessionRefresh(session);
|
@@ -10485,7 +10507,7 @@ var Client = class {
|
|
10485
10507
|
type,
|
10486
10508
|
limit,
|
10487
10509
|
page,
|
10488
|
-
|
10510
|
+
channelLabel
|
10489
10511
|
).then((response) => {
|
10490
10512
|
return Promise.resolve(response);
|
10491
10513
|
});
|
package/dist/mezon-js.esm.mjs
CHANGED
@@ -8318,6 +8318,8 @@ var Client = class {
|
|
8318
8318
|
this.autoRefreshSession = autoRefreshSession;
|
8319
8319
|
/** The expired timespan used to check session lifetime. */
|
8320
8320
|
this.expiredTimespanMs = DEFAULT_EXPIRED_TIMESPAN_MS;
|
8321
|
+
/** thre refreshTokenPromise */
|
8322
|
+
this.refreshTokenPromise = null;
|
8321
8323
|
const scheme = useSSL ? "https://" : "http://";
|
8322
8324
|
const basePath = `${scheme}${host}:${port}`;
|
8323
8325
|
this.apiClient = new MezonApi(serverkey, basePath, timeout);
|
@@ -9472,12 +9474,32 @@ var Client = class {
|
|
9472
9474
|
"Session refresh lifetime too short, please set '--session.refresh_token_expiry_sec' option. See the documentation for more info: https://mezon.vn/docs/mezon/getting-started/configuration/#session"
|
9473
9475
|
);
|
9474
9476
|
}
|
9475
|
-
|
9476
|
-
|
9477
|
-
|
9478
|
-
|
9479
|
-
|
9480
|
-
|
9477
|
+
if (this.refreshTokenPromise) {
|
9478
|
+
return this.refreshTokenPromise;
|
9479
|
+
}
|
9480
|
+
this.refreshTokenPromise = new Promise((resolve, reject) => __async(this, null, function* () {
|
9481
|
+
try {
|
9482
|
+
const apiSession = yield this.apiClient.sessionRefresh(
|
9483
|
+
this.serverkey,
|
9484
|
+
"",
|
9485
|
+
{
|
9486
|
+
token: session.refresh_token,
|
9487
|
+
vars
|
9488
|
+
}
|
9489
|
+
);
|
9490
|
+
session.update(apiSession.token, apiSession.refresh_token);
|
9491
|
+
resolve(session);
|
9492
|
+
} catch (error) {
|
9493
|
+
console.error("Session refresh failed:", error);
|
9494
|
+
reject(error);
|
9495
|
+
} finally {
|
9496
|
+
const refreshTokenPromiseTimeoutId = setTimeout(() => {
|
9497
|
+
this.refreshTokenPromise = null;
|
9498
|
+
clearInterval(refreshTokenPromiseTimeoutId);
|
9499
|
+
}, 1e3);
|
9500
|
+
}
|
9501
|
+
}));
|
9502
|
+
return this.refreshTokenPromise;
|
9481
9503
|
});
|
9482
9504
|
}
|
9483
9505
|
/** Remove the Apple ID from the social profiles on the current user's account. */
|
@@ -10435,7 +10457,7 @@ var Client = class {
|
|
10435
10457
|
});
|
10436
10458
|
});
|
10437
10459
|
}
|
10438
|
-
getChannelSettingInClan(session, clanId, parentId, categoryId, privateChannel, active, status, type, limit, page,
|
10460
|
+
getChannelSettingInClan(session, clanId, parentId, categoryId, privateChannel, active, status, type, limit, page, channelLabel) {
|
10439
10461
|
return __async(this, null, function* () {
|
10440
10462
|
if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) {
|
10441
10463
|
yield this.sessionRefresh(session);
|
@@ -10451,7 +10473,7 @@ var Client = class {
|
|
10451
10473
|
type,
|
10452
10474
|
limit,
|
10453
10475
|
page,
|
10454
|
-
|
10476
|
+
channelLabel
|
10455
10477
|
).then((response) => {
|
10456
10478
|
return Promise.resolve(response);
|
10457
10479
|
});
|