@stacksjs/actions 0.70.260 → 0.70.262

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.
@@ -1 +1 @@
1
- import process from"node:process";import{db,sql}from"@stacksjs/database";import{log}from"@stacksjs/logging";const args=process.argv.slice(2),hasFlag=(name)=>{return args.includes(`--${name}`)},getArg=(name)=>{const idx=args.findIndex((a)=>a.startsWith(`--${name}=`)||a.startsWith(`-${name.charAt(0)}=`));if(idx!==-1){const arg=args[idx];if(!arg)return;const eqIdx=arg.indexOf("=");return eqIdx>=0?arg.slice(eqIdx+1):void 0}const flagIdx=args.findIndex((a)=>a===`--${name}`||a===`-${name.charAt(0)}`),value=flagIdx!==-1?args[flagIdx+1]:void 0;if(value&&!value.startsWith("-"))return value;return},pruneExpired=!hasFlag("no-expired"),pruneRevoked=!hasFlag("no-revoked"),daysOld=Number(getArg("days"))||7;log.info("Pruning authentication tokens...");let expiredCount=0,revokedCount=0;if(pruneExpired){log.info("Removing expired tokens...");expiredCount=await db.deleteFrom("personal_access_tokens").where("expires_at","<",sql.raw("NOW()")).execute();log.success(`Removed ${expiredCount} expired token(s)`)}if(pruneRevoked){log.info(`Removing tokens revoked more than ${daysOld} day(s) ago...`);const cutoffDate=new Date;cutoffDate.setDate(cutoffDate.getDate()-daysOld);revokedCount=await db.deleteFrom("personal_access_tokens").where("revoked_at","is not",null).where("revoked_at","<",cutoffDate.toISOString()).execute();log.success(`Removed ${revokedCount} revoked token(s)`)}log.success(`Token pruning complete. Total removed: ${expiredCount+revokedCount}`);process.exit(0);
1
+ import process from"node:process";import{db,sql}from"@stacksjs/database";import{log}from"@stacksjs/logging";const args=process.argv.slice(2),hasFlag=(name)=>{return args.includes(`--${name}`)},getArg=(name)=>{const idx=args.findIndex((a)=>a.startsWith(`--${name}=`)||a.startsWith(`-${name.charAt(0)}=`));if(idx!==-1){const arg=args[idx];if(!arg)return;const eqIdx=arg.indexOf("=");return eqIdx>=0?arg.slice(eqIdx+1):void 0}const flagIdx=args.findIndex((a)=>a===`--${name}`||a===`-${name.charAt(0)}`),value=flagIdx!==-1?args[flagIdx+1]:void 0;if(value&&!value.startsWith("-"))return value;return},pruneExpired=!hasFlag("no-expired"),pruneRevoked=!hasFlag("no-revoked"),daysOld=Number(getArg("days"))||7;log.info("Pruning authentication tokens...");let expiredCount=0,revokedCount=0;if(pruneExpired){log.info("Removing expired tokens...");expiredCount=await db.deleteFrom("personal_access_tokens").where("expires_at","<",sql.raw("NOW()")).execute();log.success(`Removed ${expiredCount} expired token(s)`)}if(pruneRevoked){log.info(`Removing tokens revoked more than ${daysOld} day(s) ago...`);const cutoffDate=new Date;cutoffDate.setDate(cutoffDate.getDate()-daysOld);revokedCount=await db.deleteFrom("personal_access_tokens").whereNotNull("revoked_at").where("revoked_at","<",cutoffDate.toISOString()).execute();log.success(`Removed ${revokedCount} revoked token(s)`)}log.success(`Token pruning complete. Total removed: ${expiredCount+revokedCount}`);process.exit(0);
package/dist/dev/views.js CHANGED
@@ -1 +1 @@
1
- import{AsyncLocalStorage}from"node:async_hooks";import{existsSync}from"node:fs";import{config,overridesReady}from"@stacksjs/config";import{projectPath}from"@stacksjs/path";import{seedCsrfPageResponse}from"./csrf";import{exitWithParent}from"./exit-with-parent";const requestStore=new AsyncLocalStorage;function currentRequestContext(){return requestStore.getStore()??globalThis.__stxServeContext}globalThis.requestContext={cookie(name){return currentRequestContext()?.cookies?.[name]??null},url(){return currentRequestContext()?.url??""},search(){const url=currentRequestContext()?.url;if(!url)return"";const mark=url.indexOf("?");return mark===-1?"":url.slice(mark)},locale(){return currentRequestContext()?.locale??"en"}};exitWithParent();const projectServe=projectPath("serve.ts");try{if(await Bun.file(projectServe).exists())await import(projectServe);else await startDefaultServer()}catch{await startDefaultServer()}function parseCookies(req){const out={},header=req.headers.get("cookie")||"";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)continue;try{out[k]=decodeURIComponent(v)}catch{out[k]=v}}return out}async function startDefaultServer(){await overridesReady;const{injectGlobalAutoImports,isApiBoundRequest,proxyToBackend}=await import("@stacksjs/server"),{applyRequestLocale}=await import("@stacksjs/i18n");await injectGlobalAutoImports();const{serve}=await import("bun-plugin-stx/serve"),{site:siteConfig,i18n:i18nConfig}=await loadStxSiteConfig(),userViewsPath="resources/views",defaultViewsPath="storage/framework/defaults/resources/views",userLayoutsPath=await firstExistingPath(["resources/views/layouts","resources/layouts"])??"resources/views/layouts",defaultLayoutsPath="storage/framework/defaults/resources/layouts",userPartialsPath=await firstExistingPath(["resources/partials","resources/views/partials","partials","resources/components"]),preferredPort=Number(process.env.PORT)||3000,apiPort=Number(process.env.PORT_API)||3008,docsPort=Number(process.env.PORT_DOCS)||config.ports?.docs||3006,apiBase=`http://127.0.0.1:${apiPort}`,docsBase=`http://127.0.0.1:${docsPort}`,authCookie=config?.auth?.defaultTokenName??"auth-token";await serve({patterns:[userViewsPath,defaultViewsPath],port:preferredPort,componentsDir:"storage/framework/defaults/resources/components",layoutsDir:userLayoutsPath,...userPartialsPath&&{partialsDir:userPartialsPath},fallbackLayoutsDir:defaultLayoutsPath,fallbackPartialsDir:defaultViewsPath,quiet:!0,openPath:process.env.STACKS_DEV_ENTRY_PATH||"/",...i18nConfig&&{i18n:i18nConfig},...siteConfig?.url&&{site:siteConfig},auth:{cookieName:authCookie,redirectTo:"/login"},onRequest:async(req)=>{const url=new URL(req.url),{maintenanceGate}=await import("@stacksjs/server"),gated=await maintenanceGate(req);if(gated)return gated;if(existsSync(projectPath("resources/views/blog.stx"))){const{renderBlogFeed}=await import("../blog"),feed=await renderBlogFeed(req);if(feed)return feed}else{const{renderBlog}=await import("../blog"),blogResponse=await renderBlog(req);if(blogResponse)return blogResponse}if(url.pathname==="/docs"||url.pathname.startsWith("/docs/"))return proxyToBackend(req,docsBase,"/docs");if(isApiBoundRequest(req,url.pathname))return proxyToBackend(req,apiBase);if(i18nConfig&&req.method==="GET"){const localeSwitch=url.pathname.match(/^\/locale\/([a-z]{2}(?:-[a-z]{2})?)\/?$/i);if(localeSwitch){const{createLocaleSwitchResponse}=await import("@stacksjs/i18n");return createLocaleSwitchResponse(req,localeSwitch[1],i18nConfig)}}const locale=await applyRequestLocale(req),ctx={cookies:parseCookies(req),url:req.url,locale};globalThis.__stxServeSearch=url.search;globalThis.__stxServeContext=ctx;requestStore.enterWith(ctx);return null},onResponse:seedCsrfPageResponse})}async function firstExistingPath(candidates){const existing=candidates.filter((candidate)=>existsSync(projectPath(candidate)));if(existing.length===0)return null;for(const candidate of existing)if(containsTemplates(projectPath(candidate)))return candidate;return existing[0]}function containsTemplates(dir){try{return[...new Bun.Glob("**/*.stx").scanSync({cwd:dir,onlyFiles:!0})].length>0}catch{return!1}}function fallbackI18nFromSite(site){const locales=site.i18n.locales,defaultLocale=site.i18n.defaultLocale??locales[0];return{locales,defaultLocale,labels:site.i18n.labels??Object.fromEntries(locales.map((c)=>[c,c.toUpperCase()])),translations:{},pickerSelector:site.i18n.pickerSelector??"#lang-picker"}}async function resolveSiteI18n(site){try{const{resolveI18n}=await import("@stacksjs/stx");if(typeof resolveI18n==="function"){const i18n=resolveI18n(site,projectPath());if(i18n)return i18n}}catch{}return fallbackI18nFromSite(site)}async function loadStxSiteConfig(){const sitePath=projectPath("site.config.ts");if(!existsSync(sitePath))return{};try{const site=(await import(sitePath)).default;if(!site)return{};if(!site.i18n)return{site};const i18n=await resolveSiteI18n(site);return{site,i18n}}catch{}return{}}
1
+ import{AsyncLocalStorage}from"node:async_hooks";import{existsSync}from"node:fs";import{config,overridesReady}from"@stacksjs/config";import{projectPath}from"@stacksjs/path";import{seedCsrfPageResponse}from"./csrf";import{exitWithParent}from"./exit-with-parent";const requestStore=new AsyncLocalStorage;function currentRequestContext(){return requestStore.getStore()??globalThis.__stxServeContext}globalThis.requestContext={cookie(name){return currentRequestContext()?.cookies?.[name]??null},url(){return currentRequestContext()?.url??""},search(){const url=currentRequestContext()?.url;if(!url)return"";const mark=url.indexOf("?");return mark===-1?"":url.slice(mark)},locale(){return currentRequestContext()?.locale??"en"}};exitWithParent();const projectServe=projectPath("serve.ts");try{if(await Bun.file(projectServe).exists())await import(projectServe);else await startDefaultServer()}catch{await startDefaultServer()}function parseCookies(req){const out={},header=req.headers.get("cookie")||"";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)continue;try{out[k]=decodeURIComponent(v)}catch{out[k]=v}}return out}async function startDefaultServer(){await overridesReady;const{injectGlobalAutoImports,isApiBoundRequest,proxyToBackend}=await import("@stacksjs/server"),{applyRequestLocale}=await import("@stacksjs/i18n");await injectGlobalAutoImports();const{serve}=await import("bun-plugin-stx/serve"),{site:siteConfig,i18n:i18nConfig}=await loadStxSiteConfig(),userViewsPath="resources/views",defaultViewsPath="storage/framework/defaults/resources/views",userLayoutsPath=await firstExistingPath(["resources/views/layouts","resources/layouts"])??"resources/views/layouts",defaultLayoutsPath="storage/framework/defaults/resources/layouts",userPartialsPath=await firstExistingPath(["resources/partials","resources/views/partials","partials","resources/components"]),preferredPort=Number(process.env.PORT)||3000,apiPort=Number(process.env.PORT_API)||3008,docsPort=Number(process.env.PORT_DOCS)||config.ports?.docs||3006,apiBase=`http://127.0.0.1:${apiPort}`,docsBase=`http://127.0.0.1:${docsPort}`,hasUserDocsView=["docs.stx","docs/index.stx"].some((rel)=>existsSync(projectPath(`${userViewsPath}/${rel}`))),hasDocsSite=existsSync(projectPath("docs")),docsProxyEnabled=!hasUserDocsView&&hasDocsSite,authCookie=config?.auth?.defaultTokenName??"auth-token";await serve({patterns:[userViewsPath,defaultViewsPath],port:preferredPort,componentsDir:"storage/framework/defaults/resources/components",layoutsDir:userLayoutsPath,...userPartialsPath&&{partialsDir:userPartialsPath},fallbackLayoutsDir:defaultLayoutsPath,fallbackPartialsDir:defaultViewsPath,quiet:!0,openPath:process.env.STACKS_DEV_ENTRY_PATH||"/",...i18nConfig&&{i18n:i18nConfig},...siteConfig?.url&&{site:siteConfig},auth:{cookieName:authCookie,redirectTo:"/login"},onRequest:async(req)=>{const url=new URL(req.url),{maintenanceGate}=await import("@stacksjs/server"),gated=await maintenanceGate(req);if(gated)return gated;if(existsSync(projectPath("resources/views/blog.stx"))){const{renderBlogFeed}=await import("../blog"),feed=await renderBlogFeed(req);if(feed)return feed}else{const{renderBlog}=await import("../blog"),blogResponse=await renderBlog(req);if(blogResponse)return blogResponse}if(docsProxyEnabled&&(url.pathname==="/docs"||url.pathname.startsWith("/docs/")))return proxyToBackend(req,docsBase,"/docs");if(isApiBoundRequest(req,url.pathname))return proxyToBackend(req,apiBase);if(i18nConfig&&req.method==="GET"){const localeSwitch=url.pathname.match(/^\/locale\/([a-z]{2}(?:-[a-z]{2})?)\/?$/i);if(localeSwitch){const{createLocaleSwitchResponse}=await import("@stacksjs/i18n");return createLocaleSwitchResponse(req,localeSwitch[1],i18nConfig)}}const locale=await applyRequestLocale(req),ctx={cookies:parseCookies(req),url:req.url,locale};globalThis.__stxServeSearch=url.search;globalThis.__stxServeContext=ctx;requestStore.enterWith(ctx);return null},onResponse:seedCsrfPageResponse})}async function firstExistingPath(candidates){const existing=candidates.filter((candidate)=>existsSync(projectPath(candidate)));if(existing.length===0)return null;for(const candidate of existing)if(containsTemplates(projectPath(candidate)))return candidate;return existing[0]}function containsTemplates(dir){try{return[...new Bun.Glob("**/*.stx").scanSync({cwd:dir,onlyFiles:!0})].length>0}catch{return!1}}function fallbackI18nFromSite(site){const locales=site.i18n.locales,defaultLocale=site.i18n.defaultLocale??locales[0];return{locales,defaultLocale,labels:site.i18n.labels??Object.fromEntries(locales.map((c)=>[c,c.toUpperCase()])),translations:{},pickerSelector:site.i18n.pickerSelector??"#lang-picker"}}async function resolveSiteI18n(site){try{const{resolveI18n}=await import("@stacksjs/stx");if(typeof resolveI18n==="function"){const i18n=resolveI18n(site,projectPath());if(i18n)return i18n}}catch{}return fallbackI18nFromSite(site)}async function loadStxSiteConfig(){const sitePath=projectPath("site.config.ts");if(!existsSync(sitePath))return{};try{const site=(await import(sitePath)).default;if(!site)return{};if(!site.i18n)return{site};const i18n=await resolveSiteI18n(site);return{site,i18n}}catch{}return{}}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The pinned suite: every `protocol:…:check` and `docs:…:check` script.
2
+ * The pinned suite: every `docs:…:check` script.
3
3
  *
