@solidjs/web 2.0.0-rc.1 → 2.0.0-rc.2

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.
@@ -39,6 +39,15 @@ export type AssetResolver = {
39
39
  };
40
40
  /** Bare-function shorthand for `AssetResolver` (no sync fast path). */
41
41
  export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
42
+ /**
43
+ * CSP nonce for the tags a server render emits. A string applies to both
44
+ * nonce-aware destinations; a `{ script, style }` pair routes each tag to
45
+ * its destination's nonce, with `false` leaving that destination un-nonced.
46
+ */
47
+ export type CSPNonce = string | {
48
+ script: string | false;
49
+ style: string | false;
50
+ };
42
51
  /**
43
52
  * Renders a component tree synchronously to an HTML string. Async reads inside
44
53
  * `<Loading>` boundaries emit their `fallback` content; for full-graph
@@ -55,7 +64,7 @@ export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined
55
64
  * ```
56
65
  */
57
66
  export declare function renderToString<T>(fn: () => T, options?: {
58
- nonce?: string;
67
+ nonce?: CSPNonce;
59
68
  renderId?: string;
60
69
  noScripts?: boolean;
61
70
  plugins?: any[];
@@ -100,7 +109,7 @@ export declare function renderToString<T>(fn: () => T, options?: {
100
109
  * ```
101
110
  */
102
111
  export declare function renderToStream<T>(fn: () => T, options?: {
103
- nonce?: string;
112
+ nonce?: CSPNonce;
104
113
  renderId?: string;
105
114
  noScripts?: boolean;
106
115
  plugins?: any[];
package/types/server.d.ts CHANGED
@@ -57,10 +57,31 @@ export type AssetResolverFn = (
57
57
  key: string
58
58
  ) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
59
59
 
60
+ /**
61
+ * CSP nonce for the tags a server render emits. A string applies to both
62
+ * nonce-aware destinations. A `{ script, style }` pair routes each tag to
63
+ * the directive governing its fetch (`script-src-elem` / `style-src-elem`,
64
+ * falling back to `script-src` / `style-src` then `default-src`). Both
65
+ * keys are required; `false` leaves that destination un-nonced. Worker
66
+ * destinations take the script nonce, which only applies when their own
67
+ * fallback reaches `script-src`. A nonce on a `useHead` tag's own props
68
+ * always wins.
69
+ *
70
+ * Only `renderToString` / `renderToStream` take this shape. Surfaces that
71
+ * emit one script (`HydrationScript`, `generateHydrationScript`,
72
+ * `createSSRResponse`) take a string — project with `scriptNonce`.
73
+ */
74
+ export type CSPNonce = string | { script: string | false; style: string | false };
75
+
76
+ /** The script-destination half of a render `nonce`. */
77
+ export function scriptNonce(nonce?: CSPNonce): string | undefined;
78
+ /** The style-destination half of a render `nonce`. */
79
+ export function styleNonce(nonce?: CSPNonce): string | undefined;
80
+
60
81
  export function renderToString<T>(
61
82
  fn: () => T,
62
83
  options?: {
63
- nonce?: string;
84
+ nonce?: CSPNonce;
64
85
  renderId?: string;
65
86
  noScripts?: boolean;
66
87
  plugins?: SerializerPlugin[];
@@ -82,7 +103,7 @@ export function renderToString<T>(
82
103
  export function renderToStream<T>(
83
104
  fn: () => T,
84
105
  options?: {
85
- nonce?: string;
106
+ nonce?: CSPNonce;
86
107
  renderId?: string;
87
108
  noScripts?: boolean;
88
109
  plugins?: SerializerPlugin[];
@@ -4,3 +4,6 @@ export declare const memo: (fn: any) => import("solid-js").SourceAccessor<any>;
4
4
  export declare const runWithHydrationScope: (id: any, fn: any) => unknown;
5
5
  export declare const ssrAsyncValue: (value: any) => import("solid-js").SourceAccessor<any>;
6
6
  export declare const waitAsset: (promise: any) => void;
7
+ export declare const driveList: undefined;
8
+ export declare const patchableRaw: undefined;
9
+ export declare const registerPatch: undefined;
@@ -245,6 +245,15 @@ export interface FrameHostOptions {
245
245
  * identity only.
246
246
  */
247
247
  isContainer?(value: unknown): boolean;
248
+ /**
249
+ * Arms event types for behavior claims: the `_bnd` sweep collects the
250
+ * event names it finds and hands them here so delegated dispatch can
251
+ * reach them. Platform glue passes its `delegateEvents` — the option
252
+ * exists (rather than client.js importing the event system) so
253
+ * tree-shaken subsets without events pay nothing. Frames registered
254
+ * with this host inherit it unless they pass their own `delegate`.
255
+ */
256
+ delegate?(eventNames: Iterable<string>): void;
248
257
  }
249
258
 
250
259
  /** @experimental */
@@ -260,6 +269,13 @@ export interface FrameOptions {
260
269
  id?: string;
261
270
  /** Client content keyed by prop name (occurrences resolve by prop). */
262
271
  slots?: Record<string, Slot>;
272
+ /**
273
+ * Raw client props for behavior-claim resolution: server elements carrying
274
+ * `_bnd="pos=prop"` markers (compiled under the `serverComponents` option)
275
+ * resolve ref/event positions by name through this object — read live at
276
+ * dispatch/materialize time, so compiled prop getters stay latest-value.
277
+ */
278
+ props?: Record<string, unknown>;
263
279
  /**
264
280
  * Adopt existing server-rendered DOM: the first apply morphs against it,
265
281
  * and slots sync immediately (hydration attach) — a document-SSR boot
@@ -277,6 +293,8 @@ export interface FrameOptions {
277
293
  * streamed chunks).
278
294
  */
279
295
  ownerScope?<T>(fn: () => T): T;
296
+ /** Per-frame override of the host's `delegate` (see FrameHostOptions). */
297
+ delegate?(eventNames: Iterable<string>): void;
280
298
  /**
281
299
  * Boundary-driven segment reveal. When present, `#revealSegment` hands the
282
300
  * placeholder seam to this hook instead of swapping imperatively: the binding
@@ -127,6 +127,36 @@ export interface ServerFunctionsClientConfig {
127
127
  */
128
128
  export function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
129
129
 
130
+ export interface ServerFunctionRequestCall {
131
+ type: "request";
132
+ id: string;
133
+ instance: string;
134
+ request: Request;
135
+ meta: ServerFunctionMetadata | undefined;
136
+ time: number;
137
+ }
138
+
139
+ export interface ServerFunctionResponseCall {
140
+ type: "response";
141
+ id: string;
142
+ instance: string;
143
+ response: Response;
144
+ meta: ServerFunctionMetadata | undefined;
145
+ time: number;
146
+ }
147
+
148
+ export type ServerFunctionCall = ServerFunctionRequestCall | ServerFunctionResponseCall;
149
+
150
+ /**
151
+ * Observes cloned requests and responses without handling them. Subscribe
152
+ * from devtools; do not use this to replace `prepareRequest` /
153
+ * `responseHandler`. The server entry exports a no-op of the same name so
154
+ * isomorphic `@solidjs/web/server-functions` imports resolve.
155
+ */
156
+ export function observeServerFunctionCalls(
157
+ observer: (call: ServerFunctionCall) => void
158
+ ): () => void;
159
+
130
160
  /**
131
161
  * Declares a server function callable over HTTP GET: calls to the returned
132
162
  * reference go out as GET requests with the arguments codec-encoded in the
@@ -163,8 +193,9 @@ export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
163
193
  * A live call's answer: the source's iterable, plus an optional `onstatus`
164
194
  * side channel for the wire facts the reconnect loop erases from the value
165
195
  * stream — `"connected"` on each successful (re)connect, `"reconnecting"`
166
- * (with the error) on each post-connect death, `"closed"` when the source
167
- * completes or the consumer ends it.
196
+ * (with the error) on each transient post-connect death, `"closed"` when
197
+ * the source completes or the consumer ends it — with the error when the
198
+ * end was a definite rejection (4xx) failing fast instead of retrying.
168
199
  */
169
200
  export type LiveSource<R> = R & {
170
201
  onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
@@ -28,7 +28,7 @@ export type {
28
28
  } from "./shared.cjs";
29
29
  export { decodeFlashCookie, encodeFlashCookie } from "./flash.cjs";
30
30
  export type { FlashSubmission } from "./flash.cjs";
31
- import { ServerFunction } from "./shared.cjs";
31
+ import { ServerFunction, ServerFunctionMetadata } from "./shared.cjs";
32
32
 
33
33
  /**
34
34
  * The request event a server function call runs under: the base
@@ -197,6 +197,26 @@ export function createNoJSHandler(
197
197
  options?: NoJSHandlerOptions
198
198
  ): (result: unknown, request: Request, args: unknown[], thrown?: boolean) => Response;
199
199
 
200
+ export type ServerFunctionOriginMatcher =
201
+ | string
202
+ | readonly string[]
203
+ | ((origin: string, request: Request) => boolean | Promise<boolean>);
204
+
205
+ /** Same-origin validation options for server function requests. */
206
+ export interface ServerFunctionCSRFOptions {
207
+ /**
208
+ * Expected public origin. Defaults to the incoming request URL's origin.
209
+ * A function can validate origins dynamically for multi-tenant hosts.
210
+ */
211
+ origin?: ServerFunctionOriginMatcher;
212
+ /**
213
+ * Allows requests without `Sec-Fetch-Site`, `Origin`, or `Referer`.
214
+ * Cross-origin metadata is still rejected.
215
+ * @default false
216
+ */
217
+ allowRequestsWithoutOriginCheck?: boolean;
218
+ }
219
+
200
220
  /** Options for `configureServerFunctionsServer`. */
201
221
  export interface ServerFunctionsServerConfig {
202
222
  /**
@@ -287,6 +307,12 @@ export interface ServerFunctionsServerConfig {
287
307
  * @default "/_server"
288
308
  */
289
309
  endpoint?: string;
310
+ /**
311
+ * Same-origin protection for HTTP server function calls. Enabled by
312
+ * default. Set to `false` only when another trusted layer protects the
313
+ * endpoint.
314
+ */
315
+ csrf?: boolean | ServerFunctionCSRFOptions;
290
316
  /**
291
317
  * Codec options (extra plugins etc.) for decoding arguments and encoding
292
318
  * results — must match the client's. Stored in the shared layer, so
@@ -392,7 +418,9 @@ export function GET<A extends readonly any[], R>(
392
418
  fn: (...args: A) => R
393
419
  ): ServerFunction<A, Awaited<R>>;
394
420
 
395
- /** Wire-state transitions a live call's iterable can report (client side). */
421
+ /** Wire-state transitions a live call's iterable can report (client side).
422
+ * `"closed"` carries the error when a definite rejection (4xx) ended the
423
+ * call instead of the retry loop. */
396
424
  export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
397
425
 
398
426
  /**
@@ -529,6 +557,11 @@ export interface HandleServerFunctionOptions {
529
557
  args: unknown[],
530
558
  thrown?: boolean
531
559
  ): Response | Promise<Response>;
560
+ /**
561
+ * Overrides same-origin protection for this handler. Set to `false` only
562
+ * when another trusted layer protects the endpoint.
563
+ */
564
+ csrf?: boolean | ServerFunctionCSRFOptions;
532
565
  /** Overrides the configured codec options for this handler. */
533
566
  codec?: JSONCodecOptions;
534
567
  }
@@ -543,6 +576,10 @@ export interface HandleServerFunctionOptions {
543
576
  * (default `/_server`); platform adapters (h3, express, ...) convert their
544
577
  * request shape to a web `Request` around it.
545
578
  *
579
+ * Requests are same-origin by default. The handler accepts browser requests
580
+ * proven by `Sec-Fetch-Site`, `Origin`, or `Referer`, and rejects requests
581
+ * without usable metadata unless explicitly configured otherwise.
582
+ *
546
583
  * When the event carries a `response` head stub (`event.response`, see the
547
584
  * server entry's `ResponseStub`), the handler folds it onto every outgoing
548
585
  * response as the head freezes — its `Set-Cookie` values (cookies appended
@@ -606,6 +643,34 @@ export const GENERIC_SERVER_ERROR_MESSAGE: string;
606
643
  */
607
644
  export function sanitizeServerError(value: unknown): unknown;
608
645
 
646
+ export interface ServerFunctionRequestCall {
647
+ type: "request";
648
+ id: string;
649
+ instance: string;
650
+ request: Request;
651
+ meta: ServerFunctionMetadata | undefined;
652
+ time: number;
653
+ }
654
+
655
+ export interface ServerFunctionResponseCall {
656
+ type: "response";
657
+ id: string;
658
+ instance: string;
659
+ response: Response;
660
+ meta: ServerFunctionMetadata | undefined;
661
+ time: number;
662
+ }
663
+
664
+ export type ServerFunctionCall = ServerFunctionRequestCall | ServerFunctionResponseCall;
665
+
666
+ /**
667
+ * Client-only inspection seam. A no-op on this entry so isomorphic
668
+ * `@solidjs/web/server-functions` imports resolve.
669
+ */
670
+ export function observeServerFunctionCalls(
671
+ observer: (call: ServerFunctionCall) => void
672
+ ): () => void;
673
+
609
674
  /**
610
675
  * Overrides the build-variant dev flag for this module instance — the seam
611
676
  * for test harnesses and hand-rolled bundles whose packaging cannot replace
@@ -39,6 +39,15 @@ export type AssetResolver = {
39
39
  };
40
40
  /** Bare-function shorthand for `AssetResolver` (no sync fast path). */
41
41
  export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
42
+ /**
43
+ * CSP nonce for the tags a server render emits. A string applies to both
44
+ * nonce-aware destinations; a `{ script, style }` pair routes each tag to
45
+ * its destination's nonce, with `false` leaving that destination un-nonced.
46
+ */
47
+ export type CSPNonce = string | {
48
+ script: string | false;
49
+ style: string | false;
50
+ };
42
51
  /**
43
52
  * Renders a component tree synchronously to an HTML string. Async reads inside
44
53
  * `<Loading>` boundaries emit their `fallback` content; for full-graph
@@ -55,7 +64,7 @@ export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined
55
64
  * ```
56
65
  */
57
66
  export declare function renderToString<T>(fn: () => T, options?: {
58
- nonce?: string;
67
+ nonce?: CSPNonce;
59
68
  renderId?: string;
60
69
  noScripts?: boolean;
61
70
  plugins?: any[];
@@ -100,7 +109,7 @@ export declare function renderToString<T>(fn: () => T, options?: {
100
109
  * ```
101
110
  */
102
111
  export declare function renderToStream<T>(fn: () => T, options?: {
103
- nonce?: string;
112
+ nonce?: CSPNonce;
104
113
  renderId?: string;
105
114
  noScripts?: boolean;
106
115
  plugins?: any[];
@@ -57,10 +57,31 @@ export type AssetResolverFn = (
57
57
  key: string
58
58
  ) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
59
59
 
60
+ /**
61
+ * CSP nonce for the tags a server render emits. A string applies to both
62
+ * nonce-aware destinations. A `{ script, style }` pair routes each tag to
63
+ * the directive governing its fetch (`script-src-elem` / `style-src-elem`,
64
+ * falling back to `script-src` / `style-src` then `default-src`). Both
65
+ * keys are required; `false` leaves that destination un-nonced. Worker
66
+ * destinations take the script nonce, which only applies when their own
67
+ * fallback reaches `script-src`. A nonce on a `useHead` tag's own props
68
+ * always wins.
69
+ *
70
+ * Only `renderToString` / `renderToStream` take this shape. Surfaces that
71
+ * emit one script (`HydrationScript`, `generateHydrationScript`,
72
+ * `createSSRResponse`) take a string — project with `scriptNonce`.
73
+ */
74
+ export type CSPNonce = string | { script: string | false; style: string | false };
75
+
76
+ /** The script-destination half of a render `nonce`. */
77
+ export function scriptNonce(nonce?: CSPNonce): string | undefined;
78
+ /** The style-destination half of a render `nonce`. */
79
+ export function styleNonce(nonce?: CSPNonce): string | undefined;
80
+
60
81
  export function renderToString<T>(
61
82
  fn: () => T,
62
83
  options?: {
63
- nonce?: string;
84
+ nonce?: CSPNonce;
64
85
  renderId?: string;
65
86
  noScripts?: boolean;
66
87
  plugins?: SerializerPlugin[];
@@ -82,7 +103,7 @@ export function renderToString<T>(
82
103
  export function renderToStream<T>(
83
104
  fn: () => T,
84
105
  options?: {
85
- nonce?: string;
106
+ nonce?: CSPNonce;
86
107
  renderId?: string;
87
108
  noScripts?: boolean;
88
109
  plugins?: SerializerPlugin[];