@stacksjs/server 0.75.256 → 0.75.257

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 +12 -12
@@ -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"]),ALWAYS_ALLOWED_PREFIXES=["/css/","/js/","/images/","/fonts/","/assets/","/_stx/","/_modules/","/@vite/","/@fs/","/__deps/"],ALWAYS_ALLOWED_EXTENSIONS=[".css",".js",".mjs",".map",".woff",".woff2",".ttf",".otf",".eot",".svg",".png",".jpg",".jpeg",".gif",".webp",".avif",".ico"];function configuredAllowList(){return(process.env.APP_MAINTENANCE_ALLOW??process.env.APP_COMING_SOON_ALLOW??"").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!0;continue}if(entry.endsWith("/")){if(path.startsWith(entry))return!0;continue}if(path===entry)return!0}return!1}export function isAlwaysAllowed(path){if(ALWAYS_ALLOWED_PATHS.has(path))return!0;if(isConfiguredAllowed(path))return!0;if(ALWAYS_ALLOWED_PREFIXES.some((p)=>path.startsWith(p)))return!0;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(),eq=trimmed.indexOf("=");if(eq===-1)continue;const k=trimmed.slice(0,eq).trim(),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",path=new URL(req.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")),hasCookie=!!payload.secret&&hasValidBypassCookie(cookies,payload.secret,mode),appEnv=(process.env.APP_ENV||"development").toLowerCase(),trustLocalhost=!["production","staging"].includes(appEnv),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","/favicon.ico"]),ALWAYS_ALLOWED_PREFIXES=["/css/","/js/","/images/","/fonts/","/assets/","/_stx/","/_modules/","/@vite/","/@fs/","/__deps/"],ALWAYS_ALLOWED_EXTENSIONS=[".css",".js",".mjs",".map",".woff",".woff2",".ttf",".otf",".eot",".svg",".png",".jpg",".jpeg",".gif",".webp",".avif",".ico"];function configuredAllowList(){return(process.env.APP_MAINTENANCE_ALLOW??process.env.APP_COMING_SOON_ALLOW??"").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!0;continue}if(entry.endsWith("/")){if(path.startsWith(entry))return!0;continue}if(path===entry)return!0}return!1}export function isAlwaysAllowed(path){if(ALWAYS_ALLOWED_PATHS.has(path))return!0;if(isConfiguredAllowed(path))return!0;if(ALWAYS_ALLOWED_PREFIXES.some((p)=>path.startsWith(p)))return!0;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(),eq=trimmed.indexOf("=");if(eq===-1)continue;const k=trimmed.slice(0,eq).trim(),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",path=new URL(req.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")),hasCookie=!!payload.secret&&hasValidBypassCookie(cookies,payload.secret,mode),appEnv=(process.env.APP_ENV||process.env.NODE_ENV||"").toLowerCase(),trustLocalhost=!["production","staging"].includes(appEnv),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.256",
5
+ "version": "0.75.257",
6
6
  "description": "Local development and production-ready.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -58,21 +58,21 @@
58
58
  "prepublishOnly": "bun run build"
59
59
  },
60
60
  "dependencies": {
61
- "@stacksjs/auth": "0.75.256",
61
+ "@stacksjs/auth": "0.75.257",
62
62
  "@stacksjs/bun-router": "^0.1.24",
63
- "@stacksjs/config": "0.75.256",
64
- "@stacksjs/events": "0.75.256",
65
- "@stacksjs/i18n": "0.75.256",
66
- "@stacksjs/logging": "0.75.256",
67
- "@stacksjs/orm": "0.75.256",
68
- "@stacksjs/path": "0.75.256",
69
- "@stacksjs/payments": "0.75.256",
70
- "@stacksjs/router": "0.75.256",
71
- "@stacksjs/storage": "0.75.256",
63
+ "@stacksjs/config": "0.75.257",
64
+ "@stacksjs/events": "0.75.257",
65
+ "@stacksjs/i18n": "0.75.257",
66
+ "@stacksjs/logging": "0.75.257",
67
+ "@stacksjs/orm": "0.75.257",
68
+ "@stacksjs/path": "0.75.257",
69
+ "@stacksjs/payments": "0.75.257",
70
+ "@stacksjs/router": "0.75.257",
71
+ "@stacksjs/storage": "0.75.257",
72
72
  "bun-plugin-auto-imports": "^0.4.4"
73
73
  },
74
74
  "devDependencies": {
75
- "@stacksjs/validation": "0.75.256",
75
+ "@stacksjs/validation": "0.75.257",
76
76
  "better-dx": "^0.2.24"
77
77
  }
78
78
  }