@nexushub/client 0.7.6 → 0.7.8

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
@@ -1048,7 +1048,7 @@ var ContentEngine = class {
1048
1048
  }
1049
1049
  return includeMetadata ? cached : cached.data;
1050
1050
  }
1051
- if (!forceRefresh) {
1051
+ if (!forceRefresh && process.env.NODE_ENV === "development") {
1052
1052
  try {
1053
1053
  const localCollection = await this.localCache.getCollection(collectionId);
1054
1054
  if (localCollection) {
@@ -1123,7 +1123,7 @@ var ContentEngine = class {
1123
1123
  return cached;
1124
1124
  }
1125
1125
  }
1126
- if (!forceRefresh) {
1126
+ if (!forceRefresh && process.env.NODE_ENV === "development") {
1127
1127
  try {
1128
1128
  const localGlobals = await this.localCache.getGlobals();
1129
1129
  if (localGlobals) {
@@ -1140,9 +1140,16 @@ var ContentEngine = class {
1140
1140
  await this.rateLimiter.checkLimit();
1141
1141
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/globals`;
1142
1142
  const params = include.length > 0 ? `?include=${include.join(",")}` : "";
1143
+ const fetchTags = [
1144
+ CacheTags.project(this.config.projectId),
1145
+ CacheTags.global,
1146
+ ...options.tags || []
1147
+ ];
1143
1148
  const res = await this.fetchWithTimeout(`${url}${params}`, {
1144
1149
  method: "GET",
1145
- headers: this.getHeaders()
1150
+ headers: this.getHeaders(),
1151
+ tags: fetchTags,
1152
+ revalidate
1146
1153
  });
1147
1154
  if (!res.ok) {
1148
1155
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
@@ -1183,9 +1190,17 @@ var ContentEngine = class {
1183
1190
  params.append("include", options.include.join(","));
1184
1191
  }
1185
1192
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}/${itemId}?${params}`;
1193
+ const fetchTags = [
1194
+ CacheTags.project(this.config.projectId),
1195
+ CacheTags.collection(collectionId),
1196
+ `item_${itemId}`,
1197
+ ...options.tags || []
1198
+ ];
1186
1199
  const res = await this.fetchWithTimeout(url, {
1187
1200
  method: "GET",
1188
- headers: this.getHeaders()
1201
+ headers: this.getHeaders(),
1202
+ tags: fetchTags,
1203
+ revalidate: options.revalidate || this.defaultRevalidate
1189
1204
  });
1190
1205
  if (!res.ok) {
1191
1206
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
@@ -1194,12 +1209,7 @@ var ContentEngine = class {
1194
1209
  const data = json.data || json;
1195
1210
  this.writeCache(cacheKey, data, {
1196
1211
  revalidate: options.revalidate || this.defaultRevalidate,
1197
- tags: [
1198
- CacheTags.project(this.config.projectId),
1199
- CacheTags.collection(collectionId),
1200
- `item_${itemId}`,
1201
- ...options.tags || []
1202
- ]
1212
+ tags: fetchTags
1203
1213
  });
1204
1214
  return data;
1205
1215
  });
@@ -1293,9 +1303,6 @@ var ContentEngine = class {
1293
1303
  };
1294
1304
  }
1295
1305
  // --- CACHE MANAGEMENT ---
1296
- /**
1297
- * Check all caches in order of speed
1298
- */
1299
1306
  async checkCaches(key, forceRefresh, includeMetadata) {
1300
1307
  if (forceRefresh) return null;
1301
1308
  if (this.cacheStrategy === "memory") {
@@ -1318,22 +1325,24 @@ var ContentEngine = class {
1318
1325
  };
1319
1326
  }
1320
1327
  }
1321
- if (key.startsWith("page:")) {
1322
- const slug = key.split(":")[1];
1323
- try {
1324
- const local = await this.localCache.getPage(slug);
1325
- if (local) {
1326
- return {
1327
- data: local,
1328
- metadata: {
1329
- timestamp: Date.now(),
1330
- expiresAt: Infinity,
1331
- tags: [],
1332
- etag: void 0
1333
- }
1334
- };
1328
+ if (process.env.NODE_ENV === "development") {
1329
+ if (key.startsWith("page:")) {
1330
+ const slug = key.split(":")[1];
1331
+ try {
1332
+ const local = await this.localCache.getPage(slug);
1333
+ if (local) {
1334
+ return {
1335
+ data: local,
1336
+ metadata: {
1337
+ timestamp: Date.now(),
1338
+ expiresAt: Infinity,
1339
+ tags: [],
1340
+ etag: void 0
1341
+ }
1342
+ };
1343
+ }
1344
+ } catch {
1335
1345
  }
1336
- } catch {
1337
1346
  }
1338
1347
  }
1339
1348
  return null;
@@ -1350,9 +1359,6 @@ var ContentEngine = class {
1350
1359
  this.browserCache.set(key, data, numericRevalidate * 1e3);
1351
1360
  }
1352
1361
  }
1353
- /**
1354
- * Invalidate cache by tags
1355
- */
1356
1362
  invalidateCache(tags) {
1357
1363
  this.memoryCache.invalidateByTags(tags);
1358
1364
  if (this.config.debug) {
@@ -1361,9 +1367,6 @@ var ContentEngine = class {
1361
1367
  );
1362
1368
  }
1363
1369
  }
1364
- /**
1365
- * Clear all caches
1366
- */
1367
1370
  clearCache() {
1368
1371
  this.memoryCache.clear();
1369
1372
  if (this.browserCache) {
@@ -1373,9 +1376,6 @@ var ContentEngine = class {
1373
1376
  console.log("[NexusHub] \u{1F9F9} Cleared all caches");
1374
1377
  }
1375
1378
  }
1376
- /**
1377
- * Get cache statistics
1378
- */
1379
1379
  getCacheStats() {
1380
1380
  const stats = {
1381
1381
  memory: this.memoryCache.getStats(),
@@ -1389,14 +1389,16 @@ var ContentEngine = class {
1389
1389
  // --- REQUEST METHODS ---
1390
1390
  async fetchPage(slug, cacheKey, tags, revalidate, forceRefresh) {
1391
1391
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/page/${slug}`;
1392
- if (this.config.debug) {
1393
- console.log(`[NexusHub] \u{1F310} Fetching: ${url}`);
1394
- }
1395
1392
  const expiresAt = revalidate === false ? Infinity : Date.now() + revalidate * 1e3;
1393
+ const fetchTags = [
1394
+ CacheTags.project(this.config.projectId),
1395
+ CacheTags.content(slug),
1396
+ ...tags
1397
+ ];
1396
1398
  const res = await this.fetchWithTimeout(url, {
1397
1399
  method: "GET",
1398
1400
  headers: this.getHeaders(),
1399
- tags,
1401
+ tags: fetchTags,
1400
1402
  revalidate
1401
1403
  });
1402
1404
  if (!res.ok) {
@@ -1415,29 +1417,27 @@ var ContentEngine = class {
1415
1417
  timestamp: Date.now(),
1416
1418
  etag: etag || void 0,
1417
1419
  expiresAt,
1418
- tags: [...tags, CacheTags.content(slug)]
1420
+ tags: fetchTags
1419
1421
  }
1420
1422
  };
1421
1423
  this.writeCache(cacheKey, cacheEntry.data, {
1422
1424
  revalidate,
1423
- tags: [
1424
- CacheTags.project(this.config.projectId),
1425
- CacheTags.content(slug),
1426
- ...tags
1427
- ]
1425
+ tags: fetchTags
1428
1426
  });
1429
1427
  return cacheEntry;
1430
1428
  }
1431
1429
  async fetchCollection(collectionId, query, cacheKey, tags, revalidate) {
1432
1430
  const params = buildQueryString(query);
1433
1431
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}?${params}`;
1434
- if (this.config.debug) {
1435
- console.log(`[NexusHub] \u{1F310} Fetching Collection: ${url}`);
1436
- }
1432
+ const fetchTags = [
1433
+ CacheTags.project(this.config.projectId),
1434
+ CacheTags.collection(collectionId),
1435
+ ...tags
1436
+ ];
1437
1437
  const res = await this.fetchWithTimeout(url, {
1438
1438
  method: "GET",
1439
1439
  headers: this.getHeaders(),
1440
- tags,
1440
+ tags: fetchTags,
1441
1441
  revalidate
1442
1442
  });
1443
1443
  if (!res.ok) {
@@ -1452,16 +1452,12 @@ var ContentEngine = class {
1452
1452
  timestamp: Date.now(),
1453
1453
  etag: etag || void 0,
1454
1454
  expiresAt,
1455
- tags: [...tags, CacheTags.collection(collectionId)]
1455
+ tags: fetchTags
1456
1456
  }
1457
1457
  };
1458
1458
  this.writeCache(cacheKey, cacheEntry.data, {
1459
1459
  revalidate,
1460
- tags: [
1461
- CacheTags.project(this.config.projectId),
1462
- CacheTags.collection(collectionId),
1463
- ...tags
1464
- ]
1460
+ tags: fetchTags
1465
1461
  });
1466
1462
  return cacheEntry;
1467
1463
  }
@@ -1517,15 +1513,18 @@ var ContentEngine = class {
1517
1513
  tags = [],
1518
1514
  revalidate,
1519
1515
  ...fetchOptions
1520
- // 🚀 RESOLVED: Destructure with safe default to prevent undefined spreads
1521
1516
  } = options;
1522
1517
  const controller = new AbortController();
1523
1518
  const id = setTimeout(() => controller.abort(), timeout);
1524
- const nextConfig = this.isServer ? { next: { tags, revalidate } } : {};
1519
+ const nextConfig = this.isServer ? {
1520
+ cache: "force-cache",
1521
+ next: { tags, revalidate: revalidate === false ? false : revalidate }
1522
+ } : {};
1525
1523
  try {
1526
1524
  const response = await fetch(url, {
1527
1525
  ...fetchOptions,
1528
1526
  ...nextConfig,
1527
+ // Inject Next.js tags
1529
1528
  signal: controller.signal
1530
1529
  });
1531
1530
  clearTimeout(id);
package/dist/index.d.cts CHANGED
@@ -119,6 +119,7 @@ declare class ContentEngine {
119
119
  include?: string[];
120
120
  revalidate?: number | false;
121
121
  forceRefresh?: boolean;
122
+ tags?: string[];
122
123
  }): Promise<T>;
123
124
  /**
124
125
  * Get a single item from a collection (Uses Request Batching)
@@ -148,22 +149,10 @@ declare class ContentEngine {
148
149
  * Robust Real-time Subscriptions (SSE) with Auto-Reconnect
149
150
  */
150
151
  subscribeToUpdates(callback: (data: any) => void): () => void;
151
- /**
152
- * Check all caches in order of speed
153
- */
154
152
  private checkCaches;
155
153
  private writeCache;
156
- /**
157
- * Invalidate cache by tags
158
- */
159
154
  invalidateCache(tags: string[]): void;
160
- /**
161
- * Clear all caches
162
- */
163
155
  clearCache(): void;
164
- /**
165
- * Get cache statistics
166
- */
167
156
  getCacheStats(): {
168
157
  memory: {
169
158
  size: number;
package/dist/index.d.ts CHANGED
@@ -119,6 +119,7 @@ declare class ContentEngine {
119
119
  include?: string[];
120
120
  revalidate?: number | false;
121
121
  forceRefresh?: boolean;
122
+ tags?: string[];
122
123
  }): Promise<T>;
123
124
  /**
124
125
  * Get a single item from a collection (Uses Request Batching)
@@ -148,22 +149,10 @@ declare class ContentEngine {
148
149
  * Robust Real-time Subscriptions (SSE) with Auto-Reconnect
149
150
  */
150
151
  subscribeToUpdates(callback: (data: any) => void): () => void;
151
- /**
152
- * Check all caches in order of speed
153
- */
154
152
  private checkCaches;
155
153
  private writeCache;
156
- /**
157
- * Invalidate cache by tags
158
- */
159
154
  invalidateCache(tags: string[]): void;
160
- /**
161
- * Clear all caches
162
- */
163
155
  clearCache(): void;
164
- /**
165
- * Get cache statistics
166
- */
167
156
  getCacheStats(): {
168
157
  memory: {
169
158
  size: number;
package/dist/index.js CHANGED
@@ -1002,7 +1002,7 @@ var ContentEngine = class {
1002
1002
  }
1003
1003
  return includeMetadata ? cached : cached.data;
1004
1004
  }
1005
- if (!forceRefresh) {
1005
+ if (!forceRefresh && process.env.NODE_ENV === "development") {
1006
1006
  try {
1007
1007
  const localCollection = await this.localCache.getCollection(collectionId);
1008
1008
  if (localCollection) {
@@ -1077,7 +1077,7 @@ var ContentEngine = class {
1077
1077
  return cached;
1078
1078
  }
1079
1079
  }
1080
- if (!forceRefresh) {
1080
+ if (!forceRefresh && process.env.NODE_ENV === "development") {
1081
1081
  try {
1082
1082
  const localGlobals = await this.localCache.getGlobals();
1083
1083
  if (localGlobals) {
@@ -1094,9 +1094,16 @@ var ContentEngine = class {
1094
1094
  await this.rateLimiter.checkLimit();
1095
1095
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/globals`;
1096
1096
  const params = include.length > 0 ? `?include=${include.join(",")}` : "";
1097
+ const fetchTags = [
1098
+ CacheTags.project(this.config.projectId),
1099
+ CacheTags.global,
1100
+ ...options.tags || []
1101
+ ];
1097
1102
  const res = await this.fetchWithTimeout(`${url}${params}`, {
1098
1103
  method: "GET",
1099
- headers: this.getHeaders()
1104
+ headers: this.getHeaders(),
1105
+ tags: fetchTags,
1106
+ revalidate
1100
1107
  });
1101
1108
  if (!res.ok) {
1102
1109
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
@@ -1137,9 +1144,17 @@ var ContentEngine = class {
1137
1144
  params.append("include", options.include.join(","));
1138
1145
  }
1139
1146
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}/${itemId}?${params}`;
1147
+ const fetchTags = [
1148
+ CacheTags.project(this.config.projectId),
1149
+ CacheTags.collection(collectionId),
1150
+ `item_${itemId}`,
1151
+ ...options.tags || []
1152
+ ];
1140
1153
  const res = await this.fetchWithTimeout(url, {
1141
1154
  method: "GET",
1142
- headers: this.getHeaders()
1155
+ headers: this.getHeaders(),
1156
+ tags: fetchTags,
1157
+ revalidate: options.revalidate || this.defaultRevalidate
1143
1158
  });
1144
1159
  if (!res.ok) {
1145
1160
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
@@ -1148,12 +1163,7 @@ var ContentEngine = class {
1148
1163
  const data = json.data || json;
1149
1164
  this.writeCache(cacheKey, data, {
1150
1165
  revalidate: options.revalidate || this.defaultRevalidate,
1151
- tags: [
1152
- CacheTags.project(this.config.projectId),
1153
- CacheTags.collection(collectionId),
1154
- `item_${itemId}`,
1155
- ...options.tags || []
1156
- ]
1166
+ tags: fetchTags
1157
1167
  });
1158
1168
  return data;
1159
1169
  });
@@ -1247,9 +1257,6 @@ var ContentEngine = class {
1247
1257
  };
1248
1258
  }
1249
1259
  // --- CACHE MANAGEMENT ---
1250
- /**
1251
- * Check all caches in order of speed
1252
- */
1253
1260
  async checkCaches(key, forceRefresh, includeMetadata) {
1254
1261
  if (forceRefresh) return null;
1255
1262
  if (this.cacheStrategy === "memory") {
@@ -1272,22 +1279,24 @@ var ContentEngine = class {
1272
1279
  };
1273
1280
  }
1274
1281
  }
1275
- if (key.startsWith("page:")) {
1276
- const slug = key.split(":")[1];
1277
- try {
1278
- const local = await this.localCache.getPage(slug);
1279
- if (local) {
1280
- return {
1281
- data: local,
1282
- metadata: {
1283
- timestamp: Date.now(),
1284
- expiresAt: Infinity,
1285
- tags: [],
1286
- etag: void 0
1287
- }
1288
- };
1282
+ if (process.env.NODE_ENV === "development") {
1283
+ if (key.startsWith("page:")) {
1284
+ const slug = key.split(":")[1];
1285
+ try {
1286
+ const local = await this.localCache.getPage(slug);
1287
+ if (local) {
1288
+ return {
1289
+ data: local,
1290
+ metadata: {
1291
+ timestamp: Date.now(),
1292
+ expiresAt: Infinity,
1293
+ tags: [],
1294
+ etag: void 0
1295
+ }
1296
+ };
1297
+ }
1298
+ } catch {
1289
1299
  }
1290
- } catch {
1291
1300
  }
1292
1301
  }
1293
1302
  return null;
@@ -1304,9 +1313,6 @@ var ContentEngine = class {
1304
1313
  this.browserCache.set(key, data, numericRevalidate * 1e3);
1305
1314
  }
1306
1315
  }
1307
- /**
1308
- * Invalidate cache by tags
1309
- */
1310
1316
  invalidateCache(tags) {
1311
1317
  this.memoryCache.invalidateByTags(tags);
1312
1318
  if (this.config.debug) {
@@ -1315,9 +1321,6 @@ var ContentEngine = class {
1315
1321
  );
1316
1322
  }
1317
1323
  }
1318
- /**
1319
- * Clear all caches
1320
- */
1321
1324
  clearCache() {
1322
1325
  this.memoryCache.clear();
1323
1326
  if (this.browserCache) {
@@ -1327,9 +1330,6 @@ var ContentEngine = class {
1327
1330
  console.log("[NexusHub] \u{1F9F9} Cleared all caches");
1328
1331
  }
1329
1332
  }
1330
- /**
1331
- * Get cache statistics
1332
- */
1333
1333
  getCacheStats() {
1334
1334
  const stats = {
1335
1335
  memory: this.memoryCache.getStats(),
@@ -1343,14 +1343,16 @@ var ContentEngine = class {
1343
1343
  // --- REQUEST METHODS ---
1344
1344
  async fetchPage(slug, cacheKey, tags, revalidate, forceRefresh) {
1345
1345
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/page/${slug}`;
1346
- if (this.config.debug) {
1347
- console.log(`[NexusHub] \u{1F310} Fetching: ${url}`);
1348
- }
1349
1346
  const expiresAt = revalidate === false ? Infinity : Date.now() + revalidate * 1e3;
1347
+ const fetchTags = [
1348
+ CacheTags.project(this.config.projectId),
1349
+ CacheTags.content(slug),
1350
+ ...tags
1351
+ ];
1350
1352
  const res = await this.fetchWithTimeout(url, {
1351
1353
  method: "GET",
1352
1354
  headers: this.getHeaders(),
1353
- tags,
1355
+ tags: fetchTags,
1354
1356
  revalidate
1355
1357
  });
1356
1358
  if (!res.ok) {
@@ -1369,29 +1371,27 @@ var ContentEngine = class {
1369
1371
  timestamp: Date.now(),
1370
1372
  etag: etag || void 0,
1371
1373
  expiresAt,
1372
- tags: [...tags, CacheTags.content(slug)]
1374
+ tags: fetchTags
1373
1375
  }
1374
1376
  };
1375
1377
  this.writeCache(cacheKey, cacheEntry.data, {
1376
1378
  revalidate,
1377
- tags: [
1378
- CacheTags.project(this.config.projectId),
1379
- CacheTags.content(slug),
1380
- ...tags
1381
- ]
1379
+ tags: fetchTags
1382
1380
  });
1383
1381
  return cacheEntry;
1384
1382
  }
1385
1383
  async fetchCollection(collectionId, query, cacheKey, tags, revalidate) {
1386
1384
  const params = buildQueryString(query);
1387
1385
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}?${params}`;
1388
- if (this.config.debug) {
1389
- console.log(`[NexusHub] \u{1F310} Fetching Collection: ${url}`);
1390
- }
1386
+ const fetchTags = [
1387
+ CacheTags.project(this.config.projectId),
1388
+ CacheTags.collection(collectionId),
1389
+ ...tags
1390
+ ];
1391
1391
  const res = await this.fetchWithTimeout(url, {
1392
1392
  method: "GET",
1393
1393
  headers: this.getHeaders(),
1394
- tags,
1394
+ tags: fetchTags,
1395
1395
  revalidate
1396
1396
  });
1397
1397
  if (!res.ok) {
@@ -1406,16 +1406,12 @@ var ContentEngine = class {
1406
1406
  timestamp: Date.now(),
1407
1407
  etag: etag || void 0,
1408
1408
  expiresAt,
1409
- tags: [...tags, CacheTags.collection(collectionId)]
1409
+ tags: fetchTags
1410
1410
  }
1411
1411
  };
1412
1412
  this.writeCache(cacheKey, cacheEntry.data, {
1413
1413
  revalidate,
1414
- tags: [
1415
- CacheTags.project(this.config.projectId),
1416
- CacheTags.collection(collectionId),
1417
- ...tags
1418
- ]
1414
+ tags: fetchTags
1419
1415
  });
1420
1416
  return cacheEntry;
1421
1417
  }
@@ -1471,15 +1467,18 @@ var ContentEngine = class {
1471
1467
  tags = [],
1472
1468
  revalidate,
1473
1469
  ...fetchOptions
1474
- // 🚀 RESOLVED: Destructure with safe default to prevent undefined spreads
1475
1470
  } = options;
1476
1471
  const controller = new AbortController();
1477
1472
  const id = setTimeout(() => controller.abort(), timeout);
1478
- const nextConfig = this.isServer ? { next: { tags, revalidate } } : {};
1473
+ const nextConfig = this.isServer ? {
1474
+ cache: "force-cache",
1475
+ next: { tags, revalidate: revalidate === false ? false : revalidate }
1476
+ } : {};
1479
1477
  try {
1480
1478
  const response = await fetch(url, {
1481
1479
  ...fetchOptions,
1482
1480
  ...nextConfig,
1481
+ // Inject Next.js tags
1483
1482
  signal: controller.signal
1484
1483
  });
1485
1484
  clearTimeout(id);
package/dist/react.cjs CHANGED
@@ -647,7 +647,7 @@ var ContentEngine = class {
647
647
  }
648
648
  return includeMetadata ? cached : cached.data;
649
649
  }
650
- if (!forceRefresh) {
650
+ if (!forceRefresh && process.env.NODE_ENV === "development") {
651
651
  try {
652
652
  const localCollection = await this.localCache.getCollection(collectionId);
653
653
  if (localCollection) {
@@ -722,7 +722,7 @@ var ContentEngine = class {
722
722
  return cached;
723
723
  }
724
724
  }
725
- if (!forceRefresh) {
725
+ if (!forceRefresh && process.env.NODE_ENV === "development") {
726
726
  try {
727
727
  const localGlobals = await this.localCache.getGlobals();
728
728
  if (localGlobals) {
@@ -739,9 +739,16 @@ var ContentEngine = class {
739
739
  await this.rateLimiter.checkLimit();
740
740
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/globals`;
741
741
  const params = include.length > 0 ? `?include=${include.join(",")}` : "";
742
+ const fetchTags = [
743
+ CacheTags.project(this.config.projectId),
744
+ CacheTags.global,
745
+ ...options.tags || []
746
+ ];
742
747
  const res = await this.fetchWithTimeout(`${url}${params}`, {
743
748
  method: "GET",
744
- headers: this.getHeaders()
749
+ headers: this.getHeaders(),
750
+ tags: fetchTags,
751
+ revalidate
745
752
  });
746
753
  if (!res.ok) {
747
754
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
@@ -782,9 +789,17 @@ var ContentEngine = class {
782
789
  params.append("include", options.include.join(","));
783
790
  }
784
791
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}/${itemId}?${params}`;
792
+ const fetchTags = [
793
+ CacheTags.project(this.config.projectId),
794
+ CacheTags.collection(collectionId),
795
+ `item_${itemId}`,
796
+ ...options.tags || []
797
+ ];
785
798
  const res = await this.fetchWithTimeout(url, {
786
799
  method: "GET",
787
- headers: this.getHeaders()
800
+ headers: this.getHeaders(),
801
+ tags: fetchTags,
802
+ revalidate: options.revalidate || this.defaultRevalidate
788
803
  });
789
804
  if (!res.ok) {
790
805
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
@@ -793,12 +808,7 @@ var ContentEngine = class {
793
808
  const data = json.data || json;
794
809
  this.writeCache(cacheKey, data, {
795
810
  revalidate: options.revalidate || this.defaultRevalidate,
796
- tags: [
797
- CacheTags.project(this.config.projectId),
798
- CacheTags.collection(collectionId),
799
- `item_${itemId}`,
800
- ...options.tags || []
801
- ]
811
+ tags: fetchTags
802
812
  });
803
813
  return data;
804
814
  });
@@ -892,9 +902,6 @@ var ContentEngine = class {
892
902
  };
893
903
  }
894
904
  // --- CACHE MANAGEMENT ---
895
- /**
896
- * Check all caches in order of speed
897
- */
898
905
  async checkCaches(key, forceRefresh, includeMetadata) {
899
906
  if (forceRefresh) return null;
900
907
  if (this.cacheStrategy === "memory") {
@@ -917,22 +924,24 @@ var ContentEngine = class {
917
924
  };
918
925
  }
919
926
  }
920
- if (key.startsWith("page:")) {
921
- const slug = key.split(":")[1];
922
- try {
923
- const local = await this.localCache.getPage(slug);
924
- if (local) {
925
- return {
926
- data: local,
927
- metadata: {
928
- timestamp: Date.now(),
929
- expiresAt: Infinity,
930
- tags: [],
931
- etag: void 0
932
- }
933
- };
927
+ if (process.env.NODE_ENV === "development") {
928
+ if (key.startsWith("page:")) {
929
+ const slug = key.split(":")[1];
930
+ try {
931
+ const local = await this.localCache.getPage(slug);
932
+ if (local) {
933
+ return {
934
+ data: local,
935
+ metadata: {
936
+ timestamp: Date.now(),
937
+ expiresAt: Infinity,
938
+ tags: [],
939
+ etag: void 0
940
+ }
941
+ };
942
+ }
943
+ } catch (e7) {
934
944
  }
935
- } catch (e7) {
936
945
  }
937
946
  }
938
947
  return null;
@@ -949,9 +958,6 @@ var ContentEngine = class {
949
958
  this.browserCache.set(key, data, numericRevalidate * 1e3);
950
959
  }
951
960
  }
952
- /**
953
- * Invalidate cache by tags
954
- */
955
961
  invalidateCache(tags) {
956
962
  this.memoryCache.invalidateByTags(tags);
957
963
  if (this.config.debug) {
@@ -960,9 +966,6 @@ var ContentEngine = class {
960
966
  );
961
967
  }
962
968
  }
963
- /**
964
- * Clear all caches
965
- */
966
969
  clearCache() {
967
970
  this.memoryCache.clear();
968
971
  if (this.browserCache) {
@@ -972,9 +975,6 @@ var ContentEngine = class {
972
975
  console.log("[NexusHub] \u{1F9F9} Cleared all caches");
973
976
  }
974
977
  }
975
- /**
976
- * Get cache statistics
977
- */
978
978
  getCacheStats() {
979
979
  const stats = {
980
980
  memory: this.memoryCache.getStats(),
@@ -988,14 +988,16 @@ var ContentEngine = class {
988
988
  // --- REQUEST METHODS ---
989
989
  async fetchPage(slug, cacheKey, tags, revalidate, forceRefresh) {
990
990
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/page/${slug}`;
991
- if (this.config.debug) {
992
- console.log(`[NexusHub] \u{1F310} Fetching: ${url}`);
993
- }
994
991
  const expiresAt = revalidate === false ? Infinity : Date.now() + revalidate * 1e3;
992
+ const fetchTags = [
993
+ CacheTags.project(this.config.projectId),
994
+ CacheTags.content(slug),
995
+ ...tags
996
+ ];
995
997
  const res = await this.fetchWithTimeout(url, {
996
998
  method: "GET",
997
999
  headers: this.getHeaders(),
998
- tags,
1000
+ tags: fetchTags,
999
1001
  revalidate
1000
1002
  });
1001
1003
  if (!res.ok) {
@@ -1014,29 +1016,27 @@ var ContentEngine = class {
1014
1016
  timestamp: Date.now(),
1015
1017
  etag: etag || void 0,
1016
1018
  expiresAt,
1017
- tags: [...tags, CacheTags.content(slug)]
1019
+ tags: fetchTags
1018
1020
  }
1019
1021
  };
1020
1022
  this.writeCache(cacheKey, cacheEntry.data, {
1021
1023
  revalidate,
1022
- tags: [
1023
- CacheTags.project(this.config.projectId),
1024
- CacheTags.content(slug),
1025
- ...tags
1026
- ]
1024
+ tags: fetchTags
1027
1025
  });
1028
1026
  return cacheEntry;
1029
1027
  }
1030
1028
  async fetchCollection(collectionId, query, cacheKey, tags, revalidate) {
1031
1029
  const params = buildQueryString(query);
1032
1030
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}?${params}`;
1033
- if (this.config.debug) {
1034
- console.log(`[NexusHub] \u{1F310} Fetching Collection: ${url}`);
1035
- }
1031
+ const fetchTags = [
1032
+ CacheTags.project(this.config.projectId),
1033
+ CacheTags.collection(collectionId),
1034
+ ...tags
1035
+ ];
1036
1036
  const res = await this.fetchWithTimeout(url, {
1037
1037
  method: "GET",
1038
1038
  headers: this.getHeaders(),
1039
- tags,
1039
+ tags: fetchTags,
1040
1040
  revalidate
1041
1041
  });
1042
1042
  if (!res.ok) {
@@ -1051,16 +1051,12 @@ var ContentEngine = class {
1051
1051
  timestamp: Date.now(),
1052
1052
  etag: etag || void 0,
1053
1053
  expiresAt,
1054
- tags: [...tags, CacheTags.collection(collectionId)]
1054
+ tags: fetchTags
1055
1055
  }
1056
1056
  };
1057
1057
  this.writeCache(cacheKey, cacheEntry.data, {
1058
1058
  revalidate,
1059
- tags: [
1060
- CacheTags.project(this.config.projectId),
1061
- CacheTags.collection(collectionId),
1062
- ...tags
1063
- ]
1059
+ tags: fetchTags
1064
1060
  });
1065
1061
  return cacheEntry;
1066
1062
  }
@@ -1116,15 +1112,18 @@ var ContentEngine = class {
1116
1112
  tags = [],
1117
1113
  revalidate,
1118
1114
  ...fetchOptions
1119
- // 🚀 RESOLVED: Destructure with safe default to prevent undefined spreads
1120
1115
  } = options;
1121
1116
  const controller = new AbortController();
1122
1117
  const id = setTimeout(() => controller.abort(), timeout);
1123
- const nextConfig = this.isServer ? { next: { tags, revalidate } } : {};
1118
+ const nextConfig = this.isServer ? {
1119
+ cache: "force-cache",
1120
+ next: { tags, revalidate: revalidate === false ? false : revalidate }
1121
+ } : {};
1124
1122
  try {
1125
1123
  const response = await fetch(url, {
1126
1124
  ...fetchOptions,
1127
1125
  ...nextConfig,
1126
+ // Inject Next.js tags
1128
1127
  signal: controller.signal
1129
1128
  });
1130
1129
  clearTimeout(id);
package/dist/react.d.cts CHANGED
@@ -85,6 +85,7 @@ declare class ContentEngine {
85
85
  include?: string[];
86
86
  revalidate?: number | false;
87
87
  forceRefresh?: boolean;
88
+ tags?: string[];
88
89
  }): Promise<T>;
89
90
  /**
90
91
  * Get a single item from a collection (Uses Request Batching)
@@ -114,22 +115,10 @@ declare class ContentEngine {
114
115
  * Robust Real-time Subscriptions (SSE) with Auto-Reconnect
115
116
  */
116
117
  subscribeToUpdates(callback: (data: any) => void): () => void;
117
- /**
118
- * Check all caches in order of speed
119
- */
120
118
  private checkCaches;
121
119
  private writeCache;
122
- /**
123
- * Invalidate cache by tags
124
- */
125
120
  invalidateCache(tags: string[]): void;
126
- /**
127
- * Clear all caches
128
- */
129
121
  clearCache(): void;
130
- /**
131
- * Get cache statistics
132
- */
133
122
  getCacheStats(): {
134
123
  memory: {
135
124
  size: number;
package/dist/react.d.ts CHANGED
@@ -85,6 +85,7 @@ declare class ContentEngine {
85
85
  include?: string[];
86
86
  revalidate?: number | false;
87
87
  forceRefresh?: boolean;
88
+ tags?: string[];
88
89
  }): Promise<T>;
89
90
  /**
90
91
  * Get a single item from a collection (Uses Request Batching)
@@ -114,22 +115,10 @@ declare class ContentEngine {
114
115
  * Robust Real-time Subscriptions (SSE) with Auto-Reconnect
115
116
  */
116
117
  subscribeToUpdates(callback: (data: any) => void): () => void;
117
- /**
118
- * Check all caches in order of speed
119
- */
120
118
  private checkCaches;
121
119
  private writeCache;
122
- /**
123
- * Invalidate cache by tags
124
- */
125
120
  invalidateCache(tags: string[]): void;
126
- /**
127
- * Clear all caches
128
- */
129
121
  clearCache(): void;
130
- /**
131
- * Get cache statistics
132
- */
133
122
  getCacheStats(): {
134
123
  memory: {
135
124
  size: number;
package/dist/react.js CHANGED
@@ -647,7 +647,7 @@ var ContentEngine = class {
647
647
  }
648
648
  return includeMetadata ? cached : cached.data;
649
649
  }
650
- if (!forceRefresh) {
650
+ if (!forceRefresh && process.env.NODE_ENV === "development") {
651
651
  try {
652
652
  const localCollection = await this.localCache.getCollection(collectionId);
653
653
  if (localCollection) {
@@ -722,7 +722,7 @@ var ContentEngine = class {
722
722
  return cached;
723
723
  }
724
724
  }
725
- if (!forceRefresh) {
725
+ if (!forceRefresh && process.env.NODE_ENV === "development") {
726
726
  try {
727
727
  const localGlobals = await this.localCache.getGlobals();
728
728
  if (localGlobals) {
@@ -739,9 +739,16 @@ var ContentEngine = class {
739
739
  await this.rateLimiter.checkLimit();
740
740
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/globals`;
741
741
  const params = include.length > 0 ? `?include=${include.join(",")}` : "";
742
+ const fetchTags = [
743
+ CacheTags.project(this.config.projectId),
744
+ CacheTags.global,
745
+ ...options.tags || []
746
+ ];
742
747
  const res = await this.fetchWithTimeout(`${url}${params}`, {
743
748
  method: "GET",
744
- headers: this.getHeaders()
749
+ headers: this.getHeaders(),
750
+ tags: fetchTags,
751
+ revalidate
745
752
  });
746
753
  if (!res.ok) {
747
754
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
@@ -782,9 +789,17 @@ var ContentEngine = class {
782
789
  params.append("include", options.include.join(","));
783
790
  }
784
791
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}/${itemId}?${params}`;
792
+ const fetchTags = [
793
+ CacheTags.project(this.config.projectId),
794
+ CacheTags.collection(collectionId),
795
+ `item_${itemId}`,
796
+ ...options.tags || []
797
+ ];
785
798
  const res = await this.fetchWithTimeout(url, {
786
799
  method: "GET",
787
- headers: this.getHeaders()
800
+ headers: this.getHeaders(),
801
+ tags: fetchTags,
802
+ revalidate: options.revalidate || this.defaultRevalidate
788
803
  });
789
804
  if (!res.ok) {
790
805
  throw new Error(`API Error ${res.status}: ${res.statusText}`);
@@ -793,12 +808,7 @@ var ContentEngine = class {
793
808
  const data = json.data || json;
794
809
  this.writeCache(cacheKey, data, {
795
810
  revalidate: options.revalidate || this.defaultRevalidate,
796
- tags: [
797
- CacheTags.project(this.config.projectId),
798
- CacheTags.collection(collectionId),
799
- `item_${itemId}`,
800
- ...options.tags || []
801
- ]
811
+ tags: fetchTags
802
812
  });
803
813
  return data;
804
814
  });
@@ -892,9 +902,6 @@ var ContentEngine = class {
892
902
  };
893
903
  }
894
904
  // --- CACHE MANAGEMENT ---
895
- /**
896
- * Check all caches in order of speed
897
- */
898
905
  async checkCaches(key, forceRefresh, includeMetadata) {
899
906
  if (forceRefresh) return null;
900
907
  if (this.cacheStrategy === "memory") {
@@ -917,22 +924,24 @@ var ContentEngine = class {
917
924
  };
918
925
  }
919
926
  }
920
- if (key.startsWith("page:")) {
921
- const slug = key.split(":")[1];
922
- try {
923
- const local = await this.localCache.getPage(slug);
924
- if (local) {
925
- return {
926
- data: local,
927
- metadata: {
928
- timestamp: Date.now(),
929
- expiresAt: Infinity,
930
- tags: [],
931
- etag: void 0
932
- }
933
- };
927
+ if (process.env.NODE_ENV === "development") {
928
+ if (key.startsWith("page:")) {
929
+ const slug = key.split(":")[1];
930
+ try {
931
+ const local = await this.localCache.getPage(slug);
932
+ if (local) {
933
+ return {
934
+ data: local,
935
+ metadata: {
936
+ timestamp: Date.now(),
937
+ expiresAt: Infinity,
938
+ tags: [],
939
+ etag: void 0
940
+ }
941
+ };
942
+ }
943
+ } catch {
934
944
  }
935
- } catch {
936
945
  }
937
946
  }
938
947
  return null;
@@ -949,9 +958,6 @@ var ContentEngine = class {
949
958
  this.browserCache.set(key, data, numericRevalidate * 1e3);
950
959
  }
951
960
  }
952
- /**
953
- * Invalidate cache by tags
954
- */
955
961
  invalidateCache(tags) {
956
962
  this.memoryCache.invalidateByTags(tags);
957
963
  if (this.config.debug) {
@@ -960,9 +966,6 @@ var ContentEngine = class {
960
966
  );
961
967
  }
962
968
  }
963
- /**
964
- * Clear all caches
965
- */
966
969
  clearCache() {
967
970
  this.memoryCache.clear();
968
971
  if (this.browserCache) {
@@ -972,9 +975,6 @@ var ContentEngine = class {
972
975
  console.log("[NexusHub] \u{1F9F9} Cleared all caches");
973
976
  }
974
977
  }
975
- /**
976
- * Get cache statistics
977
- */
978
978
  getCacheStats() {
979
979
  const stats = {
980
980
  memory: this.memoryCache.getStats(),
@@ -988,14 +988,16 @@ var ContentEngine = class {
988
988
  // --- REQUEST METHODS ---
989
989
  async fetchPage(slug, cacheKey, tags, revalidate, forceRefresh) {
990
990
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/page/${slug}`;
991
- if (this.config.debug) {
992
- console.log(`[NexusHub] \u{1F310} Fetching: ${url}`);
993
- }
994
991
  const expiresAt = revalidate === false ? Infinity : Date.now() + revalidate * 1e3;
992
+ const fetchTags = [
993
+ CacheTags.project(this.config.projectId),
994
+ CacheTags.content(slug),
995
+ ...tags
996
+ ];
995
997
  const res = await this.fetchWithTimeout(url, {
996
998
  method: "GET",
997
999
  headers: this.getHeaders(),
998
- tags,
1000
+ tags: fetchTags,
999
1001
  revalidate
1000
1002
  });
1001
1003
  if (!res.ok) {
@@ -1014,29 +1016,27 @@ var ContentEngine = class {
1014
1016
  timestamp: Date.now(),
1015
1017
  etag: etag || void 0,
1016
1018
  expiresAt,
1017
- tags: [...tags, CacheTags.content(slug)]
1019
+ tags: fetchTags
1018
1020
  }
1019
1021
  };
1020
1022
  this.writeCache(cacheKey, cacheEntry.data, {
1021
1023
  revalidate,
1022
- tags: [
1023
- CacheTags.project(this.config.projectId),
1024
- CacheTags.content(slug),
1025
- ...tags
1026
- ]
1024
+ tags: fetchTags
1027
1025
  });
1028
1026
  return cacheEntry;
1029
1027
  }
1030
1028
  async fetchCollection(collectionId, query, cacheKey, tags, revalidate) {
1031
1029
  const params = buildQueryString(query);
1032
1030
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}?${params}`;
1033
- if (this.config.debug) {
1034
- console.log(`[NexusHub] \u{1F310} Fetching Collection: ${url}`);
1035
- }
1031
+ const fetchTags = [
1032
+ CacheTags.project(this.config.projectId),
1033
+ CacheTags.collection(collectionId),
1034
+ ...tags
1035
+ ];
1036
1036
  const res = await this.fetchWithTimeout(url, {
1037
1037
  method: "GET",
1038
1038
  headers: this.getHeaders(),
1039
- tags,
1039
+ tags: fetchTags,
1040
1040
  revalidate
1041
1041
  });
1042
1042
  if (!res.ok) {
@@ -1051,16 +1051,12 @@ var ContentEngine = class {
1051
1051
  timestamp: Date.now(),
1052
1052
  etag: etag || void 0,
1053
1053
  expiresAt,
1054
- tags: [...tags, CacheTags.collection(collectionId)]
1054
+ tags: fetchTags
1055
1055
  }
1056
1056
  };
1057
1057
  this.writeCache(cacheKey, cacheEntry.data, {
1058
1058
  revalidate,
1059
- tags: [
1060
- CacheTags.project(this.config.projectId),
1061
- CacheTags.collection(collectionId),
1062
- ...tags
1063
- ]
1059
+ tags: fetchTags
1064
1060
  });
1065
1061
  return cacheEntry;
1066
1062
  }
@@ -1116,15 +1112,18 @@ var ContentEngine = class {
1116
1112
  tags = [],
1117
1113
  revalidate,
1118
1114
  ...fetchOptions
1119
- // 🚀 RESOLVED: Destructure with safe default to prevent undefined spreads
1120
1115
  } = options;
1121
1116
  const controller = new AbortController();
1122
1117
  const id = setTimeout(() => controller.abort(), timeout);
1123
- const nextConfig = this.isServer ? { next: { tags, revalidate } } : {};
1118
+ const nextConfig = this.isServer ? {
1119
+ cache: "force-cache",
1120
+ next: { tags, revalidate: revalidate === false ? false : revalidate }
1121
+ } : {};
1124
1122
  try {
1125
1123
  const response = await fetch(url, {
1126
1124
  ...fetchOptions,
1127
1125
  ...nextConfig,
1126
+ // Inject Next.js tags
1128
1127
  signal: controller.signal
1129
1128
  });
1130
1129
  clearTimeout(id);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nexushub/client",
3
3
  "private": false,
4
- "version": "0.7.6",
4
+ "version": "0.7.8",
5
5
  "description": "The God-Tier NexusHub SDK",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",