@timesheet/sdk 1.1.0 → 1.1.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.
- package/CHANGELOG.md +7 -1
- package/dist/http/ApiClient.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +4 -4
- package/dist/resources/TagResource.d.ts +1 -2
- package/dist/resources/TagResource.d.ts.map +1 -1
- package/dist/resources/TodoResource.d.ts +1 -2
- package/dist/resources/TodoResource.d.ts.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
8
|
|
|
9
|
+
## [1.1.1] - 2026-05-24
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- `TodoResource.list()` and `TagResource.list()` now correctly parse the paginated wrapper response from `GET /v1/todos` and `GET /v1/tags`. 1.1.0 (Todo) and earlier (Tag) treated the response as a bare `Todo[]` / `Tag[]`, which silently produced a `NavigablePage` whose `.items` was the wrapper object instead of the actual items array. The backend has always returned the `ToDoList` / `TagList` wrapper; the bug was on the SDK side.
|
|
13
|
+
|
|
9
14
|
## [1.1.0] - 2026-05-23
|
|
10
15
|
|
|
11
16
|
### Added
|
|
@@ -163,7 +168,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
163
168
|
- Removed complex mocking in favor of simple validation tests
|
|
164
169
|
- Updated GitHub Actions to use non-deprecated action versions
|
|
165
170
|
|
|
166
|
-
[Unreleased]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.1.
|
|
171
|
+
[Unreleased]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.1.1...HEAD
|
|
172
|
+
[1.1.1]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.1.0...v1.1.1
|
|
167
173
|
[1.1.0]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.0.6...v1.1.0
|
|
168
174
|
[1.0.6]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.0.4...v1.0.6
|
|
169
175
|
[1.0.5]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.0.4...v1.0.5
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiClient.d.ts","sourceRoot":"","sources":["../../src/http/ApiClient.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAiB,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"ApiClient.d.ts","sourceRoot":"","sources":["../../src/http/ApiClient.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAiB,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAY9C,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;gBAE/B,MAAM,EAAE,YAAY;IAiC1B,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAoElD,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAWzE,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAY1F,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAazF,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,CAAC,EACV,IAAI,CAAC,EAAE,OAAO,GACb,OAAO,CAAC,CAAC,CAAC;IAcP,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;IAcpE,OAAO,CAAC,KAAK;IAOb,UAAU,IAAI,MAAM;IAQd,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;CAMpE"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var we=Object.create;var ae=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var ke=Object.getPrototypeOf,Ue=Object.prototype.hasOwnProperty;var De=(s,e)=>{for(var t in e)ae(s,t,{get:e[t],enumerable:!0})},Pe=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $e(e))!Ue.call(s,o)&&o!==t&&ae(s,o,{get:()=>e[o],enumerable:!(r=Ee(e,o))||r.enumerable});return s};var P=(s,e,t)=>(t=s!=null?we(ke(s)):{},Pe(e||!s||!s.__esModule?ae(t,"default",{value:s,enumerable:!0}):t,s)),Ie=s=>Pe(ae({},"__esModule",{value:!0}),s);var _e={};De(_e,{AbsenceResource:()=>W,AbsenceTypeResource:()=>B,ApiClient:()=>x,ApiKeyAuth:()=>re,AutomationResource:()=>O,ContractResource:()=>H,ContractTemplateResource:()=>K,DocumentReportResource:()=>J,DocumentResource:()=>L,EventResource:()=>j,ExpenseReportResource:()=>G,ExpenseResource:()=>I,ExportResource:()=>Z,NavigablePage:()=>p,NoteReportResource:()=>Y,NoteResource:()=>N,OAuth21Auth:()=>de,OAuth2Auth:()=>v,OAuthDiscovery:()=>se,OrganizationResource:()=>w,PauseResource:()=>q,ProfileResource:()=>M,ProjectResource:()=>$,RateResource:()=>U,ReportsClient:()=>X,Resource:()=>i,RetryConfig:()=>oe,SettingsResource:()=>S,TagResource:()=>D,TaskReportResource:()=>V,TaskResource:()=>k,TeamResource:()=>E,TimerResource:()=>_,TimesheetApiError:()=>l,TimesheetAuthError:()=>ee,TimesheetClient:()=>pe,TimesheetRateLimitError:()=>te,TodoResource:()=>z,WebhookEvents:()=>qe,WebhookResource:()=>F,combineWebhookEvents:()=>Me,createClient:()=>Le,discoverOAuth:()=>Ne,generateCodeChallenge:()=>ye,generateCodeVerifier:()=>be,generatePkceCodePair:()=>me,getDefaultDiscovery:()=>Ce,isValidCodeVerifier:()=>he});module.exports=Ie(_e);var C=P(require("axios"));var l=class s extends Error{constructor(e,t,r,o){let a=t?o?`${e} (HTTP ${t}, Code: ${o})`:`${e} (HTTP ${t})`:e;super(a),this.name="TimesheetApiError",this.statusCode=t,this.responseBody=r,this.errorCode=o,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,s)}};var ee=class extends l{constructor(e,t=401,r){super(e,t,r,"authentication_error"),this.name="TimesheetAuthError"}};var te=class extends l{constructor(e,t){super(e,429,void 0,"rate_limit_exceeded"),this.name="TimesheetRateLimitError",this.retryAfter=t}getRetryAfterDate(){if(!this.retryAfter)return null;let e=Number(this.retryAfter);if(!isNaN(e))return new Date(e*1e3);let t=new Date(this.retryAfter);return isNaN(t.getTime())?null:t}};var x=class{constructor(e){this.config=e,this.httpClient=e.httpClient||C.default.create({baseURL:e.baseUrl,timeout:3e4,headers:{"User-Agent":"Timesheet-TypeScript-SDK/1.1.0","Content-Type":"application/json"}}),this.httpClient.interceptors.request.use(async t=>{if(t.url!=="/oauth/token"&&this.config.authentication){let r=await this.config.authentication.getAuthHeaders();if(r)for(let[o,a]of Object.entries(r))t.headers.set(o,a)}return t})}async request(e){let t=null,r=this.config.retryConfig;for(let o=0;o<=r.maxRetries;o++)try{return(await this.httpClient.request(e)).data}catch(a){if(t=a,C.default.isAxiosError(a)&&a.response?.status===401){let c=a.response.data;throw new ee(c?.message||"Authentication failed",401,JSON.stringify(c))}if(C.default.isAxiosError(a)&&a.response?.status===429){let c=a.response.headers["retry-after"];throw new te("Rate limit exceeded",c)}let m=C.default.isAxiosError(a)?a.response?.status:void 0;if(o<r.maxRetries&&m&&r.retryableStatusCodes.includes(m)){let c=Math.min(r.initialDelay*Math.pow(r.backoffMultiplier,o),r.maxDelay);await this.sleep(c);continue}if(C.default.isAxiosError(a)){let c=a.response?.data;throw new l(c?.message||a.message,a.response?.status,JSON.stringify(c),c?.code)}else throw a instanceof Error?new l(a.message):new l("Unknown error occurred")}throw t||new Error("Unknown error")}async get(e,t){return this.request({method:"GET",url:e,params:t})}async post(e,t,r){return this.request({method:"POST",url:e,data:t,params:r})}async put(e,t,r){return this.request({method:"PUT",url:e,data:t,params:r})}async delete(e,t,r){return this.request({method:"DELETE",url:e,data:r,params:t})}async postMultipart(e,t){return this.request({method:"POST",url:e,data:t,headers:{"Content-Type":"multipart/form-data"}})}sleep(e){return new Promise(t=>setTimeout(t,e))}getBaseUrl(){return this.config.baseUrl}async getAuthHeaders(){if(this.config.authentication)return this.config.authentication.getAuthHeaders()}};var re=class{constructor(e){this.apiKey=e;if(e===null)throw new Error("API key cannot be null");if(e===void 0)throw new Error("API key cannot be undefined");if(!e)throw new Error("API key cannot be empty");if(typeof e!="string")throw new Error("API key must be a string");if(e.trim().length===0)throw new Error("API key cannot be empty or whitespace");if(!this.isValidFormat(e))throw new Error("Invalid API key format")}isValidFormat(e){return/^ts_[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/.test(e)}applyAuth(e){e.headers||(e.headers={}),e.headers.Authorization=`ApiKey ${this.apiKey}`}needsRefresh(){return!1}async refresh(){throw new Error("API keys cannot be refreshed")}async getAuthHeaders(){return{Authorization:`ApiKey ${this.apiKey}`}}isValid(){return typeof this.apiKey=="string"&&this.apiKey.trim().length>0&&this.isValidFormat(this.apiKey)}};var ce=P(require("axios")),fe=P(require("jsonwebtoken")),y=class y{constructor(e,t,r){t&&r?(this.clientId=e,this.clientSecret=t,this.refreshToken=r,this.accessToken=""):(this.accessToken=e,this.parseTokenExpiry())}applyAuth(e){e.headers||(e.headers={}),e.headers.Authorization=`Bearer ${this.accessToken}`}needsRefresh(){return this.refreshToken&&!this.accessToken?!0:!this.refreshToken||!this.tokenExpiry?!1:new Date(Date.now()+300*1e3)>=this.tokenExpiry}async refresh(){if(!this.refreshToken)throw new Error("Cannot refresh without refresh token");if(this.refreshPromise)return this.refreshPromise;this.refreshPromise=this.performRefresh();try{await this.refreshPromise}finally{this.refreshPromise=void 0}}async performRefresh(){try{let e=await ce.default.post(y.TOKEN_ENDPOINT,new URLSearchParams({grant_type:"refresh_token",refresh_token:this.refreshToken,client_id:this.clientId,client_secret:this.clientSecret}),{headers:{"Content-Type":"application/x-www-form-urlencoded"}});this.accessToken=e.data.access_token,e.data.refresh_token&&(this.refreshToken=e.data.refresh_token),this.parseTokenExpiry()}catch(e){let t=e instanceof Error?e.message:"Unknown error";throw new Error(`Failed to refresh OAuth2 token: ${t}`)}}async getAuthHeaders(){return this.needsRefresh()&&await this.refresh(),{Authorization:`Bearer ${this.accessToken}`}}static async fromAuthorizationCode(e,t,r,o){try{let a=await ce.default.post(y.TOKEN_ENDPOINT,new URLSearchParams({grant_type:"authorization_code",code:r,redirect_uri:o,client_id:e,client_secret:t}),{headers:{"Content-Type":"application/x-www-form-urlencoded"}}),m=a.data.access_token,c=a.data.refresh_token;return c?new y(e,t,c):new y(m)}catch(a){let m=a instanceof Error?a.message:"Unknown error";throw new Error(`Failed to exchange authorization code: ${m}`)}}static buildAuthorizationUrl(e,t,r){let o=new URLSearchParams({client_id:e,redirect_uri:t,response_type:"code"});return r&&o.append("state",r),`https://api.timesheet.io/oauth2/auth?${o.toString()}`}parseTokenExpiry(){try{let e=fe.default.decode(this.accessToken);e&&e.exp&&(this.tokenExpiry=new Date(e.exp*1e3))}catch{this.tokenExpiry=new Date(Date.now()+3600*1e3)}}};y.TOKEN_ENDPOINT="https://api.timesheet.io/oauth2/token";var v=y;var ue=P(require("axios")),Re=P(require("jsonwebtoken"));var ie=require("crypto");function be(s=64){if(s<43||s>128)throw new Error("Code verifier length must be between 43 and 128 characters");let e=(0,ie.randomBytes)(Math.ceil(s*3/4));return Te(e).slice(0,s)}function ye(s,e="S256"){if(e==="plain")return s;let t=(0,ie.createHash)("sha256").update(s,"ascii").digest();return Te(t)}function me(s="S256",e=64){let t=be(e),r=ye(t,s);return{codeVerifier:t,codeChallenge:r,codeChallengeMethod:s}}function he(s){return s.length<43||s.length>128?!1:/^[A-Za-z0-9\-._~]+$/.test(s)}function Te(s){return s.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var f=class f{constructor(e){if(typeof e=="string")this.accessToken=e,this.tokenEndpoint=f.DEFAULT_TOKEN_ENDPOINT,this.parseTokenExpiry();else{let t=e;this.clientId=t.clientId,this.clientSecret=t.clientSecret,this.refreshToken=t.refreshToken,this.resource=t.resource,this.tokenEndpoint=t.tokenEndpoint??f.DEFAULT_TOKEN_ENDPOINT,this.accessToken=""}}applyAuth(e){e.headers||(e.headers={}),e.headers.Authorization=`Bearer ${this.accessToken}`}needsRefresh(){return this.refreshToken&&!this.accessToken?!0:!this.refreshToken||!this.tokenExpiry?!1:new Date(Date.now()+300*1e3)>=this.tokenExpiry}async refresh(){if(!this.refreshToken)throw new Error("Cannot refresh without refresh token");if(this.refreshPromise)return this.refreshPromise;this.refreshPromise=this.performRefresh();try{await this.refreshPromise}finally{this.refreshPromise=void 0}}async performRefresh(){try{let e=new URLSearchParams({grant_type:"refresh_token",refresh_token:this.refreshToken,client_id:this.clientId});this.clientSecret&&e.append("client_secret",this.clientSecret),this.resource&&e.append("resource",this.resource);let t=await ue.default.post(this.tokenEndpoint,e,{headers:{"Content-Type":"application/x-www-form-urlencoded"}});this.accessToken=t.data.access_token,t.data.refresh_token&&(this.refreshToken=t.data.refresh_token),this.parseTokenExpiry()}catch(e){let t=e instanceof Error?e.message:"Unknown error";throw new Error(`Failed to refresh OAuth 2.1 token: ${t}`)}}async getAuthHeaders(){return this.needsRefresh()&&await this.refresh(),{Authorization:`Bearer ${this.accessToken}`}}static async fromAuthorizationCode(e){let{clientId:t,clientSecret:r,authorizationCode:o,redirectUri:a,codeVerifier:m,resource:c,tokenEndpoint:g}=e,h=g??f.DEFAULT_TOKEN_ENDPOINT;if(!he(m))throw new Error("Invalid code verifier: must be 43-128 characters using only A-Z, a-z, 0-9, -, ., _, ~");try{let u=new URLSearchParams({grant_type:"authorization_code",code:o,redirect_uri:a,client_id:t,code_verifier:m});r&&u.append("client_secret",r),c&&u.append("resource",c);let d=await ue.default.post(h,u,{headers:{"Content-Type":"application/x-www-form-urlencoded"}}),Q=d.data.access_token,R=d.data.refresh_token;return R?new f({clientId:t,clientSecret:r,refreshToken:R,resource:c,tokenEndpoint:h}):new f(Q)}catch(u){let d=u instanceof Error?u.message:"Unknown error";throw new Error(`Failed to exchange authorization code: ${d}`)}}static buildAuthorizationUrl(e){let{clientId:t,redirectUri:r,codeChallenge:o,codeChallengeMethod:a="S256",state:m,scope:c,resource:g,authorizationEndpoint:h}=e,u=h??f.DEFAULT_AUTH_ENDPOINT,d=new URLSearchParams({response_type:"code",client_id:t,redirect_uri:r,code_challenge:o,code_challenge_method:a});return m&&d.append("state",m),c&&d.append("scope",c),g&&d.append("resource",g),`${u}?${d.toString()}`}static generatePkce(e="S256"){return me(e)}parseTokenExpiry(){try{let e=Re.default.decode(this.accessToken);e&&e.exp&&(this.tokenExpiry=new Date(e.exp*1e3))}catch{this.tokenExpiry=new Date(Date.now()+3600*1e3)}}};f.DEFAULT_TOKEN_ENDPOINT="https://api.timesheet.io/oauth2/token",f.DEFAULT_AUTH_ENDPOINT="https://api.timesheet.io/oauth2/auth";var de=f;var ne=P(require("axios")),A=class A{constructor(e={}){this.cache=new Map;this.options={cacheTtl:e.cacheTtl??A.DEFAULT_CACHE_TTL,timeout:e.timeout??A.DEFAULT_TIMEOUT,fetchOpenIdConfig:e.fetchOpenIdConfig??!1,fetchProtectedResource:e.fetchProtectedResource??!1}}async discover(e){let t=this.normalizeIssuerUrl(e),r=this.getCached(t);if(r)return r;let o=await this.fetchAuthorizationServerMetadata(t),a={issuer:o.issuer,authorizationServer:o,fetchedAt:new Date};if(this.options.fetchOpenIdConfig)try{a.openIdConfiguration=await this.fetchOpenIdConfiguration(t)}catch{}if(this.options.fetchProtectedResource)try{a.protectedResource=await this.fetchProtectedResourceMetadata(t)}catch{}return this.setCache(t,a),a}async fetchAuthorizationServerMetadata(e){let t=`${this.normalizeIssuerUrl(e)}/.well-known/oauth-authorization-server`;try{let r=await ne.default.get(t,{timeout:this.options.timeout,headers:{Accept:"application/json"}});return this.validateAuthorizationServerMetadata(r.data),r.data}catch(r){let o=r instanceof Error?r.message:"Unknown error";throw new Error(`Failed to fetch authorization server metadata from ${t}: ${o}`)}}async fetchOpenIdConfiguration(e){let t=`${this.normalizeIssuerUrl(e)}/.well-known/openid-configuration`;try{let r=await ne.default.get(t,{timeout:this.options.timeout,headers:{Accept:"application/json"}});return this.validateOpenIdConfiguration(r.data),r.data}catch(r){let o=r instanceof Error?r.message:"Unknown error";throw new Error(`Failed to fetch OpenID configuration from ${t}: ${o}`)}}async fetchProtectedResourceMetadata(e){let t=`${this.normalizeIssuerUrl(e)}/.well-known/oauth-protected-resource`;try{let r=await ne.default.get(t,{timeout:this.options.timeout,headers:{Accept:"application/json"}});return this.validateProtectedResourceMetadata(r.data),r.data}catch(r){let o=r instanceof Error?r.message:"Unknown error";throw new Error(`Failed to fetch protected resource metadata from ${t}: ${o}`)}}clearCache(){this.cache.clear()}clearCacheForIssuer(e){this.cache.delete(this.normalizeIssuerUrl(e))}isCached(e){return this.getCached(this.normalizeIssuerUrl(e))!==null}normalizeIssuerUrl(e){return e.replace(/\/+$/,"")}getCached(e){let t=this.cache.get(e);return t?new Date>=t.expiresAt?(this.cache.delete(e),null):t.result:null}setCache(e,t){let r=new Date(Date.now()+this.options.cacheTtl);this.cache.set(e,{result:t,expiresAt:r})}validateAuthorizationServerMetadata(e){if(!e.issuer)throw new Error("Authorization server metadata missing required field: issuer");if(!e.authorization_endpoint)throw new Error("Authorization server metadata missing required field: authorization_endpoint");if(!e.token_endpoint)throw new Error("Authorization server metadata missing required field: token_endpoint");if(!e.response_types_supported||e.response_types_supported.length===0)throw new Error("Authorization server metadata missing required field: response_types_supported")}validateOpenIdConfiguration(e){if(!e.issuer)throw new Error("OpenID configuration missing required field: issuer");if(!e.authorization_endpoint)throw new Error("OpenID configuration missing required field: authorization_endpoint");if(!e.token_endpoint)throw new Error("OpenID configuration missing required field: token_endpoint");if(!e.jwks_uri)throw new Error("OpenID configuration missing required field: jwks_uri")}validateProtectedResourceMetadata(e){if(!e.resource)throw new Error("Protected resource metadata missing required field: resource");if(!e.authorization_servers||e.authorization_servers.length===0)throw new Error("Protected resource metadata missing required field: authorization_servers")}};A.DEFAULT_CACHE_TTL=3600*1e3,A.DEFAULT_TIMEOUT=1e4;var se=A,le=null;function Ce(){return le||(le=new se),le}async function Ne(s,e){return(e?new se(e):Ce()).discover(s)}var oe=class s{constructor(e={}){this.maxRetries=e.maxRetries??3,this.initialDelay=e.initialDelay??100,this.maxDelay=e.maxDelay??1e4,this.backoffMultiplier=e.backoffMultiplier??2,this.retryableStatusCodes=e.retryableStatusCodes??[429,502,503,504]}static default(){return new s}};var p=class{constructor(e,t){this.items=e.items,this.params=e.params,this.nextPageLoader=t}get totalPages(){return Math.ceil((this.params?.count||0)/(this.params?.limit||25))}get hasNextPage(){return(this.params?.page||1)<this.totalPages}async nextPage(){if(!this.hasNextPage)throw new Error("No more pages available");if(!this.nextPageLoader)throw new Error("Next page loader not configured");return this.nextPageLoader((this.params.page||1)+1)}async*[Symbol.asyncIterator](){let e=this;for(;;){for(let t of e.items)yield t;if(!e.hasNextPage)break;e=await e.nextPage()}}async toArray(){let e=[];for await(let t of this)e.push(t);return e}};var qe={TEAM_CREATE:"team.create",TEAM_UPDATE:"team.update",PROJECT_CREATE:"project.create",PROJECT_UPDATE:"project.update",TODO_CREATE:"todo.create",TODO_UPDATE:"todo.update",TASK_CREATE:"task.create",TASK_UPDATE:"task.update",TAG_CREATE:"tag.create",TAG_UPDATE:"tag.update",RATE_CREATE:"rate.create",RATE_UPDATE:"rate.update",TIMER_START:"timer.start",TIMER_STOP:"timer.stop",TIMER_PAUSE:"timer.pause",TIMER_RESUME:"timer.resume"};function Me(...s){return s.join(",")}var i=class{constructor(e,t){this.http=e;typeof t=="string"?this.basePath=t:this.basePath=t.basePath}createNavigablePage(e,t){return new p(e,t)}};var w=class extends i{constructor(e){super(e,"/v1/organizations")}async list(e){let t=await this.http.get(this.basePath,e);return new p(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async listMembers(e,t){let r=await this.http.post(`${this.basePath}/${encodeURIComponent(e)}/members/list`,t);return this.createNavigablePage(r,o=>this.listMembers(e,{...t,page:o}))}async getMember(e,t){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`)}async addMember(e,t){return this.http.post(`${this.basePath}/${encodeURIComponent(e)}/members`,t)}async updateMember(e,t,r){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`,r)}async removeMember(e,t){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`)}};var E=class extends i{constructor(e){super(e,"/v1/teams")}async list(e){let t=await this.http.get(this.basePath,e);return new p(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async listMembers(e,t){let r=await this.http.post(`${this.basePath}/${e}/members/list`,t);return this.createNavigablePage(r,o=>this.listMembers(e,{...t,page:o}))}async getMember(e,t){return this.http.get(`${this.basePath}/${e}/members/${t}`)}async getColleagues(e){let t=await this.http.post(`${this.basePath}/getColleagues`,e);return this.createNavigablePage(t,r=>this.getColleagues({...e,page:r}))}async addMember(e,t){return this.http.post(`${this.basePath}/${e}/members`,t)}async updateMember(e,t,r){return this.http.put(`${this.basePath}/${e}/members/${t}`,r)}async removeMember(e,t){return this.http.delete(`${this.basePath}/${e}/members/${t}`)}async removeInvitedMember(e,t){return this.http.delete(`${this.basePath}/${e}/members/${t}/invited`)}async batchAddMembers(e){return this.http.post(`${this.basePath}/batchTeamMembers`,e)}async getMemberStatus(e){let t=await this.http.post(`${this.basePath}/getMemberStatus`,e);return this.createNavigablePage(t,r=>this.getMemberStatus({...e,page:r}))}};var $=class extends i{constructor(e){super(e,"/v1/projects")}async list(e){let t=await this.http.get(this.basePath,e);return new p(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async listMembers(e,t){let r=await this.http.post(`${this.basePath}/${encodeURIComponent(e)}/members/list`,t);return this.createNavigablePage(r,o=>this.listMembers(e,{...t,page:o}))}async addMember(e,t){return this.http.post(`${this.basePath}/${encodeURIComponent(e)}/members`,t)}async getMember(e,t){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`)}async updateMember(e,t,r){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`,r)}async updateMembers(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}/members`,t)}async removeMember(e,t){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`)}async batchAddMembers(e,t){return this.http.post(`${this.basePath}/${encodeURIComponent(e)}/members/batch`,t)}async batchRemoveMembers(e,t){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}/members/batch`,void 0,t)}};var T=P(require("dayjs")),xe=P(require("dayjs/plugin/utc")),ve=P(require("dayjs/plugin/timezone")),Ae=P(require("dayjs/plugin/customParseFormat"));T.default.extend(xe.default);T.default.extend(ve.default);T.default.extend(Ae.default);var Se="YYYY-MM-DDTHH:mm:ssZ",Oe=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/,n={isValidTimestampFormat(s){return Oe.test(s)},formatTimestamp(s){return typeof s=="string"&&this.isValidTimestampFormat(s)?s:(0,T.default)(s||new Date).format(Se)},parseTimestamp(s){return(0,T.default)(s).toDate()},formatDate(s){return(0,T.default)(s||new Date).format("YYYY-MM-DD")},now(){return this.formatTimestamp()}};var k=class extends i{constructor(e){super(e,"/v1/tasks")}async list(e){let t=await this.http.get(this.basePath,e);return this.createNavigablePage(t,r=>this.list({...e,page:r}))}async create(e){let t={...e,startDateTime:n.formatTimestamp(e.startDateTime),endDateTime:e.endDateTime?n.formatTimestamp(e.endDateTime):void 0};return this.http.post(this.basePath,t)}async update(e,t){let r={...t,startDateTime:t.startDateTime?n.formatTimestamp(t.startDateTime):void 0,endDateTime:t.endDateTime?n.formatTimestamp(t.endDateTime):void 0};return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,r)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async statistics(e){return this.http.post(`${this.basePath}/statistics`,e)}async updateStatus(e){return this.http.put(`${this.basePath}/updateStatus`,e)}async updateTimes(e){let t={...e,start:n.formatTimestamp(e.start),end:n.formatTimestamp(e.end)};return this.http.put(`${this.basePath}/updateTimes`,t)}async print(e){return this.http.request({method:"GET",url:`${this.basePath}/print/${encodeURIComponent(e)}`,responseType:"arraybuffer"})}};var U=class extends i{constructor(e){super(e,"/v1/rates")}async list(e){let t=await this.http.get(this.basePath,e);return new p(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var D=class extends i{constructor(e){super(e,"/v1/tags")}async list(e){let t=await this.http.get(this.basePath,e);return new p({items:t??[],params:e??{}},r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var I=class extends i{constructor(e){super(e,"/v1/expenses")}async list(e){let t=await this.http.get(this.basePath,e);return new p(t,r=>this.list({...e,page:r}))}async create(e){let t={...e,dateTime:n.formatTimestamp(e.dateTime)};return this.http.post(this.basePath,t)}async update(e,t){let r={...t,dateTime:t.dateTime?n.formatTimestamp(t.dateTime):void 0};return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,r)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async updateStatus(e){return this.http.put(`${this.basePath}/updateStatus`,e)}async uploadFile(e,t){let r=new FormData;return r.append("file",t.file,t.fileName),this.http.postMultipart(`${this.basePath}/${encodeURIComponent(e)}/file`,r)}async createWithFile(e){let{file:t,...r}=e,o={...r,dateTime:n.formatTimestamp(r.dateTime)},a=new FormData;return a.append("data",new Blob([JSON.stringify(o)],{type:"application/json"})),t&&a.append("file",t.file,t.fileName),this.http.postMultipart(`${this.basePath}/with-file`,a)}async getFileUrl(e){return this.http.get(`${this.basePath}/getFileUrl/${encodeURIComponent(e)}`)}};var N=class extends i{constructor(e){super(e,"/v1/notes")}async list(e){let t=await this.http.get(this.basePath,e);return new p(t,r=>this.list({...e,page:r}))}async create(e){let t={...e,dateTime:n.formatTimestamp(e.dateTime)};return this.http.post(this.basePath,t)}async update(e,t){let r={...t,dateTime:n.formatTimestamp(t.dateTime)};return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,r)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async uploadFile(e,t){let r=new FormData;return r.append("file",t.file,t.fileName),this.http.postMultipart(`${this.basePath}/${encodeURIComponent(e)}/file`,r)}async createWithFile(e){let{file:t,...r}=e,o={...r,dateTime:n.formatTimestamp(r.dateTime)},a=new FormData;return a.append("data",new Blob([JSON.stringify(o)],{type:"application/json"})),t&&a.append("file",t.file,t.fileName),this.http.postMultipart(`${this.basePath}/with-file`,a)}async getFileUrl(e){return this.http.get(`${this.basePath}/getFileUrl/${encodeURIComponent(e)}`)}};var q=class extends i{constructor(e){super(e,"/v1/pauses")}async list(e){let t=await this.http.get(this.basePath,e);return new p(t,r=>this.list({...e,page:r}))}async create(e){let t={...e,startDateTime:n.formatTimestamp(e.startDateTime),endDateTime:n.formatTimestamp(e.endDateTime)};return this.http.post(this.basePath,t)}async update(e,t){let r={...t,startDateTime:n.formatTimestamp(t.startDateTime),endDateTime:n.formatTimestamp(t.endDateTime)};return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,r)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var M=class{constructor(e){this.http=e}async getProfile(){return this.http.get("/v1/profiles/me")}async updateProfile(e){return this.http.put("/v1/profiles/me",e)}};var S=class{constructor(e){this.http=e}async get(){return this.http.get("/v1/settings")}async update(e){return this.http.put("/v1/settings",e)}};var O=class extends i{constructor(e){super(e,"/v1/automations")}async list(e){let t=await this.http.get(this.basePath,e);return new p(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var L=class extends i{constructor(e){super(e,"/v1/documents")}async list(e){let{category:t,...r}=e??{},o=t!==void 0?{...r,type:t}:{...r},a=await this.http.get(this.basePath,o);return new p(a,m=>this.list({...e,page:m}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var _=class{constructor(e){this.http=e}async get(){return this.http.get("/v1/timer")}async start(e){let t={...e,startDateTime:e.startDateTime?n.formatTimestamp(e.startDateTime):n.formatTimestamp()};return this.http.post("/v1/timer/start",t)}async stop(e){let t=e?{...e,endDateTime:e.endDateTime?n.formatTimestamp(e.endDateTime):n.formatTimestamp()}:{endDateTime:n.formatTimestamp()};return this.http.post("/v1/timer/stop",t)}async pause(e){let t=e?{...e,startDateTime:e.startDateTime?n.formatTimestamp(e.startDateTime):n.formatTimestamp()}:{startDateTime:n.formatTimestamp()};return this.http.post("/v1/timer/pause",t)}async resume(e){let t=e?{...e,endDateTime:e.endDateTime?n.formatTimestamp(e.endDateTime):n.formatTimestamp()}:{endDateTime:n.formatTimestamp()};return this.http.post("/v1/timer/resume",t)}async update(e){let t={...e,startDateTime:e.startDateTime?n.formatTimestamp(e.startDateTime):void 0};return this.http.put("/v1/timer/update",t)}};var z=class extends i{constructor(e){super(e,"/v1/todos")}async list(e){let t=await this.http.get(this.basePath,e);return new p({items:t??[],params:e??{}},r=>this.list({...e,page:r}))}async create(e){let t={...e,dueDate:e.dueDate?n.formatTimestamp(e.dueDate):void 0};return this.http.post(this.basePath,t)}async update(e,t){let r={...t,dueDate:t.dueDate?n.formatTimestamp(t.dueDate):void 0};return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,r)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var F=class extends i{constructor(e){super(e,"/v1/webhooks")}async list(e){let t=await this.http.get(this.basePath,e);return new p(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var j=class extends i{constructor(e){super(e,"/v1/events")}async getStatus(){return this.http.get(`${this.basePath}/status`)}getStreamUrl(){return`${this.http.getBaseUrl()}${this.basePath}/stream`}async subscribe(e){let t=this.getStreamUrl(),o={Accept:"text/event-stream","Cache-Control":"no-cache",...await this.http.getAuthHeaders()},a=new AbortController,m=!1,c=new Map,g={close:()=>{m=!1,a.abort(),e.onClose?.()},get isConnected(){return m},on:(h,u)=>{c.has(h)||c.set(h,new Set),c.get(h).add(u)},off:(h,u)=>{c.get(h)?.delete(u)}};return this.connectSse(t,o,a.signal,{...e,onConnected:h=>{m=!0,e.onConnected?.(h)},onEvent:h=>{e.onEvent?.(h),c.get(h.event)?.forEach(d=>d(h))},onError:h=>{e.onError?.(h),c.get("error")?.forEach(d=>d(h))},onClose:()=>{m=!1,e.onClose?.()}}),g}async connectSse(e,t,r,o){try{let a=await fetch(e,{method:"GET",headers:t,signal:r});if(!a.ok)throw new Error(`SSE connection failed: ${a.status} ${a.statusText}`);if(!a.body)throw new Error("SSE response has no body");let m=a.body.getReader(),c=new TextDecoder,g="",h="",u="",d="",Q=!1;for(;!Q;){let R=await m.read();if(Q=R.done,Q||!R.value){o.onClose?.();break}g+=c.decode(R.value,{stream:!0});let ge=g.split(`
|
|
2
|
-
`);g=ge.pop()||"";for(let b of ge)b.startsWith("event:")?h=b.slice(6).trim():b.startsWith("data:")?u=b.slice(5).trim():b.startsWith("id:")?d=b.slice(3).trim():b===""&&(u&&this.processEvent(h,u,d,o),h="",u="",d="")}}catch(a){if(r.aborted)return;o.onError?.(a)}}processEvent(e,t,r,o){try{let a=JSON.parse(t);if(e==="connected"){let m=a;o.onConnected?.(m.connectionId)}else o.onEvent?.(a)}catch{o.onError?.(new Error(`Failed to parse event data: ${t}`))}}};var W=class extends i{constructor(e){super(e,"/v1/organizations")}orgPath(e){return`${this.basePath}/${encodeURIComponent(e)}/absences`}async list(e,t){let r=await this.http.get(this.orgPath(e),t);return this.createNavigablePage(r,o=>this.list(e,{...t,page:o}))}async search(e,t){let r=await this.http.post(`${this.orgPath(e)}/search`,t);return this.createNavigablePage(r,o=>this.search(e,{...t,page:o}))}async create(e,t){return this.http.post(this.orgPath(e),t)}async get(e,t){return this.http.get(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async update(e,t,r){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}`,r)}async delete(e,t){return this.http.delete(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async approve(e,t){return this.http.post(`${this.orgPath(e)}/${encodeURIComponent(t)}/approve`)}async reject(e,t,r){return this.http.post(`${this.orgPath(e)}/${encodeURIComponent(t)}/reject`,r)}async cancel(e,t,r){return this.http.post(`${this.orgPath(e)}/${encodeURIComponent(t)}/cancel`,r)}};var B=class extends i{constructor(e){super(e,"/v1/organizations")}orgPath(e){return`${this.basePath}/${encodeURIComponent(e)}/absence-types`}async list(e,t){let r=await this.http.get(this.orgPath(e),t);return this.createNavigablePage(r,o=>this.list(e,{...t,page:o}))}async create(e,t){return this.http.post(this.orgPath(e),t)}async get(e,t){return this.http.get(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async update(e,t,r){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}`,r)}async delete(e,t){return this.http.delete(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}};var H=class extends i{constructor(e){super(e,"/v1/organizations")}orgPath(e){return`${this.basePath}/${encodeURIComponent(e)}/contracts`}async list(e,t){let r=await this.http.get(this.orgPath(e),t);return this.createNavigablePage(r,o=>this.list(e,{...t,page:o}))}async create(e,t){return this.http.post(this.orgPath(e),t)}async get(e,t){return this.http.get(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async update(e,t,r){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}`,r)}async delete(e,t){return this.http.delete(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async activate(e,t){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}/activate`)}async suspend(e,t){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}/suspend`)}async reactivate(e,t){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}/reactivate`)}async terminate(e,t){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}/terminate`)}};var K=class extends i{constructor(e){super(e,"/v1/organizations")}orgPath(e){return`${this.basePath}/${encodeURIComponent(e)}/contract-templates`}async list(e,t){let r=await this.http.get(this.orgPath(e),t);return this.createNavigablePage(r,o=>this.list(e,{...t,page:o}))}async create(e,t){return this.http.post(this.orgPath(e),t)}async get(e,t){return this.http.get(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async update(e,t,r){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}`,r)}async delete(e,t){return this.http.delete(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}};var
|
|
1
|
+
"use strict";var Ee=Object.create;var ae=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames;var Ue=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty;var Ie=(s,e)=>{for(var t in e)ae(s,t,{get:e[t],enumerable:!0})},Pe=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ke(e))!De.call(s,o)&&o!==t&&ae(s,o,{get:()=>e[o],enumerable:!(r=$e(e,o))||r.enumerable});return s};var P=(s,e,t)=>(t=s!=null?Ee(Ue(s)):{},Pe(e||!s||!s.__esModule?ae(t,"default",{value:s,enumerable:!0}):t,s)),Ne=s=>Pe(ae({},"__esModule",{value:!0}),s);var ze={};Ie(ze,{AbsenceResource:()=>W,AbsenceTypeResource:()=>B,ApiClient:()=>x,ApiKeyAuth:()=>re,AutomationResource:()=>O,ContractResource:()=>H,ContractTemplateResource:()=>K,DocumentReportResource:()=>V,DocumentResource:()=>L,EventResource:()=>j,ExpenseReportResource:()=>G,ExpenseResource:()=>I,ExportResource:()=>Z,NavigablePage:()=>c,NoteReportResource:()=>Y,NoteResource:()=>N,OAuth21Auth:()=>de,OAuth2Auth:()=>v,OAuthDiscovery:()=>se,OrganizationResource:()=>w,PauseResource:()=>q,ProfileResource:()=>M,ProjectResource:()=>$,RateResource:()=>U,ReportsClient:()=>X,Resource:()=>i,RetryConfig:()=>oe,SettingsResource:()=>S,TagResource:()=>D,TaskReportResource:()=>J,TaskResource:()=>k,TeamResource:()=>E,TimerResource:()=>_,TimesheetApiError:()=>l,TimesheetAuthError:()=>ee,TimesheetClient:()=>pe,TimesheetRateLimitError:()=>te,TodoResource:()=>z,WebhookEvents:()=>Me,WebhookResource:()=>F,combineWebhookEvents:()=>Se,createClient:()=>_e,discoverOAuth:()=>qe,generateCodeChallenge:()=>Te,generateCodeVerifier:()=>ye,generatePkceCodePair:()=>me,getDefaultDiscovery:()=>xe,isValidCodeVerifier:()=>he});module.exports=Ne(ze);var C=P(require("axios"));var l=class s extends Error{constructor(e,t,r,o){let a=t?o?`${e} (HTTP ${t}, Code: ${o})`:`${e} (HTTP ${t})`:e;super(a),this.name="TimesheetApiError",this.statusCode=t,this.responseBody=r,this.errorCode=o,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,s)}};var ee=class extends l{constructor(e,t=401,r){super(e,t,r,"authentication_error"),this.name="TimesheetAuthError"}};var te=class extends l{constructor(e,t){super(e,429,void 0,"rate_limit_exceeded"),this.name="TimesheetRateLimitError",this.retryAfter=t}getRetryAfterDate(){if(!this.retryAfter)return null;let e=Number(this.retryAfter);if(!isNaN(e))return new Date(e*1e3);let t=new Date(this.retryAfter);return isNaN(t.getTime())?null:t}};var fe="1.1.1";var x=class{constructor(e){this.config=e,this.httpClient=e.httpClient||C.default.create({baseURL:e.baseUrl,timeout:3e4,headers:{"User-Agent":`Timesheet-TypeScript-SDK/${fe}`,"Content-Type":"application/json"}}),this.httpClient.interceptors.request.use(async t=>{if(t.url!=="/oauth/token"&&this.config.authentication){let r=await this.config.authentication.getAuthHeaders();if(r)for(let[o,a]of Object.entries(r))t.headers.set(o,a)}return t})}async request(e){let t=null,r=this.config.retryConfig;for(let o=0;o<=r.maxRetries;o++)try{return(await this.httpClient.request(e)).data}catch(a){if(t=a,C.default.isAxiosError(a)&&a.response?.status===401){let p=a.response.data;throw new ee(p?.message||"Authentication failed",401,JSON.stringify(p))}if(C.default.isAxiosError(a)&&a.response?.status===429){let p=a.response.headers["retry-after"];throw new te("Rate limit exceeded",p)}let m=C.default.isAxiosError(a)?a.response?.status:void 0;if(o<r.maxRetries&&m&&r.retryableStatusCodes.includes(m)){let p=Math.min(r.initialDelay*Math.pow(r.backoffMultiplier,o),r.maxDelay);await this.sleep(p);continue}if(C.default.isAxiosError(a)){let p=a.response?.data;throw new l(p?.message||a.message,a.response?.status,JSON.stringify(p),p?.code)}else throw a instanceof Error?new l(a.message):new l("Unknown error occurred")}throw t||new Error("Unknown error")}async get(e,t){return this.request({method:"GET",url:e,params:t})}async post(e,t,r){return this.request({method:"POST",url:e,data:t,params:r})}async put(e,t,r){return this.request({method:"PUT",url:e,data:t,params:r})}async delete(e,t,r){return this.request({method:"DELETE",url:e,data:r,params:t})}async postMultipart(e,t){return this.request({method:"POST",url:e,data:t,headers:{"Content-Type":"multipart/form-data"}})}sleep(e){return new Promise(t=>setTimeout(t,e))}getBaseUrl(){return this.config.baseUrl}async getAuthHeaders(){if(this.config.authentication)return this.config.authentication.getAuthHeaders()}};var re=class{constructor(e){this.apiKey=e;if(e===null)throw new Error("API key cannot be null");if(e===void 0)throw new Error("API key cannot be undefined");if(!e)throw new Error("API key cannot be empty");if(typeof e!="string")throw new Error("API key must be a string");if(e.trim().length===0)throw new Error("API key cannot be empty or whitespace");if(!this.isValidFormat(e))throw new Error("Invalid API key format")}isValidFormat(e){return/^ts_[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/.test(e)}applyAuth(e){e.headers||(e.headers={}),e.headers.Authorization=`ApiKey ${this.apiKey}`}needsRefresh(){return!1}async refresh(){throw new Error("API keys cannot be refreshed")}async getAuthHeaders(){return{Authorization:`ApiKey ${this.apiKey}`}}isValid(){return typeof this.apiKey=="string"&&this.apiKey.trim().length>0&&this.isValidFormat(this.apiKey)}};var ce=P(require("axios")),be=P(require("jsonwebtoken")),y=class y{constructor(e,t,r){t&&r?(this.clientId=e,this.clientSecret=t,this.refreshToken=r,this.accessToken=""):(this.accessToken=e,this.parseTokenExpiry())}applyAuth(e){e.headers||(e.headers={}),e.headers.Authorization=`Bearer ${this.accessToken}`}needsRefresh(){return this.refreshToken&&!this.accessToken?!0:!this.refreshToken||!this.tokenExpiry?!1:new Date(Date.now()+300*1e3)>=this.tokenExpiry}async refresh(){if(!this.refreshToken)throw new Error("Cannot refresh without refresh token");if(this.refreshPromise)return this.refreshPromise;this.refreshPromise=this.performRefresh();try{await this.refreshPromise}finally{this.refreshPromise=void 0}}async performRefresh(){try{let e=await ce.default.post(y.TOKEN_ENDPOINT,new URLSearchParams({grant_type:"refresh_token",refresh_token:this.refreshToken,client_id:this.clientId,client_secret:this.clientSecret}),{headers:{"Content-Type":"application/x-www-form-urlencoded"}});this.accessToken=e.data.access_token,e.data.refresh_token&&(this.refreshToken=e.data.refresh_token),this.parseTokenExpiry()}catch(e){let t=e instanceof Error?e.message:"Unknown error";throw new Error(`Failed to refresh OAuth2 token: ${t}`)}}async getAuthHeaders(){return this.needsRefresh()&&await this.refresh(),{Authorization:`Bearer ${this.accessToken}`}}static async fromAuthorizationCode(e,t,r,o){try{let a=await ce.default.post(y.TOKEN_ENDPOINT,new URLSearchParams({grant_type:"authorization_code",code:r,redirect_uri:o,client_id:e,client_secret:t}),{headers:{"Content-Type":"application/x-www-form-urlencoded"}}),m=a.data.access_token,p=a.data.refresh_token;return p?new y(e,t,p):new y(m)}catch(a){let m=a instanceof Error?a.message:"Unknown error";throw new Error(`Failed to exchange authorization code: ${m}`)}}static buildAuthorizationUrl(e,t,r){let o=new URLSearchParams({client_id:e,redirect_uri:t,response_type:"code"});return r&&o.append("state",r),`https://api.timesheet.io/oauth2/auth?${o.toString()}`}parseTokenExpiry(){try{let e=be.default.decode(this.accessToken);e&&e.exp&&(this.tokenExpiry=new Date(e.exp*1e3))}catch{this.tokenExpiry=new Date(Date.now()+3600*1e3)}}};y.TOKEN_ENDPOINT="https://api.timesheet.io/oauth2/token";var v=y;var ue=P(require("axios")),Ce=P(require("jsonwebtoken"));var ie=require("crypto");function ye(s=64){if(s<43||s>128)throw new Error("Code verifier length must be between 43 and 128 characters");let e=(0,ie.randomBytes)(Math.ceil(s*3/4));return Re(e).slice(0,s)}function Te(s,e="S256"){if(e==="plain")return s;let t=(0,ie.createHash)("sha256").update(s,"ascii").digest();return Re(t)}function me(s="S256",e=64){let t=ye(e),r=Te(t,s);return{codeVerifier:t,codeChallenge:r,codeChallengeMethod:s}}function he(s){return s.length<43||s.length>128?!1:/^[A-Za-z0-9\-._~]+$/.test(s)}function Re(s){return s.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var f=class f{constructor(e){if(typeof e=="string")this.accessToken=e,this.tokenEndpoint=f.DEFAULT_TOKEN_ENDPOINT,this.parseTokenExpiry();else{let t=e;this.clientId=t.clientId,this.clientSecret=t.clientSecret,this.refreshToken=t.refreshToken,this.resource=t.resource,this.tokenEndpoint=t.tokenEndpoint??f.DEFAULT_TOKEN_ENDPOINT,this.accessToken=""}}applyAuth(e){e.headers||(e.headers={}),e.headers.Authorization=`Bearer ${this.accessToken}`}needsRefresh(){return this.refreshToken&&!this.accessToken?!0:!this.refreshToken||!this.tokenExpiry?!1:new Date(Date.now()+300*1e3)>=this.tokenExpiry}async refresh(){if(!this.refreshToken)throw new Error("Cannot refresh without refresh token");if(this.refreshPromise)return this.refreshPromise;this.refreshPromise=this.performRefresh();try{await this.refreshPromise}finally{this.refreshPromise=void 0}}async performRefresh(){try{let e=new URLSearchParams({grant_type:"refresh_token",refresh_token:this.refreshToken,client_id:this.clientId});this.clientSecret&&e.append("client_secret",this.clientSecret),this.resource&&e.append("resource",this.resource);let t=await ue.default.post(this.tokenEndpoint,e,{headers:{"Content-Type":"application/x-www-form-urlencoded"}});this.accessToken=t.data.access_token,t.data.refresh_token&&(this.refreshToken=t.data.refresh_token),this.parseTokenExpiry()}catch(e){let t=e instanceof Error?e.message:"Unknown error";throw new Error(`Failed to refresh OAuth 2.1 token: ${t}`)}}async getAuthHeaders(){return this.needsRefresh()&&await this.refresh(),{Authorization:`Bearer ${this.accessToken}`}}static async fromAuthorizationCode(e){let{clientId:t,clientSecret:r,authorizationCode:o,redirectUri:a,codeVerifier:m,resource:p,tokenEndpoint:g}=e,h=g??f.DEFAULT_TOKEN_ENDPOINT;if(!he(m))throw new Error("Invalid code verifier: must be 43-128 characters using only A-Z, a-z, 0-9, -, ., _, ~");try{let u=new URLSearchParams({grant_type:"authorization_code",code:o,redirect_uri:a,client_id:t,code_verifier:m});r&&u.append("client_secret",r),p&&u.append("resource",p);let d=await ue.default.post(h,u,{headers:{"Content-Type":"application/x-www-form-urlencoded"}}),Q=d.data.access_token,R=d.data.refresh_token;return R?new f({clientId:t,clientSecret:r,refreshToken:R,resource:p,tokenEndpoint:h}):new f(Q)}catch(u){let d=u instanceof Error?u.message:"Unknown error";throw new Error(`Failed to exchange authorization code: ${d}`)}}static buildAuthorizationUrl(e){let{clientId:t,redirectUri:r,codeChallenge:o,codeChallengeMethod:a="S256",state:m,scope:p,resource:g,authorizationEndpoint:h}=e,u=h??f.DEFAULT_AUTH_ENDPOINT,d=new URLSearchParams({response_type:"code",client_id:t,redirect_uri:r,code_challenge:o,code_challenge_method:a});return m&&d.append("state",m),p&&d.append("scope",p),g&&d.append("resource",g),`${u}?${d.toString()}`}static generatePkce(e="S256"){return me(e)}parseTokenExpiry(){try{let e=Ce.default.decode(this.accessToken);e&&e.exp&&(this.tokenExpiry=new Date(e.exp*1e3))}catch{this.tokenExpiry=new Date(Date.now()+3600*1e3)}}};f.DEFAULT_TOKEN_ENDPOINT="https://api.timesheet.io/oauth2/token",f.DEFAULT_AUTH_ENDPOINT="https://api.timesheet.io/oauth2/auth";var de=f;var ne=P(require("axios")),A=class A{constructor(e={}){this.cache=new Map;this.options={cacheTtl:e.cacheTtl??A.DEFAULT_CACHE_TTL,timeout:e.timeout??A.DEFAULT_TIMEOUT,fetchOpenIdConfig:e.fetchOpenIdConfig??!1,fetchProtectedResource:e.fetchProtectedResource??!1}}async discover(e){let t=this.normalizeIssuerUrl(e),r=this.getCached(t);if(r)return r;let o=await this.fetchAuthorizationServerMetadata(t),a={issuer:o.issuer,authorizationServer:o,fetchedAt:new Date};if(this.options.fetchOpenIdConfig)try{a.openIdConfiguration=await this.fetchOpenIdConfiguration(t)}catch{}if(this.options.fetchProtectedResource)try{a.protectedResource=await this.fetchProtectedResourceMetadata(t)}catch{}return this.setCache(t,a),a}async fetchAuthorizationServerMetadata(e){let t=`${this.normalizeIssuerUrl(e)}/.well-known/oauth-authorization-server`;try{let r=await ne.default.get(t,{timeout:this.options.timeout,headers:{Accept:"application/json"}});return this.validateAuthorizationServerMetadata(r.data),r.data}catch(r){let o=r instanceof Error?r.message:"Unknown error";throw new Error(`Failed to fetch authorization server metadata from ${t}: ${o}`)}}async fetchOpenIdConfiguration(e){let t=`${this.normalizeIssuerUrl(e)}/.well-known/openid-configuration`;try{let r=await ne.default.get(t,{timeout:this.options.timeout,headers:{Accept:"application/json"}});return this.validateOpenIdConfiguration(r.data),r.data}catch(r){let o=r instanceof Error?r.message:"Unknown error";throw new Error(`Failed to fetch OpenID configuration from ${t}: ${o}`)}}async fetchProtectedResourceMetadata(e){let t=`${this.normalizeIssuerUrl(e)}/.well-known/oauth-protected-resource`;try{let r=await ne.default.get(t,{timeout:this.options.timeout,headers:{Accept:"application/json"}});return this.validateProtectedResourceMetadata(r.data),r.data}catch(r){let o=r instanceof Error?r.message:"Unknown error";throw new Error(`Failed to fetch protected resource metadata from ${t}: ${o}`)}}clearCache(){this.cache.clear()}clearCacheForIssuer(e){this.cache.delete(this.normalizeIssuerUrl(e))}isCached(e){return this.getCached(this.normalizeIssuerUrl(e))!==null}normalizeIssuerUrl(e){return e.replace(/\/+$/,"")}getCached(e){let t=this.cache.get(e);return t?new Date>=t.expiresAt?(this.cache.delete(e),null):t.result:null}setCache(e,t){let r=new Date(Date.now()+this.options.cacheTtl);this.cache.set(e,{result:t,expiresAt:r})}validateAuthorizationServerMetadata(e){if(!e.issuer)throw new Error("Authorization server metadata missing required field: issuer");if(!e.authorization_endpoint)throw new Error("Authorization server metadata missing required field: authorization_endpoint");if(!e.token_endpoint)throw new Error("Authorization server metadata missing required field: token_endpoint");if(!e.response_types_supported||e.response_types_supported.length===0)throw new Error("Authorization server metadata missing required field: response_types_supported")}validateOpenIdConfiguration(e){if(!e.issuer)throw new Error("OpenID configuration missing required field: issuer");if(!e.authorization_endpoint)throw new Error("OpenID configuration missing required field: authorization_endpoint");if(!e.token_endpoint)throw new Error("OpenID configuration missing required field: token_endpoint");if(!e.jwks_uri)throw new Error("OpenID configuration missing required field: jwks_uri")}validateProtectedResourceMetadata(e){if(!e.resource)throw new Error("Protected resource metadata missing required field: resource");if(!e.authorization_servers||e.authorization_servers.length===0)throw new Error("Protected resource metadata missing required field: authorization_servers")}};A.DEFAULT_CACHE_TTL=3600*1e3,A.DEFAULT_TIMEOUT=1e4;var se=A,le=null;function xe(){return le||(le=new se),le}async function qe(s,e){return(e?new se(e):xe()).discover(s)}var oe=class s{constructor(e={}){this.maxRetries=e.maxRetries??3,this.initialDelay=e.initialDelay??100,this.maxDelay=e.maxDelay??1e4,this.backoffMultiplier=e.backoffMultiplier??2,this.retryableStatusCodes=e.retryableStatusCodes??[429,502,503,504]}static default(){return new s}};var c=class{constructor(e,t){this.items=e.items,this.params=e.params,this.nextPageLoader=t}get totalPages(){return Math.ceil((this.params?.count||0)/(this.params?.limit||25))}get hasNextPage(){return(this.params?.page||1)<this.totalPages}async nextPage(){if(!this.hasNextPage)throw new Error("No more pages available");if(!this.nextPageLoader)throw new Error("Next page loader not configured");return this.nextPageLoader((this.params.page||1)+1)}async*[Symbol.asyncIterator](){let e=this;for(;;){for(let t of e.items)yield t;if(!e.hasNextPage)break;e=await e.nextPage()}}async toArray(){let e=[];for await(let t of this)e.push(t);return e}};var Me={TEAM_CREATE:"team.create",TEAM_UPDATE:"team.update",PROJECT_CREATE:"project.create",PROJECT_UPDATE:"project.update",TODO_CREATE:"todo.create",TODO_UPDATE:"todo.update",TASK_CREATE:"task.create",TASK_UPDATE:"task.update",TAG_CREATE:"tag.create",TAG_UPDATE:"tag.update",RATE_CREATE:"rate.create",RATE_UPDATE:"rate.update",TIMER_START:"timer.start",TIMER_STOP:"timer.stop",TIMER_PAUSE:"timer.pause",TIMER_RESUME:"timer.resume"};function Se(...s){return s.join(",")}var i=class{constructor(e,t){this.http=e;typeof t=="string"?this.basePath=t:this.basePath=t.basePath}createNavigablePage(e,t){return new c(e,t)}};var w=class extends i{constructor(e){super(e,"/v1/organizations")}async list(e){let t=await this.http.get(this.basePath,e);return new c(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async listMembers(e,t){let r=await this.http.post(`${this.basePath}/${encodeURIComponent(e)}/members/list`,t);return this.createNavigablePage(r,o=>this.listMembers(e,{...t,page:o}))}async getMember(e,t){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`)}async addMember(e,t){return this.http.post(`${this.basePath}/${encodeURIComponent(e)}/members`,t)}async updateMember(e,t,r){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`,r)}async removeMember(e,t){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`)}};var E=class extends i{constructor(e){super(e,"/v1/teams")}async list(e){let t=await this.http.get(this.basePath,e);return new c(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async listMembers(e,t){let r=await this.http.post(`${this.basePath}/${e}/members/list`,t);return this.createNavigablePage(r,o=>this.listMembers(e,{...t,page:o}))}async getMember(e,t){return this.http.get(`${this.basePath}/${e}/members/${t}`)}async getColleagues(e){let t=await this.http.post(`${this.basePath}/getColleagues`,e);return this.createNavigablePage(t,r=>this.getColleagues({...e,page:r}))}async addMember(e,t){return this.http.post(`${this.basePath}/${e}/members`,t)}async updateMember(e,t,r){return this.http.put(`${this.basePath}/${e}/members/${t}`,r)}async removeMember(e,t){return this.http.delete(`${this.basePath}/${e}/members/${t}`)}async removeInvitedMember(e,t){return this.http.delete(`${this.basePath}/${e}/members/${t}/invited`)}async batchAddMembers(e){return this.http.post(`${this.basePath}/batchTeamMembers`,e)}async getMemberStatus(e){let t=await this.http.post(`${this.basePath}/getMemberStatus`,e);return this.createNavigablePage(t,r=>this.getMemberStatus({...e,page:r}))}};var $=class extends i{constructor(e){super(e,"/v1/projects")}async list(e){let t=await this.http.get(this.basePath,e);return new c(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async listMembers(e,t){let r=await this.http.post(`${this.basePath}/${encodeURIComponent(e)}/members/list`,t);return this.createNavigablePage(r,o=>this.listMembers(e,{...t,page:o}))}async addMember(e,t){return this.http.post(`${this.basePath}/${encodeURIComponent(e)}/members`,t)}async getMember(e,t){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`)}async updateMember(e,t,r){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`,r)}async updateMembers(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}/members`,t)}async removeMember(e,t){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`)}async batchAddMembers(e,t){return this.http.post(`${this.basePath}/${encodeURIComponent(e)}/members/batch`,t)}async batchRemoveMembers(e,t){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}/members/batch`,void 0,t)}};var T=P(require("dayjs")),ve=P(require("dayjs/plugin/utc")),Ae=P(require("dayjs/plugin/timezone")),we=P(require("dayjs/plugin/customParseFormat"));T.default.extend(ve.default);T.default.extend(Ae.default);T.default.extend(we.default);var Oe="YYYY-MM-DDTHH:mm:ssZ",Le=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/,n={isValidTimestampFormat(s){return Le.test(s)},formatTimestamp(s){return typeof s=="string"&&this.isValidTimestampFormat(s)?s:(0,T.default)(s||new Date).format(Oe)},parseTimestamp(s){return(0,T.default)(s).toDate()},formatDate(s){return(0,T.default)(s||new Date).format("YYYY-MM-DD")},now(){return this.formatTimestamp()}};var k=class extends i{constructor(e){super(e,"/v1/tasks")}async list(e){let t=await this.http.get(this.basePath,e);return this.createNavigablePage(t,r=>this.list({...e,page:r}))}async create(e){let t={...e,startDateTime:n.formatTimestamp(e.startDateTime),endDateTime:e.endDateTime?n.formatTimestamp(e.endDateTime):void 0};return this.http.post(this.basePath,t)}async update(e,t){let r={...t,startDateTime:t.startDateTime?n.formatTimestamp(t.startDateTime):void 0,endDateTime:t.endDateTime?n.formatTimestamp(t.endDateTime):void 0};return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,r)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async statistics(e){return this.http.post(`${this.basePath}/statistics`,e)}async updateStatus(e){return this.http.put(`${this.basePath}/updateStatus`,e)}async updateTimes(e){let t={...e,start:n.formatTimestamp(e.start),end:n.formatTimestamp(e.end)};return this.http.put(`${this.basePath}/updateTimes`,t)}async print(e){return this.http.request({method:"GET",url:`${this.basePath}/print/${encodeURIComponent(e)}`,responseType:"arraybuffer"})}};var U=class extends i{constructor(e){super(e,"/v1/rates")}async list(e){let t=await this.http.get(this.basePath,e);return new c(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var D=class extends i{constructor(e){super(e,"/v1/tags")}async list(e){let t=await this.http.get(this.basePath,e);return this.createNavigablePage(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var I=class extends i{constructor(e){super(e,"/v1/expenses")}async list(e){let t=await this.http.get(this.basePath,e);return new c(t,r=>this.list({...e,page:r}))}async create(e){let t={...e,dateTime:n.formatTimestamp(e.dateTime)};return this.http.post(this.basePath,t)}async update(e,t){let r={...t,dateTime:t.dateTime?n.formatTimestamp(t.dateTime):void 0};return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,r)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async updateStatus(e){return this.http.put(`${this.basePath}/updateStatus`,e)}async uploadFile(e,t){let r=new FormData;return r.append("file",t.file,t.fileName),this.http.postMultipart(`${this.basePath}/${encodeURIComponent(e)}/file`,r)}async createWithFile(e){let{file:t,...r}=e,o={...r,dateTime:n.formatTimestamp(r.dateTime)},a=new FormData;return a.append("data",new Blob([JSON.stringify(o)],{type:"application/json"})),t&&a.append("file",t.file,t.fileName),this.http.postMultipart(`${this.basePath}/with-file`,a)}async getFileUrl(e){return this.http.get(`${this.basePath}/getFileUrl/${encodeURIComponent(e)}`)}};var N=class extends i{constructor(e){super(e,"/v1/notes")}async list(e){let t=await this.http.get(this.basePath,e);return new c(t,r=>this.list({...e,page:r}))}async create(e){let t={...e,dateTime:n.formatTimestamp(e.dateTime)};return this.http.post(this.basePath,t)}async update(e,t){let r={...t,dateTime:n.formatTimestamp(t.dateTime)};return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,r)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}async uploadFile(e,t){let r=new FormData;return r.append("file",t.file,t.fileName),this.http.postMultipart(`${this.basePath}/${encodeURIComponent(e)}/file`,r)}async createWithFile(e){let{file:t,...r}=e,o={...r,dateTime:n.formatTimestamp(r.dateTime)},a=new FormData;return a.append("data",new Blob([JSON.stringify(o)],{type:"application/json"})),t&&a.append("file",t.file,t.fileName),this.http.postMultipart(`${this.basePath}/with-file`,a)}async getFileUrl(e){return this.http.get(`${this.basePath}/getFileUrl/${encodeURIComponent(e)}`)}};var q=class extends i{constructor(e){super(e,"/v1/pauses")}async list(e){let t=await this.http.get(this.basePath,e);return new c(t,r=>this.list({...e,page:r}))}async create(e){let t={...e,startDateTime:n.formatTimestamp(e.startDateTime),endDateTime:n.formatTimestamp(e.endDateTime)};return this.http.post(this.basePath,t)}async update(e,t){let r={...t,startDateTime:n.formatTimestamp(t.startDateTime),endDateTime:n.formatTimestamp(t.endDateTime)};return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,r)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var M=class{constructor(e){this.http=e}async getProfile(){return this.http.get("/v1/profiles/me")}async updateProfile(e){return this.http.put("/v1/profiles/me",e)}};var S=class{constructor(e){this.http=e}async get(){return this.http.get("/v1/settings")}async update(e){return this.http.put("/v1/settings",e)}};var O=class extends i{constructor(e){super(e,"/v1/automations")}async list(e){let t=await this.http.get(this.basePath,e);return new c(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var L=class extends i{constructor(e){super(e,"/v1/documents")}async list(e){let{category:t,...r}=e??{},o=t!==void 0?{...r,type:t}:{...r},a=await this.http.get(this.basePath,o);return new c(a,m=>this.list({...e,page:m}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var _=class{constructor(e){this.http=e}async get(){return this.http.get("/v1/timer")}async start(e){let t={...e,startDateTime:e.startDateTime?n.formatTimestamp(e.startDateTime):n.formatTimestamp()};return this.http.post("/v1/timer/start",t)}async stop(e){let t=e?{...e,endDateTime:e.endDateTime?n.formatTimestamp(e.endDateTime):n.formatTimestamp()}:{endDateTime:n.formatTimestamp()};return this.http.post("/v1/timer/stop",t)}async pause(e){let t=e?{...e,startDateTime:e.startDateTime?n.formatTimestamp(e.startDateTime):n.formatTimestamp()}:{startDateTime:n.formatTimestamp()};return this.http.post("/v1/timer/pause",t)}async resume(e){let t=e?{...e,endDateTime:e.endDateTime?n.formatTimestamp(e.endDateTime):n.formatTimestamp()}:{endDateTime:n.formatTimestamp()};return this.http.post("/v1/timer/resume",t)}async update(e){let t={...e,startDateTime:e.startDateTime?n.formatTimestamp(e.startDateTime):void 0};return this.http.put("/v1/timer/update",t)}};var z=class extends i{constructor(e){super(e,"/v1/todos")}async list(e){let t=await this.http.get(this.basePath,e);return this.createNavigablePage(t,r=>this.list({...e,page:r}))}async create(e){let t={...e,dueDate:e.dueDate?n.formatTimestamp(e.dueDate):void 0};return this.http.post(this.basePath,t)}async update(e,t){let r={...t,dueDate:t.dueDate?n.formatTimestamp(t.dueDate):void 0};return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,r)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var F=class extends i{constructor(e){super(e,"/v1/webhooks")}async list(e){let t=await this.http.get(this.basePath,e);return new c(t,r=>this.list({...e,page:r}))}async create(e){return this.http.post(this.basePath,e)}async update(e,t){return this.http.put(`${this.basePath}/${encodeURIComponent(e)}`,t)}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async delete(e){return this.http.delete(`${this.basePath}/${encodeURIComponent(e)}`)}async search(e){let t=await this.http.post(`${this.basePath}/search`,e);return this.createNavigablePage(t,r=>this.search({...e,page:r}))}};var j=class extends i{constructor(e){super(e,"/v1/events")}async getStatus(){return this.http.get(`${this.basePath}/status`)}getStreamUrl(){return`${this.http.getBaseUrl()}${this.basePath}/stream`}async subscribe(e){let t=this.getStreamUrl(),o={Accept:"text/event-stream","Cache-Control":"no-cache",...await this.http.getAuthHeaders()},a=new AbortController,m=!1,p=new Map,g={close:()=>{m=!1,a.abort(),e.onClose?.()},get isConnected(){return m},on:(h,u)=>{p.has(h)||p.set(h,new Set),p.get(h).add(u)},off:(h,u)=>{p.get(h)?.delete(u)}};return this.connectSse(t,o,a.signal,{...e,onConnected:h=>{m=!0,e.onConnected?.(h)},onEvent:h=>{e.onEvent?.(h),p.get(h.event)?.forEach(d=>d(h))},onError:h=>{e.onError?.(h),p.get("error")?.forEach(d=>d(h))},onClose:()=>{m=!1,e.onClose?.()}}),g}async connectSse(e,t,r,o){try{let a=await fetch(e,{method:"GET",headers:t,signal:r});if(!a.ok)throw new Error(`SSE connection failed: ${a.status} ${a.statusText}`);if(!a.body)throw new Error("SSE response has no body");let m=a.body.getReader(),p=new TextDecoder,g="",h="",u="",d="",Q=!1;for(;!Q;){let R=await m.read();if(Q=R.done,Q||!R.value){o.onClose?.();break}g+=p.decode(R.value,{stream:!0});let ge=g.split(`
|
|
2
|
+
`);g=ge.pop()||"";for(let b of ge)b.startsWith("event:")?h=b.slice(6).trim():b.startsWith("data:")?u=b.slice(5).trim():b.startsWith("id:")?d=b.slice(3).trim():b===""&&(u&&this.processEvent(h,u,d,o),h="",u="",d="")}}catch(a){if(r.aborted)return;o.onError?.(a)}}processEvent(e,t,r,o){try{let a=JSON.parse(t);if(e==="connected"){let m=a;o.onConnected?.(m.connectionId)}else o.onEvent?.(a)}catch{o.onError?.(new Error(`Failed to parse event data: ${t}`))}}};var W=class extends i{constructor(e){super(e,"/v1/organizations")}orgPath(e){return`${this.basePath}/${encodeURIComponent(e)}/absences`}async list(e,t){let r=await this.http.get(this.orgPath(e),t);return this.createNavigablePage(r,o=>this.list(e,{...t,page:o}))}async search(e,t){let r=await this.http.post(`${this.orgPath(e)}/search`,t);return this.createNavigablePage(r,o=>this.search(e,{...t,page:o}))}async create(e,t){return this.http.post(this.orgPath(e),t)}async get(e,t){return this.http.get(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async update(e,t,r){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}`,r)}async delete(e,t){return this.http.delete(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async approve(e,t){return this.http.post(`${this.orgPath(e)}/${encodeURIComponent(t)}/approve`)}async reject(e,t,r){return this.http.post(`${this.orgPath(e)}/${encodeURIComponent(t)}/reject`,r)}async cancel(e,t,r){return this.http.post(`${this.orgPath(e)}/${encodeURIComponent(t)}/cancel`,r)}};var B=class extends i{constructor(e){super(e,"/v1/organizations")}orgPath(e){return`${this.basePath}/${encodeURIComponent(e)}/absence-types`}async list(e,t){let r=await this.http.get(this.orgPath(e),t);return this.createNavigablePage(r,o=>this.list(e,{...t,page:o}))}async create(e,t){return this.http.post(this.orgPath(e),t)}async get(e,t){return this.http.get(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async update(e,t,r){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}`,r)}async delete(e,t){return this.http.delete(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}};var H=class extends i{constructor(e){super(e,"/v1/organizations")}orgPath(e){return`${this.basePath}/${encodeURIComponent(e)}/contracts`}async list(e,t){let r=await this.http.get(this.orgPath(e),t);return this.createNavigablePage(r,o=>this.list(e,{...t,page:o}))}async create(e,t){return this.http.post(this.orgPath(e),t)}async get(e,t){return this.http.get(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async update(e,t,r){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}`,r)}async delete(e,t){return this.http.delete(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async activate(e,t){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}/activate`)}async suspend(e,t){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}/suspend`)}async reactivate(e,t){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}/reactivate`)}async terminate(e,t){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}/terminate`)}};var K=class extends i{constructor(e){super(e,"/v1/organizations")}orgPath(e){return`${this.basePath}/${encodeURIComponent(e)}/contract-templates`}async list(e,t){let r=await this.http.get(this.orgPath(e),t);return this.createNavigablePage(r,o=>this.list(e,{...t,page:o}))}async create(e,t){return this.http.post(this.orgPath(e),t)}async get(e,t){return this.http.get(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}async update(e,t,r){return this.http.put(`${this.orgPath(e)}/${encodeURIComponent(t)}`,r)}async delete(e,t){return this.http.delete(`${this.orgPath(e)}/${encodeURIComponent(t)}`)}};var V=class extends i{constructor(e){super(e,"/v1/documents")}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async getPdf(e){return this.http.request({method:"GET",url:`${this.basePath}/${encodeURIComponent(e)}/pdf`,responseType:"arraybuffer"})}async getXml(e){return this.http.request({method:"GET",url:`${this.basePath}/${encodeURIComponent(e)}/xml`,headers:{Accept:"application/xml"}})}};var J=class extends i{constructor(e){super(e,"/v1/tasks")}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async getPdf(e){return this.http.request({method:"GET",url:`${this.basePath}/${encodeURIComponent(e)}/pdf`,responseType:"arraybuffer"})}};var G=class extends i{constructor(e){super(e,"/v1/expenses")}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async getPdf(e){return this.http.request({method:"GET",url:`${this.basePath}/${encodeURIComponent(e)}/pdf`,responseType:"arraybuffer"})}};var Y=class extends i{constructor(e){super(e,"/v1/notes")}async get(e){return this.http.get(`${this.basePath}/${encodeURIComponent(e)}`)}async getPdf(e){return this.http.request({method:"GET",url:`${this.basePath}/${encodeURIComponent(e)}/pdf`,responseType:"arraybuffer"})}};var Z=class extends i{constructor(e){super(e,"/v1/export")}async generate(e){return this.http.post(`${this.basePath}/data`,e)}async send(e){return this.http.post(`${this.basePath}/send`,e)}async generateFromTemplate(e){return this.http.request({method:"POST",url:`${this.basePath}/from-template`,data:e,responseType:"arraybuffer"})}async getFields(e){return this.http.get(`${this.basePath}/fields`,e?{scope:e}:void 0)}async getReportTypes(){return this.http.get(`${this.basePath}/report-types`)}async listTemplates(e){let t=await this.http.get(`${this.basePath}/templates`,e);return new c(t,r=>this.listTemplates({...e,page:r}))}async searchTemplates(e){let t=await this.http.post(`${this.basePath}/templates/search`,e);return this.createNavigablePage(t,r=>this.searchTemplates({...e,page:r}))}async createTemplate(e){return this.http.post(`${this.basePath}/templates`,e)}async getTemplate(e){return this.http.get(`${this.basePath}/templates/${encodeURIComponent(e)}`)}async updateTemplate(e,t){return this.http.put(`${this.basePath}/templates/${encodeURIComponent(e)}`,t)}async deleteTemplate(e){return this.http.delete(`${this.basePath}/templates/${encodeURIComponent(e)}`)}async listCustomFields(e){return this.http.get(`${this.basePath}/custom-fields`,e?{scope:e}:void 0)}async createCustomField(e){return this.http.post(`${this.basePath}/custom-fields`,e)}async getCustomField(e){return this.http.get(`${this.basePath}/custom-fields/${encodeURIComponent(e)}`)}async updateCustomField(e,t){return this.http.put(`${this.basePath}/custom-fields/${encodeURIComponent(e)}`,t)}async deleteCustomField(e){return this.http.delete(`${this.basePath}/custom-fields/${encodeURIComponent(e)}`)}};var X=class{constructor(e){this.documents=new V(e),this.tasks=new J(e),this.expenses=new G(e),this.notes=new Y(e),this.export=new Z(e)}};var pe=class{constructor(e){let t=this.createAuthentication(e),r=e.retryConfig||oe.default(),o={baseUrl:e.baseUrl||"https://api.timesheet.io",authentication:t,retryConfig:r,httpClient:e.httpClient};this.apiClient=new x(o);let a={baseUrl:e.reportsBaseUrl||"https://reports.timesheet.io",authentication:t,retryConfig:r,httpClient:e.reportsHttpClient};this.reportsApiClient=new x(a),this.organizations=new w(this.apiClient),this.teams=new E(this.apiClient),this.projects=new $(this.apiClient),this.tasks=new k(this.apiClient),this.rates=new U(this.apiClient),this.tags=new D(this.apiClient),this.expenses=new I(this.apiClient),this.notes=new N(this.apiClient),this.pauses=new q(this.apiClient),this.profile=new M(this.apiClient),this.settings=new S(this.apiClient),this.automations=new O(this.apiClient),this.documents=new L(this.apiClient),this.timer=new _(this.apiClient),this.todos=new z(this.apiClient),this.webhooks=new F(this.apiClient),this.events=new j(this.apiClient),this.absences=new W(this.apiClient),this.absenceTypes=new B(this.apiClient),this.contracts=new H(this.apiClient),this.contractTemplates=new K(this.apiClient),this.reports=new X(this.reportsApiClient)}createAuthentication(e){if(e.apiKey)return new re(e.apiKey);if(e.oauth2Token)return new v(e.oauth2Token);if(e.oauth2)return new v(e.oauth2.clientId,e.oauth2.clientSecret,e.oauth2.refreshToken);if(e.authentication)return e.authentication;throw new Error("Authentication must be configured")}};function _e(s){return new pe(s)}0&&(module.exports={AbsenceResource,AbsenceTypeResource,ApiClient,ApiKeyAuth,AutomationResource,ContractResource,ContractTemplateResource,DocumentReportResource,DocumentResource,EventResource,ExpenseReportResource,ExpenseResource,ExportResource,NavigablePage,NoteReportResource,NoteResource,OAuth21Auth,OAuth2Auth,OAuthDiscovery,OrganizationResource,PauseResource,ProfileResource,ProjectResource,RateResource,ReportsClient,Resource,RetryConfig,SettingsResource,TagResource,TaskReportResource,TaskResource,TeamResource,TimerResource,TimesheetApiError,TimesheetAuthError,TimesheetClient,TimesheetRateLimitError,TodoResource,WebhookEvents,WebhookResource,combineWebhookEvents,createClient,discoverOAuth,generateCodeChallenge,generateCodeVerifier,generatePkceCodePair,getDefaultDiscovery,isValidCodeVerifier});
|
|
3
3
|
//# sourceMappingURL=index.js.map
|