mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
refactor(database): reorganize into actions/components/schemas
This commit is contained in:
+2
-2
@@ -6,8 +6,8 @@ import { eq, and, inArray } from "drizzle-orm";
|
|||||||
import * as drizzleDb from "@/db";
|
import * as drizzleDb from "@/db";
|
||||||
import { getOrganizationProjectDatabases } from "@/db/services/project";
|
import { getOrganizationProjectDatabases } from "@/db/services/project";
|
||||||
import { getActiveMember, getOrganization } from "@/lib/auth/auth";
|
import { getActiveMember, getOrganization } from "@/lib/auth/auth";
|
||||||
import { BackupModalProvider } from "@/features/database/backup-modal-context";
|
import { BackupModalProvider } from "@/features/database/components/backup-modal-context";
|
||||||
import { DatabaseContent } from "@/features/database/database-content";
|
import { DatabaseContent } from "@/features/database/components/database-content";
|
||||||
import { getHealthLast12hLogs } from "@/db/services/healthcheck";
|
import { getHealthLast12hLogs } from "@/db/services/healthcheck";
|
||||||
import { LogsModalProvider } from "@/features/logs/logs-modal-context";
|
import { LogsModalProvider } from "@/features/logs/logs-modal-context";
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {Separator} from "@/components/ui/separator";
|
|||||||
import {Badge} from "@/components/ui/badge";
|
import {Badge} from "@/components/ui/badge";
|
||||||
import {CardsWithPagination} from "@/components/common/cards-with-pagination";
|
import {CardsWithPagination} from "@/components/common/cards-with-pagination";
|
||||||
import {AgentDatabaseCard} from "@/features/agents/components/agent-database-card";
|
import {AgentDatabaseCard} from "@/features/agents/components/agent-database-card";
|
||||||
import {HealthCheckGraph} from "@/features/database/health-grid";
|
import {HealthCheckGraph} from "@/features/database/components/health-grid";
|
||||||
import {HealthcheckLog} from "@/db/schema/15_healthcheck-log";
|
import {HealthcheckLog} from "@/db/schema/15_healthcheck-log";
|
||||||
|
|
||||||
type AgentContentPageProps = {
|
type AgentContentPageProps = {
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ import * as drizzleDb from "@/db";
|
|||||||
import {and, eq, inArray} from "drizzle-orm";
|
import {and, eq, inArray} from "drizzle-orm";
|
||||||
import {withUpdatedAt} from "@/db/utils";
|
import {withUpdatedAt} from "@/db/utils";
|
||||||
import {AlertPolicy} from "@/db/schema/10_alert-policy";
|
import {AlertPolicy} from "@/db/schema/10_alert-policy";
|
||||||
import {PolicySchema} from "@/features/database/channels-policy.schema";
|
import {PolicySchema} from "@/features/database/schemas/channels-policy.schema";
|
||||||
import {StoragePolicy} from "@/db/schema/13_storage-policy";
|
import {StoragePolicy} from "@/db/schema/13_storage-policy";
|
||||||
|
|
||||||
|
|
||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { db } from "@/db";
|
import { db } from "@/db";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { DatabaseSchema } from "@/features/database/database-form.schema";
|
import { DatabaseSchema } from "@/features/database/schemas/database-form.schema";
|
||||||
import * as drizzleDb from "@/db";
|
import * as drizzleDb from "@/db";
|
||||||
import {userAction} from "@/lib/safe-actions/actions";
|
import {userAction} from "@/lib/safe-actions/actions";
|
||||||
import {Database} from "@/db/schema/07_database";
|
import {Database} from "@/db/schema/07_database";
|
||||||
+1
-1
@@ -6,7 +6,7 @@ import {eq} from "drizzle-orm"
|
|||||||
import * as drizzleDb from "@/db";
|
import * as drizzleDb from "@/db";
|
||||||
import {
|
import {
|
||||||
RetentionSettingsSchema
|
RetentionSettingsSchema
|
||||||
} from "@/features/database/retention-policy.schema";
|
} from "@/features/database/schemas/retention-policy.schema";
|
||||||
import {userAction} from "@/lib/safe-actions/actions";
|
import {userAction} from "@/lib/safe-actions/actions";
|
||||||
|
|
||||||
|
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import {BackupWith} from "@/db/schema/07_database";
|
import {BackupWith} from "@/db/schema/07_database";
|
||||||
import {useBackupModal} from "@/features/database/backup-modal-context";
|
import {useBackupModal} from "@/features/database/components/backup-modal-context";
|
||||||
import {Button} from "@/components/ui/button";
|
import {Button} from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
+3
-3
@@ -22,15 +22,15 @@ import {
|
|||||||
deleteBackupAction,
|
deleteBackupAction,
|
||||||
deleteBackupStorageAction,
|
deleteBackupStorageAction,
|
||||||
downloadBackupAction,
|
downloadBackupAction,
|
||||||
} from "@/features/database/backup-actions.action";
|
} from "@/features/database/actions/backup-actions.action";
|
||||||
import {
|
import {
|
||||||
BackupActionsSchema,
|
BackupActionsSchema,
|
||||||
BackupActionsType,
|
BackupActionsType,
|
||||||
} from "@/features/database/backup-actions.schema";
|
} from "@/features/database/schemas/backup-actions.schema";
|
||||||
import {
|
import {
|
||||||
DatabaseActionKind,
|
DatabaseActionKind,
|
||||||
useBackupModal,
|
useBackupModal,
|
||||||
} from "@/features/database/backup-modal-context";
|
} from "@/features/database/components/backup-modal-context";
|
||||||
import { Backup, BackupWith, Restoration } from "@/db/schema/07_database";
|
import { Backup, BackupWith, Restoration } from "@/db/schema/07_database";
|
||||||
import { BackupStorageWith } from "@/db/schema/14_storage-backup";
|
import { BackupStorageWith } from "@/db/schema/14_storage-backup";
|
||||||
import { ServerActionResult } from "@/types/action-type";
|
import { ServerActionResult } from "@/types/action-type";
|
||||||
+2
-2
@@ -7,11 +7,11 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {Separator} from "@/components/ui/separator";
|
import {Separator} from "@/components/ui/separator";
|
||||||
import {BackupActionsForm} from "@/features/database/backup-actions-form";
|
import {BackupActionsForm} from "@/features/database/components/backup-actions-form";
|
||||||
import {
|
import {
|
||||||
getBackupActionTextBasedOnActionKind,
|
getBackupActionTextBasedOnActionKind,
|
||||||
useBackupModal
|
useBackupModal
|
||||||
} from "@/features/database/backup-modal-context";
|
} from "@/features/database/components/backup-modal-context";
|
||||||
|
|
||||||
|
|
||||||
type DatabaseActionsModalProps = {}
|
type DatabaseActionsModalProps = {}
|
||||||
+1
-1
@@ -4,7 +4,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
import { backupButtonAction } from "@/features/database/backup-button.action";
|
import { backupButtonAction } from "@/features/database/actions/backup-button.action";
|
||||||
import { Check, DatabaseZap, X } from "lucide-react";
|
import { Check, DatabaseZap, X } from "lucide-react";
|
||||||
import { useIsMobile } from "@/hooks/use-mobile";
|
import { useIsMobile } from "@/hooks/use-mobile";
|
||||||
import { ButtonWithConfirm } from "@/components/common/button-with-confirm";
|
import { ButtonWithConfirm } from "@/components/common/button-with-confirm";
|
||||||
+2
-2
@@ -9,9 +9,9 @@ import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from "@/compon
|
|||||||
import {MemberWithUser} from "@/db/schema/03_organization";
|
import {MemberWithUser} from "@/db/schema/03_organization";
|
||||||
import {formatLocalizedDate} from "@/utils/date-formatting";
|
import {formatLocalizedDate} from "@/utils/date-formatting";
|
||||||
import {formatBytes, formatDuration} from "@/utils/text";
|
import {formatBytes, formatDuration} from "@/utils/text";
|
||||||
import {DatabaseActionsCell} from "@/features/database/backup-actions-cell";
|
import {DatabaseActionsCell} from "@/features/database/components/backup-actions-cell";
|
||||||
import { Badge as BadgeC } from "@/components/ui/badge";
|
import { Badge as BadgeC } from "@/components/ui/badge";
|
||||||
import {backupOnly} from "@/features/database/database-tabs";
|
import {backupOnly} from "@/features/database/components/database-tabs";
|
||||||
import {LogsModalTrigger} from "@/features/logs/logs-modal-trigger";
|
import {LogsModalTrigger} from "@/features/logs/logs-modal-trigger";
|
||||||
|
|
||||||
export function backupColumns(
|
export function backupColumns(
|
||||||
+1
-1
@@ -20,7 +20,7 @@ import {
|
|||||||
PoliciesSchema,
|
PoliciesSchema,
|
||||||
PoliciesType,
|
PoliciesType,
|
||||||
PolicyType,
|
PolicyType,
|
||||||
} from "@/features/database/channels-policy.schema";
|
} from "@/features/database/schemas/channels-policy.schema";
|
||||||
|
|
||||||
export type ChannelEntry = { id: string; name: string; provider: string };
|
export type ChannelEntry = { id: string; name: string; provider: string };
|
||||||
|
|
||||||
+4
-4
@@ -20,8 +20,8 @@ import { DatabaseWith } from "@/db/schema/07_database";
|
|||||||
import { NotificationChannel } from "@/db/schema/09_notification-channel";
|
import { NotificationChannel } from "@/db/schema/09_notification-channel";
|
||||||
import { StorageChannel } from "@/db/schema/12_storage-channel";
|
import { StorageChannel } from "@/db/schema/12_storage-channel";
|
||||||
import { ChannelKind, getChannelTextBasedOnKind } from "@/features/channel/components/channels-helpers";
|
import { ChannelKind, getChannelTextBasedOnKind } from "@/features/channel/components/channels-helpers";
|
||||||
import { ChannelPoliciesForm } from "@/features/database/channels-policy-form";
|
import { ChannelPoliciesForm } from "@/features/database/components/channels-policy-form";
|
||||||
import { PolicyType } from "@/features/database/channels-policy.schema";
|
import { PolicyType } from "@/features/database/schemas/channels-policy.schema";
|
||||||
import {
|
import {
|
||||||
createAlertPoliciesAction,
|
createAlertPoliciesAction,
|
||||||
createStoragePoliciesAction,
|
createStoragePoliciesAction,
|
||||||
@@ -29,8 +29,8 @@ import {
|
|||||||
deleteStoragePoliciesAction,
|
deleteStoragePoliciesAction,
|
||||||
updateAlertPoliciesAction,
|
updateAlertPoliciesAction,
|
||||||
updateStoragePoliciesAction,
|
updateStoragePoliciesAction,
|
||||||
} from "@/features/database/channels-policy.action";
|
} from "@/features/database/actions/channels-policy.action";
|
||||||
import { backupOnly } from "@/features/database/database-tabs";
|
import { backupOnly } from "@/features/database/components/database-tabs";
|
||||||
|
|
||||||
type ChannelPoliciesModalProps = {
|
type ChannelPoliciesModalProps = {
|
||||||
database: DatabaseWith;
|
database: DatabaseWith;
|
||||||
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
import { Clock9 } from "lucide-react";
|
import { Clock9 } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||||
import { CronInput } from "@/features/database/cron-input";
|
import { CronInput } from "@/features/database/components/cron-input";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
@@ -10,7 +10,7 @@ import { useState } from "react";
|
|||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { updateDatabaseBackupPolicyAction } from "@/features/database/cron.action";
|
import { updateDatabaseBackupPolicyAction } from "@/features/database/actions/cron.action";
|
||||||
import {Database} from "@/db/schema/07_database";
|
import {Database} from "@/db/schema/07_database";
|
||||||
|
|
||||||
export type CronButtonProps = {
|
export type CronButtonProps = {
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import {AdvancedCronSelect} from "@/features/database/cron-advanced-select";
|
import {AdvancedCronSelect} from "@/features/database/components/cron-advanced-select";
|
||||||
import {updateDatabaseBackupPolicyAction} from "@/features/database/cron.action";
|
import {updateDatabaseBackupPolicyAction} from "@/features/database/actions/cron.action";
|
||||||
import {useMutation, useQueryClient} from "@tanstack/react-query";
|
import {useMutation, useQueryClient} from "@tanstack/react-query";
|
||||||
import {useRouter} from "next/navigation";
|
import {useRouter} from "next/navigation";
|
||||||
import {useState} from "react";
|
import {useState} from "react";
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import {backupColumns} from "@/features/database/backup-columns";
|
import {backupColumns} from "@/features/database/components/backup-columns";
|
||||||
import {DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger} from "@/components/ui/dropdown-menu";
|
import {DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger} from "@/components/ui/dropdown-menu";
|
||||||
import {ButtonWithLoading} from "@/components/common/button-with-loading";
|
import {ButtonWithLoading} from "@/components/common/button-with-loading";
|
||||||
import {MoreHorizontal, Trash2} from "lucide-react";
|
import {MoreHorizontal, Trash2} from "lucide-react";
|
||||||
@@ -11,7 +11,7 @@ import {Setting} from "@/db/schema/01_setting";
|
|||||||
import {useMutation, useQueryClient} from "@tanstack/react-query";
|
import {useMutation, useQueryClient} from "@tanstack/react-query";
|
||||||
import {toast} from "sonner";
|
import {toast} from "sonner";
|
||||||
import {MemberWithUser} from "@/db/schema/03_organization";
|
import {MemberWithUser} from "@/db/schema/03_organization";
|
||||||
import {deleteBackupAction} from "@/features/database/backup-actions.action";
|
import {deleteBackupAction} from "@/features/database/actions/backup-actions.action";
|
||||||
import {ButtonWithConfirm} from "@/components/common/button-with-confirm";
|
import {ButtonWithConfirm} from "@/components/common/button-with-confirm";
|
||||||
|
|
||||||
|
|
||||||
+11
-11
@@ -1,26 +1,26 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import {DatabaseBackupActionsModal} from "@/features/database/backup-actions-modal";
|
import {DatabaseBackupActionsModal} from "@/features/database/components/backup-actions-modal";
|
||||||
import {DatabaseTabs} from "@/features/database/database-tabs";
|
import {DatabaseTabs} from "@/features/database/components/database-tabs";
|
||||||
import {Setting} from "@/db/schema/01_setting";
|
import {Setting} from "@/db/schema/01_setting";
|
||||||
import {BackupWith, DatabaseWith, RestorationWith} from "@/db/schema/07_database";
|
import {BackupWith, DatabaseWith, RestorationWith} from "@/db/schema/07_database";
|
||||||
import {MemberWithUser} from "@/db/schema/03_organization";
|
import {MemberWithUser} from "@/db/schema/03_organization";
|
||||||
import {useBackupModal} from "@/features/database/backup-modal-context";
|
import {useBackupModal} from "@/features/database/components/backup-modal-context";
|
||||||
import {DatabaseKpi} from "@/features/database/database-kpi";
|
import {DatabaseKpi} from "@/features/database/components/database-kpi";
|
||||||
import {useQuery} from "@tanstack/react-query";
|
import {useQuery} from "@tanstack/react-query";
|
||||||
import {getDatabaseDataAction} from "@/features/database/backup-get-data.action";
|
import {getDatabaseDataAction} from "@/features/database/actions/backup-get-data.action";
|
||||||
import {
|
import {
|
||||||
PageContent,
|
PageContent,
|
||||||
PageDescription,
|
PageDescription,
|
||||||
PageTitle,
|
PageTitle,
|
||||||
} from "@/features/layout/page";
|
} from "@/features/layout/page";
|
||||||
import {capitalizeFirstLetter} from "@/utils/text";
|
import {capitalizeFirstLetter} from "@/utils/text";
|
||||||
import {RetentionPolicySheet} from "@/features/database/retention-policy-sheet";
|
import {RetentionPolicySheet} from "@/features/database/components/retention-policy-sheet";
|
||||||
import {CronButton} from "@/features/database/cron-button";
|
import {CronButton} from "@/features/database/components/cron-button";
|
||||||
import {ChannelPoliciesModal} from "@/features/database/channels-policy-modal";
|
import {ChannelPoliciesModal} from "@/features/database/components/channels-policy-modal";
|
||||||
import {HardDrive, Megaphone} from "lucide-react";
|
import {HardDrive, Megaphone} from "lucide-react";
|
||||||
import {ImportModal} from "@/features/database/import-modal";
|
import {ImportModal} from "@/features/database/components/import-modal";
|
||||||
import {BackupButton} from "@/features/database/backup-button";
|
import {BackupButton} from "@/features/database/components/backup-button";
|
||||||
import {HealthModal} from "@/features/database/health-modal";
|
import {HealthModal} from "@/features/database/components/health-modal";
|
||||||
import {HealthcheckLog} from "@/db/schema/15_healthcheck-log";
|
import {HealthcheckLog} from "@/db/schema/15_healthcheck-log";
|
||||||
import {Badge} from "@/components/ui/badge";
|
import {Badge} from "@/components/ui/badge";
|
||||||
import {LogsModal} from "@/features/logs/logs-modal";
|
import {LogsModal} from "@/features/logs/logs-modal";
|
||||||
+2
-2
@@ -8,8 +8,8 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation } from "@tanstack/react-query";
|
||||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||||
import { DatabaseSchema, DatabaseType } from "@/features/database/database-form.schema";
|
import { DatabaseSchema, DatabaseType } from "@/features/database/schemas/database-form.schema";
|
||||||
import { updateDatabaseAction } from "@/features/database/database-form.action";
|
import { updateDatabaseAction } from "@/features/database/actions/database-form.action";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
export type DatabaseFormProps = {
|
export type DatabaseFormProps = {
|
||||||
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import {DataTable} from "@/components/common/data-table";
|
import {DataTable} from "@/components/common/data-table";
|
||||||
import {restoreColumns} from "@/features/database/restore-columns";
|
import {restoreColumns} from "@/features/database/components/restore-columns";
|
||||||
import {DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger} from "@/components/ui/dropdown-menu";
|
import {DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger} from "@/components/ui/dropdown-menu";
|
||||||
import {ButtonWithLoading} from "@/components/common/button-with-loading";
|
import {ButtonWithLoading} from "@/components/common/button-with-loading";
|
||||||
import {MoreHorizontal, Trash2} from "lucide-react";
|
import {MoreHorizontal, Trash2} from "lucide-react";
|
||||||
import {Restoration} from "@/db/schema/07_database";
|
import {Restoration} from "@/db/schema/07_database";
|
||||||
import {useMutation, useQueryClient} from "@tanstack/react-query";
|
import {useMutation, useQueryClient} from "@tanstack/react-query";
|
||||||
import {deleteRestoreAction} from "@/features/database/restore.action";
|
import {deleteRestoreAction} from "@/features/database/actions/restore.action";
|
||||||
import {toast} from "sonner";
|
import {toast} from "sonner";
|
||||||
import {MemberWithUser} from "@/db/schema/03_organization";
|
import {MemberWithUser} from "@/db/schema/03_organization";
|
||||||
import {useMemo, useState} from "react";
|
import {useMemo, useState} from "react";
|
||||||
+2
-2
@@ -5,8 +5,8 @@ import {useEffect, useState} from "react";
|
|||||||
import {useRouter, useSearchParams} from "next/navigation";
|
import {useRouter, useSearchParams} from "next/navigation";
|
||||||
import {BackupWith, DatabaseWith, Restoration} from "@/db/schema/07_database";
|
import {BackupWith, DatabaseWith, Restoration} from "@/db/schema/07_database";
|
||||||
import {Setting} from "@/db/schema/01_setting";
|
import {Setting} from "@/db/schema/01_setting";
|
||||||
import {DatabaseBackupList} from "@/features/database/database-backup-list";
|
import {DatabaseBackupList} from "@/features/database/components/database-backup-list";
|
||||||
import {DatabaseRestoreList} from "@/features/database/database-restore-list";
|
import {DatabaseRestoreList} from "@/features/database/components/database-restore-list";
|
||||||
import {MemberWithUser} from "@/db/schema/03_organization";
|
import {MemberWithUser} from "@/db/schema/03_organization";
|
||||||
|
|
||||||
export type DatabaseTabsProps = {
|
export type DatabaseTabsProps = {
|
||||||
+1
-1
@@ -11,7 +11,7 @@ import {
|
|||||||
SheetTrigger
|
SheetTrigger
|
||||||
} from "@/components/ui/sheet";
|
} from "@/components/ui/sheet";
|
||||||
import {HealthcheckLog} from "@/db/schema/15_healthcheck-log";
|
import {HealthcheckLog} from "@/db/schema/15_healthcheck-log";
|
||||||
import {HealthCheckGraph} from "@/features/database/health-grid";
|
import {HealthCheckGraph} from "@/features/database/components/health-grid";
|
||||||
|
|
||||||
type HealthModalProps = {
|
type HealthModalProps = {
|
||||||
database: DatabaseWith,
|
database: DatabaseWith,
|
||||||
+1
-1
@@ -13,7 +13,7 @@ import {Button} from "@/components/ui/button";
|
|||||||
import {DatabaseWith} from "@/db/schema/07_database";
|
import {DatabaseWith} from "@/db/schema/07_database";
|
||||||
import {Separator} from "@/components/ui/separator";
|
import {Separator} from "@/components/ui/separator";
|
||||||
import {Import} from "lucide-react";
|
import {Import} from "lucide-react";
|
||||||
import {UploadBackupZone} from "@/features/database/import-upload-zone";
|
import {UploadBackupZone} from "@/features/database/components/import-upload-zone";
|
||||||
|
|
||||||
type ImportModalProps = {
|
type ImportModalProps = {
|
||||||
database: DatabaseWith;
|
database: DatabaseWith;
|
||||||
+1
-1
@@ -7,7 +7,7 @@ import {useState} from "react";
|
|||||||
import {Loader2} from "lucide-react";
|
import {Loader2} from "lucide-react";
|
||||||
import {ButtonWithLoading} from "@/components/common/button-with-loading";
|
import {ButtonWithLoading} from "@/components/common/button-with-loading";
|
||||||
import {toast} from "sonner";
|
import {toast} from "sonner";
|
||||||
import {uploadBackupAction} from "@/features/database/import.action";
|
import {uploadBackupAction} from "@/features/database/actions/import.action";
|
||||||
import {Card, CardContent} from "@/components/ui/card";
|
import {Card, CardContent} from "@/components/ui/card";
|
||||||
import {DatabaseWith} from "@/db/schema/07_database";
|
import {DatabaseWith} from "@/db/schema/07_database";
|
||||||
import {getFileHeadersBasedOnDbms} from "@/utils/common";
|
import {getFileHeadersBasedOnDbms} from "@/utils/common";
|
||||||
+1
-1
@@ -19,7 +19,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|||||||
import {
|
import {
|
||||||
deleteRestoreAction,
|
deleteRestoreAction,
|
||||||
rerunRestorationAction,
|
rerunRestorationAction,
|
||||||
} from "@/features/database/restore.action";
|
} from "@/features/database/actions/restore.action";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { TooltipCustom } from "@/components/common/tooltip-custom";
|
import { TooltipCustom } from "@/components/common/tooltip-custom";
|
||||||
import { MemberWithUser } from "@/db/schema/03_organization";
|
import { MemberWithUser } from "@/db/schema/03_organization";
|
||||||
+1
-1
@@ -13,7 +13,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
RetentionSettings,
|
RetentionSettings,
|
||||||
RetentionSettingsSchema,
|
RetentionSettingsSchema,
|
||||||
} from "@/features/database/retention-policy.schema";
|
} from "@/features/database/schemas/retention-policy.schema";
|
||||||
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
+3
-3
@@ -7,9 +7,9 @@ import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTr
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Database, Ruler } from "lucide-react";
|
import { Database, Ruler } from "lucide-react";
|
||||||
import { DatabaseWith, RetentionPolicy } from "@/db/schema/07_database";
|
import { DatabaseWith, RetentionPolicy } from "@/db/schema/07_database";
|
||||||
import { BackupRetentionSettingsForm } from "@/features/database/retention-policy-form";
|
import { BackupRetentionSettingsForm } from "@/features/database/components/retention-policy-form";
|
||||||
import { RetentionSettings } from "@/features/database/retention-policy.schema";
|
import { RetentionSettings } from "@/features/database/schemas/retention-policy.schema";
|
||||||
import { updateOrCreateBackupRetentionPolicyAction } from "@/features/database/retention-policy.action";
|
import { updateOrCreateBackupRetentionPolicyAction } from "@/features/database/actions/retention-policy.action";
|
||||||
|
|
||||||
type RetentionPolicySheetProps = {
|
type RetentionPolicySheetProps = {
|
||||||
database: DatabaseWith;
|
database: DatabaseWith;
|
||||||
+1
-1
@@ -13,7 +13,7 @@ import {useMutation, useQueryClient} from "@tanstack/react-query";
|
|||||||
import {useRouter} from "next/navigation";
|
import {useRouter} from "next/navigation";
|
||||||
import {
|
import {
|
||||||
updateOrCreateBackupRetentionPolicyAction
|
updateOrCreateBackupRetentionPolicyAction
|
||||||
} from "@/features/database/retention-policy.action";
|
} from "@/features/database/actions/retention-policy.action";
|
||||||
import {Database as DbSchema} from "@/db/schema/07_database";
|
import {Database as DbSchema} from "@/db/schema/07_database";
|
||||||
|
|
||||||
type RetentionPolicyType = "count" | "days" | "gfs"
|
type RetentionPolicyType = "count" | "days" | "gfs"
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { ChannelPoliciesForm } from "@/features/database/channels-policy-form";
|
import { ChannelPoliciesForm } from "@/features/database/components/channels-policy-form";
|
||||||
import type { EventKind, OnboardingChannel, OnboardingNotificationPolicy } from "@/features/onboarding/types";
|
import type { EventKind, OnboardingChannel, OnboardingNotificationPolicy } from "@/features/onboarding/types";
|
||||||
import type { PolicyType } from "@/features/database/channels-policy.schema";
|
import type { PolicyType } from "@/features/database/schemas/channels-policy.schema";
|
||||||
|
|
||||||
type NotificationsSectionProps = {
|
type NotificationsSectionProps = {
|
||||||
initial: OnboardingNotificationPolicy[];
|
initial: OnboardingNotificationPolicy[];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { BackupRetentionSettingsForm } from "@/features/database/retention-policy-form";
|
import { BackupRetentionSettingsForm } from "@/features/database/components/retention-policy-form";
|
||||||
import { DEFAULT_RETENTION } from "@/features/onboarding/constants/db-settings";
|
import { DEFAULT_RETENTION } from "@/features/onboarding/constants/db-settings";
|
||||||
import type { OnboardingDbSettings } from "@/features/onboarding/types";
|
import type { OnboardingDbSettings } from "@/features/onboarding/types";
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { ChannelPoliciesForm } from "@/features/database/channels-policy-form";
|
import { ChannelPoliciesForm } from "@/features/database/components/channels-policy-form";
|
||||||
import type { OnboardingChannel, OnboardingStoragePolicy } from "@/features/onboarding/types";
|
import type { OnboardingChannel, OnboardingStoragePolicy } from "@/features/onboarding/types";
|
||||||
import type { PolicyType } from "@/features/database/channels-policy.schema";
|
import type { PolicyType } from "@/features/database/schemas/channels-policy.schema";
|
||||||
|
|
||||||
type StorageSectionProps = {
|
type StorageSectionProps = {
|
||||||
initial: OnboardingStoragePolicy[];
|
initial: OnboardingStoragePolicy[];
|
||||||
|
|||||||
+57
-26
@@ -4,11 +4,29 @@ import * as drizzleDb from "@/db";
|
|||||||
import { db } from "@/db";
|
import { db } from "@/db";
|
||||||
import { env } from "@/env.mjs";
|
import { env } from "@/env.mjs";
|
||||||
import { nextCookies } from "better-auth/next-js";
|
import { nextCookies } from "better-auth/next-js";
|
||||||
import {admin as adminPlugin, openAPI, Organization, organization, twoFactor} from "better-auth/plugins";
|
import {
|
||||||
import {ac, admin, orgAdmin, orgMember, orgOwner, pending, superadmin, user} from "@/lib/auth/permissions";
|
admin as adminPlugin,
|
||||||
|
openAPI,
|
||||||
|
Organization,
|
||||||
|
organization,
|
||||||
|
twoFactor,
|
||||||
|
} from "better-auth/plugins";
|
||||||
|
import {
|
||||||
|
ac,
|
||||||
|
admin,
|
||||||
|
orgAdmin,
|
||||||
|
orgMember,
|
||||||
|
orgOwner,
|
||||||
|
pending,
|
||||||
|
superadmin,
|
||||||
|
user,
|
||||||
|
} from "@/lib/auth/permissions";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { count, eq } from "drizzle-orm";
|
import { count, eq } from "drizzle-orm";
|
||||||
import {MemberWithUser, OrganizationWithMembersAndUsers,} from "@/db/schema/03_organization";
|
import {
|
||||||
|
MemberWithUser,
|
||||||
|
OrganizationWithMembersAndUsers,
|
||||||
|
} from "@/db/schema/03_organization";
|
||||||
import { sendEmail } from "@/lib/email";
|
import { sendEmail } from "@/lib/email";
|
||||||
import { render } from "@react-email/render";
|
import { render } from "@react-email/render";
|
||||||
import { withUpdatedAt } from "@/db/utils";
|
import { withUpdatedAt } from "@/db/utils";
|
||||||
@@ -24,7 +42,7 @@ import {getOidcProviders} from "./oidc";
|
|||||||
import { APIError } from "better-auth/api";
|
import { APIError } from "better-auth/api";
|
||||||
import { getOAuthProviders } from "./oauth";
|
import { getOAuthProviders } from "./oauth";
|
||||||
import { logger } from "@/lib/logger";
|
import { logger } from "@/lib/logger";
|
||||||
import {apiKey} from "@better-auth/api-key"
|
import { apiKey } from "@better-auth/api-key";
|
||||||
|
|
||||||
const log = logger.child({ module: "lib/auth" });
|
const log = logger.child({ module: "lib/auth" });
|
||||||
|
|
||||||
@@ -302,23 +320,39 @@ export const auth = betterAuth({
|
|||||||
displayName: session.user.email,
|
displayName: session.user.email,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (!context) throw new APIError("BAD_REQUEST", { message: "Passkey context required" });
|
if (!context)
|
||||||
|
throw new APIError("BAD_REQUEST", {
|
||||||
|
message: "Passkey context required",
|
||||||
|
});
|
||||||
const payload = verifyPasskeyContext(context);
|
const payload = verifyPasskeyContext(context);
|
||||||
if (!payload) throw new APIError("BAD_REQUEST", { message: "Invalid passkey context" });
|
if (!payload)
|
||||||
|
throw new APIError("BAD_REQUEST", {
|
||||||
|
message: "Invalid passkey context",
|
||||||
|
});
|
||||||
const [existing] = await db
|
const [existing] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(drizzleDb.schemas.user)
|
.from(drizzleDb.schemas.user)
|
||||||
.where(eq(drizzleDb.schemas.user.email, payload.email))
|
.where(eq(drizzleDb.schemas.user.email, payload.email))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
return { id: existing.id, name: existing.name || payload.name, displayName: payload.email };
|
return {
|
||||||
|
id: existing.id,
|
||||||
|
name: existing.name || payload.name,
|
||||||
|
displayName: payload.email,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const newUser = await (ctx as any).context.internalAdapter.createUser({
|
const newUser = await (
|
||||||
|
ctx as any
|
||||||
|
).context.internalAdapter.createUser({
|
||||||
name: payload.name,
|
name: payload.name,
|
||||||
email: payload.email,
|
email: payload.email,
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
});
|
});
|
||||||
return { id: newUser.id, name: payload.name, displayName: payload.email };
|
return {
|
||||||
|
id: newUser.id,
|
||||||
|
name: payload.name,
|
||||||
|
displayName: payload.email,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -506,7 +540,9 @@ export const auth = betterAuth({
|
|||||||
new Date(user.createdAt).getTime();
|
new Date(user.createdAt).getTime();
|
||||||
|
|
||||||
if (createdAtDiff < 5000) {
|
if (createdAtDiff < 5000) {
|
||||||
log.debug(`Skipping new login email for freshly created user ${user.email}`);
|
log.debug(
|
||||||
|
`Skipping new login email for freshly created user ${user.email}`,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,7 +557,6 @@ export const auth = betterAuth({
|
|||||||
|
|
||||||
const deviceInfo = getDeviceDetails(session.userAgent);
|
const deviceInfo = getDeviceDetails(session.userAgent);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await sendEmail({
|
await sendEmail({
|
||||||
to: user.email,
|
to: user.email,
|
||||||
@@ -537,12 +572,15 @@ export const auth = betterAuth({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error({
|
log.error(
|
||||||
|
{
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
details: "Please Check your env variables or system config",
|
details: "Please Check your env variables or system config",
|
||||||
email: user.email,
|
email: user.email,
|
||||||
error,
|
error,
|
||||||
}, "sendEmail failed");
|
},
|
||||||
|
"sendEmail failed",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
(await auth.$context).internalAdapter.updateUser(user.id, {
|
(await auth.$context).internalAdapter.updateUser(user.id, {
|
||||||
@@ -567,10 +605,9 @@ export const auth = betterAuth({
|
|||||||
trustedOrigins: async (request) => {
|
trustedOrigins: async (request) => {
|
||||||
const trustedOrigins = await queryTrustedDomains();
|
const trustedOrigins = await queryTrustedDomains();
|
||||||
return trustedOrigins;
|
return trustedOrigins;
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const queryTrustedDomains = async (): Promise<string[]> => {
|
const queryTrustedDomains = async (): Promise<string[]> => {
|
||||||
const envDomains = env.TRUSTED_DOMAINS || "";
|
const envDomains = env.TRUSTED_DOMAINS || "";
|
||||||
const domains = envDomains
|
const domains = envDomains
|
||||||
@@ -579,7 +616,7 @@ const queryTrustedDomains = async (): Promise<string[]> => {
|
|||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
if (env.PROJECT_URL) domains.push(env.PROJECT_URL);
|
if (env.PROJECT_URL) domains.push(env.PROJECT_URL);
|
||||||
domains.push("http://app")
|
domains.push("http://app");
|
||||||
|
|
||||||
return domains;
|
return domains;
|
||||||
};
|
};
|
||||||
@@ -622,8 +659,7 @@ export const revokeSession = async (e: string) => {
|
|||||||
headers: await headers(),
|
headers: await headers(),
|
||||||
});
|
});
|
||||||
return status;
|
return status;
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAccounts = async () => {
|
export const getAccounts = async () => {
|
||||||
@@ -643,8 +679,7 @@ export const unlinkAccount = async (provider: string, account: string) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getOrganization = async ({
|
export const getOrganization = async ({
|
||||||
@@ -674,7 +709,6 @@ export const getOrganization = async ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const getApiKeys = async () => {
|
export const getApiKeys = async () => {
|
||||||
return await auth.api.listApiKeys({
|
return await auth.api.listApiKeys({
|
||||||
headers: await headers(),
|
headers: await headers(),
|
||||||
@@ -691,7 +725,6 @@ export const createApiKey = async (name: string) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const deleteApiKey = async (keyId: string) => {
|
export const deleteApiKey = async (keyId: string) => {
|
||||||
await auth.api.deleteApiKey({
|
await auth.api.deleteApiKey({
|
||||||
body: {
|
body: {
|
||||||
@@ -814,8 +847,7 @@ export const checkSlugOrganization = async (slug: string) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
} catch {
|
} catch {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getActiveMember = async () => {
|
export const getActiveMember = async () => {
|
||||||
@@ -838,6 +870,5 @@ export const setActiveOrganization = async (slug: string) => {
|
|||||||
organizationSlug: slug,
|
organizationSlug: slug,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user