@opexa/portal-sdk 0.59.80 → 0.59.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4727,7 +4727,7 @@ var AuthService = class {
4727
4727
  return true;
4728
4728
  }
4729
4729
  }
4730
- async sendVerificationCode(input) {
4730
+ async sendVerificationCode(input, version = 1) {
4731
4731
  if (input.channel === "EMAIL")
4732
4732
  throw new Error("Email channel is not yet supported");
4733
4733
  function getErrorCode(message) {
@@ -4743,7 +4743,7 @@ var AuthService = class {
4743
4743
  }
4744
4744
  }
4745
4745
  try {
4746
- const res = await fetch(`${this.url}/otps`, {
4746
+ const res = await fetch(`${this.url}${version !== 1 ? `/v${version}/otps` : "/otps"}`, {
4747
4747
  method: "POST",
4748
4748
  headers: this.headers,
4749
4749
  body: JSON.stringify(input)
@@ -7508,6 +7508,14 @@ var SessionManagerCookie = class {
7508
7508
  this.logger.warn("'client cookies' is not available on the server.");
7509
7509
  return true;
7510
7510
  }
7511
+ const val = cookies__default.default.get(this.storageKey);
7512
+ if (val) {
7513
+ try {
7514
+ const stored = JSON.parse(val);
7515
+ if (stored.version === 4) return await this.verifyV4();
7516
+ } catch {
7517
+ }
7518
+ }
7511
7519
  const s = await this.get();
7512
7520
  if (s.error?.name === "InvalidTokenError") return false;
7513
7521
  if (s.error?.name === "SessionExpiredError") return false;
@@ -7519,6 +7527,18 @@ var SessionManagerCookie = class {
7519
7527
  }
7520
7528
  return v;
7521
7529
  }
7530
+ async verifyV4() {
7531
+ if (!this.v4AccessToken || !this.v4AccessTokenExpiresAt || isAfter(/* @__PURE__ */ new Date(), new Date(this.v4AccessTokenExpiresAt))) {
7532
+ return true;
7533
+ }
7534
+ const v = await this.authService.verifySession(this.v4AccessToken);
7535
+ if (!v) {
7536
+ cookies__default.default.remove(this.storageKey);
7537
+ this.v4AccessToken = null;
7538
+ this.v4AccessTokenExpiresAt = null;
7539
+ }
7540
+ return v;
7541
+ }
7522
7542
  get onMaya() {
7523
7543
  if (this.isServer) {
7524
7544
  this.logger.warn("'client cookies' is not available on the server.");
@@ -7955,6 +7975,14 @@ var SessionManager = class {
7955
7975
  this.logger.warn("'localStorage' is not available on the server.");
7956
7976
  return true;
7957
7977
  }
7978
+ const val = localStorage.getItem(this.storageKey);
7979
+ if (val) {
7980
+ try {
7981
+ const stored = JSON.parse(val);
7982
+ if (stored.version === 4) return await this.verifyV4();
7983
+ } catch {
7984
+ }
7985
+ }
7958
7986
  const s = await this.get();
7959
7987
  if (s.error?.name === "InvalidTokenError") return false;
7960
7988
  if (s.error?.name === "SessionExpiredError") return false;
@@ -7966,6 +7994,18 @@ var SessionManager = class {
7966
7994
  }
7967
7995
  return v;
7968
7996
  }
7997
+ async verifyV4() {
7998
+ if (!this.v4AccessToken || !this.v4AccessTokenExpiresAt || isAfter(/* @__PURE__ */ new Date(), new Date(this.v4AccessTokenExpiresAt))) {
7999
+ return true;
8000
+ }
8001
+ const v = await this.authService.verifySession(this.v4AccessToken);
8002
+ if (!v) {
8003
+ localStorage.removeItem(this.storageKey);
8004
+ this.v4AccessToken = null;
8005
+ this.v4AccessTokenExpiresAt = null;
8006
+ }
8007
+ return v;
8008
+ }
7969
8009
  get onMaya() {
7970
8010
  if (this.isServer) {
7971
8011
  this.logger.warn("'localStorage' is not available on the server.");
@@ -10764,15 +10804,18 @@ var Sdk = class {
10764
10804
  }
10765
10805
  });
10766
10806
  }
10767
- async sendVerificationCode__next(input) {
10807
+ async sendVerificationCode__next(input, version = 1) {
10768
10808
  if (input.type === "SMS") {
10769
- return this.authService.sendVerificationCode({
10770
- channel: "SMS",
10771
- recipient: addAreaCode(input.mobileNumber, await this.locale),
10772
- ...input.strict && {
10773
- verificationType: "MEMBER"
10774
- }
10775
- });
10809
+ return this.authService.sendVerificationCode(
10810
+ {
10811
+ channel: "SMS",
10812
+ recipient: addAreaCode(input.mobileNumber, await this.locale),
10813
+ ...input.strict && {
10814
+ verificationType: "MEMBER"
10815
+ }
10816
+ },
10817
+ version
10818
+ );
10776
10819
  }
10777
10820
  throw new Error("'Email' verification code is not yet supported");
10778
10821
  }