@onecal/unified-calendar-api-node-sdk 0.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/LICENSE +7 -0
- package/README.md +362 -0
- package/dist/index.cjs +542 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +786 -0
- package/dist/index.d.ts +786 -0
- package/dist/index.js +518 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth/index.cjs +20 -0
- package/dist/oauth/index.cjs.map +1 -0
- package/dist/oauth/index.d.cts +21 -0
- package/dist/oauth/index.d.ts +21 -0
- package/dist/oauth/index.js +18 -0
- package/dist/oauth/index.js.map +1 -0
- package/package.json +94 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026 OneCal SH.P.K
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# OneCal Unified Calendar API - Node.js SDK
|
|
2
|
+
|
|
3
|
+
Official Node.js/TypeScript SDK for the [OneCal Unified Calendar API](https://docs.onecalunified.com). Manage calendars, events, and integrations across Google Calendar, Microsoft Outlook, and other providers with a single, unified interface.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
✨ **Unified Interface** - Work with multiple calendar providers through one consistent API
|
|
8
|
+
🔒 **Type-Safe** - Full TypeScript support with comprehensive type definitions
|
|
9
|
+
📦 **Modern** - ESM and CommonJS support
|
|
10
|
+
🚀 **Simple** - Intuitive, promise-based API
|
|
11
|
+
📚 **Well-Documented** - Extensive documentation and examples
|
|
12
|
+
🧪 **Tested** - Comprehensive test coverage
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @onecal/unified-calendar-api-node-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or using yarn:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
yarn add @onecal/unified-calendar-api-node-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or using pnpm:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add @onecal/unified-calendar-api-node-sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { UnifiedCalendarApi } from '@onecal/unified-calendar-api-node-sdk';
|
|
36
|
+
|
|
37
|
+
// Initialize the client
|
|
38
|
+
const client = new UnifiedCalendarApi({
|
|
39
|
+
apiKey: 'your-api-key-here'
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// List calendars
|
|
43
|
+
const calendars = await client.calendars.list('endUserAccountId');
|
|
44
|
+
|
|
45
|
+
// Create an event
|
|
46
|
+
const event = await client.events.create('endUserAccountId', 'calendarId', {
|
|
47
|
+
title: 'Team Meeting',
|
|
48
|
+
start: {
|
|
49
|
+
dateTime: '2026-01-20T10:00:00Z',
|
|
50
|
+
timeZone: 'UTC'
|
|
51
|
+
},
|
|
52
|
+
end: {
|
|
53
|
+
dateTime: '2026-01-20T11:00:00Z',
|
|
54
|
+
timeZone: 'UTC'
|
|
55
|
+
},
|
|
56
|
+
attendees: [
|
|
57
|
+
{ email: 'team@example.com', name: 'Team Member' }
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
console.log(`Created event: ${event.title}`);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Configuration
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const client = new UnifiedCalendarApi({
|
|
68
|
+
apiKey: 'your-api-key', // Required: Your Unified Calendar API key
|
|
69
|
+
unifiedApiBaseUrl: 'https://api.onecalunified.com', // Optional: API base URL
|
|
70
|
+
timeout: 30000, // Optional: Request timeout in ms
|
|
71
|
+
debug: false // Optional: Enable debug logging
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API Reference
|
|
76
|
+
|
|
77
|
+
### End User Accounts
|
|
78
|
+
|
|
79
|
+
Manage end user accounts that connect to calendar providers.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// List all end user accounts
|
|
83
|
+
const accounts = await client.endUserAccounts.list({
|
|
84
|
+
limit: 20,
|
|
85
|
+
search: 'user@example.com',
|
|
86
|
+
statusFilter: 'active'
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Get a specific account
|
|
90
|
+
const account = await client.endUserAccounts.get('accountId');
|
|
91
|
+
|
|
92
|
+
// Create a new account
|
|
93
|
+
const newAccount = await client.endUserAccounts.create({
|
|
94
|
+
email: 'user@example.com',
|
|
95
|
+
refreshToken: 'refresh-token',
|
|
96
|
+
providerType: ProviderType.GOOGLE,
|
|
97
|
+
externalId: 'user-123'
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Get account credentials (automatically refreshes if expired)
|
|
101
|
+
const credentials = await client.endUserAccounts.getCredentials('accountId');
|
|
102
|
+
|
|
103
|
+
// Delete an account
|
|
104
|
+
await client.endUserAccounts.delete('accountId');
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Calendars
|
|
108
|
+
|
|
109
|
+
Manage calendars for end user accounts.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// List calendars
|
|
113
|
+
const calendars = await client.calendars.list('endUserAccountId', {
|
|
114
|
+
pageSize: 20
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Get a specific calendar
|
|
118
|
+
const calendar = await client.calendars.get('endUserAccountId', 'calendarId');
|
|
119
|
+
|
|
120
|
+
// Create a calendar
|
|
121
|
+
const newCalendar = await client.calendars.create('endUserAccountId', {
|
|
122
|
+
name: 'My Calendar',
|
|
123
|
+
hexColor: '#FF5733',
|
|
124
|
+
timeZone: 'America/New_York'
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Update a calendar
|
|
128
|
+
const updated = await client.calendars.update('endUserAccountId', 'calendarId', {
|
|
129
|
+
name: 'Updated Calendar Name'
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Delete a calendar
|
|
133
|
+
await client.calendars.delete('endUserAccountId', 'calendarId');
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Events
|
|
137
|
+
|
|
138
|
+
Create, read, update, and delete calendar events.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
// List events
|
|
142
|
+
const events = await client.events.list('endUserAccountId', 'calendarId', {
|
|
143
|
+
startDateTime: new Date('2026-01-01'),
|
|
144
|
+
endDateTime: new Date('2026-12-31'),
|
|
145
|
+
search: 'meeting',
|
|
146
|
+
orderBy: EventOrderBy.START_TIME,
|
|
147
|
+
pageSize: 50
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Get a specific event
|
|
151
|
+
const event = await client.events.get('endUserAccountId', 'calendarId', 'eventId');
|
|
152
|
+
|
|
153
|
+
// Create an event
|
|
154
|
+
const newEvent = await client.events.create('endUserAccountId', 'calendarId', {
|
|
155
|
+
title: 'Product Launch',
|
|
156
|
+
description: 'Launch event for new product',
|
|
157
|
+
start: {
|
|
158
|
+
dateTime: '2026-02-15T14:00:00Z',
|
|
159
|
+
timeZone: 'UTC'
|
|
160
|
+
},
|
|
161
|
+
end: {
|
|
162
|
+
dateTime: '2026-02-15T16:00:00Z',
|
|
163
|
+
timeZone: 'UTC'
|
|
164
|
+
},
|
|
165
|
+
location: '123 Main St, San Francisco, CA',
|
|
166
|
+
attendees: [
|
|
167
|
+
{ email: 'alice@example.com', name: 'Alice' },
|
|
168
|
+
{ email: 'bob@example.com', name: 'Bob' }
|
|
169
|
+
],
|
|
170
|
+
reminders: {
|
|
171
|
+
useDefault: false,
|
|
172
|
+
overrides: [
|
|
173
|
+
{ method: 'email', minutes: 24 * 60 }, // 1 day before
|
|
174
|
+
{ method: 'popup', minutes: 30 } // 30 minutes before
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Update an event
|
|
180
|
+
const updated = await client.events.update('endUserAccountId', 'calendarId', 'eventId', {
|
|
181
|
+
title: 'Updated Event Title',
|
|
182
|
+
location: 'New Location'
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Delete an event
|
|
186
|
+
await client.events.delete('endUserAccountId', 'calendarId', 'eventId');
|
|
187
|
+
|
|
188
|
+
// Get recurring event occurrences
|
|
189
|
+
const occurrences = await client.events.getOccurrences(
|
|
190
|
+
'endUserAccountId',
|
|
191
|
+
'calendarId',
|
|
192
|
+
'recurringEventId',
|
|
193
|
+
{
|
|
194
|
+
startDateTime: new Date('2026-01-01'),
|
|
195
|
+
endDateTime: new Date('2026-03-31')
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
// RSVP to an event
|
|
200
|
+
await client.events.rsvp('endUserAccountId', 'calendarId', 'eventId', {
|
|
201
|
+
responseStatus: 'accepted'
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Free/Busy
|
|
206
|
+
|
|
207
|
+
Query free/busy availability across calendars.
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
const freeBusy = await client.freeBusy.get('endUserAccountId', {
|
|
211
|
+
startDateTime: new Date(),
|
|
212
|
+
endDateTime: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // Next 7 days
|
|
213
|
+
timeZone: 'America/New_York',
|
|
214
|
+
calendarIds: ['calendar1', 'calendar2']
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Response is an array of FreeBusySlot objects
|
|
218
|
+
console.log('Free/Busy results:', freeBusy);
|
|
219
|
+
// Example: [{ calendarId: 'calendar1', busySlots: [{ start: {...}, end: {...} }] }]
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Calendar Subscriptions
|
|
223
|
+
|
|
224
|
+
Subscribe to calendar event notifications via webhooks.
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
// List subscriptions
|
|
228
|
+
const subscriptions = await client.calendarSubscriptions.list('endUserAccountId');
|
|
229
|
+
|
|
230
|
+
// Create a subscription for calendar events
|
|
231
|
+
const subscription = await client.calendarSubscriptions.create('endUserAccountId', {
|
|
232
|
+
webhookUrl: 'https://your-app.com/webhooks',
|
|
233
|
+
calendarId: 'calendarId',
|
|
234
|
+
subscriptionType: 'event', // 'event' for calendar events, 'calendar' for calendar changes
|
|
235
|
+
rateLimit: 100 // Optional: requests per second limit
|
|
236
|
+
});
|
|
237
|
+
// Returns: { webhookSubscriptionId: string, endpointSecret: string }
|
|
238
|
+
|
|
239
|
+
// Create a subscription for calendar list changes
|
|
240
|
+
const calendarSub = await client.calendarSubscriptions.create('endUserAccountId', {
|
|
241
|
+
webhookUrl: 'https://your-app.com/webhooks/calendars',
|
|
242
|
+
subscriptionType: 'calendar',
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Delete a subscription
|
|
246
|
+
await client.calendarSubscriptions.delete('endUserAccountId', 'subscriptionId');
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### OAuth
|
|
250
|
+
|
|
251
|
+
Generate OAuth authorization URLs for connecting user calendars.
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { getOAuthUrl } from '@onecal/unified-calendar-api-node-sdk/oauth';
|
|
255
|
+
|
|
256
|
+
// Get OAuth URL for Google
|
|
257
|
+
const googleUrl = getOAuthUrl('your-app-id', 'GOOGLE', {
|
|
258
|
+
redirectUrl: 'https://your-app.com/callback',
|
|
259
|
+
externalId: 'user-123',
|
|
260
|
+
loginHint: 'user@example.com',
|
|
261
|
+
unifiedApiBaseUrl: 'https://api.onecalunified.com' // Optional: defaults to production
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Get OAuth URL for Microsoft
|
|
265
|
+
const microsoftUrl = getOAuthUrl('your-app-id', 'MICROSOFT', {
|
|
266
|
+
redirectUrl: 'https://your-app.com/callback',
|
|
267
|
+
externalId: 'user-456'
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// Redirect user to the OAuth URL
|
|
271
|
+
// After authorization, they'll be redirected back to your redirectUrl
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Error Handling
|
|
275
|
+
|
|
276
|
+
The SDK provides specific error types for different scenarios:
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import {
|
|
280
|
+
UnifiedCalendarApiError,
|
|
281
|
+
APIRequestError,
|
|
282
|
+
AuthenticationError,
|
|
283
|
+
AuthorizationError,
|
|
284
|
+
NotFoundError,
|
|
285
|
+
RateLimitError
|
|
286
|
+
} from '@onecal/unified-calendar-api-node-sdk';
|
|
287
|
+
|
|
288
|
+
try {
|
|
289
|
+
const event = await client.events.get('accountId', 'calendarId', 'eventId');
|
|
290
|
+
} catch (error) {
|
|
291
|
+
if (error instanceof AuthenticationError) {
|
|
292
|
+
console.error('Invalid API key');
|
|
293
|
+
} else if (error instanceof NotFoundError) {
|
|
294
|
+
console.error('Event not found');
|
|
295
|
+
} else if (error instanceof RateLimitError) {
|
|
296
|
+
console.error(`Rate limited. Retry after ${error.retryAfter} seconds`);
|
|
297
|
+
} else if (error instanceof APIRequestError) {
|
|
298
|
+
console.error(`API error: ${error.message} (${error.status})`);
|
|
299
|
+
} else {
|
|
300
|
+
console.error('Unexpected error:', error);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## TypeScript Support
|
|
306
|
+
|
|
307
|
+
This SDK is written in TypeScript and provides comprehensive type definitions:
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
import type {
|
|
311
|
+
Calendar,
|
|
312
|
+
Event,
|
|
313
|
+
EndUserAccount,
|
|
314
|
+
CreateEventInput,
|
|
315
|
+
ListEventsParams,
|
|
316
|
+
EventOrderBy,
|
|
317
|
+
ProviderType
|
|
318
|
+
} from '@onecal/unified-calendar-api-node-sdk';
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Examples
|
|
322
|
+
|
|
323
|
+
See the [`examples/`](./examples/) directory for more usage examples:
|
|
324
|
+
|
|
325
|
+
- [`quickstart.ts`](./examples/quickstart.ts) - Complete quick start guide
|
|
326
|
+
|
|
327
|
+
## Development
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
# Install dependencies
|
|
331
|
+
npm install
|
|
332
|
+
|
|
333
|
+
# Build the SDK
|
|
334
|
+
npm run build
|
|
335
|
+
|
|
336
|
+
# Run tests
|
|
337
|
+
npm test
|
|
338
|
+
|
|
339
|
+
# Run linter
|
|
340
|
+
npm run lint
|
|
341
|
+
|
|
342
|
+
# Format code
|
|
343
|
+
npm run format
|
|
344
|
+
|
|
345
|
+
# Type check
|
|
346
|
+
npm run typecheck
|
|
347
|
+
|
|
348
|
+
# Watch mode (for development)
|
|
349
|
+
npm run dev
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## Support
|
|
353
|
+
|
|
354
|
+
- 📧 Email: contact@onecalunified.com
|
|
355
|
+
- 📚 Documentation: https://docs.onecalunified.com
|
|
356
|
+
|
|
357
|
+
## Links
|
|
358
|
+
|
|
359
|
+
- [OneCal Unified API Website](https://www.onecal.io/unified-calendar-api)
|
|
360
|
+
- [API Documentation](https://docs.onecalunified.com)
|
|
361
|
+
- [NPM Package](https://www.npmjs.com/package/@onecal/unified-calendar-api-node-sdk)
|
|
362
|
+
- [GitHub Repository](https://github.com/onecal-unified/unified-calendar-api-node-sdk)
|