@nexushub/client 0.7.7 → 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
@@ -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") {
@@ -1352,9 +1359,6 @@ var ContentEngine = class {
1352
1359
  this.browserCache.set(key, data, numericRevalidate * 1e3);
1353
1360
  }
1354
1361
  }
1355
- /**
1356
- * Invalidate cache by tags
1357
- */
1358
1362
  invalidateCache(tags) {
1359
1363
  this.memoryCache.invalidateByTags(tags);
1360
1364
  if (this.config.debug) {
@@ -1363,9 +1367,6 @@ var ContentEngine = class {
1363
1367
  );
1364
1368
  }
1365
1369
  }
1366
- /**
1367
- * Clear all caches
1368
- */
1369
1370
  clearCache() {
1370
1371
  this.memoryCache.clear();
1371
1372
  if (this.browserCache) {
@@ -1375,9 +1376,6 @@ var ContentEngine = class {
1375
1376
  console.log("[NexusHub] \u{1F9F9} Cleared all caches");
1376
1377
  }
1377
1378
  }
1378
- /**
1379
- * Get cache statistics
1380
- */
1381
1379
  getCacheStats() {
1382
1380
  const stats = {
1383
1381
  memory: this.memoryCache.getStats(),
@@ -1391,14 +1389,16 @@ var ContentEngine = class {
1391
1389
  // --- REQUEST METHODS ---
1392
1390
  async fetchPage(slug, cacheKey, tags, revalidate, forceRefresh) {
1393
1391
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/page/${slug}`;
1394
- if (this.config.debug) {
1395
- console.log(`[NexusHub] \u{1F310} Fetching: ${url}`);
1396
- }
1397
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
+ ];
1398
1398
  const res = await this.fetchWithTimeout(url, {
1399
1399
  method: "GET",
1400
1400
  headers: this.getHeaders(),
1401
- tags,
1401
+ tags: fetchTags,
1402
1402
  revalidate
1403
1403
  });
1404
1404
  if (!res.ok) {
@@ -1417,29 +1417,27 @@ var ContentEngine = class {
1417
1417
  timestamp: Date.now(),
1418
1418
  etag: etag || void 0,
1419
1419
  expiresAt,
1420
- tags: [...tags, CacheTags.content(slug)]
1420
+ tags: fetchTags
1421
1421
  }
1422
1422
  };
1423
1423
  this.writeCache(cacheKey, cacheEntry.data, {
1424
1424
  revalidate,
1425
- tags: [
1426
- CacheTags.project(this.config.projectId),
1427
- CacheTags.content(slug),
1428
- ...tags
1429
- ]
1425
+ tags: fetchTags
1430
1426
  });
1431
1427
  return cacheEntry;
1432
1428
  }
1433
1429
  async fetchCollection(collectionId, query, cacheKey, tags, revalidate) {
1434
1430
  const params = buildQueryString(query);
1435
1431
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}?${params}`;
1436
- if (this.config.debug) {
1437
- console.log(`[NexusHub] \u{1F310} Fetching Collection: ${url}`);
1438
- }
1432
+ const fetchTags = [
1433
+ CacheTags.project(this.config.projectId),
1434
+ CacheTags.collection(collectionId),
1435
+ ...tags
1436
+ ];
1439
1437
  const res = await this.fetchWithTimeout(url, {
1440
1438
  method: "GET",
1441
1439
  headers: this.getHeaders(),
1442
- tags,
1440
+ tags: fetchTags,
1443
1441
  revalidate
1444
1442
  });
1445
1443
  if (!res.ok) {
@@ -1454,16 +1452,12 @@ var ContentEngine = class {
1454
1452
  timestamp: Date.now(),
1455
1453
  etag: etag || void 0,
1456
1454
  expiresAt,
1457
- tags: [...tags, CacheTags.collection(collectionId)]
1455
+ tags: fetchTags
1458
1456
  }
1459
1457
  };
1460
1458
  this.writeCache(cacheKey, cacheEntry.data, {
1461
1459
  revalidate,
1462
- tags: [
1463
- CacheTags.project(this.config.projectId),
1464
- CacheTags.collection(collectionId),
1465
- ...tags
1466
- ]
1460
+ tags: fetchTags
1467
1461
  });
1468
1462
  return cacheEntry;
1469
1463
  }
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
@@ -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") {
@@ -1306,9 +1313,6 @@ var ContentEngine = class {
1306
1313
  this.browserCache.set(key, data, numericRevalidate * 1e3);
1307
1314
  }
1308
1315
  }
1309
- /**
1310
- * Invalidate cache by tags
1311
- */
1312
1316
  invalidateCache(tags) {
1313
1317
  this.memoryCache.invalidateByTags(tags);
1314
1318
  if (this.config.debug) {
@@ -1317,9 +1321,6 @@ var ContentEngine = class {
1317
1321
  );
1318
1322
  }
1319
1323
  }
1320
- /**
1321
- * Clear all caches
1322
- */
1323
1324
  clearCache() {
1324
1325
  this.memoryCache.clear();
1325
1326
  if (this.browserCache) {
@@ -1329,9 +1330,6 @@ var ContentEngine = class {
1329
1330
  console.log("[NexusHub] \u{1F9F9} Cleared all caches");
1330
1331
  }
1331
1332
  }
1332
- /**
1333
- * Get cache statistics
1334
- */
1335
1333
  getCacheStats() {
1336
1334
  const stats = {
1337
1335
  memory: this.memoryCache.getStats(),
@@ -1345,14 +1343,16 @@ var ContentEngine = class {
1345
1343
  // --- REQUEST METHODS ---
1346
1344
  async fetchPage(slug, cacheKey, tags, revalidate, forceRefresh) {
1347
1345
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/page/${slug}`;
1348
- if (this.config.debug) {
1349
- console.log(`[NexusHub] \u{1F310} Fetching: ${url}`);
1350
- }
1351
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
+ ];
1352
1352
  const res = await this.fetchWithTimeout(url, {
1353
1353
  method: "GET",
1354
1354
  headers: this.getHeaders(),
1355
- tags,
1355
+ tags: fetchTags,
1356
1356
  revalidate
1357
1357
  });
1358
1358
  if (!res.ok) {
@@ -1371,29 +1371,27 @@ var ContentEngine = class {
1371
1371
  timestamp: Date.now(),
1372
1372
  etag: etag || void 0,
1373
1373
  expiresAt,
1374
- tags: [...tags, CacheTags.content(slug)]
1374
+ tags: fetchTags
1375
1375
  }
1376
1376
  };
1377
1377
  this.writeCache(cacheKey, cacheEntry.data, {
1378
1378
  revalidate,
1379
- tags: [
1380
- CacheTags.project(this.config.projectId),
1381
- CacheTags.content(slug),
1382
- ...tags
1383
- ]
1379
+ tags: fetchTags
1384
1380
  });
1385
1381
  return cacheEntry;
1386
1382
  }
1387
1383
  async fetchCollection(collectionId, query, cacheKey, tags, revalidate) {
1388
1384
  const params = buildQueryString(query);
1389
1385
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}?${params}`;
1390
- if (this.config.debug) {
1391
- console.log(`[NexusHub] \u{1F310} Fetching Collection: ${url}`);
1392
- }
1386
+ const fetchTags = [
1387
+ CacheTags.project(this.config.projectId),
1388
+ CacheTags.collection(collectionId),
1389
+ ...tags
1390
+ ];
1393
1391
  const res = await this.fetchWithTimeout(url, {
1394
1392
  method: "GET",
1395
1393
  headers: this.getHeaders(),
1396
- tags,
1394
+ tags: fetchTags,
1397
1395
  revalidate
1398
1396
  });
1399
1397
  if (!res.ok) {
@@ -1408,16 +1406,12 @@ var ContentEngine = class {
1408
1406
  timestamp: Date.now(),
1409
1407
  etag: etag || void 0,
1410
1408
  expiresAt,
1411
- tags: [...tags, CacheTags.collection(collectionId)]
1409
+ tags: fetchTags
1412
1410
  }
1413
1411
  };
1414
1412
  this.writeCache(cacheKey, cacheEntry.data, {
1415
1413
  revalidate,
1416
- tags: [
1417
- CacheTags.project(this.config.projectId),
1418
- CacheTags.collection(collectionId),
1419
- ...tags
1420
- ]
1414
+ tags: fetchTags
1421
1415
  });
1422
1416
  return cacheEntry;
1423
1417
  }
package/dist/react.cjs CHANGED
@@ -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") {
@@ -951,9 +958,6 @@ var ContentEngine = class {
951
958
  this.browserCache.set(key, data, numericRevalidate * 1e3);
952
959
  }
953
960
  }
954
- /**
955
- * Invalidate cache by tags
956
- */
957
961
  invalidateCache(tags) {
958
962
  this.memoryCache.invalidateByTags(tags);
959
963
  if (this.config.debug) {
@@ -962,9 +966,6 @@ var ContentEngine = class {
962
966
  );
963
967
  }
964
968
  }
965
- /**
966
- * Clear all caches
967
- */
968
969
  clearCache() {
969
970
  this.memoryCache.clear();
970
971
  if (this.browserCache) {
@@ -974,9 +975,6 @@ var ContentEngine = class {
974
975
  console.log("[NexusHub] \u{1F9F9} Cleared all caches");
975
976
  }
976
977
  }
977
- /**
978
- * Get cache statistics
979
- */
980
978
  getCacheStats() {
981
979
  const stats = {
982
980
  memory: this.memoryCache.getStats(),
@@ -990,14 +988,16 @@ var ContentEngine = class {
990
988
  // --- REQUEST METHODS ---
991
989
  async fetchPage(slug, cacheKey, tags, revalidate, forceRefresh) {
992
990
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/page/${slug}`;
993
- if (this.config.debug) {
994
- console.log(`[NexusHub] \u{1F310} Fetching: ${url}`);
995
- }
996
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
+ ];
997
997
  const res = await this.fetchWithTimeout(url, {
998
998
  method: "GET",
999
999
  headers: this.getHeaders(),
1000
- tags,
1000
+ tags: fetchTags,
1001
1001
  revalidate
1002
1002
  });
1003
1003
  if (!res.ok) {
@@ -1016,29 +1016,27 @@ var ContentEngine = class {
1016
1016
  timestamp: Date.now(),
1017
1017
  etag: etag || void 0,
1018
1018
  expiresAt,
1019
- tags: [...tags, CacheTags.content(slug)]
1019
+ tags: fetchTags
1020
1020
  }
1021
1021
  };
1022
1022
  this.writeCache(cacheKey, cacheEntry.data, {
1023
1023
  revalidate,
1024
- tags: [
1025
- CacheTags.project(this.config.projectId),
1026
- CacheTags.content(slug),
1027
- ...tags
1028
- ]
1024
+ tags: fetchTags
1029
1025
  });
1030
1026
  return cacheEntry;
1031
1027
  }
1032
1028
  async fetchCollection(collectionId, query, cacheKey, tags, revalidate) {
1033
1029
  const params = buildQueryString(query);
1034
1030
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}?${params}`;
1035
- if (this.config.debug) {
1036
- console.log(`[NexusHub] \u{1F310} Fetching Collection: ${url}`);
1037
- }
1031
+ const fetchTags = [
1032
+ CacheTags.project(this.config.projectId),
1033
+ CacheTags.collection(collectionId),
1034
+ ...tags
1035
+ ];
1038
1036
  const res = await this.fetchWithTimeout(url, {
1039
1037
  method: "GET",
1040
1038
  headers: this.getHeaders(),
1041
- tags,
1039
+ tags: fetchTags,
1042
1040
  revalidate
1043
1041
  });
1044
1042
  if (!res.ok) {
@@ -1053,16 +1051,12 @@ var ContentEngine = class {
1053
1051
  timestamp: Date.now(),
1054
1052
  etag: etag || void 0,
1055
1053
  expiresAt,
1056
- tags: [...tags, CacheTags.collection(collectionId)]
1054
+ tags: fetchTags
1057
1055
  }
1058
1056
  };
1059
1057
  this.writeCache(cacheKey, cacheEntry.data, {
1060
1058
  revalidate,
1061
- tags: [
1062
- CacheTags.project(this.config.projectId),
1063
- CacheTags.collection(collectionId),
1064
- ...tags
1065
- ]
1059
+ tags: fetchTags
1066
1060
  });
1067
1061
  return cacheEntry;
1068
1062
  }
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
@@ -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") {
@@ -951,9 +958,6 @@ var ContentEngine = class {
951
958
  this.browserCache.set(key, data, numericRevalidate * 1e3);
952
959
  }
953
960
  }
954
- /**
955
- * Invalidate cache by tags
956
- */
957
961
  invalidateCache(tags) {
958
962
  this.memoryCache.invalidateByTags(tags);
959
963
  if (this.config.debug) {
@@ -962,9 +966,6 @@ var ContentEngine = class {
962
966
  );
963
967
  }
964
968
  }
965
- /**
966
- * Clear all caches
967
- */
968
969
  clearCache() {
969
970
  this.memoryCache.clear();
970
971
  if (this.browserCache) {
@@ -974,9 +975,6 @@ var ContentEngine = class {
974
975
  console.log("[NexusHub] \u{1F9F9} Cleared all caches");
975
976
  }
976
977
  }
977
- /**
978
- * Get cache statistics
979
- */
980
978
  getCacheStats() {
981
979
  const stats = {
982
980
  memory: this.memoryCache.getStats(),
@@ -990,14 +988,16 @@ var ContentEngine = class {
990
988
  // --- REQUEST METHODS ---
991
989
  async fetchPage(slug, cacheKey, tags, revalidate, forceRefresh) {
992
990
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/page/${slug}`;
993
- if (this.config.debug) {
994
- console.log(`[NexusHub] \u{1F310} Fetching: ${url}`);
995
- }
996
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
+ ];
997
997
  const res = await this.fetchWithTimeout(url, {
998
998
  method: "GET",
999
999
  headers: this.getHeaders(),
1000
- tags,
1000
+ tags: fetchTags,
1001
1001
  revalidate
1002
1002
  });
1003
1003
  if (!res.ok) {
@@ -1016,29 +1016,27 @@ var ContentEngine = class {
1016
1016
  timestamp: Date.now(),
1017
1017
  etag: etag || void 0,
1018
1018
  expiresAt,
1019
- tags: [...tags, CacheTags.content(slug)]
1019
+ tags: fetchTags
1020
1020
  }
1021
1021
  };
1022
1022
  this.writeCache(cacheKey, cacheEntry.data, {
1023
1023
  revalidate,
1024
- tags: [
1025
- CacheTags.project(this.config.projectId),
1026
- CacheTags.content(slug),
1027
- ...tags
1028
- ]
1024
+ tags: fetchTags
1029
1025
  });
1030
1026
  return cacheEntry;
1031
1027
  }
1032
1028
  async fetchCollection(collectionId, query, cacheKey, tags, revalidate) {
1033
1029
  const params = buildQueryString(query);
1034
1030
  const url = `${this.config.apiUrl}/content/${this.config.projectId}/collection/${collectionId}?${params}`;
1035
- if (this.config.debug) {
1036
- console.log(`[NexusHub] \u{1F310} Fetching Collection: ${url}`);
1037
- }
1031
+ const fetchTags = [
1032
+ CacheTags.project(this.config.projectId),
1033
+ CacheTags.collection(collectionId),
1034
+ ...tags
1035
+ ];
1038
1036
  const res = await this.fetchWithTimeout(url, {
1039
1037
  method: "GET",
1040
1038
  headers: this.getHeaders(),
1041
- tags,
1039
+ tags: fetchTags,
1042
1040
  revalidate
1043
1041
  });
1044
1042
  if (!res.ok) {
@@ -1053,16 +1051,12 @@ var ContentEngine = class {
1053
1051
  timestamp: Date.now(),
1054
1052
  etag: etag || void 0,
1055
1053
  expiresAt,
1056
- tags: [...tags, CacheTags.collection(collectionId)]
1054
+ tags: fetchTags
1057
1055
  }
1058
1056
  };
1059
1057
  this.writeCache(cacheKey, cacheEntry.data, {
1060
1058
  revalidate,
1061
- tags: [
1062
- CacheTags.project(this.config.projectId),
1063
- CacheTags.collection(collectionId),
1064
- ...tags
1065
- ]
1059
+ tags: fetchTags
1066
1060
  });
1067
1061
  return cacheEntry;
1068
1062
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nexushub/client",
3
3
  "private": false,
4
- "version": "0.7.7",
4
+ "version": "0.7.8",
5
5
  "description": "The God-Tier NexusHub SDK",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",