@dokebi/template-inertia 0.4.1 → 0.4.4

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,129 @@
1
+ import type { Logger } from '@dokebi/core';
2
+ /**
3
+ * Files the dev server never serves, whatever the app's config says (Vite globs: a pattern
4
+ * without `/` matches the name in every folder; letter case is ignored). Vite's own defaults are
5
+ * included, because a deny list replaces them.
6
+ */
7
+ export declare const DEV_FILES_DENY: readonly string[];
8
+ /**
9
+ * Header the app process sets on every request it forwards to the Vite host: `loopback` or
10
+ * `remote`, from the browser's socket peer, the forwarding headers and the host name it judged
11
+ * (isRemoteRequest, §12). Any value the browser sent is replaced. Without it (Vite run on its
12
+ * own) the Vite host judges its own socket, the forwarding headers and the Host header.
13
+ */
14
+ export declare const DEV_CLIENT_HEADER = "x-dokebi-dev-client";
15
+ /** The whole 403 a remote host gets: no path, no allow list. */
16
+ export declare const FORBIDDEN_SHORT = "403 Forbidden\n";
17
+ /** Whether a host name (no port, no brackets) is this machine: a remote one gets no details. */
18
+ export declare function isLoopbackHost(name: string): boolean;
19
+ /**
20
+ * Headers a proxy or tunnel adds (D-0129 §12). Any of them makes a request remote: a tunnel
21
+ * client runs on this machine (its socket is loopback) and may rewrite Host to localhost, so
22
+ * neither the socket nor the Host header alone tells a local browser from a forwarded one.
23
+ */
24
+ export declare const FORWARDING_HEADERS: readonly string[];
25
+ /** Whether a socket peer address is this machine (127.0.0.0/8, ::1, ::ffff:127.x). */
26
+ export declare function isLoopbackAddress(address: string | undefined): boolean;
27
+ /**
28
+ * Whether a request comes from another machine (a `devHosts` tunnel, a proxy, a LAN address).
29
+ * Local, and so shown details, only when the socket peer is loopback, no forwarding header is
30
+ * present, the Host is a loopback name and the app process (DEV_CLIENT_HEADER, when set) said
31
+ * loopback too. An unknown peer counts as remote.
32
+ */
33
+ export declare function isRemoteRequest(headers: Readonly<Record<string, string | string[] | undefined>>, peer: string | undefined): boolean;
34
+ /**
35
+ * A Vite deny glob as a regular expression on an absolute `/` path, matched like Vite matches it
36
+ * (picomatch with `dot` and `nocase`; a pattern without `/` matches in every folder). Supports
37
+ * `*`, `**`, `?` and `{a,b}`, which is all DEV_FILES_DENY and ordinary app entries use.
38
+ */
39
+ export declare function denyPattern(glob: string): RegExp;
40
+ /** The part of Vite's resolved config this policy reads (and repairs). */
41
+ export interface ResolvedFilesShape {
42
+ readonly command: 'build' | 'serve';
43
+ readonly base: string;
44
+ readonly root?: string;
45
+ readonly cacheDir?: string;
46
+ readonly plugins?: readonly {
47
+ readonly name?: string;
48
+ }[];
49
+ readonly server?: {
50
+ readonly fs?: {
51
+ strict: boolean;
52
+ allow: string[];
53
+ deny: string[];
54
+ };
55
+ };
56
+ /** Vite's set of files the served modules import (internal, read when present). */
57
+ readonly safeModulePaths?: ReadonlySet<string>;
58
+ }
59
+ /** The request and response of a connect middleware, as far as the policy needs them. */
60
+ export interface DevRequestShape {
61
+ url?: string;
62
+ method?: string;
63
+ headers?: Record<string, string | string[] | undefined>;
64
+ /** The socket: its peer address is part of the loopback judgement (§12). */
65
+ readonly socket?: {
66
+ readonly remoteAddress?: string;
67
+ };
68
+ }
69
+ export interface DevResponseShape {
70
+ statusCode: number;
71
+ readonly headersSent?: boolean;
72
+ setHeader(name: string, value: string): unknown;
73
+ removeHeader?(name: string): unknown;
74
+ write?(chunk: unknown, ...rest: unknown[]): boolean;
75
+ end(body?: string): unknown;
76
+ }
77
+ export type DevMiddleware = (request: DevRequestShape, response: DevResponseShape, next: (error?: unknown) => void) => void;
78
+ /** What the `config` hook adds for the policy (Vite merges it into the app's config). */
79
+ export interface DevFilesPatch {
80
+ readonly server: {
81
+ readonly fs: {
82
+ readonly strict: true;
83
+ readonly allow: string[];
84
+ readonly deny: string[];
85
+ };
86
+ };
87
+ }
88
+ export interface DevFilesOptions {
89
+ /** Further files or folders the browser loads (relative to the Vite root, or absolute). */
90
+ readonly allow?: readonly string[];
91
+ /** Further Vite globs the dev server never serves (added to DEV_FILES_DENY). */
92
+ readonly deny?: readonly string[];
93
+ }
94
+ /**
95
+ * The dev file policy of one Vite config (one plugin instance). `owner` `dev-host` is the copy the
96
+ * Vite host of `dokebi dev` adds: it stays inactive when the app's config has `dokebiInertia()`.
97
+ */
98
+ export declare class DevFilesPolicy {
99
+ #private;
100
+ constructor(logger: Logger, options: DevFilesOptions, owner: 'dokebi-inertia' | 'dev-host');
101
+ /** The deny entries this policy always keeps (DEV_FILES_DENY and the plugin's `deny`). */
102
+ get required(): string[];
103
+ /** The `config` hook (dev server only): the policy as a patch, and warnings for a weaker config. */
104
+ config(raw: unknown, command: 'build' | 'serve'): DevFilesPatch | null;
105
+ /** The `configResolved` hook: repairs what a later plugin loosened and keeps the live config. */
106
+ configResolved(config: ResolvedFilesShape): void;
107
+ /** The middleware to add before Vite's own (undefined when this copy is inactive). */
108
+ middleware(): DevMiddleware | undefined;
109
+ }
110
+ /** The Vite plugin of the policy alone (what the Vite host of `dokebi dev` adds). */
111
+ export interface DokebiDevFilesPlugin {
112
+ readonly name: 'dokebi-inertia:dev-files';
113
+ readonly enforce: 'pre';
114
+ config(config: unknown, env: {
115
+ command: 'build' | 'serve';
116
+ }): DevFilesPatch | null;
117
+ configResolved(config: ResolvedFilesShape): void;
118
+ configureServer(server: {
119
+ readonly middlewares: {
120
+ use(handler: DevMiddleware): unknown;
121
+ };
122
+ }): void;
123
+ }
124
+ /**
125
+ * The dev file policy as a plugin of its own, for a vite.config without `dokebiInertia()` (which
126
+ * carries the same policy): the Vite host of `dokebi dev` adds it; it stays inactive next to
127
+ * `dokebiInertia()`.
128
+ */
129
+ export declare function dokebiDevFiles(logger: Logger, options?: DevFilesOptions): DokebiDevFilesPlugin;