@bluemarble/bm-components 2.1.2 → 2.2.0

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.d.cts CHANGED
@@ -5,9 +5,12 @@ import { TableCellProps, TableCell, TextFieldProps, StandardTextFieldProps, Sele
5
5
  import * as _mui_material_OverridableComponent from '@mui/material/OverridableComponent';
6
6
  import { FactoryOpts } from 'imask';
7
7
  import { IconType } from 'react-icons';
8
+ import * as next from 'next';
8
9
  import { NextApiRequest, NextApiResponse, GetServerSidePropsContext } from 'next';
9
10
  import { ZodSchema } from 'zod';
10
11
  import { AxiosInstance } from 'axios';
12
+ import * as cookie from 'cookie';
13
+ import * as express from 'express';
11
14
 
12
15
  interface ColumnTitleProps {
13
16
  name: string;
@@ -643,4 +646,46 @@ declare function CreateAuthProvider<T>({ api, children, sessionTokenName, Provid
643
646
  sessionTokenName: string;
644
647
  }): React__default.JSX.Element;
645
648
 
646
- export { AlertContext, AlertProvider, ApiHelper, type AuthContextProps, AuthHelper, Autocomplete, BaseDialog, BaseDialogBody, BaseDialogContainer, BaseDialogCreate, BaseDialogTrigger, BaseGrid, BaseGridAutoRows, Checkbox, type ColumnTitleProps, type ColumnsProps, CreateAuthProvider, Dialog, DialogConfirm, DomainError, EditableTableCell, type FilterCompareType, type FilterProps, FormHelperContext, FormHelperProvider, GetInputLabel, Grid, HttpError, type IBaseDialogBodyProps, type IBaseDialogContainerProps, type IBaseDialogTriggerProps, type IDialogConfirmProps, type IFilter, Input, InputMask, LargeButton, Modal, Radio, Select, type SortedByProps$1 as SortedByProps, Switch, type TUseDialogConfirm, TabPanel, type TabPanelProps, Td, Tr, UseDialogConfirm, createAuthContext, createFilter, filterData, getTabProps, useAlert, useAsyncGrid, useBaseDialog, useBaseDialogInstance, useEvent, useFilter, useFormHelper, useGrid, useLoading };
649
+ /**
650
+ * Parses cookies.
651
+ *
652
+ * @param ctx NextJS page or API context, express context, null or undefined.
653
+ * @param options Options that we pass down to `cookie` library.
654
+ */
655
+ declare function parseCookies(ctx?: Pick<next.NextPageContext, 'req'> | {
656
+ req: next.NextApiRequest;
657
+ } | {
658
+ req: express.Request;
659
+ } | null | undefined, options?: cookie.ParseOptions): cookie.Cookies;
660
+ /**
661
+ * Sets a cookie.
662
+ *
663
+ * @param ctx NextJS page or API context, express context, null or undefined.
664
+ * @param name The name of your cookie.
665
+ * @param value The value of your cookie.
666
+ * @param options Options that we pass down to `cookie` library.
667
+ */
668
+ declare function setCookie(ctx: Pick<next.NextPageContext, 'res'> | {
669
+ res: next.NextApiResponse;
670
+ } | {
671
+ res: express.Response;
672
+ } | null | undefined, name: string, value: string, options?: cookie.SerializeOptions): {};
673
+ /**
674
+ * Destroys a cookie with a particular name.
675
+ *
676
+ * @param ctx NextJS page or API context, express context, null or undefined.
677
+ * @param name Cookie name.
678
+ * @param options Options that we pass down to `cookie` library.
679
+ */
680
+ declare function destroyCookie(ctx: Pick<next.NextPageContext, 'res'> | {
681
+ res: next.NextApiResponse;
682
+ } | {
683
+ res: express.Response;
684
+ } | null | undefined, name: string, options?: cookie.SerializeOptions): {};
685
+ declare const nookies: {
686
+ set: typeof setCookie;
687
+ get: typeof parseCookies;
688
+ destroy: typeof destroyCookie;
689
+ };
690
+
691
+ export { AlertContext, AlertProvider, ApiHelper, type AuthContextProps, AuthHelper, Autocomplete, BaseDialog, BaseDialogBody, BaseDialogContainer, BaseDialogCreate, BaseDialogTrigger, BaseGrid, BaseGridAutoRows, Checkbox, type ColumnTitleProps, type ColumnsProps, CreateAuthProvider, Dialog, DialogConfirm, DomainError, EditableTableCell, type FilterCompareType, type FilterProps, FormHelperContext, FormHelperProvider, GetInputLabel, Grid, HttpError, type IBaseDialogBodyProps, type IBaseDialogContainerProps, type IBaseDialogTriggerProps, type IDialogConfirmProps, type IFilter, Input, InputMask, LargeButton, Modal, Radio, Select, type SortedByProps$1 as SortedByProps, Switch, type TUseDialogConfirm, TabPanel, type TabPanelProps, Td, Tr, UseDialogConfirm, createAuthContext, createFilter, destroyCookie, filterData, getTabProps, nookies, parseCookies, setCookie, useAlert, useAsyncGrid, useBaseDialog, useBaseDialogInstance, useEvent, useFilter, useFormHelper, useGrid, useLoading };
package/dist/index.d.ts CHANGED
@@ -5,9 +5,12 @@ import { TableCellProps, TableCell, TextFieldProps, StandardTextFieldProps, Sele
5
5
  import * as _mui_material_OverridableComponent from '@mui/material/OverridableComponent';
6
6
  import { FactoryOpts } from 'imask';
7
7
  import { IconType } from 'react-icons';
8
+ import * as next from 'next';
8
9
  import { NextApiRequest, NextApiResponse, GetServerSidePropsContext } from 'next';
9
10
  import { ZodSchema } from 'zod';
10
11
  import { AxiosInstance } from 'axios';
12
+ import * as cookie from 'cookie';
13
+ import * as express from 'express';
11
14
 
12
15
  interface ColumnTitleProps {
13
16
  name: string;
@@ -643,4 +646,46 @@ declare function CreateAuthProvider<T>({ api, children, sessionTokenName, Provid
643
646
  sessionTokenName: string;
644
647
  }): React__default.JSX.Element;
645
648
 
646
- export { AlertContext, AlertProvider, ApiHelper, type AuthContextProps, AuthHelper, Autocomplete, BaseDialog, BaseDialogBody, BaseDialogContainer, BaseDialogCreate, BaseDialogTrigger, BaseGrid, BaseGridAutoRows, Checkbox, type ColumnTitleProps, type ColumnsProps, CreateAuthProvider, Dialog, DialogConfirm, DomainError, EditableTableCell, type FilterCompareType, type FilterProps, FormHelperContext, FormHelperProvider, GetInputLabel, Grid, HttpError, type IBaseDialogBodyProps, type IBaseDialogContainerProps, type IBaseDialogTriggerProps, type IDialogConfirmProps, type IFilter, Input, InputMask, LargeButton, Modal, Radio, Select, type SortedByProps$1 as SortedByProps, Switch, type TUseDialogConfirm, TabPanel, type TabPanelProps, Td, Tr, UseDialogConfirm, createAuthContext, createFilter, filterData, getTabProps, useAlert, useAsyncGrid, useBaseDialog, useBaseDialogInstance, useEvent, useFilter, useFormHelper, useGrid, useLoading };
649
+ /**
650
+ * Parses cookies.
651
+ *
652
+ * @param ctx NextJS page or API context, express context, null or undefined.
653
+ * @param options Options that we pass down to `cookie` library.
654
+ */
655
+ declare function parseCookies(ctx?: Pick<next.NextPageContext, 'req'> | {
656
+ req: next.NextApiRequest;
657
+ } | {
658
+ req: express.Request;
659
+ } | null | undefined, options?: cookie.ParseOptions): cookie.Cookies;
660
+ /**
661
+ * Sets a cookie.
662
+ *
663
+ * @param ctx NextJS page or API context, express context, null or undefined.
664
+ * @param name The name of your cookie.
665
+ * @param value The value of your cookie.
666
+ * @param options Options that we pass down to `cookie` library.
667
+ */
668
+ declare function setCookie(ctx: Pick<next.NextPageContext, 'res'> | {
669
+ res: next.NextApiResponse;
670
+ } | {
671
+ res: express.Response;
672
+ } | null | undefined, name: string, value: string, options?: cookie.SerializeOptions): {};
673
+ /**
674
+ * Destroys a cookie with a particular name.
675
+ *
676
+ * @param ctx NextJS page or API context, express context, null or undefined.
677
+ * @param name Cookie name.
678
+ * @param options Options that we pass down to `cookie` library.
679
+ */
680
+ declare function destroyCookie(ctx: Pick<next.NextPageContext, 'res'> | {
681
+ res: next.NextApiResponse;
682
+ } | {
683
+ res: express.Response;
684
+ } | null | undefined, name: string, options?: cookie.SerializeOptions): {};
685
+ declare const nookies: {
686
+ set: typeof setCookie;
687
+ get: typeof parseCookies;
688
+ destroy: typeof destroyCookie;
689
+ };
690
+
691
+ export { AlertContext, AlertProvider, ApiHelper, type AuthContextProps, AuthHelper, Autocomplete, BaseDialog, BaseDialogBody, BaseDialogContainer, BaseDialogCreate, BaseDialogTrigger, BaseGrid, BaseGridAutoRows, Checkbox, type ColumnTitleProps, type ColumnsProps, CreateAuthProvider, Dialog, DialogConfirm, DomainError, EditableTableCell, type FilterCompareType, type FilterProps, FormHelperContext, FormHelperProvider, GetInputLabel, Grid, HttpError, type IBaseDialogBodyProps, type IBaseDialogContainerProps, type IBaseDialogTriggerProps, type IDialogConfirmProps, type IFilter, Input, InputMask, LargeButton, Modal, Radio, Select, type SortedByProps$1 as SortedByProps, Switch, type TUseDialogConfirm, TabPanel, type TabPanelProps, Td, Tr, UseDialogConfirm, createAuthContext, createFilter, destroyCookie, filterData, getTabProps, nookies, parseCookies, setCookie, useAlert, useAsyncGrid, useBaseDialog, useBaseDialogInstance, useEvent, useFilter, useFormHelper, useGrid, useLoading };
package/dist/index.js CHANGED
@@ -4305,7 +4305,7 @@ var DialogConfirm = (props) => {
4305
4305
  onClick: model.onCancel,
4306
4306
  color: "inherit"
4307
4307
  },
4308
- props.cancelButtonText || "Confirmar"
4308
+ props.cancelButtonText || "Cancelar"
4309
4309
  ))))));
