@astroscope/node 1.0.0

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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +286 -0
  3. package/dist/boot.d.ts +15 -0
  4. package/dist/boot.d.ts.map +1 -0
  5. package/dist/boot.js +2 -0
  6. package/dist/compress-B11aeRHQ.js +58 -0
  7. package/dist/compress-B11aeRHQ.js.map +1 -0
  8. package/dist/construct-DgB-jR0a.d.ts +14 -0
  9. package/dist/construct-DgB-jR0a.d.ts.map +1 -0
  10. package/dist/context-Bkg-FnnQ.js +20 -0
  11. package/dist/context-Bkg-FnnQ.js.map +1 -0
  12. package/dist/csrf-middleware-entrypoint.d.ts +5 -0
  13. package/dist/csrf-middleware-entrypoint.d.ts.map +1 -0
  14. package/dist/csrf-middleware-entrypoint.js +30 -0
  15. package/dist/csrf-middleware-entrypoint.js.map +1 -0
  16. package/dist/dev-middleware-entrypoint.d.ts +15 -0
  17. package/dist/dev-middleware-entrypoint.d.ts.map +1 -0
  18. package/dist/dev-middleware-entrypoint.js +26 -0
  19. package/dist/dev-middleware-entrypoint.js.map +1 -0
  20. package/dist/events-CUzQ2_cp.d.ts +20 -0
  21. package/dist/events-CUzQ2_cp.d.ts.map +1 -0
  22. package/dist/events-CgoM3Fvu.js +39 -0
  23. package/dist/events-CgoM3Fvu.js.map +1 -0
  24. package/dist/excludes-DLF3A_Cf.d.ts +63 -0
  25. package/dist/excludes-DLF3A_Cf.d.ts.map +1 -0
  26. package/dist/excludes-pE23EbmQ.js +78 -0
  27. package/dist/excludes-pE23EbmQ.js.map +1 -0
  28. package/dist/excludes.d.ts +2 -0
  29. package/dist/excludes.js +2 -0
  30. package/dist/generation-Bp2IA0jf.js +45 -0
  31. package/dist/generation-Bp2IA0jf.js.map +1 -0
  32. package/dist/health.d.ts +38 -0
  33. package/dist/health.d.ts.map +1 -0
  34. package/dist/health.js +31 -0
  35. package/dist/health.js.map +1 -0
  36. package/dist/index.d.ts +167 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +732 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/lifecycle/events.d.ts +2 -0
  41. package/dist/lifecycle/events.js +2 -0
  42. package/dist/log/index.d.ts +55 -0
  43. package/dist/log/index.d.ts.map +1 -0
  44. package/dist/log/index.js +2 -0
  45. package/dist/log-CSJlKaxY.js +112 -0
  46. package/dist/log-CSJlKaxY.js.map +1 -0
  47. package/dist/mime-C_GwZovh.js +39 -0
  48. package/dist/mime-C_GwZovh.js.map +1 -0
  49. package/dist/native-mount-hhwWdLtL.js +120 -0
  50. package/dist/native-mount-hhwWdLtL.js.map +1 -0
  51. package/dist/native.d.ts +48 -0
  52. package/dist/native.d.ts.map +1 -0
  53. package/dist/native.js +2 -0
  54. package/dist/prepare-Be2GgRyf.js +390 -0
  55. package/dist/prepare-Be2GgRyf.js.map +1 -0
  56. package/dist/preview.d.ts +12 -0
  57. package/dist/preview.d.ts.map +1 -0
  58. package/dist/preview.js +23 -0
  59. package/dist/preview.js.map +1 -0
  60. package/dist/restart-page.html +107 -0
  61. package/dist/route-middleware-entrypoint.d.ts +13 -0
  62. package/dist/route-middleware-entrypoint.d.ts.map +1 -0
  63. package/dist/route-middleware-entrypoint.js +24 -0
  64. package/dist/route-middleware-entrypoint.js.map +1 -0
  65. package/dist/server.d.ts +14 -0
  66. package/dist/server.d.ts.map +1 -0
  67. package/dist/server.js +441 -0
  68. package/dist/server.js.map +1 -0
  69. package/dist/store-8pnTxM1x.js +37 -0
  70. package/dist/store-8pnTxM1x.js.map +1 -0
  71. package/dist/store-BIUF4lqk.js +29 -0
  72. package/dist/store-BIUF4lqk.js.map +1 -0
  73. package/dist/types-D0uMBi2M.d.ts +12 -0
  74. package/dist/types-D0uMBi2M.d.ts.map +1 -0
  75. package/package.json +114 -0
