@taujs/server 0.3.6 → 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 -7
- 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 +54 -4
- package/dist/index.js +1636 -348
- package/dist/types.d.ts +3 -0
- package/dist/types.js +0 -0
- package/package.json +18 -21
- package/dist/SSRServer-DPZped7n.d.ts +0 -153
- package/dist/build.js +0 -804
- package/dist/config.d.ts +0 -37
- package/dist/security/csp.d.ts +0 -4
- package/dist/security/csp.js +0 -67
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @taujs/server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
https://www.taujs.dev
|
|
4
|
+
|
|
5
|
+
This package is part of the τjs [ taujs ] orchestration system, authored by John Smith | Aoede, 2024-present. Attribution is appreciated.
|
|
4
6
|
|
|
5
7
|
`npm install @taujs/server`
|
|
6
8
|
|
|
@@ -24,7 +26,7 @@ Supported application structure and composition:
|
|
|
24
26
|
|
|
25
27
|
Assemble independent frontends at build time incorporating flexible per-route SPA-MPA hybrid with CSR, SSR, and Streaming SSR, rendering options.
|
|
26
28
|
|
|
27
|
-
Fastify Plugin for integration with
|
|
29
|
+
Fastify Plugin for integration with τjs [ taujs ] template https://github.com/aoede3/taujs
|
|
28
30
|
|
|
29
31
|
- Production: Fastify, React
|
|
30
32
|
- Development: Fastify, React, tsx, Vite
|
|
@@ -55,7 +57,7 @@ Integrated Vite HMR run alongside tsx (TS eXecute) providing fast responsive dev
|
|
|
55
57
|
|
|
56
58
|
https://github.com/aoede3/taujs/blob/main/src/server/index.ts
|
|
57
59
|
|
|
58
|
-
Not utilising
|
|
60
|
+
Not utilising τjs [ taujs ] template? Add in your own ts `alias` object for your own particular directory setup e.g. `alias: { object }`
|
|
59
61
|
|
|
60
62
|
### React 'entry-client.tsx'
|
|
61
63
|
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { AppConfig } from './
|
|
2
|
-
import 'vite';
|
|
3
|
-
import './SSRServer-DPZped7n.js';
|
|
4
|
-
import 'node:http';
|
|
1
|
+
import { A as AppConfig } from './Config-CjwAJCfZ.js';
|
|
5
2
|
import 'fastify';
|
|
3
|
+
import 'vite';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
6
|
+
* τjs [ taujs ] Orchestration System
|
|
9
7
|
* (c) 2024-present Aoede Ltd
|
|
10
8
|
* Author: John Smith
|
|
11
9
|
*
|
|
12
|
-
* Licensed under the MIT License
|
|
13
|
-
* Part of the
|
|
10
|
+
* Licensed under the MIT License - attribution appreciated.
|
|
11
|
+
* Part of the τjs [ taujs ] system for declarative, build-time orchestration of microfrontend applications,
|
|
14
12
|
* including CSR, SSR, streaming, and middleware composition.
|
|
15
13
|
*/
|
|
16
14
|
|
|
@@ -97,50 +97,132 @@ var require_picocolors = __commonJS({
|
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
// src/
|
|
100
|
+
// src/Build.ts
|
|
101
|
+
import path3 from "path";
|
|
102
|
+
import { build } from "vite";
|
|
103
|
+
import { nodePolyfills } from "vite-plugin-node-polyfills";
|
|
104
|
+
|
|
105
|
+
// src/utils/AssetManager.ts
|
|
106
|
+
import path2 from "path";
|
|
107
|
+
|
|
108
|
+
// src/utils/System.ts
|
|
109
|
+
import { dirname, join } from "path";
|
|
110
|
+
import "path";
|
|
111
|
+
import { fileURLToPath } from "url";
|
|
112
|
+
var isDevelopment = process.env.NODE_ENV === "development";
|
|
113
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
114
|
+
var __dirname = join(dirname(__filename), !isDevelopment ? "./" : "..");
|
|
115
|
+
|
|
116
|
+
// src/constants.ts
|
|
101
117
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
entryPoint,
|
|
107
|
-
plugins
|
|
108
|
-
}));
|
|
118
|
+
var TEMPLATE = {
|
|
119
|
+
defaultEntryClient: "entry-client",
|
|
120
|
+
defaultEntryServer: "entry-server",
|
|
121
|
+
defaultHtmlTemplate: "index.html"
|
|
109
122
|
};
|
|
110
|
-
var
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
var DEBUG = {
|
|
124
|
+
auth: { label: "auth", colour: import_picocolors.default.blue },
|
|
125
|
+
csp: { label: "csp", colour: import_picocolors.default.yellow },
|
|
126
|
+
errors: { label: "errors", colour: import_picocolors.default.red },
|
|
127
|
+
routes: { label: "routes", colour: import_picocolors.default.cyan },
|
|
128
|
+
security: { label: "security", colour: import_picocolors.default.yellow },
|
|
129
|
+
trx: { label: "trx", colour: import_picocolors.default.magenta },
|
|
130
|
+
vite: { label: "vite", colour: import_picocolors.default.yellow }
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/utils/AssetManager.ts
|
|
134
|
+
var processConfigs = (configs, baseClientRoot, templateDefaults) => {
|
|
135
|
+
return configs.map((config) => {
|
|
136
|
+
const clientRoot = path2.resolve(baseClientRoot, config.entryPoint);
|
|
137
|
+
return {
|
|
138
|
+
clientRoot,
|
|
139
|
+
entryPoint: config.entryPoint,
|
|
140
|
+
entryClient: config.entryClient || templateDefaults.defaultEntryClient,
|
|
141
|
+
entryServer: config.entryServer || templateDefaults.defaultEntryServer,
|
|
142
|
+
htmlTemplate: config.htmlTemplate || templateDefaults.defaultHtmlTemplate,
|
|
143
|
+
appId: config.appId
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// src/Build.ts
|
|
149
|
+
async function taujsBuild({
|
|
150
|
+
configs,
|
|
151
|
+
projectRoot,
|
|
152
|
+
clientBaseDir,
|
|
153
|
+
isSSRBuild = process.env.BUILD_MODE === "ssr"
|
|
154
|
+
}) {
|
|
155
|
+
const deleteDist = async () => {
|
|
156
|
+
const { rm } = await import("fs/promises");
|
|
157
|
+
const distPath = path3.resolve(projectRoot, "dist");
|
|
158
|
+
try {
|
|
159
|
+
await rm(distPath, { recursive: true, force: true });
|
|
160
|
+
console.log("Deleted the dist directory\n");
|
|
161
|
+
} catch (err) {
|
|
162
|
+
console.error("Error deleting dist directory:", err);
|
|
127
163
|
}
|
|
128
|
-
|
|
129
|
-
|
|
164
|
+
};
|
|
165
|
+
const processedConfigs = processConfigs(configs, clientBaseDir, TEMPLATE);
|
|
166
|
+
if (!isSSRBuild) await deleteDist();
|
|
167
|
+
for (const config of processedConfigs) {
|
|
168
|
+
const { appId, entryPoint, clientRoot, entryClient, entryServer, htmlTemplate, plugins = [] } = config;
|
|
169
|
+
const outDir = path3.resolve(projectRoot, `dist/client/${entryPoint}`);
|
|
170
|
+
const root = entryPoint ? path3.resolve(clientBaseDir, entryPoint) : clientBaseDir;
|
|
171
|
+
const server = path3.resolve(clientRoot, `${entryServer}.tsx`);
|
|
172
|
+
const client = path3.resolve(clientRoot, `${entryClient}.tsx`);
|
|
173
|
+
const main = path3.resolve(clientRoot, htmlTemplate);
|
|
174
|
+
const viteConfig = {
|
|
175
|
+
base: entryPoint ? `/${entryPoint}/` : "/",
|
|
176
|
+
build: {
|
|
177
|
+
outDir,
|
|
178
|
+
manifest: !isSSRBuild,
|
|
179
|
+
rollupOptions: {
|
|
180
|
+
input: isSSRBuild ? { server } : { client, main }
|
|
181
|
+
},
|
|
182
|
+
ssr: isSSRBuild ? server : void 0,
|
|
183
|
+
ssrManifest: isSSRBuild,
|
|
184
|
+
...isSSRBuild && {
|
|
185
|
+
format: "esm",
|
|
186
|
+
target: `node${process.versions.node.split(".").map(Number)[0]}`
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
css: {
|
|
190
|
+
preprocessorOptions: {
|
|
191
|
+
scss: { api: "modern-compiler" }
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
plugins: [...config.plugins ?? [], nodePolyfills({ include: ["fs", "stream"] })],
|
|
195
|
+
publicDir: "public",
|
|
196
|
+
resolve: {
|
|
197
|
+
alias: {
|
|
198
|
+
"@client": root,
|
|
199
|
+
"@server": path3.resolve(projectRoot, "src/server"),
|
|
200
|
+
"@shared": path3.resolve(projectRoot, "src/shared")
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
root,
|
|
204
|
+
server: {
|
|
205
|
+
proxy: {
|
|
206
|
+
"/api": {
|
|
207
|
+
target: "http://localhost:3000",
|
|
208
|
+
changeOrigin: true,
|
|
209
|
+
rewrite: (path4) => path4.replace(/^\/api/, "")
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
try {
|
|
215
|
+
console.log(`Building for entryPoint: "${entryPoint}" (${appId})`);
|
|
216
|
+
await build(viteConfig);
|
|
217
|
+
console.log(`Build complete for entryPoint: "${entryPoint}"
|
|
218
|
+
`);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
console.error(`Error building for entryPoint: "${entryPoint}"
|
|
221
|
+
`, error);
|
|
222
|
+
process.exit(1);
|
|
130
223
|
}
|
|
131
|
-
const sortedRoutes = allRoutes.sort((a, b) => computeScore(b.path) - computeScore(a.path));
|
|
132
|
-
const t1 = performance.now();
|
|
133
|
-
console.log(import_picocolors.default.green(`Prepared ${totalRoutes} route(s) in ${(t1 - t0).toFixed(1)}ms`));
|
|
134
|
-
return sortedRoutes;
|
|
135
|
-
} catch (err) {
|
|
136
|
-
console.log(import_picocolors.default.red("Failed to prepare routes"));
|
|
137
|
-
throw err;
|
|
138
224
|
}
|
|
139
|
-
}
|
|
140
|
-
var computeScore = (path) => {
|
|
141
|
-
return path.split("/").filter(Boolean).reduce((score, segment) => score + (segment.startsWith(":") ? 1 : 10), 0);
|
|
142
|
-
};
|
|
225
|
+
}
|
|
143
226
|
export {
|
|
144
|
-
|
|
145
|
-
extractRoutes
|
|
227
|
+
taujsBuild
|
|
146
228
|
};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { FastifyRequest, FastifyPluginCallback, FastifyPluginAsync } from 'fastify';
|
|
2
|
+
import { PluginOption } from 'vite';
|
|
3
|
+
|
|
4
|
+
declare const DEBUG_CATEGORIES: readonly ["auth", "routes", "errors", "vite", "network", "ssr"];
|
|
5
|
+
type DebugCategory = (typeof DEBUG_CATEGORIES)[number];
|
|
6
|
+
type DebugConfig = boolean | DebugCategory[] | ({
|
|
7
|
+
all?: boolean;
|
|
8
|
+
} & Partial<Record<DebugCategory, boolean>>);
|
|
9
|
+
interface BaseLogger {
|
|
10
|
+
debug?(message: string, meta?: unknown): void;
|
|
11
|
+
info?(message: string, meta?: unknown): void;
|
|
12
|
+
warn?(message: string, meta?: unknown): void;
|
|
13
|
+
error?(message: string, meta?: unknown): void;
|
|
14
|
+
log?(message: string, meta?: unknown): void;
|
|
15
|
+
}
|
|
16
|
+
interface Logs extends BaseLogger {
|
|
17
|
+
debug(message: string, meta?: unknown): void;
|
|
18
|
+
debug(category: DebugCategory, message: string, meta?: unknown): void;
|
|
19
|
+
info(message: string, meta?: unknown): void;
|
|
20
|
+
warn(message: string, meta?: unknown): void;
|
|
21
|
+
error(message: string, meta?: unknown): void;
|
|
22
|
+
child(context: Record<string, unknown>): Logs;
|
|
23
|
+
isDebugEnabled(category: DebugCategory): boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Schema<T> = (input: unknown) => T;
|
|
27
|
+
type LooseSpec = Readonly<Record<string, ServiceMethod<any, Record<string, unknown>> | {
|
|
28
|
+
handler: ServiceMethod<any, Record<string, unknown>>;
|
|
29
|
+
params?: Schema<any>;
|
|
30
|
+
result?: Schema<any>;
|
|
31
|
+
parsers?: {
|
|
32
|
+
params?: Schema<any>;
|
|
33
|
+
result?: Schema<any>;
|
|
34
|
+
};
|
|
35
|
+
}>>;
|
|
36
|
+
type ServiceContext = {
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
deadlineMs?: number;
|
|
39
|
+
traceId?: string;
|
|
40
|
+
logger?: Logs;
|
|
41
|
+
user?: {
|
|
42
|
+
id: string;
|
|
43
|
+
roles: string[];
|
|
44
|
+
} | null;
|
|
45
|
+
};
|
|
46
|
+
type ServiceMethod<P, R extends Record<string, unknown>> = (params: P, ctx: ServiceContext) => Promise<R>;
|
|
47
|
+
type ServiceMethodDescriptor<P, R extends Record<string, unknown>> = {
|
|
48
|
+
handler: ServiceMethod<P, R>;
|
|
49
|
+
parsers?: {
|
|
50
|
+
params?: Schema<P>;
|
|
51
|
+
result?: Schema<R>;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
type ServiceRegistry = Readonly<Record<string, Readonly<Record<string, ServiceMethodDescriptor<any, Record<string, unknown>>>>>>;
|
|
55
|
+
declare const defineService: <T extends LooseSpec>(spec: T) => { [K in keyof T]: T[K] extends ServiceMethod<infer P, infer R> ? ServiceMethodDescriptor<P, R> : T[K] extends {
|
|
56
|
+
handler: ServiceMethod<infer P, infer R_1>;
|
|
57
|
+
} ? ServiceMethodDescriptor<P, R_1> : never; };
|
|
58
|
+
declare const defineServiceRegistry: <R extends ServiceRegistry>(registry: R) => R;
|
|
59
|
+
|
|
60
|
+
type RequestContext<L extends Logs = Logs> = {
|
|
61
|
+
traceId: string;
|
|
62
|
+
logger: L;
|
|
63
|
+
headers: Record<string, string>;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type RouteCSPConfig = {
|
|
67
|
+
disabled?: boolean;
|
|
68
|
+
mode?: 'merge' | 'replace';
|
|
69
|
+
directives?: CSPDirectives | ((args: {
|
|
70
|
+
url: string;
|
|
71
|
+
params: PathToRegExpParams;
|
|
72
|
+
headers: FastifyRequest['headers'];
|
|
73
|
+
req: FastifyRequest;
|
|
74
|
+
}) => CSPDirectives);
|
|
75
|
+
generateCSP?: (directives: CSPDirectives, nonce: string, req: FastifyRequest) => string;
|
|
76
|
+
};
|
|
77
|
+
type Config = {
|
|
78
|
+
appId: string;
|
|
79
|
+
entryPoint: string;
|
|
80
|
+
entryClient?: string;
|
|
81
|
+
entryServer?: string;
|
|
82
|
+
htmlTemplate?: string;
|
|
83
|
+
};
|
|
84
|
+
type ProcessedConfig = {
|
|
85
|
+
appId: string;
|
|
86
|
+
clientRoot: string;
|
|
87
|
+
entryClient: string;
|
|
88
|
+
entryPoint: string;
|
|
89
|
+
entryServer: string;
|
|
90
|
+
htmlTemplate: string;
|
|
91
|
+
plugins?: PluginOption[];
|
|
92
|
+
};
|
|
93
|
+
type SSRServerOptions = {
|
|
94
|
+
alias?: Record<string, string>;
|
|
95
|
+
clientRoot: string;
|
|
96
|
+
configs: AppConfig[];
|
|
97
|
+
routes: Route<PathToRegExpParams>[];
|
|
98
|
+
serviceRegistry: ServiceRegistry;
|
|
99
|
+
security?: SecurityConfig;
|
|
100
|
+
registerStaticAssets?: false | {
|
|
101
|
+
plugin: FastifyPluginCallback<any> | FastifyPluginAsync<any>;
|
|
102
|
+
options?: Record<string, unknown>;
|
|
103
|
+
};
|
|
104
|
+
debug?: DebugConfig;
|
|
105
|
+
devNet?: {
|
|
106
|
+
host: string;
|
|
107
|
+
hmrPort: number;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
type RenderCallbacks<T = unknown> = {
|
|
111
|
+
onHead?: (headContent: string) => void;
|
|
112
|
+
onShellReady?: () => void;
|
|
113
|
+
onAllReady?: (initialData: T) => void;
|
|
114
|
+
onError?: (error: unknown) => void;
|
|
115
|
+
};
|
|
116
|
+
type SSRManifest = {
|
|
117
|
+
[key: string]: string[];
|
|
118
|
+
};
|
|
119
|
+
type ManifestEntry = {
|
|
120
|
+
file: string;
|
|
121
|
+
src?: string;
|
|
122
|
+
isDynamicEntry?: boolean;
|
|
123
|
+
imports?: string[];
|
|
124
|
+
css?: string[];
|
|
125
|
+
assets?: string[];
|
|
126
|
+
};
|
|
127
|
+
type Manifest = {
|
|
128
|
+
[key: string]: ManifestEntry;
|
|
129
|
+
};
|
|
130
|
+
type RenderSSR = (initialDataResolved: Record<string, unknown>, location: string, meta?: Record<string, unknown>, signal?: AbortSignal, opts?: {
|
|
131
|
+
logger?: Logs;
|
|
132
|
+
}) => Promise<{
|
|
133
|
+
headContent: string;
|
|
134
|
+
appHtml: string;
|
|
135
|
+
}>;
|
|
136
|
+
type RenderStream = (serverResponse: NodeJS.WritableStream, callbacks: RenderCallbacks, initialData: Record<string, unknown> | Promise<Record<string, unknown>> | (() => Promise<Record<string, unknown>>), location: string, bootstrapModules?: string, meta?: Record<string, unknown>, cspNonce?: string, signal?: AbortSignal, opts?: {
|
|
137
|
+
logger?: Logs;
|
|
138
|
+
}) => {
|
|
139
|
+
abort(): void;
|
|
140
|
+
};
|
|
141
|
+
type RenderModule = {
|
|
142
|
+
renderSSR: RenderSSR;
|
|
143
|
+
renderStream: RenderStream;
|
|
144
|
+
};
|
|
145
|
+
type GenericPlugin = FastifyPluginCallback<Record<string, unknown>> | FastifyPluginAsync<Record<string, unknown>>;
|
|
146
|
+
type BaseMiddleware = {
|
|
147
|
+
auth?: {
|
|
148
|
+
redirect?: string;
|
|
149
|
+
roles?: string[];
|
|
150
|
+
strategy?: string;
|
|
151
|
+
};
|
|
152
|
+
csp?: RouteCSPConfig | false;
|
|
153
|
+
};
|
|
154
|
+
type ServiceCall = {
|
|
155
|
+
serviceName: string;
|
|
156
|
+
serviceMethod: string;
|
|
157
|
+
args?: Record<string, unknown>;
|
|
158
|
+
};
|
|
159
|
+
type DataResult = Record<string, unknown> | ServiceCall;
|
|
160
|
+
type DataHandler<Params extends PathToRegExpParams, L extends Logs = Logs> = (params: Params, ctx: RequestContext<L> & {
|
|
161
|
+
[key: string]: unknown;
|
|
162
|
+
}) => Promise<DataResult>;
|
|
163
|
+
type PathToRegExpParams = Partial<Record<string, string | string[]>>;
|
|
164
|
+
type RouteAttributes<Params extends PathToRegExpParams = PathToRegExpParams, Middleware = BaseMiddleware, L extends Logs = Logs> = {
|
|
165
|
+
render: 'ssr';
|
|
166
|
+
hydrate?: boolean;
|
|
167
|
+
meta?: Record<string, unknown>;
|
|
168
|
+
middleware?: Middleware;
|
|
169
|
+
data?: DataHandler<Params, L>;
|
|
170
|
+
} | {
|
|
171
|
+
render: 'streaming';
|
|
172
|
+
hydrate?: boolean;
|
|
173
|
+
meta: Record<string, unknown>;
|
|
174
|
+
middleware?: Middleware;
|
|
175
|
+
data?: DataHandler<Params, L>;
|
|
176
|
+
};
|
|
177
|
+
type Route<Params extends PathToRegExpParams = PathToRegExpParams> = {
|
|
178
|
+
attr?: RouteAttributes<Params>;
|
|
179
|
+
path: string;
|
|
180
|
+
appId?: string;
|
|
181
|
+
};
|
|
182
|
+
interface InitialRouteParams extends Record<string, unknown> {
|
|
183
|
+
serviceName?: string;
|
|
184
|
+
serviceMethod?: string;
|
|
185
|
+
}
|
|
186
|
+
type RoutePathsAndAttributes<Params extends PathToRegExpParams = PathToRegExpParams> = Omit<Route<Params>, 'element'>;
|
|
187
|
+
|
|
188
|
+
type CSPDirectives = Record<string, string[]>;
|
|
189
|
+
|
|
190
|
+
type CSPViolationReport = {
|
|
191
|
+
'document-uri': string;
|
|
192
|
+
'violated-directive': string;
|
|
193
|
+
'blocked-uri'?: string;
|
|
194
|
+
'source-file'?: string;
|
|
195
|
+
'line-number'?: number;
|
|
196
|
+
'column-number'?: number;
|
|
197
|
+
'script-sample'?: string;
|
|
198
|
+
'original-policy'?: string;
|
|
199
|
+
disposition?: 'enforce' | 'report';
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* τjs [ taujs ] Orchestration System
|
|
204
|
+
* (c) 2024-present Aoede Ltd
|
|
205
|
+
* Author: John Smith
|
|
206
|
+
*
|
|
207
|
+
* Licensed under the MIT License - attribution appreciated.
|
|
208
|
+
* Part of the τjs [ taujs ] system for declarative, build-time orchestration of microfrontend applications,
|
|
209
|
+
* including CSR, SSR, streaming, and middleware composition.
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
type SecurityConfig = {
|
|
213
|
+
csp?: {
|
|
214
|
+
defaultMode?: 'merge' | 'replace';
|
|
215
|
+
directives?: CSPDirectives;
|
|
216
|
+
generateCSP?: (directives: CSPDirectives, nonce: string, req?: FastifyRequest) => string;
|
|
217
|
+
reporting?: {
|
|
218
|
+
endpoint: string;
|
|
219
|
+
onViolation?: (report: CSPViolationReport, req: FastifyRequest) => void;
|
|
220
|
+
reportOnly?: boolean;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
type AppRoute = Omit<Route<PathToRegExpParams>, 'appId'> & {
|
|
225
|
+
attr?: RouteAttributes<PathToRegExpParams>;
|
|
226
|
+
};
|
|
227
|
+
type AppConfig = {
|
|
228
|
+
appId: string;
|
|
229
|
+
entryPoint: string;
|
|
230
|
+
plugins?: PluginOption[];
|
|
231
|
+
routes?: AppRoute[];
|
|
232
|
+
};
|
|
233
|
+
type TaujsConfig = {
|
|
234
|
+
server?: {
|
|
235
|
+
host?: string;
|
|
236
|
+
port?: number;
|
|
237
|
+
hmrPort?: number;
|
|
238
|
+
};
|
|
239
|
+
security?: SecurityConfig;
|
|
240
|
+
apps: AppConfig[];
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
declare function defineConfig<T extends TaujsConfig>(config: T): T;
|
|
244
|
+
|
|
245
|
+
export { type AppConfig as A, type BaseLogger as B, type Config as C, type DebugConfig as D, type GenericPlugin as G, type InitialRouteParams as I, type ManifestEntry as M, type ProcessedConfig as P, type RouteCSPConfig as R, type SSRServerOptions as S, type TaujsConfig as T, type ServiceRegistry as a, type RenderCallbacks as b, type SSRManifest as c, type Manifest as d, type RenderSSR as e, type RenderStream as f, type RenderModule as g, type BaseMiddleware as h, type ServiceCall as i, type DataResult as j, type DataHandler as k, type PathToRegExpParams as l, type RouteAttributes as m, type Route as n, type RoutePathsAndAttributes as o, type SecurityConfig as p, type AppRoute as q, defineConfig as r, defineServiceRegistry as s, defineService as t };
|
package/dist/Config.d.ts
ADDED
package/dist/Config.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/utils/DataServices.ts
|
|
2
|
+
var defineService = (spec) => {
|
|
3
|
+
const out = {};
|
|
4
|
+
for (const [k, v] of Object.entries(spec)) {
|
|
5
|
+
if (typeof v === "function") {
|
|
6
|
+
out[k] = { handler: v };
|
|
7
|
+
} else {
|
|
8
|
+
out[k] = {
|
|
9
|
+
handler: v.handler,
|
|
10
|
+
parsers: v.parsers ?? (v.params || v.result ? { params: v.params, result: v.result } : void 0)
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
};
|
|
16
|
+
var defineServiceRegistry = (registry) => registry;
|
|
17
|
+
|
|
18
|
+
// src/Config.ts
|
|
19
|
+
function defineConfig(config) {
|
|
20
|
+
if (!config.apps || config.apps.length === 0) throw new Error("At least one app must be configured");
|
|
21
|
+
return config;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
defineConfig,
|
|
25
|
+
defineService,
|
|
26
|
+
defineServiceRegistry
|
|
27
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import '
|
|
1
|
+
import { S as SSRServerOptions, T as TaujsConfig, a as ServiceRegistry, D as DebugConfig, B as BaseLogger } from './Config-CjwAJCfZ.js';
|
|
2
|
+
export { h as BaseMiddleware, C as Config, k as DataHandler, j as DataResult, G as GenericPlugin, I as InitialRouteParams, d as Manifest, M as ManifestEntry, l as PathToRegExpParams, P as ProcessedConfig, b as RenderCallbacks, g as RenderModule, e as RenderSSR, f as RenderStream, n as Route, m as RouteAttributes, R as RouteCSPConfig, o as RoutePathsAndAttributes, c as SSRManifest, i as ServiceCall } from './Config-CjwAJCfZ.js';
|
|
3
|
+
import { FastifyPluginAsync, FastifyInstance, FastifyPluginCallback } from 'fastify';
|
|
4
4
|
import 'vite';
|
|
5
5
|
|
|
6
6
|
declare module 'fastify' {
|
|
7
7
|
interface FastifyRequest {
|
|
8
|
-
|
|
8
|
+
cspNonce?: string;
|
|
9
9
|
}
|
|
10
|
+
|
|
10
11
|
interface FastifyInstance {
|
|
11
12
|
/**
|
|
12
13
|
* Optional authentication hook to be used by the taujs SSRServer.
|
|
@@ -20,5 +21,54 @@ declare module 'fastify' {
|
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
23
|
authenticate: (req: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
24
|
+
showBanner(): void;
|
|
25
|
+
cspNonce?: string;
|
|
23
26
|
}
|
|
24
27
|
}
|
|
28
|
+
|
|
29
|
+
declare const TEMPLATE: {
|
|
30
|
+
readonly defaultEntryClient: "entry-client";
|
|
31
|
+
readonly defaultEntryServer: "entry-server";
|
|
32
|
+
readonly defaultHtmlTemplate: "index.html";
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* τjs [ taujs ] Orchestration System
|
|
37
|
+
* (c) 2024-present Aoede Ltd
|
|
38
|
+
* Author: John Smith
|
|
39
|
+
*
|
|
40
|
+
* Licensed under the MIT License - attribution appreciated.
|
|
41
|
+
* Part of the τjs [ taujs ] system for declarative, build-time orchestration of microfrontend applications,
|
|
42
|
+
* including CSR, SSR, streaming, and middleware composition.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
declare const SSRServer: FastifyPluginAsync<SSRServerOptions>;
|
|
46
|
+
|
|
47
|
+
type NetResolved = {
|
|
48
|
+
host: string;
|
|
49
|
+
port: number;
|
|
50
|
+
hmrPort: number;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type StaticAssetsRegistration = {
|
|
54
|
+
plugin: FastifyPluginCallback<any> | FastifyPluginAsync<any>;
|
|
55
|
+
options?: Record<string, unknown>;
|
|
56
|
+
};
|
|
57
|
+
type CreateServerOptions = {
|
|
58
|
+
config: TaujsConfig;
|
|
59
|
+
serviceRegistry: ServiceRegistry;
|
|
60
|
+
clientRoot?: string;
|
|
61
|
+
alias?: Record<string, string>;
|
|
62
|
+
fastify?: FastifyInstance;
|
|
63
|
+
debug?: DebugConfig;
|
|
64
|
+
logger?: BaseLogger;
|
|
65
|
+
registerStaticAssets?: false | StaticAssetsRegistration;
|
|
66
|
+
port?: number;
|
|
67
|
+
};
|
|
68
|
+
type CreateServerResult = {
|
|
69
|
+
app?: FastifyInstance;
|
|
70
|
+
net: NetResolved;
|
|
71
|
+
};
|
|
72
|
+
declare const createServer: (opts: CreateServerOptions) => Promise<CreateServerResult>;
|
|
73
|
+
|
|
74
|
+
export { SSRServer, SSRServerOptions, TEMPLATE, createServer };
|