4310
4310
  };
4311
4311
 
@@ -4753,10 +4753,119 @@ function useFormHelper() {
4753
4753
  }
4754
4754
 
4755
4755
  // src/helpers/authHelper.ts
4756
- import { serialize } from "cookie";
4757
- import { parseCookies, setCookie } from "nookies";
4756
+ import { serialize as serialize2 } from "cookie";
4758
4757
  import { v4 as uuid } from "uuid";
4759
4758
  import jwt from "jsonwebtoken";
4759
+
4760
+ // packages/nookies/index.ts
4761
+ import * as cookie from "cookie";
4762
+ import * as setCookieParser from "set-cookie-parser";
4763
+
4764
+ // packages/nookies/util.ts
4765
+ function isBrowser() {
4766
+ return typeof window !== "undefined";
4767
+ }
4768
+ function createCookie(name, value, options) {
4769
+ let sameSite = options.sameSite;
4770
+ if (sameSite === true) {
4771
+ sameSite = "strict";
4772
+ }
4773
+ if (sameSite === void 0 || sameSite === false) {
4774
+ sameSite = "lax";
4775
+ }
4776
+ const cookieToSet = { ...options, sameSite };
4777
+ delete cookieToSet.encode;
4778
+ return {
4779
+ name,
4780
+ value,
4781
+ ...cookieToSet
4782
+ };
4783
+ }
4784
+ function hasSameProperties(a, b) {
4785
+ const aProps = Object.getOwnPropertyNames(a);
4786
+ const bProps = Object.getOwnPropertyNames(b);
4787
+ if (aProps.length !== bProps.length) {
4788
+ return false;
4789
+ }
4790
+ for (let i = 0; i < aProps.length; i++) {
4791
+ const propName = aProps[i];
4792
+ if (a[propName] !== b[propName]) {
4793
+ return false;
4794
+ }
4795
+ }
4796
+ return true;
4797
+ }
4798
+ function areCookiesEqual(a, b) {
4799
+ let sameSiteSame = a.sameSite === b.sameSite;
4800
+ if (typeof a.sameSite === "string" && typeof b.sameSite === "string") {
4801
+ sameSiteSame = a.sameSite.toLowerCase() === b.sameSite.toLowerCase();
4802
+ }
4803
+ return hasSameProperties(
4804
+ { ...a, sameSite: void 0 },
4805
+ { ...b, sameSite: void 0 }
4806
+ ) && sameSiteSame;
4807
+ }
4808
+
4809
+ // packages/nookies/index.ts
4810
+ function parseCookies(ctx, options) {
4811
+ if (ctx?.req?.headers?.cookie) {
4812
+ return cookie.parse(ctx.req.headers.cookie, options);
4813
+ }
4814
+ if (isBrowser()) {
4815
+ return cookie.parse(document.cookie, options);
4816
+ }
4817
+ return {};
4818
+ }
4819
+ function setCookie(ctx, name, value, options = {}) {
4820
+ if (ctx?.res?.getHeader && ctx.res.setHeader) {
4821
+ if (ctx?.res?.finished) {
4822
+ console.warn(`Not setting "${name}" cookie. Response has finished.`);
4823
+ console.warn(`You should set cookie before res.send()`);
4824
+ return {};
4825
+ }
4826
+ let cookies = ctx.res.getHeader("Set-Cookie") || [];
4827
+ if (typeof cookies === "string") cookies = [cookies];
4828
+ if (typeof cookies === "number") cookies = [];
4829
+ const parsedCookies = setCookieParser.parse(cookies, {
4830
+ decodeValues: false
4831
+ });
4832
+ const newCookie = createCookie(name, value, options);
4833
+ let cookiesToSet = [];
4834
+ parsedCookies.forEach((parsedCookie) => {
4835
+ if (!areCookiesEqual(parsedCookie, newCookie)) {
4836
+ const serializedCookie = cookie.serialize(
4837
+ parsedCookie.name,
4838
+ parsedCookie.value,
4839
+ {
4840
+ // we prevent reencoding by default, but you might override it
4841
+ encode: (val) => val,
4842
+ ...parsedCookie
4843
+ }
4844
+ );
4845
+ cookiesToSet.push(serializedCookie);
4846
+ }
4847
+ });
4848
+ cookiesToSet.push(cookie.serialize(name, value, options));
4849
+ ctx.res.setHeader("Set-Cookie", cookiesToSet);
4850
+ }
4851
+ if (isBrowser()) {
4852
+ if (options && options.httpOnly) {
4853
+ throw new Error("Can not set a httpOnly cookie in the browser.");
4854
+ }
4855
+ document.cookie = cookie.serialize(name, value, options);
4856
+ }
4857
+ return {};
4858
+ }
4859
+ function destroyCookie(ctx, name, options) {
4860
+ return setCookie(ctx, name, "", { ...options || {}, maxAge: -1 });
4861
+ }
4862
+ var nookies = {
4863
+ set: setCookie,
4864
+ get: parseCookies,
4865
+ destroy: destroyCookie
4866
+ };
4867
+
4868
+ // src/helpers/authHelper.ts
4760
4869
  function decodeSessionToken({
4761
4870
  req,
4762
4871
  res,
@@ -4808,11 +4917,11 @@ var AuthHelper = class {
4808
4917
  };
4809
4918
  this.invalidateCookies = (res) => {
4810
4919
  return res.setHeader("Set-Cookie", [
4811
- serialize(this.cookies.sessionToken, "", {
4920
+ serialize2(this.cookies.sessionToken, "", {
4812
4921
  maxAge: -1,
4813
4922
  path: "/"
4814
4923
  }),
4815
- serialize(this.cookies.refreshToken, "", {
4924
+ serialize2(this.cookies.refreshToken, "", {
4816
4925
  maxAge: -1,
4817
4926
  path: "/"
4818
4927
  })
@@ -5114,8 +5223,26 @@ function createFilter(filters) {
5114
5223
  };
5115
5224
  }
5116
5225
 
5226
+ // src/helpers/sortHelper.ts
5227
+ function SortHelper(...fields) {
5228
+ return (a, b) => {
5229
+ for (const field of fields) {
5230
+ let direction = 1;
5231
+ let key = field;
5232
+ if (field.startsWith("-")) {
5233
+ direction = -1;
5234
+ key = field.slice(1);
5235
+ }
5236
+ const aVal = a[key];
5237
+ const bVal = b[key];
5238
+ if (aVal > bVal) return direction;
5239
+ if (aVal < bVal) return -direction;
5240
+ }
5241
+ return 0;
5242
+ };
5243
+ }
5244
+
5117
5245
  // src/hooks/useGrid.ts
5118
- import sortBy from "sort-by";
5119
5246
  function useGrid({
5120
5247
  columns,
5121
5248
  filters,
@@ -5185,7 +5312,7 @@ function useGrid({
5185
5312
  const formattedKeys = sortedBy.map(
5186
5313
  ({ prop, direction }) => `${symbolDir[direction]}${prop}`
5187
5314
  );
5188
- return data.sort(sortBy(...formattedKeys));
5315
+ return data.sort(SortHelper(...formattedKeys));
5189
5316
  } else return data;
5190
5317
  },
5191
5318
  [sortedBy]
@@ -5486,7 +5613,6 @@ import {
5486
5613
  useEffect as useEffect8,
5487
5614
  useState as useState11
5488
5615
  } from "react";
5489
- import { parseCookies as parseCookies2 } from "nookies";
5490
5616
  function createAuthContext() {
5491
5617
  return createContext5({});
5492
5618
  }
@@ -5526,7 +5652,7 @@ function CreateAuthProvider({
5526
5652
  setUser(void 0);
5527
5653
  }, [api]);
5528
5654
  useEffect8(() => {
5529
- const token = parseCookies2()[sessionTokenName];
5655
+ const token = parseCookies()[sessionTokenName];
5530
5656
  if (token) {
5531
5657
  setStatus("loading");
5532
5658
  api.get("/auth/me").then((response) => {
@@ -5587,8 +5713,12 @@ export {
5587
5713
  UseDialogConfirm,
5588
5714
  createAuthContext,
5589
5715
  createFilter,
5716
+ destroyCookie,
5590
5717
  filterData,
5591
5718
  getTabProps,
5719
+ nookies,
5720
+ parseCookies,
5721
+ setCookie,
5592
5722
  useAlert,
5593
5723
  useAsyncGrid,
5594
5724
  useBaseDialog,