@lunora/config 1.0.0-alpha.416 → 1.0.0-alpha.418

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 @@
1
+ import{resolveAdminToken as A}from"./devVariablesStamp-Cetr3qFz.mjs";import{sendStudioDocument as D,sendStudioAsset as h}from"./sendStudioAsset-XBmVLqiI.mjs";import{isStandaloneModulePath as I,studioAssetsStamp as _,loadStudioAssets as N,readStandaloneAsset as O,assetContentType as H}from"./assetContentType-CUb5bpbI.mjs";import C from"./createStudioDocumentCache-B3Sf1bIl.mjs";import{detectAgentRules as E}from"./AGENT_RULES_DIR-Bd6JPtNa.mjs";import{handlePolicyScaffoldRequest as v,POLICY_SCAFFOLD_ENDPOINT as L}from"./POLICY_SCAFFOLD_ENDPOINT-D5PpQPkf.mjs";import R from"./renderStudioHtml-ByowDtMl.mjs";import{handleSchemaEditRequest as b,SCHEMA_EDIT_ENDPOINT as x}from"./SCHEMA_EDIT_ENDPOINT-CtxWqfDe.mjs";import{handleSeedRequest as $,SEED_ENDPOINT as k}from"./SEED_ENDPOINT-C1fhrehH.mjs";import{serveJsonHandler as g}from"./serveJsonHandler-B8_GE6QC.mjs";import{transportRejectionReason as j}from"./ALLOW_FORWARDED_ENV-BUndghJx.mjs";import"./STUDIO_WRITE_TEMP_SUFFIX-BTTELz3K.mjs";const r="/__lunora",F=`${r}/studio.js`,m=`${r}/styles.css`,T=/\/$/,M={[L]:v,[x]:b,[k]:$},U=new Set(["127.0.0.1","::1","localhost"]),tt=t=>t!==void 0&&t!==!1&&!U.has(t),p=t=>t===void 0||t==="/"?"":t.replace(T,""),et=t=>`${p(t)}${r}`,w=t=>{try{return new URL(t,"http://localhost").pathname}catch{const d=t.indexOf("?");return d===-1?t:t.slice(0,d)}},ot=t=>{const{logger:d,projectRoot:c}=t,u=p(t.base);let l,S;const y=C(c,()=>R({adminToken:A(c),basePath:r,dataEditable:!0,rulesInstalled:E(c).installed,runAsIdentity:!0,schemaEditable:!0,scriptSrc:F,styleHref:m})),P=(n,o,e)=>{const s=_();if((l===void 0||s!==S)&&(l=N(d),S=s),l===void 0){e.statusCode=501,e.setHeader("Content-Type","text/plain"),e.end("Lunora studio assets not found — install and build @lunora/studio.");return}const a=n===m,i=n.slice(n.lastIndexOf("/")+1);if(a){h(o,e,l.styles,"text/css; charset=utf-8",i,s);return}const f=O(i);if(f===void 0){e.statusCode=404,e.setHeader("Content-Type","text/plain"),e.end("Not found");return}h(o,e,f,H(i),i,s)};return(n,o,e)=>{const s=w(n.url??"").replace(T,""),a=u!==""&&s.startsWith(u)?s.slice(u.length):s;if(a!==r&&!a.startsWith(`${r}/`)){e();return}if(t.isNonLoopbackBind||j(n,d)!==void 0){o.statusCode=403,o.setHeader("Content-Type","text/plain"),o.end("Lunora studio is only available on loopback hosts in dev.");return}const i=M[a];if(i!==void 0){g(n,o,i,c,{apiSpec:t.apiSpec,lazyFunctions:t.lazyFunctions,schemaDirectory:t.schemaDirectory});return}if(a===m||I(a)){P(a,n,o);return}D(o,y())}};export{r as STUDIO_PATH,F as STUDIO_SCRIPT_PATH,m as STUDIO_STYLE_PATH,ot as createStudioMiddleware,tt as isNonLoopbackHost,w as requestPathname,et as studioMountPath};
@@ -0,0 +1 @@
1
+ import{brotliCompressSync as h,constants as d,gzipSync as C}from"node:zlib";const f=e=>Array.isArray(e)?e[0]:e,S=(e,t,c,o)=>{if(t.setHeader("Cache-Control","no-cache"),o===void 0)return!1;const r=`W/"${c}-${String(o)}"`;return t.setHeader("ETag",r),f(e.headers?.["if-none-match"])!==r?!1:(t.statusCode=304,t.end(),!0)},g=/^q=0(?:\.0*)?$/,A=e=>{if(e===void 0)return;const t=new Set;for(const c of e.split(",")){const[o="",...r]=c.split(";").map(n=>n.trim().toLowerCase());r.some(n=>g.test(n))||t.add(o)}return t.has("br")?"br":t.has("gzip")?"gzip":void 0};let l;const s=new Map,T=1024,m=9,u=(e,t)=>t==="br"?h(e,{params:{[d.BROTLI_PARAM_QUALITY]:m,[d.BROTLI_PARAM_SIZE_HINT]:e.length}}):C(e,{level:d.Z_BEST_COMPRESSION}),_=(e,t,c,o)=>{if(o===void 0)return u(e,t);o!==l&&(s.clear(),l=o);const r=`${t}:${c}`;let n=s.get(r);return n===void 0&&(n=u(e,t),s.set(r,n)),n},v=(e,t,c,o,r,n)=>{if(t.setHeader("Vary","Accept-Encoding"),S(e,t,r,n))return;const a=c.length<T?void 0:A(f(e.headers?.["accept-encoding"])),i=a===void 0?c:_(c,a,r,n);t.statusCode=200,t.setHeader("Content-Type",o),a!==void 0&&t.setHeader("Content-Encoding",a),t.setHeader("Content-Length",i.length),t.end(i)},H=(e,t)=>{e.statusCode=200,e.setHeader("Cache-Control","no-store"),e.setHeader("Content-Type","text/html; charset=utf-8"),e.end(t)};export{S as applyStudioAssetCache,v as sendStudioAsset,H as sendStudioDocument};
@@ -31,23 +31,18 @@ declare const resolveAdminToken: (root: string) => string | undefined;
31
31
  */
