@liorian/sdk 0.28.0-alpha.56010ca
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/README.md +483 -0
- package/package.json +94 -0
- package/schemas/module.schema.json +818 -0
- package/src/application/index.ts +3 -0
- package/src/application/module-instance.ts +36 -0
- package/src/application/service/auth-api-service.ts +291 -0
- package/src/application/service/auth-user.service.ts +108 -0
- package/src/application/service/index.ts +12 -0
- package/src/application/service/module-activation-api.service.ts +105 -0
- package/src/application/service/notifications-api-service.ts +38 -0
- package/src/application/service/notifications-push.service.ts +299 -0
- package/src/application/service/notifications-socket-service.ts +76 -0
- package/src/application/service/organizations-api-service.ts +104 -0
- package/src/application/service/otp-api-service.ts +11 -0
- package/src/application/service/storage-api-service.ts +77 -0
- package/src/application/service/storefront-api.service.ts +72 -0
- package/src/application/service/user-preferences-api.service.ts +57 -0
- package/src/domain/config/app.config.ts +35 -0
- package/src/domain/config/auth.config.ts +30 -0
- package/src/domain/config/index.ts +4 -0
- package/src/domain/config/logo.config.ts +17 -0
- package/src/domain/entities/activities.interface.ts +18 -0
- package/src/domain/entities/catalog.interface.ts +96 -0
- package/src/domain/entities/index.ts +13 -0
- package/src/domain/entities/media.ts +22 -0
- package/src/domain/entities/module-activation.interface.ts +173 -0
- package/src/domain/entities/module.interface.ts +101 -0
- package/src/domain/entities/notification.interface.ts +23 -0
- package/src/domain/entities/objectable.type.ts +3 -0
- package/src/domain/entities/organization.interface.ts +81 -0
- package/src/domain/entities/user-auth.interface.ts +17 -0
- package/src/domain/entities/user-phone.interface.ts +11 -0
- package/src/domain/entities/user-profile.interface.ts +23 -0
- package/src/domain/entities/user.interface.ts +79 -0
- package/src/domain/enums/coloring.enum.ts +6 -0
- package/src/domain/enums/domains.enum.ts +282 -0
- package/src/domain/enums/index.ts +8 -0
- package/src/domain/enums/module-category.enum.ts +57 -0
- package/src/domain/enums/module.enum.ts +97 -0
- package/src/domain/enums/routine.enum.ts +12 -0
- package/src/domain/enums/user-profile.enum.ts +25 -0
- package/src/domain/enums/user-status.enum.ts +7 -0
- package/src/domain/index.ts +6 -0
- package/src/domain/typing/auth-caches.ts +12 -0
- package/src/domain/typing/auth-oauth.types.ts +172 -0
- package/src/domain/typing/devise.ts +2 -0
- package/src/domain/typing/index.ts +10 -0
- package/src/domain/typing/response.ts +30 -0
- package/src/domain/typing/routine.types.ts +113 -0
- package/src/domain/typing/session.interface.ts +28 -0
- package/src/domain/typing/statisticals.ts +11 -0
- package/src/domain/typing/user-media-upload.ts +9 -0
- package/src/domain/typing/values.ts +6 -0
- package/src/index.tsx +168 -0
- package/src/infrastructure/capabilities/cache-storage/capability.ts +129 -0
- package/src/infrastructure/capabilities/cache-storage/enum.ts +5 -0
- package/src/infrastructure/capabilities/cache-storage/index.ts +4 -0
- package/src/infrastructure/capabilities/cache-storage/types.ts +13 -0
- package/src/infrastructure/capabilities/index.ts +3 -0
- package/src/infrastructure/capabilities/stackable/capability.ts +55 -0
- package/src/infrastructure/capabilities/stackable/index.ts +3 -0
- package/src/infrastructure/capabilities/stackable/types.ts +24 -0
- package/src/infrastructure/common-classname.constant.ts +4 -0
- package/src/infrastructure/data/countries.ts +208 -0
- package/src/infrastructure/data/gender.ts +5 -0
- package/src/infrastructure/data/index.ts +3 -0
- package/src/infrastructure/dataset/index.ts +3 -0
- package/src/infrastructure/dataset/sign-in.dataset.ts +21 -0
- package/src/infrastructure/dataset/sign-up.dataset.ts +64 -0
- package/src/infrastructure/hooks/index.ts +10 -0
- package/src/infrastructure/hooks/use-activity-lock-draft.ts +69 -0
- package/src/infrastructure/hooks/use-auth.ts +24 -0
- package/src/infrastructure/hooks/use-elastic-interaction.ts +180 -0
- package/src/infrastructure/hooks/use-is-desktop.ts +25 -0
- package/src/infrastructure/hooks/use-is-tauri.ts +17 -0
- package/src/infrastructure/hooks/use-mobile.ts +19 -0
- package/src/infrastructure/hooks/use-notifications.ts +128 -0
- package/src/infrastructure/hooks/use-recent-colors.ts +113 -0
- package/src/infrastructure/hooks/use-recent-modules.ts +76 -0
- package/src/infrastructure/index.tsx +11 -0
- package/src/infrastructure/library/design-system.ts +95 -0
- package/src/infrastructure/library/index.tsx +5 -0
- package/src/infrastructure/library/motion-utils.ts +77 -0
- package/src/infrastructure/library/motion.tsx +31 -0
- package/src/infrastructure/library/scroll-progress.tsx +93 -0
- package/src/infrastructure/providers/auth-guard.provider.tsx +47 -0
- package/src/infrastructure/providers/auth.provider.tsx +168 -0
- package/src/infrastructure/providers/index.tsx +8 -0
- package/src/infrastructure/providers/module-usage.provider.tsx +95 -0
- package/src/infrastructure/providers/modules-guard.provider.tsx +64 -0
- package/src/infrastructure/providers/modules-routines.provider.tsx +33 -0
- package/src/infrastructure/providers/modules-switcher.provider.tsx +25 -0
- package/src/infrastructure/providers/query.provider.tsx +27 -0
- package/src/infrastructure/routines/__tests__/routine.test.ts +368 -0
- package/src/infrastructure/routines/index.tsx +3 -0
- package/src/infrastructure/routines/routine.hook.ts +121 -0
- package/src/infrastructure/routines/routine.ts +283 -0
- package/src/infrastructure/routines/routine.tsx +283 -0
- package/src/infrastructure/stores/activity-lock.store.ts +22 -0
- package/src/infrastructure/stores/auth-user-connected.store.ts +24 -0
- package/src/infrastructure/stores/dataset.store.ts +106 -0
- package/src/infrastructure/stores/index.ts +6 -0
- package/src/infrastructure/stores/module.store.ts +266 -0
- package/src/infrastructure/stores/upload.store.ts +198 -0
- package/src/infrastructure/utilities/access-label.util.ts +158 -0
- package/src/infrastructure/utilities/activities.util.tsx +54 -0
- package/src/infrastructure/utilities/activity-lock.service.ts +263 -0
- package/src/infrastructure/utilities/activity-tracker.service.ts +205 -0
- package/src/infrastructure/utilities/api-service.ts +237 -0
- package/src/infrastructure/utilities/auth-logout.util.ts +23 -0
- package/src/infrastructure/utilities/classname.util.ts +7 -0
- package/src/infrastructure/utilities/encryption.service.ts +125 -0
- package/src/infrastructure/utilities/form-snapshot.service.ts +304 -0
- package/src/infrastructure/utilities/format.util.ts +40 -0
- package/src/infrastructure/utilities/index.tsx +23 -0
- package/src/infrastructure/utilities/media-label.service.ts +47 -0
- package/src/infrastructure/utilities/modules.ts +11 -0
- package/src/infrastructure/utilities/permission.util.ts +22 -0
- package/src/infrastructure/utilities/push-permission.util.ts +43 -0
- package/src/infrastructure/utilities/route-access.ts +38 -0
- package/src/infrastructure/utilities/socket-service.ts +123 -0
- package/src/infrastructure/utilities/sso-auth.util.ts +188 -0
- package/src/infrastructure/utilities/stringable.util.ts +16 -0
- package/src/infrastructure/utilities/strings.util.ts +18 -0
- package/src/infrastructure/utilities/tauri.util.ts +15 -0
- package/src/infrastructure/utilities/utils.ts +6 -0
- package/src/infrastructure/utilities/values.ts +5 -0
- package/src/presentation/8starlabs-ui/button.tsx +94 -0
- package/src/presentation/8starlabs-ui/flip-clock.tsx +368 -0
- package/src/presentation/8starlabs-ui/heatmap.tsx +430 -0
- package/src/presentation/8starlabs-ui/hooks/index.tsx +2 -0
- package/src/presentation/8starlabs-ui/hooks/use-mobile.ts +21 -0
- package/src/presentation/8starlabs-ui/index.tsx +20 -0
- package/src/presentation/8starlabs-ui/json-viewer.tsx +972 -0
- package/src/presentation/8starlabs-ui/marquee.tsx +134 -0
- package/src/presentation/8starlabs-ui/partition-bar.tsx +198 -0
- package/src/presentation/8starlabs-ui/scroll-fade.tsx +158 -0
- package/src/presentation/8starlabs-ui/status-indicator.tsx +86 -0
- package/src/presentation/8starlabs-ui/system-banner.tsx +50 -0
- package/src/presentation/8starlabs-ui/timeline.tsx +576 -0
- package/src/presentation/8starlabs-ui/transport-badge.tsx +249 -0
- package/src/presentation/8starlabs-ui/ui/copy-button.tsx +60 -0
- package/src/presentation/8starlabs-ui/ui/index.tsx +2 -0
- package/src/presentation/analytics-section.tsx +85 -0
- package/src/presentation/app-sidebar.tsx +234 -0
- package/src/presentation/charts/area-widget.chart-skeleton.tsx +61 -0
- package/src/presentation/charts/area-widget.chart.tsx +128 -0
- package/src/presentation/charts/chart-widgets.types.ts +81 -0
- package/src/presentation/charts/index.tsx +16 -0
- package/src/presentation/charts/line-widget.chart-skeleton.tsx +64 -0
- package/src/presentation/charts/line-widget.chart.tsx +105 -0
- package/src/presentation/charts/pie-widget.chart-skeleton.tsx +56 -0
- package/src/presentation/charts/pie-widget.chart.tsx +168 -0
- package/src/presentation/charts/radar-widget.chart-skeleton.tsx +67 -0
- package/src/presentation/charts/radar-widget.chart.tsx +80 -0
- package/src/presentation/charts/radial-stacked-widget.chart-skeleton.tsx +66 -0
- package/src/presentation/charts/radial-stacked-widget.chart.tsx +120 -0
- package/src/presentation/charts/radial-widget.chart-skeleton.tsx +61 -0
- package/src/presentation/charts/radial-widget.chart.tsx +87 -0
- package/src/presentation/charts/tooltip-widget.chart-skeleton.tsx +64 -0
- package/src/presentation/charts/tooltip-widget.chart.tsx +89 -0
- package/src/presentation/components/activity-actions.tsx +20 -0
- package/src/presentation/components/activity-container.tsx +55 -0
- package/src/presentation/components/activity-content.tsx +20 -0
- package/src/presentation/components/activity-descriptor-parser.tsx +37 -0
- package/src/presentation/components/activity-header.tsx +20 -0
- package/src/presentation/components/activity-loader.tsx +19 -0
- package/src/presentation/components/activity-title.tsx +32 -0
- package/src/presentation/components/activity.tsx +22 -0
- package/src/presentation/components/auth/index.tsx +4 -0
- package/src/presentation/components/auth/sso-callback.view.tsx +44 -0
- package/src/presentation/components/auth/sso-disconnect.view.tsx +41 -0
- package/src/presentation/components/auth/sso-sign-in.view.tsx +29 -0
- package/src/presentation/components/auth-lock-screen.tsx +309 -0
- package/src/presentation/components/auth-session.view.tsx +17 -0
- package/src/presentation/components/data-table.tsx +814 -0
- package/src/presentation/components/dynamic-icon.tsx +16 -0
- package/src/presentation/components/floating-upload.tsx +291 -0
- package/src/presentation/components/index.tsx +40 -0
- package/src/presentation/components/local-time.tsx +170 -0
- package/src/presentation/components/markdown-parser.tsx +201 -0
- package/src/presentation/components/message-scroller.tsx +131 -0
- package/src/presentation/components/module-first-access-config.view.tsx +181 -0
- package/src/presentation/components/module-first-access-pending.view.tsx +38 -0
- package/src/presentation/components/module-guard.tsx +34 -0
- package/src/presentation/components/modules-first-access.guard.tsx +88 -0
- package/src/presentation/components/modules-guard-forbidden.tsx +46 -0
- package/src/presentation/components/notification-details.modal.tsx +145 -0
- package/src/presentation/components/notification-item.tsx +127 -0
- package/src/presentation/components/notifications-popover.tsx +128 -0
- package/src/presentation/components/push-notifications.provider.tsx +65 -0
- package/src/presentation/components/upload-progress-dialog.tsx +140 -0
- package/src/presentation/components/waiting-bar.tsx +22 -0
- package/src/presentation/components/waiting-section.tsx +15 -0
- package/src/presentation/components/waiting.tsx +14 -0
- package/src/presentation/data-grid/data-grid-empty.tsx +24 -0
- package/src/presentation/data-grid/data-grid-search-engine.tsx +32 -0
- package/src/presentation/data-grid/data-grid.tsx +892 -0
- package/src/presentation/data-grid/index.tsx +4 -0
- package/src/presentation/form-screen.tsx +95 -0
- package/src/presentation/icons/custom.tsx +20 -0
- package/src/presentation/icons/glyphIcons.tsx +53 -0
- package/src/presentation/icons/icons.enum.ts +4 -0
- package/src/presentation/icons/icons.util.ts +6 -0
- package/src/presentation/icons/index.tsx +8 -0
- package/src/presentation/icons/lucide.tsx +17 -0
- package/src/presentation/icons/remix.tsx +33 -0
- package/src/presentation/icons/types.ts +27 -0
- package/src/presentation/index.tsx +45 -0
- package/src/presentation/modals/components/ModalBox.tsx +74 -0
- package/src/presentation/modals/components/ModalPortal.tsx +31 -0
- package/src/presentation/modals/components/ModalStepper.tsx +319 -0
- package/src/presentation/modals/components/ModalWrapper.tsx +65 -0
- package/src/presentation/modals/components/index.tsx +5 -0
- package/src/presentation/modals/hooks/index.ts +2 -0
- package/src/presentation/modals/hooks/useModal.ts +38 -0
- package/src/presentation/modals/index.tsx +5 -0
- package/src/presentation/modals/stores/index.ts +2 -0
- package/src/presentation/modals/stores/useModalStore.ts +90 -0
- package/src/presentation/modals/types/index.ts +2 -0
- package/src/presentation/modals/types/modal.type.ts +33 -0
- package/src/presentation/module-menubar.tsx +300 -0
- package/src/presentation/module-widget.tsx +233 -0
- package/src/presentation/nav-documents.tsx +89 -0
- package/src/presentation/nav-main.tsx +62 -0
- package/src/presentation/nav-secondary.tsx +41 -0
- package/src/presentation/nav-user.tsx +109 -0
- package/src/presentation/permission-action-badge.tsx +35 -0
- package/src/presentation/reui/index.tsx +3 -0
- package/src/presentation/reui/stepper.tsx +508 -0
- package/src/presentation/reui/timeline.tsx +226 -0
- package/src/presentation/sheets/index.tsx +2 -0
- package/src/presentation/sheets/legacy-sheet-header.tsx +0 -0
- package/src/presentation/sheets/legacy-sheet.tsx +37 -0
- package/src/presentation/size.enum.ts +19 -0
- package/src/presentation/system/index.tsx +3 -0
- package/src/presentation/system/logo.theme.tsx +21 -0
- package/src/presentation/system/types.ts +10 -0
- package/src/presentation/theme/index.tsx +6 -0
- package/src/presentation/theme/prefer-color-scheme.tsx +50 -0
- package/src/presentation/theme/switch-color-scheme.tsx +16 -0
- package/src/presentation/theme/theme-switcher-button.tsx +20 -0
- package/src/presentation/theme/theme.enum.ts +4 -0
- package/src/presentation/theme/theme.store.ts +87 -0
- package/src/presentation/themes/index.tsx +2 -0
- package/src/presentation/themes/katon/dashboard-layout.tsx +1080 -0
- package/src/presentation/themes/katon/edge-section.tsx +19 -0
- package/src/presentation/themes/katon/header-menubar.tsx +270 -0
- package/src/presentation/themes/katon/header-modules-available.tsx +44 -0
- package/src/presentation/themes/katon/header-modules-recents.tsx +52 -0
- package/src/presentation/themes/katon/header-modules-store.tsx +25 -0
- package/src/presentation/themes/katon/header-options.tsx +13 -0
- package/src/presentation/themes/katon/header-organization-select.tsx +146 -0
- package/src/presentation/themes/katon/header-routines.tsx +74 -0
- package/src/presentation/themes/katon/header-tasks-connected-user.tsx +150 -0
- package/src/presentation/themes/katon/index.tsx +16 -0
- package/src/presentation/themes/katon/main-wrapper.tsx +34 -0
- package/src/presentation/themes/katon/module-item-link.tsx +32 -0
- package/src/presentation/themes/katon/view-frame.tsx +25 -0
- package/src/presentation/themes/katon/view-helmet.tsx +53 -0
- package/src/presentation/themes/katon/view-status.tsx +32 -0
- package/src/presentation/themes/katon/view-wrapper.tsx +15 -0
- package/src/presentation/themes/katon/view.tsx +42 -0
- package/src/presentation/ui/accordion-multiselect.tsx +206 -0
- package/src/presentation/ui/accordion.tsx +81 -0
- package/src/presentation/ui/alert-dialog.tsx +199 -0
- package/src/presentation/ui/alert.tsx +76 -0
- package/src/presentation/ui/aspect-ratio.tsx +11 -0
- package/src/presentation/ui/attachment.tsx +204 -0
- package/src/presentation/ui/avatar.tsx +112 -0
- package/src/presentation/ui/badge.tsx +49 -0
- package/src/presentation/ui/breadcrumb.tsx +122 -0
- package/src/presentation/ui/bubble.tsx +125 -0
- package/src/presentation/ui/button-group.tsx +83 -0
- package/src/presentation/ui/button.tsx +87 -0
- package/src/presentation/ui/calendar.tsx +222 -0
- package/src/presentation/ui/card.tsx +106 -0
- package/src/presentation/ui/carousel.tsx +242 -0
- package/src/presentation/ui/chart.tsx +373 -0
- package/src/presentation/ui/checkbox.tsx +33 -0
- package/src/presentation/ui/clickable.tsx +58 -0
- package/src/presentation/ui/collapsible.tsx +33 -0
- package/src/presentation/ui/color-swatch-selector.tsx +81 -0
- package/src/presentation/ui/combobox.tsx +299 -0
- package/src/presentation/ui/command.tsx +195 -0
- package/src/presentation/ui/context-menu.tsx +263 -0
- package/src/presentation/ui/dialog.tsx +168 -0
- package/src/presentation/ui/direction.tsx +22 -0
- package/src/presentation/ui/drawer.tsx +134 -0
- package/src/presentation/ui/dropdown-menu.tsx +269 -0
- package/src/presentation/ui/empty.tsx +104 -0
- package/src/presentation/ui/field.tsx +238 -0
- package/src/presentation/ui/granularity-selector.tsx +58 -0
- package/src/presentation/ui/hover-card.tsx +44 -0
- package/src/presentation/ui/index.tsx +74 -0
- package/src/presentation/ui/input-group.tsx +156 -0
- package/src/presentation/ui/input-otp.tsx +87 -0
- package/src/presentation/ui/input.tsx +19 -0
- package/src/presentation/ui/item.tsx +196 -0
- package/src/presentation/ui/kpi-card.tsx +203 -0
- package/src/presentation/ui/label-selector.tsx +100 -0
- package/src/presentation/ui/label.tsx +24 -0
- package/src/presentation/ui/legacy-birth-date-input.tsx +43 -0
- package/src/presentation/ui/legacy-color-picker/index.tsx +42 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.content.tsx +37 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.context.tsx +42 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.hex-input.tsx +97 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.picker.tsx +266 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.presets.ts +22 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.quick-list.tsx +49 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.recent.tsx +43 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.swatches.tsx +111 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.trigger.tsx +128 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.tsx +110 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.types.ts +1 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.utils.ts +114 -0
- package/src/presentation/ui/legacy-country-input.tsx +171 -0
- package/src/presentation/ui/legacy-gender-input.tsx +22 -0
- package/src/presentation/ui/legacy-input.tsx +106 -0
- package/src/presentation/ui/legacy-phone-input.tsx +213 -0
- package/src/presentation/ui/legacy-select-input.tsx +114 -0
- package/src/presentation/ui/legacy-text-area.tsx +111 -0
- package/src/presentation/ui/list-items.tsx +59 -0
- package/src/presentation/ui/marker.tsx +69 -0
- package/src/presentation/ui/media-player/index.tsx +12 -0
- package/src/presentation/ui/media-player/media-player.context.tsx +36 -0
- package/src/presentation/ui/media-player/media-player.tsx +167 -0
- package/src/presentation/ui/media-player/player-controls.tsx +207 -0
- package/src/presentation/ui/media-player/players/audio-player.tsx +78 -0
- package/src/presentation/ui/media-player/players/index.tsx +4 -0
- package/src/presentation/ui/media-player/players/video-player.tsx +193 -0
- package/src/presentation/ui/media-player/players/voice-note-player.tsx +108 -0
- package/src/presentation/ui/media-player/use-media-player.hook.ts +263 -0
- package/src/presentation/ui/menubar.tsx +281 -0
- package/src/presentation/ui/message.tsx +92 -0
- package/src/presentation/ui/navigation-menu.tsx +172 -0
- package/src/presentation/ui/pagination.tsx +129 -0
- package/src/presentation/ui/popover.tsx +89 -0
- package/src/presentation/ui/progress.tsx +31 -0
- package/src/presentation/ui/resizable.tsx +50 -0
- package/src/presentation/ui/select.tsx +192 -0
- package/src/presentation/ui/separator.tsx +28 -0
- package/src/presentation/ui/sheet.tsx +147 -0
- package/src/presentation/ui/sidebar.tsx +702 -0
- package/src/presentation/ui/skeleton.tsx +13 -0
- package/src/presentation/ui/slide-to-confirm.tsx +129 -0
- package/src/presentation/ui/slider.tsx +59 -0
- package/src/presentation/ui/sonner.tsx +58 -0
- package/src/presentation/ui/switch.tsx +33 -0
- package/src/presentation/ui/table.tsx +116 -0
- package/src/presentation/ui/tabs.tsx +90 -0
- package/src/presentation/ui/text-gradient.tsx +84 -0
- package/src/presentation/ui/textarea.tsx +18 -0
- package/src/presentation/ui/timeline-steps.tsx +235 -0
- package/src/presentation/ui/toggle-group.tsx +89 -0
- package/src/presentation/ui/toggle.tsx +47 -0
- package/src/presentation/ui/tooltip.tsx +57 -0
- package/src/presentation/uploading/index.tsx +3 -0
- package/src/presentation/uploading/media-upload-field.tsx +152 -0
- package/src/presentation/uploading/storage-media.tsx +210 -0
- package/src/styles.css +403 -0
- package/src/themes.css +1038 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// src/core/presentation/motion-utils.ts
|
|
2
|
+
// Motion utilities for elastic, organic, and spring-based animations (GSAP-backed)
|
|
3
|
+
|
|
4
|
+
import gsap from "gsap";
|
|
5
|
+
import { tokens } from "./design-system";
|
|
6
|
+
|
|
7
|
+
export interface EnterAnimation {
|
|
8
|
+
from: gsap.TweenVars;
|
|
9
|
+
to: gsap.TweenVars;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// The design-system spring tokens (stiffness/damping) describe a bouncy spring
|
|
13
|
+
// that settles in ~0.6-0.7s and overshoots slightly. GSAP's elastic ease is the
|
|
14
|
+
// closest built-in equivalent.
|
|
15
|
+
const ease = "elastic.out(1, 0.5)";
|
|
16
|
+
const easeSoft = "elastic.out(1, 0.75)";
|
|
17
|
+
const easeBouncy = "elastic.out(1.3, 0.4)";
|
|
18
|
+
const duration = 0.7;
|
|
19
|
+
const durationSoft = 0.45;
|
|
20
|
+
|
|
21
|
+
export const elasticEnter = (delay: number = 0): EnterAnimation => ({
|
|
22
|
+
from: { opacity: 0, y: 20, scale: 0.95 },
|
|
23
|
+
to: { opacity: 1, y: 0, scale: 1, duration, ease, delay },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const elasticExit = (): EnterAnimation => ({
|
|
27
|
+
from: { opacity: 1, y: 0, scale: 1 },
|
|
28
|
+
to: { opacity: 0, y: -20, scale: 0.95, duration: durationSoft, ease: easeSoft },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const elasticPulse = (): EnterAnimation => ({
|
|
32
|
+
from: { scale: 1 },
|
|
33
|
+
to: { scale: 1.05, duration: 0.6, ease: "sine.inOut", repeat: -1, yoyo: true },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const elasticScaleEnter = (): EnterAnimation => ({
|
|
37
|
+
from: { opacity: 0, scale: 0.92 },
|
|
38
|
+
to: { opacity: 1, scale: 1, duration: 0.6, ease: easeBouncy },
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const elasticSlideUp = (delay: number = 0): EnterAnimation => ({
|
|
42
|
+
from: { opacity: 0, y: 40 },
|
|
43
|
+
to: { opacity: 1, y: 0, duration, ease, delay },
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const elasticSlideInLeft = (): EnterAnimation => ({
|
|
47
|
+
from: { opacity: 0, x: -40 },
|
|
48
|
+
to: { opacity: 1, x: 0, duration, ease },
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export const elasticSlideInRight = (): EnterAnimation => ({
|
|
52
|
+
from: { opacity: 0, x: 40 },
|
|
53
|
+
to: { opacity: 1, x: 0, duration, ease },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const elasticContainer = (delay: number = 0, stagger: number = 0.08): EnterAnimation => ({
|
|
57
|
+
from: { opacity: 0 },
|
|
58
|
+
to: { opacity: 1, duration: 0.6, ease: "power2.out", delay, stagger },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const elasticChild = (): EnterAnimation => ({
|
|
62
|
+
from: { opacity: 0, y: 20, scale: 0.95 },
|
|
63
|
+
to: { opacity: 1, y: 0, scale: 1, duration, ease },
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export const staggeredSpringList = (motionConfig: {
|
|
67
|
+
delay: number;
|
|
68
|
+
stiffness?: number;
|
|
69
|
+
damping?: number;
|
|
70
|
+
}) => {
|
|
71
|
+
const { delay } = motionConfig;
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
from: { opacity: 0, y: 20 },
|
|
75
|
+
to: { opacity: 1, y: 0, duration, ease, delay, stagger: 0.1 },
|
|
76
|
+
};
|
|
77
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { ElementType, ReactNode, useRef } from "react";
|
|
4
|
+
import gsap from "gsap";
|
|
5
|
+
import { useGSAP } from "@gsap/react";
|
|
6
|
+
import { EnterAnimation } from "./motion-utils";
|
|
7
|
+
|
|
8
|
+
export interface MotionProps {
|
|
9
|
+
as?: ElementType;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
animation?: EnterAnimation | null;
|
|
12
|
+
className?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function Motion({ as, children, animation, className, ...rest }: MotionProps) {
|
|
17
|
+
const ref = useRef<any>(null);
|
|
18
|
+
|
|
19
|
+
useGSAP(() => {
|
|
20
|
+
if (!animation || !ref.current) return;
|
|
21
|
+
gsap.fromTo(ref.current, animation.from, animation.to);
|
|
22
|
+
}, { scope: ref });
|
|
23
|
+
|
|
24
|
+
const Comp = (as ?? "div") as ElementType;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Comp ref={ref} className={className} {...rest}>
|
|
28
|
+
{children}
|
|
29
|
+
</Comp>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from "react"
|
|
4
|
+
import gsap from "gsap"
|
|
5
|
+
import { cn } from "../utilities/utils"
|
|
6
|
+
|
|
7
|
+
interface ScrollProgressProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
/**
|
|
9
|
+
* Height of the progress bar in pixels
|
|
10
|
+
* @default 2
|
|
11
|
+
*/
|
|
12
|
+
height?: number
|
|
13
|
+
/**
|
|
14
|
+
* Color of the progress bar
|
|
15
|
+
* @default "bg-primary"
|
|
16
|
+
*/
|
|
17
|
+
color?: string
|
|
18
|
+
/**
|
|
19
|
+
* Position of the progress bar
|
|
20
|
+
* @default "top"
|
|
21
|
+
*/
|
|
22
|
+
position?: "top" | "bottom"
|
|
23
|
+
/**
|
|
24
|
+
* Container element to track scroll progress for
|
|
25
|
+
* If not provided, tracks the entire viewport
|
|
26
|
+
*/
|
|
27
|
+
container?: React.RefObject<HTMLElement | null>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function ScrollProgress({
|
|
31
|
+
height = 4,
|
|
32
|
+
color = "bg-primary",
|
|
33
|
+
position = "top",
|
|
34
|
+
className,
|
|
35
|
+
container,
|
|
36
|
+
...props
|
|
37
|
+
}: ScrollProgressProps) {
|
|
38
|
+
const ref = useRef<HTMLDivElement>(null)
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const el = ref.current
|
|
42
|
+
if (!el) return
|
|
43
|
+
|
|
44
|
+
const update = () => {
|
|
45
|
+
const scroller = container?.current ?? null
|
|
46
|
+
let progress = 0
|
|
47
|
+
|
|
48
|
+
if (scroller) {
|
|
49
|
+
const max = scroller.scrollHeight - scroller.clientHeight
|
|
50
|
+
progress = max > 0 ? scroller.scrollTop / max : 0
|
|
51
|
+
} else {
|
|
52
|
+
const doc = document.documentElement
|
|
53
|
+
const max = doc.scrollHeight - doc.clientHeight
|
|
54
|
+
progress = max > 0 ? (window.scrollY || doc.scrollTop) / max : 0
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
gsap.set(el, { scaleX: progress })
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
update()
|
|
61
|
+
|
|
62
|
+
const target = container?.current ?? window
|
|
63
|
+
target.addEventListener("scroll", update, { passive: true })
|
|
64
|
+
window.addEventListener("resize", update)
|
|
65
|
+
|
|
66
|
+
return () => {
|
|
67
|
+
target.removeEventListener("scroll", update)
|
|
68
|
+
window.removeEventListener("resize", update)
|
|
69
|
+
}
|
|
70
|
+
}, [container])
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div
|
|
74
|
+
ref={ref}
|
|
75
|
+
data-slot="scroll-progress"
|
|
76
|
+
className={cn(
|
|
77
|
+
"left-0 right-0 z-50 origin-left",
|
|
78
|
+
// Use fixed positioning for viewport scroll, allow override for container scroll
|
|
79
|
+
!container && "fixed",
|
|
80
|
+
position === "top" ? "top-0" : "bottom-0",
|
|
81
|
+
color,
|
|
82
|
+
className,
|
|
83
|
+
)}
|
|
84
|
+
style={{
|
|
85
|
+
transform: "scaleX(0)",
|
|
86
|
+
height: `${height}px`,
|
|
87
|
+
}}
|
|
88
|
+
{...props}
|
|
89
|
+
/>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { ScrollProgress }
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import React, {useEffect, useState} from "react"
|
|
4
|
+
import {usePathname} from "next/navigation"
|
|
5
|
+
import {AuthUserService} from "../../application/service/auth-user.service"
|
|
6
|
+
import {AuthSessionView} from "../../presentation/components/auth-session.view"
|
|
7
|
+
import {AuthLockScreen} from "../../presentation/components/auth-lock-screen"
|
|
8
|
+
import {AuthConfig} from "../../domain/config/auth.config";
|
|
9
|
+
import {useAuth} from "../hooks/use-auth";
|
|
10
|
+
import {activityLockStore} from "../stores/activity-lock.store";
|
|
11
|
+
|
|
12
|
+
interface AuthGuardProps {
|
|
13
|
+
children: React.ReactNode
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Garde d'accès par défaut : affiche l'écran de verrouillage SSO tant que
|
|
18
|
+
* l'utilisateur n'est pas authentifié (les routes `/auth/*` et publiques sont
|
|
19
|
+
* exemptées via `AuthConfig.excludes`).
|
|
20
|
+
*/
|
|
21
|
+
export function AuthGuard({children}: AuthGuardProps) {
|
|
22
|
+
const {isLocked} = activityLockStore();
|
|
23
|
+
const {user} = useAuth()
|
|
24
|
+
const [status, setStatus] = useState<'checking' | 'locked' | 'authorized'>('checking')
|
|
25
|
+
const pathname = usePathname()
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const isAuthenticated = AuthUserService.isAuthenticated()
|
|
29
|
+
const isAuthRoute = AuthConfig.excludes.some((route) => pathname.startsWith(route))
|
|
30
|
+
|
|
31
|
+
if ((!isAuthenticated && !isAuthRoute) || isLocked) {
|
|
32
|
+
setStatus('locked')
|
|
33
|
+
} else {
|
|
34
|
+
setStatus('authorized')
|
|
35
|
+
}
|
|
36
|
+
}, [pathname, user, isLocked])
|
|
37
|
+
|
|
38
|
+
if (status === 'checking') {
|
|
39
|
+
return <AuthSessionView/>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (status === 'locked') {
|
|
43
|
+
return <AuthLockScreen/>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return <>{children}</>
|
|
47
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import React, {useCallback, useEffect, useState} from "react"
|
|
4
|
+
import {useRouter, usePathname} from "next/navigation"
|
|
5
|
+
import {authUserConnectedStore} from "../stores/auth-user-connected.store"
|
|
6
|
+
import {AuthUserService} from "../../application/service/auth-user.service"
|
|
7
|
+
import {AuthApiService} from "../../application/service/auth-api-service"
|
|
8
|
+
import {AuthSessionView} from "../../presentation/components/auth-session.view"
|
|
9
|
+
import {AuthLockScreen} from "../../presentation/components/auth-lock-screen"
|
|
10
|
+
import {AuthConfig} from "../../domain/config/auth.config";
|
|
11
|
+
import {AppConfig} from "../../domain/config/app.config";
|
|
12
|
+
import {ActivityLockService} from "../utilities/activity-lock.service";
|
|
13
|
+
import {toast} from "sonner";
|
|
14
|
+
|
|
15
|
+
export interface AuthProviderProps {
|
|
16
|
+
children: React.ReactNode
|
|
17
|
+
/**
|
|
18
|
+
* Si `true` (défaut), un utilisateur connecté sans organisation courante est
|
|
19
|
+
* redirigé vers la sélection d'organisation. Les applications ne reposant pas
|
|
20
|
+
* sur les organisations (ex. liorian-connect) doivent passer `false`.
|
|
21
|
+
*/
|
|
22
|
+
requireOrganization?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function AuthProvider({children, requireOrganization = true}: AuthProviderProps) {
|
|
26
|
+
const {setCurrentUser, setOrganizations, setCurrentOrganization, getCurrentUser} = authUserConnectedStore()
|
|
27
|
+
const [isInitialized, setIsInitialized] = useState(false)
|
|
28
|
+
const [locked, setLocked] = useState(false)
|
|
29
|
+
const router = useRouter()
|
|
30
|
+
const pathname = usePathname()
|
|
31
|
+
|
|
32
|
+
/** (Ré)arme le verrouillage par inactivité pour l'utilisateur courant. */
|
|
33
|
+
const armActivityLock = useCallback((userId: string, disposed: { current: boolean }) => {
|
|
34
|
+
const armed = () => !disposed.current && !ActivityLockService.isLocked(userId)
|
|
35
|
+
|
|
36
|
+
ActivityLockService.getTimeout(userId)
|
|
37
|
+
.then((timeout) => {
|
|
38
|
+
if (!armed()) return
|
|
39
|
+
ActivityLockService.start({
|
|
40
|
+
userId,
|
|
41
|
+
timeout,
|
|
42
|
+
onLocked: () => setLocked(true),
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
.catch(() => {
|
|
46
|
+
if (!armed()) return
|
|
47
|
+
ActivityLockService.start({
|
|
48
|
+
userId,
|
|
49
|
+
timeout: Number(AppConfig.UI_ACTIVITY_TRACKER_TIMEOUT),
|
|
50
|
+
onLocked: () => setLocked(true),
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
}, [])
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
let timeoutId: NodeJS.Timeout;
|
|
57
|
+
|
|
58
|
+
const initAuth = async () => {
|
|
59
|
+
try {
|
|
60
|
+
// Les tokens/infos de l'utilisateur doivent être disponibles en local
|
|
61
|
+
// avant de vérifier la validité de la session.
|
|
62
|
+
await AuthUserService.ready();
|
|
63
|
+
const token = AuthUserService.getToken()
|
|
64
|
+
const user = AuthUserService.getUser()
|
|
65
|
+
const organizations = AuthUserService.getOrganizations()
|
|
66
|
+
const currentOrganization = AuthUserService.getCurrentOrganization()
|
|
67
|
+
|
|
68
|
+
if (token && user) {
|
|
69
|
+
setCurrentUser(user)
|
|
70
|
+
setOrganizations(organizations)
|
|
71
|
+
if (currentOrganization) setCurrentOrganization(currentOrganization)
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
// Vérification de session via le SSO Liorian Auth : valide le
|
|
75
|
+
// jeton d'accès OAuth sur `/oauth/userinfo`.
|
|
76
|
+
await AuthApiService.userinfo()
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error("Session verification failed", e)
|
|
79
|
+
await AuthUserService.clear()
|
|
80
|
+
toast.error("Votre session a expiré")
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error("Auth initialization error", error)
|
|
86
|
+
} finally {
|
|
87
|
+
setIsInitialized(true)
|
|
88
|
+
timeoutId = setTimeout(initAuth, AppConfig.AUTH_CHECK_SESSION_TIMEOUT || 30000)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
initAuth()
|
|
93
|
+
|
|
94
|
+
return () => {
|
|
95
|
+
if (timeoutId) clearTimeout(timeoutId)
|
|
96
|
+
}
|
|
97
|
+
}, [setCurrentUser, setOrganizations, setCurrentOrganization, router])
|
|
98
|
+
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (isInitialized) {
|
|
101
|
+
const token = AuthUserService.getToken()
|
|
102
|
+
const currentOrganization = AuthUserService.getCurrentOrganization()
|
|
103
|
+
const isAuthRoute = pathname.startsWith('/auth')
|
|
104
|
+
const isPublicRoute = AuthConfig.excludes.some((route) => pathname.startsWith(route))
|
|
105
|
+
|
|
106
|
+
if (!token && !isAuthRoute && !isPublicRoute) {
|
|
107
|
+
setLocked(true)
|
|
108
|
+
} else if (!ActivityLockService.isLocked()) {
|
|
109
|
+
setLocked(false)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (requireOrganization && token && !currentOrganization && !isAuthRoute && !isPublicRoute && pathname !== '/') {
|
|
113
|
+
router.push(`${AuthConfig.routes.selectOrganization}?callbackUrl=${encodeURIComponent(pathname)}`)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}, [isInitialized, pathname, router, requireOrganization])
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!isInitialized) return;
|
|
120
|
+
|
|
121
|
+
const token = AuthUserService.getToken();
|
|
122
|
+
const user = AuthUserService.getUser();
|
|
123
|
+
|
|
124
|
+
// Pas d'utilisateur connecté : aucun verrouillage par inactivité à surveiller.
|
|
125
|
+
if (!token || !user) {
|
|
126
|
+
ActivityLockService.stop();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let disposed = {current: false};
|
|
131
|
+
|
|
132
|
+
// Restaure un verrou persistant (l'écran reste verrouillé même après rafraîchissement).
|
|
133
|
+
if (ActivityLockService.isLocked(user.id)) {
|
|
134
|
+
setLocked(true);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (user.id) armActivityLock(user.id, disposed)
|
|
139
|
+
|
|
140
|
+
return () => {
|
|
141
|
+
disposed.current = true;
|
|
142
|
+
ActivityLockService.stop();
|
|
143
|
+
};
|
|
144
|
+
}, [isInitialized, getCurrentUser?.id, armActivityLock]);
|
|
145
|
+
|
|
146
|
+
if (!isInitialized) {
|
|
147
|
+
return <AuthSessionView/>
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (locked) {
|
|
151
|
+
const restartActivityLock = () => {
|
|
152
|
+
const user = AuthUserService.getUser()
|
|
153
|
+
if (!user?.id) return
|
|
154
|
+
ActivityLockService.unlock()
|
|
155
|
+
setLocked(false)
|
|
156
|
+
armActivityLock(user.id, {current: false})
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<AuthLockScreen
|
|
161
|
+
onAuthenticated={restartActivityLock}
|
|
162
|
+
onUnlocked={restartActivityLock}
|
|
163
|
+
/>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return <>{children}</>
|
|
168
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @liorian/sdk/infrastructure/providers — cross-cutting React providers.
|
|
2
|
+
export * from "./auth-guard.provider";
|
|
3
|
+
export * from "./auth.provider";
|
|
4
|
+
export * from "./module-usage.provider";
|
|
5
|
+
export * from "./modules-guard.provider";
|
|
6
|
+
export * from "./modules-routines.provider";
|
|
7
|
+
export * from "./modules-switcher.provider";
|
|
8
|
+
export * from "./query.provider";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {useEffect, useRef} from "react";
|
|
4
|
+
import {useModuleStore} from "../stores/module.store";
|
|
5
|
+
import {ModuleActivationApiService} from "../../application/service/module-activation-api.service";
|
|
6
|
+
import {useAuth} from "../hooks/use-auth";
|
|
7
|
+
|
|
8
|
+
const FLUSH_INTERVAL_MS = 30_000;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Suit le temps d'utilisation et la fréquence d'activation des modules actifs
|
|
12
|
+
* et les envoie au backend (analytics). Le backend n'enregistre rien tant que
|
|
13
|
+
* l'organisation/l'utilisateur n'a pas activé le partage de données anonymes ;
|
|
14
|
+
* dans ce cas l'envoi est interrompu automatiquement.
|
|
15
|
+
*/
|
|
16
|
+
export function ModuleUsageProvider() {
|
|
17
|
+
const currentModuleId = useModuleStore((state) => state.selectedModule?.identifier ?? null);
|
|
18
|
+
const {currentOrganization} = useAuth();
|
|
19
|
+
|
|
20
|
+
const moduleIdRef = useRef<string | null>(null);
|
|
21
|
+
const lastTickRef = useRef<number>(Date.now());
|
|
22
|
+
const pendingRef = useRef<Map<string, number>>(new Map());
|
|
23
|
+
const trackingEnabledRef = useRef<boolean | null>(null);
|
|
24
|
+
|
|
25
|
+
const collectPending = () => {
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
const elapsed = now - lastTickRef.current;
|
|
28
|
+
lastTickRef.current = now;
|
|
29
|
+
const current = moduleIdRef.current;
|
|
30
|
+
if (current && elapsed > 0) {
|
|
31
|
+
pendingRef.current.set(current, (pendingRef.current.get(current) ?? 0) + elapsed);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
collectPending();
|
|
37
|
+
moduleIdRef.current = currentModuleId;
|
|
38
|
+
}, [currentModuleId]);
|
|
39
|
+
|
|
40
|
+
const flush = async () => {
|
|
41
|
+
collectPending();
|
|
42
|
+
|
|
43
|
+
const orgId = currentOrganization?.id;
|
|
44
|
+
if (!orgId) return;
|
|
45
|
+
if (trackingEnabledRef.current === false) {
|
|
46
|
+
pendingRef.current.clear();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const entries = Array.from(pendingRef.current.entries());
|
|
51
|
+
pendingRef.current.clear();
|
|
52
|
+
|
|
53
|
+
for (const [moduleId, usageTimeMs] of entries) {
|
|
54
|
+
if (usageTimeMs <= 0) continue;
|
|
55
|
+
try {
|
|
56
|
+
const res = await ModuleActivationApiService.recordModuleUsage(orgId, {
|
|
57
|
+
moduleId,
|
|
58
|
+
usageTimeMs,
|
|
59
|
+
useCount: 1,
|
|
60
|
+
});
|
|
61
|
+
const tracked = res?.data?.data?.tracked;
|
|
62
|
+
if (tracked === false) {
|
|
63
|
+
trackingEnabledRef.current = false;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if (tracked === true) {
|
|
67
|
+
trackingEnabledRef.current = true;
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
pendingRef.current.set(moduleId, (pendingRef.current.get(moduleId) ?? 0) + usageTimeMs);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const id = setInterval(flush, FLUSH_INTERVAL_MS);
|
|
77
|
+
const onHide = () => void flush();
|
|
78
|
+
const onVisibility = () => {
|
|
79
|
+
if (document.visibilityState === 'hidden') void flush();
|
|
80
|
+
};
|
|
81
|
+
window.addEventListener('pagehide', onHide);
|
|
82
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
83
|
+
|
|
84
|
+
return () => {
|
|
85
|
+
clearInterval(id);
|
|
86
|
+
window.removeEventListener('pagehide', onHide);
|
|
87
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
88
|
+
void flush();
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
92
|
+
}, [currentOrganization?.id, currentModuleId]);
|
|
93
|
+
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {usePathname} from "next/navigation"
|
|
4
|
+
import {useEffect, useState} from "react"
|
|
5
|
+
import {useModuleStore} from "../stores/module.store"
|
|
6
|
+
import {useAuth} from "../hooks/use-auth"
|
|
7
|
+
import {DomainsEnum} from "../../domain/enums/domains.enum"
|
|
8
|
+
import {ModuleDeclarationInterface} from "../../domain/entities/module.interface"
|
|
9
|
+
import {UserInterface} from "../../domain/entities/user.interface"
|
|
10
|
+
import {ModulesGuardForbiddenView} from "../../presentation/components/modules-guard-forbidden"
|
|
11
|
+
|
|
12
|
+
const MODULE_DOMAINS: Record<string, DomainsEnum[]> = {
|
|
13
|
+
DASHBOARD: [DomainsEnum.Analytics, DomainsEnum.Activity, DomainsEnum.UserActivity],
|
|
14
|
+
ACCESS_CONTROL: [DomainsEnum.Role],
|
|
15
|
+
IDENTITY: [DomainsEnum.User, DomainsEnum.UserDevice],
|
|
16
|
+
BILLING: [DomainsEnum.Invoice, DomainsEnum.PaymentMethod],
|
|
17
|
+
BLOGGING: [DomainsEnum.Post, DomainsEnum.PostCategory, DomainsEnum.PostCollaborator],
|
|
18
|
+
CRM: [DomainsEnum.Deal, DomainsEnum.Lead, DomainsEnum.Contact, DomainsEnum.SalesTeam],
|
|
19
|
+
NOTIFICATION: [DomainsEnum.Notification],
|
|
20
|
+
ORGANIZATION: [DomainsEnum.Organization, DomainsEnum.OrganizationMember, DomainsEnum.OrganizationPreference],
|
|
21
|
+
PROJECT_MANAGEMENT: [DomainsEnum.Project, DomainsEnum.Task, DomainsEnum.TaskReminder],
|
|
22
|
+
RESTAURANT: [DomainsEnum.RestaurantDish, DomainsEnum.RestaurantMenu, DomainsEnum.RestaurantOrder, DomainsEnum.RestaurantCustomer, DomainsEnum.RestaurantSalesSession],
|
|
23
|
+
STOCK_MANAGEMENT: [DomainsEnum.Stock, DomainsEnum.StockMovement, DomainsEnum.Order, DomainsEnum.Product],
|
|
24
|
+
MEDIA_LIBRARY: [DomainsEnum.Media],
|
|
25
|
+
USER_ACTIVITY: [DomainsEnum.UserActivity, DomainsEnum.Activity],
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// function findCurrentModule(pathname: string, modules: ModuleDeclarationInterface[]): ModuleDeclarationInterface | undefined {
|
|
29
|
+
// const sortedModules = [...modules].sort((a, b) => b.uri.length - a.uri.length)
|
|
30
|
+
// return sortedModules.find(module => pathname.startsWith(module.uri))
|
|
31
|
+
// }
|
|
32
|
+
|
|
33
|
+
function hasReadAccess(user: UserInterface | null | undefined, domains: DomainsEnum[]): boolean {
|
|
34
|
+
if (!user?.permissions) return false
|
|
35
|
+
return domains.every(domain => user.permissions?.[domain]?.read)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function ModulesGuardProvider({children}: { children: React.ReactNode }) {
|
|
39
|
+
const pathname = usePathname()
|
|
40
|
+
const {modules, selectedModule: currentModule} = useModuleStore()
|
|
41
|
+
const {user} = useAuth()
|
|
42
|
+
const [mounted, setMounted] = useState(false)
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
setMounted(true)
|
|
46
|
+
}, [])
|
|
47
|
+
|
|
48
|
+
if (!mounted) return <>{children}</>
|
|
49
|
+
|
|
50
|
+
const isExcluded = pathname === '/' || pathname === '/dashboard' || pathname === '/store' || pathname.startsWith('/store/') || pathname.startsWith('/auth')
|
|
51
|
+
if (isExcluded) return <>{children}</>
|
|
52
|
+
|
|
53
|
+
// const currentModule = findCurrentModule(pathname, modules)
|
|
54
|
+
if (!currentModule) return <>{children}</>
|
|
55
|
+
|
|
56
|
+
const domains = MODULE_DOMAINS[currentModule.key ?? currentModule.identifier] || []
|
|
57
|
+
if (!domains || domains.length === 0) return <>{children}</>
|
|
58
|
+
|
|
59
|
+
if (!hasReadAccess(user, domains)) {
|
|
60
|
+
return <ModulesGuardForbiddenView module={currentModule}/>
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return <>{children}</>
|
|
64
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {useEffect} from "react";
|
|
4
|
+
import {useModuleStore} from "../stores/module.store";
|
|
5
|
+
import {RoutineInterface} from "../../domain/typing/routine.types";
|
|
6
|
+
import {useRoutines} from "../routines/routine.hook";
|
|
7
|
+
import {toast} from "sonner";
|
|
8
|
+
|
|
9
|
+
export function ModulesRoutinesProvider() {
|
|
10
|
+
const {enqueue, clear, run} = useRoutines()
|
|
11
|
+
const selectedModule = useModuleStore((state) => state.selectedModule);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
clear(false);
|
|
15
|
+
|
|
16
|
+
if (!selectedModule?.routines) return;
|
|
17
|
+
|
|
18
|
+
selectedModule.routines.forEach(
|
|
19
|
+
(routine: RoutineInterface<any>) =>
|
|
20
|
+
enqueue(routine).start(routine.id)
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
run()
|
|
24
|
+
.then((routines) => {
|
|
25
|
+
|
|
26
|
+
})
|
|
27
|
+
.catch(err => {
|
|
28
|
+
toast.error(err.message || err.toString())
|
|
29
|
+
})
|
|
30
|
+
}, [selectedModule]);
|
|
31
|
+
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {usePathname} from "next/navigation";
|
|
4
|
+
import {useEffect, useMemo} from "react";
|
|
5
|
+
import {useModuleStore} from "../stores/module.store";
|
|
6
|
+
|
|
7
|
+
export function ModulesSwitcherProvider() {
|
|
8
|
+
const {modules, selectModule} = useModuleStore();
|
|
9
|
+
const pathname = usePathname();
|
|
10
|
+
|
|
11
|
+
const selectedModuleKey = useMemo(() => {
|
|
12
|
+
if (!modules || !pathname) return null;
|
|
13
|
+
|
|
14
|
+
return modules
|
|
15
|
+
.filter(module => module.key && pathname.startsWith(module.uri))
|
|
16
|
+
.sort((a, b) => b.uri.length - a.uri.length)[0]?.key ?? null;
|
|
17
|
+
}, [modules, pathname]);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!selectedModuleKey) return;
|
|
21
|
+
selectModule(selectedModuleKey);
|
|
22
|
+
}, [selectedModuleKey, selectModule]);
|
|
23
|
+
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {QueryClient, QueryClientProvider} from "@tanstack/react-query";
|
|
4
|
+
import {ReactNode} from "react";
|
|
5
|
+
|
|
6
|
+
export interface QueryProviderProps{
|
|
7
|
+
children: ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const queryClient = new QueryClient({
|
|
11
|
+
defaultOptions: {
|
|
12
|
+
queries: {
|
|
13
|
+
staleTime: 30_000,
|
|
14
|
+
gcTime: 5 * 60_000,
|
|
15
|
+
refetchOnWindowFocus: false,
|
|
16
|
+
retry: 1,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
export function QueryProvider({children}: QueryProviderProps){
|
|
21
|
+
return (
|
|
22
|
+
|
|
23
|
+
<QueryClientProvider client={queryClient}>
|
|
24
|
+
{children}
|
|
25
|
+
</QueryClientProvider>
|
|
26
|
+
)
|
|
27
|
+
}
|