@zibby/core 0.5.46 → 0.5.48

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.
@@ -1 +1 @@
1
- import{existsSync as E,readFileSync as w}from"node:fs";import{homedir as I}from"node:os";import{join as T}from"node:path";var f=new Map,u={github:"GITHUB_TOKEN",gitlab:"GITLAB_TOKEN",sentry:"SENTRY_AUTH_TOKEN",slack:"SLACK_BOT_TOKEN"};function d(){let e=process.env.ZIBBY_SELF_HOST;return e!=null&&e!==""&&e!=="0"&&e.toLowerCase()!=="false"}function h(){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 e=T(I(),".zibby","config.json");return E(e)&&JSON.parse(w(e,"utf-8")).sessionToken||null}catch{return null}}function _(){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 g(e){if(d()){let l=u[e];if(l&&process.env[l])return{token:process.env[l]}}let i=Date.now(),o=f.get(e);if(o&&o.expiresAt>i)return o.data;let s=h();if(!s)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 r=`${_()}/integrations/token/${e}`,n=await fetch(r,{method:"GET",headers:{Authorization:`Bearer ${s}`}});if(!n.ok){let l=await n.text().catch(()=>"");throw n.status===404?new Error(`${e} is not connected. Connect it at https://studio.zibby.dev/integrations`):n.status===401||n.status===403?new Error("Session expired. Run `zibby login` to re-authenticate."):new Error(`Failed to resolve ${e} token (${n.status}): ${l}`)}let t=await n.json();if(!t||typeof t!="object")throw new Error(`Invalid response from ${e} token endpoint: expected object, got ${typeof t}`);if(e==="jira"){if(!t.token||typeof t.token!="string")throw new Error(`Invalid jira token response: token is ${typeof t.token}, expected string`);if(!t.cloudId)throw new Error("Invalid jira token response: missing cloudId")}else if(e==="github"&&(!t.token||typeof t.token!="string"))throw new Error(`Invalid github token response: token is ${typeof t.token}, expected string`);let c=((t.expiresInSec||3e3)-120)*1e3;return f.set(e,{data:t,expiresAt:i+c}),t}function O(e){e?f.delete(e):f.clear()}var a=null;function p(e){let i=process.env.WORKFLOW_ENABLED_INTEGRATIONS;if(typeof i!="string"||i.trim()==="")return e;let o=new Set(i.split(",").map(r=>r.trim()).filter(Boolean));if(o.size===0)return e;let s={};for(let[r,n]of Object.entries(e))o.has(r)&&(s[r]=n);return s}async function v(){let e=Date.now();if(a&&a.expiresAt>e)return a.data;if(d()){let o={};for(let[r,n]of Object.entries(u))o[r]=!!process.env[n];let s=p(o);return a={data:s,expiresAt:e+6e4},s}let i=h();if(!i)return{};try{let o=await fetch(`${_()}/integrations/status`,{method:"GET",headers:{Authorization:`Bearer ${i}`}});if(!o.ok)return{};let s=await o.json(),r={};if(s&&typeof s=="object")for(let[t,c]of Object.entries(s))c&&typeof c=="object"&&"connected"in c&&(r[t]=!!c.connected);let n=p(r);return a={data:n,expiresAt:e+6e4},n}catch{return{}}}function A(){a=null}export{A as clearConnectedCache,O as clearTokenCache,v as getConnectedIntegrations,g as resolveIntegrationToken};
1
+ import{existsSync as w,readFileSync as I}from"node:fs";import{homedir as T}from"node:os";import{join as b}from"node:path";var f=new Map,d={github:"GITHUB_TOKEN",gitlab:"GITLAB_TOKEN",sentry:"SENTRY_AUTH_TOKEN",slack:"SLACK_BOT_TOKEN"};function h(){let e=process.env.ZIBBY_SELF_HOST;return e!=null&&e!==""&&e!=="0"&&e.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 e=b(T(),".zibby","config.json");return w(e)&&JSON.parse(I(e,"utf-8")).sessionToken||null}catch{return null}}function E(){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 O(e){if(h()){let a=d[e];if(a&&process.env[a])return{token:process.env[a]}}let i=Date.now(),o=f.get(e);if(o&&o.expiresAt>i)return o.data;let s=_();if(!s)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 r=`${E()}/integrations/token/${e}`,n=await fetch(r,{method:"GET",headers:{Authorization:`Bearer ${s}`}});if(!n.ok){let a=await n.text().catch(()=>"");if(n.status===404){let p="";try{p=String(JSON.parse(a)?.error||"").trim()}catch{}throw new Error(p||`${e} is not connected. Connect it at https://studio.zibby.dev/integrations`)}throw n.status===401||n.status===403?new Error("Session expired. Run `zibby login` to re-authenticate."):new Error(`Failed to resolve ${e} token (${n.status}): ${a}`)}let t=await n.json();if(!t||typeof t!="object")throw new Error(`Invalid response from ${e} token endpoint: expected object, got ${typeof t}`);if(e==="jira"){if(!t.token||typeof t.token!="string")throw new Error(`Invalid jira token response: token is ${typeof t.token}, expected string`);if(!t.cloudId)throw new Error("Invalid jira token response: missing cloudId")}else if(e==="github"&&(!t.token||typeof t.token!="string"))throw new Error(`Invalid github token response: token is ${typeof t.token}, expected string`);let c=((t.expiresInSec||3e3)-120)*1e3;return f.set(e,{data:t,expiresAt:i+c}),t}function v(e){e?f.delete(e):f.clear()}var l=null;function u(e){let i=process.env.WORKFLOW_ENABLED_INTEGRATIONS;if(typeof i!="string"||i.trim()==="")return e;let o=new Set(i.split(",").map(r=>r.trim()).filter(Boolean));if(o.size===0)return e;let s={};for(let[r,n]of Object.entries(e))o.has(r)&&(s[r]=n);return s}async function A(){let e=Date.now();if(l&&l.expiresAt>e)return l.data;if(h()){let o={};for(let[r,n]of Object.entries(d))o[r]=!!process.env[n];let s=u(o);return l={data:s,expiresAt:e+6e4},s}let i=_();if(!i)return{};try{let o=await fetch(`${E()}/integrations/status`,{method:"GET",headers:{Authorization:`Bearer ${i}`}});if(!o.ok)return{};let s=await o.json(),r={};if(s&&typeof s=="object")for(let[t,c]of Object.entries(s))c&&typeof c=="object"&&"connected"in c&&(r[t]=!!c.connected);let n=u(r);return l={data:n,expiresAt:e+6e4},n}catch{return{}}}function B(){l=null}export{B as clearConnectedCache,v as clearTokenCache,A as getConnectedIntegrations,O as resolveIntegrationToken};