tiime-sdk 3.0.0 → 3.0.1

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +3 -1
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var E=(s,e,t)=>{let n=new URL(e,s.endsWith("/")?s:`${s}/`);if(t)for(let[r,i]of Object.entries(t))i!=null&&n.searchParams.set(r,String(i));return n.href},q=s=>new Promise(e=>setTimeout(e,s)),D=s=>!!s?.includes("application/json")||!!s?.includes("+json"),I=s=>{let e=s.retry??0,t=s.retryDelay??500,n=new Set(s.retryStatusCodes??[]);return async(r,i)=>{let o=E(s.baseURL,r,i?.query),h=new Headers(s.headers);if(i?.headers)for(let[u,c]of Object.entries(i.headers))h.set(u,c);let l;i?.body!==void 0&&(i.body instanceof FormData?l=i.body:(h.set("Content-Type","application/json"),l=JSON.stringify(i.body))),s.onRequest&&await s.onRequest({options:{headers:h}});let p;for(let u=0;u<=e;u++){u>0&&await q(t);let c;try{c=await fetch(o,{method:i?.method??"GET",headers:h,body:l});}catch(m){if(p=m,u<e)continue;throw m}if(!c.ok&&n.has(c.status)&&(p=c,u<e))continue;if(!c.ok&&s.onResponseError){let m;try{m=await c.clone().json();}catch{}let C=Object.assign(c,{_data:m});s.onResponseError({request:o,response:C});}let A=c.headers.get("content-type");return c.status===204||!A?void 0:D(A)?c.json():c.arrayBuffer()}throw p}},R=async(s,e)=>{let t=await fetch(s,e);if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);return t.json()};var $="auth0.tiime.fr",B="iEbsbe3o66gcTBfGRa012kj1Rb6vjAND",M="https://chronos/",d=class{tokens=null;credentials=null;tokenStorage;credentialStorage;constructor(e={}){if(this.tokenStorage=e.tokenStorage??null,this.credentialStorage=e.credentialStorage??null,e.tokens){this.tokens=e.tokens;return}if(e.email&&e.password){this.credentials={email:e.email,password:e.password};return}let t=process.env.TIIME_ACCESS_TOKEN;if(t){this.tokens={access_token:t,expires_at:Number.MAX_SAFE_INTEGER};return}let n=process.env.TIIME_EMAIL,r=process.env.TIIME_PASSWORD;if(n&&r){this.credentials={email:n,password:r};return}this.tokenStorage&&(this.tokens=this.tokenStorage.load());}async login(e,t){let n=await R(`https://${$}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"password",client_id:B,audience:M,scope:"openid email",username:e,password:t})});return this.tokens={access_token:n.access_token,expires_at:Date.now()+n.expires_in*1e3},this.tokenStorage?.save(this.tokens),this.credentialStorage?.save(e,t),this.tokens}async getValidToken(){if(!this.tokens||this.isExpired()){let e=this.credentials??this.credentialStorage?.load()??null;if(e)return (await this.login(e.email,e.password)).access_token;throw new Error(this.tokens?"Token expired. Provide credentials via options, TIIME_EMAIL/TIIME_PASSWORD env vars, or run `tiime auth login`.":"Not authenticated. Provide credentials via options, TIIME_EMAIL/TIIME_PASSWORD env vars, or run `tiime auth login`.")}return this.tokens.access_token}isAuthenticated(){return this.tokens!==null&&!this.isExpired()}logout(){this.tokens=null,this.tokenStorage?.clear();}getTokenInfo(){if(!this.tokens)return {email:null,expiresAt:null};try{return {email:JSON.parse(Buffer.from(this.tokens.access_token.split(".")[1],"base64").toString())["tiime/userEmail"]||null,expiresAt:new Date(this.tokens.expires_at)}}catch{return {email:null,expiresAt:new Date(this.tokens.expires_at)}}}isExpired(){return this.tokens?Date.now()>=this.tokens.expires_at-6e4:true}};var g=class extends Error{constructor(t,n,r,i){super(t);this.status=n;this.endpoint=r;this.details=i;this.name="TiimeError";}toJSON(){return {error:this.name,message:this.message,status:this.status,endpoint:this.endpoint,details:this.details}}};var a=class{constructor(e,t){this.fetch=e;this.companyId=t;}url(e){return `/companies/${this.companyId}${e}`}};var f=class extends a{list(e){return this.fetch(this.url("/bank_accounts"),{query:e!==void 0?{enabled:e}:void 0})}get(e){return this.fetch(this.url(`/bank_accounts/${e}`))}async balance(){return (await this.list(true)).map(t=>({name:t.name,balance_amount:t.balance_amount,currency:t.balance_currency}))}};var y=class extends a{list(e){let t=((e?.page??1)-1)*(e?.pageSize??100),n=t+(e?.pageSize??100),{page:r,pageSize:i,from:o,to:h,search:l,...p}=e??{},u={...p};return o&&(u.transaction_date_start=o),h&&(u.transaction_date_end=h),l&&(u.wording=l),this.fetch(this.url("/bank_transactions"),{query:{hide_refused:false,...u},headers:{Accept:"application/vnd.tiime.bank_transactions.v2+json",Range:`items=${t}-${n}`}})}async listAll(e){let t=e?.pageSize??200,n=[],r=1,i=true;for(;i;){let o=await this.list({...e,page:r,pageSize:t});n.push(...o.transactions),i=o.transactions.length===t,r++;}return n}unimputed(){return this.fetch(this.url("/bank_transactions/unimputed"))}get(e){return this.fetch(this.url(`/bank_transactions/${e}`))}labelSuggestions(e){return this.fetch(this.url(`/bank_transactions/${e}/label_suggestions`),{headers:{Accept:"application/vnd.tiime.bank_transactions.label_suggestions.v2+json"}})}impute(e,t){return this.fetch(this.url(`/bank_transactions/${e}`),{method:"PATCH",body:{imputations:t}})}matchDocuments(e,t){return this.fetch(this.url(`/bank_transactions/${e}/document_matchings`),{method:"PUT",body:{documents:t.map(n=>({id:n}))}})}getMatchings(e){return this.fetch(this.url(`/bank_transactions/${e}/matchings`))}};var k=class extends a{list(e){return this.fetch(this.url("/clients"),{query:e,headers:{Accept:"application/vnd.tiime.timeline.v2+json",Range:"items=0-*"}})}get(e){return this.fetch(this.url(`/clients/${e}`))}create(e){return this.fetch(this.url("/clients"),{method:"POST",body:e})}search(e){return this.fetch(this.url("/clients"),{query:{search:e},headers:{Accept:"application/vnd.tiime.timeline.v2+json",Range:"items=0-*"}})}};var b=class extends a{get(){return this.fetch(this.url(""))}users(){return this.fetch(this.url("/users"))}appConfig(){return this.fetch(this.url("/app_config"))}accountingPeriod(e=1){return this.fetch(this.url("/accounting_period/current"),{query:{range_year:e}})}tiles(e){return this.fetch(this.url("/tiles"),{query:{keys:e.join(",")}})}dashboardBlocks(e="monitoring"){return this.fetch(this.url("/dashboard_blocks"),{query:{sorts:"rank:asc",display_group:e}})}};var _=class extends a{list(e){let t=((e?.page??1)-1)*(e?.pageSize??25),n=t+(e?.pageSize??25),{page:r,pageSize:i,...o}=e??{};return this.fetch(this.url("/documents"),{query:{sorts:"created_at:desc",expand:"file_family,preview_available",...o},headers:{Accept:"application/vnd.tiime.documents.v2+json,application/vnd.tiime.docs.query+json,application/vnd.tiime.docs.imputation+json",Range:`items=${t}-${n}`}})}categories(){return this.fetch(this.url("/document_categories"),{headers:{Accept:"application/vnd.tiime.documents.v3+json"}})}preview(e){return this.fetch(this.url(`/documents/${e}/preview`))}upload(e,t,n){let r=new FormData;return r.append("file",new Blob([e]),t),n&&r.append("type",n),this.fetch(this.url("/documents"),{method:"POST",body:r})}searchMatchable(e){return this.fetch(this.url("/documents"),{query:{matchable:true,q:e},headers:{Accept:"application/vnd.tiime.documents.v3+json,application/vnd.tiime.docs.imputation+json",Range:"items=0-25"}})}async download(e){return this.fetch(this.url(`/documents/${e}/download`),{headers:{Accept:"application/octet-stream"}})}};var v=class extends a{list(e="metadata.date:desc"){return this.fetch(this.url("/expense_reports"),{query:{expand:"total_amount",sorts:e},headers:{Range:"items=0-25"}})}get(e){return this.fetch(this.url(`/expense_reports/${e}`))}create(e){return this.fetch(this.url("/expense_reports"),{method:"POST",body:e})}};var w=class extends a{list(e){let t=((e?.page??1)-1)*(e?.pageSize??25),n=t+(e?.pageSize??25),r={sorts:e?.sorts??"invoice_number:desc"};return e?.status&&(r.status=e.status),this.fetch(this.url("/invoices"),{query:r,headers:{Range:`items=${t}-${n}`}})}async listAll(e){let t=e?.pageSize??100,n=[],r=1,i=true;for(;i;){let o=await this.list({sorts:e?.sorts,status:e?.status,page:r,pageSize:t});n.push(...o),i=o.length===t,r++;}return n}get(e){return this.fetch(this.url(`/invoices/${e}`))}create(e){let t={...e,lines:e.lines?.map(n=>({...n}))};for(let n of t.lines??[])n.line_amount=n.quantity*n.unit_amount,n.sequence??=1,n.invoicing_category_type??="benefit",n.discount_description??="",n.discount_amount??=null,n.discount_percentage??=null;return this.fetch(this.url("/invoices"),{method:"POST",body:t})}update(e,t){return this.fetch(this.url(`/invoices/${e}`),{method:"PUT",body:t})}send(e,t){return this.fetch(this.url(`/invoices/${e}/send`),{method:"POST",body:t})}async downloadPdf(e){return this.fetch(this.url(`/invoices/${e}/pdf`),{headers:{Accept:"application/pdf"}})}delete(e){return this.fetch(this.url(`/invoices/${e}`),{method:"DELETE"})}async duplicate(e,t){let n=await this.get(e),r=new Date().toISOString().split("T")[0],i=n.lines.map(o=>({description:o.description,quantity:t?.quantity??o.quantity,unit_amount:o.unit_amount,vat_type:o.vat_type,invoicing_unit:o.invoicing_unit,invoicing_category_type:o.invoicing_category_type,article:o.article}));return this.create({client:n.client_id?{id:n.client_id}:null,emission_date:t?.emission_date??r,title:n.title,title_enabled:!!n.title,lines:i,status:"draft"})}};var T=class extends a{list(){return this.fetch(this.url("/labels"),{headers:{Accept:"application/vnd.tiime.labels.v2+json"}})}standard(){return this.fetch(this.url("/standard_labels"))}tags(){return this.fetch(this.url("/tags"),{query:{expand:"tag_detail"}})}};var S=class extends a{list(e="invoices"){return this.fetch(this.url("/quotations"),{query:{expand:e},headers:{Range:"items=0-25"}})}get(e){return this.fetch(this.url(`/quotations/${e}`))}create(e){let t={...e,lines:e.lines?.map(n=>({...n}))};for(let n of t.lines??[])n.line_amount=n.quantity*n.unit_amount,n.sequence??=1,n.invoicing_category_type??="benefit",n.discount_description??="",n.discount_amount??=null,n.discount_percentage??=null;return this.fetch(this.url("/quotations"),{method:"POST",body:t})}async downloadPdf(e){return this.fetch(this.url(`/quotations/${e}/pdf`),{headers:{Accept:"application/pdf"}})}send(e,t){return this.fetch(this.url(`/quotations/${e}/send`),{method:"POST",body:t})}};var P=class{constructor(e){this.fetch=e;}me(){return this.fetch("/users/me")}legalInformations(){return this.fetch("/users/me/legal_informations")}settings(e){return this.fetch(`/users/me/companies/${e}/settings`)}};var O="https://chronos-api.tiime-apps.com/v1",x=class{fetch;tokenManager;companyId;constructor(e){this.companyId=e.companyId,this.tokenManager=e.tokenManager??new d({tokens:e.tokens,email:e.email,password:e.password}),this.fetch=I({baseURL:O,retry:2,retryDelay:500,retryStatusCodes:[408,429,500,502,503,504],headers:{"tiime-app":"tiime","tiime-app-version":"4.30.3","tiime-app-platform":"cli"},onRequest:async({options:t})=>{let n=await this.tokenManager.getValidToken();t.headers.set("Authorization",`Bearer ${n}`);},onResponseError:({request:t,response:n})=>{throw new g(n.statusText||`HTTP ${n.status}`,n.status,String(t),n._data)}});}listCompanies(){return this.fetch("/companies",{headers:{Accept:"application/vnd.tiime.companies.v2+json",Range:"items=0-101"}})}get users(){return new P(this.fetch)}get company(){return new b(this.fetch,this.companyId)}get clients(){return new k(this.fetch,this.companyId)}get invoices(){return new w(this.fetch,this.companyId)}get quotations(){return new S(this.fetch,this.companyId)}get bankAccounts(){return new f(this.fetch,this.companyId)}get bankTransactions(){return new y(this.fetch,this.companyId)}get documents(){return new _(this.fetch,this.companyId)}get expenseReports(){return new v(this.fetch,this.companyId)}get labels(){return new T(this.fetch,this.companyId)}};
1
+ var E=(s,e,t)=>{let n=new URL(e,s.endsWith("/")?s:`${s}/`);if(t)for(let[r,i]of Object.entries(t))i!=null&&n.searchParams.set(r,String(i));return n.href},q=s=>new Promise(e=>setTimeout(e,s)),D=s=>!!s?.includes("application/json")||!!s?.includes("+json"),I=s=>{let e=s.retry??0,t=s.retryDelay??500,n=new Set(s.retryStatusCodes??[]);return async(r,i)=>{let o=E(s.baseURL,r,i?.query),h=new Headers(s.headers);if(i?.headers)for(let[u,c]of Object.entries(i.headers))h.set(u,c);let l;i?.body!==void 0&&(i.body instanceof FormData?l=i.body:(h.set("Content-Type","application/json"),l=JSON.stringify(i.body))),s.onRequest&&await s.onRequest({options:{headers:h}});let p;for(let u=0;u<=e;u++){u>0&&await q(t);let c;try{c=await fetch(o,{method:i?.method??"GET",headers:h,body:l});}catch(m){if(p=m,u<e)continue;throw m}if(!c.ok&&n.has(c.status)&&(p=c,u<e))continue;if(!c.ok&&s.onResponseError){let m;try{m=await c.clone().json();}catch{}let C=Object.assign(c,{_data:m});s.onResponseError({request:o,response:C});}let A=c.headers.get("content-type");return c.status===204||!A?void 0:D(A)?c.json():c.arrayBuffer()}throw p}},R=async(s,e)=>{let t=await fetch(s,e);if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);return t.json()};var $="auth0.tiime.fr",B="iEbsbe3o66gcTBfGRa012kj1Rb6vjAND",M="https://chronos/",d=class{tokens=null;credentials=null;tokenStorage;credentialStorage;constructor(e={}){if(this.tokenStorage=e.tokenStorage??null,this.credentialStorage=e.credentialStorage??null,e.tokens){this.tokens=e.tokens;return}if(e.email&&e.password){this.credentials={email:e.email,password:e.password};return}let t=process.env.TIIME_ACCESS_TOKEN;if(t){this.tokens={access_token:t,expires_at:Number.MAX_SAFE_INTEGER};return}let n=process.env.TIIME_EMAIL,r=process.env.TIIME_PASSWORD;if(n&&r){this.credentials={email:n,password:r};return}this.tokenStorage&&(this.tokens=this.tokenStorage.load());}async login(e,t){let n=await R(`https://${$}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"password",client_id:B,audience:M,scope:"openid email",username:e,password:t})});return this.tokens={access_token:n.access_token,expires_at:Date.now()+n.expires_in*1e3},this.tokenStorage?.save(this.tokens),this.credentialStorage?.save(e,t),this.tokens}async getValidToken(){if(!this.tokens||this.isExpired()){let e=this.credentials??this.credentialStorage?.load()??null;if(e)return (await this.login(e.email,e.password)).access_token;throw new Error(this.tokens?"Token expired. Provide credentials via options, TIIME_EMAIL/TIIME_PASSWORD env vars, or run `tiime auth login`.":"Not authenticated. Provide credentials via options, TIIME_EMAIL/TIIME_PASSWORD env vars, or run `tiime auth login`.")}return this.tokens.access_token}isAuthenticated(){return this.tokens!==null&&!this.isExpired()}logout(){this.tokens=null,this.tokenStorage?.clear();}getTokenInfo(){if(!this.tokens)return {email:null,expiresAt:null};try{return {email:JSON.parse(Buffer.from(this.tokens.access_token.split(".")[1],"base64").toString())["tiime/userEmail"]||null,expiresAt:new Date(this.tokens.expires_at)}}catch{return {email:null,expiresAt:new Date(this.tokens.expires_at)}}}isExpired(){return this.tokens?Date.now()>=this.tokens.expires_at-6e4:true}};var g=class extends Error{constructor(t,n,r,i){super(t);this.status=n;this.endpoint=r;this.details=i;this.name="TiimeError";}toJSON(){return {error:this.name,message:this.message,status:this.status,endpoint:this.endpoint,details:this.details}}};var a=class{constructor(e,t){this.fetch=e;this.companyId=t;}url(e){return `companies/${this.companyId}${e}`}};var f=class extends a{list(e){return this.fetch(this.url("/bank_accounts"),{query:e!==void 0?{enabled:e}:void 0})}get(e){return this.fetch(this.url(`/bank_accounts/${e}`))}async balance(){return (await this.list(true)).map(t=>({name:t.name,balance_amount:t.balance_amount,currency:t.balance_currency}))}};var y=class extends a{list(e){let t=((e?.page??1)-1)*(e?.pageSize??100),n=t+(e?.pageSize??100),{page:r,pageSize:i,from:o,to:h,search:l,...p}=e??{},u={...p};return o&&(u.transaction_date_start=o),h&&(u.transaction_date_end=h),l&&(u.wording=l),this.fetch(this.url("/bank_transactions"),{query:{hide_refused:false,...u},headers:{Accept:"application/vnd.tiime.bank_transactions.v2+json",Range:`items=${t}-${n}`}})}async listAll(e){let t=e?.pageSize??200,n=[],r=1,i=true;for(;i;){let o=await this.list({...e,page:r,pageSize:t});n.push(...o.transactions),i=o.transactions.length===t,r++;}return n}unimputed(){return this.fetch(this.url("/bank_transactions/unimputed"))}get(e){return this.fetch(this.url(`/bank_transactions/${e}`))}labelSuggestions(e){return this.fetch(this.url(`/bank_transactions/${e}/label_suggestions`),{headers:{Accept:"application/vnd.tiime.bank_transactions.label_suggestions.v2+json"}})}impute(e,t){return this.fetch(this.url(`/bank_transactions/${e}`),{method:"PATCH",body:{imputations:t}})}matchDocuments(e,t){return this.fetch(this.url(`/bank_transactions/${e}/document_matchings`),{method:"PUT",body:{documents:t.map(n=>({id:n}))}})}getMatchings(e){return this.fetch(this.url(`/bank_transactions/${e}/matchings`))}};var k=class extends a{list(e){return this.fetch(this.url("/clients"),{query:e,headers:{Accept:"application/vnd.tiime.timeline.v2+json",Range:"items=0-*"}})}get(e){return this.fetch(this.url(`/clients/${e}`))}create(e){return this.fetch(this.url("/clients"),{method:"POST",body:e})}search(e){return this.fetch(this.url("/clients"),{query:{search:e},headers:{Accept:"application/vnd.tiime.timeline.v2+json",Range:"items=0-*"}})}};var b=class extends a{get(){return this.fetch(this.url(""))}users(){return this.fetch(this.url("/users"))}appConfig(){return this.fetch(this.url("/app_config"))}accountingPeriod(e=1){return this.fetch(this.url("/accounting_period/current"),{query:{range_year:e}})}tiles(e){return this.fetch(this.url("/tiles"),{query:{keys:e.join(",")}})}dashboardBlocks(e="monitoring"){return this.fetch(this.url("/dashboard_blocks"),{query:{sorts:"rank:asc",display_group:e}})}};var _=class extends a{list(e){let t=((e?.page??1)-1)*(e?.pageSize??25),n=t+(e?.pageSize??25),{page:r,pageSize:i,...o}=e??{};return this.fetch(this.url("/documents"),{query:{sorts:"created_at:desc",expand:"file_family,preview_available",...o},headers:{Accept:"application/vnd.tiime.documents.v2+json,application/vnd.tiime.docs.query+json,application/vnd.tiime.docs.imputation+json",Range:`items=${t}-${n}`}})}categories(){return this.fetch(this.url("/document_categories"),{headers:{Accept:"application/vnd.tiime.documents.v3+json"}})}preview(e){return this.fetch(this.url(`/documents/${e}/preview`))}upload(e,t,n){let r=new FormData;return r.append("file",new Blob([e]),t),n&&r.append("type",n),this.fetch(this.url("/documents"),{method:"POST",body:r})}searchMatchable(e){return this.fetch(this.url("/documents"),{query:{matchable:true,q:e},headers:{Accept:"application/vnd.tiime.documents.v3+json,application/vnd.tiime.docs.imputation+json",Range:"items=0-25"}})}async download(e){return this.fetch(this.url(`/documents/${e}/download`),{headers:{Accept:"application/octet-stream"}})}};var v=class extends a{list(e="metadata.date:desc"){return this.fetch(this.url("/expense_reports"),{query:{expand:"total_amount",sorts:e},headers:{Range:"items=0-25"}})}get(e){return this.fetch(this.url(`/expense_reports/${e}`))}create(e){return this.fetch(this.url("/expense_reports"),{method:"POST",body:e})}};var w=class extends a{list(e){let t=((e?.page??1)-1)*(e?.pageSize??25),n=t+(e?.pageSize??25),r={sorts:e?.sorts??"invoice_number:desc"};return e?.status&&(r.status=e.status),this.fetch(this.url("/invoices"),{query:r,headers:{Range:`items=${t}-${n}`}})}async listAll(e){let t=e?.pageSize??100,n=[],r=1,i=true;for(;i;){let o=await this.list({sorts:e?.sorts,status:e?.status,page:r,pageSize:t});n.push(...o),i=o.length===t,r++;}return n}get(e){return this.fetch(this.url(`/invoices/${e}`))}create(e){let t={...e,lines:e.lines?.map(n=>({...n}))};for(let n of t.lines??[])n.line_amount=n.quantity*n.unit_amount,n.sequence??=1,n.invoicing_category_type??="benefit",n.discount_description??="",n.discount_amount??=null,n.discount_percentage??=null;return this.fetch(this.url("/invoices"),{method:"POST",body:t})}update(e,t){return this.fetch(this.url(`/invoices/${e}`),{method:"PUT",body:t})}send(e,t){return this.fetch(this.url(`/invoices/${e}/send`),{method:"POST",body:t})}async downloadPdf(e){return this.fetch(this.url(`/invoices/${e}/pdf`),{headers:{Accept:"application/pdf"}})}delete(e){return this.fetch(this.url(`/invoices/${e}`),{method:"DELETE"})}async duplicate(e,t){let n=await this.get(e),r=new Date().toISOString().split("T")[0],i=n.lines.map(o=>({description:o.description,quantity:t?.quantity??o.quantity,unit_amount:o.unit_amount,vat_type:o.vat_type,invoicing_unit:o.invoicing_unit,invoicing_category_type:o.invoicing_category_type,article:o.article}));return this.create({client:n.client_id?{id:n.client_id}:null,emission_date:t?.emission_date??r,title:n.title,title_enabled:!!n.title,lines:i,status:"draft"})}};var T=class extends a{list(){return this.fetch(this.url("/labels"),{headers:{Accept:"application/vnd.tiime.labels.v2+json"}})}standard(){return this.fetch(this.url("/standard_labels"))}tags(){return this.fetch(this.url("/tags"),{query:{expand:"tag_detail"}})}};var S=class extends a{list(e="invoices"){return this.fetch(this.url("/quotations"),{query:{expand:e},headers:{Range:"items=0-25"}})}get(e){return this.fetch(this.url(`/quotations/${e}`))}create(e){let t={...e,lines:e.lines?.map(n=>({...n}))};for(let n of t.lines??[])n.line_amount=n.quantity*n.unit_amount,n.sequence??=1,n.invoicing_category_type??="benefit",n.discount_description??="",n.discount_amount??=null,n.discount_percentage??=null;return this.fetch(this.url("/quotations"),{method:"POST",body:t})}async downloadPdf(e){return this.fetch(this.url(`/quotations/${e}/pdf`),{headers:{Accept:"application/pdf"}})}send(e,t){return this.fetch(this.url(`/quotations/${e}/send`),{method:"POST",body:t})}};var P=class{constructor(e){this.fetch=e;}me(){return this.fetch("users/me")}legalInformations(){return this.fetch("users/me/legal_informations")}settings(e){return this.fetch(`users/me/companies/${e}/settings`)}};var O="https://chronos-api.tiime-apps.com/v1",x=class{fetch;tokenManager;companyId;constructor(e){this.companyId=e.companyId,this.tokenManager=e.tokenManager??new d({tokens:e.tokens,email:e.email,password:e.password}),this.fetch=I({baseURL:O,retry:2,retryDelay:500,retryStatusCodes:[408,429,500,502,503,504],headers:{"tiime-app":"tiime","tiime-app-version":"4.30.3","tiime-app-platform":"cli"},onRequest:async({options:t})=>{let n=await this.tokenManager.getValidToken();t.headers.set("Authorization",`Bearer ${n}`);},onResponseError:({request:t,response:n})=>{throw new g(n.statusText||`HTTP ${n.status}`,n.status,String(t),n._data)}});}listCompanies(){return this.fetch("companies",{headers:{Accept:"application/vnd.tiime.companies.v2+json",Range:"items=0-101"}})}get users(){return new P(this.fetch)}get company(){return new b(this.fetch,this.companyId)}get clients(){return new k(this.fetch,this.companyId)}get invoices(){return new w(this.fetch,this.companyId)}get quotations(){return new S(this.fetch,this.companyId)}get bankAccounts(){return new f(this.fetch,this.companyId)}get bankTransactions(){return new y(this.fetch,this.companyId)}get documents(){return new _(this.fetch,this.companyId)}get expenseReports(){return new v(this.fetch,this.companyId)}get labels(){return new T(this.fetch,this.companyId)}};
2
2
  export{x as TiimeClient,g as TiimeError,d as TokenManager};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiime-sdk",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "TypeScript SDK for Tiime accounting API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -47,6 +47,7 @@
47
47
  "devDependencies": {
48
48
  "@biomejs/biome": "^2.4.6",
49
49
  "@types/node": "^25.3.5",
50
+ "@vitest/coverage-v8": "^4.0.18",
50
51
  "tsup": "^8.5.1",
51
52
  "typescript": "^5.9.3",
52
53
  "vitest": "^4.0.18"
@@ -56,6 +57,7 @@
56
57
  "dev": "tsup --watch",
57
58
  "lint": "biome check src/",
58
59
  "format": "biome format --write src/",
60
+ "typecheck": "tsc",
59
61
  "test": "vitest run",
60
62
  "test:watch": "vitest",
61
63
  "release": "changeset publish"