UNPKG

billdotcom-sdk-v3

Version:

TypeScript SDK for Bill.com V3 API

2 lines 29 kB
import {z as z$1}from'zod';var f=class extends Error{statusCode;responseStatus;responseData;constructor(a,r,y,C){super(a),this.name="BillApiError",this.statusCode=r,this.responseStatus=y,this.responseData=C;}},P=class extends f{constructor(a,r){super(a,401,1,r),this.name="AuthenticationError";}},B=class extends f{constructor(a,r){super(a,404,1,r),this.name="NotFoundError";}},V=class extends f{constructor(a,r){super(a,400,1,r),this.name="ValidationError";}},E=class extends f{constructor(a="Session expired",r){super(a,401,1,r),this.name="SessionExpiredError";}},A=class extends Error{constructor(a){super(a),this.name="ConfigurationError";}};async function g(p,a){let r=`${p.baseUrl}${a.path}`,y={"Content-Type":"application/json",devKey:p.devKey,...a.headers};p.sessionId&&(y.sessionId=p.sessionId);let C=await fetch(r,{method:a.method,headers:y,body:a.body?JSON.stringify(a.body):void 0}),T=await C.text();if(!T)return;let h;try{h=JSON.parse(T);}catch{if(!C.ok)throw new f(T||"API request failed",C.status,1,T);return}if(Array.isArray(h)&&!C.ok){let u=h[0]?.message||"Unknown API error";throw u.toLowerCase().includes("session")&&u.toLowerCase().includes("expired")?new E(u,h):C.status===401||u.toLowerCase().includes("unauthorized")||u.toLowerCase().includes("authentication")?new P(u,h):C.status===404||u.toLowerCase().includes("not found")?new B(u,h):C.status===400||u.toLowerCase().includes("invalid")||u.toLowerCase().includes("required")?new V(u,h):new f(u,C.status,1,h)}if(!C.ok){let u=h,at=u.message||u.error||"API request failed";throw new f(at,C.status,1,h)}return h}function it(p){return typeof p!="string"?false:/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/.test(p)}function rt(p){if(p.op==="in"||p.op==="nin")return `${p.field}:${p.op}:"${p.value.join(",")}"`;let r=p.value;return p.op==="sw"&&typeof r=="string"?`${p.field}:${p.op}:"${r}"`:it(r)?`${p.field}:${p.op}:"${r}"`:`${p.field}:${p.op}:${r}`}var d=class{constructor(a){this.getConfig=a;}async list(a){let r=this.getConfig(),y=new URLSearchParams;if(a?.max!==void 0&&y.set("max",String(a.max)),a?.page&&y.set("page",a.page),a?.sort&&a.sort.length>0){let h=a.sort.map(u=>`${u.field}:${u.order}`).join(",");y.set("sort",h);}if(a?.filters&&a.filters.length>0){let h=a.filters.map(rt).join(",");y.set("filters",h);}let C=y.toString(),T=C?`${this.endpoint}?${C}`:this.endpoint;return g(r,{method:"GET",path:T})}async get(a){let r=this.getConfig();return g(r,{method:"GET",path:`${this.endpoint}/${a}`})}async create(a){let r=this.getConfig();return g(r,{method:"POST",path:this.endpoint,body:a})}async createMultiple(a){let r=this.getConfig(),y=await g(r,{method:"POST",path:`${this.endpoint}/bulk`,body:a});return Array.isArray(y)?y:y[this.bulkResponseKey]}async update(a,r){let y=this.getConfig();return g(y,{method:"PATCH",path:`${this.endpoint}/${a}`,body:r})}async archive(a){let r=this.getConfig();return g(r,{method:"POST",path:`${this.endpoint}/${a}/archive`})}async restore(a){let r=this.getConfig();return g(r,{method:"POST",path:`${this.endpoint}/${a}/restore`})}};z$1.enum(["eq","ne","gt","gte","lt","lte","in","nin","sw"]);var st=z$1.object({field:z$1.string(),op:z$1.enum(["in","nin"]),value:z$1.array(z$1.string())}),pt=z$1.object({field:z$1.string(),op:z$1.enum(["eq","ne","gt","gte","lt","lte","sw"]),value:z$1.union([z$1.string(),z$1.number(),z$1.boolean()])}),ct=z$1.union([st,pt]),S=z$1.object({max:z$1.number().min(1).max(100).optional(),page:z$1.string().optional(),filters:z$1.array(ct).optional(),sort:z$1.array(z$1.object({field:z$1.string(),order:z$1.enum(["asc","desc"])})).optional()});var te=["BUSINESS","PERSON","NONE","UNDEFINED"],oe=["CHECKING","SAVINGS"],ne=["BUSINESS","PERSON"],ae=["ENROLLED","UNENROLLED","PENDING","UNKNOWN","VERBAL_COMMITMENT","REQUIRE_MORE_INFO","UNDEFINED"],ie=["ACH","CHECK","VIRTUAL_CARD","RPPS","UNDEFINED"],re=["MULTIPLE","LOCAL","WIRE","UNDEFINED","NONE"],se=["SSN","EIN","UNDEFINED"],pe=["UNDEFINED","CREDIT_CARD","AMEX"],mt=["id","archived","name","shortName","accountNumber","accountType","email","createdTime","updatedTime"],lt=["name","createdTime","updatedTime"],U=z$1.enum(te),F=z$1.object({line1:z$1.string().optional(),line2:z$1.string().optional(),city:z$1.string().optional(),stateOrProvince:z$1.string().optional(),zipOrPostalCode:z$1.string().optional(),country:z$1.string().optional(),countryName:z$1.string().optional()}),ce=z$1.enum(oe),me=z$1.enum(ne),le=z$1.object({nameOnAccount:z$1.string().optional(),accountNumber:z$1.string().optional(),routingNumber:z$1.string().optional(),type:ce.optional(),ownerType:me.optional(),paymentCurrency:z$1.string().optional()}),ue=z$1.enum(ae),de=z$1.enum(ie),ut=z$1.enum(re),dt=z$1.enum(se),yt=z$1.enum(pe),ye=z$1.object({status:ue.optional(),remitEmail:z$1.string().optional(),enrollDate:z$1.string().optional(),declineDate:z$1.string().optional(),alternatePayByType:yt.optional()}),St=z$1.object({text:z$1.string().optional(),code:z$1.object({name:z$1.string().optional(),value:z$1.string().optional()}).optional()}),Se=z$1.object({payeeName:z$1.string().optional(),email:z$1.string().optional(),lastPaymentDate:z$1.string().optional(),payByType:de.optional(),payBySubType:ut.nullable().optional(),bankAccount:le.optional(),virtualCard:ye.optional(),paymentPurpose:St.optional()}),Ce=z$1.object({taxId:z$1.string().optional(),taxIdType:dt.optional(),track1099:z$1.boolean().optional(),leadTimeInDays:z$1.number().optional(),combinePayments:z$1.boolean().optional(),paymentTermId:z$1.string().optional(),companyName:z$1.string().optional()}),he=z$1.object({amount:z$1.number().optional(),lastUpdatedDate:z$1.string().optional()}),ge=z$1.object({enabled:z$1.boolean().optional(),bankAccountId:z$1.string().optional(),createdBy:z$1.string().optional(),maxAmount:z$1.number().optional(),daysBeforeDueDate:z$1.number().optional()}),Ct=z$1.object({id:z$1.string(),archived:z$1.boolean(),name:z$1.string(),shortName:z$1.string().optional(),accountNumber:z$1.string().optional(),accountType:U,email:z$1.string().optional(),phone:z$1.string().optional(),address:F.optional(),paymentInformation:Se.optional(),additionalInfo:Ce.optional(),rppsId:z$1.string().optional(),bankAccountStatus:z$1.string().optional(),recurringPayments:z$1.boolean().optional(),billCurrency:z$1.string().optional(),balance:he.optional(),autoPay:ge.optional(),networkStatus:z$1.string().optional(),createdTime:z$1.string(),updatedTime:z$1.string()}),ht=z$1.object({name:z$1.string(),accountType:U,email:z$1.string().optional(),phone:z$1.string().optional(),address:F.optional(),paymentInformation:z$1.object({payeeName:z$1.string().optional(),bankAccount:z$1.object({nameOnAccount:z$1.string().optional(),accountNumber:z$1.string().optional(),routingNumber:z$1.string().optional()}).optional()}).optional(),additionalInfo:z$1.object({track1099:z$1.boolean().optional(),combinePayments:z$1.boolean().optional()}).optional(),billCurrency:z$1.string().optional()}),gt=z$1.object({name:z$1.string().optional(),accountType:U.optional(),email:z$1.string().optional(),phone:z$1.string().optional(),address:F.optional(),paymentInformation:z$1.object({payeeName:z$1.string().optional()}).optional(),additionalInfo:z$1.object({track1099:z$1.boolean().optional(),combinePayments:z$1.boolean().optional()}).optional(),billCurrency:z$1.string().optional(),autoPay:z$1.object({enabled:z$1.boolean().optional()}).optional()}),ft=S;var fe=["PAID","UNPAID","PARTIAL","SCHEDULED","UNDEFINED"],Ie=["UNASSIGNED","ASSIGNED","APPROVING","APPROVED","DENIED"],Te=["WAITING","APPROVED","DENIED","REROUTED","UNDEFINED"],It=["id","archived","vendorId","amount","dueDate","paymentStatus","approvalStatus","createdTime","updatedTime"],Tt=["dueDate","amount","createdTime","updatedTime"],Pe=z$1.enum(fe),Ee=z$1.enum(Ie),Ae=z$1.enum(Te),xe=z$1.object({userId:z$1.string(),status:Ae,approverOrder:z$1.number(),statusChangedTime:z$1.string()}),x=z$1.object({chartOfAccountId:z$1.string().optional(),accountingClassId:z$1.string().optional(),departmentId:z$1.string().optional(),locationId:z$1.string().optional(),itemId:z$1.string().optional()}),be=x.extend({employeeId:z$1.string().optional(),jobId:z$1.string().optional(),customerId:z$1.string().optional()}),q=z$1.object({invoiceNumber:z$1.string(),invoiceDate:z$1.string()}),J=z$1.object({id:z$1.string(),amount:z$1.number()}),M=z$1.object({id:z$1.string().optional(),amount:z$1.number().optional(),quantity:z$1.number().optional(),price:z$1.number().optional(),description:z$1.string().optional(),classifications:be.optional()}),Pt=z$1.object({id:z$1.string(),archived:z$1.boolean(),vendorId:z$1.string().optional(),vendorName:z$1.string().optional(),fundingAmount:z$1.number().optional(),amount:z$1.number().optional(),paidAmount:z$1.number().optional(),dueAmount:z$1.number().optional(),scheduledAmount:z$1.number().optional(),creditAmount:z$1.number(),exchangeRate:z$1.number().optional(),description:z$1.string().optional(),dueDate:z$1.string(),invoice:q,billLineItems:z$1.array(M),payFromChartOfAccountId:z$1.string().optional(),paymentStatus:Pe,approvalStatus:Ee,createdTime:z$1.string(),updatedTime:z$1.string(),classifications:x.optional(),approvers:z$1.array(xe).optional(),purchaseOrderNumber:z$1.string().optional()}),Et=z$1.object({vendorId:z$1.string(),description:z$1.string().optional(),dueDate:z$1.string(),billLineItems:z$1.array(M.omit({id:true})),invoice:q,payFromChartOfAccountId:z$1.string().optional(),classifications:x.optional(),vendorCredits:z$1.array(J).optional(),purchaseOrderNumber:z$1.string().optional(),billApprovals:z$1.boolean().optional()}),At=z$1.object({vendorId:z$1.string().optional(),description:z$1.string().optional(),dueDate:z$1.string().optional(),billLineItems:z$1.array(M.omit({id:true})).optional(),invoice:q.optional(),payFromChartOfAccountId:z$1.string().optional(),classifications:x.optional(),vendorCredits:z$1.array(J).optional(),purchaseOrderNumber:z$1.string().optional(),billApprovals:z$1.boolean().optional()}),xt=S;var Re=["UNSPECIFIED","ACCOUNTS_PAYABLE","ACCOUNTS_RECEIVABLE","BANK","COST_OF_GOODS_SOLD","CREDIT_CARD","EQUITY","EXPENSE","FIXED_ASSET","INCOME","LONG_TERM_LIABILITY","OTHER_ASSET","OTHER_CURRENT_ASSET","OTHER_CURRENT_LIABILITY","OTHER_EXPENSE","OTHER_INCOME","NON_POSTING"],bt=["id","archived","name","parentId","createdTime","updatedTime"],Rt=["name","createdTime","updatedTime"],z=z$1.enum(Re),Lt=z$1.object({id:z$1.string(),archived:z$1.boolean(),name:z$1.string(),description:z$1.string().optional(),parentId:z$1.string().optional(),account:z$1.object({type:z,number:z$1.string().optional()}),createdTime:z$1.string(),updatedTime:z$1.string()}),Dt=z$1.object({name:z$1.string(),description:z$1.string().optional(),parentId:z$1.string().optional(),account:z$1.object({type:z,number:z$1.string().optional()})}),_t=z$1.object({name:z$1.string().optional(),description:z$1.string().optional(),parentId:z$1.string().optional(),account:z$1.object({type:z.optional(),number:z$1.string().optional()}).optional()}),Nt=S;var Ot=["id","archived","name","shortName","parentId","createdTime","updatedTime"],vt=["name","createdTime","updatedTime"],Bt=z$1.object({id:z$1.string(),name:z$1.string(),shortName:z$1.string().optional(),description:z$1.string().optional(),parentId:z$1.string().optional(),archived:z$1.boolean(),createdTime:z$1.string(),updatedTime:z$1.string()}),Vt=z$1.object({name:z$1.string(),shortName:z$1.string().optional(),description:z$1.string().optional(),parentId:z$1.string().optional()}),Ut=z$1.object({name:z$1.string().optional(),shortName:z$1.string().optional(),description:z$1.string().optional(),parentId:z$1.string().optional()}),Ft=S;var Le=["OPEN","PARTIAL_PAYMENT","PAID","SCHEDULED","VOID","UNDEFINED"],De=["PAID","SCHEDULED","UNDEFINED"],qt=["id","archived","invoiceNumber","customerId","status","dueDate","invoiceDate","totalAmount","createdTime","updatedTime"],Mt=["invoiceDate","dueDate","totalAmount","createdTime","updatedTime"],_e=z$1.enum(Le),Ne=z$1.enum(De),j=z$1.object({accountingClassId:z$1.string().optional(),departmentId:z$1.string().optional(),jobId:z$1.string().optional(),locationId:z$1.string().optional()}),Oe=z$1.object({chartOfAccountId:z$1.string().optional(),accountingClassId:z$1.string().optional(),departmentId:z$1.string().optional(),jobId:z$1.string().optional(),locationId:z$1.string().optional(),itemId:z$1.string().optional()}),w=z$1.object({id:z$1.string().optional(),description:z$1.string().optional(),price:z$1.number().optional(),quantity:z$1.number().optional(),classifications:Oe.optional()}),ve=z$1.object({id:z$1.string().optional(),amount:z$1.number().optional(),status:Ne.optional(),date:z$1.string().optional()}),Y=z$1.object({percentage:z$1.number().optional()}),zt=z$1.object({id:z$1.string(),archived:z$1.boolean(),invoiceNumber:z$1.string().optional(),invoiceDate:z$1.string().optional(),dueDate:z$1.string().optional(),customerId:z$1.string().optional(),totalAmount:z$1.number().optional(),dueAmount:z$1.number().optional(),scheduledAmount:z$1.number().optional(),creditAmount:z$1.number().optional(),status:_e.optional(),exchangeRate:z$1.number().optional(),createdTime:z$1.string(),updatedTime:z$1.string(),invoiceLineItems:z$1.array(w).optional(),payToChartOfAccountId:z$1.string().optional(),payments:z$1.array(ve).optional(),classifications:j.optional(),salesTaxItemId:z$1.string().optional(),salesTaxTotal:z$1.number().optional(),salesTaxPercentage:z$1.number().optional(),enableCardPayment:z$1.boolean().optional(),convenienceFee:Y.optional(),invoicePdfId:z$1.string().optional()}),jt=z$1.object({id:z$1.string()}),wt=z$1.object({invoiceNumber:z$1.string(),invoiceDate:z$1.string(),dueDate:z$1.string(),customer:jt,invoiceLineItems:z$1.array(w.omit({id:true})),payToChartOfAccountId:z$1.string().optional(),classifications:j.optional(),salesTaxItemId:z$1.string().optional(),salesTaxTotal:z$1.number().optional(),salesTaxPercentage:z$1.number().optional(),enableCardPayment:z$1.boolean().optional(),convenienceFee:Y.optional()}),Yt=z$1.object({invoiceNumber:z$1.string().optional(),invoiceDate:z$1.string().optional(),dueDate:z$1.string().optional(),customerId:z$1.string().optional(),invoiceLineItems:z$1.array(w.omit({id:true})).optional(),payToChartOfAccountId:z$1.string().optional(),classifications:j.optional(),salesTaxItemId:z$1.string().optional(),salesTaxTotal:z$1.number().optional(),salesTaxPercentage:z$1.number().optional(),enableCardPayment:z$1.boolean().optional(),convenienceFee:Y.optional()}),kt=S;var Be=["BUSINESS","PERSON","NONE"],Kt=["id","archived","name","email","companyName","accountNumber","createdTime","updatedTime"],Gt=["name","createdTime","updatedTime"],k=z$1.enum(Be),K=z$1.object({firstName:z$1.string().optional(),lastName:z$1.string().optional()}),I=z$1.object({city:z$1.string().optional(),country:z$1.string().optional(),line1:z$1.string().optional(),zipOrPostalCode:z$1.string().optional(),line2:z$1.string().optional(),stateOrProvince:z$1.string().optional(),countryName:z$1.string().optional()}),Ve=z$1.object({amount:z$1.number().optional()}),$t=z$1.object({id:z$1.string(),archived:z$1.boolean(),email:z$1.string().optional(),name:z$1.string().optional(),companyName:z$1.string().optional(),contact:K.optional(),phone:z$1.string().optional(),fax:z$1.string().optional(),description:z$1.string().optional(),invoiceCurrency:z$1.string().optional(),accountType:k.optional(),paymentTermId:z$1.string().optional(),accountNumber:z$1.string().optional(),billingAddress:I.optional(),shippingAddress:I.optional(),balance:Ve.optional(),createdTime:z$1.string(),updatedTime:z$1.string()}),Ht=z$1.object({name:z$1.string(),email:z$1.string().optional(),companyName:z$1.string().optional(),contact:K.optional(),phone:z$1.string().optional(),fax:z$1.string().optional(),description:z$1.string().optional(),invoiceCurrency:z$1.string().optional(),accountType:k.optional(),paymentTermId:z$1.string().optional(),accountNumber:z$1.string().optional(),billingAddress:I.optional(),shippingAddress:I.optional()}),Wt=z$1.object({name:z$1.string().optional(),email:z$1.string().optional(),companyName:z$1.string().optional(),contact:K.optional(),phone:z$1.string().optional(),fax:z$1.string().optional(),description:z$1.string().optional(),invoiceCurrency:z$1.string().optional(),accountType:k.optional(),paymentTermId:z$1.string().optional(),accountNumber:z$1.string().optional(),billingAddress:I.optional(),shippingAddress:I.optional()}),Xt=S;var Ue=["APPROVING","PAID","VOID","SCHEDULED","FAILED","PENDING","UNDEFINED"],Fe=["ACH","CHECK","RPPS","INTERNATIONAL","VCARD","WALLET","OFFLINE","UNDEFINED"],qe=["DONE","FAILED","IN_PROGRESS","UNDEFINED"],Me=["BANK_ACCOUNT","CARD_ACCOUNT","AP_CARD","UNDEFINED"],ze=["CLEARED","VOID_PENDING","SCHEDULED","PAID","FAILED","UNDEFINED"],Qt=["id","vendorId","status","disbursementType","processDate","amount","createdTime","updatedTime"],Jt=["processDate","amount","createdTime","updatedTime"],je=z$1.enum(Ue),we=z$1.enum(Fe),Ye=z$1.enum(qe),ke=z$1.enum(Me),Ke=z$1.enum(ze),G=z$1.object({type:ke.optional(),id:z$1.string().optional()}),Ge=z$1.object({id:z$1.string().optional(),amount:z$1.number().optional()}),$=z$1.object({billId:z$1.string().optional(),amount:z$1.number().optional(),vendorCredits:z$1.array(Ge).optional()}),H=z$1.object({requestPayFaster:z$1.boolean().optional(),createBill:z$1.boolean().optional(),requestCheckDeliveryType:z$1.string().optional()}),$e=z$1.object({checkNumber:z$1.string().optional(),mailedDate:z$1.string().optional(),deliveryDate:z$1.string().optional(),trackingNumber:z$1.string().optional(),trackingUrl:z$1.string().optional()}),He=z$1.object({traceNumber:z$1.string().optional(),clearedDate:z$1.string().optional()}),We=z$1.object({confirmationNumber:z$1.string().optional()}),Xe=z$1.object({referenceNumber:z$1.string().optional(),clearedDate:z$1.string().optional()}),Qe=z$1.object({cardNumber:z$1.string().optional(),expirationDate:z$1.string().optional()}),Je=z$1.object({transactionId:z$1.string().optional()}),Ze=z$1.object({checkDisbursement:$e.optional(),achDisbursement:He.optional(),rppsDisbursement:We.optional(),internationalDisbursement:Xe.optional(),vcardDisbursement:Qe.optional(),walletDisbursement:Je.optional()}),et=z$1.object({voidDate:z$1.string().optional(),voidReason:z$1.string().optional(),voidedBy:z$1.string().optional()}),W=z$1.object({text:z$1.string().optional(),code:z$1.object({name:z$1.string().optional(),value:z$1.string().optional()}).optional()}),Zt=z$1.object({id:z$1.string(),amount:z$1.number().optional(),vendorId:z$1.string().optional(),vendorName:z$1.string().optional(),billId:z$1.string().optional(),description:z$1.string().optional(),processDate:z$1.string().optional(),billPayments:z$1.array($).optional(),fundingAccount:G.optional(),processingOptions:H.optional(),status:je.optional(),disbursementType:we.optional(),disbursementStatus:Ye.optional(),disbursementInfo:Ze.optional(),voidInfo:z$1.array(et).optional(),paymentPurpose:W.optional(),singleStatus:Ke.optional(),createdTime:z$1.string().optional(),updatedTime:z$1.string().optional()}),eo=z$1.object({vendorId:z$1.string(),amount:z$1.number().optional(),processDate:z$1.string().optional(),description:z$1.string().optional(),billPayments:z$1.array($).optional(),fundingAccount:G.optional(),processingOptions:H.optional(),paymentPurpose:W.optional()}),to=z$1.object({amount:z$1.number().optional(),processDate:z$1.string().optional(),description:z$1.string().optional(),billPayments:z$1.array($).optional(),fundingAccount:G.optional(),processingOptions:H.optional(),paymentPurpose:W.optional()}),oo=S;var tt=["NOT_APPLIED","PARTIALLY_APPLIED","FULLY_APPLIED"],no=["id","archived","customerId","status","creditDate","amount","createdTime","updatedTime"],ao=["creditDate","amount","createdTime","updatedTime"],ot=z$1.enum(tt),X=z$1.object({accountingClassId:z$1.string().optional(),departmentId:z$1.string().optional(),jobId:z$1.string().optional(),locationId:z$1.string().optional()}),nt=z$1.object({chartOfAccountId:z$1.string().optional(),accountingClassId:z$1.string().optional(),departmentId:z$1.string().optional(),jobId:z$1.string().optional(),locationId:z$1.string().optional(),itemId:z$1.string().optional()}),Q=z$1.object({id:z$1.string().optional(),description:z$1.string().optional(),price:z$1.number().optional(),quantity:z$1.number().optional(),amount:z$1.number().optional(),ratePercent:z$1.number().optional(),taxable:z$1.boolean().optional(),classifications:nt.optional()}),io=z$1.object({id:z$1.string(),archived:z$1.boolean(),customerId:z$1.string().optional(),referenceNumber:z$1.string().optional(),creditDate:z$1.string().optional(),description:z$1.string().optional(),salesTaxItemId:z$1.string().optional(),payToChartOfAccountId:z$1.string().optional(),payToBankAccountId:z$1.string().optional(),amount:z$1.number().optional(),appliedAmount:z$1.number().optional(),salesTaxTotal:z$1.number().optional(),salesTaxPercentage:z$1.number().optional(),status:ot.optional(),createdTime:z$1.string(),updatedTime:z$1.string(),creditMemoLineItems:z$1.array(Q).optional(),classifications:X.optional()}),ro=z$1.object({customerId:z$1.string(),referenceNumber:z$1.string().optional(),creditDate:z$1.string(),description:z$1.string().optional(),salesTaxItemId:z$1.string().optional(),payToChartOfAccountId:z$1.string().optional(),payToBankAccountId:z$1.string().optional(),salesTaxTotal:z$1.number().optional(),salesTaxPercentage:z$1.number().optional(),creditMemoLineItems:z$1.array(Q.omit({id:true})),classifications:X.optional()}),so=z$1.object({customerId:z$1.string().optional(),referenceNumber:z$1.string().optional(),creditDate:z$1.string().optional(),description:z$1.string().optional(),salesTaxItemId:z$1.string().optional(),payToChartOfAccountId:z$1.string().optional(),payToBankAccountId:z$1.string().optional(),salesTaxTotal:z$1.number().optional(),salesTaxPercentage:z$1.number().optional(),creditMemoLineItems:z$1.array(Q.omit({id:true})).optional(),classifications:X.optional()}),po=S;var b=class extends d{endpoint="/v3/vendors";bulkResponseKey="vendors"};var R=class extends d{endpoint="/v3/bills";bulkResponseKey="bills";constructor(a){super(a);}};var L=class extends d{endpoint="/v3/classifications/chart-of-accounts";bulkResponseKey="chartOfAccounts"};var D=class extends d{endpoint="/v3/classifications/accounting-classes";bulkResponseKey="accountingClasses"};var _=class extends d{endpoint="/v3/customers";bulkResponseKey="customers"};var N=class extends d{endpoint="/v3/invoices";bulkResponseKey="invoices"};var O=class extends d{endpoint="/v3/payments";bulkResponseKey="payments"};var v=class extends d{endpoint="/v3/credit-memos";bulkResponseKey="creditMemos"};var Z={sandbox:"https://gateway.stage.bill.com/connect",production:"https://gateway.bill.com/connect"},ee=class{credentials=null;autoLogin;session=null;baseUrl=Z.sandbox;vendors;bills;chartOfAccounts;accountingClasses;customers;invoices;payments;creditMemos;constructor(a){a&&"devKey"in a?(this.credentials={username:a.username,password:a.password,organizationId:a.organizationId,devKey:a.devKey,environment:a.environment},this.autoLogin=a.autoLogin??true,this.baseUrl=Z[a.environment??"sandbox"]):this.autoLogin=a?.autoLogin??true;let r=()=>this.getRequestConfig();this.vendors=new b(r),this.bills=new R(r),this.chartOfAccounts=new L(r),this.accountingClasses=new D(r),this.customers=new _(r),this.invoices=new N(r),this.payments=new O(r),this.creditMemos=new v(r);}getRequestConfig(){if(!this.credentials)throw new A("Client not configured. Call login() with credentials first.");return {baseUrl:this.baseUrl,devKey:this.credentials.devKey,sessionId:this.session?.sessionId}}async login(a){if(a&&(this.credentials=a,this.baseUrl=Z[a.environment??"sandbox"]),!this.credentials)throw new A("No credentials provided. Pass credentials to login() or constructor.");let r=await g({baseUrl:this.baseUrl,devKey:this.credentials.devKey},{method:"POST",path:"/v3/login",body:{username:this.credentials.username,password:this.credentials.password,organizationId:this.credentials.organizationId,devKey:this.credentials.devKey}});return this.session={sessionId:r.sessionId,organizationId:r.organizationId,userId:r.userId,apiEndPoint:r.apiEndPoint},this.session}async logout(){if(this.session)try{await g(this.getRequestConfig(),{method:"POST",path:"/v3/logout"});}finally{this.session=null;}}async ensureLoggedIn(){if(!this.session)if(this.autoLogin&&this.credentials)await this.login();else throw new P("Not logged in. Call login() with credentials first.")}isLoggedIn(){return this.session!==null}getSession(){return this.session?{...this.session}:null}async withAutoRetry(a){await this.ensureLoggedIn();try{return await a()}catch(r){if(r instanceof E&&this.autoLogin)return await this.login(),await a();throw r}}isConfigured(){return this.credentials!==null}}; export{Ot as ACCOUNTING_CLASS_FILTERABLE_FIELDS,vt as ACCOUNTING_CLASS_SORTABLE_FIELDS,Re as ACCOUNT_TYPES,Te as APPROVER_STATUSES,z as AccountTypeSchema,Ft as AccountingClassListParamsSchema,D as AccountingClassResource,Bt as AccountingClassSchema,Ae as ApproverStatusSchema,P as AuthenticationError,Ie as BILL_APPROVAL_STATUSES,It as BILL_FILTERABLE_FIELDS,fe as BILL_PAYMENT_STATUSES,Tt as BILL_SORTABLE_FIELDS,f as BillApiError,Ee as BillApprovalStatusSchema,xe as BillApproverSchema,x as BillClassificationsSchema,ee as BillClient,q as BillInvoiceSchema,be as BillLineItemClassificationsSchema,M as BillLineItemSchema,xt as BillListParamsSchema,Pe as BillPaymentStatusSchema,R as BillResource,Pt as BillSchema,J as BillVendorCreditSchema,bt as CHART_OF_ACCOUNT_FILTERABLE_FIELDS,Rt as CHART_OF_ACCOUNT_SORTABLE_FIELDS,no as CREDIT_MEMO_FILTERABLE_FIELDS,ao as CREDIT_MEMO_SORTABLE_FIELDS,tt as CREDIT_MEMO_STATUSES,Be as CUSTOMER_ACCOUNT_TYPES,Kt as CUSTOMER_FILTERABLE_FIELDS,Gt as CUSTOMER_SORTABLE_FIELDS,Nt as ChartOfAccountListParamsSchema,Lt as ChartOfAccountSchema,L as ChartOfAccountsResource,A as ConfigurationError,Vt as CreateAccountingClassRequestSchema,Et as CreateBillRequestSchema,Dt as CreateChartOfAccountRequestSchema,ro as CreateCreditMemoRequestSchema,Ht as CreateCustomerRequestSchema,wt as CreateInvoiceRequestSchema,eo as CreatePaymentRequestSchema,ht as CreateVendorRequestSchema,X as CreditMemoClassificationsSchema,nt as CreditMemoLineItemClassificationsSchema,Q as CreditMemoLineItemSchema,po as CreditMemoListParamsSchema,v as CreditMemoResource,io as CreditMemoSchema,ot as CreditMemoStatusSchema,k as CustomerAccountTypeSchema,I as CustomerAddressSchema,Ve as CustomerBalanceSchema,K as CustomerContactSchema,Xt as CustomerListParamsSchema,_ as CustomerResource,$t as CustomerSchema,qt as INVOICE_FILTERABLE_FIELDS,De as INVOICE_PAYMENT_STATUSES,Mt as INVOICE_SORTABLE_FIELDS,Le as INVOICE_STATUSES,j as InvoiceClassificationsSchema,Y as InvoiceConvenienceFeeSchema,Oe as InvoiceLineItemClassificationsSchema,w as InvoiceLineItemSchema,kt as InvoiceListParamsSchema,ve as InvoicePaymentSchema,Ne as InvoicePaymentStatusSchema,N as InvoiceResource,zt as InvoiceSchema,_e as InvoiceStatusSchema,B as NotFoundError,qe as PAYMENT_DISBURSEMENT_STATUSES,Fe as PAYMENT_DISBURSEMENT_TYPES,Qt as PAYMENT_FILTERABLE_FIELDS,Me as PAYMENT_FUNDING_ACCOUNT_TYPES,ze as PAYMENT_SINGLE_STATUSES,Jt as PAYMENT_SORTABLE_FIELDS,Ue as PAYMENT_STATUSES,He as PaymentAchDisbursementSchema,$ as PaymentBillPaymentSchema,$e as PaymentCheckDisbursementSchema,Ze as PaymentDisbursementInfoSchema,Ye as PaymentDisbursementStatusSchema,we as PaymentDisbursementTypeSchema,G as PaymentFundingAccountSchema,ke as PaymentFundingAccountTypeSchema,Xe as PaymentInternationalDisbursementSchema,oo as PaymentListParamsSchema,H as PaymentProcessingOptionsSchema,W as PaymentPurposeSchema,O as PaymentResource,We as PaymentRppsDisbursementSchema,Zt as PaymentSchema,Ke as PaymentSingleStatusSchema,je as PaymentStatusSchema,Qe as PaymentVcardDisbursementSchema,Ge as PaymentVendorCreditSchema,et as PaymentVoidInfoSchema,Je as PaymentWalletDisbursementSchema,E as SessionExpiredError,Ut as UpdateAccountingClassRequestSchema,At as UpdateBillRequestSchema,_t as UpdateChartOfAccountRequestSchema,so as UpdateCreditMemoRequestSchema,Wt as UpdateCustomerRequestSchema,Yt as UpdateInvoiceRequestSchema,to as UpdatePaymentRequestSchema,gt as UpdateVendorRequestSchema,te as VENDOR_ACCOUNT_TYPES,pe as VENDOR_ALTERNATE_PAY_BY_TYPES,ne as VENDOR_BANK_ACCOUNT_OWNER_TYPES,oe as VENDOR_BANK_ACCOUNT_TYPES,mt as VENDOR_FILTERABLE_FIELDS,re as VENDOR_PAY_BY_SUB_TYPES,ie as VENDOR_PAY_BY_TYPES,lt as VENDOR_SORTABLE_FIELDS,se as VENDOR_TAX_ID_TYPES,ae as VENDOR_VIRTUAL_CARD_STATUSES,V as ValidationError,U as VendorAccountTypeSchema,Ce as VendorAdditionalInfoSchema,F as VendorAddressSchema,ge as VendorAutoPaySchema,he as VendorBalanceSchema,me as VendorBankAccountOwnerTypeSchema,le as VendorBankAccountSchema,ce as VendorBankAccountTypeSchema,ft as VendorListParamsSchema,de as VendorPayByTypeSchema,Se as VendorPaymentInformationSchema,b as VendorResource,Ct as VendorSchema,ye as VendorVirtualCardSchema,ue as VendorVirtualCardStatusSchema};