4
4
  * Deliberately narrow. `types:check`, `format:check` and `deps:lockfile:check`
5
5
  * also end in `:check` but are not generated-artifact freshness checks, they
@@ -1,3 +1,3 @@
1
- import{readFileSync}from"node:fs";import{join}from"node:path";export const BYPASS_ENV="RELEASE_GATE_BYPASS";export function pinnedCheckScripts(scripts){return Object.keys(scripts).filter((name)=>/^(?:protocol|docs):(?:[\w:-]+:)?check$/.test(name)).sort()}export function readPinnedChecks(cwd){try{const pkg=JSON.parse(readFileSync(join(cwd,"package.json"),"utf8"));return pinnedCheckScripts(pkg.scripts??{})}catch{return[]}}function isBypassed(env){const value=env[BYPASS_ENV];return value==="1"||value==="true"}export async function runPinnedChecks(options={cwd:process.cwd()}){const env=options.env??process.env;if(isBypassed(env))return{ran:[],failures:[],bypassed:!0};const scripts=options.scripts??readPinnedChecks(options.cwd);if(scripts.length===0)return{ran:[],failures:[],bypassed:!1};const results=await Promise.all(scripts.map(async(script)=>{const proc=Bun.spawn(["bun","run",script],{cwd:options.cwd,stdout:"pipe",stderr:"pipe"}),[stdout,stderr,exitCode]=await Promise.all([new Response(proc.stdout).text(),new Response(proc.stderr).text(),proc.exited]);return{script,exitCode,output:`${stdout}${stderr}`.trim()}}));return{ran:scripts,failures:results.filter((r)=>r.exitCode!==0).map((r)=>({script:r.script,output:r.output})),bypassed:!1}}export function formatPreflightFailure(failures){const lines=[`Release blocked: ${failures.length} pinned check${failures.length===1?"":"s"} failed.`,""];for(const failure of failures){lines.push(` ${failure.script}`);const informative=failure.output.split(`
1
+ import{readFileSync}from"node:fs";import{join}from"node:path";export const BYPASS_ENV="RELEASE_GATE_BYPASS";export function pinnedCheckScripts(scripts){return Object.keys(scripts).filter((name)=>/^docs:(?:[\w:-]+:)?check$/.test(name)).sort()}export function readPinnedChecks(cwd){try{const pkg=JSON.parse(readFileSync(join(cwd,"package.json"),"utf8"));return pinnedCheckScripts(pkg.scripts??{})}catch{return[]}}function isBypassed(env){const value=env[BYPASS_ENV];return value==="1"||value==="true"}export async function runPinnedChecks(options={cwd:process.cwd()}){const env=options.env??process.env;if(isBypassed(env))return{ran:[],failures:[],bypassed:!0};const scripts=options.scripts??readPinnedChecks(options.cwd);if(scripts.length===0)return{ran:[],failures:[],bypassed:!1};const results=await Promise.all(scripts.map(async(script)=>{const proc=Bun.spawn(["bun","run",script],{cwd:options.cwd,stdout:"pipe",stderr:"pipe"}),[stdout,stderr,exitCode]=await Promise.all([new Response(proc.stdout).text(),new Response(proc.stderr).text(),proc.exited]);return{script,exitCode,output:`${stdout}${stderr}`.trim()}}));return{ran:scripts,failures:results.filter((r)=>r.exitCode!==0).map((r)=>({script:r.script,output:r.output})),bypassed:!1}}export function formatPreflightFailure(failures){const lines=[`Release blocked: ${failures.length} pinned check${failures.length===1?"":"s"} failed.`,""];for(const failure of failures){lines.push(` ${failure.script}`);const informative=failure.output.split(`
2
2
  `).map((line)=>line.trim()).filter((line)=>line&&!line.startsWith("[env]")&&!line.startsWith("$ ")&&!line.startsWith("error: script"));for(const line of informative.slice(0,4))lines.push(` ${line}`);lines.push("")}lines.push("Nothing was bumped, committed, or tagged.");lines.push(`Regenerate the affected artifacts and retry, or set ${BYPASS_ENV}=1 to release anyway.`);return lines.join(`
3
3
  `)}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/actions",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.70.260",
5
+ "version": "0.70.262",
6
6
  "description": "The Stacks actions.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -59,33 +59,33 @@
59
59
  "prepublishOnly": "bun run build"
60
60
  },
61
61
  "dependencies": {
62
- "@stacksjs/config": "0.70.260",
62
+ "@stacksjs/config": "0.70.262",
63
63
  "@stacksjs/bumpx": "^0.2.6",
64
64
  "@stacksjs/bunpress": "^0.1.18",
65
65
  "@stacksjs/logsmith": "^0.2.3",
66
- "@stacksjs/registry": "0.70.260",
66
+ "@stacksjs/registry": "0.70.262",
67
67
  "@stacksjs/stx": "^0.2.148",
68
- "@stacksjs/ts-cloud": "^0.7.94",
68
+ "@stacksjs/ts-cloud": "^0.7.96",
69
69
  "@stacksjs/ts-md": "^0.1.1"
70
70
  },
71
71
  "devDependencies": {
72
- "@stacksjs/api": "0.70.260",
73
- "@stacksjs/cli": "0.70.260",
74
- "@stacksjs/database": "0.70.260",
72
+ "@stacksjs/api": "0.70.262",
73
+ "@stacksjs/cli": "0.70.262",
74
+ "@stacksjs/database": "0.70.262",
75
75
  "@stacksjs/tlsx": "^0.13.2",
76
76
  "better-dx": "^0.2.17",
77
- "@stacksjs/dns": "0.70.260",
78
- "@stacksjs/enums": "0.70.260",
79
- "@stacksjs/env": "0.70.260",
80
- "@stacksjs/error-handling": "0.70.260",
81
- "@stacksjs/image": "0.70.260",
82
- "@stacksjs/logging": "0.70.260",
83
- "@stacksjs/path": "0.70.260",
84
- "@stacksjs/security": "0.70.260",
85
- "@stacksjs/storage": "0.70.260",
86
- "@stacksjs/strings": "0.70.260",
87
- "@stacksjs/utils": "0.70.260",
88
- "@stacksjs/validation": "0.70.260"
77
+ "@stacksjs/dns": "0.70.262",
78
+ "@stacksjs/enums": "0.70.262",
79
+ "@stacksjs/env": "0.70.262",
80
+ "@stacksjs/error-handling": "0.70.262",
81
+ "@stacksjs/image": "0.70.262",
82
+ "@stacksjs/logging": "0.70.262",
83
+ "@stacksjs/path": "0.70.262",
84
+ "@stacksjs/security": "0.70.262",
85
+ "@stacksjs/storage": "0.70.262",
86
+ "@stacksjs/strings": "0.70.262",
87
+ "@stacksjs/utils": "0.70.262",
88
+ "@stacksjs/validation": "0.70.262"
89
89
  },
90
90
  "peerDependencies": {
91
91
  "pickier": "^0.1.35"