mezon-js 2.12.2 → 2.12.4

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 CHANGED
@@ -3157,11 +3157,18 @@ export interface ApiUserEventRequest {
3157
3157
  }
3158
3158
 
3159
3159
  export class MezonApi {
3160
+ basePath: string;
3160
3161
  constructor(
3161
3162
  readonly serverKey: string,
3162
- readonly basePath: string,
3163
- readonly timeoutMs: number
3164
- ) {}
3163
+ readonly timeoutMs: number,
3164
+ basePath: string,
3165
+ ) {
3166
+ this.basePath = basePath
3167
+ }
3168
+
3169
+ setBasePath(basePath: string) {
3170
+ this.basePath = basePath;
3171
+ }
3165
3172
 
3166
3173
  /** A healthcheck which load balancers can use to check the service. */
3167
3174
  healthcheck(bearerToken: string, options: any = {}): Promise<any> {
@@ -3291,7 +3298,6 @@ export class MezonApi {
3291
3298
 
3292
3299
  /** */
3293
3300
  checkLoginRequest(
3294
- basePath: string,
3295
3301
  basicAuthUsername: string,
3296
3302
  basicAuthPassword: string,
3297
3303
  body: ApiConfirmLoginRequest,
@@ -3308,7 +3314,7 @@ export class MezonApi {
3308
3314
  let bodyJson: string = "";
3309
3315
  bodyJson = JSON.stringify(body || {});
3310
3316
 
3311
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
3317
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
3312
3318
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
3313
3319
  if (basicAuthUsername) {
3314
3320
  fetchOptions.headers["Authorization"] =
@@ -3333,7 +3339,6 @@ export class MezonApi {
3333
3339
 
3334
3340
  /** */
3335
3341
  confirmLogin(
3336
- basePath: string,
3337
3342
  bearerToken: string,
3338
3343
  body: ApiConfirmLoginRequest,
3339
3344
  options: any = {}
@@ -3349,7 +3354,7 @@ export class MezonApi {
3349
3354
  let bodyJson: string = "";
3350
3355
  bodyJson = JSON.stringify(body || {});
3351
3356
 
3352
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
3357
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
3353
3358
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
3354
3359
  if (bearerToken) {
3355
3360
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
@@ -3373,7 +3378,6 @@ export class MezonApi {
3373
3378
 
3374
3379
  /** */
3375
3380
  createQRLogin(
3376
- basePath: string,
3377
3381
  basicAuthUsername: string,
3378
3382
  basicAuthPassword: string,
3379
3383
  body: ApiLoginRequest,
@@ -3390,7 +3394,7 @@ export class MezonApi {
3390
3394
  let bodyJson: string = "";
3391
3395
  bodyJson = JSON.stringify(body || {});
3392
3396
 
3393
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
3397
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
3394
3398
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
3395
3399
  if (basicAuthUsername) {
3396
3400
  fetchOptions.headers["Authorization"] =
@@ -3416,7 +3420,6 @@ export class MezonApi {
3416
3420
 
3417
3421
  /** Authenticate a user with an email+password against the server. */
3418
3422
  authenticateEmail(
3419
- basePath: string,
3420
3423
  basicAuthUsername: string,
3421
3424
  basicAuthPassword: string,
3422
3425
  body:ApiAuthenticateEmailRequest,
@@ -3431,7 +3434,7 @@ export class MezonApi {
3431
3434
  let bodyJson : string = "";
3432
3435
  bodyJson = JSON.stringify(body || {});
3433
3436
 
3434
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
3437
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
3435
3438
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
3436
3439
  if (basicAuthUsername) {
3437
3440
  fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
@@ -3455,7 +3458,6 @@ export class MezonApi {
3455
3458
 
3456
3459
  /** Authenticate a user with Mezon against the server. */
3457
3460
  authenticateMezon(
3458
- basePath: string,
3459
3461
  basicAuthUsername: string,
3460
3462
  basicAuthPassword: string,
3461
3463
  account:ApiAccountMezon,
@@ -3477,7 +3479,7 @@ export class MezonApi {
3477
3479
  let bodyJson : string = "";
3478
3480
  bodyJson = JSON.stringify(account || {});
3479
3481
 
3480
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
3482
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
3481
3483
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
3482
3484
  if (basicAuthUsername) {
3483
3485
  fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
package/client.ts CHANGED
@@ -573,12 +573,11 @@ export class Client {
573
573
  const scheme = useSSL ? "https://" : "http://";
574
574
  const basePath = `${scheme}${host}:${port}`;
575
575
 
576
- this.apiClient = new MezonApi(serverkey, basePath, timeout);
576
+ this.apiClient = new MezonApi(serverkey, timeout, basePath);
577
577
  }
578
578
 
579
579
  /** Authenticate a user with a custom id against the server. */
580
580
  authenticateMezon(
581
- basePath: string,
582
581
  token: string,
583
582
  create?: boolean,
584
583
  username?: string,
@@ -592,7 +591,6 @@ export class Client {
592
591
  };
593
592
  return this.apiClient
594
593
  .authenticateMezon(
595
- basePath,
596
594
  this.serverkey,
597
595
  "",
598
596
  request,
@@ -606,6 +604,7 @@ export class Client {
606
604
  apiSession.token || "",
607
605
  apiSession.refresh_token || "",
608
606
  apiSession.created || false,
607
+ apiSession.api_url || "",
609
608
  false
610
609
  );
611
610
  });
@@ -613,7 +612,6 @@ export class Client {
613
612
 
614
613
  /** Authenticate a user with an email+password against the server. */
615
614
  authenticateEmail(
616
- basePath: string,
617
615
  email: string,
618
616
  password: string,
619
617
  username?: string,
@@ -629,17 +627,24 @@ export class Client {
629
627
  };
630
628
 
631
629
  return this.apiClient
632
- .authenticateEmail(basePath, this.serverkey, "", request, username)
630
+ .authenticateEmail(this.serverkey, "", request, username)
633
631
  .then((apiSession: ApiSession) => {
634
632
  return new Session(
635
633
  apiSession.token || "",
636
634
  apiSession.refresh_token || "",
637
- apiSession.created || false,
638
- false
635
+ apiSession.created || false,
636
+ apiSession.api_url || "",
637
+ false,
639
638
  );
640
639
  });
641
640
  }
642
641
 
642
+ /** set base path */
643
+ setBasePath(basePath: string) {
644
+ return this.apiClient
645
+ .setBasePath(basePath);
646
+ }
647
+
643
648
  /** Add users to a channel, or accept their join requests. */
644
649
  async addChannelUsers(
645
650
  session: Session,
@@ -3901,9 +3906,8 @@ export class Client {
3901
3906
  });
3902
3907
  }
3903
3908
 
3904
- async createQRLogin(basePath: string, requet: ApiLoginRequest): Promise<ApiLoginIDResponse> {
3909
+ async createQRLogin(requet: ApiLoginRequest): Promise<ApiLoginIDResponse> {
3905
3910
  const apiSession = await this.apiClient.createQRLogin(
3906
- basePath,
3907
3911
  this.serverkey,
3908
3912
  "",
3909
3913
  requet
@@ -3916,11 +3920,9 @@ export class Client {
3916
3920
  }
3917
3921
 
3918
3922
  async checkLoginRequest(
3919
- basePath: string,
3920
3923
  requet: ApiConfirmLoginRequest
3921
3924
  ): Promise<Session | null> {
3922
3925
  const apiSession = await this.apiClient.checkLoginRequest(
3923
- basePath,
3924
3926
  this.serverkey,
3925
3927
  "",
3926
3928
  requet
@@ -3932,12 +3934,12 @@ export class Client {
3932
3934
  apiSession.token || "",
3933
3935
  apiSession.refresh_token || "",
3934
3936
  apiSession.created || false,
3937
+ apiSession.api_url || "",
3935
3938
  apiSession.is_remember || false
3936
3939
  );
3937
3940
  }
3938
3941
 
3939
3942
  async confirmLogin(
3940
- basePath: string,
3941
3943
  session: Session,
3942
3944
  body: ApiConfirmLoginRequest
3943
3945
  ): Promise<any> {
@@ -3950,7 +3952,7 @@ export class Client {
3950
3952
  }
3951
3953
 
3952
3954
  return this.apiClient
3953
- .confirmLogin(basePath, session.token, body)
3955
+ .confirmLogin(session.token, body)
3954
3956
  .then((response: any) => {
3955
3957
  return response;
3956
3958
  });
package/dist/api.gen.d.ts CHANGED
@@ -1809,9 +1809,10 @@ export interface ApiUserEventRequest {
1809
1809
  }
1810
1810
  export declare class MezonApi {
1811
1811
  readonly serverKey: string;
1812
- readonly basePath: string;
1813
1812
  readonly timeoutMs: number;
1814
- constructor(serverKey: string, basePath: string, timeoutMs: number);
1813
+ basePath: string;
1814
+ constructor(serverKey: string, timeoutMs: number, basePath: string);
1815
+ setBasePath(basePath: string): void;
1815
1816
  /** A healthcheck which load balancers can use to check the service. */
1816
1817
  healthcheck(bearerToken: string, options?: any): Promise<any>;
1817
1818
  /** Delete the current user's account. */
@@ -1821,15 +1822,15 @@ export declare class MezonApi {
1821
1822
  /** Update fields in the current user's account. */
1822
1823
  updateAccount(bearerToken: string, body: ApiUpdateAccountRequest, options?: any): Promise<any>;
1823
1824
  /** */
1824
- checkLoginRequest(basePath: string, basicAuthUsername: string, basicAuthPassword: string, body: ApiConfirmLoginRequest, options?: any): Promise<ApiSession>;
1825
+ checkLoginRequest(basicAuthUsername: string, basicAuthPassword: string, body: ApiConfirmLoginRequest, options?: any): Promise<ApiSession>;
1825
1826
  /** */
1826
- confirmLogin(basePath: string, bearerToken: string, body: ApiConfirmLoginRequest, options?: any): Promise<any>;
1827
+ confirmLogin(bearerToken: string, body: ApiConfirmLoginRequest, options?: any): Promise<any>;
1827
1828
  /** */
1828
- createQRLogin(basePath: string, basicAuthUsername: string, basicAuthPassword: string, body: ApiLoginRequest, options?: any): Promise<ApiLoginIDResponse>;
1829
+ createQRLogin(basicAuthUsername: string, basicAuthPassword: string, body: ApiLoginRequest, options?: any): Promise<ApiLoginIDResponse>;
1829
1830
  /** Authenticate a user with an email+password against the server. */
1830
- authenticateEmail(basePath: string, basicAuthUsername: string, basicAuthPassword: string, body: ApiAuthenticateEmailRequest, options?: any): Promise<ApiSession>;
1831
+ authenticateEmail(basicAuthUsername: string, basicAuthPassword: string, body: ApiAuthenticateEmailRequest, options?: any): Promise<ApiSession>;
1831
1832
  /** Authenticate a user with Mezon against the server. */
1832
- authenticateMezon(basePath: string, basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountMezon, create?: boolean, username?: string, isRemember?: boolean, options?: any): Promise<ApiSession>;
1833
+ authenticateMezon(basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountMezon, create?: boolean, username?: string, isRemember?: boolean, options?: any): Promise<ApiSession>;
1833
1834
  /** Add an email+password to the social profiles on the current user's account. */
1834
1835
  linkEmail(bearerToken: string, body: ApiAccountEmail, options?: any): Promise<any>;
1835
1836
  /** Add a mezon ID to the social profiles on the current user's account. */
package/dist/client.d.ts CHANGED
@@ -353,9 +353,11 @@ export declare class Client {
353
353
  private refreshTokenPromise;
354
354
  constructor(serverkey?: string, host?: string, port?: string, useSSL?: boolean, timeout?: number, autoRefreshSession?: boolean);
355
355
  /** Authenticate a user with a custom id against the server. */
356
- authenticateMezon(basePath: string, token: string, create?: boolean, username?: string, isRemember?: boolean, vars?: Record<string, string>, options?: any): Promise<Session>;
356
+ authenticateMezon(token: string, create?: boolean, username?: string, isRemember?: boolean, vars?: Record<string, string>, options?: any): Promise<Session>;
357
357
  /** Authenticate a user with an email+password against the server. */
358
- authenticateEmail(basePath: string, email: string, password: string, username?: string, vars?: Record<string, string>): Promise<Session>;
358
+ authenticateEmail(email: string, password: string, username?: string, vars?: Record<string, string>): Promise<Session>;
359
+ /** set base path */
360
+ setBasePath(basePath: string): void;
359
361
  /** Add users to a channel, or accept their join requests. */
360
362
  addChannelUsers(session: Session, channelId: string, ids?: Array<string>): Promise<boolean>;
361
363
  /** Add friends by ID or username to a user's account. */
@@ -572,9 +574,9 @@ export declare class Client {
572
574
  /** List activity */
573
575
  listActivity(session: Session): Promise<ApiListUserActivity>;
574
576
  createActiviy(session: Session, request: ApiCreateActivityRequest): Promise<ApiUserActivity>;
575
- createQRLogin(basePath: string, requet: ApiLoginRequest): Promise<ApiLoginIDResponse>;
576
- checkLoginRequest(basePath: string, requet: ApiConfirmLoginRequest): Promise<Session | null>;
577
- confirmLogin(basePath: string, session: Session, body: ApiConfirmLoginRequest): Promise<any>;
577
+ createQRLogin(requet: ApiLoginRequest): Promise<ApiLoginIDResponse>;
578
+ checkLoginRequest(requet: ApiConfirmLoginRequest): Promise<Session | null>;
579
+ confirmLogin(session: Session, body: ApiConfirmLoginRequest): Promise<any>;
578
580
  getChanEncryptionMethod(session: Session, channelId: string): Promise<ApiChanEncryptionMethod>;
579
581
  setChanEncryptionMethod(session: Session, channelId: string, method: string): Promise<any>;
580
582
  getPubKeys(session: Session, userIds: Array<string>): Promise<ApiGetPubKeysResponse>;
@@ -728,10 +728,13 @@ function safeJSONParse(jsonStr) {
728
728
 
729
729
  // api.gen.ts
730
730
  var MezonApi = class {
731
- constructor(serverKey, basePath, timeoutMs) {
731
+ constructor(serverKey, timeoutMs, basePath) {
732
732
  this.serverKey = serverKey;
733
- this.basePath = basePath;
734
733
  this.timeoutMs = timeoutMs;
734
+ this.basePath = basePath;
735
+ }
736
+ setBasePath(basePath) {
737
+ this.basePath = basePath;
735
738
  }
736
739
  /** A healthcheck which load balancers can use to check the service. */
737
740
  healthcheck(bearerToken, options = {}) {
@@ -840,7 +843,7 @@ var MezonApi = class {
840
843
  ]);
841
844
  }
842
845
  /** */
843
- checkLoginRequest(basePath, basicAuthUsername, basicAuthPassword, body, options = {}) {
846
+ checkLoginRequest(basicAuthUsername, basicAuthPassword, body, options = {}) {
844
847
  if (body === null || body === void 0) {
845
848
  throw new Error(
846
849
  "'body' is a required parameter but is null or undefined."
@@ -850,7 +853,7 @@ var MezonApi = class {
850
853
  const queryParams = /* @__PURE__ */ new Map();
851
854
  let bodyJson = "";
852
855
  bodyJson = JSON.stringify(body || {});
853
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
856
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
854
857
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
855
858
  if (basicAuthUsername) {
856
859
  fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
@@ -871,7 +874,7 @@ var MezonApi = class {
871
874
  ]);
872
875
  }
873
876
  /** */
874
- confirmLogin(basePath, bearerToken, body, options = {}) {
877
+ confirmLogin(bearerToken, body, options = {}) {
875
878
  if (body === null || body === void 0) {
876
879
  throw new Error(
877
880
  "'body' is a required parameter but is null or undefined."
@@ -881,7 +884,7 @@ var MezonApi = class {
881
884
  const queryParams = /* @__PURE__ */ new Map();
882
885
  let bodyJson = "";
883
886
  bodyJson = JSON.stringify(body || {});
884
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
887
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
885
888
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
886
889
  if (bearerToken) {
887
890
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
@@ -902,7 +905,7 @@ var MezonApi = class {
902
905
  ]);
903
906
  }
904
907
  /** */
905
- createQRLogin(basePath, basicAuthUsername, basicAuthPassword, body, options = {}) {
908
+ createQRLogin(basicAuthUsername, basicAuthPassword, body, options = {}) {
906
909
  if (body === null || body === void 0) {
907
910
  throw new Error(
908
911
  "'body' is a required parameter but is null or undefined."
@@ -912,7 +915,7 @@ var MezonApi = class {
912
915
  const queryParams = /* @__PURE__ */ new Map();
913
916
  let bodyJson = "";
914
917
  bodyJson = JSON.stringify(body || {});
915
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
918
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
916
919
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
917
920
  if (basicAuthUsername) {
918
921
  fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
@@ -933,7 +936,7 @@ var MezonApi = class {
933
936
  ]);
934
937
  }
935
938
  /** Authenticate a user with an email+password against the server. */
936
- authenticateEmail(basePath, basicAuthUsername, basicAuthPassword, body, options = {}) {
939
+ authenticateEmail(basicAuthUsername, basicAuthPassword, body, options = {}) {
937
940
  if (body === null || body === void 0) {
938
941
  throw new Error("'body' is a required parameter but is null or undefined.");
939
942
  }
@@ -941,7 +944,7 @@ var MezonApi = class {
941
944
  const queryParams = /* @__PURE__ */ new Map();
942
945
  let bodyJson = "";
943
946
  bodyJson = JSON.stringify(body || {});
944
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
947
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
945
948
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
946
949
  if (basicAuthUsername) {
947
950
  fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
@@ -962,7 +965,7 @@ var MezonApi = class {
962
965
  ]);
963
966
  }
964
967
  /** Authenticate a user with Mezon against the server. */
965
- authenticateMezon(basePath, basicAuthUsername, basicAuthPassword, account, create, username, isRemember, options = {}) {
968
+ authenticateMezon(basicAuthUsername, basicAuthPassword, account, create, username, isRemember, options = {}) {
966
969
  if (account === null || account === void 0) {
967
970
  throw new Error("'account' is a required parameter but is null or undefined.");
968
971
  }
@@ -973,7 +976,7 @@ var MezonApi = class {
973
976
  queryParams.set("is_remember", isRemember);
974
977
  let bodyJson = "";
975
978
  bodyJson = JSON.stringify(account || {});
976
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
979
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
977
980
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
978
981
  if (basicAuthUsername) {
979
982
  fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
@@ -6661,8 +6664,9 @@ var MezonApi = class {
6661
6664
 
6662
6665
  // session.ts
6663
6666
  var Session = class _Session {
6664
- constructor(token, refresh_token, created, is_remember) {
6667
+ constructor(token, refresh_token, created, api_url, is_remember) {
6665
6668
  this.created = created;
6669
+ this.api_url = api_url;
6666
6670
  this.token = token;
6667
6671
  this.refresh_token = refresh_token;
6668
6672
  this.created_at = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
@@ -6699,8 +6703,8 @@ var Session = class _Session {
6699
6703
  this.user_id = tokenDecoded["uid"];
6700
6704
  this.vars = tokenDecoded["vrs"];
6701
6705
  }
6702
- static restore(token, refreshToken, isRemember) {
6703
- return new _Session(token, refreshToken, false, isRemember);
6706
+ static restore(token, refreshToken, api_url, isRemember) {
6707
+ return new _Session(token, refreshToken, false, api_url, isRemember);
6704
6708
  }
6705
6709
  };
6706
6710
 
@@ -7858,16 +7862,15 @@ var Client = class {
7858
7862
  this.refreshTokenPromise = null;
7859
7863
  const scheme = useSSL ? "https://" : "http://";
7860
7864
  const basePath = `${scheme}${host}:${port}`;
7861
- this.apiClient = new MezonApi(serverkey, basePath, timeout);
7865
+ this.apiClient = new MezonApi(serverkey, timeout, basePath);
7862
7866
  }
7863
7867
  /** Authenticate a user with a custom id against the server. */
7864
- authenticateMezon(basePath, token, create, username, isRemember, vars = {}, options = {}) {
7868
+ authenticateMezon(token, create, username, isRemember, vars = {}, options = {}) {
7865
7869
  const request = {
7866
7870
  token,
7867
7871
  vars
7868
7872
  };
7869
7873
  return this.apiClient.authenticateMezon(
7870
- basePath,
7871
7874
  this.serverkey,
7872
7875
  "",
7873
7876
  request,
@@ -7880,12 +7883,13 @@ var Client = class {
7880
7883
  apiSession.token || "",
7881
7884
  apiSession.refresh_token || "",
7882
7885
  apiSession.created || false,
7886
+ apiSession.api_url || "",
7883
7887
  false
7884
7888
  );
7885
7889
  });
7886
7890
  }
7887
7891
  /** Authenticate a user with an email+password against the server. */
7888
- authenticateEmail(basePath, email, password, username, vars) {
7892
+ authenticateEmail(email, password, username, vars) {
7889
7893
  const request = {
7890
7894
  username,
7891
7895
  account: {
@@ -7894,15 +7898,20 @@ var Client = class {
7894
7898
  vars
7895
7899
  }
7896
7900
  };
7897
- return this.apiClient.authenticateEmail(basePath, this.serverkey, "", request, username).then((apiSession) => {
7901
+ return this.apiClient.authenticateEmail(this.serverkey, "", request, username).then((apiSession) => {
7898
7902
  return new Session(
7899
7903
  apiSession.token || "",
7900
7904
  apiSession.refresh_token || "",
7901
7905
  apiSession.created || false,
7906
+ apiSession.api_url || "",
7902
7907
  false
7903
7908
  );
7904
7909
  });
7905
7910
  }
7911
+ /** set base path */
7912
+ setBasePath(basePath) {
7913
+ return this.apiClient.setBasePath(basePath);
7914
+ }
7906
7915
  /** Add users to a channel, or accept their join requests. */
7907
7916
  addChannelUsers(session, channelId, ids) {
7908
7917
  return __async(this, null, function* () {
@@ -9834,10 +9843,9 @@ var Client = class {
9834
9843
  });
9835
9844
  });
9836
9845
  }
9837
- createQRLogin(basePath, requet) {
9846
+ createQRLogin(requet) {
9838
9847
  return __async(this, null, function* () {
9839
9848
  const apiSession = yield this.apiClient.createQRLogin(
9840
- basePath,
9841
9849
  this.serverkey,
9842
9850
  "",
9843
9851
  requet
@@ -9849,10 +9857,9 @@ var Client = class {
9849
9857
  return response;
9850
9858
  });
9851
9859
  }
9852
- checkLoginRequest(basePath, requet) {
9860
+ checkLoginRequest(requet) {
9853
9861
  return __async(this, null, function* () {
9854
9862
  const apiSession = yield this.apiClient.checkLoginRequest(
9855
- basePath,
9856
9863
  this.serverkey,
9857
9864
  "",
9858
9865
  requet
@@ -9864,16 +9871,17 @@ var Client = class {
9864
9871
  apiSession.token || "",
9865
9872
  apiSession.refresh_token || "",
9866
9873
  apiSession.created || false,
9874
+ apiSession.api_url || "",
9867
9875
  apiSession.is_remember || false
9868
9876
  );
9869
9877
  });
9870
9878
  }
9871
- confirmLogin(basePath, session, body) {
9879
+ confirmLogin(session, body) {
9872
9880
  return __async(this, null, function* () {
9873
9881
  if (this.autoRefreshSession && session.refresh_token && session.isexpired(Date.now() / 1e3)) {
9874
9882
  yield this.sessionRefresh(session);
9875
9883
  }
9876
- return this.apiClient.confirmLogin(basePath, session.token, body).then((response) => {
9884
+ return this.apiClient.confirmLogin(session.token, body).then((response) => {
9877
9885
  return response;
9878
9886
  });
9879
9887
  });
@@ -694,10 +694,13 @@ function safeJSONParse(jsonStr) {
694
694
 
695
695
  // api.gen.ts
696
696
  var MezonApi = class {
697
- constructor(serverKey, basePath, timeoutMs) {
697
+ constructor(serverKey, timeoutMs, basePath) {
698
698
  this.serverKey = serverKey;
699
- this.basePath = basePath;
700
699
  this.timeoutMs = timeoutMs;
700
+ this.basePath = basePath;
701
+ }
702
+ setBasePath(basePath) {
703
+ this.basePath = basePath;
701
704
  }
702
705
  /** A healthcheck which load balancers can use to check the service. */
703
706
  healthcheck(bearerToken, options = {}) {
@@ -806,7 +809,7 @@ var MezonApi = class {
806
809
  ]);
807
810
  }
808
811
  /** */
809
- checkLoginRequest(basePath, basicAuthUsername, basicAuthPassword, body, options = {}) {
812
+ checkLoginRequest(basicAuthUsername, basicAuthPassword, body, options = {}) {
810
813
  if (body === null || body === void 0) {
811
814
  throw new Error(
812
815
  "'body' is a required parameter but is null or undefined."
@@ -816,7 +819,7 @@ var MezonApi = class {
816
819
  const queryParams = /* @__PURE__ */ new Map();
817
820
  let bodyJson = "";
818
821
  bodyJson = JSON.stringify(body || {});
819
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
822
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
820
823
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
821
824
  if (basicAuthUsername) {
822
825
  fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
@@ -837,7 +840,7 @@ var MezonApi = class {
837
840
  ]);
838
841
  }
839
842
  /** */
840
- confirmLogin(basePath, bearerToken, body, options = {}) {
843
+ confirmLogin(bearerToken, body, options = {}) {
841
844
  if (body === null || body === void 0) {
842
845
  throw new Error(
843
846
  "'body' is a required parameter but is null or undefined."
@@ -847,7 +850,7 @@ var MezonApi = class {
847
850
  const queryParams = /* @__PURE__ */ new Map();
848
851
  let bodyJson = "";
849
852
  bodyJson = JSON.stringify(body || {});
850
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
853
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
851
854
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
852
855
  if (bearerToken) {
853
856
  fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
@@ -868,7 +871,7 @@ var MezonApi = class {
868
871
  ]);
869
872
  }
870
873
  /** */
871
- createQRLogin(basePath, basicAuthUsername, basicAuthPassword, body, options = {}) {
874
+ createQRLogin(basicAuthUsername, basicAuthPassword, body, options = {}) {
872
875
  if (body === null || body === void 0) {
873
876
  throw new Error(
874
877
  "'body' is a required parameter but is null or undefined."
@@ -878,7 +881,7 @@ var MezonApi = class {
878
881
  const queryParams = /* @__PURE__ */ new Map();
879
882
  let bodyJson = "";
880
883
  bodyJson = JSON.stringify(body || {});
881
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
884
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
882
885
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
883
886
  if (basicAuthUsername) {
884
887
  fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
@@ -899,7 +902,7 @@ var MezonApi = class {
899
902
  ]);
900
903
  }
901
904
  /** Authenticate a user with an email+password against the server. */
902
- authenticateEmail(basePath, basicAuthUsername, basicAuthPassword, body, options = {}) {
905
+ authenticateEmail(basicAuthUsername, basicAuthPassword, body, options = {}) {
903
906
  if (body === null || body === void 0) {
904
907
  throw new Error("'body' is a required parameter but is null or undefined.");
905
908
  }
@@ -907,7 +910,7 @@ var MezonApi = class {
907
910
  const queryParams = /* @__PURE__ */ new Map();
908
911
  let bodyJson = "";
909
912
  bodyJson = JSON.stringify(body || {});
910
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
913
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
911
914
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
912
915
  if (basicAuthUsername) {
913
916
  fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
@@ -928,7 +931,7 @@ var MezonApi = class {
928
931
  ]);
929
932
  }
930
933
  /** Authenticate a user with Mezon against the server. */
931
- authenticateMezon(basePath, basicAuthUsername, basicAuthPassword, account, create, username, isRemember, options = {}) {
934
+ authenticateMezon(basicAuthUsername, basicAuthPassword, account, create, username, isRemember, options = {}) {
932
935
  if (account === null || account === void 0) {
933
936
  throw new Error("'account' is a required parameter but is null or undefined.");
934
937
  }
@@ -939,7 +942,7 @@ var MezonApi = class {
939
942
  queryParams.set("is_remember", isRemember);
940
943
  let bodyJson = "";
941
944
  bodyJson = JSON.stringify(account || {});
942
- const fullUrl = this.buildFullUrl(basePath, urlPath, queryParams);
945
+ const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
943
946
  const fetchOptions = buildFetchOptions("POST", options, bodyJson);
944
947
  if (basicAuthUsername) {
945
948
  fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword);
@@ -6627,8 +6630,9 @@ var MezonApi = class {
6627
6630
 
6628
6631
  // session.ts
6629
6632
  var Session = class _Session {
6630
- constructor(token, refresh_token, created, is_remember) {
6633
+ constructor(token, refresh_token, created, api_url, is_remember) {
6631
6634
  this.created = created;
6635
+ this.api_url = api_url;
6632
6636
  this.token = token;
6633
6637
  this.refresh_token = refresh_token;
6634
6638
  this.created_at = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
@@ -6665,8 +6669,8 @@ var Session = class _Session {
6665
6669
  this.user_id = tokenDecoded["uid"];
6666
6670
  this.vars = tokenDecoded["vrs"];
6667
6671
  }
6668
- static restore(token, refreshToken, isRemember) {
6669
- return new _Session(token, refreshToken, false, isRemember);
6672
+ static restore(token, refreshToken, api_url, isRemember) {
6673
+ return new _Session(token, refreshToken, false, api_url, isRemember);
6670
6674
  }
6671
6675
  };
6672
6676
 
@@ -7824,16 +7828,15 @@ var Client = class {
7824
7828
  this.refreshTokenPromise = null;
7825
7829
  const scheme = useSSL ? "https://" : "http://";
7826
7830
  const basePath = `${scheme}${host}:${port}`;
7827
- this.apiClient = new MezonApi(serverkey, basePath, timeout);
7831
+ this.apiClient = new MezonApi(serverkey, timeout, basePath);
7828
7832
  }
7829
7833
  /** Authenticate a user with a custom id against the server. */
7830
- authenticateMezon(basePath, token, create, username, isRemember, vars = {}, options = {}) {
7834
+ authenticateMezon(token, create, username, isRemember, vars = {}, options = {}) {
7831
7835
  const request = {
7832
7836
  token,
7833
7837
  vars
7834
7838
  };
7835
7839
  return this.apiClient.authenticateMezon(
7836
- basePath,
7837
7840
  this.serverkey,
7838
7841
  "",
7839
7842
  request,
@@ -7846,12 +7849,13 @@ var Client = class {
7846
7849
  apiSession.token || "",
7847
7850
  apiSession.refresh_token || "",
7848
7851
  apiSession.created || false,
7852
+ apiSession.api_url || "",
7849
7853
  false
7850
7854
  );
7851
7855
  });
7852
7856
  }
7853
7857
  /** Authenticate a user with an email+password against the server. */
7854
- authenticateEmail(basePath, email, password, username, vars) {
7858
+ authenticateEmail(email, password, username, vars) {
7855
7859
  const request = {
7856
7860
  username,
7857
7861
  account: {
@@ -7860,15 +7864,20 @@ var Client = class {
7860
7864
  vars
7861
7865
  }
7862
7866
  };
7863
- return this.apiClient.authenticateEmail(basePath, this.serverkey, "", request, username).then((apiSession) => {
7867
+ return this.apiClient.authenticateEmail(this.serverkey, "", request, username).then((apiSession) => {
7864
7868
  return new Session(
7865
7869
  apiSession.token || "",
7866
7870
  apiSession.refresh_token || "",
7867
7871
  apiSession.created || false,
7872
+ apiSession.api_url || "",
7868
7873
  false
7869
7874
  );
7870
7875
  });
7871
7876
  }
7877
+ /** set base path */
7878
+ setBasePath(basePath) {
7879
+ return this.apiClient.setBasePath(basePath);
7880
+ }
7872
7881
  /** Add users to a channel, or accept their join requests. */
7873
7882
  addChannelUsers(session, channelId, ids) {
7874
7883
  return __async(this, null, function* () {
@@ -9800,10 +9809,9 @@ var Client = class {
9800
9809
  });
9801
9810
  });
9802
9811
  }
9803
- createQRLogin(basePath, requet) {
9812
+ createQRLogin(requet) {
9804
9813
  return __async(this, null, function* () {
9805
9814
  const apiSession = yield this.apiClient.createQRLogin(
9806
- basePath,
9807
9815
  this.serverkey,
9808
9816
  "",
9809
9817
  requet
@@ -9815,10 +9823,9 @@ var Client = class {
9815
9823
  return response;
9816
9824
  });
9817
9825
  }
9818
- checkLoginRequest(basePath, requet) {
9826
+ checkLoginRequest(requet) {
9819
9827
  return __async(this, null, function* () {
9820
9828
  const apiSession = yield this.apiClient.checkLoginRequest(
9821
- basePath,
9822
9829
  this.serverkey,
9823
9830
  "",
9824
9831
  requet
@@ -9830,16 +9837,17 @@ var Client = class {
9830
9837
  apiSession.token || "",
9831
9838
  apiSession.refresh_token || "",
9832
9839
  apiSession.created || false,
9840
+ apiSession.api_url || "",
9833
9841
  apiSession.is_remember || false
9834
9842
  );
9835
9843
  });
9836
9844
  }
9837
- confirmLogin(basePath, session, body) {
9845
+ confirmLogin(session, body) {
9838
9846
  return __async(this, null, function* () {
9839
9847
  if (this.autoRefreshSession && session.refresh_token && session.isexpired(Date.now() / 1e3)) {
9840
9848
  yield this.sessionRefresh(session);
9841
9849
  }
9842
- return this.apiClient.confirmLogin(basePath, session.token, body).then((response) => {
9850
+ return this.apiClient.confirmLogin(session.token, body).then((response) => {
9843
9851
  return response;
9844
9852
  });
9845
9853
  });
package/dist/session.d.ts CHANGED
@@ -42,6 +42,7 @@ export interface ISession {
42
42
  }
43
43
  export declare class Session implements ISession {
44
44
  readonly created: boolean;
45
+ readonly api_url: string;
45
46
  token: string;
46
47
  readonly created_at: number;
47
48
  expires_at?: number;
@@ -51,10 +52,9 @@ export declare class Session implements ISession {
51
52
  user_id?: string;
52
53
  vars?: object;
53
54
  is_remember?: boolean;
54
- api_url?: string;
55
- constructor(token: string, refresh_token: string, created: boolean, is_remember: boolean);
55
+ constructor(token: string, refresh_token: string, created: boolean, api_url: string, is_remember: boolean);
56
56
  isexpired(currenttime: number): boolean;
57
57
  isrefreshexpired(currenttime: number): boolean;
58
58
  update(token: string, refreshToken: string, isRemember: boolean): void;
59
- static restore(token: string, refreshToken: string, isRemember: boolean): Session;
59
+ static restore(token: string, refreshToken: string, api_url: string, isRemember: boolean): Session;
60
60
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mezon-js",
3
3
 
4
- "version": "2.12.2",
4
+ "version": "2.12.4",
5
5
 
6
6
  "scripts": {
7
7
  "build": "npx tsc && npx rollup -c --bundleConfigAsCjs && node build.mjs"
package/session.ts CHANGED
@@ -57,12 +57,12 @@ export class Session implements ISession {
57
57
  user_id?: string;
58
58
  vars?: object;
59
59
  is_remember?: boolean;
60
- api_url?: string;
61
60
 
62
61
  constructor(
63
62
  token: string,
64
63
  refresh_token: string,
65
64
  readonly created: boolean,
65
+ readonly api_url: string,
66
66
  is_remember: boolean) {
67
67
  this.token = token;
68
68
  this.refresh_token = refresh_token;
@@ -113,7 +113,7 @@ export class Session implements ISession {
113
113
  this.vars = tokenDecoded['vrs'];
114
114
  }
115
115
 
116
- static restore(token: string, refreshToken: string, isRemember: boolean): Session {
117
- return new Session(token, refreshToken, false, isRemember);
116
+ static restore(token: string, refreshToken: string, api_url: string, isRemember: boolean): Session {
117
+ return new Session(token, refreshToken, false, api_url, isRemember);
118
118
  }
119
119
  }