techsbcn-storybook 2.0.3 → 2.0.5
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/helpers/AuthHelper.d.ts +4 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ export interface Session {
|
|
|
2
2
|
nameidentifier: string;
|
|
3
3
|
role: string[];
|
|
4
4
|
}
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
5
|
+
export declare const getSession: () => Session | null;
|
|
6
|
+
export declare const getJwtToken: () => string | null;
|
|
7
|
+
export declare const saveSession: (jwt: string) => void;
|
|
8
|
+
export declare const clearSession: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -23,3 +23,4 @@ export * from './components/wrappers/TabsComponent/TabsComponent';
|
|
|
23
23
|
export * from './components/wrappers/LinearProgressComponent/LinearProgressComponent';
|
|
24
24
|
export * from './components/fields/DatePickerComponent/DatePickerComponent';
|
|
25
25
|
export * from './components/wrappers/CardComponent/CardComponent';
|
|
26
|
+
export * from './helpers/index';
|
package/dist/index.js
CHANGED
|
@@ -594,6 +594,52 @@ var TextFieldComponent = ({
|
|
|
594
594
|
));
|
|
595
595
|
};
|
|
596
596
|
|
|
597
|
+
// src/helpers/AuthHelper.tsx
|
|
598
|
+
var AUTH_COOKIE_NAME = "auth_token";
|
|
599
|
+
var NAME_IDENTIFIER_CLAIM = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier";
|
|
600
|
+
var ROLE_CLAIM = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
|
|
601
|
+
var getCookie = (name) => {
|
|
602
|
+
if (typeof document === "undefined") return null;
|
|
603
|
+
const cookie = document.cookie.split("; ").find((c) => c.startsWith(`${name}=`));
|
|
604
|
+
return cookie ? decodeURIComponent(cookie.substring(name.length + 1)) : null;
|
|
605
|
+
};
|
|
606
|
+
var decodeJwtPayload = (jwt) => {
|
|
607
|
+
try {
|
|
608
|
+
const payload = jwt.split(".")[1];
|
|
609
|
+
if (!payload) return null;
|
|
610
|
+
const base64 = payload.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(payload.length / 4) * 4, "=");
|
|
611
|
+
const binary = window.atob(base64);
|
|
612
|
+
const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
|
|
613
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
614
|
+
} catch {
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
var getSession = () => {
|
|
619
|
+
const jwt = getCookie(AUTH_COOKIE_NAME);
|
|
620
|
+
if (!jwt) return null;
|
|
621
|
+
const payload = decodeJwtPayload(jwt);
|
|
622
|
+
if (!payload) return null;
|
|
623
|
+
if (typeof payload.exp === "number" && payload.exp * 1e3 <= Date.now()) return null;
|
|
624
|
+
const roles = payload[ROLE_CLAIM];
|
|
625
|
+
return {
|
|
626
|
+
nameidentifier: payload[NAME_IDENTIFIER_CLAIM],
|
|
627
|
+
role: roles === void 0 || roles === null ? [] : Array.isArray(roles) ? roles : [roles]
|
|
628
|
+
};
|
|
629
|
+
};
|
|
630
|
+
var getJwtToken = () => getCookie(AUTH_COOKIE_NAME);
|
|
631
|
+
var saveSession = (jwt) => {
|
|
632
|
+
if (typeof document === "undefined") return;
|
|
633
|
+
const payload = decodeJwtPayload(jwt);
|
|
634
|
+
const expires = typeof payload?.exp === "number" ? `; expires=${new Date(payload.exp * 1e3).toUTCString()}` : "";
|
|
635
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
636
|
+
document.cookie = `${AUTH_COOKIE_NAME}=${encodeURIComponent(jwt)}${expires}; path=/; SameSite=Lax${secure}`;
|
|
637
|
+
};
|
|
638
|
+
var clearSession = () => {
|
|
639
|
+
if (typeof document === "undefined") return;
|
|
640
|
+
document.cookie = `${AUTH_COOKIE_NAME}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; SameSite=Lax`;
|
|
641
|
+
};
|
|
642
|
+
|
|
597
643
|
// src/helpers/CheckPermission.tsx
|
|
598
644
|
var checkPermission = (persmisionAvailable, userRoles) => {
|
|
599
645
|
if (persmisionAvailable === null || persmisionAvailable === void 0 || persmisionAvailable.length === 0) {
|
|
@@ -614,6 +660,46 @@ var checkPermission = (persmisionAvailable, userRoles) => {
|
|
|
614
660
|
}
|
|
615
661
|
return userRoles.indexOf(persmisionAvailable) >= 0;
|
|
616
662
|
};
|
|
663
|
+
|
|
664
|
+
// src/helpers/GroupBy.tsx
|
|
665
|
+
var GroupBy = (xs, f) => {
|
|
666
|
+
return xs.reduce((r, v, _i, _a, k = f(v)) => {
|
|
667
|
+
(r[k] || (r[k] = [])).push(v);
|
|
668
|
+
return r;
|
|
669
|
+
}, {});
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
// src/helpers/FileDownloader.tsx
|
|
673
|
+
var downloadFileBlob = (binaryString) => {
|
|
674
|
+
const data = window.URL.createObjectURL(new Blob([binaryString.blob]));
|
|
675
|
+
const fileName = binaryString.contentDisposition.split("filename=")[1];
|
|
676
|
+
redirectDownload(data, fileName);
|
|
677
|
+
};
|
|
678
|
+
var redirectDownload = (url, fileName) => {
|
|
679
|
+
const a = document.createElement("a");
|
|
680
|
+
a.setAttribute("href", url);
|
|
681
|
+
a.setAttribute("download", fileName);
|
|
682
|
+
a.style.visibility = "hidden";
|
|
683
|
+
document.body.appendChild(a);
|
|
684
|
+
a.click();
|
|
685
|
+
document.body.removeChild(a);
|
|
686
|
+
};
|
|
687
|
+
var getImageByBlob = (binaryString) => {
|
|
688
|
+
return URL.createObjectURL(new Blob([binaryString.blob])).toString();
|
|
689
|
+
};
|
|
690
|
+
var getImageByBase64 = (content) => {
|
|
691
|
+
const binaryString = window.atob(content);
|
|
692
|
+
const blob = new Uint8Array(binaryString.length).map((_byte, i) => binaryString.charCodeAt(i));
|
|
693
|
+
return URL.createObjectURL(new Blob([blob])).toString();
|
|
694
|
+
};
|
|
695
|
+
var toBase64 = (file) => {
|
|
696
|
+
return new Promise((resolve, reject) => {
|
|
697
|
+
const reader = new FileReader();
|
|
698
|
+
reader.readAsDataURL(file);
|
|
699
|
+
reader.onload = () => reader.result && resolve(reader.result.toString());
|
|
700
|
+
reader.onerror = (error) => reject(error);
|
|
701
|
+
});
|
|
702
|
+
};
|
|
617
703
|
var usePrevious = (value) => {
|
|
618
704
|
const ref2 = React7.useRef(void 0);
|
|
619
705
|
React7.useEffect(() => {
|
|
@@ -2682,6 +2768,7 @@ exports.CardComponent = CardComponent;
|
|
|
2682
2768
|
exports.ChangePasswordForm = ChangePasswordForm;
|
|
2683
2769
|
exports.DatePickerComponent = DatePickerComponent;
|
|
2684
2770
|
exports.DrawerSidebar = DrawerSidebar;
|
|
2771
|
+
exports.GroupBy = GroupBy;
|
|
2685
2772
|
exports.LinearProgressComponent = LinearProgressComponent;
|
|
2686
2773
|
exports.LoginForm = LoginForm;
|
|
2687
2774
|
exports.MainLayoutSimple = MainLayoutSimple;
|
|
@@ -2701,5 +2788,17 @@ exports.TextFieldComponent = TextFieldComponent;
|
|
|
2701
2788
|
exports.TextSimpleComponent = TextSimpleComponent;
|
|
2702
2789
|
exports.UserInfo = UserInfo;
|
|
2703
2790
|
exports.VerticalNav = VerticalNav;
|
|
2791
|
+
exports.checkPermission = checkPermission;
|
|
2792
|
+
exports.clearSession = clearSession;
|
|
2793
|
+
exports.downloadFileBlob = downloadFileBlob;
|
|
2794
|
+
exports.getImageByBase64 = getImageByBase64;
|
|
2795
|
+
exports.getImageByBlob = getImageByBlob;
|
|
2796
|
+
exports.getJwtToken = getJwtToken;
|
|
2797
|
+
exports.getSession = getSession;
|
|
2798
|
+
exports.redirectDownload = redirectDownload;
|
|
2799
|
+
exports.saveSession = saveSession;
|
|
2800
|
+
exports.toBase64 = toBase64;
|
|
2801
|
+
exports.useIsMounted = useIsMounted;
|
|
2802
|
+
exports.usePrevious = usePrevious;
|
|
2704
2803
|
//# sourceMappingURL=index.js.map
|
|
2705
2804
|
//# sourceMappingURL=index.js.map
|