@stacksjs/server 0.75.661 → 0.75.667

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 (2) hide show
  1. package/dist/maintenance.js +1 -1
  2. package/package.json +13 -13
@@ -74,4 +74,4 @@ import{clientAddress}from"@stacksjs/bun-router";import{log}from"@stacksjs/loggin
74
74
  ${payload.retry?`<p class="retry">Expected back in about ${Math.ceil(payload.retry/60)} minutes.</p>`:""}
75
75
  </main>
76
76
  </body>
77
- </html>`}function escapeHtml(value){return value.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#039;")}export function maintenanceResponse(payload){return siteModeResponse(payload)}export function siteModeResponse(payload){const headers={"Content-Type":"text/html; charset=utf-8"};if(payload.retry){headers["Retry-After"]=String(payload.retry)}if(payload.redirect){return new Response(null,{status:302,headers:{Location:payload.redirect}})}return new Response(maintenanceHtml(payload),{status:payload.status||(payload.mode==="coming-soon"?200:503),headers})}export function bypassCookieValue(secret,mode="maintenance"){return`${bypassCookieName(mode)}=${secret}; Path=/; HttpOnly; SameSite=Lax`}const ALWAYS_ALLOWED_PATHS=new Set(["/coming-soon","/api/email/subscribe","/favicon.ico"]);const ALWAYS_ALLOWED_PREFIXES=["/css/","/js/","/images/","/fonts/","/assets/","/_stx/","/_modules/","/@vite/","/@fs/","/__deps/"];const ALWAYS_ALLOWED_EXTENSIONS=[".css",".js",".mjs",".map",".woff",".woff2",".ttf",".otf",".eot",".svg",".png",".jpg",".jpeg",".gif",".webp",".avif",".ico"];function configuredAllowList(){const raw=process.env.APP_MAINTENANCE_ALLOW??process.env.APP_COMING_SOON_ALLOW??"";return raw.split(",").map((entry)=>entry.trim()).filter(Boolean)}function isConfiguredAllowed(path){for(const entry of configuredAllowList()){if(entry.endsWith("*")){if(path.startsWith(entry.slice(0,-1)))return true;continue}if(entry.endsWith("/")){if(path.startsWith(entry))return true;continue}if(path===entry)return true}return false}export function isAlwaysAllowed(path){if(ALWAYS_ALLOWED_PATHS.has(path))return true;if(isConfiguredAllowed(path))return true;if(ALWAYS_ALLOWED_PREFIXES.some((p)=>path.startsWith(p)))return true;const lower=path.toLowerCase();return ALWAYS_ALLOWED_EXTENSIONS.some((ext)=>lower.endsWith(ext))}function parseCookieHeader(header){const out={};if(!header)return out;for(const part of header.split(";")){const trimmed=part.trim();const eq=trimmed.indexOf("=");if(eq===-1)continue;const k=trimmed.slice(0,eq).trim();const v=trimmed.slice(eq+1).trim();if(k)out[k]=v}return out}function clientIp(req){return clientAddress(req)??"127.0.0.1"}export function maintenanceGate(req){const payloadResult=activeSiteModePayloadResult();return payloadResult instanceof Promise?payloadResult.then((payload)=>applyMaintenanceGate(req,payload)):applyMaintenanceGate(req,payloadResult)}function applyMaintenanceGate(req,payload){if(!payload)return null;const mode=payload.mode??"maintenance";const url=new URL(req.url);const path=url.pathname;if(isAlwaysAllowed(path))return null;if(payload.secret&&isSecretPath(path,payload.secret)){const location=mode==="coming-soon"?`/?preview=${encodeURIComponent(payload.secret)}`:"/";return new Response(null,{status:302,headers:{Location:location,"Set-Cookie":bypassCookieValue(payload.secret,mode)}})}const cookies=parseCookieHeader(req.headers.get("cookie"));const hasCookie=!!payload.secret&&hasValidBypassCookie(cookies,payload.secret,mode);const appEnv=(process.env.APP_ENV||process.env.NODE_ENV||"").toLowerCase();const trustLocalhost=!["production","staging"].includes(appEnv);const ipAllowed=isAllowedIp(clientIp(req),payload.allowed,trustLocalhost);if(hasCookie||ipAllowed)return null;return siteModeResponse(payload)}
77
+ </html>`}function escapeHtml(value){return value.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#039;")}export function maintenanceResponse(payload){return siteModeResponse(payload)}export function siteModeResponse(payload){const headers={"Content-Type":"text/html; charset=utf-8"};if(payload.retry){headers["Retry-After"]=String(payload.retry)}if(payload.redirect){return new Response(null,{status:302,headers:{Location:payload.redirect}})}return new Response(maintenanceHtml(payload),{status:payload.status||(payload.mode==="coming-soon"?200:503),headers})}export function bypassCookieValue(secret,mode="maintenance"){return`${bypassCookieName(mode)}=${secret}; Path=/; HttpOnly; SameSite=Lax`}const ALWAYS_ALLOWED_PATHS=new Set(["/coming-soon","/api/email/subscribe","/api/email/confirm","/api/email/unsubscribe","/favicon.ico"]);const ALWAYS_ALLOWED_PREFIXES=["/css/","/js/","/images/","/fonts/","/assets/","/_stx/","/_modules/","/@vite/","/@fs/","/__deps/"];const ALWAYS_ALLOWED_EXTENSIONS=[".css",".js",".mjs",".map",".woff",".woff2",".ttf",".otf",".eot",".svg",".png",".jpg",".jpeg",".gif",".webp",".avif",".ico"];function configuredAllowList(){const raw=process.env.APP_MAINTENANCE_ALLOW??process.env.APP_COMING_SOON_ALLOW??"";return raw.split(",").map((entry)=>entry.trim()).filter(Boolean)}function isConfiguredAllowed(path){for(const entry of configuredAllowList()){if(entry.endsWith("*")){if(path.startsWith(entry.slice(0,-1)))return true;continue}if(entry.endsWith("/")){if(path.startsWith(entry))return true;continue}if(path===entry)return true}return false}export function isAlwaysAllowed(path){if(ALWAYS_ALLOWED_PATHS.has(path))return true;if(isConfiguredAllowed(path))return true;if(ALWAYS_ALLOWED_PREFIXES.some((p)=>path.startsWith(p)))return true;const lower=path.toLowerCase();return ALWAYS_ALLOWED_EXTENSIONS.some((ext)=>lower.endsWith(ext))}function parseCookieHeader(header){const out={};if(!header)return out;for(const part of header.split(";")){const trimmed=part.trim();const eq=trimmed.indexOf("=");if(eq===-1)continue;const k=trimmed.slice(0,eq).trim();const v=trimmed.slice(eq+1).trim();if(k)out[k]=v}return out}function clientIp(req){return clientAddress(req)??"127.0.0.1"}export function maintenanceGate(req){const payloadResult=activeSiteModePayloadResult();return payloadResult instanceof Promise?payloadResult.then((payload)=>applyMaintenanceGate(req,payload)):applyMaintenanceGate(req,payloadResult)}function applyMaintenanceGate(req,payload){if(!payload)return null;const mode=payload.mode??"maintenance";const url=new URL(req.url);const path=url.pathname;if(isAlwaysAllowed(path))return null;if(payload.secret&&isSecretPath(path,payload.secret)){const location=mode==="coming-soon"?`/?preview=${encodeURIComponent(payload.secret)}`:"/";return new Response(null,{status:302,headers:{Location:location,"Set-Cookie":bypassCookieValue(payload.secret,mode)}})}const cookies=parseCookieHeader(req.headers.get("cookie"));const hasCookie=!!payload.secret&&hasValidBypassCookie(cookies,payload.secret,mode);const appEnv=(process.env.APP_ENV||process.env.NODE_ENV||"").toLowerCase();const trustLocalhost=!["production","staging"].includes(appEnv);const ipAllowed=isAllowedIp(clientIp(req),payload.allowed,trustLocalhost);if(hasCookie||ipAllowed)return null;return siteModeResponse(payload)}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/server",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.661",
5
+ "version": "0.75.667",
6
6
  "description": "Local development and production-ready.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -58,22 +58,22 @@
58
58
  "prepublishOnly": "bun run build"
59
59
  },
