@taujs/server 0.3.7 → 0.4.0
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/LICENSE +1 -1
- package/README.md +5 -3
- package/dist/{build.d.ts → Build.d.ts} +5 -8
- package/dist/{config.js → Build.js} +122 -40
- package/dist/Config-CjwAJCfZ.d.ts +245 -0
- package/dist/Config.d.ts +3 -0
- package/dist/Config.js +27 -0
- package/dist/index.d.ts +53 -4
- package/dist/index.js +1633 -346
- package/dist/types.d.ts +3 -0
- package/dist/types.js +0 -0
- package/package.json +18 -21
- package/dist/SSRServer-CbXIDaoA.d.ts +0 -142
- package/dist/build.js +0 -805
- package/dist/config.d.ts +0 -38
- package/dist/security/csp.d.ts +0 -12
- package/dist/security/csp.js +0 -175
package/dist/config.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { PluginOption } from 'vite';
|
|
2
|
-
import { R as Route, a as RouteParams, b as RouteAttributes } from './SSRServer-CbXIDaoA.js';
|
|
3
|
-
import 'node:http';
|
|
4
|
-
import 'fastify';
|
|
5
|
-
import './security/csp.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* taujs [ τjs ] Orchestration System
|
|
9
|
-
* (c) 2024-present Aoede Ltd
|
|
10
|
-
* Author: John Smith
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the MIT License — attribution appreciated.
|
|
13
|
-
* Part of the taujs [ τjs ] system for declarative, build-time orchestration of microfrontend applications,
|
|
14
|
-
* including CSR, SSR, streaming, and middleware composition.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
type AppRoute = Omit<Route<RouteParams>, 'appId'> & {
|
|
18
|
-
attr?: RouteAttributes;
|
|
19
|
-
};
|
|
20
|
-
type AppConfig = {
|
|
21
|
-
appId: string;
|
|
22
|
-
entryPoint: string;
|
|
23
|
-
plugins?: PluginOption[];
|
|
24
|
-
routes?: AppRoute[];
|
|
25
|
-
};
|
|
26
|
-
type TaujsConfig = {
|
|
27
|
-
apps: AppConfig[];
|
|
28
|
-
};
|
|
29
|
-
declare const extractBuildConfigs: (config: {
|
|
30
|
-
apps: {
|
|
31
|
-
appId: string;
|
|
32
|
-
entryPoint: string;
|
|
33
|
-
plugins?: PluginOption[];
|
|
34
|
-
}[];
|
|
35
|
-
}) => AppConfig[];
|
|
36
|
-
declare const extractRoutes: (taujsConfig: TaujsConfig) => Route<RouteParams>[];
|
|
37
|
-
|
|
38
|
-
export { type AppConfig, type AppRoute, type TaujsConfig, extractBuildConfigs, extractRoutes };
|
package/dist/security/csp.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FastifyPluginAsync } from 'fastify';
|
|
2
|
-
|
|
3
|
-
interface CSPPluginOptions {
|
|
4
|
-
directives?: CSPDirectives;
|
|
5
|
-
generateCSP?: (directives: CSPDirectives, nonce: string) => string;
|
|
6
|
-
}
|
|
7
|
-
type CSPDirectives = Record<string, string[]>;
|
|
8
|
-
declare const defaultGenerateCSP: (directives: CSPDirectives, nonce: string) => string;
|
|
9
|
-
declare const generateNonce: () => string;
|
|
10
|
-
declare const cspPlugin: FastifyPluginAsync<CSPPluginOptions>;
|
|
11
|
-
|
|
12
|
-
export { type CSPDirectives, type CSPPluginOptions, cspPlugin, defaultGenerateCSP, generateNonce };
|
package/dist/security/csp.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
|
|
27
|
-
// node_modules/fastify-plugin/lib/getPluginName.js
|
|
28
|
-
var require_getPluginName = __commonJS({
|
|
29
|
-
"node_modules/fastify-plugin/lib/getPluginName.js"(exports, module) {
|
|
30
|
-
"use strict";
|
|
31
|
-
var fpStackTracePattern = /at\s{1}(?:.*\.)?plugin\s{1}.*\n\s*(.*)/;
|
|
32
|
-
var fileNamePattern = /(\w*(\.\w*)*)\..*/;
|
|
33
|
-
module.exports = function getPluginName(fn) {
|
|
34
|
-
if (fn.name.length > 0) return fn.name;
|
|
35
|
-
const stackTraceLimit = Error.stackTraceLimit;
|
|
36
|
-
Error.stackTraceLimit = 10;
|
|
37
|
-
try {
|
|
38
|
-
throw new Error("anonymous function");
|
|
39
|
-
} catch (e) {
|
|
40
|
-
Error.stackTraceLimit = stackTraceLimit;
|
|
41
|
-
return extractPluginName(e.stack);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
function extractPluginName(stack) {
|
|
45
|
-
const m = stack.match(fpStackTracePattern);
|
|
46
|
-
return m ? m[1].split(/[/\\]/).slice(-1)[0].match(fileNamePattern)[1] : "anonymous";
|
|
47
|
-
}
|
|
48
|
-
module.exports.extractPluginName = extractPluginName;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// node_modules/fastify-plugin/lib/toCamelCase.js
|
|
53
|
-
var require_toCamelCase = __commonJS({
|
|
54
|
-
"node_modules/fastify-plugin/lib/toCamelCase.js"(exports, module) {
|
|
55
|
-
"use strict";
|
|
56
|
-
module.exports = function toCamelCase(name) {
|
|
57
|
-
if (name[0] === "@") {
|
|
58
|
-
name = name.slice(1).replace("/", "-");
|
|
59
|
-
}
|
|
60
|
-
return name.replace(/-(.)/g, function(match2, g1) {
|
|
61
|
-
return g1.toUpperCase();
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// node_modules/fastify-plugin/plugin.js
|
|
68
|
-
var require_plugin = __commonJS({
|
|
69
|
-
"node_modules/fastify-plugin/plugin.js"(exports, module) {
|
|
70
|
-
"use strict";
|
|
71
|
-
var getPluginName = require_getPluginName();
|
|
72
|
-
var toCamelCase = require_toCamelCase();
|
|
73
|
-
var count = 0;
|
|
74
|
-
function plugin(fn, options = {}) {
|
|
75
|
-
let autoName = false;
|
|
76
|
-
if (fn.default !== void 0) {
|
|
77
|
-
fn = fn.default;
|
|
78
|
-
}
|
|
79
|
-
if (typeof fn !== "function") {
|
|
80
|
-
throw new TypeError(
|
|
81
|
-
`fastify-plugin expects a function, instead got a '${typeof fn}'`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
if (typeof options === "string") {
|
|
85
|
-
options = {
|
|
86
|
-
fastify: options
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
if (typeof options !== "object" || Array.isArray(options) || options === null) {
|
|
90
|
-
throw new TypeError("The options object should be an object");
|
|
91
|
-
}
|
|
92
|
-
if (options.fastify !== void 0 && typeof options.fastify !== "string") {
|
|
93
|
-
throw new TypeError(`fastify-plugin expects a version string, instead got '${typeof options.fastify}'`);
|
|
94
|
-
}
|
|
95
|
-
if (!options.name) {
|
|
96
|
-
autoName = true;
|
|
97
|
-
options.name = getPluginName(fn) + "-auto-" + count++;
|
|
98
|
-
}
|
|
99
|
-
fn[Symbol.for("skip-override")] = options.encapsulate !== true;
|
|
100
|
-
fn[Symbol.for("fastify.display-name")] = options.name;
|
|
101
|
-
fn[Symbol.for("plugin-meta")] = options;
|
|
102
|
-
if (!fn.default) {
|
|
103
|
-
fn.default = fn;
|
|
104
|
-
}
|
|
105
|
-
const camelCase = toCamelCase(options.name);
|
|
106
|
-
if (!autoName && !fn[camelCase]) {
|
|
107
|
-
fn[camelCase] = fn;
|
|
108
|
-
}
|
|
109
|
-
return fn;
|
|
110
|
-
}
|
|
111
|
-
module.exports = plugin;
|
|
112
|
-
module.exports.default = plugin;
|
|
113
|
-
module.exports.fastifyPlugin = plugin;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// src/security/csp.ts
|
|
118
|
-
var import_fastify_plugin = __toESM(require_plugin(), 1);
|
|
119
|
-
import crypto from "crypto";
|
|
120
|
-
|
|
121
|
-
// src/constants.ts
|
|
122
|
-
var DEV_CSP_DIRECTIVES = {
|
|
123
|
-
"default-src": ["'self'"],
|
|
124
|
-
"connect-src": ["'self'", "ws:", "http:"],
|
|
125
|
-
"style-src": ["'self'", "'unsafe-inline'"],
|
|
126
|
-
"img-src": ["'self'", "data:"]
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// src/utils/Utils.ts
|
|
130
|
-
import { dirname, join } from "path";
|
|
131
|
-
import "path";
|
|
132
|
-
import { fileURLToPath } from "url";
|
|
133
|
-
import { match } from "path-to-regexp";
|
|
134
|
-
var isDevelopment = process.env.NODE_ENV === "development";
|
|
135
|
-
var __filename = fileURLToPath(import.meta.url);
|
|
136
|
-
var __dirname = join(dirname(__filename), !isDevelopment ? "./" : "..");
|
|
137
|
-
|
|
138
|
-
// src/security/csp.ts
|
|
139
|
-
var defaultGenerateCSP = (directives, nonce) => {
|
|
140
|
-
const merged = { ...directives };
|
|
141
|
-
merged["script-src"] = merged["script-src"] || ["'self'"];
|
|
142
|
-
if (!merged["script-src"].some((v) => v.startsWith("'nonce-"))) merged["script-src"].push(`'nonce-${nonce}'`);
|
|
143
|
-
if (isDevelopment) {
|
|
144
|
-
const connect = merged["connect-src"] || ["'self'"];
|
|
145
|
-
if (!connect.includes("ws:")) connect.push("ws:");
|
|
146
|
-
if (!connect.includes("http:")) connect.push("http:");
|
|
147
|
-
merged["connect-src"] = connect;
|
|
148
|
-
const style = merged["style-src"] || ["'self'"];
|
|
149
|
-
if (!style.includes("'unsafe-inline'")) style.push("'unsafe-inline'");
|
|
150
|
-
merged["style-src"] = style;
|
|
151
|
-
}
|
|
152
|
-
return Object.entries(merged).map(([key, values]) => `${key} ${values.join(" ")}`).join("; ");
|
|
153
|
-
};
|
|
154
|
-
var generateNonce = () => crypto.randomBytes(16).toString("base64");
|
|
155
|
-
var cspPlugin = (0, import_fastify_plugin.default)(
|
|
156
|
-
async (fastify, opts) => {
|
|
157
|
-
fastify.addHook("onRequest", (req, reply, done) => {
|
|
158
|
-
const nonce = generateNonce();
|
|
159
|
-
req.cspNonce = nonce;
|
|
160
|
-
const directives = opts.directives ?? DEV_CSP_DIRECTIVES;
|
|
161
|
-
const generate = opts.generateCSP ?? defaultGenerateCSP;
|
|
162
|
-
const cspHeader = generate(directives, nonce);
|
|
163
|
-
reply.header("Content-Security-Policy", cspHeader);
|
|
164
|
-
done();
|
|
165
|
-
});
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
name: "taujs-csp-plugin"
|
|
169
|
-
}
|
|
170
|
-
);
|
|
171
|
-
export {
|
|
172
|
-
cspPlugin,
|
|
173
|
-
defaultGenerateCSP,
|
|
174
|
-
generateNonce
|
|
175
|
-
};
|