@v1ct0rbr/minivault-web 0.1.0

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 ADDED
@@ -0,0 +1,75 @@
1
+ # minivault-web
2
+
3
+ Módulo independente de **gestão de backups** (cliente do serviço
4
+ [minivault](../minivault)). Consumível como pacote npm em qualquer app React,
5
+ estilizado com Bootstrap. Comunica-se com a API REST do minivault — normalmente
6
+ através de um **proxy autenticado** (ex.: `/minivault` no backend do Siga+), de
7
+ modo que a `X-API-Key` do minivault jamais trafega no browser.
8
+
9
+ ## Recursos
10
+
11
+ - Lista de backups com paginação, status, tamanho e data.
12
+ - Criação de backup (com origem de arquivos LOCAL ou S3, opcional).
13
+ - Restauração de backup em um banco informado.
14
+ - Importação de dump SQL em texto (`psql`/`mysql`) via upload.
15
+ - Download e exclusão de backups.
16
+ - Tema claro/escuro e auto-refresh.
17
+
18
+ ## Instalação
19
+
20
+ ```bash
21
+ npm install @v1ct0rbr/minivault-web
22
+ ```
23
+
24
+ Como dependência local durante o desenvolvimento:
25
+
26
+ ```bash
27
+ npm install file:../minivault-web
28
+ ```
29
+
30
+ ## Uso no Siga+ (proxy autenticado)
31
+
32
+ ```tsx
33
+ import { MinivaultModule } from '@v1ct0rbr/minivault-web'
34
+ import '@v1ct0rbr/minivault-web/style.css'
35
+ import { useAuthStore } from '@/store/useAuthStore'
36
+
37
+ const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080'
38
+
39
+ export function MinivaultPage() {
40
+ const getToken = () => useAuthStore.getState().token
41
+ return <MinivaultModule baseUrl={apiBase + '/minivault'} getToken={getToken} />
42
+ }
43
+ ```
44
+
45
+ ## Uso standalone (desenvolvimento)
46
+
47
+ ```tsx
48
+ <MinivaultModule baseUrl="http://localhost:8081" token="api-key-do-minivault" />
49
+ ```
50
+
51
+ > Em produção o token do minivault deve ficar apenas no proxy do backend, nunca
52
+ > no bundle do frontend.
53
+
54
+ ## Desenvolvimento
55
+
56
+ ```bash
57
+ npm install
58
+ npm run dev # playground standalone (porta 5176)
59
+ npm run build:lib # gera dist/ (lib ES + types)
60
+ npm test # vitest
61
+ npm run typecheck # tsc --noEmit
62
+ ```
63
+
64
+ ### Playground standalone
65
+
66
+ ```bash
67
+ VITE_MINIVAULT_API_URL=http://localhost:8081 VITE_MINIVAULT_API_TOKEN=chave npm run dev
68
+ ```
69
+
70
+ ## Publicação
71
+
72
+ ```bash
73
+ npm run build:lib && npm test
74
+ npm publish --access public
75
+ ```
@@ -0,0 +1,46 @@
1
+ import { Backup, DatabaseCredentials, DumpOptions, ImportResult, OriginStorageConfig, PageResponse, StorageFileItem, VerifyResult } from '../types/minivault';
2
+ export interface MinivaultApiOptions {
3
+ /**
4
+ * URL base da API. Exemplos:
5
+ * - Seguir: '/minivault' (proxy autenticado no backend do Siga+)
6
+ * - Standalone: 'http://localhost:8081' (minivault direto)
7
+ */
8
+ baseUrl: string;
9
+ /** Token estatico (modo acesso direto a API do minivault). */
10
+ token?: string;
11
+ /** Resolvedor dinamico de token (ex.: Keycloak do host). */
12
+ getToken?: () => string | null | Promise<string | null>;
13
+ /** Transporte injetavel (padrao: global fetch). */
14
+ fetch?: typeof fetch;
15
+ timeoutMs?: number;
16
+ }
17
+ export declare class MinivaultApiError extends Error {
18
+ readonly status: number;
19
+ readonly body?: string;
20
+ constructor(message: string, status: number, body?: string);
21
+ }
22
+ /**
23
+ * Cliente tipado da API do minivault (gerenciamento de backups).
24
+ */
25
+ export declare class MinivaultApi {
26
+ private readonly baseUrl;
27
+ private readonly token?;
28
+ private readonly getToken?;
29
+ private readonly fetchFn;
30
+ private readonly timeoutMs;
31
+ constructor(options: MinivaultApiOptions);
32
+ private resolveToken;
33
+ private request;
34
+ listBackups(page?: number, size?: number): Promise<PageResponse<Backup>>;
35
+ getBackup(id: number): Promise<Backup>;
36
+ createBackup(database: DatabaseCredentials, originStorage?: OriginStorageConfig, dumpOptions?: DumpOptions): Promise<Backup>;
37
+ restoreBackup(id: number, database: DatabaseCredentials, originStorage?: OriginStorageConfig): Promise<void>;
38
+ deleteBackup(id: number): Promise<void>;
39
+ verifyBackup(id: number): Promise<VerifyResult>;
40
+ downloadBackup(id: number): Promise<Blob>;
41
+ importDump(file: File, database: DatabaseCredentials): Promise<ImportResult>;
42
+ importFromStorage(storageType: string, storagePath: string, database: DatabaseCredentials, storageConfig?: OriginStorageConfig): Promise<ImportResult>;
43
+ listStorageFiles(type: string, prefix?: string, storageConfig?: OriginStorageConfig): Promise<StorageFileItem[]>;
44
+ downloadStorageFile(key: string, type: string, storageConfig?: OriginStorageConfig): Promise<Blob>;
45
+ deleteStorageFile(key: string, type: string, storageConfig?: OriginStorageConfig): Promise<void>;
46
+ }
@@ -0,0 +1 @@
1
+ export declare function BackupsTab(): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ export declare function CreateBackupTab(): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { DatabaseCredentials } from '../types/minivault';
2
+ export declare function defaultPort(type: string): number;
3
+ export interface CredentialsFieldsProps {
4
+ value?: Partial<DatabaseCredentials>;
5
+ onChange: (value: DatabaseCredentials) => void;
6
+ onValidatedChange?: (valid: boolean) => void;
7
+ }
8
+ export declare function CredentialsFields({ value, onChange, onValidatedChange }: CredentialsFieldsProps): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ export declare function ImportDumpTab(): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { ReactNode } from 'react';
2
+ import { MinivaultApi, MinivaultApiOptions } from '../api/MinivaultApi';
3
+ export interface MinivaultApiProviderProps extends MinivaultApiOptions {
4
+ children: ReactNode;
5
+ }
6
+ export declare function MinivaultApiProvider({ children, ...options }: MinivaultApiProviderProps): import("react").JSX.Element;
7
+ export declare function useMinivaultApi(): MinivaultApi;
8
+ export declare function useMinivaultApiOrNull(): MinivaultApi | null;
@@ -0,0 +1,8 @@
1
+ import { MinivaultApiProviderProps } from './MinivaultApiProvider';
2
+ export interface MinivaultModuleProps extends Omit<MinivaultApiProviderProps, 'children'> {
3
+ theme?: 'light' | 'dark';
4
+ refetchIntervalMs?: number;
5
+ companyAcronym?: string;
6
+ storageType?: string;
7
+ }
8
+ export declare function MinivaultModule(props: MinivaultModuleProps): import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { Backup } from '../types/minivault';
2
+ export interface RestoreModalProps {
3
+ backup: Backup;
4
+ onClose: () => void;
5
+ }
6
+ export declare function RestoreModal({ backup, onClose }: RestoreModalProps): import("react").JSX.Element;
7
+ export declare function messageText(error: unknown): string;
@@ -0,0 +1,5 @@
1
+ import { BackupStatus } from '../types/minivault';
2
+ export interface StatusBadgeProps {
3
+ status: BackupStatus;
4
+ }
5
+ export declare function StatusBadge({ status }: StatusBadgeProps): import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { OriginStorageConfig } from '../types/minivault';
2
+ interface StorageExplorerTabProps {
3
+ storageType?: string;
4
+ storageConfig?: OriginStorageConfig;
5
+ }
6
+ export declare function StorageExplorerTab({ storageType, storageConfig }: StorageExplorerTabProps): import("react").JSX.Element;
7
+ export {};
@@ -0,0 +1,31 @@
1
+ import { DatabaseCredentials, DumpOptions, OriginStorageConfig } from '../types/minivault';
2
+ export declare const backupsKeys: {
3
+ all: readonly ["minivault", "backups"];
4
+ };
5
+ export declare function useBackups(page?: number, size?: number, enabled?: boolean): import('@tanstack/react-query').UseQueryResult<import('../types/minivault').PageResponse<import('../types/minivault').Backup>, Error>;
6
+ export declare function useCreateBackup(): import('@tanstack/react-query').UseMutationResult<import('../types/minivault').Backup, Error, {
7
+ database: DatabaseCredentials;
8
+ originStorage?: OriginStorageConfig;
9
+ dumpOptions?: DumpOptions;
10
+ }, unknown>;
11
+ export declare function useRestoreBackup(): import('@tanstack/react-query').UseMutationResult<void, Error, {
12
+ id: number;
13
+ database: DatabaseCredentials;
14
+ originStorage?: OriginStorageConfig;
15
+ }, unknown>;
16
+ export declare function useDeleteBackup(): import('@tanstack/react-query').UseMutationResult<void, Error, number, unknown>;
17
+ export declare function useVerifyBackup(): import('@tanstack/react-query').UseMutationResult<import('../types/minivault').VerifyResult, Error, number, unknown>;
18
+ export declare function useDownloadBackup(): import('@tanstack/react-query').UseMutationResult<Blob, Error, {
19
+ id: number;
20
+ filename: string;
21
+ }, unknown>;
22
+ export declare function useImportDump(): import('@tanstack/react-query').UseMutationResult<import('../types/minivault').ImportResult, Error, {
23
+ file: File;
24
+ database: DatabaseCredentials;
25
+ }, unknown>;
26
+ export declare function useImportFromStorage(): import('@tanstack/react-query').UseMutationResult<import('../types/minivault').ImportResult, Error, {
27
+ storageType: string;
28
+ storagePath: string;
29
+ database: DatabaseCredentials;
30
+ storageConfig?: OriginStorageConfig;
31
+ }, unknown>;
@@ -0,0 +1,15 @@
1
+ export { MinivaultModule } from './components/MinivaultModule';
2
+ export type { MinivaultModuleProps } from './components/MinivaultModule';
3
+ export { MinivaultApiProvider, useMinivaultApi } from './components/MinivaultApiProvider';
4
+ export { MinivaultApi, MinivaultApiError } from './api/MinivaultApi';
5
+ export type { MinivaultApiOptions } from './api/MinivaultApi';
6
+ export { BackupsTab } from './components/BackupsTab';
7
+ export { CreateBackupTab } from './components/CreateBackupTab';
8
+ export { ImportDumpTab } from './components/ImportDumpTab';
9
+ export { StorageExplorerTab } from './components/StorageExplorerTab';
10
+ export { RestoreModal } from './components/RestoreModal';
11
+ export { CredentialsFields } from './components/CredentialsFields';
12
+ export { StatusBadge } from './components/StatusBadge';
13
+ export { useBackups, useCreateBackup, useRestoreBackup, useDeleteBackup, useDownloadBackup, useImportDump, useImportFromStorage, } from './hooks/useBackups';
14
+ export { formatFileSize, formatDate, STATUS_LABELS, STATUS_BADGE, DATABASE_TYPE_LABELS } from './utils/format';
15
+ export type { Backup, BackupRequest, BackupStatus, DatabaseCredentials, DatabaseType, DumpOptions, DumpFormat, ImportResult, ImportFromStorageRequest, OriginStorageConfig, PageResponse, RestoreRequest, StorageFileItem, } from './types/minivault';