@stacksjs/actions 0.75.311 → 0.75.316

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.
package/README.md CHANGED
@@ -27,6 +27,18 @@ import actions from '@stacksjs/actions'
27
27
 
28
28
  Learn more in the docs.
29
29
 
30
+ ## API server listeners
31
+
32
+ Set `PORT_API=0` when a test or supervising tool needs an available port. The
33
+ operating system assigns it while starting the listener; the ready banner
34
+ prints that actual address. An omitted or empty value uses `config.ports.api`,
35
+ then port 3008. Invalid port values fail before startup.
36
+
37
+ When the API entry is spawned with Bun IPC, it sends
38
+ `{ type: 'stacks:api-ready', port: number, url: string }` after routes load and
39
+ the server is listening. Use this address to configure a fixture proxy or make
40
+ requests, without probing and releasing a port before the child starts.
41
+
30
42
  ## 🧪 Testing
31
43
 
32
44
  ```bash
package/dist/dev/api.js CHANGED
@@ -1,5 +1,3 @@
1
- import{existsSync}from"node:fs";import process from"node:process";import{parseOptions}from"@stacksjs/cli";import{config,overridesReady}from"@stacksjs/config";import{path}from"@stacksjs/path";import{disableViewRouting,route}from"@stacksjs/router";import{autoImportsAreStale,generateAutoImportFiles,generateServerAutoImportTypes,injectGlobalAutoImports,warnShadowedSecurityDefaults}from"@stacksjs/server";import{resolveApiHost}from"../helpers/api-host";import{exitWithParent}from"./exit-with-parent";const _options=parseOptions();exitWithParent();await generateServerAutoImportTypes();await overridesReady;const port=Number(process.env.PORT_API)||config.ports?.api||3008,hostname=resolveApiHost();try{const{discoverPackages}=await import("../discover-packages");await discoverPackages()}catch{}const modelsIndex=path.storagePath("framework/auto-imports/models.ts");if(!existsSync(modelsIndex)||autoImportsAreStale())await generateAutoImportFiles();await injectGlobalAutoImports();warnShadowedSecurityDefaults();try{const typesenseDev=path.appPath("Lib/typesense-dev.ts");if(existsSync(typesenseDev)){const mod=await import(typesenseDev);if(typeof mod.ensureTypesenseRunning==="function")await mod.ensureTypesenseRunning()}}catch(err){const{log}=await import("@stacksjs/cli");log.warn(`[api:dev] search engine bootstrap skipped: ${err.message}`)}try{const listenerPath=path.appPath("Listener.ts");if(existsSync(listenerPath)){const listener=await import(listenerPath);if(typeof listener.handleEvents==="function")await listener.handleEvents()}}catch(err){const{log}=await import("@stacksjs/cli");log.warn(`[api:dev] failed to bootstrap event listeners - dispatched events will be ignored: ${err.message}`)}try{const{startModelMigrationWatcher}=await import("./migrate-watcher");startModelMigrationWatcher()}catch(err){const{log}=await import("@stacksjs/cli");log.debug(`[api:dev] auto-migrate watcher not started: ${err.message}`)}function resolveDefaultsCorsPath(){const published=path.appPath("Middleware/Cors.ts");if(existsSync(published))return published;const vendored=path.frameworkPath("defaults/app/Middleware/Cors.ts");if(existsSync(vendored))return vendored;try{return`${Bun.resolveSync("@stacksjs/defaults/package.json",process.cwd()).replace(/package\.json$/,"")}app/Middleware/Cors.ts`}catch{return vendored}}const corsMod=await import(resolveDefaultsCorsPath()),corsMiddleware=corsMod.default;route.use(corsMiddleware.toRouterHandler());const SAFE_REQUEST_ID=/^[a-zA-Z0-9._-]{8,128}$/;route.use(async(request,next)=>{const inbound=request?.headers?.get?.("x-request-id")||request?.headers?.get?.("X-Request-ID")||"",id=typeof inbound==="string"&&SAFE_REQUEST_ID.test(inbound)?inbound:crypto.randomUUID();request._requestId=id;request._startNs=process.hrtime.bigint();const response=await next();if(response&&response.status===404&&(response.headers.get("content-type")||"").includes("json"))try{const body=await response.clone().json();if(body&&(body.message==="Not Found"||body.error==="Not Found")){const url=new URL(request.url),enriched={...body,path:url.pathname,method:request.method,request_id:id},headers=new Headers(response.headers);headers.set("X-Request-ID",id);return new Response(JSON.stringify(enriched),{status:404,headers})}}catch{}return response});await route.importRoutes();disableViewRouting(route.bunRouter);try{await route.serve({port,hostname});console.log(`
2
- \u279C API server ready: http://${hostname}:${port}
3
- `)}catch(err){if((err?.code||err?.errno)==="EADDRINUSE"||String(err?.message||"").includes("EADDRINUSE")){console.error(`
1
+ import{existsSync}from"node:fs";import process from"node:process";import{parseOptions}from"@stacksjs/cli";import{config,overridesReady}from"@stacksjs/config";import{path}from"@stacksjs/path";import{disableViewRouting,route}from"@stacksjs/router";import{autoImportsAreStale,generateAutoImportFiles,generateServerAutoImportTypes,injectGlobalAutoImports,warnShadowedSecurityDefaults}from"@stacksjs/server";import{reportApiReady,resolveApiHost,resolveApiPort}from"../helpers/api-host";import{exitWithParent}from"./exit-with-parent";const _options=parseOptions();exitWithParent();await generateServerAutoImportTypes();await overridesReady;const port=resolveApiPort(process.env.PORT_API,config.ports?.api),hostname=resolveApiHost();try{const{discoverPackages}=await import("../discover-packages");await discoverPackages()}catch{}const modelsIndex=path.storagePath("framework/auto-imports/models.ts");if(!existsSync(modelsIndex)||autoImportsAreStale())await generateAutoImportFiles();await injectGlobalAutoImports();warnShadowedSecurityDefaults();try{const typesenseDev=path.appPath("Lib/typesense-dev.ts");if(existsSync(typesenseDev)){const mod=await import(typesenseDev);if(typeof mod.ensureTypesenseRunning==="function")await mod.ensureTypesenseRunning()}}catch(err){const{log}=await import("@stacksjs/cli");log.warn(`[api:dev] search engine bootstrap skipped: ${err.message}`)}try{const listenerPath=path.appPath("Listener.ts");if(existsSync(listenerPath)){const listener=await import(listenerPath);if(typeof listener.handleEvents==="function")await listener.handleEvents()}}catch(err){const{log}=await import("@stacksjs/cli");log.warn(`[api:dev] failed to bootstrap event listeners - dispatched events will be ignored: ${err.message}`)}try{const{startModelMigrationWatcher}=await import("./migrate-watcher");startModelMigrationWatcher()}catch(err){const{log}=await import("@stacksjs/cli");log.debug(`[api:dev] auto-migrate watcher not started: ${err.message}`)}function resolveDefaultsCorsPath(){const published=path.appPath("Middleware/Cors.ts");if(existsSync(published))return published;const vendored=path.frameworkPath("defaults/app/Middleware/Cors.ts");if(existsSync(vendored))return vendored;try{return`${Bun.resolveSync("@stacksjs/defaults/package.json",process.cwd()).replace(/package\.json$/,"")}app/Middleware/Cors.ts`}catch{return vendored}}const corsMod=await import(resolveDefaultsCorsPath()),corsMiddleware=corsMod.default;route.use(corsMiddleware.toRouterHandler());const SAFE_REQUEST_ID=/^[a-zA-Z0-9._-]{8,128}$/;route.use(async(request,next)=>{const inbound=request?.headers?.get?.("x-request-id")||request?.headers?.get?.("X-Request-ID")||"",id=typeof inbound==="string"&&SAFE_REQUEST_ID.test(inbound)?inbound:crypto.randomUUID();request._requestId=id;request._startNs=process.hrtime.bigint();const response=await next();if(response&&response.status===404&&(response.headers.get("content-type")||"").includes("json"))try{const body=await response.clone().json();if(body&&(body.message==="Not Found"||body.error==="Not Found")){const url=new URL(request.url),enriched={...body,path:url.pathname,method:request.method,request_id:id},headers=new Headers(response.headers);headers.set("X-Request-ID",id);return new Response(JSON.stringify(enriched),{status:404,headers})}}catch{}return response});await route.importRoutes();disableViewRouting(route.bunRouter);try{const server=await route.serve({port,hostname});reportApiReady(server)}catch(err){if((err?.code||err?.errno)==="EADDRINUSE"||String(err?.message||"").includes("EADDRINUSE")){console.error(`
4
2
  [dev/api] Port ${port} is already in use. Kill the other process and re-run \`./buddy dev\`, or set PORT_API to another port.
5
3
  `);process.exit(1)}throw err}
