@pyreon/zero 0.12.1 → 0.12.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/lib/actions.js +97 -0
- package/lib/actions.js.map +1 -0
- package/lib/ai.js +503 -0
- package/lib/ai.js.map +1 -0
- package/lib/api-routes.js +137 -0
- package/lib/api-routes.js.map +1 -0
- package/lib/compression.js +80 -0
- package/lib/compression.js.map +1 -0
- package/lib/cors.js +57 -0
- package/lib/cors.js.map +1 -0
- package/lib/csp.js +119 -0
- package/lib/csp.js.map +1 -0
- package/lib/env.js +217 -0
- package/lib/env.js.map +1 -0
- package/lib/favicon.js +424 -0
- package/lib/favicon.js.map +1 -0
- package/lib/i18n-routing.js +167 -0
- package/lib/i18n-routing.js.map +1 -0
- package/lib/index.js +1631 -179
- package/lib/index.js.map +1 -1
- package/lib/link.js +5 -0
- package/lib/link.js.map +1 -1
- package/lib/logger.js +78 -0
- package/lib/logger.js.map +1 -0
- package/lib/meta.js +336 -0
- package/lib/meta.js.map +1 -0
- package/lib/middleware.js +53 -0
- package/lib/middleware.js.map +1 -0
- package/lib/og-image.js +233 -0
- package/lib/og-image.js.map +1 -0
- package/lib/rate-limit.js +76 -0
- package/lib/rate-limit.js.map +1 -0
- package/lib/testing.js +179 -0
- package/lib/testing.js.map +1 -0
- package/lib/theme.js +11 -2
- package/lib/theme.js.map +1 -1
- package/lib/types/actions.d.ts +27 -24
- package/lib/types/actions.d.ts.map +1 -1
- package/lib/types/ai.d.ts +163 -0
- package/lib/types/ai.d.ts.map +1 -0
- package/lib/types/api-routes.d.ts +37 -33
- package/lib/types/api-routes.d.ts.map +1 -1
- package/lib/types/cache.d.ts +26 -22
- package/lib/types/cache.d.ts.map +1 -1
- package/lib/types/client.d.ts +13 -9
- package/lib/types/client.d.ts.map +1 -1
- package/lib/types/compression.d.ts +14 -10
- package/lib/types/compression.d.ts.map +1 -1
- package/lib/types/config.d.ts +39 -4
- package/lib/types/config.d.ts.map +1 -1
- package/lib/types/cors.d.ts +20 -16
- package/lib/types/cors.d.ts.map +1 -1
- package/lib/types/csp.d.ts +88 -0
- package/lib/types/csp.d.ts.map +1 -0
- package/lib/types/env.d.ts +118 -0
- package/lib/types/env.d.ts.map +1 -0
- package/lib/types/favicon.d.ts +70 -24
- package/lib/types/favicon.d.ts.map +1 -1
- package/lib/types/font.d.ts +68 -65
- package/lib/types/font.d.ts.map +1 -1
- package/lib/types/i18n-routing.d.ts +43 -37
- package/lib/types/i18n-routing.d.ts.map +1 -1
- package/lib/types/image-plugin.d.ts +49 -45
- package/lib/types/image-plugin.d.ts.map +1 -1
- package/lib/types/image.d.ts +47 -36
- package/lib/types/image.d.ts.map +1 -1
- package/lib/types/index.d.ts +1961 -46
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/link.d.ts +61 -56
- package/lib/types/link.d.ts.map +1 -1
- package/lib/types/logger.d.ts +57 -0
- package/lib/types/logger.d.ts.map +1 -0
- package/lib/types/meta.d.ts +180 -69
- package/lib/types/meta.d.ts.map +1 -1
- package/lib/types/middleware.d.ts +8 -4
- package/lib/types/middleware.d.ts.map +1 -1
- package/lib/types/og-image.d.ts +111 -0
- package/lib/types/og-image.d.ts.map +1 -0
- package/lib/types/rate-limit.d.ts +20 -16
- package/lib/types/rate-limit.d.ts.map +1 -1
- package/lib/types/script.d.ts +23 -19
- package/lib/types/script.d.ts.map +1 -1
- package/lib/types/seo.d.ts +47 -43
- package/lib/types/seo.d.ts.map +1 -1
- package/lib/types/testing.d.ts +64 -27
- package/lib/types/testing.d.ts.map +1 -1
- package/lib/types/theme.d.ts +22 -12
- package/lib/types/theme.d.ts.map +1 -1
- package/package.json +37 -12
- package/src/actions.ts +1 -3
- package/src/adapters/bun.ts +2 -0
- package/src/adapters/cloudflare.ts +84 -0
- package/src/adapters/index.ts +13 -1
- package/src/adapters/netlify.ts +86 -0
- package/src/adapters/node.ts +2 -0
- package/src/adapters/validate.ts +16 -0
- package/src/adapters/vercel.ts +86 -0
- package/src/ai.ts +623 -0
- package/src/compression.ts +19 -3
- package/src/csp.ts +207 -0
- package/src/entry-server.ts +28 -5
- package/src/env.ts +344 -0
- package/src/favicon.ts +221 -80
- package/src/index.ts +42 -2
- package/src/link.tsx +6 -0
- package/src/logger.ts +144 -0
- package/src/meta.tsx +124 -14
- package/src/og-image.ts +378 -0
- package/src/rate-limit.ts +11 -9
- package/src/theme.tsx +12 -1
- package/src/types.ts +1 -1
- package/src/vite-plugin.ts +5 -1
- package/lib/types/adapters/bun.d.ts +0 -6
- package/lib/types/adapters/bun.d.ts.map +0 -1
- package/lib/types/adapters/index.d.ts +0 -10
- package/lib/types/adapters/index.d.ts.map +0 -1
- package/lib/types/adapters/node.d.ts +0 -6
- package/lib/types/adapters/node.d.ts.map +0 -1
- package/lib/types/adapters/static.d.ts +0 -7
- package/lib/types/adapters/static.d.ts.map +0 -1
- package/lib/types/app.d.ts +0 -24
- package/lib/types/app.d.ts.map +0 -1
- package/lib/types/entry-server.d.ts +0 -37
- package/lib/types/entry-server.d.ts.map +0 -1
- package/lib/types/error-overlay.d.ts +0 -6
- package/lib/types/error-overlay.d.ts.map +0 -1
- package/lib/types/fs-router.d.ts +0 -47
- package/lib/types/fs-router.d.ts.map +0 -1
- package/lib/types/isr.d.ts +0 -9
- package/lib/types/isr.d.ts.map +0 -1
- package/lib/types/not-found.d.ts +0 -7
- package/lib/types/not-found.d.ts.map +0 -1
- package/lib/types/types.d.ts +0 -111
- package/lib/types/types.d.ts.map +0 -1
- package/lib/types/utils/use-intersection-observer.d.ts +0 -10
- package/lib/types/utils/use-intersection-observer.d.ts.map +0 -1
- package/lib/types/utils/with-headers.d.ts +0 -6
- package/lib/types/utils/with-headers.d.ts.map +0 -1
- package/lib/types/vite-plugin.d.ts +0 -17
- package/lib/types/vite-plugin.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-
|
|
1
|
+
{"version":3,"file":"api-routes2.d.ts","names":[],"sources":["../../../src/api-routes.ts"],"mappings":";;;;KAKY,UAAA;AAAZ;AAAA,UAGiB,UAAA;;EAEf,OAAA,EAAS,OAAA;EALW;EAOpB,GAAA,EAAK,GAAA;EAJoB;EAMzB,IAAA;EAJS;EAMT,MAAA,EAAQ,MAAA;EAAA;EAER,OAAA,EAAS,OAAA;AAAA;;KAIC,UAAA,IAAc,GAAA,EAAK,UAAA,KAAe,QAAA,GAAW,OAAA,CAAQ,QAAA;;UAGhD,cAAA;EACf,GAAA,GAAM,UAAA;EACN,IAAA,GAAO,UAAA;EACP,GAAA,GAAM,UAAA;EACN,KAAA,GAAQ,UAAA;EACR,MAAA,GAAS,UAAA;EACT,IAAA,GAAO,UAAA;EACP,OAAA,GAAU,UAAA;AAAA;AAVZ;AAAA,UAciB,aAAA;;EAEf,OAAA;EAhB4C;EAkB5C,MAAA,EAAQ,cAAA;AAAA;;;;;iBASM,aAAA,CAAc,OAAA,UAAiB,IAAA,WAAe,MAAA;;;;;iBAwC9C,mBAAA,CAAoB,MAAA,EAAQ,aAAA,KAAkB,UAAA;;;;;iBAsC9C,UAAA,CAAW,QAAA;;;;;;;;;;iBAmBX,oBAAA,CAAqB,QAAA;;;;;iBAwCrB,sBAAA,CAAuB,KAAA,YAAiB,SAAA"}
|
package/lib/types/cache.d.ts
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { Middleware } from "@pyreon/server";
|
|
2
|
+
|
|
3
|
+
//#region src/cache.d.ts
|
|
4
|
+
interface CacheConfig {
|
|
5
|
+
/** Cache duration for immutable hashed assets (seconds). Default: 31536000 (1 year) */
|
|
6
|
+
immutable?: number;
|
|
7
|
+
/** Cache duration for static assets like images/fonts (seconds). Default: 86400 (1 day) */
|
|
8
|
+
static?: number;
|
|
9
|
+
/** Cache duration for pages (seconds). Default: 0 (no cache) */
|
|
10
|
+
pages?: number;
|
|
11
|
+
/** Stale-while-revalidate window for pages (seconds). Default: 60 */
|
|
12
|
+
staleWhileRevalidate?: number;
|
|
13
|
+
/** Custom rules by URL pattern. */
|
|
14
|
+
rules?: CacheRule[];
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
interface CacheRule {
|
|
17
|
+
/** URL pattern to match (glob-style). e.g. "/api/*" */
|
|
18
|
+
match: string;
|
|
19
|
+
/** Cache-Control header value. */
|
|
20
|
+
control: string;
|
|
19
21
|
}
|
|
20
22
|
/** @internal Exported for testing */
|
|
21
|
-
|
|
23
|
+
declare function matchGlob(pattern: string, path: string): boolean;
|
|
22
24
|
/**
|
|
23
25
|
* Cache control middleware for Zero.
|
|
24
26
|
* Sets Cache-Control headers on the response based on asset type.
|
|
@@ -39,16 +41,18 @@ export declare function matchGlob(pattern: string, path: string): boolean;
|
|
|
39
41
|
* ],
|
|
40
42
|
* })
|
|
41
43
|
*/
|
|
42
|
-
|
|
44
|
+
declare function cacheMiddleware(config?: CacheConfig): Middleware;
|
|
43
45
|
/**
|
|
44
46
|
* Security headers middleware.
|
|
45
47
|
* Adds common security headers to all responses.
|
|
46
48
|
*/
|
|
47
|
-
|
|
49
|
+
declare function securityHeaders(): Middleware;
|
|
48
50
|
/**
|
|
49
51
|
* Compression detection middleware.
|
|
50
52
|
* Sets Vary: Accept-Encoding header so caches can serve compressed variants.
|
|
51
53
|
* Actual compression is handled by the runtime (Bun/Node) or reverse proxy.
|
|
52
54
|
*/
|
|
53
|
-
|
|
54
|
-
//#
|
|
55
|
+
declare function varyEncoding(): Middleware;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { CacheConfig, CacheRule, cacheMiddleware, matchGlob, securityHeaders, varyEncoding };
|
|
58
|
+
//# sourceMappingURL=cache2.d.ts.map
|
package/lib/types/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"cache2.d.ts","names":[],"sources":["../../../src/cache.ts"],"mappings":";;;UAaiB,WAAA;;EAEf,SAAA;EAF0B;EAI1B,MAAA;EAMiB;EAJjB,KAAA;EAFA;EAIA,oBAAA;EAAA;EAEA,KAAA,GAAQ,SAAA;AAAA;AAAA,UAGO,SAAA;EAHE;EAKjB,KAAA;EAFwB;EAIxB,OAAA;AAAA;;iBAQc,SAAA,CAAU,OAAA,UAAiB,IAAA;;;;;AAiD3C;;;;;;;;;AA0BA;;;;;AAeA;;iBAzCgB,eAAA,CAAgB,MAAA,GAAQ,WAAA,GAAmB,UAAA;;;;;iBA0B3C,eAAA,CAAA,GAAmB,UAAA;;;;;;iBAenB,YAAA,CAAA,GAAgB,UAAA"}
|
package/lib/types/client.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { ComponentFn } from "@pyreon/core";
|
|
2
|
+
import { RouteRecord } from "@pyreon/router";
|
|
3
|
+
|
|
4
|
+
//#region src/client.d.ts
|
|
5
|
+
interface StartClientOptions {
|
|
6
|
+
/** Route definitions. */
|
|
7
|
+
routes: RouteRecord[];
|
|
8
|
+
/** Root layout component. */
|
|
9
|
+
layout?: ComponentFn;
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* Start the client-side app — hydrates SSR content or mounts fresh for SPA.
|
|
@@ -15,5 +17,7 @@ export interface StartClientOptions {
|
|
|
15
17
|
*
|
|
16
18
|
* startClient({ routes })
|
|
17
19
|
*/
|
|
18
|
-
|
|
19
|
-
//#
|
|
20
|
+
declare function startClient(options: StartClientOptions): () => void;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { StartClientOptions, startClient };
|
|
23
|
+
//# sourceMappingURL=client2.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"client2.d.ts","names":[],"sources":["../../../src/client.ts"],"mappings":";;;;UAQiB,kBAAA;;EAEf,MAAA,EAAQ,WAAA;EAFyB;EAIjC,MAAA,GAAS,WAAA;AAAA;;;;;;;AAYX;;;iBAAgB,WAAA,CAAY,OAAA,EAAS,kBAAA"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Middleware } from "@pyreon/server";
|
|
2
|
+
|
|
3
|
+
//#region src/compression.d.ts
|
|
4
|
+
interface CompressionConfig {
|
|
5
|
+
/** Minimum response size in bytes to compress. Default: `1024` (1KB) */
|
|
6
|
+
threshold?: number;
|
|
7
|
+
/** Encoding preference order. Default: `["gzip", "deflate"]` */
|
|
8
|
+
encodings?: ('gzip' | 'deflate')[];
|
|
7
9
|
}
|
|
8
10
|
/**
|
|
9
11
|
* Compression middleware — compresses responses using gzip or deflate
|
|
@@ -18,7 +20,7 @@ export interface CompressionConfig {
|
|
|
18
20
|
* compressionMiddleware() // gzip with 1KB threshold
|
|
19
21
|
* compressionMiddleware({ threshold: 512, encodings: ["gzip"] })
|
|
20
22
|
*/
|
|
21
|
-
|
|
23
|
+
declare function compressionMiddleware(config?: CompressionConfig): Middleware;
|
|
22
24
|
/**
|
|
23
25
|
* Compress a Response body if it meets the criteria.
|
|
24
26
|
* Use this to post-process responses after the handler runs.
|
|
@@ -27,7 +29,9 @@ export declare function compressionMiddleware(config?: CompressionConfig): Middl
|
|
|
27
29
|
* const response = await handler(request)
|
|
28
30
|
* const compressed = await compressResponse(response, 'gzip', 1024)
|
|
29
31
|
*/
|
|
30
|
-
|
|
32
|
+
declare function compressResponse(response: Response, encoding: 'gzip' | 'deflate', threshold: number): Promise<Response>;
|
|
31
33
|
/** Check if a content type is compressible. Exported for testing. */
|
|
32
|
-
|
|
33
|
-
//#
|
|
34
|
+
declare function isCompressible(contentType: string): boolean;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { CompressionConfig, compressResponse, compressionMiddleware, isCompressible };
|
|
37
|
+
//# sourceMappingURL=compression2.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"compression2.d.ts","names":[],"sources":["../../../src/compression.ts"],"mappings":";;;UAIiB,iBAAA;;EAEf,SAAA;EAFgC;EAIhC,SAAA;AAAA;;AAgBF;;;;;;;;;AAyBA;;;iBAzBgB,qBAAA,CAAsB,MAAA,GAAQ,iBAAA,GAAyB,UAAA;;;;;;;;;iBAyBjD,gBAAA,CACpB,QAAA,EAAU,QAAA,EACV,QAAA,sBACA,SAAA,WACC,OAAA,CAAQ,QAAA;;iBAsCK,cAAA,CAAe,WAAA"}
|
package/lib/types/config.d.ts
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Middleware } from "@pyreon/server";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type RenderMode = 'ssr' | 'ssg' | 'spa' | 'isr';
|
|
5
|
+
interface ISRConfig {
|
|
6
|
+
/** Revalidation interval in seconds. */
|
|
7
|
+
revalidate: number;
|
|
8
|
+
}
|
|
9
|
+
interface ZeroConfig {
|
|
10
|
+
/** Default rendering mode. Default: "ssr" */
|
|
11
|
+
mode?: RenderMode;
|
|
12
|
+
/** Vite config overrides. */
|
|
13
|
+
vite?: Record<string, unknown>;
|
|
14
|
+
/** SSR options. */
|
|
15
|
+
ssr?: {
|
|
16
|
+
/** Streaming mode. Default: "string" */mode?: 'string' | 'stream';
|
|
17
|
+
};
|
|
18
|
+
/** SSG options — only used when mode is "ssg". */
|
|
19
|
+
ssg?: {
|
|
20
|
+
/** Paths to prerender (or function returning paths). */paths?: string[] | (() => string[] | Promise<string[]>);
|
|
21
|
+
};
|
|
22
|
+
/** ISR config — only used when mode is "isr". */
|
|
23
|
+
isr?: ISRConfig;
|
|
24
|
+
/** Deploy adapter. Default: "node" */
|
|
25
|
+
adapter?: 'node' | 'bun' | 'static' | 'vercel' | 'cloudflare' | 'netlify';
|
|
26
|
+
/** Base URL path. Default: "/" */
|
|
27
|
+
base?: string;
|
|
28
|
+
/** App-level middleware applied to all routes. */
|
|
29
|
+
middleware?: Middleware[];
|
|
30
|
+
/** Server port for dev/preview. Default: 3000 */
|
|
31
|
+
port?: number;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/config.d.ts
|
|
2
35
|
/**
|
|
3
36
|
* Define a Zero configuration.
|
|
4
37
|
* Used in `zero.config.ts` at the project root.
|
|
@@ -12,7 +45,9 @@ import type { ZeroConfig } from './types';
|
|
|
12
45
|
* port: 3000,
|
|
13
46
|
* })
|
|
14
47
|
*/
|
|
15
|
-
|
|
48
|
+
declare function defineConfig(config: ZeroConfig): ZeroConfig;
|
|
16
49
|
/** Merge user config with defaults. */
|
|
17
|
-
|
|
18
|
-
//#
|
|
50
|
+
declare function resolveConfig(userConfig?: ZeroConfig): Required<Pick<ZeroConfig, 'mode' | 'base' | 'port' | 'adapter'>> & ZeroConfig;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { defineConfig, resolveConfig };
|
|
53
|
+
//# sourceMappingURL=config2.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"config2.d.ts","names":[],"sources":["../../../src/types.ts","../../../src/config.ts"],"mappings":";;;KA6CY,UAAA;AAAA,UAEK,SAAA;EAoCF;EAlCb,UAAA;AAAA;AAAA,UAKe,UAAA;;EAEf,IAAA,GAAO,UAAA;;EAGP,IAAA,GAAO,MAAA;EC5CmB;ED+C1B,GAAA;IC/C0D,wCDiDxD,IAAA;EAAA;ECjD8C;EDqDhD,GAAA;ICrD0D,wDDuDxD,KAAA,gCAAqC,OAAA;EAAA;;EAIvC,GAAA,GAAM,SAAA;ECpDS;EDuDf,OAAA;ECvDC;ED0DD,IAAA;EC1D8E;ED6D9E,UAAA,GAAa,UAAA;EC9DD;EDiEZ,IAAA;AAAA;;;;;;;AAzCF;;;;;AAEA;;;;iBChCgB,YAAA,CAAa,MAAA,EAAQ,UAAA,GAAa,UAAA;ADuClD;AAAA,iBClCgB,aAAA,CACd,UAAA,GAAY,UAAA,GACX,QAAA,CAAS,IAAA,CAAK,UAAA,2CAAqD,UAAA"}
|
package/lib/types/cors.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { Middleware } from "@pyreon/server";
|
|
2
|
+
|
|
3
|
+
//#region src/cors.d.ts
|
|
4
|
+
interface CorsConfig {
|
|
5
|
+
/** Allowed origins. Use `"*"` for any origin. Default: `"*"` */
|
|
6
|
+
origin?: string | string[] | ((origin: string) => boolean);
|
|
7
|
+
/** Allowed HTTP methods. Default: `["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]` */
|
|
8
|
+
methods?: string[];
|
|
9
|
+
/** Allowed request headers. Default: `["Content-Type", "Authorization"]` */
|
|
10
|
+
allowedHeaders?: string[];
|
|
11
|
+
/** Headers exposed to the client. Default: `[]` */
|
|
12
|
+
exposedHeaders?: string[];
|
|
13
|
+
/** Allow credentials (cookies, auth headers). Default: `false` */
|
|
14
|
+
credentials?: boolean;
|
|
15
|
+
/** Preflight cache duration in seconds. Default: `86400` (24 hours) */
|
|
16
|
+
maxAge?: number;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* CORS middleware — handles preflight requests and sets appropriate
|
|
@@ -28,5 +30,7 @@ export interface CorsConfig {
|
|
|
28
30
|
* // Multiple origins
|
|
29
31
|
* corsMiddleware({ origin: ["https://app.com", "https://admin.com"] })
|
|
30
32
|
*/
|
|
31
|
-
|
|
32
|
-
//#
|
|
33
|
+
declare function corsMiddleware(config?: CorsConfig): Middleware;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { CorsConfig, corsMiddleware };
|
|
36
|
+
//# sourceMappingURL=cors2.d.ts.map
|
package/lib/types/cors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"cors2.d.ts","names":[],"sources":["../../../src/cors.ts"],"mappings":";;;UAIiB,UAAA;;EAEf,MAAA,yBAA+B,MAAA;EAFN;EAIzB,OAAA;EAJyB;EAMzB,cAAA;EAJ+B;EAM/B,cAAA;EAFA;EAIA,WAAA;EAAA;EAEA,MAAA;AAAA;;AAqBF;;;;;;;;;;;;;;iBAAgB,cAAA,CAAe,MAAA,GAAQ,UAAA,GAAkB,UAAA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Middleware } from "@pyreon/server";
|
|
2
|
+
|
|
3
|
+
//#region src/csp.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Read the current CSP nonce in a component.
|
|
6
|
+
*
|
|
7
|
+
* SSR: reads from per-request `ctx.locals.cspNonce` via Pyreon's context
|
|
8
|
+
* system — fully isolated between concurrent requests via AsyncLocalStorage.
|
|
9
|
+
* Client/dev: falls back to module-level variable set by middleware.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { useNonce } from "@pyreon/zero/csp"
|
|
14
|
+
*
|
|
15
|
+
* function InlineScript() {
|
|
16
|
+
* const nonce = useNonce()
|
|
17
|
+
* return <script nonce={nonce}>console.log("safe")</script>
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function useNonce(): string;
|
|
22
|
+
interface CspDirectives {
|
|
23
|
+
defaultSrc?: string[];
|
|
24
|
+
scriptSrc?: string[];
|
|
25
|
+
styleSrc?: string[];
|
|
26
|
+
imgSrc?: string[];
|
|
27
|
+
fontSrc?: string[];
|
|
28
|
+
connectSrc?: string[];
|
|
29
|
+
mediaSrc?: string[];
|
|
30
|
+
objectSrc?: string[];
|
|
31
|
+
frameSrc?: string[];
|
|
32
|
+
childSrc?: string[];
|
|
33
|
+
workerSrc?: string[];
|
|
34
|
+
frameAncestors?: string[];
|
|
35
|
+
formAction?: string[];
|
|
36
|
+
baseUri?: string[];
|
|
37
|
+
manifestSrc?: string[];
|
|
38
|
+
/** Reporting endpoint URL. */
|
|
39
|
+
reportUri?: string;
|
|
40
|
+
/** Reporting endpoint name (CSP Level 3). */
|
|
41
|
+
reportTo?: string;
|
|
42
|
+
/** Upgrade insecure requests. */
|
|
43
|
+
upgradeInsecureRequests?: boolean;
|
|
44
|
+
/** Block all mixed content. */
|
|
45
|
+
blockAllMixedContent?: boolean;
|
|
46
|
+
}
|
|
47
|
+
interface CspConfig {
|
|
48
|
+
/** CSP directives. */
|
|
49
|
+
directives: CspDirectives;
|
|
50
|
+
/**
|
|
51
|
+
* Report-only mode — logs violations without blocking.
|
|
52
|
+
* Uses Content-Security-Policy-Report-Only header instead.
|
|
53
|
+
* Default: false
|
|
54
|
+
*/
|
|
55
|
+
reportOnly?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build a CSP header string from directives.
|
|
59
|
+
* Exported for testing.
|
|
60
|
+
*/
|
|
61
|
+
declare function buildCspHeader(directives: CspDirectives, nonce?: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* CSP middleware — sets Content-Security-Policy header.
|
|
64
|
+
*
|
|
65
|
+
* When directives contain `"'nonce'"`, a fresh nonce is generated per-request
|
|
66
|
+
* and attached to `ctx.locals.cspNonce` for use in inline script tags.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* // Apply to all routes
|
|
71
|
+
* export default defineConfig({
|
|
72
|
+
* middleware: [
|
|
73
|
+
* cspMiddleware({
|
|
74
|
+
* directives: {
|
|
75
|
+
* defaultSrc: ["'self'"],
|
|
76
|
+
* scriptSrc: ["'self'", "'nonce'"],
|
|
77
|
+
* styleSrc: ["'self'", "'unsafe-inline'"],
|
|
78
|
+
* imgSrc: ["'self'", "data:", "https:"],
|
|
79
|
+
* },
|
|
80
|
+
* }),
|
|
81
|
+
* ],
|
|
82
|
+
* })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function cspMiddleware(config: CspConfig): Middleware;
|
|
86
|
+
//#endregion
|
|
87
|
+
export { CspConfig, CspDirectives, buildCspHeader, cspMiddleware, useNonce };
|
|
88
|
+
//# sourceMappingURL=csp2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csp2.d.ts","names":[],"sources":["../../../src/csp.ts"],"mappings":";;;;;;;;;;;;AA8EA;;;;;;;;iBAhCgB,QAAA,CAAA;AAAA,UAMC,aAAA;EACf,UAAA;EACA,SAAA;EACA,QAAA;EACA,MAAA;EACA,OAAA;EACA,UAAA;EACA,QAAA;EACA,SAAA;EACA,QAAA;EACA,QAAA;EACA,SAAA;EACA,cAAA;EACA,UAAA;EACA,OAAA;EACA,WAAA;EAmH0D;EAjH1D,SAAA;;EAEA,QAAA;;EAEA,uBAAA;;EAEA,oBAAA;AAAA;AAAA,UAGe,SAAA;;EAEf,UAAA,EAAY,aAAA;;;;;;EAMZ,UAAA;AAAA;;;;;iBA2Bc,cAAA,CAAe,UAAA,EAAY,aAAA,EAAe,KAAA;;;;;;;;;;;;;;;;;;;;;;;;iBAqE1C,aAAA,CAAc,MAAA,EAAQ,SAAA,GAAY,UAAA"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//#region src/env.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Environment variable validation.
|
|
4
|
+
*
|
|
5
|
+
* Infers types from default values — no verbose validator imports needed.
|
|
6
|
+
* Explicit validators (`url()`, `oneOf()`) available for special cases.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { validateEnv, url, oneOf } from "@pyreon/zero/env"
|
|
11
|
+
*
|
|
12
|
+
* const env = validateEnv({
|
|
13
|
+
* PORT: 3000, // number, default 3000
|
|
14
|
+
* DEBUG: false, // boolean, default false
|
|
15
|
+
* HOST: "localhost", // string, default "localhost"
|
|
16
|
+
* DATABASE_URL: url(), // validated URL, required
|
|
17
|
+
* NODE_ENV: oneOf(["development", "production", "test"]),
|
|
18
|
+
* API_KEY: String, // required string, no default
|
|
19
|
+
* MAX_RETRIES: Number, // required number, no default
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
interface EnvValidatorOptions<T = string> {
|
|
24
|
+
/** Whether this variable is required. Default: true */
|
|
25
|
+
required?: boolean;
|
|
26
|
+
/** Default value when not set. Makes the variable optional. */
|
|
27
|
+
default?: T;
|
|
28
|
+
/** Human-readable description for error messages. */
|
|
29
|
+
description?: string;
|
|
30
|
+
}
|
|
31
|
+
interface EnvValidator<T> {
|
|
32
|
+
__type: 'env-validator';
|
|
33
|
+
parse: (raw: string | undefined, key: string) => T;
|
|
34
|
+
required: boolean;
|
|
35
|
+
defaultValue?: T | undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* String validator — accepts any non-empty string.
|
|
39
|
+
*/
|
|
40
|
+
declare function str(options?: EnvValidatorOptions<string>): EnvValidator<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Number validator — parses to a number, rejects NaN.
|
|
43
|
+
*/
|
|
44
|
+
declare function num(options?: EnvValidatorOptions<number>): EnvValidator<number>;
|
|
45
|
+
/**
|
|
46
|
+
* Boolean validator — accepts "true"/"1" as true, "false"/"0" as false.
|
|
47
|
+
*/
|
|
48
|
+
declare function bool(options?: EnvValidatorOptions<boolean>): EnvValidator<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* URL validator — validates that the value is a valid URL.
|
|
51
|
+
*/
|
|
52
|
+
declare function url(options?: EnvValidatorOptions<string>): EnvValidator<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Enum validator — value must be one of the allowed values.
|
|
55
|
+
*/
|
|
56
|
+
declare function oneOf<T extends string>(values: readonly T[], options?: EnvValidatorOptions<T>): EnvValidator<T>;
|
|
57
|
+
/** Schema entry: plain value, constructor, or explicit validator. */
|
|
58
|
+
type SchemaEntry = string | number | boolean | StringConstructor | NumberConstructor | BooleanConstructor | EnvValidator<any>;
|
|
59
|
+
/** Infer the output type from a schema entry. */
|
|
60
|
+
type InferEntry<T> = T extends EnvValidator<infer V> ? V : T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends string ? string : T extends number ? number : T extends boolean ? boolean : never;
|
|
61
|
+
type InferEnvSchema<T> = { [K in keyof T]: InferEntry<T[K]> };
|
|
62
|
+
/**
|
|
63
|
+
* Validate environment variables.
|
|
64
|
+
*
|
|
65
|
+
* Schema values can be:
|
|
66
|
+
* - **Default values**: `3000`, `false`, `"localhost"` → type inferred, used as default
|
|
67
|
+
* - **Constructors**: `String`, `Number`, `Boolean` → required, no default
|
|
68
|
+
* - **Validators**: `url()`, `oneOf([...])`, `str()`, `num()`, `bool()` → explicit validation
|
|
69
|
+
* - **Custom**: `schema(raw => z.coerce.number().parse(raw))` — bridge to any schema library
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { validateEnv, url, oneOf } from "@pyreon/zero/env"
|
|
74
|
+
*
|
|
75
|
+
* const env = validateEnv({
|
|
76
|
+
* PORT: 3000, // optional, default 3000
|
|
77
|
+
* DATABASE_URL: url(), // required, validated URL
|
|
78
|
+
* NODE_ENV: oneOf(["dev", "prod", "test"]), // required, must be one of
|
|
79
|
+
* API_KEY: String, // required string
|
|
80
|
+
* DEBUG: false, // optional, default false
|
|
81
|
+
* })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function validateEnv<T extends Record<string, SchemaEntry>>(schema: T, source?: Record<string, string | undefined>): InferEnvSchema<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Extract public environment variables (prefixed with `ZERO_PUBLIC_`).
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const pub = publicEnv()
|
|
91
|
+
* // → { API_URL: "https://...", APP_NAME: "MyApp" }
|
|
92
|
+
*
|
|
93
|
+
* const pub = publicEnv({ API_URL: url(), APP_NAME: "Default" })
|
|
94
|
+
* // → validated against ZERO_PUBLIC_API_URL, ZERO_PUBLIC_APP_NAME
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function publicEnv(): Record<string, string>;
|
|
98
|
+
declare function publicEnv<T extends Record<string, SchemaEntry>>(schema: T): InferEnvSchema<T>;
|
|
99
|
+
/**
|
|
100
|
+
* Create an env validator from a custom parse function.
|
|
101
|
+
* Use this to integrate any schema library (Zod, Valibot, ArkType, etc.).
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { z } from "zod"
|
|
106
|
+
* import { validateEnv, schema } from "@pyreon/zero/env"
|
|
107
|
+
*
|
|
108
|
+
* const env = validateEnv({
|
|
109
|
+
* PORT: schema(raw => z.coerce.number().parse(raw)),
|
|
110
|
+
* DATABASE_URL: schema(raw => z.string().url().parse(raw)),
|
|
111
|
+
* HOST: "localhost", // plain defaults still work alongside
|
|
112
|
+
* })
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare function schema<T>(parse: (raw: string) => T): EnvValidator<T>;
|
|
116
|
+
//#endregion
|
|
117
|
+
export { EnvValidator, EnvValidatorOptions, bool, num, oneOf, publicEnv, schema, str, url, validateEnv };
|
|
118
|
+
//# sourceMappingURL=env2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env2.d.ts","names":[],"sources":["../../../src/env.ts"],"mappings":";;AAsBA;;;;;;;;;;;AASA;;;;;;;;;UATiB,mBAAA;EAYf;EAVA,QAAA;EAWe;EATf,OAAA,GAAU,CAAA;EASM;EAPhB,WAAA;AAAA;AAAA,UAGe,YAAA;EACf,MAAA;EACA,KAAA,GAAQ,GAAA,sBAAyB,GAAA,aAAgB,CAAA;EACjD,QAAA;EACA,YAAA,GAAe,CAAA;AAAA;;AA2BjB;;iBAnBgB,GAAA,CAAI,OAAA,GAAU,mBAAA,WAA8B,YAAA;;;;iBAmB5C,GAAA,CAAI,OAAA,GAAU,mBAAA,WAA8B,YAAA;;;AAuB5D;iBAAgB,IAAA,CAAK,OAAA,GAAU,mBAAA,YAA+B,YAAA;;;;iBAsB9C,GAAA,CAAI,OAAA,GAAU,mBAAA,WAA8B,YAAA;;;;iBAwB5C,KAAA,kBAAA,CACd,MAAA,WAAiB,CAAA,IACjB,OAAA,GAAU,mBAAA,CAAoB,CAAA,IAC7B,YAAA,CAAa,CAAA;;KAmEX,WAAA,+BAED,iBAAA,GAAoB,iBAAA,GAAoB,kBAAA,GACxC,YAAA;;KAGC,UAAA,MACH,CAAA,SAAU,YAAA,YAAwB,CAAA,GAClC,CAAA,SAAU,iBAAA,YACV,CAAA,SAAU,iBAAA,YACV,CAAA,SAAU,kBAAA,aACV,CAAA,2BACA,CAAA,2BACA,CAAA;AAAA,KAGG,cAAA,oBACS,CAAA,GAAI,UAAA,CAAW,CAAA,CAAE,CAAA;;AAvF/B;;;;;;;;;;;;;;;;;;;;AAwBC;iBA0Fe,WAAA,WAAsB,MAAA,SAAe,WAAA,EAAA,CACnD,MAAA,EAAQ,CAAA,EACR,MAAA,GAAS,MAAA,+BACR,cAAA,CAAe,CAAA;;;;;;;;;;;;;iBAqCF,SAAA,CAAA,GAAa,MAAA;AAAA,iBACb,SAAA,WAAoB,MAAA,SAAe,WAAA,EAAA,CAAc,MAAA,EAAQ,CAAA,GAAI,cAAA,CAAe,CAAA;;;;;;;;;;;;;;;;;iBAwC5E,MAAA,GAAA,CAAU,KAAA,GAAQ,GAAA,aAAgB,CAAA,GAAI,YAAA,CAAa,CAAA"}
|
package/lib/types/favicon.d.ts
CHANGED
|
@@ -1,21 +1,49 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
|
|
3
|
+
//#region src/favicon.d.ts
|
|
4
|
+
interface FaviconLocaleConfig {
|
|
5
|
+
/** Locale-specific source icon (SVG or PNG). */
|
|
6
|
+
source: string;
|
|
7
|
+
/** Optional dark mode variant for this locale. */
|
|
8
|
+
darkSource?: string;
|
|
9
|
+
}
|
|
10
|
+
interface FaviconPluginConfig {
|
|
11
|
+
/** Path to the source icon (SVG or PNG, at least 512x512 for PNG). */
|
|
12
|
+
source: string;
|
|
13
|
+
/** Theme color for web manifest. Default: "#ffffff" */
|
|
14
|
+
themeColor?: string;
|
|
15
|
+
/** Background color for web manifest. Default: "#ffffff" */
|
|
16
|
+
backgroundColor?: string;
|
|
17
|
+
/** App name for web manifest. Uses package.json name if not set. */
|
|
18
|
+
name?: string;
|
|
19
|
+
/** Generate web manifest. Default: true */
|
|
20
|
+
manifest?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Dark mode favicon (SVG only).
|
|
23
|
+
* When provided, the SVG favicon uses prefers-color-scheme media query
|
|
24
|
+
* to switch between light and dark variants.
|
|
25
|
+
*/
|
|
26
|
+
darkSource?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Locale-specific icon overrides. Each key is a locale code,
|
|
29
|
+
* value is a source icon (and optional dark variant).
|
|
30
|
+
* Locales not in this map use the base `source`.
|
|
31
|
+
*
|
|
32
|
+
* Generated files are placed under `/{locale}/` prefix:
|
|
33
|
+
* /de/favicon.svg, /de/favicon-32x32.png, etc.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* faviconPlugin({
|
|
38
|
+
* source: "./icon.svg",
|
|
39
|
+
* locales: {
|
|
40
|
+
* de: { source: "./icon-de.svg" },
|
|
41
|
+
* cs: { source: "./icon-cs.svg" },
|
|
42
|
+
* },
|
|
43
|
+
* })
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
locales?: Record<string, FaviconLocaleConfig>;
|
|
19
47
|
}
|
|
20
48
|
/**
|
|
21
49
|
* Favicon generation Vite plugin.
|
|
@@ -33,11 +61,29 @@ export interface FaviconPluginConfig {
|
|
|
33
61
|
* }
|
|
34
62
|
* ```
|
|
35
63
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
64
|
+
declare function faviconPlugin(config: FaviconPluginConfig): Plugin;
|
|
65
|
+
/**
|
|
66
|
+
* Get favicon link tags for a specific locale.
|
|
67
|
+
* Returns link objects suitable for `useHead()` or direct HTML injection.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const links = faviconLinks("de", { source: "./icon.svg", locales: { de: { source: "./icon-de.svg" } } })
|
|
72
|
+
* // → [{ rel: "icon", type: "image/svg+xml", href: "/de/favicon.svg" }, ...]
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function faviconLinks(locale: string | undefined, config: FaviconPluginConfig): Array<{
|
|
76
|
+
rel: string;
|
|
77
|
+
type?: string;
|
|
78
|
+
sizes?: string;
|
|
79
|
+
href: string;
|
|
80
|
+
}>;
|
|
81
|
+
interface IcoEntry {
|
|
82
|
+
buffer: Buffer;
|
|
83
|
+
size: number;
|
|
40
84
|
}
|
|
41
85
|
/** @internal Exported for testing */
|
|
42
|
-
|
|
43
|
-
//#
|
|
86
|
+
declare function createIcoFromPngs(entries: IcoEntry[]): Uint8Array;
|
|
87
|
+
//#endregion
|
|
88
|
+
export { FaviconLocaleConfig, FaviconPluginConfig, IcoEntry, createIcoFromPngs, faviconLinks, faviconPlugin };
|
|
89
|
+
//# sourceMappingURL=favicon2.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"favicon2.d.ts","names":[],"sources":["../../../src/favicon.ts"],"mappings":";;;UA6BiB,mBAAA;;EAEf,MAAA;EAFkC;EAIlC,UAAA;AAAA;AAAA,UAGe,mBAAA;EAAA;EAEf,MAAA;;EAEA,UAAA;EAFA;EAIA,eAAA;EAAA;EAEA,IAAA;EAEA;EAAA,QAAA;EA0BA;;;;;EApBA,UAAA;EAoD2B;;;;;;;;AAmU7B;;;;;;;;;;;EAnWE,OAAA,GAAU,MAAA,SAAe,mBAAA;AAAA;;AAyZ3B;;;;;;;;;AAMA;;;;;;iBA/XgB,aAAA,CAAc,MAAA,EAAQ,mBAAA,GAAsB,MAAA;;;;;;;;;;;iBAmU5C,YAAA,CACd,MAAA,sBACA,MAAA,EAAQ,mBAAA,GACP,KAAA;EAAQ,GAAA;EAAa,IAAA;EAAe,KAAA;EAAgB,IAAA;AAAA;AAAA,UAmDtC,QAAA;EACf,MAAA,EAAQ,MAAA;EACR,IAAA;AAAA;;iBAIc,iBAAA,CAAkB,OAAA,EAAS,QAAA,KAAa,UAAA"}
|