@nexushub/client 0.4.2 → 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.
@@ -1,116 +1,281 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }"use client";
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/content/local-cache-server.ts
31
+ var local_cache_server_exports = {};
32
+ __export(local_cache_server_exports, {
33
+ LocalCache: () => LocalCache
34
+ });
35
+ module.exports = __toCommonJS(local_cache_server_exports);
36
+ var import_fs = __toESM(require("fs"), 1);
37
+ var import_path = __toESM(require("path"), 1);
38
+
39
+ // src/config.ts
40
+ var DEFAULT_API_URL = "https://endpoints.gnexus.co.tz";
41
+ var DEFAULT_ANALYTICS_URL = "https://sentry.gnexus.co.tz";
42
+ var LOCAL_NEST_URL = "https://endpoints.gnexus.co.tz";
43
+ var LOCAL_RUST_URL = "https://sentry.gnexus.co.tz";
44
+ var getEnvConfig = () => {
45
+ const NEXT_PUBLIC_ID = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_ID : void 0;
46
+ const NEXT_PUBLIC_KEY = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_KEY : void 0;
47
+ const NEXT_PUBLIC_URL = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_API_URL : void 0;
48
+ const NODE_ID = typeof process !== "undefined" ? process.env.NEXUS_PROJECT_ID : void 0;
49
+ const NODE_KEY = typeof process !== "undefined" ? process.env.NEXUS_API_KEY : void 0;
50
+ const NODE_URL = typeof process !== "undefined" ? process.env.NEXUS_API_URL : void 0;
51
+ const NODE_ENV = typeof process !== "undefined" ? process.env.NODE_ENV : "production";
52
+ const isDev = NODE_ENV === "development" || typeof window !== "undefined" && window.location.hostname === "localhost";
53
+ const projectId = NEXT_PUBLIC_ID ?? NODE_ID;
54
+ const apiKey = NEXT_PUBLIC_KEY ?? NODE_KEY;
55
+ const apiUrl = NEXT_PUBLIC_URL ?? NODE_URL ?? (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL);
56
+ const analyticsUrl = apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL;
57
+ return {
58
+ projectId,
59
+ apiKey,
60
+ apiUrl,
61
+ analyticsUrl
62
+ };
63
+ };
64
+
65
+ // src/content/binary-compiler.ts
66
+ var crypto = __toESM(require("crypto"), 1);
67
+ var BinaryCompiler = class {
68
+ /**
69
+ * Generates a secure, deterministic cryptographic key from the project's API key.
70
+ */
71
+ static deriveKeys(apiKey) {
72
+ const hash = crypto.createHash("sha256").update(apiKey).digest();
73
+ const encryptionKey = hash;
74
+ const hmacKey = crypto.createHmac("sha256", apiKey).update("nexus-integrity-key").digest();
75
+ return { encryptionKey, hmacKey };
76
+ }
77
+ /**
78
+ * Compiles JSON content data into a secure, signed, and encrypted .nx binary buffer.
79
+ */
80
+ static compile(data, apiKey, projectId, metadataOverrides = {}) {
81
+ const { encryptionKey, hmacKey } = this.deriveKeys(apiKey);
82
+ const metadata = {
83
+ version: "2.0.0",
84
+ compiledAt: (/* @__PURE__ */ new Date()).toISOString(),
85
+ projectId,
86
+ ...metadataOverrides
87
+ };
88
+ const metadataStr = JSON.stringify(metadata);
89
+ const metadataBuffer = Buffer.from(metadataStr, "utf-8");
90
+ const iv = crypto.randomBytes(16);
91
+ const cipher = crypto.createCipheriv(this.ALGORITHM, encryptionKey, iv);
92
+ const plainTextPayload = JSON.stringify(data);
93
+ let encryptedPayload = cipher.update(plainTextPayload, "utf8");
94
+ encryptedPayload = Buffer.concat([encryptedPayload, cipher.final()]);
95
+ const payloadBuffer = Buffer.concat([iv, encryptedPayload]);
96
+ const headerBuffer = Buffer.from(this.MAGIC_HEADER, "ascii");
97
+ const metaLengthBuffer = Buffer.alloc(4);
98
+ metaLengthBuffer.writeUInt32BE(metadataBuffer.length, 0);
99
+ const payloadLengthBuffer = Buffer.alloc(4);
100
+ payloadLengthBuffer.writeUInt32BE(payloadBuffer.length, 0);
101
+ const prefixBlock = Buffer.concat([
102
+ headerBuffer,
103
+ metaLengthBuffer,
104
+ metadataBuffer,
105
+ payloadLengthBuffer,
106
+ payloadBuffer
107
+ ]);
108
+ const hmac = crypto.createHmac("sha256", hmacKey);
109
+ hmac.update(prefixBlock);
110
+ const signature = hmac.digest();
111
+ return Buffer.concat([prefixBlock, signature]);
112
+ }
113
+ /**
114
+ * Verifies, decrypts, and decompiles a .nx binary buffer back into clean, type-safe JSON.
115
+ * Throws structured errors on integrity verification failures or file corruption.
116
+ */
117
+ static decompile(buffer, apiKey) {
118
+ if (buffer.length < 44) {
119
+ throw new Error(
120
+ "Corrupted File: Binary payload is too short to be a valid Nexus node."
121
+ );
122
+ }
123
+ const { encryptionKey, hmacKey } = this.deriveKeys(apiKey);
124
+ const prefixBlockLength = buffer.length - 32;
125
+ const prefixBlock = buffer.subarray(0, prefixBlockLength);
126
+ const expectedSignature = buffer.subarray(prefixBlockLength);
127
+ const hmac = crypto.createHmac("sha256", hmacKey);
128
+ hmac.update(prefixBlock);
129
+ const actualSignature = hmac.digest();
130
+ if (!crypto.timingSafeEqual(expectedSignature, actualSignature)) {
131
+ throw new Error(
132
+ "DATA_INTEGRITY_VIOLATION: Cryptographic signature mismatch. This local node has been modified externally or tampered with."
133
+ );
134
+ }
135
+ const magicHeader = prefixBlock.subarray(0, 4).toString("ascii");
136
+ if (magicHeader !== this.MAGIC_HEADER) {
137
+ throw new Error(
138
+ "Invalid Format: File lacks the correct Nexus binary magic header."
139
+ );
140
+ }
141
+ const metaLength = prefixBlock.readUInt32BE(4);
142
+ const metaStart = 8;
143
+ const metaEnd = metaStart + metaLength;
144
+ const metadataStr = prefixBlock.subarray(metaStart, metaEnd).toString("utf-8");
145
+ const metadata = JSON.parse(metadataStr);
146
+ const payloadLength = prefixBlock.readUInt32BE(metaEnd);
147
+ const payloadStart = metaEnd + 4;
148
+ const payloadEnd = payloadStart + payloadLength;
149
+ const payloadBuffer = prefixBlock.subarray(payloadStart, payloadEnd);
150
+ const iv = payloadBuffer.subarray(0, 16);
151
+ const cipherText = payloadBuffer.subarray(16);
152
+ const decipher = crypto.createDecipheriv(this.ALGORITHM, encryptionKey, iv);
153
+ let decrypted = decipher.update(cipherText);
154
+ decrypted = Buffer.concat([decrypted, decipher.final()]);
155
+ const data = JSON.parse(decrypted.toString("utf8"));
156
+ return { data, metadata };
157
+ }
158
+ };
159
+ BinaryCompiler.MAGIC_HEADER = "NEXS";
160
+ // 4-byte ASCII magic identifier
161
+ BinaryCompiler.ALGORITHM = "aes-256-cbc";
2
162
 
