@povio/ui 0.0.7 → 0.0.9
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/assets/icons/Calendar.js +1 -1
- package/dist/assets/icons/CheckCircle.js +3 -3
- package/dist/assets/icons/ChevronsLeft.js +11 -22
- package/dist/assets/icons/ChevronsRight.js +11 -22
- package/dist/assets/icons/DateTime.js +13 -6
- package/dist/assets/icons/Drag.js +1 -1
- package/dist/assets/icons/File.js +1 -1
- package/dist/assets/icons/Info.js +2 -4
- package/dist/assets/icons/Menu.js +1 -3
- package/dist/assets/icons/Send.js +1 -1
- package/dist/assets/icons/Upload.js +2 -2
- package/dist/assets/icons/{Warningfilled.js → WarningFilled.js} +1 -1
- package/dist/components/Menu/MenuPopover.js +1 -1
- package/dist/components/buttons/PillButton/pillButton.cva.js +1 -1
- package/dist/components/inputs/Checkbox/checkbox.cva.js +1 -1
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.js +7 -4
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +10 -4
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +7 -4
- package/dist/components/inputs/DateTime/shared/DatePickerInput.js +16 -5
- package/dist/components/inputs/DateTime/shared/DateSegmentItem.js +3 -2
- package/dist/components/inputs/DateTime/shared/TimePickerInput.js +30 -23
- package/dist/components/inputs/File/FileUpload.js +1 -1
- package/dist/components/inputs/File/InputUpload.js +1 -1
- package/dist/components/inputs/File/shared/FileUploadContentError.js +1 -1
- package/dist/components/inputs/File/shared/InputUploadContent.js +10 -4
- package/dist/components/inputs/File/shared/InputUploadFilled.js +36 -22
- package/dist/components/inputs/File/shared/fileUpload.cva.js +3 -2
- package/dist/components/inputs/File/shared/inputUploadButton.cva.js +6 -5
- package/dist/components/inputs/FormField/FormFieldLabel.d.ts +3 -2
- package/dist/components/inputs/FormField/FormFieldLabel.js +8 -2
- package/dist/components/inputs/Input/TextArea/TextArea.js +6 -9
- package/dist/components/inputs/Input/TextInput/TextInput.d.ts +1 -0
- package/dist/components/inputs/Input/TextInput/TextInput.js +26 -3
- package/dist/components/inputs/Input/shared/InputContent.js +67 -59
- package/dist/components/inputs/Selection/shared/SelectBase.d.ts +3 -2
- package/dist/components/inputs/Selection/shared/SelectBase.js +2 -1
- package/dist/components/inputs/Selection/shared/SelectInput.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectInput.js +84 -90
- package/dist/components/inputs/Selection/shared/SelectInputTags.d.ts +11 -0
- package/dist/components/inputs/Selection/shared/SelectInputTags.js +22 -0
- package/dist/components/inputs/Selection/shared/SelectListBox.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectListBox.js +56 -45
- package/dist/components/inputs/Selection/shared/select.context.js +1 -0
- package/dist/components/inputs/Selection/shared/select.types.d.ts +8 -0
- package/dist/components/inputs/shared/InputClear.d.ts +3 -1
- package/dist/components/inputs/shared/InputClear.js +4 -3
- package/dist/components/inputs/shared/input.cva.js +18 -17
- package/dist/components/inputs/shared/label.cva.js +2 -2
- package/dist/components/overlays/BottomSheet/BottomSheet.js +17 -12
- package/dist/components/overlays/Tooltip/Tooltip.d.ts +4 -2
- package/dist/components/overlays/Tooltip/Tooltip.js +32 -6
- package/dist/components/overlays/Tooltip/tooltip.cva.d.ts +21 -0
- package/dist/components/overlays/Tooltip/tooltip.cva.js +60 -0
- package/dist/components/segment/Segment.js +8 -2
- package/dist/components/segment/SegmentItem.js +4 -2
- package/dist/components/table/CellText.js +2 -2
- package/dist/components/table/HeaderText.js +1 -1
- package/dist/components/table/Table.js +34 -16
- package/dist/components/table/table.cva.d.ts +7 -3
- package/dist/components/table/table.cva.js +37 -11
- package/dist/config/uiConfig.context.d.ts +3 -1
- package/dist/config/uiConfig.context.js +6 -1
- package/dist/config/uiStyle.context.d.ts +2 -1
- package/dist/helpers/dynamicColumns.js +2 -2
- package/dist/helpers/dynamicInputs.d.ts +2 -0
- package/dist/helpers/dynamicInputs.js +5 -3
- package/dist/hooks/useAutosave.js +4 -1
- package/dist/hooks/useTableColumnConfig.js +5 -1
- package/dist/index.d.ts +12 -6
- package/dist/index.js +15 -11
- package/dist/utils/date-time.utils.js +12 -12
- package/dist/utils/dom.utils.js +2 -2
- package/dist/utils/file.utils.js +1 -1
- package/dist/utils/isEqual.js +2 -1
- package/dist/utils/object.utils.js +2 -2
- package/dist/utils/{rest/rest.utils.js → rest.utils.js} +1 -1
- package/dist/utils/vendor/acl/AclGuard.d.ts +8 -0
- package/dist/utils/vendor/acl/AclGuard.js +15 -0
- package/dist/utils/vendor/acl/Can.d.ts +9 -0
- package/dist/utils/vendor/acl/Can.js +18 -0
- package/dist/utils/vendor/acl/ability.context.d.ts +15 -0
- package/dist/utils/vendor/acl/ability.context.js +37 -0
- package/dist/utils/vendor/acl/appAbility.types.d.ts +3 -0
- package/dist/utils/vendor/auth/AuthGuard.d.ts +6 -0
- package/dist/utils/vendor/auth/AuthGuard.js +26 -0
- package/dist/utils/vendor/auth/auth.context.d.ts +21 -0
- package/dist/utils/vendor/auth/auth.context.js +36 -0
- package/dist/utils/vendor/auth/withPrivateAuthGuard.d.ts +6 -0
- package/dist/utils/vendor/auth/withPrivateAuthGuard.js +17 -0
- package/dist/utils/vendor/error-handling.js +1 -1
- package/dist/utils/{rest/rest-client.d.ts → vendor/rest-client.types.d.ts} +8 -14
- package/dist/utils/zod.utils.d.ts +2 -1
- package/package.json +2 -2
- package/dist/hooks/useSingletonMutation.d.ts +0 -4
- package/dist/hooks/useSingletonMutation.js +0 -27
- package/dist/utils/rest/interceptors/logging.interceptor.d.ts +0 -2
- package/dist/utils/rest/interceptors/logging.interceptor.js +0 -17
- package/dist/utils/rest/interceptors/response.interceptor.d.ts +0 -2
- package/dist/utils/rest/interceptors/response.interceptor.js +0 -25
- package/dist/utils/rest/rest-client.js +0 -62
- /package/dist/assets/icons/{Warningfilled.d.ts → WarningFilled.d.ts} +0 -0
- /package/dist/utils/{rest/rest.utils.d.ts → rest.utils.d.ts} +0 -0
- /package/dist/utils/{rest/interceptors → vendor}/rest-interceptor.d.ts +0 -0
- /package/dist/utils/{rest/interceptors → vendor}/rest-interceptor.js +0 -0
package/dist/index.js
CHANGED
|
@@ -110,7 +110,6 @@ import { useLocalStorage } from "./hooks/useLocalStorage.js";
|
|
|
110
110
|
import { useLongPressRepeat } from "./hooks/useLongPressRepeat.js";
|
|
111
111
|
import { usePagination } from "./hooks/usePagination.js";
|
|
112
112
|
import { useScrollableListBox } from "./hooks/useScrollableListBox.js";
|
|
113
|
-
import { useSingletonMutation } from "./hooks/useSingletonMutation.js";
|
|
114
113
|
import { useSorting } from "./hooks/useSorting.js";
|
|
115
114
|
import { useStateAndRef } from "./hooks/useStateAndRef.js";
|
|
116
115
|
import { useTableColumnConfig } from "./hooks/useTableColumnConfig.js";
|
|
@@ -126,15 +125,19 @@ import { isEqual } from "./utils/isEqual.js";
|
|
|
126
125
|
import { logger } from "./utils/logger.js";
|
|
127
126
|
import { ObjectUtils } from "./utils/object.utils.js";
|
|
128
127
|
import { QueriesUtils } from "./utils/queries.utils.js";
|
|
129
|
-
import {
|
|
130
|
-
import { ResponseInterceptor } from "./utils/rest/interceptors/response.interceptor.js";
|
|
131
|
-
import { RestInterceptor } from "./utils/rest/interceptors/rest-interceptor.js";
|
|
132
|
-
import { RestUtils } from "./utils/rest/rest.utils.js";
|
|
133
|
-
import { RestClient } from "./utils/rest/rest-client.js";
|
|
128
|
+
import { RestUtils } from "./utils/rest.utils.js";
|
|
134
129
|
import { RoutingUtils } from "./utils/routing.utils.js";
|
|
135
130
|
import { StringUtils } from "./utils/string.utils.js";
|
|
131
|
+
import { createAclGuard } from "./utils/vendor/acl/AclGuard.js";
|
|
132
|
+
import { AbilityContext } from "./utils/vendor/acl/ability.context.js";
|
|
133
|
+
import { Can } from "./utils/vendor/acl/Can.js";
|
|
134
|
+
import { AuthGuard } from "./utils/vendor/auth/AuthGuard.js";
|
|
135
|
+
import { AuthContext } from "./utils/vendor/auth/auth.context.js";
|
|
136
|
+
import { withPrivateAuthGuard } from "./utils/vendor/auth/withPrivateAuthGuard.js";
|
|
136
137
|
import { ApplicationException, ErrorHandler, SharedErrorHandler } from "./utils/vendor/error-handling.js";
|
|
138
|
+
import { RestInterceptor } from "./utils/vendor/rest-interceptor.js";
|
|
137
139
|
export {
|
|
140
|
+
AbilityContext,
|
|
138
141
|
ActionModal,
|
|
139
142
|
Alert,
|
|
140
143
|
AlignCenterIcon,
|
|
@@ -147,12 +150,15 @@ export {
|
|
|
147
150
|
ArrowDropUpIcon,
|
|
148
151
|
ArrowLeftIcon,
|
|
149
152
|
ArrowRightIcon,
|
|
153
|
+
AuthContext,
|
|
154
|
+
AuthGuard,
|
|
150
155
|
Autocomplete,
|
|
151
156
|
BoldIcon,
|
|
152
157
|
BottomSheet,
|
|
153
158
|
BulletedListIcon,
|
|
154
159
|
Button,
|
|
155
160
|
CalendarIcon,
|
|
161
|
+
Can,
|
|
156
162
|
CellText,
|
|
157
163
|
CheckIcon,
|
|
158
164
|
Checkbox,
|
|
@@ -195,7 +201,6 @@ export {
|
|
|
195
201
|
Link,
|
|
196
202
|
LinkIcon,
|
|
197
203
|
Loader,
|
|
198
|
-
LoggingInterceptor,
|
|
199
204
|
Menu,
|
|
200
205
|
MenuIcon,
|
|
201
206
|
MenuPopover,
|
|
@@ -213,9 +218,7 @@ export {
|
|
|
213
218
|
QueriesUtils,
|
|
214
219
|
QueryAutocomplete,
|
|
215
220
|
RadioGroup,
|
|
216
|
-
ResponseInterceptor,
|
|
217
221
|
ResponsivePopover,
|
|
218
|
-
RestClient,
|
|
219
222
|
RestInterceptor,
|
|
220
223
|
RestUtils,
|
|
221
224
|
RoutingUtils,
|
|
@@ -249,6 +252,7 @@ export {
|
|
|
249
252
|
ViewIcon,
|
|
250
253
|
ViewOffIcon,
|
|
251
254
|
compoundMapper,
|
|
255
|
+
createAclGuard,
|
|
252
256
|
dynamicColumns,
|
|
253
257
|
dynamicInputs,
|
|
254
258
|
isEqual,
|
|
@@ -270,11 +274,11 @@ export {
|
|
|
270
274
|
useLongPressRepeat,
|
|
271
275
|
usePagination,
|
|
272
276
|
useScrollableListBox,
|
|
273
|
-
useSingletonMutation,
|
|
274
277
|
useSorting,
|
|
275
278
|
useStateAndRef,
|
|
276
279
|
useTableColumnConfig,
|
|
277
280
|
useTableNav,
|
|
278
281
|
useToast,
|
|
279
|
-
useTranslationMemo
|
|
282
|
+
useTranslationMemo,
|
|
283
|
+
withPrivateAuthGuard
|
|
280
284
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { parseAbsoluteToLocal, getLocalTimeZone, fromDate, CalendarDate, parseAbsolute
|
|
2
|
-
import { DateTime } from "luxon";
|
|
1
|
+
import { parseAbsoluteToLocal, getLocalTimeZone, fromDate, CalendarDateTime, CalendarDate, parseAbsolute } from "@internationalized/date";
|
|
3
2
|
var DateTimeUtils;
|
|
4
3
|
((DateTimeUtils2) => {
|
|
5
4
|
function fromISOtoZonedDateTime(isoString) {
|
|
@@ -19,18 +18,19 @@ var DateTimeUtils;
|
|
|
19
18
|
}
|
|
20
19
|
DateTimeUtils2.fromDateValueToLocal = fromDateValueToLocal;
|
|
21
20
|
function fromCalendarDateToUTCISO(calendarDate, options = {}) {
|
|
22
|
-
const date = DateTime.fromObject(
|
|
23
|
-
{
|
|
24
|
-
year: calendarDate.year,
|
|
25
|
-
month: calendarDate.month,
|
|
26
|
-
day: calendarDate.day
|
|
27
|
-
},
|
|
28
|
-
{ zone: "utc" }
|
|
29
|
-
);
|
|
30
21
|
if (options.endOfDay) {
|
|
31
|
-
|
|
22
|
+
const calendarDateTime = new CalendarDateTime(
|
|
23
|
+
calendarDate.year,
|
|
24
|
+
calendarDate.month,
|
|
25
|
+
calendarDate.day,
|
|
26
|
+
23,
|
|
27
|
+
59,
|
|
28
|
+
59,
|
|
29
|
+
999
|
|
30
|
+
);
|
|
31
|
+
return calendarDateTime.toDate("UTC").toISOString();
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return calendarDate.toDate("UTC").toISOString();
|
|
34
34
|
}
|
|
35
35
|
DateTimeUtils2.fromCalendarDateToUTCISO = fromCalendarDateToUTCISO;
|
|
36
36
|
function fromUTCISOToCalendarDate(isoString) {
|
package/dist/utils/dom.utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var DomUtils;
|
|
2
2
|
((DomUtils2) => {
|
|
3
|
-
const KEYBOARD_INPUTS = ["button", "submit", "checkbox", "file", "image"];
|
|
3
|
+
const KEYBOARD_INPUTS = /* @__PURE__ */ new Set(["button", "submit", "checkbox", "file", "image"]);
|
|
4
4
|
DomUtils2.isKeyboardInput = (elem) => {
|
|
5
|
-
return elem.tagName === "INPUT" && !KEYBOARD_INPUTS.
|
|
5
|
+
return elem.tagName === "INPUT" && !KEYBOARD_INPUTS.has(elem.type) || elem.hasAttribute("contenteditable");
|
|
6
6
|
};
|
|
7
7
|
DomUtils2.isKeyboardEvent = (event) => {
|
|
8
8
|
return event.nativeEvent instanceof KeyboardEvent;
|
package/dist/utils/file.utils.js
CHANGED
package/dist/utils/isEqual.js
CHANGED
|
@@ -80,7 +80,8 @@ const deepEq = (a, b, aStack, bStack) => {
|
|
|
80
80
|
}
|
|
81
81
|
while (length--) {
|
|
82
82
|
key = keys[length];
|
|
83
|
-
if (!(Object.prototype.hasOwnProperty.call(b, key) &&
|
|
83
|
+
if (!(Object.prototype.hasOwnProperty.call(b, key) && // oxlint-disable-next-line no-explicit-any
|
|
84
|
+
eq(a[key], b[key], aStack, bStack))) {
|
|
84
85
|
return false;
|
|
85
86
|
}
|
|
86
87
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var ObjectUtils;
|
|
2
2
|
((ObjectUtils2) => {
|
|
3
3
|
ObjectUtils2.isNil = (obj) => {
|
|
4
|
-
return obj
|
|
4
|
+
return obj === null || obj === void 0;
|
|
5
5
|
};
|
|
6
6
|
ObjectUtils2.isFunction = (obj) => {
|
|
7
7
|
return typeof obj === "function";
|
|
@@ -19,7 +19,7 @@ var ObjectUtils;
|
|
|
19
19
|
return Object.prototype.toString.call(obj) === "[object RegExp]";
|
|
20
20
|
};
|
|
21
21
|
ObjectUtils2.isEmpty = (obj) => {
|
|
22
|
-
if (obj
|
|
22
|
+
if (obj === null || obj === void 0) {
|
|
23
23
|
return true;
|
|
24
24
|
}
|
|
25
25
|
if (Array.isArray(obj) || (0, ObjectUtils2.isString)(obj)) {
|
|
@@ -20,7 +20,7 @@ var RestUtils;
|
|
|
20
20
|
};
|
|
21
21
|
RestUtils2.doesServerErrorMessageContain = (e, text) => {
|
|
22
22
|
const message = (0, RestUtils2.extractServerErrorMessage)(e);
|
|
23
|
-
if (message
|
|
23
|
+
if (message === null || message === void 0) {
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
return message.toLowerCase().includes(text.toLowerCase());
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WithPrivateAuthGuardProps } from '../auth/withPrivateAuthGuard';
|
|
2
|
+
import { AppAbilities } from './appAbility.types';
|
|
3
|
+
export declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ privateAuthGuardProps, ...props }: {
|
|
4
|
+
canUse: TAppAbilities;
|
|
5
|
+
redirectTo?: string;
|
|
6
|
+
} & {
|
|
7
|
+
children?: import('react').ReactNode | undefined;
|
|
8
|
+
} & WithPrivateAuthGuardProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { UIRouter } from "../../../config/router.context.js";
|
|
2
|
+
import { AbilityContext } from "./ability.context.js";
|
|
3
|
+
import { withPrivateAuthGuard } from "../auth/withPrivateAuthGuard.js";
|
|
4
|
+
const createAclGuard = () => withPrivateAuthGuard(({ canUse, redirectTo = "/", children }) => {
|
|
5
|
+
const ability = AbilityContext.useAbility();
|
|
6
|
+
const { replace } = UIRouter.useUIRouter();
|
|
7
|
+
if (!ability.can(canUse[0], canUse[1])) {
|
|
8
|
+
replace(redirectTo);
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return children;
|
|
12
|
+
});
|
|
13
|
+
export {
|
|
14
|
+
createAclGuard
|
|
15
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbilityTuple, PureAbility } from '@casl/ability';
|
|
2
|
+
import { BoundCanProps } from '@casl/react';
|
|
3
|
+
import { AppAbilities } from './appAbility.types';
|
|
4
|
+
type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
|
|
5
|
+
type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
|
|
6
|
+
use: TAppAbilities;
|
|
7
|
+
} & Omit<BoundCanProps<CanAbility>, "do" | "I" | "on" | "a" | "an" | "this">;
|
|
8
|
+
export declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({ use, ...props }: CanProps<TAppAbilities>) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContextualCan } from "@casl/react";
|
|
3
|
+
import { AbilityContext } from "./ability.context.js";
|
|
4
|
+
const ContextualCan = createContextualCan(AbilityContext.Consumer);
|
|
5
|
+
const Can = ({ use, ...props }) => {
|
|
6
|
+
const [action, subject] = use;
|
|
7
|
+
return /* @__PURE__ */ jsx(
|
|
8
|
+
ContextualCan,
|
|
9
|
+
{
|
|
10
|
+
...props,
|
|
11
|
+
do: action,
|
|
12
|
+
on: subject
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
Can
|
|
18
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PureAbility, RawRuleOf } from '@casl/ability';
|
|
2
|
+
import { PackRule } from '@casl/ability/extra';
|
|
3
|
+
import { PropsWithChildren } from 'react';
|
|
4
|
+
import { AppAbilities, AppAbility } from './appAbility.types';
|
|
5
|
+
export declare namespace AbilityContext {
|
|
6
|
+
export const Consumer: import("react").Consumer<AppAbility>;
|
|
7
|
+
interface ProviderProps {
|
|
8
|
+
user?: {
|
|
9
|
+
aclRules?: PackRule<RawRuleOf<AppAbility>>[];
|
|
10
|
+
} | null;
|
|
11
|
+
}
|
|
12
|
+
export const Provider: ({ children }: PropsWithChildren<ProviderProps>) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities>;
|
|
14
|
+
export {};
|
|
15
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
3
|
+
import { unpackRules } from "@casl/ability/extra";
|
|
4
|
+
import { useAbility } from "@casl/react";
|
|
5
|
+
import { createContext, useState, useEffect } from "react";
|
|
6
|
+
import { AuthContext } from "../auth/auth.context.js";
|
|
7
|
+
var AbilityContext;
|
|
8
|
+
((AbilityContext2) => {
|
|
9
|
+
const createAppAbilityBuilder = () => new AbilityBuilder(createMongoAbility);
|
|
10
|
+
const initialAppAbility = createAppAbilityBuilder().build();
|
|
11
|
+
const Context = createContext({});
|
|
12
|
+
({ Consumer: AbilityContext2.Consumer } = Context);
|
|
13
|
+
AbilityContext2.Provider = ({ children }) => {
|
|
14
|
+
const [ability, setAbility] = useState(initialAppAbility);
|
|
15
|
+
const { user } = AuthContext.useAuth();
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!user || !("aclRules" in user)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const { can, build } = createAppAbilityBuilder();
|
|
21
|
+
const packedRules = user.aclRules;
|
|
22
|
+
const rules = unpackRules(packedRules);
|
|
23
|
+
rules.forEach(({ action, subject, conditions }) => {
|
|
24
|
+
can(action, subject, conditions);
|
|
25
|
+
});
|
|
26
|
+
setAbility(build());
|
|
27
|
+
}, [user]);
|
|
28
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value: ability, children });
|
|
29
|
+
};
|
|
30
|
+
AbilityContext2.useAbility = () => {
|
|
31
|
+
const ability = useAbility(Context);
|
|
32
|
+
return ability;
|
|
33
|
+
};
|
|
34
|
+
})(AbilityContext || (AbilityContext = {}));
|
|
35
|
+
export {
|
|
36
|
+
AbilityContext
|
|
37
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
export interface AuthGuardProps {
|
|
3
|
+
type: "public-only" | "private";
|
|
4
|
+
redirectTo?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const AuthGuard: ({ type, redirectTo, children }: PropsWithChildren<AuthGuardProps>) => import('react').ReactNode;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { UIRouter } from "../../../config/router.context.js";
|
|
3
|
+
import { AuthContext } from "./auth.context.js";
|
|
4
|
+
const AuthGuard = ({ type, redirectTo, children }) => {
|
|
5
|
+
const { isAuthenticated, routes, loadingState } = AuthContext.useAuth();
|
|
6
|
+
const { replace } = UIRouter.useUIRouter();
|
|
7
|
+
const [hasMounted, setHasMounted] = useState(false);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
setHasMounted(true);
|
|
10
|
+
}, []);
|
|
11
|
+
if (!hasMounted) {
|
|
12
|
+
return loadingState;
|
|
13
|
+
}
|
|
14
|
+
if (type === "private" && !isAuthenticated) {
|
|
15
|
+
replace(redirectTo || routes?.unauthenticated || "/");
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (type === "public-only" && isAuthenticated) {
|
|
19
|
+
replace(redirectTo || routes?.authenticated || "/");
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return children;
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
AuthGuard
|
|
26
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
export declare namespace AuthContext {
|
|
3
|
+
export interface Routes {
|
|
4
|
+
authenticated?: string;
|
|
5
|
+
unauthenticated?: string;
|
|
6
|
+
}
|
|
7
|
+
interface Type<TUser = unknown> {
|
|
8
|
+
isAuthenticated: boolean;
|
|
9
|
+
isInitializing: boolean;
|
|
10
|
+
logout: () => void;
|
|
11
|
+
updateTokens?: (accessToken: string | null, refreshToken?: string | null) => void;
|
|
12
|
+
accessToken?: string | null;
|
|
13
|
+
user?: TUser | null;
|
|
14
|
+
routes?: Routes;
|
|
15
|
+
loadingState?: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
type ProviderProps<TUser = unknown> = Type<TUser>;
|
|
18
|
+
export const Provider: <TUser = unknown>({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, routes, loadingState, children, }: PropsWithChildren<ProviderProps<TUser>>) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export const useAuth: <TUser = unknown>() => Type<TUser>;
|
|
20
|
+
export {};
|
|
21
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, use } from "react";
|
|
3
|
+
var AuthContext;
|
|
4
|
+
((AuthContext2) => {
|
|
5
|
+
const Context = createContext({});
|
|
6
|
+
AuthContext2.Provider = ({
|
|
7
|
+
isAuthenticated,
|
|
8
|
+
isInitializing,
|
|
9
|
+
logout,
|
|
10
|
+
updateTokens,
|
|
11
|
+
accessToken,
|
|
12
|
+
user,
|
|
13
|
+
routes,
|
|
14
|
+
loadingState,
|
|
15
|
+
children
|
|
16
|
+
}) => {
|
|
17
|
+
const value = {
|
|
18
|
+
isAuthenticated,
|
|
19
|
+
isInitializing,
|
|
20
|
+
logout,
|
|
21
|
+
updateTokens,
|
|
22
|
+
accessToken,
|
|
23
|
+
user,
|
|
24
|
+
routes,
|
|
25
|
+
loadingState
|
|
26
|
+
};
|
|
27
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value, children });
|
|
28
|
+
};
|
|
29
|
+
AuthContext2.useAuth = () => {
|
|
30
|
+
const auth = use(Context);
|
|
31
|
+
return auth;
|
|
32
|
+
};
|
|
33
|
+
})(AuthContext || (AuthContext = {}));
|
|
34
|
+
export {
|
|
35
|
+
AuthContext
|
|
36
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ComponentType, PropsWithChildren } from 'react';
|
|
2
|
+
import { AuthGuardProps } from './AuthGuard';
|
|
3
|
+
export interface WithPrivateAuthGuardProps {
|
|
4
|
+
privateAuthGuardProps?: Omit<AuthGuardProps, "type">;
|
|
5
|
+
}
|
|
6
|
+
export declare const withPrivateAuthGuard: <T extends PropsWithChildren & WithPrivateAuthGuardProps>(WrappedComponent: ComponentType<T & WithPrivateAuthGuardProps>) => ({ privateAuthGuardProps, ...props }: T & WithPrivateAuthGuardProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AuthGuard } from "./AuthGuard.js";
|
|
3
|
+
const withPrivateAuthGuard = (WrappedComponent) => {
|
|
4
|
+
return ({ privateAuthGuardProps, ...props }) => {
|
|
5
|
+
return /* @__PURE__ */ jsx(
|
|
6
|
+
AuthGuard,
|
|
7
|
+
{
|
|
8
|
+
type: "private",
|
|
9
|
+
...privateAuthGuardProps,
|
|
10
|
+
children: /* @__PURE__ */ jsx(WrappedComponent, { ...props })
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
withPrivateAuthGuard
|
|
17
|
+
};
|
|
@@ -3,7 +3,7 @@ import i18next from "i18next";
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { ns } from "../../config/i18n.js";
|
|
5
5
|
import { logger } from "../logger.js";
|
|
6
|
-
import { RestUtils } from "../rest
|
|
6
|
+
import { RestUtils } from "../rest.utils.js";
|
|
7
7
|
class ApplicationException extends Error {
|
|
8
8
|
constructor(message, code, serverMessage) {
|
|
9
9
|
super(message);
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { ErrorHandler } from './error-handling';
|
|
4
|
+
import { RestInterceptor } from './rest-interceptor';
|
|
5
|
+
export type GeneralErrorCodes = string;
|
|
6
|
+
export interface RequestInfo<ZOutput, ECodes extends string> {
|
|
6
7
|
resSchema: z.ZodType<ZOutput>;
|
|
7
8
|
errorHandler?: ErrorHandler<ECodes>;
|
|
8
9
|
}
|
|
9
|
-
interface RequestConfig<IsRawRes extends boolean = false> {
|
|
10
|
+
export interface RequestConfig<IsRawRes extends boolean = false> {
|
|
10
11
|
rawResponse?: IsRawRes;
|
|
11
12
|
}
|
|
12
|
-
type Response<ZOutput, IsRawRes extends boolean = false> = IsRawRes extends true ? AxiosResponse<ZOutput> : ZOutput;
|
|
13
|
-
export
|
|
14
|
-
protected client: AxiosInstance;
|
|
15
|
-
constructor({ config, interceptors, }?: {
|
|
16
|
-
config?: CreateAxiosDefaults;
|
|
17
|
-
interceptors?: RestInterceptor<any[]>[];
|
|
18
|
-
});
|
|
13
|
+
export type Response<ZOutput, IsRawRes extends boolean = false> = IsRawRes extends true ? AxiosResponse<ZOutput> : ZOutput;
|
|
14
|
+
export interface RestClient {
|
|
19
15
|
attachInterceptors<T extends any[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
|
|
20
16
|
attachInterceptor<T extends any[]>(interceptor: RestInterceptor<T>, ...args: T): void;
|
|
21
17
|
ejectInterceptor<T extends any[]>(interceptor: RestInterceptor<T>): void;
|
|
@@ -24,6 +20,4 @@ export declare class RestClient {
|
|
|
24
20
|
patch<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
|
|
25
21
|
put<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
|
|
26
22
|
delete<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
|
|
27
|
-
private makeRequest;
|
|
28
23
|
}
|
|
29
|
-
export {};
|
|
@@ -4,6 +4,7 @@ export declare namespace ZodUtils {
|
|
|
4
4
|
type IsZodType<T, Z> = UnwrapZod<T> extends Z ? true : false;
|
|
5
5
|
type IsZodNumber<T> = IsZodType<T, z.ZodNumber>;
|
|
6
6
|
type IsZodEnum<T> = IsZodType<T, z.ZodEnum<any>>;
|
|
7
|
+
type IsZodUUID<T> = IsZodType<T, z.ZodUUID>;
|
|
7
8
|
type IsZodDateTime<T> = IsZodType<T, z.ZodISODateTime>;
|
|
8
9
|
type IsZodString<T> = IsZodType<T, z.ZodString>;
|
|
9
10
|
type IsZodEmail<T> = IsZodType<T, z.ZodEmail>;
|
|
@@ -11,7 +12,7 @@ export declare namespace ZodUtils {
|
|
|
11
12
|
type IsZodTextEditor<T> = UnwrapZod<T> extends z.ZodObject ? UnwrapZod<UnwrapZod<T>["shape"]["html"]> extends z.ZodString ? UnwrapZod<UnwrapZod<T>["shape"]["json"]> extends z.ZodObject<any> ? true : false : false : false;
|
|
12
13
|
type IsZodObject<T> = IsZodType<T, z.ZodObject<any>>;
|
|
13
14
|
type IsZodArray<T> = IsZodType<T, z.ZodArray<any>>;
|
|
14
|
-
type ZodType<T> = IsZodType<T, z.ZodBoolean> extends true ? "boolean" : IsZodNumber<T> extends true ? "number" : IsZodEnum<T> extends true ? "enum" : IsZodDateTime<T> extends true ? "datetime" : IsZodString<T> extends true ? "string" : IsZodEmail<T> extends true ? "email" : IsZodDateRange<T> extends true ? "dateRange" : IsZodTextEditor<T> extends true ? "textEditor" : IsZodObject<T> extends true ? "object" : IsZodArray<T> extends true ? "array" : never;
|
|
15
|
+
type ZodType<T> = IsZodType<T, z.ZodBoolean> extends true ? "boolean" : IsZodNumber<T> extends true ? "number" : IsZodEnum<T> extends true ? "enum" : IsZodDateTime<T> extends true ? "datetime" : IsZodUUID<T> extends true ? "uuid" : IsZodString<T> extends true ? "string" : IsZodEmail<T> extends true ? "email" : IsZodDateRange<T> extends true ? "dateRange" : IsZodTextEditor<T> extends true ? "textEditor" : IsZodObject<T> extends true ? "object" : IsZodArray<T> extends true ? "array" : never;
|
|
15
16
|
type ZodTypeSwitch<TZodType extends z.ZodType, T extends Record<ZodType<TZodType> | "unknown", unknown>> = ZodType<TZodType> extends never ? never : T[ZodType<TZodType>];
|
|
16
17
|
const unwrapZodType: (schemaType: z.core.$ZodType) => z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
17
18
|
const isDateRange: (schemaType: z.core.$ZodType) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@povio/ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"react-aria": "^3.44.0",
|
|
58
58
|
"react-aria-components": "^1.13.0",
|
|
59
59
|
"react-hook-form": "^7.65.0",
|
|
60
|
-
"react-i18next": "^
|
|
60
|
+
"react-i18next": "^16.2.3",
|
|
61
61
|
"react-responsive": "^10.0.1",
|
|
62
62
|
"react-stately": "^3.42.0",
|
|
63
63
|
"react-toastify": "^11.0.5",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { UseMutationOptions, useMutation as iUseMutation } from '@tanstack/react-query';
|
|
2
|
-
export declare function useSingletonMutation<TData, TError, TVariables>({ mutationFn, useMutation, ...options }: UseMutationOptions<TData, TError, TVariables> & {
|
|
3
|
-
useMutation: typeof iUseMutation;
|
|
4
|
-
} & Required<Pick<UseMutationOptions<TData, TError, TVariables>, "mutationFn">>): import('@tanstack/react-query').UseMutationResult<TData, TError, TVariables, unknown>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useRef } from "react";
|
|
2
|
-
function useSingletonMutation({
|
|
3
|
-
mutationFn,
|
|
4
|
-
useMutation,
|
|
5
|
-
...options
|
|
6
|
-
}) {
|
|
7
|
-
const mutationFnPromiseRef = useRef(null);
|
|
8
|
-
return useMutation({
|
|
9
|
-
...options,
|
|
10
|
-
mutationFn: async (variables) => {
|
|
11
|
-
if (mutationFnPromiseRef.current) {
|
|
12
|
-
return mutationFnPromiseRef.current;
|
|
13
|
-
}
|
|
14
|
-
const promise = mutationFn(variables);
|
|
15
|
-
mutationFnPromiseRef.current = promise;
|
|
16
|
-
try {
|
|
17
|
-
const result = await promise;
|
|
18
|
-
return result;
|
|
19
|
-
} finally {
|
|
20
|
-
mutationFnPromiseRef.current = null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
export {
|
|
26
|
-
useSingletonMutation
|
|
27
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { logger } from "../../logger.js";
|
|
2
|
-
import { RestInterceptor } from "./rest-interceptor.js";
|
|
3
|
-
const LoggingInterceptor = new RestInterceptor((client) => {
|
|
4
|
-
return client.interceptors.request.use(
|
|
5
|
-
(config) => {
|
|
6
|
-
logger.info("Rest call", config.method, config.url, config.data);
|
|
7
|
-
return config;
|
|
8
|
-
},
|
|
9
|
-
(error) => {
|
|
10
|
-
logger.error("Rest call error", error);
|
|
11
|
-
return Promise.reject(error);
|
|
12
|
-
}
|
|
13
|
-
);
|
|
14
|
-
});
|
|
15
|
-
export {
|
|
16
|
-
LoggingInterceptor
|
|
17
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { logger } from "../../logger.js";
|
|
2
|
-
import { RestInterceptor } from "./rest-interceptor.js";
|
|
3
|
-
const ResponseInterceptor = new RestInterceptor((client) => {
|
|
4
|
-
return client.interceptors.response.use(
|
|
5
|
-
(response) => {
|
|
6
|
-
logger.info("Rest response", response.data, response?.config?.url, response?.status);
|
|
7
|
-
return {
|
|
8
|
-
...response,
|
|
9
|
-
// oxlint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
10
|
-
data: response.data === "" ? void 0 : response.data
|
|
11
|
-
};
|
|
12
|
-
},
|
|
13
|
-
(error) => {
|
|
14
|
-
logger.error(
|
|
15
|
-
`Rest response error: ${error?.response?.config?.url}`,
|
|
16
|
-
error?.response?.data,
|
|
17
|
-
error?.response?.status
|
|
18
|
-
);
|
|
19
|
-
throw error;
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
export {
|
|
24
|
-
ResponseInterceptor
|
|
25
|
-
};
|