@timesheet/sdk 1.0.2 → 1.0.4

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 CHANGED
@@ -6,6 +6,36 @@ 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.0.4] - 2026-01-04
10
+
11
+ ### Added
12
+ - OAuth 2.1 Discovery support (RFC 8414):
13
+ - `OAuthDiscovery` class for endpoint discovery from `/.well-known/oauth-authorization-server`
14
+ - Support for Protected Resource Metadata (RFC 9728)
15
+ - Support for OpenID Connect Discovery (`/.well-known/openid-configuration`)
16
+ - Discovery result caching with configurable TTL
17
+ - `discoverOAuth()` convenience function for quick discovery
18
+ - Custom `authorizationEndpoint` and `tokenEndpoint` options in OAuth21Auth methods
19
+
20
+ ## [1.0.3] - 2026-01-04
21
+
22
+ ### Added
23
+ - OAuth 2.1 authentication support with PKCE (Proof Key for Code Exchange)
24
+ - New `OAuth21Auth` class for OAuth 2.1 authorization code flow
25
+ - PKCE utilities: `generatePkceCodePair()`, `generateCodeVerifier()`, `generateCodeChallenge()`
26
+ - Support for public clients (optional client secret with PKCE)
27
+ - Resource indicators support (RFC 8707)
28
+ - Reports API integration (`reports.timesheet.io`) with full model support:
29
+ - `DocumentReportResource` - Document PDF/XML generation
30
+ - `TaskReportResource` - Task report generation
31
+ - `ExpenseReportResource` - Expense report generation
32
+ - `NoteReportResource` - Note report generation
33
+ - `ExportResource` - Excel/CSV/PDF exports with templates and custom fields
34
+ - Complete TypeScript models for reports: `DocumentReport`, `TaskReportItem`, `ExpenseReportItem`, `NoteReportItem`
35
+ - Export template management (CRUD operations)
36
+ - Custom export field management
37
+ - Comprehensive unit tests for Reports API
38
+
9
39
  ## [1.0.2] - 2025-10-25
10
40
 
11
41
  ### Added
@@ -70,7 +100,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
70
100
  - Removed complex mocking in favor of simple validation tests
71
101
  - Updated GitHub Actions to use non-deprecated action versions
72
102
 
73
- [Unreleased]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.0.2...HEAD
103
+ [Unreleased]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.0.4...HEAD
104
+ [1.0.4]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.0.3...v1.0.4
105
+ [1.0.3]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.0.2...v1.0.3
74
106
  [1.0.2]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.0.1...v1.0.2
75
107
  [1.0.1]: https://github.com/timesheetIO/timesheet-typescript/compare/v1.0.0...v1.0.1
76
108
  [1.0.0]: https://github.com/timesheetIO/timesheet-typescript/releases/tag/v1.0.0
