@nexushub/client 0.1.4 → 0.1.7
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/cli.cjs +28 -28
- package/dist/index.cjs +55 -3
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +55 -3
- package/package.json +1 -1
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 {
|
|
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);
|
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 {
|
|
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);
|