xypriss 1.3.1 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xypriss",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "XyPriss is a Node.js framework that extends Express.js with additional performance, security, and scalability features. Built with TypeScript, it maintains full Express.js compatibility while adding enterprise-level capabilities for production applications.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -12,7 +12,9 @@
12
12
  "dist/esm/**/*",
13
13
  "dist/index.d.ts",
14
14
  "README.md",
15
- "LICENSE"
15
+ "LICENSE",
16
+ "scripts/**/*",
17
+ "scripts/postinstall.js"
16
18
  ],
17
19
  "scripts": {
18
20
  "postinstall": "node scripts/postinstall.js",
@@ -0,0 +1,282 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * XyPriss Memory CLI Installer
5
+ * Downloads platform-specific memory CLI binary during npm install
6
+ */
7
+
8
+ const https = require("https");
9
+ const fs = require("fs");
10
+ const path = require("path");
11
+ const { execSync } = require("child_process");
12
+
13
+ const CDN_BASE_URL = "https://sdk.nehonix.space/dl/mds/xypriss/bin";
14
+ const BIN_DIR = path.join(__dirname, "..", "bin");
15
+ const TIMEOUT = 30000; // 30 seconds
16
+
17
+ /**
18
+ * Get platform-specific binary information
19
+ */
20
+ function getPlatformBinary() {
21
+ const platform = process.platform;
22
+ const arch = process.arch;
23
+
24
+ let binaryName;
25
+ let downloadName;
26
+
27
+ if (platform === "win32") {
28
+ binaryName =
29
+ arch === "arm64"
30
+ ? "memory-cli-windows-arm64.exe"
31
+ : "memory-cli-windows-x64.exe";
32
+ downloadName = binaryName;
33
+ } else if (platform === "darwin") {
34
+ binaryName =
35
+ arch === "arm64"
36
+ ? "memory-cli-darwin-arm64"
37
+ : "memory-cli-darwin-x64";
38
+ downloadName = binaryName;
39
+ } else if (platform === "linux") {
40
+ binaryName = "memory-cli-linux-x64";
41
+ downloadName = binaryName;
42
+ } else {
43
+ console.warn(
44
+ `⚠️ Unsupported platform: ${platform}-${arch}. Memory CLI will use fallback mode.`
45
+ );
46
+ return null;
47
+ }
48
+
49
+ return {
50
+ binaryName,
51
+ downloadName,
52
+ url: `${CDN_BASE_URL}/${downloadName}`,
53
+ localPath: path.join(BIN_DIR, binaryName),
54
+ genericPath: path.join(
55
+ BIN_DIR,
56
+ "memory-cli" + (platform === "win32" ? ".exe" : "")
57
+ ),
58
+ };
59
+ }
60
+
61
+ /**
62
+ * Download file from URL
63
+ */
64
+ function downloadFile(url, destination) {
65
+ return new Promise((resolve, reject) => {
66
+ console.log(`📥 Downloading ${url}...`);
67
+
68
+ const file = fs.createWriteStream(destination);
69
+ const request = https.get(url, { timeout: TIMEOUT }, (response) => {
70
+ if (response.statusCode === 200) {
71
+ response.pipe(file);
72
+
73
+ file.on("finish", () => {
74
+ file.close();
75
+ console.log(`✅ Downloaded to ${destination}`);
76
+ resolve();
77
+ });
78
+ } else if (
79
+ response.statusCode === 302 ||
80
+ response.statusCode === 301
81
+ ) {
82
+ // Handle redirects
83
+ file.close();
84
+ fs.unlinkSync(destination);
85
+ downloadFile(response.headers.location, destination)
86
+ .then(resolve)
87
+ .catch(reject);
88
+ } else {
89
+ file.close();
90
+ fs.unlinkSync(destination);
91
+ reject(
92
+ new Error(
93
+ `HTTP ${response.statusCode}: ${response.statusMessage}`
94
+ )
95
+ );
96
+ }
97
+ });
98
+
99
+ request.on("error", (error) => {
100
+ file.close();
101
+ if (fs.existsSync(destination)) {
102
+ fs.unlinkSync(destination);
103
+ }
104
+ reject(error);
105
+ });
106
+
107
+ request.on("timeout", () => {
108
+ request.destroy();
109
+ file.close();
110
+ if (fs.existsSync(destination)) {
111
+ fs.unlinkSync(destination);
112
+ }
113
+ reject(new Error("Download timeout"));
114
+ });
115
+ });
116
+ }
117
+
118
+ /**
119
+ * Make file executable (Unix-like systems)
120
+ */
121
+ function makeExecutable(filePath) {
122
+ if (process.platform !== "win32") {
123
+ try {
124
+ execSync(`chmod +x "${filePath}"`);
125
+ console.log(`🔧 Made ${filePath} executable`);
126
+ } catch (error) {
127
+ console.warn(
128
+ `⚠️ Failed to make ${filePath} executable:`,
129
+ error.message
130
+ );
131
+ }
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Verify downloaded binary works
137
+ */
138
+ function verifyBinary(filePath) {
139
+ return new Promise((resolve) => {
140
+ try {
141
+ const { spawn } = require("child_process");
142
+ const child = spawn(filePath, ["--help"], {
143
+ stdio: "pipe",
144
+ timeout: 5000,
145
+ });
146
+
147
+ let output = "";
148
+ child.stdout.on("data", (data) => {
149
+ output += data.toString();
150
+ });
151
+
152
+ child.on("close", (code) => {
153
+ if (code === 0 && output.includes("XyPriss Memory Info CLI")) {
154
+ console.log(`✅ Binary verification successful`);
155
+ resolve(true);
156
+ } else {
157
+ console.warn(
158
+ `⚠️ Binary verification failed (exit code: ${code})`
159
+ );
160
+ resolve(false);
161
+ }
162
+ });
163
+
164
+ child.on("error", () => {
165
+ resolve(false);
166
+ });
167
+ } catch (error) {
168
+ resolve(false);
169
+ }
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Main installation function
175
+ */
176
+ async function installMemoryCLI() {
177
+ console.log("🚀 Installing XyPriss Memory CLI...");
178
+
179
+ // Create bin directory if it doesn't exist
180
+ if (!fs.existsSync(BIN_DIR)) {
181
+ fs.mkdirSync(BIN_DIR, { recursive: true });
182
+ console.log(`📁 Created bin directory: ${BIN_DIR}`);
183
+ }
184
+
185
+ const binaryInfo = getPlatformBinary();
186
+ if (!binaryInfo) {
187
+ console.log(
188
+ "⚠️ No binary available for this platform. Using fallback mode."
189
+ );
190
+ return;
191
+ }
192
+
193
+ try {
194
+ // Download the binary
195
+ await downloadFile(binaryInfo.url, binaryInfo.localPath);
196
+
197
+ // Make it executable
198
+ makeExecutable(binaryInfo.localPath);
199
+
200
+ // Create a generic symlink/copy for easier access
201
+ if (!fs.existsSync(binaryInfo.genericPath)) {
202
+ if (process.platform === "win32") {
203
+ // On Windows, copy the file
204
+ fs.copyFileSync(binaryInfo.localPath, binaryInfo.genericPath);
205
+ } else {
206
+ // On Unix-like systems, create a symlink
207
+ fs.symlinkSync(
208
+ path.basename(binaryInfo.localPath),
209
+ binaryInfo.genericPath
210
+ );
211
+ }
212
+ console.log(
213
+ `🔗 Created generic binary link: ${binaryInfo.genericPath}`
214
+ );
215
+ }
216
+
217
+ // Verify the binary works
218
+ const isValid = await verifyBinary(binaryInfo.localPath);
219
+ if (!isValid) {
220
+ console.warn(
221
+ "⚠️ Binary verification failed. Memory CLI will use fallback mode."
222
+ );
223
+ return;
224
+ }
225
+
226
+ console.log("🎉 XyPriss Memory CLI installed successfully!");
227
+ console.log(`📍 Binary location: ${binaryInfo.localPath}`);
228
+ } catch (error) {
229
+ console.error("❌ Failed to install Memory CLI:", error.message);
230
+ console.log("📝 Memory CLI will use fallback mode (Node.js os module)");
231
+
232
+ // Clean up partial downloads
233
+ if (fs.existsSync(binaryInfo.localPath)) {
234
+ try {
235
+ fs.unlinkSync(binaryInfo.localPath);
236
+ } catch (cleanupError) {
237
+ // Ignore cleanup errors
238
+ }
239
+ }
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Check if we should skip installation
245
+ */
246
+ function shouldSkipInstall() {
247
+ // Skip if CI environment variable is set to avoid network calls in CI
248
+ if (
249
+ process.env.CI === "true" ||
250
+ process.env.SKIP_BINARY_DOWNLOAD === "true"
251
+ ) {
252
+ console.log("⏭️ Skipping binary download (CI environment detected)");
253
+ return true;
254
+ }
255
+
256
+ // Skip if binary already exists and is valid
257
+ const binaryInfo = getPlatformBinary();
258
+ if (binaryInfo && fs.existsSync(binaryInfo.localPath)) {
259
+ console.log("✅ Memory CLI binary already exists");
260
+ return true;
261
+ }
262
+
263
+ return false;
264
+ }
265
+
266
+ // Run installation if this script is executed directly
267
+ if (require.main === module) {
268
+ if (!shouldSkipInstall()) {
269
+ installMemoryCLI().catch((error) => {
270
+ console.error("💥 Installation failed:", error);
271
+ process.exit(0); // Don't fail npm install if binary download fails
272
+ });
273
+ }
274
+ }
275
+
276
+ module.exports = {
277
+ installMemoryCLI,
278
+ getPlatformBinary,
279
+ downloadFile,
280
+ verifyBinary,
281
+ };
282
+
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * XyPriss Post-Install Script
5
+ * Runs after npm install to set up platform-specific binaries
6
+ */
7
+
8
+ const { installMemoryCLI } = require('./install-memory-cli');
9
+
10
+ async function postInstall() {
11
+ console.log('🔧 Running XyPriss post-install setup...');
12
+
13
+ try {
14
+ await installMemoryCLI();
15
+ console.log('✅ XyPriss setup complete!');
16
+ } catch (error) {
17
+ console.warn('⚠️ Post-install setup encountered issues:', error.message);
18
+ console.log('📝 XyPriss will continue to work with fallback mode.');
19
+ }
20
+ }
21
+
22
+ // Only run if this is the main module (not being required)
23
+ if (require.main === module) {
24
+ postInstall().catch((error) => {
25
+ console.error('💥 Post-install failed:', error);
26
+ // Don't exit with error code to avoid breaking npm install
27
+ process.exit(0);
28
+ });
29
+ }
30
+
31
+ module.exports = { postInstall };