@nexushub/client 0.4.3 → 0.4.4
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/dist/chunk-NOIMIIA5.js +53 -0
- package/dist/chunk-VFVPDENW.cjs +53 -0
- package/dist/cli.cjs +460 -99
- package/dist/content/binary-compiler.cjs +135 -0
- package/dist/content/binary-compiler.d.cts +28 -0
- package/dist/content/binary-compiler.d.ts +28 -0
- package/dist/content/binary-compiler.js +100 -0
- package/dist/content/local-cache-server.cjs +184 -52
- package/dist/content/local-cache-server.d.cts +9 -4
- package/dist/content/local-cache-server.d.ts +9 -4
- package/dist/content/local-cache-server.js +184 -52
- package/dist/index.cjs +221 -99
- package/dist/index.js +221 -99
- package/dist/local-cache-server-BNLLL4NR.js +224 -0
- package/dist/local-cache-server-SF5SXE7H.cjs +224 -0
- package/dist/react.cjs +399 -78
- package/dist/react.d.cts +140 -1
- package/dist/react.d.ts +140 -1
- package/dist/react.js +370 -49
- package/package.json +2 -1
- package/dist/local-cache-server-6DXQJFCQ.cjs +0 -114
- package/dist/local-cache-server-DBJWR7HD.js +0 -114
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
var _chunkVFVPDENWcjs = require('./chunk-VFVPDENW.cjs');
|
|
4
|
+
|
|
5
|
+
// src/content/local-cache-server.ts
|
|
6
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
7
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
8
|
+
|
|
9
|
+
// src/content/binary-compiler.ts
|
|
10
|
+
var _crypto = require('crypto'); var crypto = _interopRequireWildcard(_crypto);
|
|
11
|
+
var BinaryCompiler = class {
|
|
12
|
+
/**
|
|
13
|
+
* Generates a secure, deterministic cryptographic key from the project's API key.
|
|
14
|
+
*/
|
|
15
|
+
static deriveKeys(apiKey) {
|
|
16
|
+
const hash = crypto.createHash("sha256").update(apiKey).digest();
|
|
17
|
+
const encryptionKey = hash;
|
|
18
|
+
const hmacKey = crypto.createHmac("sha256", apiKey).update("nexus-integrity-key").digest();
|
|
19
|
+
return { encryptionKey, hmacKey };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Compiles JSON content data into a secure, signed, and encrypted .nx binary buffer.
|
|
23
|
+
*/
|
|
24
|
+
static compile(data, apiKey, projectId, metadataOverrides = {}) {
|
|
25
|
+
const { encryptionKey, hmacKey } = this.deriveKeys(apiKey);
|
|
26
|
+
const metadata = {
|
|
27
|
+
version: "2.0.0",
|
|
28
|
+
compiledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
29
|
+
projectId,
|
|
30
|
+
...metadataOverrides
|
|
31
|
+
};
|
|
32
|
+
const metadataStr = JSON.stringify(metadata);
|
|
33
|
+
const metadataBuffer = Buffer.from(metadataStr, "utf-8");
|
|
34
|
+
const iv = crypto.randomBytes(16);
|
|
35
|
+
const cipher = crypto.createCipheriv(this.ALGORITHM, encryptionKey, iv);
|
|
36
|
+
const plainTextPayload = JSON.stringify(data);
|
|
37
|
+
let encryptedPayload = cipher.update(plainTextPayload, "utf8");
|
|
38
|
+
encryptedPayload = Buffer.concat([encryptedPayload, cipher.final()]);
|
|
39
|
+
const payloadBuffer = Buffer.concat([iv, encryptedPayload]);
|
|
40
|
+
const headerBuffer = Buffer.from(this.MAGIC_HEADER, "ascii");
|
|
41
|
+
const metaLengthBuffer = Buffer.alloc(4);
|
|
42
|
+
metaLengthBuffer.writeUInt32BE(metadataBuffer.length, 0);
|
|
43
|
+
const payloadLengthBuffer = Buffer.alloc(4);
|
|
44
|
+
payloadLengthBuffer.writeUInt32BE(payloadBuffer.length, 0);
|
|
45
|
+
const prefixBlock = Buffer.concat([
|
|
46
|
+
headerBuffer,
|
|
47
|
+
metaLengthBuffer,
|
|
48
|
+
metadataBuffer,
|
|
49
|
+
payloadLengthBuffer,
|
|
50
|
+
payloadBuffer
|
|
51
|
+
]);
|
|
52
|
+
const hmac = crypto.createHmac("sha256", hmacKey);
|
|
53
|
+
hmac.update(prefixBlock);
|
|
54
|
+
const signature = hmac.digest();
|
|
55
|
+
return Buffer.concat([prefixBlock, signature]);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Verifies, decrypts, and decompiles a .nx binary buffer back into clean, type-safe JSON.
|
|
59
|
+
* Throws structured errors on integrity verification failures or file corruption.
|
|
60
|
+
*/
|
|
61
|
+
static decompile(buffer, apiKey) {
|
|
62
|
+
if (buffer.length < 44) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
"Corrupted File: Binary payload is too short to be a valid Nexus node."
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const { encryptionKey, hmacKey } = this.deriveKeys(apiKey);
|
|
68
|
+
const prefixBlockLength = buffer.length - 32;
|
|
69
|
+
const prefixBlock = buffer.subarray(0, prefixBlockLength);
|
|
70
|
+
const expectedSignature = buffer.subarray(prefixBlockLength);
|
|
71
|
+
const hmac = crypto.createHmac("sha256", hmacKey);
|
|
72
|
+
hmac.update(prefixBlock);
|
|
73
|
+
const actualSignature = hmac.digest();
|
|
74
|
+
if (!crypto.timingSafeEqual(expectedSignature, actualSignature)) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
"DATA_INTEGRITY_VIOLATION: Cryptographic signature mismatch. This local node has been modified externally or tampered with."
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const magicHeader = prefixBlock.subarray(0, 4).toString("ascii");
|
|
80
|
+
if (magicHeader !== this.MAGIC_HEADER) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
"Invalid Format: File lacks the correct Nexus binary magic header."
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
const metaLength = prefixBlock.readUInt32BE(4);
|
|
86
|
+
const metaStart = 8;
|
|
87
|
+
const metaEnd = metaStart + metaLength;
|
|
88
|
+
const metadataStr = prefixBlock.subarray(metaStart, metaEnd).toString("utf-8");
|
|
89
|
+
const metadata = JSON.parse(metadataStr);
|
|
90
|
+
const payloadLength = prefixBlock.readUInt32BE(metaEnd);
|
|
91
|
+
const payloadStart = metaEnd + 4;
|
|
92
|
+
const payloadEnd = payloadStart + payloadLength;
|
|
93
|
+
const payloadBuffer = prefixBlock.subarray(payloadStart, payloadEnd);
|
|
94
|
+
const iv = payloadBuffer.subarray(0, 16);
|
|
95
|
+
const cipherText = payloadBuffer.subarray(16);
|
|
96
|
+
const decipher = crypto.createDecipheriv(this.ALGORITHM, encryptionKey, iv);
|
|
97
|
+
let decrypted = decipher.update(cipherText);
|
|
98
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
99
|
+
const data = JSON.parse(decrypted.toString("utf8"));
|
|
100
|
+
return { data, metadata };
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
BinaryCompiler.MAGIC_HEADER = "NEXS";
|
|
104
|
+
// 4-byte ASCII magic identifier
|
|
105
|
+
BinaryCompiler.ALGORITHM = "aes-256-cbc";
|
|
106
|
+
|
|
107
|
+
// src/content/local-cache-server.ts
|
|
108
|
+
var LocalCache = class {
|
|
109
|
+
constructor(customPath) {
|
|
110
|
+
this.apiKey = "";
|
|
111
|
+
this.baseDir = customPath || ".nexus/local";
|
|
112
|
+
const config = _chunkVFVPDENWcjs.getEnvConfig.call(void 0, );
|
|
113
|
+
this.apiKey = config.apiKey || "";
|
|
114
|
+
}
|
|
115
|
+
isLoaded() {
|
|
116
|
+
return _fs2.default.existsSync(_path2.default.resolve(process.cwd(), this.baseDir));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Helper to decrypt and decompile `.nx` files on-the-fly.
|
|
120
|
+
*/
|
|
121
|
+
decompileFile(filePath) {
|
|
122
|
+
if (!this.apiKey) {
|
|
123
|
+
if (process.env.NODE_ENV === "development") {
|
|
124
|
+
console.warn(
|
|
125
|
+
"\u26A0\uFE0F NexusHub: Missing NEXUS_API_KEY. Local decryption bypassed."
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const encryptedBuffer = _fs2.default.readFileSync(filePath);
|
|
132
|
+
const decompiled = BinaryCompiler.decompile(encryptedBuffer, this.apiKey);
|
|
133
|
+
return decompiled.data;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (process.env.NODE_ENV === "development") {
|
|
136
|
+
console.error(
|
|
137
|
+
`
|
|
138
|
+
\u{1F6A8} NexusHub Security Alert: Data Integrity Violation in file:
|
|
139
|
+
${filePath}
|
|
140
|
+
Error: ${error.message}
|
|
141
|
+
This file has been disabled until regenerated via npx nexus pull.
|
|
142
|
+
`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Retrieve a specific page directly from its .nx file.
|
|
150
|
+
*/
|
|
151
|
+
async getPage(slug) {
|
|
152
|
+
const filePath = _path2.default.resolve(
|
|
153
|
+
process.cwd(),
|
|
154
|
+
this.baseDir,
|
|
155
|
+
"pages",
|
|
156
|
+
`${slug}.nx`
|
|
157
|
+
);
|
|
158
|
+
if (_fs2.default.existsSync(filePath)) {
|
|
159
|
+
const pageData = this.decompileFile(filePath);
|
|
160
|
+
if (!pageData) return null;
|
|
161
|
+
return pageData.data !== void 0 ? pageData.data : pageData;
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Retrieve an entire collection from its specific .nx file.
|
|
167
|
+
*/
|
|
168
|
+
async getCollection(collectionId) {
|
|
169
|
+
const filePath = _path2.default.resolve(
|
|
170
|
+
process.cwd(),
|
|
171
|
+
this.baseDir,
|
|
172
|
+
"collections",
|
|
173
|
+
`${collectionId}.nx`
|
|
174
|
+
);
|
|
175
|
+
if (_fs2.default.existsSync(filePath)) {
|
|
176
|
+
return this.decompileFile(filePath);
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Retrieve global settings from its .nx file.
|
|
182
|
+
*/
|
|
183
|
+
async getGlobals() {
|
|
184
|
+
const filePath = _path2.default.resolve(process.cwd(), this.baseDir, "globals.nx");
|
|
185
|
+
if (_fs2.default.existsSync(filePath)) {
|
|
186
|
+
return this.decompileFile(filePath);
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Returns a merged JSON of the entire workspace structure.
|
|
192
|
+
*/
|
|
193
|
+
async getAllData() {
|
|
194
|
+
const pages = {};
|
|
195
|
+
const collections = {};
|
|
196
|
+
let globals = {};
|
|
197
|
+
try {
|
|
198
|
+
const pagesDir = _path2.default.resolve(process.cwd(), this.baseDir, "pages");
|
|
199
|
+
if (_fs2.default.existsSync(pagesDir)) {
|
|
200
|
+
for (const file of _fs2.default.readdirSync(pagesDir)) {
|
|
201
|
+
if (file.endsWith(".nx")) {
|
|
202
|
+
const slug = _path2.default.basename(file, ".nx");
|
|
203
|
+
pages[slug] = await this.getPage(slug);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const colsDir = _path2.default.resolve(process.cwd(), this.baseDir, "collections");
|
|
208
|
+
if (_fs2.default.existsSync(colsDir)) {
|
|
209
|
+
for (const file of _fs2.default.readdirSync(colsDir)) {
|
|
210
|
+
if (file.endsWith(".nx")) {
|
|
211
|
+
const id = _path2.default.basename(file, ".nx");
|
|
212
|
+
collections[id] = await this.getCollection(id) || [];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
globals = await this.getGlobals() || {};
|
|
217
|
+
} catch (e) {
|
|
218
|
+
}
|
|
219
|
+
return { pages, collections, globals };
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
exports.LocalCache = LocalCache;
|