@taujs/server 0.3.7 → 0.4.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- taujs [ τjs ] Orchestration System
3
+ τjs [ taujs ] Orchestration System
4
4
  Author: John Smith
5
5
  Copyright (c) Aoede Ltd 2024-present
6
6
 
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @taujs/server
2
2
 
3
- This package is part of the taujs [ τjs ] orchestration system, authored by John Smith | Aoede, 2024-present. Attribution is appreciated.
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 taujs [ τjs ] template https://github.com/aoede3/taujs
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 taujs [ τjs ] template? Add in your own ts `alias` object for your own particular directory setup e.g. `alias: { object }`
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
 
@@ -0,0 +1,175 @@
1
+ import { FastifyRequest } 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?(meta?: Record<string, unknown>, message?: string): void;
11
+ info?(meta?: Record<string, unknown>, message?: string): void;
12
+ warn?(meta?: Record<string, unknown>, message?: string): void;
13
+ error?(meta?: Record<string, unknown>, message?: string): void;
14
+ child?(context: Record<string, unknown>): BaseLogger;
15
+ }
16
+ interface Logs extends BaseLogger {
17
+ debug(meta?: unknown, message?: string): void;
18
+ debug(category: DebugCategory, meta?: unknown, message?: string): void;
19
+ info(meta?: unknown, message?: string): void;
20
+ warn(meta?: unknown, message?: string): void;
21
+ error(meta?: unknown, message?: string): 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 BaseMiddleware = {
78
+ auth?: {
79
+ redirect?: string;
80
+ roles?: string[];
81
+ strategy?: string;
82
+ };
83
+ csp?: RouteCSPConfig | false;
84
+ };
85
+ type ServiceCall = {
86
+ serviceName: string;
87
+ serviceMethod: string;
88
+ args?: Record<string, unknown>;
89
+ };
90
+ type DataResult = Record<string, unknown> | ServiceCall;
91
+ type DataHandler<Params extends PathToRegExpParams, L extends Logs = Logs> = (params: Params, ctx: RequestContext<L> & {
92
+ [key: string]: unknown;
93
+ }) => Promise<DataResult>;
94
+ type PathToRegExpParams = Partial<Record<string, string | string[]>>;
95
+ type RouteAttributes<Params extends PathToRegExpParams = PathToRegExpParams, Middleware = BaseMiddleware, L extends Logs = Logs> = {
96
+ render: 'ssr';
97
+ hydrate?: boolean;
98
+ meta?: Record<string, unknown>;
99
+ middleware?: Middleware;
100
+ data?: DataHandler<Params, L>;
101
+ } | {
102
+ render: 'streaming';
103
+ hydrate?: boolean;
104
+ meta: Record<string, unknown>;
105
+ middleware?: Middleware;
106
+ data?: DataHandler<Params, L>;
107
+ };
108
+ type Route<Params extends PathToRegExpParams = PathToRegExpParams> = {
109
+ attr?: RouteAttributes<Params>;
110
+ path: string;
111
+ appId?: string;
112
+ };
113
+ interface InitialRouteParams extends Record<string, unknown> {
114
+ serviceName?: string;
115
+ serviceMethod?: string;
116
+ }
117
+
118
+ type CSPDirectives = Record<string, string[]>;
119
+
120
+ type CSPViolationReport = {
121
+ 'document-uri': string;
122
+ 'violated-directive': string;
123
+ 'blocked-uri'?: string;
124
+ 'source-file'?: string;
125
+ 'line-number'?: number;
126
+ 'column-number'?: number;
127
+ 'script-sample'?: string;
128
+ 'original-policy'?: string;
129
+ disposition?: 'enforce' | 'report';
130
+ };
131
+
132
+ /**
133
+ * τjs [ taujs ] Orchestration System
134
+ * (c) 2024-present Aoede Ltd
135
+ * Author: John Smith
136
+ *
137
+ * Licensed under the MIT License - attribution appreciated.
138
+ * Part of the τjs [ taujs ] system for declarative, build-time orchestration of microfrontend applications,
139
+ * including CSR, SSR, streaming, and middleware composition.
140
+ */
141
+
142
+ type SecurityConfig = {
143
+ csp?: {
144
+ defaultMode?: 'merge' | 'replace';
145
+ directives?: CSPDirectives;
146
+ generateCSP?: (directives: CSPDirectives, nonce: string, req?: FastifyRequest) => string;
147
+ reporting?: {
148
+ endpoint: string;
149
+ onViolation?: (report: CSPViolationReport, req: FastifyRequest) => void;
150
+ reportOnly?: boolean;
151
+ };
152
+ };
153
+ };
154
+ type AppRoute = Omit<Route<PathToRegExpParams>, 'appId'> & {
155
+ attr?: RouteAttributes<PathToRegExpParams>;
156
+ };
157
+ type AppConfig = {
158
+ appId: string;
159
+ entryPoint: string;
160
+ plugins?: PluginOption[];
161
+ routes?: AppRoute[];
162
+ };
163
+ type TaujsConfig = {
164
+ server?: {
165
+ host?: string;
166
+ port?: number;
167
+ hmrPort?: number;
168
+ };
169
+ security?: SecurityConfig;
170
+ apps: AppConfig[];
171
+ };
172
+
173
+ declare function defineConfig<T extends TaujsConfig>(config: T): T;
174
+
175
+ export { type AppConfig as A, type BaseLogger as B, type DebugConfig as D, type InitialRouteParams as I, type ServiceRegistry as S, type TaujsConfig as T, type SecurityConfig as a, type AppRoute as b, defineServiceRegistry as c, defineConfig as d, defineService as e };
@@ -0,0 +1,3 @@
1
+ import 'fastify';
2
+ import 'vite';
3
+ export { A as AppConfig, b as AppRoute, a as SecurityConfig, T as TaujsConfig, d as defineConfig, e as defineService, c as defineServiceRegistry } from './Config-LCDjtT9m.js';
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,25 +1,54 @@
1
- import { FastifyReply } from 'fastify';
2
- export { B as BaseMiddleware, C as Config, n as DataHandler, D as DataResult, G as GenericPlugin, I as InitialRouteParams, i as Manifest, M as ManifestEntry, N as NamedService, P as ProcessedConfig, g as RenderCallbacks, l as RenderModule, j as RenderSSR, k as RenderStream, R as Route, b as RouteAttributes, a as RouteParams, o as RoutePathsAndAttributes, h as SSRManifest, S as SSRServer, d as SSRServerOptions, m as ServiceCall, e as ServiceMethod, f as ServiceRegistry, T as TEMPLATE, c as createMaps, p as processConfigs } from './SSRServer-CbXIDaoA.js';
3
- import 'node:http';
1
+ import { FastifyPluginCallback, FastifyPluginAsync, FastifyInstance } from 'fastify';
2
+ import { T as TaujsConfig, S as ServiceRegistry, D as DebugConfig, B as BaseLogger, A as AppConfig } from './Config-LCDjtT9m.js';
3
+ export { I as InitialRouteParams } from './Config-LCDjtT9m.js';
4
4
  import 'vite';
5
- import './security/csp.js';
6
5
 
7
- declare module 'fastify' {
8
- interface FastifyRequest {
9
- cspNonce?: string;
10
- }
11
- interface FastifyInstance {
12
- /**
13
- * Optional authentication hook to be used by the taujs SSRServer.
14
- * This method must be decorated by the user when using auth middleware in `taujs.config.ts`.
15
- *
16
- * Example usage:
17
- * ```ts
18
- * fastify.decorate('authenticate', async function (req, reply) {
19
- * await req.jwtVerify();
20
- * });
21
- * ```
22
- */
23
- authenticate: (req: FastifyRequest, reply: FastifyReply) => Promise<void>;
24
- }
25
- }
6
+ type StaticMountEntry = {
7
+ plugin: FastifyPluginCallback<any> | FastifyPluginAsync<any>;
8
+ options?: Record<string, unknown>;
9
+ };
10
+ type StaticAssetsRegistration = false | StaticMountEntry | StaticMountEntry[];
11
+
12
+ type NetResolved = {
13
+ host: string;
14
+ port: number;
15
+ hmrPort: number;
16
+ };
17
+
18
+ type CreateServerOptions = {
19
+ config: TaujsConfig;
20
+ serviceRegistry: ServiceRegistry;
21
+ clientRoot?: string;
22
+ alias?: Record<string, string>;
23
+ fastify?: FastifyInstance;
24
+ debug?: DebugConfig;
25
+ logger?: BaseLogger;
26
+ staticAssets?: false | StaticAssetsRegistration;
27
+ port?: number;
28
+ };
29
+ type CreateServerResult = {
30
+ app?: FastifyInstance;
31
+ net: NetResolved;
32
+ };
33
+ declare const createServer: (opts: CreateServerOptions) => Promise<CreateServerResult>;
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 function taujsBuild({ config, projectRoot, clientBaseDir, isSSRBuild, }: {
46
+ config: {
47
+ apps: AppConfig[];
48
+ };
49
+ projectRoot: string;
50
+ clientBaseDir: string;
51
+ isSSRBuild?: boolean;
52
+ }): Promise<void>;
53
+
54
+ export { createServer, taujsBuild };