woodsportal-client-sdk 4.0.7 → 4.0.8-dev.1
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/README.md +26 -0
- package/dist/adapters/angular/index.js +8 -6
- package/dist/adapters/angular/index.js.map +1 -1
- package/dist/adapters/native/index.d.ts +3 -0
- package/dist/adapters/native/index.js +11 -0
- package/dist/adapters/native/index.js.map +1 -0
- package/dist/adapters/react/index.d.ts +1 -1
- package/dist/adapters/react/index.js +9 -19
- package/dist/adapters/react/index.js.map +1 -1
- package/dist/adapters/vue/index.js +8 -6
- package/dist/adapters/vue/index.js.map +1 -1
- package/dist/auth-interceptor-policy-RGQ26NWR.js +6 -0
- package/dist/{auth-interceptor-policy-ACKZEQ6J.js.map → auth-interceptor-policy-RGQ26NWR.js.map} +1 -1
- package/dist/auth-utils-T4FIBK3O.js +7 -0
- package/dist/{auth-utils-CPO4LG4K.js.map → auth-utils-T4FIBK3O.js.map} +1 -1
- package/dist/{http-errors-CCCQECil.d.ts → build-error-description-XKI8vhGv.d.ts} +57 -6
- package/dist/{chunk-YZPW5F6U.js → chunk-5LISZE2R.js} +11 -7
- package/dist/chunk-5LISZE2R.js.map +1 -0
- package/dist/{chunk-BGUHACLT.js → chunk-AVMMEQLO.js} +3 -3
- package/dist/{chunk-BGUHACLT.js.map → chunk-AVMMEQLO.js.map} +1 -1
- package/dist/chunk-BXKFJ5NQ.js +1272 -0
- package/dist/chunk-BXKFJ5NQ.js.map +1 -0
- package/dist/chunk-DB6W3CJT.js +73 -0
- package/dist/chunk-DB6W3CJT.js.map +1 -0
- package/dist/{chunk-BKDJOWLW.js → chunk-ETYE73AH.js} +35 -8
- package/dist/chunk-ETYE73AH.js.map +1 -0
- package/dist/{chunk-ZQTCAG6K.js → chunk-JG3TEXWP.js} +7 -11
- package/dist/chunk-JG3TEXWP.js.map +1 -0
- package/dist/{chunk-WSUXZOHL.js → chunk-KPHAQNS2.js} +51 -6
- package/dist/chunk-KPHAQNS2.js.map +1 -0
- package/dist/{chunk-7J265W43.js → chunk-NDDE6ZZ3.js} +273 -87
- package/dist/chunk-NDDE6ZZ3.js.map +1 -0
- package/dist/{chunk-OAFDB4TJ.js → chunk-PVX6FWCW.js} +184 -104
- package/dist/chunk-PVX6FWCW.js.map +1 -0
- package/dist/{chunk-MO22VWRI.js → chunk-S3CVZTU4.js} +15 -9
- package/dist/chunk-S3CVZTU4.js.map +1 -0
- package/dist/{chunk-EFEBZBMU.js → chunk-UDAPRD7Z.js} +3 -2
- package/dist/chunk-UDAPRD7Z.js.map +1 -0
- package/dist/{chunk-TYJO2PSR.js → chunk-VN6VPM5C.js} +4 -4
- package/dist/{chunk-TYJO2PSR.js.map → chunk-VN6VPM5C.js.map} +1 -1
- package/dist/chunk-ZEGKRQA4.js +16 -0
- package/dist/chunk-ZEGKRQA4.js.map +1 -0
- package/dist/cross-tab-session-B34BLQU4.js +11 -0
- package/dist/{cross-tab-session-AGJVA2UZ.js.map → cross-tab-session-B34BLQU4.js.map} +1 -1
- package/dist/entries/auth.d.ts +4 -3
- package/dist/entries/auth.js +9 -8
- package/dist/entries/auth.js.map +1 -1
- package/dist/entries/crm.d.ts +3 -3
- package/dist/entries/crm.js +10 -9
- package/dist/entries/crm.js.map +1 -1
- package/dist/{index-Bh9eY8sA.d.ts → index-B-IGDI9L.d.ts} +11 -2
- package/dist/index.d.ts +45 -7
- package/dist/index.js +70 -17
- package/dist/index.js.map +1 -1
- package/dist/{pipeline-ui-DbEzI_v1.d.ts → pipeline-ui-COO9b3x2.d.ts} +2 -2
- package/dist/storage-migration-2PF52ZSB.js +4 -0
- package/dist/{storage-migration-CZTBKXQV.js.map → storage-migration-2PF52ZSB.js.map} +1 -1
- package/package.json +6 -1
- package/dist/auth-interceptor-policy-ACKZEQ6J.js +0 -5
- package/dist/auth-utils-CPO4LG4K.js +0 -5
- package/dist/chunk-7J265W43.js.map +0 -1
- package/dist/chunk-BKDJOWLW.js.map +0 -1
- package/dist/chunk-EFEBZBMU.js.map +0 -1
- package/dist/chunk-MO22VWRI.js.map +0 -1
- package/dist/chunk-OAFDB4TJ.js.map +0 -1
- package/dist/chunk-PK7GZY5P.js +0 -737
- package/dist/chunk-PK7GZY5P.js.map +0 -1
- package/dist/chunk-WSUXZOHL.js.map +0 -1
- package/dist/chunk-YZPW5F6U.js.map +0 -1
- package/dist/chunk-ZQTCAG6K.js.map +0 -1
- package/dist/cross-tab-session-AGJVA2UZ.js +0 -9
- package/dist/storage-migration-CZTBKXQV.js +0 -4
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { isCookieExpired, getStorageKeys, getCookie, isCorruptCookieRawValue, stringifyCookieValue, setCookie,
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { isCookieExpired, getStorageKeys, getCookie, isCorruptCookieRawValue, stringifyCookieValue, setCookie, removeCookie, parseCookieJson } from './chunk-KPHAQNS2.js';
|
|
2
|
+
import { getSessionStorageAdapter, writeSessionScopedItem, readSessionScopedItem, removeSessionScopedItem } from './chunk-DB6W3CJT.js';
|
|
3
|
+
import { WP_STORAGE_KEYS, wpClientIframeRefreshKey, wpClientIframeRefreshExpKey } from './chunk-UDAPRD7Z.js';
|
|
4
|
+
import { AuthErrorCode, parseApiErrorPayload } from './chunk-COHBSTHF.js';
|
|
5
|
+
import axios2 from 'axios';
|
|
4
6
|
|
|
5
7
|
// src/main/core/utils/constants.ts
|
|
6
8
|
WP_STORAGE_KEYS.c.auth.login;
|
|
@@ -95,7 +97,9 @@ var config = {
|
|
|
95
97
|
return readStorageField(DEV_PORTAL_ID) || getRuntimeHttpClientDevPortalId();
|
|
96
98
|
},
|
|
97
99
|
get portalId() {
|
|
98
|
-
|
|
100
|
+
const portal = readStorageField(PORTAL_ID);
|
|
101
|
+
if (portal) return portal;
|
|
102
|
+
return readStorageField(DEV_PORTAL_ID) || getRuntimeHttpClientDevPortalId();
|
|
99
103
|
},
|
|
100
104
|
get devApiUrl() {
|
|
101
105
|
return readStorageField(DEV_API_URL) || getRuntimeHttpClientDevApiUrl();
|
|
@@ -245,7 +249,7 @@ function defaultWarn(context, message, meta) {
|
|
|
245
249
|
console.warn(formatPrefix(context), message);
|
|
246
250
|
}
|
|
247
251
|
function defaultError(context, error, meta) {
|
|
248
|
-
if (
|
|
252
|
+
if (axios2.isAxiosError(error)) {
|
|
249
253
|
const payload = {
|
|
250
254
|
message: error.message,
|
|
251
255
|
status: error.response?.status,
|
|
@@ -322,68 +326,41 @@ function readExpiresAt(raw) {
|
|
|
322
326
|
const parsed = Number(raw);
|
|
323
327
|
return Number.isFinite(parsed) ? parsed : null;
|
|
324
328
|
}
|
|
325
|
-
function
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const win = globalThis.window;
|
|
334
|
-
return win?.sessionStorage ?? null;
|
|
335
|
-
} catch {
|
|
336
|
-
return null;
|
|
337
|
-
}
|
|
329
|
+
function readScoped(key) {
|
|
330
|
+
return readSessionScopedItem(key);
|
|
331
|
+
}
|
|
332
|
+
function writeScoped(key, value) {
|
|
333
|
+
writeSessionScopedItem(key, value);
|
|
334
|
+
}
|
|
335
|
+
function removeScoped(key) {
|
|
336
|
+
removeSessionScopedItem(key);
|
|
338
337
|
}
|
|
339
338
|
function storeMfaPendingAccessToken(token, expiresInSeconds, lane = "c") {
|
|
340
|
-
const storage2 = getSessionStorage();
|
|
341
|
-
if (!storage2) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
339
|
if (!token || typeof token !== "string") {
|
|
345
340
|
return;
|
|
346
341
|
}
|
|
347
342
|
const keys = keysForLane(lane);
|
|
348
343
|
const expiresAt = typeof expiresInSeconds === "number" && expiresInSeconds > 0 ? Date.now() + expiresInSeconds * 1e3 : Date.now() + 15 * 60 * 1e3;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
storage2.setItem(keys.exp, String(expiresAt));
|
|
352
|
-
} catch {
|
|
353
|
-
}
|
|
344
|
+
writeScoped(keys.token, token);
|
|
345
|
+
writeScoped(keys.exp, String(expiresAt));
|
|
354
346
|
}
|
|
355
347
|
function readMfaPendingAccessToken(lane = "c") {
|
|
356
|
-
const
|
|
357
|
-
|
|
348
|
+
const keys = keysForLane(lane);
|
|
349
|
+
const token = readScoped(keys.token);
|
|
350
|
+
if (!token) {
|
|
358
351
|
return null;
|
|
359
352
|
}
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (!token) {
|
|
364
|
-
return null;
|
|
365
|
-
}
|
|
366
|
-
const expiresAt = readExpiresAt(storage2.getItem(keys.exp));
|
|
367
|
-
if (expiresAt == null || Date.now() >= expiresAt) {
|
|
368
|
-
clearMfaPendingAccessToken(lane);
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
return { token, expiresAt };
|
|
372
|
-
} catch {
|
|
353
|
+
const expiresAt = readExpiresAt(readScoped(keys.exp));
|
|
354
|
+
if (expiresAt == null || Date.now() >= expiresAt) {
|
|
355
|
+
clearMfaPendingAccessToken(lane);
|
|
373
356
|
return null;
|
|
374
357
|
}
|
|
358
|
+
return { token, expiresAt };
|
|
375
359
|
}
|
|
376
360
|
function clearMfaPendingAccessToken(lane = "c") {
|
|
377
|
-
const storage2 = getSessionStorage();
|
|
378
|
-
if (!storage2) {
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
361
|
const keys = keysForLane(lane);
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
storage2.removeItem(keys.exp);
|
|
385
|
-
} catch {
|
|
386
|
-
}
|
|
362
|
+
removeScoped(keys.token);
|
|
363
|
+
removeScoped(keys.exp);
|
|
387
364
|
}
|
|
388
365
|
function isMfaPendingAccessSession(lane = "c") {
|
|
389
366
|
return readMfaPendingAccessToken(lane) != null;
|
|
@@ -456,6 +433,118 @@ async function withRefreshLock(fn) {
|
|
|
456
433
|
}
|
|
457
434
|
});
|
|
458
435
|
}
|
|
436
|
+
var SERVICE_UNAVAILABLE_MESSAGE = "Service temporarily unavailable. Please try again in a few minutes.";
|
|
437
|
+
var SERVICE_UNAVAILABLE_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
438
|
+
function classifyHttpError(error) {
|
|
439
|
+
if (!axios2.isAxiosError(error)) {
|
|
440
|
+
return "unknown";
|
|
441
|
+
}
|
|
442
|
+
const status = error.response?.status;
|
|
443
|
+
if (status != null) {
|
|
444
|
+
if (SERVICE_UNAVAILABLE_STATUSES.has(status)) return "service_unavailable";
|
|
445
|
+
if (status === 401 || status === 403) return "auth";
|
|
446
|
+
if (status >= 400 && status < 500) return "client";
|
|
447
|
+
if (status >= 500) return "server";
|
|
448
|
+
}
|
|
449
|
+
if (error.code === "ECONNABORTED" || error.message.toLowerCase().includes("timeout")) {
|
|
450
|
+
return "timeout";
|
|
451
|
+
}
|
|
452
|
+
if (error.code === "ERR_NETWORK" || error.message === "Network Error") {
|
|
453
|
+
return "service_unavailable";
|
|
454
|
+
}
|
|
455
|
+
return "network";
|
|
456
|
+
}
|
|
457
|
+
function isServiceUnavailableError(error) {
|
|
458
|
+
return classifyHttpError(error) === "service_unavailable";
|
|
459
|
+
}
|
|
460
|
+
function getHttpErrorMessage(error) {
|
|
461
|
+
const kind = classifyHttpError(error);
|
|
462
|
+
switch (kind) {
|
|
463
|
+
case "service_unavailable":
|
|
464
|
+
return SERVICE_UNAVAILABLE_MESSAGE;
|
|
465
|
+
case "timeout":
|
|
466
|
+
return "The request timed out. Please check your connection and try again.";
|
|
467
|
+
case "auth":
|
|
468
|
+
return "Your session has expired. Please sign in again.";
|
|
469
|
+
case "network":
|
|
470
|
+
return "Unable to reach the server. Please check your connection and try again.";
|
|
471
|
+
case "client":
|
|
472
|
+
case "server":
|
|
473
|
+
case "unknown": {
|
|
474
|
+
if (axios2.isAxiosError(error)) {
|
|
475
|
+
const payload = error.response?.data;
|
|
476
|
+
const apiMessage = payload?.errorMessage ?? payload?.message;
|
|
477
|
+
if (typeof apiMessage === "string" && apiMessage.trim() !== "") {
|
|
478
|
+
return apiMessage;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return "Something went wrong. Please try again.";
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// src/main/core/http/refresh-failure-policy.ts
|
|
487
|
+
var DEFINITIVE_REFRESH_AUTH_CODES = /* @__PURE__ */ new Set([
|
|
488
|
+
AuthErrorCode.TOKEN_INVALID,
|
|
489
|
+
AuthErrorCode.TOKEN_EXPIRED,
|
|
490
|
+
AuthErrorCode.MISSING_REFRESH_TOKEN,
|
|
491
|
+
AuthErrorCode.AUTHENTICATION_FAILED,
|
|
492
|
+
AuthErrorCode.INVALID_CREDENTIALS,
|
|
493
|
+
AuthErrorCode.ACCOUNT_LOCKED,
|
|
494
|
+
AuthErrorCode.ACCOUNT_DISABLED
|
|
495
|
+
]);
|
|
496
|
+
function isDefinitiveRefreshAuthError(errorCode, status) {
|
|
497
|
+
const code = (errorCode ?? "").trim().toUpperCase();
|
|
498
|
+
if (code && DEFINITIVE_REFRESH_AUTH_CODES.has(code)) {
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
if (status === 401 && !code) {
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
function classifyRefreshHttpError(error) {
|
|
507
|
+
if (!axios2.isAxiosError(error)) {
|
|
508
|
+
return "transient";
|
|
509
|
+
}
|
|
510
|
+
const status = error.response?.status;
|
|
511
|
+
const payload = parseApiErrorPayload(error.response?.data);
|
|
512
|
+
if (status === 429) {
|
|
513
|
+
return "transient";
|
|
514
|
+
}
|
|
515
|
+
if (status != null && status >= 500) {
|
|
516
|
+
return "transient";
|
|
517
|
+
}
|
|
518
|
+
const httpKind = classifyHttpError(error);
|
|
519
|
+
if (httpKind === "network" || httpKind === "timeout" || httpKind === "service_unavailable") {
|
|
520
|
+
return "transient";
|
|
521
|
+
}
|
|
522
|
+
if (status === 401 || status === 403) {
|
|
523
|
+
if (isDefinitiveRefreshAuthError(payload.errorCode, status)) {
|
|
524
|
+
return "auth_invalid";
|
|
525
|
+
}
|
|
526
|
+
return "transient";
|
|
527
|
+
}
|
|
528
|
+
return "transient";
|
|
529
|
+
}
|
|
530
|
+
function classifyRefreshResponseWithoutToken(response) {
|
|
531
|
+
if (!response || typeof response !== "object") {
|
|
532
|
+
return "transient";
|
|
533
|
+
}
|
|
534
|
+
const record = response;
|
|
535
|
+
const status = record.status;
|
|
536
|
+
const payload = parseApiErrorPayload(record.data);
|
|
537
|
+
if (isDefinitiveRefreshAuthError(payload.errorCode, status)) {
|
|
538
|
+
return "auth_invalid";
|
|
539
|
+
}
|
|
540
|
+
return "transient";
|
|
541
|
+
}
|
|
542
|
+
function isTransientRefreshFailure(kind) {
|
|
543
|
+
return kind === "transient" || kind === "missing_context";
|
|
544
|
+
}
|
|
545
|
+
function shouldLogoutAfterRefreshFailure(kind) {
|
|
546
|
+
return kind === "auth_invalid" || kind === "missing_refresh_token";
|
|
547
|
+
}
|
|
459
548
|
|
|
460
549
|
// src/main/core/http/token-store.ts
|
|
461
550
|
var accessToken = null;
|
|
@@ -469,6 +558,13 @@ var lastSuccessfulRefreshAt = null;
|
|
|
469
558
|
var sessionLifecycleListener = null;
|
|
470
559
|
var MIN_SHORT_TTL_BUFFER_MS = 5e3;
|
|
471
560
|
var MIN_PROACTIVE_REFRESH_INTERVAL_MS = 3e4;
|
|
561
|
+
var REFRESH_RETRY_BACKOFF_MS = [0, 500, 1500];
|
|
562
|
+
var REFRESH_MAX_ATTEMPTS = 3;
|
|
563
|
+
function delay(ms) {
|
|
564
|
+
return new Promise((resolve) => {
|
|
565
|
+
setTimeout(resolve, ms);
|
|
566
|
+
});
|
|
567
|
+
}
|
|
472
568
|
function getEffectiveBufferMs(ttlMs) {
|
|
473
569
|
const capMs = refreshBufferSeconds * 1e3;
|
|
474
570
|
let buffer;
|
|
@@ -499,29 +595,20 @@ function notifySessionLifecycleChange() {
|
|
|
499
595
|
}
|
|
500
596
|
}
|
|
501
597
|
function persistRefreshExhausted() {
|
|
502
|
-
if (typeof window === "undefined" || !window.sessionStorage) {
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
598
|
try {
|
|
506
|
-
|
|
599
|
+
writeSessionScopedItem(WP_STORAGE_KEYS.c.auth.refreshExhausted, JSON.stringify({ ts: Date.now() }));
|
|
507
600
|
} catch {
|
|
508
601
|
}
|
|
509
602
|
}
|
|
510
603
|
function clearPersistedRefreshExhausted() {
|
|
511
|
-
if (typeof window === "undefined" || !window.sessionStorage) {
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
604
|
try {
|
|
515
|
-
|
|
605
|
+
removeSessionScopedItem(WP_STORAGE_KEYS.c.auth.refreshExhausted);
|
|
516
606
|
} catch {
|
|
517
607
|
}
|
|
518
608
|
}
|
|
519
609
|
function readPersistedRefreshExhausted() {
|
|
520
|
-
if (typeof window === "undefined" || !window.sessionStorage) {
|
|
521
|
-
return false;
|
|
522
|
-
}
|
|
523
610
|
try {
|
|
524
|
-
return Boolean(
|
|
611
|
+
return Boolean(readSessionScopedItem(WP_STORAGE_KEYS.c.auth.refreshExhausted));
|
|
525
612
|
} catch {
|
|
526
613
|
return false;
|
|
527
614
|
}
|
|
@@ -604,7 +691,7 @@ async function refreshSession(options = {}) {
|
|
|
604
691
|
if (!refreshPromise) {
|
|
605
692
|
refreshPromise = (async () => {
|
|
606
693
|
await withRefreshLock(async () => {
|
|
607
|
-
const { getRefreshToken: getRefreshToken2 } = await import('./auth-utils-
|
|
694
|
+
const { getRefreshToken: getRefreshToken2 } = await import('./auth-utils-T4FIBK3O.js');
|
|
608
695
|
const refreshToken = getRefreshToken2();
|
|
609
696
|
if (!refreshToken) {
|
|
610
697
|
markRefreshFailed();
|
|
@@ -618,13 +705,27 @@ async function refreshSession(options = {}) {
|
|
|
618
705
|
});
|
|
619
706
|
throw new Error("Session expired: missing refresh token");
|
|
620
707
|
}
|
|
621
|
-
|
|
622
|
-
|
|
708
|
+
let lastFailureKind;
|
|
709
|
+
for (let attempt = 0; attempt < REFRESH_MAX_ATTEMPTS; attempt += 1) {
|
|
710
|
+
if (attempt > 0) {
|
|
711
|
+
await delay(REFRESH_RETRY_BACKOFF_MS[attempt] ?? REFRESH_RETRY_BACKOFF_MS.at(-1));
|
|
712
|
+
}
|
|
713
|
+
const result = await refreshCallback(refreshToken);
|
|
714
|
+
if (result.success && result.token) {
|
|
715
|
+
lastRefreshFailed = false;
|
|
716
|
+
lastSuccessfulRefreshAt = Date.now();
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
lastFailureKind = result.failureKind;
|
|
720
|
+
if (!isTransientRefreshFailure(result.failureKind)) {
|
|
721
|
+
break;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (shouldLogoutAfterRefreshFailure(lastFailureKind)) {
|
|
623
725
|
markRefreshFailed();
|
|
624
726
|
throw new Error("Session refresh failed");
|
|
625
727
|
}
|
|
626
|
-
|
|
627
|
-
lastSuccessfulRefreshAt = Date.now();
|
|
728
|
+
throw new Error("Session refresh deferred");
|
|
628
729
|
});
|
|
629
730
|
})().finally(() => {
|
|
630
731
|
refreshPromise = null;
|
|
@@ -636,6 +737,9 @@ async function ensureValidRefresh() {
|
|
|
636
737
|
if (isMfaPendingAccessSession("c") || isMfaPendingAccessSession("a")) {
|
|
637
738
|
return;
|
|
638
739
|
}
|
|
740
|
+
if (!getAccessToken() && !hasRefreshSession()) {
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
639
743
|
if (!isExpiresAccessToken()) {
|
|
640
744
|
return;
|
|
641
745
|
}
|
|
@@ -649,6 +753,12 @@ function isAuthenticateApp() {
|
|
|
649
753
|
return true;
|
|
650
754
|
}
|
|
651
755
|
}
|
|
756
|
+
if (getSessionStorageAdapter()) {
|
|
757
|
+
if (hasRefreshSession()) {
|
|
758
|
+
return true;
|
|
759
|
+
}
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
652
762
|
if (!isCookieExpired(getStorageKeys().refreshToken)) {
|
|
653
763
|
if (lastRefreshFailed && !token) {
|
|
654
764
|
return false;
|
|
@@ -667,12 +777,19 @@ function hasRefreshSession() {
|
|
|
667
777
|
if (isSessionRefreshExhausted() && !accessToken) {
|
|
668
778
|
return false;
|
|
669
779
|
}
|
|
670
|
-
const
|
|
671
|
-
if (
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
780
|
+
const adapter = getSessionStorageAdapter();
|
|
781
|
+
if (adapter) {
|
|
782
|
+
if (!adapter.getRefreshToken()) {
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
} else {
|
|
786
|
+
const refreshKey = getStorageKeys().refreshToken;
|
|
787
|
+
if (!refreshKey || isCookieExpired(refreshKey)) {
|
|
788
|
+
return false;
|
|
789
|
+
}
|
|
790
|
+
if (!readRefreshTokenValue()) {
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
676
793
|
}
|
|
677
794
|
if (lastRefreshFailed && !accessToken) {
|
|
678
795
|
return false;
|
|
@@ -680,6 +797,10 @@ function hasRefreshSession() {
|
|
|
680
797
|
return true;
|
|
681
798
|
}
|
|
682
799
|
function readRefreshTokenValue() {
|
|
800
|
+
const adapter = getSessionStorageAdapter();
|
|
801
|
+
if (adapter) {
|
|
802
|
+
return adapter.getRefreshToken();
|
|
803
|
+
}
|
|
683
804
|
const key = getStorageKeys().refreshToken;
|
|
684
805
|
const raw = getCookie(key);
|
|
685
806
|
if (!isCorruptCookieRawValue(raw)) {
|
|
@@ -695,6 +816,27 @@ function hasValidAccessToken() {
|
|
|
695
816
|
}
|
|
696
817
|
|
|
697
818
|
// src/main/core/http/auth-utils.ts
|
|
819
|
+
function readStoredJson(key) {
|
|
820
|
+
if (key == null || key === "") {
|
|
821
|
+
return null;
|
|
822
|
+
}
|
|
823
|
+
const adapter = getSessionStorageAdapter();
|
|
824
|
+
if (adapter) {
|
|
825
|
+
const raw = adapter.getItem(key);
|
|
826
|
+
if (isCorruptCookieRawValue(raw)) {
|
|
827
|
+
if (raw === "undefined" || raw === "null") {
|
|
828
|
+
adapter.removeItem(key);
|
|
829
|
+
}
|
|
830
|
+
return null;
|
|
831
|
+
}
|
|
832
|
+
try {
|
|
833
|
+
return JSON.parse(raw);
|
|
834
|
+
} catch {
|
|
835
|
+
return raw;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
return parseCookieJson(key);
|
|
839
|
+
}
|
|
698
840
|
function writeJsonCookie(key, data, expire) {
|
|
699
841
|
if (!key) {
|
|
700
842
|
return;
|
|
@@ -703,6 +845,11 @@ function writeJsonCookie(key, data, expire) {
|
|
|
703
845
|
if (serialized == null) {
|
|
704
846
|
return;
|
|
705
847
|
}
|
|
848
|
+
const adapter = getSessionStorageAdapter();
|
|
849
|
+
if (adapter) {
|
|
850
|
+
adapter.setItem(key, serialized);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
706
853
|
setCookie(key, serialized, expire);
|
|
707
854
|
}
|
|
708
855
|
var setLoggedInDetails = async (data) => {
|
|
@@ -721,19 +868,27 @@ var setProfileDetails = async (data) => {
|
|
|
721
868
|
resolve();
|
|
722
869
|
});
|
|
723
870
|
};
|
|
871
|
+
function resolveRefreshExpiryMs(expiresAt) {
|
|
872
|
+
if (typeof expiresAt === "number" && expiresAt > 1e12) {
|
|
873
|
+
return expiresAt;
|
|
874
|
+
}
|
|
875
|
+
if (typeof expiresAt === "number" && expiresAt > 1e9) {
|
|
876
|
+
return expiresAt * 1e3;
|
|
877
|
+
}
|
|
878
|
+
return Date.now() + (expiresAt || 0) * 1e3;
|
|
879
|
+
}
|
|
724
880
|
function setRefreshToken(token, expiresAt) {
|
|
725
881
|
return new Promise((resolve) => {
|
|
726
882
|
if (!token || typeof token !== "string") {
|
|
727
883
|
resolve();
|
|
728
884
|
return;
|
|
729
885
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
expiresMs = Date.now() + (expiresAt || 0) * 1e3;
|
|
886
|
+
const expiresMs = resolveRefreshExpiryMs(expiresAt);
|
|
887
|
+
const adapter = getSessionStorageAdapter();
|
|
888
|
+
if (adapter) {
|
|
889
|
+
adapter.setRefreshToken(token, expiresMs);
|
|
890
|
+
resolve();
|
|
891
|
+
return;
|
|
737
892
|
}
|
|
738
893
|
const serialized = stringifyCookieValue(token);
|
|
739
894
|
if (serialized != null) {
|
|
@@ -764,9 +919,13 @@ var setSubscriptionType = async (data) => {
|
|
|
764
919
|
});
|
|
765
920
|
};
|
|
766
921
|
function getProfile() {
|
|
767
|
-
return
|
|
922
|
+
return readStoredJson(getStorageKeys().loginDetails);
|
|
768
923
|
}
|
|
769
924
|
function getRefreshToken() {
|
|
925
|
+
const adapter = getSessionStorageAdapter();
|
|
926
|
+
if (adapter) {
|
|
927
|
+
return adapter.getRefreshToken();
|
|
928
|
+
}
|
|
770
929
|
const raw = getCookie(getStorageKeys().refreshToken);
|
|
771
930
|
if (!isCorruptCookieRawValue(raw)) {
|
|
772
931
|
return raw;
|
|
@@ -777,6 +936,11 @@ function getRefreshToken() {
|
|
|
777
936
|
return null;
|
|
778
937
|
}
|
|
779
938
|
function clearRefreshToken() {
|
|
939
|
+
const adapter = getSessionStorageAdapter();
|
|
940
|
+
if (adapter) {
|
|
941
|
+
adapter.removeRefreshToken();
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
780
944
|
const key = getStorageKeys().refreshToken;
|
|
781
945
|
if (key) {
|
|
782
946
|
removeCookie(key);
|
|
@@ -786,12 +950,34 @@ function clearRefreshToken() {
|
|
|
786
950
|
}
|
|
787
951
|
}
|
|
788
952
|
function getPortal() {
|
|
789
|
-
return
|
|
953
|
+
return readStoredJson(getStorageKeys().portal);
|
|
790
954
|
}
|
|
791
955
|
function getSubscriptionType() {
|
|
792
|
-
return
|
|
956
|
+
return readStoredJson(getStorageKeys().subscriptionType);
|
|
957
|
+
}
|
|
958
|
+
function clearAdapterSessionData() {
|
|
959
|
+
const adapter = getSessionStorageAdapter();
|
|
960
|
+
if (!adapter) {
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const keys = getStorageKeys();
|
|
964
|
+
adapter.removeRefreshToken();
|
|
965
|
+
for (const key of [
|
|
966
|
+
keys.loginDetails,
|
|
967
|
+
keys.portal,
|
|
968
|
+
keys.subscriptionType,
|
|
969
|
+
keys.authUser,
|
|
970
|
+
WP_STORAGE_KEYS.c.mfa.pendingToken,
|
|
971
|
+
WP_STORAGE_KEYS.c.mfa.pendingTokenExp,
|
|
972
|
+
WP_STORAGE_KEYS.c.auth.refreshExhausted,
|
|
973
|
+
WP_STORAGE_KEYS.c.auth.err
|
|
974
|
+
]) {
|
|
975
|
+
if (key) {
|
|
976
|
+
adapter.removeItem(key);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
793
979
|
}
|
|
794
980
|
|
|
795
|
-
export { DEV_API_URL, DEV_PORTAL_ID, HUBSPOT_DATA, HUB_ID, clearAccessToken, clearMfaPendingAccessToken, clearRefreshToken, clearSessionRefreshExhaustedState, config, configureLogger, didLastRefreshFail, ensureValidRefresh, getAccessToken, getPortal, getProfile, getRefreshToken, getSubscriptionType, hasRefreshSession, hasValidAccessToken, hydrateMfaPendingAccessToken, hydrateSessionRefreshState, isAccessTokenExpired, isAuthenticateApp, isAuthenticated, isExpiresAccessToken, isHttpTracingEnabled, isMfaPendingAccessSession, isRefreshInFlight, isSessionRefreshExhausted, logger, readMfaPendingAccessToken, refreshSession, resetSessionAuthState, sanitizeAxiosErrorData, setAccessToken, setConfig, setIframeStorageMode, setLoggedInDetails, setPortal, setProfileDetails, setRefreshBufferSeconds, setRefreshCallback, setRefreshToken, setRuntimeHttpClientHubContext, setSessionLifecycleListener, setSubscriptionType, storAccessToken, storage, storeMfaPendingAccessToken };
|
|
796
|
-
//# sourceMappingURL=chunk-
|
|
797
|
-
//# sourceMappingURL=chunk-
|
|
981
|
+
export { DEV_API_URL, DEV_PORTAL_ID, HUBSPOT_DATA, HUB_ID, PORTAL_ID, SERVICE_UNAVAILABLE_MESSAGE, classifyHttpError, classifyRefreshHttpError, classifyRefreshResponseWithoutToken, clearAccessToken, clearAdapterSessionData, clearMfaPendingAccessToken, clearRefreshToken, clearSessionRefreshExhaustedState, config, configureLogger, didLastRefreshFail, ensureValidRefresh, getAccessToken, getHttpErrorMessage, getPortal, getProfile, getRefreshToken, getSubscriptionType, hasRefreshSession, hasValidAccessToken, hydrateMfaPendingAccessToken, hydrateSessionRefreshState, isAccessTokenExpired, isAuthenticateApp, isAuthenticated, isExpiresAccessToken, isHttpTracingEnabled, isMfaPendingAccessSession, isRefreshInFlight, isServiceUnavailableError, isSessionRefreshExhausted, logger, readMfaPendingAccessToken, refreshSession, resetSessionAuthState, sanitizeAxiosErrorData, setAccessToken, setConfig, setIframeStorageMode, setLoggedInDetails, setPortal, setProfileDetails, setRefreshBufferSeconds, setRefreshCallback, setRefreshToken, setRuntimeHttpClientHubContext, setSessionLifecycleListener, setSubscriptionType, shouldLogoutAfterRefreshFailure, storAccessToken, storage, storeMfaPendingAccessToken };
|
|
982
|
+
//# sourceMappingURL=chunk-NDDE6ZZ3.js.map
|
|
983
|
+
//# sourceMappingURL=chunk-NDDE6ZZ3.js.map
|