jaz-clio 5.6.8 → 5.6.10
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/assets/skills/api/SKILL.md +1 -5
- package/assets/skills/cli/SKILL.md +1 -1
- package/assets/skills/conversion/SKILL.md +1 -1
- package/assets/skills/jaz-pseudo-sql/SKILL.md +1 -1
- package/assets/skills/jobs/SKILL.md +1 -1
- package/assets/skills/practice/SKILL.md +1 -1
- package/assets/skills/transaction-recipes/SKILL.md +1 -1
- package/cli.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: jaz-api
|
|
3
|
-
version: 5.6.
|
|
3
|
+
version: 5.6.10
|
|
4
4
|
description: >-
|
|
5
5
|
Use this skill whenever you call, debug, or review code that touches the Jaz
|
|
6
6
|
REST API. Covers field names, response shapes, 141 production gotchas, error
|
|
@@ -489,10 +489,6 @@ Bills, invoices, and credit notes share identical mandatory field specs. Adding
|
|
|
489
489
|
|
|
490
490
|
157. **Recipe input `*AccountResourceId` fields are account-class-locked — `x-accountClass` in inputSchema is authoritative.** Each `*AccountResourceId` slot on a recipe's input schema carries an `x-accountClass` constraint (`"Asset"`, `"Liability"`, `"Expense"`, `"Revenue"`, `"Equity"`). Passing an account whose class doesn't match the slot's `x-accountClass` is rejected post-commit and silently nulls `capsuleRecipeJob` (Rule 143). Schema location: `get_capsule_recipe(name).data.versions[0].inputSchema.properties.<fieldName>['x-accountClass']` — **note `versions[0].inputSchema`, NOT `inputSchema` at the top level**. Examples: PREPAID_AMORTIZATION needs `prepaidAssetAccountResourceId: Asset` + `expenseAccountResourceId: Expense`; DEFERRED_REVENUE needs `deferredRevenueAccountResourceId: Liability` + `revenueAccountResourceId: Revenue`; ACCRUAL_REVERSAL needs `expenseAccountResourceId: Expense` + `accruedLiabilityAccountResourceId: Liability`. Always pre-validate via `get_account(resourceId).accountClass` against the slot constraint, or just call `preview_capsule_recipe(recipeName, inputs)` to surface every class violation as a clean 422.
|
|
491
491
|
|
|
492
|
-
### Error Recovery
|
|
493
|
-
|
|
494
|
-
158. **Tool error envelopes may carry a structured `repair` suggestion (W1.3).** When a `create_*` / `update_*` / `get_*` tool fails with a high-confidence pattern (404 not found, 422 missing FK, duplicate reference, tax-profile direction mismatch), the response is enriched with `repair: { tool, arguments, reason }`. The `tool` field is ALWAYS read-only AND verified to exist in the registry. Consumption pattern: if `repair` is present, call `execute_tool(repair.tool, repair.arguments)` directly to recover; do NOT retry the original write tool until the repair surfaces the correct resourceId/reference. Full envelope shape, pattern list, and worked example in `references/errors.md` (Repair Suggestions section). Purely additive — no match → no `repair`, fall back to free-text `hint`. Infinite-loop protection comes from the agent-loop repetition guard (same tool+input retried 3× is blocked).
|
|
495
|
-
|
|
496
492
|
## Supporting Files
|
|
497
493
|
|
|
498
494
|
For detailed reference, read these files in this skill directory:
|
package/cli.mjs
CHANGED
|
@@ -193,7 +193,7 @@ ${c}${s}
|
|
|
193
193
|
${a}`:""}`}default:{let s=t?`${w("cyan",Z)} `:"",a=t?w("cyan",fr):"";return`${r}${s}${o}
|
|
194
194
|
${a}
|
|
195
195
|
`}}}}).prompt()});var SM,_M,Zne,Kne,Xne,Qne,eoe,ko,n1e,EM=$(()=>{ZC();SM={circleQuestionMark:"(?)",questionMarkPrefix:"(?)",square:"\u2588",squareDarkShade:"\u2593",squareMediumShade:"\u2592",squareLightShade:"\u2591",squareTop:"\u2580",squareBottom:"\u2584",squareLeft:"\u258C",squareRight:"\u2590",squareCenter:"\u25A0",bullet:"\u25CF",dot:"\u2024",ellipsis:"\u2026",pointerSmall:"\u203A",triangleUp:"\u25B2",triangleUpSmall:"\u25B4",triangleDown:"\u25BC",triangleDownSmall:"\u25BE",triangleLeftSmall:"\u25C2",triangleRightSmall:"\u25B8",home:"\u2302",heart:"\u2665",musicNote:"\u266A",musicNoteBeamed:"\u266B",arrowUp:"\u2191",arrowDown:"\u2193",arrowLeft:"\u2190",arrowRight:"\u2192",arrowLeftRight:"\u2194",arrowUpDown:"\u2195",almostEqual:"\u2248",notEqual:"\u2260",lessOrEqual:"\u2264",greaterOrEqual:"\u2265",identical:"\u2261",infinity:"\u221E",subscriptZero:"\u2080",subscriptOne:"\u2081",subscriptTwo:"\u2082",subscriptThree:"\u2083",subscriptFour:"\u2084",subscriptFive:"\u2085",subscriptSix:"\u2086",subscriptSeven:"\u2087",subscriptEight:"\u2088",subscriptNine:"\u2089",oneHalf:"\xBD",oneThird:"\u2153",oneQuarter:"\xBC",oneFifth:"\u2155",oneSixth:"\u2159",oneEighth:"\u215B",twoThirds:"\u2154",twoFifths:"\u2156",threeQuarters:"\xBE",threeFifths:"\u2157",threeEighths:"\u215C",fourFifths:"\u2158",fiveSixths:"\u215A",fiveEighths:"\u215D",sevenEighths:"\u215E",line:"\u2500",lineBold:"\u2501",lineDouble:"\u2550",lineDashed0:"\u2504",lineDashed1:"\u2505",lineDashed2:"\u2508",lineDashed3:"\u2509",lineDashed4:"\u254C",lineDashed5:"\u254D",lineDashed6:"\u2574",lineDashed7:"\u2576",lineDashed8:"\u2578",lineDashed9:"\u257A",lineDashed10:"\u257C",lineDashed11:"\u257E",lineDashed12:"\u2212",lineDashed13:"\u2013",lineDashed14:"\u2010",lineDashed15:"\u2043",lineVertical:"\u2502",lineVerticalBold:"\u2503",lineVerticalDouble:"\u2551",lineVerticalDashed0:"\u2506",lineVerticalDashed1:"\u2507",lineVerticalDashed2:"\u250A",lineVerticalDashed3:"\u250B",lineVerticalDashed4:"\u254E",lineVerticalDashed5:"\u254F",lineVerticalDashed6:"\u2575",lineVerticalDashed7:"\u2577",lineVerticalDashed8:"\u2579",lineVerticalDashed9:"\u257B",lineVerticalDashed10:"\u257D",lineVerticalDashed11:"\u257F",lineDownLeft:"\u2510",lineDownLeftArc:"\u256E",lineDownBoldLeftBold:"\u2513",lineDownBoldLeft:"\u2512",lineDownLeftBold:"\u2511",lineDownDoubleLeftDouble:"\u2557",lineDownDoubleLeft:"\u2556",lineDownLeftDouble:"\u2555",lineDownRight:"\u250C",lineDownRightArc:"\u256D",lineDownBoldRightBold:"\u250F",lineDownBoldRight:"\u250E",lineDownRightBold:"\u250D",lineDownDoubleRightDouble:"\u2554",lineDownDoubleRight:"\u2553",lineDownRightDouble:"\u2552",lineUpLeft:"\u2518",lineUpLeftArc:"\u256F",lineUpBoldLeftBold:"\u251B",lineUpBoldLeft:"\u251A",lineUpLeftBold:"\u2519",lineUpDoubleLeftDouble:"\u255D",lineUpDoubleLeft:"\u255C",lineUpLeftDouble:"\u255B",lineUpRight:"\u2514",lineUpRightArc:"\u2570",lineUpBoldRightBold:"\u2517",lineUpBoldRight:"\u2516",lineUpRightBold:"\u2515",lineUpDoubleRightDouble:"\u255A",lineUpDoubleRight:"\u2559",lineUpRightDouble:"\u2558",lineUpDownLeft:"\u2524",lineUpBoldDownBoldLeftBold:"\u252B",lineUpBoldDownBoldLeft:"\u2528",lineUpDownLeftBold:"\u2525",lineUpBoldDownLeftBold:"\u2529",lineUpDownBoldLeftBold:"\u252A",lineUpDownBoldLeft:"\u2527",lineUpBoldDownLeft:"\u2526",lineUpDoubleDownDoubleLeftDouble:"\u2563",lineUpDoubleDownDoubleLeft:"\u2562",lineUpDownLeftDouble:"\u2561",lineUpDownRight:"\u251C",lineUpBoldDownBoldRightBold:"\u2523",lineUpBoldDownBoldRight:"\u2520",lineUpDownRightBold:"\u251D",lineUpBoldDownRightBold:"\u2521",lineUpDownBoldRightBold:"\u2522",lineUpDownBoldRight:"\u251F",lineUpBoldDownRight:"\u251E",lineUpDoubleDownDoubleRightDouble:"\u2560",lineUpDoubleDownDoubleRight:"\u255F",lineUpDownRightDouble:"\u255E",lineDownLeftRight:"\u252C",lineDownBoldLeftBoldRightBold:"\u2533",lineDownLeftBoldRightBold:"\u252F",lineDownBoldLeftRight:"\u2530",lineDownBoldLeftBoldRight:"\u2531",lineDownBoldLeftRightBold:"\u2532",lineDownLeftRightBold:"\u252E",lineDownLeftBoldRight:"\u252D",lineDownDoubleLeftDoubleRightDouble:"\u2566",lineDownDoubleLeftRight:"\u2565",lineDownLeftDoubleRightDouble:"\u2564",lineUpLeftRight:"\u2534",lineUpBoldLeftBoldRightBold:"\u253B",lineUpLeftBoldRightBold:"\u2537",lineUpBoldLeftRight:"\u2538",lineUpBoldLeftBoldRight:"\u2539",lineUpBoldLeftRightBold:"\u253A",lineUpLeftRightBold:"\u2536",lineUpLeftBoldRight:"\u2535",lineUpDoubleLeftDoubleRightDouble:"\u2569",lineUpDoubleLeftRight:"\u2568",lineUpLeftDoubleRightDouble:"\u2567",lineUpDownLeftRight:"\u253C",lineUpBoldDownBoldLeftBoldRightBold:"\u254B",lineUpDownBoldLeftBoldRightBold:"\u2548",lineUpBoldDownLeftBoldRightBold:"\u2547",lineUpBoldDownBoldLeftRightBold:"\u254A",lineUpBoldDownBoldLeftBoldRight:"\u2549",lineUpBoldDownLeftRight:"\u2540",lineUpDownBoldLeftRight:"\u2541",lineUpDownLeftBoldRight:"\u253D",lineUpDownLeftRightBold:"\u253E",lineUpBoldDownBoldLeftRight:"\u2542",lineUpDownLeftBoldRightBold:"\u253F",lineUpBoldDownLeftBoldRight:"\u2543",lineUpBoldDownLeftRightBold:"\u2544",lineUpDownBoldLeftBoldRight:"\u2545",lineUpDownBoldLeftRightBold:"\u2546",lineUpDoubleDownDoubleLeftDoubleRightDouble:"\u256C",lineUpDoubleDownDoubleLeftRight:"\u256B",lineUpDownLeftDoubleRightDouble:"\u256A",lineCross:"\u2573",lineBackslash:"\u2572",lineSlash:"\u2571"},_M={tick:"\u2714",info:"\u2139",warning:"\u26A0",cross:"\u2718",squareSmall:"\u25FB",squareSmallFilled:"\u25FC",circle:"\u25EF",circleFilled:"\u25C9",circleDotted:"\u25CC",circleDouble:"\u25CE",circleCircle:"\u24DE",circleCross:"\u24E7",circlePipe:"\u24BE",radioOn:"\u25C9",radioOff:"\u25EF",checkboxOn:"\u2612",checkboxOff:"\u2610",checkboxCircleOn:"\u24E7",checkboxCircleOff:"\u24BE",pointer:"\u276F",triangleUpOutline:"\u25B3",triangleLeft:"\u25C0",triangleRight:"\u25B6",lozenge:"\u25C6",lozengeOutline:"\u25C7",hamburger:"\u2630",smiley:"\u32E1",mustache:"\u0DF4",star:"\u2605",play:"\u25B6",nodejs:"\u2B22",oneSeventh:"\u2150",oneNinth:"\u2151",oneTenth:"\u2152"},Zne={tick:"\u221A",info:"i",warning:"\u203C",cross:"\xD7",squareSmall:"\u25A1",squareSmallFilled:"\u25A0",circle:"( )",circleFilled:"(*)",circleDotted:"( )",circleDouble:"( )",circleCircle:"(\u25CB)",circleCross:"(\xD7)",circlePipe:"(\u2502)",radioOn:"(*)",radioOff:"( )",checkboxOn:"[\xD7]",checkboxOff:"[ ]",checkboxCircleOn:"(\xD7)",checkboxCircleOff:"( )",pointer:">",triangleUpOutline:"\u2206",triangleLeft:"\u25C4",triangleRight:"\u25BA",lozenge:"\u2666",lozengeOutline:"\u25CA",hamburger:"\u2261",smiley:"\u263A",mustache:"\u250C\u2500\u2510",star:"\u2736",play:"\u25BA",nodejs:"\u2666",oneSeventh:"1/7",oneNinth:"1/9",oneTenth:"1/10"},Kne={...SM,..._M},Xne={...SM,...Zne},Qne=Cd(),eoe=Qne?Kne:Xne,ko=eoe,n1e=Object.entries(_M)});var jx={};ei(jx,{COL_GAP:()=>kd,INDENT:()=>Se,accent:()=>z,box:()=>Et,danger:()=>k,highlight:()=>S,info:()=>co,isCI:()=>IM,isTTY:()=>yy,muted:()=>C,shouldAnimate:()=>Lx,subtle:()=>En,success:()=>T,sym:()=>sn,underline:()=>Px,warning:()=>X});function yy(){return!!process.stdout.isTTY}function IM(){return!!process.env.CI}function Lx(){return yy()&&!IM()&&!process.env.NO_COLOR}var z,C,T,X,k,co,S,En,Px,sn,Et,Se,kd,Q=$(()=>{"use strict";$c();EM();z=Le.hex("#6699ff"),C=Le.dim,T=Le.hex("#14b856"),X=Le.hex("#ff9466"),k=Le.hex("#f87777"),co=Le.cyan,S=Le.bold,En=Le.gray,Px=Le.underline,sn={tick:ko.tick,cross:ko.cross,warning:ko.warning,info:ko.info,pointer:ko.pointer,bullet:ko.bullet,arrowRight:ko.arrowRight,ellipsis:ko.ellipsis,line:ko.line,pointerSmall:ko.pointerSmall},Et={topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502",leftT:"\u251C",rightT:"\u2524"},Se=" ",kd=2});var eu,Bx=$(()=>{"use strict";eu="pat_"});import{readFileSync as soe,writeFileSync as aoe,renameSync as coe,mkdirSync as uoe,unlinkSync as loe,existsSync as doe,openSync as poe,fsyncSync as foe,closeSync as moe}from"fs";import{join as RM}from"path";import{homedir as hoe}from"os";function ui(){try{let e=soe(Fd,"utf-8"),t=JSON.parse(e);if(t.version===2)return t;if(t.apiKey){let r={version:2,active:"default",orgs:{default:{apiKey:t.apiKey,orgName:"Unknown (migrated)",orgId:"",currency:"",country:"",addedAt:t.createdAt??new Date().toISOString()}}};try{Pd(r)}catch{}return r}return null}catch{return null}}function Pd(e){uoe(NM,{recursive:!0});let t=Fd+".tmp";aoe(t,JSON.stringify(e,null,2)+`
|
|
196
|
-
`,{mode:384});let r=poe(t,"r");try{foe(r)}finally{moe(r)}coe(t,Fd)}function uo(e){return ui()?.orgs[e]??null}function Ld(e,t){let r=ui()??{version:2,active:"",orgs:{}};r.orgs[e]=t,(!r.active||Object.keys(r.orgs).length===1)&&(r.active=e),Pd(r)}function Ux(e){let t=ui();return!t||!(e in t.orgs)?!1:(delete t.orgs[e],t.active===e&&(t.active=""),Pd(t),!0)}function In(){return ui()?.active||null}function qx(e){let t=ui();if(!t)throw new Error("No credentials file found. Run `clio auth add <key>` first.");if(!(e in t.orgs)){let r=Object.keys(t.orgs).join(", ");throw new Error(`Org '${e}' not found. Available: ${r}`)}t.active=e,Pd(t)}function Fo(){return ui()?.orgs??{}}function zx(e){let t=ui();if(!t)return null;for(let[r,n]of Object.entries(t.orgs))if(n.apiKey===e)return r;return null}function Yx(){return doe(Fd)?(loe(Fd),!0):!1}var NM,Fd,jd=$(()=>{"use strict";NM=RM(hoe(),".config","jaz-clio"),Fd=RM(NM,"credentials.json")});function Jx(e){Md=e}function Ud(){return by}function qd(){return Un}function Dy(e){let t=process.env[e];if(t===void 0)return;let r=t.trim();if(r!==""&&!r.includes("${"))return r}function Bd(e){let t=e.split(",").map(s=>s.trim()).filter(Boolean);if(t.length===0)throw new cn("Empty key value. Provide a Jaz API key (jk-...) or personal access token (pat_...).");let r=t.filter(s=>s.startsWith(eu)),n=t.filter(s=>s.startsWith("jk-"));if(t.filter(s=>!s.startsWith(eu)&&!s.startsWith("jk-")).length>0)throw new cn("Invalid key format (unrecognized prefix). Expected jk-... (API key) or pat_... (personal access token).");if(r.length>0&&n.length>0)throw new cn("Cannot mix PAT and API keys. Use either a single personal access token (pat_...) or one or more API keys (jk-...).");if(r.length>0&&t.length!==1)throw new cn("Only one personal access token allowed. Do not combine with other keys.");return r.length===1?[{mode:"pat",token:r[0]}]:[...new Set(n)].map(s=>({mode:"direct",apiKey:s}))}function vy(e){if(by=null,Un=null,e)return Un="flag-api-key",Bd(e)[0];let t=Dy("JAZ_API_KEY");if(t)return Un="env-api-key",Bd(t)[0];if(Md)return Un="flag-org",tu(Md);let r=Dy("JAZ_ORG");if(r)return Un="env-org",tu(r);let n=In();return n?(Un="active-file",tu(n)):null}function tu(e){let t=uo(e);if(!t){let r=ui(),n=r?Object.keys(r.orgs):[],o=n.length>0?` Available: ${n.join(", ")}`:" No orgs registered. Run `clio auth add <key>` first.";throw new cn(`Org '${e}' not found.${o}`)}return by=e,{mode:"direct",apiKey:t.apiKey}}function Gx(e){if(by=null,Un=null,e)return Un="flag-api-key",Bd(e);let t=Dy("JAZ_API_KEY");if(t)return Un="env-api-key",Bd(t);if(Md)return Un="flag-org",[tu(Md)];let r=Dy("JAZ_ORG");if(r)return Un="env-org",[tu(r)];let n=In();return n?(Un="active-file",[tu(n)]):[]}function Ta(e){let t=vy(e);if(!t)throw new cn("No API key configured. Run `clio auth add <key>`, set JAZ_API_KEY, or pass --api-key.");return t}var Md,by,Un,cn,Vx=$(()=>{"use strict";Bx();jd();by=null;Un=null;cn=class extends Error{constructor(t){super(t),this.name="AuthError"}}});function Hx(e){return e.replace(/\/[a-f0-9-]{8,}(?=[/?#]|$)/gi,"/{id}")}function $M(e){let t=Hx(e),r=Sy.get(t);if(!(!r||r.state==="closed")&&r.state==="open"){if(Date.now()-r.lastFailure>3e4){r.state="half-open";return}let n=Math.ceil((3e4-(Date.now()-r.lastFailure))/1e3);throw new Error(`Circuit open for ${t} \u2014 API endpoint appears down (${r.failures} consecutive failures). Retry in ${n}s.`)}}function kM(e){let t=Hx(e),r=Sy.get(t);r&&(r.failures=0,r.state="closed")}function FM(e){let t=Hx(e),r=Sy.get(t)??{failures:0,lastFailure:0,state:"closed"};r.failures++,r.lastFailure=Date.now(),r.failures>=5&&(r.state="open"),Sy.set(t,r)}var Sy,PM=$(()=>{"use strict";Sy=new Map});function LM(e){return new Promise(t=>setTimeout(t,e))}function jM(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){let t=e;if(typeof t.message=="string")return t.message;if(typeof t.error=="string")return t.error;if(t.error&&typeof t.error=="object"){let r=t.error;if(Array.isArray(r.errors)&&r.errors.length>0)return r.errors.join("; ");if(typeof r.error_type=="string")return r.error_type}return JSON.stringify(e)}return String(e)}var goe,yoe,Doe,boe,voe,Cn,zr,li=$(()=>{"use strict";PM();goe="https://api.getjaz.com",yoe=3e4,Doe=3,boe=[429],voe=[500,502,503],Cn=class extends Error{status;body;endpoint;constructor(t,r,n,o){super(t),this.status=r,this.body=n,this.endpoint=o,this.name="JazApiError"}},zr=class{baseUrl;timeout;maxRetries;auth;onRequest;constructor(t,r={}){this.auth=t,this.baseUrl=(r.baseUrl??goe).replace(/\/$/,""),this.timeout=r.timeout??yoe,this.maxRetries=r.maxRetries??Doe,this.onRequest=r.onRequest}get isPatAuth(){return this.auth.mode==="pat"}buildHeaders(t){let r={"Content-Type":"application/json",...t};switch(this.auth.mode){case"direct":r["x-jk-api-key"]=this.auth.apiKey;break;case"pat":r.Authorization=`Bearer ${this.auth.token}`,this.auth.orgId&&(r["x-jaz-org-key"]=this.auth.orgId);break;case"delegated":r["x-clio-admin-key"]=this.auth.adminKey,r["x-user-id"]=this.auth.userId,r["x-org-id"]=this.auth.orgId,this.auth.orgUserId&&(r["x-org-user-id"]=this.auth.orgUserId);break}return r}async request(t,r,n={}){let o=new URL(`${this.baseUrl}${r}`);if(n.query)for(let[u,l]of Object.entries(n.query))l!==void 0&&o.searchParams.set(u,String(l));let i=this.buildHeaders(n.headers);n.raw&&delete i["Content-Type"];let s={method:t,headers:i,signal:AbortSignal.timeout(this.timeout)};n.body!==void 0&&t!=="GET"&&t!=="DELETE"&&(s.body=n.raw?n.body:JSON.stringify(n.body)),$M(r);let a,c=Date.now();for(let u=0;u<=this.maxRetries;u++){let l=Date.now();try{let d=await fetch(o.toString(),s),f=["GET","HEAD"].includes(t);if((boe.includes(d.status)||f&&voe.includes(d.status))&&u<this.maxRetries){this.onRequest?.({method:t,path:r,statusCode:d.status,durationMs:Date.now()-l,attempt:u,retried:!0});let m=Math.min(1e3*2**u,8e3);await LM(m);continue}if(!d.ok){let m;try{m=await d.json()}catch{m=await d.text()}throw this.onRequest?.({method:t,path:r,statusCode:d.status,durationMs:Date.now()-l,attempt:u,retried:!1,error:jM(m)}),d.status>=500&&FM(r),new Cn(`${t} ${r} \u2192 ${d.status}: ${jM(m)}`,d.status,m,r)}return this.onRequest?.({method:t,path:r,statusCode:d.status,durationMs:Date.now()-l,attempt:u,retried:!1}),kM(r),d.status===204?void 0:await d.json()}catch(d){if(d instanceof Cn)throw d;if(a=d,this.onRequest?.({method:t,path:r,statusCode:0,durationMs:Date.now()-l,attempt:u,retried:u<this.maxRetries,error:a.message}),u<this.maxRetries){let f=Math.min(1e3*2**u,8e3);await LM(f);continue}}}throw a??new Error(`Request failed: ${t} ${r}`)}async get(t,r){return this.request("GET",t,{query:r})}async post(t,r,n){return this.request("POST",t,{body:r,headers:n?.headers})}async put(t,r,n){return this.request("PUT",t,{body:r,headers:n?.headers})}async delete(t){return this.request("DELETE",t)}async postMultipart(t,r){return this.request("POST",t,{body:r,raw:!0})}async list(t,r){let n=await this.get(t,{limit:r?.limit??100,offset:r?.offset??0});return n.data||(n.data=[]),n}async search(t,r){let n={};r.query&&(n.query=r.query),r.filter&&(n.filter=r.filter),r.limit!==void 0&&(n.limit=r.limit),r.offset!==void 0&&(n.offset=r.offset),r.sort?n.sort=r.sort:r.offset!==void 0&&(n.sort={sortBy:["createdAt"],order:"DESC"});let o=await this.post(t,n);return o.data||(o.data=[]),o}async listAll(t,r=200){let n=[],o=0,i=!0;for(;i;){let s=await this.list(t,{limit:r,offset:o});if(n.push(...s.data),s.data.length<r)break;o+=1,i=o*r<s.totalElements}return n}}});async function qn(e){let t=await e.get("/api/v1/organization");return Array.isArray(t.data)?t.data[0]:t.data}var Oa=$(()=>{"use strict"});var WM=x(nt=>{"use strict";function JM(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var GM;function HM(e,t,r,n,o){if(o===void 0&&(o=nt.PaymentDueTime.End),e===0)return-(n+r*t);var i=Math.pow(1+e,t);return-n*i-r*(1+e*(o===nt.PaymentDueTime.Begin?1:0))/e*(i-1)}function Zx(e,t,r,n,o){n===void 0&&(n=0),o===void 0&&(o=nt.PaymentDueTime.End);var i=e===0,s=Math.pow(1+e,t),a=o===nt.PaymentDueTime.Begin?1:0,c=i?1:e;return-(n+r*s)/(i?t:(1+c*a)*(s-1)/c)}function VM(e,t,r,n,o,i){if(o===void 0&&(o=0),i===void 0&&(i=nt.PaymentDueTime.End),t<1)return Number.NaN;if(i===nt.PaymentDueTime.Begin&&t===1)return 0;var s=woe(e,t,Zx(e,r,n,o,i),n,i)*e;return i===nt.PaymentDueTime.Begin&&t>1&&(s/=1+e),s}function Wx(e,t){return t.reduce((function(r,n,o){return r+n/Math.pow(1+e,o)}),0)}function woe(e,t,r,n,o){return HM(e,t-1,r,n,o)}function Toe(e,t,r,n,o,i){var s=i===nt.PaymentDueTime.Begin?1:0,a=Math.pow(e+1,t),c=Math.pow(e+1,t-1);return(o+a*n+r*(a-1)*(e*s+1)/e)/(t*c*n-r*(a-1)*(e*s+1)/Math.pow(e,2)+t*r*c*(e*s+1)/e+r*(a-1)*s/e)}function Ooe(e,t,r){for(var n=r+1,o=e[0],i=1;i<e.length;i++)o+=e[i]/Math.pow(n,(t[i]-t[0])/365);return o}function Roe(e,t,r){for(var n=r+1,o=0,i=1;i<e.length;i++){var s=(t[i]-t[0])/365;o-=s*e[i]/Math.pow(n,s+1)}return o}Object.defineProperty(nt,"__esModule",{value:!0}),nt.PaymentDueTime=void 0,(GM=nt.PaymentDueTime||(nt.PaymentDueTime={})).Begin="begin",GM.End="end",nt.fv=HM,nt.ipmt=VM,nt.irr=function(e,t,r,n){t===void 0&&(t=.1),r===void 0&&(r=1e-6),n===void 0&&(n=100);for(var o=[],i=!1,s=!1,a=0;a<e.length;a++)o[a]=a===0?0:o[a-1]+365,e[a]>0&&(i=!0),e[a]<0&&(s=!0);if(!i||!s)return Number.NaN;var c=t,u=0,l=0,d=0,f=0,p=!0;do u=c-(d=Ooe(e,o,c))/Roe(e,o,c),l=Math.abs(u-c),c=u,p=l>r&&Math.abs(d)>r;while(p&&++f<n);return p?Number.NaN:c},nt.mirr=function(e,t,r){for(var n,o=!1,i=!1,s=(function(l,d){var f=typeof Symbol<"u"&&l[Symbol.iterator]||l["@@iterator"];if(f)return(f=f.call(l)).next.bind(f);if(Array.isArray(l)||(f=(function(m,h){if(m){if(typeof m=="string")return JM(m,h);var g=Object.prototype.toString.call(m).slice(8,-1);return g==="Object"&&m.constructor&&(g=m.constructor.name),g==="Map"||g==="Set"?Array.from(m):g==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(g)?JM(m,h):void 0}})(l))){f&&(l=f);var p=0;return function(){return p>=l.length?{done:!0}:{done:!1,value:l[p++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
196
|
+
`,{mode:384});let r=poe(t,"r");try{foe(r)}finally{moe(r)}coe(t,Fd)}function uo(e){return ui()?.orgs[e]??null}function Ld(e,t){let r=ui()??{version:2,active:"",orgs:{}};r.orgs[e]=t,(!r.active||Object.keys(r.orgs).length===1)&&(r.active=e),Pd(r)}function Ux(e){let t=ui();return!t||!(e in t.orgs)?!1:(delete t.orgs[e],t.active===e&&(t.active=""),Pd(t),!0)}function In(){return ui()?.active||null}function qx(e){let t=ui();if(!t)throw new Error("No credentials file found. Run `clio auth add <key>` first.");if(!(e in t.orgs)){let r=Object.keys(t.orgs).join(", ");throw new Error(`Org '${e}' not found. Available: ${r}`)}t.active=e,Pd(t)}function Fo(){return ui()?.orgs??{}}function zx(e){let t=ui();if(!t)return null;for(let[r,n]of Object.entries(t.orgs))if(n.apiKey===e)return r;return null}function Yx(){return doe(Fd)?(loe(Fd),!0):!1}var NM,Fd,jd=$(()=>{"use strict";NM=RM(hoe(),".config","jaz-clio"),Fd=RM(NM,"credentials.json")});function Jx(e){Md=e}function Ud(){return by}function qd(){return Un}function Dy(e){let t=process.env[e];if(t===void 0)return;let r=t.trim();if(r!==""&&!r.includes("${"))return r}function Bd(e){let t=e.split(",").map(s=>s.trim()).filter(Boolean);if(t.length===0)throw new cn("Empty key value. Provide a Jaz API key (jk-...) or personal access token (pat_...).");let r=t.filter(s=>s.startsWith(eu)),n=t.filter(s=>s.startsWith("jk-"));if(t.filter(s=>!s.startsWith(eu)&&!s.startsWith("jk-")).length>0)throw new cn("Invalid key format (unrecognized prefix). Expected jk-... (API key) or pat_... (personal access token).");if(r.length>0&&n.length>0)throw new cn("Cannot mix PAT and API keys. Use either a single personal access token (pat_...) or one or more API keys (jk-...).");if(r.length>0&&t.length!==1)throw new cn("Only one personal access token allowed. Do not combine with other keys.");return r.length===1?[{mode:"pat",token:r[0]}]:[...new Set(n)].map(s=>({mode:"direct",apiKey:s}))}function vy(e){if(by=null,Un=null,e)return Un="flag-api-key",Bd(e)[0];let t=Dy("JAZ_API_KEY");if(t)return Un="env-api-key",Bd(t)[0];if(Md)return Un="flag-org",tu(Md);let r=Dy("JAZ_ORG");if(r)return Un="env-org",tu(r);let n=In();return n?(Un="active-file",tu(n)):null}function tu(e){let t=uo(e);if(!t){let r=ui(),n=r?Object.keys(r.orgs):[],o=n.length>0?` Available: ${n.join(", ")}`:" No orgs registered. Run `clio auth add <key>` first.";throw new cn(`Org '${e}' not found.${o}`)}return by=e,{mode:"direct",apiKey:t.apiKey}}function Gx(e){if(by=null,Un=null,e)return Un="flag-api-key",Bd(e);let t=Dy("JAZ_API_KEY");if(t)return Un="env-api-key",Bd(t);if(Md)return Un="flag-org",[tu(Md)];let r=Dy("JAZ_ORG");if(r)return Un="env-org",[tu(r)];let n=In();return n?(Un="active-file",[tu(n)]):[]}function Ta(e){let t=vy(e);if(!t)throw new cn("No API key configured. Run `clio auth add <key>`, set JAZ_API_KEY, or pass --api-key.");return t}var Md,by,Un,cn,Vx=$(()=>{"use strict";Bx();jd();by=null;Un=null;cn=class extends Error{constructor(t){super(t),this.name="AuthError"}}});function Hx(e){return e.replace(/\/[a-f0-9-]{8,}(?=[/?#]|$)/gi,"/{id}")}function $M(e){let t=Hx(e),r=Sy.get(t);if(!(!r||r.state==="closed")&&r.state==="open"){if(Date.now()-r.lastFailure>3e4){r.state="half-open";return}let n=Math.ceil((3e4-(Date.now()-r.lastFailure))/1e3);throw new Error(`Circuit open for ${t} \u2014 API endpoint appears down (${r.failures} consecutive failures). Retry in ${n}s.`)}}function kM(e){let t=Hx(e),r=Sy.get(t);r&&(r.failures=0,r.state="closed")}function FM(e){let t=Hx(e),r=Sy.get(t)??{failures:0,lastFailure:0,state:"closed"};r.failures++,r.lastFailure=Date.now(),r.failures>=5&&(r.state="open"),Sy.set(t,r)}var Sy,PM=$(()=>{"use strict";Sy=new Map});function LM(e){return new Promise(t=>setTimeout(t,e))}function jM(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){let t=e;if(typeof t.message=="string")return t.message;if(typeof t.error=="string")return t.error;if(t.error&&typeof t.error=="object"){let r=t.error;if(Array.isArray(r.errors)&&r.errors.length>0)return r.errors.join("; ");if(typeof r.error_type=="string")return r.error_type}return JSON.stringify(e)}return String(e)}var goe,yoe,Doe,boe,voe,Cn,zr,li=$(()=>{"use strict";PM();goe="https://api.getjaz.com",yoe=3e4,Doe=3,boe=[429],voe=[500,502,503],Cn=class extends Error{status;body;endpoint;constructor(t,r,n,o){super(t),this.status=r,this.body=n,this.endpoint=o,this.name="JazApiError"}},zr=class{baseUrl;timeout;maxRetries;auth;onRequest;constructor(t,r={}){this.auth=t,this.baseUrl=(r.baseUrl??goe).replace(/\/$/,""),this.timeout=r.timeout??yoe,this.maxRetries=r.maxRetries??Doe,this.onRequest=r.onRequest}get isPatAuth(){return this.auth.mode==="pat"}buildHeaders(t){let r={"Content-Type":"application/json",...t};switch(this.auth.mode){case"direct":r["x-jk-api-key"]=this.auth.apiKey;break;case"pat":r.Authorization=`Bearer ${this.auth.token}`,this.auth.orgId&&(r["x-jaz-org-key"]=this.auth.orgId);break;case"delegated":this.auth.orgUserId?(r["x-channel-key"]=this.auth.adminKey,r["x-jaz-org-key"]=this.auth.orgId,r["x-jaz-org-user-key"]=this.auth.orgUserId):(r["x-clio-admin-key"]=this.auth.adminKey,r["x-user-id"]=this.auth.userId,r["x-org-id"]=this.auth.orgId);break}return r}async request(t,r,n={}){let o=new URL(`${this.baseUrl}${r}`);if(n.query)for(let[u,l]of Object.entries(n.query))l!==void 0&&o.searchParams.set(u,String(l));let i=this.buildHeaders(n.headers);n.raw&&delete i["Content-Type"];let s={method:t,headers:i,signal:AbortSignal.timeout(this.timeout)};n.body!==void 0&&t!=="GET"&&t!=="DELETE"&&(s.body=n.raw?n.body:JSON.stringify(n.body)),$M(r);let a,c=Date.now();for(let u=0;u<=this.maxRetries;u++){let l=Date.now();try{let d=await fetch(o.toString(),s),f=["GET","HEAD"].includes(t);if((boe.includes(d.status)||f&&voe.includes(d.status))&&u<this.maxRetries){this.onRequest?.({method:t,path:r,statusCode:d.status,durationMs:Date.now()-l,attempt:u,retried:!0});let m=Math.min(1e3*2**u,8e3);await LM(m);continue}if(!d.ok){let m;try{m=await d.json()}catch{m=await d.text()}throw this.onRequest?.({method:t,path:r,statusCode:d.status,durationMs:Date.now()-l,attempt:u,retried:!1,error:jM(m)}),d.status>=500&&FM(r),new Cn(`${t} ${r} \u2192 ${d.status}: ${jM(m)}`,d.status,m,r)}return this.onRequest?.({method:t,path:r,statusCode:d.status,durationMs:Date.now()-l,attempt:u,retried:!1}),kM(r),d.status===204?void 0:await d.json()}catch(d){if(d instanceof Cn)throw d;if(a=d,this.onRequest?.({method:t,path:r,statusCode:0,durationMs:Date.now()-l,attempt:u,retried:u<this.maxRetries,error:a.message}),u<this.maxRetries){let f=Math.min(1e3*2**u,8e3);await LM(f);continue}}}throw a??new Error(`Request failed: ${t} ${r}`)}async get(t,r){return this.request("GET",t,{query:r})}async post(t,r,n){return this.request("POST",t,{body:r,headers:n?.headers})}async put(t,r,n){return this.request("PUT",t,{body:r,headers:n?.headers})}async delete(t){return this.request("DELETE",t)}async postMultipart(t,r){return this.request("POST",t,{body:r,raw:!0})}async list(t,r){let n=await this.get(t,{limit:r?.limit??100,offset:r?.offset??0});return n.data||(n.data=[]),n}async search(t,r){let n={};r.query&&(n.query=r.query),r.filter&&(n.filter=r.filter),r.limit!==void 0&&(n.limit=r.limit),r.offset!==void 0&&(n.offset=r.offset),r.sort?n.sort=r.sort:r.offset!==void 0&&(n.sort={sortBy:["createdAt"],order:"DESC"});let o=await this.post(t,n);return o.data||(o.data=[]),o}async listAll(t,r=200){let n=[],o=0,i=!0;for(;i;){let s=await this.list(t,{limit:r,offset:o});if(n.push(...s.data),s.data.length<r)break;o+=1,i=o*r<s.totalElements}return n}}});async function qn(e){let t=await e.get("/api/v1/organization");return Array.isArray(t.data)?t.data[0]:t.data}var Oa=$(()=>{"use strict"});var WM=x(nt=>{"use strict";function JM(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var GM;function HM(e,t,r,n,o){if(o===void 0&&(o=nt.PaymentDueTime.End),e===0)return-(n+r*t);var i=Math.pow(1+e,t);return-n*i-r*(1+e*(o===nt.PaymentDueTime.Begin?1:0))/e*(i-1)}function Zx(e,t,r,n,o){n===void 0&&(n=0),o===void 0&&(o=nt.PaymentDueTime.End);var i=e===0,s=Math.pow(1+e,t),a=o===nt.PaymentDueTime.Begin?1:0,c=i?1:e;return-(n+r*s)/(i?t:(1+c*a)*(s-1)/c)}function VM(e,t,r,n,o,i){if(o===void 0&&(o=0),i===void 0&&(i=nt.PaymentDueTime.End),t<1)return Number.NaN;if(i===nt.PaymentDueTime.Begin&&t===1)return 0;var s=woe(e,t,Zx(e,r,n,o,i),n,i)*e;return i===nt.PaymentDueTime.Begin&&t>1&&(s/=1+e),s}function Wx(e,t){return t.reduce((function(r,n,o){return r+n/Math.pow(1+e,o)}),0)}function woe(e,t,r,n,o){return HM(e,t-1,r,n,o)}function Toe(e,t,r,n,o,i){var s=i===nt.PaymentDueTime.Begin?1:0,a=Math.pow(e+1,t),c=Math.pow(e+1,t-1);return(o+a*n+r*(a-1)*(e*s+1)/e)/(t*c*n-r*(a-1)*(e*s+1)/Math.pow(e,2)+t*r*c*(e*s+1)/e+r*(a-1)*s/e)}function Ooe(e,t,r){for(var n=r+1,o=e[0],i=1;i<e.length;i++)o+=e[i]/Math.pow(n,(t[i]-t[0])/365);return o}function Roe(e,t,r){for(var n=r+1,o=0,i=1;i<e.length;i++){var s=(t[i]-t[0])/365;o-=s*e[i]/Math.pow(n,s+1)}return o}Object.defineProperty(nt,"__esModule",{value:!0}),nt.PaymentDueTime=void 0,(GM=nt.PaymentDueTime||(nt.PaymentDueTime={})).Begin="begin",GM.End="end",nt.fv=HM,nt.ipmt=VM,nt.irr=function(e,t,r,n){t===void 0&&(t=.1),r===void 0&&(r=1e-6),n===void 0&&(n=100);for(var o=[],i=!1,s=!1,a=0;a<e.length;a++)o[a]=a===0?0:o[a-1]+365,e[a]>0&&(i=!0),e[a]<0&&(s=!0);if(!i||!s)return Number.NaN;var c=t,u=0,l=0,d=0,f=0,p=!0;do u=c-(d=Ooe(e,o,c))/Roe(e,o,c),l=Math.abs(u-c),c=u,p=l>r&&Math.abs(d)>r;while(p&&++f<n);return p?Number.NaN:c},nt.mirr=function(e,t,r){for(var n,o=!1,i=!1,s=(function(l,d){var f=typeof Symbol<"u"&&l[Symbol.iterator]||l["@@iterator"];if(f)return(f=f.call(l)).next.bind(f);if(Array.isArray(l)||(f=(function(m,h){if(m){if(typeof m=="string")return JM(m,h);var g=Object.prototype.toString.call(m).slice(8,-1);return g==="Object"&&m.constructor&&(g=m.constructor.name),g==="Map"||g==="Set"?Array.from(m):g==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(g)?JM(m,h):void 0}})(l))){f&&(l=f);var p=0;return function(){return p>=l.length?{done:!0}:{done:!1,value:l[p++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
197
197
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)})(e);!(n=s()).done;){var a=n.value;a>0&&(o=!0),a<0&&(i=!0)}if(!o||!i)return Number.NaN;var c=Math.abs(Wx(r,e.map((function(l){return l>0?l:0})))),u=Math.abs(Wx(t,e.map((function(l){return l<0?l:0}))));return Math.pow(c/u,1/(e.length-1))*(1+r)-1},nt.nper=function(e,t,r,n,o){if(n===void 0&&(n=0),o===void 0&&(o=nt.PaymentDueTime.End),e===0)return-(n+r)/t;var i=t*(1+e*(o===nt.PaymentDueTime.Begin?1:0))/e;return Math.log((-n+i)/(r+i))/Math.log(1+e)},nt.npv=Wx,nt.pmt=Zx,nt.ppmt=function(e,t,r,n,o,i){return o===void 0&&(o=0),i===void 0&&(i=nt.PaymentDueTime.End),Zx(e,r,n,o,i)-VM(e,t,r,n,o,i)},nt.pv=function(e,t,r,n,o){n===void 0&&(n=0),o===void 0&&(o=nt.PaymentDueTime.End);var i=o===nt.PaymentDueTime.Begin?1:0,s=e===0,a=Math.pow(1+e,t);return-(n+r*(s?t:(1+e*i)*(a-1)/e))/a},nt.rate=function(e,t,r,n,o,i,s,a){o===void 0&&(o=nt.PaymentDueTime.End),i===void 0&&(i=.1),s===void 0&&(s=1e-6),a===void 0&&(a=100);for(var c=i,u=0,l=!1;u<a&&!l;){var d=c-Toe(c,e,t,r,n,o);l=Math.abs(d-c)<s,u++,c=d}return l?c:Number.NaN}});var QM=x(ot=>{"use strict";Object.defineProperty(ot,"__esModule",{value:!0});function Noe(e,t){if(e){if(typeof e=="string")return ZM(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return ZM(e,t)}}function ZM(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function $oe(e,t){var r=typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=Noe(e))||t&&e&&typeof e.length=="number"){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
198
198
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}ot.PaymentDueTime=void 0;(function(e){e.Begin="begin",e.End="end"})(ot.PaymentDueTime||(ot.PaymentDueTime={}));function KM(e,t,r,n,o){o===void 0&&(o=ot.PaymentDueTime.End);var i=e===0;if(i)return-(n+r*t);var s=Math.pow(1+e,t),a=o===ot.PaymentDueTime.Begin?1:0;return-n*s-r*(1+e*a)/e*(s-1)}function Xx(e,t,r,n,o){n===void 0&&(n=0),o===void 0&&(o=ot.PaymentDueTime.End);var i=e===0,s=Math.pow(1+e,t),a=o===ot.PaymentDueTime.Begin?1:0,c=i?1:e,u=i?t:(1+c*a)*(s-1)/c;return-(n+r*s)/u}function koe(e,t,r,n,o){n===void 0&&(n=0),o===void 0&&(o=ot.PaymentDueTime.End);var i=e===0;if(i)return-(n+r)/t;var s=o===ot.PaymentDueTime.Begin?1:0,a=t*(1+e*s)/e;return Math.log((-n+a)/(r+a))/Math.log(1+e)}function XM(e,t,r,n,o,i){if(o===void 0&&(o=0),i===void 0&&(i=ot.PaymentDueTime.End),t<1)return Number.NaN;if(i===ot.PaymentDueTime.Begin&&t===1)return 0;var s=Xx(e,r,n,o,i),a=Boe(e,t,s,n,i)*e;return i===ot.PaymentDueTime.Begin&&t>1&&(a=a/(1+e)),a}function Foe(e,t,r,n,o,i){o===void 0&&(o=0),i===void 0&&(i=ot.PaymentDueTime.End);var s=Xx(e,r,n,o,i);return s-XM(e,t,r,n,o,i)}function Poe(e,t,r,n,o){n===void 0&&(n=0),o===void 0&&(o=ot.PaymentDueTime.End);var i=o===ot.PaymentDueTime.Begin?1:0,s=e===0,a=Math.pow(1+e,t),c=s?t:(1+e*i)*(a-1)/e;return-(n+r*c)/a}function Loe(e,t,r,n,o,i,s,a){o===void 0&&(o=ot.PaymentDueTime.End),i===void 0&&(i=.1),s===void 0&&(s=1e-6),a===void 0&&(a=100);for(var c=i,u=0,l=!1;u<a&&!l;){var d=c-Uoe(c,e,t,r,n,o),f=Math.abs(d-c);l=f<s,u++,c=d}return l?c:Number.NaN}function joe(e,t,r,n){t===void 0&&(t=.1),r===void 0&&(r=1e-6),n===void 0&&(n=100);for(var o=[],i=!1,s=!1,a=0;a<e.length;a++)o[a]=a===0?0:o[a-1]+365,e[a]>0&&(i=!0),e[a]<0&&(s=!0);if(!i||!s)return Number.NaN;var c=t,u=0,l=0,d=0,f=0,p=!0;do d=qoe(e,o,c),u=c-d/zoe(e,o,c),l=Math.abs(u-c),c=u,p=l>r&&Math.abs(d)>r;while(p&&++f<n);return p?Number.NaN:c}function Kx(e,t){return t.reduce(function(r,n,o){return r+n/Math.pow(1+e,o)},0)}function Moe(e,t,r){for(var n=!1,o=!1,i=$oe(e),s;!(s=i()).done;){var a=s.value;a>0&&(n=!0),a<0&&(o=!0)}if(!n||!o)return Number.NaN;var c=Math.abs(Kx(r,e.map(function(l){return l>0?l:0}))),u=Math.abs(Kx(t,e.map(function(l){return l<0?l:0})));return Math.pow(c/u,1/(e.length-1))*(1+r)-1}function Boe(e,t,r,n,o){return KM(e,t-1,r,n,o)}function Uoe(e,t,r,n,o,i){var s=i===ot.PaymentDueTime.Begin?1:0,a=Math.pow(e+1,t),c=Math.pow(e+1,t-1),u=o+a*n+r*(a-1)*(e*s+1)/e,l=t*c*n-r*(a-1)*(e*s+1)/Math.pow(e,2)+t*r*c*(e*s+1)/e+r*(a-1)*s/e;return u/l}function qoe(e,t,r){for(var n=r+1,o=e[0],i=1;i<e.length;i++)o+=e[i]/Math.pow(n,(t[i]-t[0])/365);return o}function zoe(e,t,r){for(var n=r+1,o=0,i=1;i<e.length;i++){var s=(t[i]-t[0])/365;o-=s*e[i]/Math.pow(n,s+1)}return o}ot.fv=KM;ot.ipmt=XM;ot.irr=joe;ot.mirr=Moe;ot.nper=koe;ot.npv=Kx;ot.pmt=Xx;ot.ppmt=Foe;ot.pv=Poe;ot.rate=Loe});var zd=x((K1e,Qx)=>{"use strict";process.env.NODE_ENV==="production"?Qx.exports=WM():Qx.exports=QM()});function N(e){return Math.round(e*100)/100}function mr(e,t){let r=e.split("-");if(r.length!==3)throw new Error(`Invalid date format: ${e}`);let[n,o,i]=r.map(Number);if(!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(i))throw new Error(`Invalid date: ${e}`);let s=o-1+t,a=n+Math.floor(s/12),c=(s%12+12)%12,u=new Date(Date.UTC(a,c+1,0)).getUTCDate(),l=Math.min(i,u);return`${String(a).padStart(4,"0")}-${String(c+1).padStart(2,"0")}-${String(l).padStart(2,"0")}`}var un=$(()=>{"use strict"});function mt(e,t){if(!Number.isFinite(e)||e<=0)throw new $e(`${t} must be a positive number (got ${e})`)}function di(e,t){if(!Number.isFinite(e)||e<0)throw new $e(`${t} must be zero or positive (got ${e})`)}function er(e,t){if(!Number.isInteger(e)||e<1)throw new $e(`${t} must be a positive integer (got ${e})`)}function _y(e,t){if(e>=t)throw new $e(`Salvage value (${e}) must be less than cost (${t})`)}function Wt(e){if(!e)return;if(!/^\d{4}-\d{2}-\d{2}$/.test(e))throw new $e(`Date must be YYYY-MM-DD format (got "${e}")`);let t=new Date(e+"T00:00:00");if(isNaN(t.getTime()))throw new $e(`Invalid date: "${e}"`)}function ds(e,t="Rate"){di(e,t),e>100&&process.stderr.write(`Warning: ${t} is ${e}% \u2014 are you sure this isn't a decimal? (e.g. 6 for 6%, not 0.06)
|
|
199
199
|
`)}function eB(e){if(!e||typeof e!="object")throw new $e("Input must be a JSON object with bankRecords and transactions arrays");let t=e;if(!Array.isArray(t.bankRecords))throw new $e("bankRecords must be an array");if(!Array.isArray(t.transactions))throw new $e("transactions must be an array");if(t.bankRecords.length===0)throw new $e("bankRecords array is empty \u2014 nothing to match");if(t.transactions.length===0)throw new $e("transactions array is empty \u2014 nothing to match");for(let o=0;o<t.bankRecords.length;o++){let i=t.bankRecords[o];if(!i.id||typeof i.id!="string")throw new $e(`bankRecords[${o}]: id is required (string)`);if(typeof i.amount!="number"||!Number.isFinite(i.amount))throw new $e(`bankRecords[${o}]: amount must be a finite number`);if(i.amount===0)throw new $e(`bankRecords[${o}]: amount must not be zero`);if(!i.date||typeof i.date!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(i.date))throw new $e(`bankRecords[${o}]: date must be YYYY-MM-DD format`)}for(let o=0;o<t.transactions.length;o++){let i=t.transactions[o];if(!i.id||typeof i.id!="string")throw new $e(`transactions[${o}]: id is required (string)`);if(i.direction!=="PAYIN"&&i.direction!=="PAYOUT")throw new $e(`transactions[${o}]: direction must be 'PAYIN' or 'PAYOUT'`);if(typeof i.amount!="number"||!Number.isFinite(i.amount)||i.amount<=0)throw new $e(`transactions[${o}]: amount must be a positive number`);if(!i.date||typeof i.date!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(i.date))throw new $e(`transactions[${o}]: date must be YYYY-MM-DD format`);if(i.crossCurrency&&(!i.currency||typeof i.currency!="string"))throw new $e(`transactions[${o}]: crossCurrency is true but currency is missing`)}let r=t.options;if(r){if(r.tolerance!==void 0&&(typeof r.tolerance!="number"||r.tolerance<0))throw new $e("options.tolerance must be a non-negative number");if(r.dateWindowDays!==void 0&&(typeof r.dateWindowDays!="number"||!Number.isInteger(r.dateWindowDays)||r.dateWindowDays<0))throw new $e("options.dateWindowDays must be a non-negative integer");if(r.maxGroupSize!==void 0&&(typeof r.maxGroupSize!="number"||!Number.isInteger(r.maxGroupSize)||r.maxGroupSize<2||r.maxGroupSize>10))throw new $e("options.maxGroupSize must be an integer between 2 and 10")}let n=r?.exchangeRates;for(let o=0;o<t.transactions.length;o++){let i=t.transactions[o];if(i.crossCurrency&&i.currency&&(!n||typeof n[i.currency]!="number"))throw new $e(`transactions[${o}]: crossCurrency is true with currency "${i.currency}" but no exchange rate provided in options.exchangeRates`)}return e}var $e,Yr=$(()=>{"use strict";$e=class extends Error{constructor(t){super(t),this.name="CalcValidationError"}}});function Xe(e,t,r,n){return{step:e,action:"journal",description:t,date:r,lines:n}}function tB(e,t,r,n){return{step:e,action:"bill",description:t,date:r,lines:n}}function rB(e,t,r,n){return{step:e,action:"invoice",description:t,date:r,lines:n}}function Ra(e,t,r,n){return{step:e,action:"cash-out",description:t,date:r,lines:n}}function Ey(e,t,r,n){return{step:e,action:"cash-in",description:t,date:r,lines:n}}function nB(e,t,r=null){return{step:e,action:"fixed-asset",description:t,date:r,lines:[]}}function oB(e,t,r=null){return{step:e,action:"note",description:t,date:r,lines:[]}}function Jt(e,t){let r=e.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0});return t?`${t} ${r}`:r}function W(e,t){let r=e.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2});return t?`${t} ${r}`:r}var zn=$(()=>{"use strict"});function Iy(e){let{principal:t,annualRate:r,termMonths:n,startDate:o,currency:i}=e;mt(t,"Principal"),ds(r,"Annual rate"),er(n,"Term (months)"),Wt(o);let s=r/100/12,a=N(-(0,iB.pmt)(s,n,t)),c=[],u=t,l=0,d=0;for(let p=1;p<=n;p++){let m=N(u),h=p===n,g,D,b;h?(g=N(m*s),D=m,b=N(D+g)):(g=N(m*s),D=N(a-g),b=a),u=N(m-D),l=N(l+g),d=N(d+D);let y=o?mr(o,p):null,v={description:`Loan payment \u2014 Month ${p} of ${n}`,lines:[{account:"Loan Payable",debit:D,credit:0},{account:"Interest Expense",debit:g,credit:0},{account:"Cash / Bank Account",debit:0,credit:b}]};c.push({period:p,date:y,openingBalance:m,payment:b,interest:g,principal:D,closingBalance:u,journal:v})}let f=null;if(o){let p=[Ey(1,"Record loan proceeds received from bank",o,[{account:"Cash / Bank Account",debit:t,credit:0},{account:"Loan Payable",debit:0,credit:t}]),...c.map((g,D)=>Xe(D+2,g.journal.description,g.date,g.journal.lines))],m=i??void 0,h=["Loan Amortization Workings",`Principal: ${W(t,m)} | Rate: ${r}% p.a. (${N(s*100)}% monthly)`,`Term: ${n} months | Monthly payment: ${W(a,m)}`,`Total payments: ${W(N(l+d),m)} | Total interest: ${W(l,m)}`,"Method: PMT formula, constant payment amortization","Rounding: 2dp per period, final period closes balance to $0.00"].join(`
|