@opexa/portal-sdk 0.59.96 → 0.59.98

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
@@ -3755,6 +3755,13 @@ var SUBMIT_MEMBER_VERIFICATION_REQUEST_IMAGE_DETAILS_MUTATION__NEXT = gql`
3755
3755
  _submitMemberVerificationRequestImageDetails(input: $input)
3756
3756
  }
3757
3757
  `;
3758
+ var SUBMIT_MEMBER_VERIFICATION_REQUEST_PERSONAL_DETAILS_MUTATION__NEXT = gql`
3759
+ mutation SubmitMemberVerificationRequestPersonalDetails(
3760
+ $input: SubmitMemberVerificationRequestPersonalDetailsInput!
3761
+ ) {
3762
+ _submitMemberVerificationRequestPersonalDetails(input: $input)
3763
+ }
3764
+ `;
3758
3765
  var START_MEMBER_VERIFICATION_REQUEST_FACE_LIVENESS_SESSION = gql`
3759
3766
  mutation StartMemberVerificationRequestFaceLivenessSession {
3760
3767
  startMemberVerificationRequestFaceLivenessSession
@@ -4667,6 +4674,17 @@ var AccountService = class {
4667
4674
  data: res.data.submitMemberVerificationRequestPersonalDetails
4668
4675
  };
4669
4676
  }
4677
+ async submitMemberVerificationRequestPersonalDetails__next(variables) {
4678
+ const res = await this.client.request(
4679
+ SUBMIT_MEMBER_VERIFICATION_REQUEST_PERSONAL_DETAILS_MUTATION__NEXT,
4680
+ variables
4681
+ );
4682
+ if (!res.ok) return res;
4683
+ return {
4684
+ ok: true,
4685
+ data: res.data._submitMemberVerificationRequestPersonalDetails
4686
+ };
4687
+ }
4670
4688
  async memberVerificationRequestAutomaticApprovalEnabled() {
4671
4689
  const res = await this.client.request(
4672
4690
  MEMBER_VERIFICATION_REQUEST_AUTOMATIC_APPROVAL_ENABLED_QUERY
@@ -7528,6 +7546,7 @@ var SessionManager = class {
7528
7546
  v4AccessToken = null;
7529
7547
  v4AccessTokenExpiresAt = null;
7530
7548
  v4RefreshPromise = null;
7549
+ invalidReason = null;
7531
7550
  refreshTokenStore;
7532
7551
  constructor(config) {
7533
7552
  this.authService = config.authService;
@@ -7559,6 +7578,7 @@ var SessionManager = class {
7559
7578
  }
7560
7579
  this.v4AccessToken = data.accessToken;
7561
7580
  this.v4AccessTokenExpiresAt = addMinutes(now, 4).getTime();
7581
+ this.invalidReason = null;
7562
7582
  if (data.refreshToken) {
7563
7583
  await this.refreshTokenStore.set(data.refreshToken);
7564
7584
  }
@@ -7568,6 +7588,7 @@ var SessionManager = class {
7568
7588
  );
7569
7589
  return true;
7570
7590
  }
7591
+ this.invalidReason = null;
7571
7592
  localStorage.setItem(
7572
7593
  this.storageKey,
7573
7594
  JSON.stringify({
@@ -7793,6 +7814,20 @@ var SessionManager = class {
7793
7814
  };
7794
7815
  }
7795
7816
  }
7817
+ async getV4(session) {
7818
+ const now = /* @__PURE__ */ new Date();
7819
+ if (this.v4AccessToken && this.v4AccessTokenExpiresAt && !isAfter(now, new Date(this.v4AccessTokenExpiresAt))) {
7820
+ return {
7821
+ ok: true,
7822
+ data: {
7823
+ session,
7824
+ accessToken: this.v4AccessToken,
7825
+ accessTokenExpiresAt: this.v4AccessTokenExpiresAt
7826
+ }
7827
+ };
7828
+ }
7829
+ return await this.refreshV4(session);
7830
+ }
7796
7831
  async refresh() {
7797
7832
  if (this.isServer) {
7798
7833
  this.logger.warn("'localStorage' is not available on the server.");
@@ -7862,20 +7897,6 @@ var SessionManager = class {
7862
7897
  };
7863
7898
  }
7864
7899
  }
7865
- async getV4(session) {
7866
- const now = /* @__PURE__ */ new Date();
7867
- if (this.v4AccessToken && this.v4AccessTokenExpiresAt && !isAfter(now, new Date(this.v4AccessTokenExpiresAt))) {
7868
- return {
7869
- ok: true,
7870
- data: {
7871
- session,
7872
- accessToken: this.v4AccessToken,
7873
- accessTokenExpiresAt: this.v4AccessTokenExpiresAt
7874
- }
7875
- };
7876
- }
7877
- return await this.refreshV4(session);
7878
- }
7879
7900
  async refreshV4(session) {
7880
7901
  if (this.v4RefreshPromise) return await this.v4RefreshPromise;
7881
7902
  this.v4RefreshPromise = this.requestV4Refresh(session);
@@ -7894,6 +7915,8 @@ var SessionManager = class {
7894
7915
  this.logger.warn("No stored refresh token. Session expired.");
7895
7916
  this.v4AccessToken = null;
7896
7917
  this.v4AccessTokenExpiresAt = null;
7918
+ this.invalidReason = "REFRESH_TOKEN_EXPIRED";
7919
+ localStorage.removeItem(this.storageKey);
7897
7920
  return {
7898
7921
  ok: false,
7899
7922
  error: {
@@ -7905,20 +7928,25 @@ var SessionManager = class {
7905
7928
  }
7906
7929
  this.refreshing = true;
7907
7930
  const res = await this.authService.refreshSession(refreshToken, 4);
7908
- this.refreshing = false;
7909
7931
  if (!res.ok) {
7910
7932
  this.logger.error(`Failed to refresh session: ${res.error.message}`);
7911
- if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError" || res.error.name === "SessionExpiredError") {
7933
+ const terminal = res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError" || res.error.name === "SessionExpiredError";
7934
+ if (terminal) {
7912
7935
  this.v4AccessToken = null;
7913
7936
  this.v4AccessTokenExpiresAt = null;
7914
- await this.refreshTokenStore.remove();
7937
+ this.invalidReason = res.error.name === "SessionExpiredError" ? "REFRESH_TOKEN_EXPIRED" : "INVALID_SESSION";
7938
+ localStorage.removeItem(this.storageKey);
7915
7939
  }
7940
+ this.refreshing = false;
7941
+ if (terminal) await this.refreshTokenStore.remove();
7916
7942
  return {
7917
7943
  ok: false,
7918
7944
  error: res.error
7919
7945
  };
7920
7946
  }
7947
+ this.refreshing = false;
7921
7948
  this.logger.success("Session refreshed!");
7949
+ this.invalidReason = null;
7922
7950
  if (res.data.refreshToken) {
7923
7951
  await this.refreshTokenStore.set(res.data.refreshToken);
7924
7952
  }
@@ -7954,6 +7982,7 @@ var SessionManager = class {
7954
7982
  }
7955
7983
  this.v4AccessToken = null;
7956
7984
  this.v4AccessTokenExpiresAt = null;
7985
+ this.invalidReason = null;
7957
7986
  await this.refreshTokenStore.remove();
7958
7987
  localStorage.removeItem(this.storageKey);
7959
7988
  }
@@ -7962,6 +7991,9 @@ var SessionManager = class {
7962
7991
  this.logger.warn("'localStorage' is not available on the server.");
7963
7992
  return { valid: true };
7964
7993
  }
7994
+ if (this.invalidReason) {
7995
+ return { valid: false, reason: this.invalidReason };
7996
+ }
7965
7997
  const val = localStorage.getItem(this.storageKey);
7966
7998
  if (val) {
7967
7999
  try {
@@ -7976,11 +8008,13 @@ var SessionManager = class {
7976
8008
  }
7977
8009
  const s = await this.get();
7978
8010
  if (s.error?.name === "InvalidTokenError" || s.error?.name === "SessionExpiredError" || s.error?.name === "AccountBlacklistedError") {
8011
+ this.invalidReason = "INVALID_SESSION";
7979
8012
  return { valid: false, reason: "INVALID_SESSION" };
7980
8013
  }
7981
8014
  if (!s.data) return { valid: true };
7982
8015
  const v = await this.authService.verifySession(s.data.accessToken);
7983
8016
  if (!v) {
8017
+ this.invalidReason = "INVALID_SESSION";
7984
8018
  localStorage.removeItem(this.storageKey);
7985
8019
  }
7986
8020
  return v ? { valid: true } : { valid: false, reason: "INVALID_SESSION" };
@@ -7988,16 +8022,16 @@ var SessionManager = class {
7988
8022
  async verifyV4(session) {
7989
8023
  if (!this.v4AccessToken || !this.v4AccessTokenExpiresAt || isAfter(/* @__PURE__ */ new Date(), new Date(this.v4AccessTokenExpiresAt))) {
7990
8024
  const res = await this.refreshV4(session);
7991
- return res.ok ? { valid: true } : {
7992
- valid: false,
7993
- reason: res.error.name === "SessionExpiredError" ? "REFRESH_TOKEN_EXPIRED" : "INVALID_SESSION"
7994
- };
8025
+ if (res.ok) return { valid: true };
8026
+ if (!this.invalidReason) return { valid: true };
8027
+ return { valid: false, reason: this.invalidReason };
7995
8028
  }
7996
8029
  const v = await this.authService.verifySession(this.v4AccessToken);
7997
8030
  if (!v) {
7998
8031
  localStorage.removeItem(this.storageKey);
7999
8032
  this.v4AccessToken = null;
8000
8033
  this.v4AccessTokenExpiresAt = null;
8034
+ this.invalidReason = "INVALID_SESSION";
8001
8035
  await this.refreshTokenStore.remove();
8002
8036
  }
8003
8037
  return v ? { valid: true } : { valid: false, reason: "INVALID_SESSION" };
@@ -8035,6 +8069,7 @@ var SessionManagerCookie = class {
8035
8069
  v4AccessToken = null;
8036
8070
  v4AccessTokenExpiresAt = null;
8037
8071
  v4RefreshPromise = null;
8072
+ invalidReason = null;
8038
8073
  refreshTokenStore;
8039
8074
  constructor(config) {
8040
8075
  this.authService = config.authService;
@@ -8050,6 +8085,7 @@ var SessionManagerCookie = class {
8050
8085
  }
8051
8086
  async persist(data, version) {
8052
8087
  const now = /* @__PURE__ */ new Date();
8088
+ this.invalidReason = null;
8053
8089
  if (version === 4) {
8054
8090
  this.v4AccessToken = data.accessToken ?? null;
8055
8091
  this.v4AccessTokenExpiresAt = addMinutes(now, 5).getTime();
@@ -8265,6 +8301,20 @@ var SessionManagerCookie = class {
8265
8301
  };
8266
8302
  }
8267
8303
  }
8304
+ async getV4(session) {
8305
+ const now = /* @__PURE__ */ new Date();
8306
+ if (this.v4AccessToken && this.v4AccessTokenExpiresAt && !isAfter(now, new Date(this.v4AccessTokenExpiresAt))) {
8307
+ return {
8308
+ ok: true,
8309
+ data: {
8310
+ session,
8311
+ accessToken: this.v4AccessToken,
8312
+ accessTokenExpiresAt: this.v4AccessTokenExpiresAt
8313
+ }
8314
+ };
8315
+ }
8316
+ return await this.refreshV4(session);
8317
+ }
8268
8318
  async refresh() {
8269
8319
  if (this.isServer) {
8270
8320
  this.logger.warn("'client cookies' is not available on the server.");
@@ -8336,20 +8386,6 @@ var SessionManagerCookie = class {
8336
8386
  };
8337
8387
  }
8338
8388
  }
8339
- async getV4(session) {
8340
- const now = /* @__PURE__ */ new Date();
8341
- if (this.v4AccessToken && this.v4AccessTokenExpiresAt && !isAfter(now, new Date(this.v4AccessTokenExpiresAt))) {
8342
- return {
8343
- ok: true,
8344
- data: {
8345
- session,
8346
- accessToken: this.v4AccessToken,
8347
- accessTokenExpiresAt: this.v4AccessTokenExpiresAt
8348
- }
8349
- };
8350
- }
8351
- return await this.refreshV4(session);
8352
- }
8353
8389
  async refreshV4(session) {
8354
8390
  if (this.v4RefreshPromise) return await this.v4RefreshPromise;
8355
8391
  this.v4RefreshPromise = this.requestV4Refresh(session);
@@ -8368,6 +8404,8 @@ var SessionManagerCookie = class {
8368
8404
  this.logger.warn("No stored refresh token. Session expired.");
8369
8405
  this.v4AccessToken = null;
8370
8406
  this.v4AccessTokenExpiresAt = null;
8407
+ this.invalidReason = "REFRESH_TOKEN_EXPIRED";
8408
+ cookies__default.default.remove(this.storageKey);
8371
8409
  return {
8372
8410
  ok: false,
8373
8411
  error: {
@@ -8379,20 +8417,25 @@ var SessionManagerCookie = class {
8379
8417
  }
8380
8418
  this.refreshing = true;
8381
8419
  const res = await this.authService.refreshSession(refreshToken, 4);
8382
- this.refreshing = false;
8383
8420
  if (!res.ok) {
8384
8421
  this.logger.error(`Failed to refresh session: ${res.error.message}`);
8385
- if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError" || res.error.name === "SessionExpiredError") {
8422
+ const terminal = res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError" || res.error.name === "SessionExpiredError";
8423
+ if (terminal) {
8386
8424
  this.v4AccessToken = null;
8387
8425
  this.v4AccessTokenExpiresAt = null;
8388
- await this.refreshTokenStore.remove();
8426
+ this.invalidReason = res.error.name === "SessionExpiredError" ? "REFRESH_TOKEN_EXPIRED" : "INVALID_SESSION";
8427
+ cookies__default.default.remove(this.storageKey);
8389
8428
  }
8429
+ this.refreshing = false;
8430
+ if (terminal) await this.refreshTokenStore.remove();
8390
8431
  return {
8391
8432
  ok: false,
8392
8433
  error: res.error
8393
8434
  };
8394
8435
  }
8436
+ this.refreshing = false;
8395
8437
  this.logger.success("Session refreshed!");
8438
+ this.invalidReason = null;
8396
8439
  if (res.data.refreshToken) {
8397
8440
  await this.refreshTokenStore.set(res.data.refreshToken);
8398
8441
  }
@@ -8428,6 +8471,7 @@ var SessionManagerCookie = class {
8428
8471
  }
8429
8472
  this.v4AccessToken = null;
8430
8473
  this.v4AccessTokenExpiresAt = null;
8474
+ this.invalidReason = null;
8431
8475
  await this.refreshTokenStore.remove();
8432
8476
  cookies__default.default.remove(this.storageKey);
8433
8477
  }
@@ -8436,6 +8480,9 @@ var SessionManagerCookie = class {
8436
8480
  this.logger.warn("'client cookies' is not available on the server.");
8437
8481
  return { valid: true };
8438
8482
  }
8483
+ if (this.invalidReason) {
8484
+ return { valid: false, reason: this.invalidReason };
8485
+ }
8439
8486
  const val = cookies__default.default.get(this.storageKey);
8440
8487
  if (val) {
8441
8488
  try {
@@ -8450,11 +8497,13 @@ var SessionManagerCookie = class {
8450
8497
  }
8451
8498
  const s = await this.get();
8452
8499
  if (s.error?.name === "InvalidTokenError" || s.error?.name === "SessionExpiredError" || s.error?.name === "AccountBlacklistedError") {
8500
+ this.invalidReason = "INVALID_SESSION";
8453
8501
  return { valid: false, reason: "INVALID_SESSION" };
8454
8502
  }
8455
8503
  if (!s.data) return { valid: true };
8456
8504
  const v = await this.authService.verifySession(s.data.accessToken);
8457
8505
  if (!v) {
8506
+ this.invalidReason = "INVALID_SESSION";
8458
8507
  cookies__default.default.remove(this.storageKey);
8459
8508
  }
8460
8509
  return v ? { valid: true } : { valid: false, reason: "INVALID_SESSION" };
@@ -8462,16 +8511,16 @@ var SessionManagerCookie = class {
8462
8511
  async verifyV4(session) {
8463
8512
  if (!this.v4AccessToken || !this.v4AccessTokenExpiresAt || isAfter(/* @__PURE__ */ new Date(), new Date(this.v4AccessTokenExpiresAt))) {
8464
8513
  const res = await this.refreshV4(session);
8465
- return res.ok ? { valid: true } : {
8466
- valid: false,
8467
- reason: res.error.name === "SessionExpiredError" ? "REFRESH_TOKEN_EXPIRED" : "INVALID_SESSION"
8468
- };
8514
+ if (res.ok) return { valid: true };
8515
+ if (!this.invalidReason) return { valid: true };
8516
+ return { valid: false, reason: this.invalidReason };
8469
8517
  }
8470
8518
  const v = await this.authService.verifySession(this.v4AccessToken);
8471
8519
  if (!v) {
8472
8520
  cookies__default.default.remove(this.storageKey);
8473
8521
  this.v4AccessToken = null;
8474
8522
  this.v4AccessTokenExpiresAt = null;
8523
+ this.invalidReason = "INVALID_SESSION";
8475
8524
  await this.refreshTokenStore.remove();
8476
8525
  }
8477
8526
  return v ? { valid: true } : { valid: false, reason: "INVALID_SESSION" };
@@ -10777,9 +10826,18 @@ var Sdk = class {
10777
10826
  let counter = 0;
10778
10827
  let timeout = null;
10779
10828
  let isForeground = true;
10829
+ let stopped = false;
10780
10830
  const listener = app.App.addListener("appStateChange", ({ isActive }) => {
10781
10831
  isForeground = isActive;
10782
10832
  });
10833
+ const stop = () => {
10834
+ stopped = true;
10835
+ if (timeout) {
10836
+ clearTimeout(timeout);
10837
+ timeout = null;
10838
+ }
10839
+ listener.then((handle) => handle.remove());
10840
+ };
10783
10841
  const assignTimeout = () => {
10784
10842
  const duration = counter <= 0 ? interval * 0.5 : interval;
10785
10843
  return setTimeout(async () => {
@@ -10788,10 +10846,13 @@ var Sdk = class {
10788
10846
  try {
10789
10847
  res = await this.sessionManager.verify();
10790
10848
  } catch {
10791
- res = { valid: false, reason: "INVALID_SESSION" };
10849
+ res = null;
10792
10850
  }
10793
- if (!res.valid) {
10851
+ if (stopped) return;
10852
+ if (res && !res.valid) {
10853
+ stop();
10794
10854
  await input.onInvalid(res.reason ?? "INVALID_SESSION");
10855
+ return;
10795
10856
  }
10796
10857
  }
10797
10858
  counter += 1;
@@ -10800,10 +10861,7 @@ var Sdk = class {
10800
10861
  };
10801
10862
  timeout = assignTimeout();
10802
10863
  return function unsubscribe() {
10803
- if (timeout) {
10804
- clearTimeout(timeout);
10805
- }
10806
- listener.then((handle) => handle.remove());
10864
+ stop();
10807
10865
  };
10808
10866
  }
10809
10867
  async session() {
@@ -13073,6 +13131,11 @@ var Sdk = class {
13073
13131
  { input }
13074
13132
  );
13075
13133
  }
13134
+ async submitMemberVerificationRequestPersonalDetails__next(input) {
13135
+ return await this.accountService.submitMemberVerificationRequestPersonalDetails__next(
13136
+ { input }
13137
+ );
13138
+ }
13076
13139
  async startMemberVerificationRequestFaceLivenessSession() {
13077
13140
  return await this.accountService.startMemberVerificationRequestFaceLivenessSession();
13078
13141
  }