@vita-mojo/aggregator 1.8.0 → 1.10.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/main.js.enc CHANGED
Binary file
package/main.js.map.enc CHANGED
Binary file
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@vita-mojo/aggregator",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "type": "commonjs",
5
5
  "scripts": {
6
- "postinstall": "npx ts-node tools/scripts/decrypt-aggregator.ts"
6
+ "postinstall": "node postinstall.js"
7
7
  },
8
8
  "dependencies": {
9
9
  "@vita-mojo/amounts": "0.0.33",
package/postinstall.js ADDED
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console */
3
+
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const crypto = require('crypto');
7
+
8
+ /**
9
+ * Load environment variables from .env file
10
+ */
11
+ function loadEnvFile() {
12
+ // Navigate up to repo root (from node_modules/@cicd_vitamojo/aggregator)
13
+ const repoRoot = path.resolve(__dirname, '../../../..');
14
+ const envFilePath = path.join(repoRoot, '.env');
15
+
16
+ if (!fs.existsSync(envFilePath)) {
17
+ console.log('ℹ No .env file found in repo root');
18
+ return;
19
+ }
20
+
21
+ try {
22
+ const envContent = fs.readFileSync(envFilePath, 'utf-8');
23
+ const lines = envContent.split('\n');
24
+
25
+ for (const line of lines) {
26
+ const trimmed = line.trim();
27
+
28
+ // Skip empty lines and comments
29
+ if (!trimmed || trimmed.startsWith('#')) {
30
+ continue;
31
+ }
32
+
33
+ const [key, ...valueParts] = trimmed.split('=');
34
+ const value = valueParts.join('=').trim();
35
+
36
+ // Remove quotes if present
37
+ const cleanValue = value.replace(/^['"]|['"]$/g, '');
38
+
39
+ // Only set if not already in environment
40
+ if (!process.env[key]) {
41
+ process.env[key] = cleanValue;
42
+ }
43
+ }
44
+
45
+ console.log('✓ Loaded environment variables from .env file');
46
+ } catch (error) {
47
+ console.error(`⚠ Failed to read .env file: ${error.message}`);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Decrypt a file using a shared secret
53
+ */
54
+ function decryptFile(filePath, sharedSecret) {
55
+ const encryptedData = fs.readFileSync(filePath);
56
+
57
+ // Extract IV from the first 16 bytes
58
+ const iv = encryptedData.slice(0, 16);
59
+ const encrypted = encryptedData.slice(16);
60
+
61
+ // Decrypt the file content with AES-256-CBC using the shared secret
62
+ const decipher = crypto.createDecipheriv('aes-256-cbc', sharedSecret, iv);
63
+ const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
64
+
65
+ return decrypted;
66
+ }
67
+
68
+ /**
69
+ * Decrypt all .enc files in the current directory
70
+ */
71
+ function decryptFiles() {
72
+ console.log('\n🔓 Decrypting aggregator files...');
73
+
74
+ const sharedSecretEnv = process.env.AGGREGATOR_ENCRYPTION_KEY;
75
+ if (!sharedSecretEnv) {
76
+ console.warn('⚠ AGGREGATOR_ENCRYPTION_KEY environment variable not set');
77
+ console.warn('⚠ Skipping decryption of aggregator files');
78
+ return;
79
+ }
80
+
81
+ // Shared secret must be 32 bytes (256 bits) for AES-256
82
+ const sharedSecret = Buffer.from(sharedSecretEnv, 'base64');
83
+ if (sharedSecret.length !== 32) {
84
+ throw new Error(`AGGREGATOR_ENCRYPTION_KEY must be 32 bytes (256 bits), got ${sharedSecret.length} bytes`);
85
+ }
86
+
87
+ // Get current directory (where the package is installed)
88
+ const currentDir = __dirname;
89
+
90
+ if (!fs.existsSync(currentDir)) {
91
+ console.log(`✗ Directory not found: ${currentDir}`);
92
+ return;
93
+ }
94
+
95
+ const files = fs.readdirSync(currentDir);
96
+ let decryptedCount = 0;
97
+
98
+ for (const file of files) {
99
+ if (!file.endsWith('.enc')) {
100
+ continue;
101
+ }
102
+
103
+ const encFilePath = path.join(currentDir, file);
104
+ const originalFilePath = encFilePath.slice(0, -4); // Remove .enc extension
105
+
106
+ try {
107
+ const decrypted = decryptFile(encFilePath, sharedSecret);
108
+ fs.writeFileSync(originalFilePath, decrypted);
109
+ fs.unlinkSync(encFilePath); // Remove encrypted file
110
+ console.log(` ✓ Decrypted: ${path.basename(originalFilePath)}`);
111
+ decryptedCount++;
112
+ } catch (error) {
113
+ console.error(`Failed to decrypt ${file}:`, error.message);
114
+ throw error;
115
+ }
116
+ }
117
+
118
+ if (decryptedCount === 0) {
119
+ console.log('No encrypted files found');
120
+ } else {
121
+ console.log(`✓ Decryption completed (${decryptedCount} files)`);
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Main execution
127
+ */
128
+ try {
129
+ loadEnvFile();
130
+ decryptFiles();
131
+ } catch (error) {
132
+ console.error('\n❌ Aggregator decryption failed:', error.message);
133
+ process.exit(1);
134
+ }