@nexus_js/server 0.9.28 → 0.9.29
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/actions.d.ts +11 -71
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +51 -442
- package/dist/actions.js.map +1 -1
- package/dist/context.d.ts +4 -38
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +3 -13
- package/dist/context.js.map +1 -1
- package/dist/csrf.d.ts +2 -16
- package/dist/csrf.d.ts.map +1 -1
- package/dist/csrf.js +30 -68
- package/dist/csrf.js.map +1 -1
- package/dist/dev-assets.d.ts +0 -31
- package/dist/dev-assets.d.ts.map +1 -1
- package/dist/dev-assets.js +38 -372
- package/dist/dev-assets.js.map +1 -1
- package/dist/dev-error-html.d.ts.map +1 -1
- package/dist/dev-error-html.js +0 -24
- package/dist/dev-error-html.js.map +1 -1
- package/dist/devradar.d.ts +1 -1
- package/dist/devradar.d.ts.map +1 -1
- package/dist/devradar.js.map +1 -1
- package/dist/index.d.ts +2 -97
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -442
- package/dist/index.js.map +1 -1
- package/dist/load-module.d.ts +0 -6
- package/dist/load-module.d.ts.map +1 -1
- package/dist/load-module.js +53 -40
- package/dist/load-module.js.map +1 -1
- package/dist/navigate.d.ts +5 -0
- package/dist/navigate.d.ts.map +1 -1
- package/dist/navigate.js +1 -0
- package/dist/navigate.js.map +1 -1
- package/dist/rate-limit.d.ts.map +1 -1
- package/dist/rate-limit.js +14 -27
- package/dist/rate-limit.js.map +1 -1
- package/dist/renderer.d.ts +7 -27
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +25 -152
- package/dist/renderer.js.map +1 -1
- package/dist/streaming.d.ts +3 -3
- package/dist/streaming.d.ts.map +1 -1
- package/dist/streaming.js +13 -33
- package/dist/streaming.js.map +1 -1
- package/package.json +8 -26
- package/dist/build-id.d.ts +0 -14
- package/dist/build-id.d.ts.map +0 -1
- package/dist/build-id.js +0 -40
- package/dist/build-id.js.map +0 -1
- package/dist/dev-assets.test.d.ts +0 -2
- package/dist/dev-assets.test.d.ts.map +0 -1
- package/dist/head-renderer.test.d.ts +0 -2
- package/dist/head-renderer.test.d.ts.map +0 -1
- package/dist/head-renderer.test.js +0 -78
- package/dist/head-renderer.test.js.map +0 -1
- package/dist/legacy-wrapper.d.ts +0 -88
- package/dist/legacy-wrapper.d.ts.map +0 -1
- package/dist/legacy-wrapper.js +0 -104
- package/dist/legacy-wrapper.js.map +0 -1
- package/dist/lib-assets.d.ts +0 -5
- package/dist/lib-assets.d.ts.map +0 -1
- package/dist/lib-assets.js +0 -95
- package/dist/lib-assets.js.map +0 -1
- package/dist/metadata.d.ts +0 -95
- package/dist/metadata.d.ts.map +0 -1
- package/dist/metadata.js +0 -132
- package/dist/metadata.js.map +0 -1
- package/dist/renderer.test.d.ts +0 -2
- package/dist/renderer.test.d.ts.map +0 -1
- package/dist/renderer.test.js +0 -251
- package/dist/renderer.test.js.map +0 -1
- package/dist/tenancy.d.ts +0 -17
- package/dist/tenancy.d.ts.map +0 -1
- package/dist/tenancy.js +0 -132
- package/dist/tenancy.js.map +0 -1
- package/dist/tenancy.test.d.ts +0 -2
- package/dist/tenancy.test.d.ts.map +0 -1
- package/dist/tenancy.test.js +0 -38
- package/dist/tenancy.test.js.map +0 -1
package/dist/build-id.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Production build identifier — written by `nexus build` to `.nexus/build-id.json`.
|
|
3
|
-
* Server and browser must agree on this value so stale tabs can be rejected with 412.
|
|
4
|
-
*/
|
|
5
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
-
import { join } from 'node:path';
|
|
7
|
-
let cached;
|
|
8
|
-
/**
|
|
9
|
-
* Reads `.nexus/build-id.json` once and caches the result.
|
|
10
|
-
* Returns `null` if the file is missing (dev without prior build, or legacy deploy).
|
|
11
|
-
*/
|
|
12
|
-
export function loadAndCacheNexusBuildId(appRoot) {
|
|
13
|
-
if (cached !== undefined)
|
|
14
|
-
return cached;
|
|
15
|
-
const p = join(appRoot, '.nexus', 'build-id.json');
|
|
16
|
-
try {
|
|
17
|
-
if (!existsSync(p)) {
|
|
18
|
-
cached = null;
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
const raw = readFileSync(p, 'utf-8');
|
|
22
|
-
const j = JSON.parse(raw);
|
|
23
|
-
const id = j.buildId;
|
|
24
|
-
cached =
|
|
25
|
-
typeof id === 'string' && id.length > 0 && id.length <= 256 ? id : null;
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
cached = null;
|
|
29
|
-
}
|
|
30
|
-
return cached;
|
|
31
|
-
}
|
|
32
|
-
/** Cached build id after {@link loadAndCacheNexusBuildId}; `null` if none loaded. */
|
|
33
|
-
export function getExpectedNexusBuildId() {
|
|
34
|
-
return cached ?? null;
|
|
35
|
-
}
|
|
36
|
-
/** Test hook */
|
|
37
|
-
export function resetNexusBuildIdCache() {
|
|
38
|
-
cached = undefined;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=build-id.js.map
|
package/dist/build-id.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-id.js","sourceRoot":"","sources":["../src/build-id.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,IAAI,MAAiC,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAe;IACtD,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;IACnD,IAAI,CAAC;QACH,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;YACnB,MAAM,GAAG,IAAI,CAAC;YACd,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACrC,MAAM,CAAC,GAAK,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;QACpD,MAAM,EAAE,GAAI,CAAC,CAAC,OAAO,CAAC;QACtB,MAAM;YACJ,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5E,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,uBAAuB;IACrC,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,sBAAsB;IACpC,MAAM,GAAG,SAAS,CAAC;AACrB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev-assets.test.d.ts","sourceRoot":"","sources":["../src/dev-assets.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"head-renderer.test.d.ts","sourceRoot":"","sources":["../src/head-renderer.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import { defineHead, flushHead, renderHeadToString } from '@nexus_js/head';
|
|
3
|
-
// Minimal mock context with head stack
|
|
4
|
-
function makeCtx() {
|
|
5
|
-
return {
|
|
6
|
-
request: new Request('http://example.com/'),
|
|
7
|
-
params: {},
|
|
8
|
-
url: new URL('http://example.com/'),
|
|
9
|
-
headers: new Headers(),
|
|
10
|
-
locals: {},
|
|
11
|
-
secrets: new Map(),
|
|
12
|
-
cspNonce: '',
|
|
13
|
-
setHeader: () => { },
|
|
14
|
-
setCookie: () => { },
|
|
15
|
-
getCookie: () => undefined,
|
|
16
|
-
redirect: (() => { throw new Error('redirect'); }),
|
|
17
|
-
notFound: (() => { throw new Error('notfound'); }),
|
|
18
|
-
__nexusHeadStack: [],
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
describe('SEO/Metadata head integration (renderer path)', () => {
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
// ensure clean global (though we prefer ctx)
|
|
24
|
-
flushHead();
|
|
25
|
-
});
|
|
26
|
-
it('defineHead with ctx stores per-request (isolated)', () => {
|
|
27
|
-
const ctx1 = makeCtx();
|
|
28
|
-
const ctx2 = makeCtx();
|
|
29
|
-
defineHead({ title: 'Page One' }, ctx1);
|
|
30
|
-
defineHead({ title: 'Page Two' }, ctx2);
|
|
31
|
-
const flushed1 = flushHead(ctx1);
|
|
32
|
-
const flushed2 = flushHead(ctx2);
|
|
33
|
-
expect(flushed1).toHaveLength(1);
|
|
34
|
-
expect(flushed1[0].title).toBe('Page One');
|
|
35
|
-
expect(flushed2).toHaveLength(1);
|
|
36
|
-
expect(flushed2[0].title).toBe('Page Two');
|
|
37
|
-
});
|
|
38
|
-
it('flushHead clears the stack for that ctx', () => {
|
|
39
|
-
const ctx = makeCtx();
|
|
40
|
-
defineHead({ title: 'Once' }, ctx);
|
|
41
|
-
const first = flushHead(ctx);
|
|
42
|
-
const second = flushHead(ctx);
|
|
43
|
-
expect(first).toHaveLength(1);
|
|
44
|
-
expect(second).toHaveLength(0);
|
|
45
|
-
});
|
|
46
|
-
it('renderHeadToString produces safe <title> and og tags with escaping', () => {
|
|
47
|
-
const metas = [
|
|
48
|
-
{ title: 'Hello <World>', description: 'A "test" & more' },
|
|
49
|
-
{ og: { image: 'https://ex.com/img.png?x=1&y=2' } },
|
|
50
|
-
];
|
|
51
|
-
const html = renderHeadToString(metas);
|
|
52
|
-
expect(html).toContain('Hello <World>'); // < escaped to <, > left as-is (perfectly valid)
|
|
53
|
-
expect(html).toContain('og:title');
|
|
54
|
-
expect(html).toContain('og:image');
|
|
55
|
-
expect(html).not.toContain('<World>'); // XSS prevented
|
|
56
|
-
expect(html).toContain('&'); // description escaped
|
|
57
|
-
});
|
|
58
|
-
it('head from load() result shape is what the renderer expects (smoke)', () => {
|
|
59
|
-
// Simulates what mergeRoutePretext does
|
|
60
|
-
const ctx = makeCtx();
|
|
61
|
-
const loadResult = {
|
|
62
|
-
title: 'from pretext',
|
|
63
|
-
head: { title: 'From load head', description: 'SEO rocks' },
|
|
64
|
-
};
|
|
65
|
-
// The actual interception code (copied logic for test)
|
|
66
|
-
if (loadResult && typeof loadResult === 'object' && 'head' in loadResult) {
|
|
67
|
-
const h = loadResult.head;
|
|
68
|
-
if (h)
|
|
69
|
-
defineHead(h, ctx);
|
|
70
|
-
delete loadResult.head;
|
|
71
|
-
}
|
|
72
|
-
expect('head' in loadResult).toBe(false); // removed before pretext merge
|
|
73
|
-
const flushed = flushHead(ctx);
|
|
74
|
-
expect(flushed[0]?.title).toBe('From load head');
|
|
75
|
-
expect(flushed[0]?.description).toBe('SEO rocks');
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
//# sourceMappingURL=head-renderer.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"head-renderer.test.js","sourceRoot":"","sources":["../src/head-renderer.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAG3E,uCAAuC;AACvC,SAAS,OAAO;IACd,OAAO;QACL,OAAO,EAAE,IAAI,OAAO,CAAC,qBAAqB,CAAC;QAC3C,MAAM,EAAE,EAAE;QACV,GAAG,EAAE,IAAI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O,CAAC,CAAC,CAAC,sBAAsB;IACzD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oEAAoE,EAAE,GAAG,EAAE;QAC5E,wCAAwC;QACxC,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;QACtB,MAAM,UAAU,GAAG;YACjB,KAAK,EAAE,cAAc;YACrB,IAAI,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE;SAC5D,CAAC;QAEF,uDAAuD;QACvD,IAAI,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,MAAM,IAAI,UAAU,EAAE,CAAC;YACzE,MAAM,CAAC,GAAI,UAAkB,CAAC,IAAI,CAAC;YACnC,IAAI,CAAC;gBAAE,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAC1B,OAAQ,UAAkB,CAAC,IAAI,CAAC;QAClC,CAAC;QAED,MAAM,CAAC,MAAM,IAAI,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,+BAA+B;QACzE,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACjD,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/legacy-wrapper.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @nexus_js/server - Legacy Action Wrapper
|
|
3
|
-
*
|
|
4
|
-
* Wrap Express/Connect middleware and route handlers as Nexus Server Actions.
|
|
5
|
-
* Use this to migrate existing business logic incrementally.
|
|
6
|
-
*/
|
|
7
|
-
import type { NexusContext } from './context.js';
|
|
8
|
-
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
9
|
-
export type ExpressMiddleware = (req: IncomingMessage & {
|
|
10
|
-
body?: unknown;
|
|
11
|
-
params?: Record<string, string>;
|
|
12
|
-
}, res: ServerResponse & {
|
|
13
|
-
json?: (data: unknown) => void;
|
|
14
|
-
status?: (code: number) => ServerResponse;
|
|
15
|
-
}, next: (err?: unknown) => void) => void;
|
|
16
|
-
/**
|
|
17
|
-
* Wrap an Express/Connect middleware as a Nexus Server Action.
|
|
18
|
-
*
|
|
19
|
-
* The middleware's `req.body` is populated from the FormData/JSON action payload.
|
|
20
|
-
* The middleware's `res.json(data)` returns `{ data }` to the client.
|
|
21
|
-
* Calling `next(err)` returns `{ error: err.message, status: 500 }`.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* // Old Express route:
|
|
26
|
-
* app.post('/api/legacy-payment', legacyPaymentMiddleware);
|
|
27
|
-
*
|
|
28
|
-
* // Wrap as Nexus action:
|
|
29
|
-
* export const legacyPayment = wrapExpressMiddleware(legacyPaymentMiddleware);
|
|
30
|
-
*
|
|
31
|
-
* // Now callable from Nexus:
|
|
32
|
-
* <form method="post" action="/_nexus/action/legacyPayment">
|
|
33
|
-
* <input name="amount" />
|
|
34
|
-
* <button type="submit">Pay</button>
|
|
35
|
-
* </form>
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function wrapExpressMiddleware(middleware: ExpressMiddleware): (formData: FormData, ctx: NexusContext) => Promise<{
|
|
39
|
-
error: string;
|
|
40
|
-
status: number;
|
|
41
|
-
data?: never;
|
|
42
|
-
} | {
|
|
43
|
-
data: {};
|
|
44
|
-
error?: never;
|
|
45
|
-
status?: never;
|
|
46
|
-
} | {
|
|
47
|
-
error?: never;
|
|
48
|
-
status?: never;
|
|
49
|
-
data?: never;
|
|
50
|
-
}>;
|
|
51
|
-
/**
|
|
52
|
-
* Wrap a callback-style Express route handler as a Nexus Server Action.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```ts
|
|
56
|
-
* // Old Express route:
|
|
57
|
-
* app.get('/api/users/:id', (req, res) => {
|
|
58
|
-
* const user = db.users.find(req.params.id);
|
|
59
|
-
* res.json({ user });
|
|
60
|
-
* });
|
|
61
|
-
*
|
|
62
|
-
* // Wrap as Nexus action:
|
|
63
|
-
* export const getUser = wrapExpressHandler((req, res) => {
|
|
64
|
-
* const user = db.users.find(req.params.id);
|
|
65
|
-
* res.json({ user });
|
|
66
|
-
* });
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
export declare function wrapExpressHandler(handler: (req: IncomingMessage & {
|
|
70
|
-
body?: unknown;
|
|
71
|
-
params?: Record<string, string>;
|
|
72
|
-
}, res: ServerResponse & {
|
|
73
|
-
json?: (data: unknown) => void;
|
|
74
|
-
status?: (code: number) => ServerResponse;
|
|
75
|
-
}) => void | Promise<void>): (formData: FormData, ctx: NexusContext) => Promise<{
|
|
76
|
-
error: string;
|
|
77
|
-
status: number;
|
|
78
|
-
data?: never;
|
|
79
|
-
} | {
|
|
80
|
-
data: {};
|
|
81
|
-
error?: never;
|
|
82
|
-
status?: never;
|
|
83
|
-
} | {
|
|
84
|
-
error?: never;
|
|
85
|
-
status?: never;
|
|
86
|
-
data?: never;
|
|
87
|
-
}>;
|
|
88
|
-
//# sourceMappingURL=legacy-wrapper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"legacy-wrapper.d.ts","sourceRoot":"","sources":["../src/legacy-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GAAG,CAC9B,GAAG,EAAE,eAAe,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,EAC1E,GAAG,EAAE,cAAc,GAAG;IACpB,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/B,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,cAAc,CAAC;CAC3C,EACD,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,KAC1B,IAAI,CAAC;AAEV;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,iBAAiB,IAC7B,UAAU,QAAQ,EAAE,KAAK,YAAY;;;;;;;;;;;;GA+D1E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,CACP,GAAG,EAAE,eAAe,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,EAC1E,GAAG,EAAE,cAAc,GAAG;IAAE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,cAAc,CAAA;CAAE,KAChG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,cAvFqB,QAAQ,OAAO,YAAY;;;;;;;;;;;;GA+F1E"}
|
package/dist/legacy-wrapper.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @nexus_js/server - Legacy Action Wrapper
|
|
3
|
-
*
|
|
4
|
-
* Wrap Express/Connect middleware and route handlers as Nexus Server Actions.
|
|
5
|
-
* Use this to migrate existing business logic incrementally.
|
|
6
|
-
*/
|
|
7
|
-
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
8
|
-
/**
|
|
9
|
-
* Wrap an Express/Connect middleware as a Nexus Server Action.
|
|
10
|
-
*
|
|
11
|
-
* The middleware's `req.body` is populated from the FormData/JSON action payload.
|
|
12
|
-
* The middleware's `res.json(data)` returns `{ data }` to the client.
|
|
13
|
-
* Calling `next(err)` returns `{ error: err.message, status: 500 }`.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* // Old Express route:
|
|
18
|
-
* app.post('/api/legacy-payment', legacyPaymentMiddleware);
|
|
19
|
-
*
|
|
20
|
-
* // Wrap as Nexus action:
|
|
21
|
-
* export const legacyPayment = wrapExpressMiddleware(legacyPaymentMiddleware);
|
|
22
|
-
*
|
|
23
|
-
* // Now callable from Nexus:
|
|
24
|
-
* <form method="post" action="/_nexus/action/legacyPayment">
|
|
25
|
-
* <input name="amount" />
|
|
26
|
-
* <button type="submit">Pay</button>
|
|
27
|
-
* </form>
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export function wrapExpressMiddleware(middleware) {
|
|
31
|
-
return async function wrappedAction(formData, ctx) {
|
|
32
|
-
// Build a mock Express req/res
|
|
33
|
-
const mockReq = Object.assign(Object.create(IncomingMessage.prototype), {
|
|
34
|
-
body: Object.fromEntries(formData.entries()),
|
|
35
|
-
params: ctx.params,
|
|
36
|
-
headers: Object.fromEntries(ctx.request?.headers?.entries() ?? []),
|
|
37
|
-
method: 'POST',
|
|
38
|
-
url: ctx.request?.url ?? '/_nexus/action',
|
|
39
|
-
});
|
|
40
|
-
let responseData = null;
|
|
41
|
-
let responseStatus = 200;
|
|
42
|
-
let errorMessage = null;
|
|
43
|
-
const mockRes = Object.assign(Object.create(ServerResponse.prototype), {
|
|
44
|
-
json: (data) => {
|
|
45
|
-
responseData = data;
|
|
46
|
-
},
|
|
47
|
-
status: (code) => {
|
|
48
|
-
responseStatus = code;
|
|
49
|
-
return mockRes;
|
|
50
|
-
},
|
|
51
|
-
writeHead: () => { },
|
|
52
|
-
end: () => { },
|
|
53
|
-
});
|
|
54
|
-
const next = (err) => {
|
|
55
|
-
if (err) {
|
|
56
|
-
errorMessage = err instanceof Error ? err.message : String(err);
|
|
57
|
-
responseStatus = 500;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
// Run middleware
|
|
61
|
-
try {
|
|
62
|
-
await new Promise((resolve) => {
|
|
63
|
-
middleware(mockReq, mockRes, (err) => {
|
|
64
|
-
next(err);
|
|
65
|
-
resolve();
|
|
66
|
-
});
|
|
67
|
-
// If middleware doesn't call next, assume success after microtask
|
|
68
|
-
queueMicrotask(resolve);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
catch (err) {
|
|
72
|
-
errorMessage = err instanceof Error ? err.message : String(err);
|
|
73
|
-
responseStatus = 500;
|
|
74
|
-
}
|
|
75
|
-
if (errorMessage) {
|
|
76
|
-
return { error: errorMessage, status: responseStatus };
|
|
77
|
-
}
|
|
78
|
-
return responseData ? { data: responseData } : {};
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Wrap a callback-style Express route handler as a Nexus Server Action.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```ts
|
|
86
|
-
* // Old Express route:
|
|
87
|
-
* app.get('/api/users/:id', (req, res) => {
|
|
88
|
-
* const user = db.users.find(req.params.id);
|
|
89
|
-
* res.json({ user });
|
|
90
|
-
* });
|
|
91
|
-
*
|
|
92
|
-
* // Wrap as Nexus action:
|
|
93
|
-
* export const getUser = wrapExpressHandler((req, res) => {
|
|
94
|
-
* const user = db.users.find(req.params.id);
|
|
95
|
-
* res.json({ user });
|
|
96
|
-
* });
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export function wrapExpressHandler(handler) {
|
|
100
|
-
return wrapExpressMiddleware((req, res, next) => {
|
|
101
|
-
Promise.resolve(handler(req, res)).then(() => next(), (err) => next(err));
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
//# sourceMappingURL=legacy-wrapper.js.map
|
|
@@ -1 +0,0 @@
|
|
|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GAAG,CAAC,CAAC,CAAC,IAAI,CACrC,GAAG,EAAE,CAAC,IAAI,EAAE,EACZ,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CACnB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/lib-assets.d.ts
DELETED
package/dist/lib-assets.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib-assets.d.ts","sourceRoot":"","sources":["../src/lib-assets.ts"],"names":[],"mappings":"AAwCA,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,OAAO,GACX,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CA8CvD"}
|
package/dist/lib-assets.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { readFile, stat } from 'node:fs/promises';
|
|
4
|
-
import { join, normalize, relative, resolve, sep } from 'node:path';
|
|
5
|
-
const LIB_PREFIX = '/_nexus/lib/';
|
|
6
|
-
function isSafeUnderRoot(root, file) {
|
|
7
|
-
const rel = relative(root, resolve(file));
|
|
8
|
-
if (rel === '..')
|
|
9
|
-
return false;
|
|
10
|
-
if (rel.startsWith(`..${sep}`))
|
|
11
|
-
return false;
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
function isDeniedLibPath(rel) {
|
|
15
|
-
const norm = rel.replace(/\\/g, '/');
|
|
16
|
-
if (norm.includes('/server/'))
|
|
17
|
-
return true;
|
|
18
|
-
if (norm.endsWith('.server.js'))
|
|
19
|
-
return true;
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
function transpileTsToEsm(source) {
|
|
23
|
-
const compilerOptions = {
|
|
24
|
-
target: ts.ScriptTarget.ESNext,
|
|
25
|
-
module: ts.ModuleKind.ESNext,
|
|
26
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
27
|
-
experimentalDecorators: true,
|
|
28
|
-
useDefineForClassFields: true,
|
|
29
|
-
verbatimModuleSyntax: false,
|
|
30
|
-
isolatedModules: true,
|
|
31
|
-
declaration: false,
|
|
32
|
-
};
|
|
33
|
-
let js = ts.transpileModule(source, { compilerOptions }).outputText;
|
|
34
|
-
// Bundler resolution keeps .ts extensions in relative imports.
|
|
35
|
-
// Rewrite them to .js so the browser can resolve them at runtime.
|
|
36
|
-
js = js.replace(/from\s+(['"])\.([^'"]+)\.tsx?\1/g, 'from $1.$2.js$1');
|
|
37
|
-
js = js.replace(/import\s+(['"])\.([^'"]+)\.tsx?\1/g, 'import $1.$2.js$1');
|
|
38
|
-
return js;
|
|
39
|
-
}
|
|
40
|
-
export async function tryServeLibAsset(pathname, appRoot, dev) {
|
|
41
|
-
if (!pathname.startsWith(LIB_PREFIX))
|
|
42
|
-
return null;
|
|
43
|
-
const rel = pathname.slice(LIB_PREFIX.length);
|
|
44
|
-
if (!rel)
|
|
45
|
-
return null;
|
|
46
|
-
if (rel.includes('..'))
|
|
47
|
-
return null;
|
|
48
|
-
if (!/^[\w./-]+\.js$/u.test(rel))
|
|
49
|
-
return null;
|
|
50
|
-
if (isDeniedLibPath(rel))
|
|
51
|
-
return null;
|
|
52
|
-
const outRoot = resolve(join(appRoot, '.nexus', 'lib'));
|
|
53
|
-
const outFile = resolve(join(outRoot, normalize(rel)));
|
|
54
|
-
if (!isSafeUnderRoot(outRoot, outFile))
|
|
55
|
-
return null;
|
|
56
|
-
try {
|
|
57
|
-
const s = await stat(outFile);
|
|
58
|
-
if (!s.isFile())
|
|
59
|
-
return null;
|
|
60
|
-
const body = await readFile(outFile);
|
|
61
|
-
return { body, contentType: 'application/javascript; charset=utf-8' };
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
/* not found */
|
|
65
|
-
}
|
|
66
|
-
if (!dev)
|
|
67
|
-
return null;
|
|
68
|
-
const srcRoot = resolve(join(appRoot, 'src', 'lib'));
|
|
69
|
-
const tryFiles = [
|
|
70
|
-
resolve(join(srcRoot, normalize(rel.replace(/\.js$/u, '.ts')))),
|
|
71
|
-
resolve(join(srcRoot, normalize(rel.replace(/\.js$/u, '.tsx')))),
|
|
72
|
-
resolve(join(srcRoot, normalize(rel.replace(/\.js$/u, '.mts')))),
|
|
73
|
-
];
|
|
74
|
-
for (const f of tryFiles) {
|
|
75
|
-
if (!isSafeUnderRoot(srcRoot, f))
|
|
76
|
-
continue;
|
|
77
|
-
if (isDeniedLibPath(relative(srcRoot, f).replace(/\\/g, '/')))
|
|
78
|
-
continue;
|
|
79
|
-
if (!existsSync(f))
|
|
80
|
-
continue;
|
|
81
|
-
try {
|
|
82
|
-
const s = await stat(f);
|
|
83
|
-
if (!s.isFile())
|
|
84
|
-
continue;
|
|
85
|
-
const source = await readFile(f, 'utf-8');
|
|
86
|
-
const js = transpileTsToEsm(source);
|
|
87
|
-
return { body: Buffer.from(js, 'utf-8'), contentType: 'application/javascript; charset=utf-8' };
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=lib-assets.js.map
|
package/dist/lib-assets.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib-assets.js","sourceRoot":"","sources":["../src/lib-assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEpE,MAAM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,CAAC;AACd,CAAC"}
|
package/dist/metadata.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Nexus Metadata API — type-safe, XSS-safe `<head>` metadata for .nx pages.
|
|
3
|
-
*
|
|
4
|
-
* Usage in a page or layout frontmatter (server block):
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* export const nxPretext = async (ctx) => {
|
|
8
|
-
* return {
|
|
9
|
-
* meta: defineMetadata({
|
|
10
|
-
* title: ctx.params.name + ' — My App',
|
|
11
|
-
* description: 'Profile page for ' + ctx.params.name,
|
|
12
|
-
* og: { image: 'https://cdn.example.com/og.png' },
|
|
13
|
-
* }),
|
|
14
|
-
* };
|
|
15
|
-
* };
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* In the layout template:
|
|
19
|
-
*
|
|
20
|
-
* ```html
|
|
21
|
-
* <head>
|
|
22
|
-
* {{{ pretext.meta?.html ?? '' }}}
|
|
23
|
-
* </head>
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* All dynamic values are HTML-escaped before injection to prevent XSS via
|
|
27
|
-
* user-controlled title / description strings.
|
|
28
|
-
*/
|
|
29
|
-
export interface MetadataInput {
|
|
30
|
-
/** Page title — becomes `<title>` and `og:title`. */
|
|
31
|
-
title?: string;
|
|
32
|
-
/** Short description — becomes `<meta name="description">` and `og:description`. */
|
|
33
|
-
description?: string;
|
|
34
|
-
/** Canonical URL for this page. */
|
|
35
|
-
canonical?: string;
|
|
36
|
-
/** Robots directive (default: 'index, follow'). */
|
|
37
|
-
robots?: string;
|
|
38
|
-
/** Open Graph fields. */
|
|
39
|
-
og?: {
|
|
40
|
-
title?: string;
|
|
41
|
-
description?: string;
|
|
42
|
-
image?: string;
|
|
43
|
-
type?: string;
|
|
44
|
-
url?: string;
|
|
45
|
-
siteName?: string;
|
|
46
|
-
};
|
|
47
|
-
/** Twitter card fields. */
|
|
48
|
-
twitter?: {
|
|
49
|
-
card?: 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
50
|
-
title?: string;
|
|
51
|
-
description?: string;
|
|
52
|
-
image?: string;
|
|
53
|
-
creator?: string;
|
|
54
|
-
site?: string;
|
|
55
|
-
};
|
|
56
|
-
/** Arbitrary additional `<meta>` tags. */
|
|
57
|
-
extra?: Array<{
|
|
58
|
-
name?: string;
|
|
59
|
-
property?: string;
|
|
60
|
-
content: string;
|
|
61
|
-
}>;
|
|
62
|
-
}
|
|
63
|
-
export interface MetadataResult {
|
|
64
|
-
/** Raw HTML string safe for injection into `<head>`. All values are escaped. */
|
|
65
|
-
html: string;
|
|
66
|
-
/** Original input (for programmatic access). */
|
|
67
|
-
input: MetadataInput;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Escapes a string for safe use inside HTML attribute values and text content.
|
|
71
|
-
* Prevents XSS when injecting user-controlled strings into `<meta>` tags.
|
|
72
|
-
*/
|
|
73
|
-
export declare function escapeHtml(value: string): string;
|
|
74
|
-
/**
|
|
75
|
-
* Builds XSS-safe `<head>` metadata from a typed descriptor.
|
|
76
|
-
*
|
|
77
|
-
* @deprecated Use `defineHead()` from `@nexus_js/head` instead. It now auto-injects
|
|
78
|
-
* during SSR when used in `load()` or server blocks. This function is kept for
|
|
79
|
-
* backward compatibility but will be removed in a future major release.
|
|
80
|
-
*
|
|
81
|
-
* @returns `MetadataResult` — inject `.html` into your layout's `<head>`.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* const meta = defineMetadata({
|
|
86
|
-
* title: 'My Page',
|
|
87
|
-
* description: 'Welcome to my site',
|
|
88
|
-
* og: { image: 'https://cdn.example.com/og.png', type: 'website' },
|
|
89
|
-
* twitter: { card: 'summary_large_image', creator: '@myhandle' },
|
|
90
|
-
* });
|
|
91
|
-
* // meta.html → safe HTML string for <head>
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
export declare function defineMetadata(input: MetadataInput): MetadataResult;
|
|
95
|
-
//# sourceMappingURL=metadata.d.ts.map
|
package/dist/metadata.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,EAAE,CAAC,EAAE;QACH,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,2BAA2B;IAC3B,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,SAAS,GAAG,qBAAqB,GAAG,KAAK,GAAG,QAAQ,CAAC;QAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,0CAA0C;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,cAAc;IAC7B,gFAAgF;IAChF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