@bluemarble/bm-components 2.4.1 → 2.4.3

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
@@ -1,3 +1,4 @@
1
+ import * as cookie from 'cookie';
1
2
  import * as React from 'react';
2
3
  import React__default, { PropsWithChildren, ReactNode, FC, Provider } from 'react';
3
4
  import * as _mui_material from '@mui/material';
@@ -5,25 +6,72 @@ import { TableCellProps, TableCell, TextFieldProps, StandardTextFieldProps, Sele
5
6
  import * as _mui_material_OverridableComponent from '@mui/material/OverridableComponent';
6
7
  import { FactoryOpts } from 'imask';
7
8
  import { IconType } from 'react-icons';
8
- import * as next from 'next';
9
- import { NextApiRequest, NextApiResponse, GetServerSidePropsContext } from 'next';
10
- import { ZodSchema } from 'zod';
11
9
  import { AxiosInstance } from 'axios';
12
- import * as cookie from 'cookie';
13
- import * as express from 'express';
10
+ import { ZodSchema } from 'zod';
11
+
12
+ interface NookiesRequest {
13
+ headers?: {
14
+ cookie?: string;
15
+ };
16
+ }
17
+ interface NookiesResponse {
18
+ finished?: boolean;
19
+ getHeader(name: string): string | string[] | number | undefined;
20
+ setHeader(name: string, value: string | readonly string[]): any;
21
+ }
22
+
23
+ /**
24
+ * Parses cookies.
25
+ *
26
+ * @param ctx Object with a `req` property, null or undefined.
27
+ * @param options Options that we pass down to `cookie` library.
28
+ */
29
+ declare function parseCookies(ctx?: {
30
+ req: NookiesRequest;
31
+ } | null | undefined, options?: cookie.ParseOptions): cookie.Cookies;
32
+ /**
33
+ * Sets a cookie.
34
+ *
35
+ * @param ctx Object with a `res` property, null or undefined.
36
+ * @param name The name of your cookie.
37
+ * @param value The value of your cookie.
38
+ * @param options Options that we pass down to `cookie` library.
39
+ */
40
+ declare function setCookie(ctx: {
41
+ res: NookiesResponse;
42
+ } | null | undefined, name: string, value: string, options?: cookie.SerializeOptions): {};
43
+ /**
44
+ * Destroys a cookie with a particular name.
45
+ *
46
+ * @param ctx Object with a `res` property, null or undefined.
47
+ * @param name Cookie name.
48
+ * @param options Options that we pass down to `cookie` library.
49
+ */
50
+ declare function destroyCookie(ctx: {
51
+ res: NookiesResponse;
52
+ } | null | undefined, name: string, options?: cookie.SerializeOptions): {};
53
+ declare const nookies: {
54
+ set: typeof setCookie;
55
+ get: typeof parseCookies;
56
+ destroy: typeof destroyCookie;
57
+ };
14
58
 
59
+ /** @deprecated Use {@link ColumnsProps} from `BaseGrid` instead. */
15
60
  interface ColumnTitleProps {
16
61
  name: string;
17
62
  label: string;
18
63
  transformer?: (value: string | number | Date) => string;
19
64
  sx?: TableCellProps['sx'];
20
65
  }
66
+ /** @deprecated Use {@link FilterProps} from `useFilter` instead. */
21
67
  interface FilterProps$1 {
22
68
  column: string;
23
69
  value: string;
24
70
  transformer?: (value: string | number | Date) => string;
25
71
  }
72
+ /** @deprecated Use {@link FilterProps} from `useFilter` instead. */
26
73
  type IFilter = FilterProps$1;
74
+ /** @deprecated */
27
75
  interface GridProps$1<T> {
28
76
  columnTitles: ColumnTitleProps[];
29
77
  defaultData: T[];
@@ -41,14 +89,22 @@ interface GridProps$1<T> {
41
89
  noFilters?: boolean;
42
90
  primaryKey?: string;
43
91
  }
92
+ /**
93
+ * @deprecated Use {@link BaseGrid} with the {@link useGrid} or {@link useAsyncGrid} hook instead.
94
+ * `BaseGrid` separates rendering from state management, eliminating the need to pass
95
+ * `tableData`, `setTableData`, `selectedFilters`, and `updateFilters` as props.
96
+ */
44
97
  declare const Grid: <ObjectType>(props: PropsWithChildren<GridProps$1<ObjectType>>) => React__default.JSX.Element;
45
98
 
99
+ /** @deprecated Use the `useFilter` hook instead. */
46
100
  declare function filterData<T>(filters: FilterProps$1[], defaultData: {
47
101
  current: T[];
48
102
  }): T[];
49
103
 
104
+ /** @deprecated Use `TableRow` from `@mui/material` directly. */
50
105
  declare const Tr: _mui_material_OverridableComponent.OverridableComponent<_mui_material.TableRowTypeMap<{}, "tr">>;
51
106
 
107
+ /** @deprecated Use `TableCell` from `@mui/material` directly. */
52
108
  declare const Td: typeof TableCell;
53
109
 
54
110
  interface EditableTableCellProps extends TableCellProps {
@@ -103,7 +159,7 @@ type SelectProps<T> = MuiSelectPropsWithouVariant<T> & {
103
159
  InputLabelProps?: Partial<CustomInputLabelProps>;
104
160
  helperText?: string;
105
161
  };
106
- declare function Select<T>({ withFormik, ...rest }: SelectProps<T>): React__default.JSX.Element;
162
+ declare function Select<T>({ withFormik, helperText, ...rest }: SelectProps<T>): React__default.JSX.Element;
107
163
 
108
164
  type MuiAutocompleteBaseProps<T> = Omit<AutocompleteProps$1<T, boolean, undefined, boolean>, 'renderInput' | 'getOptionLabel'>;
109
165
  interface AutocompleteWithoutProps<T> extends MuiAutocompleteBaseProps<T> {
@@ -138,12 +194,14 @@ type CheckboxProps = CheckboxWithFormik | CheckboxWithoutFormik;
138
194
  interface CheckboxWithFormik extends CheckboxProps$1 {
139
195
  name: string;
140
196
  label?: string;
197
+ helperText?: string;
141
198
  withFormik?: true;
142
199
  FormControlLabelProps?: Partial<FormControlLabelProps>;
143
200
  }
144
201
  interface CheckboxWithoutFormik extends CheckboxProps$1 {
145
202
  name?: never;
146
203
  label?: string;
204
+ helperText?: string;
147
205
  withFormik: false;
148
206
  FormControlLabelProps?: Partial<FormControlLabelProps>;
149
207
  }
@@ -153,12 +211,14 @@ type SwitchProps = SwitchWithFormik | SwitchWithoutFormik;
153
211
  interface SwitchWithFormik extends SwitchProps$1 {
154
212
  name: string;
155
213
  label?: string;
214
+ helperText?: string;
156
215
  withFormik?: true;
157
216
  FormControlLabelProps?: Partial<FormControlLabelProps>;
158
217
  }
159
218
  interface SwitchWithoutFormik extends SwitchProps$1 {
160
219
  name?: never;
161
220
  label?: string;
221
+ helperText?: string;
162
222
  withFormik: false;
163
223
  FormControlLabelProps?: Partial<FormControlLabelProps>;
164
224
  }
@@ -173,12 +233,14 @@ interface RadioWithFormik extends RadioGroupProps {
173
233
  name: string;
174
234
  label?: string;
175
235
  options: RadioOptionProps[];
236
+ helperText?: string;
176
237
  withFormik?: true;
177
238
  }
178
239
  interface RadioWithoutFormik extends RadioGroupProps {
179
240
  name?: never;
180
241
  label?: string;
181
242
  options: RadioOptionProps[];
243
+ helperText?: string;
182
244
  withFormik: false;
183
245
  }
184
246
  declare const Radio: ({ name, withFormik, ...rest }: RadioOptionsProps) => React__default.JSX.Element;
@@ -314,6 +376,9 @@ type TModalProps = {
314
376
  children: React__default.ReactNode;
315
377
  BoxProps?: BoxProps;
316
378
  } & Omit<ModalProps, 'children'>;
379
+ /**
380
+ * @deprecated Use `Dialog` or `BaseDialog` instead. `Modal` will be removed in a future release.
381
+ */
317
382
  declare const Modal: ({ open, onClose, BoxProps, ...rest }: TModalProps) => React__default.JSX.Element;
318
383
 
319
384
  declare function GetInputLabel<T extends Array<Record<string, any>>, K extends T[number]['name']>(columns: T): (columnName: K) => {
@@ -424,6 +489,42 @@ declare const BaseDialog: {
424
489
  Body: (props: IBaseDialogBodyProps) => React__default.JSX.Element;
425
490
  };
426
491
 
492
+ type FormHelperContextProps = {
493
+ formatErrorMessage: (message: any) => string;
494
+ api: AxiosInstance;
495
+ };
496
+ declare const FormHelperContext: React__default.Context<FormHelperContextProps>;
497
+ type FormHelperProviderProps = {
498
+ formatErrorMessage: (message: any) => string;
499
+ children: ReactNode;
500
+ api: AxiosInstance;
501
+ };
502
+ declare const FormHelperProvider: ({ formatErrorMessage, api, children }: FormHelperProviderProps) => React__default.JSX.Element;
503
+
504
+ type AlertContextProps = {
505
+ createAlert(message: string, type: AlertColor): void;
506
+ };
507
+ declare const AlertContext: React__default.Context<AlertContextProps>;
508
+ type AlertProviderProps = {
509
+ children: ReactNode;
510
+ };
511
+ declare const AlertProvider: ({ children }: AlertProviderProps) => React__default.JSX.Element;
512
+
513
+ type AuthenticateStatus = 'autenticated' | 'unauthenticated' | 'loading';
514
+ interface AuthContextProps<T> {
515
+ user?: T;
516
+ status: AuthenticateStatus;
517
+ signIn(credentials: Record<string, any>): Promise<boolean>;
518
+ signOut: () => Promise<void>;
519
+ }
520
+ declare function createAuthContext<T>(): React__default.Context<AuthContextProps<T>>;
521
+ declare function CreateAuthProvider<T>({ api, children, sessionTokenName, Provider }: {
522
+ Provider: Provider<AuthContextProps<T>>;
523
+ children: ReactNode;
524
+ api: AxiosInstance;
525
+ sessionTokenName: string;
526
+ }): React__default.JSX.Element;
527
+
427
528
  declare class HttpError extends Error {
428
529
  status: number;
429
530
  constructor(status: number, message: any);
@@ -433,18 +534,45 @@ declare class DomainError extends Error {
433
534
  constructor(message: any);
434
535
  }
435
536
 
537
+ interface HelperRequest {
538
+ url?: string;
539
+ method?: string;
540
+ headers: {
541
+ authorization?: string;
542
+ cookie?: string;
543
+ [key: string]: string | string[] | undefined;
544
+ };
545
+ cookies: Record<string, string>;
546
+ body?: any;
547
+ query?: Record<string, string | string[] | undefined>;
548
+ user?: any;
549
+ }
550
+ interface HelperResponse {
551
+ finished?: boolean;
552
+ status(code: number): HelperResponse;
553
+ json(data: any): any;
554
+ send(data: any): any;
555
+ end(data?: any): any;
556
+ getHeader(name: string): string | string[] | number | undefined;
557
+ setHeader(name: string, value: string | readonly string[]): any;
558
+ }
559
+ interface ServerSidePropsContext {
560
+ query: Record<string, string | string[] | undefined>;
561
+ res: HelperResponse;
562
+ }
563
+
436
564
  type PossibleMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'ALL';
437
- type NextHandlerApiRequest<T = string> = NextApiRequest & {
565
+ type NextHandlerApiRequest<T = string> = HelperRequest & {
438
566
  user?: T;
439
567
  };
440
- type HandlerProps<UserKeyType> = (req: NextHandlerApiRequest<UserKeyType>, res: NextApiResponse, options?: TApiOptions) => Promise<any>;
568
+ type HandlerProps<UserKeyType> = (req: NextHandlerApiRequest<UserKeyType>, res: HelperResponse, options?: TApiOptions) => Promise<any>;
441
569
  type MethodProps<T> = Partial<Record<PossibleMethods, HandlerProps<T>>>;
442
570
  type MiddlewaresProps<T> = ((handler: HandlerProps<T>, options?: TApiOptions) => HandlerProps<T>)[];
443
571
  type ConstructorProps$1<T> = {
444
572
  public?: boolean;
445
573
  middlewares?: MiddlewaresProps<T>;
446
- onFinally?: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
447
- onError?: (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
574
+ onFinally?: (req: HelperRequest, res: HelperResponse) => Promise<void>;
575
+ onError?: (req: HelperRequest, res: HelperResponse) => Promise<void>;
448
576
  };
449
577
  type TApiOptions = {
450
578
  public?: boolean;
@@ -456,9 +584,9 @@ declare class ApiHelper<T> {
456
584
  private onFinally;
457
585
  private onError;
458
586
  constructor(props?: ConstructorProps$1<T>);
459
- createMethods(methods: MethodProps<T>): (req: NextApiRequest, res: NextApiResponse) => Promise<any>;
587
+ createMethods(methods: MethodProps<T>): (req: HelperRequest, res: HelperResponse) => Promise<any>;
460
588
  private buildFactory;
461
- static build(factory: (req: NextHandlerApiRequest, res: NextApiResponse) => MethodProps<string>, options?: TApiOptions): (req: NextHandlerApiRequest, res: NextApiResponse) => Promise<any>;
589
+ static build(factory: (req: NextHandlerApiRequest, res: HelperResponse) => MethodProps<string>, options?: TApiOptions): (req: NextHandlerApiRequest, res: HelperResponse) => Promise<any>;
462
590
  static parse<Output, Def>(body: Record<string, any>, parser: ZodSchema<Output, Def>): Output;
463
591
  /** @deprecated Use {@link ApiHelper.parser} instead. */
464
592
  static parserErrorWrapper: typeof ApiHelper.parse;
@@ -468,23 +596,11 @@ declare class ApiHelper<T> {
468
596
  }): ApiHelper<unknown>;
469
597
  }
470
598
 
471
- type Methods = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options';
472
- type HandleProps = {
473
- name: `${Methods}:${string}`;
474
- };
475
- declare function useFormHelper(): {
476
- onSubmitWrapper: <T extends Record<string, any>>(fn: (fields: T, methods: any) => Promise<void>, { name }: HandleProps) => (fields: T, methods: any) => Promise<void>;
477
- onRequestWrapper: <F extends (...args: Parameters<F>) => R, R>(fn: F, { name }: HandleProps) => (...params: Parameters<F>) => Promise<R>;
478
- isLoading: (prop: string) => boolean;
479
- setLoading: (prop: string, remove?: boolean) => void;
480
- createAlert(message: string, type: _mui_material.AlertColor): void;
481
- };
482
-
483
- type NextApiRequestWithAuth = NextApiRequest & {
599
+ type AuthRequest = HelperRequest & {
484
600
  user?: any;
485
601
  };
486
602
  interface OnLoginSuccessResponse {
487
- status: 'sucess';
603
+ status: 'success';
488
604
  userId: string;
489
605
  }
490
606
  interface OnLoginFailedResponse {
@@ -525,7 +641,7 @@ declare class AuthHelper {
525
641
  onCreateRefreshToken: ConstructorProps['onCreateRefreshToken'];
526
642
  onGetUserData: ConstructorProps['onGetUserData'];
527
643
  constructor({ cookies, oauth, tokenExpTimeInSeconds, onLogin, onValidateRefreshToken, onInvalidateRefreshToken, onCreateRefreshToken, onGetUserData }: ConstructorProps);
528
- handler(req: NextApiRequestWithAuth, res: NextApiResponse): Promise<void>;
644
+ handler(req: AuthRequest, res: HelperResponse): Promise<any>;
529
645
  oauthSignInCallback(code: string): Promise<{
530
646
  decodedToken: {
531
647
  upn: string;
@@ -538,7 +654,7 @@ declare class AuthHelper {
538
654
  createOauthCallbackGetServerSideProps({ onSuccessDestination, onFailedDestination }: {
539
655
  onSuccessDestination: string;
540
656
  onFailedDestination?: string;
541
- }): (ctx: GetServerSidePropsContext) => Promise<{
657
+ }): (ctx: ServerSidePropsContext) => Promise<{
542
658
  redirect: {
543
659
  permanent: boolean;
544
660
  destination: string;
@@ -551,7 +667,7 @@ declare class AuthHelper {
551
667
  redirect?: undefined;
552
668
  }>;
553
669
  private generateJwtAndRefreshToken;
554
- invalidateCookies: (res: NextApiResponse) => NextApiResponse;
670
+ invalidateCookies: (res: HelperResponse) => any;
555
671
  }
556
672
 
557
673
  type SortedDirectionProps = 'asc' | 'desc';
@@ -620,82 +736,16 @@ declare const useAlert: () => {
620
736
  createAlert(message: string, type: _mui_material.AlertColor): void;
621
737
  };
622
738
 
623
- type FormHelperContextProps = {
624
- formatErrorMessage: (message: any) => string;
625
- api: AxiosInstance;
626
- };
627
- declare const FormHelperContext: React__default.Context<FormHelperContextProps>;
628
- type FormHelperProviderProps = {
629
- formatErrorMessage: (message: any) => string;
630
- children: ReactNode;
631
- api: AxiosInstance;
632
- };
633
- declare const FormHelperProvider: ({ formatErrorMessage, api, children }: FormHelperProviderProps) => React__default.JSX.Element;
634
-
635
- type AlertContextProps = {
636
- createAlert(message: string, type: AlertColor): void;
637
- };
638
- declare const AlertContext: React__default.Context<AlertContextProps>;
639
- type AlertProviderProps = {
640
- children: ReactNode;
739
+ type Methods = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options';
740
+ type HandleProps = {
741
+ name: `${Methods}:${string}`;
641
742
  };
642
- declare const AlertProvider: ({ children }: AlertProviderProps) => React__default.JSX.Element;
643
-
644
- type AuthenticateStatus = 'autenticated' | 'unauthenticated' | 'loading';
645
- interface AuthContextProps<T> {
646
- user?: T;
647
- status: AuthenticateStatus;
648
- signIn(credentials: Record<string, any>): Promise<boolean>;
649
- signOut: () => Promise<void>;
650
- }
651
- declare function createAuthContext<T>(): React__default.Context<AuthContextProps<T>>;
652
- declare function CreateAuthProvider<T>({ api, children, sessionTokenName, Provider }: {
653
- Provider: Provider<AuthContextProps<T>>;
654
- children: ReactNode;
655
- api: AxiosInstance;
656
- sessionTokenName: string;
657
- }): React__default.JSX.Element;
658
-
659
- /**
660
- * Parses cookies.
661
- *
662
- * @param ctx NextJS page or API context, express context, null or undefined.
663
- * @param options Options that we pass down to `cookie` library.
664
- */
665
- declare function parseCookies(ctx?: Pick<next.NextPageContext, 'req'> | {
666
- req: next.NextApiRequest;
667
- } | {
668
- req: express.Request;
669
- } | null | undefined, options?: cookie.ParseOptions): cookie.Cookies;
670
- /**
671
- * Sets a cookie.
672
- *
673
- * @param ctx NextJS page or API context, express context, null or undefined.
674
- * @param name The name of your cookie.
675
- * @param value The value of your cookie.
676
- * @param options Options that we pass down to `cookie` library.
677
- */
678
- declare function setCookie(ctx: Pick<next.NextPageContext, 'res'> | {
679
- res: next.NextApiResponse;
680
- } | {
681
- res: express.Response;
682
- } | null | undefined, name: string, value: string, options?: cookie.SerializeOptions): {};
683
- /**
684
- * Destroys a cookie with a particular name.
685
- *
686
- * @param ctx NextJS page or API context, express context, null or undefined.
687
- * @param name Cookie name.
688
- * @param options Options that we pass down to `cookie` library.
689
- */
690
- declare function destroyCookie(ctx: Pick<next.NextPageContext, 'res'> | {
691
- res: next.NextApiResponse;
692
- } | {
693
- res: express.Response;
694
- } | null | undefined, name: string, options?: cookie.SerializeOptions): {};
695
- declare const nookies: {
696
- set: typeof setCookie;
697
- get: typeof parseCookies;
698
- destroy: typeof destroyCookie;
743
+ declare function useFormHelper(): {
744
+ onSubmitWrapper: <T extends Record<string, any>>(fn: (fields: T, methods: any) => Promise<void>, { name }: HandleProps) => (fields: T, methods: any) => Promise<void>;
745
+ onRequestWrapper: <F extends (...args: Parameters<F>) => R, R>(fn: F, { name }: HandleProps) => (...params: Parameters<F>) => Promise<R>;
746
+ isLoading: (prop: string) => boolean;
747
+ setLoading: (prop: string, remove?: boolean) => void;
748
+ createAlert(message: string, type: _mui_material.AlertColor): void;
699
749
  };
700
750
 
701
- 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, type HandlerProps, HttpError, type IBaseDialogBodyProps, type IBaseDialogContainerProps, type IBaseDialogTriggerProps, type IDialogConfirmProps, type IFilter, Input, InputMask, LargeButton, type MethodProps, Modal, Radio, Select, type SortedByProps$1 as SortedByProps, Switch, type TApiOptions, 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 };
751
+ 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, type HandlerProps, type HelperRequest, type HelperResponse, HttpError, type IBaseDialogBodyProps, type IBaseDialogContainerProps, type IBaseDialogTriggerProps, type IDialogConfirmProps, type IFilter, Input, InputMask, LargeButton, type MethodProps, type MiddlewaresProps, Modal, type NextHandlerApiRequest, type NookiesRequest, type NookiesResponse, Radio, Select, type ServerSidePropsContext, type SortedByProps$1 as SortedByProps, Switch, type TApiOptions, 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 };