@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/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Markup } from './html.js';
|
|
2
2
|
import type { Action } from './registry.js';
|
|
3
3
|
import type { Fields, Infer } from './schema.js';
|
|
4
|
+
/** The app's settings that plugins and the checks read, from createApp(). */
|
|
4
5
|
export interface AppConfig {
|
|
5
6
|
/** Public origin, for example https://example.com. Used for canonical URLs, the sitemap and the checks. */
|
|
6
7
|
readonly origin: string;
|
|
@@ -8,10 +9,16 @@ export interface AppConfig {
|
|
|
8
9
|
readonly lang: string;
|
|
9
10
|
/** Severity overrides and extra rules for the build checks. */
|
|
10
11
|
readonly checks: {
|
|
12
|
+
/** A severity per rule id, or "off". */
|
|
11
13
|
readonly overrides?: Readonly<Record<string, 'error' | 'warning' | 'off'>>;
|
|
14
|
+
/** The app's own check rules, run with the built-in ones. */
|
|
12
15
|
readonly rules?: readonly CheckRuleLike[];
|
|
13
16
|
};
|
|
14
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* What `ctx.route` holds: the page, action or plugin route the request
|
|
20
|
+
* matched, the built-in tool list, or nothing.
|
|
21
|
+
*/
|
|
15
22
|
export type RouteMatch = {
|
|
16
23
|
kind: 'page';
|
|
17
24
|
page: Page;
|
|
@@ -40,10 +47,15 @@ export type RouteMatch = {
|
|
|
40
47
|
* declare module '@pexis/core' { interface Context { db: Database } }
|
|
41
48
|
*/
|
|
42
49
|
export interface Context {
|
|
50
|
+
/** The incoming request. */
|
|
43
51
|
readonly request: Request;
|
|
52
|
+
/** The request's URL, parsed. */
|
|
44
53
|
readonly url: URL;
|
|
54
|
+
/** The route's parameters: for "/menu/:dish", `{ dish }`. */
|
|
45
55
|
params: Record<string, string>;
|
|
56
|
+
/** What the request matched. */
|
|
46
57
|
route: RouteMatch;
|
|
58
|
+
/** The app's settings: origin, language, checks. */
|
|
47
59
|
readonly app: AppConfig;
|
|
48
60
|
/**
|
|
49
61
|
* Random per-request value for the Content Security Policy. Pexis adds it to
|
|
@@ -71,7 +83,9 @@ export interface Context {
|
|
|
71
83
|
* type cannot be set here. Redirects use redirect(), not a 3xx status.
|
|
72
84
|
*/
|
|
73
85
|
readonly response: {
|
|
86
|
+
/** The page's status, such as 410. */
|
|
74
87
|
status?: number;
|
|
88
|
+
/** Headers added to the response. */
|
|
75
89
|
readonly headers: Headers;
|
|
76
90
|
};
|
|
77
91
|
/**
|
|
@@ -83,14 +97,16 @@ export interface Context {
|
|
|
83
97
|
/**
|
|
84
98
|
* Set when an agent acts for a person with a token (see AgentIdentity),
|
|
85
99
|
* so a permission can tell: permission: (ctx) => !ctx.agent && isStaff(ctx.user).
|
|
86
|
-
*
|
|
100
|
+
*
|
|
101
|
+
* @experimental
|
|
87
102
|
*/
|
|
88
103
|
readonly agent?: AgentIdentity;
|
|
89
104
|
/**
|
|
90
105
|
* The result of checking an Authorization: Bearer token, set by an
|
|
91
106
|
* authorization plugin (@pexis/auth/server) only on the routes it protects,
|
|
92
107
|
* such as /pexis/mcp. Undefined when the request carried no bearer token.
|
|
93
|
-
*
|
|
108
|
+
*
|
|
109
|
+
* @experimental
|
|
94
110
|
*/
|
|
95
111
|
bearer?: BearerCheck;
|
|
96
112
|
/**
|
|
@@ -98,19 +114,27 @@ export interface Context {
|
|
|
98
114
|
* permission check (as the person making this request, never with more
|
|
99
115
|
* rights), validation and an action event, but no rate limit, since this
|
|
100
116
|
* request was already counted. For one team's code to use another team's
|
|
101
|
-
* action without reaching into its files.
|
|
102
|
-
*
|
|
103
|
-
* const found = await ctx.call(checkDish, { dish: 'soup' });
|
|
104
|
-
* if (!found.ok) return invalid({ dish: found.message });
|
|
117
|
+
* action without reaching into its files.
|
|
105
118
|
*
|
|
106
119
|
* A call cannot carry more risk than the request it runs in: a page or a
|
|
107
120
|
* GET request calls only read actions, an action calls only actions of
|
|
108
121
|
* the same risk or lower, and an action that needs approval only from one
|
|
109
122
|
* that needs it too. Breaking these throws, since it is a mistake in code.
|
|
123
|
+
*
|
|
124
|
+
* @experimental
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const found = await ctx.call(checkDish, { dish: 'soup' });
|
|
128
|
+
* if (!found.ok) return invalid({ dish: found.message });
|
|
129
|
+
* ```
|
|
110
130
|
*/
|
|
111
131
|
call<F extends Fields>(action: Action<F>, input: Infer<F>): Promise<CallResult>;
|
|
112
132
|
}
|
|
113
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* A bearer token, checked.
|
|
135
|
+
*
|
|
136
|
+
* @experimental
|
|
137
|
+
*/
|
|
114
138
|
export type BearerCheck = {
|
|
115
139
|
readonly ok: true;
|
|
116
140
|
readonly agent: AgentIdentity;
|
|
@@ -120,26 +144,41 @@ export type BearerCheck = {
|
|
|
120
144
|
};
|
|
121
145
|
/**
|
|
122
146
|
* A write an agent made for a person, with how to reverse it. Given only to
|
|
123
|
-
* the one recorder an app installs (api.recordAgentWrites).
|
|
147
|
+
* the one recorder an app installs (api.recordAgentWrites).
|
|
148
|
+
*
|
|
149
|
+
* @experimental
|
|
124
150
|
*/
|
|
125
151
|
export interface AgentWrite {
|
|
152
|
+
/** The action the agent ran. */
|
|
126
153
|
action: string;
|
|
154
|
+
/** That action's title, for people. */
|
|
127
155
|
actionTitle: string;
|
|
156
|
+
/** The action that reverses it. */
|
|
128
157
|
undoAction: string;
|
|
158
|
+
/** The undo action's title, for people. */
|
|
129
159
|
undoTitle: string;
|
|
130
160
|
/** The undo action's input, already validated; null when it could not be built, so this one cannot be undone. */
|
|
131
161
|
undoInput: Record<string, unknown> | null;
|
|
162
|
+
/** The person the agent acted for. */
|
|
132
163
|
userId: string;
|
|
164
|
+
/** The agent's OAuth client id. */
|
|
133
165
|
clientId: string;
|
|
166
|
+
/** The grant the agent's token came from. */
|
|
134
167
|
grantId: string;
|
|
135
168
|
/** ms since the epoch. */
|
|
136
169
|
at: number;
|
|
170
|
+
/** When the undo is no longer offered, in ms since the epoch. */
|
|
137
171
|
expiresAt: number;
|
|
138
172
|
/** The write's own result message. Untrusted text. */
|
|
139
173
|
message: string;
|
|
140
174
|
}
|
|
141
|
-
/**
|
|
175
|
+
/**
|
|
176
|
+
* Keeps agent writes so the person can undo them; see @pexis/approvals.
|
|
177
|
+
*
|
|
178
|
+
* @experimental
|
|
179
|
+
*/
|
|
142
180
|
export interface AgentWriteRecorder {
|
|
181
|
+
/** Keeps one write. */
|
|
143
182
|
record(write: AgentWrite): void | Promise<void>;
|
|
144
183
|
/** An undo action succeeded for a person, from any path: matching writes are undone. */
|
|
145
184
|
undone(match: {
|
|
@@ -148,11 +187,19 @@ export interface AgentWriteRecorder {
|
|
|
148
187
|
undoInput: Record<string, unknown>;
|
|
149
188
|
}): void | Promise<void>;
|
|
150
189
|
}
|
|
151
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* What ctx.call returns: the same answer an agent gets as JSON.
|
|
192
|
+
*
|
|
193
|
+
* @experimental
|
|
194
|
+
*/
|
|
152
195
|
export type CallResult = {
|
|
153
196
|
readonly ok: true;
|
|
154
197
|
readonly message: string;
|
|
155
198
|
readonly data: unknown;
|
|
199
|
+
readonly link?: {
|
|
200
|
+
readonly href: string;
|
|
201
|
+
readonly text: string;
|
|
202
|
+
};
|
|
156
203
|
} | {
|
|
157
204
|
readonly ok: false;
|
|
158
205
|
readonly outcome: 'invalid';
|
|
@@ -165,22 +212,28 @@ export type CallResult = {
|
|
|
165
212
|
};
|
|
166
213
|
/** What the adapter knows about the connection a request came in on. */
|
|
167
214
|
export interface Connection {
|
|
215
|
+
/** The client's network address: the socket's, or from a proxy header the adapter was told to trust. */
|
|
168
216
|
clientAddress?: string;
|
|
169
217
|
/**
|
|
170
218
|
* Set only by plugin code through api.fetch, never by an adapter: the
|
|
171
219
|
* request is an agent acting for a person with a token it was granted
|
|
172
|
-
* (such as an MCP client signed in through OAuth).
|
|
220
|
+
* (such as an MCP client signed in through OAuth).
|
|
221
|
+
*
|
|
222
|
+
* @experimental
|
|
173
223
|
*/
|
|
174
224
|
agent?: AgentIdentity;
|
|
175
225
|
}
|
|
176
226
|
/**
|
|
177
227
|
* An agent acting for a signed-in person. The core refuses agent requests to
|
|
178
228
|
* actions that need the person's approval or are for people only, and to
|
|
179
|
-
* actions outside the granted scopes.
|
|
229
|
+
* actions outside the granted scopes.
|
|
230
|
+
*
|
|
231
|
+
* @experimental
|
|
180
232
|
*/
|
|
181
233
|
export interface AgentIdentity {
|
|
182
234
|
/** The person the agent acts for, as the app's sign-in knows them. */
|
|
183
235
|
readonly user: {
|
|
236
|
+
/** The person's user id. */
|
|
184
237
|
readonly id: string;
|
|
185
238
|
};
|
|
186
239
|
/** Who the agent is, such as the client's metadata URL. */
|
|
@@ -193,6 +246,8 @@ export interface AgentIdentity {
|
|
|
193
246
|
/**
|
|
194
247
|
* Maps a request path to the path routing should use, plus context fields,
|
|
195
248
|
* before routing. Return null to leave the request alone.
|
|
249
|
+
*
|
|
250
|
+
* @category plugins
|
|
196
251
|
*/
|
|
197
252
|
export type Rewrite = (url: URL) => {
|
|
198
253
|
pathname: string;
|
|
@@ -206,8 +261,11 @@ type Segments<P extends string> = P extends `${infer Head}/${infer Rest}` ? Segm
|
|
|
206
261
|
export type PathParams<P extends string> = {
|
|
207
262
|
[K in Segments<P>]: string;
|
|
208
263
|
};
|
|
264
|
+
/** A page's head: what search engines, link previews and agents read first. */
|
|
209
265
|
export interface HeadData {
|
|
266
|
+
/** The page title, for `<title>`. Required and non-empty. */
|
|
210
267
|
title: string;
|
|
268
|
+
/** The meta description. Required and non-empty. */
|
|
211
269
|
description: string;
|
|
212
270
|
/** Absolute URL. Defaults to the app origin plus the request path. */
|
|
213
271
|
canonical?: string;
|
|
@@ -216,41 +274,56 @@ export interface HeadData {
|
|
|
216
274
|
/** Extra markup for <head>. */
|
|
217
275
|
extra?: Markup;
|
|
218
276
|
}
|
|
277
|
+
/** The context a page's load, head and render receive, with its own route parameters typed. */
|
|
219
278
|
export type PageContext<P extends string> = Context & {
|
|
220
279
|
params: PathParams<P>;
|
|
221
280
|
};
|
|
281
|
+
/** What notFound() returns: answer 404 with the not-found page. */
|
|
222
282
|
export interface NotFound {
|
|
283
|
+
/** Marks the object as a signal. */
|
|
223
284
|
readonly pexisSignal: 'not-found';
|
|
224
285
|
}
|
|
286
|
+
/** What redirect() returns: send the visitor elsewhere. */
|
|
225
287
|
export interface Redirect {
|
|
288
|
+
/** Marks the object as a signal. */
|
|
226
289
|
readonly pexisSignal: 'redirect';
|
|
290
|
+
/** Where to send the visitor: a path on this site, or an absolute URL when `external`. */
|
|
227
291
|
readonly location: string;
|
|
292
|
+
/** The redirect status. */
|
|
228
293
|
readonly status: 301 | 302 | 303 | 307 | 308;
|
|
229
294
|
/** Allow a target on another site. Off by default, so user input cannot cause an open redirect. */
|
|
230
295
|
readonly external: boolean;
|
|
231
296
|
}
|
|
297
|
+
/** What a page's load() may return to stop rendering: notFound() or redirect(). */
|
|
232
298
|
export type Signal = NotFound | Redirect;
|
|
233
299
|
/** A page shown when no page matches (notFound) or a request fails (serverError). */
|
|
234
300
|
export interface ErrorPage {
|
|
301
|
+
/** The error page's head. */
|
|
235
302
|
head: HeadData;
|
|
236
303
|
/** Keep it simple: it is shown when something already went wrong, so it should not load data. */
|
|
237
304
|
render: (props: {
|
|
238
305
|
ctx: Context;
|
|
239
306
|
}) => Markup | null | undefined;
|
|
240
307
|
}
|
|
308
|
+
/** A layout from defineLayout(): wraps every page's body. */
|
|
241
309
|
export interface Layout {
|
|
310
|
+
/** Marks the object as a layout. */
|
|
242
311
|
readonly kind: 'layout';
|
|
312
|
+
/** Renders the shell around a page; must include `<main>` with `children` inside it. */
|
|
243
313
|
render(props: {
|
|
244
314
|
children: Markup;
|
|
245
315
|
ctx: Context;
|
|
246
316
|
}): Markup | null | undefined;
|
|
247
317
|
}
|
|
318
|
+
/** What definePage() takes. */
|
|
248
319
|
export interface PageDefinition<P extends string, D> {
|
|
249
320
|
/** URLPattern pathname syntax: "/", "/menu", "/menu/:dish", "/docs/*". */
|
|
250
321
|
path: P;
|
|
251
322
|
/** Load data for the page. Return notFound() or redirect(url) to stop. */
|
|
252
323
|
load?: (ctx: PageContext<P>) => D | Signal | Promise<D | Signal>;
|
|
324
|
+
/** The page's title and description, fixed or built from the loaded data. */
|
|
253
325
|
head: HeadData | ((data: D, ctx: PageContext<P>) => HeadData);
|
|
326
|
+
/** Renders the page's body, inside the layout's `<main>`. */
|
|
254
327
|
render: (props: {
|
|
255
328
|
data: D;
|
|
256
329
|
ctx: PageContext<P>;
|
|
@@ -268,31 +341,67 @@ export interface PageDefinition<P extends string, D> {
|
|
|
268
341
|
* Sends the head and the start of the layout as soon as load() finishes,
|
|
269
342
|
* while async components in the page are still working. Put slow data in
|
|
270
343
|
* async components to benefit. Once streaming has started the status is
|
|
271
|
-
* 200: an error after that is shown in the page and logged.
|
|
344
|
+
* 200: an error after that is shown in the page and logged.
|
|
345
|
+
*
|
|
346
|
+
* @experimental
|
|
272
347
|
*/
|
|
273
348
|
stream?: boolean;
|
|
274
349
|
}
|
|
350
|
+
/** A page, as definePage() returns it. */
|
|
275
351
|
export interface Page {
|
|
352
|
+
/** Marks the object as a page. */
|
|
276
353
|
readonly kind: 'page';
|
|
354
|
+
/** The page's path pattern. */
|
|
277
355
|
readonly path: string;
|
|
356
|
+
/** Whether the path has parameters (":name" or "*"). */
|
|
278
357
|
readonly hasParams: boolean;
|
|
358
|
+
/** Whether the page is indexed: in the sitemap and the checks. */
|
|
279
359
|
readonly index: boolean;
|
|
360
|
+
/** The page's own language, if it sets one. */
|
|
280
361
|
readonly lang: string | undefined;
|
|
362
|
+
/** The page's own layout: undefined for the app's, null for none. */
|
|
281
363
|
readonly layout: Layout | null | undefined;
|
|
364
|
+
/** The parameter values of every public URL, for paths with parameters. */
|
|
282
365
|
readonly entries: (() => Record<string, string>[] | Promise<Record<string, string>[]>) | undefined;
|
|
366
|
+
/** Loads the page's data. */
|
|
283
367
|
readonly load: ((ctx: Context) => unknown) | undefined;
|
|
368
|
+
/** The page's head. */
|
|
284
369
|
readonly head: HeadData | ((data: unknown, ctx: Context) => HeadData);
|
|
370
|
+
/** Renders the page's body. */
|
|
285
371
|
readonly render: (props: {
|
|
286
372
|
data: unknown;
|
|
287
373
|
ctx: Context;
|
|
288
374
|
params: Record<string, string>;
|
|
289
375
|
}) => Markup | null | undefined;
|
|
376
|
+
/** Whether the page streams. */
|
|
290
377
|
readonly stream: boolean;
|
|
291
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* Runs around every request: answer it yourself, or call `next()` for the
|
|
381
|
+
* rest of the app and change what comes back.
|
|
382
|
+
*
|
|
383
|
+
* @category plugins
|
|
384
|
+
*/
|
|
292
385
|
export type Middleware = (ctx: Context, next: () => Promise<Response>) => Promise<Response>;
|
|
386
|
+
/**
|
|
387
|
+
* Answers a plugin route added with api.route().
|
|
388
|
+
*
|
|
389
|
+
* @category plugins
|
|
390
|
+
*/
|
|
293
391
|
export type RouteHandler = (ctx: Context) => Response | Promise<Response>;
|
|
392
|
+
/**
|
|
393
|
+
* Adds markup to a page's `<head>` or the end of its `<body>`, or nothing (null) for this request.
|
|
394
|
+
*
|
|
395
|
+
* @category plugins
|
|
396
|
+
*/
|
|
294
397
|
export type HeadContribution = (ctx: Context) => Markup | null | undefined;
|
|
398
|
+
/**
|
|
399
|
+
* What api.onAction listeners receive for each action call: field names, never values.
|
|
400
|
+
*
|
|
401
|
+
* @category plugins
|
|
402
|
+
*/
|
|
295
403
|
export interface ActionEvent {
|
|
404
|
+
/** The action's name. */
|
|
296
405
|
action: string;
|
|
297
406
|
/** ISO timestamp. */
|
|
298
407
|
at: string;
|
|
@@ -300,35 +409,65 @@ export interface ActionEvent {
|
|
|
300
409
|
via: 'json' | 'form' | 'call';
|
|
301
410
|
/** refused: turned away before running (rate limit, wrong method, a body too large or malformed, people only). */
|
|
302
411
|
outcome: 'done' | 'invalid' | 'forbidden' | 'failed' | 'refused';
|
|
412
|
+
/** The HTTP status the call was answered with. */
|
|
303
413
|
status: number;
|
|
414
|
+
/** How long the call took, in milliseconds. */
|
|
304
415
|
durationMs: number;
|
|
305
416
|
/** Names of the input fields that were sent. Values are never recorded. */
|
|
306
417
|
fields: string[];
|
|
418
|
+
/** The caller's User-Agent header, if any. */
|
|
307
419
|
userAgent: string | null;
|
|
308
420
|
}
|
|
309
421
|
/**
|
|
310
422
|
* A build check rule, in the shape @pexis/checks runs. The core only stores
|
|
311
423
|
* them; see @pexis/checks for the full type.
|
|
424
|
+
*
|
|
425
|
+
* @category plugins
|
|
312
426
|
*/
|
|
313
427
|
export interface CheckRuleLike {
|
|
428
|
+
/** The rule's id, such as "myplugin/rule-name". */
|
|
314
429
|
id: string;
|
|
430
|
+
/** Whether it checks each page or the site as a whole. */
|
|
315
431
|
scope: 'page' | 'site';
|
|
432
|
+
/** The rule's category, such as "a11y" or "seo". */
|
|
316
433
|
category: string;
|
|
434
|
+
/** How a finding is reported by default. */
|
|
317
435
|
severity: 'error' | 'warning';
|
|
436
|
+
/** The check itself; see @pexis/checks. */
|
|
318
437
|
check: (ctx: never) => unknown;
|
|
319
438
|
}
|
|
320
|
-
/**
|
|
439
|
+
/**
|
|
440
|
+
* A page in the admin, added by a plugin. Rendered without scripts.
|
|
441
|
+
*
|
|
442
|
+
* @category plugins
|
|
443
|
+
*/
|
|
321
444
|
export interface AdminPanel {
|
|
322
445
|
/** URL segment under the admin, such as "tables". */
|
|
323
446
|
path: string;
|
|
324
447
|
/** Shown in the admin's navigation and as the page heading. */
|
|
325
448
|
title: string;
|
|
449
|
+
/** Renders the panel's content, read-only and without scripts. */
|
|
326
450
|
render(ctx: Context): Markup | Promise<Markup>;
|
|
327
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* What a plugin's setup() receives: everything a plugin can add to the app
|
|
454
|
+
* or read from it.
|
|
455
|
+
*
|
|
456
|
+
* @category plugins
|
|
457
|
+
*/
|
|
328
458
|
export interface PluginApi {
|
|
459
|
+
/** The app's settings. */
|
|
329
460
|
readonly config: AppConfig;
|
|
330
|
-
/**
|
|
331
|
-
|
|
461
|
+
/**
|
|
462
|
+
* Add middleware. Plugin middleware runs before the app's, in plugin order.
|
|
463
|
+
* Middleware that answers some paths itself, with no page or route behind
|
|
464
|
+
* them (an admin under /pexis/admin, Markdown copies at /page.md), says which
|
|
465
|
+
* with `answers`, so app.matches() hands those requests to the app when it
|
|
466
|
+
* is mounted inside another server.
|
|
467
|
+
*/
|
|
468
|
+
use(middleware: Middleware, options?: {
|
|
469
|
+
answers?: (url: URL, method: string) => boolean;
|
|
470
|
+
}): void;
|
|
332
471
|
/** The app's request body limit, in bytes, for plugin routes that read a body. */
|
|
333
472
|
readonly maxBodyBytes: number;
|
|
334
473
|
/** Keeps browsers from prefetching paths under this prefix (with navigation.prefetch on), such as "/auth/", where a visit has an effect. */
|
|
@@ -347,10 +486,14 @@ export interface PluginApi {
|
|
|
347
486
|
onAction(listener: (event: ActionEvent) => void): void;
|
|
348
487
|
/**
|
|
349
488
|
* Installs the one recorder of agent writes that declare an undo. Only one
|
|
350
|
-
* per app, since records carry values.
|
|
489
|
+
* per app, since records carry values.
|
|
490
|
+
*
|
|
491
|
+
* @experimental
|
|
351
492
|
*/
|
|
352
493
|
recordAgentWrites(recorder: AgentWriteRecorder): void;
|
|
494
|
+
/** The app's pages, plugins' included. */
|
|
353
495
|
pages(): readonly Page[];
|
|
496
|
+
/** The app's actions, plugins' included. */
|
|
354
497
|
actions(): readonly Action[];
|
|
355
498
|
/** Whether a plugin with this name is installed. Reliable at request time, when every plugin is set up. */
|
|
356
499
|
hasPlugin(name: string): boolean;
|
|
@@ -386,13 +529,14 @@ export interface PluginApi {
|
|
|
386
529
|
* so the inner request is rate-limited as the same client.
|
|
387
530
|
*/
|
|
388
531
|
fetch(request: Request, connection?: Connection): Promise<Response>;
|
|
389
|
-
/** Render a page's HTML response directly, skipping middleware. Null if no page matches. */
|
|
390
|
-
renderPage(path: string, ctx: Context): Promise<Response | null>;
|
|
391
532
|
}
|
|
533
|
+
/** A plugin, from definePlugin(): adds features to an app through the plugin API. */
|
|
392
534
|
export interface Plugin {
|
|
535
|
+
/** A unique name: lowercase letters, digits and hyphens. */
|
|
393
536
|
readonly name: string;
|
|
394
537
|
/** Names of plugins that must come before this one. */
|
|
395
538
|
readonly requires?: readonly string[];
|
|
539
|
+
/** Runs once, when the app is created, in the order plugins are listed. */
|
|
396
540
|
setup(api: PluginApi): void;
|
|
397
541
|
}
|
|
398
542
|
export {};
|
package/dist/urls.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
/** Attributes whose value is a URL the browser may navigate to or load. */
|
|
2
2
|
export declare const URL_ATTRIBUTES: Set<string>;
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* What a blocked URL is replaced with: harmless, and easy to find in the page.
|
|
5
|
+
*
|
|
6
|
+
* @category plugins
|
|
7
|
+
*/
|
|
4
8
|
export declare const BLOCKED_URL = "about:blank#blocked";
|
|
5
9
|
/**
|
|
6
10
|
* True for javascript: URLs, including disguised ones. Browsers ignore
|
|
7
11
|
* leading spaces and control characters and remove tabs and newlines
|
|
8
12
|
* anywhere in the scheme, so "java\tscript:" still runs; normalize first.
|
|
13
|
+
*
|
|
14
|
+
* @category plugins
|
|
15
|
+
* @param value A URL, as written in an attribute.
|
|
9
16
|
*/
|
|
10
17
|
export declare function isScriptUrl(value: string): boolean;
|
package/dist/urls.js
CHANGED
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
// html`` template, so both ways of writing markup block the same things.
|
|
3
3
|
/** Attributes whose value is a URL the browser may navigate to or load. */
|
|
4
4
|
export const URL_ATTRIBUTES = new Set(['href', 'src', 'action', 'formaction', 'xlink:href', 'poster', 'cite', 'background', 'ping']);
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* What a blocked URL is replaced with: harmless, and easy to find in the page.
|
|
7
|
+
*
|
|
8
|
+
* @category plugins
|
|
9
|
+
*/
|
|
6
10
|
export const BLOCKED_URL = 'about:blank#blocked';
|
|
7
11
|
/**
|
|
8
12
|
* True for javascript: URLs, including disguised ones. Browsers ignore
|
|
9
13
|
* leading spaces and control characters and remove tabs and newlines
|
|
10
14
|
* anywhere in the scheme, so "java\tscript:" still runs; normalize first.
|
|
15
|
+
*
|
|
16
|
+
* @category plugins
|
|
17
|
+
* @param value A URL, as written in an attribute.
|
|
11
18
|
*/
|
|
12
19
|
export function isScriptUrl(value) {
|
|
13
20
|
const normalized = value.replace(/^[\u0000-\u0020]+/, '').replace(/[\t\n\r]/g, '');
|
package/dist/urls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls.js","sourceRoot":"","sources":["../src/urls.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,yEAAyE;AAEzE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAErI
|
|
1
|
+
{"version":3,"file":"urls.js","sourceRoot":"","sources":["../src/urls.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,yEAAyE;AAEzE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAErI;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACnF,OAAO,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC1C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pexis/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Pexis core: app, pages, layouts, routing, actions, fields, context, plugins, JSX runtime and HTML rendering. Web-standard APIs only, no dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/pexis-dev/pexis/tree/main/packages/core#readme",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"dist",
|
|
32
|
+
"api.json",
|
|
32
33
|
"API.md",
|
|
33
34
|
"AGENTS.md"
|
|
34
35
|
],
|