@stacksjs/actions 0.75.315 → 0.75.317
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 +12 -0
- package/dist/dev/api.js +1 -3
- package/dist/helpers/api-host.d.ts +5 -0
- package/dist/helpers/api-host.js +3 -1
- package/package.json +40 -40
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=
|
|
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;
|
package/dist/helpers/api-host.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export function
|
|
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"}
|
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.
|
|
5
|
+
"version": "0.75.317",
|
|
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.
|
|
70
|
-
"@stacksjs/ai": "0.75.
|
|
71
|
-
"@stacksjs/analytics": "0.75.
|
|
72
|
-
"@stacksjs/api": "0.75.
|
|
73
|
-
"@stacksjs/auth": "0.75.
|
|
74
|
-
"@stacksjs/build": "0.75.
|
|
69
|
+
"@stacksjs/action-runner": "0.75.317",
|
|
70
|
+
"@stacksjs/ai": "0.75.317",
|
|
71
|
+
"@stacksjs/analytics": "0.75.317",
|
|
72
|
+
"@stacksjs/api": "0.75.317",
|
|
73
|
+
"@stacksjs/auth": "0.75.317",
|
|
74
|
+
"@stacksjs/build": "0.75.317",
|
|
75
75
|
"@stacksjs/bumpx": "^0.2.26",
|
|
76
76
|
"@stacksjs/bunpress": "^0.2.15",
|
|
77
|
-
"@stacksjs/cli": "0.75.
|
|
78
|
-
"@stacksjs/cloud": "0.75.
|
|
79
|
-
"@stacksjs/cms": "0.75.
|
|
77
|
+
"@stacksjs/cli": "0.75.317",
|
|
78
|
+
"@stacksjs/cloud": "0.75.317",
|
|
79
|
+
"@stacksjs/cms": "0.75.317",
|
|
80
80
|
"@stacksjs/components": "0.2.691",
|
|
81
|
-
"@stacksjs/config": "0.75.
|
|
82
|
-
"@stacksjs/database": "0.75.
|
|
83
|
-
"@stacksjs/desktop-build": "0.75.
|
|
84
|
-
"@stacksjs/dns": "0.75.
|
|
85
|
-
"@stacksjs/enums": "0.75.
|
|
86
|
-
"@stacksjs/env": "0.75.
|
|
87
|
-
"@stacksjs/error-handling": "0.75.
|
|
88
|
-
"@stacksjs/github": "0.75.
|
|
81
|
+
"@stacksjs/config": "0.75.317",
|
|
82
|
+
"@stacksjs/database": "0.75.317",
|
|
83
|
+
"@stacksjs/desktop-build": "0.75.317",
|
|
84
|
+
"@stacksjs/dns": "0.75.317",
|
|
85
|
+
"@stacksjs/enums": "0.75.317",
|
|
86
|
+
"@stacksjs/env": "0.75.317",
|
|
87
|
+
"@stacksjs/error-handling": "0.75.317",
|
|
88
|
+
"@stacksjs/github": "0.75.317",
|
|
89
89
|
"@stacksjs/gitit": "^0.2.5",
|
|
90
|
-
"@stacksjs/i18n": "0.75.
|
|
91
|
-
"@stacksjs/image": "0.75.
|
|
92
|
-
"@stacksjs/logging": "0.75.
|
|
90
|
+
"@stacksjs/i18n": "0.75.317",
|
|
91
|
+
"@stacksjs/image": "0.75.317",
|
|
92
|
+
"@stacksjs/logging": "0.75.317",
|
|
93
93
|
"@stacksjs/logsmith": "^0.2.11",
|
|
94
|
-
"@stacksjs/mobile": "0.75.
|
|
95
|
-
"@stacksjs/orm": "0.75.
|
|
96
|
-
"@stacksjs/path": "0.75.
|
|
97
|
-
"@stacksjs/payments": "0.75.
|
|
98
|
-
"@stacksjs/queue": "0.75.
|
|
99
|
-
"@stacksjs/registry": "0.75.
|
|
100
|
-
"@stacksjs/router": "0.75.
|
|
94
|
+
"@stacksjs/mobile": "0.75.317",
|
|
95
|
+
"@stacksjs/orm": "0.75.317",
|
|
96
|
+
"@stacksjs/path": "0.75.317",
|
|
97
|
+
"@stacksjs/payments": "0.75.317",
|
|
98
|
+
"@stacksjs/queue": "0.75.317",
|
|
99
|
+
"@stacksjs/registry": "0.75.317",
|
|
100
|
+
"@stacksjs/router": "0.75.317",
|
|
101
101
|
"@stacksjs/rpx": "^0.11.54",
|
|
102
|
-
"@stacksjs/scheduler": "0.75.
|
|
103
|
-
"@stacksjs/search-engine": "0.75.
|
|
104
|
-
"@stacksjs/security": "0.75.
|
|
105
|
-
"@stacksjs/server": "0.75.
|
|
106
|
-
"@stacksjs/sites": "0.75.
|
|
107
|
-
"@stacksjs/storage": "0.75.
|
|
108
|
-
"@stacksjs/strings": "0.75.
|
|
102
|
+
"@stacksjs/scheduler": "0.75.317",
|
|
103
|
+
"@stacksjs/search-engine": "0.75.317",
|
|
104
|
+
"@stacksjs/security": "0.75.317",
|
|
105
|
+
"@stacksjs/server": "0.75.317",
|
|
106
|
+
"@stacksjs/sites": "0.75.317",
|
|
107
|
+
"@stacksjs/storage": "0.75.317",
|
|
108
|
+
"@stacksjs/strings": "0.75.317",
|
|
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.
|
|
114
|
-
"@stacksjs/types": "0.75.
|
|
115
|
-
"@stacksjs/utils": "0.75.
|
|
116
|
-
"@stacksjs/whois": "0.75.
|
|
113
|
+
"@stacksjs/tunnel": "0.75.317",
|
|
114
|
+
"@stacksjs/types": "0.75.317",
|
|
115
|
+
"@stacksjs/utils": "0.75.317",
|
|
116
|
+
"@stacksjs/whois": "0.75.317",
|
|
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.
|
|
132
|
+
"@stacksjs/validation": "0.75.317",
|
|
133
133
|
"better-dx": "^0.2.24"
|
|
134
134
|
}
|
|
135
135
|
}
|