@taujs/server 0.2.5 → 0.2.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/build.js +16 -17
- package/dist/index.js +16 -17
- package/dist/security/csp.d.ts +0 -1
- package/dist/security/csp.js +3 -3
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -251,10 +251,10 @@ var cspHook = (options = {}) => (req, reply, done) => {
|
|
|
251
251
|
done();
|
|
252
252
|
};
|
|
253
253
|
var applyCSP = (security, reply) => {
|
|
254
|
-
if (!security?.csp) return;
|
|
255
254
|
const nonce = generateNonce();
|
|
256
|
-
const
|
|
257
|
-
const
|
|
255
|
+
const directives = security?.csp?.directives ?? DEV_CSP_DIRECTIVES;
|
|
256
|
+
const generate = security?.csp?.generateCSP ?? defaultGenerateCSP;
|
|
257
|
+
const header = generate(directives, nonce);
|
|
258
258
|
reply.header("Content-Security-Policy", header);
|
|
259
259
|
reply.request.nonce = nonce;
|
|
260
260
|
return nonce;
|
|
@@ -330,16 +330,15 @@ function renderPreloadLink(file) {
|
|
|
330
330
|
return "";
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
-
var callServiceMethod = async (
|
|
334
|
-
const service =
|
|
335
|
-
if (service
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
throw new Error(`Service method ${serviceMethod} does not exist on ${serviceName}`);
|
|
333
|
+
var callServiceMethod = async (registry, serviceName, methodName, params) => {
|
|
334
|
+
const service = registry[serviceName];
|
|
335
|
+
if (!service) throw new Error(`Service ${String(serviceName)} does not exist in the registry`);
|
|
336
|
+
const method = service[methodName];
|
|
337
|
+
if (typeof method !== "function") throw new Error(`Service method ${String(methodName)} does not exist on ${String(serviceName)}`);
|
|
338
|
+
const data = await method(params);
|
|
339
|
+
if (typeof data !== "object" || data === null)
|
|
340
|
+
throw new Error(`Expected object response from ${String(serviceName)}.${String(methodName)}, but got ${typeof data}`);
|
|
341
|
+
return data;
|
|
343
342
|
};
|
|
344
343
|
var fetchData = async ({ url, options }) => {
|
|
345
344
|
if (url) {
|
|
@@ -357,10 +356,10 @@ var fetchInitialData = async (attr, params, serviceRegistry) => {
|
|
|
357
356
|
headers: { "Content-Type": "application/json" },
|
|
358
357
|
params
|
|
359
358
|
}).then(async (data) => {
|
|
360
|
-
if (data.serviceName && data.serviceMethod)
|
|
359
|
+
if (data.serviceName && data.serviceMethod && typeof data.serviceName === "string" && typeof data.serviceMethod === "string")
|
|
361
360
|
return await callServiceMethod(serviceRegistry, data.serviceName, data.serviceMethod, data.options?.params ?? {});
|
|
362
|
-
|
|
363
|
-
|
|
361
|
+
if (data.url && typeof data.url === "string") return await fetchData(data);
|
|
362
|
+
throw new Error("Invalid fetch configuration: must have either serviceName+serviceMethod or url");
|
|
364
363
|
}).catch((error) => {
|
|
365
364
|
console.error("Error fetching initial data:", error);
|
|
366
365
|
throw error;
|
|
@@ -475,7 +474,7 @@ var SSRServer = (0, import_fastify_plugin.default)(
|
|
|
475
474
|
app.addHook(
|
|
476
475
|
"onRequest",
|
|
477
476
|
cspHook({
|
|
478
|
-
directives: opts.security?.csp?.directives
|
|
477
|
+
directives: opts.security?.csp?.directives,
|
|
479
478
|
generateCSP: opts.security?.csp?.generateCSP
|
|
480
479
|
})
|
|
481
480
|
);
|
package/dist/index.js
CHANGED
|
@@ -246,10 +246,10 @@ var cspHook = (options = {}) => (req, reply, done) => {
|
|
|
246
246
|
done();
|
|
247
247
|
};
|
|
248
248
|
var applyCSP = (security, reply) => {
|
|
249
|
-
if (!security?.csp) return;
|
|
250
249
|
const nonce = generateNonce();
|
|
251
|
-
const
|
|
252
|
-
const
|
|
250
|
+
const directives = security?.csp?.directives ?? DEV_CSP_DIRECTIVES;
|
|
251
|
+
const generate = security?.csp?.generateCSP ?? defaultGenerateCSP;
|
|
252
|
+
const header = generate(directives, nonce);
|
|
253
253
|
reply.header("Content-Security-Policy", header);
|
|
254
254
|
reply.request.nonce = nonce;
|
|
255
255
|
return nonce;
|
|
@@ -325,16 +325,15 @@ function renderPreloadLink(file) {
|
|
|
325
325
|
return "";
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
|
-
var callServiceMethod = async (
|
|
329
|
-
const service =
|
|
330
|
-
if (service
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
throw new Error(`Service method ${serviceMethod} does not exist on ${serviceName}`);
|
|
328
|
+
var callServiceMethod = async (registry, serviceName, methodName, params) => {
|
|
329
|
+
const service = registry[serviceName];
|
|
330
|
+
if (!service) throw new Error(`Service ${String(serviceName)} does not exist in the registry`);
|
|
331
|
+
const method = service[methodName];
|
|
332
|
+
if (typeof method !== "function") throw new Error(`Service method ${String(methodName)} does not exist on ${String(serviceName)}`);
|
|
333
|
+
const data = await method(params);
|
|
334
|
+
if (typeof data !== "object" || data === null)
|
|
335
|
+
throw new Error(`Expected object response from ${String(serviceName)}.${String(methodName)}, but got ${typeof data}`);
|
|
336
|
+
return data;
|
|
338
337
|
};
|
|
339
338
|
var fetchData = async ({ url, options }) => {
|
|
340
339
|
if (url) {
|
|
@@ -352,10 +351,10 @@ var fetchInitialData = async (attr, params, serviceRegistry) => {
|
|
|
352
351
|
headers: { "Content-Type": "application/json" },
|
|
353
352
|
params
|
|
354
353
|
}).then(async (data) => {
|
|
355
|
-
if (data.serviceName && data.serviceMethod)
|
|
354
|
+
if (data.serviceName && data.serviceMethod && typeof data.serviceName === "string" && typeof data.serviceMethod === "string")
|
|
356
355
|
return await callServiceMethod(serviceRegistry, data.serviceName, data.serviceMethod, data.options?.params ?? {});
|
|
357
|
-
|
|
358
|
-
|
|
356
|
+
if (data.url && typeof data.url === "string") return await fetchData(data);
|
|
357
|
+
throw new Error("Invalid fetch configuration: must have either serviceName+serviceMethod or url");
|
|
359
358
|
}).catch((error) => {
|
|
360
359
|
console.error("Error fetching initial data:", error);
|
|
361
360
|
throw error;
|
|
@@ -470,7 +469,7 @@ var SSRServer = (0, import_fastify_plugin.default)(
|
|
|
470
469
|
app.addHook(
|
|
471
470
|
"onRequest",
|
|
472
471
|
cspHook({
|
|
473
|
-
directives: opts.security?.csp?.directives
|
|
472
|
+
directives: opts.security?.csp?.directives,
|
|
474
473
|
generateCSP: opts.security?.csp?.generateCSP
|
|
475
474
|
})
|
|
476
475
|
);
|
package/dist/security/csp.d.ts
CHANGED
|
@@ -98,7 +98,6 @@ type Manifest = {
|
|
|
98
98
|
type RenderSSR = (initialDataResolved: Record<string, unknown>, location: string, meta?: Record<string, unknown>) => Promise<{
|
|
99
99
|
headContent: string;
|
|
100
100
|
appHtml: string;
|
|
101
|
-
initialDataScript: string;
|
|
102
101
|
}>;
|
|
103
102
|
type RenderStream = (serverResponse: ServerResponse, callbacks: RenderCallbacks, initialDataPromise: Promise<Record<string, unknown>>, location: string, bootstrapModules?: string, meta?: Record<string, unknown>) => void;
|
|
104
103
|
type RenderModule = {
|
package/dist/security/csp.js
CHANGED
|
@@ -41,10 +41,10 @@ var cspHook = (options = {}) => (req, reply, done) => {
|
|
|
41
41
|
};
|
|
42
42
|
var getRequestNonce = (req) => req.nonce;
|
|
43
43
|
var applyCSP = (security, reply) => {
|
|
44
|
-
if (!security?.csp) return;
|
|
45
44
|
const nonce = generateNonce();
|
|
46
|
-
const
|
|
47
|
-
const
|
|
45
|
+
const directives = security?.csp?.directives ?? DEV_CSP_DIRECTIVES;
|
|
46
|
+
const generate = security?.csp?.generateCSP ?? defaultGenerateCSP;
|
|
47
|
+
const header = generate(directives, nonce);
|
|
48
48
|
reply.header("Content-Security-Policy", header);
|
|
49
49
|
reply.request.nonce = nonce;
|
|
50
50
|
return nonce;
|