@nexushub/client 0.8.9 → 1.1.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.
@@ -37,23 +37,27 @@ var import_fs = __toESM(require("fs"), 1);
37
37
  var import_path = __toESM(require("path"), 1);
38
38
 
39
39
  // src/config.ts
40
- var DEFAULT_API_URL = "https://gnapex.gnexus.co.tz";
41
- var DEFAULT_ANALYTICS_URL = "https://sentry.gnexus.co.tz";
42
- var LOCAL_NEST_URL = "https://gnapex.gnexus.co.tz";
43
- var LOCAL_RUST_URL = "https://sentry.gnexus.co.tz";
40
+ var DEFAULT_API_URL = "https://api.gnapex.com";
41
+ var DEFAULT_ANALYTICS_URL = "https://sentry.gnapex.com";
42
+ var LOCAL_NEST_URL = "https://api.gnapex.com";
43
+ var LOCAL_RUST_URL = "https://sentry.gnapex.com";
44
44
  var getEnvConfig = () => {
45
45
  const NEXT_PUBLIC_ID = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_ID : void 0;
46
46
  const NEXT_PUBLIC_KEY = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_KEY : void 0;
47
47
  const NEXT_PUBLIC_URL = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_API_URL : void 0;
48
+ const NEXT_PUBLIC_ANALYTICS_URL = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_ANALYTICS_URL : void 0;
48
49
  const NODE_ID = typeof process !== "undefined" ? process.env.NEXUS_PROJECT_ID : void 0;
49
50
  const NODE_KEY = typeof process !== "undefined" ? process.env.NEXUS_API_KEY : void 0;
50
51
  const NODE_URL = typeof process !== "undefined" ? process.env.NEXUS_API_URL : void 0;
52
+ const NODE_ANALYTICS_URL = typeof process !== "undefined" ? process.env.NEXUS_ANALYTICS_URL : void 0;
51
53
  const NODE_ENV = typeof process !== "undefined" ? process.env.NODE_ENV : "production";
52
54
  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;
55
+ const runtime = typeof window !== "undefined" ? window.__GNAPEX__ ?? window.__NEXUS__ : void 0;
56
+ const meta = typeof document !== "undefined" ? (name) => document.querySelector(`meta[name="${name}"]`)?.getAttribute("content") ?? void 0 : (_name) => void 0;
57
+ const projectId = runtime?.projectId ?? meta("gnapex-project") ?? meta("nexus-project") ?? NEXT_PUBLIC_ID ?? NODE_ID;
58
+ const apiKey = runtime?.apiKey ?? meta("gnapex-key") ?? meta("nexus-key") ?? NEXT_PUBLIC_KEY ?? NODE_KEY;
59
+ const apiUrl = runtime?.apiUrl ?? meta("gnapex-api") ?? meta("nexus-api") ?? NEXT_PUBLIC_URL ?? NODE_URL ?? (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL);
60
+ const analyticsUrl = runtime?.analyticsUrl ?? meta("gnapex-analytics") ?? meta("nexus-analytics") ?? NEXT_PUBLIC_ANALYTICS_URL ?? NODE_ANALYTICS_URL ?? (apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL);
57
61
  return {
58
62
  projectId,
59
63
  apiKey,
@@ -160,6 +164,16 @@ BinaryCompiler.MAGIC_HEADER = "NEXS";
160
164
  // 4-byte ASCII magic identifier
161
165
  BinaryCompiler.ALGORITHM = "aes-256-cbc";
162
166
 
167
+ // src/content/utils.ts
168
+ function validateSlug(slug) {
169
+ if (!slug || typeof slug !== "string") {
170
+ throw new Error("Slug must be a non-empty string");
171
+ }
172
+ if (!/^[a-z0-9-_]+$/.test(slug)) {
173
+ throw new Error("Slug can only contain lowercase letters, numbers, hyphens, and underscores");
174
+ }
175
+ }
176
+
163
177
  // src/content/local-cache-server.ts
164
178
  var LocalCache = class {
165
179
  constructor(customPath, apiKey) {
@@ -171,9 +185,6 @@ var LocalCache = class {
171
185
  isLoaded() {
172
186
  return import_fs.default.existsSync(import_path.default.resolve(process.cwd(), this.baseDir));
173
187
  }
174
- /**
175
- * Helper to decrypt and decompile `.nx` files on-the-fly.
176
- */
177
188
  decompileFile(filePath) {
178
189
  if (!this.apiKey) {
179
190
  if (process.env.NODE_ENV === "development") {
@@ -202,9 +213,14 @@ var LocalCache = class {
202
213
  }
203
214
  }
204
215
  /**
205
- * Retrieve a specific page directly from its .nx file.
216
+ * Retrieve a specific page safely from its .nx file.
206
217
  */
207
218
  async getPage(slug) {
219
+ try {
220
+ validateSlug(slug);
221
+ } catch {
222
+ return null;
223
+ }
208
224
  const filePath = import_path.default.resolve(
209
225
  process.cwd(),
210
226
  this.baseDir,
@@ -223,9 +239,14 @@ var LocalCache = class {
223
239
  return null;
224
240
  }
225
241
  /**
226
- * Retrieve an entire collection from its specific .nx file.
242
+ * Retrieve an entire collection safely from its specific .nx file.
227
243
  */
228
244
  async getCollection(collectionId) {
245
+ try {
246
+ validateSlug(collectionId);
247
+ } catch {
248
+ return null;
249
+ }
229
250
  const filePath = import_path.default.resolve(
230
251
  process.cwd(),
231
252
  this.baseDir,
@@ -5,16 +5,13 @@ declare class LocalCache implements ILocalCache {
5
5
  private apiKey;
6
6
  constructor(customPath?: string, apiKey?: string);
7
7
  isLoaded(): boolean;
8
- /**
9
- * Helper to decrypt and decompile `.nx` files on-the-fly.
10
- */
11
8
  private decompileFile;
12
9
  /**
13
- * Retrieve a specific page directly from its .nx file.
10
+ * Retrieve a specific page safely from its .nx file.
14
11
  */
15
12
  getPage(slug: string): Promise<any>;
16
13
  /**
17
- * Retrieve an entire collection from its specific .nx file.
14
+ * Retrieve an entire collection safely from its specific .nx file.
18
15
  */
19
16
  getCollection(collectionId: string): Promise<any[] | null>;
20
17
  /**
@@ -5,16 +5,13 @@ declare class LocalCache implements ILocalCache {
5
5
  private apiKey;
6
6
  constructor(customPath?: string, apiKey?: string);
7
7
  isLoaded(): boolean;
8
- /**
9
- * Helper to decrypt and decompile `.nx` files on-the-fly.
10
- */
11
8
  private decompileFile;
12
9
  /**
13
- * Retrieve a specific page directly from its .nx file.
10
+ * Retrieve a specific page safely from its .nx file.
14
11
  */
15
12
  getPage(slug: string): Promise<any>;
16
13
  /**
17
- * Retrieve an entire collection from its specific .nx file.
14
+ * Retrieve an entire collection safely from its specific .nx file.
18
15
  */
19
16
  getCollection(collectionId: string): Promise<any[] | null>;
20
17
  /**
@@ -3,23 +3,27 @@ import fs from "fs";
3
3
  import path from "path";
4
4
 
5
5
  // src/config.ts
6
- var DEFAULT_API_URL = "https://gnapex.gnexus.co.tz";
7
- var DEFAULT_ANALYTICS_URL = "https://sentry.gnexus.co.tz";
8
- var LOCAL_NEST_URL = "https://gnapex.gnexus.co.tz";
9
- var LOCAL_RUST_URL = "https://sentry.gnexus.co.tz";
6
+ var DEFAULT_API_URL = "https://api.gnapex.com";
7
+ var DEFAULT_ANALYTICS_URL = "https://sentry.gnapex.com";
8
+ var LOCAL_NEST_URL = "https://api.gnapex.com";
9
+ var LOCAL_RUST_URL = "https://sentry.gnapex.com";
10
10
  var getEnvConfig = () => {
11
11
  const NEXT_PUBLIC_ID = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_ID : void 0;
12
12
  const NEXT_PUBLIC_KEY = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_KEY : void 0;
13
13
  const NEXT_PUBLIC_URL = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_API_URL : void 0;
14
+ const NEXT_PUBLIC_ANALYTICS_URL = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_NEXUS_ANALYTICS_URL : void 0;
14
15
  const NODE_ID = typeof process !== "undefined" ? process.env.NEXUS_PROJECT_ID : void 0;
15
16
  const NODE_KEY = typeof process !== "undefined" ? process.env.NEXUS_API_KEY : void 0;
16
17
  const NODE_URL = typeof process !== "undefined" ? process.env.NEXUS_API_URL : void 0;
18
+ const NODE_ANALYTICS_URL = typeof process !== "undefined" ? process.env.NEXUS_ANALYTICS_URL : void 0;
17
19
  const NODE_ENV = typeof process !== "undefined" ? process.env.NODE_ENV : "production";
18
20
  const isDev = NODE_ENV === "development" || typeof window !== "undefined" && window.location.hostname === "localhost";
19
- const projectId = NEXT_PUBLIC_ID ?? NODE_ID;
20
- const apiKey = NEXT_PUBLIC_KEY ?? NODE_KEY;
21
- const apiUrl = NEXT_PUBLIC_URL ?? NODE_URL ?? (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL);
22
- const analyticsUrl = apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL;
21
+ const runtime = typeof window !== "undefined" ? window.__GNAPEX__ ?? window.__NEXUS__ : void 0;
22
+ const meta = typeof document !== "undefined" ? (name) => document.querySelector(`meta[name="${name}"]`)?.getAttribute("content") ?? void 0 : (_name) => void 0;
23
+ const projectId = runtime?.projectId ?? meta("gnapex-project") ?? meta("nexus-project") ?? NEXT_PUBLIC_ID ?? NODE_ID;
24
+ const apiKey = runtime?.apiKey ?? meta("gnapex-key") ?? meta("nexus-key") ?? NEXT_PUBLIC_KEY ?? NODE_KEY;
25
+ const apiUrl = runtime?.apiUrl ?? meta("gnapex-api") ?? meta("nexus-api") ?? NEXT_PUBLIC_URL ?? NODE_URL ?? (isDev ? LOCAL_NEST_URL : DEFAULT_API_URL);
26
+ const analyticsUrl = runtime?.analyticsUrl ?? meta("gnapex-analytics") ?? meta("nexus-analytics") ?? NEXT_PUBLIC_ANALYTICS_URL ?? NODE_ANALYTICS_URL ?? (apiUrl.includes("localhost") ? LOCAL_RUST_URL : DEFAULT_ANALYTICS_URL);
23
27
  return {
24
28
  projectId,
25
29
  apiKey,
@@ -126,6 +130,16 @@ BinaryCompiler.MAGIC_HEADER = "NEXS";
126
130
  // 4-byte ASCII magic identifier
127
131
  BinaryCompiler.ALGORITHM = "aes-256-cbc";
128
132
 
133
+ // src/content/utils.ts
134
+ function validateSlug(slug) {
135
+ if (!slug || typeof slug !== "string") {
136
+ throw new Error("Slug must be a non-empty string");
137
+ }
138
+ if (!/^[a-z0-9-_]+$/.test(slug)) {
139
+ throw new Error("Slug can only contain lowercase letters, numbers, hyphens, and underscores");
140
+ }
141
+ }
142
+
129
143
  // src/content/local-cache-server.ts
130
144
  var LocalCache = class {
131
145
  constructor(customPath, apiKey) {
@@ -137,9 +151,6 @@ var LocalCache = class {
137
151
  isLoaded() {
138
152
  return fs.existsSync(path.resolve(process.cwd(), this.baseDir));
139
153
  }
140
- /**
141
- * Helper to decrypt and decompile `.nx` files on-the-fly.
142
- */
143
154
  decompileFile(filePath) {
144
155
  if (!this.apiKey) {
145
156
  if (process.env.NODE_ENV === "development") {
@@ -168,9 +179,14 @@ var LocalCache = class {
168
179
  }
169
180
  }
170
181
  /**
171
- * Retrieve a specific page directly from its .nx file.
182
+ * Retrieve a specific page safely from its .nx file.
172
183
  */
173
184
  async getPage(slug) {
185
+ try {
186
+ validateSlug(slug);
187
+ } catch {
188
+ return null;
189
+ }
174
190
  const filePath = path.resolve(
175
191
  process.cwd(),
176
192
  this.baseDir,
@@ -189,9 +205,14 @@ var LocalCache = class {
189
205
  return null;
190
206
  }
191
207
  /**
192
- * Retrieve an entire collection from its specific .nx file.
208
+ * Retrieve an entire collection safely from its specific .nx file.
193
209
  */
194
210
  async getCollection(collectionId) {
211
+ try {
212
+ validateSlug(collectionId);
213
+ } catch {
214
+ return null;
215
+ }
195
216
  const filePath = path.resolve(
196
217
  process.cwd(),
197
218
  this.baseDir,