@@ -1,2 +1,7 @@
1
+ import type { Server } from 'bun';
2
+ /** Keep port zero as an explicit request for an OS-owned ephemeral listener. */
3
+ export declare function resolveApiPort(value: string | undefined, configured?: number): number;
4
+ /** Notify supervising tools only after the server owns its actual address. */
5
+ export declare function reportApiReady(server: Pick<Server<unknown>, 'port' | 'url'>): void;
1
6
  /** Resolve the interface used by API entrypoints in local and deployed runtimes. */
2
7
  export declare function resolveApiHost(env?: Record<string, string | undefined>): string;
@@ -1 +1,3 @@
1
- export function resolveApiHost(env=process.env){if(env.API_HOST)return env.API_HOST;if(env.HOST)return env.HOST;return env.NODE_ENV==="production"||env.APP_ENV==="production"?"0.0.0.0":"127.0.0.1"}
1
+ import process from"node:process";export function resolveApiPort(value,configured=3008){const port=value?.trim()?Number(value):configured;if(!Number.isInteger(port)||port<0||port>65535)throw RangeError("PORT_API must be an integer between 0 and 65535");return port}export function reportApiReady(server){process.send?.({type:"stacks:api-ready",port:server.port,url:server.url.href});console.log(`
2
+ \u279C API server ready: ${server.url.origin}
3
+ `)}export function resolveApiHost(env=process.env){if(env.API_HOST)return env.API_HOST;if(env.HOST)return env.HOST;return env.NODE_ENV==="production"||env.APP_ENV==="production"?"0.0.0.0":"127.0.0.1"}
@@ -6,6 +6,8 @@ export declare function parsePantryVersion(output: string): string | undefined;
6
6
  * declares it in its own manifest, if at all.
