@p47h/vault-js 0.9.0 → 0.9.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@p47h/vault-js",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Secure, local-first cryptographic storage for browser environments. Argon2id + XChaCha20Poly1305 + Ed25519 backed by WASM.",
5
5
  "keywords": [
6
6
  "security",
@@ -34,6 +34,7 @@
34
34
  "files": [
35
35
  "dist",
36
36
  "wasm",
37
+ "scripts/postinstall.js",
37
38
  "LICENSE",
38
39
  "README.md"
39
40
  ],
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * P47H Vault JS - Postinstall Helper
5
+ * Este script ayuda al usuario a copiar los binarios WASM necesarios
6
+ * a su carpeta de assets públicos para que el navegador pueda cargarlos.
7
+ */
8
+
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+
13
+ // Reconstruir __dirname para ESM
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = path.dirname(__filename);
16
+
17
+ // Colores para la consola (DX amigable)
18
+ const CYAN = '\x1b[36m';
19
+ const RESET = '\x1b[0m';
20
+ const GREEN = '\x1b[32m';
21
+ const YELLOW = '\x1b[33m';
22
+ const RED = '\x1b[31m';
23
+
24
+ // Rutas relativas dentro del paquete instalado
25
+ const PACKAGE_ROOT = path.resolve(__dirname, '..');
26
+ const WASM_SOURCE_DIR = path.join(PACKAGE_ROOT, 'wasm');
27
+
28
+ // Detectar directorio del proyecto del usuario
29
+ const USER_PROJECT_ROOT = process.env.INIT_CWD || path.resolve(PACKAGE_ROOT, '../../..');
30
+
31
+ console.log(`${CYAN}
32
+ ╔══════════════════════════════════════════════════════════════╗
33
+ ║ P47H VAULT JS - SETUP ║
34
+ ╚══════════════════════════════════════════════════════════════╝
35
+ ${RESET}`);
36
+
37
+ function main() {
38
+ // 1. Verificar que los binarios fuente existen
39
+ if (!fs.existsSync(WASM_SOURCE_DIR)) {
40
+ // Si estamos en desarrollo local, tal vez no se ha compilado aún el wasm
41
+ // No fallamos el install, solo avisamos.
42
+ console.warn(`${YELLOW}[Warn] Source wasm directory not found at: ${WASM_SOURCE_DIR}${RESET}`);
43
+ console.warn(` If you are developing the library, run 'npm run build' first.`);
44
+ return;
45
+ }
46
+
47
+ // 2. Intentar detectar carpetas públicas comunes
48
+ const potentialDirs = [
49
+ 'public', // Vite, Next.js, Create React App
50
+ 'static', // Gatsby
51
+ 'assets', // Frameworks personalizados
52
+ 'wwwroot' // .NET
53
+ ];
54
+
55
+ let targetBaseDir = null;
56
+
57
+ for (const dir of potentialDirs) {
58
+ const attemptPath = path.join(USER_PROJECT_ROOT, dir);
59
+ if (fs.existsSync(attemptPath)) {
60
+ targetBaseDir = attemptPath;
61
+ break;
62
+ }
63
+ }
64
+
65
+ // 3. Ejecutar copia o mostrar instrucciones
66
+ if (targetBaseDir) {
67
+ const targetWasmDir = path.join(targetBaseDir, 'wasm');
68
+ console.log(`Detected public directory: ${GREEN}${targetBaseDir}${RESET}`);
69
+ copyFiles(WASM_SOURCE_DIR, targetWasmDir);
70
+ } else {
71
+ // No mostramos error rojo, solo instrucciones amarillas para no asustar
72
+ // si es un entorno donde no aplica (ej: CI/CD sin frontend)
73
+ printManualInstructions();
74
+ }
75
+ }
76
+
77
+ function copyFiles(srcDir, destDir) {
78
+ try {
79
+ if (!fs.existsSync(destDir)) {
80
+ fs.mkdirSync(destDir, { recursive: true });
81
+ }
82
+
83
+ let copiedCount = 0;
84
+ const files = fs.readdirSync(srcDir);
85
+
86
+ for (const file of files) {
87
+ const srcFile = path.join(srcDir, file);
88
+ const destFile = path.join(destDir, file);
89
+
90
+ fs.copyFileSync(srcFile, destFile);
91
+ copiedCount++;
92
+ }
93
+
94
+ console.log(`${GREEN}✔ Successfully copied ${copiedCount} WASM files to:${RESET}`);
95
+ console.log(` ${destDir}`);
96
+ console.log(`\n${CYAN}Ready to rock! 🚀${RESET}`);
97
+
98
+ } catch (err) {
99
+ console.error(`${RED}Failed to copy files automatically:${RESET}`, err.message);
100
+ printManualInstructions();
101
+ }
102
+ }
103
+
104
+ function printManualInstructions() {
105
+ console.log(`
106
+ ${YELLOW}ℹ️ MANUAL SETUP REQUIRED${RESET}
107
+
108
+ To ensure P47H Vault works correctly, please copy the WASM binaries
109
+ from the package to your application's public assets folder.
110
+
111
+ ${CYAN}Source:${RESET} node_modules/@p47h/vault-js/wasm/
112
+ ${CYAN}Destination:${RESET} [Your Public Folder]/wasm/
113
+ `);
114
+ }
115
+
116
+ main();