@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,106 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import {create, StoreApi, UseBoundStore} from "zustand";
|
|
5
|
+
import { toast } from "sonner";
|
|
6
|
+
|
|
7
|
+
export type DatesetPayload<T> = {
|
|
8
|
+
value: T;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
key?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// export type DatesetEntity<T> = Record<keyof T, DatesetPayload<T[keyof T]>>
|
|
14
|
+
|
|
15
|
+
export type DatasetValidatorCallable<T> = (value: T) => string | null | undefined | boolean
|
|
16
|
+
|
|
17
|
+
export interface DatasetInterface<T extends Object> {
|
|
18
|
+
dataset: T;
|
|
19
|
+
clear: () => void;
|
|
20
|
+
consolidate: () => T;
|
|
21
|
+
getter: <K extends keyof T>(key: K) => (T[K]) | undefined;
|
|
22
|
+
remove: <K extends keyof T>(key: K) => void;
|
|
23
|
+
setter: <K extends keyof T>(key: K, value: T[K]|undefined) => void;
|
|
24
|
+
setMany: (data: Partial<T>) => void;
|
|
25
|
+
validate: () => { valid: boolean; errors: Record<string, string> };
|
|
26
|
+
ensureValidAndToast: (mode?: "single" | "multiple" | "rich") => boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type DatasetInstanceType<T extends Object> = UseBoundStore<StoreApi<DatasetInterface<T>>>
|
|
30
|
+
|
|
31
|
+
export function createDataset<T extends Object>(defaultValues?: T, validators?: Partial<Record<keyof T, DatasetValidatorCallable<any>>>): DatasetInstanceType<T> {
|
|
32
|
+
return create<DatasetInterface<T>>((setState, getState) => ({
|
|
33
|
+
dataset: defaultValues || {} as T,
|
|
34
|
+
clear() {
|
|
35
|
+
setState({
|
|
36
|
+
dataset: {} as T
|
|
37
|
+
})
|
|
38
|
+
},
|
|
39
|
+
consolidate() {
|
|
40
|
+
const state = getState() as any;
|
|
41
|
+
// appeler la validation et afficher les erreurs via toast riche si nécessaire
|
|
42
|
+
if (typeof state.ensureValidAndToast === "function") {
|
|
43
|
+
state.ensureValidAndToast('rich');
|
|
44
|
+
}
|
|
45
|
+
return state.dataset || {};
|
|
46
|
+
},
|
|
47
|
+
getter<K extends keyof T>(key: K): (T[K]) | undefined {
|
|
48
|
+
return getState().dataset[key] || undefined;
|
|
49
|
+
},
|
|
50
|
+
remove<K extends keyof T>(key: K) {
|
|
51
|
+
const dataset: T = {} as T;
|
|
52
|
+
for (const [k, value] of Object.entries(getState().dataset)) {
|
|
53
|
+
if (k !== (key as string)) {
|
|
54
|
+
(dataset as any)[k] = value as any;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return setState({dataset});
|
|
58
|
+
},
|
|
59
|
+
setter<K extends keyof T>(key: K, value: T[K]|undefined) {
|
|
60
|
+
return setState({dataset: {...getState().dataset, [key]: value}})
|
|
61
|
+
},
|
|
62
|
+
setMany(data: Partial<T>) {
|
|
63
|
+
setState({dataset: {...getState().dataset, ...data}})
|
|
64
|
+
},
|
|
65
|
+
validate() {
|
|
66
|
+
const errors: Record<string, string> = {};
|
|
67
|
+
if (validators) {
|
|
68
|
+
for (const [k, fn] of Object.entries(validators as Record<string, DatasetValidatorCallable<any>>)) {
|
|
69
|
+
try {
|
|
70
|
+
const value = (getState().dataset as any)[k];
|
|
71
|
+
const res = fn?.(value);
|
|
72
|
+
if (typeof res === "string" && res.length) errors[k] = res;
|
|
73
|
+
else if (res === false) errors[k] = "Invalid value";
|
|
74
|
+
} catch (err) {
|
|
75
|
+
errors[k] = "Validation failed";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { valid: Object.keys(errors).length === 0, errors };
|
|
80
|
+
},
|
|
81
|
+
ensureValidAndToast(mode: "single" | "multiple" | "rich" = "single") {
|
|
82
|
+
const result = (getState() as any).validate() as { valid: boolean; errors: Record<string, string> };
|
|
83
|
+
if (!result.valid) {
|
|
84
|
+
if (mode === "multiple") {
|
|
85
|
+
for (const [k, m] of Object.entries(result.errors)) {
|
|
86
|
+
toast.error(`${k}: ${m}`);
|
|
87
|
+
}
|
|
88
|
+
} else if (mode === "rich") {
|
|
89
|
+
const items = Object.entries(result.errors).map(([k, m]) => React.createElement('li', { key: k }, `${k}: ${m}`));
|
|
90
|
+
const content = React.createElement(
|
|
91
|
+
'div',
|
|
92
|
+
{ style: { padding: 0 } },
|
|
93
|
+
React.createElement('strong', null, 'Veuillez corriger les erreurs suivantes :'),
|
|
94
|
+
React.createElement('ul', { style: { margin: '8px 0 0 16px' } }, ...items)
|
|
95
|
+
);
|
|
96
|
+
toast.error(content as any);
|
|
97
|
+
} else {
|
|
98
|
+
const lines = Object.entries(result.errors).map(([k, m]) => `• ${k}: ${m}`);
|
|
99
|
+
const message = ["Veuillez corriger les erreurs suivantes :", ...lines].join("\n");
|
|
100
|
+
toast.error(message);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return result.valid;
|
|
104
|
+
}
|
|
105
|
+
}))
|
|
106
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {create} from "zustand";
|
|
4
|
+
import {persist} from "zustand/middleware";
|
|
5
|
+
import {ModuleDeclarationInterface, ModuleInstanceInterface} from "../../domain/entities/module.interface";
|
|
6
|
+
import {ModuleInstance} from "../../application/module-instance";
|
|
7
|
+
import {ModuleActivationApiService} from "../../application/service/module-activation-api.service";
|
|
8
|
+
import {StorefrontApiService} from "../../application/service/storefront-api.service";
|
|
9
|
+
import {ModuleActivationInterface} from "../../domain/entities/module-activation.interface";
|
|
10
|
+
import {ModuleStoreStateType} from "../../domain/entities/module-activation.interface";
|
|
11
|
+
import {authUserConnectedStore} from "./auth-user-connected.store";
|
|
12
|
+
|
|
13
|
+
interface ModuleState {
|
|
14
|
+
modules: ModuleDeclarationInterface[];
|
|
15
|
+
addModule: (module: ModuleDeclarationInterface) => void;
|
|
16
|
+
addModules: (modules: ModuleDeclarationInterface[]) => void;
|
|
17
|
+
toggleModule: (id: string) => void;
|
|
18
|
+
removeModule: (id: string) => void;
|
|
19
|
+
setModules: (modules: ModuleDeclarationInterface[]) => void;
|
|
20
|
+
selectedModule: ModuleDeclarationInterface | null;
|
|
21
|
+
selectModule: (idOrKeyOrIdentifier: string) => void;
|
|
22
|
+
construct: (idOrKeyOrIdentifier: string) => ModuleInstanceInterface | null;
|
|
23
|
+
verifyModules: () => Promise<void>;
|
|
24
|
+
|
|
25
|
+
// Module Store extensions
|
|
26
|
+
updateModuleState: (id: string, state: ModuleStoreStateType) => void;
|
|
27
|
+
updateModuleConfig: (id: string, config: Record<string, string>) => void;
|
|
28
|
+
setModuleInstalled: (id: string, installed: boolean) => void;
|
|
29
|
+
setModuleActivationExpiry: (id: string, expiresAt: string | null) => void;
|
|
30
|
+
getModuleByState: (state: ModuleStoreStateType) => ModuleDeclarationInterface[];
|
|
31
|
+
getModuleStoreStats: () => {
|
|
32
|
+
total: number;
|
|
33
|
+
installed: number;
|
|
34
|
+
enabled: number;
|
|
35
|
+
disabled: number;
|
|
36
|
+
available: number;
|
|
37
|
+
failed: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Une activation est valide si activée et non expirée (au niveau de l'activation
|
|
43
|
+
* elle-même et de sa clé sérielle).
|
|
44
|
+
*/
|
|
45
|
+
function isActivationActive(activation: ModuleActivationInterface): boolean {
|
|
46
|
+
if (!activation.isEnabled) return false;
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
if (activation.expiredAt && new Date(activation.expiredAt).getTime() < now) return false;
|
|
49
|
+
if (activation.serialKey?.expiredAt && new Date(activation.serialKey.expiredAt).getTime() < now) return false;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface ModuleVerification {
|
|
54
|
+
catalog: Set<string>;
|
|
55
|
+
allowed: Set<string>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Récupère le catalogue des modules (ModuleStore) et les activations de
|
|
60
|
+
* l'organisation courante, puis calcule :
|
|
61
|
+
* - `catalog` : les identifiants existants dans le ModuleStore ;
|
|
62
|
+
* - `allowed` : les identifiants dont l'organisation a effectivement accès.
|
|
63
|
+
* Retourne `null` si l'organisation est inconnue ou si l'appel API échoue
|
|
64
|
+
* (dans ce cas, aucune vérification n'est appliquée).
|
|
65
|
+
*/
|
|
66
|
+
async function fetchModuleVerification(organizationId?: string | null): Promise<ModuleVerification | null> {
|
|
67
|
+
if (!organizationId) return null;
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const [catalogResponse, activationsResponse] = await Promise.all([
|
|
71
|
+
StorefrontApiService.getCatalogModules(),
|
|
72
|
+
ModuleActivationApiService.getOrganizationModules(organizationId),
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
const catalog = Array.isArray(catalogResponse?.data?.data) ? catalogResponse.data.data : [];
|
|
76
|
+
const activations = Array.isArray(activationsResponse?.data?.data) ? activationsResponse.data.data : [];
|
|
77
|
+
|
|
78
|
+
if (catalog.length === 0) return null;
|
|
79
|
+
|
|
80
|
+
const activeModuleIdentifiers = new Set(
|
|
81
|
+
activations.filter(isActivationActive).map(activation => activation.moduleIdentifier)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
catalog: new Set(catalog.map(module => module.identifier)),
|
|
86
|
+
allowed: new Set(
|
|
87
|
+
catalog
|
|
88
|
+
.filter(module => activeModuleIdentifiers.has(module.identifier))
|
|
89
|
+
.map(module => module.identifier)
|
|
90
|
+
),
|
|
91
|
+
};
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Recherche un module du store par son identifiant technique (recommandé),
|
|
99
|
+
* en acceptant un repli sur sa clé courte.
|
|
100
|
+
*/
|
|
101
|
+
function findModule(
|
|
102
|
+
modules: ModuleDeclarationInterface[],
|
|
103
|
+
idOrKeyOrIdentifier: string,
|
|
104
|
+
): ModuleDeclarationInterface | undefined {
|
|
105
|
+
return modules.find(m =>
|
|
106
|
+
m.identifier === idOrKeyOrIdentifier || m.key === idOrKeyOrIdentifier
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const useModuleStore = create<ModuleState>()(
|
|
111
|
+
// persist(
|
|
112
|
+
(setState, getState) => ({
|
|
113
|
+
modules: [],
|
|
114
|
+
selectedModule: null,
|
|
115
|
+
addModule: (module) => {
|
|
116
|
+
setState((state) => {
|
|
117
|
+
const persisted = state.modules.find(m => m.identifier === module.identifier);
|
|
118
|
+
return {
|
|
119
|
+
modules: [...state.modules.filter(m => m.identifier !== module.identifier), {
|
|
120
|
+
...module,
|
|
121
|
+
storeState: persisted?.storeState ?? module.storeState ?? (module.isEnabled ? 'enabled' : 'available'),
|
|
122
|
+
storeConfig: persisted?.storeConfig ?? module.storeConfig,
|
|
123
|
+
isInstalled: persisted?.isInstalled ?? module.isInstalled ?? false,
|
|
124
|
+
activationExpiresAt: persisted?.activationExpiresAt ?? module.activationExpiresAt,
|
|
125
|
+
lastSyncedAt: persisted?.lastSyncedAt ?? module.lastSyncedAt,
|
|
126
|
+
isEnabled: persisted?.isEnabled ?? module.isEnabled,
|
|
127
|
+
}]
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
void getState().verifyModules();
|
|
131
|
+
},
|
|
132
|
+
addModules: (newModules: ModuleDeclarationInterface[]) => {
|
|
133
|
+
setState((state) => {
|
|
134
|
+
// Fusionne les nouvelles déclarations (complètes) avec l'état
|
|
135
|
+
// (storeState, config, installation) des modules existants.
|
|
136
|
+
const existingByIdentifier = new Map(state.modules.map(m => [m.identifier, m]));
|
|
137
|
+
const merged = newModules.map((m) => {
|
|
138
|
+
const persisted = existingByIdentifier.get(m.identifier);
|
|
139
|
+
return {
|
|
140
|
+
...m,
|
|
141
|
+
storeState: persisted?.storeState ?? m.storeState ?? (m.isEnabled ? 'enabled' : 'available'),
|
|
142
|
+
storeConfig: persisted?.storeConfig ?? m.storeConfig,
|
|
143
|
+
isInstalled: persisted?.isInstalled ?? m.isInstalled ?? false,
|
|
144
|
+
activationExpiresAt: persisted?.activationExpiresAt ?? m.activationExpiresAt,
|
|
145
|
+
lastSyncedAt: persisted?.lastSyncedAt ?? m.lastSyncedAt,
|
|
146
|
+
isEnabled: persisted?.isEnabled ?? m.isEnabled,
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
const newIds = new Set(merged.map(m => m.identifier));
|
|
150
|
+
const others = state.modules.filter(m => !newIds.has(m.identifier));
|
|
151
|
+
return {modules: [...others, ...merged]};
|
|
152
|
+
});
|
|
153
|
+
void getState().verifyModules();
|
|
154
|
+
},
|
|
155
|
+
toggleModule: (id) => setState((state) => ({
|
|
156
|
+
modules: state.modules.map((m) => {
|
|
157
|
+
if (m.identifier !== id || m.isDefault) return m;
|
|
158
|
+
const newEnabled = !m.isEnabled;
|
|
159
|
+
return {
|
|
160
|
+
...m,
|
|
161
|
+
isEnabled: newEnabled,
|
|
162
|
+
storeState: newEnabled ? 'enabled' as ModuleStoreStateType : 'disabled' as ModuleStoreStateType,
|
|
163
|
+
};
|
|
164
|
+
}),
|
|
165
|
+
})),
|
|
166
|
+
removeModule: (id) => setState((state) => ({
|
|
167
|
+
modules: state.modules.filter((m) => m.identifier !== id || m.isDefault),
|
|
168
|
+
})),
|
|
169
|
+
setModules: (modules) => setState({
|
|
170
|
+
modules: modules.map(m => ({
|
|
171
|
+
...m,
|
|
172
|
+
storeState: m.storeState ?? (m.isEnabled ? 'enabled' : 'available'),
|
|
173
|
+
}))
|
|
174
|
+
}),
|
|
175
|
+
verifyModules: async () => {
|
|
176
|
+
const organizationId = authUserConnectedStore.getState().currentOrganization?.id;
|
|
177
|
+
const verification = await fetchModuleVerification(organizationId);
|
|
178
|
+
if (!verification) return;
|
|
179
|
+
|
|
180
|
+
setState((state) => ({
|
|
181
|
+
// Garde les modules hors catalogue (déclarés en local) et ceux
|
|
182
|
+
// autorisés pour l'organisation ; retire les modules du catalogue
|
|
183
|
+
// auxquels l'organisation n'a pas accès.
|
|
184
|
+
modules: state.modules.filter(
|
|
185
|
+
(module) => !verification.catalog.has(module.identifier) || verification.allowed.has(module.identifier)
|
|
186
|
+
),
|
|
187
|
+
}));
|
|
188
|
+
},
|
|
189
|
+
construct: (idOrKeyOrIdentifier: string) => {
|
|
190
|
+
const module = findModule(getState().modules, idOrKeyOrIdentifier);
|
|
191
|
+
return (module && module.key) ? new ModuleInstance(module.key) : null;
|
|
192
|
+
},
|
|
193
|
+
selectModule: (idOrKeyOrIdentifier: string) => {
|
|
194
|
+
const module = findModule(getState().modules, idOrKeyOrIdentifier);
|
|
195
|
+
if (module) {
|
|
196
|
+
setState({selectedModule: module});
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
// Module Store extensions
|
|
201
|
+
updateModuleState: (id, storeState) => setState((state) => ({
|
|
202
|
+
modules: state.modules.map((m) =>
|
|
203
|
+
m.identifier === id ? {
|
|
204
|
+
...m,
|
|
205
|
+
storeState,
|
|
206
|
+
isEnabled: storeState === 'enabled' || storeState === 'installed',
|
|
207
|
+
} : m
|
|
208
|
+
),
|
|
209
|
+
})),
|
|
210
|
+
|
|
211
|
+
updateModuleConfig: (id, config) => setState((state) => ({
|
|
212
|
+
modules: state.modules.map((m) =>
|
|
213
|
+
m.identifier === id ? {...m, storeConfig: config} : m
|
|
214
|
+
),
|
|
215
|
+
})),
|
|
216
|
+
|
|
217
|
+
setModuleInstalled: (id, installed) => setState((state) => ({
|
|
218
|
+
modules: state.modules.map((m) =>
|
|
219
|
+
m.identifier === id ? {
|
|
220
|
+
...m,
|
|
221
|
+
isInstalled: installed,
|
|
222
|
+
storeState: installed
|
|
223
|
+
? (m.isEnabled ? 'enabled' : 'installed') as ModuleStoreStateType
|
|
224
|
+
: 'available' as ModuleStoreStateType,
|
|
225
|
+
} : m
|
|
226
|
+
),
|
|
227
|
+
})),
|
|
228
|
+
|
|
229
|
+
setModuleActivationExpiry: (id, expiresAt) => setState((state) => ({
|
|
230
|
+
modules: state.modules.map((m) =>
|
|
231
|
+
m.identifier === id ? {...m, activationExpiresAt: expiresAt ?? undefined} : m
|
|
232
|
+
),
|
|
233
|
+
})),
|
|
234
|
+
|
|
235
|
+
getModuleByState: (storeState) => {
|
|
236
|
+
return getState().modules.filter(m => m.storeState === storeState);
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
getModuleStoreStats: () => {
|
|
240
|
+
const modules = getState().modules;
|
|
241
|
+
return {
|
|
242
|
+
total: modules.length,
|
|
243
|
+
installed: modules.filter(m => m.isInstalled || m.storeState === 'installed' || m.storeState === 'enabled').length,
|
|
244
|
+
enabled: modules.filter(m => m.storeState === 'enabled').length,
|
|
245
|
+
disabled: modules.filter(m => m.storeState === 'disabled').length,
|
|
246
|
+
available: modules.filter(m => m.storeState === 'available').length,
|
|
247
|
+
failed: modules.filter(m => m.storeState === 'failed').length,
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
})
|
|
251
|
+
// {
|
|
252
|
+
// name: "module-storage",
|
|
253
|
+
// partialize: (state) => ({
|
|
254
|
+
// modules: state.modules.map(m => ({
|
|
255
|
+
// id: m.identifier,
|
|
256
|
+
// storeState: m.storeState,
|
|
257
|
+
// isInstalled: m.isInstalled,
|
|
258
|
+
// storeConfig: m.storeConfig,
|
|
259
|
+
// lastSyncedAt: m.lastSyncedAt,
|
|
260
|
+
// activationExpiresAt: m.activationExpiresAt,
|
|
261
|
+
// isEnabled: m.isEnabled,
|
|
262
|
+
// })),
|
|
263
|
+
// }),
|
|
264
|
+
// }
|
|
265
|
+
// )
|
|
266
|
+
);
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { create } from "zustand"
|
|
4
|
+
import { StorageApiService } from "../../application/service/storage-api-service"
|
|
5
|
+
import type { MediaUploadOptions } from "../../domain/entities/media"
|
|
6
|
+
import type { AxiosProgressEvent } from "axios"
|
|
7
|
+
|
|
8
|
+
export type UploadStatus = "idle" | "uploading" | "done" | "error" | "cancelled"
|
|
9
|
+
|
|
10
|
+
export interface UploadItem {
|
|
11
|
+
id: string
|
|
12
|
+
name: string
|
|
13
|
+
size: number
|
|
14
|
+
progress: number
|
|
15
|
+
speed: number
|
|
16
|
+
eta: number | null
|
|
17
|
+
status: UploadStatus
|
|
18
|
+
error?: string
|
|
19
|
+
result?: any
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface UploadStoreState {
|
|
23
|
+
uploads: UploadItem[]
|
|
24
|
+
isExpanded: boolean
|
|
25
|
+
hasActiveUploads: boolean
|
|
26
|
+
expand: () => void
|
|
27
|
+
collapse: () => void
|
|
28
|
+
toggle: () => void
|
|
29
|
+
addFiles: (files: File[], options?: MediaUploadOptions) => void
|
|
30
|
+
uploadFile: (file: File, options?: MediaUploadOptions, onProgress?: (event: AxiosProgressEvent) => void) => Promise<any>
|
|
31
|
+
removeFile: (id: string) => void
|
|
32
|
+
retryFile: (id: string) => void
|
|
33
|
+
cancelAll: () => void
|
|
34
|
+
clearCompleted: () => void
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const filesById = new Map<string, File>()
|
|
38
|
+
const optionsById = new Map<string, MediaUploadOptions>()
|
|
39
|
+
const speedTrackers = new Map<string, { loaded: number; timestamp: number }>()
|
|
40
|
+
const controllers = new Map<string, AbortController>()
|
|
41
|
+
|
|
42
|
+
export const useUploadStore = create<UploadStoreState>((set, get) => {
|
|
43
|
+
const recomputeActive = (uploads: UploadItem[]) =>
|
|
44
|
+
uploads.some((u) => u.status === "uploading")
|
|
45
|
+
|
|
46
|
+
const updateUpload = (id: string, patch: Partial<UploadItem>) => {
|
|
47
|
+
const uploads = get().uploads.map((u) => (u.id === id ? { ...u, ...patch } : u))
|
|
48
|
+
set({ uploads, hasActiveUploads: recomputeActive(uploads) })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const trackProgress = (id: string, loaded: number) => {
|
|
52
|
+
const now = Date.now()
|
|
53
|
+
const prev = speedTrackers.get(id)
|
|
54
|
+
const speed = prev
|
|
55
|
+
? (loaded - prev.loaded) / Math.max((now - prev.timestamp) / 1000, 0.001)
|
|
56
|
+
: 0
|
|
57
|
+
speedTrackers.set(id, { loaded, timestamp: now })
|
|
58
|
+
const item = get().uploads.find((u) => u.id === id)
|
|
59
|
+
if (!item) return
|
|
60
|
+
const remaining = item.size - loaded
|
|
61
|
+
const eta = speed > 0 ? remaining / speed : null
|
|
62
|
+
updateUpload(id, { speed, eta, progress: item.size ? (loaded / item.size) * 100 : 0 })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const startUpload = async (id: string, onProgress?: (event: AxiosProgressEvent) => void) => {
|
|
66
|
+
const file = filesById.get(id)
|
|
67
|
+
const item = get().uploads.find((u) => u.id === id)
|
|
68
|
+
const options = optionsById.get(id)
|
|
69
|
+
if (!file || !item) return
|
|
70
|
+
|
|
71
|
+
const controller = new AbortController()
|
|
72
|
+
controllers.set(id, controller)
|
|
73
|
+
updateUpload(id, { status: "uploading", progress: 0, speed: 0, eta: null, error: undefined })
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const response = await StorageApiService.uploadFile(file, options, (event) => {
|
|
77
|
+
trackProgress(id, event.loaded)
|
|
78
|
+
onProgress?.(event)
|
|
79
|
+
}, { signal: controller.signal })
|
|
80
|
+
const result = response.data?.data
|
|
81
|
+
updateUpload(id, { status: "done", progress: 100, eta: null, result })
|
|
82
|
+
return result
|
|
83
|
+
} catch (error: any) {
|
|
84
|
+
const cancelled = controller.signal.aborted
|
|
85
|
+
updateUpload(id, {
|
|
86
|
+
status: cancelled ? "cancelled" : "error",
|
|
87
|
+
eta: null,
|
|
88
|
+
error: cancelled
|
|
89
|
+
? undefined
|
|
90
|
+
: error?.response?.data?.message || error?.message || "Une erreur est survenue",
|
|
91
|
+
})
|
|
92
|
+
throw error
|
|
93
|
+
} finally {
|
|
94
|
+
speedTrackers.delete(id)
|
|
95
|
+
controllers.delete(id)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const abortUpload = (id: string) => {
|
|
100
|
+
controllers.get(id)?.abort()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
uploads: [],
|
|
105
|
+
isExpanded: false,
|
|
106
|
+
hasActiveUploads: false,
|
|
107
|
+
|
|
108
|
+
expand: () => set({ isExpanded: true }),
|
|
109
|
+
collapse: () => set({ isExpanded: false }),
|
|
110
|
+
toggle: () => set((state) => ({ isExpanded: !state.isExpanded })),
|
|
111
|
+
|
|
112
|
+
addFiles: (files, options) => {
|
|
113
|
+
if (!files.length) return
|
|
114
|
+
const newUploads: UploadItem[] = files.map((file) => {
|
|
115
|
+
const id = crypto.randomUUID()
|
|
116
|
+
filesById.set(id, file)
|
|
117
|
+
if (options) optionsById.set(id, options)
|
|
118
|
+
return {
|
|
119
|
+
id,
|
|
120
|
+
name: file.name,
|
|
121
|
+
size: file.size,
|
|
122
|
+
progress: 0,
|
|
123
|
+
speed: 0,
|
|
124
|
+
eta: null,
|
|
125
|
+
status: "idle",
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
set((state) => ({
|
|
129
|
+
uploads: [...state.uploads, ...newUploads],
|
|
130
|
+
isExpanded: true,
|
|
131
|
+
hasActiveUploads: true,
|
|
132
|
+
}))
|
|
133
|
+
newUploads.forEach((upload) => {
|
|
134
|
+
startUpload(upload.id).catch(() => {})
|
|
135
|
+
})
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
uploadFile: (file, options, onProgress) => {
|
|
139
|
+
const id = crypto.randomUUID()
|
|
140
|
+
filesById.set(id, file)
|
|
141
|
+
if (options) optionsById.set(id, options)
|
|
142
|
+
const newUpload: UploadItem = {
|
|
143
|
+
id,
|
|
144
|
+
name: file.name,
|
|
145
|
+
size: file.size,
|
|
146
|
+
progress: 0,
|
|
147
|
+
speed: 0,
|
|
148
|
+
eta: null,
|
|
149
|
+
status: "idle",
|
|
150
|
+
}
|
|
151
|
+
set((state) => ({
|
|
152
|
+
uploads: [...state.uploads, newUpload],
|
|
153
|
+
isExpanded: true,
|
|
154
|
+
hasActiveUploads: true,
|
|
155
|
+
}))
|
|
156
|
+
return startUpload(id, onProgress)
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
removeFile: (id) => {
|
|
160
|
+
abortUpload(id)
|
|
161
|
+
filesById.delete(id)
|
|
162
|
+
optionsById.delete(id)
|
|
163
|
+
speedTrackers.delete(id)
|
|
164
|
+
const uploads = get().uploads.filter((u) => u.id !== id)
|
|
165
|
+
set({ uploads, hasActiveUploads: recomputeActive(uploads) })
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
retryFile: (id) => {
|
|
169
|
+
if (!filesById.has(id)) return
|
|
170
|
+
updateUpload(id, { status: "idle", progress: 0, speed: 0, eta: null, error: undefined })
|
|
171
|
+
set({ hasActiveUploads: true })
|
|
172
|
+
startUpload(id).catch(() => {})
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
cancelAll: () => {
|
|
176
|
+
get().uploads.forEach((u) => abortUpload(u.id))
|
|
177
|
+
const uploads = get().uploads.map((u) =>
|
|
178
|
+
u.status === "uploading" || u.status === "idle"
|
|
179
|
+
? { ...u, status: "cancelled" as const, eta: null }
|
|
180
|
+
: u
|
|
181
|
+
)
|
|
182
|
+
set({ uploads, hasActiveUploads: recomputeActive(uploads) })
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
clearCompleted: () => {
|
|
186
|
+
const uploads = get().uploads.filter(
|
|
187
|
+
(u) => u.status === "uploading" || u.status === "idle"
|
|
188
|
+
)
|
|
189
|
+
get().uploads.forEach((u) => {
|
|
190
|
+
if (u.status === "done" || u.status === "cancelled" || u.status === "error") {
|
|
191
|
+
filesById.delete(u.id)
|
|
192
|
+
optionsById.delete(u.id)
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
set({ uploads, hasActiveUploads: recomputeActive(uploads) })
|
|
196
|
+
},
|
|
197
|
+
}
|
|
198
|
+
})
|