32
32
  declare const devVariablesStamp: (root: string) => string;
33
33
  /**
34
- * Set the asset cache headers, answering `304` when the request already holds
35
- * this version. Returns true when the response is finished, false when the
36
- * caller should go on to write the body.
34
+ * Send a studio static asset (the stylesheet, the `studio.js` entry, a chunk or
35
+ * a source map): cache headers and `304` via {@link applyStudioAssetCache}, then
36
+ * the body — brotli- or gzip-compressed when the client accepts it. Neither the
37
+ * Vite dev server nor `lunora dev` compresses on its own, so without this the
38
+ * studio's first load is the full raw bundle.
37
39
  *
38
- * `no-cache` forces revalidation on every load: an unchanged asset costs a
39
- * cheap `304`, a rebuild (new stamp, new chunk names) is always fetched fresh.
40
- * The ETag is keyed on the requested file (not just its kind) so each chunk
41
- * revalidates independently, while the rebuild stamp busts them all at once. No
42
- * stamp (the studio isn't resolvable) means no ETag and no `304` — `no-cache`
43
- * alone.
44
- *
45
- * `If-None-Match` is compared byte-for-byte, per RFC 7232: entity tags are
46
- * case-sensitive, and these are keyed on file names that can differ only in
47
- * case (base64url chunk names), so a case-insensitive compare would cross-match
48
- * two distinct chunks into a wrong `304`.
40
+ * `Vary: Accept-Encoding` is set on every answer, `304` included, so a cache
41
+ * never hands a compressed body to a client that didn't ask for one. The weak
42
+ * ETag is shared across encodings: a weak tag means "semantically equivalent",
43
+ * which a re-encoding is (the convention nginx follows too).
49
44
  */
50
- declare const applyStudioAssetCache: (request: IncomingMessage, response: ServerResponse, fileName: string, stamp: number | undefined) => boolean;
45
+ declare const sendStudioAsset: (request: IncomingMessage, response: ServerResponse, body: Buffer, contentType: string, fileName: string, stamp: number | undefined) => void;
51
46
  /**
52
47
  * Send the studio's SPA document. It embeds the admin token, so it is
53
48
  * `no-store` — not merely revalidated — and carries no ETag: a cached `304` for
@@ -435,7 +430,7 @@ declare const ALLOW_FORWARDED_ENV = "LUNORA_STUDIO_ALLOW_FORWARDED";
435
430
  * the dev server, not just as an opaque 403 in the browser.
436
431
  */