60
60
  "dependencies": {
61
- "@stacksjs/auth": "0.75.661",
61
+ "@stacksjs/auth": "0.75.667",
62
62
  "@stacksjs/bun-router": "^0.1.24",
63
- "@stacksjs/config": "0.75.661",
64
- "@stacksjs/events": "0.75.661",
65
- "@stacksjs/i18n": "0.75.661",
66
- "@stacksjs/logging": "0.75.661",
67
- "@stacksjs/orm": "0.75.661",
68
- "@stacksjs/path": "0.75.661",
69
- "@stacksjs/payments": "0.75.661",
70
- "@stacksjs/router": "0.75.661",
71
- "@stacksjs/storage": "0.75.661",
72
- "@stacksjs/stx": "^0.2.908",
63
+ "@stacksjs/config": "0.75.667",
64
+ "@stacksjs/events": "0.75.667",
65
+ "@stacksjs/i18n": "0.75.667",
66
+ "@stacksjs/logging": "0.75.667",
67
+ "@stacksjs/orm": "0.75.667",
68
+ "@stacksjs/path": "0.75.667",
69
+ "@stacksjs/payments": "0.75.667",
70
+ "@stacksjs/router": "0.75.667",
71
+ "@stacksjs/storage": "0.75.667",
72
+ "@stacksjs/stx": "^0.2.930",
73
73
  "bun-plugin-auto-imports": "^0.4.4"
74
74
  },
75
75
  "devDependencies": {
76
- "@stacksjs/validation": "0.75.661",
76
+ "@stacksjs/validation": "0.75.667",
77
77
  "better-dx": "^0.2.39"
78
78
  }
79
79
  }