3
163
  // src/content/local-cache-server.ts
4
- var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
5
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
6
164
  var LocalCache = class {
7
165
  constructor(customPath) {
166
+ this.apiKey = "";
8
167
  this.baseDir = customPath || ".nexus/local";
168
+ const config = getEnvConfig();
169
+ this.apiKey = config.apiKey || "";
9
170
  }
10
171
  isLoaded() {
11
- return _fs2.default.existsSync(_path2.default.resolve(process.cwd(), this.baseDir));
172
+ return import_fs.default.existsSync(import_path.default.resolve(process.cwd(), this.baseDir));
12
173
  }
13
174
  /**
14
- * Retrieve a specific page directly from its file.
175
+ * Helper to decrypt and decompile `.nx` files on-the-fly.
15
176
  */
16
- async getPage(slug) {
17
- try {
18
- const filePath = _path2.default.resolve(
19
- process.cwd(),
20
- this.baseDir,
21
- "pages",
22
- `${slug}.json`
23
- );
24
- if (_fs2.default.existsSync(filePath)) {
25
- const fileContent = _fs2.default.readFileSync(filePath, "utf-8");
26
- const pageData = JSON.parse(fileContent);
27
- return pageData.data !== void 0 ? pageData.data : pageData;
177
+ decompileFile(filePath) {
178
+ if (!this.apiKey) {
179
+ if (process.env.NODE_ENV === "development") {
180
+ console.warn(
181
+ "\u26A0\uFE0F NexusHub: Missing NEXUS_API_KEY. Local decryption bypassed."
182
+ );
28
183
  }
184
+ return null;
185
+ }
186
+ try {
187
+ const encryptedBuffer = import_fs.default.readFileSync(filePath);
188
+ const decompiled = BinaryCompiler.decompile(encryptedBuffer, this.apiKey);
189
+ return decompiled.data;
29
190
  } catch (error) {
30
191
  if (process.env.NODE_ENV === "development") {
31
- console.warn(
32
- `\u26A0\uFE0F NexusHub: Failed to load local page '${slug}':`,
33
- error
192
+ console.error(
193
+ `
194
+ \u{1F6A8} NexusHub Security Alert: Data Integrity Violation in file:
195
+ ${filePath}
196
+ Error: ${error.message}
197
+ This file has been disabled until regenerated via npx nexus pull.
198
+ `
34
199
  );
35
200
  }
201
+ return null;
202
+ }
203
+ }
204
+ /**
205
+ * Retrieve a specific page directly from its .nx file.
206
+ */
207
+ async getPage(slug) {
208
+ const filePath = import_path.default.resolve(
209
+ process.cwd(),
210
+ this.baseDir,
211
+ "pages",
212
+ `${slug}.nx`
213
+ );
214
+ if (import_fs.default.existsSync(filePath)) {
215
+ const pageData = this.decompileFile(filePath);
216
+ if (!pageData) return null;
217
+ return pageData.data !== void 0 ? pageData.data : pageData;
36
218
  }
37
219
  return null;
38
220
  }
39
221
  /**
40
- * Retrieve an entire collection from its specific collection file.
222
+ * Retrieve an entire collection from its specific .nx file.
41
223
  */
42
224
  async getCollection(collectionId) {
43
- try {
44
- const filePath = _path2.default.resolve(
45
- process.cwd(),
46
- this.baseDir,
47
- "collections",
48
- `${collectionId}.json`
49
- );
50
- if (_fs2.default.existsSync(filePath)) {
51
- const fileContent = _fs2.default.readFileSync(filePath, "utf-8");
52
- return JSON.parse(fileContent);
53
- }
54
- } catch (error) {
55
- if (process.env.NODE_ENV === "development") {
56
- console.warn(
57
- `\u26A0\uFE0F NexusHub: Failed to load local collection '${collectionId}':`,
58
- error
59
- );
60
- }
225
+ const filePath = import_path.default.resolve(
226
+ process.cwd(),
227
+ this.baseDir,
228
+ "collections",
229
+ `${collectionId}.nx`
230
+ );
231
+ if (import_fs.default.existsSync(filePath)) {
232
+ return this.decompileFile(filePath);
61
233
  }
62
234
  return null;
63
235
  }
64
236
  /**
65
- * Retrieve global settings from its file.
237
+ * Retrieve global settings from its .nx file.
66
238
  */
67
239
  async getGlobals() {
68
- try {
69
- const filePath = _path2.default.resolve(
70
- process.cwd(),
71
- this.baseDir,
72
- "globals.json"
73
- );
74
- if (_fs2.default.existsSync(filePath)) {
75
- const fileContent = _fs2.default.readFileSync(filePath, "utf-8");
76
- return JSON.parse(fileContent);
77
- }
78
- } catch (e) {
240
+ const filePath = import_path.default.resolve(process.cwd(), this.baseDir, "globals.nx");
241
+ if (import_fs.default.existsSync(filePath)) {
242
+ return this.decompileFile(filePath);
79
243
  }
80
244
  return null;
81
245
  }
82
246
  /**
83
- * Returns a merged JSON of the entire workspace structure (for dev analytics/inspectors)
247
+ * Returns a merged JSON of the entire workspace structure.
84
248
  */
85
249
  async getAllData() {
86
250
  const pages = {};
87
251
  const collections = {};
88
252
  let globals = {};
89
253
  try {
90
- const pagesDir = _path2.default.resolve(process.cwd(), this.baseDir, "pages");
91
- if (_fs2.default.existsSync(pagesDir)) {
92
- for (const file of _fs2.default.readdirSync(pagesDir)) {
93
- if (file.endsWith(".json")) {
94
- const slug = _path2.default.basename(file, ".json");
254
+ const pagesDir = import_path.default.resolve(process.cwd(), this.baseDir, "pages");
255
+ if (import_fs.default.existsSync(pagesDir)) {
256
+ for (const file of import_fs.default.readdirSync(pagesDir)) {
257
+ if (file.endsWith(".nx")) {
258
+ const slug = import_path.default.basename(file, ".nx");
95
259
  pages[slug] = await this.getPage(slug);
96
260
  }
97
261
  }
98
262
  }
99
- const colsDir = _path2.default.resolve(process.cwd(), this.baseDir, "collections");
100
- if (_fs2.default.existsSync(colsDir)) {
101
- for (const file of _fs2.default.readdirSync(colsDir)) {
102
- if (file.endsWith(".json")) {
103
- const id = _path2.default.basename(file, ".json");
263
+ const colsDir = import_path.default.resolve(process.cwd(), this.baseDir, "collections");
264
+ if (import_fs.default.existsSync(colsDir)) {
265
+ for (const file of import_fs.default.readdirSync(colsDir)) {
266
+ if (file.endsWith(".nx")) {
267
+ const id = import_path.default.basename(file, ".nx");
104
268
  collections[id] = await this.getCollection(id) || [];
105
269
  }
106
270
  }
107
271
  }
108
272
  globals = await this.getGlobals() || {};
109
- } catch (e2) {
273
+ } catch {
110
274
  }
111
275
  return { pages, collections, globals };
112
276
  }
113
277
  };
114
-
115
-
116
- exports.LocalCache = LocalCache;
278
+ // Annotate the CommonJS export names for ESM import in node:
279
+ 0 && (module.exports = {
280
+ LocalCache
281
+ });
@@ -2,22 +2,27 @@ import { I as ILocalCache } from '../cache-types-B39iNHfE.cjs';
2
2
 
3
3
  declare class LocalCache implements ILocalCache {
4
4
  private baseDir;
5
+ private apiKey;
5
6
  constructor(customPath?: string);
6
7
  isLoaded(): boolean;
7
8
  /**
8
- * Retrieve a specific page directly from its file.
9
+ * Helper to decrypt and decompile `.nx` files on-the-fly.
10
+ */
11
+ private decompileFile;
12
+ /**
13
+ * Retrieve a specific page directly from its .nx file.
9
14
  */
10
15
  getPage(slug: string): Promise<any>;
11
16
  /**
12
- * Retrieve an entire collection from its specific collection file.
17
+ * Retrieve an entire collection from its specific .nx file.
13
18
  */
14
19
  getCollection(collectionId: string): Promise<any[] | null>;
15
20
  /**
16
- * Retrieve global settings from its file.
21
+ * Retrieve global settings from its .nx file.
17
22
  */
18
23
  getGlobals(): Promise<any>;
19
24
  /**
20
- * Returns a merged JSON of the entire workspace structure (for dev analytics/inspectors)
25
+ * Returns a merged JSON of the entire workspace structure.
21
26
  */
22
27
  getAllData(): Promise<any>;
23
28
  }
@@ -2,22 +2,27 @@ import { I as ILocalCache } from '../cache-types-B39iNHfE.js';
2
2
 
3
3
  declare class LocalCache implements ILocalCache {
4
4
  private baseDir;
5
+ private apiKey;
5
6
  constructor(customPath?: string);
6
7
  isLoaded(): boolean;
7
8
  /**
8
- * Retrieve a specific page directly from its file.
9
+ * Helper to decrypt and decompile `.nx` files on-the-fly.
10
+ */
11
+ private decompileFile;
12
+ /**
13
+ * Retrieve a specific page directly from its .nx file.
9
14
  */
10
15
  getPage(slug: string): Promise<any>;
11
16
  /**
12
- * Retrieve an entire collection from its specific collection file.
17
+ * Retrieve an entire collection from its specific .nx file.
13
18
  */
14
19
  getCollection(collectionId: string): Promise<any[] | null>;
15
20
  /**
16
- * Retrieve global settings from its file.
21
+ * Retrieve global settings from its .nx file.
17
22
  */
18
23
  getGlobals(): Promise<any>;
19
24
  /**
20
- * Returns a merged JSON of the entire workspace structure (for dev analytics/inspectors)
25
+ * Returns a merged JSON of the entire workspace structure.
21
26
  */
22
27
  getAllData(): Promise<any>;
23
28
  }