@@ -0,0 +1,63 @@
1
+ import { StringPattern } from "@entwico/dash/match";
2
+ import { APIContext, MiddlewareHandler } from "astro";
3
+
4
+ //#region src/excludes/excludes.d.ts
5
+ /**
6
+ * Patterns accepted by @astroscope/node exclude options. The serializable
7
+ * subset of dash's `StringPattern` — no matcher functions, since integration
8
+ * options cross a virtual-module boundary.
9
+ */
10
+ type ExcludePattern = Exclude<StringPattern, (value: string) => boolean>;
11
+ /**
12
+ * Vite/Astro dev server paths - only relevant in development.
13
+ */
14
+ declare const DEV_EXCLUDES: ExcludePattern[];
15
+ /**
16
+ * Astro internal paths for static assets and image optimization.
17
+ */
18
+ declare const ASTRO_STATIC_EXCLUDES: ExcludePattern[];
19
+ /**
20
+ * Common static asset paths.
21
+ */
22
+ declare const STATIC_EXCLUDES: ExcludePattern[];
23
+ /**
24
+ * Recommended excludes for middleware.
25
+ * Includes dev paths and Astro internals.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * createI18nMiddleware({
30
+ * locale: (ctx) => ctx.locals.session?.locale ?? 'en',
31
+ * exclude: [
32
+ * ...RECOMMENDED_EXCLUDES,
33
+ * { exact: "/health" }, // your health endpoint
34
+ * ],
35
+ * })
36
+ * ```
37
+ */
38
+ declare const RECOMMENDED_EXCLUDES: ExcludePattern[];
39
+ /**
40
+ * Check if a request should be excluded based on patterns or a function.
41
+ */
42
+ declare function shouldExclude(ctx: APIContext, exclude: readonly StringPattern[] | ((context: APIContext) => boolean) | undefined): boolean;
43
+ /**
44
+ * Wraps a middleware to skip execution for excluded paths.
45
+ * Useful for third-party middlewares that don't have built-in exclude support.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { RECOMMENDED_EXCLUDES, withExcluded } from '@astroscope/node/excludes';
50
+ * import { someExternalMiddleware } from 'some-package';
51
+ *
52
+ * export const onRequest = sequence(
53
+ * withExcluded(someExternalMiddleware(), [
54
+ * ...RECOMMENDED_EXCLUDES,
55
+ * { prefix: '/api/webhooks/' },
56
+ * ]),
57
+ * );
58
+ * ```
59
+ */
60
+ declare function withExcluded(middleware: MiddlewareHandler, exclude: readonly StringPattern[] | ((context: APIContext) => boolean)): MiddlewareHandler;
61
+ //#endregion
62
+ export { STATIC_EXCLUDES as a, RECOMMENDED_EXCLUDES as i, DEV_EXCLUDES as n, shouldExclude as o, ExcludePattern as r, withExcluded as s, ASTRO_STATIC_EXCLUDES as t };
63
+ //# sourceMappingURL=excludes-DLF3A_Cf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excludes-DLF3A_Cf.d.ts","names":[],"sources":["../src/excludes/excludes.ts"],"mappings":";;;;;;AAQA;;;KAAY,cAAA,GAAiB,OAAO,CAAC,aAAA,GAAgB,KAAA;;;;cAKxC,YAAA,EAAc,cAAc;AALyB;AAKlE;;AALkE,cAgBrD,qBAAA,EAAuB,cAAc;;AAXT;AAWzC;cAKa,eAAA,EAAiB,cAAc;;;AALM;AAKlD;;;;AAA4C;AAwB5C;;;;AAAiD;AAKjD;;cALa,oBAAA,EAAsB,cAAc;;;;iBAKjC,aAAA,CACd,GAAA,EAAK,UAAA,EACL,OAAA,WAAkB,aAAA,OAAoB,OAAA,EAAS,UAAA;;;;;;;;;AAAmC;AA4BpF;;;;;;;;iBAAgB,YAAA,CACd,UAAA,EAAY,iBAAA,EACZ,OAAA,WAAkB,aAAA,OAAoB,OAAA,EAAS,UAAA,gBAC9C,iBAAA"}
@@ -0,0 +1,78 @@
1
+ import { matchesAny } from "@entwico/dash/match";
2
+ //#region src/excludes/excludes.ts
3
+ /**
4
+ * Vite/Astro dev server paths - only relevant in development.
5
+ */
6
+ const DEV_EXCLUDES = [
7
+ { prefix: "/@id/" },
8
+ { prefix: "/@fs/" },
9
+ { prefix: "/@vite/" },
10
+ { prefix: "/src/" },
11
+ { prefix: "/node_modules/" }
12
+ ];
13
+ /**
14
+ * Astro internal paths for static assets and image optimization.
15
+ */
16
+ const ASTRO_STATIC_EXCLUDES = [{ prefix: "/_astro/" }, { prefix: "/_image" }];
17
+ /**
18
+ * Common static asset paths.
19
+ */
20
+ const STATIC_EXCLUDES = [
21
+ { exact: "/favicon.ico" },
22
+ { exact: "/robots.txt" },
23
+ { exact: "/sitemap.xml" },
24
+ { exact: "/browserconfig.xml" },
25
+ { exact: "/manifest.json" },
26
+ { exact: "/manifest.webmanifest" }
27
+ ];
28
+ /**
29
+ * Recommended excludes for middleware.
30
+ * Includes dev paths and Astro internals.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * createI18nMiddleware({
35
+ * locale: (ctx) => ctx.locals.session?.locale ?? 'en',
36
+ * exclude: [
37
+ * ...RECOMMENDED_EXCLUDES,
38
+ * { exact: "/health" }, // your health endpoint
39
+ * ],
40
+ * })
41
+ * ```
42
+ */
43
+ const RECOMMENDED_EXCLUDES = [...DEV_EXCLUDES, ...ASTRO_STATIC_EXCLUDES];
44
+ /**
45
+ * Check if a request should be excluded based on patterns or a function.
46
+ */
47
+ function shouldExclude(ctx, exclude) {
48
+ if (!exclude) return false;
49
+ if (typeof exclude === "function") return exclude(ctx);
50
+ return matchesAny(ctx.url.pathname, exclude);
51
+ }
52
+ /**
53
+ * Wraps a middleware to skip execution for excluded paths.
54
+ * Useful for third-party middlewares that don't have built-in exclude support.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { RECOMMENDED_EXCLUDES, withExcluded } from '@astroscope/node/excludes';
59
+ * import { someExternalMiddleware } from 'some-package';
60
+ *
61
+ * export const onRequest = sequence(
62
+ * withExcluded(someExternalMiddleware(), [
63
+ * ...RECOMMENDED_EXCLUDES,
64
+ * { prefix: '/api/webhooks/' },
65
+ * ]),
66
+ * );
67
+ * ```
68
+ */
69
+ function withExcluded(middleware, exclude) {
70
+ return (ctx, next) => {
71
+ if (shouldExclude(ctx, exclude)) return next();
72
+ return middleware(ctx, next);
73
+ };
74
+ }
75
+ //#endregion
76
+ export { shouldExclude as a, STATIC_EXCLUDES as i, DEV_EXCLUDES as n, withExcluded as o, RECOMMENDED_EXCLUDES as r, ASTRO_STATIC_EXCLUDES as t };
77
+
78
+ //# sourceMappingURL=excludes-pE23EbmQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excludes-pE23EbmQ.js","names":[],"sources":["../src/excludes/excludes.ts"],"sourcesContent":["import { type StringPattern, matchesAny } from '@entwico/dash/match';\nimport type { APIContext, MiddlewareHandler } from 'astro';\n\n/**\n * Patterns accepted by @astroscope/node exclude options. The serializable\n * subset of dash's `StringPattern` — no matcher functions, since integration\n * options cross a virtual-module boundary.\n */\nexport type ExcludePattern = Exclude<StringPattern, (value: string) => boolean>;\n\n/**\n * Vite/Astro dev server paths - only relevant in development.\n */\nexport const DEV_EXCLUDES: ExcludePattern[] = [\n { prefix: '/@id/' },\n { prefix: '/@fs/' },\n { prefix: '/@vite/' },\n { prefix: '/src/' },\n { prefix: '/node_modules/' },\n];\n\n/**\n * Astro internal paths for static assets and image optimization.\n */\nexport const ASTRO_STATIC_EXCLUDES: ExcludePattern[] = [{ prefix: '/_astro/' }, { prefix: '/_image' }];\n\n/**\n * Common static asset paths.\n */\nexport const STATIC_EXCLUDES: ExcludePattern[] = [\n { exact: '/favicon.ico' },\n { exact: '/robots.txt' },\n { exact: '/sitemap.xml' },\n { exact: '/browserconfig.xml' },\n { exact: '/manifest.json' },\n { exact: '/manifest.webmanifest' },\n];\n\n/**\n * Recommended excludes for middleware.\n * Includes dev paths and Astro internals.\n *\n * @example\n * ```ts\n * createI18nMiddleware({\n * locale: (ctx) => ctx.locals.session?.locale ?? 'en',\n * exclude: [\n * ...RECOMMENDED_EXCLUDES,\n * { exact: \"/health\" }, // your health endpoint\n * ],\n * })\n * ```\n */\nexport const RECOMMENDED_EXCLUDES: ExcludePattern[] = [...DEV_EXCLUDES, ...ASTRO_STATIC_EXCLUDES];\n\n/**\n * Check if a request should be excluded based on patterns or a function.\n */\nexport function shouldExclude(\n ctx: APIContext,\n exclude: readonly StringPattern[] | ((context: APIContext) => boolean) | undefined,\n): boolean {\n if (!exclude) return false;\n\n if (typeof exclude === 'function') {\n return exclude(ctx);\n }\n\n return matchesAny(ctx.url.pathname, exclude);\n}\n\n/**\n * Wraps a middleware to skip execution for excluded paths.\n * Useful for third-party middlewares that don't have built-in exclude support.\n *\n * @example\n * ```ts\n * import { RECOMMENDED_EXCLUDES, withExcluded } from '@astroscope/node/excludes';\n * import { someExternalMiddleware } from 'some-package';\n *\n * export const onRequest = sequence(\n * withExcluded(someExternalMiddleware(), [\n * ...RECOMMENDED_EXCLUDES,\n * { prefix: '/api/webhooks/' },\n * ]),\n * );\n * ```\n */\nexport function withExcluded(\n middleware: MiddlewareHandler,\n exclude: readonly StringPattern[] | ((context: APIContext) => boolean),\n): MiddlewareHandler {\n return (ctx, next) => {\n if (shouldExclude(ctx, exclude)) {\n return next();\n }\n\n return middleware(ctx, next);\n };\n}\n"],"mappings":";;;;;AAaA,MAAa,eAAiC;CAC5C,EAAE,QAAQ,QAAQ;CAClB,EAAE,QAAQ,QAAQ;CAClB,EAAE,QAAQ,UAAU;CACpB,EAAE,QAAQ,QAAQ;CAClB,EAAE,QAAQ,iBAAiB;AAC7B;;;;AAKA,MAAa,wBAA0C,CAAC,EAAE,QAAQ,WAAW,GAAG,EAAE,QAAQ,UAAU,CAAC;;;;AAKrG,MAAa,kBAAoC;CAC/C,EAAE,OAAO,eAAe;CACxB,EAAE,OAAO,cAAc;CACvB,EAAE,OAAO,eAAe;CACxB,EAAE,OAAO,qBAAqB;CAC9B,EAAE,OAAO,iBAAiB;CAC1B,EAAE,OAAO,wBAAwB;AACnC;;;;;;;;;;;;;;;;AAiBA,MAAa,uBAAyC,CAAC,GAAG,cAAc,GAAG,qBAAqB;;;;AAKhG,SAAgB,cACd,KACA,SACS;CACT,IAAI,CAAC,SAAS,OAAO;CAErB,IAAI,OAAO,YAAY,YACrB,OAAO,QAAQ,GAAG;CAGpB,OAAO,WAAW,IAAI,IAAI,UAAU,OAAO;AAC7C;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aACd,YACA,SACmB;CACnB,QAAQ,KAAK,SAAS;EACpB,IAAI,cAAc,KAAK,OAAO,GAC5B,OAAO,KAAK;EAGd,OAAO,WAAW,KAAK,IAAI;CAC7B;AACF"}
@@ -0,0 +1,2 @@
1
+ import { a as STATIC_EXCLUDES, i as RECOMMENDED_EXCLUDES, n as DEV_EXCLUDES, o as shouldExclude, r as ExcludePattern, s as withExcluded, t as ASTRO_STATIC_EXCLUDES } from "./excludes-DLF3A_Cf.js";
2
+ export { ASTRO_STATIC_EXCLUDES, DEV_EXCLUDES, ExcludePattern, RECOMMENDED_EXCLUDES, STATIC_EXCLUDES, shouldExclude, withExcluded };
@@ -0,0 +1,2 @@
1
+ import { a as shouldExclude, i as STATIC_EXCLUDES, n as DEV_EXCLUDES, o as withExcluded, r as RECOMMENDED_EXCLUDES, t as ASTRO_STATIC_EXCLUDES } from "./excludes-pE23EbmQ.js";
2
+ export { ASTRO_STATIC_EXCLUDES, DEV_EXCLUDES, RECOMMENDED_EXCLUDES, STATIC_EXCLUDES, shouldExclude, withExcluded };
@@ -0,0 +1,45 @@
1
+ //#region src/dev-mode/generation.ts
2
+ /**
3
+ * Per-process generation state shared between the integration's connect-level
4
+ * stamp and the runtime Astro middleware.
5
+ */
6
+ const GEN_HEADER = "x-astroscope-node-gen";
7
+ const STATE_KEY = Symbol.for("@astroscope/node/generation");
8
+ function getState() {
9
+ const g = globalThis;
10
+ let s = g[STATE_KEY];
11
+ if (!s) {
12
+ s = {
13
+ generation: 0,
14
+ staleCount: 0,
15
+ flushTimer: void 0
16
+ };
17
+ g[STATE_KEY] = s;
18
+ }
19
+ return s;
20
+ }
21
+ function getCurrentGeneration() {
22
+ return getState().generation;
23
+ }
24
+ function incrementGeneration() {
25
+ getState().generation++;
26
+ }
27
+ /**
28
+ * Buffer a swallowed stale-request error and flush a single concise line per
29
+ * burst — replaces the multi-line stack traces astro otherwise emits.
30
+ */
31
+ function recordStaleError() {
32
+ const s = getState();
33
+ s.staleCount++;
34
+ if (s.flushTimer) return;
35
+ s.flushTimer = setTimeout(() => {
36
+ const n = s.staleCount;
37
+ s.staleCount = 0;
38
+ s.flushTimer = void 0;
39
+ console.log(`[@astroscope/node] suppressed ${n} stale request error${n === 1 ? "" : "s"} from a previous app generation`);
40
+ }, 50);
41
+ }
42
+ //#endregion
43
+ export { recordStaleError as i, getCurrentGeneration as n, incrementGeneration as r, GEN_HEADER as t };
44
+
45
+ //# sourceMappingURL=generation-Bp2IA0jf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generation-Bp2IA0jf.js","names":[],"sources":["../src/dev-mode/generation.ts"],"sourcesContent":["/**\n * Per-process generation state shared between the integration's connect-level\n * stamp and the runtime Astro middleware.\n */\n\nexport const GEN_HEADER = 'x-astroscope-node-gen';\n\nconst STATE_KEY = Symbol.for('@astroscope/node/generation');\n\ninterface State {\n generation: number;\n staleCount: number;\n flushTimer: ReturnType<typeof setTimeout> | undefined;\n}\n\nfunction getState(): State {\n const g = globalThis as Record<symbol, unknown>;\n let s = g[STATE_KEY] as State | undefined;\n\n if (!s) {\n s = { generation: 0, staleCount: 0, flushTimer: undefined };\n g[STATE_KEY] = s;\n }\n\n return s;\n}\n\nexport function getCurrentGeneration(): number {\n return getState().generation;\n}\n\nexport function incrementGeneration(): void {\n getState().generation++;\n}\n\n/**\n * Buffer a swallowed stale-request error and flush a single concise line per\n * burst — replaces the multi-line stack traces astro otherwise emits.\n */\nexport function recordStaleError(): void {\n const s = getState();\n\n s.staleCount++;\n\n if (s.flushTimer) return;\n\n s.flushTimer = setTimeout(() => {\n const n = s.staleCount;\n\n s.staleCount = 0;\n s.flushTimer = undefined;\n\n console.log(\n `[@astroscope/node] suppressed ${n} stale request error${n === 1 ? '' : 's'} from a previous app generation`,\n );\n }, 50);\n}\n"],"mappings":";;;;;AAKA,MAAa,aAAa;AAE1B,MAAM,YAAY,OAAO,IAAI,6BAA6B;AAQ1D,SAAS,WAAkB;CACzB,MAAM,IAAI;CACV,IAAI,IAAI,EAAE;CAEV,IAAI,CAAC,GAAG;EACN,IAAI;GAAE,YAAY;GAAG,YAAY;GAAG,YAAY,KAAA;EAAU;EAC1D,EAAE,aAAa;CACjB;CAEA,OAAO;AACT;AAEA,SAAgB,uBAA+B;CAC7C,OAAO,SAAS,CAAC,CAAC;AACpB;AAEA,SAAgB,sBAA4B;CAC1C,SAAS,CAAC,CAAC;AACb;;;;;AAMA,SAAgB,mBAAyB;CACvC,MAAM,IAAI,SAAS;CAEnB,EAAE;CAEF,IAAI,EAAE,YAAY;CAElB,EAAE,aAAa,iBAAiB;EAC9B,MAAM,IAAI,EAAE;EAEZ,EAAE,aAAa;EACf,EAAE,aAAa,KAAA;EAEf,QAAQ,IACN,iCAAiC,EAAE,sBAAsB,MAAM,IAAI,KAAK,IAAI,gCAC9E;CACF,GAAG,EAAE;AACP"}
@@ -0,0 +1,38 @@
1
+ //#region src/health/health.d.ts
2
+ interface HealthCheckResult {
3
+ status: 'healthy' | 'unhealthy';
4
+ latency?: number | undefined;
5
+ error?: string | undefined;
6
+ }
7
+ interface HealthCheckDefinition {
8
+ /**
9
+ * Unique name for this health check.
10
+ */
11
+ name: string;
12
+ /**
13
+ * Performs the check. Throw or return an unhealthy result to fail;
14
+ * returning void or completing without error means healthy.
15
+ */
16
+ check: () => Promise<HealthCheckResult | void> | HealthCheckResult | void;
17
+ /**
18
+ * Optional checks don't affect the ready probe.
19
+ * @default false
20
+ */
21
+ optional?: boolean | undefined;
22
+ /**
23
+ * Maximum time in ms for the check to complete.
24
+ * @default 5000
25
+ */
26
+ timeout?: number | undefined;
27
+ }
28
+ /**
29
+ * Register a health check against the adapter's health server.
30
+ *
31
+ * No-op when no health runtime is active (dev mode, `health: false`), so boot
32
+ * files can call it unconditionally. Returns an unregister function; checks
33
+ * still registered after `onShutdown` are removed automatically.
34
+ */
35
+ declare function registerHealthCheck(definition: HealthCheckDefinition): () => void;
36
+ //#endregion
37
+ export { HealthCheckDefinition, HealthCheckResult, registerHealthCheck };
38
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","names":[],"sources":["../src/health/health.ts"],"mappings":";UAEiB,iBAAA;EACf,MAAA;EACA,OAAA;EACA,KAAA;AAAA;AAAA,UAGe,qBAAA;EAJf;;;EAQA,IAAA;EAJe;;;;EAUf,KAAA,QAAa,OAAA,CAAQ,iBAAA,WAA4B,iBAAA;EAAA;;;;EAMjD,QAAA;EANa;;;;EAYb,OAAA;AAAA;AAAO;AAUT;;;;AAAqE;;AAV5D,iBAUO,mBAAA,CAAoB,UAAiC,EAArB,qBAAqB"}
package/dist/health.js ADDED
@@ -0,0 +1,31 @@
1
+ import { r as getHealthStore } from "./store-8pnTxM1x.js";
2
+ //#region src/health/health.ts
3
+ /**
4
+ * Register a health check against the adapter's health server.
5
+ *
6
+ * No-op when no health runtime is active (dev mode, `health: false`), so boot
7
+ * files can call it unconditionally. Returns an unregister function; checks
8
+ * still registered after `onShutdown` are removed automatically.
9
+ */
10
+ function registerHealthCheck(definition) {
11
+ const store = getHealthStore();
12
+ if (!store.registry) return () => {};
13
+ const unregister = store.registry.register({
14
+ name: definition.name,
15
+ check: definition.check,
16
+ ...definition.optional !== void 0 && { optional: definition.optional },
17
+ ...definition.timeout !== void 0 && { timeout: definition.timeout }
18
+ });
19
+ store.unregisters.set(definition.name, unregister);
20
+ return () => {
21
+ const current = store.unregisters.get(definition.name);
22
+ if (current) {
23
+ store.unregisters.delete(definition.name);
24
+ current();
25
+ }
26
+ };
27
+ }
28
+ //#endregion
29
+ export { registerHealthCheck };
30
+
31
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","names":[],"sources":["../src/health/health.ts"],"sourcesContent":["import { getHealthStore } from './store.js';\n\nexport interface HealthCheckResult {\n status: 'healthy' | 'unhealthy';\n latency?: number | undefined;\n error?: string | undefined;\n}\n\nexport interface HealthCheckDefinition {\n /**\n * Unique name for this health check.\n */\n name: string;\n\n /**\n * Performs the check. Throw or return an unhealthy result to fail;\n * returning void or completing without error means healthy.\n */\n check: () => Promise<HealthCheckResult | void> | HealthCheckResult | void;\n\n /**\n * Optional checks don't affect the ready probe.\n * @default false\n */\n optional?: boolean | undefined;\n\n /**\n * Maximum time in ms for the check to complete.\n * @default 5000\n */\n timeout?: number | undefined;\n}\n\n/**\n * Register a health check against the adapter's health server.\n *\n * No-op when no health runtime is active (dev mode, `health: false`), so boot\n * files can call it unconditionally. Returns an unregister function; checks\n * still registered after `onShutdown` are removed automatically.\n */\nexport function registerHealthCheck(definition: HealthCheckDefinition): () => void {\n const store = getHealthStore();\n\n if (!store.registry) {\n return () => {};\n }\n\n const unregister = store.registry.register({\n name: definition.name,\n check: definition.check,\n ...(definition.optional !== undefined && { optional: definition.optional }),\n ...(definition.timeout !== undefined && { timeout: definition.timeout }),\n });\n\n store.unregisters.set(definition.name, unregister);\n\n return () => {\n const current = store.unregisters.get(definition.name);\n\n if (current) {\n store.unregisters.delete(definition.name);\n current();\n }\n };\n}\n"],"mappings":";;;;;;;;;AAwCA,SAAgB,oBAAoB,YAA+C;CACjF,MAAM,QAAQ,eAAe;CAE7B,IAAI,CAAC,MAAM,UACT,aAAa,CAAC;CAGhB,MAAM,aAAa,MAAM,SAAS,SAAS;EACzC,MAAM,WAAW;EACjB,OAAO,WAAW;EAClB,GAAI,WAAW,aAAa,KAAA,KAAa,EAAE,UAAU,WAAW,SAAS;EACzE,GAAI,WAAW,YAAY,KAAA,KAAa,EAAE,SAAS,WAAW,QAAQ;CACxE,CAAC;CAED,MAAM,YAAY,IAAI,WAAW,MAAM,UAAU;CAEjD,aAAa;EACX,MAAM,UAAU,MAAM,YAAY,IAAI,WAAW,IAAI;EAErD,IAAI,SAAS;GACX,MAAM,YAAY,OAAO,WAAW,IAAI;GACxC,QAAQ;EACV;CACF;AACF"}
@@ -0,0 +1,167 @@
1
+ import { r as ExcludePattern } from "./excludes-DLF3A_Cf.js";
2
+ import { t as BootContext } from "./types-D0uMBi2M.js";
3
+ import { n as BootEventName, t as BootEventHandler } from "./events-CUzQ2_cp.js";
4
+ import { AstroIntegration } from "astro";
5
+
6
+ //#region src/types.d.ts
7
+ interface NodeBootOptions {
8
+ /**
9
+ * Path to the boot file relative to the project root.
10
+ * @default "src/boot.ts" (or "src/boot/index.ts" if present)
11
+ */
12
+ entry?: string | undefined;
13
+ /**
14
+ * Restart the dev server when the boot file (or any of its dependencies) changes.
15
+ * Dev-only — has no effect in production.
16
+ * @default true
17
+ */
18
+ watch?: boolean | undefined;
19
+ }
20
+ /**
21
+ * Structurally compatible with `ProbePaths` from `health-probes`.
22
+ */
23
+ interface HealthProbePaths {
24
+ live?: string | undefined;
25
+ startup?: string | undefined;
26
+ ready?: string | undefined;
27
+ health?: string | undefined;
28
+ }
29
+ interface NodeHealthOptions {
30
+ /**
31
+ * Host to bind the health server to.
32
+ * Falls back to the `HEALTH_HOST` env var, then `'0.0.0.0'` for kubelet probes
33
+ */
34
+ host?: string | undefined;
35
+ /**
36
+ * Port to bind the health server to.
37
+ * Falls back to the `HEALTH_PORT` env var, then `9090`.
38
+ */
39
+ port?: number | undefined;
40
+ /**
41
+ * Custom paths for probe endpoints.
42
+ * @default K8sPaths (from health-probes)
43
+ */
44
+ paths?: HealthProbePaths | undefined;
45
+ }
46
+ interface NodeLoggingOptions {
47
+ /**
48
+ * Paths excluded from request logging. Replaces the default
49
+ * (`RECOMMENDED_EXCLUDES` + `STATIC_EXCLUDES`) entirely when provided.
50
+ */
51
+ exclude?: ExcludePattern[] | undefined;
52
+ /**
53
+ * Extended request logging: query string, headers, client address.
54
+ * May capture sensitive data (auth tokens, PII in query strings).
55
+ * @default false
56
+ */
57
+ extended?: boolean | undefined;
58
+ /**
59
+ * Also log requests in dev at the connect level. Off by default — astro's
60
+ * dev server already narrates requests; the `log` proxy works regardless.
61
+ * @default false
62
+ */
63
+ dev?: boolean | undefined;
64
+ }
65
+ interface NodePrometheusOptions {
66
+ /**
67
+ * Host to bind the Prometheus reader to.
68
+ * Falls back to the `OTEL_EXPORTER_PROMETHEUS_HOST` env var, then `'0.0.0.0'`.
69
+ */
70
+ host?: string | undefined;
71
+ /**
72
+ * Port for the Prometheus reader.
73
+ * Falls back to the `OTEL_EXPORTER_PROMETHEUS_PORT` env var, then `9464`.
74
+ */
75
+ port?: number | undefined;
76
+ }
77
+ interface NodeTelemetryOptions {
78
+ /**
79
+ * Paths excluded from request tracing and metrics. Replaces the default
80
+ * (`RECOMMENDED_EXCLUDES` + `STATIC_EXCLUDES`) entirely when provided.
81
+ */
82
+ exclude?: ExcludePattern[] | undefined;
83
+ /**
84
+ * Prometheus metrics reader on its own port; `false` disables it.
85
+ * @default { host: '0.0.0.0', port: 9464 }
86
+ */
87
+ prometheus?: NodePrometheusOptions | false | undefined;
88
+ /**
89
+ * Also start the telemetry SDK in dev (once per process). Off by default —
90
+ * several apps share localhost and would fight over the Prometheus port.
91
+ * @default false
92
+ */
93
+ dev?: boolean | undefined;
94
+ }
95
+ interface NodeOptions {
96
+ /**
97
+ * Boot lifecycle configuration. The boot file's `onStartup` runs before the
98
+ * server starts listening; `onShutdown` runs on SIGTERM/SIGINT after in-flight
99
+ * requests drained. Set to `false` to disable the lifecycle entirely.
100
+ *
101
+ * When left at the default and no boot file exists, the lifecycle is skipped.
102
+ */
103
+ boot?: NodeBootOptions | false | undefined;
104
+ /**
105
+ * Request logging at the native handler (real status, response size,
106
+ * aborted-vs-completed) plus the request-scoped `log` proxy exported from
107
+ * `@astroscope/node/log`. Enabled by default in production; `false` disables
108
+ * request logging (the `log` proxy keeps working).
109
+ */
110
+ logging?: NodeLoggingOptions | false | undefined;
111
+ /**
112
+ * Platform telemetry: server spans and request metrics at the native
113
+ * handler, fetch instrumentation via undici, runtime + host metrics, and a
114
+ * Prometheus reader. Trace exporters are driven by standard `OTEL_*` env
115
+ * vars. Enabled by default in production, off in dev; `false` disables.
116
+ */
117
+ telemetry?: NodeTelemetryOptions | false | undefined;
118
+ /**
119
+ * Kubernetes-style health probes served on a separate port, driven around the
120
+ * boot lifecycle (live before startup, ready after listen, draining on shutdown).
121
+ * Enabled by default in production (never active in dev); set to `false` to disable.
122
+ */
123
+ health?: NodeHealthOptions | false | undefined;
124
+ /**
125
+ * CSRF protection: rejects cross-origin POST/PUT/PATCH/DELETE requests by
126
+ * comparing the Origin header against the request origin. Replaces Astro's
127
+ * built-in `security.checkOrigin` (which supports no exclusions).
128
+ * Enabled by default; set to `false` to keep Astro's built-in behavior.
129
+ */
130
+ csrf?: {
131
+ exclude?: ExcludePattern[] | undefined;
132
+ } | false | undefined;
133
+ /**
134
+ * Maximum request body size in bytes. `0` or `Infinity` disables the limit.
135
+ * @default 1073741824 (1 GiB)
136
+ */
137
+ bodySizeLimit?: number | undefined;
138
+ /**
139
+ * How long to wait (ms) for in-flight requests to finish on shutdown before
140
+ * remaining connections are closed forcefully.
141
+ * @default 10000
142
+ */
143
+ shutdownTimeout?: number | undefined;
144
+ }
145
+ //#endregion
146
+ //#region src/integration/integration.d.ts
147
+ /**
148
+ * Node adapter for Astro with a first-class server entrypoint: the boot
149
+ * lifecycle, module warmup, health probes, request logging and telemetry run
150
+ * as plain code around `server.listen()` instead of being injected into the
151
+ * build output.
152
+ */
153
+ declare function node(options?: NodeOptions): AstroIntegration;
154
+ //#endregion
155
+ //#region src/platform/prepare.d.ts
156
+ interface InstrumentationContext {
157
+ dev: boolean;
158
+ }
159
+ //#endregion
160
+ //#region src/lifecycle/lifecycle.d.ts
161
+ interface BootModule {
162
+ onStartup?: ((context: BootContext) => Promise<void> | void) | undefined;
163
+ onShutdown?: ((context: BootContext) => Promise<void> | void) | undefined;
164
+ }
165
+ //#endregion
166
+ export { type BootContext, type BootEventHandler, type BootEventName, type BootModule, type HealthProbePaths, type InstrumentationContext, type NodeBootOptions, type NodeHealthOptions, type NodeLoggingOptions, type NodeOptions, type NodePrometheusOptions, type NodeTelemetryOptions, node as default };
167
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/integration/integration.ts","../src/platform/prepare.ts","../src/lifecycle/lifecycle.ts"],"mappings":";;;;;;UAEiB,eAAA;;;;;EAKf,KAAA;EALe;;;;AAYV;EAAL,KAAK;AAAA;;;;UAMU,gBAAA;EACf,IAAA;EACA,OAAA;EACA,KAAA;EACA,MAAA;AAAA;AAAA,UAGe,iBAAA;;;;;EAKf,IAAA;EAYQ;;AAAgB;AAG1B;EATE,IAAA;;;;;EAMA,KAAA,GAAQ,gBAAgB;AAAA;AAAA,UAGT,kBAAA;EAmBZ;AAGL;;;EAjBE,OAAA,GAAU,cAAc;EA4BpB;AAGN;;;;EAxBE,QAAA;EA6BU;;;;;EAtBV,GAAA;AAAA;AAAA,UAGe,qBAAA;;;;;EAKf,IAAA;EAqEmB;;;;EA/DnB,IAAI;AAAA;AAAA,UAGW,oBAAA;EA6Cf;;;;EAxCA,OAAA,GAAU,cAAA;EAuDD;;;;EAjDT,UAAA,GAAa,qBAAqB;EA8DnB;;;;ACzI+D;EDkF9E,GAAA;AAAA;AAAA,UAGe,WAAA;EClCqB;;;;AAAmC;;;ED0CvE,IAAA,GAAO,eAAA;EE1GQ;;;;AACZ;;EFiHH,OAAA,GAAU,kBAAA;;AGrHZ;;;;;EH6HE,SAAA,GAAY,oBAAA;EG3H4B;;;;;EHkIxC,MAAA,GAAS,iBAAA;EGnI8B;;;;;;EH2IvC,IAAA;IAAS,OAAA,GAAU,cAAA;EAAA;;;;;EAMnB,aAAA;;;;;;EAOA,eAAA;AAAA;;;;;;AA9IK;AAMP;;iBCkDwB,IAAA,CAAK,OAAA,GAAS,WAAA,GAAmB,gBAAgB;;;UChExD,sBAAA;EACf,GAAG;AAAA;;;UCJY,UAAA;EACf,SAAA,KAAc,OAAA,EAAS,WAAA,KAAgB,OAAA;EACvC,UAAA,KAAe,OAAA,EAAS,WAAA,KAAgB,OAAA;AAAA"}