package/README.md CHANGED
@@ -12,7 +12,7 @@ The official TypeScript SDK for the [Timesheet API](https://timesheet.io), provi
12
12
 
13
13
  - ✅ **Type-Safe** - Full TypeScript support with comprehensive types
14
14
  - ✅ **Modern Architecture** - Promise-based with async/await support
15
- - ✅ **Authentication** - Built-in API Key and OAuth2 support
15
+ - ✅ **Authentication** - Built-in API Key, OAuth2, and OAuth 2.1 (PKCE) with automatic discovery (RFC 8414)
16
16
  - ✅ **Error Handling** - Typed exceptions for better error management
17
17
  - ✅ **Pagination** - Automatic pagination with async iterators
18
18
  - ✅ **Retry Logic** - Configurable retry with exponential backoff
@@ -89,6 +89,137 @@ const client = new TimesheetClient({
89
89
  });
90
90
  ```
91
91
 
92
+ ### OAuth 2.1 Authentication (with PKCE)
93
+
94
+ OAuth 2.1 is the recommended authentication method for new applications. It requires PKCE (Proof Key for Code Exchange) for enhanced security.
95
+
96
+ ```typescript
97
+ import { OAuth21Auth, generatePkceCodePair } from '@timesheet/sdk';
98
+
99
+ // Step 1: Generate PKCE code pair
100
+ const pkce = generatePkceCodePair();
101
+ // Store pkce.codeVerifier securely (e.g., in session storage)
102
+
103
+ // Step 2: Build authorization URL and redirect user
104
+ const authUrl = OAuth21Auth.buildAuthorizationUrl({
105
+ clientId: 'your-client-id',
106
+ redirectUri: 'https://your-app.com/callback',
107
+ codeChallenge: pkce.codeChallenge,
108
+ codeChallengeMethod: pkce.codeChallengeMethod,
109
+ state: 'random-csrf-state', // Optional but recommended
110
+ scope: 'read write', // Optional
111
+ });
112
+
113
+ // Redirect user to authUrl...
114
+
115
+ // Step 3: After user authorizes, exchange code for tokens
116
+ const auth = await OAuth21Auth.fromAuthorizationCode({
117
+ clientId: 'your-client-id',
118
+ clientSecret: 'your-client-secret', // Optional for public clients
119
+ authorizationCode: codeFromCallback,
120
+ redirectUri: 'https://your-app.com/callback',
121
+ codeVerifier: pkce.codeVerifier,
122
+ });
123
+
124
+ // Step 4: Use with TimesheetClient
125
+ const client = new TimesheetClient({
126
+ authentication: auth
127
+ });
128
+ ```
129
+
130
+ #### OAuth 2.1 with Endpoint Discovery (RFC 8414)
131
+
132
+ The SDK supports automatic endpoint discovery from `/.well-known/oauth-authorization-server`, allowing you to dynamically configure OAuth endpoints:
133
+
134
+ ```typescript
135
+ import { OAuth21Auth, OAuthDiscovery, generatePkceCodePair } from '@timesheet/sdk';
136
+
137
+ // Step 1: Discover OAuth endpoints
138
+ const discovery = new OAuthDiscovery();
139
+ const metadata = await discovery.discover('https://api.timesheet.io');
140
+
141
+ console.log('Authorization endpoint:', metadata.authorizationServer.authorization_endpoint);
142
+ console.log('Token endpoint:', metadata.authorizationServer.token_endpoint);
143
+ console.log('Supported scopes:', metadata.authorizationServer.scopes_supported);
144
+
145
+ // Step 2: Generate PKCE and build authorization URL using discovered endpoints
146
+ const pkce = generatePkceCodePair();
147
+
148
+ const authUrl = OAuth21Auth.buildAuthorizationUrl({
149
+ clientId: 'your-client-id',
150
+ redirectUri: 'https://your-app.com/callback',
151
+ codeChallenge: pkce.codeChallenge,
152
+ codeChallengeMethod: pkce.codeChallengeMethod,
153
+ scope: 'read write',
154
+ state: 'random-csrf-state',
155
+ authorizationEndpoint: metadata.authorizationServer.authorization_endpoint,
156
+ });
157
+
158
+ // Store pkce.codeVerifier and token endpoint securely, then redirect user
159
+ sessionStorage.setItem('pkce_verifier', pkce.codeVerifier);
160
+ sessionStorage.setItem('token_endpoint', metadata.authorizationServer.token_endpoint);
161
+
162
+ // Step 3: After callback, exchange code using discovered token endpoint
163
+ const auth = await OAuth21Auth.fromAuthorizationCode({
164
+ clientId: 'your-client-id',
165
+ authorizationCode: codeFromCallback,
166
+ redirectUri: 'https://your-app.com/callback',
167
+ codeVerifier: sessionStorage.getItem('pkce_verifier'),
168
+ tokenEndpoint: sessionStorage.getItem('token_endpoint'),
169
+ });
170
+
171
+ const client = new TimesheetClient({
172
+ authentication: auth
173
+ });
174
+ ```
175
+
176
+ The `OAuthDiscovery` class provides caching and additional discovery options:
177
+
178
+ ```typescript
179
+ import { OAuthDiscovery, discoverOAuth } from '@timesheet/sdk';
180
+
181
+ // Using convenience function (uses shared cached instance)
182
+ const result = await discoverOAuth('https://api.timesheet.io');
183
+
184
+ // Using class with custom options
185
+ const discovery = new OAuthDiscovery({
186
+ cacheTtl: 3600000, // Cache for 1 hour (default)
187
+ timeout: 10000, // Request timeout in ms
188
+ fetchOpenIdConfig: true, // Also fetch OpenID Connect config
189
+ fetchProtectedResource: true, // Also fetch protected resource metadata (RFC 9728)
190
+ });
191
+
192
+ const metadata = await discovery.discover('https://api.timesheet.io');
193
+
194
+ // Check cache status
195
+ if (discovery.isCached('https://api.timesheet.io')) {
196
+ console.log('Using cached metadata');
197
+ }
198
+
199
+ // Clear cache when needed
200
+ discovery.clearCache();
201
+ ```
202
+
203
+ #### Using OAuth 2.1 with existing tokens
204
+
205
+ ```typescript
206
+ import { OAuth21Auth } from '@timesheet/sdk';
207
+
208
+ // With just an access token
209
+ const auth = new OAuth21Auth('your-access-token');
210
+
211
+ // With refresh token for automatic token refresh
212
+ const auth = new OAuth21Auth({
213
+ clientId: 'your-client-id',
214
+ clientSecret: 'your-client-secret', // Optional for public clients
215
+ refreshToken: 'your-refresh-token',
216
+ });
217
+
218
+ const client = new TimesheetClient({
219
+ authentication: auth
220
+ });
221
+ ```
222
+
92
223
  ## Resources
93
224
 
94
225
  All API resources are available through the client: