@mcp-com-ai/shared-utils 1.0.1-beta.260914 → 1.1.0

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
@@ -29,7 +29,7 @@ Deploying & Registering MCP Servers
29
29
 
30
30
  ---
31
31
 
32
- # HAPI Shared Utilities ![NPM Version](https://img.shields.io/npm/v/%40mcp-com-ai%2fhapimcp)
32
+ # HAPI Shared Utilities ![NPM Version](https://img.shields.io/npm/v/%40mcp-com-ai%2fhapi)
33
33
 
34
34
  `@mcp-com-ai/shared-utils` contains the configuration, logging, HAPI home, and
35
35
  runtime helpers used internally by the HAPI CLI and its plugins.
package/dist/errors.js CHANGED
@@ -1,3 +1,4 @@
1
1
  // @bun
2
- var d={},a=f(),{isBunRuntime:s,isCloudflareRuntime:p,isNodeRuntime:E,hasFileSystemAccess:m,console:x}=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 A(e,n){if(typeof process<"u")process.env[e]=n;y[e]=n}function L(e){globalThis.__hapiRuntimeOverride="cloudflare",h(),Object.assign(d,e)}function P(){delete globalThis.__hapiRuntimeOverride,h()}async function V(e){if(!s)throw Error(`File system access not available in this runtime: ${e}`);return await Bun.file(e).text()}async function I(e){if(!s)throw Error(`File system access not available in this runtime: ${e}`);return await Bun.file(e).json()}async function U(e){return s?await Bun.file(e).exists():!1}function H(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 M(){if(m)return;if(b()!==void 0)return;let e=f();v(e),g()}function f(){let e=b(),n=w(e),t=n?!1:k(e),i=B(e,t);return{isBunRuntime:n,isCloudflareRuntime:t,isNodeRuntime:i,hasFileSystemAccess:!t&&(n||i),console:S()}}function w(e){if(e==="bun")return!0;if(e==="cloudflare"||e==="node")return!1;return typeof Bun<"u"}function k(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 B(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 S(){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,E=e.isNodeRuntime,m=e.hasFileSystemAccess,x=e.console}function g(){let e=_();for(let n of Object.keys(d))delete d[n];Object.assign(d,e)}function _(){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)}}function C(e){if(!e)return;return e.split(`
3
- `).map((n)=>n.trim()).find(Boolean)}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 T(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 z(e,n,t={}){let{message:i,hints:o,stack:r}=T(n),c=t.showStack??N();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,T as formatCliError,N as isDebugEnabled,z as printCliError};
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};