@webjsdev/server 0.8.14 → 0.8.16

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.
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Type overlay for `@webjsdev/server/testing` (the handle() test harness, #267).
3
+ *
4
+ * The runtime is packages/server/src/testing.js (JSDoc-annotated JavaScript);
5
+ * this overlay exists so a TypeScript app's `import { testRequest, getCsrf }
6
+ * from '@webjsdev/server/testing'` resolves precise types instead of emitting
7
+ * TS7016. The same declarations are re-exported from the package's main
8
+ * `index.d.ts` (the helpers ship from both entry points). Zero runtime cost.
9
+ */
10
+
11
+ /** The `handle(req)` function returned by `createRequestHandler`. */
12
+ export type Handle = (req: Request) => Promise<Response> | Response;
13
+
14
+ /** A `createRequestHandler` return value, or a bare `handle` function. */
15
+ export type AppOrHandle = { handle: Handle; appDir: string } | Handle;
16
+
17
+ /** A CSRF token + cookie + header-name triple minted off the first SSR response. */
18
+ export interface CsrfPair {
19
+ /** The bare token value for the `x-webjs-csrf` request header. */
20
+ token: string;
21
+ /** The header NAME (`x-webjs-csrf`). */
22
+ header: string;
23
+ /** The `name=value` cookie string for the `Cookie` request header. */
24
+ cookie: string;
25
+ }
26
+
27
+ /**
28
+ * Coerce a bare path, full URL string, or pre-built `Request` into a `Request`.
29
+ * A bare path is prefixed with a dummy origin; `init` is merged when provided.
30
+ */
31
+ export declare function toRequest(input: string | Request, init?: RequestInit): Request;
32
+
33
+ /**
34
+ * Fire a request through the real `handle()` pipeline and return the `Response`.
35
+ * The documented one-liner: `await testRequest(app.handle, '/about')`.
36
+ */
37
+ export declare function testRequest(
38
+ handle: Handle,
39
+ input: string | Request,
40
+ init?: RequestInit,
41
+ ): Promise<Response>;
42
+
43
+ /** Read the `webjs_csrf` cookie value off a response's `Set-Cookie` header(s). */
44
+ export declare function readCsrfCookie(res: Response): string | null;
45
+
46
+ /** Collect all `Set-Cookie` header values off a response. */
47
+ export declare function getSetCookies(res: Response): string[];
48
+
49
+ /** Reduce raw `Set-Cookie` strings to a single `name=value; name2=value2` `Cookie` header value. */
50
+ export declare function cookiesToHeader(setCookies: string[]): string;
51
+
52
+ /**
53
+ * Mint a `{ token, header, cookie }` CSRF triple off the first SSR response.
54
+ * `path` is the GET path used to issue the cookie (default `/`).
55
+ */
56
+ export declare function getCsrf(handle: Handle, path?: string): Promise<CsrfPair>;
57
+
58
+ /** Merge an extra cookie string into a `RequestInit`'s `Cookie` header. */
59
+ export declare function withCookies(init: RequestInit | undefined, cookieValue: string): RequestInit;
60
+
61
+ /** Merge a session cookie string into a `RequestInit`'s `Cookie` header. */
62
+ export declare function withSessionCookie(init: RequestInit | undefined, sessionCookie: string): RequestInit;
63
+
64
+ /**
65
+ * Drive the REAL credentials login (`POST /api/auth/signin/credentials` by
66
+ * default) and capture the genuine signed session `Set-Cookie`.
67
+ */
68
+ export declare function loginAndGetCookies(
69
+ handle: Handle,
70
+ credentials: { email: string; password: string },
71
+ opts?: {
72
+ loginPath?: string;
73
+ method?: string;
74
+ body?: BodyInit;
75
+ contentType?: string;
76
+ expectStatuses?: number[];
77
+ },
78
+ ): Promise<{ cookies: string; setCookies: string[]; response: Response }>;
79
+
80
+ /**
81
+ * Compute the `/__webjs/action/<hash>/<fn>` RPC endpoint path for an action,
82
+ * addressing it the same way the generated client stub does.
83
+ */
84
+ export declare function actionEndpoint(
85
+ appDir: string,
86
+ serverFilePath: string,
87
+ fnName: string,
88
+ ): Promise<string>;
89
+
90
+ /**
91
+ * Round-trip an action through its REAL RPC endpoint (serializer + CSRF + prod
92
+ * error sanitization) and return the parsed return value.
93
+ */
94
+ export declare function invokeActionForTest<T = unknown>(
95
+ app: AppOrHandle,
96
+ serverFilePath: string,
97
+ fnName: string,
98
+ args?: unknown[],
99
+ opts?: {
100
+ csrf?: CsrfPair;
101
+ appDir?: string;
102
+ extraCookies?: string;
103
+ throwOnError?: boolean;
104
+ },
105
+ ): Promise<T>;
106
+
107
+ /**
108
+ * Lower-level variant of `invokeActionForTest` that returns the raw `Response`
109
+ * (never throws on a non-2xx), so a test can assert the status directly.
110
+ */
111
+ export declare function rawActionRequest(
112
+ app: AppOrHandle,
113
+ serverFilePath: string,
114
+ fnName: string,
115
+ args?: unknown[],
116
+ opts?: {
117
+ csrf?: CsrfPair | null;
118
+ omitCsrf?: boolean;
119
+ appDir?: string;
120
+ extraCookies?: string;
121
+ contentType?: string;
122
+ },
123
+ ): Promise<Response>;