@mcp-com-ai/shared-utils 1.0.1-beta.260912

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.
@@ -0,0 +1,30 @@
1
+ type ConsoleLike = {
2
+ log: (...args: any[]) => void;
3
+ info: (...args: any[]) => void;
4
+ warn: (...args: any[]) => void;
5
+ error: (...args: any[]) => void;
6
+ debug: (...args: any[]) => void;
7
+ };
8
+ export declare let isBunRuntime: boolean;
9
+ export declare let isCloudflareRuntime: boolean;
10
+ export declare let isNodeRuntime: boolean;
11
+ export declare let hasFileSystemAccess: boolean;
12
+ export declare let runtimeConsole: ConsoleLike;
13
+ export declare const runtimeEnv: Record<string, unknown>;
14
+ export declare function getEnvVar(key: string, fallback?: string): string | undefined;
15
+ export declare function setEnvVar(key: string, value: string): void;
16
+ /**
17
+ * Cloudflare Worker entrypoints receive bindings only when handling a request.
18
+ * Explicitly selecting the runtime prevents Node-compatibility shims from
19
+ * being mistaken for a writable local filesystem.
20
+ */
21
+ export declare function initializeCloudflareRuntime(env: Record<string, unknown>): void;
22
+ /** Test-only counterpart for Worker integration tests running under Bun. */
23
+ export declare function resetRuntimeForTests(): void;
24
+ export declare function readTextFile(path: string): Promise<string>;
25
+ export declare function readJsonFile<T = unknown>(path: string): Promise<T>;
26
+ export declare function fileExists(path: string): Promise<boolean>;
27
+ export declare function getBunFile(path: string): any;
28
+ export declare function refreshRuntimeEnvironment(): void;
29
+ export declare function ensureRuntimeSynchronized(): void;
30
+ export {};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ var F=Object.create;var{getPrototypeOf:N,defineProperty:Y,getOwnPropertyNames:O}=Object;var W=Object.prototype.hasOwnProperty;function z(j){return this[j]}var A,V,b=(j,q,w)=>{var D=j!=null&&typeof j==="object";if(D){var G=q?A??=new WeakMap:V??=new WeakMap,I=G.get(j);if(I)return I}w=j!=null?F(N(j)):{};let J=q||!j||!j.__esModule?Y(w,"default",{value:j,enumerable:!0}):w;for(let K of O(j))if(!W.call(J,K))Y(J,K,{get:z.bind(j,K),enumerable:!0});if(D)G.set(j,J);return J};var C=(j,q)=>()=>(q||j((q={exports:{}}).exports,q),q.exports);var h=import.meta.require;var M={},P=Q(),L=P.isBunRuntime,Z=P.isCloudflareRuntime,B=P.isNodeRuntime,_=P.hasFileSystemAccess,S=P.console,$=M;X();function g(j,q){let w=typeof process<"u"?process.env:void 0,D=w?w[j]:void 0,G=L?Bun?.env?.[j]:void 0,I=$[j],J=typeof I==="string"?I:void 0,K=Z?J??D??G:D??G??J;return K===void 0||K===""?q:K}function p(j,q){if(typeof process<"u")process.env[j]=q;$[j]=q}function c(j){globalThis.__hapiRuntimeOverride="cloudflare",H(),Object.assign(M,j)}function s(){delete globalThis.__hapiRuntimeOverride,H()}async function v(j){if(!L)throw Error(`File system access not available in this runtime: ${j}`);return await Bun.file(j).text()}async function m(j){if(!L)throw Error(`File system access not available in this runtime: ${j}`);return await Bun.file(j).json()}async function d(j){return L?await Bun.file(j).exists():!1}function a(j){if(!L)throw Error(`File system access not available in this runtime: ${j}`);return Bun.file(j)}function H(){let j=Q();U(j),X()}function l(){if(_)return;if(T()!==void 0)return;let j=Q();U(j),X()}function Q(){let j=T(),q=E(j),w=q?!1:y(j),D=f(j,w);return{isBunRuntime:q,isCloudflareRuntime:w,isNodeRuntime:D,hasFileSystemAccess:!w&&(q||D),console:k()}}function E(j){if(j==="bun")return!0;if(j==="cloudflare"||j==="node")return!1;return typeof Bun<"u"}function y(j){if(j==="cloudflare")return!0;if(j==="bun"||j==="node")return!1;let q=typeof globalThis<"u"?globalThis:void 0,w=q?.navigator?.userAgent??"",D=typeof w==="string"&&w.includes("Cloudflare-Workers"),G=typeof q?.__ENVIRONMENT__==="string"&&q.__ENVIRONMENT__.toLowerCase()==="workerd",I=typeof q?.caches?.default<"u";return D||G||I}function f(j,q){if(j==="node")return!0;if(j==="bun"||j==="cloudflare")return!1;if(q)return!1;let w=typeof process<"u"?process.versions?.node:void 0;return typeof w==="string"&&w.length>0}function T(){return typeof globalThis<"u"?globalThis.__hapiRuntimeOverride:void 0}function k(){let j=()=>{},q=typeof console<"u"?console:void 0;if(!q)return{log:j,info:j,warn:j,error:j,debug:j};let w=(G,I)=>typeof G==="function"?G.bind(q):I,D=w(q.log,j);return{log:D,info:w(q.info,D),warn:w(q.warn,D),error:w(q.error,D),debug:w(q.debug,D)}}function U(j){L=j.isBunRuntime,Z=j.isCloudflareRuntime,B=j.isNodeRuntime,_=j.hasFileSystemAccess,S=j.console}function X(){let j=x();for(let q of Object.keys(M))delete M[q];Object.assign(M,j)}function x(){if(L)return{...typeof Bun<"u"?Bun.env:{},...typeof process<"u"?process.env:{}};return(typeof process<"u"?process:void 0)?.env??{}}export{p as setEnvVar,$ as runtimeEnv,S as runtimeConsole,s as resetRuntimeForTests,H as refreshRuntimeEnvironment,v as readTextFile,m as readJsonFile,B as isNodeRuntime,Z as isCloudflareRuntime,L as isBunRuntime,c as initializeCloudflareRuntime,_ as hasFileSystemAccess,g as getEnvVar,a as getBunFile,d as fileExists,l as ensureRuntimeSynchronized};
@@ -0,0 +1,3 @@
1
+ export declare function getSecret(service: string, name: string): Promise<string | null>;
2
+ export declare function setSecret(service: string, name: string, value: string): Promise<void>;
3
+ export declare function deleteSecret(service: string, name: string): Promise<void>;
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ var c=Object.create;var{getPrototypeOf:f,defineProperty:O,getOwnPropertyNames:F}=Object;var H=Object.prototype.hasOwnProperty;function N(s){return this[s]}var U,W,h=(s,P,w)=>{var A=s!=null&&typeof s==="object";if(A){var I=P?U??=new WeakMap:W??=new WeakMap,M=I.get(s);if(M)return M}w=s!=null?c(f(s)):{};let g=P||!s||!s.__esModule?O(w,"default",{value:s,enumerable:!0}):w;for(let K of F(s))if(!H.call(g,K))O(g,K,{get:N.bind(s,K),enumerable:!0});if(A)I.set(s,g);return g};var x=(s,P)=>()=>(P||s((P={exports:{}}).exports,P),P.exports);var p=import.meta.require;var j={},q=G(),$=q.isBunRuntime,Q=q.isCloudflareRuntime,y=q.isNodeRuntime,T=q.hasFileSystemAccess,S=q.console,X=j;J();function r(s,P){let w=typeof process<"u"?process.env:void 0,A=w?w[s]:void 0,I=$?Bun?.env?.[s]:void 0,M=X[s],g=typeof M==="string"?M:void 0,K=Q?g??A??I:A??I??g;return K===void 0||K===""?P:K}function R(s,P){if(typeof process<"u")process.env[s]=P;X[s]=P}function a(s){globalThis.__hapiRuntimeOverride="cloudflare",Y(),Object.assign(j,s)}function m(){delete globalThis.__hapiRuntimeOverride,Y()}async function d(s){if(!$)throw Error(`File system access not available in this runtime: ${s}`);return await Bun.file(s).text()}async function i(s){if(!$)throw Error(`File system access not available in this runtime: ${s}`);return await Bun.file(s).json()}async function v(s){return $?await Bun.file(s).exists():!1}function u(s){if(!$)throw Error(`File system access not available in this runtime: ${s}`);return Bun.file(s)}function Y(){let s=G();_(s),J()}function t(){if(T)return;if(Z()!==void 0)return;let s=G();_(s),J()}function G(){let s=Z(),P=z(s),w=P?!1:V(s),A=k(s,w);return{isBunRuntime:P,isCloudflareRuntime:w,isNodeRuntime:A,hasFileSystemAccess:!w&&(P||A),console:E()}}function z(s){if(s==="bun")return!0;if(s==="cloudflare"||s==="node")return!1;return typeof Bun<"u"}function V(s){if(s==="cloudflare")return!0;if(s==="bun"||s==="node")return!1;let P=typeof globalThis<"u"?globalThis:void 0,w=P?.navigator?.userAgent??"",A=typeof w==="string"&&w.includes("Cloudflare-Workers"),I=typeof P?.__ENVIRONMENT__==="string"&&P.__ENVIRONMENT__.toLowerCase()==="workerd",M=typeof P?.caches?.default<"u";return A||I||M}function k(s,P){if(s==="node")return!0;if(s==="bun"||s==="cloudflare")return!1;if(P)return!1;let w=typeof process<"u"?process.versions?.node:void 0;return typeof w==="string"&&w.length>0}function Z(){return typeof globalThis<"u"?globalThis.__hapiRuntimeOverride:void 0}function E(){let s=()=>{},P=typeof console<"u"?console:void 0;if(!P)return{log:s,info:s,warn:s,error:s,debug:s};let w=(I,M)=>typeof I==="function"?I.bind(P):M,A=w(P.log,s);return{log:A,info:w(P.info,A),warn:w(P.warn,A),error:w(P.error,A),debug:w(P.debug,A)}}function _(s){$=s.isBunRuntime,Q=s.isCloudflareRuntime,y=s.isNodeRuntime,T=s.hasFileSystemAccess,S=s.console}function J(){let s=b();for(let P of Object.keys(j))delete j[P];Object.assign(j,s)}function b(){if($)return{...typeof Bun<"u"?Bun.env:{},...typeof process<"u"?process.env:{}};return(typeof process<"u"?process:void 0)?.env??{}}var B=new Map;function L(){if(!$)return null;let s=globalThis.Bun?.secrets;if(!s||typeof s.get!=="function")return null;return s}var D=(s,P)=>`${s}::${P}`;async function o(s,P){let w=L();if(w)try{return await w.get({service:s,name:P})}catch{return B.get(D(s,P))??null}return B.get(D(s,P))??null}async function e(s,P,w){let A=L();if(A)try{await A.set({service:s,name:P,value:w});return}catch{}B.set(D(s,P),w)}async function ss(s,P){let w=L();if(w)try{await w.delete({service:s,name:P});return}catch{}B.delete(D(s,P))}export{e as setSecret,o as getSecret,ss as deleteSecret};
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@mcp-com-ai/shared-utils",
3
+ "version": "1.0.1-beta.260912",
4
+ "description": "Shared HAPI utilities: HAPI_HOME resolution, logger, config loader, errors, runtime detection, secrets. Consumed by the CLI, the core engine, and all first-party plugins.",
5
+ "license": "LRL-CL",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "hapi-build-source": "./src/index.ts",
14
+ "bun": "./dist/index.js",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./home": {
18
+ "types": "./dist/home.d.ts",
19
+ "hapi-build-source": "./src/home.ts",
20
+ "bun": "./dist/home.js",
21
+ "default": "./dist/home.js"
22
+ },
23
+ "./logger": {
24
+ "types": "./dist/logger.d.ts",
25
+ "hapi-build-source": "./src/logger.ts",
26
+ "bun": "./dist/logger.js",
27
+ "default": "./dist/logger.js"
28
+ },
29
+ "./config": {
30
+ "types": "./dist/config.d.ts",
31
+ "hapi-build-source": "./src/config.ts",
32
+ "bun": "./dist/config.js",
33
+ "default": "./dist/config.js"
34
+ },
35
+ "./errors": {
36
+ "types": "./dist/errors.d.ts",
37
+ "hapi-build-source": "./src/errors.ts",
38
+ "bun": "./dist/errors.js",
39
+ "default": "./dist/errors.js"
40
+ },
41
+ "./runtime": {
42
+ "types": "./dist/runtime.d.ts",
43
+ "hapi-build-source": "./src/runtime.ts",
44
+ "bun": "./dist/runtime.js",
45
+ "default": "./dist/runtime.js"
46
+ },
47
+ "./secrets": {
48
+ "types": "./dist/secrets.d.ts",
49
+ "hapi-build-source": "./src/secrets.ts",
50
+ "bun": "./dist/secrets.js",
51
+ "default": "./dist/secrets.js"
52
+ }
53
+ },
54
+ "files": ["dist", "README.md"],
55
+ "scripts": {
56
+ "typecheck": "bunx tsc --noEmit",
57
+ "test": "bun test",
58
+ "build": "bun ../../scripts/build-package.ts ."
59
+ },
60
+ "peerDependencies": {
61
+ "typescript": "^5"
62
+ },
63
+ "dependencies": {
64
+ "winston": "^3.19.0",
65
+ "winston-daily-rotate-file": "^5.0.0",
66
+ "yaml": "^2.8.2"
67
+ },
68
+ "engines": {
69
+ "bun": ">=1.3.0"
70
+ },
71
+ "publishConfig": {
72
+ "access": "public"
73
+ }
74
+ }