@nexushub/client 0.1.3 → 0.1.6

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/index.cjs CHANGED
@@ -988,6 +988,46 @@ var ContentEngine = class {
988
988
  this.browserCache.set(key, data, options.revalidate * 1e3);
989
989
  }
990
990
  }
991
+ // packages/client-sdk/src/content/index.ts
992
+ /**
993
+ * ⚡ THE PULSE: Next.js Cache Revalidation Receiver
994
+ * Used in app/api/nexus-revalidate/route.ts to handle instant updates from the NexusHub backend.
995
+ *
996
+ * @param req The incoming Request object from Next.js
997
+ * @param revalidateFn The revalidateTag function imported from 'next/cache'
998
+ */
999
+ async handleRevalidation(req, revalidateFn) {
1000
+ try {
1001
+ if (!req.body) {
1002
+ return { success: false, message: "Missing Pulse Payload" };
1003
+ }
1004
+ const body = await req.json();
1005
+ const { secret, tag } = body;
1006
+ if (!secret || secret !== this.config.projectId) {
1007
+ if (this.config.debug) {
1008
+ console.warn(`[NexusHub] \u26A0\uFE0F Blocked unauthorized Pulse request.`);
1009
+ }
1010
+ return { success: false, message: "Invalid Pulse Signature" };
1011
+ }
1012
+ const targetTag = tag || "content_all";
1013
+ revalidateFn(targetTag);
1014
+ this.invalidateCache([targetTag]);
1015
+ if (this.config.debug) {
1016
+ console.log(
1017
+ `[NexusHub] \u26A1 Pulse Received: Successfully revalidated tag [${targetTag}]`
1018
+ );
1019
+ }
1020
+ return { success: true, now: Date.now() };
1021
+ } catch (e) {
1022
+ if (this.config.debug) {
1023
+ console.error(`[NexusHub] \u274C Pulse Processing Error:`, e.message);
1024
+ }
1025
+ return {
1026
+ success: false,
1027
+ message: "Malformed Pulse Payload or Processing Error"
1028
+ };
1029
+ }
1030
+ }
991
1031
  /**
992
1032
  * Invalidate cache by tags
993
1033
  */
@@ -1032,7 +1072,9 @@ var ContentEngine = class {
1032
1072
  }
1033
1073
  const res = await this.fetchWithTimeout(url, {
1034
1074
  method: "GET",
1035
- headers: this.getHeaders()
1075
+ headers: this.getHeaders(),
1076
+ tags,
1077
+ revalidate
1036
1078
  });
