s3-client-dtb 0.0.1 → 1.0.2
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 +532 -148
- package/dist/client/index.d.ts +74 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +125 -3
- package/dist/client/index.js.map +1 -1
- package/dist/client/local-storage-client.d.ts +97 -0
- package/dist/client/local-storage-client.d.ts.map +1 -0
- package/dist/client/local-storage-client.js +108 -0
- package/dist/client/local-storage-client.js.map +1 -0
- package/dist/client/storage-client.d.ts +28 -3
- package/dist/client/storage-client.d.ts.map +1 -1
- package/dist/client/storage-client.js +270 -27
- package/dist/client/storage-client.js.map +1 -1
- package/dist/config/config-reader.d.ts +67 -0
- package/dist/config/config-reader.d.ts.map +1 -0
- package/dist/config/config-reader.js +201 -0
- package/dist/config/config-reader.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +11 -6
package/dist/client/index.d.ts
CHANGED
|
@@ -1,3 +1,77 @@
|
|
|
1
|
+
import { StorageClient } from './storage-client';
|
|
2
|
+
import { LocalStorageClient } from './local-storage-client';
|
|
1
3
|
export { StorageClient } from './storage-client';
|
|
4
|
+
export { LocalStorageClient } from './local-storage-client';
|
|
2
5
|
export type { StorageClientOptions } from './storage-client';
|
|
6
|
+
export type { LocalStorageClientOptions } from './local-storage-client';
|
|
7
|
+
export { readClientConfig, readStorageConfig, readOfflineConfig, readOnlineConfig, getStorageMode, toClientConfig, } from '../config/config-reader';
|
|
8
|
+
export type { ClientConfigFile, ClientConfig, OfflineConfigFile, StorageConfigFile, StorageMode, } from '../config/config-reader';
|
|
9
|
+
/** Tipo unificado para cualquier cliente de almacenamiento */
|
|
10
|
+
export type UnifiedStorageClient = StorageClient | LocalStorageClient;
|
|
11
|
+
/**
|
|
12
|
+
* Crea un cliente de almacenamiento desde variables de entorno.
|
|
13
|
+
* Detecta automáticamente el modo (online/offline) según STORAGE_MODE.
|
|
14
|
+
*
|
|
15
|
+
* ## Modo Online (servidor remoto) - STORAGE_MODE=online (o no definido)
|
|
16
|
+
*
|
|
17
|
+
* Requiere las siguientes variables de entorno:
|
|
18
|
+
* - STORAGE_CLIENT_ID
|
|
19
|
+
* - STORAGE_CLIENT_NAME
|
|
20
|
+
* - STORAGE_BASE_URL
|
|
21
|
+
* - STORAGE_PERMISSIONS (JSON array o comma-separated: "read,write,delete")
|
|
22
|
+
* - STORAGE_ALLOWED_PATHS (JSON array o comma-separated: "*" o ["path1", "path2"])
|
|
23
|
+
* - STORAGE_CLIENT_SECRET
|
|
24
|
+
* - STORAGE_TOTP_SECRET
|
|
25
|
+
*
|
|
26
|
+
* Opcionales:
|
|
27
|
+
* - STORAGE_TOKEN_EXPIRES_IN (ej: "5m", "30m")
|
|
28
|
+
* - STORAGE_TOTP_PERIOD (segundos, 15-300; default 30)
|
|
29
|
+
* - STORAGE_RATE_LIMIT_REQUESTS (número)
|
|
30
|
+
* - STORAGE_RATE_LIMIT_WINDOW (ej: "1h", "30m")
|
|
31
|
+
*
|
|
32
|
+
* ## Modo Offline (almacenamiento local) - STORAGE_MODE=offline
|
|
33
|
+
*
|
|
34
|
+
* Requiere las siguientes variables de entorno:
|
|
35
|
+
* - STORAGE_ROOT_PATH (directorio donde guardar archivos)
|
|
36
|
+
*
|
|
37
|
+
* Opcionales:
|
|
38
|
+
* - STORAGE_MAX_FILE_SIZE (ej: "50mb", "100kb". Default: "50mb")
|
|
39
|
+
* - STORAGE_ALLOWED_MIME_TYPES (JSON array o comma-separated. Default: "*")
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // .env para desarrollo (offline)
|
|
44
|
+
* STORAGE_MODE=offline
|
|
45
|
+
* STORAGE_ROOT_PATH=./uploads
|
|
46
|
+
*
|
|
47
|
+
* // .env para producción (online)
|
|
48
|
+
* STORAGE_MODE=online
|
|
49
|
+
* STORAGE_BASE_URL=https://storage.example.com
|
|
50
|
+
* STORAGE_CLIENT_ID=mi-app
|
|
51
|
+
* // ... otras variables
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @returns StorageClient para modo online, LocalStorageClient para modo offline
|
|
55
|
+
*/
|
|
56
|
+
export declare function createClientFromConfig(): UnifiedStorageClient;
|
|
57
|
+
/**
|
|
58
|
+
* Crea un StorageClient para modo online desde variables de entorno.
|
|
59
|
+
* Útil cuando quieres forzar el modo online ignorando STORAGE_MODE.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Usa createClientFromConfig() para detección automática de modo
|
|
62
|
+
*/
|
|
63
|
+
export declare function createOnlineClient(): StorageClient;
|
|
64
|
+
/**
|
|
65
|
+
* Crea un LocalStorageClient para modo offline desde variables de entorno.
|
|
66
|
+
* Útil cuando quieres forzar el modo offline ignorando STORAGE_MODE.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createOfflineClient(): LocalStorageClient;
|
|
69
|
+
/**
|
|
70
|
+
* Helper para verificar si el cliente está en modo offline
|
|
71
|
+
*/
|
|
72
|
+
export declare function isOfflineClient(client: UnifiedStorageClient): client is LocalStorageClient;
|
|
73
|
+
/**
|
|
74
|
+
* Helper para verificar si el cliente está en modo online
|
|
75
|
+
*/
|
|
76
|
+
export declare function isOnlineClient(client: UnifiedStorageClient): client is StorageClient;
|
|
3
77
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAQ5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,cAAc,GACf,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,GACZ,MAAM,yBAAyB,CAAC;AAEjC,8DAA8D;AAC9D,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG,kBAAkB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,sBAAsB,IAAI,oBAAoB,CAqB7D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,aAAa,CAWlD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,kBAAkB,CAQxD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,IAAI,kBAAkB,CAE1F;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,IAAI,aAAa,CAEpF"}
|
package/dist/client/index.js
CHANGED
|
@@ -1,6 +1,128 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StorageClient = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.toClientConfig = exports.getStorageMode = exports.readOnlineConfig = exports.readOfflineConfig = exports.readStorageConfig = exports.readClientConfig = exports.LocalStorageClient = exports.StorageClient = void 0;
|
|
4
|
+
exports.createClientFromConfig = createClientFromConfig;
|
|
5
|
+
exports.createOnlineClient = createOnlineClient;
|
|
6
|
+
exports.createOfflineClient = createOfflineClient;
|
|
7
|
+
exports.isOfflineClient = isOfflineClient;
|
|
8
|
+
exports.isOnlineClient = isOnlineClient;
|
|
9
|
+
const storage_client_1 = require("./storage-client");
|
|
10
|
+
const local_storage_client_1 = require("./local-storage-client");
|
|
11
|
+
const config_reader_1 = require("../config/config-reader");
|
|
12
|
+
var storage_client_2 = require("./storage-client");
|
|
13
|
+
Object.defineProperty(exports, "StorageClient", { enumerable: true, get: function () { return storage_client_2.StorageClient; } });
|
|
14
|
+
var local_storage_client_2 = require("./local-storage-client");
|
|
15
|
+
Object.defineProperty(exports, "LocalStorageClient", { enumerable: true, get: function () { return local_storage_client_2.LocalStorageClient; } });
|
|
16
|
+
var config_reader_2 = require("../config/config-reader");
|
|
17
|
+
Object.defineProperty(exports, "readClientConfig", { enumerable: true, get: function () { return config_reader_2.readClientConfig; } });
|
|
18
|
+
Object.defineProperty(exports, "readStorageConfig", { enumerable: true, get: function () { return config_reader_2.readStorageConfig; } });
|
|
19
|
+
Object.defineProperty(exports, "readOfflineConfig", { enumerable: true, get: function () { return config_reader_2.readOfflineConfig; } });
|
|
20
|
+
Object.defineProperty(exports, "readOnlineConfig", { enumerable: true, get: function () { return config_reader_2.readOnlineConfig; } });
|
|
21
|
+
Object.defineProperty(exports, "getStorageMode", { enumerable: true, get: function () { return config_reader_2.getStorageMode; } });
|
|
22
|
+
Object.defineProperty(exports, "toClientConfig", { enumerable: true, get: function () { return config_reader_2.toClientConfig; } });
|
|
23
|
+
/**
|
|
24
|
+
* Crea un cliente de almacenamiento desde variables de entorno.
|
|
25
|
+
* Detecta automáticamente el modo (online/offline) según STORAGE_MODE.
|
|
26
|
+
*
|
|
27
|
+
* ## Modo Online (servidor remoto) - STORAGE_MODE=online (o no definido)
|
|
28
|
+
*
|
|
29
|
+
* Requiere las siguientes variables de entorno:
|
|
30
|
+
* - STORAGE_CLIENT_ID
|
|
31
|
+
* - STORAGE_CLIENT_NAME
|
|
32
|
+
* - STORAGE_BASE_URL
|
|
33
|
+
* - STORAGE_PERMISSIONS (JSON array o comma-separated: "read,write,delete")
|
|
34
|
+
* - STORAGE_ALLOWED_PATHS (JSON array o comma-separated: "*" o ["path1", "path2"])
|
|
35
|
+
* - STORAGE_CLIENT_SECRET
|
|
36
|
+
* - STORAGE_TOTP_SECRET
|
|
37
|
+
*
|
|
38
|
+
* Opcionales:
|
|
39
|
+
* - STORAGE_TOKEN_EXPIRES_IN (ej: "5m", "30m")
|
|
40
|
+
* - STORAGE_TOTP_PERIOD (segundos, 15-300; default 30)
|
|
41
|
+
* - STORAGE_RATE_LIMIT_REQUESTS (número)
|
|
42
|
+
* - STORAGE_RATE_LIMIT_WINDOW (ej: "1h", "30m")
|
|
43
|
+
*
|
|
44
|
+
* ## Modo Offline (almacenamiento local) - STORAGE_MODE=offline
|
|
45
|
+
*
|
|
46
|
+
* Requiere las siguientes variables de entorno:
|
|
47
|
+
* - STORAGE_ROOT_PATH (directorio donde guardar archivos)
|
|
48
|
+
*
|
|
49
|
+
* Opcionales:
|
|
50
|
+
* - STORAGE_MAX_FILE_SIZE (ej: "50mb", "100kb". Default: "50mb")
|
|
51
|
+
* - STORAGE_ALLOWED_MIME_TYPES (JSON array o comma-separated. Default: "*")
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // .env para desarrollo (offline)
|
|
56
|
+
* STORAGE_MODE=offline
|
|
57
|
+
* STORAGE_ROOT_PATH=./uploads
|
|
58
|
+
*
|
|
59
|
+
* // .env para producción (online)
|
|
60
|
+
* STORAGE_MODE=online
|
|
61
|
+
* STORAGE_BASE_URL=https://storage.example.com
|
|
62
|
+
* STORAGE_CLIENT_ID=mi-app
|
|
63
|
+
* // ... otras variables
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @returns StorageClient para modo online, LocalStorageClient para modo offline
|
|
67
|
+
*/
|
|
68
|
+
function createClientFromConfig() {
|
|
69
|
+
const config = (0, config_reader_1.readStorageConfig)();
|
|
70
|
+
if (config.mode === 'offline') {
|
|
71
|
+
return new local_storage_client_1.LocalStorageClient({
|
|
72
|
+
rootPath: config.rootPath,
|
|
73
|
+
maxFileSize: config.maxFileSize,
|
|
74
|
+
allowedMimeTypes: config.allowedMimeTypes,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
// Modo online
|
|
78
|
+
const clientConfig = (0, config_reader_1.toClientConfig)(config);
|
|
79
|
+
return new storage_client_1.StorageClient({
|
|
80
|
+
baseUrl: config.baseUrl,
|
|
81
|
+
clientConfig,
|
|
82
|
+
clientSecret: config.clientSecret,
|
|
83
|
+
totpSecret: config.totpSecret,
|
|
84
|
+
totpPeriodSeconds: config.totpPeriod ?? 30,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Crea un StorageClient para modo online desde variables de entorno.
|
|
89
|
+
* Útil cuando quieres forzar el modo online ignorando STORAGE_MODE.
|
|
90
|
+
*
|
|
91
|
+
* @deprecated Usa createClientFromConfig() para detección automática de modo
|
|
92
|
+
*/
|
|
93
|
+
function createOnlineClient() {
|
|
94
|
+
const config = (0, config_reader_1.readOnlineConfig)();
|
|
95
|
+
const clientConfig = (0, config_reader_1.toClientConfig)(config);
|
|
96
|
+
return new storage_client_1.StorageClient({
|
|
97
|
+
baseUrl: config.baseUrl,
|
|
98
|
+
clientConfig,
|
|
99
|
+
clientSecret: config.clientSecret,
|
|
100
|
+
totpSecret: config.totpSecret,
|
|
101
|
+
totpPeriodSeconds: config.totpPeriod ?? 30,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Crea un LocalStorageClient para modo offline desde variables de entorno.
|
|
106
|
+
* Útil cuando quieres forzar el modo offline ignorando STORAGE_MODE.
|
|
107
|
+
*/
|
|
108
|
+
function createOfflineClient() {
|
|
109
|
+
const config = (0, config_reader_1.readOfflineConfig)();
|
|
110
|
+
return new local_storage_client_1.LocalStorageClient({
|
|
111
|
+
rootPath: config.rootPath,
|
|
112
|
+
maxFileSize: config.maxFileSize,
|
|
113
|
+
allowedMimeTypes: config.allowedMimeTypes,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Helper para verificar si el cliente está en modo offline
|
|
118
|
+
*/
|
|
119
|
+
function isOfflineClient(client) {
|
|
120
|
+
return 'mode' in client && client.mode === 'offline';
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Helper para verificar si el cliente está en modo online
|
|
124
|
+
*/
|
|
125
|
+
function isOnlineClient(client) {
|
|
126
|
+
return !('mode' in client) || client.mode !== 'offline';
|
|
127
|
+
}
|
|
6
128
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;AA6EA,wDAqBC;AAQD,gDAWC;AAMD,kDAQC;AAKD,0CAEC;AAKD,wCAEC;AAjJD,qDAAiD;AACjD,iEAA4D;AAC5D,2DAKiC;AAEjC,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA;AAG3B,yDAOiC;AAN/B,iHAAA,gBAAgB,OAAA;AAChB,kHAAA,iBAAiB,OAAA;AACjB,kHAAA,iBAAiB,OAAA;AACjB,iHAAA,gBAAgB,OAAA;AAChB,+GAAA,cAAc,OAAA;AACd,+GAAA,cAAc,OAAA;AAahB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;G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AAgB;KAC1C,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,MAA4B;IAC1D,OAAO,MAAM,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC;AACvD,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,MAA4B;IACzD,OAAO,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,IAAK,MAAc,CAAC,IAAI,KAAK,SAAS,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import type { FileMetadata, ListFilesOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Opciones para el cliente de almacenamiento local (modo offline)
|
|
5
|
+
*/
|
|
6
|
+
export interface LocalStorageClientOptions {
|
|
7
|
+
/** Directorio raíz donde se guardarán los archivos */
|
|
8
|
+
rootPath: string;
|
|
9
|
+
/** Tamaño máximo de archivo (ej: "50mb", "100kb"). Default: "50mb" */
|
|
10
|
+
maxFileSize?: string;
|
|
11
|
+
/** MIME types permitidos. Default: ["*"] (todos) */
|
|
12
|
+
allowedMimeTypes?: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Cliente de almacenamiento local para modo offline.
|
|
16
|
+
*
|
|
17
|
+
* Implementa la misma interfaz que StorageClient pero guarda
|
|
18
|
+
* los archivos localmente usando StorageCore.
|
|
19
|
+
*
|
|
20
|
+
* Ideal para desarrollo sin necesidad de un servidor en línea.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const client = new LocalStorageClient({
|
|
25
|
+
* rootPath: './uploads',
|
|
26
|
+
* maxFileSize: '50mb',
|
|
27
|
+
* allowedMimeTypes: ['image/*', 'application/pdf']
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Subir archivo
|
|
31
|
+
* const path = await client.uploadFile('images', buffer, 'image/png');
|
|
32
|
+
*
|
|
33
|
+
* // Descargar archivo
|
|
34
|
+
* const stream = await client.downloadFile(path);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class LocalStorageClient {
|
|
38
|
+
private readonly storageCore;
|
|
39
|
+
readonly mode: "offline";
|
|
40
|
+
constructor(options: LocalStorageClientOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Sube un archivo al almacenamiento local
|
|
43
|
+
*
|
|
44
|
+
* @param filePath - Ruta/carpeta donde guardar el archivo
|
|
45
|
+
* @param buffer - Contenido del archivo
|
|
46
|
+
* @param mimeType - Tipo MIME del archivo
|
|
47
|
+
* @param prefix - Prefijo opcional para el nombre del archivo
|
|
48
|
+
* @returns Ruta relativa del archivo guardado
|
|
49
|
+
*/
|
|
50
|
+
uploadFile(filePath: string, buffer: Buffer, mimeType: string, prefix?: string): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Descarga un archivo del almacenamiento local
|
|
53
|
+
*
|
|
54
|
+
* @param path - Ruta del archivo a descargar
|
|
55
|
+
* @returns Stream readable del archivo
|
|
56
|
+
*/
|
|
57
|
+
downloadFile(path: string): Promise<Readable>;
|
|
58
|
+
/**
|
|
59
|
+
* Elimina un archivo del almacenamiento local
|
|
60
|
+
*
|
|
61
|
+
* @param path - Ruta del archivo a eliminar
|
|
62
|
+
*/
|
|
63
|
+
deleteFile(path: string): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Obtiene los metadatos de un archivo
|
|
66
|
+
*
|
|
67
|
+
* @param path - Ruta del archivo
|
|
68
|
+
* @returns Metadatos del archivo
|
|
69
|
+
*/
|
|
70
|
+
getFileMetadata(path: string): Promise<FileMetadata>;
|
|
71
|
+
/**
|
|
72
|
+
* Lista los archivos en un directorio
|
|
73
|
+
*
|
|
74
|
+
* @param directoryPath - Ruta del directorio (opcional)
|
|
75
|
+
* @param options - Opciones de listado (limit, offset, prefix)
|
|
76
|
+
* @returns Lista de archivos y total
|
|
77
|
+
*/
|
|
78
|
+
listFiles(directoryPath?: string, options?: ListFilesOptions): Promise<{
|
|
79
|
+
files: FileMetadata[];
|
|
80
|
+
total: number;
|
|
81
|
+
}>;
|
|
82
|
+
/**
|
|
83
|
+
* Verifica si un archivo existe
|
|
84
|
+
*
|
|
85
|
+
* @param path - Ruta del archivo
|
|
86
|
+
* @returns true si existe, false si no
|
|
87
|
+
*/
|
|
88
|
+
fileExists(path: string): Promise<boolean>;
|
|
89
|
+
/**
|
|
90
|
+
* Método de compatibilidad con StorageClient.
|
|
91
|
+
* En modo offline no hay TOTP que verificar, siempre retorna éxito.
|
|
92
|
+
*/
|
|
93
|
+
verifyTotp(): Promise<{
|
|
94
|
+
message: string;
|
|
95
|
+
}>;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=local-storage-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage-client.d.ts","sourceRoot":"","sources":["../../src/client/local-storage-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAsB,MAAM,UAAU,CAAC;AAEnF;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,SAAgB,IAAI,EAAG,SAAS,CAAU;gBAE9B,OAAO,EAAE,yBAAyB;IAc9C;;;;;;;;OAQG;IACG,UAAU,CACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC;IAIlB;;;;;OAKG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAInD;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C;;;;;OAKG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAI1D;;;;;;OAMG;IACG,SAAS,CACb,aAAa,GAAE,MAAW,EAC1B,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAIpD;;;;;OAKG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIhD;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAGjD"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalStorageClient = void 0;
|
|
4
|
+
const storage_core_1 = require("../core/storage-core");
|
|
5
|
+
/**
|
|
6
|
+
* Cliente de almacenamiento local para modo offline.
|
|
7
|
+
*
|
|
8
|
+
* Implementa la misma interfaz que StorageClient pero guarda
|
|
9
|
+
* los archivos localmente usando StorageCore.
|
|
10
|
+
*
|
|
11
|
+
* Ideal para desarrollo sin necesidad de un servidor en línea.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const client = new LocalStorageClient({
|
|
16
|
+
* rootPath: './uploads',
|
|
17
|
+
* maxFileSize: '50mb',
|
|
18
|
+
* allowedMimeTypes: ['image/*', 'application/pdf']
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Subir archivo
|
|
22
|
+
* const path = await client.uploadFile('images', buffer, 'image/png');
|
|
23
|
+
*
|
|
24
|
+
* // Descargar archivo
|
|
25
|
+
* const stream = await client.downloadFile(path);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
class LocalStorageClient {
|
|
29
|
+
storageCore;
|
|
30
|
+
mode = 'offline';
|
|
31
|
+
constructor(options) {
|
|
32
|
+
if (!options.rootPath) {
|
|
33
|
+
throw new Error('rootPath es requerido para el modo offline');
|
|
34
|
+
}
|
|
35
|
+
const coreOptions = {
|
|
36
|
+
rootPath: options.rootPath,
|
|
37
|
+
maxFileSize: options.maxFileSize,
|
|
38
|
+
allowedMimeTypes: options.allowedMimeTypes,
|
|
39
|
+
};
|
|
40
|
+
this.storageCore = new storage_core_1.StorageCore(coreOptions);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sube un archivo al almacenamiento local
|
|
44
|
+
*
|
|
45
|
+
* @param filePath - Ruta/carpeta donde guardar el archivo
|
|
46
|
+
* @param buffer - Contenido del archivo
|
|
47
|
+
* @param mimeType - Tipo MIME del archivo
|
|
48
|
+
* @param prefix - Prefijo opcional para el nombre del archivo
|
|
49
|
+
* @returns Ruta relativa del archivo guardado
|
|
50
|
+
*/
|
|
51
|
+
async uploadFile(filePath, buffer, mimeType, prefix) {
|
|
52
|
+
return this.storageCore.uploadFile(filePath, buffer, mimeType, prefix);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Descarga un archivo del almacenamiento local
|
|
56
|
+
*
|
|
57
|
+
* @param path - Ruta del archivo a descargar
|
|
58
|
+
* @returns Stream readable del archivo
|
|
59
|
+
*/
|
|
60
|
+
async downloadFile(path) {
|
|
61
|
+
return this.storageCore.downloadFile(path);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Elimina un archivo del almacenamiento local
|
|
65
|
+
*
|
|
66
|
+
* @param path - Ruta del archivo a eliminar
|
|
67
|
+
*/
|
|
68
|
+
async deleteFile(path) {
|
|
69
|
+
return this.storageCore.deleteFile(path);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Obtiene los metadatos de un archivo
|
|
73
|
+
*
|
|
74
|
+
* @param path - Ruta del archivo
|
|
75
|
+
* @returns Metadatos del archivo
|
|
76
|
+
*/
|
|
77
|
+
async getFileMetadata(path) {
|
|
78
|
+
return this.storageCore.getFileMetadata(path);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Lista los archivos en un directorio
|
|
82
|
+
*
|
|
83
|
+
* @param directoryPath - Ruta del directorio (opcional)
|
|
84
|
+
* @param options - Opciones de listado (limit, offset, prefix)
|
|
85
|
+
* @returns Lista de archivos y total
|
|
86
|
+
*/
|
|
87
|
+
async listFiles(directoryPath = '', options = {}) {
|
|
88
|
+
return this.storageCore.listFiles(directoryPath, options);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Verifica si un archivo existe
|
|
92
|
+
*
|
|
93
|
+
* @param path - Ruta del archivo
|
|
94
|
+
* @returns true si existe, false si no
|
|
95
|
+
*/
|
|
96
|
+
async fileExists(path) {
|
|
97
|
+
return this.storageCore.fileExists(path);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Método de compatibilidad con StorageClient.
|
|
101
|
+
* En modo offline no hay TOTP que verificar, siempre retorna éxito.
|
|
102
|
+
*/
|
|
103
|
+
async verifyTotp() {
|
|
104
|
+
return { message: 'Modo offline: verificación TOTP no requerida' };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.LocalStorageClient = LocalStorageClient;
|
|
108
|
+
//# sourceMappingURL=local-storage-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage-client.js","sourceRoot":"","sources":["../../src/client/local-storage-client.ts"],"names":[],"mappings":";;;AACA,uDAAmD;AAenD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,kBAAkB;IACZ,WAAW,CAAc;IAC1B,IAA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,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,OAAO,EAAE,8CAA8C,EAAE,CAAC;IACrE,CAAC;CACF;AAhGD,gDAgGC"}
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
|
-
import type { FileMetadata, ListFilesOptions } from '../types';
|
|
2
|
+
import type { FileMetadata, ListFilesOptions, ClientConfig } from '../types';
|
|
3
3
|
export interface StorageClientOptions {
|
|
4
4
|
baseUrl: string;
|
|
5
|
-
apiKey: string;
|
|
6
5
|
timeout?: number;
|
|
6
|
+
clientConfig: ClientConfig;
|
|
7
|
+
clientSecret: string;
|
|
8
|
+
totpSecret: string;
|
|
9
|
+
/** Período TOTP en segundos (default 30). Debe coincidir con TOTP_PERIOD del servidor. */
|
|
10
|
+
totpPeriodSeconds?: number;
|
|
7
11
|
}
|
|
8
12
|
export declare class StorageClient {
|
|
9
13
|
private readonly baseUrl;
|
|
10
|
-
private readonly apiKey;
|
|
11
14
|
private readonly timeout;
|
|
12
15
|
private readonly apiPrefix;
|
|
16
|
+
private readonly clientConfig;
|
|
17
|
+
private readonly clientSecret;
|
|
18
|
+
private readonly totpSecret;
|
|
19
|
+
private readonly totpPeriodSec;
|
|
20
|
+
private readonly totpPeriodMs;
|
|
21
|
+
private tokenCache;
|
|
13
22
|
constructor(options: StorageClientOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Genera un token JWT firmado con HMAC usando CLIENT_SECRET + código TOTP actual.
|
|
25
|
+
* Genera un nuevo token cuando el TOTP cambia (cada totpPeriodSeconds).
|
|
26
|
+
*/
|
|
27
|
+
private generateToken;
|
|
28
|
+
/**
|
|
29
|
+
* Convierte expiresIn string (ej: "30m", "7d") a segundos
|
|
30
|
+
*/
|
|
31
|
+
private parseExpiresIn;
|
|
14
32
|
private getHeaders;
|
|
15
33
|
private request;
|
|
16
34
|
uploadFile(filePath: string, buffer: Buffer, mimeType: string, prefix?: string): Promise<string>;
|
|
@@ -22,5 +40,12 @@ export declare class StorageClient {
|
|
|
22
40
|
total: number;
|
|
23
41
|
}>;
|
|
24
42
|
fileExists(path: string): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Verifica que el cliente puede generar el código TOTP correcto
|
|
45
|
+
* (opcional, para validar configuración)
|
|
46
|
+
*/
|
|
47
|
+
verifyTotp(): Promise<{
|
|
48
|
+
message: string;
|
|
49
|
+
}>;
|
|
25
50
|
}
|
|
26
51
|
//# sourceMappingURL=storage-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-client.d.ts","sourceRoot":"","sources":["../../src/client/storage-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"storage-client.d.ts","sourceRoot":"","sources":["../../src/client/storage-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAIlC,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAa7E,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,0FAA0F;IAC1F,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAWD,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuB;IACjD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS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