7
7
  */
8
8
  export declare function declaredPantryRange(cwd: string): { range: string, file: string } | undefined;
9
+ /** The source and publication jobs must use the SDK's declared toolchain too. */
10
+ export declare function declaredPantryWorkflowVersions(cwd: string): Array<{ file: string, job: string, version: string }>;
9
11
  /** Resolve the Pantry this release will run, and check it against the declared toolchain. */
10
12
  export declare function resolvePantryToolchain(options: PantryToolchainOptions): PantryToolchain;
11
13
  export declare interface PantryToolchainOptions {
@@ -1 +1 @@
1
- import{existsSync,readFileSync}from"node:fs";import{join}from"node:path";export function parsePantryVersion(output){return/\bpantry\s+v?(\d+\.\d+\.\d+(?:-[\w.]+)?)/i.exec(output)?.[1]}export function declaredPantryRange(cwd){for(const file of["storage/framework/core/buddy/package.json","package.json"]){const path=join(cwd,file);if(!existsSync(path))continue;try{const manifest=JSON.parse(readFileSync(path,"utf8")),range=manifest.dependencies?.["ts-pantry"]??manifest.devDependencies?.["ts-pantry"];if(range)return{range,file}}catch{}}return}function probeVersion(bin){try{const result=Bun.spawnSync([bin,"--version"],{stdout:"pipe",stderr:"pipe"});return{exitCode:result.exitCode??1,stdout:`${result.stdout.toString()}${result.stderr.toString()}`}}catch{return{exitCode:127,stdout:""}}}export function resolvePantryToolchain(options){const env=options.env??process.env,allowOverride=options.allowOverride!==!1,bin=allowOverride&&env.PANTRY_BIN?.trim()||"pantry",result=(options.probe??probeVersion)(bin),version=result.exitCode===0?parsePantryVersion(result.stdout):void 0;if(!version)return{ok:!1,bin,message:`Release aborted: could not run \`${bin} --version\`, so the Pantry that would regenerate pantry.lock is unknown. `+(allowOverride?"Install the declared Pantry, or set PANTRY_BIN to it, then re-run.":"Install the declared Pantry and put it first on PATH, then re-run.")};const declared=declaredPantryRange(options.cwd);if(declared&&!Bun.semver.satisfies(version,declared.range))return{ok:!1,bin,message:`Release aborted before any file changed: \`${bin}\` is Pantry ${version}, but ${declared.file} declares ts-pantry ${declared.range}. A different Pantry writes a different pantry.lock than the one CI validates. `+(allowOverride?"Set PANTRY_BIN to a Pantry that satisfies the declared range (or put one first on PATH), then re-run.":"Install a Pantry that satisfies the declared range and put it first on PATH, then re-run.")};return{ok:!0,bin,version,declared:declared?.range,declaredIn:declared?.file}}
1
+ import{existsSync,readFileSync}from"node:fs";import{join}from"node:path";export function parsePantryVersion(output){return/\bpantry\s+v?(\d+\.\d+\.\d+(?:-[\w.]+)?)/i.exec(output)?.[1]}export function declaredPantryRange(cwd){for(const file of["storage/framework/core/buddy/package.json","package.json"]){const path=join(cwd,file);if(!existsSync(path))continue;try{const manifest=JSON.parse(readFileSync(path,"utf8")),range=manifest.dependencies?.["ts-pantry"]??manifest.devDependencies?.["ts-pantry"];if(range)return{range,file}}catch{}}return}export function declaredPantryWorkflowVersions(cwd){const versions=[];for(const file of[".github/workflows/ci.yml",".github/workflows/release.yml"]){const path=join(cwd,file);if(!existsSync(path))continue;const workflow=Bun.YAML.parse(readFileSync(path,"utf8"));for(const[job,config]of Object.entries(workflow.jobs??{}))for(const step of config.steps??[])if(step.uses?.startsWith("pantry-pm/pantry/packages/action@"))versions.push({file,job,version:String(step.with?.version??"")})}return versions}function probeVersion(bin){try{const result=Bun.spawnSync([bin,"--version"],{stdout:"pipe",stderr:"pipe"});return{exitCode:result.exitCode??1,stdout:`${result.stdout.toString()}${result.stderr.toString()}`}}catch{return{exitCode:127,stdout:""}}}export function resolvePantryToolchain(options){const env=options.env??process.env,allowOverride=options.allowOverride!==!1,bin=allowOverride&&env.PANTRY_BIN?.trim()||"pantry",result=(options.probe??probeVersion)(bin),version=result.exitCode===0?parsePantryVersion(result.stdout):void 0;if(!version)return{ok:!1,bin,message:`Release aborted: could not run \`${bin} --version\`, so the Pantry that would regenerate pantry.lock is unknown. `+(allowOverride?"Install the declared Pantry, or set PANTRY_BIN to it, then re-run.":"Install the declared Pantry and put it first on PATH, then re-run.")};const declared=declaredPantryRange(options.cwd);if(declared&&!Bun.semver.satisfies(version,declared.range))return{ok:!1,bin,message:`Release aborted before any file changed: \`${bin}\` is Pantry ${version}, but ${declared.file} declares ts-pantry ${declared.range}. A different Pantry writes a different pantry.lock than the one CI validates. `+(allowOverride?"Set PANTRY_BIN to a Pantry that satisfies the declared range (or put one first on PATH), then re-run.":"Install a Pantry that satisfies the declared range and put it first on PATH, then re-run.")};if(declared?.file==="storage/framework/core/buddy/package.json")try{const pins=declaredPantryWorkflowVersions(options.cwd),bootstrap="storage/framework/scripts/pantry-install",bootstrapPath=join(options.cwd,bootstrap);if(existsSync(bootstrapPath))pins.push({file:bootstrap,job:"bootstrap",version:readFileSync(bootstrapPath,"utf8").match(/PANTRY_VERSION:-([0-9.]+)/)?.[1]??""});const mismatches=pins.filter((pin)=>!/^\d+\.\d+\.\d+$/.test(pin.version)||!Bun.semver.satisfies(pin.version,declared.range));if(mismatches.length)return{ok:!1,bin,message:`Release aborted before any file changed: Pantry toolchain pins do not satisfy ts-pantry ${declared.range}: `+mismatches.map((pin)=>`${pin.file} (${pin.job}): ${pin.version||"missing version"}`).join("; ")+". Update the pinned Pantry action and CLI together before releasing."}}catch(error){return{ok:!1,bin,message:`Could not validate CI Pantry versions before release: ${error instanceof Error?error.message:String(error)}`}}return{ok:!0,bin,version,declared:declared?.range,declaredIn:declared?.file}}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/actions",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.311",
5
+ "version": "0.75.316",
6
6
  "description": "The Stacks actions.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -66,54 +66,54 @@
66
66
  "prepublishOnly": "bun run build"
67
67
  },