1037
1079
  if (!res.ok) {
1038
1080
  if (res.status === 404) {
@@ -1071,7 +1113,9 @@ var ContentEngine = class {
1071
1113
  }
1072
1114
  const res = await this.fetchWithTimeout(url, {
1073
1115
  method: "GET",
1074
- headers: this.getHeaders()
1116
+ headers: this.getHeaders(),
1117
+ tags,
1118
+ revalidate
1075
1119
  });
1076
1120
  if (!res.ok) {
1077
1121
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
@@ -1144,12 +1188,20 @@ var ContentEngine = class {
1144
1188
  };
1145
1189
  }
1146
1190
  async fetchWithTimeout(url, options = {}) {
1147
- const { timeout = this.config.timeout || 1e4, ...fetchOptions } = options;
1191
+ const {
1192
+ timeout = this.config.timeout || 1e4,
1193
+ tags = [],
1194
+ revalidate,
1195
+ ...fetchOptions
1196
+ } = options;
1148
1197
  const controller = new AbortController();
1149
1198
  const id = setTimeout(() => controller.abort(), timeout);
1199
+ const nextConfig = this.isServer ? { next: { tags, revalidate } } : {};
1150
1200
  try {
1151
1201
  const response = await fetch(url, {
1152
1202
  ...fetchOptions,
1203
+ ...nextConfig,
1204
+ // Inject Next.js tags
1153
1205
  signal: controller.signal
1154
1206
  });
1155
1207
  clearTimeout(id);
@@ -1336,7 +1388,7 @@ var initVitals = (tracker) => {
1336
1388
  // src/analytics/storage.ts
1337
1389
  var DB_NAME = "NexusHub_Analytics";
1338
1390
  var STORE_NAME = "events_queue";
1339
- var DB_VERSION = 1;
1391
+ var DB_VERSION = 2;
1340
1392
  var EventStorage = class {
1341
1393
  constructor() {
1342
1394
  this.db = null;
@@ -1349,7 +1401,9 @@ var EventStorage = class {
1349
1401
  return new Promise((resolve, reject) => {
1350
1402
  const request = indexedDB.open(DB_NAME, DB_VERSION);
1351
1403
  request.onerror = () => {
1352
- console.warn("[NexusHub] Failed to open IndexedDB. Falling back to memory.");
1404
+ console.warn(
1405
+ "[NexusHub] Failed to open IndexedDB. Falling back to memory."
1406
+ );
1353
1407
  resolve();
1354
1408
  };
1355
1409
  request.onsuccess = (event) => {
@@ -1358,9 +1412,13 @@ var EventStorage = class {
1358
1412
  };
1359
1413
  request.onupgradeneeded = (event) => {
1360
1414
  const db = event.target.result;
1361
- if (!db.objectStoreNames.contains(STORE_NAME)) {
1362
- db.createObjectStore(STORE_NAME, { keyPath: "id", autoIncrement: true });
1415
+ if (db.objectStoreNames.contains(STORE_NAME)) {
1416
+ db.deleteObjectStore(STORE_NAME);
1363
1417
  }
1418
+ db.createObjectStore(STORE_NAME, {
1419
+ keyPath: "id",
1420
+ autoIncrement: true
1421
+ });
1364
1422
  };
1365
1423
  });
1366
1424
  }
package/dist/index.d.cts CHANGED
@@ -156,6 +156,18 @@ declare class ContentEngine {
156
156
  */
157
157
  private checkCaches;
158
158
  private writeCache;
159
+ /**
160
+ * ⚡ THE PULSE: Next.js Cache Revalidation Receiver
161
+ * Used in app/api/nexus-revalidate/route.ts to handle instant updates from the NexusHub backend.
162
+ *
163
+ * @param req The incoming Request object from Next.js
164
+ * @param revalidateFn The revalidateTag function imported from 'next/cache'
165
+ */
166
+ handleRevalidation(req: Request, revalidateFn: (tag: string) => void): Promise<{
167
+ success: boolean;
168
+ message?: string;
169
+ now?: number;
170
+ }>;
159
171
  /**
160
172
  * Invalidate cache by tags
161
173
  */
package/dist/index.d.ts CHANGED
@@ -156,6 +156,18 @@ declare class ContentEngine {
156
156
  */
157
157
  private checkCaches;
158
158
  private writeCache;
159
+ /**
160
+ * ⚡ THE PULSE: Next.js Cache Revalidation Receiver
161
+ * Used in app/api/nexus-revalidate/route.ts to handle instant updates from the NexusHub backend.
162
+ *
163
+ * @param req The incoming Request object from Next.js
164
+ * @param revalidateFn The revalidateTag function imported from 'next/cache'
165
+ */
166
+ handleRevalidation(req: Request, revalidateFn: (tag: string) => void): Promise<{
167
+ success: boolean;
168
+ message?: string;
169
+ now?: number;
170
+ }>;
159
171
  /**
160
172
  * Invalidate cache by tags
161
173
  */
package/dist/index.js CHANGED
@@ -988,6 +988,46 @@ var ContentEngine = class {
988
988
  this.browserCache.set(key, data, options.revalidate * 1e3);
989
989
  }
990
990
  }
991
+ // packages/client-sdk/src/content/index.ts
992
+ /**
993
+ * ⚡ THE PULSE: Next.js Cache Revalidation Receiver
994
+ * Used in app/api/nexus-revalidate/route.ts to handle instant updates from the NexusHub backend.
995
+ *
996
+ * @param req The incoming Request object from Next.js
997
+ * @param revalidateFn The revalidateTag function imported from 'next/cache'
998
+ */
999
+ async handleRevalidation(req, revalidateFn) {
1000
+ try {
1001
+ if (!req.body) {
1002
+ return { success: false, message: "Missing Pulse Payload" };
1003
+ }
1004
+ const body = await req.json();
1005
+ const { secret, tag } = body;
1006
+ if (!secret || secret !== this.config.projectId) {
1007
+ if (this.config.debug) {
1008
+ console.warn(`[NexusHub] \u26A0\uFE0F Blocked unauthorized Pulse request.`);
1009
+ }
1010
+ return { success: false, message: "Invalid Pulse Signature" };
1011
+ }
1012
+ const targetTag = tag || "content_all";
1013
+ revalidateFn(targetTag);
1014
+ this.invalidateCache([targetTag]);
1015
+ if (this.config.debug) {
1016
+ console.log(
1017
+ `[NexusHub] \u26A1 Pulse Received: Successfully revalidated tag [${targetTag}]`
1018
+ );
1019
+ }
1020
+ return { success: true, now: Date.now() };
1021
+ } catch (e) {
1022
+ if (this.config.debug) {
1023
+ console.error(`[NexusHub] \u274C Pulse Processing Error:`, e.message);
1024
+ }
1025
+ return {
1026
+ success: false,
1027
+ message: "Malformed Pulse Payload or Processing Error"
1028
+ };
1029
+ }
1030
+ }
991
1031
  /**
992
1032
  * Invalidate cache by tags
993
1033
  */
@@ -1032,7 +1072,9 @@ var ContentEngine = class {
1032
1072
  }
1033
1073
  const res = await this.fetchWithTimeout(url, {
1034
1074
  method: "GET",
1035
- headers: this.getHeaders()
1075
+ headers: this.getHeaders(),
1076
+ tags,
1077
+ revalidate
1036
1078
  });
1037
1079
  if (!res.ok) {
1038
1080
  if (res.status === 404) {
@@ -1071,7 +1113,9 @@ var ContentEngine = class {
1071
1113
  }
1072
1114
  const res = await this.fetchWithTimeout(url, {
1073
1115
  method: "GET",
1074
- headers: this.getHeaders()
1116
+ headers: this.getHeaders(),
1117
+ tags,
1118
+ revalidate
1075
1119
  });
1076
1120
  if (!res.ok) {
1077
1121
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
@@ -1144,12 +1188,20 @@ var ContentEngine = class {
1144
1188
  };
1145
1189
  }
1146
1190
  async fetchWithTimeout(url, options = {}) {
1147
- const { timeout = this.config.timeout || 1e4, ...fetchOptions } = options;
1191
+ const {
1192
+ timeout = this.config.timeout || 1e4,
1193
+ tags = [],
1194
+ revalidate,
1195
+ ...fetchOptions
1196
+ } = options;
1148
1197
  const controller = new AbortController();
1149
1198
  const id = setTimeout(() => controller.abort(), timeout);
1199
+ const nextConfig = this.isServer ? { next: { tags, revalidate } } : {};
1150
1200
  try {
1151
1201
  const response = await fetch(url, {
1152
1202
  ...fetchOptions,
1203
+ ...nextConfig,
1204
+ // Inject Next.js tags
1153
1205
  signal: controller.signal
1154
1206
  });
1155
1207
  clearTimeout(id);
@@ -1336,7 +1388,7 @@ var initVitals = (tracker) => {
1336
1388
  // src/analytics/storage.ts
1337
1389
  var DB_NAME = "NexusHub_Analytics";
1338
1390
  var STORE_NAME = "events_queue";
1339
- var DB_VERSION = 1;
1391
+ var DB_VERSION = 2;
1340
1392
  var EventStorage = class {
1341
1393
  constructor() {
1342
1394
  this.db = null;
@@ -1349,7 +1401,9 @@ var EventStorage = class {
1349
1401
  return new Promise((resolve, reject) => {
1350
1402
  const request = indexedDB.open(DB_NAME, DB_VERSION);
1351
1403
  request.onerror = () => {
1352
- console.warn("[NexusHub] Failed to open IndexedDB. Falling back to memory.");
1404
+ console.warn(
1405
+ "[NexusHub] Failed to open IndexedDB. Falling back to memory."
1406
+ );
1353
1407
  resolve();
1354
1408
  };
1355
1409
  request.onsuccess = (event) => {
@@ -1358,9 +1412,13 @@ var EventStorage = class {
1358
1412
  };
1359
1413
  request.onupgradeneeded = (event) => {
1360
1414
  const db = event.target.result;
1361
- if (!db.objectStoreNames.contains(STORE_NAME)) {
1362
- db.createObjectStore(STORE_NAME, { keyPath: "id", autoIncrement: true });
1415
+ if (db.objectStoreNames.contains(STORE_NAME)) {
1416
+ db.deleteObjectStore(STORE_NAME);
1363
1417
  }
1418
+ db.createObjectStore(STORE_NAME, {
1419
+ keyPath: "id",
1420
+ autoIncrement: true
1421
+ });
1364
1422
  };
1365
1423
  });
1366
1424
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nexushub/client",
3
3
  "private": false,
4
- "version": "0.1.3",
4
+ "version": "0.1.6",
5
5
  "description": "The God-Tier NexusHub SDK",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",