@pexis/core 0.1.1 → 0.1.3
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/AGENTS.md +65 -15
- package/API.md +11 -8
- package/README.md +1 -1
- package/api.json +5951 -0
- package/dist/app.d.ts +77 -3
- package/dist/app.js +284 -38
- package/dist/app.js.map +1 -1
- package/dist/components.d.ts +100 -6
- package/dist/components.js +87 -19
- package/dist/components.js.map +1 -1
- package/dist/context.d.ts +27 -2
- package/dist/context.js +18 -2
- package/dist/context.js.map +1 -1
- package/dist/cors.d.ts +14 -0
- package/dist/cors.js +8 -0
- package/dist/cors.js.map +1 -1
- package/dist/csrf.d.ts +9 -0
- package/dist/csrf.js +9 -0
- package/dist/csrf.js.map +1 -1
- package/dist/form.d.ts +21 -3
- package/dist/form.js +38 -4
- package/dist/form.js.map +1 -1
- package/dist/host.d.ts +6 -1
- package/dist/host.js +6 -1
- package/dist/host.js.map +1 -1
- package/dist/html.d.ts +46 -5
- package/dist/html.js +112 -5
- package/dist/html.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime.d.ts +32 -0
- package/dist/jsx-runtime.js +16 -0
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/page.d.ts +74 -1
- package/dist/page.js +48 -5
- package/dist/page.js.map +1 -1
- package/dist/rate-limit.d.ts +46 -0
- package/dist/rate-limit.js +19 -0
- package/dist/rate-limit.js.map +1 -1
- package/dist/registry.d.ts +126 -3
- package/dist/registry.js +53 -1
- package/dist/registry.js.map +1 -1
- package/dist/schema.d.ts +129 -3
- package/dist/schema.js +80 -7
- package/dist/schema.js.map +1 -1
- package/dist/security.d.ts +38 -2
- package/dist/security.js +44 -9
- package/dist/security.js.map +1 -1
- package/dist/styles.d.ts +37 -2
- package/dist/styles.js +32 -2
- package/dist/styles.js.map +1 -1
- package/dist/types.d.ts +163 -19
- package/dist/urls.d.ts +8 -1
- package/dist/urls.js +8 -1
- package/dist/urls.js.map +1 -1
- package/package.json +2 -1
package/dist/context.js
CHANGED
|
@@ -23,11 +23,20 @@ function storage() {
|
|
|
23
23
|
holder[KEY] = detect();
|
|
24
24
|
return holder[KEY] ?? null;
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Installs request context storage, replacing the detected one. Pass null to turn it off.
|
|
28
|
+
*
|
|
29
|
+
* @category plugins
|
|
30
|
+
* @param next The storage, or null.
|
|
31
|
+
*/
|
|
27
32
|
export function setContextStorage(next) {
|
|
28
33
|
holder[KEY] = next;
|
|
29
34
|
}
|
|
30
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* The current request's context, or undefined outside a request. Never throws.
|
|
37
|
+
*
|
|
38
|
+
* @category plugins
|
|
39
|
+
*/
|
|
31
40
|
export function peekContext() {
|
|
32
41
|
return storage()?.get();
|
|
33
42
|
}
|
|
@@ -35,6 +44,13 @@ export function peekContext() {
|
|
|
35
44
|
export function hasContextStorage() {
|
|
36
45
|
return storage() !== null;
|
|
37
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Runs fn with ctx as the current request's context, so getContext() finds it.
|
|
49
|
+
*
|
|
50
|
+
* @category plugins
|
|
51
|
+
* @param ctx The request's context.
|
|
52
|
+
* @param fn The work to run in it.
|
|
53
|
+
*/
|
|
38
54
|
export function runWithContext(ctx, fn) {
|
|
39
55
|
const s = storage();
|
|
40
56
|
return s ? s.run(ctx, fn) : fn();
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,6DAA6D;AAC7D,EAAE;AACF,6EAA6E;AAC7E,sEAAsE;AACtE,4EAA4E;AAC5E,2EAA2E;AAC3E,uEAAuE;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings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;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAI,GAAY,EAAE,EAAW;IACzD,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,IAAI,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,IAAI,KAAK,CACb,oMAAoM,CACrM,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACpB,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,sLAAsL,CACvL,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/cors.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-origin access to the API (action endpoints, `/pexis/actions.json`,
|
|
3
|
+
* `/pexis/openapi.json`), for createApp({ security: { cors } }). Pages are never shared.
|
|
4
|
+
*
|
|
5
|
+
* @category plugins
|
|
6
|
+
*/
|
|
1
7
|
export interface CorsOptions {
|
|
2
8
|
/** Origins allowed to call the API from a browser, such as "https://app.example.com", or "*" for read-only access from anywhere. */
|
|
3
9
|
origins: string[];
|
|
@@ -16,4 +22,12 @@ export interface Cors {
|
|
|
16
22
|
/** Origins that may also send state-changing requests, for the CSRF check. */
|
|
17
23
|
writers: readonly string[];
|
|
18
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* CORS for the API surface: answers preflights and adds headers for allowed
|
|
27
|
+
* origins. Throws for a configuration that would be unsafe, such as cookies
|
|
28
|
+
* with "*".
|
|
29
|
+
*
|
|
30
|
+
* @category plugins
|
|
31
|
+
* @param options The allowed origins and settings.
|
|
32
|
+
*/
|
|
19
33
|
export declare function createCors(options: CorsOptions): Cors;
|
package/dist/cors.js
CHANGED
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
// - Only the Content-Type and Accept request headers are allowed.
|
|
9
9
|
const API_PATH = /^\/(?:actions\/[a-z][a-z0-9_]{0,63}|pexis\/actions\.json|pexis\/openapi\.json)$/;
|
|
10
10
|
const ALLOWED_HEADERS = ['content-type', 'accept'];
|
|
11
|
+
/**
|
|
12
|
+
* CORS for the API surface: answers preflights and adds headers for allowed
|
|
13
|
+
* origins. Throws for a configuration that would be unsafe, such as cookies
|
|
14
|
+
* with "*".
|
|
15
|
+
*
|
|
16
|
+
* @category plugins
|
|
17
|
+
* @param options The allowed origins and settings.
|
|
18
|
+
*/
|
|
11
19
|
export function createCors(options) {
|
|
12
20
|
const credentials = options.credentials === true;
|
|
13
21
|
const wildcard = options.origins.includes('*');
|
package/dist/cors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0EAA0E;AAC1E,EAAE;AACF,SAAS;AACT,+DAA+D;AAC/D,6EAA6E;AAC7E,2EAA2E;AAC3E,kEAAkE;
|
|
1
|
+
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0EAA0E;AAC1E,EAAE;AACF,SAAS;AACT,+DAA+D;AAC/D,6EAA6E;AAC7E,2EAA2E;AAC3E,kEAAkE;AA4BlE,MAAM,QAAQ,GAAG,iFAAiF,CAAC;AACnG,MAAM,eAAe,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,OAAoB;IAC7C,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,KAAK,IAAI,CAAC;IACjD,MAAM,QAAQ,GAAG,OAAO,C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CAAC,CAAC;YAC9C,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;gBACxC,IAAI,CAAC,KAAK,MAAM,EAAE,CAAC;oBACjB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;oBACpC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,UAAU,CAAC,CAAC,CAAC,OAAO,IAAI,QAAQ,CAAC,CAAC;gBAC5G,CAAC;;oBAAM,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC3B,CAAC;YACD,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5G,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/csrf.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CSRF check, with Fetch Metadata: a 403 response for a write from
|
|
3
|
+
* another site, or null when the request may go on. Forms need no tokens.
|
|
4
|
+
*
|
|
5
|
+
* @category plugins
|
|
6
|
+
* @param request The request.
|
|
7
|
+
* @param url The request's URL.
|
|
8
|
+
* @param trusted Other origins allowed to send writes.
|
|
9
|
+
*/
|
|
1
10
|
export declare function crossSiteRefusal(request: Request, url: URL, trusted: ReadonlySet<string>): Response | null;
|
|
2
11
|
export declare function isSafeMethod(method: string): boolean;
|
package/dist/csrf.js
CHANGED
|
@@ -13,6 +13,15 @@
|
|
|
13
13
|
// victim's ambient cookies across sites. Refusing it would break agents,
|
|
14
14
|
// MCP clients and scripts. OWASP would refuse these too unless another
|
|
15
15
|
// defense applies; this is a deliberate difference (ARCHITECTURE.md).
|
|
16
|
+
/**
|
|
17
|
+
* The CSRF check, with Fetch Metadata: a 403 response for a write from
|
|
18
|
+
* another site, or null when the request may go on. Forms need no tokens.
|
|
19
|
+
*
|
|
20
|
+
* @category plugins
|
|
21
|
+
* @param request The request.
|
|
22
|
+
* @param url The request's URL.
|
|
23
|
+
* @param trusted Other origins allowed to send writes.
|
|
24
|
+
*/
|
|
16
25
|
export function crossSiteRefusal(request, url, trusted) {
|
|
17
26
|
const origin = request.headers.get('origin');
|
|
18
27
|
const allowed = origin !== null && (origin === url.origin || trusted.has(origin));
|
package/dist/csrf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csrf.js","sourceRoot":"","sources":["../src/csrf.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+EAA+E;AAC/E,6EAA6E;AAC7E,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,4BAA4B;AAC5B,8EAA8E;AAC9E,+DAA+D;AAC/D,6EAA6E;AAC7E,+EAA+E;AAC/E,2EAA2E;AAC3E,4EAA4E;AAC5E,0EAA0E;AAC1E,yEAAyE;AAEzE,MAAM,UAAU,gBAAgB,CAAC,OAAgB,EAAE,GAAQ,EAAE,OAA4B;IACvF,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAClF,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAEnD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,IAAI,IAAI,KAAK,aAAa,IAAI,IAAI,KAAK,MAAM,IAAI,OAAO;YAAE,OAAO,IAAI,CAAC;QACtE,OAAO,MAA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,GAAG;QACX,OAAO,EAAE,EAAE,cAAc,EAAE,2BAA2B,EAAE,IAAI,EAAE,wBAAwB,EAAE;KACzF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,SAAS,CAAC;AACvE,CAAC"}
|
package/dist/form.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { type SafeHtml } from './html.js';
|
|
2
2
|
import type { Action } from './registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* What a form shows besides its fields: the values sent and the errors, after a failed submission.
|
|
5
|
+
*
|
|
6
|
+
* @category plugins
|
|
7
|
+
*/
|
|
3
8
|
export interface FormState {
|
|
4
9
|
/** Values to show, for example after a failed submission. */
|
|
5
10
|
values?: Record<string, unknown>;
|
|
6
11
|
/** Error message per field name. */
|
|
7
12
|
errors?: Record<string, string>;
|
|
8
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Where a form rendered with renderForm() submits, and how its ids are made.
|
|
16
|
+
*
|
|
17
|
+
* @category plugins
|
|
18
|
+
*/
|
|
9
19
|
export interface FormOptions {
|
|
10
20
|
/** Where the form submits. Defaults to /actions/<name>. */
|
|
11
21
|
url?: string;
|
|
@@ -14,7 +24,9 @@ export interface FormOptions {
|
|
|
14
24
|
/**
|
|
15
25
|
* The id of the element around the form that its result replaces with
|
|
16
26
|
* JavaScript on (px-target). Field ids then start with it, unless idPrefix
|
|
17
|
-
* is given.
|
|
27
|
+
* is given.
|
|
28
|
+
*
|
|
29
|
+
* @experimental
|
|
18
30
|
*/
|
|
19
31
|
target?: string;
|
|
20
32
|
}
|
|
@@ -24,7 +36,13 @@ export declare const TARGET_ID: RegExp;
|
|
|
24
36
|
export declare function checkTarget(action: Action, target: string): void;
|
|
25
37
|
/**
|
|
26
38
|
* Renders the action as an accessible HTML form carrying the px- attributes
|
|
27
|
-
*
|
|
28
|
-
*
|
|
39
|
+
* of the actions spec, without JSX, for the `html` template path. A reader
|
|
40
|
+
* that parses this form derives the same tool descriptor as describeAction()
|
|
41
|
+
* returns; the conformance tests check that.
|
|
42
|
+
*
|
|
43
|
+
* @category plugins
|
|
44
|
+
* @param action The action.
|
|
45
|
+
* @param state Values and errors to show.
|
|
46
|
+
* @param options Where it submits, and its id prefix.
|
|
29
47
|
*/
|
|
30
48
|
export declare function renderForm(action: Action, state?: FormState, options?: FormOptions): SafeHtml;
|
package/dist/form.js
CHANGED
|
@@ -46,6 +46,11 @@ function control(name, f, id, describedBy, value, invalid) {
|
|
|
46
46
|
return html `<input type="date"${common}${attr('min', f.min)}${attr('max', f.max)} value="${text}">`;
|
|
47
47
|
case 'choice':
|
|
48
48
|
return html `<select${common}><option value="">Choose…</option>${f.options.map((o) => html `<option value="${o.value}"${flag('selected', o.value === text)}>${o.label}</option>`)}</select>`;
|
|
49
|
+
case 'choices': {
|
|
50
|
+
// One checkbox per option, each with its own label; the fieldset's legend names the group.
|
|
51
|
+
const checked = Array.isArray(value) ? value.map(String) : typeof value === 'string' ? [value] : [];
|
|
52
|
+
return html `${f.options.map((o, i) => html `<div class="px-choice"><input type="checkbox" id="${id}-${i}" name="${name}" value="${o.value}"${attr('px-description', f.description)}${flag('aria-invalid="true"', invalid)}${flag('checked', checked.includes(o.value))}> <label for="${id}-${i}">${o.label}</label></div>`)}`;
|
|
53
|
+
}
|
|
49
54
|
case 'boolean':
|
|
50
55
|
return html `<input type="checkbox" value="on"${common}${flag('checked', value === true || value === 'on')}>`;
|
|
51
56
|
case 'custom':
|
|
@@ -62,14 +67,14 @@ function fieldBlock(name, f, prefix, state) {
|
|
|
62
67
|
// The "(optional)" marker sits outside the label so the label text, and so the
|
|
63
68
|
// schema title, stays exactly f.label. Screen readers already announce
|
|
64
69
|
// "required" on the other fields.
|
|
65
|
-
const optional = f.kind !== 'boolean' && f.optional ? html ` <span class="px-optional" aria-hidden="true">(optional)</span>` : '';
|
|
70
|
+
const optional = f.kind !== 'boolean' && f.kind !== 'choices' && f.optional ? html ` <span class="px-optional" aria-hidden="true">(optional)</span>` : '';
|
|
66
71
|
const label = html `<label for="${id}">${f.label}</label>${optional}`;
|
|
67
72
|
const hint = f.description ? html `<p class="px-hint" id="${hintId}">${f.description}</p>` : '';
|
|
68
73
|
const err = error ? html `<p class="px-error" id="${errorId}">${error}</p>` : '';
|
|
69
74
|
if (f.kind === 'boolean') {
|
|
70
75
|
return html `<div class="px-field px-field-checkbox">${input} ${label}${hint}${err}</div>`;
|
|
71
76
|
}
|
|
72
|
-
if (f.kind === 'custom' && f.fieldKind.group) {
|
|
77
|
+
if (f.kind === 'choices' || (f.kind === 'custom' && f.fieldKind.group)) {
|
|
73
78
|
return html `<fieldset class="px-field"${describedBy ? html ` aria-describedby="${describedBy}"` : ''}><legend>${f.label}</legend>${optional}${hint}${input}${err}</fieldset>`;
|
|
74
79
|
}
|
|
75
80
|
return html `<div class="px-field">${label}${hint}${input}${err}</div>`;
|
|
@@ -79,6 +84,35 @@ function fieldBlock(name, f, prefix, state) {
|
|
|
79
84
|
* from the Pexis actions draft. A reader that parses this form derives the same
|
|
80
85
|
* tool descriptor as describeAction() returns; the conformance tests check that.
|
|
81
86
|
*/
|
|
87
|
+
/**
|
|
88
|
+
* The button that sends the form. An irreversible action asks people first,
|
|
89
|
+
* with no script: the visible control is a <details> disclosure whose panel
|
|
90
|
+
* says it cannot be undone and holds the real submit button. A disabled submit
|
|
91
|
+
* button placed first is the form's default button, so pressing Enter in a
|
|
92
|
+
* field sends nothing and cannot skip the step. Agents ask the person
|
|
93
|
+
* themselves (px-confirm); the server checks everything either way.
|
|
94
|
+
*/
|
|
95
|
+
function submitControls(action, prefix) {
|
|
96
|
+
if (action.risk !== 'irreversible')
|
|
97
|
+
return html `<button type="submit">${action.title}</button>`;
|
|
98
|
+
return html `<button type="submit" disabled hidden>${action.title}</button>
|
|
99
|
+
<details class="px-confirm">
|
|
100
|
+
<summary>${action.title}</summary>
|
|
101
|
+
<p id="${prefix}-confirm">This cannot be undone. Check the values above before you go on.</p>
|
|
102
|
+
<button type="submit" aria-describedby="${prefix}-confirm">Yes, ${action.title.charAt(0).toLowerCase()}${action.title.slice(1)}</button>
|
|
103
|
+
</details>`;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Renders the action as an accessible HTML form carrying the px- attributes
|
|
107
|
+
* of the actions spec, without JSX, for the `html` template path. A reader
|
|
108
|
+
* that parses this form derives the same tool descriptor as describeAction()
|
|
109
|
+
* returns; the conformance tests check that.
|
|
110
|
+
*
|
|
111
|
+
* @category plugins
|
|
112
|
+
* @param action The action.
|
|
113
|
+
* @param state Values and errors to show.
|
|
114
|
+
* @param options Where it submits, and its id prefix.
|
|
115
|
+
*/
|
|
82
116
|
export function renderForm(action, state = {}, options = {}) {
|
|
83
117
|
if (options.target !== undefined)
|
|
84
118
|
checkTarget(action, options.target);
|
|
@@ -90,12 +124,12 @@ export function renderForm(action, state = {}, options = {}) {
|
|
|
90
124
|
// A people-only action: a plain form, marked so agent tooling leaves it alone.
|
|
91
125
|
return html `<form method="${action.method.toLowerCase()}" action="${url}" aria-label="${action.title}" px-agent="exclude">
|
|
92
126
|
${fields}
|
|
93
|
-
|
|
127
|
+
${submitControls(action, prefix)}
|
|
94
128
|
</form>`;
|
|
95
129
|
}
|
|
96
130
|
return html `<form method="${action.method.toLowerCase()}" action="${url}" aria-label="${action.title}" px-action="${action.name}" px-description="${action.description}" px-risk="${action.risk}"${flag('px-confirm', action.confirm)}${target}>
|
|
97
131
|
${fields}
|
|
98
|
-
|
|
132
|
+
${submitControls(action, prefix)}
|
|
99
133
|
</form>`;
|
|
100
134
|
}
|
|
101
135
|
//# sourceMappingURL=form.js.map
|
package/dist/form.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form.js","sourceRoot":"","sources":["../src/form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAA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,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACnG,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA,eAAe,OAAO,CAAC,MAAM,GAAG,CAAC;IACxF,IAAI,MAAM,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;QAC5B,+EAA+E;QAC/E,OAAO,IAAI,CAAA,iBAAiB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,GAAG,iBAAiB,MAAM,CAAC,KAAK;EACtG,MAAM;EACN,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,CAAC;IACP,CAAC;IACD,OAAO,IAAI,CAAA,iBAAiB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,GAAG,iBAAiB,MAAM,CAAC,KAAK,gBAAgB,MAAM,CAAC,IAAI,qBAAqB,MAAM,CAAC,WAAW,cAAc,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM;EAC9O,MAAM;EACN,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,CAAC;AACT,CAAC"}
|
package/dist/host.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* The host name from a Host header, without the port, lowercased; null if the header is malformed.
|
|
3
|
+
*
|
|
4
|
+
* @category plugins
|
|
5
|
+
* @param header The Host header's value.
|
|
6
|
+
*/
|
|
2
7
|
export declare function hostFromHeader(header: string | undefined): string | null;
|
package/dist/host.js
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
// with an optional port and nothing else. Anything more ("a:80@evil.com",
|
|
5
5
|
// "a/path") is malformed and refused, because the header becomes part of a URL.
|
|
6
6
|
const HOST = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*|\[[0-9a-f:.]+\])(?::\d{1,5})?$/;
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The host name from a Host header, without the port, lowercased; null if the header is malformed.
|
|
9
|
+
*
|
|
10
|
+
* @category plugins
|
|
11
|
+
* @param header The Host header's value.
|
|
12
|
+
*/
|
|
8
13
|
export function hostFromHeader(header) {
|
|
9
14
|
if (!header)
|
|
10
15
|
return null;
|
package/dist/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,qEAAqE;AAErE,4EAA4E;AAC5E,0EAA0E;AAC1E,gFAAgF;AAChF,MAAM,IAAI,GAAG,oHAAoH,CAAC;AAElI
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,qEAAqE;AAErE,4EAA4E;AAC5E,0EAA0E;AAC1E,gFAAgF;AAChF,MAAM,IAAI,GAAG,oHAAoH,CAAC;AAElI;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAA0B;IACvD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC1C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;AAC/F,CAAC"}
|
package/dist/html.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markup Pexis trusts: made by JSX, the `html` template or raw(). Anything
|
|
3
|
+
* else interpolated into a page is escaped as text.
|
|
4
|
+
*/
|
|
1
5
|
export interface SafeHtml {
|
|
2
6
|
/** Type-level brand only; the runtime check uses a symbol. */
|
|
3
7
|
readonly ' pexisSafeHtml': true;
|
|
8
|
+
/** The HTML. */
|
|
4
9
|
readonly value: string;
|
|
10
|
+
/** The HTML, so it can be used where a string is expected. */
|
|
5
11
|
toString(): string;
|
|
6
12
|
}
|
|
7
13
|
/**
|
|
@@ -9,18 +15,53 @@ export interface SafeHtml {
|
|
|
9
15
|
* an async component is somewhere in the tree, in which case it is a promise.
|
|
10
16
|
*/
|
|
11
17
|
export type Markup = SafeHtml | Promise<SafeHtml>;
|
|
18
|
+
/**
|
|
19
|
+
* Whether a value is trusted markup. JSON can never produce one, so parsed
|
|
20
|
+
* data (model output included) never passes.
|
|
21
|
+
*
|
|
22
|
+
* @category plugins
|
|
23
|
+
* @param v Anything.
|
|
24
|
+
*/
|
|
12
25
|
export declare function isSafeHtml(v: unknown): v is SafeHtml;
|
|
26
|
+
/**
|
|
27
|
+
* Escapes text for HTML: `&`, `<`, `>`, `"` and `'`.
|
|
28
|
+
*
|
|
29
|
+
* @param s The text.
|
|
30
|
+
*/
|
|
13
31
|
export declare function escapeHtml(s: string): string;
|
|
14
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Marks a trusted string as HTML. Never pass user or model input to this.
|
|
34
|
+
*
|
|
35
|
+
* @param value Markup you wrote yourself.
|
|
36
|
+
*/
|
|
15
37
|
export declare function raw(value: string): SafeHtml;
|
|
16
38
|
/**
|
|
17
|
-
* Tagged template for HTML, for code without a JSX build step.
|
|
18
|
-
* attribute values
|
|
19
|
-
*
|
|
39
|
+
* Tagged template for HTML, for code without a JSX build step. Escaping
|
|
40
|
+
* protects text and quoted attribute values, so a value anywhere else (an
|
|
41
|
+
* event handler, an unquoted value, between attributes, inside script, style
|
|
42
|
+
* or srcdoc) throws, as the JSX runtime refuses the same things. Synchronous JSX output can be interpolated.
|
|
20
43
|
* Values at the start of a URL attribute (href, src, action and others) are
|
|
21
44
|
* checked as JSX checks them: a javascript: URL is replaced, never rendered.
|
|
45
|
+
*
|
|
46
|
+
* @param strings The template's literal parts.
|
|
47
|
+
* @param values The values, escaped unless they are trusted markup.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* html`<p>Hello, ${name}.</p><a href="${url}">More</a>`
|
|
51
|
+
* ```
|
|
22
52
|
*/
|
|
23
53
|
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): SafeHtml;
|
|
24
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Waits for any async components and returns the final markup.
|
|
56
|
+
*
|
|
57
|
+
* @param markup What a component or page returned.
|
|
58
|
+
*/
|
|
25
59
|
export declare function renderToString(markup: Markup | null | undefined): Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* A `Response` from markup, with the doctype and an HTML content type.
|
|
62
|
+
*
|
|
63
|
+
* @category plugins
|
|
64
|
+
* @param body The document.
|
|
65
|
+
* @param init Status and headers.
|
|
66
|
+
*/
|
|
26
67
|
export declare function htmlResponse(body: SafeHtml, init?: ResponseInit): Response;
|
package/dist/html.js
CHANGED
|
@@ -10,9 +10,21 @@ const SAFE = Symbol.for('pexis.safe-html');
|
|
|
10
10
|
function safe(value) {
|
|
11
11
|
return { [SAFE]: true, value, toString: () => value };
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Whether a value is trusted markup. JSON can never produce one, so parsed
|
|
15
|
+
* data (model output included) never passes.
|
|
16
|
+
*
|
|
17
|
+
* @category plugins
|
|
18
|
+
* @param v Anything.
|
|
19
|
+
*/
|
|
13
20
|
export function isSafeHtml(v) {
|
|
14
21
|
return typeof v === 'object' && v !== null && SAFE in v;
|
|
15
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Escapes text for HTML: `&`, `<`, `>`, `"` and `'`.
|
|
25
|
+
*
|
|
26
|
+
* @param s The text.
|
|
27
|
+
*/
|
|
16
28
|
export function escapeHtml(s) {
|
|
17
29
|
return s
|
|
18
30
|
.replaceAll('&', '&')
|
|
@@ -21,7 +33,11 @@ export function escapeHtml(s) {
|
|
|
21
33
|
.replaceAll('"', '"')
|
|
22
34
|
.replaceAll("'", ''');
|
|
23
35
|
}
|
|
24
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Marks a trusted string as HTML. Never pass user or model input to this.
|
|
38
|
+
*
|
|
39
|
+
* @param value Markup you wrote yourself.
|
|
40
|
+
*/
|
|
25
41
|
export function raw(value) {
|
|
26
42
|
return safe(value);
|
|
27
43
|
}
|
|
@@ -61,12 +77,91 @@ function attributeOpenedAtEnd(text) {
|
|
|
61
77
|
i--;
|
|
62
78
|
return end > i + 1 ? text.slice(i + 1, end).toLowerCase() : null;
|
|
63
79
|
}
|
|
80
|
+
const RAW_TEXT_OPEN = /<(script|style)\b[^>]*>(?![\s\S]*<\/\1\s*>)/i;
|
|
81
|
+
function placeAtEnd(markup) {
|
|
82
|
+
const rawText = RAW_TEXT_OPEN.exec(markup);
|
|
83
|
+
if (rawText)
|
|
84
|
+
return { kind: 'raw-text', tag: rawText[1].toLowerCase() };
|
|
85
|
+
const open = markup.lastIndexOf('<');
|
|
86
|
+
if (open === -1 || markup.lastIndexOf('>') > open || !/^<[a-zA-Z]/.test(markup.slice(open, open + 2)))
|
|
87
|
+
return { kind: 'text' };
|
|
88
|
+
// Inside a start tag: walk its attributes, minding quotes, to see where the end is.
|
|
89
|
+
const tag = markup.slice(open + 1);
|
|
90
|
+
let i = tag.search(/[\s/]|$/);
|
|
91
|
+
let name = '';
|
|
92
|
+
while (i < tag.length) {
|
|
93
|
+
const c = tag[i];
|
|
94
|
+
if (/[\s/]/.test(c)) {
|
|
95
|
+
i++;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const nameMatch = /^[^\s/>=]+/.exec(tag.slice(i));
|
|
99
|
+
name = nameMatch ? nameMatch[0].toLowerCase() : '';
|
|
100
|
+
i += nameMatch ? nameMatch[0].length : 1;
|
|
101
|
+
while (i < tag.length && /\s/.test(tag[i]))
|
|
102
|
+
i++;
|
|
103
|
+
if (tag[i] !== '=')
|
|
104
|
+
continue;
|
|
105
|
+
i++;
|
|
106
|
+
while (i < tag.length && /\s/.test(tag[i]))
|
|
107
|
+
i++;
|
|
108
|
+
if (i >= tag.length)
|
|
109
|
+
return { kind: 'value', attribute: name, quoted: false };
|
|
110
|
+
const quote = tag[i];
|
|
111
|
+
if (quote === '"' || quote === "'") {
|
|
112
|
+
const close = tag.indexOf(quote, i + 1);
|
|
113
|
+
if (close === -1)
|
|
114
|
+
return { kind: 'value', attribute: name, quoted: true };
|
|
115
|
+
i = close + 1;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const end = tag.slice(i).search(/\s/);
|
|
119
|
+
if (end === -1)
|
|
120
|
+
return { kind: 'value', attribute: name, quoted: false };
|
|
121
|
+
i += end;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { kind: 'tag' };
|
|
125
|
+
}
|
|
126
|
+
/** Throws when a value would land where escaping does not protect it. */
|
|
127
|
+
function checkPlace(markup, value) {
|
|
128
|
+
const empty = value === null || value === undefined || value === false || value === true || value === '';
|
|
129
|
+
if (empty)
|
|
130
|
+
return;
|
|
131
|
+
const place = placeAtEnd(markup);
|
|
132
|
+
const trusted = isSafeHtml(value) || isStyleSheet(value);
|
|
133
|
+
if (place.kind === 'raw-text' && !trusted) {
|
|
134
|
+
throw new Error(`html\`\`: a value inside <${place.tag}> is not escaped by the browser, so text there could end the element or run as code. Pass trusted markup with raw(), or build the ${place.tag} another way.`);
|
|
135
|
+
}
|
|
136
|
+
if (place.kind === 'tag' && !trusted) {
|
|
137
|
+
throw new Error('html``: a value between attributes could add attributes of its own, such as an event handler. Put values inside quoted attribute values, or pass trusted markup such as html`checked`.');
|
|
138
|
+
}
|
|
139
|
+
if (place.kind === 'value') {
|
|
140
|
+
if (/^on/.test(place.attribute)) {
|
|
141
|
+
throw new Error(`html\`\`: ${place.attribute}="…" runs its value as code, so no value may go in an event handler attribute. Pexis renders HTML on the server: use an action, or a script file.`);
|
|
142
|
+
}
|
|
143
|
+
if (place.attribute === 'srcdoc' && !trusted) {
|
|
144
|
+
throw new Error('html``: srcdoc is read as a whole HTML document, so escaping does not make text safe there. Pass trusted markup with raw().');
|
|
145
|
+
}
|
|
146
|
+
if (!place.quoted) {
|
|
147
|
+
throw new Error(`html\`\`: the value of ${place.attribute}= is not in quotes, so a space in it could add attributes. Write ${place.attribute}="\${…}".`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
64
151
|
/**
|
|
65
|
-
* Tagged template for HTML, for code without a JSX build step.
|
|
66
|
-
* attribute values
|
|
67
|
-
*
|
|
152
|
+
* Tagged template for HTML, for code without a JSX build step. Escaping
|
|
153
|
+
* protects text and quoted attribute values, so a value anywhere else (an
|
|
154
|
+
* event handler, an unquoted value, between attributes, inside script, style
|
|
155
|
+
* or srcdoc) throws, as the JSX runtime refuses the same things. Synchronous JSX output can be interpolated.
|
|
68
156
|
* Values at the start of a URL attribute (href, src, action and others) are
|
|
69
157
|
* checked as JSX checks them: a javascript: URL is replaced, never rendered.
|
|
158
|
+
*
|
|
159
|
+
* @param strings The template's literal parts.
|
|
160
|
+
* @param values The values, escaped unless they are trusted markup.
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* html`<p>Hello, ${name}.</p><a href="${url}">More</a>`
|
|
164
|
+
* ```
|
|
70
165
|
*/
|
|
71
166
|
export function html(strings, ...values) {
|
|
72
167
|
let out = strings[0] ?? '';
|
|
@@ -80,6 +175,7 @@ export function html(strings, ...values) {
|
|
|
80
175
|
urlStart = opened && URL_ATTRIBUTES.has(opened) ? '' : null;
|
|
81
176
|
}
|
|
82
177
|
const value = values[i];
|
|
178
|
+
checkPlace(out, value);
|
|
83
179
|
let rendered = render(value);
|
|
84
180
|
if (urlStart !== null && !isSafeHtml(value)) {
|
|
85
181
|
const text = typeof value === 'string' || typeof value === 'number' ? String(value) : '';
|
|
@@ -93,7 +189,11 @@ export function html(strings, ...values) {
|
|
|
93
189
|
}
|
|
94
190
|
return safe(out);
|
|
95
191
|
}
|
|
96
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* Waits for any async components and returns the final markup.
|
|
194
|
+
*
|
|
195
|
+
* @param markup What a component or page returned.
|
|
196
|
+
*/
|
|
97
197
|
export async function renderToString(markup) {
|
|
98
198
|
if (markup === null || markup === undefined)
|
|
99
199
|
return '';
|
|
@@ -105,6 +205,13 @@ export async function renderToString(markup) {
|
|
|
105
205
|
throw new Error(`A render returned ${typeof value}, not markup. Return JSX, html\`...\`, text or null.`);
|
|
106
206
|
return value.value;
|
|
107
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* A `Response` from markup, with the doctype and an HTML content type.
|
|
210
|
+
*
|
|
211
|
+
* @category plugins
|
|
212
|
+
* @param body The document.
|
|
213
|
+
* @param init Status and headers.
|
|
214
|
+
*/
|
|
108
215
|
export function htmlResponse(body, init = {}) {
|
|
109
216
|
const headers = new Headers(init.headers);
|
|
110
217
|
if (!headers.has('content-type'))
|
package/dist/html.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,iFAAiF;AAEjF,2EAA2E;AAC3E,4EAA4E;AAC5E,+EAA+E;AAC/E,2EAA2E;AAC3E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAErE,MAAM,IAAI,GA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AI,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAC9E,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export { agentRefusal, createApp, definePlugin, jsonLd, speculationRules, TOOLS_PATH, type App, type AppOptions, type NavigationOptions } from './app.js';
|
|
2
2
|
export { definePage, defineLayout, notFound, redirect, isSignal, atPath, type UnroutedPage } from './page.js';
|
|
3
3
|
export { getContext, peekContext, setContextStorage, runWithContext, type ContextStorage } from './context.js';
|
|
4
|
-
export { ActionForm, HumanOnly, Untrusted, hasInPlaceForms, type ActionFormProps, type UntrustedProps } from './components.js';
|
|
4
|
+
export { ActionForm, HumanOnly, Region, Untrusted, hasInPlaceForms, type ActionFormProps, type RegionProps, type UntrustedProps } from './components.js';
|
|
5
5
|
export { css, globalCss, minifyCss, isStyleSheet, type StyleSheet, type GlobalStyle } from './styles.js';
|
|
6
6
|
export { crossSiteRefusal } from './csrf.js';
|
|
7
7
|
export { createCors, type CorsOptions } from './cors.js';
|
|
8
8
|
export { BodyError, contentSecurityPolicy, DEFAULT_ACTION_RATE_LIMIT, DEFAULT_MAX_BODY_BYTES, readBodyText, type CspDirective, type SecurityOptions } from './security.js';
|
|
9
9
|
export { hostFromHeader } from './host.js';
|
|
10
10
|
export { clientKey, forwardedClient, memoryRateStore, rateLimiter, type RateLimitDecision, type RateLimiter, type RateLimitRule, type RateLimitStore } from './rate-limit.js';
|
|
11
|
-
export { field, toJsonSchema, fieldSchema, validate, type Field, type Fields, type ChoiceOption, type TextField, type IntegerField, type NumberField, type DateField, type ChoiceField, type BooleanField, type CustomField, type FieldKind, type FieldBase, type ControlProps, defineFieldKind, type Infer, type ObjectSchema, type ValidationResult, } from './schema.js';
|
|
12
|
-
export { defineAction, invalid, actionFile, describeAction, createRegistry, type Action, type ActionContext, type ActionDefinition, type ActionResult, type Invalid, type Registry, type Risk, type ToolDescriptor, type UndoDefinition, } from './registry.js';
|
|
11
|
+
export { field, toJsonSchema, fieldSchema, validate, type Field, type Fields, type ChoiceOption, type TextField, type IntegerField, type NumberField, type DateField, type ChoiceField, type ChoicesField, type BooleanField, type CustomField, type FieldKind, type FieldBase, type ControlProps, defineFieldKind, type Infer, type ObjectSchema, type ValidationResult, } from './schema.js';
|
|
12
|
+
export { defineAction, invalid, actionFile, describeAction, createRegistry, type Action, type ActionContext, type ActionDefinition, type ActionResult, type ResultLink, type Invalid, type Registry, type Risk, type ToolDescriptor, type UndoDefinition, } from './registry.js';
|
|
13
13
|
export { html, raw, escapeHtml, htmlResponse, renderToString, isSafeHtml, type SafeHtml, type Markup } from './html.js';
|
|
14
14
|
export type { Child } from './jsx-runtime.js';
|
|
15
15
|
export { renderForm, type FormState, type FormOptions } from './form.js';
|