68
68
  "dependencies": {
69
- "@stacksjs/action-runner": "0.75.311",
70
- "@stacksjs/ai": "0.75.311",
71
- "@stacksjs/analytics": "0.75.311",
72
- "@stacksjs/api": "0.75.311",
73
- "@stacksjs/auth": "0.75.311",
74
- "@stacksjs/build": "0.75.311",
69
+ "@stacksjs/action-runner": "0.75.316",
70
+ "@stacksjs/ai": "0.75.316",
71
+ "@stacksjs/analytics": "0.75.316",
72
+ "@stacksjs/api": "0.75.316",
73
+ "@stacksjs/auth": "0.75.316",
74
+ "@stacksjs/build": "0.75.316",
75
75
  "@stacksjs/bumpx": "^0.2.26",
76
76
  "@stacksjs/bunpress": "^0.2.15",
77
- "@stacksjs/cli": "0.75.311",
78
- "@stacksjs/cloud": "0.75.311",
79
- "@stacksjs/cms": "0.75.311",
77
+ "@stacksjs/cli": "0.75.316",
78
+ "@stacksjs/cloud": "0.75.316",
79
+ "@stacksjs/cms": "0.75.316",
80
80
  "@stacksjs/components": "0.2.691",
81
- "@stacksjs/config": "0.75.311",
82
- "@stacksjs/database": "0.75.311",
83
- "@stacksjs/desktop-build": "0.75.311",
84
- "@stacksjs/dns": "0.75.311",
85
- "@stacksjs/enums": "0.75.311",
86
- "@stacksjs/env": "0.75.311",
87
- "@stacksjs/error-handling": "0.75.311",
88
- "@stacksjs/github": "0.75.311",
81
+ "@stacksjs/config": "0.75.316",
82
+ "@stacksjs/database": "0.75.316",
83
+ "@stacksjs/desktop-build": "0.75.316",
84
+ "@stacksjs/dns": "0.75.316",
85
+ "@stacksjs/enums": "0.75.316",
86
+ "@stacksjs/env": "0.75.316",
87
+ "@stacksjs/error-handling": "0.75.316",
88
+ "@stacksjs/github": "0.75.316",
89
89
  "@stacksjs/gitit": "^0.2.5",
90
- "@stacksjs/i18n": "0.75.311",
91
- "@stacksjs/image": "0.75.311",
92
- "@stacksjs/logging": "0.75.311",
90
+ "@stacksjs/i18n": "0.75.316",
91
+ "@stacksjs/image": "0.75.316",
92
+ "@stacksjs/logging": "0.75.316",
93
93
  "@stacksjs/logsmith": "^0.2.11",
94
- "@stacksjs/mobile": "0.75.311",
95
- "@stacksjs/orm": "0.75.311",
96
- "@stacksjs/path": "0.75.311",
97
- "@stacksjs/payments": "0.75.311",
98
- "@stacksjs/queue": "0.75.311",
99
- "@stacksjs/registry": "0.75.311",
100
- "@stacksjs/router": "0.75.311",
94
+ "@stacksjs/mobile": "0.75.316",
95
+ "@stacksjs/orm": "0.75.316",
96
+ "@stacksjs/path": "0.75.316",
97
+ "@stacksjs/payments": "0.75.316",
98
+ "@stacksjs/queue": "0.75.316",
99
+ "@stacksjs/registry": "0.75.316",
100
+ "@stacksjs/router": "0.75.316",
101
101
  "@stacksjs/rpx": "^0.11.54",
102
- "@stacksjs/scheduler": "0.75.311",
103
- "@stacksjs/search-engine": "0.75.311",
104
- "@stacksjs/security": "0.75.311",
105
- "@stacksjs/server": "0.75.311",
106
- "@stacksjs/sites": "0.75.311",
107
- "@stacksjs/storage": "0.75.311",
108
- "@stacksjs/strings": "0.75.311",
102
+ "@stacksjs/scheduler": "0.75.316",
103
+ "@stacksjs/search-engine": "0.75.316",
104
+ "@stacksjs/security": "0.75.316",
105
+ "@stacksjs/server": "0.75.316",
106
+ "@stacksjs/sites": "0.75.316",
107
+ "@stacksjs/storage": "0.75.316",
108
+ "@stacksjs/strings": "0.75.316",
109
109
  "@stacksjs/stx": "0.2.691",
110
110
  "@stacksjs/tlsx": "^0.13.19",
111
111
  "@stacksjs/ts-cloud": "^0.16.69",
112
112
  "@stacksjs/ts-md": "^0.1.1",
113
- "@stacksjs/tunnel": "0.75.311",
114
- "@stacksjs/types": "0.75.311",
115
- "@stacksjs/utils": "0.75.311",
116
- "@stacksjs/whois": "0.75.311",
113
+ "@stacksjs/tunnel": "0.75.316",
114
+ "@stacksjs/types": "0.75.316",
115
+ "@stacksjs/utils": "0.75.316",
116
+ "@stacksjs/whois": "0.75.316",
117
117
  "bun-plugin-stx": "0.2.691"
118
118
  },
119
119
  "peerDependencies": {
@@ -129,7 +129,7 @@
129
129
  }
130
130
  },
131
131
  "devDependencies": {
132
- "@stacksjs/validation": "0.75.311",
132
+ "@stacksjs/validation": "0.75.316",
133
133
  "better-dx": "^0.2.24"
134
134
  }
135
135
  }