@opexa/portal-sdk 0.59.84 → 0.59.85
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 +128 -122
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +128 -122
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
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');
|
|
@@ -7216,8 +7217,8 @@ function pollable(func, config) {
|
|
|
7216
7217
|
};
|
|
7217
7218
|
}
|
|
7218
7219
|
|
|
7219
|
-
// src/sdk/session-manager
|
|
7220
|
-
var
|
|
7220
|
+
// src/sdk/session-manager.ts
|
|
7221
|
+
var SessionManager = class {
|
|
7221
7222
|
logger;
|
|
7222
7223
|
storageKey = "session";
|
|
7223
7224
|
platformStorageKey = "session/platform";
|
|
@@ -7231,10 +7232,15 @@ var SessionManagerCookie = class {
|
|
|
7231
7232
|
*/
|
|
7232
7233
|
v4AccessToken = null;
|
|
7233
7234
|
v4AccessTokenExpiresAt = null;
|
|
7235
|
+
v4RefreshPromise = null;
|
|
7234
7236
|
constructor(config) {
|
|
7235
7237
|
this.authService = config.authService;
|
|
7236
7238
|
this.walletService = config.walletService;
|
|
7237
7239
|
this.logger = config.logger;
|
|
7240
|
+
if (config.sessionPrefix) {
|
|
7241
|
+
this.storageKey = `${config.sessionPrefix}/${this.storageKey}`;
|
|
7242
|
+
this.platformStorageKey = `${config.sessionPrefix}/${this.platformStorageKey}`;
|
|
7243
|
+
}
|
|
7238
7244
|
}
|
|
7239
7245
|
get refreshing() {
|
|
7240
7246
|
return this._refreshing;
|
|
@@ -7245,27 +7251,51 @@ var SessionManagerCookie = class {
|
|
|
7245
7251
|
persist(data, version) {
|
|
7246
7252
|
const now = /* @__PURE__ */ new Date();
|
|
7247
7253
|
if (version === 4) {
|
|
7248
|
-
|
|
7254
|
+
if (!data.session || !data.accessToken) {
|
|
7255
|
+
this.logger.error(
|
|
7256
|
+
"Malformed session response: expected 'session' and 'accessToken'."
|
|
7257
|
+
);
|
|
7258
|
+
return false;
|
|
7259
|
+
}
|
|
7260
|
+
this.v4AccessToken = data.accessToken;
|
|
7249
7261
|
this.v4AccessTokenExpiresAt = addMinutes(now, 5).getTime();
|
|
7250
|
-
|
|
7262
|
+
localStorage.setItem(
|
|
7251
7263
|
this.storageKey,
|
|
7252
|
-
JSON.stringify({ version, session: data.session })
|
|
7253
|
-
{ expires: subMinutes(addDays(now, 15), 2).getTime() }
|
|
7264
|
+
JSON.stringify({ version, session: data.session })
|
|
7254
7265
|
);
|
|
7255
|
-
return;
|
|
7266
|
+
return true;
|
|
7256
7267
|
}
|
|
7257
|
-
|
|
7268
|
+
localStorage.setItem(
|
|
7258
7269
|
this.storageKey,
|
|
7259
7270
|
JSON.stringify({
|
|
7260
7271
|
version,
|
|
7261
7272
|
...data,
|
|
7262
7273
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
7263
7274
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
7264
|
-
})
|
|
7265
|
-
{ expires: subMinutes(addDays(now, 30), 2).getTime() }
|
|
7275
|
+
})
|
|
7266
7276
|
);
|
|
7277
|
+
return true;
|
|
7278
|
+
}
|
|
7279
|
+
malformedResponseError() {
|
|
7280
|
+
return {
|
|
7281
|
+
ok: false,
|
|
7282
|
+
error: {
|
|
7283
|
+
name: "UnknownError",
|
|
7284
|
+
message: "Something went wrong."
|
|
7285
|
+
}
|
|
7286
|
+
};
|
|
7267
7287
|
}
|
|
7268
7288
|
async create(input, version = 1) {
|
|
7289
|
+
if (this.isServer) {
|
|
7290
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
7291
|
+
return {
|
|
7292
|
+
ok: false,
|
|
7293
|
+
error: {
|
|
7294
|
+
name: "UnknownError",
|
|
7295
|
+
message: "Server sign in is not supported."
|
|
7296
|
+
}
|
|
7297
|
+
};
|
|
7298
|
+
}
|
|
7269
7299
|
if (input.type === "MAYA") {
|
|
7270
7300
|
localStorage.setItem(this.platformStorageKey, "MAYA");
|
|
7271
7301
|
const f0 = () => this.walletService.mayaSession({ id: input.sessionId });
|
|
@@ -7291,7 +7321,7 @@ var SessionManagerCookie = class {
|
|
|
7291
7321
|
maxAttempt: 5
|
|
7292
7322
|
})();
|
|
7293
7323
|
if (!r1.ok) return r1;
|
|
7294
|
-
this.persist(r1.data, version);
|
|
7324
|
+
if (!this.persist(r1.data, version)) return this.malformedResponseError();
|
|
7295
7325
|
return {
|
|
7296
7326
|
ok: true,
|
|
7297
7327
|
data: null
|
|
@@ -7300,7 +7330,7 @@ var SessionManagerCookie = class {
|
|
|
7300
7330
|
if (input.type === "MOBILE_NUMBER") {
|
|
7301
7331
|
const res2 = await this.authService.createSession(input, version);
|
|
7302
7332
|
if (res2.ok) {
|
|
7303
|
-
this.persist(res2.data, version);
|
|
7333
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
7304
7334
|
return {
|
|
7305
7335
|
ok: true,
|
|
7306
7336
|
data: null
|
|
@@ -7312,12 +7342,13 @@ var SessionManagerCookie = class {
|
|
|
7312
7342
|
const res2 = await this.authService.createSession(
|
|
7313
7343
|
{
|
|
7314
7344
|
type: "SOCIALS",
|
|
7315
|
-
token: input.token
|
|
7345
|
+
token: input.token,
|
|
7346
|
+
channel: input.channel
|
|
7316
7347
|
},
|
|
7317
7348
|
version
|
|
7318
7349
|
);
|
|
7319
7350
|
if (res2.ok) {
|
|
7320
|
-
this.persist(res2.data, version);
|
|
7351
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
7321
7352
|
return {
|
|
7322
7353
|
ok: true,
|
|
7323
7354
|
data: null
|
|
@@ -7329,7 +7360,7 @@ var SessionManagerCookie = class {
|
|
|
7329
7360
|
localStorage.setItem(this.platformStorageKey, "CABINET");
|
|
7330
7361
|
const res2 = await this.authService.createSession(input, version);
|
|
7331
7362
|
if (res2.ok) {
|
|
7332
|
-
this.persist(res2.data, version);
|
|
7363
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
7333
7364
|
return {
|
|
7334
7365
|
ok: true,
|
|
7335
7366
|
data: null
|
|
@@ -7347,7 +7378,7 @@ var SessionManagerCookie = class {
|
|
|
7347
7378
|
}
|
|
7348
7379
|
};
|
|
7349
7380
|
}
|
|
7350
|
-
this.persist(res.data, version);
|
|
7381
|
+
if (!this.persist(res.data, version)) return this.malformedResponseError();
|
|
7351
7382
|
return {
|
|
7352
7383
|
ok: true,
|
|
7353
7384
|
data: null
|
|
@@ -7357,9 +7388,9 @@ var SessionManagerCookie = class {
|
|
|
7357
7388
|
const res = await this.authService.authenticate(input);
|
|
7358
7389
|
if (res.ok) {
|
|
7359
7390
|
if (this.isServer) {
|
|
7360
|
-
this.logger.warn("'
|
|
7361
|
-
} else {
|
|
7362
|
-
this.
|
|
7391
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
7392
|
+
} else if (!this.persist(res.data, 1)) {
|
|
7393
|
+
return this.malformedResponseError();
|
|
7363
7394
|
}
|
|
7364
7395
|
return { ok: true };
|
|
7365
7396
|
} else {
|
|
@@ -7368,7 +7399,7 @@ var SessionManagerCookie = class {
|
|
|
7368
7399
|
}
|
|
7369
7400
|
async get() {
|
|
7370
7401
|
if (this.isServer) {
|
|
7371
|
-
this.logger.warn("'
|
|
7402
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
7372
7403
|
return {
|
|
7373
7404
|
ok: true,
|
|
7374
7405
|
data: null
|
|
@@ -7378,7 +7409,7 @@ var SessionManagerCookie = class {
|
|
|
7378
7409
|
await sleep(1e3);
|
|
7379
7410
|
return await this.get();
|
|
7380
7411
|
}
|
|
7381
|
-
const val =
|
|
7412
|
+
const val = localStorage.getItem(this.storageKey);
|
|
7382
7413
|
if (!val) {
|
|
7383
7414
|
return {
|
|
7384
7415
|
ok: true,
|
|
@@ -7396,7 +7427,7 @@ var SessionManagerCookie = class {
|
|
|
7396
7427
|
const refreshTokenExpiresAt = new Date(obj.refreshTokenExpiresAt);
|
|
7397
7428
|
if (isAfter(now, refreshTokenExpiresAt)) {
|
|
7398
7429
|
this.logger.warn("Session expired. Logging out..");
|
|
7399
|
-
|
|
7430
|
+
localStorage.removeItem(this.storageKey);
|
|
7400
7431
|
return {
|
|
7401
7432
|
ok: false,
|
|
7402
7433
|
error: {
|
|
@@ -7416,7 +7447,7 @@ var SessionManagerCookie = class {
|
|
|
7416
7447
|
if (!res.ok) {
|
|
7417
7448
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
7418
7449
|
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
7419
|
-
|
|
7450
|
+
localStorage.removeItem(this.storageKey);
|
|
7420
7451
|
return {
|
|
7421
7452
|
ok: false,
|
|
7422
7453
|
error: res.error
|
|
@@ -7438,9 +7469,7 @@ var SessionManagerCookie = class {
|
|
|
7438
7469
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
7439
7470
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
7440
7471
|
};
|
|
7441
|
-
|
|
7442
|
-
expires: subMinutes(addDays(now, 30), 2).getTime()
|
|
7443
|
-
});
|
|
7472
|
+
localStorage.setItem(this.storageKey, JSON.stringify(obj));
|
|
7444
7473
|
}
|
|
7445
7474
|
return {
|
|
7446
7475
|
ok: true,
|
|
@@ -7458,13 +7487,13 @@ var SessionManagerCookie = class {
|
|
|
7458
7487
|
}
|
|
7459
7488
|
async refresh() {
|
|
7460
7489
|
if (this.isServer) {
|
|
7461
|
-
this.logger.warn("'
|
|
7490
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
7462
7491
|
return {
|
|
7463
7492
|
ok: true,
|
|
7464
7493
|
data: null
|
|
7465
7494
|
};
|
|
7466
7495
|
}
|
|
7467
|
-
const val =
|
|
7496
|
+
const val = localStorage.getItem(this.storageKey);
|
|
7468
7497
|
if (!val) {
|
|
7469
7498
|
return {
|
|
7470
7499
|
ok: true,
|
|
@@ -7488,7 +7517,7 @@ var SessionManagerCookie = class {
|
|
|
7488
7517
|
if (!res.ok) {
|
|
7489
7518
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
7490
7519
|
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
7491
|
-
|
|
7520
|
+
localStorage.removeItem(this.storageKey);
|
|
7492
7521
|
return {
|
|
7493
7522
|
ok: false,
|
|
7494
7523
|
error: res.error
|
|
@@ -7510,9 +7539,7 @@ var SessionManagerCookie = class {
|
|
|
7510
7539
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
7511
7540
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
7512
7541
|
};
|
|
7513
|
-
|
|
7514
|
-
expires: subMinutes(addDays(now, 30), 2).getTime()
|
|
7515
|
-
});
|
|
7542
|
+
localStorage.setItem(this.storageKey, JSON.stringify(obj));
|
|
7516
7543
|
return {
|
|
7517
7544
|
ok: true,
|
|
7518
7545
|
data: obj
|
|
@@ -7542,6 +7569,15 @@ var SessionManagerCookie = class {
|
|
|
7542
7569
|
return await this.refreshV4(session);
|
|
7543
7570
|
}
|
|
7544
7571
|
async refreshV4(session) {
|
|
7572
|
+
if (this.v4RefreshPromise) return await this.v4RefreshPromise;
|
|
7573
|
+
this.v4RefreshPromise = this.requestV4Refresh(session);
|
|
7574
|
+
try {
|
|
7575
|
+
return await this.v4RefreshPromise;
|
|
7576
|
+
} finally {
|
|
7577
|
+
this.v4RefreshPromise = null;
|
|
7578
|
+
}
|
|
7579
|
+
}
|
|
7580
|
+
async requestV4Refresh(session) {
|
|
7545
7581
|
this.logger.info("Refreshing session...");
|
|
7546
7582
|
this.refreshing = true;
|
|
7547
7583
|
const res = await this.authService.refreshSession(void 0, 4);
|
|
@@ -7549,7 +7585,7 @@ var SessionManagerCookie = class {
|
|
|
7549
7585
|
if (!res.ok) {
|
|
7550
7586
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
7551
7587
|
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
7552
|
-
|
|
7588
|
+
localStorage.removeItem(this.storageKey);
|
|
7553
7589
|
this.v4AccessToken = null;
|
|
7554
7590
|
this.v4AccessTokenExpiresAt = null;
|
|
7555
7591
|
}
|
|
@@ -7573,11 +7609,11 @@ var SessionManagerCookie = class {
|
|
|
7573
7609
|
}
|
|
7574
7610
|
async destroy() {
|
|
7575
7611
|
if (this.isServer) {
|
|
7576
|
-
this.logger.warn("'
|
|
7612
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
7577
7613
|
return;
|
|
7578
7614
|
}
|
|
7579
7615
|
let version = 1;
|
|
7580
|
-
const val =
|
|
7616
|
+
const val = localStorage.getItem(this.storageKey);
|
|
7581
7617
|
if (val) {
|
|
7582
7618
|
try {
|
|
7583
7619
|
const stored = JSON.parse(val);
|
|
@@ -7591,14 +7627,14 @@ var SessionManagerCookie = class {
|
|
|
7591
7627
|
}
|
|
7592
7628
|
this.v4AccessToken = null;
|
|
7593
7629
|
this.v4AccessTokenExpiresAt = null;
|
|
7594
|
-
|
|
7630
|
+
localStorage.removeItem(this.storageKey);
|
|
7595
7631
|
}
|
|
7596
7632
|
async verify() {
|
|
7597
7633
|
if (this.isServer) {
|
|
7598
|
-
this.logger.warn("'
|
|
7634
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
7599
7635
|
return true;
|
|
7600
7636
|
}
|
|
7601
|
-
const val =
|
|
7637
|
+
const val = localStorage.getItem(this.storageKey);
|
|
7602
7638
|
if (val) {
|
|
7603
7639
|
try {
|
|
7604
7640
|
const stored = JSON.parse(val);
|
|
@@ -7613,7 +7649,7 @@ var SessionManagerCookie = class {
|
|
|
7613
7649
|
if (!s.data) return true;
|
|
7614
7650
|
const v = await this.authService.verifySession(s.data.accessToken);
|
|
7615
7651
|
if (!v) {
|
|
7616
|
-
|
|
7652
|
+
localStorage.removeItem(this.storageKey);
|
|
7617
7653
|
}
|
|
7618
7654
|
return v;
|
|
7619
7655
|
}
|
|
@@ -7624,7 +7660,7 @@ var SessionManagerCookie = class {
|
|
|
7624
7660
|
}
|
|
7625
7661
|
const v = await this.authService.verifySession(this.v4AccessToken);
|
|
7626
7662
|
if (!v) {
|
|
7627
|
-
|
|
7663
|
+
localStorage.removeItem(this.storageKey);
|
|
7628
7664
|
this.v4AccessToken = null;
|
|
7629
7665
|
this.v4AccessTokenExpiresAt = null;
|
|
7630
7666
|
}
|
|
@@ -7632,7 +7668,7 @@ var SessionManagerCookie = class {
|
|
|
7632
7668
|
}
|
|
7633
7669
|
get onMaya() {
|
|
7634
7670
|
if (this.isServer) {
|
|
7635
|
-
this.logger.warn("'
|
|
7671
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
7636
7672
|
return false;
|
|
7637
7673
|
}
|
|
7638
7674
|
return localStorage.getItem(this.platformStorageKey) === "MAYA";
|
|
@@ -7648,9 +7684,7 @@ var SessionManagerCookie = class {
|
|
|
7648
7684
|
return typeof window === "undefined";
|
|
7649
7685
|
}
|
|
7650
7686
|
};
|
|
7651
|
-
|
|
7652
|
-
// src/sdk/session-manager.ts
|
|
7653
|
-
var SessionManager = class {
|
|
7687
|
+
var SessionManagerCookie = class {
|
|
7654
7688
|
logger;
|
|
7655
7689
|
storageKey = "session";
|
|
7656
7690
|
platformStorageKey = "session/platform";
|
|
@@ -7664,15 +7698,10 @@ var SessionManager = class {
|
|
|
7664
7698
|
*/
|
|
7665
7699
|
v4AccessToken = null;
|
|
7666
7700
|
v4AccessTokenExpiresAt = null;
|
|
7667
|
-
v4RefreshPromise = null;
|
|
7668
7701
|
constructor(config) {
|
|
7669
7702
|
this.authService = config.authService;
|
|
7670
7703
|
this.walletService = config.walletService;
|
|
7671
7704
|
this.logger = config.logger;
|
|
7672
|
-
if (config.sessionPrefix) {
|
|
7673
|
-
this.storageKey = `${config.sessionPrefix}/${this.storageKey}`;
|
|
7674
|
-
this.platformStorageKey = `${config.sessionPrefix}/${this.platformStorageKey}`;
|
|
7675
|
-
}
|
|
7676
7705
|
}
|
|
7677
7706
|
get refreshing() {
|
|
7678
7707
|
return this._refreshing;
|
|
@@ -7683,51 +7712,27 @@ var SessionManager = class {
|
|
|
7683
7712
|
persist(data, version) {
|
|
7684
7713
|
const now = /* @__PURE__ */ new Date();
|
|
7685
7714
|
if (version === 4) {
|
|
7686
|
-
|
|
7687
|
-
this.logger.error(
|
|
7688
|
-
"Malformed session response: expected 'session' and 'accessToken'."
|
|
7689
|
-
);
|
|
7690
|
-
return false;
|
|
7691
|
-
}
|
|
7692
|
-
this.v4AccessToken = data.accessToken;
|
|
7715
|
+
this.v4AccessToken = data.accessToken ?? null;
|
|
7693
7716
|
this.v4AccessTokenExpiresAt = addMinutes(now, 5).getTime();
|
|
7694
|
-
|
|
7717
|
+
cookies__default.default.set(
|
|
7695
7718
|
this.storageKey,
|
|
7696
|
-
JSON.stringify({ version, session: data.session })
|
|
7719
|
+
JSON.stringify({ version, session: data.session }),
|
|
7720
|
+
{ expires: subMinutes(addDays(now, 15), 2).getTime() }
|
|
7697
7721
|
);
|
|
7698
|
-
return
|
|
7722
|
+
return;
|
|
7699
7723
|
}
|
|
7700
|
-
|
|
7724
|
+
cookies__default.default.set(
|
|
7701
7725
|
this.storageKey,
|
|
7702
7726
|
JSON.stringify({
|
|
7703
7727
|
version,
|
|
7704
7728
|
...data,
|
|
7705
7729
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
7706
7730
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
7707
|
-
})
|
|
7731
|
+
}),
|
|
7732
|
+
{ expires: subMinutes(addDays(now, 30), 2).getTime() }
|
|
7708
7733
|
);
|
|
7709
|
-
return true;
|
|
7710
|
-
}
|
|
7711
|
-
malformedResponseError() {
|
|
7712
|
-
return {
|
|
7713
|
-
ok: false,
|
|
7714
|
-
error: {
|
|
7715
|
-
name: "UnknownError",
|
|
7716
|
-
message: "Something went wrong."
|
|
7717
|
-
}
|
|
7718
|
-
};
|
|
7719
7734
|
}
|
|
7720
7735
|
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
7736
|
if (input.type === "MAYA") {
|
|
7732
7737
|
localStorage.setItem(this.platformStorageKey, "MAYA");
|
|
7733
7738
|
const f0 = () => this.walletService.mayaSession({ id: input.sessionId });
|
|
@@ -7753,7 +7758,7 @@ var SessionManager = class {
|
|
|
7753
7758
|
maxAttempt: 5
|
|
7754
7759
|
})();
|
|
7755
7760
|
if (!r1.ok) return r1;
|
|
7756
|
-
|
|
7761
|
+
this.persist(r1.data, version);
|
|
7757
7762
|
return {
|
|
7758
7763
|
ok: true,
|
|
7759
7764
|
data: null
|
|
@@ -7762,7 +7767,7 @@ var SessionManager = class {
|
|
|
7762
7767
|
if (input.type === "MOBILE_NUMBER") {
|
|
7763
7768
|
const res2 = await this.authService.createSession(input, version);
|
|
7764
7769
|
if (res2.ok) {
|
|
7765
|
-
|
|
7770
|
+
this.persist(res2.data, version);
|
|
7766
7771
|
return {
|
|
7767
7772
|
ok: true,
|
|
7768
7773
|
data: null
|
|
@@ -7774,13 +7779,12 @@ var SessionManager = class {
|
|
|
7774
7779
|
const res2 = await this.authService.createSession(
|
|
7775
7780
|
{
|
|
7776
7781
|
type: "SOCIALS",
|
|
7777
|
-
token: input.token
|
|
7778
|
-
channel: input.channel
|
|
7782
|
+
token: input.token
|
|
7779
7783
|
},
|
|
7780
7784
|
version
|
|
7781
7785
|
);
|
|
7782
7786
|
if (res2.ok) {
|
|
7783
|
-
|
|
7787
|
+
this.persist(res2.data, version);
|
|
7784
7788
|
return {
|
|
7785
7789
|
ok: true,
|
|
7786
7790
|
data: null
|
|
@@ -7792,7 +7796,7 @@ var SessionManager = class {
|
|
|
7792
7796
|
localStorage.setItem(this.platformStorageKey, "CABINET");
|
|
7793
7797
|
const res2 = await this.authService.createSession(input, version);
|
|
7794
7798
|
if (res2.ok) {
|
|
7795
|
-
|
|
7799
|
+
this.persist(res2.data, version);
|
|
7796
7800
|
return {
|
|
7797
7801
|
ok: true,
|
|
7798
7802
|
data: null
|
|
@@ -7810,7 +7814,7 @@ var SessionManager = class {
|
|
|
7810
7814
|
}
|
|
7811
7815
|
};
|
|
7812
7816
|
}
|
|
7813
|
-
|
|
7817
|
+
this.persist(res.data, version);
|
|
7814
7818
|
return {
|
|
7815
7819
|
ok: true,
|
|
7816
7820
|
data: null
|
|
@@ -7820,9 +7824,9 @@ var SessionManager = class {
|
|
|
7820
7824
|
const res = await this.authService.authenticate(input);
|
|
7821
7825
|
if (res.ok) {
|
|
7822
7826
|
if (this.isServer) {
|
|
7823
|
-
this.logger.warn("'
|
|
7824
|
-
} else
|
|
7825
|
-
|
|
7827
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
7828
|
+
} else {
|
|
7829
|
+
this.persist(res.data, 1);
|
|
7826
7830
|
}
|
|
7827
7831
|
return { ok: true };
|
|
7828
7832
|
} else {
|
|
@@ -7831,7 +7835,7 @@ var SessionManager = class {
|
|
|
7831
7835
|
}
|
|
7832
7836
|
async get() {
|
|
7833
7837
|
if (this.isServer) {
|
|
7834
|
-
this.logger.warn("'
|
|
7838
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
7835
7839
|
return {
|
|
7836
7840
|
ok: true,
|
|
7837
7841
|
data: null
|
|
@@ -7841,7 +7845,7 @@ var SessionManager = class {
|
|
|
7841
7845
|
await sleep(1e3);
|
|
7842
7846
|
return await this.get();
|
|
7843
7847
|
}
|
|
7844
|
-
const val =
|
|
7848
|
+
const val = cookies__default.default.get(this.storageKey);
|
|
7845
7849
|
if (!val) {
|
|
7846
7850
|
return {
|
|
7847
7851
|
ok: true,
|
|
@@ -7859,7 +7863,7 @@ var SessionManager = class {
|
|
|
7859
7863
|
const refreshTokenExpiresAt = new Date(obj.refreshTokenExpiresAt);
|
|
7860
7864
|
if (isAfter(now, refreshTokenExpiresAt)) {
|
|
7861
7865
|
this.logger.warn("Session expired. Logging out..");
|
|
7862
|
-
|
|
7866
|
+
cookies__default.default.remove(this.storageKey);
|
|
7863
7867
|
return {
|
|
7864
7868
|
ok: false,
|
|
7865
7869
|
error: {
|
|
@@ -7879,7 +7883,7 @@ var SessionManager = class {
|
|
|
7879
7883
|
if (!res.ok) {
|
|
7880
7884
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
7881
7885
|
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
7882
|
-
|
|
7886
|
+
cookies__default.default.remove(this.storageKey);
|
|
7883
7887
|
return {
|
|
7884
7888
|
ok: false,
|
|
7885
7889
|
error: res.error
|
|
@@ -7901,7 +7905,9 @@ var SessionManager = class {
|
|
|
7901
7905
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
7902
7906
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
7903
7907
|
};
|
|
7904
|
-
|
|
7908
|
+
cookies__default.default.set(this.storageKey, JSON.stringify(obj), {
|
|
7909
|
+
expires: subMinutes(addDays(now, 30), 2).getTime()
|
|
7910
|
+
});
|
|
7905
7911
|
}
|
|
7906
7912
|
return {
|
|
7907
7913
|
ok: true,
|
|
@@ -7919,13 +7925,13 @@ var SessionManager = class {
|
|
|
7919
7925
|
}
|
|
7920
7926
|
async refresh() {
|
|
7921
7927
|
if (this.isServer) {
|
|
7922
|
-
this.logger.warn("'
|
|
7928
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
7923
7929
|
return {
|
|
7924
7930
|
ok: true,
|
|
7925
7931
|
data: null
|
|
7926
7932
|
};
|
|
7927
7933
|
}
|
|
7928
|
-
const val =
|
|
7934
|
+
const val = cookies__default.default.get(this.storageKey);
|
|
7929
7935
|
if (!val) {
|
|
7930
7936
|
return {
|
|
7931
7937
|
ok: true,
|
|
@@ -7949,7 +7955,7 @@ var SessionManager = class {
|
|
|
7949
7955
|
if (!res.ok) {
|
|
7950
7956
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
7951
7957
|
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
7952
|
-
|
|
7958
|
+
cookies__default.default.remove(this.storageKey);
|
|
7953
7959
|
return {
|
|
7954
7960
|
ok: false,
|
|
7955
7961
|
error: res.error
|
|
@@ -7971,7 +7977,9 @@ var SessionManager = class {
|
|
|
7971
7977
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
7972
7978
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
7973
7979
|
};
|
|
7974
|
-
|
|
7980
|
+
cookies__default.default.set(this.storageKey, JSON.stringify(obj), {
|
|
7981
|
+
expires: subMinutes(addDays(now, 30), 2).getTime()
|
|
7982
|
+
});
|
|
7975
7983
|
return {
|
|
7976
7984
|
ok: true,
|
|
7977
7985
|
data: obj
|
|
@@ -8001,15 +8009,6 @@ var SessionManager = class {
|
|
|
8001
8009
|
return await this.refreshV4(session);
|
|
8002
8010
|
}
|
|
8003
8011
|
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
8012
|
this.logger.info("Refreshing session...");
|
|
8014
8013
|
this.refreshing = true;
|
|
8015
8014
|
const res = await this.authService.refreshSession(void 0, 4);
|
|
@@ -8017,7 +8016,7 @@ var SessionManager = class {
|
|
|
8017
8016
|
if (!res.ok) {
|
|
8018
8017
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
8019
8018
|
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
8020
|
-
|
|
8019
|
+
cookies__default.default.remove(this.storageKey);
|
|
8021
8020
|
this.v4AccessToken = null;
|
|
8022
8021
|
this.v4AccessTokenExpiresAt = null;
|
|
8023
8022
|
}
|
|
@@ -8041,11 +8040,11 @@ var SessionManager = class {
|
|
|
8041
8040
|
}
|
|
8042
8041
|
async destroy() {
|
|
8043
8042
|
if (this.isServer) {
|
|
8044
|
-
this.logger.warn("'
|
|
8043
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
8045
8044
|
return;
|
|
8046
8045
|
}
|
|
8047
8046
|
let version = 1;
|
|
8048
|
-
const val =
|
|
8047
|
+
const val = cookies__default.default.get(this.storageKey);
|
|
8049
8048
|
if (val) {
|
|
8050
8049
|
try {
|
|
8051
8050
|
const stored = JSON.parse(val);
|
|
@@ -8059,14 +8058,14 @@ var SessionManager = class {
|
|
|
8059
8058
|
}
|
|
8060
8059
|
this.v4AccessToken = null;
|
|
8061
8060
|
this.v4AccessTokenExpiresAt = null;
|
|
8062
|
-
|
|
8061
|
+
cookies__default.default.remove(this.storageKey);
|
|
8063
8062
|
}
|
|
8064
8063
|
async verify() {
|
|
8065
8064
|
if (this.isServer) {
|
|
8066
|
-
this.logger.warn("'
|
|
8065
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
8067
8066
|
return true;
|
|
8068
8067
|
}
|
|
8069
|
-
const val =
|
|
8068
|
+
const val = cookies__default.default.get(this.storageKey);
|
|
8070
8069
|
if (val) {
|
|
8071
8070
|
try {
|
|
8072
8071
|
const stored = JSON.parse(val);
|
|
@@ -8081,7 +8080,7 @@ var SessionManager = class {
|
|
|
8081
8080
|
if (!s.data) return true;
|
|
8082
8081
|
const v = await this.authService.verifySession(s.data.accessToken);
|
|
8083
8082
|
if (!v) {
|
|
8084
|
-
|
|
8083
|
+
cookies__default.default.remove(this.storageKey);
|
|
8085
8084
|
}
|
|
8086
8085
|
return v;
|
|
8087
8086
|
}
|
|
@@ -8092,7 +8091,7 @@ var SessionManager = class {
|
|
|
8092
8091
|
}
|
|
8093
8092
|
const v = await this.authService.verifySession(this.v4AccessToken);
|
|
8094
8093
|
if (!v) {
|
|
8095
|
-
|
|
8094
|
+
cookies__default.default.remove(this.storageKey);
|
|
8096
8095
|
this.v4AccessToken = null;
|
|
8097
8096
|
this.v4AccessTokenExpiresAt = null;
|
|
8098
8097
|
}
|
|
@@ -8100,7 +8099,7 @@ var SessionManager = class {
|
|
|
8100
8099
|
}
|
|
8101
8100
|
get onMaya() {
|
|
8102
8101
|
if (this.isServer) {
|
|
8103
|
-
this.logger.warn("'
|
|
8102
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
8104
8103
|
return false;
|
|
8105
8104
|
}
|
|
8106
8105
|
return localStorage.getItem(this.platformStorageKey) === "MAYA";
|
|
@@ -10394,13 +10393,19 @@ var Sdk = class {
|
|
|
10394
10393
|
await this.sessionManager.destroy();
|
|
10395
10394
|
}
|
|
10396
10395
|
watchSession(input) {
|
|
10397
|
-
const interval = clamp(input.interval ?? 3e4,
|
|
10396
|
+
const interval = clamp(input.interval ?? 3e4, 5e3, 6e4);
|
|
10398
10397
|
let timeout = null;
|
|
10398
|
+
let isForeground = true;
|
|
10399
|
+
const listener = app.App.addListener("appStateChange", ({ isActive }) => {
|
|
10400
|
+
isForeground = isActive;
|
|
10401
|
+
});
|
|
10399
10402
|
const assignTimeout = () => {
|
|
10400
10403
|
return setTimeout(async () => {
|
|
10401
|
-
|
|
10402
|
-
|
|
10403
|
-
|
|
10404
|
+
if (isForeground) {
|
|
10405
|
+
const v = await this.sessionManager.verify();
|
|
10406
|
+
if (!v) {
|
|
10407
|
+
await input.onInvalid();
|
|
10408
|
+
}
|
|
10404
10409
|
}
|
|
10405
10410
|
timeout = assignTimeout();
|
|
10406
10411
|
}, interval);
|
|
@@ -10410,6 +10415,7 @@ var Sdk = class {
|
|
|
10410
10415
|
if (timeout) {
|
|
10411
10416
|
clearTimeout(timeout);
|
|
10412
10417
|
}
|
|
10418
|
+
listener.then((handle) => handle.remove());
|
|
10413
10419
|
};
|
|
10414
10420
|
}
|
|
10415
10421
|
async session() {
|