@zibby/core 0.5.47 → 0.5.49
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/dist/backend-client.js +1 -1
- package/dist/index.js +152 -152
- package/dist/package.json +1 -1
- package/dist/register-built-in-strategies.js +36 -36
- package/dist/strategies/claude-strategy.js +5 -5
- package/dist/strategies/codex-strategy.js +7 -7
- package/dist/strategies/cursor-strategy.js +24 -24
- package/dist/strategies/gemini-strategy.js +18 -18
- package/dist/strategies/index.js +66 -66
- package/dist/strategies/mcp-server-config.js +1 -1
- package/dist/utils/secure-git.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function e(n){return!!n&&(n.transport==="http"||typeof n.url=="string"&&!n.command)}var f=new Set(["claude"]);function p(){let n=String(process.env.MCP_ALWAYS_LOAD??"").trim().toLowerCase();return!(n==="0"||n==="false"||n==="off")}function o(n,t){return f.has(n)?p()?typeof t.alwaysLoad=="boolean"?{alwaysLoad:t.alwaysLoad}:{}:{}:{}}function h(n,t,{processEnv:i}={}){if(!t)return null;let u=o(n,t);if(e(t)){let r=String(t.url||"").trim();if(!r)return null;let a=t.headers&&typeof t.headers=="object"?t.headers:void 0;switch(n){case"claude":return{type:"http",url:r,...a&&{headers:a},...u};case"codex":return{url:r,...a&&{http_headers:a}};case"gemini":return{url:r,type:"http",...a&&{headers:a}};case"cursor":return{url:r,...a&&{headers:a}};default:return{type:"http",url:r,...a&&{headers:a},...u}}}let c={command:t.command};return t.args?.length&&(c.args=t.args),t.cwd&&(c.cwd=t.cwd),i?c.env={...i,...t.env||{}}:t.env&&Object.keys(t.env).length&&(c.env=t.env),{...c,...u}}function m(n){return e(n)?`http \u2192 ${String(n.url||"").replace(/\?.*$/,"")}`:`${n?.command||"?"} ${(n?.args||[]).join(" ")}`.trim()}export{e as isRemoteMcp,m as mcpLogLabel,h as mcpServerConfigFor};
|
package/dist/utils/secure-git.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as T,readFileSync as _}from"node:fs";import{homedir as y}from"node:os";import{join as I}from"node:path";var b=new Map,x={github:"GITHUB_TOKEN",gitlab:"GITLAB_TOKEN",sentry:"SENTRY_AUTH_TOKEN",slack:"SLACK_BOT_TOKEN"};function k(){let t=process.env.ZIBBY_SELF_HOST;return t!=null&&t!==""&&t!=="0"&&t.toLowerCase()!=="false"}function $(){if(process.env.PROJECT_API_TOKEN)return process.env.PROJECT_API_TOKEN;if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let t=I(y(),".zibby","config.json");return T(t)&&JSON.parse(_(t,"utf-8")).sessionToken||null}catch{return null}}function O(){return process.env.ZIBBY_ACCOUNT_API_URL?process.env.ZIBBY_ACCOUNT_API_URL.replace(/\/$/,""):(process.env.ZIBBY_ENV||"prod")==="local"?"http://localhost:3001":process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://api-prod.zibby.app"}async function w(t){if(k()){let i=x[t];if(i&&process.env[i])return{token:process.env[i]}}let e=Date.now(),n=b.get(t);if(n&&n.expiresAt>e)return n.data;let r=$();if(!r)throw new Error("Missing session credential: neither PROJECT_API_TOKEN nor ZIBBY_USER_TOKEN is set in this process env (and no ~/.zibby/config.json session). If this is an MCP skill child, the spawning skill must forward them \u2014 check the skill's envKeys / resolve() env (see @zibby/skills backend-session-env-contract). Interactive CLI: run `zibby login`.");let a=`${O()}/integrations/token/${t}`,s=await fetch(a,{method:"GET",headers:{Authorization:`Bearer ${r}`}});if(!s.ok){let i=await s.text().catch(()=>"");if(s.status===404){let u="";try{u=String(JSON.parse(i)?.error||"").trim()}catch{}throw new Error(u||`${t} is not connected. Connect it at https://studio.zibby.dev/integrations`)}throw s.status===401||s.status===403?new Error("Session expired. Run `zibby login` to re-authenticate."):new Error(`Failed to resolve ${t} token (${s.status}): ${i}`)}let o=await s.json();if(!o||typeof o!="object")throw new Error(`Invalid response from ${t} token endpoint: expected object, got ${typeof o}`);if(t==="jira"){if(!o.token||typeof o.token!="string")throw new Error(`Invalid jira token response: token is ${typeof o.token}, expected string`);if(!o.cloudId)throw new Error("Invalid jira token response: missing cloudId")}else if(t==="github"&&(!o.token||typeof o.token!="string"))throw new Error(`Invalid github token response: token is ${typeof o.token}, expected string`);let l=((o.expiresInSec||3e3)-120)*1e3;return b.set(t,{data:o,expiresAt:e+l}),o}var K=Object.freeze(["github.com","gitlab.com"]);function m(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function d(t){if(typeof t!="string"||t===""||/[\\\x00-\x20\x7f]/.test(t))return"";let e;try{e=new URL(t)}catch{return""}return e.protocol!=="https:"?"":e.hostname.toLowerCase()}function v(t=process.env){let e=t&&(t.GITLAB_URL||t.GITLAB_INSTANCE_URL)||"";return m(e)}function h(t={}){if(t.gitlabHost){let e=String(t.gitlabHost).trim().toLowerCase();return e?e.includes("://")?m(e):e.replace(/:\d+$/,""):""}return v()}function S(t,e={}){let n=d(t);if(!n)return!1;if(n==="github.com"||n==="gitlab.com")return!0;let r=h(e);return!!(r&&n===r)}function A(t,e={}){if(t==="github.com")return"github";if(t==="gitlab.com")return"gitlab";let n=h(e);return n&&t===n?"gitlab":null}function C(t,e,n={}){if(!t||!e)return t;let r=d(t);if(!r)return t;if(r==="github.com")return t.replace(/^https:\/\/(?:[^@/]+@)?github\.com(?=[:/]|$)/i,`https://x-access-token:${e}@github.com`);if(r==="gitlab.com")return t.replace(/^https:\/\/(?:[^@/]+@)?gitlab\.com(?=[:/]|$)/i,`https://oauth2:${e}@gitlab.com`);let a=h(n);if(a&&r===a){let s=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(`^https:\\/\\/(?:[^@/]+@)?${s}(?=[:/]|$)`,"i");return t.replace(o,`https://oauth2:${e}@${a}`)}return t}function B(t){return t&&String(t).replace(/^(https:\/\/)[^@/]+@/i,"$1")}function N(t,e){let n=t==null?"":String(t);return e&&(n=n.split(e).join("***")),n=n.replace(/(https?:\/\/)(?:x-access-token|oauth2):[^@\s/]+@/gi,"$1"),n=n.replace(/(https?:\/\/)[^@\s/:]+:[^@\s/]+@/gi,"$1"),n}async function P(t,e,n){try{await t("git",["remote","set-url","origin",B(n)],e)}catch(r){console.warn(`\u26A0\uFE0F could not scrub token from origin remote (continuing): ${r?.message||r}`)}}async function z({run:t,repoPath:e,repoUrl:n,branch:r,token:a,resolveToken:s=w,gitlabHost:o}={}){if(typeof t!="function")throw new Error("securePush: `run` (a spawn wrapper resolving {code,stdout,stderr}) is required");if(!r)throw new Error("securePush: `branch` is required");let l=h({gitlabHost:o}),i=d(n),u=S(n,{gitlabHost:l}),f=a||"";if(!f&&u&&typeof s=="function"){let p=A(i,{gitlabHost:l});if(p)try{f=(await s(p))?.token||""}catch{}}else!f&&!u&&console.warn(`\u26A0\uFE0F push target host '${i||"(unparseable)"}' is not a trusted VCS host \u2014 refusing to mint a token`);let g=f&&u,E=g?C(n,f,{gitlabHost:l}):"origin",c=await t("git",["push",E,r],e);if(!c||c.code!==0){let p=N(c&&c.stderr||"",f);throw new Error(`git push failed (exit ${c?c.code:"?"}): ${String(p).slice(-500)}`)}return{code:c.code,stdout:c.stdout,stderr:c.stderr,pushedAuthed:!!g,target:g?"<authed>":"origin"}}export{K as TRUSTED_VCS_HOSTS,C as authedUrl,m as hostnameOf,S as isTrustedVcsHost,A as providerForHost,N as redactGitSecrets,d as safeVcsHostname,P as scrubRemoteToTokenless,z as securePush,v as selfHostGitlabHost,B as tokenlessUrl};
|