437
432
  declare const transportRejectionReason: (request: IncomingMessage, logger?: WarnLogger) => string | undefined;
438
- export { ALLOW_FORWARDED_ENV, type LocalEndpointContext, type LocalEndpointHandler, type LocalEndpointRequest, type LocalEndpointResponse, POLICY_SCAFFOLD_ENDPOINT, type PolicyScaffoldBody, type PolicyScaffoldRequest, type PolicyScaffoldResponse, SCHEMA_EDIT_ENDPOINT, SEED_ENDPOINT, STUDIO_PATH, STUDIO_SCRIPT_PATH, STUDIO_STYLE_PATH, STUDIO_WRITE_TEMP_SUFFIX, type SchemaEditRequest, type SchemaEditResponse, type SeedRequest, type SeedRequestBody, type SeedResponse, type StudioAssets, type StudioHtmlConfig, type StudioMiddlewareOptions, type WarnLogger, type WirePolicyEdit, applyStudioAssetCache, assetContentType, consumeStudioWrite, createStudioDocumentCache, createStudioMiddleware,
433
+ export { ALLOW_FORWARDED_ENV, type LocalEndpointContext, type LocalEndpointHandler, type LocalEndpointRequest, type LocalEndpointResponse, POLICY_SCAFFOLD_ENDPOINT, type PolicyScaffoldBody, type PolicyScaffoldRequest, type PolicyScaffoldResponse, SCHEMA_EDIT_ENDPOINT, SEED_ENDPOINT, STUDIO_PATH, STUDIO_SCRIPT_PATH, STUDIO_STYLE_PATH, STUDIO_WRITE_TEMP_SUFFIX, type SchemaEditRequest, type SchemaEditResponse, type SeedRequest, type SeedRequestBody, type SeedResponse, type StudioAssets, type StudioHtmlConfig, type StudioMiddlewareOptions, type WarnLogger, type WirePolicyEdit, assetContentType, consumeStudioWrite, createStudioDocumentCache, createStudioMiddleware,
439
434
  /**
440
435
  * `@lunora/config/studio-host` — internal, build-time-shared helpers for hosting
441
436
  * the prebuilt `@lunora/studio` SPA during local dev.
@@ -483,4 +478,4 @@ parseDevVariable, readStandaloneAsset, renderStudioHtml, requestPathname,
483
478
  * config injected, resolve the admin token the same way the worker does, gate
484
479
  * the transport, and load the prebuilt asset bytes.
485
480
  */
486
- resolveAdminToken, resolveStandaloneDirectory, sendStudioDocument, serveJsonHandler, studioAssetsStamp, studioMountPath, transportRejectionReason };
481
+ resolveAdminToken, resolveStandaloneDirectory, sendStudioAsset, sendStudioDocument, serveJsonHandler, studioAssetsStamp, studioMountPath, transportRejectionReason };
@@ -31,23 +31,18 @@ declare const resolveAdminToken: (root: string) => string | undefined;
31
31
  */
32
32
  declare const devVariablesStamp: (root: string) => string;
33
33
  /**
34
- * Set the asset cache headers, answering `304` when the request already holds
35
- * this version. Returns true when the response is finished, false when the
36
- * caller should go on to write the body.
34
+ * Send a studio static asset (the stylesheet, the `studio.js` entry, a chunk or
35
+ * a source map): cache headers and `304` via {@link applyStudioAssetCache}, then
36
+ * the body — brotli- or gzip-compressed when the client accepts it. Neither the
37
+ * Vite dev server nor `lunora dev` compresses on its own, so without this the
38
+ * studio's first load is the full raw bundle.
37
39
  *
38
- * `no-cache` forces revalidation on every load: an unchanged asset costs a
39
- * cheap `304`, a rebuild (new stamp, new chunk names) is always fetched fresh.
40
- * The ETag is keyed on the requested file (not just its kind) so each chunk
41
- * revalidates independently, while the rebuild stamp busts them all at once. No
42
- * stamp (the studio isn't resolvable) means no ETag and no `304` — `no-cache`
43
- * alone.
44
- *
45
- * `If-None-Match` is compared byte-for-byte, per RFC 7232: entity tags are
46
- * case-sensitive, and these are keyed on file names that can differ only in
47
- * case (base64url chunk names), so a case-insensitive compare would cross-match
48
- * two distinct chunks into a wrong `304`.
40
+ * `Vary: Accept-Encoding` is set on every answer, `304` included, so a cache
41
+ * never hands a compressed body to a client that didn't ask for one. The weak
42
+ * ETag is shared across encodings: a weak tag means "semantically equivalent",
43
+ * which a re-encoding is (the convention nginx follows too).
49
44
  */
