@opexa/portal-sdk 0.59.84 → 0.59.86

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
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var objectId = require('@opexa/object-id');
4
+ var app = require('@capacitor/app');
4
5
  var core = require('@capacitor/core');
5
6
  var thumbmarkjs = require('@thumbmarkjs/thumbmarkjs');
6
7
  var cookies = require('js-cookie');
@@ -2128,6 +2129,11 @@ var RESET_PASSWORD_MUTATION = gql`
2128
2129
  }
2129
2130
  }
2130
2131
  `;
2132
+ var UPDATE_PASSWORD_MUTATION = gql`
2133
+ mutation UpdatePassword($input: UpdatePasswordInput!) {
2134
+ updatePassword(input: $input)
2135
+ }
2136
+ `;
2131
2137
  var DELETE_MEMBER_ACCOUNT_MUTATION = gql`
2132
2138
  mutation DeleteMemberAccount($input: DeleteMemberAccountInput!) {
2133
2139
  deleteMemberAccount(input: $input)
@@ -4154,6 +4160,22 @@ var AccountService = class {
4154
4160
  ok: true
4155
4161
  };
4156
4162
  }
4163
+ async updatePassword(variables) {
4164
+ const res = await this.client.request(UPDATE_PASSWORD_MUTATION, variables);
4165
+ if (!res.ok) return res;
4166
+ if (!res.data.updatePassword) {
4167
+ return {
4168
+ ok: false,
4169
+ error: {
4170
+ name: "UnknownError",
4171
+ message: "Something went wrong."
4172
+ }
4173
+ };
4174
+ }
4175
+ return {
4176
+ ok: true
4177
+ };
4178
+ }
4157
4179
  async profileCompletion() {
4158
4180
  const res = await this.client.request(
4159
4181
  PROFILE_COMPLETION_QUERY
@@ -7216,8 +7238,8 @@ function pollable(func, config) {
7216
7238
  };
7217
7239
  }
7218
7240
 
7219
- // src/sdk/session-manager-cookie.ts
7220
- var SessionManagerCookie = class {
7241
+ // src/sdk/session-manager.ts
7242
+ var SessionManager = class {
7221
7243
  logger;
7222
7244
  storageKey = "session";
7223
7245
  platformStorageKey = "session/platform";
@@ -7231,10 +7253,15 @@ var SessionManagerCookie = class {
7231
7253
  */
7232
7254
  v4AccessToken = null;
7233
7255
  v4AccessTokenExpiresAt = null;
7256
+ v4RefreshPromise = null;
7234
7257
  constructor(config) {
7235
7258
  this.authService = config.authService;
7236
7259
  this.walletService = config.walletService;
7237
7260
  this.logger = config.logger;
7261
+ if (config.sessionPrefix) {
7262
+ this.storageKey = `${config.sessionPrefix}/${this.storageKey}`;
7263
+ this.platformStorageKey = `${config.sessionPrefix}/${this.platformStorageKey}`;
7264
+ }
7238
7265
  }
7239
7266
  get refreshing() {
7240
7267
  return this._refreshing;
@@ -7245,27 +7272,51 @@ var SessionManagerCookie = class {
7245
7272
  persist(data, version) {
7246
7273
  const now = /* @__PURE__ */ new Date();
7247
7274
  if (version === 4) {
7248
- this.v4AccessToken = data.accessToken ?? null;
7275
+ if (!data.session || !data.accessToken) {
7276
+ this.logger.error(
7277
+ "Malformed session response: expected 'session' and 'accessToken'."
7278
+ );
7279
+ return false;
7280
+ }
7281
+ this.v4AccessToken = data.accessToken;
7249
7282
  this.v4AccessTokenExpiresAt = addMinutes(now, 5).getTime();
7250
- cookies__default.default.set(
7283
+ localStorage.setItem(
7251
7284
  this.storageKey,
7252
- JSON.stringify({ version, session: data.session }),
7253
- { expires: subMinutes(addDays(now, 15), 2).getTime() }
7285
+ JSON.stringify({ version, session: data.session })
7254
7286
  );
7255
- return;
7287
+ return true;
7256
7288
  }
7257
- cookies__default.default.set(
7289
+ localStorage.setItem(
7258
7290
  this.storageKey,
7259
7291
  JSON.stringify({
7260
7292
  version,
7261
7293
  ...data,
7262
7294
  accessTokenExpiresAt: addMinutes(now, 8).getTime(),
7263
7295
  refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
7264
- }),
7265
- { expires: subMinutes(addDays(now, 30), 2).getTime() }
7296
+ })
7266
7297
  );
7298
+ return true;
7299
+ }
7300
+ malformedResponseError() {
7301
+ return {
7302
+ ok: false,
7303
+ error: {
7304
+ name: "UnknownError",
7305
+ message: "Something went wrong."
7306
+ }
7307
+ };
7267
7308
  }
7268
7309
  async create(input, version = 1) {
7310
+ if (this.isServer) {
7311
+ this.logger.warn("'localStorage' is not available on the server.");
7312
+ return {
7313
+ ok: false,
7314
+ error: {
7315
+ name: "UnknownError",
7316
+ message: "Server sign in is not supported."
7317
+ }
7318
+ };
7319
+ }
7269
7320
  if (input.type === "MAYA") {
7270
7321
  localStorage.setItem(this.platformStorageKey, "MAYA");
7271
7322
  const f0 = () => this.walletService.mayaSession({ id: input.sessionId });
@@ -7291,7 +7342,7 @@ var SessionManagerCookie = class {
7291
7342
  maxAttempt: 5
7292
7343
  })();
7293
7344
  if (!r1.ok) return r1;
7294
- this.persist(r1.data, version);
7345
+ if (!this.persist(r1.data, version)) return this.malformedResponseError();
7295
7346
  return {
7296
7347
  ok: true,
7297
7348
  data: null
@@ -7300,7 +7351,7 @@ var SessionManagerCookie = class {
7300
7351
  if (input.type === "MOBILE_NUMBER") {
7301
7352
  const res2 = await this.authService.createSession(input, version);
7302
7353
  if (res2.ok) {
7303
- this.persist(res2.data, version);
7354
+ if (!this.persist(res2.data, version)) return this.malformedResponseError();
7304
7355
  return {
7305
7356
  ok: true,
7306
7357
  data: null
@@ -7312,12 +7363,13 @@ var SessionManagerCookie = class {
7312
7363
  const res2 = await this.authService.createSession(
7313
7364
  {
7314
7365
  type: "SOCIALS",
7315
- token: input.token
7366
+ token: input.token,
7367
+ channel: input.channel
7316
7368
  },
7317
7369
  version
7318
7370
  );
7319
7371
  if (res2.ok) {
7320
- this.persist(res2.data, version);
7372
+ if (!this.persist(res2.data, version)) return this.malformedResponseError();
7321
7373
  return {
7322
7374
  ok: true,
7323
7375
  data: null
@@ -7329,7 +7381,7 @@ var SessionManagerCookie = class {
7329
7381
  localStorage.setItem(this.platformStorageKey, "CABINET");
7330
7382
  const res2 = await this.authService.createSession(input, version);
7331
7383
  if (res2.ok) {
7332
- this.persist(res2.data, version);
7384
+ if (!this.persist(res2.data, version)) return this.malformedResponseError();
7333
7385
  return {
7334
7386
  ok: true,
7335
7387
  data: null
@@ -7347,7 +7399,7 @@ var SessionManagerCookie = class {
7347
7399
  }
7348
7400
  };
7349
7401
  }
7350
- this.persist(res.data, version);
7402
+ if (!this.persist(res.data, version)) return this.malformedResponseError();
7351
7403
  return {
7352
7404
  ok: true,
7353
7405
  data: null
@@ -7357,9 +7409,9 @@ var SessionManagerCookie = class {
7357
7409
  const res = await this.authService.authenticate(input);
7358
7410
  if (res.ok) {
7359
7411
  if (this.isServer) {
7360
- this.logger.warn("'client cookies' is not available on the server.");
7361
- } else {
7362
- this.persist(res.data, 1);
7412
+ this.logger.warn("'localStorage' is not available on the server.");
7413
+ } else if (!this.persist(res.data, 1)) {
7414
+ return this.malformedResponseError();
7363
7415
  }
7364
7416
  return { ok: true };
7365
7417
  } else {
@@ -7368,7 +7420,7 @@ var SessionManagerCookie = class {
7368
7420
  }
7369
7421
  async get() {
7370
7422
  if (this.isServer) {
7371
- this.logger.warn("'client cookies' is not available on the server.");
7423
+ this.logger.warn("'localStorage' is not available on the server.");
7372
7424
  return {
7373
7425
  ok: true,
7374
7426
  data: null
@@ -7378,7 +7430,7 @@ var SessionManagerCookie = class {
7378
7430
  await sleep(1e3);
7379
7431
  return await this.get();
7380
7432
  }
7381
- const val = cookies__default.default.get(this.storageKey);
7433
+ const val = localStorage.getItem(this.storageKey);
7382
7434
  if (!val) {
7383
7435
  return {
7384
7436
  ok: true,
@@ -7396,7 +7448,7 @@ var SessionManagerCookie = class {
7396
7448
  const refreshTokenExpiresAt = new Date(obj.refreshTokenExpiresAt);
7397
7449
  if (isAfter(now, refreshTokenExpiresAt)) {
7398
7450
  this.logger.warn("Session expired. Logging out..");
7399
- cookies__default.default.remove(this.storageKey);
7451
+ localStorage.removeItem(this.storageKey);
7400
7452
  return {
7401
7453
  ok: false,
7402
7454
  error: {
@@ -7416,7 +7468,7 @@ var SessionManagerCookie = class {
7416
7468
  if (!res.ok) {
7417
7469
  this.logger.error(`Failed to refresh session: ${res.error.message}`);
7418
7470
  if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
7419
- cookies__default.default.remove(this.storageKey);
7471
+ localStorage.removeItem(this.storageKey);
7420
7472
  return {
7421
7473
  ok: false,
7422
7474
  error: res.error
@@ -7438,9 +7490,7 @@ var SessionManagerCookie = class {
7438
7490
  accessTokenExpiresAt: addMinutes(now, 8).getTime(),
7439
7491
  refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
7440
7492
  };
7441
- cookies__default.default.set(this.storageKey, JSON.stringify(obj), {
7442
- expires: subMinutes(addDays(now, 30), 2).getTime()
7443
- });
7493
+ localStorage.setItem(this.storageKey, JSON.stringify(obj));
7444
7494
  }
7445
7495
  return {
7446
7496
  ok: true,
@@ -7458,13 +7508,13 @@ var SessionManagerCookie = class {
7458
7508
  }
7459
7509
  async refresh() {
7460
7510
  if (this.isServer) {
7461
- this.logger.warn("'client cookies' is not available on the server.");
7511
+ this.logger.warn("'localStorage' is not available on the server.");
7462
7512
  return {
7463
7513
  ok: true,
7464
7514
  data: null
7465
7515
  };
7466
7516
  }
7467
- const val = cookies__default.default.get(this.storageKey);
7517
+ const val = localStorage.getItem(this.storageKey);
7468
7518
  if (!val) {
7469
7519
  return {
7470
7520
  ok: true,
@@ -7488,7 +7538,7 @@ var SessionManagerCookie = class {
7488
7538
  if (!res.ok) {
7489
7539
  this.logger.error(`Failed to refresh session: ${res.error.message}`);
7490
7540
  if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
7491
- cookies__default.default.remove(this.storageKey);
7541
+ localStorage.removeItem(this.storageKey);
7492
7542
  return {
7493
7543
  ok: false,
7494
7544
  error: res.error
@@ -7510,9 +7560,7 @@ var SessionManagerCookie = class {
7510
7560
  accessTokenExpiresAt: addMinutes(now, 8).getTime(),
7511
7561
  refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
7512
7562
  };
7513
- cookies__default.default.set(this.storageKey, JSON.stringify(obj), {
7514
- expires: subMinutes(addDays(now, 30), 2).getTime()
7515
- });
7563
+ localStorage.setItem(this.storageKey, JSON.stringify(obj));
7516
7564
  return {
7517
7565
  ok: true,
7518
7566
  data: obj
@@ -7542,6 +7590,15 @@ var SessionManagerCookie = class {
7542
7590
  return await this.refreshV4(session);
7543
7591
  }
7544
7592
  async refreshV4(session) {
7593
+ if (this.v4RefreshPromise) return await this.v4RefreshPromise;
7594
+ this.v4RefreshPromise = this.requestV4Refresh(session);
7595
+ try {
7596
+ return await this.v4RefreshPromise;
7597
+ } finally {
7598
+ this.v4RefreshPromise = null;
7599
+ }
7600
+ }
7601
+ async requestV4Refresh(session) {
7545
7602
  this.logger.info("Refreshing session...");
7546
7603
  this.refreshing = true;
7547
7604
  const res = await this.authService.refreshSession(void 0, 4);
@@ -7549,7 +7606,7 @@ var SessionManagerCookie = class {
7549
7606
  if (!res.ok) {
7550
7607
  this.logger.error(`Failed to refresh session: ${res.error.message}`);
7551
7608
  if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
7552
- cookies__default.default.remove(this.storageKey);
7609
+ localStorage.removeItem(this.storageKey);
7553
7610
  this.v4AccessToken = null;
7554
7611
  this.v4AccessTokenExpiresAt = null;
7555
7612
  }
@@ -7573,11 +7630,11 @@ var SessionManagerCookie = class {
7573
7630
  }
7574
7631
  async destroy() {
7575
7632
  if (this.isServer) {
7576
- this.logger.warn("'client cookies' is not available on the server.");
7633
+ this.logger.warn("'localStorage' is not available on the server.");
7577
7634
  return;
7578
7635
  }
7579
7636
  let version = 1;
7580
- const val = cookies__default.default.get(this.storageKey);
7637
+ const val = localStorage.getItem(this.storageKey);
7581
7638
  if (val) {
7582
7639
  try {
7583
7640
  const stored = JSON.parse(val);
@@ -7591,14 +7648,14 @@ var SessionManagerCookie = class {
7591
7648
  }
7592
7649
  this.v4AccessToken = null;
7593
7650
  this.v4AccessTokenExpiresAt = null;
7594
- cookies__default.default.remove(this.storageKey);
7651
+ localStorage.removeItem(this.storageKey);
7595
7652
  }
7596
7653
  async verify() {
7597
7654
  if (this.isServer) {
7598
- this.logger.warn("'client cookies' is not available on the server.");
7655
+ this.logger.warn("'localStorage' is not available on the server.");
7599
7656
  return true;
7600
7657
  }
7601
- const val = cookies__default.default.get(this.storageKey);
7658
+ const val = localStorage.getItem(this.storageKey);
7602
7659
  if (val) {
7603
7660
  try {
7604
7661
  const stored = JSON.parse(val);
@@ -7613,7 +7670,7 @@ var SessionManagerCookie = class {
7613
7670
  if (!s.data) return true;
7614
7671
  const v = await this.authService.verifySession(s.data.accessToken);
7615
7672
  if (!v) {
7616
- cookies__default.default.remove(this.storageKey);
7673
+ localStorage.removeItem(this.storageKey);
7617
7674
  }
7618
7675
  return v;
7619
7676
  }
@@ -7624,7 +7681,7 @@ var SessionManagerCookie = class {
7624
7681
  }
7625
7682
  const v = await this.authService.verifySession(this.v4AccessToken);
7626
7683
  if (!v) {
7627
- cookies__default.default.remove(this.storageKey);
7684
+ localStorage.removeItem(this.storageKey);
7628
7685
  this.v4AccessToken = null;
7629
7686
  this.v4AccessTokenExpiresAt = null;
7630
7687
  }
@@ -7632,7 +7689,7 @@ var SessionManagerCookie = class {
7632
7689
  }
7633
7690
  get onMaya() {
7634
7691
  if (this.isServer) {
7635
- this.logger.warn("'client cookies' is not available on the server.");
7692
+ this.logger.warn("'localStorage' is not available on the server.");
7636
7693
  return false;
7637
7694
  }
7638
7695
  return localStorage.getItem(this.platformStorageKey) === "MAYA";
@@ -7648,9 +7705,7 @@ var SessionManagerCookie = class {
7648
7705
  return typeof window === "undefined";
7649
7706
  }
7650
7707
  };
7651
-
7652
- // src/sdk/session-manager.ts
7653
- var SessionManager = class {
7708
+ var SessionManagerCookie = class {
7654
7709
  logger;
7655
7710
  storageKey = "session";
7656
7711
  platformStorageKey = "session/platform";
@@ -7664,15 +7719,10 @@ var SessionManager = class {
7664
7719
  */
7665
7720
  v4AccessToken = null;
7666
7721
  v4AccessTokenExpiresAt = null;
7667
- v4RefreshPromise = null;
7668
7722
  constructor(config) {
7669
7723
  this.authService = config.authService;
7670
7724
  this.walletService = config.walletService;
7671
7725
  this.logger = config.logger;
7672
- if (config.sessionPrefix) {
7673
- this.storageKey = `${config.sessionPrefix}/${this.storageKey}`;
7674
- this.platformStorageKey = `${config.sessionPrefix}/${this.platformStorageKey}`;
7675
- }
7676
7726
  }
7677
7727
  get refreshing() {
7678
7728
  return this._refreshing;
@@ -7683,51 +7733,27 @@ var SessionManager = class {
7683
7733
  persist(data, version) {
7684
7734
  const now = /* @__PURE__ */ new Date();
7685
7735
  if (version === 4) {
7686
- if (!data.session || !data.accessToken) {
7687
- this.logger.error(
7688
- "Malformed session response: expected 'session' and 'accessToken'."
7689
- );
7690
- return false;
7691
- }
7692
- this.v4AccessToken = data.accessToken;
7736
+ this.v4AccessToken = data.accessToken ?? null;
7693
7737
  this.v4AccessTokenExpiresAt = addMinutes(now, 5).getTime();
7694
- localStorage.setItem(
7738
+ cookies__default.default.set(
7695
7739
  this.storageKey,
7696
- JSON.stringify({ version, session: data.session })
7740
+ JSON.stringify({ version, session: data.session }),
7741
+ { expires: subMinutes(addDays(now, 15), 2).getTime() }
7697
7742
  );
7698
- return true;
7743
+ return;
7699
7744
  }
7700
- localStorage.setItem(
7745
+ cookies__default.default.set(
7701
7746
  this.storageKey,
7702
7747
  JSON.stringify({
7703
7748
  version,
7704
7749
  ...data,
7705
7750
  accessTokenExpiresAt: addMinutes(now, 8).getTime(),
7706
7751
  refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
7707
- })
7752
+ }),
7753
+ { expires: subMinutes(addDays(now, 30), 2).getTime() }
7708
7754
  );
7709
- return true;
7710
- }
7711
- malformedResponseError() {
7712
- return {
7713
- ok: false,
7714
- error: {
7715
- name: "UnknownError",
7716
- message: "Something went wrong."
7717
- }
7718
- };
7719
7755
  }
7720
7756
  async create(input, version = 1) {
7721
- if (this.isServer) {
7722
- this.logger.warn("'localStorage' is not available on the server.");
7723
- return {
7724
- ok: false,
7725
- error: {
7726
- name: "UnknownError",
7727
- message: "Server sign in is not supported."
7728
- }
7729
- };
7730
- }
7731
7757
  if (input.type === "MAYA") {
7732
7758
  localStorage.setItem(this.platformStorageKey, "MAYA");
7733
7759
  const f0 = () => this.walletService.mayaSession({ id: input.sessionId });
@@ -7753,7 +7779,7 @@ var SessionManager = class {
7753
7779
  maxAttempt: 5
7754
7780
  })();
7755
7781
  if (!r1.ok) return r1;
7756
- if (!this.persist(r1.data, version)) return this.malformedResponseError();
7782
+ this.persist(r1.data, version);
7757
7783
  return {
7758
7784
  ok: true,
7759
7785
  data: null
@@ -7762,7 +7788,7 @@ var SessionManager = class {
7762
7788
  if (input.type === "MOBILE_NUMBER") {
7763
7789
  const res2 = await this.authService.createSession(input, version);
7764
7790
  if (res2.ok) {
7765
- if (!this.persist(res2.data, version)) return this.malformedResponseError();
7791
+ this.persist(res2.data, version);
7766
7792
  return {
7767
7793
  ok: true,
7768
7794
  data: null
@@ -7774,13 +7800,12 @@ var SessionManager = class {
7774
7800
  const res2 = await this.authService.createSession(
7775
7801
  {
7776
7802
  type: "SOCIALS",
7777
- token: input.token,
7778
- channel: input.channel
7803
+ token: input.token
7779
7804
  },
7780
7805
  version
7781
7806
  );
7782
7807
  if (res2.ok) {
7783
- if (!this.persist(res2.data, version)) return this.malformedResponseError();
7808
+ this.persist(res2.data, version);
7784
7809
  return {
7785
7810
  ok: true,
7786
7811
  data: null
@@ -7792,7 +7817,7 @@ var SessionManager = class {
7792
7817
  localStorage.setItem(this.platformStorageKey, "CABINET");
7793
7818
  const res2 = await this.authService.createSession(input, version);
7794
7819
  if (res2.ok) {
7795
- if (!this.persist(res2.data, version)) return this.malformedResponseError();
7820
+ this.persist(res2.data, version);
7796
7821
  return {
7797
7822
  ok: true,
7798
7823
  data: null
@@ -7810,7 +7835,7 @@ var SessionManager = class {
7810
7835
  }
7811
7836
  };
7812
7837
  }
7813
- if (!this.persist(res.data, version)) return this.malformedResponseError();
7838
+ this.persist(res.data, version);
7814
7839
  return {
7815
7840
  ok: true,
7816
7841
  data: null
@@ -7820,9 +7845,9 @@ var SessionManager = class {
7820
7845
  const res = await this.authService.authenticate(input);
7821
7846
  if (res.ok) {
7822
7847
  if (this.isServer) {
7823
- this.logger.warn("'localStorage' is not available on the server.");
7824
- } else if (!this.persist(res.data, 1)) {
7825
- return this.malformedResponseError();
7848
+ this.logger.warn("'client cookies' is not available on the server.");
7849
+ } else {
7850
+ this.persist(res.data, 1);
7826
7851
  }
7827
7852
  return { ok: true };
7828
7853
  } else {
@@ -7831,7 +7856,7 @@ var SessionManager = class {
7831
7856
  }
7832
7857
  async get() {
7833
7858
  if (this.isServer) {
7834
- this.logger.warn("'localStorage' is not available on the server.");
7859
+ this.logger.warn("'client cookies' is not available on the server.");
7835
7860
  return {
7836
7861
  ok: true,
7837
7862
  data: null
@@ -7841,7 +7866,7 @@ var SessionManager = class {
7841
7866
  await sleep(1e3);
7842
7867
  return await this.get();
7843
7868
  }
7844
- const val = localStorage.getItem(this.storageKey);
7869
+ const val = cookies__default.default.get(this.storageKey);
7845
7870
  if (!val) {
7846
7871
  return {
7847
7872
  ok: true,
@@ -7859,7 +7884,7 @@ var SessionManager = class {
7859
7884
  const refreshTokenExpiresAt = new Date(obj.refreshTokenExpiresAt);
7860
7885
  if (isAfter(now, refreshTokenExpiresAt)) {
7861
7886
  this.logger.warn("Session expired. Logging out..");
7862
- localStorage.removeItem(this.storageKey);
7887
+ cookies__default.default.remove(this.storageKey);
7863
7888
  return {
7864
7889
  ok: false,
7865
7890
  error: {
@@ -7879,7 +7904,7 @@ var SessionManager = class {
7879
7904
  if (!res.ok) {
7880
7905
  this.logger.error(`Failed to refresh session: ${res.error.message}`);
7881
7906
  if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
7882
- localStorage.removeItem(this.storageKey);
7907
+ cookies__default.default.remove(this.storageKey);
7883
7908
  return {
7884
7909
  ok: false,
7885
7910
  error: res.error
@@ -7901,7 +7926,9 @@ var SessionManager = class {
7901
7926
  accessTokenExpiresAt: addMinutes(now, 8).getTime(),
7902
7927
  refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
7903
7928
  };
7904
- localStorage.setItem(this.storageKey, JSON.stringify(obj));
7929
+ cookies__default.default.set(this.storageKey, JSON.stringify(obj), {
7930
+ expires: subMinutes(addDays(now, 30), 2).getTime()
7931
+ });
7905
7932
  }
7906
7933
  return {
7907
7934
  ok: true,
@@ -7919,13 +7946,13 @@ var SessionManager = class {
7919
7946
  }
7920
7947
  async refresh() {
7921
7948
  if (this.isServer) {
7922
- this.logger.warn("'localStorage' is not available on the server.");
7949
+ this.logger.warn("'client cookies' is not available on the server.");
7923
7950
  return {
7924
7951
  ok: true,
7925
7952
  data: null
7926
7953
  };
7927
7954
  }
7928
- const val = localStorage.getItem(this.storageKey);
7955
+ const val = cookies__default.default.get(this.storageKey);
7929
7956
  if (!val) {
7930
7957
  return {
7931
7958
  ok: true,
@@ -7949,7 +7976,7 @@ var SessionManager = class {
7949
7976
  if (!res.ok) {
7950
7977
  this.logger.error(`Failed to refresh session: ${res.error.message}`);
7951
7978
  if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
7952
- localStorage.removeItem(this.storageKey);
7979
+ cookies__default.default.remove(this.storageKey);
7953
7980
  return {
7954
7981
  ok: false,
7955
7982
  error: res.error
@@ -7971,7 +7998,9 @@ var SessionManager = class {
7971
7998
  accessTokenExpiresAt: addMinutes(now, 8).getTime(),
7972
7999
  refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
7973
8000
  };
7974
- localStorage.setItem(this.storageKey, JSON.stringify(obj));
8001
+ cookies__default.default.set(this.storageKey, JSON.stringify(obj), {
8002
+ expires: subMinutes(addDays(now, 30), 2).getTime()
8003
+ });
7975
8004
  return {
7976
8005
  ok: true,
7977
8006
  data: obj
@@ -8001,15 +8030,6 @@ var SessionManager = class {
8001
8030
  return await this.refreshV4(session);
8002
8031
  }
8003
8032
  async refreshV4(session) {
8004
- if (this.v4RefreshPromise) return await this.v4RefreshPromise;
8005
- this.v4RefreshPromise = this.requestV4Refresh(session);
8006
- try {
8007
- return await this.v4RefreshPromise;
8008
- } finally {
8009
- this.v4RefreshPromise = null;
8010
- }
8011
- }
8012
- async requestV4Refresh(session) {
8013
8033
  this.logger.info("Refreshing session...");
8014
8034
  this.refreshing = true;
8015
8035
  const res = await this.authService.refreshSession(void 0, 4);
@@ -8017,7 +8037,7 @@ var SessionManager = class {
8017
8037
  if (!res.ok) {
8018
8038
  this.logger.error(`Failed to refresh session: ${res.error.message}`);
8019
8039
  if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
8020
- localStorage.removeItem(this.storageKey);
8040
+ cookies__default.default.remove(this.storageKey);
8021
8041
  this.v4AccessToken = null;
8022
8042
  this.v4AccessTokenExpiresAt = null;
8023
8043
  }
@@ -8041,11 +8061,11 @@ var SessionManager = class {
8041
8061
  }
8042
8062
  async destroy() {
8043
8063
  if (this.isServer) {
8044
- this.logger.warn("'localStorage' is not available on the server.");
8064
+ this.logger.warn("'client cookies' is not available on the server.");
8045
8065
  return;
8046
8066
  }
8047
8067
  let version = 1;
8048
- const val = localStorage.getItem(this.storageKey);
8068
+ const val = cookies__default.default.get(this.storageKey);
8049
8069
  if (val) {
8050
8070
  try {
8051
8071
  const stored = JSON.parse(val);
@@ -8059,14 +8079,14 @@ var SessionManager = class {
8059
8079
  }
8060
8080
  this.v4AccessToken = null;
8061
8081
  this.v4AccessTokenExpiresAt = null;
8062
- localStorage.removeItem(this.storageKey);
8082
+ cookies__default.default.remove(this.storageKey);
8063
8083
  }
8064
8084
  async verify() {
8065
8085
  if (this.isServer) {
8066
- this.logger.warn("'localStorage' is not available on the server.");
8086
+ this.logger.warn("'client cookies' is not available on the server.");
8067
8087
  return true;
8068
8088
  }
8069
- const val = localStorage.getItem(this.storageKey);
8089
+ const val = cookies__default.default.get(this.storageKey);
8070
8090
  if (val) {
8071
8091
  try {
8072
8092
  const stored = JSON.parse(val);
@@ -8081,7 +8101,7 @@ var SessionManager = class {
8081
8101
  if (!s.data) return true;
8082
8102
  const v = await this.authService.verifySession(s.data.accessToken);
8083
8103
  if (!v) {
8084
- localStorage.removeItem(this.storageKey);
8104
+ cookies__default.default.remove(this.storageKey);
8085
8105
  }
8086
8106
  return v;
8087
8107
  }
@@ -8092,7 +8112,7 @@ var SessionManager = class {
8092
8112
  }
8093
8113
  const v = await this.authService.verifySession(this.v4AccessToken);
8094
8114
  if (!v) {
8095
- localStorage.removeItem(this.storageKey);
8115
+ cookies__default.default.remove(this.storageKey);
8096
8116
  this.v4AccessToken = null;
8097
8117
  this.v4AccessTokenExpiresAt = null;
8098
8118
  }
@@ -8100,7 +8120,7 @@ var SessionManager = class {
8100
8120
  }
8101
8121
  get onMaya() {
8102
8122
  if (this.isServer) {
8103
- this.logger.warn("'localStorage' is not available on the server.");
8123
+ this.logger.warn("'client cookies' is not available on the server.");
8104
8124
  return false;
8105
8125
  }
8106
8126
  return localStorage.getItem(this.platformStorageKey) === "MAYA";
@@ -10394,13 +10414,19 @@ var Sdk = class {
10394
10414
  await this.sessionManager.destroy();
10395
10415
  }
10396
10416
  watchSession(input) {
10397
- const interval = clamp(input.interval ?? 3e4, 3e4, 6e4);
10417
+ const interval = clamp(input.interval ?? 3e4, 5e3, 6e4);
10398
10418
  let timeout = null;
10419
+ let isForeground = true;
10420
+ const listener = app.App.addListener("appStateChange", ({ isActive }) => {
10421
+ isForeground = isActive;
10422
+ });
10399
10423
  const assignTimeout = () => {
10400
10424
  return setTimeout(async () => {
10401
- const v = await this.sessionManager.verify();
10402
- if (!v) {
10403
- await input.onInvalid();
10425
+ if (isForeground) {
10426
+ const v = await this.sessionManager.verify();
10427
+ if (!v) {
10428
+ await input.onInvalid();
10429
+ }
10404
10430
  }
10405
10431
  timeout = assignTimeout();
10406
10432
  }, interval);
@@ -10410,6 +10436,7 @@ var Sdk = class {
10410
10436
  if (timeout) {
10411
10437
  clearTimeout(timeout);
10412
10438
  }
10439
+ listener.then((handle) => handle.remove());
10413
10440
  };
10414
10441
  }
10415
10442
  async session() {
@@ -10867,6 +10894,13 @@ var Sdk = class {
10867
10894
  verificationCode: input.verificationCode
10868
10895
  });
10869
10896
  }
10897
+ async updatePassword(input) {
10898
+ return await this.accountService.updatePassword({
10899
+ input: {
10900
+ password: await sha256(input.password)
10901
+ }
10902
+ });
10903
+ }
10870
10904
  async verifyMobileNumber(verificationCode) {
10871
10905
  return await this.accountService.verifyMobileNumber({
10872
10906
  input: {