@fluid-app/rep-sdk 0.1.1 → 0.1.2
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 +70 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -215,6 +215,7 @@ function createFluidClient(config) {
|
|
|
215
215
|
}
|
|
216
216
|
if (response.status === 401) {
|
|
217
217
|
effectiveOnAuthError();
|
|
218
|
+
return null;
|
|
218
219
|
}
|
|
219
220
|
if (!response.ok) {
|
|
220
221
|
try {
|
|
@@ -375,6 +376,16 @@ function createFluidClient(config) {
|
|
|
375
376
|
var ThemeContext = react.createContext(null);
|
|
376
377
|
function applyThemeVariables(theme, container) {
|
|
377
378
|
const target = container ?? document.documentElement;
|
|
379
|
+
const toRemove = [];
|
|
380
|
+
for (let i = 0; i < target.style.length; i++) {
|
|
381
|
+
const prop = target.style[i];
|
|
382
|
+
if (prop.startsWith("--fluid-")) {
|
|
383
|
+
toRemove.push(prop);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
for (const prop of toRemove) {
|
|
387
|
+
target.style.removeProperty(prop);
|
|
388
|
+
}
|
|
378
389
|
for (const [key, value] of Object.entries(theme.config)) {
|
|
379
390
|
target.style.setProperty(`--fluid-${key}`, value);
|
|
380
391
|
}
|
|
@@ -441,7 +452,11 @@ function FluidProvider({
|
|
|
441
452
|
const configRef = react.useRef(config);
|
|
442
453
|
configRef.current = config;
|
|
443
454
|
const client = react.useMemo(
|
|
444
|
-
() => createFluidClient(
|
|
455
|
+
() => createFluidClient({
|
|
456
|
+
...configRef.current,
|
|
457
|
+
getAuthToken: () => configRef.current.getAuthToken?.() ?? null,
|
|
458
|
+
onAuthError: () => configRef.current.onAuthError?.()
|
|
459
|
+
}),
|
|
445
460
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
446
461
|
[config.baseUrl]
|
|
447
462
|
);
|
|
@@ -494,10 +509,12 @@ var URL_PARAMS = {
|
|
|
494
509
|
COMPANY_TOKEN: "fluidCompanyToken"
|
|
495
510
|
};
|
|
496
511
|
|
|
497
|
-
// src/auth/
|
|
512
|
+
// src/auth/browser-utils.ts
|
|
498
513
|
function isBrowser() {
|
|
499
|
-
return typeof window !== "undefined";
|
|
514
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
500
515
|
}
|
|
516
|
+
|
|
517
|
+
// src/auth/url-token.ts
|
|
501
518
|
function extractTokenFromUrl(tokenKey = URL_PARAMS.USER_TOKEN) {
|
|
502
519
|
if (!isBrowser()) {
|
|
503
520
|
return null;
|
|
@@ -568,11 +585,8 @@ function extractAllTokensFromUrl(userTokenKey = URL_PARAMS.USER_TOKEN, companyTo
|
|
|
568
585
|
}
|
|
569
586
|
|
|
570
587
|
// src/auth/token-storage.ts
|
|
571
|
-
function isBrowser2() {
|
|
572
|
-
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
573
|
-
}
|
|
574
588
|
function parseCookies() {
|
|
575
|
-
if (!
|
|
589
|
+
if (!isBrowser()) {
|
|
576
590
|
return {};
|
|
577
591
|
}
|
|
578
592
|
const cookies = {};
|
|
@@ -589,7 +603,7 @@ function parseCookies() {
|
|
|
589
603
|
return cookies;
|
|
590
604
|
}
|
|
591
605
|
function setCookie(name, value, options = {}) {
|
|
592
|
-
if (!
|
|
606
|
+
if (!isBrowser()) {
|
|
593
607
|
return;
|
|
594
608
|
}
|
|
595
609
|
const {
|
|
@@ -608,13 +622,13 @@ function setCookie(name, value, options = {}) {
|
|
|
608
622
|
document.cookie = cookieString;
|
|
609
623
|
}
|
|
610
624
|
function deleteCookie(name, path = "/") {
|
|
611
|
-
if (!
|
|
625
|
+
if (!isBrowser()) {
|
|
612
626
|
return;
|
|
613
627
|
}
|
|
614
628
|
document.cookie = `${name}=; path=${path}; max-age=0`;
|
|
615
629
|
}
|
|
616
630
|
function getStoredToken(config) {
|
|
617
|
-
if (!
|
|
631
|
+
if (!isBrowser()) {
|
|
618
632
|
return null;
|
|
619
633
|
}
|
|
620
634
|
const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
|
|
@@ -631,7 +645,7 @@ function getStoredToken(config) {
|
|
|
631
645
|
}
|
|
632
646
|
}
|
|
633
647
|
function storeToken(token, config) {
|
|
634
|
-
if (!
|
|
648
|
+
if (!isBrowser()) {
|
|
635
649
|
return;
|
|
636
650
|
}
|
|
637
651
|
const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
|
|
@@ -654,7 +668,7 @@ function storeToken(token, config) {
|
|
|
654
668
|
}
|
|
655
669
|
}
|
|
656
670
|
function clearTokens(config) {
|
|
657
|
-
if (!
|
|
671
|
+
if (!isBrowser()) {
|
|
658
672
|
return;
|
|
659
673
|
}
|
|
660
674
|
const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
|
|
@@ -671,16 +685,31 @@ function clearTokens(config) {
|
|
|
671
685
|
function hasStoredToken(config) {
|
|
672
686
|
return getStoredToken(config) !== null;
|
|
673
687
|
}
|
|
688
|
+
|
|
689
|
+
// src/auth/types.ts
|
|
690
|
+
var USER_TYPES = {
|
|
691
|
+
admin: "admin",
|
|
692
|
+
rep: "rep",
|
|
693
|
+
root_admin: "root_admin",
|
|
694
|
+
customer: "customer"
|
|
695
|
+
};
|
|
696
|
+
function isUserType(value) {
|
|
697
|
+
return Object.values(USER_TYPES).includes(value);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// src/auth/token-utils.ts
|
|
674
701
|
function extractPayloadFromJose(decoded) {
|
|
702
|
+
const rawUserType = decoded.user_type;
|
|
703
|
+
const rawOgUserType = decoded.og_user_type;
|
|
675
704
|
return {
|
|
676
|
-
id: decoded.id,
|
|
677
|
-
email: decoded.email,
|
|
678
|
-
full_name: decoded.full_name,
|
|
679
|
-
user_type:
|
|
680
|
-
og_user_type:
|
|
681
|
-
company_id: decoded.company_id,
|
|
705
|
+
id: typeof decoded.id === "number" ? decoded.id : void 0,
|
|
706
|
+
email: typeof decoded.email === "string" ? decoded.email : void 0,
|
|
707
|
+
full_name: typeof decoded.full_name === "string" ? decoded.full_name : void 0,
|
|
708
|
+
user_type: typeof rawUserType === "string" && isUserType(rawUserType) ? rawUserType : "rep",
|
|
709
|
+
og_user_type: typeof rawOgUserType === "string" && isUserType(rawOgUserType) ? rawOgUserType : void 0,
|
|
710
|
+
company_id: typeof decoded.company_id === "number" ? decoded.company_id : void 0,
|
|
682
711
|
exp: decoded.exp,
|
|
683
|
-
auth_type: decoded.auth_type
|
|
712
|
+
auth_type: typeof decoded.auth_type === "string" ? decoded.auth_type : void 0
|
|
684
713
|
};
|
|
685
714
|
}
|
|
686
715
|
function decodeToken(token) {
|
|
@@ -770,17 +799,6 @@ async function verifyToken(token, jwksUrl) {
|
|
|
770
799
|
}
|
|
771
800
|
}
|
|
772
801
|
|
|
773
|
-
// src/auth/types.ts
|
|
774
|
-
var USER_TYPES = {
|
|
775
|
-
admin: "admin",
|
|
776
|
-
rep: "rep",
|
|
777
|
-
root_admin: "root_admin",
|
|
778
|
-
customer: "customer"
|
|
779
|
-
};
|
|
780
|
-
function isUserType(value) {
|
|
781
|
-
return Object.values(USER_TYPES).includes(value);
|
|
782
|
-
}
|
|
783
|
-
|
|
784
802
|
// src/auth/dev-utils.ts
|
|
785
803
|
function isDevBypassActive(devBypass) {
|
|
786
804
|
if (!devBypass) return false;
|
|
@@ -792,12 +810,14 @@ function isDevBypassActive(devBypass) {
|
|
|
792
810
|
}
|
|
793
811
|
function createDevUser() {
|
|
794
812
|
return {
|
|
795
|
-
id:
|
|
813
|
+
id: 99999,
|
|
814
|
+
// Dev placeholder — avoids falsy 0
|
|
796
815
|
email: "dev@localhost",
|
|
797
816
|
full_name: "Dev User",
|
|
798
817
|
user_type: USER_TYPES.rep,
|
|
799
818
|
og_user_type: void 0,
|
|
800
|
-
company_id:
|
|
819
|
+
company_id: 99999,
|
|
820
|
+
// Dev placeholder — avoids falsy 0
|
|
801
821
|
exp: void 0,
|
|
802
822
|
// Never expires
|
|
803
823
|
auth_type: "dev_bypass"
|
|
@@ -816,7 +836,11 @@ function FluidAuthProvider({
|
|
|
816
836
|
const [error, setError] = react.useState(null);
|
|
817
837
|
react.useEffect(() => {
|
|
818
838
|
const initializeAuth = async () => {
|
|
819
|
-
const handleAuthFailure =
|
|
839
|
+
const handleAuthFailure = () => {
|
|
840
|
+
const current = configRef.current;
|
|
841
|
+
const handler = resolveAuthFailureHandler(current?.onAuthFailure, current?.authUrl);
|
|
842
|
+
handler();
|
|
843
|
+
};
|
|
820
844
|
try {
|
|
821
845
|
if (isDevBypassActive(config?.devBypass)) {
|
|
822
846
|
const envToken = undefined.VITE_DEV_TOKEN;
|
|
@@ -1939,7 +1963,19 @@ function AuthError({
|
|
|
1939
1963
|
}
|
|
1940
1964
|
);
|
|
1941
1965
|
}
|
|
1966
|
+
var SPIN_STYLE_ID = "fluid-auth-loading-spin";
|
|
1967
|
+
function ensureSpinStyle() {
|
|
1968
|
+
if (typeof document === "undefined") return;
|
|
1969
|
+
if (document.getElementById(SPIN_STYLE_ID)) return;
|
|
1970
|
+
const style = document.createElement("style");
|
|
1971
|
+
style.id = SPIN_STYLE_ID;
|
|
1972
|
+
style.textContent = `@keyframes spin { to { transform: rotate(360deg); } }`;
|
|
1973
|
+
document.head.appendChild(style);
|
|
1974
|
+
}
|
|
1942
1975
|
function AuthLoading() {
|
|
1976
|
+
react.useEffect(() => {
|
|
1977
|
+
ensureSpinStyle();
|
|
1978
|
+
}, []);
|
|
1943
1979
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1944
1980
|
"div",
|
|
1945
1981
|
{
|
|
@@ -1976,12 +2012,7 @@ function AuthLoading() {
|
|
|
1976
2012
|
},
|
|
1977
2013
|
children: "Authenticating..."
|
|
1978
2014
|
}
|
|
1979
|
-
)
|
|
1980
|
-
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `
|
|
1981
|
-
@keyframes spin {
|
|
1982
|
-
to { transform: rotate(360deg); }
|
|
1983
|
-
}
|
|
1984
|
-
` })
|
|
2015
|
+
)
|
|
1985
2016
|
]
|
|
1986
2017
|
}
|
|
1987
2018
|
);
|