@mcp-com-ai/shared-utils 1.0.1-beta.260912 → 1.0.2-beta.260914
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 +46 -0
- package/dist/config.js +126 -126
- package/dist/errors.js +3 -2
- package/dist/home.d.ts +13 -0
- package/dist/home.js +1 -1
- package/dist/index.js +177 -176
- package/dist/logger.js +38 -38
- package/dist/runtime.js +1 -1
- package/dist/secrets.js +1 -1
- package/package.json +56 -56
package/dist/errors.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var d={},a=f(),{isBunRuntime:s,isCloudflareRuntime:p,isNodeRuntime:x,hasFileSystemAccess:m,console:w}=a,y=d;g();function l(e,n){let t=typeof process<"u"?process.env:void 0,i=t?t[e]:void 0,o=s?Bun?.env?.[e]:void 0,r=y[e],c=typeof r==="string"?r:void 0,u=p?c??i??o:i??o??c;return u===void 0||u===""?n:u}function L(e,n){if(typeof process<"u")process.env[e]=n;y[e]=n}function P(e){globalThis.__hapiRuntimeOverride="cloudflare",h(),Object.assign(d,e)}function V(){delete globalThis.__hapiRuntimeOverride,h()}async function I(e){if(!s)throw Error(`File system access not available in this runtime: ${e}`);return await Bun.file(e).text()}async function H(e){if(!s)throw Error(`File system access not available in this runtime: ${e}`);return await Bun.file(e).json()}async function M(e){return s?await Bun.file(e).exists():!1}function U(e){if(!s)throw Error(`File system access not available in this runtime: ${e}`);return Bun.file(e)}function h(){let e=f();v(e),g()}function j(){if(m)return;if(b()!==void 0)return;let e=f();v(e),g()}function f(){let e=b(),n=k(e),t=n?!1:S(e),i=_(e,t);return{isBunRuntime:n,isCloudflareRuntime:t,isNodeRuntime:i,hasFileSystemAccess:!t&&(n||i),console:B()}}function k(e){if(e==="bun")return!0;if(e==="cloudflare"||e==="node")return!1;return typeof Bun<"u"}function S(e){if(e==="cloudflare")return!0;if(e==="bun"||e==="node")return!1;let n=typeof globalThis<"u"?globalThis:void 0,t=n?.navigator?.userAgent??"",i=typeof t==="string"&&t.includes("Cloudflare-Workers"),o=typeof n?.__ENVIRONMENT__==="string"&&n.__ENVIRONMENT__.toLowerCase()==="workerd",r=typeof n?.caches?.default<"u";return i||o||r}function _(e,n){if(e==="node")return!0;if(e==="bun"||e==="cloudflare")return!1;if(n)return!1;let t=typeof process<"u"?process.versions?.node:void 0;return typeof t==="string"&&t.length>0}function b(){return typeof globalThis<"u"?globalThis.__hapiRuntimeOverride:void 0}function B(){let e=()=>{},n=typeof console<"u"?console:void 0;if(!n)return{log:e,info:e,warn:e,error:e,debug:e};let t=(o,r)=>typeof o==="function"?o.bind(n):r,i=t(n.log,e);return{log:i,info:t(n.info,i),warn:t(n.warn,i),error:t(n.error,i),debug:t(n.debug,i)}}function v(e){s=e.isBunRuntime,p=e.isCloudflareRuntime,x=e.isNodeRuntime,m=e.hasFileSystemAccess,w=e.console}function g(){let e=T();for(let n of Object.keys(d))delete d[n];Object.assign(d,e)}function T(){if(s)return{...typeof Bun<"u"?Bun.env:{},...typeof process<"u"?process.env:{}};return(typeof process<"u"?process:void 0)?.env??{}}function R(e){if(typeof e==="string")return e;if(e&&typeof e.toString==="function")return e.toString();try{return JSON.stringify(e)}catch{return String(e)}}var E=4000;function C(e){if(!e)return;let n=e.trim();if(!n)return;return n.length>E?`${n.slice(0,E)}
|
|
3
|
+
\u2026 (truncated)`:n}function N(){return l("HAPI_DEBUG")==="true"||l("NODE_ENV")==="development"||l("DEBUG")==="true"||process.argv.includes("--dev")}function O(e){let n=[],t=e.toLowerCase();if(t.includes("wrangler")&&(t.includes("not found")||t.includes("command not found")))n.push("Wrangler CLI not found. Install with: bun add -g wrangler | npm i -g wrangler"),n.push("Then run: hapi cloudflare login");if(t.includes("not authenticated")||t.includes("unauthorized"))n.push("You may need to authenticate: hapi cloudflare login");if(t.includes("bun: command not found")||t.startsWith("bun: "))n.push("Bun runtime not found. Install from https://bun.sh and ensure `bun` is in PATH");if(t.includes("eaddrinuse")||t.includes("address already in use"))n.push("Port is in use. Try a different `--port` or stop the process holding it");if(t.includes("econnrefused")||t.includes("connection refused"))n.push("Connection refused. Ensure the target server is running and reachable");if(t.includes("enotfound")||t.includes("getaddrinfo enotfound"))n.push("Host not found. Check the URL or your network connectivity");if(t.includes("yaml")&&(t.includes("parse")||t.includes("syntax")))n.push("YAML parsing failed. Check the file for syntax/indentation issues");if(t.includes("could not connect")||t.includes("org.freedesktop.secrets")||t.includes("was not provided by any .service files"))n.push("OS secrets service (keyring/D-Bus) is unavailable \u2014 this is unrelated to any file path you passed. "+"Provide the key via a --public-key/--private-key file, a LICENSE_PUBLIC_KEY_PEM/LICENSE_PRIVATE_KEY_PEM env var, or start a session keyring (e.g. dbus-run-session).");else if(t.includes("no such file or directory")||t.includes("enoent"))n.push("File not found. Verify the path or provide the correct argument");if(t.includes("permission denied")||t.includes("eacces"))n.push("Permission denied. Try a different directory or adjust permissions");return n}function A(e){let n=e,t=n?.stderr?R(n.stderr):void 0,i=n?.stdout?R(n.stdout):void 0,r=C(t)||C(i)||n?.message||"Unknown error";return{message:r.trim(),hints:O(r),stack:n&&typeof n.stack==="string"?n.stack:void 0}}function G(e,n,t={}){let{message:i,hints:o,stack:r}=A(n),c=t.showStack??N();if(i.includes(`
|
|
4
|
+
`))console.error(`${e}:`),console.error(i);else console.error(`${e}${i?`: ${i}`:""}`);for(let u of o)console.error(`\u2022 ${u}`);if(c&&r)console.error("Stack:"),console.error(r)}class F extends Error{exitCode;hints;constructor(e,n={}){super(e);if(this.name="HapiCliError",this.exitCode=n.exitCode??1,this.hints=n.hints??[],n.cause!==void 0)this.cause=n.cause}}export{F as HapiCliError,A as formatCliError,N as isDebugEnabled,G as printCliError};
|
package/dist/home.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface HapiPaths {
|
|
|
11
11
|
logs: string;
|
|
12
12
|
/** TLS certificates */
|
|
13
13
|
certs: string;
|
|
14
|
+
/** Managed extension packages for standalone HAPI hosts. */
|
|
15
|
+
plugins: string;
|
|
14
16
|
}
|
|
15
17
|
export declare const hapiHome: string;
|
|
16
18
|
export declare const hapiSpecs: string;
|
|
@@ -18,12 +20,23 @@ export declare const hapiConfig: string;
|
|
|
18
20
|
export declare const hapiSrc: string;
|
|
19
21
|
export declare const hapiLogs: string;
|
|
20
22
|
export declare const hapiCerts: string;
|
|
23
|
+
export declare const hapiPlugins: string;
|
|
21
24
|
export declare function getHapiPaths(): HapiPaths;
|
|
22
25
|
/**
|
|
23
26
|
* Resolve HAPI paths on the fly — useful for tests that set HAPI_HOME
|
|
24
27
|
* after module import.
|
|
25
28
|
*/
|
|
26
29
|
export declare function resolveHapiPaths(): HapiPaths;
|
|
30
|
+
/**
|
|
31
|
+
* Expand the current-user home shorthand and make HAPI_HOME absolute.
|
|
32
|
+
*
|
|
33
|
+
* Shells only expand `~` when it appears unquoted in a command line. A value
|
|
34
|
+
* supplied through an environment file, Docker configuration, or a quoted
|
|
35
|
+
* assignment reaches HAPI literally, so this normalization must live here.
|
|
36
|
+
* `~other-user` deliberately remains untouched: HAPI never guesses another
|
|
37
|
+
* user's home directory.
|
|
38
|
+
*/
|
|
39
|
+
export declare function normalizeHapiHomePath(value: string): string;
|
|
27
40
|
/**
|
|
28
41
|
* Ensure a HAPI subdirectory exists (best-effort; silently ignores when
|
|
29
42
|
* the runtime has no file-system access).
|
package/dist/home.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
2
|
+
import o from"path";var f={},d=g(),{isBunRuntime:r,isCloudflareRuntime:R,isNodeRuntime:w,hasFileSystemAccess:a,console:O}=d,v=f;m();function l(n,e){let t=typeof process<"u"?process.env:void 0,i=t?t[n]:void 0,u=r?Bun?.env?.[n]:void 0,c=v[n],y=typeof c==="string"?c:void 0,p=R?y??i??u:i??u??y;return p===void 0||p===""?e:p}function W(n,e){if(typeof process<"u")process.env[n]=e;v[n]=e}function J(n){globalThis.__hapiRuntimeOverride="cloudflare",x(),Object.assign(f,n)}function q(){delete globalThis.__hapiRuntimeOverride,x()}async function G(n){if(!r)throw Error(`File system access not available in this runtime: ${n}`);return await Bun.file(n).text()}async function K(n){if(!r)throw Error(`File system access not available in this runtime: ${n}`);return await Bun.file(n).json()}async function Q(n){return r?await Bun.file(n).exists():!1}function X(n){if(!r)throw Error(`File system access not available in this runtime: ${n}`);return Bun.file(n)}function x(){let n=g();E(n),m()}function Y(){if(a)return;if(b()!==void 0)return;let n=g();E(n),m()}function g(){let n=b(),e=B(n),t=e?!1:F(n),i=S(n,t);return{isBunRuntime:e,isCloudflareRuntime:t,isNodeRuntime:i,hasFileSystemAccess:!t&&(e||i),console:_()}}function B(n){if(n==="bun")return!0;if(n==="cloudflare"||n==="node")return!1;return typeof Bun<"u"}function F(n){if(n==="cloudflare")return!0;if(n==="bun"||n==="node")return!1;let e=typeof globalThis<"u"?globalThis:void 0,t=e?.navigator?.userAgent??"",i=typeof t==="string"&&t.includes("Cloudflare-Workers"),u=typeof e?.__ENVIRONMENT__==="string"&&e.__ENVIRONMENT__.toLowerCase()==="workerd",c=typeof e?.caches?.default<"u";return i||u||c}function S(n,e){if(n==="node")return!0;if(n==="bun"||n==="cloudflare")return!1;if(e)return!1;let t=typeof process<"u"?process.versions?.node:void 0;return typeof t==="string"&&t.length>0}function b(){return typeof globalThis<"u"?globalThis.__hapiRuntimeOverride:void 0}function _(){let n=()=>{},e=typeof console<"u"?console:void 0;if(!e)return{log:n,info:n,warn:n,error:n,debug:n};let t=(u,c)=>typeof u==="function"?u.bind(e):c,i=t(e.log,n);return{log:i,info:t(e.info,i),warn:t(e.warn,i),error:t(e.error,i),debug:t(e.debug,i)}}function E(n){r=n.isBunRuntime,R=n.isCloudflareRuntime,w=n.isNodeRuntime,a=n.hasFileSystemAccess,O=n.console}function m(){let n=T();for(let e of Object.keys(f))delete f[e];Object.assign(f,n)}function T(){if(r)return{...typeof Bun<"u"?Bun.env:{},...typeof process<"u"?process.env:{}};return(typeof process<"u"?process:void 0)?.env??{}}var s=a?P():C(),{home:j,specs:A,config:N,src:k,logs:V,certs:M,plugins:L}=s;function tn(){return{...s}}function on(){return a?P():C()}function P(){let n=l("HAPI_HOME"),e=n&&n.trim().length>0?D(n):I();return H(e)}function C(){return H("/hapi")}function H(n){return{home:n,specs:o.join(n,"specs"),config:o.join(n,"config"),src:o.join(n,"src"),logs:o.join(n,"logs"),certs:o.join(n,"certs"),plugins:o.join(n,"plugins")}}function I(){return o.join(h(),".hapi")}function D(n){let e=n.trim(),t=e==="~"?h():e.replace(/^~(?=[\\/])/,h());return o.resolve(t)}function h(){let n=r?globalThis.Bun?.env??{}:{},e=n.HOME??n.USERPROFILE??l("HOME")??l("USERPROFILE")??z(l("HOMEDRIVE"),l("HOMEPATH"));return e?o.resolve(e):o.resolve(".")}function z(n,e){if(!n||!e)return;return`${n}${e}`}async function U(n){if(!a)return;try{let e=await import("fs/promises");await e.mkdir(n,{recursive:!0})}catch{}}async function rn(){if(!a)return;await Promise.all([j,A,N,k,V,M,L].map(U))}export{rn as ensureAllHapiDirs,U as ensureHapiDir,tn as getHapiPaths,M as hapiCerts,N as hapiConfig,j as hapiHome,V as hapiLogs,L as hapiPlugins,A as hapiSpecs,k as hapiSrc,D as normalizeHapiHomePath,on as resolveHapiPaths};
|