50
- declare const applyStudioAssetCache: (request: IncomingMessage, response: ServerResponse, fileName: string, stamp: number | undefined) => boolean;
45
+ declare const sendStudioAsset: (request: IncomingMessage, response: ServerResponse, body: Buffer, contentType: string, fileName: string, stamp: number | undefined) => void;
51
46
  /**
52
47
  * Send the studio's SPA document. It embeds the admin token, so it is
53
48
  * `no-store` — not merely revalidated — and carries no ETag: a cached `304` for
@@ -435,7 +430,7 @@ declare const ALLOW_FORWARDED_ENV = "LUNORA_STUDIO_ALLOW_FORWARDED";
435
430
  * the dev server, not just as an opaque 403 in the browser.
436
431
  */
437
432
  declare const transportRejectionReason: (request: IncomingMessage, logger?: WarnLogger) => string | undefined;
438
- export { ALLOW_FORWARDED_ENV, type LocalEndpointContext, type LocalEndpointHandler, type LocalEndpointRequest, type LocalEndpointResponse, POLICY_SCAFFOLD_ENDPOINT, type PolicyScaffoldBody, type PolicyScaffoldRequest, type PolicyScaffoldResponse, SCHEMA_EDIT_ENDPOINT, SEED_ENDPOINT, STUDIO_PATH, STUDIO_SCRIPT_PATH, STUDIO_STYLE_PATH, STUDIO_WRITE_TEMP_SUFFIX, type SchemaEditRequest, type SchemaEditResponse, type SeedRequest, type SeedRequestBody, type SeedResponse, type StudioAssets, type StudioHtmlConfig, type StudioMiddlewareOptions, type WarnLogger, type WirePolicyEdit, applyStudioAssetCache, assetContentType, consumeStudioWrite, createStudioDocumentCache, createStudioMiddleware,
433
+ export { ALLOW_FORWARDED_ENV, type LocalEndpointContext, type LocalEndpointHandler, type LocalEndpointRequest, type LocalEndpointResponse, POLICY_SCAFFOLD_ENDPOINT, type PolicyScaffoldBody, type PolicyScaffoldRequest, type PolicyScaffoldResponse, SCHEMA_EDIT_ENDPOINT, SEED_ENDPOINT, STUDIO_PATH, STUDIO_SCRIPT_PATH, STUDIO_STYLE_PATH, STUDIO_WRITE_TEMP_SUFFIX, type SchemaEditRequest, type SchemaEditResponse, type SeedRequest, type SeedRequestBody, type SeedResponse, type StudioAssets, type StudioHtmlConfig, type StudioMiddlewareOptions, type WarnLogger, type WirePolicyEdit, assetContentType, consumeStudioWrite, createStudioDocumentCache, createStudioMiddleware,
439
434
  /**
440
435
  * `@lunora/config/studio-host` — internal, build-time-shared helpers for hosting
441
436
  * the prebuilt `@lunora/studio` SPA during local dev.
@@ -483,4 +478,4 @@ parseDevVariable, readStandaloneAsset, renderStudioHtml, requestPathname,
483
478
  * config injected, resolve the admin token the same way the worker does, gate
484
479
  * the transport, and load the prebuilt asset bytes.
485
480
  */
486
- resolveAdminToken, resolveStandaloneDirectory, sendStudioDocument, serveJsonHandler, studioAssetsStamp, studioMountPath, transportRejectionReason };
481
+ resolveAdminToken, resolveStandaloneDirectory, sendStudioAsset, sendStudioDocument, serveJsonHandler, studioAssetsStamp, studioMountPath, transportRejectionReason };
@@ -1 +1 @@
1
- import{devVariablesStamp as t,parseDevVariable as r,resolveAdminToken as a}from"../packem_shared/devVariablesStamp-Cetr3qFz.mjs";import{applyStudioAssetCache as d,sendStudioDocument as n}from"../packem_shared/applyStudioAssetCache-DHQEJuuv.mjs";import{assetContentType as i,isStandaloneModulePath as l,loadStudioAssets as m,readStandaloneAsset as p,resolveStandaloneDirectory as u,studioAssetsStamp as T}from"../packem_shared/assetContentType-CUb5bpbI.mjs";import{default as D}from"../packem_shared/createStudioDocumentCache-B3Sf1bIl.mjs";import{STUDIO_PATH as c,STUDIO_SCRIPT_PATH as A,STUDIO_STYLE_PATH as E,createStudioMiddleware as P,isNonLoopbackHost as x,requestPathname as I,studioMountPath as O}from"../packem_shared/STUDIO_PATH-DbOwZDBM.mjs";import{POLICY_SCAFFOLD_ENDPOINT as R,handlePolicyScaffoldRequest as N}from"../packem_shared/POLICY_SCAFFOLD_ENDPOINT-D5PpQPkf.mjs";import{default as H}from"../packem_shared/renderStudioHtml-ByowDtMl.mjs";import{SCHEMA_EDIT_ENDPOINT as v,handleSchemaEditRequest as F}from"../packem_shared/SCHEMA_EDIT_ENDPOINT-CtxWqfDe.mjs";import{SEED_ENDPOINT as U,handleSeedRequest as b}from"../packem_shared/SEED_ENDPOINT-C1fhrehH.mjs";import{serveJsonHandler as y}from"../packem_shared/serveJsonHandler-B8_GE6QC.mjs";import{STUDIO_WRITE_TEMP_SUFFIX as W,consumeStudioWrite as k}from"../packem_shared/STUDIO_WRITE_TEMP_SUFFIX-BTTELz3K.mjs";import{ALLOW_FORWARDED_ENV as j,headerValue as w,isLoopbackAddress as J,transportRejectionReason as X}from"../packem_shared/ALLOW_FORWARDED_ENV-BUndghJx.mjs";export{j as ALLOW_FORWARDED_ENV,R as POLICY_SCAFFOLD_ENDPOINT,v as SCHEMA_EDIT_ENDPOINT,U as SEED_ENDPOINT,c as STUDIO_PATH,A as STUDIO_SCRIPT_PATH,E as STUDIO_STYLE_PATH,W as STUDIO_WRITE_TEMP_SUFFIX,d as applyStudioAssetCache,i as assetContentType,k as consumeStudioWrite,D as createStudioDocumentCache,P as createStudioMiddleware,t as devVariablesStamp,N as handlePolicyScaffoldRequest,F as handleSchemaEditRequest,b as handleSeedRequest,w as headerValue,J as isLoopbackAddress,x as isNonLoopbackHost,l as isStandaloneModulePath,m as loadStudioAssets,r as parseDevVariable,p as readStandaloneAsset,H as renderStudioHtml,I as requestPathname,a as resolveAdminToken,u as resolveStandaloneDirectory,n as sendStudioDocument,y as serveJsonHandler,T as studioAssetsStamp,O as studioMountPath,X as transportRejectionReason};
1
+ import{devVariablesStamp as t,parseDevVariable as r,resolveAdminToken as a}from"../packem_shared/devVariablesStamp-Cetr3qFz.mjs";import{sendStudioAsset as d,sendStudioDocument as n}from"../packem_shared/sendStudioAsset-XBmVLqiI.mjs";import{assetContentType as i,isStandaloneModulePath as m,loadStudioAssets as u,readStandaloneAsset as l,resolveStandaloneDirectory as p,studioAssetsStamp as T}from"../packem_shared/assetContentType-CUb5bpbI.mjs";import{default as D}from"../packem_shared/createStudioDocumentCache-B3Sf1bIl.mjs";import{STUDIO_PATH as c,STUDIO_SCRIPT_PATH as A,STUDIO_STYLE_PATH as E,createStudioMiddleware as P,isNonLoopbackHost as x,requestPathname as I,studioMountPath as O}from"../packem_shared/STUDIO_PATH-Dc-3nLO6.mjs";import{POLICY_SCAFFOLD_ENDPOINT as R,handlePolicyScaffoldRequest as N}from"../packem_shared/POLICY_SCAFFOLD_ENDPOINT-D5PpQPkf.mjs";import{default as L}from"../packem_shared/renderStudioHtml-ByowDtMl.mjs";import{SCHEMA_EDIT_ENDPOINT as v,handleSchemaEditRequest as F}from"../packem_shared/SCHEMA_EDIT_ENDPOINT-CtxWqfDe.mjs";import{SEED_ENDPOINT as U,handleSeedRequest as b}from"../packem_shared/SEED_ENDPOINT-C1fhrehH.mjs";import{serveJsonHandler as V}from"../packem_shared/serveJsonHandler-B8_GE6QC.mjs";import{STUDIO_WRITE_TEMP_SUFFIX as k,consumeStudioWrite as y}from"../packem_shared/STUDIO_WRITE_TEMP_SUFFIX-BTTELz3K.mjs";import{ALLOW_FORWARDED_ENV as j,headerValue as w,isLoopbackAddress as J,transportRejectionReason as X}from"../packem_shared/ALLOW_FORWARDED_ENV-BUndghJx.mjs";export{j as ALLOW_FORWARDED_ENV,R as POLICY_SCAFFOLD_ENDPOINT,v as SCHEMA_EDIT_ENDPOINT,U as SEED_ENDPOINT,c as STUDIO_PATH,A as STUDIO_SCRIPT_PATH,E as STUDIO_STYLE_PATH,k as STUDIO_WRITE_TEMP_SUFFIX,i as assetContentType,y as consumeStudioWrite,D as createStudioDocumentCache,P as createStudioMiddleware,t as devVariablesStamp,N as handlePolicyScaffoldRequest,F as handleSchemaEditRequest,b as handleSeedRequest,w as headerValue,J as isLoopbackAddress,x as isNonLoopbackHost,m as isStandaloneModulePath,u as loadStudioAssets,r as parseDevVariable,l as readStandaloneAsset,L as renderStudioHtml,I as requestPathname,a as resolveAdminToken,p as resolveStandaloneDirectory,d as sendStudioAsset,n as sendStudioDocument,V as serveJsonHandler,T as studioAssetsStamp,O as studioMountPath,X as transportRejectionReason};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/config",
3
- "version": "1.0.0-alpha.416",
3
+ "version": "1.0.0-alpha.418",
4
4
  "description": "Internal shared CLI + Vite config layer for Lunora: wrangler.jsonc validation, binding inference, and .dev.vars scaffolding",
