xypriss 1.3.1 → 1.3.3

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