@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,237 @@
|
|
|
1
|
+
import axios, {AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosProgressEvent} from "axios";
|
|
2
|
+
import {AppConfig} from "../../domain/config/app.config";
|
|
3
|
+
import {AuthUserService} from "../../application/service/auth-user.service";
|
|
4
|
+
import {redirect} from "next/navigation";
|
|
5
|
+
import {AuthConfig} from "../../domain/config/auth.config";
|
|
6
|
+
import {toast} from "sonner";
|
|
7
|
+
import {useAuth} from "../hooks/use-auth";
|
|
8
|
+
|
|
9
|
+
class RequestLock {
|
|
10
|
+
private pending = 0;
|
|
11
|
+
private readonly queue: Array<() => void> = [];
|
|
12
|
+
private lastRequestTime = 0;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
private readonly maxConcurrency: number = 3,
|
|
16
|
+
private readonly minInterval: number = 200,
|
|
17
|
+
) {}
|
|
18
|
+
|
|
19
|
+
async acquire(): Promise<void> {
|
|
20
|
+
if (this.pending >= this.maxConcurrency) {
|
|
21
|
+
await new Promise<void>(resolve => this.queue.push(resolve));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const now = Date.now();
|
|
25
|
+
const elapsed = now - this.lastRequestTime;
|
|
26
|
+
if (elapsed < this.minInterval && this.lastRequestTime > 0) {
|
|
27
|
+
await new Promise<void>(resolve => setTimeout(resolve, this.minInterval - elapsed));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.pending++;
|
|
31
|
+
this.lastRequestTime = Date.now();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
release(): void {
|
|
35
|
+
this.pending--;
|
|
36
|
+
this.lastRequestTime = Date.now();
|
|
37
|
+
const next = this.queue.shift();
|
|
38
|
+
if (next) next();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const requestLock = new RequestLock(3, 200);
|
|
43
|
+
|
|
44
|
+
export class ApiService {
|
|
45
|
+
|
|
46
|
+
protected static _instance: AxiosInstance | undefined;
|
|
47
|
+
|
|
48
|
+
protected static baseUrl: string = AppConfig.CORE_API_HOST as string;
|
|
49
|
+
protected static timeout: number = AppConfig.API_TIMEOUT;
|
|
50
|
+
|
|
51
|
+
static get instance() {
|
|
52
|
+
this._instance = this._instance || axios.create({
|
|
53
|
+
timeout: this.timeout,
|
|
54
|
+
headers: {
|
|
55
|
+
// "X-API-KEY": `${AppConfig.key}`,
|
|
56
|
+
// "X-API-TOKEN": `${AppConfig.token}`,
|
|
57
|
+
// "X-TIMESTAMP": Math.floor(Date.now()/1000).toString(),
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// this._instance = this._instance || axios;
|
|
62
|
+
|
|
63
|
+
return this._instance;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
protected static buildAuthHeaders(extra?: Record<string, string>): Record<string, string> {
|
|
67
|
+
const token = AuthUserService.getToken();
|
|
68
|
+
const device = AuthUserService.getDevice();
|
|
69
|
+
const apiKey = AuthUserService.getApiKey();
|
|
70
|
+
const organization = AuthUserService.getCurrentOrganization();
|
|
71
|
+
const csrfToken = ApiService.getCsrfToken();
|
|
72
|
+
return {
|
|
73
|
+
"X-timestamp": (new Date()).toString(),
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
"Accept": "*",
|
|
76
|
+
...(token ? {"Authorization": `Bearer ${token}`} : {}),
|
|
77
|
+
...(device ? {"X-Device": device} : {}),
|
|
78
|
+
...(apiKey ? {"X-API-KEY": apiKey} : {}),
|
|
79
|
+
...(organization ? {"X-Organization-Id": organization.id} : {}),
|
|
80
|
+
...(csrfToken ? {"X-CSRF-Token": csrfToken} : {}),
|
|
81
|
+
"X-Client-Type": "desktop",
|
|
82
|
+
...extra,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private static getCsrfToken(): string | null {
|
|
87
|
+
if (typeof document === 'undefined') return null;
|
|
88
|
+
const match = document.cookie.match(/(?:^|;\s*)_csrf=([^;]*)/);
|
|
89
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static async request<T>(method: string, uri: string, data?: Record<string, any>, config?: AxiosRequestConfig<any> | undefined): Promise<AxiosResponse<T, any, {}>> {
|
|
93
|
+
return this.executeWithRateLimit(async () => {
|
|
94
|
+
const isGetMethod = method.toLowerCase() === 'get'
|
|
95
|
+
const headers = this.buildAuthHeaders()
|
|
96
|
+
|
|
97
|
+
let url = `${this.baseUrl}${uri}`;
|
|
98
|
+
|
|
99
|
+
if (isGetMethod) {
|
|
100
|
+
let queryString = '';
|
|
101
|
+
if (data) {
|
|
102
|
+
const params = Object.entries(data)
|
|
103
|
+
.map(([key, value]) => value ? `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`: undefined)
|
|
104
|
+
.filter(v => typeof v !== 'undefined')
|
|
105
|
+
.join('&');
|
|
106
|
+
if (params) {
|
|
107
|
+
queryString = (url.includes('?') ? '&' : '?') + params;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
url = `${url}${queryString}`;
|
|
111
|
+
data = undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
return await this.instance.request({method, data, url, headers, ...config});
|
|
116
|
+
} catch (error: any) {
|
|
117
|
+
if (axios.isAxiosError(error) && error.response)
|
|
118
|
+
await this.checkUnAuthenticationError(error.response);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private static isRetryableError(error: any): boolean {
|
|
125
|
+
return axios.isAxiosError(error) && (
|
|
126
|
+
error.response?.status === 429 ||
|
|
127
|
+
!error.response
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private static async executeWithRateLimit<T>(fn: () => Promise<T>, retries: number = 3): Promise<T> {
|
|
132
|
+
await requestLock.acquire();
|
|
133
|
+
let lastError: any;
|
|
134
|
+
try {
|
|
135
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
136
|
+
try {
|
|
137
|
+
const result = await fn();
|
|
138
|
+
return result;
|
|
139
|
+
} catch (error: any) {
|
|
140
|
+
lastError = error;
|
|
141
|
+
if (this.isRetryableError(error) && attempt < retries) {
|
|
142
|
+
const delay = error.response?.status === 429
|
|
143
|
+
? (() => {
|
|
144
|
+
const retryAfter = error.response.headers['retry-after'];
|
|
145
|
+
return retryAfter
|
|
146
|
+
? parseInt(retryAfter, 10) * 1000
|
|
147
|
+
: Math.min(1000 * Math.pow(2, attempt), 10000);
|
|
148
|
+
})()
|
|
149
|
+
: 500 * Math.pow(2, attempt);
|
|
150
|
+
await new Promise<void>(resolve => setTimeout(resolve, delay));
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (!this.isRetryableError(lastError)) {
|
|
154
|
+
this.parseError(lastError);
|
|
155
|
+
}
|
|
156
|
+
throw lastError;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
throw lastError;
|
|
160
|
+
} finally {
|
|
161
|
+
requestLock.release();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
protected static async checkUnAuthenticationError<T extends AxiosResponse<any>>(responses: T): Promise<void> {
|
|
166
|
+
if (typeof responses === 'object') {
|
|
167
|
+
if (responses.status === 401 || responses.status === 403) {
|
|
168
|
+
toast.error(`Vous n'êtes pas authorisé à avoir acceder à cette ressource`);
|
|
169
|
+
// await authLogoutUtil();
|
|
170
|
+
// redirect(AuthConfig.routes.login);
|
|
171
|
+
}
|
|
172
|
+
// if (responses.status === 500) {
|
|
173
|
+
// if ('errorCode' in responses.data) {
|
|
174
|
+
// const errorCode = parseInt((responses.data['errorCode']).toString());
|
|
175
|
+
// if (errorCode === 1001) {
|
|
176
|
+
// toast.error(`Vous devez être connecté pour acceder à cette ressource`);
|
|
177
|
+
// await authLogoutUtil();
|
|
178
|
+
// console.log(`Vous devez être connecté pour acceder à cette ressource`);
|
|
179
|
+
// redirect(AuthConfig.routes.login);
|
|
180
|
+
// }
|
|
181
|
+
// }
|
|
182
|
+
// }
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static async upload<T = any>(uri: string, formData: FormData, onUploadProgress?: (progressEvent: AxiosProgressEvent) => void, config?: AxiosRequestConfig<any> | undefined): Promise<AxiosResponse<T, any, {}>> {
|
|
187
|
+
// Ne PAS forcer « Content-Type » : axios (transformRequest) laisse le header tel quel
|
|
188
|
+
// pour un FormData, et un multipart sans boundary fait attendre le parseur serveur.
|
|
189
|
+
// On retire donc le défaut JSON pour que le client HTTP pose le bon header + boundary.
|
|
190
|
+
const headers = this.buildAuthHeaders();
|
|
191
|
+
delete headers["Content-Type"];
|
|
192
|
+
const url = `${this.baseUrl}${uri}`;
|
|
193
|
+
|
|
194
|
+
return this.executeWithRateLimit(async () => {
|
|
195
|
+
try {
|
|
196
|
+
return await this.instance.post(url, formData, {
|
|
197
|
+
headers,
|
|
198
|
+
onUploadProgress,
|
|
199
|
+
...config,
|
|
200
|
+
});
|
|
201
|
+
} catch (error: any) {
|
|
202
|
+
if (axios.isAxiosError(error) && error.response)
|
|
203
|
+
await this.checkUnAuthenticationError(error.response);
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static parseError(error: any, defaultMessage?: string) {
|
|
210
|
+
toast.error(
|
|
211
|
+
(axios.isAxiosError(error) && error.response)
|
|
212
|
+
? error.response.data.message
|
|
213
|
+
: defaultMessage || error.message || "Une erreur est survenue pendant le traitement de la requête"
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
static async post<T = any>(uri: string, data?: Record<string, any>, config?: AxiosRequestConfig<any> | undefined): Promise<AxiosResponse<T, any, {}>> {
|
|
218
|
+
return await this.request<T>('post', `${uri}`, data, config);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
static async get<T = any>(uri: string, data?: Record<string, any>, config?: AxiosRequestConfig<any> | undefined): Promise<AxiosResponse<T, any, {}>> {
|
|
222
|
+
return await this.request<T>('get', `${uri}`, data, config);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
static async put<T = any>(uri: string, data?: Record<string, any>, config?: AxiosRequestConfig<any> | undefined): Promise<AxiosResponse<T, any, {}>> {
|
|
226
|
+
return await this.request<T>('put', `${uri}`, data, config);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
static async patch<T = any>(uri: string, data?: Record<string, any>, config?: AxiosRequestConfig<any> | undefined): Promise<AxiosResponse<T, any, {}>> {
|
|
230
|
+
return await this.request<T>('patch', `${uri}`, data, config);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
static async delete<T = any>(uri: string, data?: Record<string, any>, config?: AxiosRequestConfig<any> | undefined): Promise<AxiosResponse<T, any, {}>> {
|
|
234
|
+
return await this.request<T>('delete', `${uri}`, data, config);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {AuthUserService} from "../../application/service/auth-user.service";
|
|
2
|
+
import {authUserConnectedStore} from "../stores/auth-user-connected.store";
|
|
3
|
+
import {ApiService} from "./api-service";
|
|
4
|
+
import {AuthConfig} from "../../domain/config/auth.config";
|
|
5
|
+
|
|
6
|
+
export async function authLogoutUtil() {
|
|
7
|
+
const {setCurrentUser} = authUserConnectedStore.getState()
|
|
8
|
+
|
|
9
|
+
// 1. Marque au backend que cette application s'est déconnectée sur cet appareil
|
|
10
|
+
// (révocation de la session persistée, de l'appareil et des jetons OAuth).
|
|
11
|
+
await AuthUserService.ready();
|
|
12
|
+
try {
|
|
13
|
+
await ApiService.post('/auth/logout', {clientId: AuthConfig.sso.clientId});
|
|
14
|
+
} catch {
|
|
15
|
+
// best-effort : la suppression locale doit toujours avoir lieu,
|
|
16
|
+
// même si le backend est injoignable ou que la session est déjà expirée.
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 2. Suppression des informations locales (localStorage '@auth-session' + cookie 'token').
|
|
20
|
+
await AuthUserService.clear()
|
|
21
|
+
setCurrentUser(undefined)
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export const CommonClassName = {
|
|
4
|
+
layer: 'backdrop-blur-2xl p-1.5 gap-2 bg-background/50 dark:bg-background-800/50 text-white text-white rounded-full border border-background-400/10',
|
|
5
|
+
glossyBorder: ""
|
|
6
|
+
// glossyBorder: "relative shadow-xs ring-1 ring-white/20 backdrop-blur-md border-1 border-primary/10 dark:border-primary/30"
|
|
7
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
export class EncryptionService {
|
|
4
|
+
private static algorithm = { name: 'AES-GCM', length: 256 };
|
|
5
|
+
private static key: CryptoKey | null = null;
|
|
6
|
+
private static readonly ENCRYPTION_KEY = process.env.NEXT_PUBLIC_ENCRYPTION_KEY;
|
|
7
|
+
|
|
8
|
+
private static async getWebCrypto(): Promise<Crypto> {
|
|
9
|
+
if (typeof window !== 'undefined' && window.crypto?.subtle) {
|
|
10
|
+
return window.crypto;
|
|
11
|
+
}
|
|
12
|
+
if (typeof globalThis !== 'undefined' && globalThis.crypto?.subtle) {
|
|
13
|
+
return globalThis.crypto;
|
|
14
|
+
}
|
|
15
|
+
// For older Node.js environments if globalThis.crypto is not available
|
|
16
|
+
try {
|
|
17
|
+
const { webcrypto } = await import('node:crypto');
|
|
18
|
+
return webcrypto as unknown as Crypto;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw new Error('Web Crypto API not available. Ensure the page is served over HTTPS or localhost (secure context).');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private static async getKey(): Promise<CryptoKey> {
|
|
25
|
+
if (this.key) return this.key;
|
|
26
|
+
|
|
27
|
+
if (!this.ENCRYPTION_KEY) {
|
|
28
|
+
throw new Error('NEXT_PUBLIC_ENCRYPTION_KEY is not defined');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const webCrypto = await this.getWebCrypto();
|
|
32
|
+
const encoder = new TextEncoder();
|
|
33
|
+
const keyData = encoder.encode(this.ENCRYPTION_KEY);
|
|
34
|
+
|
|
35
|
+
// Hash the key to ensure it has the correct length for AES-GCM (256 bits)
|
|
36
|
+
const hash = await webCrypto.subtle.digest('SHA-256', keyData);
|
|
37
|
+
|
|
38
|
+
this.key = await webCrypto.subtle.importKey(
|
|
39
|
+
'raw',
|
|
40
|
+
hash,
|
|
41
|
+
this.algorithm,
|
|
42
|
+
false,
|
|
43
|
+
['encrypt', 'decrypt']
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return this.key;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private static arrayBufferToBase64(buffer: Uint8Array): string {
|
|
50
|
+
if (typeof Buffer !== 'undefined') {
|
|
51
|
+
return Buffer.from(buffer).toString('base64');
|
|
52
|
+
}
|
|
53
|
+
return btoa(String.fromCharCode(...buffer));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private static base64ToArrayBuffer(base64: string): Uint8Array {
|
|
57
|
+
if (typeof Buffer !== 'undefined') {
|
|
58
|
+
return new Uint8Array(Buffer.from(base64, 'base64'));
|
|
59
|
+
}
|
|
60
|
+
const binaryString = atob(base64);
|
|
61
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
62
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
63
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
64
|
+
}
|
|
65
|
+
return bytes;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static async encrypt(data: string): Promise<string> {
|
|
69
|
+
try {
|
|
70
|
+
const key = await this.getKey();
|
|
71
|
+
const webCrypto = await this.getWebCrypto();
|
|
72
|
+
const encoder = new TextEncoder();
|
|
73
|
+
const encodedData = encoder.encode(data);
|
|
74
|
+
|
|
75
|
+
// Initialization vector (IV) - must be unique for each encryption
|
|
76
|
+
const iv = webCrypto.getRandomValues(new Uint8Array(12));
|
|
77
|
+
|
|
78
|
+
const encryptedBuffer = await webCrypto.subtle.encrypt(
|
|
79
|
+
{
|
|
80
|
+
name: this.algorithm.name,
|
|
81
|
+
iv: iv
|
|
82
|
+
},
|
|
83
|
+
key,
|
|
84
|
+
encodedData
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// Combine IV and encrypted data
|
|
88
|
+
const combined = new Uint8Array(iv.length + encryptedBuffer.byteLength);
|
|
89
|
+
combined.set(iv);
|
|
90
|
+
combined.set(new Uint8Array(encryptedBuffer), iv.length);
|
|
91
|
+
|
|
92
|
+
// Convert to base64 for storage
|
|
93
|
+
return this.arrayBufferToBase64(combined);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error('Encryption failed:', error);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static async decrypt(encryptedData: string): Promise<string> {
|
|
101
|
+
try {
|
|
102
|
+
const key = await this.getKey();
|
|
103
|
+
const webCrypto = await this.getWebCrypto();
|
|
104
|
+
const combined = this.base64ToArrayBuffer(encryptedData);
|
|
105
|
+
|
|
106
|
+
const iv = combined.slice(0, 12);
|
|
107
|
+
const data = combined.slice(12);
|
|
108
|
+
|
|
109
|
+
const decryptedBuffer = await webCrypto.subtle.decrypt(
|
|
110
|
+
{
|
|
111
|
+
name: this.algorithm.name,
|
|
112
|
+
iv: iv
|
|
113
|
+
},
|
|
114
|
+
key,
|
|
115
|
+
data
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const decoder = new TextDecoder();
|
|
119
|
+
return decoder.decode(decryptedBuffer);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error('Decryption failed:', error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|