5
5
  "keywords": [
6
6
  "bindings",
@@ -58,10 +58,10 @@
58
58
  "access": "public"
59
59
  },
60
60
  "dependencies": {
61
- "@lunora/codegen": "1.0.0-alpha.362",
62
- "@lunora/container": "1.0.0-alpha.93",
61
+ "@lunora/codegen": "1.0.0-alpha.363",
62
+ "@lunora/container": "1.0.0-alpha.94",
63
63
  "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
64
- "@lunora/seed": "1.0.0-alpha.259",
64
+ "@lunora/seed": "1.0.0-alpha.260",
65
65
  "@visulima/colorize": "3.0.0",
66
66
  "@visulima/find-ai-runner": "1.0.2",
67
67
  "@visulima/fs": "7.0.0",
@@ -1 +0,0 @@
1
- import{resolveAdminToken as A}from"./devVariablesStamp-Cetr3qFz.mjs";import{sendStudioDocument as D,applyStudioAssetCache as I}from"./applyStudioAssetCache-DHQEJuuv.mjs";import{isStandaloneModulePath as O,studioAssetsStamp as _,loadStudioAssets as C,readStandaloneAsset as H,assetContentType as N}from"./assetContentType-CUb5bpbI.mjs";import E from"./createStudioDocumentCache-B3Sf1bIl.mjs";import{detectAgentRules as v}from"./AGENT_RULES_DIR-Bd6JPtNa.mjs";import{handlePolicyScaffoldRequest as L,POLICY_SCAFFOLD_ENDPOINT as R}from"./POLICY_SCAFFOLD_ENDPOINT-D5PpQPkf.mjs";import b from"./renderStudioHtml-ByowDtMl.mjs";import{handleSchemaEditRequest as x,SCHEMA_EDIT_ENDPOINT as k}from"./SCHEMA_EDIT_ENDPOINT-CtxWqfDe.mjs";import{handleSeedRequest as $,SEED_ENDPOINT as g}from"./SEED_ENDPOINT-C1fhrehH.mjs";import{serveJsonHandler as j}from"./serveJsonHandler-B8_GE6QC.mjs";import{transportRejectionReason as F}from"./ALLOW_FORWARDED_ENV-BUndghJx.mjs";import"./STUDIO_WRITE_TEMP_SUFFIX-BTTELz3K.mjs";const c="/__lunora",M=`${c}/studio.js`,m=`${c}/styles.css`,T=/\/$/,U={[R]:L,[k]:x,[g]:$},q=new Set(["127.0.0.1","::1","localhost"]),et=t=>t!==void 0&&t!==!1&&!q.has(t),y=t=>t===void 0||t==="/"?"":t.replace(T,""),ot=t=>`${y(t)}${c}`,h=(t,s,r)=>{t.statusCode=200,t.setHeader("Content-Type",r),t.end(s)},w=t=>{try{return new URL(t,"http://localhost").pathname}catch{const s=t.indexOf("?");return s===-1?t:t.slice(0,s)}},nt=t=>{const{logger:s,projectRoot:r}=t,u=y(t.base);let l,f;const p=E(r,()=>b({adminToken:A(r),basePath:c,dataEditable:!0,rulesInstalled:v(r).installed,runAsIdentity:!0,schemaEditable:!0,scriptSrc:M,styleHref:m})),P=(o,n,e)=>{const i=_();if((l===void 0||i!==f)&&(l=C(s),f=i),l===void 0){e.statusCode=501,e.setHeader("Content-Type","text/plain"),e.end("Lunora studio assets not found — install and build @lunora/studio.");return}const a=o===m,d=o.slice(o.lastIndexOf("/")+1);if(I(n,e,d,i))return;if(a){h(e,l.styles,"text/css; charset=utf-8");return}const S=H(d);if(S===void 0){e.statusCode=404,e.setHeader("Content-Type","text/plain"),e.end("Not found");return}h(e,S,N(d))};return(o,n,e)=>{const i=w(o.url??"").replace(T,""),a=u!==""&&i.startsWith(u)?i.slice(u.length):i;if(a!==c&&!a.startsWith(`${c}/`)){e();return}if(t.isNonLoopbackBind||F(o,s)!==void 0){n.statusCode=403,n.setHeader("Content-Type","text/plain"),n.end("Lunora studio is only available on loopback hosts in dev.");return}const d=U[a];if(d!==void 0){j(o,n,d,r,{apiSpec:t.apiSpec,lazyFunctions:t.lazyFunctions,schemaDirectory:t.schemaDirectory});return}if(a===m||O(a)){P(a,o,n);return}D(n,p())}};export{c as STUDIO_PATH,M as STUDIO_SCRIPT_PATH,m as STUDIO_STYLE_PATH,nt as createStudioMiddleware,et as isNonLoopbackHost,w as requestPathname,ot as studioMountPath};
@@ -1 +0,0 @@
1
- const n=t=>Array.isArray(t)?t[0]:t,o=(t,e,d,a)=>{if(e.setHeader("Cache-Control","no-cache"),a===void 0)return!1;const r=`W/"${d}-${String(a)}"`;return e.setHeader("ETag",r),n(t.headers?.["if-none-match"])!==r?!1:(e.statusCode=304,e.end(),!0)},c=(t,e)=>{t.statusCode=200,t.setHeader("Cache-Control","no-store"),t.setHeader("Content-Type","text/html; charset=utf-8"),t.end(e)};export{o as applyStudioAssetCache,c as sendStudioDocument};