@opexa/portal-sdk 0.57.2 → 0.57.3
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 +107 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +107 -90
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -2134,8 +2134,16 @@ declare class Sdk {
|
|
|
2134
2134
|
constructor(config: SdkConfig);
|
|
2135
2135
|
private _fetch;
|
|
2136
2136
|
private _middleware;
|
|
2137
|
+
/**
|
|
2138
|
+
* @deprecated use `setFetch` instead
|
|
2139
|
+
*/
|
|
2137
2140
|
set fetch(value: typeof globalThis.fetch | null);
|
|
2141
|
+
/**
|
|
2142
|
+
* @deprecated use `getFetch` instead
|
|
2143
|
+
*/
|
|
2138
2144
|
get fetch(): typeof globalThis.fetch | null;
|
|
2145
|
+
setFetch(value: typeof globalThis.fetch | null): Promise<void>;
|
|
2146
|
+
getFetch(): typeof fetch | null;
|
|
2139
2147
|
set middleware(value: GraphQLClientMiddleware);
|
|
2140
2148
|
get middleware(): GraphQLClientMiddleware;
|
|
2141
2149
|
initWebDomain(): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -2134,8 +2134,16 @@ declare class Sdk {
|
|
|
2134
2134
|
constructor(config: SdkConfig);
|
|
2135
2135
|
private _fetch;
|
|
2136
2136
|
private _middleware;
|
|
2137
|
+
/**
|
|
2138
|
+
* @deprecated use `setFetch` instead
|
|
2139
|
+
*/
|
|
2137
2140
|
set fetch(value: typeof globalThis.fetch | null);
|
|
2141
|
+
/**
|
|
2142
|
+
* @deprecated use `getFetch` instead
|
|
2143
|
+
*/
|
|
2138
2144
|
get fetch(): typeof globalThis.fetch | null;
|
|
2145
|
+
setFetch(value: typeof globalThis.fetch | null): Promise<void>;
|
|
2146
|
+
getFetch(): typeof fetch | null;
|
|
2139
2147
|
set middleware(value: GraphQLClientMiddleware);
|
|
2140
2148
|
get middleware(): GraphQLClientMiddleware;
|
|
2141
2149
|
initWebDomain(): void;
|
package/dist/index.js
CHANGED
|
@@ -6271,8 +6271,8 @@ function pollable(func, config) {
|
|
|
6271
6271
|
};
|
|
6272
6272
|
}
|
|
6273
6273
|
|
|
6274
|
-
// src/sdk/session-manager.ts
|
|
6275
|
-
var
|
|
6274
|
+
// src/sdk/session-manager-cookie.ts
|
|
6275
|
+
var SessionManagerCookie = class {
|
|
6276
6276
|
logger;
|
|
6277
6277
|
storageKey = "session";
|
|
6278
6278
|
platformStorageKey = "session/platform";
|
|
@@ -6283,10 +6283,6 @@ var SessionManager = class {
|
|
|
6283
6283
|
this.authService = config.authService;
|
|
6284
6284
|
this.walletService = config.walletService;
|
|
6285
6285
|
this.logger = config.logger;
|
|
6286
|
-
if (config.sessionPrefix) {
|
|
6287
|
-
this.storageKey = `${config.sessionPrefix}/${this.storageKey}`;
|
|
6288
|
-
this.platformStorageKey = `${config.sessionPrefix}/${this.platformStorageKey}`;
|
|
6289
|
-
}
|
|
6290
6286
|
}
|
|
6291
6287
|
get refreshing() {
|
|
6292
6288
|
return this._refreshing;
|
|
@@ -6295,16 +6291,6 @@ var SessionManager = class {
|
|
|
6295
6291
|
this._refreshing = value;
|
|
6296
6292
|
}
|
|
6297
6293
|
async create(input) {
|
|
6298
|
-
if (this.isServer) {
|
|
6299
|
-
this.logger.warn("'localStorage' is not available on the server.");
|
|
6300
|
-
return {
|
|
6301
|
-
ok: false,
|
|
6302
|
-
error: {
|
|
6303
|
-
name: "UnknownError",
|
|
6304
|
-
message: "Server sign in is not supported."
|
|
6305
|
-
}
|
|
6306
|
-
};
|
|
6307
|
-
}
|
|
6308
6294
|
if (input.type === "MAYA") {
|
|
6309
6295
|
localStorage.setItem(this.platformStorageKey, "MAYA");
|
|
6310
6296
|
const f0 = () => this.walletService.mayaSession({ id: input.sessionId });
|
|
@@ -6331,13 +6317,14 @@ var SessionManager = class {
|
|
|
6331
6317
|
})();
|
|
6332
6318
|
if (!r1.ok) return r1;
|
|
6333
6319
|
const now2 = /* @__PURE__ */ new Date();
|
|
6334
|
-
|
|
6320
|
+
cookies.set(
|
|
6335
6321
|
this.storageKey,
|
|
6336
6322
|
JSON.stringify({
|
|
6337
6323
|
...r1.data,
|
|
6338
6324
|
accessTokenExpiresAt: addMinutes(now2, 8).getTime(),
|
|
6339
6325
|
refreshTokenExpiresAt: subMinutes(addDays(now2, 30), 2).getTime()
|
|
6340
|
-
})
|
|
6326
|
+
}),
|
|
6327
|
+
{ expires: subMinutes(addDays(now2, 30), 2).getTime() }
|
|
6341
6328
|
);
|
|
6342
6329
|
return {
|
|
6343
6330
|
ok: true,
|
|
@@ -6348,13 +6335,16 @@ var SessionManager = class {
|
|
|
6348
6335
|
const res2 = await this.authService.createSession(input);
|
|
6349
6336
|
if (res2.ok) {
|
|
6350
6337
|
const now2 = /* @__PURE__ */ new Date();
|
|
6351
|
-
|
|
6338
|
+
cookies.set(
|
|
6352
6339
|
this.storageKey,
|
|
6353
6340
|
JSON.stringify({
|
|
6354
6341
|
...res2.data,
|
|
6355
6342
|
accessTokenExpiresAt: addMinutes(now2, 8).getTime(),
|
|
6356
6343
|
refreshTokenExpiresAt: subMinutes(addDays(now2, 30), 2).getTime()
|
|
6357
|
-
})
|
|
6344
|
+
}),
|
|
6345
|
+
{
|
|
6346
|
+
expires: subMinutes(addDays(now2, 30), 2).getTime()
|
|
6347
|
+
}
|
|
6358
6348
|
);
|
|
6359
6349
|
return {
|
|
6360
6350
|
ok: true,
|
|
@@ -6366,18 +6356,18 @@ var SessionManager = class {
|
|
|
6366
6356
|
if (input.type === "SOCIALS" || input.type === "TOKEN") {
|
|
6367
6357
|
const res2 = await this.authService.createSession({
|
|
6368
6358
|
type: "SOCIALS",
|
|
6369
|
-
token: input.token
|
|
6370
|
-
channel: input.channel
|
|
6359
|
+
token: input.token
|
|
6371
6360
|
});
|
|
6372
6361
|
if (res2.ok) {
|
|
6373
6362
|
const now2 = /* @__PURE__ */ new Date();
|
|
6374
|
-
|
|
6363
|
+
cookies.set(
|
|
6375
6364
|
this.storageKey,
|
|
6376
6365
|
JSON.stringify({
|
|
6377
6366
|
...res2.data,
|
|
6378
6367
|
accessTokenExpiresAt: addMinutes(now2, 8).getTime(),
|
|
6379
6368
|
refreshTokenExpiresAt: subMinutes(addDays(now2, 30), 2).getTime()
|
|
6380
|
-
})
|
|
6369
|
+
}),
|
|
6370
|
+
{ expires: subMinutes(addDays(now2, 30), 2).getTime() }
|
|
6381
6371
|
);
|
|
6382
6372
|
return {
|
|
6383
6373
|
ok: true,
|
|
@@ -6391,13 +6381,14 @@ var SessionManager = class {
|
|
|
6391
6381
|
const res2 = await this.authService.createSession(input);
|
|
6392
6382
|
if (res2.ok) {
|
|
6393
6383
|
const now2 = /* @__PURE__ */ new Date();
|
|
6394
|
-
|
|
6384
|
+
cookies.set(
|
|
6395
6385
|
this.storageKey,
|
|
6396
6386
|
JSON.stringify({
|
|
6397
6387
|
...res2.data,
|
|
6398
6388
|
accessTokenExpiresAt: addMinutes(now2, 8).getTime(),
|
|
6399
6389
|
refreshTokenExpiresAt: subMinutes(addDays(now2, 30), 2).getTime()
|
|
6400
|
-
})
|
|
6390
|
+
}),
|
|
6391
|
+
{ expires: subMinutes(addDays(now2, 30), 2).getTime() }
|
|
6401
6392
|
);
|
|
6402
6393
|
return {
|
|
6403
6394
|
ok: true,
|
|
@@ -6417,13 +6408,14 @@ var SessionManager = class {
|
|
|
6417
6408
|
};
|
|
6418
6409
|
}
|
|
6419
6410
|
const now = /* @__PURE__ */ new Date();
|
|
6420
|
-
|
|
6411
|
+
cookies.set(
|
|
6421
6412
|
this.storageKey,
|
|
6422
6413
|
JSON.stringify({
|
|
6423
6414
|
...res.data,
|
|
6424
6415
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
6425
6416
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
6426
|
-
})
|
|
6417
|
+
}),
|
|
6418
|
+
{}
|
|
6427
6419
|
);
|
|
6428
6420
|
return {
|
|
6429
6421
|
ok: true,
|
|
@@ -6435,15 +6427,18 @@ var SessionManager = class {
|
|
|
6435
6427
|
if (res.ok) {
|
|
6436
6428
|
const now = /* @__PURE__ */ new Date();
|
|
6437
6429
|
if (this.isServer) {
|
|
6438
|
-
this.logger.warn("'
|
|
6430
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
6439
6431
|
} else {
|
|
6440
|
-
|
|
6432
|
+
cookies.set(
|
|
6441
6433
|
this.storageKey,
|
|
6442
6434
|
JSON.stringify({
|
|
6443
6435
|
...res.data,
|
|
6444
6436
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
6445
6437
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
6446
|
-
})
|
|
6438
|
+
}),
|
|
6439
|
+
{
|
|
6440
|
+
expires: subMinutes(addDays(now, 30), 2).getTime()
|
|
6441
|
+
}
|
|
6447
6442
|
);
|
|
6448
6443
|
}
|
|
6449
6444
|
return { ok: true };
|
|
@@ -6453,7 +6448,7 @@ var SessionManager = class {
|
|
|
6453
6448
|
}
|
|
6454
6449
|
async get() {
|
|
6455
6450
|
if (this.isServer) {
|
|
6456
|
-
this.logger.warn("'
|
|
6451
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
6457
6452
|
return {
|
|
6458
6453
|
ok: true,
|
|
6459
6454
|
data: null
|
|
@@ -6463,7 +6458,7 @@ var SessionManager = class {
|
|
|
6463
6458
|
await sleep(1e3);
|
|
6464
6459
|
return await this.get();
|
|
6465
6460
|
}
|
|
6466
|
-
const val =
|
|
6461
|
+
const val = cookies.get(this.storageKey);
|
|
6467
6462
|
if (!val) {
|
|
6468
6463
|
return {
|
|
6469
6464
|
ok: true,
|
|
@@ -6477,7 +6472,7 @@ var SessionManager = class {
|
|
|
6477
6472
|
const refreshTokenExpiresAt = new Date(obj.refreshTokenExpiresAt);
|
|
6478
6473
|
if (isAfter(now, refreshTokenExpiresAt)) {
|
|
6479
6474
|
this.logger.warn("Session expired. Logging out..");
|
|
6480
|
-
|
|
6475
|
+
cookies.remove(this.storageKey);
|
|
6481
6476
|
return {
|
|
6482
6477
|
ok: false,
|
|
6483
6478
|
error: {
|
|
@@ -6494,7 +6489,7 @@ var SessionManager = class {
|
|
|
6494
6489
|
if (!res.ok) {
|
|
6495
6490
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
6496
6491
|
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
6497
|
-
|
|
6492
|
+
cookies.remove(this.storageKey);
|
|
6498
6493
|
return {
|
|
6499
6494
|
ok: false,
|
|
6500
6495
|
error: res.error
|
|
@@ -6515,7 +6510,9 @@ var SessionManager = class {
|
|
|
6515
6510
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
6516
6511
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
6517
6512
|
};
|
|
6518
|
-
|
|
6513
|
+
cookies.set(this.storageKey, JSON.stringify(obj), {
|
|
6514
|
+
expires: subMinutes(addDays(now, 30), 2).getTime()
|
|
6515
|
+
});
|
|
6519
6516
|
}
|
|
6520
6517
|
return {
|
|
6521
6518
|
ok: true,
|
|
@@ -6533,13 +6530,13 @@ var SessionManager = class {
|
|
|
6533
6530
|
}
|
|
6534
6531
|
async refresh() {
|
|
6535
6532
|
if (this.isServer) {
|
|
6536
|
-
this.logger.warn("'
|
|
6533
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
6537
6534
|
return {
|
|
6538
6535
|
ok: true,
|
|
6539
6536
|
data: null
|
|
6540
6537
|
};
|
|
6541
6538
|
}
|
|
6542
|
-
const val =
|
|
6539
|
+
const val = cookies.get(this.storageKey);
|
|
6543
6540
|
if (!val) {
|
|
6544
6541
|
return {
|
|
6545
6542
|
ok: true,
|
|
@@ -6556,7 +6553,7 @@ var SessionManager = class {
|
|
|
6556
6553
|
if (!res.ok) {
|
|
6557
6554
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
6558
6555
|
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
6559
|
-
|
|
6556
|
+
cookies.remove(this.storageKey);
|
|
6560
6557
|
return {
|
|
6561
6558
|
ok: false,
|
|
6562
6559
|
error: res.error
|
|
@@ -6577,7 +6574,9 @@ var SessionManager = class {
|
|
|
6577
6574
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
6578
6575
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
6579
6576
|
};
|
|
6580
|
-
|
|
6577
|
+
cookies.set(this.storageKey, JSON.stringify(obj), {
|
|
6578
|
+
expires: subMinutes(addDays(now, 30), 2).getTime()
|
|
6579
|
+
});
|
|
6581
6580
|
return {
|
|
6582
6581
|
ok: true,
|
|
6583
6582
|
data: obj
|
|
@@ -6594,18 +6593,18 @@ var SessionManager = class {
|
|
|
6594
6593
|
}
|
|
6595
6594
|
async destroy() {
|
|
6596
6595
|
if (this.isServer) {
|
|
6597
|
-
this.logger.warn("'
|
|
6596
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
6598
6597
|
return;
|
|
6599
6598
|
}
|
|
6600
6599
|
const res = await this.get();
|
|
6601
6600
|
if (res.data?.accessToken) {
|
|
6602
6601
|
await this.authService.destroySession(res.data.accessToken);
|
|
6603
6602
|
}
|
|
6604
|
-
|
|
6603
|
+
cookies.remove(this.storageKey);
|
|
6605
6604
|
}
|
|
6606
6605
|
async verify() {
|
|
6607
6606
|
if (this.isServer) {
|
|
6608
|
-
this.logger.warn("'
|
|
6607
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
6609
6608
|
return true;
|
|
6610
6609
|
}
|
|
6611
6610
|
const s = await this.get();
|
|
@@ -6615,13 +6614,13 @@ var SessionManager = class {
|
|
|
6615
6614
|
if (!s.data) return true;
|
|
6616
6615
|
const v = await this.authService.verifySession(s.data.accessToken);
|
|
6617
6616
|
if (!v) {
|
|
6618
|
-
|
|
6617
|
+
cookies.remove(this.storageKey);
|
|
6619
6618
|
}
|
|
6620
6619
|
return v;
|
|
6621
6620
|
}
|
|
6622
6621
|
get onMaya() {
|
|
6623
6622
|
if (this.isServer) {
|
|
6624
|
-
this.logger.warn("'
|
|
6623
|
+
this.logger.warn("'client cookies' is not available on the server.");
|
|
6625
6624
|
return false;
|
|
6626
6625
|
}
|
|
6627
6626
|
return localStorage.getItem(this.platformStorageKey) === "MAYA";
|
|
@@ -6637,7 +6636,9 @@ var SessionManager = class {
|
|
|
6637
6636
|
return typeof window === "undefined";
|
|
6638
6637
|
}
|
|
6639
6638
|
};
|
|
6640
|
-
|
|
6639
|
+
|
|
6640
|
+
// src/sdk/session-manager.ts
|
|
6641
|
+
var SessionManager = class {
|
|
6641
6642
|
logger;
|
|
6642
6643
|
storageKey = "session";
|
|
6643
6644
|
platformStorageKey = "session/platform";
|
|
@@ -6648,6 +6649,10 @@ var SessionManagerCookie = class {
|
|
|
6648
6649
|
this.authService = config.authService;
|
|
6649
6650
|
this.walletService = config.walletService;
|
|
6650
6651
|
this.logger = config.logger;
|
|
6652
|
+
if (config.sessionPrefix) {
|
|
6653
|
+
this.storageKey = `${config.sessionPrefix}/${this.storageKey}`;
|
|
6654
|
+
this.platformStorageKey = `${config.sessionPrefix}/${this.platformStorageKey}`;
|
|
6655
|
+
}
|
|
6651
6656
|
}
|
|
6652
6657
|
get refreshing() {
|
|
6653
6658
|
return this._refreshing;
|
|
@@ -6656,6 +6661,16 @@ var SessionManagerCookie = class {
|
|
|
6656
6661
|
this._refreshing = value;
|
|
6657
6662
|
}
|
|
6658
6663
|
async create(input) {
|
|
6664
|
+
if (this.isServer) {
|
|
6665
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
6666
|
+
return {
|
|
6667
|
+
ok: false,
|
|
6668
|
+
error: {
|
|
6669
|
+
name: "UnknownError",
|
|
6670
|
+
message: "Server sign in is not supported."
|
|
6671
|
+
}
|
|
6672
|
+
};
|
|
6673
|
+
}
|
|
6659
6674
|
if (input.type === "MAYA") {
|
|
6660
6675
|
localStorage.setItem(this.platformStorageKey, "MAYA");
|
|
6661
6676
|
const f0 = () => this.walletService.mayaSession({ id: input.sessionId });
|
|
@@ -6682,14 +6697,13 @@ var SessionManagerCookie = class {
|
|
|
6682
6697
|
})();
|
|
6683
6698
|
if (!r1.ok) return r1;
|
|
6684
6699
|
const now2 = /* @__PURE__ */ new Date();
|
|
6685
|
-
|
|
6700
|
+
localStorage.setItem(
|
|
6686
6701
|
this.storageKey,
|
|
6687
6702
|
JSON.stringify({
|
|
6688
6703
|
...r1.data,
|
|
6689
6704
|
accessTokenExpiresAt: addMinutes(now2, 8).getTime(),
|
|
6690
6705
|
refreshTokenExpiresAt: subMinutes(addDays(now2, 30), 2).getTime()
|
|
6691
|
-
})
|
|
6692
|
-
{ expires: subMinutes(addDays(now2, 30), 2).getTime() }
|
|
6706
|
+
})
|
|
6693
6707
|
);
|
|
6694
6708
|
return {
|
|
6695
6709
|
ok: true,
|
|
@@ -6700,16 +6714,13 @@ var SessionManagerCookie = class {
|
|
|
6700
6714
|
const res2 = await this.authService.createSession(input);
|
|
6701
6715
|
if (res2.ok) {
|
|
6702
6716
|
const now2 = /* @__PURE__ */ new Date();
|
|
6703
|
-
|
|
6717
|
+
localStorage.setItem(
|
|
6704
6718
|
this.storageKey,
|
|
6705
6719
|
JSON.stringify({
|
|
6706
6720
|
...res2.data,
|
|
6707
6721
|
accessTokenExpiresAt: addMinutes(now2, 8).getTime(),
|
|
6708
6722
|
refreshTokenExpiresAt: subMinutes(addDays(now2, 30), 2).getTime()
|
|
6709
|
-
})
|
|
6710
|
-
{
|
|
6711
|
-
expires: subMinutes(addDays(now2, 30), 2).getTime()
|
|
6712
|
-
}
|
|
6723
|
+
})
|
|
6713
6724
|
);
|
|
6714
6725
|
return {
|
|
6715
6726
|
ok: true,
|
|
@@ -6721,18 +6732,18 @@ var SessionManagerCookie = class {
|
|
|
6721
6732
|
if (input.type === "SOCIALS" || input.type === "TOKEN") {
|
|
6722
6733
|
const res2 = await this.authService.createSession({
|
|
6723
6734
|
type: "SOCIALS",
|
|
6724
|
-
token: input.token
|
|
6735
|
+
token: input.token,
|
|
6736
|
+
channel: input.channel
|
|
6725
6737
|
});
|
|
6726
6738
|
if (res2.ok) {
|
|
6727
6739
|
const now2 = /* @__PURE__ */ new Date();
|
|
6728
|
-
|
|
6740
|
+
localStorage.setItem(
|
|
6729
6741
|
this.storageKey,
|
|
6730
6742
|
JSON.stringify({
|
|
6731
6743
|
...res2.data,
|
|
6732
6744
|
accessTokenExpiresAt: addMinutes(now2, 8).getTime(),
|
|
6733
6745
|
refreshTokenExpiresAt: subMinutes(addDays(now2, 30), 2).getTime()
|
|
6734
|
-
})
|
|
6735
|
-
{ expires: subMinutes(addDays(now2, 30), 2).getTime() }
|
|
6746
|
+
})
|
|
6736
6747
|
);
|
|
6737
6748
|
return {
|
|
6738
6749
|
ok: true,
|
|
@@ -6746,14 +6757,13 @@ var SessionManagerCookie = class {
|
|
|
6746
6757
|
const res2 = await this.authService.createSession(input);
|
|
6747
6758
|
if (res2.ok) {
|
|
6748
6759
|
const now2 = /* @__PURE__ */ new Date();
|
|
6749
|
-
|
|
6760
|
+
localStorage.setItem(
|
|
6750
6761
|
this.storageKey,
|
|
6751
6762
|
JSON.stringify({
|
|
6752
6763
|
...res2.data,
|
|
6753
6764
|
accessTokenExpiresAt: addMinutes(now2, 8).getTime(),
|
|
6754
6765
|
refreshTokenExpiresAt: subMinutes(addDays(now2, 30), 2).getTime()
|
|
6755
|
-
})
|
|
6756
|
-
{ expires: subMinutes(addDays(now2, 30), 2).getTime() }
|
|
6766
|
+
})
|
|
6757
6767
|
);
|
|
6758
6768
|
return {
|
|
6759
6769
|
ok: true,
|
|
@@ -6773,14 +6783,13 @@ var SessionManagerCookie = class {
|
|
|
6773
6783
|
};
|
|
6774
6784
|
}
|
|
6775
6785
|
const now = /* @__PURE__ */ new Date();
|
|
6776
|
-
|
|
6786
|
+
localStorage.setItem(
|
|
6777
6787
|
this.storageKey,
|
|
6778
6788
|
JSON.stringify({
|
|
6779
6789
|
...res.data,
|
|
6780
6790
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
6781
6791
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
6782
|
-
})
|
|
6783
|
-
{}
|
|
6792
|
+
})
|
|
6784
6793
|
);
|
|
6785
6794
|
return {
|
|
6786
6795
|
ok: true,
|
|
@@ -6792,18 +6801,15 @@ var SessionManagerCookie = class {
|
|
|
6792
6801
|
if (res.ok) {
|
|
6793
6802
|
const now = /* @__PURE__ */ new Date();
|
|
6794
6803
|
if (this.isServer) {
|
|
6795
|
-
this.logger.warn("'
|
|
6804
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
6796
6805
|
} else {
|
|
6797
|
-
|
|
6806
|
+
localStorage.setItem(
|
|
6798
6807
|
this.storageKey,
|
|
6799
6808
|
JSON.stringify({
|
|
6800
6809
|
...res.data,
|
|
6801
6810
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
6802
6811
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
6803
|
-
})
|
|
6804
|
-
{
|
|
6805
|
-
expires: subMinutes(addDays(now, 30), 2).getTime()
|
|
6806
|
-
}
|
|
6812
|
+
})
|
|
6807
6813
|
);
|
|
6808
6814
|
}
|
|
6809
6815
|
return { ok: true };
|
|
@@ -6813,7 +6819,7 @@ var SessionManagerCookie = class {
|
|
|
6813
6819
|
}
|
|
6814
6820
|
async get() {
|
|
6815
6821
|
if (this.isServer) {
|
|
6816
|
-
this.logger.warn("'
|
|
6822
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
6817
6823
|
return {
|
|
6818
6824
|
ok: true,
|
|
6819
6825
|
data: null
|
|
@@ -6823,7 +6829,7 @@ var SessionManagerCookie = class {
|
|
|
6823
6829
|
await sleep(1e3);
|
|
6824
6830
|
return await this.get();
|
|
6825
6831
|
}
|
|
6826
|
-
const val =
|
|
6832
|
+
const val = localStorage.getItem(this.storageKey);
|
|
6827
6833
|
if (!val) {
|
|
6828
6834
|
return {
|
|
6829
6835
|
ok: true,
|
|
@@ -6837,7 +6843,7 @@ var SessionManagerCookie = class {
|
|
|
6837
6843
|
const refreshTokenExpiresAt = new Date(obj.refreshTokenExpiresAt);
|
|
6838
6844
|
if (isAfter(now, refreshTokenExpiresAt)) {
|
|
6839
6845
|
this.logger.warn("Session expired. Logging out..");
|
|
6840
|
-
|
|
6846
|
+
localStorage.removeItem(this.storageKey);
|
|
6841
6847
|
return {
|
|
6842
6848
|
ok: false,
|
|
6843
6849
|
error: {
|
|
@@ -6854,7 +6860,7 @@ var SessionManagerCookie = class {
|
|
|
6854
6860
|
if (!res.ok) {
|
|
6855
6861
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
6856
6862
|
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
6857
|
-
|
|
6863
|
+
localStorage.removeItem(this.storageKey);
|
|
6858
6864
|
return {
|
|
6859
6865
|
ok: false,
|
|
6860
6866
|
error: res.error
|
|
@@ -6875,9 +6881,7 @@ var SessionManagerCookie = class {
|
|
|
6875
6881
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
6876
6882
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
6877
6883
|
};
|
|
6878
|
-
|
|
6879
|
-
expires: subMinutes(addDays(now, 30), 2).getTime()
|
|
6880
|
-
});
|
|
6884
|
+
localStorage.setItem(this.storageKey, JSON.stringify(obj));
|
|
6881
6885
|
}
|
|
6882
6886
|
return {
|
|
6883
6887
|
ok: true,
|
|
@@ -6895,13 +6899,13 @@ var SessionManagerCookie = class {
|
|
|
6895
6899
|
}
|
|
6896
6900
|
async refresh() {
|
|
6897
6901
|
if (this.isServer) {
|
|
6898
|
-
this.logger.warn("'
|
|
6902
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
6899
6903
|
return {
|
|
6900
6904
|
ok: true,
|
|
6901
6905
|
data: null
|
|
6902
6906
|
};
|
|
6903
6907
|
}
|
|
6904
|
-
const val =
|
|
6908
|
+
const val = localStorage.getItem(this.storageKey);
|
|
6905
6909
|
if (!val) {
|
|
6906
6910
|
return {
|
|
6907
6911
|
ok: true,
|
|
@@ -6918,7 +6922,7 @@ var SessionManagerCookie = class {
|
|
|
6918
6922
|
if (!res.ok) {
|
|
6919
6923
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
6920
6924
|
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
6921
|
-
|
|
6925
|
+
localStorage.removeItem(this.storageKey);
|
|
6922
6926
|
return {
|
|
6923
6927
|
ok: false,
|
|
6924
6928
|
error: res.error
|
|
@@ -6939,9 +6943,7 @@ var SessionManagerCookie = class {
|
|
|
6939
6943
|
accessTokenExpiresAt: addMinutes(now, 8).getTime(),
|
|
6940
6944
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
6941
6945
|
};
|
|
6942
|
-
|
|
6943
|
-
expires: subMinutes(addDays(now, 30), 2).getTime()
|
|
6944
|
-
});
|
|
6946
|
+
localStorage.setItem(this.storageKey, JSON.stringify(obj));
|
|
6945
6947
|
return {
|
|
6946
6948
|
ok: true,
|
|
6947
6949
|
data: obj
|
|
@@ -6958,18 +6960,18 @@ var SessionManagerCookie = class {
|
|
|
6958
6960
|
}
|
|
6959
6961
|
async destroy() {
|
|
6960
6962
|
if (this.isServer) {
|
|
6961
|
-
this.logger.warn("'
|
|
6963
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
6962
6964
|
return;
|
|
6963
6965
|
}
|
|
6964
6966
|
const res = await this.get();
|
|
6965
6967
|
if (res.data?.accessToken) {
|
|
6966
6968
|
await this.authService.destroySession(res.data.accessToken);
|
|
6967
6969
|
}
|
|
6968
|
-
|
|
6970
|
+
localStorage.removeItem(this.storageKey);
|
|
6969
6971
|
}
|
|
6970
6972
|
async verify() {
|
|
6971
6973
|
if (this.isServer) {
|
|
6972
|
-
this.logger.warn("'
|
|
6974
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
6973
6975
|
return true;
|
|
6974
6976
|
}
|
|
6975
6977
|
const s = await this.get();
|
|
@@ -6979,13 +6981,13 @@ var SessionManagerCookie = class {
|
|
|
6979
6981
|
if (!s.data) return true;
|
|
6980
6982
|
const v = await this.authService.verifySession(s.data.accessToken);
|
|
6981
6983
|
if (!v) {
|
|
6982
|
-
|
|
6984
|
+
localStorage.removeItem(this.storageKey);
|
|
6983
6985
|
}
|
|
6984
6986
|
return v;
|
|
6985
6987
|
}
|
|
6986
6988
|
get onMaya() {
|
|
6987
6989
|
if (this.isServer) {
|
|
6988
|
-
this.logger.warn("'
|
|
6990
|
+
this.logger.warn("'localStorage' is not available on the server.");
|
|
6989
6991
|
return false;
|
|
6990
6992
|
}
|
|
6991
6993
|
return localStorage.getItem(this.platformStorageKey) === "MAYA";
|
|
@@ -8696,7 +8698,7 @@ var Sdk = class {
|
|
|
8696
8698
|
url: cmsPortalUrl,
|
|
8697
8699
|
site,
|
|
8698
8700
|
platform: sitePlatform,
|
|
8699
|
-
fetch: this.
|
|
8701
|
+
fetch: this.getFetch()
|
|
8700
8702
|
}));
|
|
8701
8703
|
this._fetch = config.fetch ?? null;
|
|
8702
8704
|
this._middleware = config.middleware ?? ((req) => req);
|
|
@@ -8708,7 +8710,7 @@ var Sdk = class {
|
|
|
8708
8710
|
this.miscMiddleware,
|
|
8709
8711
|
this.middleware
|
|
8710
8712
|
],
|
|
8711
|
-
fetch: this.
|
|
8713
|
+
fetch: this.getFetch(),
|
|
8712
8714
|
fetchOptions: {
|
|
8713
8715
|
headers: {
|
|
8714
8716
|
Role: "MEMBER",
|
|
@@ -8788,12 +8790,27 @@ var Sdk = class {
|
|
|
8788
8790
|
}
|
|
8789
8791
|
_fetch = null;
|
|
8790
8792
|
_middleware;
|
|
8793
|
+
/**
|
|
8794
|
+
* @deprecated use `setFetch` instead
|
|
8795
|
+
*/
|
|
8791
8796
|
set fetch(value) {
|
|
8792
8797
|
this._fetch = value;
|
|
8793
8798
|
}
|
|
8799
|
+
/**
|
|
8800
|
+
* @deprecated use `getFetch` instead
|
|
8801
|
+
*/
|
|
8794
8802
|
get fetch() {
|
|
8795
8803
|
return this._fetch;
|
|
8796
8804
|
}
|
|
8805
|
+
async setFetch(value) {
|
|
8806
|
+
return new Promise((resolve) => {
|
|
8807
|
+
this._fetch = value;
|
|
8808
|
+
setTimeout(() => resolve(), 1);
|
|
8809
|
+
});
|
|
8810
|
+
}
|
|
8811
|
+
getFetch() {
|
|
8812
|
+
return this._fetch;
|
|
8813
|
+
}
|
|
8797
8814
|
set middleware(value) {
|
|
8798
8815
|
this._middleware = value;
|
|
8799
8816
|
}
|