techsbcn-storybook 2.0.2 → 2.0.4

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.mjs CHANGED
@@ -563,6 +563,51 @@ var TextFieldComponent = ({
563
563
  ));
564
564
  };
565
565
 
566
+ // src/helpers/AuthHelper.tsx
567
+ var AUTH_COOKIE_NAME = "auth_token";
568
+ var NAME_IDENTIFIER_CLAIM = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier";
569
+ var ROLE_CLAIM = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
570
+ var getCookie = (name) => {
571
+ if (typeof document === "undefined") return null;
572
+ const cookie = document.cookie.split("; ").find((c) => c.startsWith(`${name}=`));
573
+ return cookie ? decodeURIComponent(cookie.substring(name.length + 1)) : null;
574
+ };
575
+ var decodeJwtPayload = (jwt) => {
576
+ try {
577
+ const payload = jwt.split(".")[1];
578
+ if (!payload) return null;
579
+ const base64 = payload.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(payload.length / 4) * 4, "=");
580
+ const binary = window.atob(base64);
581
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
582
+ return JSON.parse(new TextDecoder().decode(bytes));
583
+ } catch {
584
+ return null;
585
+ }
586
+ };
587
+ var getSession = () => {
588
+ const jwt = getCookie(AUTH_COOKIE_NAME);
589
+ if (!jwt) return null;
590
+ const payload = decodeJwtPayload(jwt);
591
+ if (!payload) return null;
592
+ if (typeof payload.exp === "number" && payload.exp * 1e3 <= Date.now()) return null;
593
+ const roles = payload[ROLE_CLAIM];
594
+ return {
595
+ nameidentifier: payload[NAME_IDENTIFIER_CLAIM],
596
+ role: roles === void 0 || roles === null ? [] : Array.isArray(roles) ? roles : [roles]
597
+ };
598
+ };
599
+ var saveSession = (jwt) => {
600
+ if (typeof document === "undefined") return;
601
+ const payload = decodeJwtPayload(jwt);
602
+ const expires = typeof payload?.exp === "number" ? `; expires=${new Date(payload.exp * 1e3).toUTCString()}` : "";
603
+ const secure = window.location.protocol === "https:" ? "; Secure" : "";
604
+ document.cookie = `${AUTH_COOKIE_NAME}=${encodeURIComponent(jwt)}${expires}; path=/; SameSite=Lax${secure}`;
605
+ };
606
+ var clearSession = () => {
607
+ if (typeof document === "undefined") return;
608
+ document.cookie = `${AUTH_COOKIE_NAME}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; SameSite=Lax`;
609
+ };
610
+
566
611
  // src/helpers/CheckPermission.tsx
567
612
  var checkPermission = (persmisionAvailable, userRoles) => {
568
613
  if (persmisionAvailable === null || persmisionAvailable === void 0 || persmisionAvailable.length === 0) {
@@ -583,6 +628,46 @@ var checkPermission = (persmisionAvailable, userRoles) => {
583
628
  }
584
629
  return userRoles.indexOf(persmisionAvailable) >= 0;
585
630
  };
631
+
632
+ // src/helpers/GroupBy.tsx
633
+ var GroupBy = (xs, f) => {
634
+ return xs.reduce((r, v, _i, _a, k = f(v)) => {
635
+ (r[k] || (r[k] = [])).push(v);
636
+ return r;
637
+ }, {});
638
+ };
639
+
640
+ // src/helpers/FileDownloader.tsx
641
+ var downloadFileBlob = (binaryString) => {
642
+ const data = window.URL.createObjectURL(new Blob([binaryString.blob]));
643
+ const fileName = binaryString.contentDisposition.split("filename=")[1];
644
+ redirectDownload(data, fileName);
645
+ };
646
+ var redirectDownload = (url, fileName) => {
647
+ const a = document.createElement("a");
648
+ a.setAttribute("href", url);
649
+ a.setAttribute("download", fileName);
650
+ a.style.visibility = "hidden";
651
+ document.body.appendChild(a);
652
+ a.click();
653
+ document.body.removeChild(a);
654
+ };
655
+ var getImageByBlob = (binaryString) => {
656
+ return URL.createObjectURL(new Blob([binaryString.blob])).toString();
657
+ };
658
+ var getImageByBase64 = (content) => {
659
+ const binaryString = window.atob(content);
660
+ const blob = new Uint8Array(binaryString.length).map((_byte, i) => binaryString.charCodeAt(i));
661
+ return URL.createObjectURL(new Blob([blob])).toString();
662
+ };
663
+ var toBase64 = (file) => {
664
+ return new Promise((resolve, reject) => {
665
+ const reader = new FileReader();
666
+ reader.readAsDataURL(file);
667
+ reader.onload = () => reader.result && resolve(reader.result.toString());
668
+ reader.onerror = (error) => reject(error);
669
+ });
670
+ };
586
671
  var usePrevious = (value) => {
587
672
  const ref2 = useRef(void 0);
588
673
  useEffect(() => {
@@ -2644,6 +2729,6 @@ var CardComponent = ({ backgroundType = "white", ...rest }) => {
2644
2729
  );
2645
2730
  };
2646
2731
 
2647
- export { AppHeader, AppSidebar, ButtonComponent, CardComponent, ChangePasswordForm, DatePickerComponent, DrawerSidebar, LinearProgressComponent, LoginForm, MainLayoutSimple, MainWrapperComponent, ModalComponent, NavigationType, PublicFormWrapper, ResetPasswordForm, SearchComponent, SelectAsyncField, SelectField, SimpleTableComponent, SplitLayout, TableComponent, TabsComponent, TextFieldComponent, TextSimpleComponent, UserInfo, VerticalNav };
2732
+ export { AppHeader, AppSidebar, ButtonComponent, CardComponent, ChangePasswordForm, DatePickerComponent, DrawerSidebar, GroupBy, LinearProgressComponent, LoginForm, MainLayoutSimple, MainWrapperComponent, ModalComponent, NavigationType, PublicFormWrapper, ResetPasswordForm, SearchComponent, SelectAsyncField, SelectField, SimpleTableComponent, SplitLayout, TableComponent, TabsComponent, TextFieldComponent, TextSimpleComponent, UserInfo, VerticalNav, checkPermission, clearSession, downloadFileBlob, getImageByBase64, getImageByBlob, getSession, redirectDownload, saveSession, toBase64, useIsMounted, usePrevious };
2648
2733
  //# sourceMappingURL=index.mjs.map
2649
2734
  //# sourceMappingURL=index.mjs.map